From 79839e60731da936718674f1e095e35e61837d9c Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Thu, 1 Jan 2015 20:46:46 +0000 Subject: [PATCH 12/14] further tidyups --- src/coaster.cpp | 4 ++-- src/map.h | 8 +++----- src/path_build.cpp | 10 ++++------ src/track_piece.cpp | 9 ++++----- src/track_piece.h | 4 +--- 5 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/coaster.cpp b/src/coaster.cpp index e3556b1..dd2d535 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(XYZPoint16(placed.base_voxel.x + tvx->dx, placed.base_voxel.y + tvx->dy, placed.base_voxel.z + tvx->dz), true); + Voxel *vx = _additions.GetCreateVoxel(placed.base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz), 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(XYZPoint16(placed.base_voxel.x + tvx->dx, placed.base_voxel.y + tvx->dy, placed.base_voxel.z + tvx->dz), false); + Voxel *vx = _additions.GetCreateVoxel(placed.base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz), false); assert(vx->GetInstance() == (SmallRideInstance)this->GetIndex()); vx->SetInstance(SRI_FREE); vx->SetInstanceData(0); // Not really needed. diff --git a/src/map.h b/src/map.h index 23a4f3a..dc7a0e5 100644 --- a/src/map.h +++ b/src/map.h @@ -643,14 +643,12 @@ static inline bool IsVoxelstackInsideWorld(int x, int y) /** * Is the given world voxel coordinate within the world boundaries? - * @param x X position of the voxel. - * @param y Y position of the voxel. - * @param z Z position of the voxel. + * @param vox Position of the voxel. * @return %Voxel coordinate is within world boundaries. */ -static inline bool IsVoxelInsideWorld(int x, int y, int z) +static inline bool IsVoxelInsideWorld(const XYZPoint16 &vox) { - return z >= 0 && z < WORLD_Z_SIZE && IsVoxelstackInsideWorld(x, y); + return vox.z >= 0 && vox.z < WORLD_Z_SIZE && IsVoxelstackInsideWorld(vox.x, vox.y); } /** diff --git a/src/path_build.cpp b/src/path_build.cpp index b924f80..43531bf 100644 --- a/src/path_build.cpp +++ b/src/path_build.cpp @@ -568,19 +568,17 @@ XYZPoint16 PathBuildManager::ComputeArrowCursorPosition() assert(this->selected_arrow != INVALID_EDGE); Point16 dxy = _tile_dxy[this->selected_arrow]; - int xpos = this->pos.x + dxy.x; - int ypos = this->pos.y + dxy.y; + XYZPoint16 arr_pos = this->pos + XYZPoint16(dxy.x, dxy.y, 0); uint8 bit = 1 << this->selected_arrow; - int zpos = this->pos.z; if ((bit & this->allowed_arrows) == 0) { // Build direction is not at the bottom of the voxel. assert(((bit << 4) & this->allowed_arrows) != 0); // Should be available at the top of the voxel. - zpos++; + arr_pos.z++; } /* Do some paranoia checking. */ - assert(IsVoxelInsideWorld(xpos, ypos, zpos)); - return XYZPoint16(xpos, ypos, zpos); + assert(IsVoxelInsideWorld(arr_pos)); + return arr_pos; } /** Compute the new contents of the voxel where the path should be added from the #_world. */ diff --git a/src/track_piece.cpp b/src/track_piece.cpp index 6dd60c3..4b45d54 100644 --- a/src/track_piece.cpp +++ b/src/track_piece.cpp @@ -245,12 +245,11 @@ PositionedTrackPiece::PositionedTrackPiece(const XYZPoint16 &vox_pos, ConstTrack bool PositionedTrackPiece::IsOnWorld() const { assert(this->piece != nullptr); - if (!IsVoxelInsideWorld(this->base_voxel.x, this->base_voxel.y, this->base_voxel.z)) return false; - if (!IsVoxelInsideWorld(this->base_voxel.x + this->piece->exit_dx, this->base_voxel.y + this->piece->exit_dy, - this->base_voxel.z + this->piece->exit_dz)) return false; + 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; const TrackVoxel *tvx = this->piece->track_voxels; for (int i = 0; i < this->piece->voxel_count; i++) { - if (!IsVoxelInsideWorld(this->base_voxel.x + tvx->dx, this->base_voxel.y + tvx->dy, this->base_voxel.z + tvx->dz)) return false; + if (!IsVoxelInsideWorld(this->base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz))) return false; tvx++; } return true; @@ -268,7 +267,7 @@ bool PositionedTrackPiece::CanBePlaced() const 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(XYZPoint16(this->base_voxel.x + tvx->dx, this->base_voxel.y + tvx->dy, this->base_voxel.z + tvx->dz)); + const Voxel *vx = _world.GetVoxel(this->base_voxel + XYZPoint16(tvx->dx, tvx->dy, tvx->dz)); if (vx != nullptr && !vx->CanPlaceInstance()) return false; } return true; diff --git a/src/track_piece.h b/src/track_piece.h index 2b5bfec..f8bae37 100644 --- a/src/track_piece.h +++ b/src/track_piece.h @@ -293,9 +293,7 @@ public: */ inline XYZPoint16 GetEndXYZ() const { - return XYZPoint16(this->base_voxel.x + this->piece->exit_dx, - this->base_voxel.y + this->piece->exit_dy, - this->base_voxel.z + this->piece->exit_dz); + return this->base_voxel + XYZPoint16(this->piece->exit_dx, this->piece->exit_dy, this->piece->exit_dz); } XYZPoint16 base_voxel; ///< Position (in voxels) of the entry point of the track piece. -- 2.2.1