increase precision of mode_countdown_ handling

potentially there could be modes running a bit too long, depending on passed in ms (which were implicitly truncated before when passing in)

also fix some harmless warnings
This commit is contained in:
toxie 2021-10-17 19:31:10 +02:00
parent 3b11d6019b
commit 51b637a5e3
2 changed files with 14 additions and 14 deletions

View File

@ -29,8 +29,8 @@
TPinballTable* pb::MainTable = nullptr; TPinballTable* pb::MainTable = nullptr;
DatFile* pb::record_table = nullptr; DatFile* pb::record_table = nullptr;
int pb::time_ticks = 0, pb::demo_mode = 0, pb::game_mode = 2, pb::mode_countdown_; int pb::time_ticks = 0, pb::demo_mode = 0, pb::game_mode = 2;
float pb::time_now = 0, pb::time_next = 0, pb::ball_speed_limit, pb::time_ticks_remainder = 0; float pb::mode_countdown_, pb::time_now = 0, pb::time_next = 0, pb::ball_speed_limit, pb::time_ticks_remainder = 0;
high_score_struct pb::highscore_table[5]; high_score_struct pb::highscore_table[5];
bool pb::FullTiltMode = false, pb::cheat_mode = false; bool pb::FullTiltMode = false, pb::cheat_mode = false;
@ -169,7 +169,7 @@ void pb::mode_change(int mode)
case 4: case 4:
winmain::LaunchBallEnabled = false; winmain::LaunchBallEnabled = false;
winmain::HighScoresEnabled = false; winmain::HighScoresEnabled = false;
mode_countdown_ = 5000; mode_countdown_ = 5000.f;
break; break;
} }
game_mode = mode; game_mode = mode;
@ -399,7 +399,7 @@ void pb::InputDown(GameInput input)
if (game_mode != 1) if (game_mode != 1)
{ {
mode_countdown(-1); mode_countdown(-1.f);
return; return;
} }
@ -485,7 +485,7 @@ void pb::InputDown(GameInput input)
} }
} }
int pb::mode_countdown(int time) int pb::mode_countdown(float time)
{ {
if (!game_mode || game_mode <= 0) if (!game_mode || game_mode <= 0)
return 1; return 1;
@ -494,13 +494,13 @@ int pb::mode_countdown(int time)
if (game_mode == 3) if (game_mode == 3)
{ {
mode_countdown_ -= time; mode_countdown_ -= time;
if (mode_countdown_ < 0 || time < 0) if (mode_countdown_ < 0.f || time < 0.f)
mode_change(4); mode_change(4);
} }
else if (game_mode == 4) else if (game_mode == 4)
{ {
mode_countdown_ -= time; mode_countdown_ -= time;
if (mode_countdown_ < 0 || time < 0) if (mode_countdown_ < 0.f || time < 0.f)
mode_change(1); mode_change(1);
} }
return 1; return 1;
@ -517,7 +517,6 @@ void pb::end_game()
{ {
int scores[4]{}; int scores[4]{};
int scoreIndex[4]{}; int scoreIndex[4]{};
char String1[200];
mode_change(2); mode_change(2);
int playerCount = MainTable->PlayerCount; int playerCount = MainTable->PlayerCount;
@ -532,7 +531,7 @@ void pb::end_game()
for (auto i = 0; i < playerCount; ++i) for (auto i = 0; i < playerCount; ++i)
{ {
for (auto j = i; j < playerCount; ++j) for (auto j = i+1; j < playerCount; ++j)
{ {
if (scores[j] > scores[i]) if (scores[j] > scores[i])
{ {
@ -554,6 +553,7 @@ void pb::end_game()
int position = high_score::get_score_position(highscore_table, scores[i]); int position = high_score::get_score_position(highscore_table, scores[i]);
if (position >= 0) if (position >= 0)
{ {
char String1[200];
strncpy(String1, pinball::get_rc_string(scoreIndex[i] + 26, 0), sizeof String1 - 1); strncpy(String1, pinball::get_rc_string(scoreIndex[i] + 26, 0), sizeof String1 - 1);
high_score::show_and_set_high_score_dialog(highscore_table, scores[i], position, String1); high_score::show_and_set_high_score_dialog(highscore_table, scores[i], position, String1);
} }
@ -593,9 +593,6 @@ bool pb::chk_highscore()
float pb::collide(float timeNow, float timeDelta, TBall* ball) float pb::collide(float timeNow, float timeDelta, TBall* ball)
{ {
ray_type ray{};
vector_type positionMod{};
if (ball->ActiveFlag && !ball->CollisionComp) if (ball->ActiveFlag && !ball->CollisionComp)
{ {
if (ball_speed_limit < ball->Speed) if (ball_speed_limit < ball->Speed)
@ -606,6 +603,7 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball)
ball->RayMaxDistance = maxDistance; ball->RayMaxDistance = maxDistance;
ball->TimeNow = timeNow; ball->TimeNow = timeNow;
ray_type ray{};
ray.Origin.X = ball->Position.X; ray.Origin.X = ball->Position.X;
ray.Origin.Y = ball->Position.Y; ray.Origin.Y = ball->Position.Y;
ray.Origin.Z = ball->Position.Z; ray.Origin.Z = ball->Position.Z;
@ -625,6 +623,7 @@ float pb::collide(float timeNow, float timeDelta, TBall* ball)
{ {
maxDistance = timeDelta * ball->Speed; maxDistance = timeDelta * ball->Speed;
ball->RayMaxDistance = maxDistance; ball->RayMaxDistance = maxDistance;
vector_type positionMod{};
positionMod.X = maxDistance * ball->Acceleration.X; positionMod.X = maxDistance * ball->Acceleration.X;
positionMod.Y = maxDistance * ball->Acceleration.Y; positionMod.Y = maxDistance * ball->Acceleration.Y;
positionMod.Z = 0.0; positionMod.Z = 0.0;

View File

@ -57,7 +57,7 @@ public:
static void loose_focus(); static void loose_focus();
static void InputUp(GameInput input); static void InputUp(GameInput input);
static void InputDown(GameInput input); static void InputDown(GameInput input);
static int mode_countdown(int time); static int mode_countdown(float time);
static void launch_ball(); static void launch_ball();
static void end_game(); static void end_game();
static void high_scores(); static void high_scores();
@ -66,7 +66,8 @@ public:
static float collide(float timeNow, float timeDelta, TBall* ball); static float collide(float timeNow, float timeDelta, TBall* ball);
static void PushCheat(const std::string& cheat); static void PushCheat(const std::string& cheat);
private: private:
static int demo_mode, mode_countdown_; static int demo_mode;
static float mode_countdown_;
static bool AnyBindingMatchesInput(GameInput (&options)[3], GameInput key); static bool AnyBindingMatchesInput(GameInput (&options)[3], GameInput key);
}; };