First, a coupe remarks.
1). To initialize m_bKeys
in ctor GameOGL::GameOGL()
instead of the cycle next code can be used (that is nothing new):
memset( m_bKeys, 0, sizeof(m_bKeys) );
In general, memset, memcpy, memmove, memcmp
RTL function are written in pure assembler, highly optimized and very fast.
From the other side, if we make bool m_bKeys
global static data inside GameOGL.cpp, the compiler will initialize the array with zeros for us. :)
2). I think that all the troubles with typing VK_KEYx-set is superfluous. I mean if we need to handle say Z-key we can write 'Z'
instead of VK_KEYZ
and so on. Again, that is noncritical.
3). To close the app by pressing ESC-key we should add in GameOGL::HandleKeyboard()
one more line of code:
if (m_bKeys[VK_ESCAPE]) // TEMPORARY!
m_bQuit = true;
I know that later the ESC will be used for other purposes. But so long as the development stage is in full blast we can gain the advantages of quick escape. :)
Second, I would like to show my keyboard handler. It does the same as bool m_bKeys
, and I know that it is very probably that later it will be replaced with something more appropriate, such as std::map() and the like. But at present we can play around the array.
Initially, I have decided to rewrite the code to use bits to store key-press-flags. In such case the size of array is reduced to 32 bytes = 256 / 8. There are some advantages in smaller working set, i.e. smaller data better â€œfitâ€