diff --git a/src/win/pxTimerNative.cpp b/src/win/pxTimerNative.cpp index 42f25df579..45a16453f8 100755 --- a/src/win/pxTimerNative.cpp +++ b/src/win/pxTimerNative.cpp @@ -18,11 +18,7 @@ limitations under the License. // pxTimerNative.cpp -#include -#include - -static bool gFreqInitialized = false; -static LARGE_INTEGER gFreq; +#include "pxTimerNative.h" double pxSeconds() { diff --git a/src/win/pxTimerNative.h b/src/win/pxTimerNative.h new file mode 100755 index 0000000000..d45430c2b5 --- /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.h + +#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..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 @@ -159,6 +160,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 +173,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 +285,8 @@ LRESULT __stdcall pxWindowNative::windowProc(HWND hWnd, UINT msg, WPARAM wParam, } // re resolve the window ptr since we have destroyed it - + + double startT = 0; w = (pxWindowNative*)getWindowPtr(hWnd); if (w) { @@ -410,8 +415,10 @@ 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(); + w->mTimerId = SetTimer(w->mWindow, 1, (1000 / sFPS) - (pxSeconds() - startT), NULL); break; case WM_KEYDOWN: