Skip to content

Commit

Permalink
TransitionDefinition cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Jan 1, 2025
1 parent e195b51 commit 70e1774
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 89 deletions.
8 changes: 4 additions & 4 deletions OpenTESArena/src/Interface/AutomapUiView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const Color &AutomapUiView::getPixelColor(const VoxelTraitsDefinition &floorDef,
}
else
{
const TransitionType transitionType = transitionDef->getType();
const TransitionType transitionType = transitionDef->type;
if ((transitionType == TransitionType::CityGate) ||
(transitionType == TransitionType::EnterInterior) ||
(transitionType == TransitionType::ExitInterior))
Expand All @@ -114,7 +114,7 @@ const Color &AutomapUiView::getPixelColor(const VoxelTraitsDefinition &floorDef,
}
else if (transitionType == TransitionType::LevelChange)
{
const TransitionDefinition::LevelChangeDef &levelChangeDef = transitionDef->getLevelChange();
const LevelChangeTransitionDefinition &levelChangeDef = transitionDef->levelChange;
return levelChangeDef.isLevelUp ? AutomapUiView::ColorLevelUp : AutomapUiView::ColorLevelDown;
}
else
Expand Down Expand Up @@ -219,7 +219,7 @@ const Color &AutomapUiView::getWildPixelColor(const VoxelTraitsDefinition &floor
}
else
{
const TransitionType transitionType = transitionDef->getType();
const TransitionType transitionType = transitionDef->type;
if ((transitionType == TransitionType::CityGate) ||
(transitionType == TransitionType::EnterInterior) ||
(transitionType == TransitionType::ExitInterior))
Expand All @@ -232,7 +232,7 @@ const Color &AutomapUiView::getWildPixelColor(const VoxelTraitsDefinition &floor
}
else if (transitionType == TransitionType::LevelChange)
{
const TransitionDefinition::LevelChangeDef &levelChangeDef = transitionDef->getLevelChange();
const LevelChangeTransitionDefinition &levelChangeDef = transitionDef->levelChange;
return levelChangeDef.isLevelUp ? AutomapUiView::ColorLevelUp : AutomapUiView::ColorLevelDown;
}
else
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Interface/AutomapUiView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
class GameState;
class Renderer;
class Texture;
class TransitionDefinition;
class VoxelChunkManager;

enum class CardinalDirectionName;

struct TransitionDefinition;
struct VoxelTraitsDefinition;

namespace AutomapUiView
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Player/PlayerLogicController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ void PlayerLogicController::handleScreenToWorldInteraction(Game &game, const Int
if (chunk.tryGetTransitionDefID(voxel.x, voxel.y, voxel.z, &transitionDefID))
{
const TransitionDefinition &transitionDef = chunk.getTransitionDef(transitionDefID);
if (transitionDef.getType() != TransitionType::LevelChange)
if (transitionDef.type != TransitionType::LevelChange)
{
MapLogicController::handleMapTransition(game, hit, transitionDef);
}
Expand Down
6 changes: 3 additions & 3 deletions OpenTESArena/src/Voxels/VoxelChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,14 @@ void VoxelChunkManager::populateWildChunkBuildingNames(VoxelChunk &chunk,
}

const TransitionDefinition &transitionDef = chunk.getTransitionDef(transitionDefID);
if (transitionDef.getType() != TransitionType::EnterInterior)
if (transitionDef.type != TransitionType::EnterInterior)
{
continue;
}

const TransitionDefinition::InteriorEntranceDef &interiorEntranceDef = transitionDef.getInteriorEntrance();
const InteriorEntranceTransitionDefinition &interiorEntranceDef = transitionDef.interiorEntrance;
const MapGeneration::InteriorGenInfo &interiorGenInfo = interiorEntranceDef.interiorGenInfo;
const ArenaTypes::InteriorType interiorType = interiorGenInfo.getInteriorType();
const ArenaTypes::InteriorType interiorType = interiorGenInfo.interiorType;

LevelVoxelBuildingNameID buildingNameID;
if (!buildingNameInfo.tryGetBuildingNameID(interiorType, &buildingNameID))
Expand Down
30 changes: 8 additions & 22 deletions OpenTESArena/src/World/MapGeneration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1758,16 +1758,16 @@ namespace MapGeneration
}

const TransitionDefinition &transitionDef = outLevelInfoDef->getTransitionDef(*transitionDefID);
const TransitionType transitionType = transitionDef.getType();
const TransitionType transitionType = transitionDef.type;
if (transitionType != TransitionType::EnterInterior)
{
// Not a transition to an interior.
return std::nullopt;
}

const auto &interiorEntranceDef = transitionDef.getInteriorEntrance();
const InteriorEntranceTransitionDefinition &interiorEntranceDef = transitionDef.interiorEntrance;
const InteriorGenInfo &interiorGenInfo = interiorEntranceDef.interiorGenInfo;
return interiorGenInfo.getInteriorType();
return interiorGenInfo.interiorType;
};

// Lambda for looping through main-floor voxels and generating names for *MENU blocks that
Expand Down Expand Up @@ -2057,16 +2057,16 @@ namespace MapGeneration
{
const LevelTransitionPlacementDefinition &placementDef = levelDef.getTransitionPlacementDef(i);
const TransitionDefinition &transitionDef = outLevelInfoDef->getTransitionDef(placementDef.id);
const TransitionType transitionType = transitionDef.getType();
const TransitionType transitionType = transitionDef.type;
if (transitionType != TransitionType::EnterInterior)
{
// Not a transition to an interior.
continue;
}

const auto &interiorEntranceDef = transitionDef.getInteriorEntrance();
const InteriorEntranceTransitionDefinition &interiorEntranceDef = transitionDef.interiorEntrance;
const InteriorGenInfo &interiorGenInfo = interiorEntranceDef.interiorGenInfo;
if (interiorGenInfo.getInteriorType() != interiorType)
if (interiorGenInfo.interiorType != interiorType)
{
// Not the interior we're generating a name for.
continue;
Expand Down Expand Up @@ -2141,31 +2141,17 @@ MapGeneration::InteriorGenInfo::InteriorGenInfo()
void MapGeneration::InteriorGenInfo::initPrefab(const std::string &mifName, ArenaTypes::InteriorType interiorType, const std::optional<bool> &rulerIsMale)
{
this->type = InteriorGenType::Prefab;
this->interiorType = interiorType;
this->prefab.init(mifName, interiorType, rulerIsMale);
}

void MapGeneration::InteriorGenInfo::initDungeon(const LocationDungeonDefinition &dungeonDef, bool isArtifactDungeon)
{
this->type = InteriorGenType::Dungeon;
this->interiorType = ArenaTypes::InteriorType::Dungeon;
this->dungeon.init(dungeonDef, isArtifactDungeon);
}

ArenaTypes::InteriorType MapGeneration::InteriorGenInfo::getInteriorType() const
{
if (this->type == InteriorGenType::Prefab)
{
return this->prefab.interiorType;
}
else if (this->type == InteriorGenType::Dungeon)
{
return ArenaTypes::InteriorType::Dungeon;
}
else
{
DebugUnhandledReturnMsg(ArenaTypes::InteriorType, std::to_string(static_cast<int>(this->type)));
}
}

void MapGeneration::CityGenInfo::init(std::string &&mifName, std::string &&cityTypeName, ArenaTypes::CityType cityType,
uint32_t citySeed, uint32_t rulerSeed, int raceID, bool isPremade, bool coastal, bool rulerIsMale,
bool palaceIsMainQuestDungeon, Buffer<uint8_t> &&reservedBlocks,
Expand Down
3 changes: 1 addition & 2 deletions OpenTESArena/src/World/MapGeneration.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,14 @@ namespace MapGeneration
struct InteriorGenInfo
{
InteriorGenType type;
ArenaTypes::InteriorType interiorType;
InteriorPrefabGenInfo prefab;
InteriorDungeonGenInfo dungeon;

InteriorGenInfo();

void initPrefab(const std::string &mifName, ArenaTypes::InteriorType interiorType, const std::optional<bool> &rulerIsMale);
void initDungeon(const LocationDungeonDefinition &dungeonDef, bool isArtifactDungeon);

ArenaTypes::InteriorType getInteriorType() const;
};

// Input: 1 .MIF + 1 weather .INF
Expand Down
10 changes: 5 additions & 5 deletions OpenTESArena/src/World/MapLogicController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void MapLogicController::handleTriggers(Game &game, const CoordInt3 &coord, Text

void MapLogicController::handleMapTransition(Game &game, const RayCastHit &hit, const TransitionDefinition &transitionDef)
{
const TransitionType transitionType = transitionDef.getType();
const TransitionType transitionType = transitionDef.type;
DebugAssert(transitionType != TransitionType::LevelChange);

DebugAssert(hit.type == RayCastHitType::Voxel);
Expand Down Expand Up @@ -235,13 +235,13 @@ void MapLogicController::handleMapTransition(Game &game, const RayCastHit &hit,
return hitCoord + delta;
}();

const TransitionDefinition::InteriorEntranceDef &interiorEntranceDef = transitionDef.getInteriorEntrance();
const InteriorEntranceTransitionDefinition &interiorEntranceDef = transitionDef.interiorEntrance;
const MapGeneration::InteriorGenInfo &interiorGenInfo = interiorEntranceDef.interiorGenInfo;

MapDefinition mapDefinition;
if (!mapDefinition.initInterior(interiorGenInfo, textureManager))
{
DebugLogError("Couldn't init MapDefinition for interior type " + std::to_string(static_cast<int>(interiorGenInfo.getInteriorType())) + ".");
DebugLogError("Couldn't init MapDefinition for interior type " + std::to_string(static_cast<int>(interiorGenInfo.interiorType)) + ".");
return;
}

Expand Down Expand Up @@ -592,11 +592,11 @@ void MapLogicController::handleLevelTransition(Game &game, const CoordInt3 &play
};

// See if it's a level up or level down transition. Ignore other transition types.
if (transitionDef.getType() == TransitionType::LevelChange)
if (transitionDef.type == TransitionType::LevelChange)
{
const int activeLevelIndex = gameState.getActiveLevelIndex();
const int levelCount = interiorMapDef.getLevels().getCount();
const TransitionDefinition::LevelChangeDef &levelChangeDef = transitionDef.getLevelChange();
const LevelChangeTransitionDefinition &levelChangeDef = transitionDef.levelChange;
if (levelChangeDef.isLevelUp)
{
// Level up transition. If the custom function has a target, call it and reset it (necessary
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/World/MapLogicController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

class Game;
class TextBox;
class TransitionDefinition;

struct RayCastHit;
struct TransitionDefinition;

namespace MapLogicController
{
Expand Down
34 changes: 6 additions & 28 deletions OpenTESArena/src/World/TransitionDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include "components/debug/Debug.h"

void TransitionDefinition::InteriorEntranceDef::init(MapGeneration::InteriorGenInfo &&interiorGenInfo)
void InteriorEntranceTransitionDefinition::init(MapGeneration::InteriorGenInfo &&interiorGenInfo)
{
this->interiorGenInfo = std::move(interiorGenInfo);
}

void TransitionDefinition::LevelChangeDef::init(bool isLevelUp)
void LevelChangeTransitionDefinition::init(bool isLevelUp)
{
this->isLevelUp = isLevelUp;
}
Expand All @@ -17,46 +17,24 @@ TransitionDefinition::TransitionDefinition()
this->type = static_cast<TransitionType>(-1);
}

void TransitionDefinition::init(TransitionType type)
{
this->type = type;
}

void TransitionDefinition::initCityGate()
{
this->init(TransitionType::CityGate);
this->type = TransitionType::CityGate;
}

void TransitionDefinition::initInteriorEntrance(MapGeneration::InteriorGenInfo &&interiorGenInfo)
{
this->init(TransitionType::EnterInterior);
this->type = TransitionType::EnterInterior;
this->interiorEntrance.init(std::move(interiorGenInfo));
}

void TransitionDefinition::initInteriorExit()
{
this->init(TransitionType::ExitInterior);
this->type = TransitionType::ExitInterior;
}

void TransitionDefinition::initLevelChange(bool isLevelUp)
{
this->init(TransitionType::LevelChange);
this->type = TransitionType::LevelChange;
this->levelChange.init(isLevelUp);
}

TransitionType TransitionDefinition::getType() const
{
return this->type;
}

const TransitionDefinition::InteriorEntranceDef &TransitionDefinition::getInteriorEntrance() const
{
DebugAssert(this->type == TransitionType::EnterInterior);
return this->interiorEntrance;
}

const TransitionDefinition::LevelChangeDef &TransitionDefinition::getLevelChange() const
{
DebugAssert(this->type == TransitionType::LevelChange);
return this->levelChange;
}
37 changes: 15 additions & 22 deletions OpenTESArena/src/World/TransitionDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,33 @@
#include "MapGeneration.h"
#include "TransitionType.h"

// @todo: share with both voxels and entities; probably delete EntityDefinition variant of this class.
class TransitionDefinition
struct InteriorEntranceTransitionDefinition
{
public:
struct InteriorEntranceDef
{
MapGeneration::InteriorGenInfo interiorGenInfo;
MapGeneration::InteriorGenInfo interiorGenInfo;

void init(MapGeneration::InteriorGenInfo &&interiorGenInfo);
};

void init(MapGeneration::InteriorGenInfo &&interiorGenInfo);
};
struct LevelChangeTransitionDefinition
{
bool isLevelUp;

struct LevelChangeDef
{
bool isLevelUp;
void init(bool isLevelUp);
};

void init(bool isLevelUp);
};
private:
// @todo: share with both voxels and entities; probably delete EntityDefinition variant of this class.
struct TransitionDefinition
{
TransitionType type;
InteriorEntranceDef interiorEntrance;
LevelChangeDef levelChange;
InteriorEntranceTransitionDefinition interiorEntrance;
LevelChangeTransitionDefinition levelChange;

void init(TransitionType type);
public:
TransitionDefinition();

void initCityGate();
void initInteriorEntrance(MapGeneration::InteriorGenInfo &&interiorGenInfo);
void initInteriorExit();
void initLevelChange(bool isLevelUp);

TransitionType getType() const;
const InteriorEntranceDef &getInteriorEntrance() const;
const LevelChangeDef &getLevelChange() const;
};

#endif

0 comments on commit 70e1774

Please sign in to comment.