diff --git a/luprex/core/cpp/driver-mingw.cpp b/luprex/core/cpp/driver-mingw.cpp index 64ab144b..88fe23ec 100644 --- a/luprex/core/cpp/driver-mingw.cpp +++ b/luprex/core/cpp/driver-mingw.cpp @@ -347,6 +347,7 @@ public: handle_new_outgoing_sockets(); handle_console_output(); handle_console_input(); + handle_console_output(); int mstimeout = short_sleep_ ? 0 : 100; handle_socket_input_output(mstimeout); handle_clock(); diff --git a/luprex/core/cpp/gui.cpp b/luprex/core/cpp/gui.cpp index 79e713ec..796e5ed9 100644 --- a/luprex/core/cpp/gui.cpp +++ b/luprex/core/cpp/gui.cpp @@ -36,12 +36,22 @@ bool Gui::has_action(const std::string &action) const { } std::string Gui::get_action(int index) { - if ((index < 0) || (index >= elts_.size())) { + if ((index < 0) || (index >= int(elts_.size()))) { return ""; } return elts_[index].action(); } +std::string Gui::menu_debug_string() const { + std::ostringstream oss; + int index = 0; + for (const GuiElt &elt : elts()) { + oss << index << " " << elt.label() << std::endl; + index += 1; + } + return oss.str(); +} + LuaDefine(gui_menu_item, "c") { Gui *gui = Gui::fetch_global_pointer(L); LuaArg laction, llabel; diff --git a/luprex/core/cpp/gui.hpp b/luprex/core/cpp/gui.hpp index a45e8aef..f4018d1c 100644 --- a/luprex/core/cpp/gui.hpp +++ b/luprex/core/cpp/gui.hpp @@ -30,13 +30,17 @@ class Gui { public: using EltVec = std::vector; private: + int64_t place_; EltVec elts_; public: + Gui() { place_ = 0; } + int64_t place() { return place_; } const EltVec &elts() const { return elts_; } - void clear() { elts_.clear(); } + void clear(int64_t p) { place_ = p; elts_.clear(); } bool has_action(const std::string &action) const; void menu_item(const std::string &action, const std::string &label); std::string get_action(int index); + std::string menu_debug_string() const; // Put a pointer to a gui into the lua registry. // diff --git a/luprex/core/cpp/lpxclient.cpp b/luprex/core/cpp/lpxclient.cpp index 63821a8a..6682e7bb 100644 --- a/luprex/core/cpp/lpxclient.cpp +++ b/luprex/core/cpp/lpxclient.cpp @@ -18,7 +18,6 @@ public: LuaConsole console_; PrintChanneler print_channeler_; Gui gui_; - int64_t gui_place_; public: void set_initial_state() { @@ -104,22 +103,14 @@ public: } void do_view_command(const StringVec &cmd) { - for (int64_t id : world_->get_near(actor_id_, 100, true)) { - const Tangible *tan = world_->tangible_get(id); - const AnimStep &aqback = tan->anim_queue_.back(); - stdostream() << id << ": " << aqback.graphic() << " " << aqback.plane() << " " << aqback.xyz().debug_string() << std::endl; - } + stdostream() << world_->tangibles_near_debug_string(actor_id_, 100); } void do_menu_command(const StringVec &cmd) { world_to_asynchronous(); - gui_place_ = util::strtoint(cmd[1], actor_id_); - world_->update_gui(actor_id_, gui_place_, &gui_); - int index = 0; - for (const GuiElt &elt : gui_.elts()) { - stdostream() << index << " " << elt.label() << std::endl; - index += 1; - } + int64_t place = util::strtoint(cmd[1], actor_id_); + world_->update_gui(actor_id_, place, &gui_); + stdostream() << gui_.menu_debug_string(); } void do_choose_command(const StringVec &cmd) { @@ -129,7 +120,7 @@ public: return; } stdostream() << "Invoking plan: " << action << std::endl; - Invocation inv(Invocation::KIND_PLAN, actor_id_, gui_place_, action); + Invocation inv(Invocation::KIND_PLAN, actor_id_, gui_.place(), action); send_invocation(inv); } diff --git a/luprex/core/cpp/textgame.cpp b/luprex/core/cpp/textgame.cpp index 67649b75..515ce06b 100644 --- a/luprex/core/cpp/textgame.cpp +++ b/luprex/core/cpp/textgame.cpp @@ -26,7 +26,6 @@ private: LuaConsole console_; PrintChanneler print_channeler_; Gui gui_; - int64_t gui_place_; int64_t actor_id_; void do_lua_command(const StringVec &words) { @@ -38,21 +37,13 @@ private: } void do_view_command(const StringVec &cmd) { - for (int64_t id : world_->get_near(actor_id_, 100, true)) { - const Tangible *tan = world_->tangible_get(id); - const AnimStep &aqback = tan->anim_queue_.back(); - stdostream() << id << ": " << aqback.graphic() << " " << aqback.plane() << " " << aqback.xyz().debug_string() << std::endl; - } + stdostream() << world_->tangibles_near_debug_string(actor_id_, 100); } void do_menu_command(const StringVec &cmd) { - gui_place_ = util::strtoint(cmd[1], actor_id_); - world_->update_gui(actor_id_, gui_place_, &gui_); - int index = 0; - for (const GuiElt &elt : gui_.elts()) { - stdostream() << index << " " << elt.label() << std::endl; - index += 1; - } + int64_t place = util::strtoint(cmd[1], actor_id_); + world_->update_gui(actor_id_, place, &gui_); + stdostream() << gui_.menu_debug_string(); } void do_choose_command(const StringVec &cmd) { @@ -61,7 +52,7 @@ private: stdostream() << "Invalid menu item #" << std::endl; return; } - Invocation inv(Invocation::KIND_PLAN, actor_id_, gui_place_, action); + Invocation inv(Invocation::KIND_PLAN, actor_id_, gui_.place(), action); stdostream() << "Invoking: " << inv.debug_string() << std::endl; world_->invoke(inv); } @@ -104,7 +95,7 @@ private: if (p.first == actor_id_) { actor_id_ = p.second; stdostream() << "Login actor ID: " << actor_id_ << std::endl; - gui_.clear(); + gui_.clear(0); } } } diff --git a/luprex/core/cpp/world-core.cpp b/luprex/core/cpp/world-core.cpp index 9378fa5e..bce3333a 100644 --- a/luprex/core/cpp/world-core.cpp +++ b/luprex/core/cpp/world-core.cpp @@ -237,7 +237,9 @@ util::IdVector World::get_near_unsorted(int64_t player_id, float radius, bool ex // Find out where's the center of the world. const AnimStep &aqback = player->anim_queue_.back(); if (exclude_nowhere && (aqback.plane() == "nowhere")) { - return IdVector(); + IdVector idv; + idv.push_back(player_id); + return idv; } return plane_map_.scan_radius(aqback.plane(), aqback.xyz().x, aqback.xyz().y, radius, player_id); @@ -274,7 +276,7 @@ int64_t World::create_login_actor() { void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) { assert(stack_is_clear()); - gui->clear(); + gui->clear(place_id); lua_State *L = state(); LuaVar actor, place, ugui, func, tangibles, mt, index; @@ -316,7 +318,7 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) { close_lthread_state(); Gui::store_global_pointer(L, nullptr); if (status != 0) { - gui->clear(); + gui->clear(0); std::cerr << lua_tostring(L, -1); LS.result(); return; diff --git a/luprex/core/cpp/world-testing.cpp b/luprex/core/cpp/world-testing.cpp index bbe6e886..25c7ca06 100644 --- a/luprex/core/cpp/world-testing.cpp +++ b/luprex/core/cpp/world-testing.cpp @@ -30,6 +30,16 @@ std::string World::tangible_ids_debug_string() const { return util::id_vector_debug_string(idv); } +std::string World::tangibles_near_debug_string(int64_t actor, int64_t distance) { + std::ostringstream result; + for (int64_t id : get_near(actor, distance, true)) { + const Tangible *tan = tangible_get(id); + const AnimStep &aqback = tan->anim_queue_.back(); + result << id << ": " << aqback.graphic() << " " << aqback.plane() << " " << aqback.xyz().debug_string() << std::endl; + } + return result.str(); +} + std::string World::tangible_pprint(int64_t id) const { lua_State *L = state(); LuaVar tangibles, tan, meta; diff --git a/luprex/core/cpp/world.hpp b/luprex/core/cpp/world.hpp index 561c3741..e24a958e 100644 --- a/luprex/core/cpp/world.hpp +++ b/luprex/core/cpp/world.hpp @@ -115,8 +115,8 @@ public: // get_near // // Get a list of the tangibles that are near the player. If 'exclude_nowhere' is - // true, exclude any tangibles on the nowhere plane. The unsorted version returns - // the tangibles in an unpredictable order. + // true, exclude any tangibles on the nowhere plane (but still include the player himself). + // The unsorted version returns the tangibles in an unpredictable order. // IdVector get_near(int64_t player_id, float radius, bool exclude_nowhere) const; IdVector get_near_unsorted(int64_t player_id, float radius, bool exclude_nowhere) const; @@ -290,6 +290,10 @@ public: // std::string tangible_ids_debug_string() const; + // Get a list of all tangibles near the target as a string. + // + std::string tangibles_near_debug_string(int64_t actor, int64_t distance); + // Shows the TID (table ID) of the tables that were numbered. // TIDs are in alphabetical order. Any table without a TID // shows up as "unknown"