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

351 lines
8.0 KiB

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
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
  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 MainMenuState;
  41. class PlayState;
  42. class CameraController;
  43. class SurfaceCameraController;
  44. class TunnelCameraController;
  45. class LineBatcher;
  46. class ModelLoader;
  47. class MaterialLoader;
  48. class Toolbar;
  49. /**
  50. * Encapsulates the state of the application.
  51. */
  52. class Application
  53. {
  54. public:
  55. Application(int argc, char* argv[]);
  56. ~Application();
  57. // Executes the application and returns a status code
  58. int execute();
  59. // Changes the application state
  60. void changeState(ApplicationState* state);
  61. // Sets the termination code to be returned when the application finishes
  62. void setTerminationCode(int code);
  63. // Closes the application
  64. void close(int terminationCode);
  65. void changeFullscreen();
  66. void changeVerticalSync();
  67. void saveUserSettings();
  68. bool loadScene();
  69. bool loadUI();
  70. bool loadModels();
  71. bool loadControls();
  72. bool loadGame();
  73. void resizeUI();
  74. void enterMenu(std::size_t index);
  75. void exitMenu(std::size_t index);
  76. void selectMenuItem(std::size_t index);
  77. void activateMenuItem(std::size_t index);
  78. void selectLevel(std::size_t index);
  79. void activateLevel(std::size_t index);
  80. void enterLevelSelection();
  81. void loadLevel();
  82. void pauseSimulation();
  83. void unpauseSimulation();
  84. private:
  85. ApplicationState* state;
  86. ApplicationState* nextState;
  87. int terminationCode;
  88. public:
  89. // SDL
  90. SDL_Window* window;
  91. SDL_GLContext context;
  92. // Paths
  93. std::string appDataPath;
  94. std::string userDataPath;
  95. std::string defaultSettingsFilename;
  96. std::string userSettingsFilename;
  97. // Settings
  98. ParameterDict settings;
  99. // Window
  100. bool fullscreen;
  101. int fullscreenWidth;
  102. int fullscreenHeight;
  103. int windowedWidth;
  104. int windowedHeight;
  105. int swapInterval;
  106. int width;
  107. int height;
  108. // State machine
  109. LoadingState* loadingState;
  110. SplashState* splashState;
  111. TitleState* titleState;
  112. MainMenuState* mainMenuState;
  113. PlayState* playState;
  114. // Scene
  115. Scene scene;
  116. SceneLayer* backgroundLayer;
  117. SceneLayer* defaultLayer;
  118. SceneLayer* uiLayer;
  119. Camera camera;
  120. Camera sunlightCamera;
  121. Camera uiCamera;
  122. Camera bgCamera;
  123. DirectionalLight sunlight;
  124. Spotlight lensHotspot;
  125. Spotlight lensFalloff;
  126. ModelInstance forcepsModelInstance;
  127. ModelInstance navigatorObject;
  128. ModelInstance antModelInstance;
  129. ModelInstance antHillModelInstance;
  130. ModelInstance nestModelInstance;
  131. // Graphics
  132. Renderer renderer;
  133. RenderTarget defaultRenderTarget;
  134. RenderTarget shadowMapRenderTarget;
  135. GLuint shadowFramebuffer;
  136. GLuint shadowDepthTexture;
  137. ShadowMapRenderPass shadowMapPass;
  138. SoilRenderPass soilPass;
  139. LightingRenderPass lightingPass;
  140. DebugRenderPass debugPass;
  141. Compositor shadowCompositor;
  142. Compositor defaultCompositor;
  143. BillboardBatch* uiBatch;
  144. UIBatcher* uiBatcher;
  145. UIRenderPass uiPass;
  146. Compositor uiCompositor;
  147. BillboardBatch bgBatch;
  148. Compositor bgCompositor;
  149. VignetteRenderPass vignettePass;
  150. TextureLoader* textureLoader;
  151. MaterialLoader* materialLoader;
  152. ModelLoader* modelLoader;
  153. // Controls
  154. InputManager* inputManager;
  155. Keyboard* keyboard;
  156. Mouse* mouse;
  157. ControlProfile* menuControlProfile;
  158. Control menuLeft;
  159. Control menuRight;
  160. Control menuUp;
  161. Control menuDown;
  162. Control menuSelect;
  163. Control menuCancel;
  164. Control toggleFullscreen;
  165. Control escape;
  166. ControlProfile* gameControlProfile;
  167. Control cameraMoveForward;
  168. Control cameraMoveBack;
  169. Control cameraMoveLeft;
  170. Control cameraMoveRight;
  171. Control cameraRotateCW;
  172. Control cameraRotateCCW;
  173. Control cameraZoomIn;
  174. Control cameraZoomOut;
  175. Control cameraToggleOverheadView;
  176. Control cameraToggleNestView;
  177. Control walkForward;
  178. Control walkBack;
  179. Control turnLeft;
  180. Control turnRight;
  181. Control togglePause;
  182. Arcball arcball;
  183. // Misc
  184. Timer frameTimer;
  185. float t;
  186. float dt;
  187. // UI text
  188. ParameterDict strings;
  189. float dpi;
  190. float fontSizePT;
  191. float fontSizePX;
  192. Font* menuFont;
  193. Font* copyrightFont;
  194. // UI textures
  195. Texture* splashTexture;
  196. Texture* titleTexture;
  197. Texture* levelActiveTexture;
  198. Texture* levelInactiveTexture;
  199. Texture* levelConnectorTexture;
  200. Texture* pauseButtonTexture;
  201. Texture* playButtonTexture;
  202. Texture* rectangularPaletteTexture;
  203. Texture* toolBrushTexture;
  204. Texture* toolLensTexture;
  205. Texture* toolForcepsTexture;
  206. Texture* toolTrowelTexture;
  207. Texture* toolbarTopTexture;
  208. Texture* toolbarBottomTexture;
  209. Texture* toolbarMiddleTexture;
  210. Texture* toolbarButtonRaisedTexture;
  211. Texture* toolbarButtonDepressedTexture;
  212. // UI elements
  213. Vector4 selectedColor;
  214. Vector4 deselectedColor;
  215. UIContainer* uiRootElement;
  216. UIImage* blackoutImage;
  217. UIImage* splashImage;
  218. UIImage* titleImage;
  219. UIContainer* titleScreenInfoContainer;
  220. UILabel* copyrightLabel;
  221. UILabel* versionLabel;
  222. UILabel* frameTimeLabel;
  223. UILabel* anyKeyLabel;
  224. UILabel* menuSelectorLabel;
  225. UIContainer* mainMenuContainer;
  226. UIContainer* challengeMenuContainer;
  227. UIContainer* experimentMenuContainer;
  228. UIContainer* settingsMenuContainer;
  229. UILabel* challengeLabel;
  230. UILabel* experimentLabel;
  231. UILabel* settingsLabel;
  232. UILabel* quitLabel;
  233. UILabel* loadLabel;
  234. UILabel* newLabel;
  235. UILabel* experimentBackLabel;
  236. UILabel* videoLabel;
  237. UILabel* audioLabel;
  238. UILabel* controlsLabel;
  239. UILabel* gameLabel;
  240. UILabel* settingsBackLabel;
  241. UIContainer* pauseMenuContainer;
  242. UILabel* pausedResumeLabel;
  243. UILabel* pausedSaveLabel;
  244. UILabel* pausedNewLabel;
  245. UILabel* pausedSettingsLabel;
  246. UILabel* returnToMainMenuLabel;
  247. UILabel* quitToDesktopLabel;
  248. UIContainer* levelSelectorContainer;
  249. UIImage* levelSelections[10];
  250. UIImage* levelConnectors[9];
  251. UIImage* pauseButtonImage;
  252. UIImage* playButtonImage;
  253. UIImage* rectangularPaletteImage;
  254. Toolbar* toolbar;
  255. // Animation
  256. Tweener* tweener;
  257. Tween<Vector4>* fadeInTween;
  258. Tween<Vector4>* fadeOutTween;
  259. Tween<Vector4>* splashFadeInTween;
  260. Tween<float>* splashHangTween;
  261. Tween<Vector4>* splashFadeOutTween;
  262. Tween<Vector4>* titleFadeInTween;
  263. Tween<Vector4>* titleFadeOutTween;
  264. Tween<Vector4>* copyrightFadeInTween;
  265. Tween<Vector4>* copyrightFadeOutTween;
  266. Tween<Vector4>* anyKeyFadeInTween;
  267. Tween<Vector4>* anyKeyFadeOutTween;
  268. Tween<Vector4>* menuFadeInTween;
  269. Tween<Vector4>* menuFadeOutTween;
  270. Tween<Vector2>* menuSlideInTween;
  271. Tween<Vector2>* levelSelectorSlideInTween;
  272. Tween<float>* antHillZoomInTween;
  273. Tween<Vector4>* antHillFadeOutTween;
  274. Tween<Vector4>* playButtonFadeTween;
  275. // Menus
  276. std::size_t menuCount;
  277. Menu** menus;
  278. int currentMenuIndex;
  279. int selectedMenuItemIndex;
  280. UIContainer** menuContainers;
  281. Menu* currentMenu;
  282. Menu* mainMenu;
  283. Menu* challengeMenu;
  284. Menu* experimentMenu;
  285. Menu* settingsMenu;
  286. Menu* levelSelectorMenu;
  287. // Models
  288. Model* antModel;
  289. Model* antHillModel;
  290. Model* nestModel;
  291. Model* forcepsModel;
  292. // Game variables
  293. Campaign campaign;
  294. int currentWorld;
  295. int currentLevel;
  296. Biosphere biosphere;
  297. Terrain terrain;
  298. Colony* colony;
  299. SurfaceCameraController* surfaceCam;
  300. TunnelCameraController* tunnelCam;
  301. bool cameraOverheadView;
  302. bool cameraNestView;
  303. int toolIndex;
  304. bool simulationPaused;
  305. bool forcepsClosed;
  306. // Debug
  307. LineBatcher* lineBatcher;
  308. };
  309. #endif // APPLICATION_HPP