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

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