[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: saving state
- From: "Bilyk, Alex" <ABilyk@...>
- Date: Tue, 29 Apr 2003 12:49:38 -0700
Actually that registry would have to have anything that is allocated by Lua probably including closures, strings and tables and anything else that is accessed by VM via a C pointer. One would probably have to modify Lua a bit to store new pointers or remove garbage-collected ones and their types with in/from the registry.
Alex
-----Original Message-----
From: Bilyk, Alex
Sent: Tuesday, April 29, 2003 12:35 PM
To: Multiple recipients of list
Subject: RE: saving state
I would suggest that perhaps you reevaluate what is absolutely necessary to save in your game as saving lua_State sounds like a brute-force approach. But, if you did want to save the state, I would simply make sure that every lua_State is in yielding and simply persist every data structure it owns. The only subtle moment would be persisting C pointers, I would think. For them I would add a facility where every C pointer gets a unique ID and can be resolved to and from this ID, a C pointer registry of sorts. Same would apply to lua_State and user data pointers. Then I would save the IDs and the registry while persisting lua_State and make sure the registry has been restored by the time the game is loaded. I don't see why would lua_State in Lua be any different from any other C structure one would want to persist. The yielding state would guaranty that resume would work on any state after load. I would still question whether saving lua_State is the best solution. One of the hu!
ge!
ly successful games called Diablo [II] has taken very simplistic approach to saving games avoiding a ton of work a bugs at the same time by reloading a game when the main character is at his camp. Most NPCs and most other things in the game world don't have to be saved at all. You might consider something like this too.
Just the .02,
Alex
-----Original Message-----
From: Enno Rehling [mailto:enno@despammed.com]
Sent: Tuesday, April 29, 2003 1:39 AM
To: Multiple recipients of list
Subject: saving state
I want to use lua to create a game. NPCs for example will be running lua
scripts, and events will also be scripted. I'm thinking of implementing the
scripts as coroutines that yield whenever they've done the amount of work
they want to do during one frame of the game's engine. That way, I only have
one lua_State object, and I can call the script engine once per frame, and
return back to C.
One difficulty I have is that I need to save the current state of the
scripts when the player is saving the game. Given my current lua_State
object, I'd like to be able to serialize it to disk together with the rest
of my savegame data.
Has anyone written something like this before? I've looked through the lua
code this morning before breakfast - it looks like recreating the state
object, and registering everything in the right places, is a bit of an
adventure, and if anyone has gone that way before, I'd like to not reinvent
that particular wheel :-)
Enno.