Commit MetaInfo

Revisãob041acc1610d575028317409e679f2c7e1eff7d0 (tree)
Hora2020-03-02 04:09:14
AutorDavid Ludwig <dludwig@pobo...>
CommiterDavid Ludwig

Mensagem de Log

misc code cleanups

Mudança Sumário

Diff

diff -r 93a27092163b -r b041acc1610d main.cpp
--- a/main.cpp Sat Feb 29 17:52:40 2020 -0500
+++ b/main.cpp Sun Mar 01 14:09:14 2020 -0500
@@ -36,10 +36,19 @@
3636 #include "emscripten.h"
3737 #endif
3838
39+static bool isRunning = true;
40+static SDL_Renderer * renderer = nullptr;
41+static Uint64 currentTime = 0;
42+static Uint64 timeFrequency = 0;
43+static bool didCopyMapping = false;
3944
4045 // TODO: persist these on-disk
4146 static bool autoOpenJoysticks = false;
4247 static bool autoOpenGameControllers = true;
48+static bool showGameControllerMappingUnformatted = false;
49+static bool showWindowImGuiDemo = false;
50+static bool showWindowJoysticks = true;
51+static bool showWindowGameControllers = true;
4352
4453
4554 extern bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
@@ -739,6 +748,9 @@
739748
740749 // if (ImGui::Button("Add Virtual Game Controller")) {
741750 // }
751+ // ImGui::SameLine();
752+ // ImGui::Dummy(ImVec2(32,0));
753+ // ImGui::SameLine();
742754
743755 std::vector<int> controller_indices;
744756 int num_controllers = 0;
@@ -748,9 +760,6 @@
748760 controller_indices.push_back(i);
749761 }
750762 }
751- ImGui::SameLine();
752- ImGui::Dummy(ImVec2(32,0));
753- ImGui::SameLine();
754763 ImGui::Text("Controllers, Total-Count: %d", num_controllers);
755764
756765 ImGui::Separator();
@@ -817,9 +826,8 @@
817826 ImGui::Text("%s", (mapping ? "YES" : "NO"));
818827 if (mapping) {
819828 ImGui::SameLine();
820- static bool did_copy = false;
821829 if (ImGui::Button("Show...")) {
822- did_copy = false;
830+ didCopyMapping = false;
823831 ImGui::OpenPopup("Show Mapping");
824832 }
825833 if (ImGui::IsPopupOpen("Show Mapping")) {
@@ -828,19 +836,18 @@
828836 if (ImGui::BeginPopup("Show Mapping")) {
829837 if (ImGui::Button("Copy to clipboard")) {
830838 if (SDL_SetClipboardText(mapping) == 0) { // SDL_SetClipboardText() will convert NULL to "", here
831- did_copy = true;
839+ didCopyMapping = true;
832840 }
833841 }
834- if (did_copy) {
842+ if (didCopyMapping) {
835843 ImGui::SameLine();
836844 ImGui::Text("copied!");
837845 }
838846 ImGui::Separator();
839- static bool show_unformatted = false;
840- ImGui::Checkbox("Show unformatted?", &show_unformatted);
847+ ImGui::Checkbox("Show unformatted?", &showGameControllerMappingUnformatted);
841848 ImGui::Separator();
842849
843- if (show_unformatted || !mapping) {
850+ if (showGameControllerMappingUnformatted || !mapping) {
844851 // const float wrap_width = 235.f;
845852 const float wrap_width = ImGui::GetWindowWidth() - 16.f;
846853 ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + wrap_width);
@@ -1058,9 +1065,6 @@
10581065 ImGui::EndChild();
10591066 }
10601067
1061-static bool isRunning = true;
1062-static SDL_Renderer * renderer = nullptr;
1063-
10641068 void Tick()
10651069 {
10661070 // Process user-input events
@@ -1104,43 +1108,45 @@
11041108 }
11051109
11061110 // Record time-advancement
1107- static Uint64 g_Time = 0;
1108- static const Uint64 frequency = SDL_GetPerformanceFrequency();
1109- const Uint64 current_time = SDL_GetPerformanceCounter();
1110- io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
1111- g_Time = current_time;
1111+ if (timeFrequency == 0) {
1112+ timeFrequency = SDL_GetPerformanceFrequency();
1113+ }
1114+ const Uint64 previousTime = currentTime;
1115+ currentTime = SDL_GetPerformanceCounter();
1116+ if (previousTime > 0) {
1117+ io.DeltaTime = (float)((double)(currentTime - previousTime) / timeFrequency);
1118+ } else {
1119+ io.DeltaTime = (float)(1.0f / 60.0f);
1120+ }
11121121
11131122 // Update mouse inputs
11141123 int mouseX, mouseY;
1115- const int buttons = SDL_GetMouseState(&mouseX, &mouseY);
1124+ const int mouseButtonState = SDL_GetMouseState(&mouseX, &mouseY);
11161125 io.MousePos = ImVec2(static_cast<float>(mouseX), static_cast<float>(mouseY));
1117- io.MouseDown[0] = buttons & SDL_BUTTON(SDL_BUTTON_LEFT);
1118- io.MouseDown[1] = buttons & SDL_BUTTON(SDL_BUTTON_RIGHT);
1126+ io.MouseDown[0] = mouseButtonState & SDL_BUTTON(SDL_BUTTON_LEFT);
1127+ io.MouseDown[1] = mouseButtonState & SDL_BUTTON(SDL_BUTTON_RIGHT);
11191128 io.MouseWheel = static_cast<float>(wheel);
11201129
11211130 // Tell ImGui that we're ready to draw a new frame
11221131 ImGui::NewFrame();
11231132
11241133 // Layout this frame's ImGui
1125- static bool show_window_imgui_demo = false;
1126- static bool show_window_joysticks = true;
1127- static bool show_window_game_controllers = true;
11281134 if (ImGui::BeginMainMenuBar()) {
11291135 if (ImGui::BeginMenu("View")) {
1130- ImGui::MenuItem("Game Controllers...", NULL, &show_window_game_controllers);
1131- ImGui::MenuItem("ImGui Demo Window...", NULL, &show_window_imgui_demo);
1132- ImGui::MenuItem("Joysticks...", NULL, &show_window_joysticks);
1136+ ImGui::MenuItem("Game Controllers...", NULL, &showWindowGameControllers);
1137+ ImGui::MenuItem("ImGui Demo Window...", NULL, &showWindowImGuiDemo);
1138+ ImGui::MenuItem("Joysticks...", NULL, &showWindowJoysticks);
11331139 ImGui::EndMenu();
11341140 }
11351141 ImGui::EndMainMenuBar();
11361142 }
1137- if (show_window_imgui_demo) {
1143+ if (showWindowImGuiDemo) {
11381144 ImGui::ShowDemoWindow();
11391145 }
1140- if (show_window_joysticks) {
1146+ if (showWindowJoysticks) {
11411147 ShowJoystickMainWindow();
11421148 }
1143- if (show_window_game_controllers) {
1149+ if (showWindowGameControllers) {
11441150 ShowGameControllersMainWindow();
11451151 }
11461152
Show on old repository browser