Skip to content

Commit

Permalink
move window manager start_frame logic to is_frame_ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Archez committed Jan 9, 2025
1 parent 9f810af commit c8bbc4d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 10 deletions.
4 changes: 4 additions & 0 deletions src/graphic/Fast3D/Fast3dWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ void Fast3dWindow::StartFrame() {
void Fast3dWindow::EndFrame() {
}

bool Fast3dWindow::IsFrameReady() {
return mWindowManagerApi->is_frame_ready();
}

void Fast3dWindow::SetCursorVisibility(bool visible) {
mWindowManagerApi->set_cursor_visibility(visible);
}
Expand Down
1 change: 1 addition & 0 deletions src/graphic/Fast3D/Fast3dWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Fast3dWindow : public Ship::Window {
void Close() override;
void StartFrame() override;
void EndFrame() override;
bool IsFrameReady() override;
void SetCursorVisibility(bool visible) override;
uint32_t GetWidth() override;
uint32_t GetHeight() override;
Expand Down
4 changes: 2 additions & 2 deletions src/graphic/Fast3D/gfx_dxgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ static uint64_t qpc_to_100ns(uint64_t qpc) {
qpc % dxgi.qpc_freq * _100NANOSECONDS_IN_SECOND / dxgi.qpc_freq;
}

static bool gfx_dxgi_start_frame() {
static bool gfx_dxgi_is_frame_ready() {
DXGI_FRAME_STATISTICS stats;
if (dxgi.swap_chain->GetFrameStatistics(&stats) == S_OK &&
(stats.SyncRefreshCount != 0 || stats.SyncQPCTime.QuadPart != 0ULL)) {
Expand Down Expand Up @@ -1058,7 +1058,7 @@ extern "C" struct GfxWindowManagerAPI gfx_dxgi_api = { gfx_dxgi_init,
gfx_dxgi_is_mouse_captured,
gfx_dxgi_get_dimensions,
gfx_dxgi_handle_events,
gfx_dxgi_start_frame,
gfx_dxgi_is_frame_ready,
gfx_dxgi_swap_buffers_begin,
gfx_dxgi_swap_buffers_end,
gfx_dxgi_get_time,
Expand Down
14 changes: 9 additions & 5 deletions src/graphic/Fast3D/gfx_pc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4123,6 +4123,10 @@ struct GfxRenderingAPI* gfx_get_current_rendering_api() {
return gfx_rapi;
}

bool gfx_is_frame_ready() {
return gfx_wapi->is_frame_ready();
}

void gfx_start_frame() {
gfx_wapi->handle_events();
gfx_wapi->get_dimensions(&gfx_current_window_dimensions.width, &gfx_current_window_dimensions.height,
Expand Down Expand Up @@ -4189,11 +4193,11 @@ void gfx_run(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtx_replacemen
get_pixel_depth_pending.clear();
get_pixel_depth_cached.clear();

if (!gfx_wapi->start_frame()) {
dropped_frame = true;
// Ship::Context::GetInstance()->GetWindow()->GetGui()->Draw();
return;
}
// if (!gfx_wapi->start_frame()) {
// dropped_frame = true;
// // Ship::Context::GetInstance()->GetWindow()->GetGui()->Draw();
// return;
// }
dropped_frame = false;

current_mtx_replacements = &mtx_replacements;
Expand Down
1 change: 1 addition & 0 deletions src/graphic/Fast3D/gfx_pc.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void gfx_start_frame();

// Since this function is "exposted" to the games, it needs to take a normal Gfx
void gfx_run(Gfx* commands, const std::unordered_map<Mtx*, MtxF>& mtx_replacements);
bool gfx_is_frame_ready();
void gfx_end_frame();
void gfx_set_target_ucode(UcodeHandlers ucode);
void gfx_set_target_fps(int);
Expand Down
4 changes: 2 additions & 2 deletions src/graphic/Fast3D/gfx_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ static void gfx_sdl_handle_events() {
}
}

static bool gfx_sdl_start_frame() {
static bool gfx_sdl_is_frame_ready() {
return true;
}

Expand Down Expand Up @@ -709,7 +709,7 @@ struct GfxWindowManagerAPI gfx_sdl = { gfx_sdl_init,
gfx_sdl_is_mouse_captured,
gfx_sdl_get_dimensions,
gfx_sdl_handle_events,
gfx_sdl_start_frame,
gfx_sdl_is_frame_ready,
gfx_sdl_swap_buffers_begin,
gfx_sdl_swap_buffers_end,
gfx_sdl_get_time,
Expand Down
2 changes: 1 addition & 1 deletion src/graphic/Fast3D/gfx_window_manager_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct GfxWindowManagerAPI {
bool (*is_mouse_captured)();
void (*get_dimensions)(uint32_t* width, uint32_t* height, int32_t* posX, int32_t* posY);
void (*handle_events)();
bool (*start_frame)();
bool (*is_frame_ready)();
void (*swap_buffers_begin)();
void (*swap_buffers_end)();
double (*get_time)(); // For debug
Expand Down
1 change: 1 addition & 0 deletions src/window/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Window {
virtual void Close() = 0;
virtual void StartFrame() = 0;
virtual void EndFrame() = 0;
virtual bool IsFrameReady() = 0;
virtual void SetCursorVisibility(bool visible) = 0;
virtual uint32_t GetWidth() = 0;
virtual uint32_t GetHeight() = 0;
Expand Down

0 comments on commit c8bbc4d

Please sign in to comment.