Skip to content

Commit

Permalink
Renamed voxel def IDs for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
afritz1 committed Jan 1, 2025
1 parent 99b60cd commit bf58f65
Show file tree
Hide file tree
Showing 24 changed files with 395 additions and 397 deletions.
2 changes: 1 addition & 1 deletion OpenTESArena/src/Collision/CollisionChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ CollisionChunk::CollisionShapeDefID CollisionChunk::addCollisionShapeDef(Collisi
return id;
}

CollisionChunk::CollisionShapeDefID CollisionChunk::getOrAddShapeDefIdMapping(const VoxelChunk &voxelChunk, VoxelChunk::VoxelShapeDefID voxelShapeDefID)
CollisionChunk::CollisionShapeDefID CollisionChunk::getOrAddShapeDefIdMapping(const VoxelChunk &voxelChunk, VoxelShapeDefID voxelShapeDefID)
{
CollisionChunk::CollisionShapeDefID collisionShapeDefID = -1;

Expand Down
4 changes: 2 additions & 2 deletions OpenTESArena/src/Collision/CollisionChunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class CollisionChunk final : public Chunk
using CollisionShapeDefID = int;

std::vector<CollisionShapeDefinition> shapeDefs;
std::unordered_map<VoxelChunk::VoxelShapeDefID, CollisionChunk::CollisionShapeDefID> shapeMappings;
std::unordered_map<VoxelShapeDefID, CollisionChunk::CollisionShapeDefID> shapeMappings;
Buffer3D<CollisionShapeDefID> shapeDefIDs;
Buffer3D<bool> enabledColliders; // @todo: decide if this is obsolete and whether the Body can store its in/out of world state
Buffer3D<JPH::BodyID> physicsBodyIDs;
Expand All @@ -33,7 +33,7 @@ class CollisionChunk final : public Chunk
int getCollisionShapeDefCount() const;
const CollisionShapeDefinition &getCollisionShapeDef(CollisionShapeDefID id) const;
CollisionShapeDefID addCollisionShapeDef(CollisionShapeDefinition &&shapeDef);
CollisionChunk::CollisionShapeDefID getOrAddShapeDefIdMapping(const VoxelChunk &voxelChunk, VoxelChunk::VoxelShapeDefID voxelShapeDefID);
CollisionChunk::CollisionShapeDefID getOrAddShapeDefIdMapping(const VoxelChunk &voxelChunk, VoxelShapeDefID voxelShapeDefID);
};

#endif
16 changes: 8 additions & 8 deletions OpenTESArena/src/Collision/CollisionChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ void CollisionChunkManager::populateChunk(int index, double ceilingScale, const
{
for (SNInt x = 0; x < Chunk::WIDTH; x++)
{
const VoxelChunk::VoxelShapeDefID voxelShapeDefID = voxelChunk.getShapeDefID(x, y, z);
const VoxelShapeDefID voxelShapeDefID = voxelChunk.getShapeDefID(x, y, z);
const CollisionChunk::CollisionShapeDefID collisionShapeDefID = collisionChunk.getOrAddShapeDefIdMapping(voxelChunk, voxelShapeDefID);
collisionChunk.shapeDefIDs.set(x, y, z, collisionShapeDefID);

const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = voxelChunk.getTraitsDefID(x, y, z);
const VoxelTraitsDefID voxelTraitsDefID = voxelChunk.getTraitsDefID(x, y, z);
const VoxelTraitsDefinition &voxelTraitsDef = voxelChunk.getTraitsDef(voxelTraitsDefID);
const bool voxelHasCollision = voxelTraitsDef.hasCollision();
collisionChunk.enabledColliders.set(x, y, z, voxelHasCollision);

VoxelChunk::TriggerDefID triggerDefID;
VoxelTriggerDefID triggerDefID;
const bool isTriggerVoxel = voxelChunk.tryGetTriggerDefID(x, y, z, &triggerDefID);

VoxelChunk::TransitionDefID transitionDefID;
VoxelTransitionDefID transitionDefID;
const bool isTransitionVoxel = voxelChunk.tryGetTransitionDefID(x, y, z, &transitionDefID);
const bool isSensorCollider = isTriggerVoxel || isTransitionVoxel;
const bool shouldCreateCollider = voxelHasCollision || isSensorCollider;
Expand Down Expand Up @@ -143,11 +143,11 @@ void CollisionChunkManager::updateDirtyVoxels(const ChunkInt2 &chunkPos, double
const SNInt x = voxelPos.x;
const int y = voxelPos.y;
const WEInt z = voxelPos.z;
const VoxelChunk::VoxelShapeDefID voxelShapeDefID = voxelChunk.getShapeDefID(x, y, z);
const VoxelShapeDefID voxelShapeDefID = voxelChunk.getShapeDefID(x, y, z);
const CollisionChunk::CollisionShapeDefID collisionShapeDefID = collisionChunk.getOrAddShapeDefIdMapping(voxelChunk, voxelShapeDefID);
collisionChunk.shapeDefIDs.set(x, y, z, collisionShapeDefID);

const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = voxelChunk.getTraitsDefID(x, y, z);
const VoxelTraitsDefID voxelTraitsDefID = voxelChunk.getTraitsDefID(x, y, z);
const VoxelTraitsDefinition &voxelTraitsDef = voxelChunk.getTraitsDef(voxelTraitsDefID);
const bool voxelHasCollision = voxelTraitsDef.hasCollision();
collisionChunk.enabledColliders.set(x, y, z, voxelHasCollision);
Expand All @@ -164,10 +164,10 @@ void CollisionChunkManager::updateDirtyVoxels(const ChunkInt2 &chunkPos, double
collisionChunk.physicsBodyIDs.set(x, y, z, Physics::INVALID_BODY_ID);
}

VoxelChunk::TriggerDefID triggerDefID;
VoxelTriggerDefID triggerDefID;
const bool isTriggerVoxel = voxelChunk.tryGetTriggerDefID(x, y, z, &triggerDefID);

VoxelChunk::TransitionDefID transitionDefID;
VoxelTransitionDefID transitionDefID;
const bool isTransitionVoxel = voxelChunk.tryGetTransitionDefID(x, y, z, &transitionDefID);
const bool isSensorCollider = isTriggerVoxel || isTransitionVoxel;
const bool shouldCreateCollider = voxelHasCollision || isSensorCollider;
Expand Down
4 changes: 2 additions & 2 deletions OpenTESArena/src/Collision/Physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ namespace Physics
return false;
}

const VoxelChunk::VoxelShapeDefID voxelShapeDefID = voxelChunk->getShapeDefID(voxel.x, voxel.y, voxel.z);
const VoxelShapeDefID voxelShapeDefID = voxelChunk->getShapeDefID(voxel.x, voxel.y, voxel.z);
const VoxelShapeDefinition &voxelShapeDef = voxelChunk->getShapeDef(voxelShapeDefID);
const VoxelShapeScaleType scaleType = voxelShapeDef.scaleType;

Expand Down Expand Up @@ -327,7 +327,7 @@ namespace Physics
return false;
}

const VoxelChunk::VoxelShapeDefID voxelShapeDefID = voxelChunk->getShapeDefID(voxel.x, voxel.y, voxel.z);
const VoxelShapeDefID voxelShapeDefID = voxelChunk->getShapeDefID(voxel.x, voxel.y, voxel.z);
const VoxelShapeDefinition &voxelShapeDef = voxelChunk->getShapeDef(voxelShapeDefID);
const VoxelShapeScaleType scaleType = voxelShapeDef.scaleType;

Expand Down
14 changes: 7 additions & 7 deletions OpenTESArena/src/Entities/EntityChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void EntityChunkManager::populateChunkEntities(EntityChunk &entityChunk, const V
for (int i = 0; i < levelDefinition.getEntityPlacementDefCount(); i++)
{
const LevelDefinition::EntityPlacementDef &placementDef = levelDefinition.getEntityPlacementDef(i);
const LevelDefinition::EntityDefID levelEntityDefID = placementDef.id;
const LevelVoxelEntityDefID levelEntityDefID = placementDef.id;
const EntityDefinition &entityDef = levelInfoDefinition.getEntityDef(levelEntityDefID);
const EntityDefinitionType entityDefType = entityDef.getType();
const bool isDynamicEntity = EntityUtils::isDynamicEntity(entityDefType);
Expand Down Expand Up @@ -300,8 +300,8 @@ void EntityChunkManager::populateChunkEntities(EntityChunk &entityChunk, const V
for (int spawnTry = 0; spawnTry < spawnTriesCount; spawnTry++)
{
const VoxelInt2 spawnVoxel(random.next(Chunk::WIDTH), random.next(Chunk::DEPTH));
const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = voxelChunk.getTraitsDefID(spawnVoxel.x, 1, spawnVoxel.y);
const VoxelChunk::VoxelTraitsDefID groundVoxelTraitsDefID = voxelChunk.getTraitsDefID(spawnVoxel.x, 0, spawnVoxel.y);
const VoxelTraitsDefID voxelTraitsDefID = voxelChunk.getTraitsDefID(spawnVoxel.x, 1, spawnVoxel.y);
const VoxelTraitsDefID groundVoxelTraitsDefID = voxelChunk.getTraitsDefID(spawnVoxel.x, 0, spawnVoxel.y);
const VoxelTraitsDefinition &voxelTraitsDef = voxelChunk.getTraitsDef(voxelTraitsDefID);
const VoxelTraitsDefinition &groundVoxelTraitsDef = voxelChunk.getTraitsDef(groundVoxelTraitsDefID);

Expand Down Expand Up @@ -559,15 +559,15 @@ void EntityChunkManager::updateCitizenStates(double dt, EntityChunk &entityChunk
auto isPassableVoxel = [&coord, voxelChunk]()
{
const VoxelInt3 voxel(coord.voxel.x, 1, coord.voxel.y);
const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = voxelChunk->getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefID voxelTraitsDefID = voxelChunk->getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefinition &voxelTraitsDef = voxelChunk->getTraitsDef(voxelTraitsDefID);
return voxelTraitsDef.type == ArenaTypes::VoxelType::None;
};

auto isWalkableVoxel = [&coord, voxelChunk]()
{
const VoxelInt3 voxel(coord.voxel.x, 0, coord.voxel.y);
const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = voxelChunk->getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefID voxelTraitsDefID = voxelChunk->getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefinition &voxelTraitsDef = voxelChunk->getTraitsDef(voxelTraitsDefID);
return voxelTraitsDef.type == ArenaTypes::VoxelType::Floor;
};
Expand Down Expand Up @@ -873,13 +873,13 @@ double EntityChunkManager::getEntityCorrectedY(EntityInstanceID id, double ceili

// If they are in a raised platform voxel, they are set on top of it.
double raisedPlatformYOffset = 0.0;
const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = chunk->getTraitsDefID(entityVoxelCoord.voxel.x, entityVoxelY, entityVoxelCoord.voxel.y);
const VoxelTraitsDefID voxelTraitsDefID = chunk->getTraitsDefID(entityVoxelCoord.voxel.x, entityVoxelY, entityVoxelCoord.voxel.y);
const VoxelTraitsDefinition &voxelTraitsDef = chunk->getTraitsDef(voxelTraitsDefID);
if (voxelTraitsDef.type == ArenaTypes::VoxelType::Raised)
{
const VoxelTraitsDefinition::Raised &raised = voxelTraitsDef.raised;
const double shapeYPos = raised.yOffset + raised.ySize;
const VoxelChunk::VoxelShapeDefID voxelShapeDefID = chunk->getShapeDefID(entityVoxelCoord.voxel.x, entityVoxelY, entityVoxelCoord.voxel.y);
const VoxelShapeDefID voxelShapeDefID = chunk->getShapeDefID(entityVoxelCoord.voxel.x, entityVoxelY, entityVoxelCoord.voxel.y);
const VoxelShapeDefinition &voxelShapeDef = chunk->getShapeDef(voxelShapeDefID);
raisedPlatformYOffset = MeshUtils::getScaledVertexY(shapeYPos, voxelShapeDef.scaleType, ceilingScale);
}
Expand Down
4 changes: 2 additions & 2 deletions OpenTESArena/src/Entities/EntityDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ EntityDefinition::TransitionDefinition::TransitionDefinition()
this->transitionDefID = -1;
}

void EntityDefinition::TransitionDefinition::init(LevelDefinition::TransitionDefID transitionDefID)
void EntityDefinition::TransitionDefinition::init(LevelVoxelTransitionDefID transitionDefID)
{
this->transitionDefID = transitionDefID;
}
Expand Down Expand Up @@ -785,7 +785,7 @@ void EntityDefinition::initVfx(VfxEntityAnimationType type, int index, EntityAni
this->vfx.init(type, index);
}

void EntityDefinition::initTransition(LevelDefinition::TransitionDefID defID,
void EntityDefinition::initTransition(LevelVoxelTransitionDefID defID,
EntityAnimationDefinition &&animDef)
{
this->init(EntityDefinitionType::Transition, std::move(animDef));
Expand Down
6 changes: 3 additions & 3 deletions OpenTESArena/src/Entities/EntityDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ class EntityDefinition
// Should be fine to store this ID that points into a LevelInfoDefinition since transition
// entities should only exist on the level they're spawned and wouldn't be globally reusable
// like some entity definitions.
LevelDefinition::TransitionDefID transitionDefID;
LevelVoxelTransitionDefID transitionDefID;

TransitionDefinition();

void init(LevelDefinition::TransitionDefID transitionDefID);
void init(LevelVoxelTransitionDefID transitionDefID);

bool operator==(const TransitionDefinition &other) const;
};
Expand Down Expand Up @@ -363,7 +363,7 @@ class EntityDefinition

void initVfx(VfxEntityAnimationType type, int index, EntityAnimationDefinition &&animDef);

void initTransition(LevelDefinition::TransitionDefID defID, EntityAnimationDefinition &&animDef);
void initTransition(LevelVoxelTransitionDefID defID, EntityAnimationDefinition &&animDef);

void initDoodad(int yOffset, double scale, bool collider, bool transparent, bool ceiling, bool streetlight, bool puddle,
int lightIntensity, EntityAnimationDefinition &&animDef);
Expand Down
6 changes: 3 additions & 3 deletions OpenTESArena/src/Interface/AutomapUiView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ Buffer2D<uint32_t> AutomapUiView::makeAutomap(const CoordInt2 &playerCoord, Card
{
for (WEInt z = 0; z < ChunkUtils::CHUNK_DIM; z++)
{
const VoxelChunk::VoxelTraitsDefID floorVoxelTraitsDefID = chunk.getTraitsDefID(x, 0, z);
const VoxelChunk::VoxelTraitsDefID wallVoxelTraitsDefID = chunk.getTraitsDefID(x, 1, z);
const VoxelTraitsDefID floorVoxelTraitsDefID = chunk.getTraitsDefID(x, 0, z);
const VoxelTraitsDefID wallVoxelTraitsDefID = chunk.getTraitsDefID(x, 1, z);
const VoxelTraitsDefinition &floorVoxelTraitsDef = chunk.getTraitsDef(floorVoxelTraitsDefID);
const VoxelTraitsDefinition &wallVoxelTraitsDef = chunk.getTraitsDef(wallVoxelTraitsDefID);

VoxelChunk::TransitionDefID transitionDefID;
VoxelTransitionDefID transitionDefID;
const TransitionDefinition *transitionDef = nullptr;
if (chunk.tryGetTransitionDefID(x, 1, z, &transitionDefID))
{
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Interface/GameWorldUiView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ void GameWorldUiView::DEBUG_PhysicsRaycast(Game &game)

const RayCastVoxelHit &voxelHit = hit.voxelHit;
const VoxelInt3 &voxel = voxelHit.voxel;
const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = chunk.getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefID voxelTraitsDefID = chunk.getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefinition &voxelTraitsDef = chunk.getTraitsDef(voxelTraitsDefID);

text = "Voxel: (" + voxel.toString() + "), " + std::to_string(static_cast<int>(voxelTraitsDef.type)) + ' ' + std::to_string(hit.t);
Expand Down
8 changes: 4 additions & 4 deletions OpenTESArena/src/Player/PlayerLogicController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ void PlayerLogicController::handleScreenToWorldInteraction(Game &game, const Int
VoxelChunk &chunk = voxelChunkManager.getChunkAtPosition(chunkPos);
const RayCastVoxelHit &voxelHit = hit.voxelHit;
const VoxelInt3 &voxel = voxelHit.voxel;
const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = chunk.getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefID voxelTraitsDefID = chunk.getTraitsDefID(voxel.x, voxel.y, voxel.z);
const VoxelTraitsDefinition &voxelTraitsDef = chunk.getTraitsDef(voxelTraitsDefID);
const ArenaTypes::VoxelType voxelType = voxelTraitsDef.type;

Expand All @@ -626,7 +626,7 @@ void PlayerLogicController::handleScreenToWorldInteraction(Game &game, const Int

if (isWall || isEdge)
{
VoxelChunk::TransitionDefID transitionDefID;
VoxelTransitionDefID transitionDefID;
if (chunk.tryGetTransitionDefID(voxel.x, voxel.y, voxel.z, &transitionDefID))
{
const TransitionDefinition &transitionDef = chunk.getTransitionDef(transitionDefID);
Expand Down Expand Up @@ -662,7 +662,7 @@ void PlayerLogicController::handleScreenToWorldInteraction(Game &game, const Int
chunk.addDoorAnimInst(std::move(newDoorAnimInst));

// Get the door's opening sound and play it at the center of the voxel.
VoxelChunk::DoorDefID doorDefID;
VoxelDoorDefID doorDefID;
if (!chunk.tryGetDoorDefID(voxel.x, voxel.y, voxel.z, &doorDefID))
{
DebugCrash("Expected door def ID to exist.");
Expand All @@ -686,7 +686,7 @@ void PlayerLogicController::handleScreenToWorldInteraction(Game &game, const Int
// Handle secondary click (i.e. right click).
if (ArenaSelectionUtils::isVoxelSelectableAsSecondary(voxelType))
{
VoxelChunk::BuildingNameID buildingNameID;
VoxelBuildingNameID buildingNameID;
if (chunk.tryGetBuildingNameID(voxel.x, voxel.y, voxel.z, &buildingNameID))
{
const std::string &buildingName = chunk.getBuildingName(buildingNameID);
Expand Down
4 changes: 2 additions & 2 deletions OpenTESArena/src/Rendering/RenderVoxelChunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ class RenderVoxelChunk final : public Chunk
static constexpr RenderVoxelMeshInstID AIR_MESH_INST_ID = 0;

std::vector<RenderVoxelMeshInstance> meshInsts;
std::unordered_map<VoxelChunk::VoxelShapeDefID, RenderVoxelMeshInstID> meshInstMappings; // Note: this doesn't support VoxelIDs changing which def they point to (important if VoxelChunk::removeVoxelDef() is ever in use).
std::unordered_map<VoxelShapeDefID, RenderVoxelMeshInstID> meshInstMappings; // Note: this doesn't support VoxelIDs changing which def they point to (important if VoxelChunk::removeVoxelDef() is ever in use).
Buffer3D<RenderVoxelMeshInstID> meshInstIDs; // Points into mesh instances.
std::unordered_map<VoxelChunk::ChasmDefID, ObjectTextureID> activeChasmFloorTextureIDs; // Updated every frame, shared by chasms in this chunk, owned by RenderVoxelChunkManager.
std::unordered_map<VoxelChasmDefID, ObjectTextureID> activeChasmFloorTextureIDs; // Updated every frame, shared by chasms in this chunk, owned by RenderVoxelChunkManager.
std::unordered_map<VoxelInt3, IndexBufferID> chasmWallIndexBufferIDsMap; // If an index buffer ID exists for a voxel, it adds a draw call for the chasm wall. IDs are owned by the render chunk manager.
UniformBufferID transformBufferID; // One RenderTransform buffer for all voxels, though doors are handled separately. Owned by this chunk.
std::unordered_map<VoxelInt3, UniformBufferID> doorTransformBuffers; // Unique transform buffer per door instance, owned by this chunk. Four RenderTransforms (one per door face) per buffer.
Expand Down
Loading

0 comments on commit bf58f65

Please sign in to comment.