Overhaul tangible_make to get rid of LuaOldStack
This commit is contained in:
@@ -167,8 +167,7 @@ LuaDefine(tangible_build, "config",
|
||||
|
||||
World *w = World::fetch_global_pointer(L);
|
||||
int64_t new_id = w->alloc_id_predictable();
|
||||
Tangible *tan = w->tangible_make(L, new_id, "nowhere", true);
|
||||
lua_replace(L, database.index());
|
||||
Tangible *tan = w->tangible_make(LS, database, new_id, "nowhere");
|
||||
|
||||
// Update the class of the new tangible.
|
||||
LS.getmetatable(mt, database);
|
||||
|
||||
@@ -43,7 +43,7 @@ World::World(WorldType wt) {
|
||||
|
||||
// Prepare to manipulate the lua state.
|
||||
LuaVar world, globtab;
|
||||
LuaOldStack LS(state(), world, globtab);
|
||||
LuaExtStack LS(state(), world, globtab);
|
||||
|
||||
// Put the world pointer into the lua registry.
|
||||
World::store_global_pointer(state(), this);
|
||||
@@ -75,9 +75,6 @@ World::World(WorldType wt) {
|
||||
|
||||
// Initialize global variable state.
|
||||
assign_seqno_ = 1;
|
||||
|
||||
LS.result();
|
||||
assert (stack_is_clear());
|
||||
}
|
||||
|
||||
Tangible::Tangible(World *w, int64_t id) : world_(w), anim_queue_(w->world_type_), id_player_pool_(&w->id_global_pool_) {
|
||||
@@ -143,17 +140,10 @@ Tangible *World::tangible_get(const LuaCoreStack &LS, LuaSlot tab, bool allowdel
|
||||
return result;
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(lua_State *L, int64_t id, const eng::string &plane, bool pushdb) {
|
||||
// Get a state if we don't already have one.
|
||||
if (L == nullptr) {
|
||||
L = state();
|
||||
assert(!pushdb);
|
||||
}
|
||||
Tangible *World::tangible_make(const LuaCoreStack &LS0, LuaSlot database, int64_t id, const eng::string &plane) {
|
||||
assert(id != 0);
|
||||
|
||||
LuaVar metatab;
|
||||
LuaRet database;
|
||||
LuaOldStack LS(L, database, metatab);
|
||||
LuaExtStack LS(LS0.state(), metatab);
|
||||
|
||||
// Create the C++ part of the structure.
|
||||
UniqueTangible &t = tangibles_[id];
|
||||
@@ -171,21 +161,24 @@ Tangible *World::tangible_make(lua_State *L, int64_t id, const eng::string &plan
|
||||
// Set up the inventory and thread table.
|
||||
LS.rawset(database, "inventory", LuaNewTable);
|
||||
LS.rawset(metatab, "threads", LuaNewTable);
|
||||
|
||||
LS.result();
|
||||
if (!pushdb) lua_pop(L, 1);
|
||||
|
||||
return t.get();
|
||||
}
|
||||
|
||||
Tangible *World::tangible_make(int64_t id, const eng::string &plane) {
|
||||
LuaVar database;
|
||||
LuaExtStack LS(state(), database);
|
||||
return tangible_make(LS, database, id, plane);
|
||||
}
|
||||
|
||||
void World::tangible_delete(int64_t id) {
|
||||
lua_State *L = state();
|
||||
LuaVar tangibles, database, metatab;
|
||||
LuaOldStack LS(L, tangibles, database, metatab);
|
||||
LuaExtStack LS(L, tangibles, database, metatab);
|
||||
|
||||
// Fetch the C++ side of the tangible.
|
||||
auto iter = tangibles_.find(id);
|
||||
if (iter == tangibles_.end()) {
|
||||
LS.result();
|
||||
return; // Nothing to delete.
|
||||
}
|
||||
|
||||
@@ -204,7 +197,6 @@ void World::tangible_delete(int64_t id) {
|
||||
|
||||
// Remove the C++ portion from the tangibles table.
|
||||
tangibles_.erase(iter);
|
||||
LS.result();
|
||||
}
|
||||
|
||||
util::IdVector World::get_near(int64_t player_id, float radius, bool exclude_nowhere, bool omit_player, bool sorted) const {
|
||||
@@ -235,17 +227,14 @@ World::Redirects World::fetch_redirects() {
|
||||
int64_t World::create_login_actor() {
|
||||
assert(stack_is_clear());
|
||||
int64_t id = id_global_pool_.get_one();
|
||||
Tangible *tan = tangible_make(state(), id, "nowhere", true);
|
||||
LuaArg database;
|
||||
LuaVar classtab, mt;
|
||||
LuaOldStack LS(state(), database, classtab, mt);
|
||||
LuaVar database, classtab, mt;
|
||||
LuaExtStack LS(state(), database, classtab, mt);
|
||||
Tangible *tan = tangible_make(LS, database, id, "nowhere");
|
||||
LS.makeclass(classtab, "login");
|
||||
LS.getmetatable(mt, database);
|
||||
LS.rawset(mt, "__index", classtab);
|
||||
LS.result();
|
||||
tan->configure_id_pool_for_actor();
|
||||
tan->print_buffer_.clear();
|
||||
assert(stack_is_clear());
|
||||
return tan->id();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ int64_t World::patch_actor(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
Tangible *s_actor = tangible_get(actor_id);
|
||||
if (s_actor == nullptr) {
|
||||
DebugLine(dbc) << "create new actor " << actor_id;
|
||||
s_actor = tangible_make(nullptr, actor_id, "", false);
|
||||
s_actor = tangible_make(actor_id, "");
|
||||
s_actor->id_player_pool_.deserialize(sb);
|
||||
s_actor->anim_queue_.deserialize(sb);
|
||||
s_actor->print_buffer_.deserialize(sb);
|
||||
@@ -61,7 +61,7 @@ void World::patch_visible(StreamBuffer *sb, DebugCollector *dbc) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
int64_t id = sb->read_int64();
|
||||
DebugLine(dbc) << "patch_visible create tan " << id;
|
||||
Tangible *t = tangible_make(state(), id, "", false);
|
||||
Tangible *t = tangible_make(id, "");
|
||||
t->anim_queue_.deserialize(sb);
|
||||
t->update_plane_item();
|
||||
}
|
||||
|
||||
@@ -267,8 +267,8 @@ LuaDefine(unittests_world1animdiff, "", "some unit tests") {
|
||||
util::IdVector ids = util::id_vector_create(123, 345);
|
||||
|
||||
// Create some tangibles, and add some animations.
|
||||
m->tangible_make(0, 123, "somewhere", false);
|
||||
m->tangible_make(0, 345, "somewhere", false);
|
||||
m->tangible_make(123, "somewhere");
|
||||
m->tangible_make(345, "somewhere");
|
||||
m->tangible_walkto(123, 770, 3, 4);
|
||||
m->tangible_walkto(345, 771, 6, 2);
|
||||
LuaAssertStrEq(L, m->tangible_ids_debug_string(), "123,345");
|
||||
@@ -337,7 +337,7 @@ LuaDefine(unittests_world2pairtab, "", "some unit tests") {
|
||||
|
||||
// Create a master model containing some general tables, and
|
||||
// some specialty tables (not numberable).
|
||||
m->tangible_make(0, 123, "somewhere", false);
|
||||
m->tangible_make(123, "somewhere");
|
||||
m->tangible_set_string(123, "inventory.TID", "inventory");
|
||||
m->tangible_set_string(123, "transactions.TID", "transactions");
|
||||
m->tangible_set_string(123, "skills.TID", "skills");
|
||||
@@ -348,7 +348,7 @@ LuaDefine(unittests_world2pairtab, "", "some unit tests") {
|
||||
|
||||
// Now we're going to create a synchronous model that's similar to, but not
|
||||
// exactly the same as that master model.
|
||||
ss->tangible_make(0, 123, "somewhere", false);
|
||||
ss->tangible_make(123, "somewhere");
|
||||
ss->tangible_set_string(123, "inventory.TID", "inventory");
|
||||
ss->tangible_set_string(123, "skills.TID", "skills");
|
||||
ss->tangible_set_string(123, "skills.crap.TID", "skills.crap");
|
||||
@@ -384,12 +384,12 @@ LuaDefine(unittests_world3diffluatab, "", "some unit tests") {
|
||||
StreamBuffer sb;
|
||||
|
||||
// Initialize all three models so that a tangible exists.
|
||||
m->tangible_make(0, 123, "somewhere", false);
|
||||
ss->tangible_make(0, 123, "somewhere", false);
|
||||
cs->tangible_make(0, 123, "somewhere", false);
|
||||
m->tangible_make(0, 345, "somewhere", false);
|
||||
ss->tangible_make(0, 345, "somewhere", false);
|
||||
cs->tangible_make(0, 345, "somewhere", false);
|
||||
m->tangible_make(123, "somewhere");
|
||||
ss->tangible_make(123, "somewhere");
|
||||
cs->tangible_make(123, "somewhere");
|
||||
m->tangible_make(345, "somewhere");
|
||||
ss->tangible_make(345, "somewhere");
|
||||
cs->tangible_make(345, "somewhere");
|
||||
|
||||
// Put some data into the master model.
|
||||
m->tangible_set_string(123, "bacon", "crispy");
|
||||
@@ -438,9 +438,9 @@ LuaDefine(unittests_world4difftanclass, "", "some unit tests") {
|
||||
StreamBuffer sb;
|
||||
|
||||
// Initialize all three models so that a tangible exists.
|
||||
m->tangible_make(0, 123, "somewhere", false);
|
||||
ss->tangible_make(0, 123, "somewhere", false);
|
||||
cs->tangible_make(0, 123, "somewhere", false);
|
||||
m->tangible_make(123, "somewhere");
|
||||
ss->tangible_make(123, "somewhere");
|
||||
cs->tangible_make(123, "somewhere");
|
||||
|
||||
// Change the lua class of the tangible.
|
||||
m->tangible_set_class(123, "chicken");
|
||||
|
||||
@@ -129,11 +129,12 @@ public:
|
||||
|
||||
// Make a tangible.
|
||||
//
|
||||
// You must provide a valid previously-unused ID. If pushdb is true, pushes
|
||||
// the tangible's database onto the lua stack. Otherwise, leaves the lua
|
||||
// stack untouched.
|
||||
// You must provide a valid previously-unused ID. Otherwise, leaves the lua
|
||||
// stack untouched. Returns a pointer to the C++ part of the tangible, and
|
||||
// optionally stores the Lua part in a stack slot.
|
||||
//
|
||||
Tangible *tangible_make(lua_State *L, int64_t id, const eng::string &plane, bool pushdb);
|
||||
Tangible *tangible_make(const LuaCoreStack &LS0, LuaSlot tan, int64_t id, const eng::string &plane);
|
||||
Tangible *tangible_make(int64_t id, const eng::string &plane);
|
||||
|
||||
// Get a pointer to the specified tangible.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user