Redesign of animation queue for unreal, add get_tangibles_near to drivenengine

This commit is contained in:
2023-07-24 17:19:25 -04:00
parent 4da86e6f89
commit 87aa47b96d
19 changed files with 1406 additions and 980 deletions

View File

@@ -3,18 +3,37 @@
#include "json.hpp"
#include <cassert>
void World::tangible_walkto(int64_t id, int64_t animid, float x, float y) {
void World::tangible_clear_anim_queue_to_empty(int64_t id) {
Tangible *t = tangible_get(id);
assert(animid != 0);
assert(t != nullptr);
AnimStep step;
step.set_action("walkto");
step.set_x(x);
step.set_y(y);
t->anim_queue_.add(animid, step);
AnimState state;
t->anim_queue_.clear(state);
t->update_plane_item();
}
void World::tangible_clear_plane_and_xyz(int64_t id, const eng::string &plane, const util::DXYZ &xyz) {
Tangible *t = tangible_get(id);
assert(t != nullptr);
AnimState state;
state.set_string("plane", plane);
state.set_xyz("xyz", xyz);
state.set_persistent("plane");
state.set_persistent("xyz");
t->anim_queue_.clear(state);
t->update_plane_item();
}
void World::tangible_walkto(int64_t id, float x, float y) {
Tangible *t = tangible_get(id);
assert(t != nullptr);
AnimState state = t->anim_queue_.get_final_persistent();
state.set_string("action", "walkto");
state.set_xyz("xyz", util::DXYZ(x,y,0.0));
t->anim_queue_.add(state);
}
eng::string World::tangible_anim_debug_string(int64_t id) const {
const Tangible *t = tangible_get(id);
if (t == 0) return "no such tangible";
@@ -40,10 +59,12 @@ eng::string World::tangible_ids_debug_string() const {
eng::string World::tangibles_near_debug_string(int64_t actor, int64_t distance) {
eng::ostringstream result;
for (int64_t id : get_near(actor, distance, true, false, true)) {
util::IdVector tans;
get_near(actor, distance, true, false, true, &tans);
for (int64_t id : tans) {
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;
AnimState state = tan->anim_queue_.get_final_everything();
result << id << ": " << state.debug_string() << std::endl;
}
return result.str();
}
@@ -267,53 +288,35 @@ LuaDefine(unittests_world1animdiff, "", "some unit tests") {
util::IdVector ids = util::id_vector_create(123, 345);
// Create some tangibles, and add some animations.
m->tangible_make(123, "somewhere");
m->tangible_make(345, "somewhere");
m->tangible_walkto(123, 770, 3, 4);
m->tangible_walkto(345, 771, 6, 2);
m->tangible_make(123);
m->tangible_make(345);
m->tangible_clear_anim_queue_to_empty(123);
m->tangible_clear_anim_queue_to_empty(345);
m->tangible_walkto(123, 3, 4);
m->tangible_walkto(345, 6, 2);
LuaAssertStrEq(L, m->tangible_ids_debug_string(), "123,345");
LuaAssertStrEq(L, m->tangible_anim_debug_string(123),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=770 action=walkto x=3 y=4; ");
LuaAssertStrEq(L, m->tangible_anim_debug_string(345),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=771 action=walkto x=6 y=2; ");
LuaAssertStrEq(L, m->tangible_anim_debug_string(123), "[empty]; action:walkto xyz:3,4,0");
LuaAssertStrEq(L, m->tangible_anim_debug_string(345), "[empty]; action:walkto xyz:6,2,0");
// Now difference transmit all that to the client.
ss->diff_visible(ids, m.get(), &sb);
cs->patch_visible(&sb, nullptr);
LuaAssertStrEq(L, ss->tangible_ids_debug_string(), "123,345");
LuaAssertStrEq(L, ss->tangible_anim_debug_string(123),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=770 action=walkto x=3 y=4; ");
LuaAssertStrEq(L, ss->tangible_anim_debug_string(345),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=771 action=walkto x=6 y=2; ");
LuaAssertStrEq(L, ss->tangible_anim_debug_string(123), "[empty]; action:walkto xyz:3,4,0");
LuaAssertStrEq(L, ss->tangible_anim_debug_string(345), "[empty]; action:walkto xyz:6,2,0");
LuaAssert(L, worlds_identical(ss, cs));
// Now add some more animation records to the master.
m->tangible_walkto(123, 772, 7, 3);
m->tangible_walkto(345, 773, 2, 5);
LuaAssertStrEq(L, m->tangible_anim_debug_string(123),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=770 action=walkto x=3 y=4; "
"id=772 action=walkto x=7 y=3; ");
LuaAssertStrEq(L, m->tangible_anim_debug_string(345),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=771 action=walkto x=6 y=2; "
"id=773 action=walkto x=2 y=5; ");
m->tangible_walkto(123, 7, 3);
m->tangible_walkto(345, 2, 5);
LuaAssertStrEq(L, m->tangible_anim_debug_string(123), "[empty]; action:walkto xyz:3,4,0; action:walkto xyz:7,3,0");
LuaAssertStrEq(L, m->tangible_anim_debug_string(345), "[empty]; action:walkto xyz:6,2,0; action:walkto xyz:2,5,0");
// Now difference transmit all that to the client again.
ss->diff_visible(ids, m.get(), &sb);
cs->patch_visible(&sb, nullptr);
LuaAssertStrEq(L, ss->tangible_anim_debug_string(123),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=770 action=walkto x=3 y=4; "
"id=772 action=walkto x=7 y=3; ");
LuaAssertStrEq(L, ss->tangible_anim_debug_string(345),
"id=0 action= plane=somewhere x=0 y=0 z=0 facing=0 graphic=; "
"id=771 action=walkto x=6 y=2; "
"id=773 action=walkto x=2 y=5; ");
LuaAssertStrEq(L, ss->tangible_anim_debug_string(123), "[empty]; action:walkto xyz:3,4,0; action:walkto xyz:7,3,0");
LuaAssertStrEq(L, ss->tangible_anim_debug_string(345), "[empty]; action:walkto xyz:6,2,0; action:walkto xyz:2,5,0");
LuaAssert(L, worlds_identical(ss, cs));
// Delete tangible 345.
@@ -337,7 +340,7 @@ LuaDefine(unittests_world2pairtab, "", "some unit tests") {
// Create a master model containing some general tables, and
// some specialty tables (not numberable).
m->tangible_make(123, "somewhere");
m->tangible_make(123);
m->tangible_set_string(123, "inventory.TID", "inventory");
m->tangible_set_string(123, "transactions.TID", "transactions");
m->tangible_set_string(123, "skills.TID", "skills");
@@ -348,7 +351,7 @@ LuaDefine(unittests_world2pairtab, "", "some unit tests") {
// Now we're going to create a synchronous model that's similar to, but not
// exactly the same as that master model.
ss->tangible_make(123, "somewhere");
ss->tangible_make(123);
ss->tangible_set_string(123, "inventory.TID", "inventory");
ss->tangible_set_string(123, "skills.TID", "skills");
ss->tangible_set_string(123, "skills.crap.TID", "skills.crap");
@@ -384,13 +387,20 @@ LuaDefine(unittests_world3diffluatab, "", "some unit tests") {
StreamBuffer sb;
// Initialize all three models so that a tangible exists.
m->tangible_make(123, "somewhere");
ss->tangible_make(123, "somewhere");
cs->tangible_make(123, "somewhere");
m->tangible_make(345, "somewhere");
ss->tangible_make(345, "somewhere");
cs->tangible_make(345, "somewhere");
m->tangible_make(123);
ss->tangible_make(123);
cs->tangible_make(123);
m->tangible_make(345);
ss->tangible_make(345);
cs->tangible_make(345);
m->tangible_clear_plane_and_xyz(123, "earth", util::DXYZ(0,0,0));
ss->tangible_clear_plane_and_xyz(123, "earth", util::DXYZ(0,0,0));
cs->tangible_clear_plane_and_xyz(123, "earth", util::DXYZ(0,0,0));
m->tangible_clear_plane_and_xyz(345, "earth", util::DXYZ(0,0,0));
ss->tangible_clear_plane_and_xyz(345, "earth", util::DXYZ(0,0,0));
cs->tangible_clear_plane_and_xyz(345, "earth", util::DXYZ(0,0,0));
// Put some data into the master model.
m->tangible_set_string(123, "bacon", "crispy");
m->tangible_set_string(123, "inventory.gold", "wealthy");
@@ -438,9 +448,9 @@ LuaDefine(unittests_world4difftanclass, "", "some unit tests") {
StreamBuffer sb;
// Initialize all three models so that a tangible exists.
m->tangible_make(123, "somewhere");
ss->tangible_make(123, "somewhere");
cs->tangible_make(123, "somewhere");
m->tangible_make(123);
ss->tangible_make(123);
cs->tangible_make(123);
// Change the lua class of the tangible.
m->tangible_set_class(123, "chicken");