@@ -21,12 +21,16 @@ namespace Tetragrama::Components
21
21
std::string DockspaceUIComponent::s_asset_importer_report_msg = " " ;
22
22
float DockspaceUIComponent::s_editor_scene_serializer_progress = 0 .0f ;
23
23
24
- DockspaceUIComponent::DockspaceUIComponent (std::string_view name, bool visibility) : UIComponent(name, visibility, false ), m_asset_importer(CreateScope<Importers::AssimpImporter>()), m_editor_serializer(CreateScope<Serializers::EditorSceneSerializer>())
24
+ DockspaceUIComponent::DockspaceUIComponent (Layers::ImguiLayer* parent, std::string_view name, bool visibility) : UIComponent(parent, name, visibility, false ), m_asset_importer(CreateScope<Importers::AssimpImporter>()), m_editor_serializer(CreateScope<Serializers::EditorSceneSerializer>())
25
25
{
26
26
m_dockspace_node_flag = ImGuiDockNodeFlags_NoWindowMenuButton | ImGuiDockNodeFlags_PassthruCentralNode;
27
27
m_window_flags = ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
28
28
29
- const auto & editor_config = Editor::GetCurrentEditorConfiguration ();
29
+ auto context = reinterpret_cast <EditorContext*>(ParentLayer->ParentContext );
30
+ m_editor_serializer->Context = context;
31
+ m_asset_importer->Context = context;
32
+
33
+ const auto & editor_config = *context->ConfigurationPtr ;
30
34
31
35
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 )};
32
36
@@ -52,21 +56,13 @@ namespace Tetragrama::Components
52
56
m_asset_importer->SetOnProgressCallback (OnAssetImporterProgress);
53
57
m_asset_importer->SetOnLogCallback (OnAssetImporterLog);
54
58
m_asset_importer->SetOnErrorCallback (OnAssetImporterError);
55
-
56
- auto scene_fullname = fmt::format (" {0}/{1}/{2}.zescene" , editor_config.WorkingSpacePath , editor_config.ScenePath , editor_config.ActiveSceneName );
57
-
58
- #ifdef _WIN32
59
- std::replace (scene_fullname.begin (), scene_fullname.end (), ' /' , ' \\ ' ); // Todo : Move this replace into an helper function....
60
- #endif // _WIN32
61
-
62
- m_editor_serializer->Deserialize (scene_fullname);
63
59
}
64
60
65
61
DockspaceUIComponent::~DockspaceUIComponent () {}
66
62
67
63
void DockspaceUIComponent::Update (ZEngine::Core::TimeStep dt) {}
68
64
69
- void DockspaceUIComponent::Render (ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Rendering::Buffers ::CommandBuffer* const command_buffer)
65
+ void DockspaceUIComponent::Render (ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares ::CommandBuffer* const command_buffer)
70
66
{
71
67
const ImGuiViewport* viewport = ImGui::GetMainViewport ();
72
68
ImGui::SetNextWindowPos (viewport->Pos );
@@ -123,6 +119,12 @@ namespace Tetragrama::Components
123
119
RenderSaveSceneAs ();
124
120
125
121
ImGui::End ();
122
+
123
+ auto ctx = reinterpret_cast <EditorContext*>(ParentLayer->ParentContext );
124
+ if (ctx->CurrentScenePtr && ctx->CurrentScenePtr ->RenderScene ->IsDrawDataDirty )
125
+ {
126
+ ctx->CurrentScenePtr ->RenderScene ->InitOrResetDrawBuffer (renderer->Device , renderer->RenderGraph .get (), renderer->AsyncLoader .get ());
127
+ }
126
128
}
127
129
128
130
void DockspaceUIComponent::RenderImporter ()
@@ -299,9 +301,9 @@ namespace Tetragrama::Components
299
301
300
302
if (ImGui::Button (" Save" , ImVec2 (80 , 0 )) && is_save_button_enabled)
301
303
{
302
- auto active_scene = Editor::GetCurrentEditorScene ( );
303
- active_scene-> SetName ( s_save_as_input_buffer) ;
304
- m_editor_serializer->Serialize (active_scene );
304
+ auto context = reinterpret_cast <EditorContext*>(ParentLayer-> ParentContext );
305
+ context-> CurrentScenePtr -> Name = s_save_as_input_buffer;
306
+ m_editor_serializer->Serialize (context-> CurrentScenePtr );
305
307
306
308
m_open_save_scene_as = false ;
307
309
m_open_save_scene = true ;
@@ -334,7 +336,8 @@ namespace Tetragrama::Components
334
336
335
337
m_pending_shutdown = true ;
336
338
337
- auto current_scene = Editor::GetCurrentEditorScene ();
339
+ auto context = reinterpret_cast <EditorContext*>(ParentLayer->ParentContext );
340
+ auto current_scene = context->CurrentScenePtr ;
338
341
if (!current_scene->HasPendingChange ())
339
342
{
340
343
Helpers::UIDispatcher::RunAsync ([this ] { OnExitAsync (); });
@@ -348,7 +351,7 @@ namespace Tetragrama::Components
348
351
349
352
if (ImGui::BeginPopupModal (str_id, NULL , ImGuiWindowFlags_AlwaysAutoResize))
350
353
{
351
- ImGui::Text (fmt::format (" You have unsaved changes for your current scene : {}" , current_scene->GetName () ).c_str ());
354
+ ImGui::Text (fmt::format (" You have unsaved changes for your current scene : {}" , current_scene->Name ).c_str ());
352
355
ImGui::Separator ();
353
356
354
357
if (ImGui::Button (" Save" , ImVec2 (120 , 0 )))
@@ -357,7 +360,7 @@ namespace Tetragrama::Components
357
360
m_open_exit = false ;
358
361
ImGui::CloseCurrentPopup ();
359
362
360
- m_editor_serializer->Serialize (Editor::GetCurrentEditorScene () );
363
+ m_editor_serializer->Serialize (current_scene );
361
364
}
362
365
ImGui::SetItemDefaultFocus ();
363
366
ImGui::SameLine ();
@@ -391,17 +394,16 @@ namespace Tetragrama::Components
391
394
ZEngine::Helpers::secure_memset (s_save_as_input_buffer, 0 , IM_ARRAYSIZE (s_save_as_input_buffer), IM_ARRAYSIZE (s_save_as_input_buffer));
392
395
}
393
396
394
- void DockspaceUIComponent::OnAssetImporterComplete (Importers::ImporterData&& data)
397
+ void DockspaceUIComponent::OnAssetImporterComplete (void * const context, Importers::ImporterData&& data)
395
398
{
396
399
s_asset_importer_report_msg_color = {0 .0f , 1 .0f , 0 .0f , 1 .0f };
397
400
s_asset_importer_report_msg = " Completed" ;
398
401
399
- auto editor_scene = Editor::GetCurrentEditorScene ();
400
- auto editor_config = Editor::GetCurrentEditorConfiguration ();
402
+ auto context_ptr = reinterpret_cast <EditorContext*>(context);
401
403
/*
402
404
* Removing the WorkingSpace Path
403
405
*/
404
- auto ws = editor_config. WorkingSpacePath + " \\ " ;
406
+ auto ws = context_ptr-> ConfigurationPtr -> WorkingSpacePath + " \\ " ;
405
407
if (data.SerializedMeshesPath .find (ws) != std::string::npos)
406
408
{
407
409
data.SerializedMeshesPath .replace (data.SerializedMeshesPath .find (ws), ws.size (), " " );
@@ -416,27 +418,28 @@ namespace Tetragrama::Components
416
418
{
417
419
data.SerializedModelPath .replace (data.SerializedModelPath .find (ws), ws.size (), " " );
418
420
}
419
- editor_scene->AddModel ({.Name = data.Name , .MeshesPath = data.SerializedMeshesPath , .MaterialsPath = data.SerializedMaterialsPath , .ModelPath = data.SerializedModelPath });
421
+
422
+ context_ptr->CurrentScenePtr ->Push (data.SerializedMeshesPath , data.SerializedModelPath , data.SerializedMaterialsPath );
420
423
}
421
424
422
- void DockspaceUIComponent::OnAssetImporterProgress (float value)
425
+ void DockspaceUIComponent::OnAssetImporterProgress (void * const context, float value)
423
426
{
424
427
s_asset_importer_report_msg_color = {1 .0f , 1 .0f , 1 .0f , 1 .0f };
425
428
s_asset_importer_report_msg = fmt::format (" Reading file: {:.1f} %%" , (value * 100 .f ));
426
429
}
427
430
428
- void DockspaceUIComponent::OnAssetImporterError (std::string_view msg)
431
+ void DockspaceUIComponent::OnAssetImporterError (void * const , std::string_view msg)
429
432
{
430
433
s_asset_importer_report_msg_color = {1 .0f , 0 .0f , 0 .0f , 1 .0f };
431
434
s_asset_importer_report_msg = msg;
432
435
}
433
436
434
- void DockspaceUIComponent::OnEditorSceneSerializerError (std::string_view msg)
437
+ void DockspaceUIComponent::OnEditorSceneSerializerError (void * const , std::string_view msg)
435
438
{
436
439
ZENGINE_CORE_ERROR (" {}" , msg)
437
440
}
438
441
439
- void DockspaceUIComponent::OnAssetImporterLog (std::string_view msg)
442
+ void DockspaceUIComponent::OnAssetImporterLog (void * const , std::string_view msg)
440
443
{
441
444
s_asset_importer_report_msg_color = {1 .0f , 1 .0f , 1 .0f , 1 .0f };
442
445
s_asset_importer_report_msg = msg;
@@ -465,7 +468,13 @@ namespace Tetragrama::Components
465
468
{
466
469
m_open_save_scene = true ;
467
470
m_request_save_scene_ui_close = true ;
468
- Helpers::UIDispatcher::RunAsync ([this ] { m_editor_serializer->Serialize (Editor::GetCurrentEditorScene ()); });
471
+ Helpers::UIDispatcher::RunAsync ([this ] {
472
+ if (ParentLayer->ParentContext )
473
+ {
474
+ auto ctx = reinterpret_cast <EditorContext*>(ParentLayer->ParentContext );
475
+ m_editor_serializer->Serialize (ctx->CurrentScenePtr );
476
+ }
477
+ });
469
478
}
470
479
471
480
ImGui::MenuItem (" Save As..." , NULL , &m_open_save_scene_as);
@@ -488,45 +497,26 @@ namespace Tetragrama::Components
488
497
}
489
498
}
490
499
491
- void DockspaceUIComponent::OnEditorSceneSerializerProgress (float value)
500
+ void DockspaceUIComponent::OnEditorSceneSerializerProgress (void * const , float value)
492
501
{
493
502
s_editor_scene_serializer_progress = value;
494
503
}
495
504
496
- void DockspaceUIComponent::OnEditorSceneSerializerComplete () {}
505
+ void DockspaceUIComponent::OnEditorSceneSerializerComplete (void * const ) {}
497
506
498
- void DockspaceUIComponent::OnEditorSceneSerializerDeserializeComplete (EditorScene&& scene)
507
+ void DockspaceUIComponent::OnEditorSceneSerializerDeserializeComplete (void * const context, EditorScene&& scene)
499
508
{
500
- ZENGINE_CORE_INFO ( " Scene {} loaded successfully " , scene. GetName ())
509
+ auto ctx = reinterpret_cast <EditorContext*>(context);
501
510
502
- ZEngine::Rendering::Scenes::GraphicScene::SetRootNodeName (scene.GetName ());
511
+ // Todo : Ensure no data race on CurrentScenePtr
512
+ ctx->CurrentScenePtr ->Name = scene.Name ;
513
+ ctx->CurrentScenePtr ->Data = scene.Data ;
514
+ ctx->CurrentScenePtr ->MeshFiles = scene.MeshFiles ;
515
+ ctx->CurrentScenePtr ->ModelFiles = scene.ModelFiles ;
516
+ ctx->CurrentScenePtr ->MaterialFiles = scene.MaterialFiles ;
517
+ ctx->CurrentScenePtr ->RenderScene = scene.RenderScene ;
503
518
504
- const auto & config = Editor::GetCurrentEditorConfiguration ();
505
- const auto & scene_models = scene.GetModels ();
506
-
507
- std::vector<ZEngine::Rendering::Scenes::SceneRawData> scene_data;
508
- for (auto & [_, model] : scene_models)
509
- {
510
- auto model_path = fmt::format (" {0}/{1}" , config.WorkingSpacePath , model.ModelPath );
511
- auto mesh_path = fmt::format (" {0}/{1}" , config.WorkingSpacePath , model.MeshesPath );
512
- auto material_path = fmt::format (" {0}/{1}" , config.WorkingSpacePath , model.MaterialsPath );
513
-
514
- #ifdef _WIN32
515
- std::replace (model_path.begin (), model_path.end (), ' /' , ' \\ ' );
516
- std::replace (mesh_path.begin (), mesh_path.end (), ' /' , ' \\ ' );
517
- std::replace (material_path.begin (), material_path.end (), ' /' , ' \\ ' );
518
- #endif // _WIN32
519
-
520
- auto import_data = Importers::IAssetImporter::DeserializeImporterData (model_path, mesh_path, material_path);
521
- scene_data.push_back (import_data.Scene );
522
- }
523
-
524
- if (!scene_data.empty ())
525
- {
526
- ZEngine::Rendering::Scenes::GraphicScene::Merge (scene_data);
527
- }
528
-
529
- Editor::SetCurrentEditorScene (std::move (scene));
519
+ ZENGINE_CORE_INFO (" Scene {} deserialized successfully" , ctx->CurrentScenePtr ->Name )
530
520
}
531
521
532
522
std::future<void > DockspaceUIComponent::OnNewSceneAsync ()
@@ -539,11 +529,14 @@ namespace Tetragrama::Components
539
529
if (ParentLayer)
540
530
{
541
531
auto window = ParentLayer->GetAttachedWindow ();
542
- std::vector<std::string_view> filters = {" ." };
532
+ std::vector<std::string_view> filters = {" .zescene " };
543
533
std::string scene_filename = co_await window->OpenFileDialogAsync (filters);
544
534
545
535
if (!scene_filename.empty ())
546
536
{
537
+ #ifdef _WIN32
538
+ std::replace (scene_filename.begin (), scene_filename.end (), ' /' , ' \\ ' ); // Todo : Move this replace into an helper function....
539
+ #endif
547
540
m_editor_serializer->Deserialize (scene_filename);
548
541
}
549
542
}
0 commit comments