feat: add play mode pause resume and step controls

This commit is contained in:
2026-04-02 19:56:07 +08:00
parent fb15d60be9
commit 1f29dfd611
11 changed files with 270 additions and 3 deletions

View File

@@ -30,6 +30,20 @@ void PlaySessionController::Attach(IEditorContext& context) {
PausePlay(context);
});
}
if (m_playResumeRequestedHandlerId == 0) {
m_playResumeRequestedHandlerId = context.GetEventBus().Subscribe<PlayModeResumeRequestedEvent>(
[this, &context](const PlayModeResumeRequestedEvent&) {
ResumePlay(context);
});
}
if (m_playStepRequestedHandlerId == 0) {
m_playStepRequestedHandlerId = context.GetEventBus().Subscribe<PlayModeStepRequestedEvent>(
[this, &context](const PlayModeStepRequestedEvent&) {
StepPlay(context);
});
}
}
void PlaySessionController::Detach(IEditorContext& context) {
@@ -49,6 +63,16 @@ void PlaySessionController::Detach(IEditorContext& context) {
context.GetEventBus().Unsubscribe<PlayModePauseRequestedEvent>(m_playPauseRequestedHandlerId);
m_playPauseRequestedHandlerId = 0;
}
if (m_playResumeRequestedHandlerId != 0) {
context.GetEventBus().Unsubscribe<PlayModeResumeRequestedEvent>(m_playResumeRequestedHandlerId);
m_playResumeRequestedHandlerId = 0;
}
if (m_playStepRequestedHandlerId != 0) {
context.GetEventBus().Unsubscribe<PlayModeStepRequestedEvent>(m_playStepRequestedHandlerId);
m_playStepRequestedHandlerId = 0;
}
}
void PlaySessionController::Update(IEditorContext& context, float deltaTime) {
@@ -118,5 +142,25 @@ bool PlaySessionController::PausePlay(IEditorContext& context) {
return true;
}
bool PlaySessionController::ResumePlay(IEditorContext& context) {
if (context.GetRuntimeMode() != EditorRuntimeMode::Paused || !m_runtimeLoop.IsRunning()) {
return false;
}
m_runtimeLoop.Resume();
context.SetRuntimeMode(EditorRuntimeMode::Play);
context.GetEventBus().Publish(PlayModeResumedEvent{});
return true;
}
bool PlaySessionController::StepPlay(IEditorContext& context) {
if (context.GetRuntimeMode() != EditorRuntimeMode::Paused || !m_runtimeLoop.IsRunning()) {
return false;
}
m_runtimeLoop.StepFrame();
return true;
}
} // namespace Editor
} // namespace XCEngine