Entity.h
Update Paddle.h the same way, by removing include "GameMode.h", and other things related to GameMode
#pragma once
#include "SDL2\SDL.h"
#include "Utility.h"
using namespace util;
enum class PivotMode: Uint8 {CENTER,TOP_LEFT};
class Entity
{
protected://variables
float XCenter;
float YCenter;
SDL_Rect CollisionBox;
SDL_Texture* Sprite;
SDL_Renderer* Renderer; // This can also be moved outside of this class if needed
public://constructors
Entity(PivotMode inputMode, int x, int y, std::string path);
virtual ~Entity();
Entity(const Entity&) = delete;
Entity& operator=(const Entity&) = delete;
Entity(Entity&&) = delete;
Entity& operator=(Entity&&) = delete;
public://methods
virtual void Update(float deltaTime) = 0;
virtual void Draw(float interpolation) = 0;
private://methods
void SetTexture(SDL_Texture* texture)const; // Call this from the new class below to set the enitity's texture
void SetCollisionBox(int x, int y, PivotMode InputMode);
};
GameMode.h
Removed #include "Entity.h" and #include "Paddle.h", also removed class declarations:
class Entity;
class Paddle;
#pragma once
#include "SDL2\SDL.h"
#include <string>
#include <vector>
#include <memory>
#include "App.h"
class GameMode
{
friend class App;
private://variables
bool Running;
SDL_Window* Window;
SDL_Renderer* Renderer;
App* AppRef;
public://constructors
GameMode(SDL_Window* Window, SDL_Renderer* Renderer, App* App);
~GameMode();
GameMode(const GameMode&) = delete;
GameMode& operator=(const GameMode&) = delete;
GameMode(GameMode&&) = delete;
GameMode& operator=(GameMode&&) = delete;
public://methods
SDL_Texture* RequestTexture(std::string path)const;
bool IsRunning()const;
SDL_Renderer* GetRenderer()const;
private://methods
void Update(float deltaTime);
void Draw(float interpolation);
};
ClassName.h
#include "Paddle.h"
#include "GameMode.h"
class ClassName
{
GameMode* m_pGameMode;
std::list<Entity*> m_pEntities; // List of all entities, does not have to include paddle if you include the following line
// but you have make sure you update and render the paddle and this list.
Paddle* m_pPaddle; // I've only included this for easier access to the paddle
// Other class variables/functions
}
ClassName.cpp
ClassName::ClassName(GameMode* gameRef) : m_pGameMode{ gameRef }
{
if (m_pGameMode) { Renderer = m_pGameMode->GetRenderer(); }
// You can comment this out, and create and initialize m_pGameMode here, but its not necessary
}
ClassName::~ClassName()
{
}
SDL_Texture* ClassName::RequestTexture(std::string path)const
{
if (m_pGameMode->IsRunning())
{
return m_pGameMode->RequestTexture(path);
}
return nullptr;
}
// Other Funtions
You probably won't have to worry about the last part of my previous post, but if you started using shared_ptr or something similar, then you'd have a potential memory leak. Basically, two classes would not let go of their references to each other until the other one did, so they never would, I don't know how to put it simpler than that, so if you still don't understand, then look it up.