11#include " app.hpp"
22#include " compat/assert.hpp"
33#include " compat/sysexits.hpp"
4+ #include " compat/shared-ptr-wrapper.hpp"
45#include " editor.hpp"
56#include " src/anim-atlas.hpp"
67#include " src/critter.hpp"
@@ -28,16 +29,22 @@ floormat_main& app::main() { return *M; }
2829const cursor_state& app::cursor_state () { return cursor; }
2930
3031
31- std::shared_ptr <critter> app::ensure_player_character (world& w)
32+ shared_ptr_wrapper <critter> app::ensure_player_character (world& w)
3233{
3334 if (_character_id)
35+ {
36+ std::shared_ptr<critter> tmp;
3437 if (auto C = w.find_object (_character_id); C && C->type () == object_type::critter)
35- return std::static_pointer_cast<critter>(C);
38+ {
39+ auto ptr = std::static_pointer_cast<critter>(C);
40+ return {ptr};
41+ }
42+ }
3643 _character_id = 0 ;
3744
3845 auto id = (object_id)-1 ;
3946
40- std::shared_ptr <critter> ret;
47+ shared_ptr_wrapper <critter> ret;
4148
4249 for (const auto & [coord, c] : w.chunks ())
4350 {
@@ -50,7 +57,7 @@ std::shared_ptr<critter> app::ensure_player_character(world& w)
5057 if (C.playable )
5158 {
5259 id = std::min (id, C.id );
53- ret = std::static_pointer_cast<critter>(e_);
60+ ret. ptr = std::static_pointer_cast<critter>(e_);
5461 }
5562 }
5663 }
@@ -63,11 +70,11 @@ std::shared_ptr<critter> app::ensure_player_character(world& w)
6370 critter_proto cproto;
6471 cproto.name = " Player" _s;
6572 cproto.playable = true ;
66- ret = w.make_object <critter>(w.make_id (), global_coords{}, cproto);
67- _character_id = ret->id ;
73+ ret. ptr = w.make_object <critter>(w.make_id (), global_coords{}, cproto);
74+ _character_id = ret. ptr ->id ;
6875 }
69- fm_debug_assert (ret);
70- return ret;
76+ fm_debug_assert (ret. ptr );
77+ return shared_ptr_wrapper<critter>{ ret} ;
7178}
7279
7380void app::reset_world (class world && w_)
@@ -176,15 +183,13 @@ int app::run_from_argv(const int argc, const char* const* const argv)
176183 opts.argv = argv;
177184 opts.argc = argc;
178185
179- Pointer<struct floormat_main > main;
180- Pointer<struct app > app_ptr{new app{Utility::move (opts)}};
181- auto & app = *app_ptr;
182- {
183- ret = app.exec ();
184- main = Utility::move (app.M );
185- (void )main;
186- }
187- loader_::destroy ();
186+ struct app * A = new app{Utility::move (opts)};
187+ floormat_main* M = A->M ;
188+ fm_assert (M != nullptr );
189+ ret = A->exec ();
190+ loader.destroy ();
191+ delete A;
192+ delete M;
188193 return ret;
189194}
190195
0 commit comments