Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -38,17 +38,17 @@ CPMAddPackage(
|
||||
|
||||
CPMAddPackage(
|
||||
NAME ReWindow
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-30.zip
|
||||
URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-31.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME JGL
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-42.zip
|
||||
URL https://git.redacted.cc/josh/JGL/archive/Prerelease-46.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
NAME JUI
|
||||
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-5.5.zip
|
||||
URL https://git.redacted.cc/josh/ReJUI/archive/Prerelease-5.6.zip
|
||||
)
|
||||
|
||||
CPMAddPackage(
|
||||
|
@@ -40,7 +40,7 @@ void CaveGame::Client::Splash::ComputeMatrixTextureCache()
|
||||
for (int i = 0; i < column_textures.size(); i++)
|
||||
{
|
||||
|
||||
Vector2 column_size = {glyph_measurement.x, glyph_measurement.y * 100};
|
||||
Vector2i column_size = {(int) glyph_measurement.x, (int) glyph_measurement.y * 100};
|
||||
auto* column = new JGL::RenderTarget(column_size, {0, 0, 0, 0}, false);
|
||||
|
||||
JGL::J2D::Begin(column, true);
|
||||
|
@@ -66,7 +66,7 @@ namespace CaveGame::Core
|
||||
[[nodiscard]] const TileID* ptr() const { return &tiles[0][0];}
|
||||
|
||||
|
||||
[[nodiscard]] std::vector<TileID> DataContiguous() const;
|
||||
[[nodiscard]] std::array<TileID, ChunkSize * ChunkSize> DataContiguous() const;
|
||||
|
||||
void SetData(char* buffer);
|
||||
|
||||
|
@@ -43,6 +43,25 @@ namespace CaveGame::Core
|
||||
|
||||
explicit World(const std::string &worldName, int seed = 0, bool overwrite = false);
|
||||
|
||||
Vector2 GetChunkCoordinatesAtCell(int x, int y) const {
|
||||
float chunkX = Math::Floor((float)x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor((float)y / Chunk::ChunkSize);
|
||||
|
||||
return Vector2(chunkX, chunkY);
|
||||
}
|
||||
|
||||
Vector2 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 Vector2(tileX, tileY);
|
||||
}
|
||||
|
||||
TileID GetTile(int x, int y) const override;
|
||||
|
||||
void SetTile(int x, int y, TileID t, bool flag_update = true) override;
|
||||
@@ -79,70 +98,9 @@ namespace CaveGame::Core
|
||||
|
||||
void DoForcedTileTicks();
|
||||
|
||||
void DoRandomTileTick(const Vector2 coords, Chunk* chunk) {
|
||||
Tile* tile = nullptr;
|
||||
|
||||
int max_tries = RandomTileTickCoefficient*5;
|
||||
int max_successes = RandomTileTickCoefficient;
|
||||
|
||||
for (int ticc = 0; ticc < RandomTileTickCoefficient; ticc++)
|
||||
{
|
||||
// Select random x,y coordinates between [0, ChunkSize]
|
||||
int x = rng.Int(0, Chunk::ChunkSize-1);
|
||||
int y = rng.Int(0, Chunk::ChunkSize-1);
|
||||
|
||||
int wx = coords.x*Chunk::ChunkSize + x;
|
||||
int wy = coords.y*Chunk::ChunkSize + y;
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
|
||||
/*
|
||||
if (tile != nullptr)
|
||||
if (tile->DoesRandomTicc())
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
*/
|
||||
if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
}
|
||||
}
|
||||
|
||||
void DoForcedTileTick(const Vector2 coords, Chunk* chunk) {
|
||||
Tile* tile = nullptr;
|
||||
|
||||
chunk->SwapTileUpdateBuffers();
|
||||
|
||||
for (int x = 0; x < Core::Chunk::ChunkSize; x++) {
|
||||
for (int y = 0; y < Core::Chunk::ChunkSize; y++) {
|
||||
int wx = coords.x*Chunk::ChunkSize + x;
|
||||
int wy = coords.y*Chunk::ChunkSize + y;
|
||||
|
||||
if (!chunk->GetTileUpdateBufferFlag(x, y))
|
||||
continue;
|
||||
|
||||
chunk->SetTileUpdateBufferFlag(x, y, false);
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
|
||||
if (tile != nullptr) {
|
||||
if (tile->DoesForcedTicc()) {
|
||||
tile->ForcedTicc(this, 0, wx, wy);
|
||||
//chunk->SetTileUpdateFlag(x, y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void DoRandomTileTick(const Vector2 coords, Chunk* chunk);
|
||||
|
||||
void DoForcedTileTick(const Vector2 coords, Chunk* chunk);
|
||||
|
||||
virtual void Update(float elapsed);
|
||||
|
||||
|
@@ -72,10 +72,10 @@ namespace CaveGame::Core
|
||||
return GetChunkCell()*Core::Chunk::ChunkSize;
|
||||
}
|
||||
|
||||
std::vector<TileID> Chunk::DataContiguous() const {
|
||||
std::vector<TileID> data(ChunkSize * ChunkSize);
|
||||
memcpy(data.data(), tiles, ChunkSize * ChunkSize * sizeof(TileID));
|
||||
return data;
|
||||
std::array<TileID, Chunk::ChunkSize * Chunk::ChunkSize> Chunk::DataContiguous() const {
|
||||
std::array<TileID, ChunkSize * ChunkSize> result{};
|
||||
memcpy(result.data(), tiles, ChunkSize * ChunkSize * sizeof(TileID));
|
||||
return result;
|
||||
}
|
||||
|
||||
void Chunk::SetData(char* buffer) {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
std::array<Tile*, 65535> registered_tiles{};
|
||||
std::array<Tile*, 65536> registered_tiles{};
|
||||
|
||||
|
||||
void Tile::DecayTo(ITileMap *world, TileState state, int x, int y, TileID TDecaysTo) {
|
||||
|
@@ -11,64 +11,6 @@
|
||||
namespace CaveGame::Core
|
||||
{
|
||||
void CaveGame::Core::World::Update(float elapsed) {
|
||||
/*
|
||||
auto DoRandom = [this](const Vector2 coords, Chunk* chunk) {
|
||||
Tile* tile = nullptr;
|
||||
|
||||
for (int ticc = 0; ticc < RandomTileTickCoefficient; ticc++)
|
||||
{
|
||||
// Select random x,y coordinates between [0, ChunkSize]
|
||||
int x = rng.Int(0, Chunk::ChunkSize-1);
|
||||
int y = rng.Int(0, Chunk::ChunkSize-1);
|
||||
|
||||
int wx = coords.x*Chunk::ChunkSize + x;
|
||||
int wy = coords.y*Chunk::ChunkSize + y;
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
}
|
||||
};
|
||||
|
||||
auto DoForced = [this](const Vector2 coords, Chunk* chunk) {
|
||||
Tile* tile = nullptr;
|
||||
|
||||
chunk->SwapTileUpdateBuffers();
|
||||
|
||||
for (int x = 0; x < Core::Chunk::ChunkSize; x++) {
|
||||
for (int y = 0; y < Core::Chunk::ChunkSize; y++) {
|
||||
int wx = coords.x*Chunk::ChunkSize + x;
|
||||
int wy = coords.y*Chunk::ChunkSize + y;
|
||||
|
||||
if (!chunk->GetTileUpdateBufferFlag(x, y))
|
||||
continue;
|
||||
|
||||
chunk->SetTileUpdateBufferFlag(x, y, false);
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
|
||||
if (tile != nullptr) {
|
||||
if (tile->DoesForcedTicc()) {
|
||||
tile->ForcedTicc(this, 0, wx, wy);
|
||||
//chunk->SetTileUpdateFlag(x, y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
time_of_day += elapsed;
|
||||
|
||||
time_of_day = std::fmod(time_of_day, 24*60);
|
||||
@@ -105,6 +47,7 @@ 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);
|
||||
@@ -120,10 +63,19 @@ namespace CaveGame::Core
|
||||
if (HasChunkAtCell(coords))
|
||||
return loaded_chunks.at(coords)->GetTile(tileX, tileY);
|
||||
|
||||
return TileID::VOID;*/
|
||||
|
||||
Vector2 chunkCoords = GetChunkCoordinatesAtCell(x, y);
|
||||
Vector2 tileCoords = GetTileCoordinatesAtCell(x, y);
|
||||
|
||||
if (HasChunkAtCell(chunkCoords))
|
||||
return loaded_chunks.at(chunkCoords)->GetTile(tileCoords.x, tileCoords.y);
|
||||
|
||||
return TileID::VOID;
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -148,6 +100,21 @@ namespace CaveGame::Core
|
||||
SetTileUpdateFlag(x-1, y, true);
|
||||
SetTileUpdateFlag(x+1, y, true);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
Vector2 chunkCoords = GetChunkCoordinatesAtCell(x, y);
|
||||
Vector2 tileCoords = GetTileCoordinatesAtCell(x, y);
|
||||
|
||||
if (HasChunkAtCell(chunkCoords)) {
|
||||
loaded_chunks.at(chunkCoords)->SetTile(tileCoords.x, tileCoords.y, t, flag_update);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -188,6 +155,7 @@ namespace CaveGame::Core
|
||||
std::unordered_map<Vector2, Chunk*> World::GetChunkList() { return loaded_chunks; }
|
||||
|
||||
void World::SetTileUpdateFlag(int x, int y, bool flag) {
|
||||
/*
|
||||
float chunkX = Math::Floor((float)x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor((float)y / Chunk::ChunkSize);
|
||||
|
||||
@@ -203,10 +171,19 @@ namespace CaveGame::Core
|
||||
const Vector2 coords = Vector2(chunkX, chunkY);
|
||||
|
||||
if (HasChunkAtCell(coords))
|
||||
loaded_chunks.at(coords)->SetTileUpdateFlag(tileX, tileY, flag);
|
||||
loaded_chunks.at(coords)->SetTileUpdateFlag(tileX, tileY, flag);*/
|
||||
|
||||
|
||||
const Vector2 chunkCoords = GetChunkCoordinatesAtCell(x, y);
|
||||
Vector2 tileCoords = GetTileCoordinatesAtCell(x, y);
|
||||
|
||||
if (HasChunkAtCell(chunkCoords))
|
||||
loaded_chunks.at(chunkCoords)->SetTileUpdateFlag(tileCoords.x, tileCoords.y, flag);
|
||||
|
||||
}
|
||||
|
||||
bool World::GetTileUpdateFlag(int x, int y) const {
|
||||
/*
|
||||
float chunkX = Math::Floor((float)x / Chunk::ChunkSize);
|
||||
float chunkY = Math::Floor((float)y / Chunk::ChunkSize);
|
||||
|
||||
@@ -224,7 +201,14 @@ namespace CaveGame::Core
|
||||
if (HasChunkAtCell(coords))
|
||||
return loaded_chunks.at(coords)->GetTileUpdateFlag(tileX, tileY);
|
||||
|
||||
return false;
|
||||
return false;*/
|
||||
|
||||
Vector2 chunkCoords = GetChunkCoordinatesAtCell(x, y);
|
||||
Vector2 tileCoords = GetTileCoordinatesAtCell(x, y);
|
||||
|
||||
if (HasChunkAtCell(chunkCoords))
|
||||
return loaded_chunks.at(chunkCoords)->GetTileUpdateFlag(tileCoords.x, tileCoords.y);
|
||||
|
||||
}
|
||||
|
||||
Vector2 World::ToUnitDirection(float rotation) {
|
||||
@@ -500,4 +484,68 @@ namespace CaveGame::Core
|
||||
}
|
||||
Logs::Info("Saving successful!");
|
||||
}
|
||||
|
||||
void World::DoRandomTileTick(const Vector2 coords, Chunk *chunk) {
|
||||
Tile* tile = nullptr;
|
||||
|
||||
int max_tries = RandomTileTickCoefficient*5;
|
||||
int max_successes = RandomTileTickCoefficient;
|
||||
|
||||
for (int ticc = 0; ticc < RandomTileTickCoefficient; ticc++)
|
||||
{
|
||||
// Select random x,y coordinates between [0, ChunkSize]
|
||||
int x = rng.Int(0, Chunk::ChunkSize-1);
|
||||
int y = rng.Int(0, Chunk::ChunkSize-1);
|
||||
|
||||
int wx = coords.x*Chunk::ChunkSize + x;
|
||||
int wy = coords.y*Chunk::ChunkSize + y;
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
|
||||
/*
|
||||
if (tile != nullptr)
|
||||
if (tile->DoesRandomTicc())
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
*/
|
||||
if ((tile != nullptr) && (tile->DoesRandomTicc()))
|
||||
tile->RandomTicc(this, 0, wx, wy);
|
||||
}
|
||||
}
|
||||
|
||||
void World::DoForcedTileTick(const Vector2 coords, Chunk *chunk) {
|
||||
Tile* tile = nullptr;
|
||||
|
||||
chunk->SwapTileUpdateBuffers();
|
||||
|
||||
for (int x = 0; x < Core::Chunk::ChunkSize; x++) {
|
||||
for (int y = 0; y < Core::Chunk::ChunkSize; y++) {
|
||||
int wx = coords.x*Chunk::ChunkSize + x;
|
||||
int wy = coords.y*Chunk::ChunkSize + y;
|
||||
|
||||
if (!chunk->GetTileUpdateBufferFlag(x, y))
|
||||
continue;
|
||||
|
||||
chunk->SetTileUpdateBufferFlag(x, y, false);
|
||||
|
||||
TileID at = chunk->GetTile(x, y);
|
||||
|
||||
if (at == TileID::AIR)
|
||||
continue;
|
||||
|
||||
tile = GetByNumeric(at);
|
||||
|
||||
if (tile != nullptr) {
|
||||
if (tile->DoesForcedTicc()) {
|
||||
tile->ForcedTicc(this, 0, wx, wy);
|
||||
//chunk->SetTileUpdateFlag(x, y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user