No longer need to specify an application when creating a game state

This commit is contained in:
Grayson Riffe (Laptop) 2021-09-07 12:22:54 -05:00
parent b1efc4934e
commit 6e3a576fef
8 changed files with 20 additions and 25 deletions

View File

@ -7,7 +7,7 @@ int main(int argc, char* argv[]) {
//app.setWindowIcon(...); //app.setWindowIcon(...);
// app.setWindowCursor(...); // app.setWindowCursor(...);
MainState* test = new MainState(&app); MainState* test = new MainState;
app.addState(test, "Main State"); app.addState(test, "Main State");
app.addDefaultState("Main State"); app.addDefaultState("Main State");

View File

@ -1,11 +1,5 @@
#include "MainState.h" #include "MainState.h"
MainState::MainState(nf::Application* app) :
Gamestate(app)
{
}
void MainState::onEnter() { void MainState::onEnter() {
Log("MainState onEnter!"); Log("MainState onEnter!");

View File

@ -3,8 +3,6 @@
class MainState : public nf::Gamestate { class MainState : public nf::Gamestate {
public: public:
MainState(nf::Application* app);
void onEnter() override; void onEnter() override;
void update(double deltaTime) override; void update(double deltaTime) override;

View File

@ -280,7 +280,8 @@ namespace nf {
} }
void Application::startIntroState() { void Application::startIntroState() {
m_sIntro = new IntroGamestate(this); m_sIntro = new IntroGamestate;
m_sIntro->setup(this);
m_currentState = m_sIntro; m_currentState = m_sIntro;
m_currentState->onEnter(); m_currentState->onEnter();
} }
@ -295,6 +296,7 @@ namespace nf {
if (m_renderer->isFadeOutComplete()) { if (m_renderer->isFadeOutComplete()) {
m_currentState->onExit(); m_currentState->onExit();
m_currentState = m_states[m_nextState]; m_currentState = m_states[m_nextState];
m_currentState->setup(this);
m_currentState->onEnter(); m_currentState->onEnter();
m_renderer->setFade(true, false, false); m_renderer->setFade(true, false, false);
m_stateChange = false; m_stateChange = false;

View File

@ -4,10 +4,16 @@
#include "Utility.h" #include "Utility.h"
namespace nf { namespace nf {
Gamestate::Gamestate(Application* app) : Gamestate::Gamestate() :
camera(app) app(nullptr),
camera(nullptr)
{ {
}
void Gamestate::setup(Application* app) {
this->app = app; this->app = app;
camera = new Camera(this->app);
} }
void Gamestate::onEnter() { void Gamestate::onEnter() {
@ -19,7 +25,7 @@ namespace nf {
} }
Camera* Gamestate::getCamera() { Camera* Gamestate::getCamera() {
return &camera; return camera;
} }
void Gamestate::render(Renderer& renderer) { void Gamestate::render(Renderer& renderer) {

View File

@ -5,18 +5,13 @@
#include "Input.h" #include "Input.h"
namespace nf { namespace nf {
IntroGamestate::IntroGamestate(Application* app) :
Gamestate(app),
m_counter(0)
{
}
void IntroGamestate::onEnter() { void IntroGamestate::onEnter() {
Log("Intro onEnter!"); Log("Intro onEnter!");
logoTex.create(BaseAssets::logo, Vec2(0.0, 0.0)); logoTex.create(BaseAssets::logo, Vec2(0.0, 0.0));
logoTex.centered(true, true); logoTex.centered(true, true);
text.create("(C) Grayson Riffe 2021", Vec2(0.01, 0.025), Vec3(0.8)); text.create("(C) Grayson Riffe 2021", Vec2(0.01, 0.025), Vec3(0.8));
text.setScale(0.6); text.setScale(0.6);
m_counter = 0;
} }
void IntroGamestate::update(double deltaTime) { void IntroGamestate::update(double deltaTime) {

View File

@ -4,13 +4,15 @@
namespace nf { namespace nf {
class Application; class Application;
class Renderer; class Renderer;
class Camera;
class Gamestate { class Gamestate {
public: public:
Gamestate(Application* app); Gamestate();
Gamestate() = delete;
Gamestate(const Gamestate& other) = delete; Gamestate(const Gamestate& other) = delete;
void setup(Application* app);
virtual void onEnter(); virtual void onEnter();
virtual void update(double deltaTime); virtual void update(double deltaTime);
@ -20,6 +22,6 @@ namespace nf {
virtual void onExit(); virtual void onExit();
protected: protected:
Application* app; Application* app;
Camera camera; Camera* camera;
}; };
} }

View File

@ -6,8 +6,6 @@
namespace nf { namespace nf {
class IntroGamestate : public Gamestate { class IntroGamestate : public Gamestate {
public: public:
IntroGamestate(Application* app);
void onEnter() override; void onEnter() override;
void update(double deltaTime) override; void update(double deltaTime) override;