1 /**
2  * The base class for a system.
3  * 
4  * <p>A system is part of the core functionality of the game. After a system is added to the engine, its
5  * update method will be called on every frame of the engine. When the system is removed from the engine, 
6  * the update method is no longer called.</p>
7  * 
8  * <p>The aggregate of all systems in the engine is the functionality of the game, with the update
9  * methods of those systems collectively constituting the engine update loop. Systems generally operate on
10  * node lists - collections of nodes. Each node contains the components from an entity in the engine
11  * that match the node.</p>
12  */
13 module ashd.core.system;
14 
15 import ashd.core.iengine : IEngine;
16 
17 import std.datetime  : Duration, SysTime;
18 
19 abstract class System
20 {
21     protected
22     {
23         /**
24          * Used internally to manage the list of systems within the engine. The previous system in the list.
25          */
26         System mPrevious;
27         /**
28          * Used internally to manage the list of systems within the engine. The next system in the list.
29          */
30         System mNext;
31         /**
32          * Used internally to hold the priority of this system within the system list. This is 
33          * used to order the systems so they are updated in the correct order.
34          */
35         int mPriority;
36         
37         /**
38          * Used internally to hold the type of the system
39          */
40         ClassInfo mType;
41     }
42 
43     @property
44     {
45         System next() { return mNext; }
46         void next( System system_a ) { mNext = system_a; }
47     }
48     @property
49     {
50         System previous() { return mPrevious; }
51         void previous( System system_a ) { mPrevious = system_a; }
52     }
53     @property
54     {
55         int priority() { return mPriority; }
56         void priority( int priority_a ) { mPriority = priority_a; }
57     }
58     
59     @property
60     {
61         ClassInfo type() { return mType; }
62         void type( ClassInfo type_a ) { mType = type_a; }
63     }
64    
65 
66     /**
67      * Called just after the system is added to the engine, before any calls to the update method.
68      * Override this method to add your own functionality.
69      * 
70      * @param engine The engine the system was added to.
71      */
72     public void addToEngine( IEngine engine_a )
73     {
74     }
75     
76     /**
77      * Called just after the system is removed from the engine, after all calls to the update method.
78      * Override this method to add your own functionality.
79      * 
80      * @param engine The engine the system was removed from.
81      */
82     public void removeFromEngine( IEngine engine_a )
83     {
84     }
85 
86 
87     /**
88      * After the system is added to the engine, this method is called every frame until the system
89      * is removed from the engine. Override this method to add your own functionality.
90      * 
91      * <p>If you need to perform an action outside of the update loop (e.g. you need to change the
92      * systems in the engine and you don't want to do it while they're updating) add a listener to
93      * the engine's updateComplete signal to be notified when the update loop completes.</p>
94      * 
95      * @param time The duration, in seconds, of the frame.
96      */
97     public void update( Duration time_a )
98     {
99         
100     }
101 }