Redesigned ID allocator and tangible.actor

This commit is contained in:
2021-10-14 11:43:16 -04:00
parent 50d62d9bfd
commit 796a3c4139
6 changed files with 131 additions and 126 deletions

View File

@@ -22,7 +22,7 @@ LuaDefine(tangible_animate, "c") {
LuaStack LS(L, tanobj, config);
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_get(LS, tanobj);
int64_t id = w->id_global_pool_.alloc_id_for_thread(L);
int64_t id = w->alloc_id_predictable();
const AnimStep &prev = tan->anim_queue_.back();
AnimStep step;
step.from_lua(L, config.index(), prev);
@@ -94,7 +94,8 @@ LuaDefine(tangible_build, "c") {
// TODO: generate error if there's extra crap in the config table.
World *w = World::fetch_global_pointer(L);
Tangible *tan = w->tangible_make(L, 0, "nowhere", true);
int64_t new_id = w->alloc_id_predictable();
Tangible *tan = w->tangible_make(L, new_id, "nowhere", true);
lua_replace(L, database.index());
// Update the class of the new tangible.
@@ -102,7 +103,7 @@ LuaDefine(tangible_build, "c") {
LS.rawset(mt, "__index", classtab);
// Update the animation queue and planemap of the new tangible.
int64_t stepid = w->id_global_pool_.alloc_id_for_thread(L);
int64_t stepid = w->alloc_id_predictable();
tan->anim_queue_.add(stepid, initstep);
tan->update_plane_item();
@@ -153,21 +154,26 @@ LuaDefine(tangible_id, "c") {
return LS.result();
}
LuaDefine(tangible_getactor, "c") {
LuaDefine(tangible_actor, "c") {
LuaRet actor;
LuaStack LS(L, actor);
LS.rawget(actor, LuaRegistry, "actor");
LuaVar tangibles;
LuaStack LS(L, tangibles, actor);
World *w = World::fetch_global_pointer(L);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(actor, tangibles, w->lthread_actor_id_);
return LS.result();
}
LuaDefine(tangible_getplace, "c") {
LuaDefine(tangible_place, "c") {
LuaRet place;
LuaStack LS(L, place);
LS.rawget(place, LuaRegistry, "place");
LuaVar tangibles;
LuaStack LS(L, tangibles, place);
World *w = World::fetch_global_pointer(L);
LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(place, tangibles, w->lthread_place_id_);
return LS.result();
}
LuaDefine(world_wait, "f") {
if ((lua_gettop(L) != 1) || (lua_type(L, -1) != LUA_TNUMBER)) {
luaL_error(L, "Argument to wait must be a number.");