feat? add basich ah scene loading
This commit is contained in:
@@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user