Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef _KEYSTATE_H_
- #define _KEYSTATE_H_
- #include "PaulMath.h"
- #include "GL/glfw.h"
- static class KeyState
- {
- private:
- //arrays
- static BitSet * m_keyVal;
- static BitSet * m_keyState;
- //key update
- static void GLFWCALL UpdateSingle(int key, int val)
- {
- //update value
- if(!(*(m_keyState))[key] && val)
- m_keyVal->SetBit(key);
- //update state
- if(val)
- m_keyState->SetBit(key);
- else
- m_keyState->ClearBit(key);
- }
- public:
- //construct
- KeyState(void)
- {
- m_keyVal = new BitSet(GLFW_KEY_LAST);
- m_keyState = new BitSet(GLFW_KEY_LAST);
- }
- //destruct
- ~KeyState(void)
- {
- delete m_keyVal;
- delete m_keyState;
- glfwSetKeyCallback(NULL);
- }
- //needed to be done after GL init, so it works correctly
- void InitCallBack() { glfwSetKeyCallback(KeyState::UpdateSingle); }
- //call at end of every cycle to get desired logic
- void Clear() { m_keyVal->ClearAllBits(); }
- //for getting a key
- bool GetKey(const int key) const { return (*(m_keyVal))[key]; }
- }KeyState;
- //without these we get linker errors,
- BitSet * KeyState::m_keyVal = NULL;
- BitSet * KeyState::m_keyState = NULL;
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement