Hi all,
[edit: egads... that looked like crap... trying to format the code some]
First time posting here, so I'll try to include all the relevant data... (ie, this is gonna be long
Little bit of background here. I'm using DirectDraw, Win32, and all the (*cough*) annoyances of winbl...Windows programming.
I've been working on my game for a while now and I have always had an annoying problem. Whenever the mouse is moved, the callback function is flooded with WM_MOUSEMOVE messages and almost everything slows down considerably. My framerate still stays high (50, but I'm filling and animating the screen) but any changes done in the callback function take longer to process. It *looks* like I am losing framerate, but I'm really not. The framerate timer does not change but maybe one or two fps.
Here's some sample code:
#include
... <-- do stuff
LRESULT CALLBACK callback(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
// update our mouse here. It just filters out the mouse
// messages and returns if it used it or not. If it used
// it, it skips to the end, otherwise it processes the
// message
if (!mouse.update(msg, lparam))
{
switch (msg)
{
case WM_TIMER:
{
switch (wparam)
{
case FPS30_TIMER: // every 30ms, a message is sent
{
if (++spriteCurr > spriteEnd) spriteCurr = spriteStart;
} break;
case FRAMERATE_TIMER:
{
itoa(framecount, frtext, 10);
framecount = 0;
} break;
}
} break;
...
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmd, int show)
{
...
// set our respective timers to go off
SetTimer(hwnd, FRAMERATE_TIMER, framerate_timer_speed, NULL);
SetTimer(hwnd, FPS30_TIMER, fps30_timer_speed, NULL);
while(1)
{
static const Point frloc = {0, 0}; // framerate position
for (int y = 0; y < 30; y++)
{
Point spriteLoc = {sprman[spriteCurr].width()>>1, y * sprman[spriteCurr].height()};
for (int i = 0; i < 40; i++)
{
screen.blit(spriteLoc, sprmanager[spriteCurr]);
spriteLoc.x += sprmanager[spriteCurr].width();
}
}
fontset.print(frloc, frtext); // framerate counter
screen.publish();
screen.clear();
framecount++;
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage(&msg, NULL, 0, 0))
return msg.wParam;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 1;
}
Here's my mouse.update function from the beginning of the callback function. The first item up for grabs is the mouse move message so it (AFAIK) should return as soon as possible.
int Mouse::update(const unsigned int msg, const unsigned int lparam)
{
if (msg & 0x0200) // is it a valid mouse message?
{
switch (msg)
{
case WM_MOUSEMOVE: { xy = lparam; } break; // set x and y
...
I guess my question is, is there anything I can do about it? If so, I'd really love to know what (as it is *Really* starting to grate on my nerves =p ). Any suggestions, no matter how drastic, are welcome... err... let me rephrase that. Any suggestions, barring skipping DirectX and Winbl...Windows...
Thanks all and sorry for the length.
random
---
Wait, you mean I have to actually... THINK?!
Edited by - random on 5/16/00 10:32:17 PM
---Wait, you mean I have to actually... THINK?!