diff --git a/Documentation/WickedEngine-Documentation.md b/Documentation/WickedEngine-Documentation.md index 089f89fb6..0aa2fa980 100644 --- a/Documentation/WickedEngine-Documentation.md +++ b/Documentation/WickedEngine-Documentation.md @@ -114,22 +114,21 @@ This is a reference for the C++ features of Wicked Engine 4. [wiContainers](#wicontainers) 1. [ThreadSafeRingBuffer](#threadsaferingbuffer) 5. [wiFadeManager](#wifademanager) - 6. [wiHashString](#wihashstring) - 7. [wiHelper](#wihelper) - 8. [wiIntersect](#wiintersect) + 6. [wiHelper](#wihelper) + 7. [wiIntersect](#wiintersect) 1. [AABB](#aabb) 2. [SPHERE](#sphere) 2. [CAPSULE](#capsule) 3. [RAY](#ray) 4. [Frustum](#frustum) 5. [Hitbox2D](#hitbox2d) - 9. [wiMath](#wimath) - 10. [wiRandom](#wirandom) - 11. [wiRectPacker](#wirectpacker) - 12. [wiResourceManager](#wiresourcemanager) - 13. [wiSpinLock](#wispinlock) - 14. [wiStartupArguments](#wistartuparguments) - 15. [wiTimer](#witimer) + 8. [wiMath](#wimath) + 9. [wiRandom](#wirandom) + 10. [wiRectPacker](#wirectpacker) + 11. [wiResourceManager](#wiresourcemanager) + 12. [wiSpinLock](#wispinlock) + 13. [wiStartupArguments](#wistartuparguments) + 14. [wiTimer](#witimer) 6. [Input](#input) 7. [Audio](#audio) 1. [wiAudio](#wiaudio) @@ -893,10 +892,6 @@ This is a thread safe container that can hold elements of one certain data type [[Header]](../WickedEngine/wiFadeManager.h) [[Cpp]](../WickedEngine/wiFadeManager.cpp) Simple helper to manage a fadeout screen. Fadeout starts at transparent, then fades smoothly to an opaque color (such as black, in most cases), then a callback occurs which the user can handle with their own event. After that, the color will fade back to transperent. This is used by the [MainComponent](#maincomponent) to fade from one RenderPath to an other. -### wiHashString -[[Header]](../WickedEngine/wiHashString.h) -Stores a string and a number hash value. The string is supposed to be easily readable by a human, while the hash part is designed for easy comparison of values. If two wiHashString hash values are equal, the strings are equal as well. - ### wiHelper [[Header]](../WickedEngine/wiHelper.h) [[Cpp]](../WickedEngine/wiHelper.cpp) Many helper utility functions, like screenshot, readfile, messagebox, splitpath, sleep, etc... diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 5def632bd..e089923f3 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -42,6 +42,7 @@ void Editor::Initialize() infoDisplay.watermark = true; infoDisplay.fpsinfo = true; infoDisplay.resolution = true; + infoDisplay.heap_allocation_counter = true; wiRenderer::GetDevice()->SetVSyncEnabled(true); wiRenderer::SetOcclusionCullingEnabled(true); diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index 7744b224e..a502d7637 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -94,7 +94,7 @@ namespace tinygltf std::shared_ptr RegisterTexture(tinygltf::Image *image, const string& type_name) { // We will load the texture2d by hand here and register to the resource manager (if it was not already registered) - if (!wiResourceManager::Contains(wiHashString(image->uri))) + if (!wiResourceManager::Contains(image->uri)) { int width = image->width; int height = image->height; diff --git a/Tests/Tests.cpp b/Tests/Tests.cpp index c0e0709ff..54cba95d2 100644 --- a/Tests/Tests.cpp +++ b/Tests/Tests.cpp @@ -16,6 +16,7 @@ void Tests::Initialize() infoDisplay.watermark = true; infoDisplay.fpsinfo = true; infoDisplay.resolution = true; + infoDisplay.heap_allocation_counter = true; renderer.Load(); diff --git a/WickedEngine/CommonInclude.h b/WickedEngine/CommonInclude.h index c410b0bb2..2ba3250e2 100644 --- a/WickedEngine/CommonInclude.h +++ b/WickedEngine/CommonInclude.h @@ -16,4 +16,5 @@ static const XMFLOAT4X4 IDENTITYMATRIX = XMFLOAT4X4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0 #define NOMINMAX #define ALIGN_16 void* operator new(size_t i){return _mm_malloc(i, 16);} void operator delete(void* p){_mm_free(p);} + #endif //WICKEDENGINE_COMMONINCLUDE_H diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index b927e7059..c9668ba22 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -19,6 +19,8 @@ #include "wiGraphicsDevice_DX12.h" #include "wiGraphicsDevice_Vulkan.h" +#include "Utility/replace_new.h" + #include #include @@ -302,6 +304,11 @@ void MainComponent::Compose(CommandList cmd) ss.precision(2); ss << fixed << 1.0f / displaydeltatime << " FPS" << endl; } + if (infoDisplay.heap_allocation_counter) + { + ss << "Heap allocations per frame: " << number_of_allocs.load() << endl; + number_of_allocs.store(0); + } #ifdef _DEBUG ss << "Warning: This is a [DEBUG] build, performance will be slow!" << endl; diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h index ec58f8a0e..5fd8bf536 100644 --- a/WickedEngine/MainComponent.h +++ b/WickedEngine/MainComponent.h @@ -74,6 +74,8 @@ public: bool fpsinfo = false; // display resolution info bool resolution = false; + // display number of heap allocations per frame + bool heap_allocation_counter = false; // text size int size = 16; }; diff --git a/WickedEngine/Utility/replace_new.h b/WickedEngine/Utility/replace_new.h new file mode 100644 index 000000000..609ddf740 --- /dev/null +++ b/WickedEngine/Utility/replace_new.h @@ -0,0 +1,31 @@ +#pragma once +#include +#include +#include + +std::atomic number_of_allocs{ 0 }; + +void* operator new(std::size_t size) { + number_of_allocs.fetch_add(1); + void* p = malloc(size); + if (!p) throw std::bad_alloc(); + return p; +} +void* operator new[](std::size_t size) { + number_of_allocs.fetch_add(1); + void* p = malloc(size); + if (!p) throw std::bad_alloc(); + return p; +} +void* operator new[](std::size_t size, const std::nothrow_t&) throw() { + number_of_allocs.fetch_add(1); + return malloc(size); +} +void* operator new(std::size_t size, const std::nothrow_t&) throw() { + number_of_allocs.fetch_add(1); + return malloc(size); +} +void operator delete(void* ptr) throw() { free(ptr); } +void operator delete (void* ptr, const std::nothrow_t&) throw() { free(ptr); } +void operator delete[](void* ptr) throw() { free(ptr); } +void operator delete[](void* ptr, const std::nothrow_t&) throw() { free(ptr); } diff --git a/WickedEngine/WickedEngine.h b/WickedEngine/WickedEngine.h index 0a6fc85a5..ae0a5eb2f 100644 --- a/WickedEngine/WickedEngine.h +++ b/WickedEngine/WickedEngine.h @@ -50,7 +50,6 @@ #include "wiGraphicsDevice.h" #include "wiGUI.h" #include "wiWidget.h" -#include "wiHashString.h" #include "wiArchive.h" #include "wiSpinLock.h" #include "wiRectPacker.h" diff --git a/WickedEngine/WickedEngine_SOURCE.vcxitems b/WickedEngine/WickedEngine_SOURCE.vcxitems index eadc1f2a8..e53ad1ed3 100644 --- a/WickedEngine/WickedEngine_SOURCE.vcxitems +++ b/WickedEngine/WickedEngine_SOURCE.vcxitems @@ -257,6 +257,7 @@ + @@ -277,7 +278,6 @@ - diff --git a/WickedEngine/WickedEngine_SOURCE.vcxitems.filters b/WickedEngine/WickedEngine_SOURCE.vcxitems.filters index 3f2ae04ba..30c3705fe 100644 --- a/WickedEngine/WickedEngine_SOURCE.vcxitems.filters +++ b/WickedEngine/WickedEngine_SOURCE.vcxitems.filters @@ -864,9 +864,6 @@ ENGINE\Graphics - - ENGINE\Helpers - ENGINE\Helpers @@ -1128,6 +1125,9 @@ ENGINE\Graphics\GPUMapping + + UTILITY + diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index b163b1846..14debb524 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -3,6 +3,7 @@ #include "wiGraphicsDevice.h" #include "wiColor.h" +#include // Do not alter order because it is bound to lua manually enum wiFontAlign diff --git a/WickedEngine/wiGUI.cpp b/WickedEngine/wiGUI.cpp index fe5231c34..7096345b3 100644 --- a/WickedEngine/wiGUI.cpp +++ b/WickedEngine/wiGUI.cpp @@ -1,6 +1,5 @@ #include "wiGUI.h" #include "wiWidget.h" -#include "wiHashString.h" #include "wiRenderer.h" #include "wiInput.h" @@ -177,7 +176,7 @@ void wiGUI::RemoveWidget(wiWidget* widget) widgets.remove(widget); } -wiWidget* wiGUI::GetWidget(const wiHashString& name) +wiWidget* wiGUI::GetWidget(const std::string& name) { for (auto& x : widgets) { diff --git a/WickedEngine/wiGUI.h b/WickedEngine/wiGUI.h index e8d9567d9..b76cc9973 100644 --- a/WickedEngine/wiGUI.h +++ b/WickedEngine/wiGUI.h @@ -5,8 +5,6 @@ #include -class wiHashString; - class wiWidget; class wiGUIElement : public wiScene::TransformComponent @@ -40,7 +38,7 @@ public: void AddWidget(wiWidget* widget); void RemoveWidget(wiWidget* widget); - wiWidget* GetWidget(const wiHashString& name); + wiWidget* GetWidget(const std::string& name); void ActivateWidget(wiWidget* widget); void DeactivateWidget(wiWidget* widget); diff --git a/WickedEngine/wiGraphicsDevice.h b/WickedEngine/wiGraphicsDevice.h index cd56c2f46..5d5cd756e 100644 --- a/WickedEngine/wiGraphicsDevice.h +++ b/WickedEngine/wiGraphicsDevice.h @@ -2,7 +2,6 @@ #include "CommonInclude.h" #include "wiGraphics.h" -#include #include namespace wiGraphics @@ -46,7 +45,7 @@ namespace wiGraphics virtual bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) = 0; - virtual void SetName(GPUResource* pResource, const std::string& name) = 0; + virtual void SetName(GPUResource* pResource, const char* name) = 0; virtual void PresentBegin(CommandList cmd) = 0; virtual void PresentEnd(CommandList cmd) = 0; @@ -148,9 +147,9 @@ namespace wiGraphics // This allocation can be used to provide temporary vertex buffer, index buffer or raw buffer data to shaders virtual GPUAllocation AllocateGPU(size_t dataSize, CommandList cmd) = 0; - virtual void EventBegin(const std::string& name, CommandList cmd) = 0; + virtual void EventBegin(const char* name, CommandList cmd) = 0; virtual void EventEnd(CommandList cmd) = 0; - virtual void SetMarker(const std::string& name, CommandList cmd) = 0; + virtual void SetMarker(const char* name, CommandList cmd) = 0; }; } diff --git a/WickedEngine/wiGraphicsDevice_DX11.cpp b/WickedEngine/wiGraphicsDevice_DX11.cpp index 4ca233596..ee74a778a 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.cpp +++ b/WickedEngine/wiGraphicsDevice_DX11.cpp @@ -2342,10 +2342,10 @@ bool GraphicsDevice_DX11::DownloadResource(const GPUResource* resourceToDownload return false; } -void GraphicsDevice_DX11::SetName(GPUResource* pResource, const std::string& name) +void GraphicsDevice_DX11::SetName(GPUResource* pResource, const char* name) { auto internal_state = to_internal(pResource); - internal_state->resource->SetPrivateData(WKPDID_D3DDebugObjectName, (uint32_t)name.length(), name.c_str()); + internal_state->resource->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)strlen(name), name); } void GraphicsDevice_DX11::PresentBegin(CommandList cmd) @@ -3115,17 +3115,25 @@ GraphicsDevice::GPUAllocation GraphicsDevice_DX11::AllocateGPU(size_t dataSize, return result; } -void GraphicsDevice_DX11::EventBegin(const std::string& name, CommandList cmd) +void GraphicsDevice_DX11::EventBegin(const char* name, CommandList cmd) { - userDefinedAnnotations[cmd]->BeginEvent(std::wstring(name.begin(), name.end()).c_str()); + wchar_t text[128]; + if (wiHelper::StringConvert(name, text) > 0) + { + userDefinedAnnotations[cmd]->BeginEvent(text); + } } void GraphicsDevice_DX11::EventEnd(CommandList cmd) { userDefinedAnnotations[cmd]->EndEvent(); } -void GraphicsDevice_DX11::SetMarker(const std::string& name, CommandList cmd) +void GraphicsDevice_DX11::SetMarker(const char* name, CommandList cmd) { - userDefinedAnnotations[cmd]->SetMarker(std::wstring(name.begin(),name.end()).c_str()); + wchar_t text[128]; + if (wiHelper::StringConvert(name, text) > 0) + { + userDefinedAnnotations[cmd]->SetMarker(text); + } } } diff --git a/WickedEngine/wiGraphicsDevice_DX11.h b/WickedEngine/wiGraphicsDevice_DX11.h index 26107f077..616314b1a 100644 --- a/WickedEngine/wiGraphicsDevice_DX11.h +++ b/WickedEngine/wiGraphicsDevice_DX11.h @@ -87,7 +87,7 @@ namespace wiGraphics bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) override; - void SetName(GPUResource* pResource, const std::string& name) override; + void SetName(GPUResource* pResource, const char* name) override; void PresentBegin(CommandList cmd) override; void PresentEnd(CommandList cmd) override; @@ -139,9 +139,9 @@ namespace wiGraphics GPUAllocation AllocateGPU(size_t dataSize, CommandList cmd) override; - void EventBegin(const std::string& name, CommandList cmd) override; + void EventBegin(const char* name, CommandList cmd) override; void EventEnd(CommandList cmd) override; - void SetMarker(const std::string& name, CommandList cmd) override; + void SetMarker(const char* name, CommandList cmd) override; }; } diff --git a/WickedEngine/wiGraphicsDevice_DX12.cpp b/WickedEngine/wiGraphicsDevice_DX12.cpp index 5a5ed5a71..f725003cf 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.cpp +++ b/WickedEngine/wiGraphicsDevice_DX12.cpp @@ -2942,10 +2942,14 @@ using namespace DX12_Internal; return false; } - void GraphicsDevice_DX12::SetName(GPUResource* pResource, const std::string& name) + void GraphicsDevice_DX12::SetName(GPUResource* pResource, const char* name) { - auto internal_state = to_internal(pResource); - internal_state->resource->SetName(std::wstring(name.begin(), name.end()).c_str()); + wchar_t text[128]; + if (wiHelper::StringConvert(name, text) > 0) + { + auto internal_state = to_internal(pResource); + internal_state->resource->SetName(text); + } } @@ -4098,17 +4102,25 @@ using namespace DX12_Internal; return result; } - void GraphicsDevice_DX12::EventBegin(const std::string& name, CommandList cmd) + void GraphicsDevice_DX12::EventBegin(const char* name, CommandList cmd) { - PIXBeginEvent(GetDirectCommandList(cmd), 0xFF000000, std::wstring(name.begin(), name.end()).c_str()); + wchar_t text[128]; + if (wiHelper::StringConvert(name, text) > 0) + { + PIXBeginEvent(GetDirectCommandList(cmd), 0xFF000000, text); + } } void GraphicsDevice_DX12::EventEnd(CommandList cmd) { PIXEndEvent(GetDirectCommandList(cmd)); } - void GraphicsDevice_DX12::SetMarker(const std::string& name, CommandList cmd) + void GraphicsDevice_DX12::SetMarker(const char* name, CommandList cmd) { - PIXSetMarker(GetDirectCommandList(cmd), 0xFFFF0000, std::wstring(name.begin(), name.end()).c_str()); + wchar_t text[128]; + if (wiHelper::StringConvert(name, text) > 0) + { + PIXSetMarker(GetDirectCommandList(cmd), 0xFFFF0000, text); + } } diff --git a/WickedEngine/wiGraphicsDevice_DX12.h b/WickedEngine/wiGraphicsDevice_DX12.h index 01bf4bd6a..55745c22f 100644 --- a/WickedEngine/wiGraphicsDevice_DX12.h +++ b/WickedEngine/wiGraphicsDevice_DX12.h @@ -218,7 +218,7 @@ namespace wiGraphics bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) override; - void SetName(GPUResource* pResource, const std::string& name) override; + void SetName(GPUResource* pResource, const char* name) override; void PresentBegin(CommandList cmd) override; void PresentEnd(CommandList cmd) override; @@ -271,9 +271,9 @@ namespace wiGraphics GPUAllocation AllocateGPU(size_t dataSize, CommandList cmd) override; - void EventBegin(const std::string& name, CommandList cmd) override; + void EventBegin(const char* name, CommandList cmd) override; void EventEnd(CommandList cmd) override; - void SetMarker(const std::string& name, CommandList cmd) override; + void SetMarker(const char* name, CommandList cmd) override; struct AllocationHandler diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.cpp b/WickedEngine/wiGraphicsDevice_Vulkan.cpp index 789c7e787..457c01a9c 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.cpp +++ b/WickedEngine/wiGraphicsDevice_Vulkan.cpp @@ -3632,11 +3632,11 @@ using namespace Vulkan_Internal; return false; } - void GraphicsDevice_Vulkan::SetName(GPUResource* pResource, const std::string& name) + void GraphicsDevice_Vulkan::SetName(GPUResource* pResource, const char* name) { VkDebugUtilsObjectNameInfoEXT info = {}; info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; - info.pObjectName = name.c_str(); + info.pObjectName = name; if (pResource->IsTexture()) { info.objectType = VK_OBJECT_TYPE_IMAGE; @@ -4948,13 +4948,13 @@ using namespace Vulkan_Internal; return result; } - void GraphicsDevice_Vulkan::EventBegin(const std::string& name, CommandList cmd) + void GraphicsDevice_Vulkan::EventBegin(const char* name, CommandList cmd) { if (cmdBeginDebugUtilsLabelEXT != nullptr) { VkDebugUtilsLabelEXT label = {}; label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; - label.pLabelName = name.c_str(); + label.pLabelName = name; label.color[0] = 0; label.color[1] = 0; label.color[2] = 0; @@ -4969,13 +4969,13 @@ using namespace Vulkan_Internal; cmdEndDebugUtilsLabelEXT(GetDirectCommandList(cmd)); } } - void GraphicsDevice_Vulkan::SetMarker(const std::string& name, CommandList cmd) + void GraphicsDevice_Vulkan::SetMarker(const char* name, CommandList cmd) { if (cmdInsertDebugUtilsLabelEXT != nullptr) { VkDebugUtilsLabelEXT label = {}; label.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT; - label.pLabelName = name.c_str(); + label.pLabelName = name; label.color[0] = 0; label.color[1] = 0; label.color[2] = 0; diff --git a/WickedEngine/wiGraphicsDevice_Vulkan.h b/WickedEngine/wiGraphicsDevice_Vulkan.h index 1d32769f9..223c40f28 100644 --- a/WickedEngine/wiGraphicsDevice_Vulkan.h +++ b/WickedEngine/wiGraphicsDevice_Vulkan.h @@ -252,7 +252,7 @@ namespace wiGraphics bool DownloadResource(const GPUResource* resourceToDownload, const GPUResource* resourceDest, void* dataDest) override; - void SetName(GPUResource* pResource, const std::string& name) override; + void SetName(GPUResource* pResource, const char* name) override; void PresentBegin(CommandList cmd) override; void PresentEnd(CommandList cmd) override; @@ -305,9 +305,9 @@ namespace wiGraphics GPUAllocation AllocateGPU(size_t dataSize, CommandList cmd) override; - void EventBegin(const std::string& name, CommandList cmd) override; + void EventBegin(const char* name, CommandList cmd) override; void EventEnd(CommandList cmd) override; - void SetMarker(const std::string& name, CommandList cmd) override; + void SetMarker(const char* name, CommandList cmd) override; struct AllocationHandler diff --git a/WickedEngine/wiHashString.h b/WickedEngine/wiHashString.h deleted file mode 100644 index af0dbd54c..000000000 --- a/WickedEngine/wiHashString.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once -#include "CommonInclude.h" - -#include - -class wiHashString -{ -private: - std::string str; - size_t hash; -public: - wiHashString(const std::string& value = "") : str(value), hash(std::hash{}(value)) {} - wiHashString(const char* value) : wiHashString(std::string(value)) {} - - constexpr const std::string& GetString() const { return str; } - constexpr size_t GetHash() const { return hash; } -}; - -constexpr bool operator==(const wiHashString& a, const wiHashString& b) -{ - return a.GetHash() == b.GetHash(); -} - -namespace std -{ - template <> - struct hash - { - constexpr size_t operator()(const wiHashString& k) const - { - return k.GetHash(); - } - }; -} - diff --git a/WickedEngine/wiHelper.cpp b/WickedEngine/wiHelper.cpp index 9b6c37dbe..78a313f3a 100644 --- a/WickedEngine/wiHelper.cpp +++ b/WickedEngine/wiHelper.cpp @@ -433,6 +433,26 @@ namespace wiHelper WideCharToMultiByte(CP_UTF8, 0, from.c_str(), -1, &to[0], num, NULL, NULL); } } + + int StringConvert(const char* from, wchar_t* to) + { + int num = MultiByteToWideChar(CP_UTF8, 0, from, -1, NULL, 0); + if (num > 0) + { + MultiByteToWideChar(CP_UTF8, 0, from, -1, &to[0], num); + } + return num; + } + + int StringConvert(const wchar_t* from, char* to) + { + int num = WideCharToMultiByte(CP_UTF8, 0, from, -1, NULL, 0, NULL, NULL); + if (num > 0) + { + WideCharToMultiByte(CP_UTF8, 0, from, -1, &to[0], num, NULL, NULL); + } + return num; + } void Sleep(float milliseconds) { diff --git a/WickedEngine/wiHelper.h b/WickedEngine/wiHelper.h index ac534b9f6..ced5273af 100644 --- a/WickedEngine/wiHelper.h +++ b/WickedEngine/wiHelper.h @@ -14,6 +14,22 @@ namespace wiHelper seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } + constexpr size_t string_hash(const char* input) + { + // https://stackoverflow.com/questions/2111667/compile-time-string-hashing + size_t hash = sizeof(size_t) == 8 ? 0xcbf29ce484222325 : 0x811c9dc5; + const size_t prime = sizeof(size_t) == 8 ? 0x00000100000001b3 : 0x01000193; + + while (*input) + { + hash ^= static_cast(*input); + hash *= prime; + ++input; + } + + return hash; + } + std::string toUpper(const std::string& s); bool readByteData(const std::string& fileName, std::vector& data); @@ -73,6 +89,14 @@ namespace wiHelper void StringConvert(const std::wstring from, std::string& to); + // Parameter - to - must be pre-allocated! + // returns result string length + int StringConvert(const char* from, wchar_t* to); + + // Parameter - to - must be pre-allocated! + // returns result string length + int StringConvert(const wchar_t* from, char* to); + // Puts the current thread to sleeping state for a given time (OS can overtake) void Sleep(float milliseconds); diff --git a/WickedEngine/wiProfiler.cpp b/WickedEngine/wiProfiler.cpp index 761c75ac9..9112d87ac 100644 --- a/WickedEngine/wiProfiler.cpp +++ b/WickedEngine/wiProfiler.cpp @@ -5,6 +5,7 @@ #include "wiImage.h" #include "wiTimer.h" #include "wiTextureHelper.h" +#include "wiHelper.h" #include #include @@ -115,18 +116,18 @@ namespace wiProfiler } } - range_id BeginRangeCPU(const wiHashString& name) + range_id BeginRangeCPU(const char* name) { if (!ENABLED || !initialized) return 0; - range_id id = name.GetHash(); + range_id id = wiHelper::string_hash(name); lock.lock(); if (ranges.find(id) == ranges.end()) { Range range; - range.name = name.GetString(); + range.name = name; range.time = 0; range.cpuBegin.Start(); @@ -141,18 +142,18 @@ namespace wiProfiler return id; } - range_id BeginRangeGPU(const wiHashString& name, CommandList cmd) + range_id BeginRangeGPU(const char* name, CommandList cmd) { if (!ENABLED || !initialized) return 0; - range_id id = name.GetHash(); + range_id id = wiHelper::string_hash(name); lock.lock(); if (ranges.find(id) == ranges.end()) { Range range; - range.name = name.GetString(); + range.name = name; range.time = 0; GPUQueryDesc desc; diff --git a/WickedEngine/wiProfiler.h b/WickedEngine/wiProfiler.h index 79412edf2..96c0de037 100644 --- a/WickedEngine/wiProfiler.h +++ b/WickedEngine/wiProfiler.h @@ -1,6 +1,5 @@ #pragma once #include "wiGraphicsDevice.h" -#include "wiHashString.h" #include @@ -15,10 +14,10 @@ namespace wiProfiler void EndFrame(wiGraphics::CommandList cmd); // Start a CPU profiling range - range_id BeginRangeCPU(const wiHashString& name); + range_id BeginRangeCPU(const char* name); // Start a GPU profiling range - range_id BeginRangeGPU(const wiHashString& name, wiGraphics::CommandList cmd); + range_id BeginRangeGPU(const char* name, wiGraphics::CommandList cmd); // End a profiling range void EndRange(range_id id); diff --git a/WickedEngine/wiResourceManager.cpp b/WickedEngine/wiResourceManager.cpp index 6bad08134..49d80dd64 100644 --- a/WickedEngine/wiResourceManager.cpp +++ b/WickedEngine/wiResourceManager.cpp @@ -29,7 +29,7 @@ wiResource::~wiResource() namespace wiResourceManager { std::mutex locker; - std::unordered_map> resources; + std::unordered_map> resources; static const std::unordered_map types = { std::make_pair("JPG", wiResource::IMAGE), @@ -39,7 +39,7 @@ namespace wiResourceManager std::make_pair("WAV", wiResource::SOUND) }; - std::shared_ptr Load(const wiHashString& name) + std::shared_ptr Load(const std::string& name) { locker.lock(); std::weak_ptr& weak_resource = resources[name]; @@ -58,8 +58,7 @@ namespace wiResourceManager } - std::string nameStr = name.GetString(); - std::string ext = wiHelper::toUpper(nameStr.substr(nameStr.length() - 3, nameStr.length())); + std::string ext = wiHelper::toUpper(name.substr(name.length() - 3, name.length())); wiResource::DATA_TYPE type; // dynamic type selection: @@ -86,7 +85,7 @@ namespace wiResourceManager // Load dds tinyddsloader::DDSFile dds; - auto result = dds.Load(nameStr.c_str()); + auto result = dds.Load(name.c_str()); if (result == tinyddsloader::Result::Success) { @@ -215,7 +214,7 @@ namespace wiResourceManager Texture* image = new Texture; wiRenderer::GetDevice()->CreateTexture(&desc, InitData.data(), image); - wiRenderer::GetDevice()->SetName(image, nameStr); + wiRenderer::GetDevice()->SetName(image, name.c_str()); success = image; } else assert(0); // failed to load DDS @@ -227,7 +226,7 @@ namespace wiResourceManager const int channelCount = 4; int width, height, bpp; - unsigned char* rgb = stbi_load(nameStr.c_str(), &width, &height, &bpp, channelCount); + unsigned char* rgb = stbi_load(name.c_str(), &width, &height, &bpp, channelCount); if (rgb != nullptr) { @@ -255,7 +254,7 @@ namespace wiResourceManager Texture* image = new Texture; device->CreateTexture(&desc, InitData.data(), image); - device->SetName(image, nameStr); + device->SetName(image, name.c_str()); for (uint32_t i = 0; i < image->GetDesc().MipLevels; ++i) { @@ -276,7 +275,7 @@ namespace wiResourceManager case wiResource::SOUND: { wiAudio::Sound* sound = new wiAudio::Sound; - if (wiAudio::CreateSound(name.GetString(), sound)) + if (wiAudio::CreateSound(name, sound)) { success = sound; } @@ -300,7 +299,7 @@ namespace wiResourceManager return nullptr; } - bool Contains(const wiHashString& name) + bool Contains(const std::string& name) { bool result = false; locker.lock(); @@ -314,7 +313,7 @@ namespace wiResourceManager return result; } - std::shared_ptr Register(const wiHashString& name, void* data, wiResource::DATA_TYPE data_type) + std::shared_ptr Register(const std::string& name, void* data, wiResource::DATA_TYPE data_type) { std::shared_ptr resource; diff --git a/WickedEngine/wiResourceManager.h b/WickedEngine/wiResourceManager.h index 6ec50324e..3c5a7e0c0 100644 --- a/WickedEngine/wiResourceManager.h +++ b/WickedEngine/wiResourceManager.h @@ -2,7 +2,6 @@ #include "CommonInclude.h" #include "wiGraphicsDevice.h" #include "wiAudio.h" -#include "wiHashString.h" #include #include @@ -30,11 +29,11 @@ struct wiResource namespace wiResourceManager { // Load a resource - std::shared_ptr Load(const wiHashString& name); + std::shared_ptr Load(const std::string& name); // Check if a resource is currently loaded - bool Contains(const wiHashString& name); + bool Contains(const std::string& name); // Register a pre-created resource - std::shared_ptr Register(const wiHashString& name, void* data, wiResource::DATA_TYPE data_type); + std::shared_ptr Register(const std::string& name, void* data, wiResource::DATA_TYPE data_type); // Invalidate all resources void Clear(); }; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 3afb7faf7..93b5035db 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 39; // minor bug fixes, alterations, refactors, updates - const int revision = 78; + const int revision = 79; long GetVersion() diff --git a/WickedEngine/wiWidget.cpp b/WickedEngine/wiWidget.cpp index e1da98594..b99581559 100644 --- a/WickedEngine/wiWidget.cpp +++ b/WickedEngine/wiWidget.cpp @@ -129,9 +129,9 @@ void wiWidget::RenderTooltip(const wiGUI* gui, CommandList cmd) const } } } -const wiHashString& wiWidget::GetName() const +const std::string& wiWidget::GetName() const { - return fastName; + return name; } void wiWidget::SetName(const std::string& value) { @@ -140,11 +140,11 @@ void wiWidget::SetName(const std::string& value) static unsigned long widgetID = 0; stringstream ss(""); ss << "widget_" << widgetID++; - fastName = wiHashString(ss.str()); + name = ss.str(); } else { - fastName = wiHashString(value); + name = value; } } @@ -253,7 +253,7 @@ void wiWidget::LoadShaders() wiButton::wiButton(const std::string& name) :wiWidget() { SetName(name); - SetText(fastName.GetString()); + SetText(name); OnClick([](wiEventArgs args) {}); OnDragStart([](wiEventArgs args) {}); OnDrag([](wiEventArgs args) {}); @@ -420,7 +420,7 @@ void wiButton::OnDragEnd(function func) wiLabel::wiLabel(const std::string& name) { SetName(name); - SetText(fastName.GetString()); + SetText(name); SetSize(XMFLOAT2(100, 20)); } wiLabel::~wiLabel() @@ -464,7 +464,7 @@ wiFont wiTextInputField::font_input; wiTextInputField::wiTextInputField(const std::string& name) { SetName(name); - SetText(fastName.GetString()); + SetText(name); OnInputAccepted([](wiEventArgs args) {}); SetSize(XMFLOAT2(100, 30)); @@ -647,7 +647,7 @@ void wiTextInputField::DeleteFromInput() wiSlider::wiSlider(float start, float end, float defaultValue, float step, const std::string& name) : start(start), end(end), value(defaultValue), step(std::max(step, 1.0f)) { SetName(name); - SetText(fastName.GetString()); + SetText(name); OnSlide([](wiEventArgs args) {}); SetSize(XMFLOAT2(200, 40)); @@ -851,7 +851,7 @@ void wiSlider::OnSlide(function func) wiCheckBox::wiCheckBox(const std::string& name) { SetName(name); - SetText(fastName.GetString()); + SetText(name); OnClick([](wiEventArgs args) {}); SetSize(XMFLOAT2(20, 20)); @@ -983,7 +983,7 @@ bool wiCheckBox::GetCheck() const wiComboBox::wiComboBox(const std::string& name) { SetName(name); - SetText(fastName.GetString()); + SetText(name); OnSelect([](wiEventArgs args) {}); SetSize(XMFLOAT2(100, 20)); @@ -1378,7 +1378,7 @@ wiWindow::wiWindow(wiGUI* gui, const std::string& name, bool window_controls) : SetColor(wiColor::Ghost()); SetName(name); - SetText(fastName.GetString()); + SetText(name); SetSize(XMFLOAT2(640, 480)); for (int i = IDLE + 1; i < WIDGETSTATE_COUNT; ++i) @@ -2490,7 +2490,7 @@ static const float tree_scrollbar_width = 12; wiTreeList::wiTreeList(const std::string& name) { SetName(name); - SetText(fastName.GetString()); + SetText(name); OnSelect([](wiEventArgs args) {}); SetSize(XMFLOAT2(100, 20)); diff --git a/WickedEngine/wiWidget.h b/WickedEngine/wiWidget.h index ec973f65a..a015e2e9f 100644 --- a/WickedEngine/wiWidget.h +++ b/WickedEngine/wiWidget.h @@ -1,7 +1,6 @@ #pragma once #include "CommonInclude.h" #include "wiGUI.h" -#include "wiHashString.h" #include "wiColor.h" #include "wiGraphicsDevice.h" #include "wiIntersect.h" @@ -42,7 +41,7 @@ public: private: int tooltipTimer = 0; protected: - wiHashString fastName; + std::string name; std::string tooltip; std::string scriptTip; bool enabled = true; @@ -56,7 +55,7 @@ protected: public: wiWidget(); - const wiHashString& GetName() const; + const std::string& GetName() const; void SetName(const std::string& value); const std::string GetText() const; void SetText(const std::string& value);