Cleanup LocalWorld

This commit is contained in:
2025-03-31 16:36:21 -04:00
parent d55a64163b
commit 0d7306b9ae
2 changed files with 42 additions and 64 deletions

View File

@@ -86,14 +86,9 @@ namespace CaveGame::Client
};
/// An extension of the world object that provides rendering for the game world.
class LocalWorld : public CaveGame::Core::World
{
class LocalWorld : public CaveGame::Core::World {
public:
Camera2D camera;
Vector2 mouse_pos;
ChunkDebugGizmo chunk_debug;
public:
JGL::Font font;
LocalWorld(const std::string& world_name, int seed, bool overwrite);
void PostInit();
void Draw();
@@ -103,27 +98,38 @@ namespace CaveGame::Client
unsigned int GetRenderTargetCount() const;
void SaveAndExit() override
{
World::SaveAndExit();
void SaveAndExit() override;
}
void SetShowTileActivity(bool enabled);
void SetShowTileActivity(bool enabled)
{
show_tile_activity = enabled;
}
bool IsShowTileActivityEnabled() const { return show_tile_activity;}
bool IsShowTileActivityEnabled() const;
void RenderTile(const Core::TileID &tid, int wx, int wy, int tx, int ty);
//Camera2D* Camera() { return &camera;}
void Emit(const Particle& p)
{
particles.push_back(p);
}
void Emit(const Particle& p);
protected:
/// Determines whether a given chunk coordinate lies within the viewable space, with an optional 'oversize' parameter.
/// @param extraChunkRadius Specifies how many extra chunks can be considered within the viewport when they are in fact, just outside of the viewport.
/// @note This is used to overdraw
bool IsChunkCellWithinViewport(const Vector2i& coords, int extraChunkRadius = 0) const;
void RenderChunk(const Vector2i& coords);
void LookForChunksNeedLoading();
void LookForChunksNeedUnloading();
void RenderChunkTexture(const Vector2i &coords, JGL::RenderTarget* destination, Core::Chunk* chunk);
/// Checks for missing, or out-of-date, cached sprites of chunks, and renders them.
void CheckCachedChunkSprites();
static Color4 GetSkyColorInterpolatedForTimeOfDay(float time);
static Color4 GetSkyColorBaseForTimeOfDay(float time);
void DrawSky();
public:
Camera2D camera;
Vector2 mouse_pos;
ChunkDebugGizmo chunk_debug;
JGL::Font font;
protected:
float check_chunks_timer = 0.f;
@@ -134,28 +140,7 @@ namespace CaveGame::Client
std::vector<Particle> particles;
/// Determines whether a given chunk coordinate lies within the viewable space, with an optional 'oversize' parameter.
/// @param extraChunkRadius Specifies how many extra chunks can be considered within the viewport when they are in fact, just outside of the viewport.
/// @note This is used to overdraw
bool IsChunkCellWithinViewport(const Vector2i& coords, int extraChunkRadius = 0) const;
void RenderChunk(const Vector2i& coords);
void LookForChunksNeedLoading();
void LookForChunksNeedUnloading();
void RenderChunkTexture(const Vector2i &coords, JGL::RenderTarget* destination, Core::Chunk* chunk);
/// Render chunk boundaries and relative coordinates, around the camera.
void DrawChunkGrid() const;
/// Checks for missing, or out-of-date, cached sprites of chunks, and renders them.
void CheckCachedChunkSprites();
static Color4 GetSkyColorInterpolatedForTimeOfDay(float time);
static Color4 GetSkyColorBaseForTimeOfDay(float time);
void DrawSky();
bool show_tile_activity = false;
};

View File

@@ -22,29 +22,7 @@ namespace CaveGame::Client {
//font = JGL::Font("assets/fonts/Jupiteroid.ttf");
}
void LocalWorld::DrawChunkGrid() const {
/*Vector2 viewport_topleft = camera.ScaledViewport().minPoint;
Vector2 viewport_bottomright = camera.ScaledViewport().maxPoint;
int nearest_grid_left = Math::Floor(viewport_topleft.x / Core::Chunk::ChunkSize);
int nearest_grid_right = Math::Floor(viewport_bottomright.x / Core::Chunk::ChunkSize);
for (int x = nearest_grid_left; x <= nearest_grid_right; x++) {
auto top = Vector2(x * Core::Chunk::ChunkSize, viewport_topleft.y);
auto bottom = Vector2(x * Core::Chunk::ChunkSize, viewport_bottomright.y);
JGL::J2D::DrawLine(debug_grid_color, top, bottom, 1 / camera.Zoom());
}
int nearest_grid_top = Math::Floor(viewport_topleft.y / Core::Chunk::ChunkSize);
int nearest_grid_bottom = Math::Floor(viewport_bottomright.y / Core::Chunk::ChunkSize);
for (int y = nearest_grid_top; y <= nearest_grid_bottom; y++) {
auto left = Vector2(viewport_topleft.x, y * Core::Chunk::ChunkSize);
auto right = Vector2(viewport_bottomright.x, y * Core::Chunk::ChunkSize);
JGL::J2D::DrawLine(debug_grid_color, left, right, 1 / camera.Zoom());
}*/
}
void LocalWorld::CheckCachedChunkSprites() {
for (auto& [chunk_pos, chunk] : loaded_chunks) {
@@ -537,6 +515,21 @@ namespace CaveGame::Client {
chunk_debug.Enable(enabled);
}
void LocalWorld::SaveAndExit() {
World::SaveAndExit();
}
void LocalWorld::SetShowTileActivity(bool enabled) {
show_tile_activity = enabled;
}
bool LocalWorld::IsShowTileActivityEnabled() const { return show_tile_activity;}
void LocalWorld::Emit(const Particle &p) {
particles.push_back(p);
}
}