Skip to content

Commit

Permalink
editor crash fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TobyAdd committed Dec 2, 2024
1 parent 45c956f commit b442805
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
28 changes: 22 additions & 6 deletions src/hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class $modify(FMODAudioEngine) {

float left_over = 0.f;
bool disable_render = false;
bool need_to_stop = false;

class $modify(PlayLayer) {
struct Fields {
Expand Down Expand Up @@ -329,7 +330,7 @@ class $modify(PlayLayer) {
auto& engine = ReplayEngine::get();

PlayLayer::resetLevel();
engine.handle_reset(this);
engine.handle_reset();

if (config.get<bool>("no_do_not_flip", false) && m_attemptLabel)
m_attemptLabel->setScaleY(1);
Expand Down Expand Up @@ -439,11 +440,6 @@ class $modify(GJBaseGameLayer) {
if (!config.get<bool>("tps_enabled", false))
return GJBaseGameLayer::update(dt);

if (!config.get<bool>("tps_enabled", false)) {
GJBaseGameLayer::update(dt);
return;
}

float tps_value = config.get<float>("tps_value", 240.f);
float newdt = 1.f / tps_value;

Expand All @@ -455,6 +451,12 @@ class $modify(GJBaseGameLayer) {

for (unsigned i = 0; i < times; ++i) {
disable_render = (i != times - 1);

if (need_to_stop) {
need_to_stop = false;
break;
}

GJBaseGameLayer::update(newdt);
engine.handle_update(this);

Expand Down Expand Up @@ -1037,4 +1039,18 @@ class $modify(LevelEditorLayer) {
m_trailTimer = 0.1f;
LevelEditorLayer::postUpdate(dt);
}

void onPlaytest() {
auto& engine = ReplayEngine::get();
LevelEditorLayer::onPlaytest();

if (engine.mode == state::play) {
engine.handle_reset();
}
}

void onStopPlaytest() {
need_to_stop = true;
LevelEditorLayer::onStopPlaytest();
}
};
2 changes: 1 addition & 1 deletion src/replayEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void ReplayEngine::handle_update(GJBaseGameLayer* self) {
}
}

void ReplayEngine::handle_reset(GJBaseGameLayer* self) {
void ReplayEngine::handle_reset() {
if (mode == state::record) {
int lastCheckpointFrame = get_frame();
remove_actions(lastCheckpointFrame);
Expand Down
2 changes: 1 addition & 1 deletion src/replayEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ReplayEngine {
std::string clear();

void handle_update(GJBaseGameLayer* self);
void handle_reset(GJBaseGameLayer* self);
void handle_reset();
void handle_button(bool down, int button, bool isPlayer1);

void auto_button_release();
Expand Down

0 comments on commit b442805

Please sign in to comment.