mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 22:18:19 +00:00
Use const reference to pass CEvent
objects
The size of the `CEvent` class is 140 bytes, so it's more efficient to pass objects by reference.
This commit is contained in:
parent
8b26fa0bc3
commit
2b7f054590
|
@ -77,7 +77,7 @@ private:
|
|||
|
||||
void AddEvent(char *pText, int Key, int Flags);
|
||||
void Clear() override;
|
||||
bool IsEventValid(CEvent *pEvent) const override { return pEvent->m_InputCount == m_InputCounter; }
|
||||
bool IsEventValid(const CEvent &Event) const override { return Event.m_InputCount == m_InputCounter; }
|
||||
|
||||
// quick access to input
|
||||
unsigned short m_aInputCount[g_MaxKeys]; // tw-KEY
|
||||
|
|
|
@ -55,8 +55,8 @@ public:
|
|||
|
||||
// events
|
||||
int NumEvents() const { return m_NumEvents; }
|
||||
virtual bool IsEventValid(CEvent *pEvent) const = 0;
|
||||
CEvent GetEvent(int Index) const
|
||||
virtual bool IsEventValid(const CEvent &Event) const = 0;
|
||||
const CEvent &GetEvent(int Index) const
|
||||
{
|
||||
dbg_assert(Index >= 0 && Index < m_NumEvents, "Index invalid");
|
||||
return m_aInputEvents[Index];
|
||||
|
|
|
@ -209,9 +209,9 @@ public:
|
|||
virtual bool OnCursorMove(float x, float y, IInput::ECursorType CursorType) { return false; }
|
||||
/**
|
||||
* Called on a input event.
|
||||
* @param e The input event.
|
||||
* @param Event The input event.
|
||||
*/
|
||||
virtual bool OnInput(IInput::CEvent e) { return false; }
|
||||
virtual bool OnInput(const IInput::CEvent &Event) { return false; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
static const ColorRGBA gs_BindPrintColor{1.0f, 1.0f, 0.8f, 1.0f};
|
||||
|
||||
bool CBinds::CBindsSpecial::OnInput(IInput::CEvent Event)
|
||||
bool CBinds::CBindsSpecial::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
// only handle F and composed F binds
|
||||
if(((Event.m_Key >= KEY_F1 && Event.m_Key <= KEY_F12) || (Event.m_Key >= KEY_F13 && Event.m_Key <= KEY_F24)) && (Event.m_Key != KEY_F5 || !m_pClient->m_Menus.IsActive()))
|
||||
|
@ -123,33 +123,33 @@ int CBinds::GetModifierMaskOfKey(int Key)
|
|||
}
|
||||
}
|
||||
|
||||
bool CBinds::OnInput(IInput::CEvent e)
|
||||
bool CBinds::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
// don't handle invalid events
|
||||
if(e.m_Key <= 0 || e.m_Key >= KEY_LAST)
|
||||
if(Event.m_Key <= 0 || Event.m_Key >= KEY_LAST)
|
||||
return false;
|
||||
|
||||
int Mask = GetModifierMask(Input());
|
||||
int KeyModifierMask = GetModifierMaskOfKey(e.m_Key);
|
||||
int KeyModifierMask = GetModifierMaskOfKey(Event.m_Key);
|
||||
Mask &= ~KeyModifierMask;
|
||||
|
||||
bool ret = false;
|
||||
if(m_aapKeyBindings[Mask][e.m_Key])
|
||||
if(m_aapKeyBindings[Mask][Event.m_Key])
|
||||
{
|
||||
if(e.m_Flags & IInput::FLAG_PRESS)
|
||||
Console()->ExecuteLineStroked(1, m_aapKeyBindings[Mask][e.m_Key]);
|
||||
if(e.m_Flags & IInput::FLAG_RELEASE)
|
||||
Console()->ExecuteLineStroked(0, m_aapKeyBindings[Mask][e.m_Key]);
|
||||
if(Event.m_Flags & IInput::FLAG_PRESS)
|
||||
Console()->ExecuteLineStroked(1, m_aapKeyBindings[Mask][Event.m_Key]);
|
||||
if(Event.m_Flags & IInput::FLAG_RELEASE)
|
||||
Console()->ExecuteLineStroked(0, m_aapKeyBindings[Mask][Event.m_Key]);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
if(m_aapKeyBindings[0][e.m_Key] && !ret)
|
||||
if(m_aapKeyBindings[0][Event.m_Key] && !ret)
|
||||
{
|
||||
// When ctrl+shift are pressed (ctrl+shift binds and also the hard-coded ctrl+shift+d, ctrl+shift+g, ctrl+shift+e), ignore other +xxx binds
|
||||
if(e.m_Flags & IInput::FLAG_PRESS && Mask != ((1 << MODIFIER_CTRL) | (1 << MODIFIER_SHIFT)) && Mask != ((1 << MODIFIER_GUI) | (1 << MODIFIER_SHIFT)))
|
||||
Console()->ExecuteLineStroked(1, m_aapKeyBindings[0][e.m_Key]);
|
||||
if(e.m_Flags & IInput::FLAG_RELEASE)
|
||||
Console()->ExecuteLineStroked(0, m_aapKeyBindings[0][e.m_Key]);
|
||||
if(Event.m_Flags & IInput::FLAG_PRESS && Mask != ((1 << MODIFIER_CTRL) | (1 << MODIFIER_SHIFT)) && Mask != ((1 << MODIFIER_GUI) | (1 << MODIFIER_SHIFT)))
|
||||
Console()->ExecuteLineStroked(1, m_aapKeyBindings[0][Event.m_Key]);
|
||||
if(Event.m_Flags & IInput::FLAG_RELEASE)
|
||||
Console()->ExecuteLineStroked(0, m_aapKeyBindings[0][Event.m_Key]);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ public:
|
|||
public:
|
||||
CBinds *m_pBinds;
|
||||
virtual int Sizeof() const override { return sizeof(*this); }
|
||||
virtual bool OnInput(IInput::CEvent Event) override;
|
||||
virtual bool OnInput(const IInput::CEvent &Event) override;
|
||||
};
|
||||
|
||||
enum
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
static const char *GetKeyBindModifiersName(int ModifierCombination);
|
||||
|
||||
virtual void OnConsoleInit() override;
|
||||
virtual bool OnInput(IInput::CEvent Event) override;
|
||||
virtual bool OnInput(const IInput::CEvent &Event) override;
|
||||
|
||||
// DDRace
|
||||
|
||||
|
|
|
@ -165,7 +165,7 @@ void CChat::OnInit()
|
|||
Console()->Chain("cl_chat_old", ConchainChatOld, this);
|
||||
}
|
||||
|
||||
bool CChat::OnInput(IInput::CEvent Event)
|
||||
bool CChat::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
if(m_Mode == MODE_NONE)
|
||||
return false;
|
||||
|
|
|
@ -166,7 +166,7 @@ public:
|
|||
void Reset();
|
||||
void OnRelease() override;
|
||||
void OnMessage(int MsgType, void *pRawMsg) override;
|
||||
bool OnInput(IInput::CEvent Event) override;
|
||||
bool OnInput(const IInput::CEvent &Event) override;
|
||||
void OnInit() override;
|
||||
|
||||
void RebuildChat();
|
||||
|
|
|
@ -203,7 +203,7 @@ void CGameConsole::CInstance::PossibleArgumentsCompleteCallback(int Index, const
|
|||
}
|
||||
}
|
||||
|
||||
void CGameConsole::CInstance::OnInput(IInput::CEvent Event)
|
||||
void CGameConsole::CInstance::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
bool Handled = false;
|
||||
|
||||
|
@ -939,7 +939,7 @@ void CGameConsole::OnMessage(int MsgType, void *pRawMsg)
|
|||
{
|
||||
}
|
||||
|
||||
bool CGameConsole::OnInput(IInput::CEvent Event)
|
||||
bool CGameConsole::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
// accept input when opening, but not at first frame to discard the input that caused the console to open
|
||||
if(m_ConsoleState != CONSOLE_OPEN && (m_ConsoleState != CONSOLE_OPENING || m_StateChangeEnd == TimeNow() + m_StateChangeDuration))
|
||||
|
|
|
@ -71,7 +71,7 @@ class CGameConsole : public CComponent
|
|||
|
||||
void ExecuteLine(const char *pLine);
|
||||
|
||||
void OnInput(IInput::CEvent Event);
|
||||
void OnInput(const IInput::CEvent &Event);
|
||||
void PrintLine(const char *pLine, int Len, ColorRGBA PrintColor);
|
||||
|
||||
const char *GetString() const { return m_Input.GetString(); }
|
||||
|
@ -138,7 +138,7 @@ public:
|
|||
virtual void OnReset() override;
|
||||
virtual void OnRender() override;
|
||||
virtual void OnMessage(int MsgType, void *pRawMsg) override;
|
||||
virtual bool OnInput(IInput::CEvent Events) override;
|
||||
virtual bool OnInput(const IInput::CEvent &Event) override;
|
||||
|
||||
bool IsClosed() { return m_ConsoleState == CONSOLE_CLOSED; }
|
||||
};
|
||||
|
|
|
@ -2297,7 +2297,7 @@ bool CMenus::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CMenus::OnInput(IInput::CEvent Event)
|
||||
bool CMenus::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
// special handle esc and enter for popup purposes
|
||||
if(Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE)
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
int m_ModifierCombination;
|
||||
CMenusKeyBinder();
|
||||
virtual int Sizeof() const override { return sizeof(*this); }
|
||||
virtual bool OnInput(IInput::CEvent Event) override;
|
||||
virtual bool OnInput(const IInput::CEvent &Event) override;
|
||||
};
|
||||
|
||||
class CMenus : public CComponent
|
||||
|
@ -593,7 +593,7 @@ public:
|
|||
virtual void OnWindowResize() override;
|
||||
virtual void OnReset() override;
|
||||
virtual void OnRender() override;
|
||||
virtual bool OnInput(IInput::CEvent Event) override;
|
||||
virtual bool OnInput(const IInput::CEvent &Event) override;
|
||||
virtual bool OnCursorMove(float x, float y, IInput::ECursorType CursorType) override;
|
||||
virtual void OnShutdown() override;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ CMenusKeyBinder::CMenusKeyBinder()
|
|||
m_ModifierCombination = 0;
|
||||
}
|
||||
|
||||
bool CMenusKeyBinder::OnInput(IInput::CEvent Event)
|
||||
bool CMenusKeyBinder::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
if(m_TakeKey)
|
||||
{
|
||||
|
|
|
@ -131,7 +131,7 @@ void CMotd::OnMessage(int MsgType, void *pRawMsg)
|
|||
}
|
||||
}
|
||||
|
||||
bool CMotd::OnInput(IInput::CEvent Event)
|
||||
bool CMotd::OnInput(const IInput::CEvent &Event)
|
||||
{
|
||||
if(IsActive() && Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE)
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
virtual void OnStateChange(int NewState, int OldState) override;
|
||||
virtual void OnWindowResize() override;
|
||||
virtual void OnMessage(int MsgType, void *pRawMsg) override;
|
||||
virtual bool OnInput(IInput::CEvent Event) override;
|
||||
virtual bool OnInput(const IInput::CEvent &Event) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -394,13 +394,13 @@ void CGameClient::OnUpdate()
|
|||
// handle key presses
|
||||
for(int i = 0; i < Input()->NumEvents(); i++)
|
||||
{
|
||||
IInput::CEvent e = Input()->GetEvent(i);
|
||||
if(!Input()->IsEventValid(&e))
|
||||
const IInput::CEvent &Event = Input()->GetEvent(i);
|
||||
if(!Input()->IsEventValid(Event))
|
||||
continue;
|
||||
|
||||
for(auto &pComponent : m_vpInput)
|
||||
{
|
||||
if(pComponent->OnInput(e))
|
||||
if(pComponent->OnInput(Event))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue