NokiMo
relativisticgame
relativisticgame

patreon


Week 3 progress update

Before this week my game engine was entirely controlled by hand. In the train-tunnel paradox demo, for example, I had to use keyboard or controller to either move the train or select items from a menu. The menu enables doing various things, such as slowing time down, showing and hiding the tunnel interior, changing the reference frame from landscape to train and back, etc.

For the upcoming demo, however, I need to be able to automatically control the entities in the game. This way I can program what each entity should do and I can then start the rendering, try different resolutions and settings without having to play the scene again and again on my keyboard. By tweaking the recording I can also make sure that everything moves with the ideal timing, etc. It would be impractical each time having to play the same scene by hand. For this reason, this week I focused on adding record and replay functionality to the game.

To achieve this, I had to restructure the flow of input in the game. I now send all events from input devices (keyboard, mouse, joysticks, …) to the “input” listener group. Every entity in the game can register to receive input from this group. It is all managed by an EventManager system (“system” according to the ECS nomenclature). In the game, I would normally have a FocusedGroupDispatcher as the only listener of the input group. The role of the FocusedGroupDispatcher is to take all input events and forward them to the currently focused listener group. This allows sending input to the menus when they are active or to the game, when the menus are hidden.

The EventRecorder, all written in a short Lua script, registers as a listener to the “input” group and records all events to disk, attaching a time stamp to each of them. The EventPlayer, again a short Lua script, loads the events from file and replays them back, sending all events to the “input” group at the right time.

This simple architecture allows me to first run the engine in “real-time” mode and record all events to file. Later, I can re-run the engine (even in headless mode and with a different fixed framerate) and replay all the events, possibly recording the output to a video.

This week I also did some restructuring of the Lua sources. They are reaching about 10% of the whole engine source code, the other 90% being mostly C++ code and some shader GLSL code. I can see the Lua source line-count only increasing in the months to come.

Another thing I did this week was to set up a site for the project. In the past weeks I mostly tried WordPress, but it simply didn’t click for me. After exploring GitHub Pages a bit I found this solution much easier to set up. The site is now up at relativisticgame.net, although it is still empty. As mentioned in previous posts, I plan to use this site for technical posts on Physics, Maths and programming.


Related Creators