Better scene management.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "JGL/types/Texture.h"
|
||||
#include <JGL/types/Texture.h>
|
||||
|
||||
using JGL::Texture;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "J3ML/LinearAlgebra/Vector2.hpp"
|
||||
#include <J3ML/LinearAlgebra/Vector2.hpp>
|
||||
#include <vector>
|
||||
|
||||
class Entity {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Entity.h"
|
||||
#include "JGL/JGL.h"
|
||||
#include <Engine/Entity/Entity.h>
|
||||
#include <JGL/JGL.h>
|
||||
|
||||
class Renderable : public Entity {
|
||||
public:
|
||||
|
@@ -4,10 +4,22 @@
|
||||
#include <Engine/GameWindow.h>
|
||||
|
||||
namespace Globals {
|
||||
inline std::vector<Scene*> SceneList{};
|
||||
inline Scene* CurrentScene = nullptr;
|
||||
inline DemoGameWindow* Window = nullptr;
|
||||
|
||||
inline float DeltaTime() { return Window->GetDeltaTime(); }
|
||||
inline void RemoveScene() { delete CurrentScene; CurrentScene = nullptr; }
|
||||
inline void ChangeScene(Scene* scene) { delete CurrentScene; CurrentScene = scene; CurrentScene->Init(); }
|
||||
inline void ChangeScene(Scene* scene) { if (CurrentScene != nullptr) CurrentScene->Unload(); CurrentScene = scene; if (CurrentScene != nullptr) CurrentScene->Init(); }
|
||||
inline bool ChangeScene (const std::string& scene_name)
|
||||
{
|
||||
Scene* scene = nullptr;
|
||||
for (auto* s : SceneList)
|
||||
if (s->GetName() == scene_name)
|
||||
scene = s;
|
||||
|
||||
if (scene)
|
||||
ChangeScene(scene);
|
||||
|
||||
return scene;
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
class Scene {
|
||||
protected:
|
||||
bool Paused = false;
|
||||
std::string name;
|
||||
Hud* HeadsUpDisplay = nullptr;
|
||||
std::vector<Fixed*> FixedList{};
|
||||
std::vector<Entity*> EntityList{};
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
[[nodiscard]] bool FixedListContains(const Fixed* fixed) const;
|
||||
[[nodiscard]] size_t FixedCount() const;
|
||||
[[nodiscard]] size_t EntityCount() const;
|
||||
[[nodiscard]] std::string GetName() const;
|
||||
public:
|
||||
void AppendEntity(Entity* entity);
|
||||
void AppendFixed(Fixed* fixed);
|
||||
@@ -28,10 +29,11 @@ public:
|
||||
void RemoveEntity(Entity* entity);
|
||||
void RemoveFixed(Fixed* fixed);
|
||||
|
||||
virtual void Unload();
|
||||
virtual void Init() {}
|
||||
virtual void Update();
|
||||
virtual void Render();
|
||||
public:
|
||||
Scene() = default;
|
||||
explicit Scene(const std::string& name) : name(name) {}
|
||||
virtual ~Scene();
|
||||
};
|
||||
|
11
include/Game/Scene/ControllableBox.h
Normal file
11
include/Game/Scene/ControllableBox.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <Engine/Level/Scene.h>
|
||||
|
||||
class ControllableBox final : public Scene {
|
||||
public:
|
||||
void Init() final;
|
||||
public:
|
||||
explicit ControllableBox(const std::string& name) : Scene(name) {}
|
||||
};
|
||||
|
||||
|
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
#include "Engine/Level/Scene.h"
|
||||
|
||||
class DemoGameScene final : public Scene {
|
||||
public:
|
||||
void Init() final;
|
||||
public:
|
||||
DemoGameScene() = default;
|
||||
|
||||
};
|
||||
|
||||
|
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
#include "Engine/Level/Scene.h"
|
||||
#include <Engine/Level/Scene.h>
|
||||
|
||||
class DemoGameSplash final : public Scene {
|
||||
class LoadingScreen final : public Scene {
|
||||
protected:
|
||||
float elapsed = 0.0f;
|
||||
float angle = 0.0f;
|
||||
Texture* RedactedSoftware = nullptr;
|
||||
public:
|
||||
DemoGameSplash() : Scene() {}
|
||||
explicit LoadingScreen(const std::string& name) : Scene(name) {}
|
||||
|
||||
void Init() final;
|
||||
void Update() final;
|
||||
void Render() final;
|
||||
~DemoGameSplash() final;
|
||||
~LoadingScreen() final;
|
||||
};
|
Reference in New Issue
Block a user