Skip to content

Commit

Permalink
Merge pull request OpenEnroth#1883 from captainurist/macos_fixes_610
Browse files Browse the repository at this point in the history
Terrain cleanup finished
  • Loading branch information
captainurist authored Nov 16, 2024
2 parents 17627ec + 85da476 commit 92be04a
Show file tree
Hide file tree
Showing 31 changed files with 632 additions and 558 deletions.
3 changes: 3 additions & 0 deletions src/Application/Startup/GameStarter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ void GameStarter::initWithLogger() {
GameStarter::~GameStarter() {
_application->removeComponent<EngineControlComponent>(); // Join the control thread first.

_game.reset();
_engine.reset();

::engine = nullptr;
::render = nullptr;
::application = nullptr;
Expand Down
5 changes: 3 additions & 2 deletions src/Engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ set(ENGINE_SOURCES
TeleportPoint.cpp
GameResourceManager.cpp
mm7_data.cpp
mm7text_ru.cpp)
mm7text_ru.cpp
Seasons.cpp)

set(ENGINE_HEADERS
ArenaEnumFunctions.h
Expand Down Expand Up @@ -54,7 +55,7 @@ set(ENGINE_HEADERS
GameResourceManager.h
mm7_data.h
stru314.h
Data/AutonoteData.h)
Seasons.h)

add_library(engine STATIC ${ENGINE_SOURCES} ${ENGINE_HEADERS})
target_check_style(engine)
Expand Down
10 changes: 6 additions & 4 deletions src/Engine/Data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.27 FATAL_ERROR)

set(ENGINE_DATA_SOURCES)
set(ENGINE_DATA_SOURCES
TileEnumFunctions.cpp)

set(ENGINE_DATA_HEADERS
AutonoteEnums.h
Expand All @@ -15,8 +16,9 @@ set(ENGINE_DATA_HEADERS
IconFrameData.h
PortraitFrameData.h
TileData.h
TileEnums.h)
TileEnums.h
TileEnumFunctions.h)

add_library(engine_data INTERFACE ${ENGINE_DATA_SOURCES} ${ENGINE_DATA_HEADERS})
target_link_libraries(engine_data INTERFACE library_serialization utility)
add_library(engine_data STATIC ${ENGINE_DATA_SOURCES} ${ENGINE_DATA_HEADERS})
target_link_libraries(engine_data PUBLIC library_serialization utility)
target_check_style(engine_data)
2 changes: 1 addition & 1 deletion src/Engine/Data/TileData.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
struct TileData {
std::string name;
uint16_t uTileID = 0;
TileSet tileset = TILE_SET_INVALID;
Tileset tileset = TILESET_INVALID;
TileVariant uSection = TILE_VARIANT_BASE1;
TileFlags uAttributes;
};
67 changes: 67 additions & 0 deletions src/Engine/Data/TileEnumFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "TileEnumFunctions.h"

#include <cassert>

SoundId walkSoundForTileset(Tileset tileset, bool isRunning) {
switch (tileset) {
default:
assert(false);
[[fallthrough]];
case TILESET_INVALID:
return isRunning ? SOUND_RunDirt : SOUND_WalkDirt;
case TILESET_GRASS:
return isRunning ? SOUND_RunGrass : SOUND_WalkGrass;
case TILESET_SNOW:
return isRunning ? SOUND_RunSnow : SOUND_WalkSnow;
case TILESET_DESERT:
return isRunning ? SOUND_RunDesert : SOUND_WalkDesert;
case TILESET_COOLED_LAVA:
return isRunning ? SOUND_RunCooledLava : SOUND_WalkCooledLava;
case TILESET_DIRT:
return isRunning ? SOUND_RunDirt : SOUND_WalkDirt; // Water sounds were used.
case TILESET_WATER:
return isRunning ? SOUND_RunWater : SOUND_WalkWater; // Dirt sounds were used.
case TILESET_BADLANDS:
return isRunning ? SOUND_RunBadlands : SOUND_WalkBadlands;
case TILESET_SWAMP:
return isRunning ? SOUND_RunSwamp : SOUND_WalkSwamp;
case TILESET_TROPICAL:
return isRunning ? SOUND_RunGrass : SOUND_WalkGrass; // TODO(Nik-RE-dev): is that correct?
case TILESET_CITY:
return isRunning ? SOUND_RunGround : SOUND_WalkGround; // TODO(Nik-RE-dev): is that correct?
case TILESET_ROAD_GRASS_COBBLE:
case TILESET_ROAD_GRASS_DIRT:
case TILESET_ROAD_SNOW_COBBLE:
case TILESET_ROAD_SNOW_DIRT:
case TILESET_ROAD_SAND_COBBLE:
case TILESET_ROAD_SAND_DIRT:
case TILESET_ROAD_VOLCANO_COBBLE:
case TILESET_ROAD_VOLCANO_DIRT:
case TILESET_ROAD_CRACKED_COBBLE:
case TILESET_ROAD_CRACKED_DIRT:
case TILESET_ROAD_SWAMP_COBBLE:
case TILESET_ROAD_SWAMP_DIRT:
case TILESET_ROAD_TROPICAL_COBBLE:
case TILESET_ROAD_TROPICAL_DIRT:
return isRunning ? SOUND_RunRoad : SOUND_WalkRoad;
case TILESET_ROAD_CITY_STONE:
return isRunning ? SOUND_RunGround : SOUND_WalkGround; // TODO(Nik-RE-dev): is that correct?
}
}

int foodRequiredForTileset(Tileset tileset) {
switch (tileset) {
case TILESET_GRASS:
return 1;
case TILESET_SNOW:
case TILESET_SWAMP:
return 3;
case TILESET_COOLED_LAVA:
case TILESET_BADLANDS:
return 4;
case TILESET_DESERT:
return 5;
default:
return 2;
}
}
19 changes: 19 additions & 0 deletions src/Engine/Data/TileEnumFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "TileEnums.h"

#include "Media/Audio/SoundEnums.h"

#include "Utility/Segment.h"

inline Segment<TileVariant> allSpecialTileVariants() {
return {TILE_VARIANT_FIRST_SPECIAL, TILE_VARIANT_LAST_SPECIAL};
}

/**
* @param tileset Tileset to get walk/run sound for.
* @param isRunning Run flag.
* @return Sound id to use.
* @offset 0x47EE49
*/
SoundId walkSoundForTileset(Tileset tileset, bool isRunning);

int foodRequiredForTileset(Tileset tileset);
61 changes: 28 additions & 33 deletions src/Engine/Data/TileEnums.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "Utility/Flags.h"
#include "Utility/Segment.h"

enum class TileFlag {
TILE_BURN = 0x1,
Expand Down Expand Up @@ -62,41 +61,37 @@ enum class TileVariant {
};
using enum TileVariant;

inline Segment<TileVariant> allSpecialTileSects() {
return {TILE_VARIANT_FIRST_SPECIAL, TILE_VARIANT_LAST_SPECIAL};
}

/**
* Tile set id.
*
* Most of these tile sets don't exist in mm7 data, see comments.
*/
enum class TileSet {
TILE_SET_INVALID = 255, // Tile with id 0 has tile set = 255.
TILE_SET_GRASS = 0,
TILE_SET_SNOW = 1,
TILE_SET_DESERT = 2, // Sand.
TILE_SET_COOLED_LAVA = 3, // Somehow this tileset is all dirt in the data files.
TILE_SET_DIRT = 4, // This one has only 3 tiles.
TILE_SET_WATER = 5, // Water tile & shoreline tiles.
TILE_SET_BADLANDS = 6, // Looks like Deyja.
TILE_SET_SWAMP = 7,
TILE_SET_TROPICAL = 8, // This is all dirt.
TILE_SET_CITY = 9, // This is sand too, lol.
TILE_SET_ROAD_GRASS_COBBLE = 10, // Cobble road on dirt actually.
TILE_SET_ROAD_GRASS_DIRT = 11, // This is all dirt.
TILE_SET_ROAD_SNOW_COBBLE = 12, // This is all dirt.
TILE_SET_ROAD_SNOW_DIRT = 13, // This is all dirt.
TILE_SET_ROAD_SAND_COBBLE = 14, // This doesn't exist in mm7 tiles at all.
TILE_SET_ROAD_SAND_DIRT = 15, // This doesn't exist in mm7 tiles at all.
TILE_SET_ROAD_VOLCANO_COBBLE = 16, // This is all dirt.
TILE_SET_ROAD_VOLCANO_DIRT = 17, // This is all dirt.
TILE_SET_ROAD_CRACKED_COBBLE = 22, // This is all dirt.
TILE_SET_ROAD_CRACKED_DIRT = 23, // This is all dirt.
TILE_SET_ROAD_SWAMP_COBBLE = 24, // This is all dirt.
TILE_SET_ROAD_SWAMP_DIRT = 25, // This is all dirt.
TILE_SET_ROAD_TROPICAL_COBBLE = 26, // This is all dirt.
TILE_SET_ROAD_TROPICAL_DIRT = 27, // This is all dirt.
TILE_SET_ROAD_CITY_STONE = 28, // This is all dirt.
enum class Tileset {
TILESET_INVALID = 255, // Tile with id 0 has tile set = 255.
TILESET_GRASS = 0,
TILESET_SNOW = 1,
TILESET_DESERT = 2, // Sand.
TILESET_COOLED_LAVA = 3, // Somehow this tileset is all dirt in the data files.
TILESET_DIRT = 4, // This one has only 3 tiles.
TILESET_WATER = 5, // Water tile & shoreline tiles.
TILESET_BADLANDS = 6, // Looks like Deyja.
TILESET_SWAMP = 7,
TILESET_TROPICAL = 8, // This is all dirt.
TILESET_CITY = 9, // This is sand too, lol.
TILESET_ROAD_GRASS_COBBLE = 10, // Cobble road on dirt actually.
TILESET_ROAD_GRASS_DIRT = 11, // This is all dirt.
TILESET_ROAD_SNOW_COBBLE = 12, // This is all dirt.
TILESET_ROAD_SNOW_DIRT = 13, // This is all dirt.
TILESET_ROAD_SAND_COBBLE = 14, // This doesn't exist in mm7 tiles at all.
TILESET_ROAD_SAND_DIRT = 15, // This doesn't exist in mm7 tiles at all.
TILESET_ROAD_VOLCANO_COBBLE = 16, // This is all dirt.
TILESET_ROAD_VOLCANO_DIRT = 17, // This is all dirt.
TILESET_ROAD_CRACKED_COBBLE = 22, // This is all dirt.
TILESET_ROAD_CRACKED_DIRT = 23, // This is all dirt.
TILESET_ROAD_SWAMP_COBBLE = 24, // This is all dirt.
TILESET_ROAD_SWAMP_DIRT = 25, // This is all dirt.
TILESET_ROAD_TROPICAL_COBBLE = 26, // This is all dirt.
TILESET_ROAD_TROPICAL_DIRT = 27, // This is all dirt.
TILESET_ROAD_CITY_STONE = 28, // This is all dirt.
};
using enum TileSet;
using enum Tileset;
21 changes: 0 additions & 21 deletions src/Engine/Graphics/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,27 +518,6 @@ void Camera3D::CalculateRotations(int cameraYaw, int cameraPitch) {
_pitchRotationCosine = std::cos((pi_double + pi_double) * _viewPitch / 2048.0);
}

//----- (00436A6D) --------------------------------------------------------
float Camera3D::GetPolygonMinZ(RenderVertexSoft *pVertices, unsigned int uStripType) {
float result = FLT_MAX;
for (unsigned i = 0; i < uStripType; i++) {
if (pVertices[i].vWorldPosition.z < result) {
result = pVertices[i].vWorldPosition.z;
}
}
return result;
}

//----- (00436A40) --------------------------------------------------------
float Camera3D::GetPolygonMaxZ(RenderVertexSoft *pVertex, unsigned int uStripType) {
float result = FLT_MIN;
for (unsigned i = 0; i < uStripType; i++) {
if (pVertex[i].vWorldPosition.z > result)
result = pVertex[i].vWorldPosition.z;
}
return result;
}

void Camera3D::CullByNearClip(RenderVertexSoft *pverts, unsigned *unumverts) {
float near = GetNearClip();

Expand Down
5 changes: 0 additions & 5 deletions src/Engine/Graphics/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ struct Camera3D {
RenderVertexSoft *pVertices,
signed int NumFrustumPlanes);

float GetPolygonMaxZ(RenderVertexSoft *pVertex,
unsigned int uStripType);
float GetPolygonMinZ(RenderVertexSoft *pVertices,
unsigned int uStripType);

void LightmapNeerClip(RenderVertexSoft *pInVertices,
int uNumInVertices,
RenderVertexSoft *pOutVertices,
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Graphics/Collisions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ void ProcessActorCollisionsODM(Actor &actor, bool isFlying) {
break;

CollideOutdoorWithModels(true);
CollideOutdoorWithDecorations(WorldPosToGrid(actor.pos));
CollideOutdoorWithDecorations(worldToGrid(actor.pos));
CollideWithParty(false);
_46ED8A_collide_against_sprite_objects(Pid(OBJECT_Actor, actor.id));

Expand Down Expand Up @@ -1023,7 +1023,7 @@ void ProcessPartyCollisionsODM(Vec3f *partyNewPos, Vec3f *partyInputSpeed, int *
}

CollideOutdoorWithModels(true);
CollideOutdoorWithDecorations(WorldPosToGrid(pParty->pos));
CollideOutdoorWithDecorations(worldToGrid(pParty->pos));
_46ED8A_collide_against_sprite_objects(Pid::character(0));
if (!engine->config->gameplay.NoPartyActorCollisions.value()) {
for (size_t actor_id = 0; actor_id < pActors.size(); ++actor_id)
Expand Down
6 changes: 3 additions & 3 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(bool fading, Vec3f *terrnorm, float *tridotdist,
bool DecalBuilder::ApplyBloodSplatToTerrain(bool fading, const Vec3f &terrnorm, float *tridotdist,
RenderVertexSoft *triverts, const int whichsplat) {
// tracks how many decals are applied to this tri
this->uNumSplatsThisFace = 0;
Expand All @@ -240,8 +240,8 @@ bool DecalBuilder::ApplyBloodSplatToTerrain(bool fading, Vec3f *terrnorm, float

if (NumBloodsplats > 0) {
// check plane distance
*tridotdist = -dot(triverts->vWorldPosition, *terrnorm);
float planedist = dot(*terrnorm, bloodsplat_container->pBloodsplats_to_apply[whichsplat].pos) + *tridotdist + 0.5f;
*tridotdist = -dot(triverts->vWorldPosition, terrnorm);
float planedist = dot(terrnorm, bloodsplat_container->pBloodsplats_to_apply[whichsplat].pos) + *tridotdist + 0.5f;

if (planedist <= bloodsplat_container->pBloodsplats_to_apply[whichsplat].radius) {
// blood splat hits this terrain tri
Expand Down
2 changes: 1 addition & 1 deletion src/Engine/Graphics/DecalBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct DecalBuilder {
*
* @return True if bloodsplat_container->uNumBloodsplats > 0, false otherwise.
*/
bool ApplyBloodSplatToTerrain(bool fading, Vec3f *terrnorm, float *tridotdist,
bool ApplyBloodSplatToTerrain(bool fading, const Vec3f &terrnorm, float *tridotdist,
RenderVertexSoft *triverts, const int whichsplat);
void DrawDecals(float z_bias);
void DrawBloodsplats();
Expand Down
Loading

0 comments on commit 92be04a

Please sign in to comment.