0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 13:43:41 +00:00

rename Game->GameInternal

This commit is contained in:
Benedikt Galbavy 2024-05-29 09:02:08 +02:00
parent 5dfe42195f
commit 68a3e48131
19 changed files with 51 additions and 52 deletions

View File

@ -22,14 +22,14 @@ namespace engine {
extern gamefunction init; extern gamefunction init;
extern gamefunction update; extern gamefunction update;
extern Game* game; // this is a temporary fix to remove artifacts of chicken_game from the engine while the API is not yet finalized extern GameInternal* game; // this is a temporary fix to remove artifacts of chicken_game from the engine while the API is not yet finalized
} }
class Game class GameInternal
{ {
public: public:
Game(); GameInternal();
~Game(); ~GameInternal();
void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen); void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
void selectCharacters(const char* &playerSprite, const char* &enemySprite); void selectCharacters(const char* &playerSprite, const char* &enemySprite);

View File

@ -9,11 +9,11 @@
#include "Constants.h" #include "Constants.h"
#include "Entity.h" #include "Entity.h"
class Game; class GameInternal;
class Manager class Manager
{ {
public: public:
Manager(Game* game) : game(game) {}; Manager(GameInternal* game) : game(game) {};
void update(); void update();
void draw(); void draw();
@ -29,10 +29,10 @@ public:
Entity& addEntity(); Entity& addEntity();
Game* getGame() { return this->game; }; GameInternal* getGame() { return this->game; };
private: private:
Game* game; GameInternal* game;
std::vector<std::unique_ptr<Entity>> entities; std::vector<std::unique_ptr<Entity>> entities;
std::array<std::vector<Entity*>, MAX_GROUPS> entitiesByGroup; std::array<std::vector<Entity*>, MAX_GROUPS> entitiesByGroup;
std::array<std::vector<Entity*>, MAX_TEAMS> entitiesByTeam; std::array<std::vector<Entity*>, MAX_TEAMS> entitiesByTeam;

View File

@ -3,7 +3,7 @@
#include <map> #include <map>
#include <string> #include <string>
class Game; class GameInternal;
class Map class Map
{ {
public: public:
@ -21,6 +21,6 @@ public:
* \return Boolean for success * \return Boolean for success
* *
*/ */
static void loadMap(const char* path, int sizeX, int sizeY, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */); static void loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */);
static void addTile(unsigned long id, int x, int y, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict); static void addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict);
}; };

View File

@ -5,7 +5,7 @@
#include "Entity.h" #include "Entity.h"
class Game; class GameInternal;
class PopupWindow { class PopupWindow {

View File

@ -13,7 +13,7 @@ enum SoundTypes
THROW_EGG, THROW_EGG,
}; };
class Game; class GameInternal;
class SoundManager class SoundManager
{ {
public: public:
@ -30,6 +30,6 @@ class SoundManager
std::map<const char*, Mix_Chunk*> sound_cache; std::map<const char*, Mix_Chunk*> sound_cache;
Mix_Chunk* loadSound(const char* fileName); Mix_Chunk* loadSound(const char* fileName);
static void playSound(Game* game, SoundTypes sound); static void playSound(GameInternal* game, SoundTypes sound);
private: private:
}; };

View File

@ -3,7 +3,7 @@
#include "TextureManager.h" #include "TextureManager.h"
#include "SoundManager.h" #include "SoundManager.h"
#include "ProjectileComponent.h" #include "ProjectileComponent.h"
#include "Game.h" #include "GameInternal.h"
#include "TransformComponent.h" #include "TransformComponent.h"
@ -11,7 +11,6 @@
#include "ColliderComponent.h" #include "ColliderComponent.h"
#include "Constants.h" #include "Constants.h"
#include "Entity.h" #include "Entity.h"
#include "Game.h"
#include "Vector2D.h" #include "Vector2D.h"
#include "PowerupComponent.h" #include "PowerupComponent.h"
#include <iostream> #include <iostream>

View File

@ -2,7 +2,7 @@
#include "CollisionHandler.h" #include "CollisionHandler.h"
#include "Entity.h" #include "Entity.h"
#include "Game.h" #include "GameInternal.h"
#include "TransformComponent.h" #include "TransformComponent.h"
#include <iostream> #include <iostream>

View File

@ -1,4 +1,4 @@
#include "Game.h" #include "GameInternal.h"
#include <SDL_error.h> #include <SDL_error.h>
@ -15,9 +15,9 @@
#include "StatEffectsComponent.h" #include "StatEffectsComponent.h"
#include "Constants.h" #include "Constants.h"
Game* engine::game = nullptr; // will be initialized in constructor GameInternal* engine::game = nullptr; // will be initialized in constructor
Game::Game() : GameInternal::GameInternal() :
manager(this), manager(this),
tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES)), tiles(manager.getGroup((size_t)Entity::GroupLabel::MAPTILES)),
players(manager.getGroup((size_t)Entity::GroupLabel::PLAYERS)), players(manager.getGroup((size_t)Entity::GroupLabel::PLAYERS)),
@ -31,14 +31,14 @@ Game::Game() :
engine::game = this; engine::game = this;
}; };
Game::~Game() = default; GameInternal::~GameInternal() = default;
void Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen) void GameInternal::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
{ {
Game::assets = new AssetManager(&manager); GameInternal::assets = new AssetManager(&manager);
Game::textureManager = new TextureManager(&manager); GameInternal::textureManager = new TextureManager(&manager);
Game::soundManager = new SoundManager(); GameInternal::soundManager = new SoundManager();
Game::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer? GameInternal::collisionHandler = new CollisionHandler(manager); // why does this use a referrence, but AssetManager a pointer?
int flags = 0; int flags = 0;
if (fullscreen) if (fullscreen)
@ -84,7 +84,7 @@ void Game::init(const char* title, int xpos, int ypos, int width, int height, bo
} }
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_Texture* backgroundTexture = Game::textureManager->loadTexture("assets/startscreen.png"); SDL_Texture* backgroundTexture = GameInternal::textureManager->loadTexture("assets/startscreen.png");
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL); SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL);
@ -184,7 +184,7 @@ void Game::init(const char* title, int xpos, int ypos, int width, int height, bo
engine::init(); engine::init();
} }
void Game::selectCharacters(const char* &playerSprite, const char* &enemySprite) void GameInternal::selectCharacters(const char* &playerSprite, const char* &enemySprite)
{ {
// TODO: move this whereever it makes sense (maybe game as a member) // TODO: move this whereever it makes sense (maybe game as a member)
std::map<int, std::pair<const char*, const char*>> characterSprites; std::map<int, std::pair<const char*, const char*>> characterSprites;
@ -252,7 +252,7 @@ void Game::selectCharacters(const char* &playerSprite, const char* &enemySprite)
} }
} }
SDL_Texture* backgroundTexture = Game::textureManager->loadTexture("assets/characterSelection.png"); SDL_Texture* backgroundTexture = GameInternal::textureManager->loadTexture("assets/characterSelection.png");
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL); SDL_RenderCopy(renderer, backgroundTexture, NULL, NULL);
@ -280,7 +280,7 @@ void Game::selectCharacters(const char* &playerSprite, const char* &enemySprite)
this->isRunning = true; this->isRunning = true;
} }
void Game::handleEvents() void GameInternal::handleEvents()
{ {
SDL_PollEvent(&event); SDL_PollEvent(&event);
@ -294,7 +294,7 @@ void Game::handleEvents()
} }
} }
void Game::update() void GameInternal::update()
{ {
manager.refresh(); manager.refresh();
manager.update(); manager.update();
@ -302,7 +302,7 @@ void Game::update()
engine::update(); // TODO: this might have to be split up into two update functions, before and after manager... engine::update(); // TODO: this might have to be split up into two update functions, before and after manager...
} }
void Game::render() void GameInternal::render()
{ {
SDL_RenderClear(renderer); SDL_RenderClear(renderer);
for (auto& t : tiles) for (auto& t : tiles)
@ -323,7 +323,7 @@ void Game::render()
SDL_RenderPresent(renderer); SDL_RenderPresent(renderer);
} }
void Game::clean() void GameInternal::clean()
{ {
delete(textureManager); delete(textureManager);
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
@ -332,18 +332,18 @@ void Game::clean()
std::cout << "Game Cleaned!" << std::endl; std::cout << "Game Cleaned!" << std::endl;
} }
bool Game::running() const bool GameInternal::running() const
{ {
return isRunning; return isRunning;
} }
void Game::setWinner(Entity::TeamLabel winningTeam) void GameInternal::setWinner(Entity::TeamLabel winningTeam)
{ {
this->winner = winningTeam; this->winner = winningTeam;
this->isRunning = false; this->isRunning = false;
} }
Entity::TeamLabel Game::getWinner() const Entity::TeamLabel GameInternal::getWinner() const
{ {
return this->winner; return this->winner;
} }

View File

@ -2,7 +2,7 @@
#include "SDL_error.h" #include "SDL_error.h"
#include "TextureManager.h" #include "TextureManager.h"
#include "Game.h" #include "GameInternal.h"
GameObject::GameObject(const char* texturesheet, int x, int y) GameObject::GameObject(const char* texturesheet, int x, int y)
{ {

View File

@ -2,7 +2,7 @@
#include "Direction.h" #include "Direction.h"
#include "Entity.h" #include "Entity.h"
#include "Game.h" #include "GameInternal.h"
#include <cstdio> #include <cstdio>
void HealthComponent::init() void HealthComponent::init()

View File

@ -6,11 +6,11 @@
#include <utility> #include <utility>
#include "Constants.h" #include "Constants.h"
#include "Game.h" #include "GameInternal.h"
#include "SDL_error.h" #include "SDL_error.h"
#include "TileComponent.h" #include "TileComponent.h"
void Map::loadMap(const char* path, int sizeX, int sizeY, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */) void Map::loadMap(const char* path, int sizeX, int sizeY, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict /* backreference */)
{ {
std::string tileIDstr; std::string tileIDstr;
char singleChar = 0; char singleChar = 0;
@ -56,7 +56,7 @@ void Map::loadMap(const char* path, int sizeX, int sizeY, Game* game, const std:
mapFile.close(); mapFile.close();
} }
void Map::addTile(unsigned long id, int x, int y, Game* game, const std::map<int, std::pair<std::string, bool>>* textureDict) // tile entity void Map::addTile(unsigned long id, int x, int y, GameInternal* game, const std::map<int, std::pair<std::string, bool>>* textureDict) // tile entity
{ {
auto& tile(game->manager.addEntity()); auto& tile(game->manager.addEntity());
tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id, textureDict); tile.addComponent<TileComponent>(x, y, TILE_SIZE, TILE_SIZE, id, textureDict);

View File

@ -4,7 +4,7 @@
#include "Entity.h" #include "Entity.h"
#include "PopupWindow.h" #include "PopupWindow.h"
#include "TextureManager.h" #include "TextureManager.h"
#include "Game.h" #include "GameInternal.h"
PopupWindow::PopupWindow(const char* title, const std::string &message) : PopupWindow::PopupWindow(const char* title, const std::string &message) :
continueGame(false), interacted(false) { continueGame(false), interacted(false) {

View File

@ -1,5 +1,5 @@
#include "PowerupComponent.h" #include "PowerupComponent.h"
#include "Game.h" #include "GameInternal.h"
#include "CollisionHandler.h" #include "CollisionHandler.h"
#include "Entity.h" #include "Entity.h"
#include "HealthComponent.h" #include "HealthComponent.h"

View File

@ -4,7 +4,7 @@
#include "SoundManager.h" #include "SoundManager.h"
#include "TransformComponent.h" #include "TransformComponent.h"
#include "Entity.h" #include "Entity.h"
#include "Game.h" #include "GameInternal.h"
#include "HealthComponent.h" #include "HealthComponent.h"
#include "Vector2D.h" #include "Vector2D.h"
#include <cassert> #include <cassert>

View File

@ -4,7 +4,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "Game.h" #include "GameInternal.h"
#include "AssetManager.h" #include "AssetManager.h"
Mix_Chunk* SoundManager::loadSound(const char* fileName) Mix_Chunk* SoundManager::loadSound(const char* fileName)
@ -27,7 +27,7 @@ Mix_Chunk* SoundManager::loadSound(const char* fileName)
return sound; return sound;
} }
void SoundManager::playSound(Game* game, SoundTypes sound) void SoundManager::playSound(GameInternal* game, SoundTypes sound)
{ {
switch (sound) switch (sound)
{ {

View File

@ -9,7 +9,7 @@
#include "TextureManager.h" #include "TextureManager.h"
#include "Entity.h" #include "Entity.h"
#include "TransformComponent.h" #include "TransformComponent.h"
#include "Game.h" #include "GameInternal.h"
#include "Manager.h" #include "Manager.h"
SpriteComponent::SpriteComponent(const char* path) SpriteComponent::SpriteComponent(const char* path)

View File

@ -4,7 +4,7 @@
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
#include "Game.h" #include "GameInternal.h"
SDL_Texture* TextureManager::loadTexture(const char* fileName) SDL_Texture* TextureManager::loadTexture(const char* fileName)
{ {

View File

@ -4,7 +4,7 @@
#include "ColliderComponent.h" #include "ColliderComponent.h"
#include "Constants.h" #include "Constants.h"
#include "Entity.h" #include "Entity.h"
#include "Game.h" #include "GameInternal.h"
#include "Vector2D.h" #include "Vector2D.h"
#include <cstdio> #include <cstdio>
#include <initializer_list> #include <initializer_list>

View File

@ -2,11 +2,11 @@
#include <ctime> #include <ctime>
#include "Entity.h" #include "Entity.h"
#include "Game.h" #include "GameInternal.h"
#include "Constants.h" #include "Constants.h"
#include "PopupWindow.h" #include "PopupWindow.h"
Game* game = nullptr; GameInternal* game = nullptr;
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
@ -18,7 +18,7 @@ int main(int argc, char* argv[])
Uint32 frameStart; Uint32 frameStart;
int frameTime; int frameTime;
game = new Game(); game = new GameInternal();
game->init("No_Name_Chicken_Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_WIDTH, SCREEN_SIZE_HEIGHT, false); game->init("No_Name_Chicken_Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, SCREEN_SIZE_WIDTH, SCREEN_SIZE_HEIGHT, false);
while (game->running()) { while (game->running()) {