From 97aea205860bdb1f3838e26f3779d647070432b3 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Fri, 20 May 2022 11:51:00 +0300 Subject: [PATCH] Renamed some collision variables. --- SpaceCadetPinball/DebugOverlay.cpp | 6 ++-- SpaceCadetPinball/TBall.cpp | 20 ++++++------ SpaceCadetPinball/TBall.h | 9 +++--- SpaceCadetPinball/TBumper.cpp | 2 +- SpaceCadetPinball/TBumper.h | 2 +- SpaceCadetPinball/TCircle.cpp | 8 ++--- SpaceCadetPinball/TCircle.h | 2 +- SpaceCadetPinball/TCollisionComponent.cpp | 2 +- SpaceCadetPinball/TCollisionComponent.h | 2 +- SpaceCadetPinball/TDemo.cpp | 4 +-- SpaceCadetPinball/TDemo.h | 2 +- SpaceCadetPinball/TDrain.cpp | 2 +- SpaceCadetPinball/TDrain.h | 2 +- SpaceCadetPinball/TEdgeManager.cpp | 4 +-- SpaceCadetPinball/TEdgeManager.h | 4 +-- SpaceCadetPinball/TEdgeSegment.h | 2 +- SpaceCadetPinball/TFlagSpinner.cpp | 4 +-- SpaceCadetPinball/TFlagSpinner.h | 2 +- SpaceCadetPinball/TFlipper.cpp | 2 +- SpaceCadetPinball/TFlipper.h | 2 +- SpaceCadetPinball/TFlipperEdge.cpp | 14 ++++----- SpaceCadetPinball/TFlipperEdge.h | 2 +- SpaceCadetPinball/THole.cpp | 30 +++++++++--------- SpaceCadetPinball/THole.h | 4 +-- SpaceCadetPinball/TKickback.cpp | 2 +- SpaceCadetPinball/TKickback.h | 2 +- SpaceCadetPinball/TKickout.cpp | 14 ++++----- SpaceCadetPinball/TKickout.h | 4 +-- SpaceCadetPinball/TLightRollover.cpp | 4 +-- SpaceCadetPinball/TLightRollover.h | 2 +- SpaceCadetPinball/TLine.cpp | 4 +-- SpaceCadetPinball/TLine.h | 2 +- SpaceCadetPinball/TOneway.cpp | 4 +-- SpaceCadetPinball/TOneway.h | 2 +- SpaceCadetPinball/TPlunger.cpp | 6 ++-- SpaceCadetPinball/TPlunger.h | 2 +- SpaceCadetPinball/TPopupTarget.cpp | 2 +- SpaceCadetPinball/TPopupTarget.h | 2 +- SpaceCadetPinball/TRamp.cpp | 18 +++++------ SpaceCadetPinball/TRamp.h | 2 +- SpaceCadetPinball/TRollover.cpp | 4 +-- SpaceCadetPinball/TRollover.h | 2 +- SpaceCadetPinball/TSink.cpp | 6 ++-- SpaceCadetPinball/TSink.h | 4 +-- SpaceCadetPinball/TSoloTarget.cpp | 2 +- SpaceCadetPinball/TSoloTarget.h | 2 +- SpaceCadetPinball/TTableLayer.cpp | 8 ++--- SpaceCadetPinball/TTripwire.cpp | 4 +-- SpaceCadetPinball/TTripwire.h | 2 +- SpaceCadetPinball/TWall.cpp | 2 +- SpaceCadetPinball/TWall.h | 2 +- SpaceCadetPinball/loader.cpp | 2 +- SpaceCadetPinball/loader.h | 2 +- SpaceCadetPinball/maths.cpp | 37 +++++++++++++---------- SpaceCadetPinball/maths.h | 2 +- SpaceCadetPinball/nudge.cpp | 19 +++--------- SpaceCadetPinball/pb.cpp | 30 +++++++++--------- 57 files changed, 162 insertions(+), 173 deletions(-) diff --git a/SpaceCadetPinball/DebugOverlay.cpp b/SpaceCadetPinball/DebugOverlay.cpp index 2c1f226..af6dfed 100644 --- a/SpaceCadetPinball/DebugOverlay.cpp +++ b/SpaceCadetPinball/DebugOverlay.cpp @@ -19,7 +19,7 @@ gdrv_bitmap8* DebugOverlay::dbScreen = nullptr; -int SDL_RenderDrawCircle(SDL_Renderer* renderer, int x, int y, int radius) +static int SDL_RenderDrawCircle(SDL_Renderer* renderer, int x, int y, int radius) { int offsetx, offsety, d; int status; @@ -184,7 +184,7 @@ void DebugOverlay::DrawBallInfo() SDL_RenderDrawCircle(winmain::Renderer, pt1.X, pt1.Y, 10); auto nextPos = ballPosition; - maths::vector_add(nextPos, maths::vector_mul(ball->Acceleration, ball->Speed / 10.0f)); + maths::vector_add(nextPos, maths::vector_mul(ball->Direction, ball->Speed / 10.0f)); auto pt2 = proj::xform_to_2d(nextPos); SDL_RenderDrawLine(winmain::Renderer, pt1.X, pt1.Y, pt2.X, pt2.Y); } @@ -223,7 +223,7 @@ void DebugOverlay::DrawEdge(TEdgeSegment* edge) break; } } - if (refBall != nullptr && (refBall->FieldFlag & edge->CollisionGroup) == 0) + if (refBall != nullptr && (refBall->CollisionMask & edge->CollisionGroup) == 0) return; } diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index 823df3f..d05130b 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -21,13 +21,11 @@ TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) CollisionComp = nullptr; EdgeCollisionCount = 0; TimeDelta = 0.0; - FieldFlag = 1; + CollisionMask = 1; CollisionFlag = 0; Speed = 0.0; - Acceleration.Y = 0.0; - Acceleration.X = 0.0; - InvAcceleration.Y = 1000000000.0; - InvAcceleration.X = 1000000000.0; + Direction.Y = 0.0; + Direction.X = 0.0; Position.X = 0.0; Position.Y = 0.0; @@ -117,23 +115,23 @@ int TBall::Message(int code, float value) Position.Y = 0.0; ActiveFlag = 0; CollisionFlag = 0; - FieldFlag = 1; - Acceleration.Y = 0.0; + CollisionMask = 1; + Direction.Y = 0.0; Position.Z = Offset; - Acceleration.X = 0.0; + Direction.X = 0.0; Speed = 0.0; RayMaxDistance = 0.0; } return 0; } -void TBall::throw_ball(TBall* ball, vector3* acceleration, float angleMult, float speedMult1, float speedMult2) +void TBall::throw_ball(TBall* ball, vector3* direction, float angleMult, float speedMult1, float speedMult2) { ball->CollisionComp = nullptr; - ball->Acceleration = *acceleration; + ball->Direction = *direction; float rnd = RandFloat(); float angle = (1.0f - (rnd + rnd)) * angleMult; - maths::RotateVector(ball->Acceleration, angle); + maths::RotateVector(ball->Direction, angle); rnd = RandFloat(); ball->Speed = (1.0f - (rnd + rnd)) * (speedMult1 * speedMult2) + speedMult1; } diff --git a/SpaceCadetPinball/TBall.h b/SpaceCadetPinball/TBall.h index a9046aa..b596f01 100644 --- a/SpaceCadetPinball/TBall.h +++ b/SpaceCadetPinball/TBall.h @@ -14,19 +14,18 @@ public : bool already_hit(TEdgeSegment* edge); int Message(int code, float value) override; - static void throw_ball(TBall* ball, vector3* acceleration, float angleMult, float speedMult1, + static void throw_ball(TBall* ball, vector3* direction, float angleMult, float speedMult1, float speedMult2); vector3 Position{}; - vector3 Acceleration{}; + vector3 Direction{}; float Speed; float RayMaxDistance; float TimeDelta; float TimeNow; - vector2 InvAcceleration{}; - vector2 RampFieldForce{}; + vector2 RampFieldForce{}; TCollisionComponent* CollisionComp; - int FieldFlag; + int CollisionMask; TEdgeSegment* Collisions[5]{}; int EdgeCollisionCount; vector3 CollisionOffset{}; diff --git a/SpaceCadetPinball/TBumper.cpp b/SpaceCadetPinball/TBumper.cpp index b55dd75..9575d82 100644 --- a/SpaceCadetPinball/TBumper.cpp +++ b/SpaceCadetPinball/TBumper.cpp @@ -100,7 +100,7 @@ int TBumper::Message(int code, float value) return 0; } -void TBumper::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TBumper::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (DefaultCollision(ball, nextPosition, direction)) { diff --git a/SpaceCadetPinball/TBumper.h b/SpaceCadetPinball/TBumper.h index cee5e15..99e7213 100644 --- a/SpaceCadetPinball/TBumper.h +++ b/SpaceCadetPinball/TBumper.h @@ -14,7 +14,7 @@ public: TBumper(TPinballTable* table, int groupIndex); ~TBumper() override = default; int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; diff --git a/SpaceCadetPinball/TCircle.cpp b/SpaceCadetPinball/TCircle.cpp index b61ccfd..485346b 100644 --- a/SpaceCadetPinball/TCircle.cpp +++ b/SpaceCadetPinball/TCircle.cpp @@ -17,16 +17,16 @@ float TCircle::FindCollisionDistance(ray_type* ray) return maths::ray_intersect_circle(*ray, Circle); } -void TCircle::EdgeCollision(TBall* ball, float coef) +void TCircle::EdgeCollision(TBall* ball, float distance) { vector2 direction{}, nextPosition{}; - nextPosition.X = coef * ball->Acceleration.X + ball->Position.X; - nextPosition.Y = coef * ball->Acceleration.Y + ball->Position.Y; + nextPosition.X = distance * ball->Direction.X + ball->Position.X; + nextPosition.Y = distance * ball->Direction.Y + ball->Position.Y; direction.X = nextPosition.X - Circle.Center.X; direction.Y = nextPosition.Y - Circle.Center.Y; maths::normalize_2d(direction); - CollisionComponent->Collision(ball, &nextPosition, &direction, coef, this); + CollisionComponent->Collision(ball, &nextPosition, &direction, distance, this); } void TCircle::place_in_grid() diff --git a/SpaceCadetPinball/TCircle.h b/SpaceCadetPinball/TCircle.h index 24b8aea..2ba6b35 100644 --- a/SpaceCadetPinball/TCircle.h +++ b/SpaceCadetPinball/TCircle.h @@ -11,6 +11,6 @@ public: TCircle(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, vector2* center, float radius); float FindCollisionDistance(ray_type* ray) override; - void EdgeCollision(TBall* ball, float coef) override; + void EdgeCollision(TBall* ball, float distance) override; void place_in_grid() override; }; diff --git a/SpaceCadetPinball/TCollisionComponent.cpp b/SpaceCadetPinball/TCollisionComponent.cpp index f0b958e..8078dfa 100644 --- a/SpaceCadetPinball/TCollisionComponent.cpp +++ b/SpaceCadetPinball/TCollisionComponent.cpp @@ -74,7 +74,7 @@ int TCollisionComponent::DefaultCollision(TBall* ball, vector2* nextPosition, ve } void TCollisionComponent::Collision(TBall* ball, vector2* nextPosition, vector2* direction, - float coef, TEdgeSegment* edge) + float distance, TEdgeSegment* edge) { int soundIndex; diff --git a/SpaceCadetPinball/TCollisionComponent.h b/SpaceCadetPinball/TCollisionComponent.h index f8b77ae..1f9d5e6 100644 --- a/SpaceCadetPinball/TCollisionComponent.h +++ b/SpaceCadetPinball/TCollisionComponent.h @@ -19,7 +19,7 @@ public: TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall); ~TCollisionComponent() override; void port_draw() override; - virtual void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + virtual void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge); virtual int FieldEffect(TBall* ball, vector2* vecDst); int DefaultCollision(TBall* ball, vector2* nextPosition, vector2* direction); diff --git a/SpaceCadetPinball/TDemo.cpp b/SpaceCadetPinball/TDemo.cpp index b39a957..0231eda 100644 --- a/SpaceCadetPinball/TDemo.cpp +++ b/SpaceCadetPinball/TDemo.cpp @@ -93,12 +93,12 @@ int TDemo::Message(int code, float value) return 0; } -void TDemo::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TDemo::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { ball->not_again(edge); ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - ball->RayMaxDistance -= coef; + ball->RayMaxDistance -= distance; switch (reinterpret_cast(edge->WallValue)) { diff --git a/SpaceCadetPinball/TDemo.h b/SpaceCadetPinball/TDemo.h index 8ebea88..d3f1bd8 100644 --- a/SpaceCadetPinball/TDemo.h +++ b/SpaceCadetPinball/TDemo.h @@ -7,7 +7,7 @@ class TDemo : public: TDemo(TPinballTable* table, int groupIndex); int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void PlungerRelease(int timerId, void* caller); diff --git a/SpaceCadetPinball/TDrain.cpp b/SpaceCadetPinball/TDrain.cpp index 9579bcc..3aa8099 100644 --- a/SpaceCadetPinball/TDrain.cpp +++ b/SpaceCadetPinball/TDrain.cpp @@ -28,7 +28,7 @@ int TDrain::Message(int code, float value) return 0; } -void TDrain::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TDrain::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { ball->Message(1024, 0.0); PinballTable->BallInSink = 1; diff --git a/SpaceCadetPinball/TDrain.h b/SpaceCadetPinball/TDrain.h index 7b1d907..d96c00a 100644 --- a/SpaceCadetPinball/TDrain.h +++ b/SpaceCadetPinball/TDrain.h @@ -7,7 +7,7 @@ class TDrain : public: TDrain(TPinballTable* table, int groupIndex); int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void TimerCallback(int timerId, void* caller); diff --git a/SpaceCadetPinball/TEdgeManager.cpp b/SpaceCadetPinball/TEdgeManager.cpp index dfe18f5..fedc6d4 100644 --- a/SpaceCadetPinball/TEdgeManager.cpp +++ b/SpaceCadetPinball/TEdgeManager.cpp @@ -74,7 +74,7 @@ int TEdgeManager::TestGridBox(int x, int y, float* distPtr, TEdgeSegment** edgeD for (auto it = edgeBox->EdgeList.rbegin(); it != edgeBox->EdgeList.rend(); ++it) { auto edge = *it; - if (!edge->ProcessedFlag && *edge->ActiveFlag && (edge->CollisionGroup & ray->FieldFlag)) + if (!edge->ProcessedFlag && *edge->ActiveFlag && (edge->CollisionGroup & ray->CollisionMask)) { if (!ball->already_hit(edge)) { @@ -104,7 +104,7 @@ void TEdgeManager::FieldEffects(TBall* ball, vector2* dstVec) for (auto it = edgeBox->FieldList.rbegin(); it != edgeBox->FieldList.rend(); ++it) { auto field = *it; - if (*field->Flag2Ptr && ball->FieldFlag & field->Mask) + if (*field->ActiveFlag && ball->CollisionMask & field->CollisionGroup) { if (field->CollisionComp->FieldEffect(ball, &vec)) { diff --git a/SpaceCadetPinball/TEdgeManager.h b/SpaceCadetPinball/TEdgeManager.h index a5d284b..cb5a3f6 100644 --- a/SpaceCadetPinball/TEdgeManager.h +++ b/SpaceCadetPinball/TEdgeManager.h @@ -6,8 +6,8 @@ class TEdgeBox; struct field_effect_type { - char* Flag2Ptr; - int Mask; + char* ActiveFlag; + int CollisionGroup; TCollisionComponent* CollisionComp; }; diff --git a/SpaceCadetPinball/TEdgeSegment.h b/SpaceCadetPinball/TEdgeSegment.h index d68f526..6ea257b 100644 --- a/SpaceCadetPinball/TEdgeSegment.h +++ b/SpaceCadetPinball/TEdgeSegment.h @@ -22,7 +22,7 @@ public: TEdgeSegment(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup); virtual ~TEdgeSegment() = default; - virtual void EdgeCollision(TBall* ball, float coef) = 0; + virtual void EdgeCollision(TBall* ball, float distance) = 0; virtual void port_draw(); virtual void place_in_grid() = 0; virtual float FindCollisionDistance(ray_type* ray) = 0; diff --git a/SpaceCadetPinball/TFlagSpinner.cpp b/SpaceCadetPinball/TFlagSpinner.cpp index 86b1bf5..235e926 100644 --- a/SpaceCadetPinball/TFlagSpinner.cpp +++ b/SpaceCadetPinball/TFlagSpinner.cpp @@ -72,12 +72,12 @@ int TFlagSpinner::Message(int code, float value) return 0; } -void TFlagSpinner::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, +void TFlagSpinner::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - ball->RayMaxDistance = ball->RayMaxDistance - coef; + ball->RayMaxDistance = ball->RayMaxDistance - distance; ball->not_again(edge); SpinDirection = 2 * (PrevCollider != edge) - 1; diff --git a/SpaceCadetPinball/TFlagSpinner.h b/SpaceCadetPinball/TFlagSpinner.h index c0f835d..eb4e4da 100644 --- a/SpaceCadetPinball/TFlagSpinner.h +++ b/SpaceCadetPinball/TFlagSpinner.h @@ -7,7 +7,7 @@ class TFlagSpinner : public: TFlagSpinner(TPinballTable* table, int groupIndex); int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; diff --git a/SpaceCadetPinball/TFlipper.cpp b/SpaceCadetPinball/TFlipper.cpp index 09621c9..d2e4bf2 100644 --- a/SpaceCadetPinball/TFlipper.cpp +++ b/SpaceCadetPinball/TFlipper.cpp @@ -128,7 +128,7 @@ void TFlipper::port_draw() FlipperEdge->port_draw(); } -void TFlipper::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TFlipper::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { } diff --git a/SpaceCadetPinball/TFlipper.h b/SpaceCadetPinball/TFlipper.h index 3e2ef05..a0e3538 100644 --- a/SpaceCadetPinball/TFlipper.h +++ b/SpaceCadetPinball/TFlipper.h @@ -11,7 +11,7 @@ public: ~TFlipper() override; int Message(int code, float value) override; void port_draw() override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void TimerExpired(int timerId, void* caller); diff --git a/SpaceCadetPinball/TFlipperEdge.cpp b/SpaceCadetPinball/TFlipperEdge.cpp index ecdebe7..aa8c63b 100644 --- a/SpaceCadetPinball/TFlipperEdge.cpp +++ b/SpaceCadetPinball/TFlipperEdge.cpp @@ -298,7 +298,7 @@ float TFlipperEdge::FindCollisionDistance(ray_type* ray) return 1e+09; } -void TFlipperEdge::EdgeCollision(TBall* ball, float coef) +void TFlipperEdge::EdgeCollision(TBall* ball, float distance) { EdgeCollisionFlag = 1; if (!FlipperFlag || !CollisionFlag2 || CollisionFlag1) @@ -308,11 +308,11 @@ void TFlipperEdge::EdgeCollision(TBall* ball, float coef) { float dx = NextBallPosition.X - RotOrigin.X; float dy = NextBallPosition.Y - RotOrigin.Y; - float distance = dy * dy + dx * dx; - if (circlebase.RadiusSq * 1.01f < distance) + float distanceSq = dy * dy + dx * dx; + if (circlebase.RadiusSq * 1.01f < distanceSq) { float v11; - float v20 = sqrt(distance / DistanceDivSq) * (fabs(AngleMax) / AngleMult); + float v20 = sqrt(distanceSq / DistanceDivSq) * (fabs(AngleMax) / AngleMult); float dot1 = maths::DotProduct(CollisionLinePerp, CollisionDirection); if (dot1 >= 0.0f) v11 = dot1 * v20; @@ -337,9 +337,9 @@ void TFlipperEdge::EdgeCollision(TBall* ball, float coef) float elasticity; float dx = NextBallPosition.X - RotOrigin.X; float dy = NextBallPosition.Y - RotOrigin.Y; - float distance = dy * dy + dx * dx; - if (circlebase.RadiusSq * 1.01f < distance) - elasticity = (1.0f - sqrt(distance / DistanceDivSq)) * Elasticity; + float distanceSq = dy * dy + dx * dx; + if (circlebase.RadiusSq * 1.01f < distanceSq) + elasticity = (1.0f - sqrt(distanceSq / DistanceDivSq)) * Elasticity; else elasticity = Elasticity; maths::basic_collision(ball, &NextBallPosition, &CollisionDirection, elasticity, Smoothness, 1000000000.0, 0.0); diff --git a/SpaceCadetPinball/TFlipperEdge.h b/SpaceCadetPinball/TFlipperEdge.h index c82c6ec..07c776c 100644 --- a/SpaceCadetPinball/TFlipperEdge.h +++ b/SpaceCadetPinball/TFlipperEdge.h @@ -12,7 +12,7 @@ public: float elasticity, float smoothness); void port_draw() override; float FindCollisionDistance(ray_type* ray) override; - void EdgeCollision(TBall* ball, float coef) override; + void EdgeCollision(TBall* ball, float distance) override; void place_in_grid() override; void set_control_points(float timeNow); void build_edges_in_motion(); diff --git a/SpaceCadetPinball/THole.cpp b/SpaceCadetPinball/THole.cpp index 265bc7b..38cad6f 100644 --- a/SpaceCadetPinball/THole.cpp +++ b/SpaceCadetPinball/THole.cpp @@ -40,20 +40,20 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table, } ZSetValue = loader::query_float_attribute(groupIndex, 0, 408)[2]; - FieldFlag = static_cast(floor(*loader::query_float_attribute(groupIndex, 0, 1304))); + CollisionMask = static_cast(floor(*loader::query_float_attribute(groupIndex, 0, 1304))); - /*Full tilt hack - FieldFlag should be on*/ + // Full tilt hack - CollisionMask should be 1 if (pb::FullTiltMode) - FieldFlag = 1; + CollisionMask = 1; Circle.RadiusSq = visual.FloatArr[2] * visual.FloatArr[2]; circle.RadiusSq = Circle.RadiusSq; circle.Center.X = Circle.Center.X; circle.Center.Y = Circle.Center.Y; - Field.Flag2Ptr = &ActiveFlag; + Field.ActiveFlag = &ActiveFlag; Field.CollisionComp = this; - Field.Mask = visual.CollisionGroup; + Field.CollisionGroup = visual.CollisionGroup; TTableLayer::edges_insert_circle(&circle, nullptr, &Field); } @@ -69,7 +69,7 @@ int THole::Message(int code, float value) return 0; } -void THole::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void THole::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (!BallCapturedFlag) { @@ -79,7 +79,7 @@ void THole::Collision(TBall* ball, vector2* nextPosition, vector2* direction, fl ball->CollisionComp = this; ball->Position.X = Circle.Center.X; ball->Position.Y = Circle.Center.Y; - ball->Acceleration.Z = 0.0; + ball->Direction.Z = 0.0; // Ramp hole has no delay in FT. auto captureTime = pb::FullTiltMode ? 0 : 0.5f; @@ -102,18 +102,18 @@ int THole::FieldEffect(TBall* ball, vector2* vecDst) { if (BallCapturedSecondStage) { - ball->Acceleration.Z -= PinballTable->GravityDirVectMult * ball->TimeDelta * GravityMult; - ball->Position.Z += ball->Acceleration.Z; + ball->Direction.Z -= PinballTable->GravityDirVectMult * ball->TimeDelta * GravityMult; + ball->Position.Z += ball->Direction.Z; if (ball->Position.Z <= ZSetValue) { BallCapturedFlag = 0; BallCapturedSecondStage = 0; ball->Position.Z = ZSetValue; - ball->Acceleration.Z = 0.0; - ball->FieldFlag = FieldFlag; - ball->Acceleration.Y = 0.0; + ball->Direction.Z = 0.0; + ball->CollisionMask = CollisionMask; + ball->Direction.Y = 0.0; ball->CollisionComp = nullptr; - ball->Acceleration.X = 0.0; + ball->Direction.X = 0.0; ball->Speed = 0.0; loader::play_sound(SoftHitSoundId); control::handler(58, this); @@ -128,8 +128,8 @@ int THole::FieldEffect(TBall* ball, vector2* vecDst) if (direction.X * direction.X + direction.Y * direction.Y <= Circle.RadiusSq) { maths::normalize_2d(direction); - vecDst->X = direction.X * GravityPull - ball->Acceleration.X * ball->Speed; - vecDst->Y = direction.Y * GravityPull - ball->Acceleration.Y * ball->Speed; + vecDst->X = direction.X * GravityPull - ball->Direction.X * ball->Speed; + vecDst->Y = direction.Y * GravityPull - ball->Direction.Y * ball->Speed; result = 1; } else diff --git a/SpaceCadetPinball/THole.h b/SpaceCadetPinball/THole.h index 187a4b0..f877898 100644 --- a/SpaceCadetPinball/THole.h +++ b/SpaceCadetPinball/THole.h @@ -9,7 +9,7 @@ class THole : public: THole(TPinballTable* table, int groupIndex); int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; int FieldEffect(TBall* ball, vector2* vecDst) override; @@ -22,7 +22,7 @@ public: float Unknown4; float GravityMult; float ZSetValue; - int FieldFlag; + int CollisionMask; float GravityPull; circle_type Circle{}; field_effect_type Field{}; diff --git a/SpaceCadetPinball/TKickback.cpp b/SpaceCadetPinball/TKickback.cpp index 8abb403..56cfcdf 100644 --- a/SpaceCadetPinball/TKickback.cpp +++ b/SpaceCadetPinball/TKickback.cpp @@ -33,7 +33,7 @@ int TKickback::Message(int code, float value) return 0; } -void TKickback::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, +void TKickback::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (PinballTable->TiltLockFlag) diff --git a/SpaceCadetPinball/TKickback.h b/SpaceCadetPinball/TKickback.h index ebdd14b..5cf88cf 100644 --- a/SpaceCadetPinball/TKickback.h +++ b/SpaceCadetPinball/TKickback.h @@ -7,7 +7,7 @@ class TKickback : public: TKickback(TPinballTable* table, int groupIndex); int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void TimerExpired(int timerId, void* caller); diff --git a/SpaceCadetPinball/TKickout.cpp b/SpaceCadetPinball/TKickout.cpp index c321a3f..623628c 100644 --- a/SpaceCadetPinball/TKickout.cpp +++ b/SpaceCadetPinball/TKickout.cpp @@ -47,16 +47,16 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis auto zAttr = loader::query_float_attribute(groupIndex, 0, 408); CollisionBallSetZ = pb::FullTiltMode && !pb::FullTiltDemoMode ? zAttr[3] : zAttr[2]; ThrowSpeedMult2 = visual.Kicker.ThrowBallMult * 0.01f; - BallAcceleration = visual.Kicker.ThrowBallAcceleration; + BallThrowDirection = visual.Kicker.ThrowBallDirection; ThrowAngleMult = visual.Kicker.ThrowBallAngleMult; ThrowSpeedMult1 = visual.Kicker.Boost; circle.RadiusSq = Circle.RadiusSq; circle.Center.X = Circle.Center.X; circle.Center.Y = Circle.Center.Y; - Field.Flag2Ptr = &ActiveFlag; + Field.ActiveFlag = &ActiveFlag; Field.CollisionComp = this; - Field.Mask = visual.CollisionGroup; + Field.CollisionGroup = visual.CollisionGroup; TTableLayer::edges_insert_circle(&circle, nullptr, &Field); } @@ -104,7 +104,7 @@ int TKickout::get_scoring(int index) return index < 5 ? Scores[index] : 0; } -void TKickout::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TKickout::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (!KickFlag1) { @@ -139,8 +139,8 @@ int TKickout::FieldEffect(TBall* ball, vector2* dstVec) if (direction.Y * direction.Y + direction.X * direction.X > Circle.RadiusSq) return 0; maths::normalize_2d(direction); - dstVec->X = direction.X * FieldMult - ball->Acceleration.X * ball->Speed; - dstVec->Y = direction.Y * FieldMult - ball->Acceleration.Y * ball->Speed; + dstVec->X = direction.X * FieldMult - ball->Direction.X * ball->Speed; + dstVec->Y = direction.Y * FieldMult - ball->Direction.Y * ball->Speed; return 1; } @@ -154,7 +154,7 @@ void TKickout::TimerExpired(int timerId, void* caller) if (kick->Ball) { kick->Ball->Position.Z = kick->OriginalBallZ; - TBall::throw_ball(kick->Ball, &kick->BallAcceleration, kick->ThrowAngleMult, kick->ThrowSpeedMult1, + TBall::throw_ball(kick->Ball, &kick->BallThrowDirection, kick->ThrowAngleMult, kick->ThrowSpeedMult1, kick->ThrowSpeedMult2); kick->ActiveFlag = 0; kick->Ball = nullptr; diff --git a/SpaceCadetPinball/TKickout.h b/SpaceCadetPinball/TKickout.h index 05623cb..e29859a 100644 --- a/SpaceCadetPinball/TKickout.h +++ b/SpaceCadetPinball/TKickout.h @@ -11,7 +11,7 @@ public: int Message(int code, float value) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; int FieldEffect(TBall* ball, vector2* vecDst) override; @@ -28,7 +28,7 @@ public: float FieldMult; circle_type Circle{}; float OriginalBallZ{}; - vector3 BallAcceleration{}; + vector3 BallThrowDirection{}; float ThrowAngleMult; float ThrowSpeedMult1; float ThrowSpeedMult2; diff --git a/SpaceCadetPinball/TLightRollover.cpp b/SpaceCadetPinball/TLightRollover.cpp index e139db0..7be1064 100644 --- a/SpaceCadetPinball/TLightRollover.cpp +++ b/SpaceCadetPinball/TLightRollover.cpp @@ -34,12 +34,12 @@ int TLightRollover::Message(int code, float value) return 0; } -void TLightRollover::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, +void TLightRollover::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - ball->RayMaxDistance -= coef; + ball->RayMaxDistance -= distance; ball->not_again(edge); if (!PinballTable->TiltLockFlag) { diff --git a/SpaceCadetPinball/TLightRollover.h b/SpaceCadetPinball/TLightRollover.h index 9100e1b..0e36366 100644 --- a/SpaceCadetPinball/TLightRollover.h +++ b/SpaceCadetPinball/TLightRollover.h @@ -8,7 +8,7 @@ public: TLightRollover(TPinballTable* table, int groupIndex); ~TLightRollover() override = default; int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void delay_expired(int timerId, void* caller); diff --git a/SpaceCadetPinball/TLine.cpp b/SpaceCadetPinball/TLine.cpp index a2d6741..bb3e35e 100644 --- a/SpaceCadetPinball/TLine.cpp +++ b/SpaceCadetPinball/TLine.cpp @@ -41,13 +41,13 @@ float TLine::FindCollisionDistance(ray_type* ray) return maths::ray_intersect_line(*ray, Line); } -void TLine::EdgeCollision(TBall* ball, float coef) +void TLine::EdgeCollision(TBall* ball, float distance) { CollisionComponent->Collision( ball, &Line.RayIntersect, &Line.PerpendicularC, - coef, + distance, this); } diff --git a/SpaceCadetPinball/TLine.h b/SpaceCadetPinball/TLine.h index 1009c40..1bb8894 100644 --- a/SpaceCadetPinball/TLine.h +++ b/SpaceCadetPinball/TLine.h @@ -12,6 +12,6 @@ public: TLine(TCollisionComponent* collCmp, char* activeFlag, unsigned int collisionGroup, const vector2& start, const vector2& end); void Offset(float offset); float FindCollisionDistance(ray_type* ray) override; - void EdgeCollision(TBall* ball, float coef) override; + void EdgeCollision(TBall* ball, float distance) override; void place_in_grid() override; }; diff --git a/SpaceCadetPinball/TOneway.cpp b/SpaceCadetPinball/TOneway.cpp index 227f77c..7067a53 100644 --- a/SpaceCadetPinball/TOneway.cpp +++ b/SpaceCadetPinball/TOneway.cpp @@ -40,14 +40,14 @@ TOneway::TOneway(TPinballTable* table, int groupIndex) : TCollisionComponent(tab } } -void TOneway::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TOneway::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (edge == Line) { ball->not_again(edge); ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - ball->RayMaxDistance -= coef; + ball->RayMaxDistance -= distance; if (!PinballTable->TiltLockFlag) { if (HardHitSoundId) diff --git a/SpaceCadetPinball/TOneway.h b/SpaceCadetPinball/TOneway.h index 01fc02b..f85afe0 100644 --- a/SpaceCadetPinball/TOneway.h +++ b/SpaceCadetPinball/TOneway.h @@ -8,7 +8,7 @@ class TOneway : public TCollisionComponent public: TOneway(TPinballTable* table, int groupIndex); ~TOneway() override = default; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; diff --git a/SpaceCadetPinball/TPlunger.cpp b/SpaceCadetPinball/TPlunger.cpp index 7fda598..2a5454b 100644 --- a/SpaceCadetPinball/TPlunger.cpp +++ b/SpaceCadetPinball/TPlunger.cpp @@ -33,12 +33,12 @@ TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent(t table->PlungerPositionY = floatArr[1]; } -void TPlunger::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TPlunger::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (PinballTable->TiltLockFlag) Message(1017, 0.0); - coef = RandFloat() * Boost * 0.1f + Boost; // it is intended that the passed in coef is never used! - maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, Threshold, coef); + auto boost = RandFloat() * Boost * 0.1f + Boost; + maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, Threshold, boost); } int TPlunger::Message(int code, float value) diff --git a/SpaceCadetPinball/TPlunger.h b/SpaceCadetPinball/TPlunger.h index 2fe44bf..2b909dd 100644 --- a/SpaceCadetPinball/TPlunger.h +++ b/SpaceCadetPinball/TPlunger.h @@ -7,7 +7,7 @@ class TPlunger : public: TPlunger(TPinballTable* table, int groupIndex); ~TPlunger() override = default; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; int Message(int code, float value) override; diff --git a/SpaceCadetPinball/TPopupTarget.cpp b/SpaceCadetPinball/TPopupTarget.cpp index af29c1c..7a4fe09 100644 --- a/SpaceCadetPinball/TPopupTarget.cpp +++ b/SpaceCadetPinball/TPopupTarget.cpp @@ -62,7 +62,7 @@ int TPopupTarget::get_scoring(int index) return index < 3 ? Scores[index] : 0; } -void TPopupTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, +void TPopupTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (this->PinballTable->TiltLockFlag) diff --git a/SpaceCadetPinball/TPopupTarget.h b/SpaceCadetPinball/TPopupTarget.h index ebae2f2..422bdf0 100644 --- a/SpaceCadetPinball/TPopupTarget.h +++ b/SpaceCadetPinball/TPopupTarget.h @@ -9,7 +9,7 @@ public: int Message(int code, float value) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void TimerExpired(int timerId, void* caller); diff --git a/SpaceCadetPinball/TRamp.cpp b/SpaceCadetPinball/TRamp.cpp index 800e71d..562ef50 100644 --- a/SpaceCadetPinball/TRamp.cpp +++ b/SpaceCadetPinball/TRamp.cpp @@ -116,9 +116,9 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, PinballTable->GravityDirVectMult; } - Field.Flag2Ptr = &ActiveFlag; + Field.ActiveFlag = &ActiveFlag; Field.CollisionComp = this; - Field.Mask = visual.CollisionGroup; + Field.CollisionGroup = visual.CollisionGroup; auto x1 = xMax; auto y1 = yMax; @@ -138,12 +138,12 @@ int TRamp::get_scoring(int index) return index < 4 ? Scores[index] : 0; } -void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { ball->not_again(edge); ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - ball->RayMaxDistance -= coef; + ball->RayMaxDistance -= distance; auto plane = static_cast(edge->WallValue); if (plane) @@ -156,7 +156,7 @@ void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, fl ball->RampFieldForce.Y = plane->FieldForce.Y; ball->Position.Z = ball->Position.X * ball->CollisionOffset.X + ball->Position.Y * ball->CollisionOffset.Y + ball->Offset + ball->CollisionOffset.Z; - ball->FieldFlag = CollisionGroup; + ball->CollisionMask = CollisionGroup; return; } @@ -173,13 +173,13 @@ void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, fl ball->CollisionFlag = 0; if (edge == Line2) { - ball->FieldFlag = Wall1CollisionGroup; + ball->CollisionMask = Wall1CollisionGroup; if (BallZOffsetFlag) ball->Position.Z = ball->Offset + Wall1BallOffset; } else { - ball->FieldFlag = Wall2CollisionGroup; + ball->CollisionMask = Wall2CollisionGroup; if (BallZOffsetFlag) ball->Position.Z = ball->Offset + Wall2BallOffset; } @@ -188,8 +188,8 @@ void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, fl int TRamp::FieldEffect(TBall* ball, vector2* vecDst) { - vecDst->X = ball->RampFieldForce.X - ball->Acceleration.X * ball->Speed * BallFieldMult; - vecDst->Y = ball->RampFieldForce.Y - ball->Acceleration.Y * ball->Speed * BallFieldMult; + vecDst->X = ball->RampFieldForce.X - ball->Direction.X * ball->Speed * BallFieldMult; + vecDst->Y = ball->RampFieldForce.Y - ball->Direction.Y * ball->Speed * BallFieldMult; return 1; } diff --git a/SpaceCadetPinball/TRamp.h b/SpaceCadetPinball/TRamp.h index 101ddf0..3635134 100644 --- a/SpaceCadetPinball/TRamp.h +++ b/SpaceCadetPinball/TRamp.h @@ -12,7 +12,7 @@ public: TRamp(TPinballTable* table, int groupIndex); void put_scoring(int index, int score) override; int get_scoring(int index) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; int FieldEffect(TBall* ball, vector2* vecDst) override; void port_draw() override; diff --git a/SpaceCadetPinball/TRollover.cpp b/SpaceCadetPinball/TRollover.cpp index d091aed..ac4ecca 100644 --- a/SpaceCadetPinball/TRollover.cpp +++ b/SpaceCadetPinball/TRollover.cpp @@ -37,12 +37,12 @@ int TRollover::Message(int code, float value) return 0; } -void TRollover::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, +void TRollover::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - ball->RayMaxDistance -= coef; + ball->RayMaxDistance -= distance; ball->not_again(edge); gdrv_bitmap8* bmp = nullptr; if (!PinballTable->TiltLockFlag) diff --git a/SpaceCadetPinball/TRollover.h b/SpaceCadetPinball/TRollover.h index 421e88d..b90893f 100644 --- a/SpaceCadetPinball/TRollover.h +++ b/SpaceCadetPinball/TRollover.h @@ -10,7 +10,7 @@ public: TRollover(TPinballTable* table, int groupIndex); ~TRollover() override = default; int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; diff --git a/SpaceCadetPinball/TSink.cpp b/SpaceCadetPinball/TSink.cpp index 0aaabb1..2885ad5 100644 --- a/SpaceCadetPinball/TSink.cpp +++ b/SpaceCadetPinball/TSink.cpp @@ -16,7 +16,7 @@ TSink::TSink(TPinballTable* table, int groupIndex) : TCollisionComponent(table, MessageField = 0; Timer = 0; loader::query_visual(groupIndex, 0, &visual); - BallAcceleration = visual.Kicker.ThrowBallAcceleration; + BallThrowDirection = visual.Kicker.ThrowBallDirection; ThrowAngleMult = visual.Kicker.ThrowBallAngleMult; ThrowSpeedMult1 = visual.Kicker.Boost; ThrowSpeedMult2 = visual.Kicker.ThrowBallMult * 0.01f; @@ -75,7 +75,7 @@ int TSink::get_scoring(int index) return index < 3 ? Scores[index] : 0; } -void TSink::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TSink::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { Timer = 0; if (PinballTable->TiltLockFlag) @@ -99,7 +99,7 @@ void TSink::TimerExpired(int timerId, void* caller) ball->ActiveFlag = 1; ball->Position.X = sink->BallPosition.X; ball->Position.Y = sink->BallPosition.Y; - TBall::throw_ball(ball, &sink->BallAcceleration, sink->ThrowAngleMult, sink->ThrowSpeedMult1, + TBall::throw_ball(ball, &sink->BallThrowDirection, sink->ThrowAngleMult, sink->ThrowSpeedMult1, sink->ThrowSpeedMult2); if (sink->SoundIndex3) loader::play_sound(sink->SoundIndex3); diff --git a/SpaceCadetPinball/TSink.h b/SpaceCadetPinball/TSink.h index f1a4bd1..21c080e 100644 --- a/SpaceCadetPinball/TSink.h +++ b/SpaceCadetPinball/TSink.h @@ -10,7 +10,7 @@ public: int Message(int code, float value) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void TimerExpired(int timerId, void* caller); @@ -18,7 +18,7 @@ public: int Timer; float TimerTime; vector2 BallPosition{}; - vector3 BallAcceleration{}; + vector3 BallThrowDirection{}; float ThrowAngleMult; float ThrowSpeedMult1; float ThrowSpeedMult2; diff --git a/SpaceCadetPinball/TSoloTarget.cpp b/SpaceCadetPinball/TSoloTarget.cpp index f55f213..f7b494f 100644 --- a/SpaceCadetPinball/TSoloTarget.cpp +++ b/SpaceCadetPinball/TSoloTarget.cpp @@ -64,7 +64,7 @@ int TSoloTarget::get_scoring(int index) return index < 1 ? Scores[index] : 0; } -void TSoloTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, +void TSoloTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (DefaultCollision(ball, nextPosition, direction)) diff --git a/SpaceCadetPinball/TSoloTarget.h b/SpaceCadetPinball/TSoloTarget.h index cbcf2c7..26d7342 100644 --- a/SpaceCadetPinball/TSoloTarget.h +++ b/SpaceCadetPinball/TSoloTarget.h @@ -9,7 +9,7 @@ public: int Message(int code, float value) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; static void TimerExpired(int timerId, void* caller); diff --git a/SpaceCadetPinball/TTableLayer.cpp b/SpaceCadetPinball/TTableLayer.cpp index 0dfc914..df2b09a 100644 --- a/SpaceCadetPinball/TTableLayer.cpp +++ b/SpaceCadetPinball/TTableLayer.cpp @@ -98,8 +98,8 @@ TTableLayer::TTableLayer(TPinballTable* table): TCollisionComponent(table, -1, f visArrPtr += 2; } - Field.Mask = -1; - Field.Flag2Ptr = &ActiveFlag; + Field.CollisionGroup = -1; + Field.ActiveFlag = &ActiveFlag; Field.CollisionComp = this; edges_insert_square(Unknown2F, Unknown1F, Unknown4F, Unknown3F, nullptr, &Field); @@ -113,9 +113,9 @@ TTableLayer::~TTableLayer() int TTableLayer::FieldEffect(TBall* ball, vector2* vecDst) { - vecDst->X = GraityDirX - (0.5f - RandFloat() + ball->Acceleration.X) * + vecDst->X = GraityDirX - (0.5f - RandFloat() + ball->Direction.X) * ball->Speed * GraityMult; - vecDst->Y = GraityDirY - ball->Acceleration.Y * ball->Speed * GraityMult; + vecDst->Y = GraityDirY - ball->Direction.Y * ball->Speed * GraityMult; return 1; } diff --git a/SpaceCadetPinball/TTripwire.cpp b/SpaceCadetPinball/TTripwire.cpp index cd36e3a..4a9c5a4 100644 --- a/SpaceCadetPinball/TTripwire.cpp +++ b/SpaceCadetPinball/TTripwire.cpp @@ -10,12 +10,12 @@ TTripwire::TTripwire(TPinballTable* table, int groupIndex) : TRollover(table, gr { } -void TTripwire::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, +void TTripwire::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - ball->RayMaxDistance -= coef; + ball->RayMaxDistance -= distance; ball->not_again(edge); if (!PinballTable->TiltLockFlag) { diff --git a/SpaceCadetPinball/TTripwire.h b/SpaceCadetPinball/TTripwire.h index 178caa3..0756961 100644 --- a/SpaceCadetPinball/TTripwire.h +++ b/SpaceCadetPinball/TTripwire.h @@ -7,6 +7,6 @@ class TTripwire : public: TTripwire(TPinballTable* table, int groupIndex); ~TTripwire() override = default; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; }; diff --git a/SpaceCadetPinball/TWall.cpp b/SpaceCadetPinball/TWall.cpp index 3130566..94716cb 100644 --- a/SpaceCadetPinball/TWall.cpp +++ b/SpaceCadetPinball/TWall.cpp @@ -24,7 +24,7 @@ int TWall::Message(int code, float value) return 0; } -void TWall::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, TEdgeSegment* edge) +void TWall::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { if (DefaultCollision(ball, nextPosition, direction)) { diff --git a/SpaceCadetPinball/TWall.h b/SpaceCadetPinball/TWall.h index 988b74c..9e2dd59 100644 --- a/SpaceCadetPinball/TWall.h +++ b/SpaceCadetPinball/TWall.h @@ -10,7 +10,7 @@ class TWall : public: TWall(TPinballTable* table, int groupIndex); int Message(int code, float value) override; - void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float coef, + void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void put_scoring(int index, int score) override; int get_scoring(int index) override; diff --git a/SpaceCadetPinball/loader.cpp b/SpaceCadetPinball/loader.cpp index c01c065..47c51cf 100644 --- a/SpaceCadetPinball/loader.cpp +++ b/SpaceCadetPinball/loader.cpp @@ -390,7 +390,7 @@ int loader::kicker(int groupIndex, visualKickerStruct* kicker) kicker->ThrowBallMult = *floatArr; break; case 404: - kicker->ThrowBallAcceleration = *reinterpret_cast(floatArr); + kicker->ThrowBallDirection = *reinterpret_cast(floatArr); floatArr += 3; index += 4; break; diff --git a/SpaceCadetPinball/loader.h b/SpaceCadetPinball/loader.h index cd1ffba..597b153 100644 --- a/SpaceCadetPinball/loader.h +++ b/SpaceCadetPinball/loader.h @@ -25,7 +25,7 @@ struct visualKickerStruct float Threshold; float Boost; float ThrowBallMult; - vector3 ThrowBallAcceleration; + vector3 ThrowBallDirection; float ThrowBallAngleMult; int HardHitSoundId; }; diff --git a/SpaceCadetPinball/maths.cpp b/SpaceCadetPinball/maths.cpp index 0ae2250..e553760 100644 --- a/SpaceCadetPinball/maths.cpp +++ b/SpaceCadetPinball/maths.cpp @@ -231,30 +231,35 @@ float maths::basic_collision(TBall* ball, vector2* nextPosition, vector2* direct ball->Position.X = nextPosition->X; ball->Position.Y = nextPosition->Y; - auto proj = -DotProduct(*direction, ball->Acceleration); - if (proj < 0) + // Project ball direction on collision rebound direction + auto reboundProj = -DotProduct(*direction, ball->Direction); + if (reboundProj < 0) { - proj = -proj; + // Negative projection means no rebound, both direction vectors point the same way. + reboundProj = -reboundProj; } else { - float dx1 = proj * direction->X; - float dy1 = proj * direction->Y; - ball->Acceleration.X = (dx1 + ball->Acceleration.X) * smoothness + dx1 * elasticity; - ball->Acceleration.Y = (dy1 + ball->Acceleration.Y) * smoothness + dy1 * elasticity; - normalize_2d(ball->Acceleration); + // Apply rebound to ball direction + float dx1 = reboundProj * direction->X; + float dy1 = reboundProj * direction->Y; + ball->Direction.X = (dx1 + ball->Direction.X) * smoothness + dx1 * elasticity; + ball->Direction.Y = (dy1 + ball->Direction.Y) * smoothness + dy1 * elasticity; + normalize_2d(ball->Direction); } - float projSpeed = proj * ball->Speed; - float newSpeed = ball->Speed - (1.0f - elasticity) * projSpeed; - ball->Speed = newSpeed; - if (projSpeed >= threshold) + // Apply rebound to ball speed + float reboundSpeed = reboundProj * ball->Speed; + ball->Speed -= (1.0f - elasticity) * reboundSpeed; + + if (reboundSpeed >= threshold) { - ball->Acceleration.X = newSpeed * ball->Acceleration.X + direction->X * boost; - ball->Acceleration.Y = newSpeed * ball->Acceleration.Y + direction->Y * boost; - ball->Speed = normalize_2d(ball->Acceleration); + // Change ball direction if rebound speed is above threshold + ball->Direction.X = ball->Speed * ball->Direction.X + direction->X * boost; + ball->Direction.Y = ball->Speed * ball->Direction.Y + direction->Y * boost; + ball->Speed = normalize_2d(ball->Direction); } - return projSpeed; + return reboundSpeed; } float maths::Distance_Squared(const vector2& vec1, const vector2& vec2) diff --git a/SpaceCadetPinball/maths.h b/SpaceCadetPinball/maths.h index 863eccc..226b64a 100644 --- a/SpaceCadetPinball/maths.h +++ b/SpaceCadetPinball/maths.h @@ -53,7 +53,7 @@ struct ray_type float MinDistance; float TimeNow; float TimeDelta; - int FieldFlag; + int CollisionMask; }; struct line_type diff --git a/SpaceCadetPinball/nudge.cpp b/SpaceCadetPinball/nudge.cpp index 9c5a456..43fb522 100644 --- a/SpaceCadetPinball/nudge.cpp +++ b/SpaceCadetPinball/nudge.cpp @@ -65,7 +65,6 @@ void nudge::nudge_up() void nudge::_nudge(float xDiff, float yDiff) { vector2 accelMod; - float invAccelX, invAccelY; accelMod.X = xDiff * 0.5f; accelMod.Y = yDiff * 0.5f; @@ -73,20 +72,10 @@ void nudge::_nudge(float xDiff, float yDiff) { if (ball->ActiveFlag && !ball->CollisionComp) { - ball->Acceleration.X = ball->Acceleration.X * ball->Speed; - ball->Acceleration.Y = ball->Acceleration.Y * ball->Speed; - maths::vector_add(ball->Acceleration, accelMod); - ball->Speed = maths::normalize_2d(ball->Acceleration); - if (ball->Acceleration.X == 0.0f) - invAccelX = 1000000000.0; - else - invAccelX = 1.0f / ball->Acceleration.X; - ball->InvAcceleration.X = invAccelX; - if (ball->Acceleration.Y == 0.0f) - invAccelY = 1000000000.0; - else - invAccelY = 1.0f / ball->Acceleration.Y; - ball->InvAcceleration.Y = invAccelY; + ball->Direction.X = ball->Direction.X * ball->Speed; + ball->Direction.Y = ball->Direction.Y * ball->Speed; + maths::vector_add(ball->Direction, accelMod); + ball->Speed = maths::normalize_2d(ball->Direction); } } diff --git a/SpaceCadetPinball/pb.cpp b/SpaceCadetPinball/pb.cpp index 839b9c2..65c2fbc 100644 --- a/SpaceCadetPinball/pb.cpp +++ b/SpaceCadetPinball/pb.cpp @@ -241,9 +241,9 @@ void pb::ballset(float dx, float dy) // dx and dy are normalized to window, ideally in [-1, 1] static constexpr float sensitivity = 7000; TBall* ball = MainTable->BallList.at(0); - ball->Acceleration.X = dx * sensitivity; - ball->Acceleration.Y = dy * sensitivity; - ball->Speed = maths::normalize_2d(ball->Acceleration); + ball->Direction.X = dx * sensitivity; + ball->Direction.Y = dy * sensitivity; + ball->Speed = maths::normalize_2d(ball->Direction); } void pb::frame(float dtMilliSec) @@ -311,12 +311,10 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) TTableLayer::edge_manager->FieldEffects(ball, &vec2); vec2.X = vec2.X * timeDelta; vec2.Y = vec2.Y * timeDelta; - ball->Acceleration.X = ball->Speed * ball->Acceleration.X; - ball->Acceleration.Y = ball->Speed * ball->Acceleration.Y; - maths::vector_add(ball->Acceleration, vec2); - ball->Speed = maths::normalize_2d(ball->Acceleration); - ball->InvAcceleration.X = ball->Acceleration.X == 0.0f ? 1.0e9f : 1.0f / ball->Acceleration.X; - ball->InvAcceleration.Y = ball->Acceleration.Y == 0.0f ? 1.0e9f : 1.0f / ball->Acceleration.Y; + ball->Direction.X = ball->Speed * ball->Direction.X; + ball->Direction.Y = ball->Speed * ball->Direction.Y; + maths::vector_add(ball->Direction, vec2); + ball->Speed = maths::normalize_2d(ball->Direction); } auto timeDelta2 = timeDelta; @@ -489,9 +487,9 @@ void pb::InputDown(GameInput input) ball->Position.X = 1.0; ball->Position.Z = ball->Offset; ball->Position.Y = 1.0; - ball->Acceleration.Z = 0.0; - ball->Acceleration.Y = 0.0; - ball->Acceleration.X = 0.0; + ball->Direction.Z = 0.0; + ball->Direction.Y = 0.0; + ball->Direction.X = 0.0; break; case 'h': { @@ -607,9 +605,9 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball) ball->TimeNow = timeNow; ray.Origin = ball->Position; - ray.Direction = ball->Acceleration; + ray.Direction = ball->Direction; ray.MaxDistance = maxDistance; - ray.FieldFlag = ball->FieldFlag; + ray.CollisionMask = ball->CollisionMask; ray.TimeNow = timeNow; ray.TimeDelta = timeDelta; ray.MinDistance = 0.0020000001f; @@ -621,8 +619,8 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball) { maxDistance = timeDelta * ball->Speed; ball->RayMaxDistance = maxDistance; - positionMod.X = maxDistance * ball->Acceleration.X; - positionMod.Y = maxDistance * ball->Acceleration.Y; + positionMod.X = maxDistance * ball->Direction.X; + positionMod.Y = maxDistance * ball->Direction.Y; maths::vector_add(ball->Position, positionMod); } else