Add global variables 'actor' and 'place'

This commit is contained in:
2025-06-27 16:34:11 -04:00
parent 8298ef6e72
commit be9ff4db35
2 changed files with 33 additions and 8 deletions

View File

@@ -1139,6 +1139,12 @@ const PrintBuffer *World::get_printbuffer(int64_t actor_id) {
}
void World::clear_lthread_state() {
LuaVar globals;
LuaExtStack LS(state(), globals);
LS.getglobaltable(globals);
LS.rawset(globals, "actor", LuaNil);
LS.rawset(globals, "place", LuaNil);
lthread_prints_.reset();
lthread_actor_id_ = 0;
lthread_place_id_ = 0;
@@ -1147,6 +1153,24 @@ void World::clear_lthread_state() {
}
void World::open_lthread_state(int64_t actor, int64_t place, int64_t thread, bool ppool, bool prints) {
// Store actor and place in global variables.
LuaVar lactor, lplace, tangibles, globals;
LuaExtStack LS(state(), lactor, lplace, tangibles, globals);
LS.getglobaltable(globals);
if ((actor == 0) && (place == 0))
{
LS.rawset(globals, "actor", LuaNil);
LS.rawset(globals, "place", LuaNil);
}
else
{
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(lactor, tangibles, actor);
LS.rawget(lplace, tangibles, place);
LS.rawset(globals, "actor", lactor);
LS.rawset(globals, "place", lplace);
}
lthread_actor_id_ = actor;
lthread_place_id_ = place;
lthread_thread_id_ = thread;

View File

@@ -6,15 +6,17 @@ makeclass('sphere')
-- This gets called on every login except the admin user.
function login.init()
local actor = tangible.actor()
dprint("login.init:", actor)
tangible.animinit(actor, {bp="character", plane="earth", xyz={0, 0, 90}})
local player = global.get("nextplayer")
global.set("nextplayer", player + 1)
dprint("login.init initializing player ", player)
actor.player = player
tangible.animinit(actor, {bp="character", plane="earth", xyz={player * 100, 0, 90}})
end
-- This gets called on the admin user. You can call login.init in here if you want.
function world.init()
local actor = tangible.actor()
dprint("world.init:", actor)
dprint("world.init")
global.set("nextplayer", 0)
tangible.build{class=cube, plane="earth", xyz={500,-100,0}}
tangible.build{class=sphere, plane="earth", xyz={500,100,0}}
login.init()
@@ -22,7 +24,6 @@ end
function engio.move(action, xyz, facing)
-- todo: sanity check the parameters.
local actor = tangible.actor()
dprint("engio.move ", action, " ", xyz[1], " ", xyz[2], " ", xyz[3])
tangible.animate(actor, nil, {action=action, xyz=xyz, facing=facing})
end
@@ -41,7 +42,7 @@ end
function engio.getlookat()
local class = tangible.getclass(tangible.place())
local class = tangible.getclass(place)
-- if the tangible is not of any class, return empty string.
if class == nil then
@@ -68,7 +69,7 @@ function engio.getlookat()
end
function engio.presshotkey(action)
local class = tangible.getclass(tangible.place())
local class = tangible.getclass(place)
-- if the tangible doesn't have a 'lookhotkeys' function, do nothing
if class == nil or class.lookhotkeys == nil then