1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Use getters for all VehicleGeometry tables

This commit is contained in:
Gymnasiast
2025-10-21 21:22:37 +02:00
parent a7aea1ad8b
commit 1e07385ff6
3 changed files with 73 additions and 47 deletions

View File

@@ -2916,8 +2916,9 @@ void Vehicle::UpdateCrashSetup()
lastVehicle = trainVehicle; lastVehicle = trainVehicle;
trainVehicle->sub_state = 0; trainVehicle->sub_state = 0;
int32_t trainX = Geometry::kCrashDirectionComponents[trainVehicle->Orientation / 2].x; auto crashDirection = Geometry::getCrashDirectionComponents(trainVehicle->Orientation);
int32_t trainY = Geometry::kCrashDirectionComponents[trainVehicle->Orientation / 2].y; int32_t trainX = crashDirection.x;
int32_t trainY = crashDirection.y;
auto carLaunchDirection = Geometry::getPitchVector32(trainVehicle->pitch); auto carLaunchDirection = Geometry::getPitchVector32(trainVehicle->pitch);
@@ -3743,7 +3744,7 @@ void Vehicle::UpdateMotionBoatHire()
} }
int32_t edi = (Orientation | (var_35 & 1)) & 0x1F; int32_t edi = (Orientation | (var_35 & 1)) & 0x1F;
loc2 = { x + Geometry::kFreeroamVehicleMovementData[edi].x, y + Geometry::kFreeroamVehicleMovementData[edi].y }; loc2 = { x + Geometry::getFreeroamVehicleMovementData(edi).x, y + Geometry::getFreeroamVehicleMovementData(edi).y };
if (UpdateMotionCollisionDetection({ loc2, z }, nullptr)) if (UpdateMotionCollisionDetection({ loc2, z }, nullptr))
{ {
remaining_distance = 0; remaining_distance = 0;
@@ -3841,7 +3842,7 @@ void Vehicle::UpdateMotionBoatHire()
TrackLocation = { flooredLocation, TrackLocation.z }; TrackLocation = { flooredLocation, TrackLocation.z };
} }
remaining_distance -= Geometry::kFreeroamVehicleMovementData[edi].distance; remaining_distance -= Geometry::getFreeroamVehicleMovementData(edi).distance;
_vehicleCurPosition.x = loc2.x; _vehicleCurPosition.x = loc2.x;
_vehicleCurPosition.y = loc2.y; _vehicleCurPosition.y = loc2.y;
if (remaining_distance < 0x368A) if (remaining_distance < 0x368A)
@@ -4916,7 +4917,7 @@ void Vehicle::UpdateSound()
sound2_volume = soundIdVolume.volume; sound2_volume = soundIdVolume.volume;
// Calculate Sound Vector (used for sound frequency calcs) // Calculate Sound Vector (used for sound frequency calcs)
int32_t soundDirection = Geometry::kSpriteDirectionToSoundDirection[Orientation]; int32_t soundDirection = Geometry::getSoundDirectionFromOrientation(Orientation);
int32_t soundVector = ((velocity >> 14) * soundDirection) >> 14; int32_t soundVector = ((velocity >> 14) * soundDirection) >> 14;
soundVector = std::clamp(soundVector, -127, 127); soundVector = std::clamp(soundVector, -127, 127);
@@ -5024,7 +5025,7 @@ OpenRCT2::Audio::SoundId Vehicle::ProduceScreamSound(const int32_t totalNumPeeps
GForces Vehicle::GetGForces() const GForces Vehicle::GetGForces() const
{ {
int32_t gForceVert = ((static_cast<int64_t>(0x280000)) * Geometry::getPitchVector32(pitch).x) >> 32; int32_t gForceVert = ((static_cast<int64_t>(0x280000)) * Geometry::getPitchVector32(pitch).x) >> 32;
gForceVert = ((static_cast<int64_t>(gForceVert)) * Geometry::kRollHorizontalComponent[EnumValue(roll)]) >> 32; gForceVert = ((static_cast<int64_t>(gForceVert)) * Geometry::getRollHorizontalComponent(roll)) >> 32;
const auto& ted = GetTrackElementDescriptor(GetTrackType()); const auto& ted = GetTrackElementDescriptor(GetTrackType());
const int32_t vertFactor = ted.verticalFactor(track_progress); const int32_t vertFactor = ted.verticalFactor(track_progress);
@@ -5180,10 +5181,10 @@ int32_t Vehicle::UpdateMotionDodgems()
CoordsXYZ location = { x, y, z }; CoordsXYZ location = { x, y, z };
location.x += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection].x; location.x += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection).x;
location.y += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection].y; location.y += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection).y;
location.x += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection + 1].x; location.x += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection + 1).x;
location.y += Geometry::kFreeroamVehicleMovementData[oldCollisionDirection + 1].y; location.y += Geometry::getFreeroamVehicleMovementData(oldCollisionDirection + 1).y;
if (collideSprite = DodgemsCarWouldCollideAt(location); !collideSprite.has_value()) if (collideSprite = DodgemsCarWouldCollideAt(location); !collideSprite.has_value())
{ {
@@ -5207,15 +5208,15 @@ int32_t Vehicle::UpdateMotionDodgems()
direction |= var_35 & 1; direction |= var_35 & 1;
CoordsXY location = _vehicleCurPosition; CoordsXY location = _vehicleCurPosition;
location.x += Geometry::kFreeroamVehicleMovementData[direction].x; location.x += Geometry::getFreeroamVehicleMovementData(direction).x;
location.y += Geometry::kFreeroamVehicleMovementData[direction].y; location.y += Geometry::getFreeroamVehicleMovementData(direction).y;
if (collideSprite = DodgemsCarWouldCollideAt(location); collideSprite.has_value()) if (collideSprite = DodgemsCarWouldCollideAt(location); collideSprite.has_value())
{ {
break; break;
} }
remaining_distance -= Geometry::kFreeroamVehicleMovementData[direction].distance; remaining_distance -= Geometry::getFreeroamVehicleMovementData(direction).distance;
_vehicleCurPosition.x = location.x; _vehicleCurPosition.x = location.x;
_vehicleCurPosition.y = location.y; _vehicleCurPosition.y = location.y;
if (remaining_distance < 13962) if (remaining_distance < 13962)

View File

@@ -41,7 +41,7 @@ namespace OpenRCT2::RideVehicle::Geometry
static_assert(std::size(kSubpositionTranslationDistances) == 16); static_assert(std::size(kSubpositionTranslationDistances) == 16);
/** rct2: 0x009A36C4 */ /** rct2: 0x009A36C4 */
constexpr auto kFreeroamVehicleMovementData = std::to_array<Unk9A36C4Struct>({ const auto kFreeroamVehicleMovementData = std::to_array<Unk9A36C4Struct>({
{ -1, 0, 8716 }, { -1, 0, 8716 }, { -1, 0, 8716 }, { -1, 1, 12327 }, { -1, 1, 12327 }, { -1, 1, 12327 }, { -1, 0, 8716 }, { -1, 0, 8716 }, { -1, 0, 8716 }, { -1, 1, 12327 }, { -1, 1, 12327 }, { -1, 1, 12327 },
{ 0, 1, 8716 }, { -1, 1, 12327 }, { 0, 1, 8716 }, { 0, 1, 8716 }, { 0, 1, 8716 }, { 1, 1, 12327 }, { 0, 1, 8716 }, { -1, 1, 12327 }, { 0, 1, 8716 }, { 0, 1, 8716 }, { 0, 1, 8716 }, { 1, 1, 12327 },
{ 1, 1, 12327 }, { 1, 1, 12327 }, { 1, 0, 8716 }, { 1, 1, 12327 }, { 1, 0, 8716 }, { 1, 0, 8716 }, { 1, 1, 12327 }, { 1, 1, 12327 }, { 1, 0, 8716 }, { 1, 1, 12327 }, { 1, 0, 8716 }, { 1, 0, 8716 },
@@ -186,7 +186,7 @@ namespace OpenRCT2::RideVehicle::Geometry
static_assert(std::size(kPitchToDirectionVectorInt32) == EnumValue(VehiclePitch::pitchCount)); static_assert(std::size(kPitchToDirectionVectorInt32) == EnumValue(VehiclePitch::pitchCount));
/** rct2: 0x009A39C4 */ /** rct2: 0x009A39C4 */
constexpr auto kRollHorizontalComponent = std::to_array<int32_t>({ const auto kRollHorizontalComponent = std::to_array<int32_t>({
2147483647, 2096579710, 1946281152, 2096579710, 1946281152, 1380375879, 555809667, 2147483647, 2096579710, 1946281152, 2096579710, 1946281152, 1380375879, 555809667,
-372906620, -1231746017, -1859775391, 1380375879, 555809667, -372906620, -1231746017, -372906620, -1231746017, -1859775391, 1380375879, 555809667, -372906620, -1231746017,
-1859775391, 0, 2096579710, 1946281152, 2096579710, 1946281152, -1859775391, 0, 2096579710, 1946281152, 2096579710, 1946281152,
@@ -194,7 +194,7 @@ namespace OpenRCT2::RideVehicle::Geometry
static_assert(std::size(kRollHorizontalComponent) == EnumValue(VehicleRoll::rollCount)); static_assert(std::size(kRollHorizontalComponent) == EnumValue(VehicleRoll::rollCount));
/** rct2: 0x009A3684 */ /** rct2: 0x009A3684 */
constexpr auto kSpriteDirectionToSoundDirection = std::to_array<int32_t>({ const auto kSpriteDirectionToSoundDirection = std::to_array<int32_t>({
-0x4000, // 0 -0x4000, // 0
-0x3000, // 1 -0x3000, // 1
-0x2000, // 2 -0x2000, // 2
@@ -230,7 +230,7 @@ namespace OpenRCT2::RideVehicle::Geometry
}); });
/** rct2: 0x009A3AC4, 0x009A3AC6 */ /** rct2: 0x009A3AC4, 0x009A3AC6 */
constexpr auto kCrashDirectionComponents = std::to_array<CoordsXY>({ const auto kCrashDirectionComponents = std::to_array<CoordsXY>({
{ -256, 0 }, { -256, 0 },
{ -236, 98 }, { -236, 98 },
{ -181, 181 }, { -181, 181 },
@@ -250,4 +250,49 @@ namespace OpenRCT2::RideVehicle::Geometry
}); });
static_assert(std::size(kCrashDirectionComponents) == 16); static_assert(std::size(kCrashDirectionComponents) == 16);
Unk9A36C4Struct getFreeroamVehicleMovementData(uint8_t orientation)
{
return kFreeroamVehicleMovementData[orientation];
}
int32_t getRollHorizontalComponent(VehicleRoll roll)
{
return kRollHorizontalComponent[EnumValue(roll)];
}
int32_t getSoundDirectionFromOrientation(uint8_t orientation)
{
return kSpriteDirectionToSoundDirection[orientation];
}
CoordsXY getCrashDirectionComponents(uint8_t orientation)
{
return kCrashDirectionComponents[orientation / 2];
}
int32_t getTranslationDistance(CoordsXYZ distance, bool useReverserDistance)
{
uint8_t index = ((distance.x != 0) << 0) | ((distance.y != 0) << 1) | ((distance.z != 0) << 2)
| ((useReverserDistance) << 3);
return kSubpositionTranslationDistances[index];
}
int32_t getAccelerationFromPitch(VehiclePitch pitch)
{
if (pitch >= VehiclePitch::pitchCount)
{
return 0;
}
return kAccelerationFromPitch[EnumValue(pitch)];
}
CoordsXY getPitchVector32(VehiclePitch pitch)
{
if (pitch >= VehiclePitch::pitchCount)
{
pitch = VehiclePitch::flat;
}
return kPitchToDirectionVectorInt32[EnumValue(pitch)];
}
} // namespace OpenRCT2::RideVehicle::Geometry } // namespace OpenRCT2::RideVehicle::Geometry

View File

@@ -17,7 +17,6 @@
namespace OpenRCT2::RideVehicle::Geometry namespace OpenRCT2::RideVehicle::Geometry
{ {
struct Unk9A36C4Struct struct Unk9A36C4Struct
{ {
int16_t x; int16_t x;
@@ -25,40 +24,21 @@ namespace OpenRCT2::RideVehicle::Geometry
uint32_t distance; uint32_t distance;
}; };
extern const std::array<int32_t, 16> kSubpositionTranslationDistances; Unk9A36C4Struct getFreeroamVehicleMovementData(uint8_t orientation);
extern const std::array<Unk9A36C4Struct, 32> kFreeroamVehicleMovementData;
extern const std::array<int32_t, EnumValue(VehiclePitch::pitchCount)> kAccelerationFromPitch; int32_t getRollHorizontalComponent(VehicleRoll roll);
extern const std::array<CoordsXY, EnumValue(VehiclePitch::pitchCount)> kPitchToDirectionVectorInt32;
extern const std::array<int32_t, EnumValue(VehicleRoll::rollCount)> kRollHorizontalComponent; int32_t getSoundDirectionFromOrientation(uint8_t orientation);
extern const std::array<int32_t, 32> kSpriteDirectionToSoundDirection;
extern const std::array<CoordsXY, 16> kCrashDirectionComponents; CoordsXY getCrashDirectionComponents(uint8_t orientation);
/** The distance between subposition points in a movement vector. /** The distance between subposition points in a movement vector.
* Squashes vector components to 0 or !0, so vector length is ignored. * Squashes vector components to 0 or !0, so vector length is ignored.
*/ */
constexpr int32_t getTranslationDistance(CoordsXYZ distance, bool useReverserDistance) int32_t getTranslationDistance(CoordsXYZ distance, bool useReverserDistance);
{
uint8_t index = ((distance.x != 0) << 0) | ((distance.y != 0) << 1) | ((distance.z != 0) << 2)
| ((useReverserDistance) << 3);
return kSubpositionTranslationDistances[index];
}
constexpr int32_t getAccelerationFromPitch(VehiclePitch pitch) int32_t getAccelerationFromPitch(VehiclePitch pitch);
{
if (pitch >= VehiclePitch::pitchCount)
{
return 0;
}
return kAccelerationFromPitch[EnumValue(pitch)];
}
constexpr CoordsXY getPitchVector32(VehiclePitch pitch) CoordsXY getPitchVector32(VehiclePitch pitch);
{
if (pitch >= VehiclePitch::pitchCount)
{
pitch = VehiclePitch::flat;
}
return kPitchToDirectionVectorInt32[EnumValue(pitch)];
}
} // namespace OpenRCT2::RideVehicle::Geometry } // namespace OpenRCT2::RideVehicle::Geometry