Game.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include "SDL/SDL.h"
  10. #include <unordered_map>
  11. #include <string>
  12. #include <vector>
  13. #include "Math.h"
  14. class Game
  15. {
  16. public:
  17. Game();
  18. bool Initialize();
  19. void RunLoop();
  20. void Shutdown();
  21. void AddActor(class Actor* actor);
  22. void RemoveActor(class Actor* actor);
  23. void AddSprite(class SpriteComponent* sprite);
  24. void RemoveSprite(class SpriteComponent* sprite);
  25. class Texture* GetTexture(const std::string& fileName);
  26. // Game-specific (add/remove asteroid)
  27. void AddAsteroid(class Asteroid* ast);
  28. void RemoveAsteroid(class Asteroid* ast);
  29. std::vector<class Asteroid*>& GetAsteroids() { return mAsteroids; }
  30. private:
  31. void ProcessInput();
  32. void UpdateGame();
  33. void GenerateOutput();
  34. bool LoadShaders();
  35. void CreateSpriteVerts();
  36. void LoadData();
  37. void UnloadData();
  38. // Map of textures loaded
  39. std::unordered_map<std::string, class Texture*> mTextures;
  40. // All the actors in the game
  41. std::vector<class Actor*> mActors;
  42. // Any pending actors
  43. std::vector<class Actor*> mPendingActors;
  44. // All the sprite components drawn
  45. std::vector<class SpriteComponent*> mSprites;
  46. // Sprite shader
  47. class Shader* mSpriteShader;
  48. // Sprite vertex array
  49. class VertexArray* mSpriteVerts;
  50. SDL_Window* mWindow;
  51. SDL_GLContext mContext;
  52. Uint32 mTicksCount;
  53. bool mIsRunning;
  54. // Track if we're updating actors right now
  55. bool mUpdatingActors;
  56. // Game-specific
  57. class Ship* mShip;
  58. std::vector<class Asteroid*> mAsteroids;
  59. };