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

416 lines
9.6 KiB

7 years ago
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
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
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 MenuItem;
  36. class ApplicationState;
  37. class Colony;
  38. class LoadingState;
  39. class SplashState;
  40. class TitleState;
  41. class GameState;
  42. class CameraController;
  43. class SurfaceCameraController;
  44. class LineBatcher;
  45. class ModelLoader;
  46. class MaterialLoader;
  47. class Toolbar;
  48. class PieMenu;
  49. class Tool;
  50. class Forceps;
  51. class Lens;
  52. class Brush;
  53. /**
  54. * Encapsulates the state of the application.
  55. */
  56. class Application
  57. {
  58. public:
  59. Application(int argc, char* argv[]);
  60. ~Application();
  61. // Executes the application and returns a status code
  62. int execute();
  63. // Changes the application state
  64. void changeState(ApplicationState* state);
  65. // Sets the termination code to be returned when the application finishes
  66. void setTerminationCode(int code);
  67. // Closes the application
  68. void close(int terminationCode);
  69. void changeFullscreen();
  70. void changeVerticalSync();
  71. void saveUserSettings();
  72. bool loadScene();
  73. bool loadUI();
  74. bool loadModels();
  75. bool loadControls();
  76. bool loadGame();
  77. void resizeUI();
  78. void restringUI();
  79. void openMenu(Menu* menu);
  80. void closeMenu();
  81. void selectMenuItem(std::size_t index);
  82. void activateMenuItem();
  83. void incrementMenuItem();
  84. void decrementMenuItem();
  85. void loadWorld(std::size_t index);
  86. void loadLevel(std::size_t index);
  87. void continueGame();
  88. void newGame();
  89. void deselectTool(Tool* tool);
  90. void selectTool(Tool* tool);
  91. void pauseSimulation();
  92. void unpauseSimulation();
  93. void setDisplayDebugInfo(bool display);
  94. std::u32string getLevelName(std::size_t world, std::size_t level) const;
  95. // Options menu functions
  96. void selectWindowedResolution(std::size_t index);
  97. void selectFullscreenResolution(std::size_t index);
  98. void selectFullscreenMode(std::size_t index);
  99. void selectVSyncMode(std::size_t index);
  100. void selectLanguage(std::size_t index);
  101. void bindControl(Control* control);
  102. private:
  103. ApplicationState* state;
  104. ApplicationState* nextState;
  105. int terminationCode;
  106. public:
  107. // SDL
  108. SDL_Window* window;
  109. SDL_GLContext context;
  110. // Paths
  111. std::string appDataPath;
  112. std::string userDataPath;
  113. std::string defaultSettingsFilename;
  114. std::string userSettingsFilename;
  115. // Settings
  116. ParameterDict settings;
  117. // State machine
  118. LoadingState* loadingState;
  119. SplashState* splashState;
  120. TitleState* titleState;
  121. GameState* gameState;
  122. // Scene
  123. Scene scene;
  124. SceneLayer* backgroundLayer;
  125. SceneLayer* defaultLayer;
  126. SceneLayer* uiLayer;
  127. Camera camera;
  128. Camera sunlightCamera;
  129. Camera uiCamera;
  130. Camera bgCamera;
  131. DirectionalLight sunlight;
  132. ModelInstance forcepsModelInstance;
  133. ModelInstance navigatorObject;
  134. ModelInstance antModelInstance;
  135. ModelInstance antHillModelInstance;
  136. ModelInstance nestModelInstance;
  137. ModelInstance biomeFloorModelInstance;
  138. // Graphics
  139. Renderer renderer;
  140. RenderTarget defaultRenderTarget;
  141. int shadowMapResolution;
  142. GLuint shadowMapDepthTexture;
  143. GLuint shadowMapFramebuffer;
  144. RenderTarget shadowMapRenderTarget;
  145. ShadowMapRenderPass shadowMapPass;
  146. Compositor shadowMapCompositor;
  147. GLuint framebufferAColorTexture;
  148. GLuint framebufferADepthTexture;
  149. GLuint framebufferA;
  150. RenderTarget framebufferARenderTarget;
  151. GLuint framebufferBColorTexture;
  152. GLuint framebufferBDepthTexture;
  153. GLuint framebufferB;
  154. RenderTarget framebufferBRenderTarget;
  155. GLuint pheromonePBO;
  156. GLuint pheromoneTextureID;
  157. Texture pheromoneTexture;
  158. ClearRenderPass clearDepthPass;
  159. SoilRenderPass soilPass;
  160. LightingRenderPass lightingPass;
  161. DebugRenderPass debugPass;
  162. Compositor defaultCompositor;
  163. BillboardBatch* uiBatch;
  164. UIBatcher* uiBatcher;
  165. UIRenderPass uiPass;
  166. Compositor uiCompositor;
  167. BillboardBatch bgBatch;
  168. Compositor bgCompositor;
  169. VignetteRenderPass vignettePass;
  170. SkyboxRenderPass skyboxPass;
  171. TextureLoader* textureLoader;
  172. MaterialLoader* materialLoader;
  173. ModelLoader* modelLoader;
  174. BlurRenderPass horizontalBlurPass;
  175. BlurRenderPass verticalBlurPass;
  176. BlurRenderPass horizontalBlurPass2;
  177. BlurRenderPass verticalBlurPass2;
  178. // Controls
  179. Control* bindingControl;
  180. InputManager* inputManager;
  181. Keyboard* keyboard;
  182. Mouse* mouse;
  183. ControlProfile* menuControlProfile;
  184. Control menuLeft;
  185. Control menuRight;
  186. Control menuUp;
  187. Control menuDown;
  188. Control menuSelect;
  189. Control menuCancel;
  190. Control toggleFullscreen;
  191. Control toggleDebugDisplay;
  192. Control escape;
  193. ControlProfile* gameControlProfile;
  194. Control cameraMoveForward;
  195. Control cameraMoveBack;
  196. Control cameraMoveLeft;
  197. Control cameraMoveRight;
  198. Control cameraRotateCW;
  199. Control cameraRotateCCW;
  200. Control cameraZoomIn;
  201. Control cameraZoomOut;
  202. Control cameraToggleOverheadView;
  203. Control cameraToggleNestView;
  204. Control walkForward;
  205. Control walkBack;
  206. Control turnLeft;
  207. Control turnRight;
  208. Control togglePause;
  209. Arcball arcball;
  210. // Misc
  211. Timer frameTimer;
  212. float t;
  213. float dt;
  214. // UI text
  215. ParameterDict strings;
  216. float dpi;
  217. float fontSizePT;
  218. float fontSizePX;
  219. Font* menuFont;
  220. Font* copyrightFont;
  221. Font* levelNameFont;
  222. // UI textures
  223. Texture* splashTexture;
  224. Texture* titleTexture;
  225. Texture* rectangularPaletteTexture;
  226. Texture* foodIndicatorTexture;
  227. Texture* toolBrushTexture;
  228. Texture* toolLensTexture;
  229. Texture* toolForcepsTexture;
  230. Texture* toolTrowelTexture;
  231. Texture* toolbarTopTexture;
  232. Texture* toolbarBottomTexture;
  233. Texture* toolbarMiddleTexture;
  234. Texture* toolbarButtonRaisedTexture;
  235. Texture* toolbarButtonDepressedTexture;
  236. Texture* arcNorthTexture;
  237. Texture* arcEastTexture;
  238. Texture* arcSouthTexture;
  239. Texture* arcWestTexture;
  240. Texture* mouseLeftTexture;
  241. Texture* mouseRightTexture;
  242. Texture* depthTexture;
  243. // UI elements
  244. Vector4 selectedColor;
  245. Vector4 deselectedColor;
  246. UIContainer* uiRootElement;
  247. UIImage* blackoutImage;
  248. UIImage* splashBackgroundImage;
  249. UIImage* splashImage;
  250. UIImage* titleImage;
  251. UIImage* darkenImage;
  252. UILabel* frameTimeLabel;
  253. UILabel* anyKeyLabel;
  254. UILabel* copyrightLabel;
  255. UIImage* rectangularPaletteImage;
  256. UIImage* foodIndicatorImage;
  257. UIImage* contextButtonImage0;
  258. UIImage* contextButtonImage1;
  259. UIImage* depthTextureImage;
  260. UILabel* levelNameLabel;
  261. Toolbar* toolbar;
  262. PieMenu* pieMenu;
  263. // Animation
  264. Tweener* tweener;
  265. Tween<Vector4>* fadeInTween;
  266. Tween<Vector4>* fadeOutTween;
  267. Tween<Vector4>* darkenFadeInTween;
  268. Tween<Vector4>* darkenFadeOutTween;
  269. Tween<float>* blurFadeInTween;
  270. Tween<float>* blurFadeOutTween;
  271. Tween<Vector4>* splashFadeInTween;
  272. Tween<Vector4>* splashFadeOutTween;
  273. Tween<float>* splashHangTween;
  274. Tween<Vector4>* titleFadeInTween;
  275. Tween<Vector4>* titleFadeOutTween;
  276. Tween<Vector4>* anyKeyFadeInTween;
  277. Tween<Vector4>* anyKeyFadeOutTween;
  278. Tween<Vector4>* menuFadeInTween;
  279. Tween<Vector4>* menuFadeOutTween;
  280. Tween<float>* menuActivateTween;
  281. Tween<Vector3>* cameraTranslationTween;
  282. Tween<float>* forcepsSwoopTween;
  283. // Menus
  284. Menu* activeMenu;
  285. Menu* previousActiveMenu;
  286. Menu* mainMenu;
  287. MenuItem* mainMenuContinueItem;
  288. MenuItem* mainMenuLevelsItem;
  289. MenuItem* mainMenuNewGameItem;
  290. MenuItem* mainMenuSandboxItem;
  291. MenuItem* mainMenuOptionsItem;
  292. MenuItem* mainMenuExitItem;
  293. Menu* levelsMenu;
  294. MenuItem* levelsMenuBackItem;
  295. Menu* optionsMenu;
  296. MenuItem* optionsMenuWindowedResolutionItem;
  297. MenuItem* optionsMenuFullscreenResolutionItem;
  298. MenuItem* optionsMenuFullscreenItem;
  299. MenuItem* optionsMenuVSyncItem;
  300. MenuItem* optionsMenuLanguageItem;
  301. MenuItem* optionsMenuControlsItem;
  302. MenuItem* optionsMenuBackItem;
  303. Menu* controlsMenu;
  304. MenuItem* controlsMenuResetToDefaultItem;
  305. MenuItem* controlsMenuMoveForwardItem;
  306. MenuItem* controlsMenuMoveBackItem;
  307. MenuItem* controlsMenuMoveLeftItem;
  308. MenuItem* controlsMenuMoveRightItem;
  309. MenuItem* controlsMenuBackItem;
  310. Menu* graphicsMenu;
  311. Menu* audioMenu;
  312. Menu* gameplayMenu;
  313. Menu* pauseMenu;
  314. MenuItem* pauseMenuResumeItem;
  315. MenuItem* pauseMenuLevelsItem;
  316. MenuItem* pauseMenuOptionsItem;
  317. MenuItem* pauseMenuMainMenuItem;
  318. MenuItem* pauseMenuExitItem;
  319. // Models
  320. Model* antModel;
  321. Model* antHillModel;
  322. Model* nestModel;
  323. Model* forcepsModel;
  324. Model* lensModel;
  325. Model* brushModel;
  326. Model* biomeFloorModel;
  327. // Game variables
  328. Biosphere biosphere;
  329. Campaign campaign;
  330. int currentWorldIndex;
  331. int currentLevelIndex;
  332. Level* currentLevel;
  333. Colony* colony;
  334. SurfaceCameraController* surfaceCam;
  335. bool cameraOverheadView;
  336. bool cameraNestView;
  337. int toolIndex;
  338. Tool* currentTool;
  339. Forceps* forceps;
  340. Lens* lens;
  341. Brush* brush;
  342. bool simulationPaused;
  343. // Debug
  344. LineBatcher* lineBatcher;
  345. bool displayDebugInfo;
  346. // Options menu values
  347. bool fullscreen;
  348. int swapInterval;
  349. Vector2 resolution;
  350. std::vector<Vector2> resolutions;
  351. std::size_t windowedResolutionIndex;
  352. std::size_t fullscreenResolutionIndex;
  353. int* fullscreenModes;
  354. int* vsyncModes;
  355. std::vector<std::string> languages;
  356. std::size_t languageIndex;
  357. };
  358. #endif // APPLICATION_HPP