From 5cd84258d8949cbd19937702a7df1e7221354454 Mon Sep 17 00:00:00 2001 From: josh Date: Fri, 28 Mar 2025 01:26:31 -0400 Subject: [PATCH] Adding More Tile Functions (Non-building commit). --- ClientApp/assets/data/tiles.json | 6 ++- Core/include/Core/Tile.hpp | 13 +++--- Core/src/Core/Tile.cpp | 71 ++++++++++++++++++++++++++++++++ Core/src/Core/TileRegistry.cpp | 18 ++++++++ Core/src/Core/World.cpp | 26 ------------ 5 files changed, 100 insertions(+), 34 deletions(-) diff --git a/ClientApp/assets/data/tiles.json b/ClientApp/assets/data/tiles.json index 450c3b9..4362cb9 100644 --- a/ClientApp/assets/data/tiles.json +++ b/ClientApp/assets/data/tiles.json @@ -100,6 +100,8 @@ "mnemonic-id" : "grass", "display-name" : "Grass", "solid": true, + "forced-ticc-func": "grass-forced", + "random-ticc-func": "grass-random", "color": [124, 252, 0], "pallet": [[126, 252, 5], [122, 238, 0], [124, 248, 12]] }, @@ -113,7 +115,9 @@ "mnemonic-id" : "vine", "display-name" : "Vine", "solid": false, - "color": [32, 139, 34] + "color": [32, 139, 34], + "forced-ticc-func": "vine-forced", + "random-ticc-func": "vine-random" }, { "mnemonic-id" : "sand", diff --git a/Core/include/Core/Tile.hpp b/Core/include/Core/Tile.hpp index 8ddbecb..fec0fe5 100644 --- a/Core/include/Core/Tile.hpp +++ b/Core/include/Core/Tile.hpp @@ -13,7 +13,6 @@ namespace CaveGame::Core { using J3ML::LinearAlgebra::Vector2i; - using TileID = u16; struct Tile; @@ -24,6 +23,12 @@ namespace CaveGame::Core { void SandGravTiccFunc(const Tile& data, ITileMap* world, int x, int y); void LiquidSettleTiccFunc(const Tile& data, ITileMap* world, int x, int y); + void GrassRandomTiccFunc(const Tile& data, ITileMap* world, int x, int y); + void GrassForcedTiccFunc(const Tile& data, ITileMap* world, int x, int y); + void MossRandomTiccFunc(const Tile& data, ITileMap* world, int x, int y); + void MossForcedTiccFunc(const Tile& data, ITileMap* world, int x, int y); + void VineRandomTiccFunc(const Tile& data, ITileMap* world, int x, int y); + void VineForcedTiccFunc(const Tile& data, ITileMap* world, int x, int y); static std::map ticc_funcs; @@ -124,12 +129,6 @@ namespace CaveGame::Core { uint8_t b; uint8_t g; }; - - - - - - /*std::unordered_map tile_functions { {"check-spread", [](const Tile& data, ITileMap* world, int x, int y){ diff --git a/Core/src/Core/Tile.cpp b/Core/src/Core/Tile.cpp index 2cc3aee..4eff197 100644 --- a/Core/src/Core/Tile.cpp +++ b/Core/src/Core/Tile.cpp @@ -305,4 +305,75 @@ namespace CaveGame::Core { } + void MossRandomTiccFunc(const Tile &data, ITileMap *world, int x, int y) { + + } + + void GrassForcedTiccFunc(const Tile &data, ITileMap *world, int x, int y) { + + } + + void GrassRandomTiccFunc(const Tile &data, ITileMap *world, int x, int y) { + + } + + void MossForcedTiccFunc(const Tile &data, ITileMap *world, int x, int y) { + + } + + void VineRandomTiccFunc(const Tile &data, ITileMap *world, int x, int y) { + static TileID air = Tiles()["air"].numeric_id; + + + + if (DecayCheck(world, x,y, air)) + return; + + if (SpreadCheck(world, x, y, air)) + return; + + } + + void VineForcedTiccFunc(const Tile &data, ITileMap *world, int x, int y) { + static TileID air = Tiles()["air"].numeric_id; + if (DecayCheck(world, x, y, TileID::AIR)) + return; + } + + bool DecayCheck(ITileMap* world, int x, int y, TileID decays_to) { + static TileID vine = Tiles()["vine"].numeric_id; + static TileID grass = Tiles()["grass"].numeric_id; + static TileID air = Tiles()["air"].numeric_id; + + TileID above = world->GetTile(x, y-1); + if (above != vine && above != grass) + { + DecayTo(world, x, y, air); + return true; + } + return false; + } + + bool VineTile::ShouldSpread(ITileMap* world, int x, int y, TileID spreads_to) const + { + if (world->GetTile(x, y) == spreads_to) + { + return true; + } + return false; + } + + bool VineTile::SpreadCheck(ITileMap* world, TileState state, int x, int y, TileID spreads_to) + { + if (ShouldSpread(world, x, y + 1, spreads_to)) + { + if (world->GetTile(x+1, y+1) == TileID::AIR && world->GetTile(x-1, y+1) == TileID::AIR) + { + world->SetTile(x, y+1, numeric_id); + return true; + } + } + return false; + } + } \ No newline at end of file diff --git a/Core/src/Core/TileRegistry.cpp b/Core/src/Core/TileRegistry.cpp index e26f91c..653a86d 100644 --- a/Core/src/Core/TileRegistry.cpp +++ b/Core/src/Core/TileRegistry.cpp @@ -92,6 +92,24 @@ namespace CaveGame::Core bool LoadTileMetadata(const std::filesystem::path &path) { ticc_funcs.insert({"sand-grav", SandGravTiccFunc}); + ticc_funcs.insert({"liquid-settle", LiquidSettleTiccFunc}); + ticc_funcs.insert({"grass-random", GrassRandomTiccFunc}); + ticc_funcs.insert({"grass-forced", GrassForcedTiccFunc}); + ticc_funcs.insert({"moss-random", MossRandomTiccFunc}); + ticc_funcs.insert({"moss-forced", MossForcedTiccFunc}); + ticc_funcs.insert({"vine-random", VineRandomTiccFunc}); + ticc_funcs.insert({"vine-forced", VineForcedTiccFunc}); + //ticc_funcs.insert({"water-solver", }) + + // Subgroups for what collides with what. ~Will + // Like collision mask? Or tile-reactions (i.e. obsidian and water) + + // Solid means the tile is noncompressible. It is a solid box. + // Collides means whether any collision test is even performed. Will be used for cosmetic tiles. Terrain decoration. + // Otherwise, i'm thinking you could use an idiom like + // Tile collided; + // if (collided.tagged("soil")) { ... } + using namespace JJX; std::string content = read_file(path); diff --git a/Core/src/Core/World.cpp b/Core/src/Core/World.cpp index 3f02c49..b9b2940 100644 --- a/Core/src/Core/World.cpp +++ b/Core/src/Core/World.cpp @@ -471,13 +471,6 @@ namespace CaveGame::Core { if (tile.does_random_ticc) tile.random_ticc_func(tile, this, wx, wy); - - //if (at == TileID::AIR) - // continue; - - //tile = GetByNumeric(at); - //if ((tile != nullptr) && (tile->DoesRandomTicc())) - // tile->RandomTicc(this, 0, wx, wy); } } @@ -516,23 +509,4 @@ 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); - }*/ }