Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Command: 2049 - SetGameSpeed #3109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/fps_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void FpsOverlay::Draw(Bitmap& dst) {
}

// Always drawn when speedup is on independent of FPS
if (last_speed_mod > 1) {
if (!Game_Clock::GetSpeedOverlayMode() && last_speed_mod > 1) {
if (speedup_dirty) {
std::string text = "> x" + std::to_string(last_speed_mod);

Expand Down
2 changes: 2 additions & 0 deletions src/game_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
constexpr bool Game_Clock::is_steady;
Game_Clock::Data Game_Clock::data;

int hideDisplay = 0;

// Damping factor fps computation.
static constexpr auto _fps_smooth = 2.0f / 121.0f;

Expand Down
17 changes: 17 additions & 0 deletions src/game_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Game_Clock {
using duration = clock::duration;
using time_point = clock::time_point;

int hideDisplay;

static constexpr bool is_steady = clock::is_steady;

/** Get current time */
Expand Down Expand Up @@ -76,6 +78,12 @@ class Game_Clock {
/** @return the speed up or slowdown factor we'll use to run the game. */
static float GetGameSpeedFactor();

/** Set either if Speed Multiplier Overlay is hidden or Visible. */
static void setSpeedOverlayMode(bool mode);

/** Check if Speed Multiplier Overlay is hidden or Visible. */
static int GetSpeedOverlayMode();

/** Get the time of the current frame */
static time_point GetFrameTime();

Expand Down Expand Up @@ -117,6 +125,7 @@ class Game_Clock {
float speed = 1.0;
float fps = 0.0;
int frame = 0;
bool hideSpeedOverlay = 0;
};
static Data data;
};
Expand Down Expand Up @@ -180,4 +189,12 @@ inline float Game_Clock::GetGameSpeedFactor() {
return data.speed;
}

inline int Game_Clock::GetSpeedOverlayMode() {
return data.hideSpeedOverlay;
}

inline void Game_Clock::setSpeedOverlayMode(bool s) {
data.hideSpeedOverlay = s;
}

#endif
21 changes: 21 additions & 0 deletions src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,8 @@ bool Game_Interpreter::ExecuteCommand(lcf::rpg::EventCommand const& com) {
return CommandManiacControlStrings(com);
case Cmd::Maniac_CallCommand:
return CommandManiacCallCommand(com);
case static_cast<Game_Interpreter::Cmd>(2049) : //Cmd::Easy_SetGameSpeed
return CommandSetGameSpeed(com);
default:
return true;
}
Expand Down Expand Up @@ -4985,6 +4987,25 @@ bool Game_Interpreter::CommandManiacCallCommand(lcf::rpg::EventCommand const&) {
return true;
}

bool Game_Interpreter::CommandSetGameSpeed(lcf::rpg::EventCommand const& com) {
// #SetGameSpeed, "",[speedIsVar, speed, speedLimitIsVar,speedLimit, hideSpeedMultiplierIsVar, hideSpeedMultiplier ];

int32_t speed = ValueOrVariable(com.parameters[0], com.parameters[1]) * Game_Clock::GetGameSpeedFactor();
int32_t speedLimit = ValueOrVariable(com.parameters[2], com.parameters[3]);
bool hideSpeedMultiplier = ValueOrVariable(com.parameters[4], com.parameters[5]);

if (speedLimit == 0) speedLimit = 100;
if (speed > speedLimit) speed = speedLimit;

if (Input::IsSystemPressed(Input::FAST_FORWARD_A) || Input::IsSystemPressed(Input::FAST_FORWARD_B))
Game_Clock::setSpeedOverlayMode(0);
else
Game_Clock::setSpeedOverlayMode(hideSpeedMultiplier);

Game_Clock::SetGameSpeedFactor(speed);
return true;
}

Game_Interpreter& Game_Interpreter::GetForegroundInterpreter() {
return Game_Battle::IsBattleRunning()
? Game_Battle::GetInterpreter()
Expand Down
1 change: 1 addition & 0 deletions src/game_interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class Game_Interpreter
bool CommandManiacSetGameOption(lcf::rpg::EventCommand const& com);
bool CommandManiacControlStrings(lcf::rpg::EventCommand const& com);
bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com);
bool CommandSetGameSpeed(lcf::rpg::EventCommand const& com);

int DecodeInt(lcf::DBArray<int32_t>::const_iterator& it);
const std::string DecodeString(lcf::DBArray<int32_t>::const_iterator& it);
Expand Down
1 change: 1 addition & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ void Player::UpdateInput() {
if (Input::IsSystemPressed(Input::FAST_FORWARD_B)) {
speed = speed_modifier_b;
}
Game_Clock::setSpeedOverlayMode(0);
Game_Clock::SetGameSpeedFactor(speed);

if (Main_Data::game_quit) {
Expand Down
Loading