diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 18:31:47 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 18:31:47 +0100 |
| commit | 05f6826cca6f644444ddb6aaede4955500d48f3b (patch) | |
| tree | 4f6cceeb705dd7bf616a8317601fddb7cd496632 /editor | |
| parent | 73abf154e82546256f4a860c666f1f652767bda9 (diff) | |
a
Diffstat (limited to 'editor')
| -rw-r--r-- | editor/app.cpp | 26 | ||||
| -rw-r--r-- | editor/app.hpp | 2 | ||||
| -rw-r--r-- | editor/save.cpp | 5 | ||||
| -rw-r--r-- | editor/update.cpp | 9 |
4 files changed, 27 insertions, 15 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index 9023b5ac..a452934f 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -28,22 +28,34 @@ app::app(fm_settings&& opts) : _table{loader.anim_atlas("table", loader.SCENERY_PATH)}, _control_panel(loader.anim_atlas("control-panel", loader.SCENERY_PATH)) { - world& w = M->world(); - chunk_coords coord{0 ,0}; + reset_world(); + auto& w = M->world(); + constexpr chunk_coords coord{0, 0}; maybe_initialize_chunk_(coord, w[coord]); reset_camera_offset(); inspectors.reserve(16); - _character_id = w.make_entity<character>(global_coords{})->id; } app::~app() = default; +void app::reset_world() +{ + reset_world(floormat::world{}); +} + +void app::reset_world(struct world&& w) +{ + _character_id = 0; + if (!M) + return; + auto& w2 = M->reset_world(std::move(w)); + w2.collect(true); + _character_id = w2.make_entity<character>(global_coords{})->id; +} + int app::exec() { - int ret = M->exec(); - if (M) - M->reset_world(); - return ret; + return M->exec(); } static const char* const true_values[] = { "1", "true", "yes", "y", "Y", "on", "ON", "enable", "enabled", }; diff --git a/editor/app.hpp b/editor/app.hpp index abfe2418..4cb7305c 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -75,6 +75,8 @@ private: void maybe_initialize_chunk(const chunk_coords& pos, chunk& c) override; void maybe_initialize_chunk_(const chunk_coords& pos, chunk& c); void update_character(float dt); + void reset_world(); + void reset_world(struct world&& w); void draw() override; diff --git a/editor/save.cpp b/editor/save.cpp index 8e38b2da..6d79bfce 100644 --- a/editor/save.cpp +++ b/editor/save.cpp @@ -45,13 +45,14 @@ void app::do_quickload() return; } fputs("quickload... ", stderr); fflush(stderr); - M->reset_world(world::deserialize(quicksave_file)); + reset_world(world::deserialize(quicksave_file)); fputs("done\n", stderr); fflush(stderr); } void app::do_new_file() { - auto& w = M->reset_world(); + reset_world(); + auto& w = M->world(); maybe_initialize_chunk_(chunk_coords{}, w[chunk_coords{}]); } diff --git a/editor/update.cpp b/editor/update.cpp index 07d703e0..6107cfa6 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -202,12 +202,9 @@ void app::update_world(float dt) void app::update_character([[maybe_unused]] float dt) { auto& w = M->world(); - auto cptr = w.find_entity(_character_id); - if (cptr) - { - fm_debug_assert(cptr->type == entity_type::character); - static_cast<character&>(*cptr).set_keys(keys[key_left], keys[key_right], keys[key_up], keys[key_down]); - } + auto c = w.find_entity<character>(_character_id); + if (c) + c->set_keys(keys[key_left], keys[key_right], keys[key_up], keys[key_down]); } void app::set_cursor() |
