1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-12-20 19:17:54 +01:00

FT collision part6: fixes and cleanup.

This commit is contained in:
Muzychenko Andrey 2023-03-13 10:54:33 +03:00
parent e0424bed65
commit 43e2ab896b
8 changed files with 15 additions and 23 deletions

View file

@ -17,7 +17,6 @@ TBall::TBall(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
visualStruct visual{}; visualStruct visual{};
char ballGroupName[10]{"ball"}; char ballGroupName[10]{"ball"};
TimeNow = 0.0;
RayMaxDistance = 0.0; RayMaxDistance = 0.0;
ActiveFlag = 1; ActiveFlag = 1;
CollisionComp = nullptr; CollisionComp = nullptr;

View file

@ -24,7 +24,6 @@ public :
float Speed; float Speed;
float RayMaxDistance; float RayMaxDistance;
float TimeDelta; float TimeDelta;
float TimeNow;
vector2 RampFieldForce{}; vector2 RampFieldForce{};
TCollisionComponent* CollisionComp; TCollisionComponent* CollisionComp;
int CollisionMask; int CollisionMask;

View file

@ -125,7 +125,7 @@ void TDemo::Collision(TBall* ball, vector2* nextPosition, vector2* direction, fl
case 1404: case 1404:
if (!PlungerFlag) if (!PlungerFlag)
{ {
PinballTable->Message(MessageCode::PlungerInputPressed, ball->TimeNow); PinballTable->Message(MessageCode::PlungerInputPressed, 0);
float time = RandFloat() + 2.0f; float time = RandFloat() + 2.0f;
PlungerFlag = timer::set(time, this, PlungerRelease); PlungerFlag = timer::set(time, this, PlungerRelease);
} }

View file

@ -615,7 +615,6 @@ TBall* TPinballTable::AddBall(vector2 position)
ball->Direction = {}; ball->Direction = {};
ball->Speed = 0; ball->Speed = 0;
ball->TimeDelta = 0; ball->TimeDelta = 0;
ball->TimeNow = 0;
ball->EdgeCollisionCount = 0; ball->EdgeCollisionCount = 0;
ball->CollisionFlag = 0; ball->CollisionFlag = 0;
ball->CollisionMask = 1; ball->CollisionMask = 1;

View file

@ -251,8 +251,8 @@ vector2 maths::vector_mul(const vector2& vec1, float val)
float maths::basic_collision(TBall* ball, vector2* nextPosition, vector2* direction, float elasticity, float smoothness, float maths::basic_collision(TBall* ball, vector2* nextPosition, vector2* direction, float elasticity, float smoothness,
float threshold, float boost) float threshold, float boost)
{ {
ball->Position.X = nextPosition->X; ball->Position.X = nextPosition->X + direction->X * 0.0005f;
ball->Position.Y = nextPosition->Y; ball->Position.Y = nextPosition->Y + direction->Y * 0.0005f;
// Project ball direction on collision rebound direction // Project ball direction on collision rebound direction
auto reboundProj = -DotProduct(*direction, ball->Direction); auto reboundProj = -DotProduct(*direction, ball->Direction);

View file

@ -52,7 +52,6 @@ struct ray_type
vector2 Direction; vector2 Direction;
float MaxDistance; float MaxDistance;
float MinDistance; float MinDistance;
float TimeNow;
int CollisionMask; int CollisionMask;
}; };

View file

@ -285,7 +285,7 @@ void pb::frame(float dtMilliSec)
float dtSec = dtMilliSec * 0.001f; float dtSec = dtMilliSec * 0.001f;
time_next = time_now + dtSec; time_next = time_now + dtSec;
timed_frame(time_now, dtSec, true); timed_frame(dtSec);
time_now = time_next; time_now = time_next;
dtMilliSec += time_ticks_remainder; dtMilliSec += time_ticks_remainder;
@ -318,7 +318,7 @@ void pb::frame(float dtMilliSec)
} }
} }
void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls) void pb::timed_frame(float timeDelta)
{ {
for (auto ball : MainTable->BallList) for (auto ball : MainTable->BallList)
{ {
@ -346,12 +346,13 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
} }
} }
int ballSteps[20]{-1}; int ballSteps[20]{};
float ballStepsDistance[20]{}; float ballStepsDistance[20]{};
int maxStep = -1; int maxStep = -1;
for (auto index = 0u; index < MainTable->BallList.size(); index++) for (auto index = 0u; index < MainTable->BallList.size(); index++)
{ {
auto ball = MainTable->BallList[index]; auto ball = MainTable->BallList[index];
ballSteps[index] = -1;
if (ball->ActiveFlag != 0) if (ball->ActiveFlag != 0)
{ {
vector2 vecDst{}; vector2 vecDst{};
@ -366,8 +367,8 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
else else
{ {
TTableLayer::edge_manager->FieldEffects(ball, &vecDst); TTableLayer::edge_manager->FieldEffects(ball, &vecDst);
vecDst.X *= timeDelta; vecDst.X *= ball->TimeDelta;
vecDst.Y *= timeDelta; vecDst.Y *= ball->TimeDelta;
ball->Direction.X *= ball->Speed; ball->Direction.X *= ball->Speed;
ball->Direction.Y *= ball->Speed; ball->Direction.Y *= ball->Speed;
maths::vector_add(ball->Direction, vecDst); maths::vector_add(ball->Direction, vecDst);
@ -401,16 +402,15 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
for (auto ballIndex = 0u; ballIndex < MainTable->BallList.size(); ballIndex++) for (auto ballIndex = 0u; ballIndex < MainTable->BallList.size(); ballIndex++)
{ {
auto ball = MainTable->BallList[ballIndex]; auto ball = MainTable->BallList[ballIndex];
if (!ball->CollisionDisabledFlag && step <= ballSteps[ballIndex]) if (!ball->CollisionDisabledFlag && ballSteps[ballIndex] >= step)
{ {
ray.CollisionMask = ball->CollisionMask; ray.CollisionMask = ball->CollisionMask;
ball->TimeNow = timeNow;
for (auto distanceSum = 0.0f; distanceSum < BallHalfRadius;) for (auto distanceSum = 0.0f; distanceSum < BallHalfRadius;)
{ {
ray.Origin = ball->Position; ray.Origin = ball->Position;
ray.Direction = ball->Direction; ray.Direction = ball->Direction;
if (step >= ballSteps[ballIndex]) if (ballSteps[ballIndex] <= step)
{ {
ray.MaxDistance = ballStepsDistance[ballIndex] - ballSteps[ballIndex] * BallHalfRadius; ray.MaxDistance = ballStepsDistance[ballIndex] - ballSteps[ballIndex] * BallHalfRadius;
} }
@ -418,7 +418,6 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
{ {
ray.MaxDistance = BallHalfRadius; ray.MaxDistance = BallHalfRadius;
} }
ray.TimeNow = ball->TimeNow;
TEdgeSegment* edge = nullptr; TEdgeSegment* edge = nullptr;
auto distance = TTableLayer::edge_manager->FindCollisionDistance(&ray, ball, &edge); auto distance = TTableLayer::edge_manager->FindCollisionDistance(&ray, ball, &edge);
@ -462,14 +461,11 @@ void pb::timed_frame(float timeNow, float timeDelta, bool drawBalls)
flipper->UpdateSprite(); flipper->UpdateSprite();
} }
if (drawBalls)
{
for (auto ball : MainTable->BallList) for (auto ball : MainTable->BallList)
{ {
if (ball->ActiveFlag) if (ball->ActiveFlag)
ball->Repaint(); ball->Repaint();
} }
}
} }
void pb::pause_continue() void pb::pause_continue()

View file

@ -66,7 +66,7 @@ public:
static void replay_level(bool demoMode); static void replay_level(bool demoMode);
static void ballset(float dx, float dy); static void ballset(float dx, float dy);
static void frame(float dtMilliSec); static void frame(float dtMilliSec);
static void timed_frame(float timeNow, float timeDelta, bool drawBalls); static void timed_frame(float timeDelta);
static void pause_continue(); static void pause_continue();
static void loose_focus(); static void loose_focus();
static void InputUp(GameInput input); static void InputUp(GameInput input);