diff options
-rw-r--r-- | main.cpp | 69 | ||||
-rw-r--r-- | src/render.cpp | 6 | ||||
-rw-r--r-- | src/world.cpp | 2 |
3 files changed, 75 insertions, 2 deletions
@@ -193,3 +193,72 @@ int main(int argc, char *argv[]) return 0; // Calls everything passed to atexit } + +constexpr int memEntries = 2048; + +static void* mems[memEntries]; +static std::size_t sizs[memEntries]; + +int balance = 0; + +std::size_t getUsedMem(void) +{ + std::size_t total = 0; + for (int i = 0; i < memEntries; i++) + total += sizs[i]; + + return total; +} + +void *operator new(std::size_t n) throw (std::bad_alloc) +{ + auto buf = std::malloc(n); + balance++; + + if (buf == nullptr) + throw std::bad_alloc(); + + for (int i = 0; i < memEntries; i++) { + if (mems[i] == nullptr) { + mems[i] = buf; + sizs[i] = n; + break; + } + } + + return buf; +} + +void operator delete(void* p) throw () +{ + if (p != nullptr) { + std::free(p); + balance--; + + for (int i = 0; i < memEntries; i++) { + if (mems[i] == p) { + mems[i] = nullptr; + sizs[i] = 0; + break; + } + } + } +} + +void operator delete(void* p, std::size_t n) throw () +{ + (void)n; + + if (p != nullptr) { + std::free(p); + balance--; + + for (int i = 0; i < memEntries; i++) { + if (mems[i] == p) { + mems[i] = nullptr; + sizs[i] = 0; + break; + } + } + } +} diff --git a/src/render.cpp b/src/render.cpp index 8c2f50d..8b99847 100644 --- a/src/render.cpp +++ b/src/render.cpp @@ -171,6 +171,8 @@ void preRender(void) Render::textShader.unuse(); } +extern std::size_t getUsedMem(void); +extern int balance; void render(const int& fps) { preRender(); @@ -187,10 +189,10 @@ void render(const int& fps) if (ui::debug) { auto pos = game::engine.getSystem<PlayerSystem>()->getPosition(); UISystem::putText(vec2(offset.x - game::SCREEN_WIDTH / 2, (offset.y + game::SCREEN_HEIGHT / 2) - FontSystem::getSize()), - "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s", + "loc: %s\noffset: %s\nfps: %d\nticks: %d\npcount: %d\nxml: %s\nmem: %llukb (%d)", pos.toString().c_str(), offset.toString().c_str(), fps, game::time::getTickCount(), game::engine.getSystem<ParticleSystem>()->getCount(), - WorldSystem::getXMLFile().c_str() + WorldSystem::getXMLFile().c_str(), getUsedMem() / 1024, balance ); } diff --git a/src/world.cpp b/src/world.cpp index e251706..e87d6d0 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -700,6 +700,8 @@ void WorldSystem::render(void) glDrawArrays(GL_TRIANGLES, 0, stars.size() * 6); } + delete[] star_coord; + Render::worldShader.disable(); glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0); |