From ecb461ce0cd404ee13c1b94c707afd8a5953e6a1 Mon Sep 17 00:00:00 2001 From: ashkalokhe Date: Fri, 17 Jan 2020 15:41:44 -0500 Subject: [PATCH 1/6] added fix for lower fps speed on windows --- src/win/pxTimerNative.cpp | 3 +-- src/win/pxTimerNative.h | 32 ++++++++++++++++++++++++++++++++ src/win/pxWindowNative.cpp | 9 ++++++++- 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100755 src/win/pxTimerNative.h diff --git a/src/win/pxTimerNative.cpp b/src/win/pxTimerNative.cpp index 42f25df579..e555d78544 100755 --- a/src/win/pxTimerNative.cpp +++ b/src/win/pxTimerNative.cpp @@ -18,8 +18,7 @@ limitations under the License. // pxTimerNative.cpp -#include -#include +#include "pxTimerNative.h" static bool gFreqInitialized = false; static LARGE_INTEGER gFreq; diff --git a/src/win/pxTimerNative.h b/src/win/pxTimerNative.h new file mode 100755 index 0000000000..cae6cdb5eb --- /dev/null +++ b/src/win/pxTimerNative.h @@ -0,0 +1,32 @@ +/* + +pxCore Copyright 2005-2018 John Robinson + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +*/ + +// pxTimerNative.cpp + +#include +#include + +static bool gFreqInitialized = false; +static LARGE_INTEGER gFreq; + +double pxSeconds(); + +double pxMilliseconds(); + +double pxMicroseconds(); +void pxSleepMS(uint32_t sleepMS); diff --git a/src/win/pxWindowNative.cpp b/src/win/pxWindowNative.cpp index d85b7bbce0..36455f2c39 100755 --- a/src/win/pxWindowNative.cpp +++ b/src/win/pxWindowNative.cpp @@ -159,6 +159,7 @@ void pxWindow::setVisibility(bool visible) ShowWindow(mWindow, visible?SW_SHOW:SW_HIDE); } +static int sFPS = 0; pxError pxWindow::setAnimationFPS(uint32_t fps) { #if 0 @@ -171,6 +172,8 @@ pxError pxWindow::setAnimationFPS(uint32_t fps) if (fps > 0) { mTimerId = SetTimer(mWindow, 1, 1000/fps, NULL); + + sFPS = fps; } return PX_OK; #else @@ -281,7 +284,8 @@ LRESULT __stdcall pxWindowNative::windowProc(HWND hWnd, UINT msg, WPARAM wParam, } // re resolve the window ptr since we have destroyed it - + + double currT = 0; w = (pxWindowNative*)getWindowPtr(hWnd); if (w) { @@ -411,7 +415,10 @@ LRESULT __stdcall pxWindowNative::windowProc(HWND hWnd, UINT msg, WPARAM wParam, case WM_TIMER: // Should filter this to a single id + currT = pxSeconds(); w->onAnimationTimer(); + //printf("\ntime:%d fps:%d", abs(pxSeconds() - currT), w->mAnimationFPS); + w->mTimerId = SetTimer(w->mWindow, 1, (1000 / sFPS) - (pxSeconds() - currT), NULL); break; case WM_KEYDOWN: From 6ffed92a9df74c2f9c35790f1ee70c09b7adffc8 Mon Sep 17 00:00:00 2001 From: ashkalokhe Date: Fri, 17 Jan 2020 15:42:35 -0500 Subject: [PATCH 2/6] cleanup --- src/win/pxTimerNative.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/win/pxTimerNative.h b/src/win/pxTimerNative.h index cae6cdb5eb..d45430c2b5 100755 --- a/src/win/pxTimerNative.h +++ b/src/win/pxTimerNative.h @@ -16,7 +16,7 @@ limitations under the License. */ -// pxTimerNative.cpp +// pxTimerNative.h #include #include From 0067d7d84ad3d289c542e15c6adb0169b5ba1dfd Mon Sep 17 00:00:00 2001 From: ashkalokhe Date: Fri, 17 Jan 2020 15:44:08 -0500 Subject: [PATCH 3/6] renamed var --- src/win/pxWindowNative.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/win/pxWindowNative.cpp b/src/win/pxWindowNative.cpp index 36455f2c39..7a0b9bc947 100755 --- a/src/win/pxWindowNative.cpp +++ b/src/win/pxWindowNative.cpp @@ -285,7 +285,7 @@ LRESULT __stdcall pxWindowNative::windowProc(HWND hWnd, UINT msg, WPARAM wParam, // re resolve the window ptr since we have destroyed it - double currT = 0; + double startT = 0; w = (pxWindowNative*)getWindowPtr(hWnd); if (w) { @@ -415,10 +415,10 @@ LRESULT __stdcall pxWindowNative::windowProc(HWND hWnd, UINT msg, WPARAM wParam, case WM_TIMER: // Should filter this to a single id - currT = pxSeconds(); + startT = pxSeconds(); w->onAnimationTimer(); //printf("\ntime:%d fps:%d", abs(pxSeconds() - currT), w->mAnimationFPS); - w->mTimerId = SetTimer(w->mWindow, 1, (1000 / sFPS) - (pxSeconds() - currT), NULL); + w->mTimerId = SetTimer(w->mWindow, 1, (1000 / sFPS) - (pxSeconds() - startT), NULL); break; case WM_KEYDOWN: From 7553e14d521b5b057afd830848affcc31a848542 Mon Sep 17 00:00:00 2001 From: ashkalokhe Date: Fri, 17 Jan 2020 15:49:33 -0500 Subject: [PATCH 4/6] cleanup --- src/win/pxWindowNative.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/win/pxWindowNative.cpp b/src/win/pxWindowNative.cpp index 7a0b9bc947..57a2d19b35 100755 --- a/src/win/pxWindowNative.cpp +++ b/src/win/pxWindowNative.cpp @@ -414,10 +414,9 @@ LRESULT __stdcall pxWindowNative::windowProc(HWND hWnd, UINT msg, WPARAM wParam, #endif case WM_TIMER: - // Should filter this to a single id + // Should filter this to a single id startT = pxSeconds(); w->onAnimationTimer(); - //printf("\ntime:%d fps:%d", abs(pxSeconds() - currT), w->mAnimationFPS); w->mTimerId = SetTimer(w->mWindow, 1, (1000 / sFPS) - (pxSeconds() - startT), NULL); break; From f9994c1b431cf90af181a3a91613c04d2772ada7 Mon Sep 17 00:00:00 2001 From: ashkalokhe Date: Sat, 18 Jan 2020 11:33:35 -0500 Subject: [PATCH 5/6] cleanup --- src/win/pxTimerNative.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/win/pxTimerNative.cpp b/src/win/pxTimerNative.cpp index e555d78544..45a16453f8 100755 --- a/src/win/pxTimerNative.cpp +++ b/src/win/pxTimerNative.cpp @@ -20,9 +20,6 @@ limitations under the License. #include "pxTimerNative.h" -static bool gFreqInitialized = false; -static LARGE_INTEGER gFreq; - double pxSeconds() { if (!gFreqInitialized) From 68aca649b885404ee08f3dd2e0476607996e1b38 Mon Sep 17 00:00:00 2001 From: ashkalokhe Date: Fri, 24 Jan 2020 10:54:28 -0500 Subject: [PATCH 6/6] fixed missing include --- src/win/pxWindowNative.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win/pxWindowNative.cpp b/src/win/pxWindowNative.cpp index 57a2d19b35..196c869aef 100755 --- a/src/win/pxWindowNative.cpp +++ b/src/win/pxWindowNative.cpp @@ -25,6 +25,7 @@ limitations under the License. #include "../pxWindowUtil.h" #include "../pxKeycodes.h" +#include "pxTimerNative.h" #ifndef WINCE #include