💿🐜 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.

353 lines
7.9 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 incrementMenuItem();
  82. void decrementMenuItem();
  83. void loadWorld(std::size_t index);
  84. void loadLevel(std::size_t index);
  85. void continueGame();
  86. void newGame();
  87. void deselectTool(Tool* tool);
  88. void selectTool(Tool* tool);
  89. void pauseSimulation();
  90. void unpauseSimulation();
  91. void setDisplayDebugInfo(bool display);
  92. std::string getLevelName(std::size_t world, std::size_t level) const;
  93. // Options menu functions
  94. void selectWindowedResolution(std::size_t index);
  95. void selectFullscreenResolution(std::size_t index);
  96. void selectFullscreenMode(std::size_t index);
  97. void selectVSyncMode(std::size_t index);
  98. void selectLanguage(std::size_t index);
  99. private:
  100. ApplicationState* state;
  101. ApplicationState* nextState;
  102. int terminationCode;
  103. public:
  104. // SDL
  105. SDL_Window* window;
  106. SDL_GLContext context;
  107. // Paths
  108. std::string appDataPath;
  109. std::string userDataPath;
  110. std::string defaultSettingsFilename;
  111. std::string userSettingsFilename;
  112. // Settings
  113. ParameterDict settings;
  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. Font* levelNameFont;
  205. // UI textures
  206. Texture* splashTexture;
  207. Texture* titleTexture;
  208. Texture* rectangularPaletteTexture;
  209. Texture* foodIndicatorTexture;
  210. Texture* toolBrushTexture;
  211. Texture* toolLensTexture;
  212. Texture* toolForcepsTexture;
  213. Texture* toolTrowelTexture;
  214. Texture* toolbarTopTexture;
  215. Texture* toolbarBottomTexture;
  216. Texture* toolbarMiddleTexture;
  217. Texture* toolbarButtonRaisedTexture;
  218. Texture* toolbarButtonDepressedTexture;
  219. Texture* arcNorthTexture;
  220. Texture* arcEastTexture;
  221. Texture* arcSouthTexture;
  222. Texture* arcWestTexture;
  223. Texture* mouseLeftTexture;
  224. Texture* mouseRightTexture;
  225. Texture* depthTexture;
  226. // UI elements
  227. Vector4 selectedColor;
  228. Vector4 deselectedColor;
  229. UIContainer* uiRootElement;
  230. UIImage* blackoutImage;
  231. UIImage* splashBackgroundImage;
  232. UIImage* splashImage;
  233. UIImage* titleImage;
  234. UIImage* darkenImage;
  235. UILabel* frameTimeLabel;
  236. UILabel* anyKeyLabel;
  237. UIImage* rectangularPaletteImage;
  238. UIImage* foodIndicatorImage;
  239. UIImage* contextButtonImage0;
  240. UIImage* contextButtonImage1;
  241. UIImage* depthTextureImage;
  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* previousActiveMenu;
  264. Menu* mainMenu;
  265. Menu* levelsMenu;
  266. Menu* optionsMenu;
  267. Menu* pauseMenu;
  268. // Models
  269. Model* antModel;
  270. Model* antHillModel;
  271. Model* nestModel;
  272. Model* forcepsModel;
  273. Model* lensModel;
  274. Model* brushModel;
  275. Model* biomeFloorModel;
  276. // Game variables
  277. Biosphere biosphere;
  278. Campaign campaign;
  279. int currentWorldIndex;
  280. int currentLevelIndex;
  281. Level* currentLevel;
  282. Colony* colony;
  283. SurfaceCameraController* surfaceCam;
  284. bool cameraOverheadView;
  285. bool cameraNestView;
  286. int toolIndex;
  287. Tool* currentTool;
  288. Forceps* forceps;
  289. Lens* lens;
  290. Brush* brush;
  291. bool simulationPaused;
  292. // Debug
  293. LineBatcher* lineBatcher;
  294. bool displayDebugInfo;
  295. // Options menu values
  296. bool fullscreen;
  297. int swapInterval;
  298. Vector2 resolution;
  299. std::vector<Vector2> resolutions;
  300. std::size_t windowedResolutionIndex;
  301. std::size_t fullscreenResolutionIndex;
  302. int* fullscreenModes;
  303. int* vsyncModes;
  304. std::string* languages;
  305. };
  306. #endif // APPLICATION_HPP