diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 15:55:50 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-03-15 16:22:16 +0100 |
commit | 73abf154e82546256f4a860c666f1f652767bda9 (patch) | |
tree | 8dda30884e3c8da99f1ea7ebc9232890eeab8bcc /editor | |
parent | 23eae734c5e8a49c02e48fe0b401d610abfee9c8 (diff) |
aa
Diffstat (limited to 'editor')
-rw-r--r-- | editor/app.cpp | 12 | ||||
-rw-r--r-- | editor/app.hpp | 3 | ||||
-rw-r--r-- | editor/draw.cpp | 19 | ||||
-rw-r--r-- | editor/save.cpp | 5 | ||||
-rw-r--r-- | editor/update.cpp | 8 |
5 files changed, 16 insertions, 31 deletions
diff --git a/editor/app.cpp b/editor/app.cpp index aa8608c5..9023b5ac 100644 --- a/editor/app.cpp +++ b/editor/app.cpp @@ -33,17 +33,17 @@ app::app(fm_settings&& opts) : maybe_initialize_chunk_(coord, w[coord]); reset_camera_offset(); inspectors.reserve(16); - _character = w.make_entity<character>(global_coords{}); + _character_id = w.make_entity<character>(global_coords{})->id; } -app::~app() -{ - void(); -} +app::~app() = default; int app::exec() { - return M->exec(); + int ret = M->exec(); + if (M) + M->reset_world(); + return ret; } 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 9e6b1312..abfe2418 100644 --- a/editor/app.hpp +++ b/editor/app.hpp @@ -77,7 +77,6 @@ private: void update_character(float dt); void draw() override; - void draw_character(); void on_mouse_move(const mouse_move_event& event) noexcept override; void on_mouse_up_down(const mouse_button_event& event, bool is_down) noexcept override; @@ -149,7 +148,7 @@ private: key_set keys; std::array<int, key_set::COUNT> key_modifiers = {}; std::vector<popup_target> inspectors; - std::shared_ptr<character> _character; + std::uint64_t _character_id = 0; cursor_state cursor; popup_target _popup_target; diff --git a/editor/draw.cpp b/editor/draw.cpp index dd286edf..5cd6a124 100644 --- a/editor/draw.cpp +++ b/editor/draw.cpp @@ -142,25 +142,6 @@ void app::draw_collision_boxes() shader.set_tint({1, 1, 1, 1}); } -void app::draw_character() -{ - GL::Renderer::enable(GL::Renderer::Feature::DepthTest); - GL::Renderer::setDepthMask(false); - - auto& shader = M->shader(); - auto& mesh = M->meshes().anim; - const auto sz = M->window_size(); - auto& c = *_character; - const auto [minx, maxx, miny, maxy] = M->get_draw_bounds(); - - const with_shifted_camera_offset o{shader, c.coord.chunk(), {minx, miny}, {maxx, maxy}}; - if (floormat_main::check_chunk_visible(shader.camera_offset(), sz)) - mesh.draw(shader, *c.atlas, c.r, c.frame, c.coord.local(), Vector2b(c.offset), tile_shader::character_depth_offset); - - GL::Renderer::setDepthMask(true); - GL::Renderer::disable(GL::Renderer::Feature::DepthTest); -} - void app::draw() { //draw_character(); diff --git a/editor/save.cpp b/editor/save.cpp index 8c33b435..8e38b2da 100644 --- a/editor/save.cpp +++ b/editor/save.cpp @@ -45,14 +45,13 @@ void app::do_quickload() return; } fputs("quickload... ", stderr); fflush(stderr); - M->world() = world::deserialize(quicksave_file); + M->reset_world(world::deserialize(quicksave_file)); fputs("done\n", stderr); fflush(stderr); } void app::do_new_file() { - auto& w = M->world(); - w = world{}; + auto& w = M->reset_world(); maybe_initialize_chunk_(chunk_coords{}, w[chunk_coords{}]); } diff --git a/editor/update.cpp b/editor/update.cpp index dd985b88..07d703e0 100644 --- a/editor/update.cpp +++ b/editor/update.cpp @@ -201,7 +201,13 @@ void app::update_world(float dt) void app::update_character([[maybe_unused]] float dt) { - _character->set_keys(keys[key_left], keys[key_right], keys[key_up], keys[key_down]); + 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]); + } } void app::set_cursor() |