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{};
char ballGroupName[10]{"ball"};
TimeNow = 0.0;
RayMaxDistance = 0.0;
ActiveFlag = 1;
CollisionComp = nullptr;

View File

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

View File

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

View File

@ -615,7 +615,6 @@ TBall* TPinballTable::AddBall(vector2 position)
ball->Direction = {};
ball->Speed = 0;
ball->TimeDelta = 0;
ball->TimeNow = 0;
ball->EdgeCollisionCount = 0;
ball->CollisionFlag = 0;
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 threshold, float boost)
{
ball->Position.X = nextPosition->X;
ball->Position.Y = nextPosition->Y;
ball->Position.X = nextPosition->X + direction->X * 0.0005f;
ball->Position.Y = nextPosition->Y + direction->Y * 0.0005f;
// Project ball direction on collision rebound direction
auto reboundProj = -DotProduct(*direction, ball->Direction);

View File

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

View File

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

View File

@ -66,7 +66,7 @@ public:
static void replay_level(bool demoMode);
static void ballset(float dx, float dy);
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 loose_focus();
static void InputUp(GameInput input);