Change how animstate is accessed

This commit is contained in:
2021-03-28 13:27:28 -04:00
parent 3e424f3fa6
commit f88fafc585
4 changed files with 34 additions and 52 deletions

View File

@@ -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") {

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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<int64_t> 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<int64_t>();
}
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.");