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

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