Skip to content

Commit

Permalink
Implement BaseID to avoid clashes
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpect committed Sep 26, 2022
1 parent 0eabdfc commit 404fb85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions editor/editor_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ void EditorSystem::drawDefaultUI(float deltaMilliseconds)
ImGui::Separator();
if (ImGui::BeginMenu("Create Scene"))
{
SceneID inputBaseID = 0;
ImGui::InputText("Scene Name", &newSceneName, ImGuiInputTextFlags_AlwaysInsertMode);
ImGui::InputScalar("Scene BaseID", ImGuiDataType_U32, &inputBaseID);
Scene::SetBaseID(inputBaseID);
if (!newSceneName.empty() && ImGui::Button("Create"))
{
if (SceneLoader::GetSingleton()->getCurrentScene())
Expand Down
12 changes: 11 additions & 1 deletion rootex/framework/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include "components/visual/camera_component.h"
#include "components/audio/audio_listener_component.h"

static SceneID NextSceneID = ROOT_SCENE_ID + 1;
Vector<Scene*> Scene::s_Scenes;
SceneID Scene::BaseID;
static SceneID NextSceneID = ROOT_SCENE_ID + 1;

void to_json(JSON::json& j, const SceneSettings& s)
{
Expand Down Expand Up @@ -50,6 +51,13 @@ void Scene::ResetNextID()
NextSceneID = ROOT_SCENE_ID + 1;
}

void Scene::SetBaseID(const SceneID& inputBaseID)
{
BaseID = inputBaseID;
SceneID SceneIDOffset = 4;
NextSceneID = std::max(std::max(BaseID, NextSceneID), SceneIDOffset);
}

Ptr<Scene> Scene::Create(const JSON::json& sceneData, const bool assignNewIDs)
{
// Decide ID
Expand Down Expand Up @@ -321,6 +329,7 @@ JSON::json Scene::getJSON() const

j["ID"] = m_ID;
j["name"] = m_Name;
j["BaseID"] = m_BaseID;
j["importStyle"] = m_ImportStyle;
j["sceneFile"] = m_SceneFile;
j["entity"] = m_Entity.getJSON();
Expand All @@ -345,6 +354,7 @@ Scene::Scene(SceneID id, const String& name, const SceneSettings& settings, Impo
, m_Entity(this)
{
setName(m_Name);
setBaseID();
s_Scenes.push_back(this);
}

Expand Down
5 changes: 4 additions & 1 deletion rootex/framework/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class Scene
bool m_IsScenePaused;

static Vector<Scene*> s_Scenes;

static SceneID BaseID;
SceneID m_ID;
String m_Name;
SceneID m_BaseID;
String m_FullName;
ImportStyle m_ImportStyle;
/// Contains the current file name if local, else contains the linked scene file
Expand All @@ -57,6 +58,7 @@ class Scene

public:
static void ResetNextID();
static void SetBaseID(const SceneID& inputBaseID);

static Ptr<Scene> Create(const JSON::json& sceneData, const bool assignNewIDs);
static Ptr<Scene> CreateFromFile(const String& sceneFile);
Expand All @@ -80,6 +82,7 @@ class Scene
bool removeChild(Scene* toRemove);

void setName(const String& name);
void setBaseID() { m_BaseID = BaseID; }

JSON::json getJSON() const;
bool& getIsScenePaused() { return m_IsScenePaused; }
Expand Down

0 comments on commit 404fb85

Please sign in to comment.