I have just set up my render loop and it looks like this (simplified):
while(mIsAppRunning) {
while(currentTime() > nextUpdateTime) {
WindowUtilities::messagePump();
captureInput();
update();
}
renderOneFrame();
}
I am rendering as often as possible and call update() every N milliseconds (constant tick rate).
messagePump() just calls PeekMessage() in a while loop and captureInput() captures and stores the current keyboard and mouse state in a global state.
But I have problems implementing the input system. Currently I can only think of 2 systems:
1) Call a function that does all the updates (in my code above update()). So update() uses the global keyboard/mouse state and manipulates all dynamic/moving scene graph objects
2) All scene graph objects that require input have a method like Object::input() and in update() the whole scene graph is traversed, input() is called for all the objects and the objects handle input themself.
I do not like 1) very much, because this would lead to ONE big function that handles all the input/update logics.
I do not like 2) either, because that would mean the user has to derive from an abstract object in order to implement virtual void input(). Let's say me engine has a class Box for a simple box mesh. Now the user had to derive (MyBox : public Box) just to be able to implement the input/update code...
What do you think of my ideas? How do you implement input/update?
Oh, another question: Do you separate processing input and the real update or do you make both in one function. For example the separation could look like this:
void processInput() {
if(key == W)
object->action = MOVE_FORWARD;
}
void input() {
if(object->action == MOVE_FORWARD)
object->position = += ...
}
Or do you just have one update for input processing AND the update?