- Jun 3, 2005
I mean, technically, there really isn't any such thing as a "real time" game at the level an AI thinks at. But one of the design tricks I've been using to do multithreading in a current project is that everything occurs in passive voice. You get hit by shrapnel. Shrapnel never hits you. I've noticed a lot of actions in other games I've dug around in are written in active voice: The shrapnel hits you, inflicting damage when the game is processing the shrapnel. Not here. Because the thread processing you holds ownership of your structure and only accesses the read-only buffer of the current state of any potential shrapnel you get hit by, there can't be a thread accident in which your state is overwritten nondeterministically by two pieces of shrapnel hitting you, where if two pieces of shrapnel hit you, one dealing 1 damage and the other doing 2 damage, we don't know whether you will have lost 1 hitpoint, 2 hitpoints, or 3 hitpoints at the end of this because we can't determine the order in which these events would occur in a multithreaded environment. You get hit by shrapnel, never shrapnel hits you.You also have much more trouble multi-threading in real time in a strategy game.
I've also double-buffered all state of objects for this reason: Everything about the world in its current form is read-only and won't be overwritten with the next tick, which is written into the next-tick-buffer when the thread responsible for processing a given object does so, and this state will never be read from, only written to, and only by the owning thread.