Improve memory safety + fix high disk usage.

This commit is contained in:
2025-01-17 22:53:13 -05:00
parent 79958d395d
commit ac54243e4f
5 changed files with 20 additions and 27 deletions

View File

@@ -301,17 +301,17 @@ namespace CaveGame::Client {
//void LocalWorld::LookForChunksNeedLoading()
void LocalWorld::LookForChunksNeedLoading()
{
// TODO: Make sure an extra layer of chunks beyond the viewport is generated.
// This will limit the amount of "pop-in" the player will notice.
// TODO If you want to load chunks the player cannot see, Update the "LookForChunksNeedUnloading" function to use the same bounds.
// The chunks just outside the visible area would be written to the disk and reloaded every time the loop went around - Redacted.
Vector2 viewport_topleft = camera.ScaledViewport().minPoint;
Vector2 viewport_bottomright = camera.ScaledViewport().maxPoint;
int lower_bound_h = Math::Floor(viewport_topleft.x / Core::Chunk::ChunkSize)-2;
int upper_bound_h = Math::Floor(viewport_bottomright.x / Core::Chunk::ChunkSize)+2;
int lower_bound_h = Math::Floor(viewport_topleft.x / Core::Chunk::ChunkSize)/*-2*/;
int upper_bound_h = Math::Floor(viewport_bottomright.x / Core::Chunk::ChunkSize)/*+2*/;
int lower_bound_v = Math::Floor(viewport_topleft.y / Core::Chunk::ChunkSize)-2;
int upper_bound_v = Math::Floor(viewport_bottomright.y / Core::Chunk::ChunkSize)+2;
int lower_bound_v = Math::Floor(viewport_topleft.y / Core::Chunk::ChunkSize)/*-2*/;
int upper_bound_v = Math::Floor(viewport_bottomright.y / Core::Chunk::ChunkSize)/*+2*/;
for (int x = lower_bound_h; x <= upper_bound_h; x++)
{

View File

@@ -126,8 +126,8 @@ void CaveGame::Client::Splash::Update(float elapsed)
}
void CaveGame::Client::Splash::Load() {
column_textures.fill(nullptr);
splash = new JGL::Texture("assets/textures/redacted.png");
ComputeMatrixTextureCache();
Scene::Load();
@@ -135,10 +135,11 @@ void CaveGame::Client::Splash::Load() {
}
void CaveGame::Client::Splash::Unload() {
for (auto* r : column_textures)
for (auto& r : column_textures)
delete r;
delete splash;
column_textures.fill(nullptr);
Scene::Unload();
}

View File

@@ -24,8 +24,8 @@ int main(int argc, char** argv) {
JGL::Logger::Warning.EnableConsole(false);
JGL::Logger::Debug.EnableConsole(false);
ReWindow::Logger::Debug.EnableConsole(false);
ReWindow::Logger::Debug.EnableFile(false);
ReWindow::Logger::Debug.EnableConsole(true);
ReWindow::Logger::Debug.EnableFile(true);
CaveGame::Logs::Info.IncludeLocation(false);
CaveGame::Logs::Info("Starting client program.");

View File

@@ -26,7 +26,8 @@ namespace CaveGame::ClientApp
delete wm;
Logs::Info("Closing game window.");
RWindow::~RWindow();
// The base destructor will get called automatically - Redacted.
//RWindow::~RWindow();
}
void CaveGameWindow::CreateContexts()

View File

@@ -296,30 +296,21 @@ namespace CaveGame::Core
void World::ChunkServerThread() {
while (run_chunk_thread)
{
// TODO sleep the thread if requestedchunks is empty and wake it when pushing something into requestedchunks if it was empty.
// Will cut down on needless busywaiting - Redacted.
while (!RequestedChunks.empty())
{
Vector2 cell;
RequestedChunks.front_pop(cell);
if (HasChunkOnFile(cell)) {
//std::thread([&]() {
ServedChunks.push(new Core::Chunk(cell, GetChunkFullPath(cell)));
//}).detach();
} else {
//std::thread( [&]() {
Core::Chunk* chunk = new Chunk(cell);
generator.FirstPass(chunk);
//SaveChunkToFile(cell, chunk);
ServedChunks.push(chunk);
//}).detach();
ServedChunks.push(new Core::Chunk(cell, GetChunkFullPath(cell)));
continue;
}
//generator.FirstPass()
//std::this_thread::sleep_for(100ms);
auto* chunk = new Chunk(cell);
generator.FirstPass(chunk);
ServedChunks.push(chunk);
}
//std::this_thread::sleep_for(250ns);
}
}