Triangles.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * Triangles
  3. * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #pragma once
  18. #include <SFML/Graphics.hpp>
  19. #include <vector>
  20. #include <functional>
  21. #include "TrianglesWindow.hpp"
  22. #include "State.hpp"
  23. #include "Assets.hpp"
  24. #include "Triangle.hpp"
  25. class Triangles
  26. {
  27. public:
  28. Triangles() = delete;
  29. Triangles(int argc, char** argv);
  30. int run(unsigned count);
  31. private:
  32. /**
  33. * @brief This speaks for itself.
  34. */
  35. void init();
  36. /**
  37. * @brief This will redo some of constructor's and init's job, reading the program arguments.
  38. * @param argc Argument count + 1
  39. * @param argv Argument vector
  40. */
  41. void passArguments(int argc, char** argv);
  42. void searchArgument(int argc, std::string argvStr[], char callShort, std::string callLong, std::function<void()> lambda);
  43. void searchArgument(int argc, std::string argvStr[], char callShort, std::string callLong, std::function<void(std::string param)> lambda);
  44. /**
  45. * @brief Changes gamestate.
  46. * @param stateType The type of state that is about to be loaded (takes flags from the enum of State class).
  47. */
  48. void load(int stateType);
  49. /**
  50. * @brief Called whenever the screen resolution changes.
  51. */
  52. void refresh();
  53. /**
  54. * @brief Game's event loop
  55. */
  56. void coreThink();
  57. /**
  58. * @brief Input outside of the event loop.
  59. */
  60. void coreInput();
  61. /**
  62. * @brief Handles the top-left fps counter, if it is enabled.
  63. * @param delta Delta time since last update.
  64. */
  65. void fpsCalc(sf::Time delta);
  66. /**
  67. * @brief Game logic
  68. * @param delta Delta time since last update.
  69. */
  70. void coreUpdate(sf::Time delta);
  71. /**
  72. * @brief Renders the stuff of the current gamestate.
  73. */
  74. void coreRender();
  75. /**
  76. * @brief A temporal loop that renders the loading screen in a seperate thread. Calls coreThink() and renders stuff.
  77. */
  78. void loadingRender();
  79. sf::Text _loadingText;
  80. sf::Text _loadingHint;
  81. Triangle _loadingTriangle;
  82. std::vector<sf::String> _loadingHints;
  83. int _returnCode;
  84. TrianglesWindow _window;
  85. sf::Text _fps;
  86. sf::RectangleShape _fpsRect;
  87. State* _current;
  88. int _initialState;
  89. Context _context; // Intended to be a pointer for States.
  90. Context _variables; // Used internally by Triangles class.
  91. Assets _assets;
  92. };