Skip to content

Commit 6a1b6f4

Browse files
More update around the editor (#431)
* initial move to arena * initial editor move to arena alloc * more arena for importers and serializers * cleanup around the editor * fixed scene name * format * improved importers and serializers concurrency
1 parent 58137a4 commit 6a1b6f4

23 files changed

+599
-518
lines changed

Tetragrama/Components/DockspaceUIComponent.cpp

+35-17
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,41 @@ namespace Tetragrama::Components
2121
std::string DockspaceUIComponent::s_asset_importer_report_msg = "";
2222
float DockspaceUIComponent::s_editor_scene_serializer_progress = 0.0f;
2323

24-
DockspaceUIComponent::DockspaceUIComponent() : m_asset_importer(CreateScope<Importers::AssimpImporter>()), m_editor_serializer(CreateScope<Serializers::EditorSceneSerializer>()) {}
24+
DockspaceUIComponent::DockspaceUIComponent() {}
2525

2626
DockspaceUIComponent::~DockspaceUIComponent() {}
2727

2828
void DockspaceUIComponent::Initialize(Layers::ImguiLayer* parent, const char* name, bool visibility, bool closed)
2929
{
3030
UIComponent::Initialize(parent, name, visibility, closed);
3131

32-
m_dockspace_node_flag = ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_PassthruCentralNode;
33-
m_window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
32+
m_asset_importer = ZPushStructCtor(&(parent->LayerArena), Importers::AssimpImporter);
33+
m_editor_serializer = ZPushStructCtor(&(parent->LayerArena), Serializers::EditorSceneSerializer);
3434

35-
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
36-
m_editor_serializer->Context = context;
37-
m_asset_importer->Context = context;
35+
m_editor_serializer->Initialize(&(parent->LayerArena));
36+
m_asset_importer->Initialize(&(parent->LayerArena));
3837

39-
const auto& editor_config = *context->ConfigurationPtr;
38+
m_editor_serializer->AssetImporter = m_asset_importer;
4039

41-
m_default_import_configuration = {.OutputModelFilePath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath), .OutputMeshFilePath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath), .OutputTextureFilesPath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.DefaultImportTexturePath), .OutputMaterialsPath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath)};
40+
m_dockspace_node_flag = ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_PassthruCentralNode;
41+
m_window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
42+
43+
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
44+
m_editor_serializer->Context = context;
45+
m_asset_importer->Context = context;
46+
47+
const auto& editor_config = *context->ConfigurationPtr;
48+
49+
auto o_model_fpath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath);
50+
auto o_mesh_fpath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath);
51+
auto o_texture_fpath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.DefaultImportTexturePath);
52+
auto o_material_fpath = fmt::format("{0}/{1}", editor_config.WorkingSpacePath, editor_config.SceneDataPath);
53+
54+
m_default_import_configuration = {};
55+
m_default_import_configuration.OutputModelFilePath.init(&(parent->LayerArena), o_model_fpath.c_str());
56+
m_default_import_configuration.OutputMeshFilePath.init(&(parent->LayerArena), o_mesh_fpath.c_str());
57+
m_default_import_configuration.OutputTextureFilesPath.init(&(parent->LayerArena), o_texture_fpath.c_str());
58+
m_default_import_configuration.OutputMaterialsPath.init(&(parent->LayerArena), o_material_fpath.c_str());
4259

4360
#ifdef _WIN32
4461
std::replace(m_default_import_configuration.OutputModelFilePath.begin(), m_default_import_configuration.OutputModelFilePath.end(), '/', '\\');
@@ -305,8 +322,8 @@ namespace Tetragrama::Components
305322

306323
if (ImGui::Button("Save", ImVec2(80, 0)) && is_save_button_enabled)
307324
{
308-
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
309-
ZEngine::Helpers::secure_strcpy(context->CurrentScenePtr->Name, 50, s_save_as_input_buffer);
325+
auto context = reinterpret_cast<EditorContext*>(ParentLayer->ParentContext);
326+
context->CurrentScenePtr->Name = s_save_as_input_buffer;
310327
m_editor_serializer->Serialize(context->CurrentScenePtr);
311328

312329
m_open_save_scene_as = false;
@@ -422,7 +439,7 @@ namespace Tetragrama::Components
422439
//{
423440
// data.SerializedModelPath.replace(data.SerializedModelPath.find(ws), ws.size(), "");
424441
// }
425-
442+
//
426443
// context_ptr->CurrentScenePtr->Push(data.SerializedMeshesPath, data.SerializedModelPath, data.SerializedMaterialsPath);
427444
}
428445

@@ -513,8 +530,9 @@ namespace Tetragrama::Components
513530
auto ctx = reinterpret_cast<EditorContext*>(context);
514531

515532
// Todo : Ensure no data race on CurrentScenePtr
516-
ZEngine::Helpers::secure_strcpy(ctx->CurrentScenePtr->Name, 50, scene.Name);
533+
ZEngine::Helpers::secure_strcpy(ctx->ConfigurationPtr->ActiveSceneName, ZEngine::Helpers::secure_strlen(scene.Name), scene.Name);
517534

535+
ctx->CurrentScenePtr->Name = ctx->ConfigurationPtr->ActiveSceneName;
518536
ctx->CurrentScenePtr->Data = scene.Data;
519537
ctx->CurrentScenePtr->MeshFiles = scene.MeshFiles;
520538
ctx->CurrentScenePtr->ModelFiles = scene.ModelFiles;
@@ -552,11 +570,11 @@ namespace Tetragrama::Components
552570
{
553571
if (!filename.empty())
554572
{
555-
auto parent_path = std::filesystem::path(filename).parent_path().string();
556-
auto asset_name = fs::path(filename).filename().replace_extension().string();
557-
auto import_config = m_default_import_configuration;
558-
import_config.AssetFilename = asset_name;
559-
import_config.InputBaseAssetFilePath = parent_path;
573+
auto parent_path = std::filesystem::path(filename).parent_path().string();
574+
auto asset_name = fs::path(filename).filename().replace_extension().string();
575+
auto import_config = m_default_import_configuration;
576+
import_config.AssetFilename.init(&(ParentLayer->LayerArena), asset_name.c_str());
577+
import_config.InputBaseAssetFilePath.init(&(ParentLayer->LayerArena), parent_path.c_str());
560578
co_await m_asset_importer->ImportAsync(filename, import_config);
561579
}
562580
co_return;

Tetragrama/Components/DockspaceUIComponent.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ namespace Tetragrama::Components
5555
static float s_editor_scene_serializer_progress;
5656

5757
private:
58-
bool m_open_asset_importer{false};
59-
bool m_open_exit{false};
60-
bool m_pending_shutdown{false};
61-
bool m_open_save_scene{false};
62-
bool m_open_save_scene_as{false};
63-
bool m_request_save_scene_ui_close{false};
64-
ImGuiDockNodeFlags m_dockspace_node_flag;
65-
ImGuiWindowFlags m_window_flags;
66-
Importers::ImportConfiguration m_default_import_configuration;
67-
ZEngine::Helpers::Scope<Importers::IAssetImporter> m_asset_importer;
68-
ZEngine::Helpers::Scope<Serializers::EditorSceneSerializer> m_editor_serializer;
58+
bool m_open_asset_importer{false};
59+
bool m_open_exit{false};
60+
bool m_pending_shutdown{false};
61+
bool m_open_save_scene{false};
62+
bool m_open_save_scene_as{false};
63+
bool m_request_save_scene_ui_close{false};
64+
ImGuiDockNodeFlags m_dockspace_node_flag;
65+
ImGuiWindowFlags m_window_flags;
66+
Importers::ImportConfiguration m_default_import_configuration;
67+
ZRawPtr(Importers::IAssetImporter) m_asset_importer;
68+
ZRawPtr(Serializers::EditorSceneSerializer) m_editor_serializer;
6969
};
7070
} // namespace Tetragrama::Components

Tetragrama/Controllers/EditorCameraController.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Tetragrama::Controllers
1010
m_position = {0.0f, 0.0f, 1.5f};
1111
m_process_event = true;
1212
m_controller_type = Controllers::CameraControllerType::PERSPECTIVE_CONTROLLER;
13+
m_window = window;
1314

1415
m_perspective_camera = ZPushStructCtor(arena, PerspectiveCamera);
1516
m_perspective_camera->Initialize(m_camera_fov, m_aspect_ratio, m_camera_near, m_camera_far, glm::radians(yaw_degree), glm::radians(pitch_degree));

Tetragrama/Controllers/ICameraController.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ namespace Tetragrama::Controllers
1010
struct ICameraController : public IController
1111
{
1212
ICameraController() {}
13-
virtual ~ICameraController() = default;
13+
virtual ~ICameraController() = default;
1414

15-
virtual glm::vec3 GetPosition() const = 0;
16-
virtual void SetPosition(const glm::vec3& position) = 0;
17-
virtual const ZEngine::Helpers::Ref<ZEngine::Rendering::Cameras::Camera> GetCamera() const = 0;
18-
virtual void UpdateProjectionMatrix() = 0;
15+
virtual glm::vec3 GetPosition() const = 0;
16+
virtual void SetPosition(const glm::vec3& position) = 0;
17+
virtual ZRawPtr(ZEngine::Rendering::Cameras::Camera) GetCamera() const = 0;
18+
virtual void UpdateProjectionMatrix() = 0;
1919

20-
float GetRotationAngle() const
20+
float GetRotationAngle() const
2121
{
2222
return m_rotation_angle;
2323
}

Tetragrama/Controllers/IController.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace Tetragrama::Controllers
1010
{
11-
struct IController : public ZEngine::Core::IUpdatable, public ZEngine::Core::IEventable, public ZEngine::Helpers::RefCounted
11+
struct IController : public ZEngine::Core::IUpdatable, public ZEngine::Core::IEventable
1212
{
1313
IController() = default;
1414
~IController() = default;

Tetragrama/Controllers/PerspectiveCameraController.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ namespace Tetragrama::Controllers
103103
}
104104
}
105105

106-
const Ref<Rendering::Cameras::Camera> PerspectiveCameraController::GetCamera() const
106+
ZRawPtr(ZEngine::Rendering::Cameras::Camera) PerspectiveCameraController::GetCamera() const
107107
{
108108
return m_perspective_camera;
109109
}

Tetragrama/Controllers/PerspectiveCameraController.h

+16-16
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ namespace Tetragrama::Controllers
1414
PerspectiveCameraController();
1515
virtual ~PerspectiveCameraController() = default;
1616

17-
void Update(ZEngine::Core::TimeStep) override;
18-
bool OnEvent(ZEngine::Core::CoreEvent&) override;
17+
void Update(ZEngine::Core::TimeStep) override;
18+
bool OnEvent(ZEngine::Core::CoreEvent&) override;
1919

20-
const ZEngine::Helpers::Ref<ZEngine::Rendering::Cameras::Camera> GetCamera() const override;
20+
ZRawPtr(ZEngine::Rendering::Cameras::Camera) GetCamera() const override;
2121

22-
void UpdateProjectionMatrix() override;
22+
void UpdateProjectionMatrix() override;
2323

24-
virtual glm::vec3 GetPosition() const override;
25-
virtual void SetPosition(const glm::vec3& position) override;
24+
virtual glm::vec3 GetPosition() const override;
25+
virtual void SetPosition(const glm::vec3& position) override;
2626

27-
virtual float GetFieldOfView() const;
28-
virtual void SetFieldOfView(float rad_fov);
27+
virtual float GetFieldOfView() const;
28+
virtual void SetFieldOfView(float rad_fov);
2929

30-
virtual float GetNear() const;
31-
virtual void SetNear(float value);
30+
virtual float GetNear() const;
31+
virtual void SetNear(float value);
3232

33-
virtual float GetFar() const;
34-
virtual void SetFar(float value);
33+
virtual float GetFar() const;
34+
virtual void SetFar(float value);
3535

36-
void SetViewport(float width, float height);
37-
void SetTarget(const glm::vec3& target);
36+
void SetViewport(float width, float height);
37+
void SetTarget(const glm::vec3& target);
3838

39-
virtual void ResumeEventProcessing();
40-
virtual void PauseEventProcessing();
39+
virtual void ResumeEventProcessing();
40+
virtual void PauseEventProcessing();
4141

4242
public:
4343
bool OnMouseButtonPressed(ZEngine::Windows::Events::MouseButtonPressedEvent&) override

Tetragrama/Editor.cpp

+45-22
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <nlohmann/json.hpp>
77

88
using namespace ZEngine;
9+
using namespace ZEngine::Core::Container;
910
using namespace ZEngine::Core::Memory;
1011
using namespace ZEngine::Helpers;
1112
using namespace Tetragrama::Layers;
@@ -23,34 +24,30 @@ namespace Tetragrama
2324
{
2425
Context = ZPushStruct(arena, EditorContext);
2526

26-
arena->CreateSubArena(ZMega(3), &(Context->Arena));
27+
arena->CreateSubArena(ZMega(10), &(Context->Arena));
2728

28-
Context->ConfigurationPtr = ZPushStructCtor(&(Context->Arena), EditorConfiguration);
29-
Context->CameraControllerPtr = ZPushStructCtor(&(Context->Arena), EditorCameraController);
29+
Context->ConfigurationPtr = ZPushStructCtor(&(Context->Arena), EditorConfiguration);
30+
Context->CameraControllerPtr = ZPushStructCtor(&(Context->Arena), EditorCameraController);
31+
UILayer = ZPushStructCtor(&(Context->Arena), ImguiLayer);
32+
CanvasLayer = ZPushStructCtor(&(Context->Arena), RenderLayer);
3033

31-
Context->CurrentScenePtr = ZPushStructCtor(&(Context->Arena), EditorScene);
32-
Context->CurrentScenePtr->RenderScene = ZPushStructCtor(&(Context->Arena), ZEngine::Rendering::Scenes::GraphicScene);
33-
34-
UILayer = ZPushStructCtor(&(Context->Arena), ImguiLayer);
35-
CanvasLayer = ZPushStructCtor(&(Context->Arena), RenderLayer);
34+
Context->CurrentScenePtr = ZPushStructCtor(&(Context->Arena), EditorScene);
3635

3736
if (Helpers::secure_strlen(file))
3837
{
3938
Context->ConfigurationPtr->ReadConfig(file);
4039

4140
if (Helpers::secure_strlen(Context->ConfigurationPtr->ActiveSceneName))
4241
{
43-
Helpers::secure_strcpy(Context->CurrentScenePtr->Name, 50, Context->ConfigurationPtr->ActiveSceneName);
42+
Context->CurrentScenePtr->Initialize(&(Context->Arena), Context->ConfigurationPtr->ActiveSceneName);
4443
}
4544
}
4645

47-
Context->CurrentScenePtr->RenderScene->IsDrawDataDirty = true;
48-
49-
UILayer->ParentContext = reinterpret_cast<void*>(Context);
50-
CanvasLayer->ParentContext = reinterpret_cast<void*>(Context);
46+
UILayer->ParentContext = reinterpret_cast<void*>(Context);
47+
CanvasLayer->ParentContext = reinterpret_cast<void*>(Context);
5148

52-
std::string title = fmt::format("{0} - Active Scene : {1}", Context->ConfigurationPtr->ProjectName, Context->CurrentScenePtr->Name);
53-
Windows::WindowConfiguration window_conf = {.EnableVsync = true};
49+
std::string title = fmt::format("{0} - Active Scene : {1}", Context->ConfigurationPtr->ProjectName, Context->CurrentScenePtr->Name);
50+
Windows::WindowConfiguration window_conf = {.EnableVsync = true};
5451
window_conf.Title.init(&(Context->Arena), title.c_str());
5552
window_conf.RenderingLayerCollection.init(&(Context->Arena), 1, 0);
5653
window_conf.OverlayLayerCollection.init(&(Context->Arena), 1, 0);
@@ -70,22 +67,48 @@ namespace Tetragrama
7067
// ZEngine::Engine::Run();
7168
}
7269

73-
void EditorScene::Push(std::string_view mesh, std::string_view model, std::string_view material)
70+
void EditorScene::Initialize(ZEngine::Core::Memory::ArenaAllocator* arena, const char* name)
71+
{
72+
Name = name;
73+
74+
RenderScene = ZPushStructCtor(arena, ZEngine::Rendering::Scenes::GraphicScene);
75+
RenderScene->IsDrawDataDirty = true;
76+
77+
MeshFiles.init(arena, 1, 0);
78+
ModelFiles.init(arena, 1, 0);
79+
MaterialFiles.init(arena, 1, 0);
80+
Hashes.init(arena, 1, 0);
81+
}
82+
83+
void EditorScene::Push(ZEngine::Core::Memory::ArenaAllocator* arena, const char* mesh, const char* model, const char* material)
7484
{
7585
uint16_t mesh_file_id = MeshFiles.size();
7686
uint16_t model_file_id = ModelFiles.size();
7787
uint16_t material_file_id = MaterialFiles.size();
7888

79-
MeshFiles.emplace_back(mesh);
80-
ModelFiles.emplace_back(model);
81-
MaterialFiles.emplace_back(material);
89+
String mesh_file = {};
90+
String model_file = {};
91+
String mat_file = {};
92+
93+
mesh_file.init(arena, mesh);
94+
model_file.init(arena, model);
95+
mat_file.init(arena, material);
96+
97+
MeshFiles.push(mesh_file);
98+
ModelFiles.push(model_file);
99+
MaterialFiles.push(mat_file);
82100

83101
std::stringstream ss;
84102
ss << mesh_file_id << ":" << model_file_id << ":" << material_file_id;
85-
auto hash = ss.str();
86-
Data[hash] = {.MeshFileIndex = mesh_file_id, .ModelPathIndex = model_file_id, .MaterialPathIndex = material_file_id};
103+
auto hash = ss.str();
104+
105+
String hash_str = {};
106+
hash_str.init(arena, hash.c_str());
107+
Hashes.push(hash_str);
108+
109+
Data[hash_str.c_str()] = {.MeshFileIndex = mesh_file_id, .ModelPathIndex = model_file_id, .MaterialPathIndex = material_file_id};
87110

88-
m_has_pending_change = true;
111+
m_has_pending_change = true;
89112
}
90113

91114
bool EditorScene::HasPendingChange() const

0 commit comments

Comments
 (0)