Having a little time to mess around with coding I sat down and opened my input engine and found that it's no longer responding to keypresses. (I swear the thing was working when I archived it.)
I followed it in the debugger and manually simulated a keypress, but something is wrong with this blasted VS2010 'for each' loop:
void KeyMap::update() {
for each(auto key in m_keys) {
key.second.update();
}
}
There's only one element in the std::map 'm_keys'. I follow the debugger into the update() call and have it set the object state to indicate that the key is pressed. When I come back out of the function keys.second has the correct state, but if I examine m_keys, the element there does not have the correct state. So apparently this loop is copying the std::pair objects from the map here? I disabled the copy ctor for the object's class and sure enough I get a compiler error. If I comment out the loop body I still get the error, so it's the loop making the copy, not the std::pair.
The MSDN docs for the loop make the cryptic comment 'When identifier is a tracking reference, you can modify the element.'
Gosh, thanks, MS. How the hell do I get it to work by reference rather than trying to copy?
I suppose I can just do it the old fashioned way, but I do like the simplified syntax.
Any advice would be appreciated. Thank you for your time anyone that responds.