Skip to content

Commit

Permalink
Simplify 'scene' interface
Browse files Browse the repository at this point in the history
  • Loading branch information
feresr committed Aug 22, 2020
1 parent 9acef5d commit 56f5c81
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 37 deletions.
3 changes: 0 additions & 3 deletions include/ecs/ecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,4 @@ class World {
private:
std::vector<Entity*> entities;
std::vector<System*> systems;
// TODO: use std::vector<std::unique_ptr<System>> systems; to
// make the fact that World owns the systems more explicit
// https://stackoverflow.com/questions/45087944/how-to-indicate-c-ownership-of-pointer
};
6 changes: 1 addition & 5 deletions include/scenes/EditorScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
class EditorScene : public Scene {

public:
EditorScene(SDL_Window* window);
explicit EditorScene(SDL_Window* window);

private:
void update() override;

public:
bool isFinished() override;
};
6 changes: 2 additions & 4 deletions include/scenes/GameScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ class GameScene : public Scene {
public:
explicit GameScene(SDL_Window* window);

bool isFinished() override;

private:
bool gameOver = false;
void update() override;

public:
bool isFinished() override;

};
11 changes: 5 additions & 6 deletions include/scenes/IntroScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
class IntroScene : public Scene {

public:
IntroScene(SDL_Window* window);
explicit IntroScene(SDL_Window* window);

private:
int timer = 0;
void update() override;

public:
bool isFinished() override;

void update() override;

private:
int timer = 0;
};
6 changes: 4 additions & 2 deletions include/scenes/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@

class Scene {
protected:
World* world;
World* world = new World();

public:

virtual void update() {};
virtual void update() {
world->tick();
};

virtual bool isFinished() { return true; }
virtual void handleEvents(SDL_Event& event) {
Expand Down
7 changes: 0 additions & 7 deletions src/scenes/EditorScene.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#include "scenes/EditorScene.h"

EditorScene::EditorScene(SDL_Window* window) {
world = new World();
world->registerSystem<RenderSystem>(window, SNES_RESOLUTION_WIDTH, SNES_RESOLUTION_HEIGHT);
world->registerSystem<EditorSystem>();
world->registerSystem<TileSystem>();
world->registerSystem<PhysicsSystem>();


auto title = world->create();
title->assign<TextComponent>("MAP EDITOR MODE");
title->assign<TransformComponent>(10, 10, 60, 8);
Expand All @@ -33,11 +31,6 @@ EditorScene::EditorScene(SDL_Window* window) {
instructions5->assign<TransformComponent>(10, 44, 80, 5);
}

void EditorScene::update() {
Scene::update();
world->tick();
}

bool EditorScene::isFinished() {
return false;
}
Expand Down
5 changes: 0 additions & 5 deletions src/scenes/GameScene.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "scenes/GameScene.h"

GameScene::GameScene(SDL_Window* window) {
world = new World();
world->registerSystem<SoundSystem>();
world->registerSystem<RenderSystem>(window, SNES_RESOLUTION_WIDTH, SNES_RESOLUTION_HEIGHT);
world->registerSystem<PlayerSystem>([&](){ this->gameOver = true; });
Expand All @@ -15,10 +14,6 @@ GameScene::GameScene(SDL_Window* window) {
world->registerSystem<PhysicsSystem>();
}

void GameScene::update() {
world->tick();
}

bool GameScene::isFinished() {
return gameOver;
}
Expand Down
5 changes: 0 additions & 5 deletions src/scenes/IntroScene.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "scenes/IntroScene.h"


IntroScene::IntroScene(SDL_Window* window) {
world = new World();
world->registerSystem<RenderSystem>(window, SNES_RESOLUTION_WIDTH, SNES_RESOLUTION_HEIGHT)
->setBackgroundColor(0, 0, 0);
world->registerSystem<ScoreSystem>();
Expand Down Expand Up @@ -37,11 +35,8 @@ IntroScene::IntroScene(SDL_Window* window) {
void IntroScene::update() {
timer++;
Scene::update();
world->tick();
}

bool IntroScene::isFinished() {
return timer >= INTRO_SCREEN_TIME;
}


0 comments on commit 56f5c81

Please sign in to comment.