Get rid of having to have Globals::CurrentScene everywhere.
This commit is contained in:
@@ -55,6 +55,6 @@ public:
|
||||
void Render(JGL::RenderTarget* render_target);
|
||||
void Render(ReWindow::RWindow* window);
|
||||
public:
|
||||
explicit Scene(const std::string& name, const u8 tick_rate = 40) : tick_rate(tick_rate), name(name), entity_list(new Entity()) {}
|
||||
explicit Scene(const std::string& name, const u8 tick_rate = 40) : tick_rate(tick_rate), name(name), entity_list(new Entity(this)) {}
|
||||
virtual ~Scene();
|
||||
};
|
||||
|
@@ -4,13 +4,15 @@
|
||||
#include <chrono>
|
||||
|
||||
namespace Engine {
|
||||
class Scene;
|
||||
class Entity;
|
||||
}
|
||||
|
||||
class Engine::Entity {
|
||||
protected:
|
||||
private:
|
||||
// nullptr means no parent.
|
||||
Entity* parent = nullptr;
|
||||
Scene* scene = nullptr;
|
||||
|
||||
// Epoch micro-seconds.
|
||||
long creation_time = 0.0f;
|
||||
@@ -27,6 +29,8 @@ public:
|
||||
[[nodiscard]] bool HasChildren() const { return !children.empty(); }
|
||||
[[nodiscard]] bool HasParent() const { return parent; }
|
||||
[[nodiscard]] Entity* GetParent() const;
|
||||
[[nodiscard]] Scene* GetScene() const;
|
||||
[[nodiscard]] Scene* GetScene();
|
||||
|
||||
// Microseconds.
|
||||
[[nodiscard]] long GetCreationTime() const;
|
||||
@@ -35,5 +39,6 @@ public:
|
||||
virtual void Update() {}
|
||||
public:
|
||||
virtual ~Entity();
|
||||
explicit Entity(Scene* scene) : scene(scene), creation_time(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()) {}
|
||||
explicit Entity() : creation_time(std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count()) {}
|
||||
};
|
@@ -23,7 +23,7 @@ public:
|
||||
void SetSize(const Vector2& new_size) { size = new_size; }
|
||||
public:
|
||||
explicit Trigger(const Vector2& position, const Vector2& size, bool enabled = true) :
|
||||
size(size), Entity(), Living(enabled), BoxCollider(enabled), Movable(position), Renderable(0, false) {}
|
||||
size(size), Living(enabled), BoxCollider(enabled), Movable(position), Renderable(0, false) {}
|
||||
|
||||
~Trigger() override = default;
|
||||
};
|
||||
|
Reference in New Issue
Block a user