Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tiles under skyscrapers not changing to rubble #3731

Merged
merged 4 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "combat.h"
#include "multiplay.h"
#include "qtscript.h"
#include "terrain.h"

#include "mapgrid.h"
#include "display3d.h"
Expand Down Expand Up @@ -545,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)
{
Expand All @@ -554,18 +557,18 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime)
/* Clear feature bits */
if (isUrban)
{
psTile->texture = TileNumber_texture(psTile->texture) | RUBBLE_TILE;
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;
makeTileRubbleTexture(psTile, x, y, BLOCKING_RUBBLE_TILE);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 15 additions & 9 deletions src/terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(xSectors) * static_cast<size_t>(ySectors);
for (size_t i = 0; i < len; ++i)
{
sectors[i].dirty = true;
}
}
}

void loadWaterTextures(int maxTerrainTextureSize, optional<int> maxTerrainAuxTextureSize = nullopt);

void loadTerrainTextures_Fallback(MAP_TILESET mapTileset)
Expand Down Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions src/terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ gfx_api::texture* getTerrainLightmapTexture();
const glm::mat4& getModelUVLightmapMatrix();

void markTileDirty(int i, int j);
void dirtyAllSectors();

enum TerrainShaderType
{
Expand Down
Loading