Skip to content

Commit

Permalink
Ignore ray cast collisions on some voxels.
Browse files Browse the repository at this point in the history
Drying socks, store signs, and archways can't be hit in the original game.
  • Loading branch information
afritz1 committed Jul 28, 2024
1 parent a21854e commit 46aba3a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
12 changes: 9 additions & 3 deletions OpenTESArena/src/Collision/CollisionChunkManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ void CollisionChunkManager::populateChunk(int index, const ChunkInt2 &chunkPos,
{
for (SNInt x = 0; x < Chunk::WIDTH; x++)
{
// Colliders are dependent on the voxel mesh definition.
// Colliders are dependent on the mesh and any special traits.
const VoxelChunk::VoxelMeshDefID voxelMeshDefID = voxelChunk.getMeshDefID(x, y, z);
const CollisionChunk::CollisionMeshDefID collisionMeshDefID = collisionChunk.getOrAddMeshDefIdMapping(voxelChunk, voxelMeshDefID);
collisionChunk.meshDefIDs.set(x, y, z, collisionMeshDefID);
collisionChunk.enabledColliders.set(x, y, z, true);

const VoxelChunk::VoxelTraitsDefID voxelTraitsDefID = voxelChunk.getTraitsDefID(x, y, z);
const VoxelTraitsDefinition &voxelTraitsDef = voxelChunk.getTraitsDef(voxelTraitsDefID);
collisionChunk.enabledColliders.set(x, y, z, voxelTraitsDef.hasCollision());
}
}
}
Expand All @@ -32,7 +35,10 @@ void CollisionChunkManager::updateDirtyVoxels(const ChunkInt2 &chunkPos, const V
const VoxelChunk::VoxelMeshDefID voxelMeshDefID = voxelChunk.getMeshDefID(voxelPos.x, voxelPos.y, voxelPos.z);
const CollisionChunk::CollisionMeshDefID collisionMeshDefID = collisionChunk.getOrAddMeshDefIdMapping(voxelChunk, voxelMeshDefID);
collisionChunk.meshDefIDs.set(voxelPos.x, voxelPos.y, voxelPos.z, collisionMeshDefID);
collisionChunk.enabledColliders.set(voxelPos.x, voxelPos.y, voxelPos.z, true);

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

for (const VoxelInt3 &voxelPos : voxelChunk.getDirtyDoorAnimInstPositions())
Expand Down
13 changes: 13 additions & 0 deletions OpenTESArena/src/Voxels/VoxelTraitsDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,16 @@ void VoxelTraitsDefinition::initChasm(ArenaTypes::ChasmType chasmType)
this->initGeneral(ArenaTypes::VoxelType::Chasm);
this->chasm.type = chasmType;
}

bool VoxelTraitsDefinition::hasCollision() const
{
switch (this->type)
{
case ArenaTypes::VoxelType::TransparentWall:
return this->transparentWall.collider;
case ArenaTypes::VoxelType::Edge:
return this->edge.collider;
default:
return true;
}
}
2 changes: 2 additions & 0 deletions OpenTESArena/src/Voxels/VoxelTraitsDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct VoxelTraitsDefinition
void initTransparentWall(bool collider);
void initEdge(VoxelFacing2D facing, bool collider);
void initChasm(ArenaTypes::ChasmType chasmType);

bool hasCollision() const;
};

#endif

0 comments on commit 46aba3a

Please sign in to comment.