Skip to content

Commit

Permalink
Added OutdoorTerrain::isWaterOrShoreByGrid, dropped some of OutdoorLo…
Browse files Browse the repository at this point in the history
…cation methods
  • Loading branch information
captainurist committed Nov 10, 2024
1 parent 976e063 commit 4758ad2
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/Engine/Graphics/DecalBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ bool DecalBuilder::ApplyBloodSplat_OutdoorFace(ODMFace *pFace) {

//----- (0049BE8A) --------------------------------------------------------
// apply outdoor blodsplats - check to see if bloodsplat hits terrain triangle
bool DecalBuilder::ApplyBloodSplatToTerrain(TileFlags terrainFlags, Vec3f *terrnorm, float *tridotdist,
bool DecalBuilder::ApplyBloodSplatToTerrain(bool fading, Vec3f *terrnorm, float *tridotdist,
RenderVertexSoft *triverts, const int whichsplat) {
// tracks how many decals are applied to this tri
this->uNumSplatsThisFace = 0;
Expand All @@ -247,7 +247,7 @@ bool DecalBuilder::ApplyBloodSplatToTerrain(TileFlags terrainFlags, Vec3f *terrn
// blood splat hits this terrain tri

// check if water or something else (maybe should be border tile or swampy?)
if (terrainFlags & TILE_WATER || terrainFlags & TILE_SHORE) {
if (fading) {
// apply fade flags
if (!(bloodsplat_container->pBloodsplats_to_apply[whichsplat].blood_flags & DecalFlagsFade)) {
bloodsplat_container->pBloodsplats_to_apply[whichsplat].blood_flags |= DecalFlagsFade;
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Graphics/DecalBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ struct DecalBuilder {
*
* Attemps to apply a certain bloodsplat onto the supplied terrain triangle.
*
* @param terrainFlags Terrain flags
* @param fading Whether blood splat should be fading.
* @param terrnorm Normal vector of supplied triangle.
* @param[out] tridotdist Plane dot distance of supplied vertices.
* @param triverts Vertices of terrain triangle to apply splat onto.
* @param whichsplat Index of which bloodsplat in bloodsplat_container->pBloodsplats_to_apply[index] to use.
*
* @return True if bloodsplat_container->uNumBloodsplats > 0, false otherwise.
*/
bool ApplyBloodSplatToTerrain(TileFlags terrainFlags, Vec3f *terrnorm, float *tridotdist,
bool ApplyBloodSplatToTerrain(bool fading, Vec3f *terrnorm, float *tridotdist,
RenderVertexSoft *triverts, const int whichsplat);
void DrawDecals(float z_bias);
void DrawBloodsplats();
Expand Down
10 changes: 0 additions & 10 deletions src/Engine/Graphics/Outdoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,6 @@ double OutdoorLocation::GetFogDensityByTime() {
}
}

TileFlags OutdoorLocation::getTileAttribByPos(const Vec3f &pos) {
Vec2i gridPos = WorldPosToGrid(pos);
return getTileAttribByGrid(gridPos.x, gridPos.y);
}

TileData *OutdoorLocation::getTileDescByPos(const Vec3f &pos) {
Vec2i gridPos = WorldPosToGrid(pos);
return getTileDescByGrid(gridPos.x, gridPos.y);
Expand Down Expand Up @@ -619,11 +614,6 @@ TileData *OutdoorLocation::getTileDescByGrid(int sX, int sY) {
return &pTileTable->tiles[tileId];
}

TileFlags OutdoorLocation::getTileAttribByGrid(int gridX, int gridY) {
int tileId = this->pTerrain.tileIdByGrid(Vec2i(gridX, gridY));
return pTileTable->tiles[tileId].uAttributes;
}

//----- (0047EF60) --------------------------------------------------------
int OutdoorLocation::UpdateDiscoveredArea(Vec2i gridPos) {
for (int i = -10; i < 10; i++) {
Expand Down
10 changes: 0 additions & 10 deletions src/Engine/Graphics/Outdoor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ struct OutdoorLocation {
void Release();
void Load(std::string_view filename, int days_played, int respawn_interval_days, bool *outdoors_was_respawned);

/**
* @offset 0x47EDB3
*/
TileFlags getTileAttribByGrid(int gridX, int gridY);

int UpdateDiscoveredArea(Vec2i gridPos);
bool IsMapCellFullyRevealed(signed int a2, signed int a3);
bool IsMapCellPartiallyRevealed(signed int a2, signed int a3);
Expand All @@ -49,11 +44,6 @@ struct OutdoorLocation {
bool InitalizeActors(MapId a1);
double GetFogDensityByTime();

/**
* @offset 0x488EB1
*/
TileFlags getTileAttribByPos(const Vec3f &pos);

/**
* @offset 0x488EEF
*/
Expand Down
4 changes: 4 additions & 0 deletions src/Engine/Graphics/OutdoorTerrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ bool OutdoorTerrain::isWaterByGrid(Vec2i gridPos) const {
return pTileTable->tiles[tileIdByGrid(gridPos)].uAttributes & TILE_WATER;
}

bool OutdoorTerrain::isWaterOrShoreByGrid(Vec2i gridPos) const {
return pTileTable->tiles[tileIdByGrid(gridPos)].uAttributes & (TILE_WATER | TILE_SHORE);
}

bool OutdoorTerrain::isWaterByPos(const Vec3f &pos) const {
return isWaterByGrid(WorldPosToGrid(pos));
}
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/Graphics/OutdoorTerrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class OutdoorTerrain {
*/
bool isWaterByGrid(Vec2i gridPos) const;

bool isWaterOrShoreByGrid(Vec2i gridPos) const;

bool isWaterByPos(const Vec3f &pos) const;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Engine/Graphics/Renderer/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ void OpenGLRenderer::DrawOutdoorTerrain() {
continue;

// splat hits this square of terrain
TileFlags terrainFlags = pOutdoor->getTileAttribByGrid(loopx, loopy);
bool fading = pOutdoor->pTerrain.isWaterOrShoreByGrid({loopx, loopy});

unsigned norm_idx = pOutdoor->pTerrain.pTerrainNormalIndices[(2 * loopx * 128) + (2 * loopy) + 2]; // 2 is top tri // 3 is bottom
unsigned bottnormidx = pOutdoor->pTerrain.pTerrainNormalIndices[(2 * loopx * 128) + (2 * loopy) + 3];
Expand All @@ -1961,7 +1961,7 @@ void OpenGLRenderer::DrawOutdoorTerrain() {
float _f1 = norm->x * pOutdoor->vSunlight.x + norm->y * pOutdoor->vSunlight.y + norm->z * pOutdoor->vSunlight.z;
int dimming_level = std::clamp(static_cast<int>(20.0f - floorf(20.0f * _f1 + 0.5f)), 0, 31);

decal_builder->ApplyBloodSplatToTerrain(terrainFlags, norm, &Light_tile_dist, VertexRenderList, i);
decal_builder->ApplyBloodSplatToTerrain(fading, norm, &Light_tile_dist, VertexRenderList, i);
Planef plane;
plane.normal = *norm;
plane.dist = Light_tile_dist;
Expand All @@ -1972,7 +1972,7 @@ void OpenGLRenderer::DrawOutdoorTerrain() {
float _f = norm2->x * pOutdoor->vSunlight.x + norm2->y * pOutdoor->vSunlight.y + norm2->z * pOutdoor->vSunlight.z;
dimming_level = std::clamp(static_cast<int>(20.0 - floorf(20.0 * _f + 0.5f)), 0, 31);

decal_builder->ApplyBloodSplatToTerrain(terrainFlags, norm2, &Light_tile_dist, (VertexRenderList + 3), i);
decal_builder->ApplyBloodSplatToTerrain(fading, norm2, &Light_tile_dist, (VertexRenderList + 3), i);
plane.normal = *norm2;
plane.dist = Light_tile_dist;
if (decal_builder->uNumSplatsThisFace > 0)
Expand Down

0 comments on commit 4758ad2

Please sign in to comment.