I had an idea about applying the “map reduce” model to a realtime game code.
I have written alot of game code, both on my own homebrew game engines, and on Unity & Unreal.
My game loops have allways been designed as a collection of entities ( objects or componnents ) which call each-others' methods sequentially.
Simplified example: Hero raycasts gunshot to enemy → Hero's gun calculates that shot hit → Gun calls enemy's “do 20 damage” function.
I had always avoided parallel game logic because of all of the consistency problems that might arise.
Recently I had toyed with creating a new type of loop (loosely based on map reduce) which might be an interesting way to do parallel computing without locks:
1. An entity can only ever operate uppon itself
2. All state changes in other entities are handled as messages.
ex: Gun cannot call a method enemy.doDamage(20) directly. Instead, it queues a message to said enemy.
Then for each logic frame:
- Entities are split between the different CPU threads
- Each entity reads and operates on it's own queued messages for that frame.
- Entities can only:
- Change their own state
- Queue messages for other entities
- Entities can only:
- One might repeat step 1 and 2 until all messages for the current frame have been processed.
This way, one can parallelise game logic without worrying about locks and atomicty.
Let's ignore for a minute the complexity of said memory allocation, and debugging stackless chains of logic code ;-) . I am a hobbyist, I am not interested in practicality, I just want to do something cool ;-) .
This engine design idea seems very basic to me, I am wondering if you are aware of a game or a game engine that have tried this before?
What do you think of the concept?