feat? add basich ah scene loading

This commit is contained in:
2026-07-25 21:46:01 +02:00
parent aa5c497f29
commit 4b6f773c0c
18 changed files with 523 additions and 73 deletions
+4 -9
View File
@@ -2,13 +2,10 @@
#include <stdexcept>
#include <destrum/ObjectModel/GameObject.h>
// #include "imgui.h"
Component::Component(GameObject& pParent, const std::string& name): Object(name), m_ParentGameObjectPtr(&pParent) {
// if (m_ParentGameObjectPtr == nullptr) {
// //TODO: Change pParent ot be a reference
// throw std::runtime_error("Component made with no GameObject??");
// }
Component::Component(GameObject& pParent, const std::string& name)
: Object(name),
m_ParentGameObjectPtr(&pParent) {
}
Transform& Component::GetTransform() const {
@@ -16,7 +13,6 @@ Transform& Component::GetTransform() const {
}
void Component::Destroy() {
// const bool isBeingDestroyed = GetIsBeingDestroyed();
Object::Destroy();
}
@@ -40,5 +36,4 @@ void Component::ImGuiRender() {
}
void Component::Render(const RenderContext& ctx) {
}
}
+36 -22
View File
@@ -1,18 +1,30 @@
#include <destrum/ObjectModel/GameObject.h>
#include <string>
#include <iostream>
#include "spdlog/spdlog.h"
// #include "Managers/ResourceManager.h"
GameObject::~GameObject() {
// spdlog::debug("GameObject destroyed: {}", GetName());
}
GameObject::GameObject(const std::string& name)
: Object(name),
m_Id(s_NextId++) {
}
void GameObject::SetIdForDeserialization(ObjectId id) {
m_Id = id;
// Prevent newly created objects from reusing loaded IDs.
if (id >= s_NextId) {
s_NextId = id + 1;
}
}
void GameObject::SetActiveDirty() {
m_ActiveDirty = true;
for (const Transform* child : m_TransformPtr.GetChildren()) {
child->GetOwner()->SetActiveDirty();
}
@@ -21,7 +33,7 @@ void GameObject::SetActiveDirty() {
void GameObject::UpdateActiveState() {
const auto* parentPtr = m_TransformPtr.GetParent();
if(parentPtr == nullptr) {
if (parentPtr == nullptr) {
m_ActiveInHierarchy = m_Active;
} else {
m_ActiveInHierarchy = m_Active && parentPtr->GetOwner()->IsActiveInHierarchy();
@@ -38,49 +50,51 @@ bool GameObject::IsActiveInHierarchy() {
return m_ActiveInHierarchy;
}
GameObject::GameObject(const std::string& name): Object(name) {
}
void GameObject::Update() {
for (const auto& component: m_Components) {
for (const auto& component : m_Components) {
if (!component->isEnabled()) {
continue;
}
if (!component->HasStarted) {
component->Start();
component->HasStarted = true;
}
component->Update();
}
}
void GameObject::LateUpdate() {
for (const auto& component: m_Components) {
component->LateUpdate();
for (const auto& component : m_Components) {
if (component->isEnabled()) {
component->LateUpdate();
}
}
}
void GameObject::FixedUpdate() {
for (const auto& component: m_Components) {
component->FixedUpdate();
for (const auto& component : m_Components) {
if (component->isEnabled()) {
component->FixedUpdate();
}
}
}
void GameObject::Render(const RenderContext& ctx) const {
for (const auto& component: m_Components) {
component->Render(ctx);
for (const auto& component : m_Components) {
if (component->isEnabled()) {
component->Render(ctx);
}
}
}
// void GameObject::ImGuiRender() {
// for (const auto& component: m_Components) {
// component->ImGuiRender();
// }
// }
void GameObject::Destroy() {
Object::Destroy();
m_TransformPtr.SetParent(nullptr);
for (const auto& component: m_Components) {
for (const auto& component : m_Components) {
component->Destroy();
}
@@ -93,4 +107,4 @@ void GameObject::CleanupComponents() {
std::erase_if(m_Components, [](const std::unique_ptr<Component>& component) {
return component->IsBeingDestroyed();
});
}
}