33#include <stdio.h>
44#include <editor_camera.h>
55#include <game/model.h>
6+ #include <game/camera.h>
67#include <game_manager.h>
78#include <io/log.h>
89#include <misc/memory_usage.h>
1314#include <widget/widget.h>
1415#include <window.h>
1516#include <world.h>
17+ #include <ui/editor_ui.h>
1618
1719struct te_editor {
1820 // Always valid pointer. Must be destroyed during the editor's destruction.
@@ -24,6 +26,12 @@ struct te_editor {
2426 // Not NULL if game world exists.
2527 te_world * game_world ;
2628
29+ // Not NULL if exists.
30+ te_world * editor_world ;
31+
32+ // Always valid.
33+ te_editor_ui * ui ;
34+
2735 // Time (in seconds) since @ref game_world_stats_widget was updated.
2836 float time_since_stats_update_sec ;
2937};
@@ -32,8 +40,10 @@ te_editor*
3240editor_create () {
3341 te_editor * editor = malloc (sizeof (te_editor ));
3442 editor -> editor_camera = editor_camera_create ();
43+ editor -> ui = editor_ui_create ();
3544 editor -> game_world_stats_widget = NULL ;
3645 editor -> game_world = NULL ;
46+ editor -> editor_world = NULL ;
3747 editor -> time_since_stats_update_sec = 10.0f ;
3848
3949 return editor ;
@@ -42,19 +52,33 @@ editor_create() {
4252void
4353editor_destroy (te_editor * editor ) {
4454 editor_camera_destroy (editor -> editor_camera );
55+ editor_ui_destroy (editor -> ui );
4556
4657 free (editor );
4758}
4859
60+ static void
61+ editor_create_editor_world (te_editor * editor , struct te_game_manager * game_manager ) {
62+ editor -> editor_world = game_manager_create_world (game_manager , "editor world" );
63+
64+ // Create a dummy camera to display editor's UI.
65+ te_camera * camera = camera_create ();
66+ world_spawn_camera (editor -> editor_world , camera );
67+ world_set_active_camera (editor -> editor_world , camera );
68+
69+ ui_spawn (editor -> ui , editor -> editor_world );
70+ }
71+
4972void
5073editor_on_game_started (void * game_instance , te_game_manager * game_manager ) {
5174 // Load font.
5275 te_renderer * renderer = game_manager_get_renderer (game_manager );
5376 te_font_manager * font_manager = renderer_get_font_manager (renderer );
5477 font_manager_load_font (font_manager , "engine/font/font.ttf" );
5578
56- // Create default game world .
79+ // Create worlds .
5780 te_editor * editor = game_instance ;
81+ editor_create_editor_world (editor , game_manager );
5882 editor_create_game_world (editor , game_manager );
5983}
6084
0 commit comments