@@ -61,6 +61,7 @@ Index of this file:
6161
6262// unstable extensions
6363#include "pl_ecs_ext.h"
64+ #include "pl_material_ext.h"
6465#include "pl_mesh_ext.h"
6566#include "pl_camera_ext.h"
6667#include "pl_animation_ext.h"
@@ -76,6 +77,7 @@ Index of this file:
7677#include "pl_shader_variant_ext.h"
7778#include "pl_vfs_ext.h"
7879#include "pl_compress_ext.h"
80+ #include "pl_script_ext.h"
7981
8082// shaders
8183#include "pl_shader_interop_renderer.h" // PL_MESH_FORMAT_FLAG_XXXX
@@ -120,6 +122,8 @@ const plVfsI* gptVfs = NULL;
120122const plPakI * gptPak = NULL ;
121123const plDateTimeI * gptDateTime = NULL ;
122124const plCompressI * gptCompress = NULL ;
125+ const plMaterialI * gptMaterial = NULL ;
126+ const plScriptI * gptScript = NULL ;
123127
124128#define PL_ALLOC (x ) gptMemory->tracked_realloc(NULL, (x), __FILE__, __LINE__)
125129#define PL_REALLOC (x , y ) gptMemory->tracked_realloc((x), (y), __FILE__, __LINE__)
@@ -390,10 +394,12 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
390394
391395 gptEcs -> initialize ((plEcsInit ){0 });
392396 gptRenderer -> register_ecs_system ();
397+ gptScript -> register_ecs_system ();
393398 gptCamera -> register_ecs_system ();
394399 gptAnimation -> register_ecs_system ();
395400 gptMesh -> register_ecs_system ();
396401 gptPhysics -> register_ecs_system ();
402+ gptMaterial -> register_ecs_system ();
397403 gptEcs -> finalize ();
398404 ptAppData -> ptComponentLibrary = gptEcs -> get_default_library ();
399405
@@ -403,14 +409,13 @@ pl_app_load(plApiRegistryI* ptApiRegistry, plAppData* ptAppData)
403409 };
404410 ptAppData -> ptScene = gptRenderer -> create_scene (tSceneInit );
405411 ptAppData -> ptView = gptRenderer -> create_view (ptAppData -> ptScene , ptIO -> tMainViewportSize );
406- ptAppData -> ptSecondaryView = gptRenderer -> create_view (ptAppData -> ptScene , (plVec2 ){500.0f , 500.0f });
407412
408413 // create main camera
409414 plCamera * ptMainCamera = NULL ;
410415 ptAppData -> tMainCamera = gptCamera -> create_perspective (ptAppData -> ptComponentLibrary , "main camera" , pl_create_vec3 (-4.012f , 2.984f , -1.109f ), PL_PI_3 , ptIO -> tMainViewportSize .x / ptIO -> tMainViewportSize .y , 0.1f , 48.0f , true, & ptMainCamera );
411416 gptCamera -> set_pitch_yaw (ptMainCamera , -0.465f , 1.341f );
412417 gptCamera -> update (ptMainCamera );
413- gptEcs -> attach_script (ptAppData -> ptComponentLibrary , "pl_script_camera" , PL_SCRIPT_FLAG_PLAYING | PL_SCRIPT_FLAG_RELOADABLE , ptAppData -> tMainCamera , NULL );
418+ gptScript -> attach (ptAppData -> ptComponentLibrary , "pl_script_camera" , PL_SCRIPT_FLAG_PLAYING | PL_SCRIPT_FLAG_RELOADABLE , ptAppData -> tMainCamera , NULL );
414419
415420 // create secondary camera
416421 plCamera * ptSecondaryCamera = NULL ;
@@ -530,7 +535,8 @@ pl_app_shutdown(plAppData* ptAppData)
530535 gptConsole -> cleanup ();
531536
532537 gptRenderer -> cleanup_view (ptAppData -> ptView );
533- gptRenderer -> cleanup_view (ptAppData -> ptSecondaryView );
538+ if (ptAppData -> ptSecondaryView )
539+ gptRenderer -> cleanup_view (ptAppData -> ptSecondaryView );
534540 gptRenderer -> cleanup_scene (ptAppData -> ptScene );
535541
536542 gptEcs -> cleanup ();
@@ -615,7 +621,7 @@ pl_app_update(plAppData* ptAppData)
615621
616622 // run ecs system
617623 pl_begin_cpu_sample (gptProfile , 0 , "Run ECS" );
618- gptEcs -> run_script_update_system (ptAppData -> ptComponentLibrary );
624+ gptScript -> run_update_system (ptAppData -> ptComponentLibrary );
619625 gptAnimation -> run_animation_update_system (ptAppData -> ptComponentLibrary , ptIO -> fDeltaTime );
620626 gptPhysics -> update (ptIO -> fDeltaTime , ptAppData -> ptComponentLibrary );
621627 gptEcs -> run_transform_update_system (ptAppData -> ptComponentLibrary );
@@ -700,19 +706,22 @@ pl_app_update(plAppData* ptAppData)
700706 plLightComponent * ptLights = NULL ;
701707 const uint32_t uLightCount = gptEcs -> get_components (ptAppData -> ptComponentLibrary , gptRenderer -> get_ecs_type_key_light (), (void * * )& ptLights , NULL );
702708 gptRenderer -> debug_draw_lights (ptAppData -> ptView , ptLights , uLightCount );
703- gptRenderer -> debug_draw_lights (ptAppData -> ptSecondaryView , ptLights , uLightCount );
709+ if (ptAppData -> ptSecondaryView )
710+ gptRenderer -> debug_draw_lights (ptAppData -> ptSecondaryView , ptLights , uLightCount );
704711 }
705712
706713 if (ptAppData -> bDrawAllBoundingBoxes )
707714 {
708715 gptRenderer -> debug_draw_all_bound_boxes (ptAppData -> ptView );
709- gptRenderer -> debug_draw_all_bound_boxes (ptAppData -> ptSecondaryView );
716+ if (ptAppData -> ptSecondaryView )
717+ gptRenderer -> debug_draw_all_bound_boxes (ptAppData -> ptSecondaryView );
710718 }
711719
712720 if (ptAppData -> bShowSkybox )
713721 {
714722 gptRenderer -> show_skybox (ptAppData -> ptView );
715- gptRenderer -> show_skybox (ptAppData -> ptSecondaryView );
723+ if (ptAppData -> ptSecondaryView )
724+ gptRenderer -> show_skybox (ptAppData -> ptSecondaryView );
716725 }
717726
718727 if (ptAppData -> bShowBVH )
@@ -724,7 +733,8 @@ pl_app_update(plAppData* ptAppData)
724733 if (ptAppData -> bShowGrid )
725734 {
726735 gptRenderer -> show_grid (ptAppData -> ptView );
727- gptRenderer -> show_grid (ptAppData -> ptSecondaryView );
736+ if (ptAppData -> ptSecondaryView )
737+ gptRenderer -> show_grid (ptAppData -> ptSecondaryView );
728738 }
729739
730740 // render scene
@@ -839,7 +849,18 @@ pl__show_editor_window(plAppData* ptAppData)
839849 gptUI -> checkbox ("Editor Attached" , & ptAppData -> bEditorAttached );
840850 gptUI -> checkbox ("Show Debug Lights" , & ptAppData -> bShowDebugLights );
841851 gptUI -> checkbox ("Show Bounding Boxes" , & ptAppData -> bDrawAllBoundingBoxes );
842- gptUI -> checkbox ("Secondary View" , & ptAppData -> bSecondaryViewActive );
852+ if (gptUI -> checkbox ("Secondary View" , & ptAppData -> bSecondaryViewActive ))
853+ {
854+ if (ptAppData -> bSecondaryViewActive )
855+ {
856+ ptAppData -> ptSecondaryView = gptRenderer -> create_view (ptAppData -> ptScene , (plVec2 ){500.0f , 500.0f });
857+ }
858+ else
859+ {
860+ gptRenderer -> cleanup_view (ptAppData -> ptSecondaryView );
861+ ptAppData -> ptSecondaryView = NULL ;
862+ }
863+ }
843864
844865 gptUI -> vertical_spacing ();
845866
@@ -1061,6 +1082,8 @@ pl__load_apis(plApiRegistryI* ptApiRegistry)
10611082 gptPak = pl_get_api_latest (ptApiRegistry , plPakI );
10621083 gptDateTime = pl_get_api_latest (ptApiRegistry , plDateTimeI );
10631084 gptCompress = pl_get_api_latest (ptApiRegistry , plCompressI );
1085+ gptMaterial = pl_get_api_latest (ptApiRegistry , plMaterialI );
1086+ gptScript = pl_get_api_latest (ptApiRegistry , plScriptI );
10641087}
10651088
10661089
0 commit comments