diff --git a/luprex/core/cpp/animqueue.cpp b/luprex/core/cpp/animqueue.cpp index e1b3279d..7a4d4ce3 100644 --- a/luprex/core/cpp/animqueue.cpp +++ b/luprex/core/cpp/animqueue.cpp @@ -253,19 +253,8 @@ void AnimQueue::deserialize(StreamBuffer *sb) { } } -const std::string &AnimQueue::get_graphic() const { - const AnimStep &last = steps_.back(); - return last.graphic_; -} - -const std::string &AnimQueue::get_plane() const { - const AnimStep &last = steps_.back(); - return last.plane_; -} - -const util::XYZ &AnimQueue::get_xyz() const { - const AnimStep &last = steps_.back(); - return last.xyz_; +const AnimStep &AnimQueue::back() const { + return steps_.back(); } LuaDefine(unittests_animqueue, "c") { diff --git a/luprex/core/cpp/animqueue.hpp b/luprex/core/cpp/animqueue.hpp index 9c30608b..1ce1ddb4 100644 --- a/luprex/core/cpp/animqueue.hpp +++ b/luprex/core/cpp/animqueue.hpp @@ -117,9 +117,7 @@ public: void add(int64_t id, lua_State *L, int idx); // Get the final resting place after all animations are complete. - const std::string &get_graphic() const; - const std::string &get_plane() const; - const util::XYZ &get_xyz() const; + const AnimStep &back() const; // (For testing): change the size limit. void set_size_limit(int32_t n); diff --git a/luprex/core/cpp/textgame.cpp b/luprex/core/cpp/textgame.cpp index f9741cb0..c6c1cf08 100644 --- a/luprex/core/cpp/textgame.cpp +++ b/luprex/core/cpp/textgame.cpp @@ -83,8 +83,8 @@ void TextGame::do_view_command(const StringVec &cmd) { } for (int64_t id : world_->get_near(1, 100, true)) { const Tangible *tan = world_->tangible_get(id); - const AnimQueue &aq = tan->anim_queue_; - std::cerr << id << ": " << aq.get_graphic() << " " << aq.get_plane() << " " << aq.get_xyz() << std::endl; + const AnimStep &aqback = tan->anim_queue_.back(); + std::cerr << id << ": " << aqback.graphic() << " " << aqback.plane() << " " << aqback.xyz() << std::endl; } } diff --git a/luprex/core/cpp/world.cpp b/luprex/core/cpp/world.cpp index 209f1f4b..e752cbb9 100644 --- a/luprex/core/cpp/world.cpp +++ b/luprex/core/cpp/world.cpp @@ -57,9 +57,8 @@ Tangible::Tangible(World *w, int64_t id) : world_(w), id_player_pool_(&w->id_glo } void Tangible::update_plane_item() { - util::XYZ xyz = anim_queue_.get_xyz(); - std::string plane = anim_queue_.get_plane(); - plane_item_.set_pos(plane, xyz.x, xyz.y, xyz.z); + const AnimStep &aqback = anim_queue_.back(); + plane_item_.set_pos(aqback.plane(), aqback.xyz().x, aqback.xyz().y, aqback.xyz().z); } void Tangible::serialize(StreamBuffer *sb) { @@ -164,13 +163,12 @@ std::vector World::get_near(int64_t player_id, float radius, bool exclu Tangible *player = tangible_get(player_id); // Find out where's the center of the world. - std::string plane = player->anim_queue_.get_plane(); - if (exclude_nowhere && (plane == "nowhere")) { + const AnimStep &aqback = player->anim_queue_.back(); + if (exclude_nowhere && (aqback.plane() == "nowhere")) { return std::vector(); } - util::XYZ xyz = player->anim_queue_.get_xyz(); - return plane_map_.scan_radius(plane, xyz.x, xyz.y, radius, player_id); + return plane_map_.scan_radius(aqback.plane(), aqback.xyz().x, aqback.xyz().y, radius, player_id); } Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) { @@ -446,36 +444,19 @@ void World::rollback() { deserialize(&snapshot_); } -LuaDefine(tangible_xyz, "c") { +LuaDefine(tangible_animstate, "c") { LuaArg tanobj; - LuaRet X, Y, Z; - LuaStack LS(L, tanobj, X, Y, Z); + LuaRet graphic, plane, x, y, z, facing; + LuaStack LS(L, tanobj, graphic, plane, x, y, z, facing); World *w = World::fetch_global_pointer(L); Tangible *tan = w->tangible_get(L, tanobj.index()); - util::XYZ xyz = tan->anim_queue_.get_xyz(); - LS.set(X, xyz.x); - LS.set(Y, xyz.y); - LS.set(Z, xyz.z); - return LS.result(); -} - -LuaDefine(tangible_plane, "c") { - LuaArg tanobj; - LuaRet plane; - LuaStack LS(L, tanobj, plane); - World *w = World::fetch_global_pointer(L); - Tangible *tan = w->tangible_get(L, tanobj.index()); - LS.set(plane, tan->anim_queue_.get_plane()); - return LS.result(); -} - -LuaDefine(tangible_graphic, "c") { - LuaArg tanobj; - LuaRet graphic; - LuaStack LS(L, tanobj, graphic); - World *w = World::fetch_global_pointer(L); - Tangible *tan = w->tangible_get(L, tanobj.index()); - LS.set(graphic, tan->anim_queue_.get_graphic()); + const AnimStep &aqback = tan->anim_queue_.back(); + LS.set(graphic, aqback.graphic()); + LS.set(plane, aqback.plane()); + LS.set(x, aqback.xyz().x); + LS.set(y, aqback.xyz().y); + LS.set(z, aqback.xyz().z); + LS.set(facing, aqback.facing()); return LS.result(); } @@ -516,6 +497,20 @@ LuaDefine(tangible_make, "c") { return 1; } +LuaDefine(tangible_get, "c") { + LuaArg id; + LuaVar tangibles; + LuaRet database; + LuaStack LS(L, id, tangibles, database); + int64_t nid = LS.ckinteger(id); + LS.rawget(tangibles, LuaRegistry, "tangibles"); + LS.rawget(database, tangibles, id); + if (!LS.istable(database)) { + luaL_error(L, "Not a tangible ID: %d", nid); + } + return LS.result(); +} + LuaDefine(world_wait, "f") { if ((lua_gettop(L) != 1) || (lua_type(L, -1) != LUA_TNUMBER)) { luaL_error(L, "Argument to wait must be a number.");