From de0d7097da84584872284e5916c1c8a6902efd82 Mon Sep 17 00:00:00 2001 From: Eric Date: Wed, 27 Sep 2023 11:08:49 -0700 Subject: [PATCH] fixed issue where vsync setting could be incorrect at launch --- .efrocachemap | 56 +++++++++---------- CHANGELOG.md | 2 +- src/assets/ba_data/python/baenv.py | 2 +- .../base/app_adapter/app_adapter_sdl.cc | 47 ++++++++++------ .../base/app_adapter/app_adapter_sdl.h | 4 +- src/ballistica/base/base.h | 1 + src/ballistica/shared/ballistica.cc | 2 +- 7 files changed, 63 insertions(+), 51 deletions(-) diff --git a/.efrocachemap b/.efrocachemap index 4809a7f7..3a7df5bc 100644 --- a/.efrocachemap +++ b/.efrocachemap @@ -4056,26 +4056,26 @@ "build/assets/windows/Win32/ucrtbased.dll": "2def5335207d41b21b9823f6805997f1", "build/assets/windows/Win32/vc_redist.x86.exe": "b08a55e2e77623fe657bea24f223a3ae", "build/assets/windows/Win32/vcruntime140d.dll": "865b2af4d1e26a1a8073c89acb06e599", - "build/prefab/full/linux_arm64_gui/debug/ballisticakit": "24a88ffc78cd3f59a7fa7df974d79e25", - "build/prefab/full/linux_arm64_gui/release/ballisticakit": "ba97e6d831cfc129ebc46443b49c3055", - "build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "f054f613e6a053a281b3d75c0bc19a8b", - "build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "c95435393ac3946b0cdd288cea6fd578", - "build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "a0ef35af73a0d6566f57cd57c603c3cd", - "build/prefab/full/linux_x86_64_gui/release/ballisticakit": "ef54d4c6043e4fd789936d5fc60757af", - "build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "a2dc425aa51d6fd086346e9418d21b97", - "build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "73ba9c896b534902308178627e67746b", - "build/prefab/full/mac_arm64_gui/debug/ballisticakit": "bc6e2a93f1cb4cf0b19ceb577eb15ab9", - "build/prefab/full/mac_arm64_gui/release/ballisticakit": "4e813fd82f679f2d87d420535cd0d549", - "build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "24497a56d078c29c8ebaca01b655dc7c", - "build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "955dd7032ecd7fb0e329a40964cdebb3", - "build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "cb0519ef32e0e5a2cdcb0405def7bd9c", - "build/prefab/full/mac_x86_64_gui/release/ballisticakit": "df6c673f248be2612388edc56b1e5288", - "build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "a4913759d8f9b6013fae9c213441298d", - "build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "1f4534097a3b1bfa1f26aec4e7eefff3", - "build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "c97a6cc985522514c5ba5b57cd4a6b70", - "build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "4cd0b0cd2f114ef58dc25cf148e3be64", - "build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "4beca89d3ef221cf195bef82933a5e96", - "build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "6d97073ef999fe7e44fa9aa8ef1b5a42", + "build/prefab/full/linux_arm64_gui/debug/ballisticakit": "6c81d1a60622f49d40044c8706d7bb05", + "build/prefab/full/linux_arm64_gui/release/ballisticakit": "62fc890f8f89c61ac4f9115398d5bb39", + "build/prefab/full/linux_arm64_server/debug/dist/ballisticakit_headless": "6efb3f630d26baeb2b80c30cdddf90aa", + "build/prefab/full/linux_arm64_server/release/dist/ballisticakit_headless": "7617fda847c7d266ebe51869c2da87d6", + "build/prefab/full/linux_x86_64_gui/debug/ballisticakit": "0ccb43af7bcb2e4168f06ad9da5d75c9", + "build/prefab/full/linux_x86_64_gui/release/ballisticakit": "3eaf0b2db096db79515e92882125c0ad", + "build/prefab/full/linux_x86_64_server/debug/dist/ballisticakit_headless": "54abd8dbfcbeaa4a083a500346cfdc08", + "build/prefab/full/linux_x86_64_server/release/dist/ballisticakit_headless": "ddac92f49840d335e22ee96f18219651", + "build/prefab/full/mac_arm64_gui/debug/ballisticakit": "dde541c9422b550b1ee2f449893d870e", + "build/prefab/full/mac_arm64_gui/release/ballisticakit": "fbc55e0085fdf93d0a5245576df6b1f0", + "build/prefab/full/mac_arm64_server/debug/dist/ballisticakit_headless": "1ff2fd68ad51c33de16e2e08d08d9394", + "build/prefab/full/mac_arm64_server/release/dist/ballisticakit_headless": "4886ab5f22950161fbe87c8fade07453", + "build/prefab/full/mac_x86_64_gui/debug/ballisticakit": "e1cd77c418b9ad22a31c654c76954c5a", + "build/prefab/full/mac_x86_64_gui/release/ballisticakit": "4eba3abcc02e5375568e28af3aba8f24", + "build/prefab/full/mac_x86_64_server/debug/dist/ballisticakit_headless": "071455b304d2cc338e83410885152a1b", + "build/prefab/full/mac_x86_64_server/release/dist/ballisticakit_headless": "8ad0a29cc1fd06e643ff2d2b74b74813", + "build/prefab/full/windows_x86_gui/debug/BallisticaKit.exe": "20c983102789107cfbf197c6798f184a", + "build/prefab/full/windows_x86_gui/release/BallisticaKit.exe": "86c6eb5770512d5c838745282f7beb2e", + "build/prefab/full/windows_x86_server/debug/dist/BallisticaKitHeadless.exe": "d4584a0b3f5ba812ee7100df1f24edc6", + "build/prefab/full/windows_x86_server/release/dist/BallisticaKitHeadless.exe": "3522a8eb50e7898ecd388402cd765848", "build/prefab/lib/linux_arm64_gui/debug/libballisticaplus.a": "f3d305e647a7f77dd70a48f615cfd750", "build/prefab/lib/linux_arm64_gui/release/libballisticaplus.a": "931ce8eab9859d20ad86c47d196ba62c", "build/prefab/lib/linux_arm64_server/debug/libballisticaplus.a": "f3d305e647a7f77dd70a48f615cfd750", @@ -4092,14 +4092,14 @@ "build/prefab/lib/mac_x86_64_gui/release/libballisticaplus.a": "097e17c460bf798edf61303789860596", "build/prefab/lib/mac_x86_64_server/debug/libballisticaplus.a": "14df40bc07bdde8184843d16d5ba7798", "build/prefab/lib/mac_x86_64_server/release/libballisticaplus.a": "097e17c460bf798edf61303789860596", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.lib": "8542bbc154faedf633dd82bc78dc50b7", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.pdb": "eb625ccd56cd37e26b6abb99ecc385c3", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.lib": "835d9280dddb9fa6554e631184a62f6d", - "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.pdb": "5aca1f8dfd9ff294cf2ec2229e393d8e", - "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.lib": "f270764cfbb3791752fbd265b5787889", - "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.pdb": "64ca7172f66176fef0ef71d5b1e51663", - "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.lib": "81b8aeeecb650f57d4f89636cbdf5916", - "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.pdb": "a3c06c787f387c586de3ff6b092c32dc", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.lib": "72c03bbb9007b347430bb2b8811cc258", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitGenericPlus.pdb": "e1507e2630f191c970f972a39c167fb8", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.lib": "b5008266d94788e17ca01722ce4a5515", + "build/prefab/lib/windows/Debug_Win32/BallisticaKitHeadlessPlus.pdb": "d5df3b94bc7bf8cc50f75e587e03d308", + "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.lib": "ec7073a212061ba663a50222fd0d2fba", + "build/prefab/lib/windows/Release_Win32/BallisticaKitGenericPlus.pdb": "210f6d639f2820241f7d86168b82ddf8", + "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.lib": "8d57e179388d27c77b0b6d3276d0ced5", + "build/prefab/lib/windows/Release_Win32/BallisticaKitHeadlessPlus.pdb": "f3dc84fd4772d0107ec297852f17ef33", "src/assets/ba_data/python/babase/_mgen/__init__.py": "f885fed7f2ed98ff2ba271f9dbe3391c", "src/assets/ba_data/python/babase/_mgen/enums.py": "f8cd3af311ac63147882590123b78318", "src/ballistica/base/mgen/pyembed/binding_base.inc": "c81b2b1f3a14b4cd20a7b93416fe893a", diff --git a/CHANGELOG.md b/CHANGELOG.md index 76a542c2..3a8c6aee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -### 1.7.28 (build 21385, api 8, 2023-09-27) +### 1.7.28 (build 21386, api 8, 2023-09-27) - Massively cleaned up code related to rendering and window systems (OpenGL, SDL, etc). This code had been growing into a nasty tangle for 15 years diff --git a/src/assets/ba_data/python/baenv.py b/src/assets/ba_data/python/baenv.py index ad6f61ac..a10a6bb7 100644 --- a/src/assets/ba_data/python/baenv.py +++ b/src/assets/ba_data/python/baenv.py @@ -52,7 +52,7 @@ if TYPE_CHECKING: # Build number and version of the ballistica binary we expect to be # using. -TARGET_BALLISTICA_BUILD = 21385 +TARGET_BALLISTICA_BUILD = 21386 TARGET_BALLISTICA_VERSION = '1.7.28' diff --git a/src/ballistica/base/app_adapter/app_adapter_sdl.cc b/src/ballistica/base/app_adapter/app_adapter_sdl.cc index a4a0551e..7bac9ec9 100644 --- a/src/ballistica/base/app_adapter/app_adapter_sdl.cc +++ b/src/ballistica/base/app_adapter/app_adapter_sdl.cc @@ -141,7 +141,7 @@ void AppAdapterSDL::RunMainThreadEventLoopToCompletion() { // to the edges. Note that we want this tweak to be small enough that it // won't be noticable in situations where vsync and max-fps *don't* // match. (for instance limiting to 60hz on a 120hz vsynced monitor). - if (vsync_enabled_) { + if (vsync_actually_enabled_) { millisecs_per_frame = 99 * millisecs_per_frame / 100; } microsecs_t target_time = @@ -296,7 +296,6 @@ void AppAdapterSDL::HandleSDLEvent_(const SDL_Event& event) { case SDL_WINDOWEVENT: { switch (event.window.event) { case SDL_WINDOWEVENT_MAXIMIZED: { - printf("MAXIMIZED\n"); if (g_buildconfig.ostype_macos() && !fullscreen_) { // Special case: on Mac, we wind up here if someone fullscreens // our window via the window widget. This *basically* is the @@ -316,9 +315,8 @@ void AppAdapterSDL::HandleSDLEvent_(const SDL_Event& event) { } case SDL_WINDOWEVENT_RESTORED: - printf("RESTORED\n"); if (g_buildconfig.ostype_macos() && fullscreen_) { - // See note above. + // See note above about Mac fullscreen. fullscreen_ = false; g_base->logic->event_loop()->PushCall([] { g_base->python->objs() @@ -329,18 +327,15 @@ void AppAdapterSDL::HandleSDLEvent_(const SDL_Event& event) { break; case SDL_WINDOWEVENT_MINIMIZED: - printf("MINIMIZED\n"); break; case SDL_WINDOWEVENT_HIDDEN: { // PauseApp(); - printf("HIDDEN\n"); break; } case SDL_WINDOWEVENT_SHOWN: { // ResumeApp(); - printf("SHOWN\n"); break; } @@ -495,33 +490,49 @@ void AppAdapterSDL::SetScreen_( } // VSync always gets set independent of the screen (though we set it down - // here to make sure we have one). - if (vsync_requested != vsync_) { - switch (vsync_requested) { - case VSyncRequest::kNever: { + // here to make sure we have a screen when its set). + VSync vsync; + switch (vsync_requested) { + case VSyncRequest::kNever: + vsync = VSync::kNever; + break; + case VSyncRequest::kAlways: + vsync = VSync::kAlways; + break; + case VSyncRequest::kAuto: + vsync = VSync::kAdaptive; + break; + default: + vsync = VSync::kNever; + break; + } + if (vsync != vsync_) { + switch (vsync) { + case VSync::kUnset: + case VSync::kNever: { SDL_GL_SetSwapInterval(0); - vsync_enabled_ = false; + vsync_actually_enabled_ = false; break; } - case VSyncRequest::kAlways: { + case VSync::kAlways: { SDL_GL_SetSwapInterval(1); - vsync_enabled_ = true; + vsync_actually_enabled_ = true; break; } - case VSyncRequest::kAuto: { + case VSync::kAdaptive: { // In this case, let's try setting to 'adaptive' and turn it off if // that is unsupported. auto result = SDL_GL_SetSwapInterval(-1); if (result == 0) { - vsync_enabled_ = true; + vsync_actually_enabled_ = true; } else { SDL_GL_SetSwapInterval(0); - vsync_enabled_ = false; + vsync_actually_enabled_ = false; } break; } } - vsync_ = vsync_requested; + vsync_ = vsync; } // This we can set anytime. Probably could have just set it from the logic diff --git a/src/ballistica/base/app_adapter/app_adapter_sdl.h b/src/ballistica/base/app_adapter/app_adapter_sdl.h index 4c02e4b7..3cb3e442 100644 --- a/src/ballistica/base/app_adapter/app_adapter_sdl.h +++ b/src/ballistica/base/app_adapter/app_adapter_sdl.h @@ -78,8 +78,8 @@ class AppAdapterSDL : public AppAdapter { // SDL_Surface* sdl_screen_surface_{}; bool done_{}; bool fullscreen_{}; - VSyncRequest vsync_{VSyncRequest::kNever}; - bool vsync_enabled_{}; + VSync vsync_{VSync::kUnset}; + bool vsync_actually_enabled_{}; microsecs_t oversleep{}; int max_fps_{60}; bool debug_log_sdl_frame_timing_{}; diff --git a/src/ballistica/base/base.h b/src/ballistica/base/base.h index 673e639f..723b764d 100644 --- a/src/ballistica/base/base.h +++ b/src/ballistica/base/base.h @@ -175,6 +175,7 @@ enum class GraphicsQuality { kHigher, }; +enum class VSync { kUnset, kNever, kAlways, kAdaptive }; enum class VSyncRequest { kNever, kAlways, kAuto }; /// Requests for exact or auto graphics quality values. diff --git a/src/ballistica/shared/ballistica.cc b/src/ballistica/shared/ballistica.cc index 9a28a58e..50529af6 100644 --- a/src/ballistica/shared/ballistica.cc +++ b/src/ballistica/shared/ballistica.cc @@ -39,7 +39,7 @@ auto main(int argc, char** argv) -> int { namespace ballistica { // These are set automatically via script; don't modify them here. -const int kEngineBuildNumber = 21385; +const int kEngineBuildNumber = 21386; const char* kEngineVersion = "1.7.28"; const int kEngineApiVersion = 8;