Game.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef GAME_H
  2. #define GAME_H
  3. #include <vector>
  4. #include <deque>
  5. #include "input/Keys.h"
  6. #include "rendering/Renderer.h"
  7. struct Point {
  8. bool operator<(const Point& other) const;
  9. float distance(const Point& other) const;
  10. float x;
  11. float y;
  12. };
  13. class Game final {
  14. public:
  15. Game(Keys& control, const char* file, bool steps);
  16. void tick();
  17. void render(float lag, Renderer& renderer) const;
  18. bool isRunning() const;
  19. private:
  20. enum State {
  21. SPLIT, MERGE, FIND_LOWER_TANGENT, FIND_UPPER_TANGENT, FINALIZE_MERGE, END
  22. };
  23. bool isLowerTangent(const std::vector<Point>& hull) const;
  24. bool isUpperTangent(const std::vector<Point>& hull) const;
  25. bool findLowerTangent();
  26. bool findUpperTangent();
  27. int findMaxX(const std::vector<Point>& hull) const;
  28. int findMinX(const std::vector<Point>& hull) const;
  29. float det(const Point& a, const Point& b, const Point& c) const;
  30. void split();
  31. bool merge();
  32. void finalizeMerge();
  33. void next();
  34. void renderGroup(Renderer& renderer, const std::vector<Point>& hull, uint color) const;
  35. void skip();
  36. float normalizeX(float f) const;
  37. float normalizeY(float f) const;
  38. Keys& keys;
  39. int keyNext;
  40. std::vector<Point> data;
  41. std::vector<Point> convexHull;
  42. int active;
  43. std::deque<std::vector<Point>> groups[2];
  44. State state;
  45. std::vector<Point> hullA;
  46. std::vector<Point> hullB;
  47. int lowerIndexA;
  48. int lowerIndexB;
  49. int upperIndexA;
  50. int upperIndexB;
  51. float minX;
  52. float maxX;
  53. float minY;
  54. float maxY;
  55. };
  56. #endif