Add global variables 'actor' and 'place'
This commit is contained in:
@@ -1139,6 +1139,12 @@ const PrintBuffer *World::get_printbuffer(int64_t actor_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void World::clear_lthread_state() {
|
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_prints_.reset();
|
||||||
lthread_actor_id_ = 0;
|
lthread_actor_id_ = 0;
|
||||||
lthread_place_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) {
|
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_actor_id_ = actor;
|
||||||
lthread_place_id_ = place;
|
lthread_place_id_ = place;
|
||||||
lthread_thread_id_ = thread;
|
lthread_thread_id_ = thread;
|
||||||
|
|||||||
@@ -6,15 +6,17 @@ makeclass('sphere')
|
|||||||
|
|
||||||
-- This gets called on every login except the admin user.
|
-- This gets called on every login except the admin user.
|
||||||
function login.init()
|
function login.init()
|
||||||
local actor = tangible.actor()
|
local player = global.get("nextplayer")
|
||||||
dprint("login.init:", actor)
|
global.set("nextplayer", player + 1)
|
||||||
tangible.animinit(actor, {bp="character", plane="earth", xyz={0, 0, 90}})
|
dprint("login.init initializing player ", player)
|
||||||
|
actor.player = player
|
||||||
|
tangible.animinit(actor, {bp="character", plane="earth", xyz={player * 100, 0, 90}})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This gets called on the admin user. You can call login.init in here if you want.
|
-- This gets called on the admin user. You can call login.init in here if you want.
|
||||||
function world.init()
|
function world.init()
|
||||||
local actor = tangible.actor()
|
dprint("world.init")
|
||||||
dprint("world.init:", actor)
|
global.set("nextplayer", 0)
|
||||||
tangible.build{class=cube, plane="earth", xyz={500,-100,0}}
|
tangible.build{class=cube, plane="earth", xyz={500,-100,0}}
|
||||||
tangible.build{class=sphere, plane="earth", xyz={500,100,0}}
|
tangible.build{class=sphere, plane="earth", xyz={500,100,0}}
|
||||||
login.init()
|
login.init()
|
||||||
@@ -22,7 +24,6 @@ end
|
|||||||
|
|
||||||
function engio.move(action, xyz, facing)
|
function engio.move(action, xyz, facing)
|
||||||
-- todo: sanity check the parameters.
|
-- todo: sanity check the parameters.
|
||||||
local actor = tangible.actor()
|
|
||||||
dprint("engio.move ", action, " ", xyz[1], " ", xyz[2], " ", xyz[3])
|
dprint("engio.move ", action, " ", xyz[1], " ", xyz[2], " ", xyz[3])
|
||||||
tangible.animate(actor, nil, {action=action, xyz=xyz, facing=facing})
|
tangible.animate(actor, nil, {action=action, xyz=xyz, facing=facing})
|
||||||
end
|
end
|
||||||
@@ -41,7 +42,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function engio.getlookat()
|
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 the tangible is not of any class, return empty string.
|
||||||
if class == nil then
|
if class == nil then
|
||||||
@@ -68,7 +69,7 @@ function engio.getlookat()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function engio.presshotkey(action)
|
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 the tangible doesn't have a 'lookhotkeys' function, do nothing
|
||||||
if class == nil or class.lookhotkeys == nil then
|
if class == nil or class.lookhotkeys == nil then
|
||||||
|
|||||||
Reference in New Issue
Block a user