@@ -167,6 +167,7 @@ class IGameClient : public IInterface
virtual void OnEnterGame() = 0;
virtual void OnShutdown() = 0;
virtual void OnRender() = 0;
virtual void OnUpdate() = 0;
virtual void OnStateChange(int NewState, int OldState) = 0;
virtual void OnConnected() = 0;
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker) = 0;
@@ -1651,6 +1651,10 @@ void CClient::Update()
// update the server browser
m_ServerBrowser.Update(m_ResortServerBrowser);
m_ResortServerBrowser = false;

// update gameclient
if(!m_EditorActive)
GameClient()->OnUpdate();
}

void CClient::VersionUpdate()
@@ -1837,7 +1841,7 @@ void CClient::Run()
Input()->MouseModeAbsolute();
m_WindowMustRefocus = 1;
}
else if (g_Config.m_DbgFocus && Input()->KeyPress(KEY_ESCAPE))
else if (g_Config.m_DbgFocus && Input()->KeyPress(KEY_ESCAPE, true))
{
Input()->MouseModeAbsolute();
m_WindowMustRefocus = 1;
@@ -1852,7 +1856,7 @@ void CClient::Run()
m_WindowMustRefocus++;
}

if(m_WindowMustRefocus >= 3 || Input()->KeyPress(KEY_MOUSE_1))
if(m_WindowMustRefocus >= 3 || Input()->KeyPress(KEY_MOUSE_1, true))
{
Input()->MouseModeRelative();
m_WindowMustRefocus = 0;
@@ -1865,29 +1869,24 @@ void CClient::Run()
}

// panic quit button
if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_Q))
if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_Q, true))
{
Quit();
break;
}

if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_D))
if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_D, true))
g_Config.m_Debug ^= 1;

if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_G))
if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_G, true))
g_Config.m_DbgGraphs ^= 1;

if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_E))
if(Input()->KeyIsPressed(KEY_LCTRL) && Input()->KeyIsPressed(KEY_LSHIFT) && Input()->KeyPress(KEY_E, true))
{
g_Config.m_ClEditor = g_Config.m_ClEditor^1;
Input()->MouseModeRelative();
}

/*
if(!gfx_window_open())
break;
*/

// render
{
if(g_Config.m_ClEditor)
@@ -10,7 +10,6 @@

#include "input.h"

//print >>f, "int inp_key_code(const char *key_name) { int i; if (!strcmp(key_name, \"-?-\")) return -1; else for (i = 0; i < 512; i++) if (!strcmp(key_strings[i], key_name)) return i; return -1; }"

// this header is protected so you don't include it from anywere
#define KEYS_INCLUDE
@@ -27,6 +26,7 @@ void CInput::AddEvent(char *pText, int Key, int Flags)
m_aInputEvents[m_NumEvents].m_aText[0] = 0;
else
str_copy(m_aInputEvents[m_NumEvents].m_aText, pText, sizeof(m_aInputEvents[m_NumEvents].m_aText));
m_aInputEvents[m_NumEvents].m_InputCount = m_InputCounter;
m_NumEvents++;
}
}
@@ -36,9 +36,8 @@ CInput::CInput()
mem_zero(m_aInputCount, sizeof(m_aInputCount));
mem_zero(m_aInputState, sizeof(m_aInputState));

m_InputCurrent = 0;
m_InputCounter = 1;
m_InputGrabbed = 0;
m_InputDispatched = false;

m_LastRelease = 0;
m_ReleaseDelta = -1;
@@ -50,7 +49,6 @@ void CInput::Init()
{
m_pGraphics = Kernel()->RequestInterface<IEngineGraphics>();
// FIXME: unicode handling: use SDL_StartTextInput/SDL_StopTextInput on inputs
// FIXME: key repeat: not a global setting anymore; need to do manually

MouseModeRelative();
}
@@ -101,47 +99,42 @@ int CInput::MouseDoubleClick()
return 0;
}

void CInput::ClearKeyStates()
void CInput::Clear()
{
mem_zero(m_aInputState, sizeof(m_aInputState));
mem_zero(m_aInputCount, sizeof(m_aInputCount));
m_NumEvents = 0;
}

bool CInput::KeyState(int Key) const
{
return m_aInputState[m_InputCurrent][Key>=KEY_MOUSE_1 ? Key : SDL_GetScancodeFromKey(KeyToKeycode(Key))];
return m_aInputState[Key>=KEY_MOUSE_1 ? Key : SDL_GetScancodeFromKey(KeyToKeycode(Key))];
}

int CInput::Update()
{
if(m_InputDispatched)
{
// clear and begin count on the other one
m_InputCurrent^=1;
mem_zero(&m_aInputCount[m_InputCurrent], sizeof(m_aInputCount[m_InputCurrent]));
mem_zero(&m_aInputState[m_InputCurrent], sizeof(m_aInputState[m_InputCurrent]));
m_InputDispatched = false;
}
// keep the counter between 1..0xFFFF, 0 means not pressed
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[m_InputCurrent], pState, i);
mem_copy(m_aInputState, pState, i);
}

// these states must always be updated manually because they are not in the GetKeyState from SDL
int i = SDL_GetMouseState(NULL, NULL);
if(i&SDL_BUTTON(1)) m_aInputState[m_InputCurrent][KEY_MOUSE_1] = 1; // 1 is left
if(i&SDL_BUTTON(3)) m_aInputState[m_InputCurrent][KEY_MOUSE_2] = 1; // 3 is right
if(i&SDL_BUTTON(2)) m_aInputState[m_InputCurrent][KEY_MOUSE_3] = 1; // 2 is middle
if(i&SDL_BUTTON(4)) m_aInputState[m_InputCurrent][KEY_MOUSE_4] = 1;
if(i&SDL_BUTTON(5)) m_aInputState[m_InputCurrent][KEY_MOUSE_5] = 1;
if(i&SDL_BUTTON(6)) m_aInputState[m_InputCurrent][KEY_MOUSE_6] = 1;
if(i&SDL_BUTTON(7)) m_aInputState[m_InputCurrent][KEY_MOUSE_7] = 1;
if(i&SDL_BUTTON(8)) m_aInputState[m_InputCurrent][KEY_MOUSE_8] = 1;
if(i&SDL_BUTTON(9)) m_aInputState[m_InputCurrent][KEY_MOUSE_9] = 1;
if(i&SDL_BUTTON(1)) m_aInputState[KEY_MOUSE_1] = 1; // 1 is left
if(i&SDL_BUTTON(3)) m_aInputState[KEY_MOUSE_2] = 1; // 3 is right
if(i&SDL_BUTTON(2)) m_aInputState[KEY_MOUSE_3] = 1; // 2 is middle
if(i&SDL_BUTTON(4)) m_aInputState[KEY_MOUSE_4] = 1;
if(i&SDL_BUTTON(5)) m_aInputState[KEY_MOUSE_5] = 1;
if(i&SDL_BUTTON(6)) m_aInputState[KEY_MOUSE_6] = 1;
if(i&SDL_BUTTON(7)) m_aInputState[KEY_MOUSE_7] = 1;
if(i&SDL_BUTTON(8)) m_aInputState[KEY_MOUSE_8] = 1;
if(i&SDL_BUTTON(9)) m_aInputState[KEY_MOUSE_9] = 1;

{
SDL_Event Event;
@@ -218,8 +211,8 @@ int CInput::Update()
{
if(Action&IInput::FLAG_PRESS)
{
m_aInputState[m_InputCurrent][Scancode] = 1;
m_aInputCount[m_InputCurrent][Key].m_Presses++;
m_aInputState[Scancode] = 1;
m_aInputCount[Key] = m_InputCounter;
}
AddEvent(0, Key, Action);
}
@@ -13,22 +13,13 @@ class CInput : public IEngineInput
int64 m_ReleaseDelta;

void AddEvent(char *pText, int Key, int Flags);
void ClearEvents()
{
IInput::ClearEvents();
m_InputDispatched = true;
}
void Clear();
bool IsEventValid(CEvent *pEvent) const { return pEvent->m_InputCount == m_InputCounter; };

//quick access to input
struct
{
unsigned char m_Presses;
unsigned char m_Releases;
} m_aInputCount[2][g_MaxKeys]; // tw-KEY

unsigned char m_aInputState[2][g_MaxKeys]; // SDL_SCANCODE
int m_InputCurrent;
bool m_InputDispatched;
unsigned short m_aInputCount[g_MaxKeys]; // tw-KEY
unsigned char m_aInputState[g_MaxKeys]; // SDL_SCANCODE
int m_InputCounter;

void ClearKeyStates();
bool KeyState(int Key) const;
@@ -41,8 +32,7 @@ class CInput : public IEngineInput
virtual void Init();

bool KeyIsPressed(int Key) const { return KeyState(Key); }
bool KeyRelease(int Key) const { return m_aInputCount[m_InputCurrent][Key].m_Releases; }
bool KeyPress(int Key) const { return m_aInputCount[m_InputCurrent][Key].m_Presses; }
bool KeyPress(int Key, bool CheckCounter) const { return CheckCounter ? (m_aInputCount[Key] == m_InputCounter) : m_aInputCount[Key]; }

virtual void MouseRelative(float *x, float *y);
virtual void MouseModeAbsolute();
@@ -18,6 +18,7 @@ class IInput : public IInterface
int m_Flags;
int m_Key;
char m_aText[32];
int m_InputCount;
};

protected:
@@ -41,10 +42,7 @@ class IInput : public IInterface

// events
int NumEvents() const { return m_NumEvents; }
virtual void ClearEvents()
{
m_NumEvents = 0;
}
virtual bool IsEventValid(CEvent *pEvent) const = 0;
CEvent GetEvent(int Index) const
{
if(Index < 0 || Index >= m_NumEvents)
@@ -57,9 +55,9 @@ class IInput : public IInterface

// keys
virtual bool KeyIsPressed(int Key) const = 0;
virtual bool KeyRelease(int Key) const = 0;
virtual bool KeyPress(int Key) const = 0;
virtual bool KeyPress(int Key, bool CheckCounter=false) const = 0;
const char *KeyName(int Key) const { return (Key >= 0 && Key < g_MaxKeys) ? g_aaKeyStrings[Key] : g_aaKeyStrings[0]; }
virtual void Clear() = 0;

// mouse
virtual void MouseModeRelative() = 0;
@@ -287,7 +287,7 @@ void CChat::EnableMode(int Team)
m_Mode = MODE_ALL;

m_Input.Clear();
Input()->ClearEvents();
Input()->Clear();
m_CompletionChosen = -1;
}
}
@@ -298,7 +298,7 @@ void CGameClient::OnInit()
m_ServerMode = SERVERMODE_PURE;
}

void CGameClient::DispatchInput()
void CGameClient::OnUpdate()
{
// handle mouse movement
float x = 0.0f, y = 0.0f;
@@ -320,10 +320,7 @@ void CGameClient::DispatchInput()
for(int h = 0; h < m_Input.m_Num; h++)
{
if(m_Input.m_paComponents[h]->OnInput(e))
{
//dbg_msg("", "%d char=%d key=%d flags=%d", h, e.ch, e.key, e.flags);
break;
}
}
}
}
@@ -440,33 +437,15 @@ void CGameClient::EvolveCharacter(CNetObj_Character *pCharacter, int Tick)

void CGameClient::OnRender()
{
/*Graphics()->Clear(1,0,0);
menus->render_background();
return;*/
/*
Graphics()->Clear(1,0,0);
Graphics()->MapScreen(0,0,100,100);
Graphics()->QuadsBegin();
Graphics()->SetColor(1,1,1,1);
Graphics()->QuadsDraw(50, 50, 30, 30);
Graphics()->QuadsEnd();
return;*/

// update the local character and spectate position
UpdatePositions();

// dispatch all input to systems
DispatchInput();

// render all systems
for(int i = 0; i < m_All.m_Num; i++)
m_All.m_paComponents[i]->OnRender();

// clear all events for this frame
Input()->ClearEvents();
// clear all events/input for this frame
Input()->Clear();
}

void CGameClient::OnRelease()
@@ -49,7 +49,6 @@ class CGameClient : public IGameClient
class CCollision m_Collision;
CUI m_UI;

void DispatchInput();
void ProcessEvents();
void ProcessTriggeredEvents(int Events, vec2 Pos);
void UpdatePositions();
@@ -224,6 +223,7 @@ class CGameClient : public IGameClient
// hooks
virtual void OnConnected();
virtual void OnRender();
virtual void OnUpdate();
virtual void OnRelease();
virtual void OnInit();
virtual void OnConsoleInit();
@@ -4537,7 +4537,7 @@ void CEditor::UpdateAndRender()
}

UI()->FinishCheck();
Input()->ClearEvents();
Input()->Clear();
}

IEditor *CreateEditor() { return new CEditor; }