Skip to content

Commit

Permalink
优化菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
Admenri Chen committed May 14, 2024
1 parent b6f7d32 commit 95955eb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
9 changes: 9 additions & 0 deletions content/public/graphics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,15 @@ void Graphics::DrawSettingsWindowInternal() {

void Graphics::DrawGraphicsSettingsGUI() {
if (ImGui::CollapsingHeader("Graphics")) {
ImGui::TextWrapped("Renderer: %s", renderer::GL.GetString(GL_RENDERER));
ImGui::Separator();
ImGui::TextWrapped("Vendor: %s", renderer::GL.GetString(GL_VENDOR));
ImGui::Separator();
ImGui::TextWrapped("Version: %s", renderer::GL.GetString(GL_VERSION));
ImGui::Separator();
ImGui::Text("Average FPS: %d", share_data_->display_fps);
ImGui::Separator();

// V-Sync
int gl_vsync;
SDL_GL_GetSwapInterval(&gl_vsync);
Expand Down
29 changes: 5 additions & 24 deletions content/worker/event_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace content {

EventRunner::EventRunner(WorkerShareData* share_data)
: share_data_(share_data),
fps_counter_{false, 0, SDL_GetPerformanceCounter(),
fps_counter_{0, SDL_GetPerformanceCounter(),
SDL_GetPerformanceFrequency(), 0} {
share_data_->user_event_id = SDL_RegisterEvents(EVENT_NUMS);
}
Expand Down Expand Up @@ -67,11 +67,11 @@ void EventRunner::EventDispatch(const SDL_Event& event) {
uint64_t now_ticks = SDL_GetPerformanceCounter();
uint64_t delta_ticks = now_ticks - fps_counter_.last_counter;
if (delta_ticks >= fps_counter_.counter_freq) {
if (fps_counter_.enable_display) {
fps_counter_.average_fps = fps_counter_.frame_count;
UpdateFPSDisplay(std::make_optional<int32_t>(fps_counter_.average_fps));
}
// Set display fps
fps_counter_.average_fps = fps_counter_.frame_count;
share_data_->display_fps = fps_counter_.average_fps;

// Update fps
fps_counter_.last_counter = SDL_GetPerformanceCounter();
fps_counter_.frame_count = 0;
}
Expand All @@ -85,15 +85,6 @@ void EventRunner::EventDispatch(const SDL_Event& event) {
if (event.key.keysym.scancode == SDL_SCANCODE_F1) {
// Settings menu
share_data_->enable_settings_menu = !share_data_->enable_settings_menu;
} else if (event.key.keysym.scancode == SDL_SCANCODE_F2) {
// Switch fps display mode
fps_counter_.enable_display = !fps_counter_.enable_display;

std::optional<int32_t> fps = std::nullopt;
if (fps_counter_.enable_display)
fps = std::make_optional<int32_t>(fps_counter_.average_fps);

UpdateFPSDisplay(fps);
} else if (event.key.keysym.scancode == SDL_SCANCODE_F12) {
// Trigger reset process
binding_runner_->RequestReset();
Expand All @@ -111,14 +102,4 @@ void EventRunner::EventDispatch(const SDL_Event& event) {
}
}

void EventRunner::UpdateFPSDisplay(std::optional<int32_t> fps) {
base::WeakPtr<ui::Widget> window = share_data_->window;
scoped_refptr<CoreConfigure> config = share_data_->config;

if (fps.has_value())
return window->SetTitle(config->game_title() +
" - FPS: " + std::to_string(*fps));
return window->SetTitle(config->game_title());
}

} // namespace content
2 changes: 0 additions & 2 deletions content/worker/event_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ class EventRunner : public base::RefCounted<EventRunner> {
private:
static int EventFilter(void* userdata, SDL_Event* event);
void EventDispatch(const SDL_Event& event);
void UpdateFPSDisplay(std::optional<int32_t> fps);

WorkerShareData* share_data_;
base::WeakPtr<BindingRunner> binding_runner_;
base::CallbackListSubscription quit_observer_;
std::unique_ptr<base::RunLoop> loop_runner_;

struct {
bool enable_display;
uint64_t frame_count;
uint64_t last_counter;
uint64_t counter_freq;
Expand Down
1 change: 1 addition & 0 deletions content/worker/worker_share.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct WorkerShareData {
} background_sync;

// GUI Event Queue
int display_fps = 0;
bool enable_settings_menu = false;
bool disable_gui_key_input = false;
moodycamel::ConcurrentQueue<SDL_Event> event_queue;
Expand Down
Binary file removed third_party/ruby.7z
Binary file not shown.

0 comments on commit 95955eb

Please sign in to comment.