Skip to content

Commit

Permalink
chore: 更好的处理卡顿以及添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
Blinue committed Dec 31, 2024
1 parent 4c62a17 commit 6c65469
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Magpie.Core/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,14 @@ void Renderer::_BackendThreadProc() noexcept {
return;
}

bool waitMsgForNewFrame =
StepTimerStatus stepTimerStatus = StepTimerStatus::WaitForNewFrame;
const bool waitMsgForNewFrame =
_frameSource->WaitType() == FrameSourceWaitType::WaitForMessage;

MSG msg;
while (true) {
StepTimerStatus stepTimerStatus = _stepTimer.WaitForNextFrame(waitMsgForNewFrame);
stepTimerStatus = _stepTimer.WaitForNextFrame(
waitMsgForNewFrame && stepTimerStatus != StepTimerStatus::WaitForFPSLimiter);

while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT) {
Expand All @@ -684,21 +686,19 @@ void Renderer::_BackendThreadProc() noexcept {
}

if (stepTimerStatus == StepTimerStatus::WaitForFPSLimiter) {
// 新帧消息可能已被处理,之后的 WaitForNextFrame 不要等待消息,直到状态变化
continue;
}

switch (_frameSource->Update()) {
case FrameSourceState::Waiting:
waitMsgForNewFrame = _frameSource->WaitType() == FrameSourceWaitType::WaitForMessage;

if (stepTimerStatus != StepTimerStatus::ForceNewFrame) {
break;
}

// 强制帧
[[fallthrough]];
case FrameSourceState::NewFrame:
waitMsgForNewFrame = false;
_stepTimer.PrepareForRender();
_BackendRender(outputTexture);
break;
Expand Down

0 comments on commit 6c65469

Please sign in to comment.