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

394 lines
9.0 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
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. Spotlight lensHotspot;
  133. Spotlight lensFalloff;
  134. ModelInstance forcepsModelInstance;
  135. ModelInstance navigatorObject;
  136. ModelInstance antModelInstance;
  137. ModelInstance antHillModelInstance;
  138. ModelInstance nestModelInstance;
  139. ModelInstance biomeFloorModelInstance;
  140. // Graphics
  141. Renderer renderer;
  142. RenderTarget defaultRenderTarget;
  143. int shadowMapResolution;
  144. GLuint shadowMapDepthTexture;
  145. GLuint shadowMapFramebuffer;
  146. RenderTarget shadowMapRenderTarget;
  147. ShadowMapRenderPass shadowMapPass;
  148. Compositor shadowMapCompositor;
  149. ClearRenderPass clearDepthPass;
  150. SoilRenderPass soilPass;
  151. LightingRenderPass lightingPass;
  152. DebugRenderPass debugPass;
  153. Compositor defaultCompositor;
  154. BillboardBatch* uiBatch;
  155. UIBatcher* uiBatcher;
  156. UIRenderPass uiPass;
  157. Compositor uiCompositor;
  158. BillboardBatch bgBatch;
  159. Compositor bgCompositor;
  160. VignetteRenderPass vignettePass;
  161. SkyboxRenderPass skyboxPass;
  162. TextureLoader* textureLoader;
  163. MaterialLoader* materialLoader;
  164. ModelLoader* modelLoader;
  165. // Controls
  166. Control* bindingControl;
  167. InputManager* inputManager;
  168. Keyboard* keyboard;
  169. Mouse* mouse;
  170. ControlProfile* menuControlProfile;
  171. Control menuLeft;
  172. Control menuRight;
  173. Control menuUp;
  174. Control menuDown;
  175. Control menuSelect;
  176. Control menuCancel;
  177. Control toggleFullscreen;
  178. Control toggleDebugDisplay;
  179. Control escape;
  180. ControlProfile* gameControlProfile;
  181. Control cameraMoveForward;
  182. Control cameraMoveBack;
  183. Control cameraMoveLeft;
  184. Control cameraMoveRight;
  185. Control cameraRotateCW;
  186. Control cameraRotateCCW;
  187. Control cameraZoomIn;
  188. Control cameraZoomOut;
  189. Control cameraToggleOverheadView;
  190. Control cameraToggleNestView;
  191. Control walkForward;
  192. Control walkBack;
  193. Control turnLeft;
  194. Control turnRight;
  195. Control togglePause;
  196. Arcball arcball;
  197. // Misc
  198. Timer frameTimer;
  199. float t;
  200. float dt;
  201. // UI text
  202. ParameterDict strings;
  203. float dpi;
  204. float fontSizePT;
  205. float fontSizePX;
  206. Font* menuFont;
  207. Font* copyrightFont;
  208. Font* levelNameFont;
  209. // UI textures
  210. Texture* splashTexture;
  211. Texture* titleTexture;
  212. Texture* rectangularPaletteTexture;
  213. Texture* foodIndicatorTexture;
  214. Texture* toolBrushTexture;
  215. Texture* toolLensTexture;
  216. Texture* toolForcepsTexture;
  217. Texture* toolTrowelTexture;
  218. Texture* toolbarTopTexture;
  219. Texture* toolbarBottomTexture;
  220. Texture* toolbarMiddleTexture;
  221. Texture* toolbarButtonRaisedTexture;
  222. Texture* toolbarButtonDepressedTexture;
  223. Texture* arcNorthTexture;
  224. Texture* arcEastTexture;
  225. Texture* arcSouthTexture;
  226. Texture* arcWestTexture;
  227. Texture* mouseLeftTexture;
  228. Texture* mouseRightTexture;
  229. Texture* depthTexture;
  230. // UI elements
  231. Vector4 selectedColor;
  232. Vector4 deselectedColor;
  233. UIContainer* uiRootElement;
  234. UIImage* blackoutImage;
  235. UIImage* splashBackgroundImage;
  236. UIImage* splashImage;
  237. UIImage* titleImage;
  238. UIImage* darkenImage;
  239. UILabel* frameTimeLabel;
  240. UILabel* anyKeyLabel;
  241. UIImage* rectangularPaletteImage;
  242. UIImage* foodIndicatorImage;
  243. UIImage* contextButtonImage0;
  244. UIImage* contextButtonImage1;
  245. UIImage* depthTextureImage;
  246. UILabel* levelNameLabel;
  247. Toolbar* toolbar;
  248. PieMenu* pieMenu;
  249. // Animation
  250. Tweener* tweener;
  251. Tween<Vector4>* fadeInTween;
  252. Tween<Vector4>* fadeOutTween;
  253. Tween<Vector4>* splashFadeInTween;
  254. Tween<float>* splashHangTween;
  255. Tween<Vector4>* splashFadeOutTween;
  256. Tween<Vector4>* titleFadeInTween;
  257. Tween<Vector4>* titleFadeOutTween;
  258. Tween<Vector4>* anyKeyFadeInTween;
  259. Tween<Vector4>* anyKeyFadeOutTween;
  260. Tween<Vector4>* menuFadeInTween;
  261. Tween<Vector4>* menuFadeOutTween;
  262. Tween<float>* menuActivateTween;
  263. Tween<Vector3>* cameraTranslationTween;
  264. Tween<float>* forcepsSwoopTween;
  265. // Menus
  266. Menu* activeMenu;
  267. Menu* previousActiveMenu;
  268. Menu* mainMenu;
  269. MenuItem* mainMenuContinueItem;
  270. MenuItem* mainMenuLevelsItem;
  271. MenuItem* mainMenuNewGameItem;
  272. MenuItem* mainMenuSandboxItem;
  273. MenuItem* mainMenuOptionsItem;
  274. MenuItem* mainMenuExitItem;
  275. Menu* levelsMenu;
  276. MenuItem* levelsMenuBackItem;
  277. Menu* optionsMenu;
  278. MenuItem* optionsMenuWindowedResolutionItem;
  279. MenuItem* optionsMenuFullscreenResolutionItem;
  280. MenuItem* optionsMenuFullscreenItem;
  281. MenuItem* optionsMenuVSyncItem;
  282. MenuItem* optionsMenuLanguageItem;
  283. MenuItem* optionsMenuControlsItem;
  284. MenuItem* optionsMenuBackItem;
  285. Menu* controlsMenu;
  286. MenuItem* controlsMenuResetToDefaultItem;
  287. MenuItem* controlsMenuMoveForwardItem;
  288. MenuItem* controlsMenuMoveBackItem;
  289. MenuItem* controlsMenuMoveLeftItem;
  290. MenuItem* controlsMenuMoveRightItem;
  291. MenuItem* controlsMenuBackItem;
  292. Menu* graphicsMenu;
  293. Menu* audioMenu;
  294. Menu* gameplayMenu;
  295. Menu* pauseMenu;
  296. MenuItem* pauseMenuResumeItem;
  297. MenuItem* pauseMenuLevelsItem;
  298. MenuItem* pauseMenuOptionsItem;
  299. MenuItem* pauseMenuMainMenuItem;
  300. MenuItem* pauseMenuExitItem;
  301. // Models
  302. Model* antModel;
  303. Model* antHillModel;
  304. Model* nestModel;
  305. Model* forcepsModel;
  306. Model* lensModel;
  307. Model* brushModel;
  308. Model* biomeFloorModel;
  309. // Game variables
  310. Biosphere biosphere;
  311. Campaign campaign;
  312. int currentWorldIndex;
  313. int currentLevelIndex;
  314. Level* currentLevel;
  315. Colony* colony;
  316. SurfaceCameraController* surfaceCam;
  317. bool cameraOverheadView;
  318. bool cameraNestView;
  319. int toolIndex;
  320. Tool* currentTool;
  321. Forceps* forceps;
  322. Lens* lens;
  323. Brush* brush;
  324. bool simulationPaused;
  325. // Debug
  326. LineBatcher* lineBatcher;
  327. bool displayDebugInfo;
  328. // Options menu values
  329. bool fullscreen;
  330. int swapInterval;
  331. Vector2 resolution;
  332. std::vector<Vector2> resolutions;
  333. std::size_t windowedResolutionIndex;
  334. std::size_t fullscreenResolutionIndex;
  335. int* fullscreenModes;
  336. int* vsyncModes;
  337. std::vector<std::string> languages;
  338. std::size_t languageIndex;
  339. };
  340. #endif // APPLICATION_HPP