Simple high-FPS working Event receiver

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
ent1ty
Competition winner
Posts: 1106
Joined: Sun Nov 08, 2009 11:09 am

Simple high-FPS working Event receiver

Post by ent1ty »

Hi,
just feel like sharing my event receiver. I tried keeping it as simple as I could. Works fine at 300 FPS.

Code: Select all

class MyEventReceiver : public IEventReceiver
{
  public:
    virtual bool OnEvent(const SEvent& event)
    {
    if (event.EventType == irr::EET_KEY_INPUT_EVENT)
      {
        if(KeyWasDown[event.KeyInput.Key]) KeyIsDown[event.KeyInput.Key]= true;
        KeyWasDown[event.KeyInput.Key] = event.KeyInput.PressedDown;

        return false;
      }
    }

    virtual bool IsKeyDown(EKEY_CODE keyCode)
    {
      if(KeyIsDown[keyCode])
      {
        KeyIsDown[keyCode]= false;
        return true;
      }
      return false;
    }
        
    MyEventReceiver()
    {
      for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
      KeyIsDown[i] = false;
    }

  private:
    bool KeyIsDown[KEY_KEY_CODES_COUNT];
    bool KeyWasDown[KEY_KEY_CODES_COUNT];
};
The most of it is copied from the Movement example(# 4)
Post Reply