Redesign of animation queue for unreal, add get_tangibles_near to drivenengine
This commit is contained in:
@@ -77,14 +77,14 @@ World::World(WorldType wt) {
|
||||
assign_seqno_ = 1;
|
||||
}
|
||||
|
||||
Tangible::Tangible(World *w, int64_t id) : world_(w), anim_queue_(w->world_type_), id_player_pool_(&w->id_global_pool_) {
|
||||
Tangible::Tangible(World *w, int64_t id) : world_(w), anim_queue_(), id_player_pool_(&w->id_global_pool_) {
|
||||
plane_item_.set_id(id);
|
||||
plane_item_.track(&w->plane_map_);
|
||||
}
|
||||
|
||||
void Tangible::update_plane_item() {
|
||||
const AnimStep &aqback = anim_queue_.back();
|
||||
plane_item_.set_pos(aqback.plane(), aqback.xyz().x, aqback.xyz().y, aqback.xyz().z);
|
||||
AnimCoreState pos = anim_queue_.get_final_core_state();
|
||||
plane_item_.set_pos(pos.plane, pos.xyz.x, pos.xyz.y, pos.xyz.z);
|
||||
}
|
||||
|
||||
void Tangible::serialize(StreamBuffer *sb) {
|
||||
@@ -140,7 +140,7 @@ Tangible *World::tangible_get(const LuaCoreStack &LS, LuaSlot tab, bool allowdel
|
||||
return result;
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_t id, const eng::string &plane) {
|
||||
Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_t id) {
|
||||
assert(id != 0);
|
||||
LuaVar metatab;
|
||||
LuaExtStack LS(LS0.state(), metatab);
|
||||
@@ -150,8 +150,10 @@ Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_
|
||||
assert (t == nullptr);
|
||||
t.reset(new Tangible(this, id));
|
||||
|
||||
// Set up initial animation state.
|
||||
t->anim_queue_.clear(plane);
|
||||
// AnimQueue initializes itself to a valid default state.
|
||||
AnimState state;
|
||||
state.add_defaults(nullptr);
|
||||
t->anim_queue_.clear(state);
|
||||
t->update_plane_item();
|
||||
|
||||
// Fetch the tangible's Lua database and metatable.
|
||||
@@ -165,10 +167,10 @@ Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_
|
||||
return t.get();
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(int64_t id, const eng::string &plane) {
|
||||
Tangible *World::tangible_make(int64_t id) {
|
||||
LuaVar database;
|
||||
LuaExtStack LS(state(), database);
|
||||
return tangible_make(LS, database, id, plane);
|
||||
return tangible_make(LS, database, id);
|
||||
}
|
||||
|
||||
void World::tangible_delete(int64_t id) {
|
||||
@@ -199,23 +201,33 @@ void World::tangible_delete(int64_t id) {
|
||||
tangibles_.erase(iter);
|
||||
}
|
||||
|
||||
util::IdVector World::get_near(int64_t player_id, float radius, bool exclude_nowhere, bool omit_player, bool sorted) const {
|
||||
const Tangible *player = tangible_get(player_id);
|
||||
if (player == nullptr) {
|
||||
return IdVector();
|
||||
void World::get_near(PlaneScan &scan, util::IdVector *into) const {
|
||||
uint32_t hash1 = eng::memhash();
|
||||
into->clear();
|
||||
// If 'near' is set, update the plane and center.
|
||||
int64_t actor_id = scan.near();
|
||||
if (actor_id != 0) {
|
||||
const Tangible *player = tangible_get(actor_id);
|
||||
if (player == nullptr) {
|
||||
return;
|
||||
}
|
||||
const PlaneItem &pi = player->plane_item_;
|
||||
scan.set_plane(pi.plane());
|
||||
scan.set_center(util::XYZ(pi.x(), pi.y(), pi.z()));
|
||||
}
|
||||
plane_map_.scan(scan, into);
|
||||
uint32_t hash2 = eng::memhash();
|
||||
assert(hash1 == hash2);
|
||||
}
|
||||
|
||||
// Find out where the player is.
|
||||
const AnimStep &aqback = player->anim_queue_.back();
|
||||
|
||||
void World::get_near(int64_t player_id, float radius, bool exclude_nowhere, bool omit_player, bool sorted, util::IdVector *into) const {
|
||||
PlaneScan scan;
|
||||
scan.set_plane(aqback.plane());
|
||||
scan.set_bbox_given_center_radius(aqback.xyz(), radius);
|
||||
scan.set_radius(radius);
|
||||
scan.set_shape(PlaneScan::SPHERE);
|
||||
scan.set_sorted(sorted);
|
||||
scan.set_omit_nowhere(exclude_nowhere);
|
||||
scan.set_near(player_id, !omit_player);
|
||||
return plane_map_.scan(scan);
|
||||
get_near(scan, into);
|
||||
}
|
||||
|
||||
World::Redirects World::fetch_redirects() {
|
||||
@@ -229,7 +241,7 @@ int64_t World::create_login_actor() {
|
||||
int64_t id = id_global_pool_.get_one();
|
||||
LuaVar database, classtab, mt;
|
||||
LuaExtStack LS(state(), database, classtab, mt);
|
||||
Tangible *tan = tangible_make(LS, database, id, "nowhere");
|
||||
Tangible *tan = tangible_make(LS, database, id);
|
||||
LS.makeclass(classtab, "login");
|
||||
LS.getmetatable(mt, database);
|
||||
LS.rawset(mt, "__index", classtab);
|
||||
|
||||
Reference in New Issue
Block a user