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

@@ -2,7 +2,7 @@
#include "wrap-vector.hpp"
#include "util.hpp"
#include "drivenengine.hpp"
#include "world.hpp"
#include "animqueue.hpp"
#include "base-buffer.hpp"
#include <string_view>
@@ -56,10 +56,10 @@ Channel *DrivenEngine::get_chid(int chid) const {
return channels_[chid].get();
}
static DrivenEngine *make_engine(std::string_view kind) {
static DrivenEngine *make_engine(std::string_view kind, EngineWrapper *w) {
for (auto reg = DrivenEngineReg::All; reg != nullptr; reg=reg->next) {
if (kind == reg->name) {
UniqueDrivenEngine result = reg->maker();
UniqueDrivenEngine result = reg->maker(w);
return result.release();
}
}
@@ -386,43 +386,6 @@ int64_t DrivenEngine::drv_get_actor_id() const {
return actor_id_;
}
void DrivenEngine::drv_get_tangibles_near(int64_t tanid, double rx, double ry, double rz, uint32_t *count, int64_t **ids) {
uint32_t hash1 = eng::memhash();
scan_result_.clear();
if (world_ && (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);
world_->get_near(scan, &scan_result_);
}
*count = scan_result_.size();
if (*count > 0) {
*ids = &scan_result_[0];
} else {
*ids = nullptr;
}
uint32_t hash2 = eng::memhash();
assert(hash1 == hash2);
}
void DrivenEngine::drv_get_animation_queues(uint32_t count, const int64_t *ids, uint32_t *lengths, const char **strings) {
anim_queues_.resize(count);
if (!world_) {
for (int i = 0; i < int(count); i++) {
anim_queues_[i] = AnimQueue::get_encoded_blank_queue();
}
} else {
world_->get_encoded_animation_queues(count, ids, anim_queues_);
}
for (int i = 0; i < int(count); i++) {
lengths[i] = anim_queues_[i]->size();
strings[i] = anim_queues_[i]->c_str();
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
@@ -541,13 +504,6 @@ static uint64_t drv_get_actor_id(EngineWrapper *w) {
return w->engine->drv_get_actor_id();
}
static void drv_get_tangibles_near(EngineWrapper *w, uint64_t tanid, double rx, double ry, double rz, uint32_t *count, int64_t **ids) {
return w->engine->drv_get_tangibles_near(tanid, rx, ry, rz, count, ids);
}
static void drv_get_animation_queues(EngineWrapper *w, uint32_t count, const int64_t *ids, uint32_t *lengths, const char **strings) {
return w->engine->drv_get_animation_queues(count, ids, lengths, strings);
}
//////////////////////////////////////////////////////////////////////////////
@@ -588,7 +544,7 @@ static void play_initialize(EngineWrapper *w, const char *engtype, const char *l
}
// Create the engine of the appropriate type.
w->engine = make_engine(engtype);
w->engine = make_engine(engtype, w);
if (w->engine == nullptr) {
return reset_wrapper(w, "No such driven engine type: %s", engtype);
}
@@ -604,7 +560,7 @@ static void replay_initialize(EngineWrapper *w) {
}
// Create the engine.
w->engine = make_engine(engtype.c_str());
w->engine = make_engine(engtype.c_str(), w);
if (w->engine == nullptr) {
return reset_wrapper(w, "No such driven engine type: %s", engtype.c_str());
}
@@ -888,6 +844,27 @@ static void replaycore_step(EngineWrapper *w) {
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static int64_t empty_id_list_ = 0;
static void default_get_tangibles_near(EngineWrapper *, uint64_t, double, double, double, uint32_t *count, int64_t **ids) {
*count = 0;
*ids = &empty_id_list_;
}
static void default_get_animation_queues(EngineWrapper *, uint32_t count, const int64_t *, uint32_t *lengths, const char **strings) {
util::SharedStdString blank = AnimQueue::get_encoded_blank_queue();
for (int i = 0; i < int(count); i++) {
lengths[i] = blank->size();
strings[i] = blank->c_str();
}
}
void DrivenEngine::unexpose_world_to_driver(EngineWrapper *w) {
w->world = nullptr;
w->get_tangibles_near = default_get_tangibles_near;
w->get_animation_queues = default_get_animation_queues;
}
static void init_engine_wrapper_helper(EngineWrapper *w) {
static bool called_initializer;
assert(DrivenEngineInitializerReg::func != nullptr);
@@ -909,9 +886,9 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
w->get_rescan_lua_source = drv_get_rescan_lua_source;
w->get_stop_driver = drv_get_stop_driver;
w->get_actor_id = drv_get_actor_id;
w->get_tangibles_near = drv_get_tangibles_near;
w->get_animation_queues = drv_get_animation_queues;
w->get_tangibles_near = default_get_tangibles_near;
w->get_animation_queues = default_get_animation_queues;
w->play_initialize = play_initialize;
w->play_clear_new_outgoing = play_clear_new_outgoing;
w->play_sent_outgoing = play_sent_outgoing;