Add calculation of close-tangibles
This commit is contained in:
@@ -185,7 +185,7 @@ std::string World::tangible_ids_debug_string() const {
|
||||
}
|
||||
|
||||
|
||||
util::IdVector World::get_near(int64_t player_id, float radius, bool exclude_nowhere) const {
|
||||
util::IdVector World::get_near_unsorted(int64_t player_id, float radius, bool exclude_nowhere) const {
|
||||
const Tangible *player = tangible_get(player_id);
|
||||
if (player == nullptr) {
|
||||
return IdVector();
|
||||
@@ -200,6 +200,12 @@ util::IdVector World::get_near(int64_t player_id, float radius, bool exclude_now
|
||||
return plane_map_.scan_radius(aqback.plane(), aqback.xyz().x, aqback.xyz().y, radius, player_id);
|
||||
}
|
||||
|
||||
util::IdVector World::get_near(int64_t player_id, float radius, bool exclude_nowhere) const {
|
||||
util::IdVector v = get_near_unsorted(player_id, radius, exclude_nowhere);
|
||||
std::sort(v.begin(), v.end());
|
||||
return v;
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(lua_State *L, int64_t id, bool pushdb) {
|
||||
// Get a state if we don't already have one.
|
||||
if (L == nullptr) {
|
||||
@@ -550,8 +556,8 @@ void World::difference_transmit(int64_t actor_id, const World *master, StreamBuf
|
||||
// Get the list of tangibles visible in either model.
|
||||
// Some tangibles may be missing in the master, some may be missing in the sync.
|
||||
util::IdVector visible = util::sort_union_id_vectors(
|
||||
master->get_near(actor_id, 100.0, true),
|
||||
this->get_near(actor_id, 100.0, true));
|
||||
master->get_near_unsorted(actor_id, RadiusVisibility, true),
|
||||
get_near_unsorted(actor_id, RadiusVisibility, true));
|
||||
TanVector m_visible = master->tangible_get_all(visible);
|
||||
TanVector s_visible = tangible_get_all(visible);
|
||||
assert(m_visible.size() == s_visible.size());
|
||||
@@ -575,12 +581,24 @@ void World::difference_transmit(int64_t actor_id, const World *master, StreamBuf
|
||||
}
|
||||
}
|
||||
|
||||
// Obtain the list of tangibles whose tables we're going to transmit.
|
||||
util::IdVector closetans = get_near(actor_id, RadiusClose, true);
|
||||
assert(closetans == master->get_near(actor_id, RadiusClose, true));
|
||||
util::HashValue closehash = util::hash_id_vector(closetans);
|
||||
|
||||
// Confirm the close tangibles with the client.
|
||||
sb->write_hashvalue(closehash);
|
||||
|
||||
assert(tsb.at_eof());
|
||||
}
|
||||
|
||||
void World::apply_differences(StreamBuffer *sb) {
|
||||
patch_actor_essentials(sb);
|
||||
int64_t actor_id = patch_actor_essentials(sb);
|
||||
patch_visible_animations(sb);
|
||||
util::IdVector closetans = get_near(actor_id, RadiusClose, true);
|
||||
util::HashValue closehash = util::hash_id_vector(closetans);
|
||||
util::HashValue m_closehash = sb->read_hashvalue();
|
||||
assert(closehash == m_closehash);
|
||||
}
|
||||
|
||||
void World::diff_actor_essentials(const Tangible *m_actor, const Tangible *s_actor, StreamBuffer *sb) {
|
||||
@@ -594,7 +612,7 @@ void World::diff_actor_essentials(const Tangible *m_actor, const Tangible *s_act
|
||||
}
|
||||
}
|
||||
|
||||
void World::patch_actor_essentials(StreamBuffer *sb) {
|
||||
int64_t World::patch_actor_essentials(StreamBuffer *sb) {
|
||||
int64_t actor_id = sb->read_int64();
|
||||
Tangible *s_actor = tangible_get(actor_id);
|
||||
if (s_actor == nullptr) {
|
||||
@@ -606,6 +624,7 @@ void World::patch_actor_essentials(StreamBuffer *sb) {
|
||||
s_actor->anim_queue_.patch(sb);
|
||||
}
|
||||
s_actor->update_plane_item();
|
||||
return actor_id;
|
||||
}
|
||||
|
||||
void World::diff_visible_animations(const TanVector &mvis, const TanVector &svis, StreamBuffer *sb) {
|
||||
|
||||
Reference in New Issue
Block a user