From aa1aab229f90e791d8b5936b1eee03fb1656f198 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Thu, 1 Jan 2015 20:55:41 +0000 Subject: [PATCH 13/14] TrackPiece and TrackVoxel --- src/coaster.cpp | 4 ++-- src/track_piece.cpp | 21 +++++++++++---------- src/track_piece.h | 12 ++++-------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/coaster.cpp b/src/coaster.cpp index dd2d535..21c929c 100644 --- a/src/coaster.cpp +++ b/src/coaster.cpp @@ -787,7 +787,7 @@ void CoasterInstance::PlaceTrackPieceInAdditions(const PositionedTrackPiece &pla const CoasterType *ct = this->GetCoasterType(); const TrackVoxel *tvx = placed.piece->track_voxels; for (int i = 0; i < placed.piece->voxel_count; i++) { - Voxel *vx = _additions.GetCreateVoxel(placed.base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz), true); + Voxel *vx = _additions.GetCreateVoxel(placed.base_voxel + tvx->dxyz, true); // assert(vx->CanPlaceInstance()): Checked by this->CanBePlaced(). vx->SetInstance(ride_number); vx->SetInstanceData(ct->GetTrackVoxelIndex(tvx)); @@ -803,7 +803,7 @@ void CoasterInstance::RemoveTrackPieceInAdditions(const PositionedTrackPiece &pl { const TrackVoxel *tvx = placed.piece->track_voxels; for (int i = 0; i < placed.piece->voxel_count; i++) { - Voxel *vx = _additions.GetCreateVoxel(placed.base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz), false); + Voxel *vx = _additions.GetCreateVoxel(placed.base_voxel + tvx->dxyz, false); assert(vx->GetInstance() == (SmallRideInstance)this->GetIndex()); vx->SetInstance(SRI_FREE); vx->SetInstanceData(0); // Not really needed. diff --git a/src/track_piece.cpp b/src/track_piece.cpp index 4b45d54..9397ab1 100644 --- a/src/track_piece.cpp +++ b/src/track_piece.cpp @@ -42,9 +42,9 @@ bool TrackVoxel::Load(RcdFileReader *rcd_file, size_t length, const ImageMap &sp for (uint i = 0; i < 4; i++) { if (!LoadSpriteFromFile(rcd_file, sprites, &this->front[i])) return false; } - this->dx = rcd_file->GetInt8(); - this->dy = rcd_file->GetInt8(); - this->dz = rcd_file->GetInt8(); + this->dxyz.x = rcd_file->GetInt8(); + this->dxyz.y = rcd_file->GetInt8(); + this->dxyz.z = rcd_file->GetInt8(); this->flags = rcd_file->GetUInt8(); return true; } @@ -196,9 +196,9 @@ bool TrackPiece::Load(RcdFileReader *rcd_file, const ImageMap &sprites) this->entry_connect = rcd_file->GetUInt8(); this->exit_connect = rcd_file->GetUInt8(); - this->exit_dx = rcd_file->GetInt8(); - this->exit_dy = rcd_file->GetInt8(); - this->exit_dz = rcd_file->GetInt8(); + this->exit_dxyz.x = rcd_file->GetInt8(); + this->exit_dxyz.y = rcd_file->GetInt8(); + this->exit_dxyz.z = rcd_file->GetInt8(); this->speed = rcd_file->GetInt8(); this->track_flags = rcd_file->GetUInt16(); this->cost = rcd_file->GetUInt32(); @@ -246,10 +246,10 @@ bool PositionedTrackPiece::IsOnWorld() const { assert(this->piece != nullptr); if (!IsVoxelInsideWorld(this->base_voxel)) return false; - if (!IsVoxelInsideWorld(this->base_voxel + XYZPoint16(this->piece->exit_dx, this->piece->exit_dy, this->piece->exit_dz))) return false; + if (!IsVoxelInsideWorld(this->GetEndXYZ())) return false; const TrackVoxel *tvx = this->piece->track_voxels; for (int i = 0; i < this->piece->voxel_count; i++) { - if (!IsVoxelInsideWorld(this->base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz))) return false; + if (!IsVoxelInsideWorld(this->base_voxel + tvx->dxyz)) return false; tvx++; } return true; @@ -266,8 +266,9 @@ bool PositionedTrackPiece::CanBePlaced() const const TrackVoxel *tvx = this->piece->track_voxels; for (int i = 0; i < this->piece->voxel_count; i++) { /* Is the voxel above ground level? */ - if (_world.GetGroundHeight(this->base_voxel.x + tvx->dx, this->base_voxel.y + tvx->dy) > this->base_voxel.z + tvx->dz) return false; - const Voxel *vx = _world.GetVoxel(this->base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz)); + const XYZPoint16 part_pos = this->base_voxel + tvx->dxyz; + if (_world.GetGroundHeight(part_pos.x, part_pos.y) > part_pos.z) return false; + const Voxel *vx = _world.GetVoxel(part_pos); if (vx != nullptr && !vx->CanPlaceInstance()) return false; } return true; diff --git a/src/track_piece.h b/src/track_piece.h index f8bae37..b7be286 100644 --- a/src/track_piece.h +++ b/src/track_piece.h @@ -49,10 +49,8 @@ struct TrackVoxel { ImageData *back[4]; ///< Reference to the background tracks (N/E/S/W view). ImageData *front[4]; ///< Reference to the front tracks (N/E/S/W view). - int8 dx; ///< Relative X position of the voxel. - int8 dy; ///< Relative Y position of the voxel. - int8 dz; ///< Relative Z position of the voxel. - uint8 flags; ///< Flags of the voxel (space requirements, platform direction). + XYZPoint16 dxyz; ///< Relative position of the voxel. + uint8 flags; ///< Flags of the voxel (space requirements, platform direction). }; /** Banking of the track piece. */ @@ -170,9 +168,7 @@ public: uint8 entry_connect; ///< Entry connection code uint8 exit_connect; ///< Exit connection code - int8 exit_dx; ///< Relative X position of the exit voxel. - int8 exit_dy; ///< Relative Y position of the exit voxel. - int8 exit_dz; ///< Relative Z position of the exit voxel. + XYZPoint16 exit_dxyz; ///< Relative position of the exit voxel. int8 speed; ///< If non-zero, the minimal speed of cars at the track. uint16 track_flags; ///< Flags of the track piece. Money cost; ///< Cost of this track piece. @@ -293,7 +289,7 @@ public: */ inline XYZPoint16 GetEndXYZ() const { - return this->base_voxel + XYZPoint16(this->piece->exit_dx, this->piece->exit_dy, this->piece->exit_dz); + return this->base_voxel + this->piece->exit_dxyz; } XYZPoint16 base_voxel; ///< Position (in voxels) of the entry point of the track piece. -- 2.2.1