• Useful guides on project/engine structure?
    5 replies, posted
After trying to make a simple main menu for a game engine and failing ([url]https://github.com/Tetramputechture/Yttra[/url]), as I was told my structure was just confusing to work with and follow (it was), I want to start again, this time actually knowing how to structure an engine before I work on it. I need to devise a simple blueprint for my project structure and then coding it will be easy, because I have found out that structuring a large project is the hardest thing to do, and the coding for it comes naturally. Does anyone have any tools for coming up with structures, or even popular, standard structures that a lot of engines use? Thanks.
Look up finite state machines.
[QUOTE=DarkCybo7;39532909]Look up finite state machines.[/QUOTE] all the links I got were really confusing and hard to follow
[QUOTE=Meatpuppet;39532993]all the links I got were really confusing and hard to follow[/QUOTE] Finite state machines are simpler than they may seem. Basically, you have a list of states that an object can be in. For example, an AI might have Patrol, Chase, and Attack: [IMG]http://i.imgur.com/CFvybq7.png[/IMG] The circles are each a state, the arrows show which state changes can take place. The green text represents the conditions that have to be met before a change happens. Usually each change will trigger a function or so code besides just setting the new state, e.g. patrol to chase might do something like: [code] void SwitchToChase(Entity* target) { this.Speed = target->Speed * 1.1f; //move faster than the target, to catch up ArmCannon(); //prepare to attack target when we get close enough } [/code] And for updating/drawing, you could use virtual methods unique to each state - so you only have to call Entity->Update(), and the correct method will be used depending on the state. You can do all sorts of neat stuff like assigning probabilities to switches to give the machine some randomness, hierarchies (each state having child states), concurrency (being in 2+ states at once - like chase & attack for the above example) etc.
In regards to actual application implemention, a FSM can be used as such: [code] //Main loop while( pCurrentState ) { pCurrentState->Think(); } [/code] Where pCurrentState is a pointer to an existing state, and there probably exists an array or vector of all active or available game states, which your state machine handles. Essentially you're pushing your game logic into an object and running that object. When I designed my game, I used FSM, as well as had things such as resource factories which handled the loading and storing of materials such as graphics, sprites, sounds, lua files, etc.. I had interfaces which contained the logic that manipulated these factories, and then the game states accessed the game interface to do what it had to do etc..
-snip- wrong thread..
Sorry, you need to Log In to post a reply to this thread.