Initial implementation of 'engio' finished

This commit is contained in:
2023-10-24 15:49:43 -04:00
parent 7f5744da2d
commit c0c360a3a7
8 changed files with 49 additions and 25 deletions

View File

@@ -486,8 +486,8 @@ void DrivenEngine::drv_call_event_update(double clock) {
event_update();
}
void DrivenEngine::drv_invoke_player(int64_t place, uint32_t datapklen, const char *datapk) {
Invocation *inv = new Invocation(Invocation::KIND_PLAYER, visible_actor_id_, place, std::string_view(datapk, datapklen));
void DrivenEngine::drv_invoke_engio(int64_t place, uint32_t datapklen, const char *datapk) {
Invocation *inv = new Invocation(Invocation::KIND_ENGIO, visible_actor_id_, place, std::string_view(datapk, datapklen));
queued_invocations_.emplace_back(inv);
}
@@ -826,7 +826,7 @@ static void replay_invoke_event_update(EngineWrapper *w) {
////////////////////////
void play_invoke_player(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk) {
void play_invoke_engio(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk) {
assert(w->rlog == nullptr);
if (w->wlog != nullptr) {
w->wlog->write_cmd_hash(PLAY_INVOKE_PLAYER, eng::memhash());
@@ -835,17 +835,17 @@ void play_invoke_player(EngineWrapper *w, int64_t place, uint32_t datapklen, con
w->wlog->flush();
}
w->engine->drv_invoke_player(place, datapklen, datapk);
w->engine->drv_invoke_engio(place, datapklen, datapk);
}
void replay_invoke_player(EngineWrapper *w) {
void replay_invoke_engio(EngineWrapper *w) {
int64_t place = w->rlog->read_int64();
std::string srcpack = w->rlog->read_string();
if (!w->rlog->good()) {
return reset_wrapper(w, "replay log corrupt in replay_invoke_player");
return reset_wrapper(w, "replay log corrupt in replay_invoke_engio");
}
w->engine->drv_invoke_player(place, srcpack.size(), srcpack.c_str());
w->engine->drv_invoke_engio(place, srcpack.size(), srcpack.c_str());
}
@@ -1029,7 +1029,7 @@ static void init_engine_wrapper_helper(EngineWrapper *w) {
w->play_notify_close = play_notify_close;
w->play_notify_accept = play_notify_accept;
w->play_invoke_event_update = play_invoke_event_update;
w->play_invoke_player = play_invoke_player;
w->play_invoke_engio = play_invoke_engio;
w->play_invoke_choose = play_invoke_choose;
w->play_invoke_lua_source = play_invoke_lua_source;

View File

@@ -293,7 +293,7 @@ public:
void drv_notify_close(uint32_t chid, uint32_t len, const char *data);
uint32_t drv_notify_accept(uint32_t port);
void drv_call_event_update(double clock);
void drv_invoke_player(int64_t place, uint32_t datapklen, const char *datapk);
void drv_invoke_engio(int64_t place, uint32_t datapklen, const char *datapk);
void drv_invoke_choose(int64_t place, uint32_t datapklen, const char *datapk);
void drv_invoke_lua_source(uint32_t srcpklen, const char *srcpk);

View File

@@ -197,12 +197,12 @@ struct EngineWrapper {
//
void (*play_invoke_event_update)(EngineWrapper *w, double clock);
// Send an invoke/KIND_PLAYER
// Send an invoke/KIND_ENGIO
//
// This is the main pathway for the graphics engine to control the player
// character.
//
void (*play_invoke_player)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk);
void (*play_invoke_engio)(EngineWrapper *w, int64_t place, uint32_t datapklen, const char *datapk);
// Send an invoke/KIND_CHOOSE
//

View File

@@ -48,7 +48,7 @@ public:
enum Kind {
KIND_INVALID,
KIND_CHOOSE,
KIND_PLAYER,
KIND_ENGIO,
KIND_LUA,
KIND_FLUSH_PRINTS,
KIND_TICK,

View File

@@ -141,11 +141,7 @@ public:
}
void do_work_command(const util::StringVec &words) {
int reps = 10000;
for (int i = 0; i < reps; i++) {
world_to_synchronous();
world_to_asynchronous();
}
// The 'work' command is a stub for sticking temporary debugging code in here.
}
void do_quit_command(const util::StringVec &words) {

View File

@@ -569,8 +569,8 @@ void World::invoke(const Invocation &inv) {
case Invocation::KIND_CHOOSE:
invoke_choose(inv.actor(), inv.place(), inv.datapack());
break;
case Invocation::KIND_PLAYER:
invoke_player(inv.actor(), inv.place(), inv.datapack());
case Invocation::KIND_ENGIO:
invoke_engio(inv.actor(), inv.place(), inv.datapack());
break;
case Invocation::KIND_LUA:
invoke_lua(inv.actor(), inv.place(), inv.datapack());
@@ -769,7 +769,7 @@ void World::invoke_choose(int64_t actor_id, int64_t place_id, std::string_view d
assert(stack_is_clear());
}
void World::invoke_player(int64_t actor_id, int64_t place_id, std::string_view datapack) {
void World::invoke_engio(int64_t actor_id, int64_t place_id, std::string_view datapack) {
assert(stack_is_clear());
// Get the actor and place. Make sure both exist.
@@ -793,7 +793,7 @@ void World::invoke_player(int64_t actor_id, int64_t place_id, std::string_view d
} catch (const StreamException &ex) {
return;
}
if (sv::is_lua_id(funcname)) {
if (!sv::is_lua_id(funcname)) {
return;
}
@@ -812,7 +812,7 @@ void World::invoke_player(int64_t actor_id, int64_t place_id, std::string_view d
}
// Get the closure (playerinvoke.funcname).
eng::string err = LS.getclass(playercb, "playerinvoke");
eng::string err = LS.getclass(playercb, "engio");
if ((!err.empty()) || (!LS.istable(playercb))) {
return;
}
@@ -829,7 +829,30 @@ void World::invoke_player(int64_t actor_id, int64_t place_id, std::string_view d
lua_pushvalue(L, place.index());
// Push any additional args from the datapack.
// TODO: IMPLEMENT ME.
try {
while (!datasb.empty()) {
SimpleDynamicTag type = datasb.read_simple_dynamic_tag();
switch (type) {
case SimpleDynamicTag::NUMBER: {
lua_pushnumber(L, datasb.read_double());
break;
}
case SimpleDynamicTag::BOOLEAN: {
lua_pushboolean(L, datasb.read_bool() ? 1:0);
break;
}
case SimpleDynamicTag::STRING: {
std::string_view s = datasb.read_string_view();
lua_pushlstring(L, s.data(), s.size());
break;
}
default: return;
}
nargs++;
}
} catch (const StreamException &exc) {
return;
}
// Transfer all arguments to the new thread.
lua_xmove(L, CO, nargs);

View File

@@ -355,7 +355,7 @@ private:
// Invoke a player method, used by the graphics engine to control the player.
//
void invoke_player(int64_t actor_id, int64_t place_id, std::string_view datapack);
void invoke_engio(int64_t actor_id, int64_t place_id, std::string_view datapack);
// Invoke a lua string.
//

View File

@@ -50,3 +50,8 @@ function gosomewhere()
function mkt()
return tangible.build{class="login", animstate={plane="somewhere", xyz={1,2,3}}}
end
makeclass("engio")
function engio.myfunction(actor, place, a, b, c)
print("Myfunction actor=", actor," place=", place, " a=", a, " b=", b, " c=", c)
end