Refactor to remove dependency of DrivenEngine on World

This commit is contained in:
2026-02-24 22:36:01 -05:00
parent 8889a36ba3
commit a7027873ab
10 changed files with 194 additions and 92 deletions

View File

@@ -1,5 +1,6 @@
#include "world.hpp"
#include "enginewrapper.hpp"
#include "idalloc.hpp"
#include "animqueue.hpp"
#include "traceback.hpp"
@@ -301,18 +302,6 @@ void World::get_near(int64_t player_id, float radius, bool exclude_nowhere, bool
get_near(scan, into);
}
void World::get_encoded_animation_queues(uint32_t count, const int64_t *ids, util::SharedStdStringVec &into) {
into.resize(count);
for (int i = 0; i < int(count); i++) {
Tangible *tan = tangible_get(ids[i]);
if (tan == nullptr) {
into[i] = AnimQueue::get_encoded_blank_queue();
} else {
into[i] = tan->anim_queue_.get_encoded_queue();
}
}
}
World::Redirects World::fetch_redirects() {
World::Redirects result = std::move(redirects_);
redirects_.clear();
@@ -1293,3 +1282,51 @@ void engine_initialization() {
}
static DrivenEngineInitializerReg eireg(engine_initialization);
//////////////////////////////////////////////////////////////////////////////
//
// Functions that allow the Driver to Peer Directly into the World.
//
//////////////////////////////////////////////////////////////////////////////
void World::get_animation_queues(uint32_t count, const int64_t *ids, uint32_t *lengths, const char **strings) {
wrapper_anim_queues_.resize(count);
for (int i = 0; i < int(count); i++) {
Tangible *tan = tangible_get(ids[i]);
if (tan == nullptr) {
wrapper_anim_queues_[i] = AnimQueue::get_encoded_blank_queue();
} else {
wrapper_anim_queues_[i] = tan->anim_queue_.get_encoded_queue();
}
lengths[i] = wrapper_anim_queues_[i]->size();
strings[i] = wrapper_anim_queues_[i]->c_str();
}
}
void World::get_tangibles_near(uint64_t tanid, double rx, double ry, double rz, uint32_t *count, int64_t **ids) {
uint32_t hash1 = eng::memhash();
wrapper_scan_result_.clear();
if (tanid != 0) {
PlaneScan scan;
scan.set_near(tanid, true);
scan.set_omit_nowhere(true);
scan.set_sorted(false);
scan.set_radius(util::XYZ(rx, ry, rz));
scan.set_shape(PlaneScan::CYLINDER);
get_near(scan, &wrapper_scan_result_);
}
*count = wrapper_scan_result_.size();
*ids = &wrapper_scan_result_[0];
uint32_t hash2 = eng::memhash();
assert(hash1 == hash2);
}
void World::expose_world_to_driver(EngineWrapper *w) {
w->world = this;
w->get_tangibles_near = [](EngineWrapper *w, uint64_t tanid, double rx, double ry, double rz, uint32_t *count, int64_t **ids) {
w->world->get_tangibles_near(tanid, rx, ry, rz, count, ids);
};
w->get_animation_queues = [](EngineWrapper *w, uint32_t count, const int64_t *ids, uint32_t *lengths, const char **strings) {
w->world->get_animation_queues(count, ids, lengths, strings);
};
}