diff --git a/src/assetcompile.ps1 b/src/assetcompile.ps1 index 40d4019..7938228 100644 --- a/src/assetcompile.ps1 +++ b/src/assetcompile.ps1 @@ -1,5 +1,5 @@ -$texturecPath = ".\cmake-build\texturec.exe" +$texturecPath = "..\tools\texturec.exe" $textureAssetDir = "..\assets\textures" $outputBaseDir = ".\textures" diff --git a/src/game/Global.cpp b/src/game/Global.cpp index 6c5e999..f7b4609 100644 --- a/src/game/Global.cpp +++ b/src/game/Global.cpp @@ -58,10 +58,8 @@ namespace Game LOG_ERROR("Can't resize to more than previous size!"); return false; } - LOG("Resizing last allocation from %llu to %llu", arena.LastAllocSize, newByteCount); arena.Used -= arena.LastAllocSize; arena.Used += newByteCount; - LOG("New total: %llu", arena.Used); return true; } diff --git a/src/game/Instance.h b/src/game/Instance.h index b358cbf..2b0c657 100644 --- a/src/game/Instance.h +++ b/src/game/Instance.h @@ -69,6 +69,7 @@ namespace Game uint8_t DebugCardRotation = 0; bool ShortenLogFileNames = true; bool ShowStats = true; + bool ShowArenaUsage = false; }; struct GameInstance diff --git a/src/game/Tools.cpp b/src/game/Tools.cpp index fb89c01..d283698 100644 --- a/src/game/Tools.cpp +++ b/src/game/Tools.cpp @@ -8,6 +8,7 @@ #include "Tools.h" #include "bx/filepath.h" +#include "bx/string.h" #include "bx/timer.h" #include #include @@ -121,6 +122,50 @@ namespace Tools return changed; } + constexpr const char* UnitStrings[]{ + "b", + "kb", + "mb", + "gb", + }; + const char* GetUnitString(uint64_t byteCount, uint64_t& outCount) + { + outCount = byteCount; + int32_t strIdx = 0; + for (int32_t i = 0; i < BX_COUNTOF(UnitStrings); ++i) + { + if (outCount < 1024) break; + ++strIdx; + outCount /= 1024; + } + return UnitStrings[strIdx]; + } + + void ProgressBar(const char* title, uint64_t current, uint64_t max) + { + ImGui::PushID(title); + float percent = static_cast(current) / static_cast(max); + ImVec2 startPos = ImGui::GetCursorScreenPos(); + char content[128]{0}; + + uint64_t currentUnit = 0; + const char* currentUnitStr = GetUnitString(current, currentUnit); + uint64_t maxUnit = 0; + const char* maxUnitStr = GetUnitString(max, maxUnit); + + bx::snprintf(content, + sizeof(content), + "%s: %u %s/%u %s (%.2f%%)", + title, + currentUnit, + currentUnitStr, + maxUnit, + maxUnitStr, + percent); + ImGui::Text("%s", content); + ImGui::PopID(); + } + bool TransformUI(Gen::Transform& transform) { bool changed = false; @@ -420,6 +465,23 @@ namespace Tools } } ImGui::End(); + if (ImGui::Begin("Debug")) + { + ImGui::Checkbox("Arenas", &debug.ShowArenaUsage); + ImGui::Checkbox("ImGui Demo", &debug.ShowImguiDemo); + } + ImGui::End(); + + if (debug.ShowArenaUsage) + { + if (ImGui::Begin("Arenas", &debug.ShowArenaUsage)) + { + ProgressBar("Permanent", shared.Game.PermanentArena.Used, shared.Game.PermanentArena.MaxSize); + ProgressBar("Entity", shared.Game.EntityArena.Used, shared.Game.EntityArena.MaxSize); + ProgressBar("Transient", shared.Game.TransientArena.Used, shared.Game.TransientArena.MaxSize); + } + ImGui::End(); + } } if (debug.ShowStats) { diff --git a/src/game/rendering/Rendering.cpp b/src/game/rendering/Rendering.cpp index 38b1b5a..0dc722f 100644 --- a/src/game/rendering/Rendering.cpp +++ b/src/game/rendering/Rendering.cpp @@ -235,8 +235,18 @@ namespace Game *_orientation = imageContainer.m_orientation; } - const bgfx::Memory* mem = - bgfx::makeRef(data->data + imageContainer.m_offset, data->size - imageContainer.m_offset); + // We're working with ktx textures, so the size should be in front of the actual data + const uint32_t* texSizePtr = reinterpret_cast(data->data + imageContainer.m_offset); + uint8_t* dataPtr = data->data + imageContainer.m_offset + sizeof(uint32_t); + uint32_t dataSize = data->size - imageContainer.m_offset - sizeof(uint32_t); + + // Extra sanity check + if (*texSizePtr != dataSize) + { + LOG_WARN("Texture size sanity check failed! %u != %u", texSizePtr, dataSize); + return handle; + } + const bgfx::Memory* mem = bgfx::makeRef(dataPtr, dataSize); if (NULL != _info) {