Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/win/pxTimerNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ limitations under the License.

// pxTimerNative.cpp

#include <windows.h>
#include <stdint.h>

static bool gFreqInitialized = false;
static LARGE_INTEGER gFreq;
#include "pxTimerNative.h"

double pxSeconds()
{
Expand Down
32 changes: 32 additions & 0 deletions src/win/pxTimerNative.h
Original file line number Diff line number Diff line change
@@ -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 <windows.h>
#include <stdint.h>

static bool gFreqInitialized = false;
static LARGE_INTEGER gFreq;

double pxSeconds();

double pxMilliseconds();

double pxMicroseconds();
void pxSleepMS(uint32_t sleepMS);
11 changes: 9 additions & 2 deletions src/win/pxWindowNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ limitations under the License.
#include "../pxWindowUtil.h"

#include "../pxKeycodes.h"
#include "pxTimerNative.h"

#ifndef WINCE
#include <tchar.h>
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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:
Expand Down