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

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