added heap allocation counter; reduced string allocations;
This commit is contained in:
@@ -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...
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace tinygltf
|
||||
std::shared_ptr<wiResource> 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;
|
||||
|
||||
@@ -16,6 +16,7 @@ void Tests::Initialize()
|
||||
infoDisplay.watermark = true;
|
||||
infoDisplay.fpsinfo = true;
|
||||
infoDisplay.resolution = true;
|
||||
infoDisplay.heap_allocation_counter = true;
|
||||
|
||||
renderer.Load();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include "wiGraphicsDevice_DX12.h"
|
||||
#include "wiGraphicsDevice_Vulkan.h"
|
||||
|
||||
#include "Utility/replace_new.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <new>
|
||||
#include <cstdlib>
|
||||
#include <atomic>
|
||||
|
||||
std::atomic<uint32_t> 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); }
|
||||
@@ -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"
|
||||
|
||||
@@ -257,6 +257,7 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)RenderPath3D_TiledForward_BindLua.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\D3D12MemAlloc.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\d3dx12.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\replace_new.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\stb_image.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\stb_image_write.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\stb_truetype.h" />
|
||||
@@ -277,7 +278,6 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiInput.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiInput_BindLua.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiIntersect.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiHashString.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)LoadingScreen.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)LoadingScreen_BindLua.h" />
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)LUA\lapi.h" />
|
||||
|
||||
@@ -864,9 +864,6 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiEnums.h">
|
||||
<Filter>ENGINE\Graphics</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiHashString.h">
|
||||
<Filter>ENGINE\Helpers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)wiColor.h">
|
||||
<Filter>ENGINE\Helpers</Filter>
|
||||
</ClInclude>
|
||||
@@ -1128,6 +1125,9 @@
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)ShaderInterop_Paint.h">
|
||||
<Filter>ENGINE\Graphics\GPUMapping</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="$(MSBuildThisFileDirectory)Utility\replace_new.h">
|
||||
<Filter>UTILITY</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(MSBuildThisFileDirectory)LUA\lapi.c">
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "wiGraphicsDevice.h"
|
||||
#include "wiColor.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
// Do not alter order because it is bound to lua manually
|
||||
enum wiFontAlign
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
|
||||
#include <list>
|
||||
|
||||
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);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "CommonInclude.h"
|
||||
#include "wiGraphics.h"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
#include "CommonInclude.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
class wiHashString
|
||||
{
|
||||
private:
|
||||
std::string str;
|
||||
size_t hash;
|
||||
public:
|
||||
wiHashString(const std::string& value = "") : str(value), hash(std::hash<std::string>{}(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<wiHashString>
|
||||
{
|
||||
constexpr size_t operator()(const wiHashString& k) const
|
||||
{
|
||||
return k.GetHash();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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<size_t>(*input);
|
||||
hash *= prime;
|
||||
++input;
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
std::string toUpper(const std::string& s);
|
||||
|
||||
bool readByteData(const std::string& fileName, std::vector<uint8_t>& 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);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "wiImage.h"
|
||||
#include "wiTimer.h"
|
||||
#include "wiTextureHelper.h"
|
||||
#include "wiHelper.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include "wiGraphicsDevice.h"
|
||||
#include "wiHashString.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -29,7 +29,7 @@ wiResource::~wiResource()
|
||||
namespace wiResourceManager
|
||||
{
|
||||
std::mutex locker;
|
||||
std::unordered_map<wiHashString, std::weak_ptr<wiResource>> resources;
|
||||
std::unordered_map<std::string, std::weak_ptr<wiResource>> resources;
|
||||
|
||||
static const std::unordered_map<std::string, wiResource::DATA_TYPE> types = {
|
||||
std::make_pair("JPG", wiResource::IMAGE),
|
||||
@@ -39,7 +39,7 @@ namespace wiResourceManager
|
||||
std::make_pair("WAV", wiResource::SOUND)
|
||||
};
|
||||
|
||||
std::shared_ptr<wiResource> Load(const wiHashString& name)
|
||||
std::shared_ptr<wiResource> Load(const std::string& name)
|
||||
{
|
||||
locker.lock();
|
||||
std::weak_ptr<wiResource>& 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<wiResource> Register(const wiHashString& name, void* data, wiResource::DATA_TYPE data_type)
|
||||
std::shared_ptr<wiResource> Register(const std::string& name, void* data, wiResource::DATA_TYPE data_type)
|
||||
{
|
||||
std::shared_ptr<wiResource> resource;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "CommonInclude.h"
|
||||
#include "wiGraphicsDevice.h"
|
||||
#include "wiAudio.h"
|
||||
#include "wiHashString.h"
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
@@ -30,11 +29,11 @@ struct wiResource
|
||||
namespace wiResourceManager
|
||||
{
|
||||
// Load a resource
|
||||
std::shared_ptr<wiResource> Load(const wiHashString& name);
|
||||
std::shared_ptr<wiResource> 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<wiResource> Register(const wiHashString& name, void* data, wiResource::DATA_TYPE data_type);
|
||||
std::shared_ptr<wiResource> Register(const std::string& name, void* data, wiResource::DATA_TYPE data_type);
|
||||
// Invalidate all resources
|
||||
void Clear();
|
||||
};
|
||||
|
||||
@@ -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()
|
||||
|
||||
+12
-12
@@ -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<void(wiEventArgs args)> 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<void(wiEventArgs args)> 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));
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user