After Xmas Update
Finally got around to coding now, heres the final hirachy:
Main program divided into 3 subsections:
GUI (main gui and action handlers)
Engine (main runfile, manages everything)
The Entities are related by:
JEntity (basic knowldge of position/lane, abstract methods for tick/draw)
JVehicle Other Ents (Divided into general/info markers/static road etc).
All ents must
Tick() – called by engine to upadate ent
Draw() – called by GUI to engine to ent to draw the object (if drawn).
Development so far:
- Basic GUI to display vehicles
- Basic vehicle place holder ents which just move forwards
- Entities such as
- Road ents – a 'peice' of road for the cars to drive down. Each 800 units long. Divided into 4 200 unit subsections where ents can be placed. Onramp placeholder made. Handles kill car ents
- Spawns for cars (needs work to add variation)
- Kill Car entities
Logic so far:
- Engine timer called. Loop through all entities in list and Tick(). Loop through all Vehicles and Tick().
- Entities Tick() – do what is needed. May be generate a new Vehicle etc (or nothing)
- Vehicles Tick() – first check where we are. If we have entered a new 200 unit subsection then check if there are any new info ents to know about (speed limits/headway markers etc). Then we call Move(). If we find a CarKill then tell the engine we have.
- Engine – see how many cars have to be Killed. Pop from appropriate ques.
- Engine Draw Timer. Loop through all ents and vehicles and call Draw().
How to Manage entities within the engine
When a new entity is created, the constructor within JEntity adds it to the engines know entities. Cars are added to a queue (there are three queues, one for each lane, when a kill signal comes it pops the queue). Entities are added to a linked list, organised by position. NEED WORK If an entity is moved its position in list needs updating! Change list to an array and just search? Speed if each car keeps searching?
Needed to add a second timer to call Draw() seperatly or else when moving/resizing window timing dies.
What to do now
- Add ability to add entities by clicking on GUI. Shouldnt be too hard (current structure makes it v. easy to add ents, just need basic code and dias to manage ents)
- Develop Road Entity to auto generate entities
- Develop car spawns – need to ability to increase/decrase flow over time