From fa03d9d0fae2433919341649f13eb392cfe8c77d Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Thu, 11 Apr 2024 18:51:24 -0500 Subject: [PATCH 1/4] Create a way to dirty all tiles Squelch a multiplication warning with the for loop. --- src/terrain.cpp | 24 +++++++++++++++--------- src/terrain.h | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/terrain.cpp b/src/terrain.cpp index d0e441e5039..e0ac1ad1e01 100644 --- a/src/terrain.cpp +++ b/src/terrain.cpp @@ -777,6 +777,20 @@ void markTileDirty(int i, int j) } } +// Mark all tiles dirty +// (when switching between classic and other modes, recalculating tile heights is required due to water) +void dirtyAllSectors() +{ + if (sectors) + { + size_t len = static_cast(xSectors) * static_cast(ySectors); + for (size_t i = 0; i < len; ++i) + { + sectors[i].dirty = true; + } + } +} + void loadWaterTextures(int maxTerrainTextureSize, optional maxTerrainAuxTextureSize = nullopt); void loadTerrainTextures_Fallback(MAP_TILESET mapTileset) @@ -2340,15 +2354,7 @@ bool setTerrainShaderQuality(TerrainShaderQuality newValue, bool force, bool for std::string terrainQualityUintStr = std::to_string(debugQualityUint); crashHandlingProviderSetTag("wz.terrain_quality", terrainQualityUintStr); - if (sectors) - { - // mark all tiles dirty - // (when switching between classic and other modes, recalculating tile heights is required due to water) - for (size_t i = 0; i < xSectors * ySectors; ++i) - { - sectors[i].dirty = true; - } - } + dirtyAllSectors(); // re-load terrain textures if (!rebuildExistingSearchPathWithGraphicsOptionChange()) diff --git a/src/terrain.h b/src/terrain.h index 1bcd9df9817..4d25b0b5128 100644 --- a/src/terrain.h +++ b/src/terrain.h @@ -48,6 +48,7 @@ gfx_api::texture* getTerrainLightmapTexture(); const glm::mat4& getModelUVLightmapMatrix(); void markTileDirty(int i, int j); +void dirtyAllSectors(); enum TerrainShaderType { From f34f2b445d820db5fbfa2904fa29399f848f9454 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Thu, 11 Apr 2024 18:53:15 -0500 Subject: [PATCH 2/4] Dirty Rubble tiles after destroying skyscrapers --- src/feature.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/feature.cpp b/src/feature.cpp index 5bd2bc37c7d..260eb8c9ce1 100644 --- a/src/feature.cpp +++ b/src/feature.cpp @@ -46,6 +46,7 @@ #include "combat.h" #include "multiplay.h" #include "qtscript.h" +#include "terrain.h" #include "mapgrid.h" #include "display3d.h" @@ -555,6 +556,7 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) if (isUrban) { psTile->texture = TileNumber_texture(psTile->texture) | RUBBLE_TILE; + markTileDirty(b.map.x + width, b.map.y + breadth); } auxClearBlocking(b.map.x + width, b.map.y + breadth, AUXBITS_ALL); } @@ -566,6 +568,7 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) if (isUrban) { psTile->texture = TileNumber_texture(psTile->texture) | BLOCKING_RUBBLE_TILE; + markTileDirty(b.map.x + width, b.map.y + breadth); } } } From 3bbfe87f9c7f0aad8de27e66fdd82a25f813a4d5 Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Thu, 11 Apr 2024 19:54:16 -0500 Subject: [PATCH 3/4] Mark tiles under skyscrapers as decals --- src/feature.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/feature.cpp b/src/feature.cpp index 260eb8c9ce1..afbdc557576 100644 --- a/src/feature.cpp +++ b/src/feature.cpp @@ -556,6 +556,7 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) if (isUrban) { psTile->texture = TileNumber_texture(psTile->texture) | RUBBLE_TILE; + SET_TILE_DECAL(psTile); markTileDirty(b.map.x + width, b.map.y + breadth); } auxClearBlocking(b.map.x + width, b.map.y + breadth, AUXBITS_ALL); @@ -568,6 +569,7 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) if (isUrban) { psTile->texture = TileNumber_texture(psTile->texture) | BLOCKING_RUBBLE_TILE; + SET_TILE_DECAL(psTile); markTileDirty(b.map.x + width, b.map.y + breadth); } } From c19d1638ef2650d13bba4e5c547fac3e75678b3a Mon Sep 17 00:00:00 2001 From: KJeff01 Date: Fri, 12 Apr 2024 11:24:15 -0500 Subject: [PATCH 4/4] Create `makeTileRubbleTexture()` to set tiles to a rubble texture --- src/feature.cpp | 16 +++++++--------- src/map.h | 7 +++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/feature.cpp b/src/feature.cpp index afbdc557576..0790101a490 100644 --- a/src/feature.cpp +++ b/src/feature.cpp @@ -546,7 +546,9 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) { for (int width = 0; width < b.size.x; ++width) { - MAPTILE *psTile = mapTile(b.map.x + width, b.map.y + breadth); + const unsigned int x = b.map.x + width; + const unsigned int y = b.map.y + breadth; + MAPTILE *psTile = mapTile(x, y); // stops water texture changing for underwater features if (terrainType(psTile) != TER_WATER) { @@ -555,22 +557,18 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime) /* Clear feature bits */ if (isUrban) { - psTile->texture = TileNumber_texture(psTile->texture) | RUBBLE_TILE; - SET_TILE_DECAL(psTile); - markTileDirty(b.map.x + width, b.map.y + breadth); + makeTileRubbleTexture(psTile, x, y, RUBBLE_TILE); } - auxClearBlocking(b.map.x + width, b.map.y + breadth, AUXBITS_ALL); + auxClearBlocking(x, y, AUXBITS_ALL); } else { /* This remains a blocking tile */ psTile->psObject = nullptr; - auxClearBlocking(b.map.x + width, b.map.y + breadth, AIR_BLOCKED); // Shouldn't remain blocking for air units, however. + auxClearBlocking(x, y, AIR_BLOCKED); // Shouldn't remain blocking for air units, however. if (isUrban) { - psTile->texture = TileNumber_texture(psTile->texture) | BLOCKING_RUBBLE_TILE; - SET_TILE_DECAL(psTile); - markTileDirty(b.map.x + width, b.map.y + breadth); + makeTileRubbleTexture(psTile, x, y, BLOCKING_RUBBLE_TILE); } } } diff --git a/src/map.h b/src/map.h index 46035fd31c4..175a86601f7 100644 --- a/src/map.h +++ b/src/map.h @@ -524,6 +524,13 @@ WZ_DECL_ALWAYS_INLINE static inline bool worldOnMap(Vector2i pos) return worldOnMap(pos.x, pos.y); } +static inline void makeTileRubbleTexture(MAPTILE *psTile, const unsigned int x, const unsigned int y, const unsigned int newTexture) +{ + psTile->texture = TileNumber_texture(psTile->texture) | newTexture; + SET_TILE_DECAL(psTile); + markTileDirty(x, y); +} + /* Intersect a line with the map and report tile intersection points */ bool map_Intersect(int *Cx, int *Cy, int *Vx, int *Vy, int *Sx, int *Sy);