Added luasnap checkpointing mechanism

This commit is contained in:
2021-02-09 17:15:54 -05:00
parent 368d066cc7
commit 8f557ff387
11 changed files with 349 additions and 73 deletions

View File

@@ -15,22 +15,15 @@ World::~World() {
}
World::World() {
// Create the lua state.
lua_state_ = lua_open();
if (lua_state_ == nullptr) {
std::cerr << "Cannot create lua state." << std::endl;
exit(1);
}
// Initialize the userdata metatables.
LuaStack::register_all_userdata(lua_state_);
LuaStack::register_all_userdata(state());
// Initialize the ID allocator in master mode.
id_global_pool_.init_master(10);
// Prepare to manipulate the lua state.
LuaVar world;
LuaStack LS(lua_state_, world);
LuaStack LS(state(), world);
// Put the world pointer into the lua registry.
LS.newpointer(world, this, false);
@@ -40,11 +33,11 @@ World::World() {
LS.setfield(LuaRegistry, "tangibles", LuaNewTable);
// Initialize the SourceDB
source_db_.initialize(lua_state_);
source_db_.initialize(state());
source_db_.rebuild();
LS.result();
assert (lua_gettop(lua_state_) == 0);
assert (lua_gettop(state()) == 0);
}
void Tangible::be_a_player() {
@@ -53,6 +46,16 @@ void Tangible::be_a_player() {
anim_queue_.add(world_->id_global_pool_.get_one(), "");
anim_queue_.set_graphic("player");
LuaVar classtab, mt, place, tangibles;
LuaStack LS(world_->state(), classtab, mt, place, tangibles);
LS.call(classtab, source_makeclass, "player");
LS.getfield(tangibles, LuaRegistry, "tangibles");
LS.rawget(place, tangibles, anim_queue_.get_id());
LS.getmetatable(mt, place);
LS.setfield(mt, "__index", classtab);
LS.result();
}
}
@@ -65,7 +68,7 @@ void World::init_standalone() {
source_db_.run_unittests();
// Create the player tangible.
Tangible *player = tangible_make(lua_state_, 1, false);
Tangible *player = tangible_make(state(), 1, false);
player->be_a_player();
}
@@ -135,7 +138,7 @@ World *World::fetch(lua_State *L) {
void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
gui->clear();
lua_State *L = get_lua_state();
lua_State *L = state();
LuaVar actor, place, ugui, func, tangibles;
LuaStack LS(L, actor, place, ugui, func, tangibles);
@@ -179,8 +182,6 @@ void World::update_gui(int64_t actor_id, int64_t place_id, Gui *gui) {
LS.result();
}
LuaDefine(tangible_get, "c") {
LuaArg id;
LuaRet database;