Refactor code for invoke_lua_source and world.init. Also, add compile_commands.json to luprex

This commit is contained in:
2025-06-16 19:58:26 -04:00
parent f150b14d30
commit 80ff7d7d92
14 changed files with 279 additions and 331 deletions

View File

@@ -436,9 +436,6 @@ void DrivenEngine::drv_get_animation_queues(uint32_t count, const int64_t *ids,
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void DrivenEngine::drv_initialize(uint32_t srcpklen, const char *srcpk, int argc, char **argv) {
event_init(std::string_view(srcpk, srcpklen), argc, argv);
}
void DrivenEngine::drv_clear_new_outgoing() {
new_outgoing_.clear();
@@ -569,7 +566,7 @@ static void drv_get_animation_queues(EngineWrapper *w, uint32_t count, const int
//////////////////////////////////////////////////////////////////////////////
static void play_initialize(EngineWrapper *w, uint32_t argc, char **argv, uint32_t srcpklen, const char *srcpk, const char *logfn) {
static void play_initialize(EngineWrapper *w, const char *engtype, const char *logfn) {
if (w->engine != nullptr) {
return reset_wrapper(w, "Cannot initialize wrapper, it's already initialized.");
}
@@ -590,63 +587,31 @@ static void play_initialize(EngineWrapper *w, uint32_t argc, char **argv, uint32
// If we have a logfile, then log this initialization.
if (w->wlog != nullptr) {
w->wlog->write_cmd_hash(PLAY_INITIALIZE, eng::memhash());
w->wlog->write_uint32(argc);
for (uint32_t i = 0; i < argc; i++) {
w->wlog->write_string(argv[i]);
}
w->wlog->write_string(std::string_view(srcpk, srcpklen));
w->wlog->write_string(engtype);
w->wlog->flush();
}
// Create the engine of the appropriate type.
if (argc < 1) {
std::ostringstream oss;
oss << "Must pass an engine type on the command line. Known types:\n";
for (auto reg = DrivenEngineReg::All; reg != nullptr; reg=reg->next) {
oss << " " << reg->name << std::endl;
}
std::string err = oss.str();
return reset_wrapper(w, err.c_str());
}
w->engine = make_engine(argv[0]);
w->engine = make_engine(engtype);
if (w->engine == nullptr) {
return reset_wrapper(w, "No such driven engine type: %s", argv[0]);
return reset_wrapper(w, "No such driven engine type: %s", engtype);
}
// Call the engine initialization sequence.
w->engine->drv_initialize(srcpklen, srcpk, argc - 1, argv + 1);
}
static void replay_initialize(EngineWrapper *w) {
assert(w->rlog != nullptr);
std::vector<std::string> argvstr;
uint32_t argc = w->rlog->read_uint32();
for (uint32_t i = 0; i < argc; i++) {
argvstr.push_back(w->rlog->read_string());
}
std::string srcpk = w->rlog->read_string();
std::string engtype = w->rlog->read_string();
if (!w->rlog->good()) {
return reset_wrapper(w, "replay log corrupt in replay_initialize");
}
// We need to convert the argument vector from an array
// of C++ strings into the canonical argc, argv format.
std::vector<char *> argvec;
for (uint32_t i = 0; i < argc; i++) {
argvec.push_back(&argvstr[i][0]);
}
char **argv = &argvec[0];
// Create the engine.
w->engine = make_engine(argv[0]);
w->engine = make_engine(engtype.c_str());
if (w->engine == nullptr) {
return reset_wrapper(w, "No such driven engine type: %s", argvstr[0]);
return reset_wrapper(w, "No such driven engine type: %s", engtype.c_str());
}
w->engine->drv_initialize(srcpk.size(), srcpk.c_str(), argc - 1, argv + 1);
}