💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

339 lines
7.4 KiB

7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
6 years ago
6 years ago
7 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
  1. /*
  2. * Copyright (C) 2017 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper Source Code.
  5. *
  6. * Antkeeper Source Code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper Source Code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper Source Code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef APPLICATION_HPP
  20. #define APPLICATION_HPP
  21. #include <emergent/emergent.hpp>
  22. using namespace Emergent;
  23. #include "mesh.hpp"
  24. #include "game/terrain.hpp"
  25. #include "game/level.hpp"
  26. #include "game/biome.hpp"
  27. #include "game/terrain.hpp"
  28. #include "input.hpp"
  29. #include "controls.hpp"
  30. #include "settings.hpp"
  31. #include "render-passes.hpp"
  32. #include "ui/ui.hpp"
  33. #include "ui/tween.hpp"
  34. class Menu;
  35. class ApplicationState;
  36. class Colony;
  37. class LoadingState;
  38. class SplashState;
  39. class TitleState;
  40. class GameState;
  41. class CameraController;
  42. class SurfaceCameraController;
  43. class LineBatcher;
  44. class ModelLoader;
  45. class MaterialLoader;
  46. class Toolbar;
  47. class PieMenu;
  48. class Tool;
  49. class Forceps;
  50. class Lens;
  51. class Brush;
  52. /**
  53. * Encapsulates the state of the application.
  54. */
  55. class Application
  56. {
  57. public:
  58. Application(int argc, char* argv[]);
  59. ~Application();
  60. // Executes the application and returns a status code
  61. int execute();
  62. // Changes the application state
  63. void changeState(ApplicationState* state);
  64. // Sets the termination code to be returned when the application finishes
  65. void setTerminationCode(int code);
  66. // Closes the application
  67. void close(int terminationCode);
  68. void changeFullscreen();
  69. void changeVerticalSync();
  70. void saveUserSettings();
  71. bool loadScene();
  72. bool loadUI();
  73. bool loadModels();
  74. bool loadControls();
  75. bool loadGame();
  76. void resizeUI();
  77. void openMenu(Menu* menu);
  78. void closeMenu();
  79. void selectMenuItem(std::size_t index);
  80. void activateMenuItem();
  81. void loadWorld(std::size_t index);
  82. void loadLevel(std::size_t index);
  83. void continueGame();
  84. void newGame();
  85. void deselectTool(Tool* tool);
  86. void selectTool(Tool* tool);
  87. void pauseSimulation();
  88. void unpauseSimulation();
  89. void setDisplayDebugInfo(bool display);
  90. private:
  91. ApplicationState* state;
  92. ApplicationState* nextState;
  93. int terminationCode;
  94. public:
  95. // SDL
  96. SDL_Window* window;
  97. SDL_GLContext context;
  98. // Paths
  99. std::string appDataPath;
  100. std::string userDataPath;
  101. std::string defaultSettingsFilename;
  102. std::string userSettingsFilename;
  103. // Settings
  104. ParameterDict settings;
  105. // Window
  106. bool fullscreen;
  107. int fullscreenWidth;
  108. int fullscreenHeight;
  109. int windowedWidth;
  110. int windowedHeight;
  111. int swapInterval;
  112. int width;
  113. int height;
  114. // State machine
  115. LoadingState* loadingState;
  116. SplashState* splashState;
  117. TitleState* titleState;
  118. GameState* gameState;
  119. // Scene
  120. Scene scene;
  121. SceneLayer* backgroundLayer;
  122. SceneLayer* defaultLayer;
  123. SceneLayer* uiLayer;
  124. Camera camera;
  125. Camera sunlightCamera;
  126. Camera uiCamera;
  127. Camera bgCamera;
  128. DirectionalLight sunlight;
  129. Spotlight lensHotspot;
  130. Spotlight lensFalloff;
  131. ModelInstance forcepsModelInstance;
  132. ModelInstance navigatorObject;
  133. ModelInstance antModelInstance;
  134. ModelInstance antHillModelInstance;
  135. ModelInstance nestModelInstance;
  136. ModelInstance biomeFloorModelInstance;
  137. // Graphics
  138. Renderer renderer;
  139. RenderTarget defaultRenderTarget;
  140. int shadowMapResolution;
  141. GLuint shadowMapDepthTexture;
  142. GLuint shadowMapFramebuffer;
  143. RenderTarget shadowMapRenderTarget;
  144. ShadowMapRenderPass shadowMapPass;
  145. Compositor shadowMapCompositor;
  146. ClearRenderPass clearDepthPass;
  147. SoilRenderPass soilPass;
  148. LightingRenderPass lightingPass;
  149. DebugRenderPass debugPass;
  150. Compositor defaultCompositor;
  151. BillboardBatch* uiBatch;
  152. UIBatcher* uiBatcher;
  153. UIRenderPass uiPass;
  154. Compositor uiCompositor;
  155. BillboardBatch bgBatch;
  156. Compositor bgCompositor;
  157. VignetteRenderPass vignettePass;
  158. SkyboxRenderPass skyboxPass;
  159. TextureLoader* textureLoader;
  160. MaterialLoader* materialLoader;
  161. ModelLoader* modelLoader;
  162. // Controls
  163. InputManager* inputManager;
  164. Keyboard* keyboard;
  165. Mouse* mouse;
  166. ControlProfile* menuControlProfile;
  167. Control menuLeft;
  168. Control menuRight;
  169. Control menuUp;
  170. Control menuDown;
  171. Control menuSelect;
  172. Control menuCancel;
  173. Control toggleFullscreen;
  174. Control toggleDebugDisplay;
  175. Control escape;
  176. ControlProfile* gameControlProfile;
  177. Control cameraMoveForward;
  178. Control cameraMoveBack;
  179. Control cameraMoveLeft;
  180. Control cameraMoveRight;
  181. Control cameraRotateCW;
  182. Control cameraRotateCCW;
  183. Control cameraZoomIn;
  184. Control cameraZoomOut;
  185. Control cameraToggleOverheadView;
  186. Control cameraToggleNestView;
  187. Control walkForward;
  188. Control walkBack;
  189. Control turnLeft;
  190. Control turnRight;
  191. Control togglePause;
  192. Arcball arcball;
  193. // Misc
  194. Timer frameTimer;
  195. float t;
  196. float dt;
  197. // UI text
  198. ParameterDict strings;
  199. float dpi;
  200. float fontSizePT;
  201. float fontSizePX;
  202. Font* menuFont;
  203. Font* copyrightFont;
  204. // UI textures
  205. Texture* splashTexture;
  206. Texture* titleTexture;
  207. Texture* rectangularPaletteTexture;
  208. Texture* foodIndicatorTexture;
  209. Texture* toolBrushTexture;
  210. Texture* toolLensTexture;
  211. Texture* toolForcepsTexture;
  212. Texture* toolTrowelTexture;
  213. Texture* toolbarTopTexture;
  214. Texture* toolbarBottomTexture;
  215. Texture* toolbarMiddleTexture;
  216. Texture* toolbarButtonRaisedTexture;
  217. Texture* toolbarButtonDepressedTexture;
  218. Texture* arcNorthTexture;
  219. Texture* arcEastTexture;
  220. Texture* arcSouthTexture;
  221. Texture* arcWestTexture;
  222. Texture* mouseLeftTexture;
  223. Texture* mouseRightTexture;
  224. Texture* depthTexture;
  225. // UI elements
  226. Vector4 selectedColor;
  227. Vector4 deselectedColor;
  228. UIContainer* uiRootElement;
  229. UIImage* blackoutImage;
  230. UIImage* splashBackgroundImage;
  231. UIImage* splashImage;
  232. UIImage* titleImage;
  233. UIImage* darkenImage;
  234. UILabel* frameTimeLabel;
  235. UILabel* anyKeyLabel;
  236. UIImage* rectangularPaletteImage;
  237. UIImage* foodIndicatorImage;
  238. UIImage* contextButtonImage0;
  239. UIImage* contextButtonImage1;
  240. UIImage* depthTextureImage;
  241. UILabel* levelIDLabel;
  242. UILabel* levelNameLabel;
  243. Toolbar* toolbar;
  244. PieMenu* pieMenu;
  245. // Animation
  246. Tweener* tweener;
  247. Tween<Vector4>* fadeInTween;
  248. Tween<Vector4>* fadeOutTween;
  249. Tween<Vector4>* splashFadeInTween;
  250. Tween<float>* splashHangTween;
  251. Tween<Vector4>* splashFadeOutTween;
  252. Tween<Vector4>* titleFadeInTween;
  253. Tween<Vector4>* titleFadeOutTween;
  254. Tween<Vector4>* anyKeyFadeInTween;
  255. Tween<Vector4>* anyKeyFadeOutTween;
  256. Tween<Vector4>* menuFadeInTween;
  257. Tween<Vector4>* menuFadeOutTween;
  258. Tween<Vector2>* menuSlideInTween;
  259. Tween<Vector3>* cameraTranslationTween;
  260. Tween<float>* forcepsSwoopTween;
  261. // Menus
  262. Menu* activeMenu;
  263. Menu* mainMenu;
  264. Menu* optionsMenu;
  265. Menu* pauseMenu;
  266. // Models
  267. Model* antModel;
  268. Model* antHillModel;
  269. Model* nestModel;
  270. Model* forcepsModel;
  271. Model* lensModel;
  272. Model* brushModel;
  273. Model* biomeFloorModel;
  274. // Game variables
  275. Biosphere biosphere;
  276. Campaign campaign;
  277. int currentWorldIndex;
  278. int currentLevelIndex;
  279. Level* currentLevel;
  280. Colony* colony;
  281. SurfaceCameraController* surfaceCam;
  282. bool cameraOverheadView;
  283. bool cameraNestView;
  284. int toolIndex;
  285. Tool* currentTool;
  286. Forceps* forceps;
  287. Lens* lens;
  288. Brush* brush;
  289. bool simulationPaused;
  290. // Debug
  291. LineBatcher* lineBatcher;
  292. bool displayDebugInfo;
  293. };
  294. #endif // APPLICATION_HPP