Change the way the lua engine initialization functions are called
This commit is contained in:
@@ -21,13 +21,6 @@ DrivenEngineReg::DrivenEngineReg(const char *n, DrivenEngineMaker fn) {
|
||||
All = this;
|
||||
}
|
||||
|
||||
DrivenEngineInitializer DrivenEngineInitializerReg::func;
|
||||
|
||||
DrivenEngineInitializerReg::DrivenEngineInitializerReg(DrivenEngineInitializer fn) {
|
||||
assert(func == nullptr);
|
||||
func = fn;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -443,69 +436,6 @@ void DrivenEngine::drv_access(AccessKind kind, int64_t place, uint32_t datapklen
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// C Wrappers: Getters
|
||||
//
|
||||
// These wrappers make it possible to call the drv_get routines using C
|
||||
// functions instead of methods. This is important if the engine is compiled
|
||||
// with one C++ compiler, but the driver is compiled with a different C++
|
||||
// compiler.
|
||||
//
|
||||
// Some of these take parameter 'EngineWrapper', some take 'EngineWrapper',
|
||||
// and some come in two versions. This all depends on whether they are used
|
||||
// during play, during replay, or both.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void drv_get_listen_ports(EngineWrapper *w, uint32_t *nports, const uint32_t **ports) {
|
||||
return w->engine->drv_get_listen_ports(nports, ports);
|
||||
}
|
||||
|
||||
static void drv_get_new_outgoing(EngineWrapper *w, uint32_t *nchanids, const uint32_t **chanids) {
|
||||
return w->engine->drv_get_new_outgoing(nchanids, chanids);
|
||||
}
|
||||
|
||||
static const char *drv_get_target(EngineWrapper *w, uint32_t chid) {
|
||||
return w->engine->drv_get_target(chid);
|
||||
}
|
||||
|
||||
static bool drv_get_channel_released(EngineWrapper *w, uint32_t chid) {
|
||||
return w->engine->drv_get_channel_released(chid);
|
||||
}
|
||||
|
||||
static void drv_get_outgoing(EngineWrapper *w, uint32_t chid, uint32_t *len, const char **data) {
|
||||
return w->engine->drv_get_outgoing(chid, len, data);
|
||||
}
|
||||
|
||||
static bool drv_get_outgoing_empty(EngineWrapper *w, uint32_t chid) {
|
||||
return w->engine->drv_get_outgoing_empty(chid);
|
||||
}
|
||||
|
||||
static double drv_get_clock(EngineWrapper *w) {
|
||||
return w->engine->drv_get_clock();
|
||||
}
|
||||
|
||||
static bool drv_get_have_prints(EngineWrapper *w) {
|
||||
return w->engine->drv_get_have_prints();
|
||||
}
|
||||
|
||||
static bool drv_get_rescan_lua_source(EngineWrapper *w) {
|
||||
return w->engine->drv_get_rescan_lua_source();
|
||||
}
|
||||
|
||||
static bool drv_get_stop_driver(EngineWrapper *w) {
|
||||
return w->engine->drv_get_stop_driver();
|
||||
}
|
||||
|
||||
static uint64_t drv_get_actor_id(EngineWrapper *w) {
|
||||
return w->engine->drv_get_actor_id();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@@ -846,47 +776,58 @@ 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) {
|
||||
for (int i = 0; i < int(count); i++) {
|
||||
lengths[i] = 0;
|
||||
strings[i] = "";
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
w->get_tangibles_near = [](EngineWrapper *, uint64_t, double, double, double, uint32_t *count, int64_t **ids) {
|
||||
*count = 0;
|
||||
*ids = &empty_id_list_;
|
||||
};
|
||||
w->get_animation_queues = [](EngineWrapper *, uint32_t count, const int64_t *, uint32_t *lengths, const char **strings) {
|
||||
for (int i = 0; i < int(count); i++) {
|
||||
lengths[i] = 0;
|
||||
strings[i] = "";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
static void init_engine_wrapper_helper(EngineWrapper *w) {
|
||||
static bool called_initializer;
|
||||
assert(DrivenEngineInitializerReg::func != nullptr);
|
||||
if (!called_initializer) {
|
||||
DrivenEngineInitializerReg::func();
|
||||
called_initializer = true;
|
||||
}
|
||||
|
||||
void DrivenEngine::init_engine_wrapper(EngineWrapper *w) {
|
||||
memset(w, 0, sizeof(EngineWrapper));
|
||||
|
||||
w->get_listen_ports = drv_get_listen_ports;
|
||||
w->get_new_outgoing = drv_get_new_outgoing;
|
||||
w->get_target = drv_get_target;
|
||||
w->get_channel_released = drv_get_channel_released;
|
||||
w->get_outgoing = drv_get_outgoing;
|
||||
w->get_outgoing_empty = drv_get_outgoing_empty;
|
||||
w->get_clock = drv_get_clock;
|
||||
w->get_have_prints = drv_get_have_prints;
|
||||
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 = default_get_tangibles_near;
|
||||
w->get_animation_queues = default_get_animation_queues;
|
||||
w->get_listen_ports = [](EngineWrapper *w, uint32_t *nports, const uint32_t **ports) {
|
||||
w->engine->drv_get_listen_ports(nports, ports);
|
||||
};
|
||||
w->get_new_outgoing = [](EngineWrapper *w, uint32_t *nchanids, const uint32_t **chanids) {
|
||||
w->engine->drv_get_new_outgoing(nchanids, chanids);
|
||||
};
|
||||
w->get_target = [](EngineWrapper *w, uint32_t chid) {
|
||||
return w->engine->drv_get_target(chid);
|
||||
};
|
||||
w->get_channel_released = [](EngineWrapper *w, uint32_t chid) {
|
||||
return w->engine->drv_get_channel_released(chid);
|
||||
};
|
||||
w->get_outgoing = [](EngineWrapper *w, uint32_t chid, uint32_t *len, const char **data) {
|
||||
w->engine->drv_get_outgoing(chid, len, data);
|
||||
};
|
||||
w->get_outgoing_empty = [](EngineWrapper *w, uint32_t chid) {
|
||||
return w->engine->drv_get_outgoing_empty(chid);
|
||||
};
|
||||
w->get_clock = [](EngineWrapper *w) {
|
||||
return w->engine->drv_get_clock();
|
||||
};
|
||||
w->get_have_prints = [](EngineWrapper *w) {
|
||||
return w->engine->drv_get_have_prints();
|
||||
};
|
||||
w->get_rescan_lua_source = [](EngineWrapper *w) {
|
||||
return w->engine->drv_get_rescan_lua_source();
|
||||
};
|
||||
w->get_stop_driver = [](EngineWrapper *w) {
|
||||
return w->engine->drv_get_stop_driver();
|
||||
};
|
||||
w->get_actor_id = [](EngineWrapper *w) {
|
||||
return w->engine->drv_get_actor_id();
|
||||
};
|
||||
|
||||
unexpose_world_to_driver(w);
|
||||
|
||||
w->play_initialize = play_initialize;
|
||||
w->play_clear_new_outgoing = play_clear_new_outgoing;
|
||||
@@ -902,7 +843,7 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
|
||||
|
||||
w->hook_dprint = util::hook_dprint;
|
||||
w->release = release;
|
||||
};
|
||||
}
|
||||
|
||||
#if defined(__linux__)
|
||||
#define DLLEXPORT __attribute__((visibility("default")))
|
||||
@@ -912,6 +853,7 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
|
||||
|
||||
extern "C" {
|
||||
DLLEXPORT void init_engine_wrapper(EngineWrapper *w) {
|
||||
init_engine_wrapper_helper(w);
|
||||
DrivenEngine::init_engine_wrapper(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user