GetChunkCoordinatesAtCell and GetTileCoordinatesAtCell very weird error trying to move to implementation.
This commit is contained in:
@@ -34,6 +34,8 @@ namespace CaveGame::Core {
|
||||
/// The world class manages and coordinates terrain generation, chunk file IO, thread synchronization, and entity logic.
|
||||
class World : public ITileMap {
|
||||
public:
|
||||
Event<> OnNextDay;
|
||||
Event<> OnAutosave;
|
||||
constexpr static float TileTiccRate = 48.f; // Ticcs per second.
|
||||
constexpr static uint RandomTileTickCoefficient = 100;
|
||||
constexpr static float PeriodicAutosaveIntervalSeconds = 30.f;
|
||||
@@ -42,6 +44,7 @@ namespace CaveGame::Core {
|
||||
|
||||
explicit World(const std::string &worldName, int seed = 0, bool overwrite = false);
|
||||
|
||||
|
||||
Vector2i GetChunkCoordinatesAtCell(int x, int y) const {
|
||||
float chunkX = Math::Floor((float)x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor((float)y / Chunk::ChunkSize);
|
||||
@@ -61,16 +64,35 @@ namespace CaveGame::Core {
|
||||
return Vector2i(tileX, tileY);
|
||||
}
|
||||
|
||||
/// Returns the chunk-coordinate for the given set of tile coordinates.
|
||||
/// @param x world-space tile row.
|
||||
/// @param y world-space tile column.
|
||||
//Vector2i GetChunkCoordinatesAtCell(int x, int y) const;
|
||||
|
||||
/// Returns the local-space tile coordinates [0,32] from the given set of world-space tile coordinates.
|
||||
/// @param x world-space tile row.
|
||||
/// @param y world-space tile column.
|
||||
//Vector2i GetTileCoordinatesAtCell(int x, int y) const;
|
||||
|
||||
/// Returns the numeric ID of the tile a the given world-space coordinates.
|
||||
TileID GetTile(int x, int y) const override;
|
||||
|
||||
/// Sets the tile stored at the given location.
|
||||
void SetTile(int x, int y, TileID t, bool flag_update = true) override;
|
||||
|
||||
/// Swaps two tiles at given locations in-place.
|
||||
void SwapTile(int source_x, int source_y, int dest_x, int dest_y, bool flag_update = true) override;
|
||||
|
||||
/// Returns whether tile simulation logic is enabled.
|
||||
bool GetTileSimulationEnabled() const;
|
||||
|
||||
/// Set whether tile simulation logic is enabled.
|
||||
void SetTileSimulationEnabled(bool enabled);
|
||||
|
||||
/// Returns the World Seed.
|
||||
int GetSeed() const;
|
||||
|
||||
/// Sets the World Seed.
|
||||
void SetSeed(int seed);
|
||||
|
||||
|
||||
|
@@ -19,7 +19,11 @@ namespace CaveGame::Core
|
||||
|
||||
time_of_day += elapsed;
|
||||
|
||||
time_of_day = std::fmod(time_of_day, 24*60);
|
||||
if (time_of_day >= 24*60)
|
||||
{
|
||||
OnNextDay.Invoke();
|
||||
time_of_day = 0;
|
||||
}
|
||||
|
||||
autosave_timer += elapsed;
|
||||
|
||||
@@ -53,24 +57,6 @@ namespace CaveGame::Core
|
||||
}
|
||||
|
||||
TileID World::GetTile(int x, int y) const {
|
||||
/*
|
||||
float chunkX = Math::Floor((float)x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor((float)y / Chunk::ChunkSize);
|
||||
float tileX = Math::Mod(x, Chunk::ChunkSize);
|
||||
float tileY = Math::Mod(y, Chunk::ChunkSize);
|
||||
|
||||
if (tileX < 0)
|
||||
tileX = Chunk::ChunkSize + tileX;
|
||||
if (tileY < 0)
|
||||
tileY = Chunk::ChunkSize + tileY;
|
||||
|
||||
Vector2 coords = Vector2(chunkX, chunkY);
|
||||
|
||||
if (HasChunkAtCell(coords))
|
||||
return loaded_chunks.at(coords)->GetTile(tileX, tileY);
|
||||
|
||||
return TileID::VOID;*/
|
||||
|
||||
Vector2i chunkCoords = GetChunkCoordinatesAtCell(x, y);
|
||||
Vector2i tileCoords = GetTileCoordinatesAtCell(x, y);
|
||||
|
||||
@@ -81,34 +67,6 @@ namespace CaveGame::Core
|
||||
}
|
||||
|
||||
void World::SetTile(int x, int y, TileID t, bool flag_update) {
|
||||
/*
|
||||
float chunkX = Math::Floor((float)x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor((float)y / Chunk::ChunkSize);
|
||||
float tileX = Math::Mod(x, Chunk::ChunkSize);
|
||||
float tileY = Math::Mod(y, Chunk::ChunkSize);
|
||||
|
||||
if (tileX < 0)
|
||||
tileX = Chunk::ChunkSize + tileX;
|
||||
if (tileY < 0)
|
||||
tileY = Chunk::ChunkSize + tileY;
|
||||
|
||||
const Vector2 coords = Vector2(chunkX, chunkY);
|
||||
|
||||
if (HasChunkAtCell(coords))
|
||||
{
|
||||
loaded_chunks.at(coords)->SetTile(tileX, tileY, t, flag_update);
|
||||
|
||||
//SetTileUpdateFlag(x, y, true);
|
||||
if (flag_update) {
|
||||
SetTileUpdateFlag(x, y, true);
|
||||
SetTileUpdateFlag(x, y-1, true);
|
||||
SetTileUpdateFlag(x, y+1, true);
|
||||
SetTileUpdateFlag(x-1, y, true);
|
||||
SetTileUpdateFlag(x+1, y, true);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
Vector2i chunkCoords = GetChunkCoordinatesAtCell(x, y);
|
||||
Vector2i tileCoords = GetTileCoordinatesAtCell(x, y);
|
||||
|
||||
@@ -468,6 +426,7 @@ namespace CaveGame::Core
|
||||
}
|
||||
|
||||
void World::AutoSave() {
|
||||
OnAutosave.Invoke();
|
||||
Logs::Info("Autosaving...");
|
||||
for (auto& [coords, chunk] : loaded_chunks)
|
||||
{
|
||||
@@ -550,4 +509,23 @@ namespace CaveGame::Core
|
||||
void World::SetSeed(int seed) {
|
||||
generator.SetSeed(seed);
|
||||
}
|
||||
|
||||
/*Vector2i World::GetChunkCoordinatesAtCell(int x, int y) const {
|
||||
float chunkX = Math::Floor(x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor(y / Chunk::ChunkSize);
|
||||
|
||||
return Vector2i(chunkX, chunkY);
|
||||
}
|
||||
|
||||
Vector2i World::GetTileCoordinatesAtCell(int x, int y) const {
|
||||
float tileX = Math::Mod(x, Chunk::ChunkSize);
|
||||
float tileY = Math::Mod(y, Chunk::ChunkSize);
|
||||
|
||||
if (tileX < 0)
|
||||
tileX = Chunk::ChunkSize + tileX;
|
||||
if (tileY < 0)
|
||||
tileY = Chunk::ChunkSize + tileY;
|
||||
|
||||
return Vector2i(tileX, tileY);
|
||||
}*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user