PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Problem with timer :(

Hi all,

I'm trying to use timer in a new game. I followed GR Moore instructions but I must be doing something wrong, the timerproc would't be called.

Here's the code :

Code:

class MyApp : public CGapiApplicationMTwithSound
{
[...]
};

void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);

HRESULT MyApp::InitInstance()
{
m_iTimerID = SetTimer ( NULL, 0, 100, ( TIMERPROC ) TimerProc );
if ( m_iTimerID == 0 ) return E_FAIL;

return S_OK;
}

HRESULT MyApp::ExitInstance()
{
KillTimer ( NULL, m_iTimerID );

return S_OK;
}

void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime)
{
// the stuff here is not executed :(
}



Please tell me if you see a mistake, I really do not want to base animations on frame rate for this game ;)
Thanks
The code you're showing is correct - in fact, other than the time (100ms), its exactly what I'm using in Warlords to control timed functions. What code do you have in TimerProc? If it is slow code, you have the potential of a race condition whereby you call the code again without ever finishing the previous call. All I do in my callback is increment some counters to track the elapsed time. (Good to hear from you again seb0uille!)
GR the Timer Expert :-)

I remember GRs big help with my BOTG game timer.
mmm looks like the problem is CGapiApplicationMTwithSound. I tried the same code with CGapiApplication and it worked perfectly...
I think that wont work with MultiThreading :-( I tried that with my other game using the MT but it behaves crazy hehe
I'm not sure if the 2.0 multithreaded behaves the same (I haven't tested it), but under GD1.04 the timer works fine with the multithreaded framework (both pocketPachisi and 5 Card Spin use it). You might try creating the timer on the first pass through ProcessNextFrame to ensure you are on the draw thread. You can do this by testing if m_timerID == 0 in ProcessNextFrame and creating then creating it. As long as m_timerID > 0 then you won't recreate the timer.
Thanks for your help, but...
- It didn't work with MT, even when I created the timer in ProcessNextFrame

- I tried to replace CGapiApplicationMTWithSound by CGapiDrawApplicationWithSound (the one that should be single threaded) but despite my efforts it wouldn't compile :(
I'm still using 2.01b, maybe there's something with that.

I enventually decided to give up trying to add sound for the game...
Post your code or drop Gersen a note. This will help especially there are readers here who can help you. I'm using Hekkus and it's great :-)
Hi, I'm new to this forum, GapiDraw, CE programming and even Windows programming.....
so be warned to read some stupid questions :P

i need a timer, but it just doesn't work...

I use EVC4, GapiDraw301 and code like this (from ppcstudios...):

Code:
m_Timer = SetTimer(NULL,0,100, (TIMERPROC) TimerProc );

I've made the "void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);" function a member of CMyApplication to get access to the member variables and get compile errors:
myapplication.cpp(138) : error C2440: 'type cast' : cannot convert from '' to 'void (__cdecl *)(struct HWND__ *,unsigned int,unsigned int,unsigned long)'
None of the functions with this name in scope match the target type

Can anyone tell me, what I'm doing wrong, please?
SetTimer seems to expect some function pointer, but I don't really understand, what this is all about. :oops:


EDIT: Okay, I think this one was really stupid. I've placed some variables to other places and now it should work. So no help needed anymore, got it running by myself :) Nevertheless thanks for your support in this place!
Pejo Software - Per · 01 Sep 2004, 14:29 UTC
If you make the TimerProc a member of CApplication it needs to be static.
If someone is still interested I have updated my GapiDraw+Hekkus sample (GD 3.01b and Hekkus 0.99.x).
Later I will add a sample for GD 3.5.
You can find all on my website.

Have fun :)
If you make the TimerProc a member of CApplication it needs to be static.

Thanks for answering, but how can I access the non static member variables and functions in the static callback function?
Would be great if I could do a GetBackbuffer() for example...
Sorry, if I show some newbie behaviour :(