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