Initial Commit

This commit is contained in:
2025-01-02 00:15:37 -05:00
commit b9afc57e6e
29 changed files with 1826 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
#include "Engine/Level/Scene.h"
bool Scene::EntityListContains(const Entity* entity) const {
for (auto* e : EntityList)
if (e == entity)
return true;
return false;
}
bool Scene::FixedListContains(const Fixed* fixed) const {
for (auto* f : FixedList)
if (f == fixed)
return true;
return false;
}
size_t Scene::FixedCount() const {
return FixedList.size();
}
size_t Scene::EntityCount() const {
return EntityList.size();
}
void Scene::Update() {
for (auto& e : EntityList)
e->Update();
}
void Scene::Render() {
for (auto& f : FixedList)
if (f->Enabled())
f->Render();
// TODO Render order. In this system it's not possible for child entities to be rendered before the parent.
for (auto& e : EntityList)
if (auto* r = dynamic_cast<Renderable*>(e))
r->Render();
if (HeadsUpDisplay)
HeadsUpDisplay->Render();
}
Scene::~Scene() {
for (auto* f : FixedList)
delete f;
for (auto* e : EntityList)
delete e;
}
void Scene::AppendEntity(Entity* entity) {
if (!EntityListContains(entity))
EntityList.push_back(entity);
}
void Scene::AppendFixed(Fixed* fixed) {
if (!FixedListContains(fixed))
FixedList.push_back(fixed);
}
void Scene::DestroyEntity(Entity *entity) {
auto it = std::find(EntityList.begin(), EntityList.end(), entity);
if (it != EntityList.end())
delete *it, EntityList.erase(it);
}
void Scene::DestroyFixed(Fixed* fixed) {
auto it = std::find(FixedList.begin(), FixedList.end(), fixed);
if (it != FixedList.end())
delete *it, FixedList.erase(it);
}
void Scene::RemoveEntity(Entity* entity) {
auto it = std::find(EntityList.begin(), EntityList.end(), entity);
if (it != EntityList.end())
EntityList.erase(it);
}
void Scene::RemoveFixed(Fixed* fixed) {
auto it = std::find(FixedList.begin(), FixedList.end(), fixed);
if (it != FixedList.end())
FixedList.erase(it);
}