Over the last week I have made some significant amount of progress in the game/simulation whatever. There were a couple of ideas I had been toying with essentially how to pass messages between game objects and how they should react to events etc.
The solution I am came up with is that objects now each have a Priority based Event Queue. Events can be sent to objects to by adding to this queue and since I its priority based we can assign different priorities to the events eg USER EVENT, AI EVENT, IMMEDIATE EVENT.
- USER EVENTS - any event triggered by a user eg. click on the unit,commands to the unit by a user.
- AI EVENTS- more useful while a unit is being controlled by an AI. The AI need not be a master AI it can be like a Group AI thread created by a user. Eg A User creates a group out of a bunch of units and sends them out on a reconnaissance mission. One unit in the group identifies an incoming hostile and it can send events to all its group members to prepare for the incoming hostile etc. The Message passing is also useful in simulations to trigger events eg if more than 3 simutrons ( yes thats my name for actors:p ) are near a simutron it can randomly ask a simutron to clone itself .
- IMMEDIATE EVENTS - These must be highest priority events eg A simutron got shot and needs to die. We can decided to process event that lead to the units death first before handling other user commands.
One thing I forgot to do is sort it based on event time priority. At this time I am not sure if that is the right approach probably I should just use event time as a sorting criteria and not the type of event or just have 3 separate event queues per simutron.
Right now the simulation ignores priorities as all the events are currently simulation events and its just simutrons signalling to each other to die or clone themselves or die of loneliness.
I also added more states to each simutron. A simutron's state machine looks like the following right now
CREATED ->ACTIVE -> DEAD->DESTROYED
-CREATED - The simutron is growing to life and won't process any events in this state( useful or doing a creation animation)
-ACTIVE - Simutron is ready and will process events now as well as fire off events based on certain conditions being met.
-SLUMBERING (not shown will update diagram later)- Simutron will process incoming events but will not trigger any events by itself nor do any checks. Its like a sleep state for the simutron.
-DEAD - Simutron is dead and will not process any more events. Useful to start playing a death animation.
-DESTROYED- Simutron is done dying! release all resources now.
I will expand this state machine as the game develops but for now its sufficient. Now the code I have implemented allows me to just add a seed population of simutrons and just watch them kill/clone other simutrons.
As of now I have the flexibility to easily change the simulation logic and try out different simulations. The current simulation is a variant of Conway's Game of Life but there are a few bugs I need to fix with it:) Mainly, the creation rate of simutrons is far higher than their death rate leading to a few thousand of them on screen and bringing the simulation to a halt! What I would like to achieve is a stable population of simutrons using simple rules.
Screenshots/video to come!