Re-implemented debug lines.
This commit is contained in:
@@ -31,12 +31,68 @@ namespace CaveGame::Client
|
||||
|
||||
};
|
||||
|
||||
|
||||
/// A class object that renders an overlay on chunks for debugging. This includes grid-lines, cell coordinates, activity stats, etc.
|
||||
class ChunkDebugGizmo
|
||||
{
|
||||
public:
|
||||
|
||||
void DrawGrid(const AABB2D& bounds) {
|
||||
Vector2 viewport_topleft = bounds.minPoint;
|
||||
Vector2 viewport_bottomright = bounds.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(grid_color, top, bottom, 1 / bounds.Width());
|
||||
}
|
||||
|
||||
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(grid_color, left, right, 1 / bounds.Height());
|
||||
}
|
||||
}
|
||||
void DrawCellCoords(const Vector2i& coords, float scale) {
|
||||
// TODO: Fix offset on text.
|
||||
JGL::J2D::DrawString(Colors::Black, std::format("{}, {}", coords.x, coords.y), coords.x * Core::Chunk::ChunkSize, (coords.y * Core::Chunk::ChunkSize)-5, scale, 10);
|
||||
}
|
||||
void DrawStats(Core::Chunk* chunk, float scale) {
|
||||
Vector2i cell = chunk->GetChunkCell();
|
||||
Vector2i coords = chunk->GetChunkRealCoordinates();
|
||||
|
||||
JGL::J2D::DrawString(Colors::Black, std::format("RenderTarget Age: {}", chunk->time_since_refresh), coords.x, coords.y, scale, 10);
|
||||
}
|
||||
void DrawHeatmap() {}
|
||||
|
||||
void Enable(bool enable = true)
|
||||
{
|
||||
this->enabled = enable;
|
||||
}
|
||||
void Disable() { Enable(false); }
|
||||
bool IsEnabled() const { return true;}
|
||||
|
||||
protected:
|
||||
bool enabled = true;
|
||||
bool draw_grid = true;
|
||||
Color4 grid_color = {128, 128, 128, 128};
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
/// An extension of the world object that provides rendering for the game 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);
|
||||
@@ -44,6 +100,10 @@ namespace CaveGame::Client
|
||||
void Draw();
|
||||
void Update(float elapsed) override;
|
||||
void RefreshAll() override;
|
||||
void DebugChunks(bool enabled)
|
||||
{
|
||||
chunk_debug.Enable(enabled);
|
||||
}
|
||||
|
||||
unsigned int GetRenderTargetCount() const;
|
||||
|
||||
|
@@ -21,7 +21,7 @@ namespace CaveGame::Client {
|
||||
}
|
||||
|
||||
void LocalWorld::DrawChunkGrid() const {
|
||||
Vector2 viewport_topleft = camera.ScaledViewport().minPoint;
|
||||
/*Vector2 viewport_topleft = camera.ScaledViewport().minPoint;
|
||||
Vector2 viewport_bottomright = camera.ScaledViewport().maxPoint;
|
||||
|
||||
int nearest_grid_left = Math::Floor(viewport_topleft.x / Core::Chunk::ChunkSize);
|
||||
@@ -30,7 +30,7 @@ namespace CaveGame::Client {
|
||||
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(Colors::Red, top, bottom);
|
||||
JGL::J2D::DrawLine(debug_grid_color, top, bottom, 1 / camera.Zoom());
|
||||
}
|
||||
|
||||
int nearest_grid_top = Math::Floor(viewport_topleft.y / Core::Chunk::ChunkSize);
|
||||
@@ -39,8 +39,10 @@ namespace CaveGame::Client {
|
||||
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(Colors::Red, left, right);
|
||||
}
|
||||
JGL::J2D::DrawLine(debug_grid_color, left, right, 1 / camera.Zoom());
|
||||
}*/
|
||||
|
||||
// TODO: Draw coordinates for the chunk the mouse is in
|
||||
}
|
||||
|
||||
|
||||
@@ -172,14 +174,23 @@ namespace CaveGame::Client {
|
||||
for (const auto& [chunk_pos, chunk] : loaded_chunks)
|
||||
{
|
||||
if (IsChunkCellWithinViewport(chunk_pos))
|
||||
{
|
||||
RenderChunk(chunk_pos);
|
||||
|
||||
//JGL::J2D::DrawString(Colors::Black, std::format("{}, {}", chunk_pos.x, chunk_pos.y), chunk.GetChunkRealCoordinates().x, chunk.GetChunkRealCoordinates().y,
|
||||
// 1, 8, font);
|
||||
// Debug Grid
|
||||
if (chunk_debug.IsEnabled())
|
||||
{
|
||||
chunk_debug.DrawStats(chunk, 0.99f / camera.Zoom());
|
||||
chunk_debug.DrawCellCoords(chunk_pos, 0.99f / camera.Zoom());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Debug Grid
|
||||
//DrawChunkGrid();
|
||||
if (chunk_debug.IsEnabled())
|
||||
chunk_debug.DrawGrid(camera.ScaledViewport());
|
||||
|
||||
|
||||
|
||||
|
||||
|
@@ -120,8 +120,16 @@ namespace CaveGame::Core
|
||||
|
||||
void SetSecondPassCompleted(bool complete = true);
|
||||
|
||||
// TODO: Don't do this unless debugging, iterating over every chunk just to increment this number is slow.
|
||||
void Update(float delta)
|
||||
{
|
||||
time_since_refresh += delta;
|
||||
}
|
||||
|
||||
public:
|
||||
bool touched;
|
||||
// For to the rendertarget!!
|
||||
float time_since_refresh = 0.f;
|
||||
protected:
|
||||
Vector2i cell;
|
||||
TileID tiles[ChunkSize][ChunkSize];
|
||||
@@ -132,6 +140,8 @@ namespace CaveGame::Core
|
||||
bool second_pass_complete = false;
|
||||
bool has_update = false;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
constexpr std::size_t Chunk::BufferSizeBytes()
|
||||
|
@@ -21,7 +21,7 @@ struct std::hash<Vector2i>
|
||||
{
|
||||
std::size_t operator()(const Vector2i& k) const
|
||||
{
|
||||
return Math::Pow(k.x, 3) + Math::Pow(k.y, 2);
|
||||
return k.x; //Math::Pow(k.x, 3) + Math::Pow(k.y, 2);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -70,12 +70,8 @@ namespace CaveGame::Core {
|
||||
|
||||
void SetTileSimulationEnabled(bool enabled);
|
||||
|
||||
int GetSeed() const {
|
||||
return generator.GetSeed();
|
||||
}
|
||||
void SetSeed(int seed) {
|
||||
generator.SetSeed(seed);
|
||||
}
|
||||
int GetSeed() const;
|
||||
void SetSeed(int seed);
|
||||
|
||||
|
||||
TileState GetTileState(int x, int y) const override { return 0; /* TODO: Implement tile state field */ }
|
||||
|
@@ -11,6 +11,12 @@
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
void CaveGame::Core::World::Update(float elapsed) {
|
||||
|
||||
for (const auto& [coords, chunk] : loaded_chunks) {
|
||||
chunk->Update(elapsed);
|
||||
}
|
||||
|
||||
|
||||
time_of_day += elapsed;
|
||||
|
||||
time_of_day = std::fmod(time_of_day, 24*60);
|
||||
@@ -536,4 +542,12 @@ namespace CaveGame::Core
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int World::GetSeed() const {
|
||||
return generator.GetSeed();
|
||||
}
|
||||
|
||||
void World::SetSeed(int seed) {
|
||||
generator.SetSeed(seed);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user