Adds basic scene management
Implements a basic scene management system with GameObject and Component structure. Adds initial support for TagComponent serialization. Includes Scene class in Core and an AssetManager profiling scope.
This commit is contained in:
parent
19388ba003
commit
656f1c070f
@ -14,6 +14,7 @@
|
||||
#include "systems/Profiler.h"
|
||||
#include "systems/WindowManager.h"
|
||||
#include "systems/MACROS.h"
|
||||
#include "systems/Scene/Scene.h"
|
||||
|
||||
#define OX_ENGINE_VERSION "Onyx Engine (2025.1)"
|
||||
|
||||
@ -54,6 +55,8 @@ namespace OX
|
||||
WindowManager window;
|
||||
Renderer renderer;
|
||||
|
||||
Scene m_activeScene;
|
||||
|
||||
bool m_running = false;
|
||||
std::string m_name = "Application";
|
||||
};
|
||||
|
@ -7,6 +7,9 @@
|
||||
#include <GL/glew.h>
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <fstream>
|
||||
#include <ranges>
|
||||
|
||||
#include "Profiler.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@ -69,6 +72,10 @@ namespace OX
|
||||
s_TotalTexturesToLoad.store(0);
|
||||
s_LoadedTexturesCount.store(0);
|
||||
s_ScanThread = std::thread(BackgroundScan);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void AssetManager::BackgroundScan()
|
||||
@ -144,6 +151,7 @@ namespace OX
|
||||
|
||||
void AssetManager::Tick()
|
||||
{
|
||||
OX_PROFILE_FUNCTION();
|
||||
std::lock_guard<std::mutex> qlock(s_QueueMutex);
|
||||
while (!s_TextureQueue.empty()) {
|
||||
auto pending = s_TextureQueue.front();
|
||||
|
@ -1,4 +1,4 @@
|
||||
// src/h/Components/TagComponent.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
@ -1,6 +1,9 @@
|
||||
// src/GameObject.cpp
|
||||
|
||||
#include "GameObject.h"
|
||||
|
||||
#include "Components/TagComponent.h"
|
||||
#include "systems/Logger.h"
|
||||
|
||||
namespace OX
|
||||
{
|
||||
GameObject::GameObject(const std::string &name)
|
||||
@ -69,11 +72,18 @@ namespace OX
|
||||
|
||||
if (node["components"]) {
|
||||
for (auto &cnode: node["components"]) {
|
||||
// e.g.:
|
||||
// std::string type = cnode["type"].as<std::string>();
|
||||
// auto comp = ComponentFactory::Create(type);
|
||||
// comp->Deserialize(cnode);
|
||||
// addComponent(std::move(comp));
|
||||
std::string type = cnode["type"].as<std::string>();
|
||||
if (type == "TagComponent") {
|
||||
auto name = cnode["name"].as<std::string>();
|
||||
std::unique_ptr<Component> comp = std::make_unique<TagComponent>(name);
|
||||
addComponent(std::move(comp));
|
||||
} else if (type == "TransformComponent") {
|
||||
//auto name = cnode["name"].as<std::string>();
|
||||
//std::unique_ptr<Component> comp = std::make_unique<TagComponent>(name);
|
||||
//addComponent(std::move(comp));
|
||||
} else {
|
||||
Logger::LogError("Invalid Component: '%s'", type.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// src/h/GameObject.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
@ -19,16 +19,16 @@ namespace OX
|
||||
// Name
|
||||
void setName(const std::string &name);
|
||||
|
||||
const std::string &name() const;
|
||||
[[nodiscard]] const std::string &name() const;
|
||||
|
||||
// Hierarchy
|
||||
GameObject *parent() const;
|
||||
[[nodiscard]] GameObject *parent() const;
|
||||
|
||||
void addChild(std::unique_ptr<GameObject> child);
|
||||
|
||||
std::unique_ptr<GameObject> removeChild(GameObject *child);
|
||||
|
||||
const std::vector<std::unique_ptr<GameObject> > &children() const;
|
||||
[[nodiscard]] const std::vector<std::unique_ptr<GameObject> > &children() const;
|
||||
|
||||
// Components
|
||||
void addComponent(std::unique_ptr<Component> comp);
|
||||
@ -39,10 +39,10 @@ namespace OX
|
||||
template<typename T>
|
||||
std::unique_ptr<Component> removeComponent();
|
||||
|
||||
const std::vector<std::unique_ptr<Component> > &components() const;
|
||||
[[nodiscard]] const std::vector<std::unique_ptr<Component> > &components() const;
|
||||
|
||||
// Serialization
|
||||
YAML::Node Serialize() const;
|
||||
[[nodiscard]] YAML::Node Serialize() const;
|
||||
|
||||
void Deserialize(const YAML::Node &node);
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
// src/Scene.cpp
|
||||
#include "Scene.h"
|
||||
#include <algorithm> // for std::find_if
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// src/h/Scene.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
@ -93,6 +93,10 @@ namespace OX
|
||||
} else {
|
||||
if (ImGui::Button("Grid View")) _gridMode = true;
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Rescan")) {
|
||||
AssetManager::Rescan();
|
||||
}
|
||||
|
||||
size_t total = AssetManager::GetTotalTexturesToLoad();
|
||||
size_t loaded = AssetManager::GetLoadedTexturesCount();
|
||||
|
Loading…
Reference in New Issue
Block a user