World model is now operational

This commit is contained in:
2021-01-16 01:24:33 -05:00
parent d7d633bd96
commit 313e78067a
11 changed files with 313 additions and 188 deletions

View File

@@ -1,5 +1,6 @@
#include "animqueue.hpp"
#include "luastack.hpp"
#include <limits>
@@ -16,7 +17,7 @@ AnimQueue::AnimQueue(int size_limit) {
init.xyz_ = util::XYZ(0,0,0);
init.graphic_ = "nothing";
init.plane_ = "nowhere";
init.bits_ = 0;
init.bits_ = AnimStep::HAS_EVERYTHING;
}
void AnimQueue::add(int64_t id, const std::string &action) {
@@ -33,7 +34,7 @@ void AnimQueue::add(int64_t id, const std::string &action) {
AnimStep &init = steps_.front();
init.id_ = 0;
init.action_ = "";
init.bits_ = 0;
init.bits_ = AnimStep::HAS_EVERYTHING;
}
void AnimQueue::set_facing(float f) {
@@ -59,3 +60,64 @@ void AnimQueue::set_plane(const std::string &p) {
last.bits_ |= AnimStep::HAS_PLANE;
last.plane_ = p;
}
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_;
}
LuaDefine(unittests_animqueue, "c") {
// Check initial state.
AnimQueue aq(3);
LuaAssert(L, aq.size() == 1);
const AnimStep *st = &aq.nth(0);
LuaAssert(L, st->id() == 0);
LuaAssert(L, st->action() == "");
LuaAssert(L, st->bits() == AnimStep::HAS_EVERYTHING);
LuaAssert(L, st->facing() == 0.0);
LuaAssert(L, st->xyz() == util::XYZ(0,0,0));
LuaAssert(L, st->graphic() == "nothing");
LuaAssert(L, st->plane() == "nowhere");
// Add a step.
aq.add(12345, "walk");
LuaAssert(L, aq.size() == 2);
st = &aq.nth(1);
LuaAssert(L, st->id() == 12345);
LuaAssert(L, st->action() == "walk");
LuaAssert(L, st->bits() == 0);
LuaAssert(L, st->facing() == 0.0);
LuaAssert(L, st->xyz() == util::XYZ(0,0,0));
LuaAssert(L, st->graphic() == "nothing");
LuaAssert(L, st->plane() == "nowhere");
// Test the setters.
aq.set_facing(180);
LuaAssert(L, st->facing() == 180);
LuaAssert(L, st->bits() == AnimStep::HAS_FACING);
aq.set_xyz(util::XYZ(3,4,5));
LuaAssert(L, st->xyz() == util::XYZ(3, 4, 5));
LuaAssert(L, st->bits() == (AnimStep::HAS_FACING | AnimStep::HAS_XYZ));
aq.set_plane("somewhere");
LuaAssert(L, st->plane() == "somewhere");
LuaAssert(L, st->bits() == (AnimStep::HAS_FACING | AnimStep::HAS_XYZ | AnimStep::HAS_PLANE));
aq.set_graphic("something");
LuaAssert(L, st->graphic() == "something");
LuaAssert(L, st->bits() == (AnimStep::HAS_FACING | AnimStep::HAS_XYZ | AnimStep::HAS_PLANE | AnimStep::HAS_GRAPHIC));
// Exceed the length limit, dropping first element.
aq.add(12346, "walk");
aq.add(12347, "walk");
LuaAssert(L, aq.size() == 3);
LuaAssert(L, aq.nth(0).id() == 0);
LuaAssert(L, aq.nth(0).action() == "");
LuaAssert(L, aq.nth(0).bits() == AnimStep::HAS_EVERYTHING);
LuaAssert(L, aq.nth(1).id() == 12346);
LuaAssert(L, aq.nth(2).id() == 12347);
return 0;
}