Hello everyone, it’s my first post here (but I’ve been watching this list for some time)
I’ve borrowed kernel/task design from Enginuity (series of articles on GameDev) and slightly modificated it to fit into my needs, I also borrowed it’s input design. Now my input system looks like this (cut unrelated things):
class InputTask : public ITask
{
public:
…
bool CurrentKey(usint _index)
{
return (actKeys[_index] != 0 );
}
// -------------------------------------------------
bool OldKey(usint _index)
{
return (oldKeys[_index] != 0 );
}
// -------------------------------------------------
bool KeyboardKeyNowDown(usint _index)
{
return ( CurrentKey(_index)) && (!OldKey(_index));
}
// -------------------------------------------------
bool KeyboardKeyStillDown(usint _index)
{
return ( CurrentKey(_index)) && ( OldKey(_index));
}
// -------------------------------------------------
uchar * actKeys; // unsigned char
uchar * oldKeys;
ulint keyCount; // unsigned long int
};
bool InputTask :: Start()
{
actKeys = SDL_GetKeyState((int*) &keyCount );
oldKeys = new uchar[keyCount];
if (!oldKeys) return false;
// call twice to flush any pending key presses
SDL_PumpEvents();
SDL_PumpEvents();
return true;
}
void InputTask :: Update()
{
SDL_PumpEvents();
…
memcpy( oldKeys, actKeys, sizeof(uchar) * keyCount);
actKeys = SDL_GetKeyState((int*) &keyCount);
}
void InputTask :: Stop()
{
delete [] oldKeys;
}
Now, at first glance everything looks nice, but when you run test program, you’ll notice that KeyboardKeyNowDown doesn’t work! I’ve experimented with it for some time but nothing helped. I’s even more strange beacose KeyboardKeyStillDown works fine, and it’s design is very similiar (to be precise, it’s nearly identical except for !) to KeyboardKeyNowDown. Additionaly, I use identical approach when dealing with mouse input, and do I have to tell that it works perfectly? :-] I’ve run out of ideas what can be wrong here, so any advices will be very appreciated!
Thanks in advance!–
Koshmaar
<Of all the things I’'ve lost, I miss my mind the most>
GG: 3928072
http://jnr.sourceforge.net/
www.pongowar.prv.pl
www.liero-turbo.prv.pl