diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2025-01-31 01:02:33 -0600 |
|---|---|---|
| committer | KiritoDv <kiritodev01@gmail.com> | 2025-01-31 01:02:33 -0600 |
| commit | 01afbc67b7e8357a3e9ed5f2c70b7565d6dddb7e (patch) | |
| tree | 6ff27be75c82b3ef72d42a29f5936bc2a02c013b /src/port/Engine.cpp | |
| parent | 820da896e350b4e25a6fa6ea833e0ac4281a54cc (diff) | |
Fixed audio decompression, -100 mental points for Lywx
Diffstat (limited to 'src/port/Engine.cpp')
| -rw-r--r-- | src/port/Engine.cpp | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 1b7099a9..27c7fb1e 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -55,8 +55,8 @@ bool gEnableGammaBoost = true; void AudioThread_CreateNextAudioBuffer(int16_t* samples, uint32_t num_samples); } +std::vector<uint8_t*> MemoryPool; GameEngine* GameEngine::Instance; -static GamePool MemoryPool = { .chunk = 1024 * 512, .cursor = 0, .length = 0, .memory = nullptr }; GameEngine::GameEngine() { std::vector<std::string> archiveFiles; @@ -284,7 +284,10 @@ void GameEngine::Create() { void GameEngine::Destroy() { PortEnhancements_Exit(); AudioExit(); - free(MemoryPool.memory); + for (auto ptr : MemoryPool) { + free(ptr); + } + MemoryPool.clear(); } void GameEngine::StartFrame() const { @@ -749,27 +752,16 @@ extern "C" int32_t OTRConvertHUDXToScreenX(int32_t v) { } extern "C" void* GameEngine_Malloc(size_t size) { - // This is really wrong - return malloc(size); - // TODO: Kenix please take a look at this, i think it works but you are better at this - - const auto chunk = MemoryPool.chunk; - - if (size == 0) { - return nullptr; - } + MemoryPool.push_back(new uint8_t[size]); + return (void*) MemoryPool.back(); +} - if (MemoryPool.cursor + size < MemoryPool.length) { - const auto res = static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.cursor; - MemoryPool.cursor += size; - // SPDLOG_INFO("Allocating {} into memory pool", size); - return res; +extern "C" void GameEngine_Free(void* ptr) { + for (auto it = MemoryPool.begin(); it != MemoryPool.end(); ++it) { + if (*it == ptr) { + free(ptr); + MemoryPool.erase(it); + break; + } } - - MemoryPool.length += chunk; - MemoryPool.memory = - MemoryPool.memory == nullptr ? malloc(MemoryPool.length) : realloc(MemoryPool.memory, MemoryPool.length); - memset(static_cast<uint8_t*>(MemoryPool.memory) + MemoryPool.length, 0, MemoryPool.length - chunk); - SPDLOG_INFO("Memory pool resized from {} to {}", MemoryPool.length - chunk, MemoryPool.length); - return GameEngine_Malloc(size); }
\ No newline at end of file |
