Split CInput::NextFrame() from CInput::Update() (fixes #444)

This commit is contained in:
def 2016-05-01 00:18:25 +02:00
parent a0a7d96ca0
commit 72a6e20ba8
4 changed files with 12 additions and 8 deletions

View file

@ -2809,6 +2809,7 @@ void CClient::Run()
} }
m_pGraphics->Swap(); m_pGraphics->Swap();
} }
Input()->NextFrame();
} }
if(Input()->VideoRestartNeeded()) if(Input()->VideoRestartNeeded())
{ {

View file

@ -126,19 +126,20 @@ bool CInput::KeyState(int Key) const
return m_aInputState[Key>=KEY_MOUSE_1 ? Key : SDL_GetScancodeFromKey(KeyToKeycode(Key))]; return m_aInputState[Key>=KEY_MOUSE_1 ? Key : SDL_GetScancodeFromKey(KeyToKeycode(Key))];
} }
void CInput::NextFrame()
{
int i;
const Uint8 *pState = SDL_GetKeyboardState(&i);
if(i >= KEY_LAST)
i = KEY_LAST-1;
mem_copy(m_aInputState, pState, i);
}
int CInput::Update() int CInput::Update()
{ {
// keep the counter between 1..0xFFFF, 0 means not pressed // keep the counter between 1..0xFFFF, 0 means not pressed
m_InputCounter = (m_InputCounter%0xFFFF)+1; m_InputCounter = (m_InputCounter%0xFFFF)+1;
{
int i;
const Uint8 *pState = SDL_GetKeyboardState(&i);
if(i >= KEY_LAST)
i = KEY_LAST-1;
mem_copy(m_aInputState, pState, i);
}
// these states must always be updated manually because they are not in the GetKeyState from SDL // these states must always be updated manually because they are not in the GetKeyState from SDL
int i = SDL_GetMouseState(NULL, NULL); int i = SDL_GetMouseState(NULL, NULL);
if(i&SDL_BUTTON(1)) m_aInputState[KEY_MOUSE_1] = 1; // 1 is left if(i&SDL_BUTTON(1)) m_aInputState[KEY_MOUSE_1] = 1; // 1 is left

View file

@ -44,6 +44,7 @@ public:
virtual void SetClipboardText(const char *Text); virtual void SetClipboardText(const char *Text);
virtual int Update(); virtual int Update();
virtual void NextFrame();
virtual int VideoRestartNeeded(); virtual int VideoRestartNeeded();
}; };

View file

@ -76,6 +76,7 @@ class IEngineInput : public IInput
public: public:
virtual void Init() = 0; virtual void Init() = 0;
virtual int Update() = 0; virtual int Update() = 0;
virtual void NextFrame() = 0;
virtual int VideoRestartNeeded() = 0; virtual int VideoRestartNeeded() = 0;
}; };