1 module evael.core.GameState; 2 3 import decs; 4 5 import evael.core.Game; 6 7 import evael.graphics.GraphicsDevice; 8 import evael.graphics.Drawable; 9 import evael.graphics.gui.GuiManager; 10 11 import evael.system.Input; 12 import evael.system.AssetLoader; 13 14 import evael.utils.Math; 15 16 public import std.variant; 17 18 /** 19 * GameState. 20 */ 21 abstract class GameState 22 { 23 protected Game m_game; 24 protected GraphicsDevice m_graphicsDevice; 25 protected GuiManager m_guiManager; 26 protected AssetLoader m_assetLoader; 27 28 /// Indicates if mouse button is clicked 29 protected bool m_mouseClicked; 30 31 /** 32 * GameState constructor. 33 */ 34 @nogc @safe 35 public this() pure nothrow 36 { 37 38 } 39 40 /** 41 * GameState destructor. 42 */ 43 public void dispose() 44 { 45 } 46 47 /** 48 * Processes game logic at fixed time rate, defined by m_tickrate. 49 */ 50 public abstract void fixedUpdate(); 51 52 /** 53 * Processes game rendering. 54 * Params: 55 * interpolation : 56 */ 57 public abstract void update(in float interpolation); 58 59 /** 60 * Event called when current game state is defined as the main state. 61 * Params: 62 * params : 63 */ 64 public void onInit(Variant[] params = null) 65 { 66 67 } 68 69 /** 70 * Event called when current game state ends. 71 * Params: 72 * params : 73 */ 74 public void onExit() 75 { 76 77 } 78 79 /** 80 * Event called on mouse button click action. 81 * Params: 82 * position : mouse position 83 * mouseButton : clicked mouse button 84 */ 85 public void onMouseClick(in ref vec2 position, in MouseButton mouseButton) 86 { 87 this.m_mouseClicked = true; 88 89 this.m_guiManager.onMouseClick(mouseButton, position); 90 } 91 92 /** 93 * Event called on mouse button release action. 94 * Params: 95 * position : mouse position 96 * mouseButton : released mouse button 97 */ 98 public void onMouseUp(in ref vec2 position, in MouseButton mouseButton) 99 { 100 this.m_mouseClicked = false; 101 102 this.m_guiManager.onMouseUp(mouseButton); 103 } 104 105 /** 106 * Event called on mouse movement action. 107 * Params: 108 * position : mouse position 109 */ 110 public void onMouseMove(in ref vec2 position) 111 { 112 this.m_guiManager.onMouseMove(position); 113 } 114 115 /** 116 * Event called on mouse wheel action. 117 * Params: 118 * delta : delta value 119 */ 120 public void onMouseWheel(in int delta) 121 { 122 123 } 124 125 /** 126 * Event called on character input. 127 * Params: 128 * text : 129 */ 130 public void onText(in int text) 131 { 132 this.m_guiManager.onText(text); 133 } 134 135 /** 136 * Event called on key action. 137 * Params: 138 * key : pressed key 139 */ 140 public void onKey(in int key) 141 { 142 this.m_guiManager.onKey(key); 143 } 144 145 /** 146 * Sets game state parent. 147 * Called only one time by Game class. 148 */ 149 @nogc @safe 150 package void setParent(Game game) pure nothrow 151 { 152 this.m_game = game; 153 this.m_graphicsDevice = game.graphicsDevice; 154 this.m_guiManager = game.guiManager; 155 this.m_assetLoader = game.assetLoader; 156 } 157 158 public Entity createEntity() 159 { 160 return this.m_game.entityManager.createEntity(); 161 } 162 163 @nogc @safe 164 @property pure nothrow 165 { 166 public Game game() 167 { 168 return this.m_game; 169 } 170 171 public GraphicsDevice graphicsDevice() 172 { 173 return this.m_graphicsDevice; 174 } 175 176 public GuiManager guiManager() 177 { 178 return this.m_guiManager; 179 } 180 181 public EntityManager entityManager() 182 { 183 return this.m_game.entityManager; 184 } 185 } 186 }