The future is here

The future is here

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

The future is here

Post by hokomoko »

https://youtu.be/FhwWfE64P4Q
To explain what you're seeing, this is regular ZK being saved and loaded by the engine with barely any work required from the game developer.
The engine saves the synced lua states in their entirety and loads them back virtually unchanged.

Note that at the moment saving more complex games might crash.
While lua seems to be successfully saved and loaded, the rest of the engine is not there yet as there are some remaining bugs to squash.
Last edited by hokomoko on 19 Mar 2019, 15:15, edited 1 time in total.
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: The future is here

Post by hokomoko »

https://youtu.be/wkkNPynIj5Q
Bugs seem to be gone :-)

Feel free to test saving and loading on your games and report what you find.
Make sure to use 104.0.1-1118-g89a6f16 maintenance or later (I'll put a link when the buildbots build it)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: The future is here

Post by FLOZi »

Monumental.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: The future is here

Post by PicassoCT »

Out of interest, how is it saved, how is the lua state restored?
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: The future is here

Post by hokomoko »

PicassoCT wrote: 19 Mar 2019, 21:54 Out of interest, how is it saved, how is the lua state restored?
The code is actually not very sophisticated:
https://github.com/spring/spring/blob/d ... aState.cpp
I've mirrored all of lua's data structures and integrated spring's serialisation framework (creg) in the mirrors, that does all the pointer following and saves the easy stuff.
Some things inside lua were more tricky - obviously it holds pointers to spring's API which is C functions, so these are automatically registered according to their name ("Spring.Whatever" etc.) which gives us a two-way dictionary for serialising and deserialising.

One of the last issues was when deserialising tables. While you can't use pairs() on a table with tables/functions/etc. as keys, you can still hold one (and I suspect lua makes some as well for its own use), that means that the location of the key/value pairs in the hash table vector depends on the pointer.
When serialising, I just dump the table as is (which helps preserve sync in tables with sane keys).
When deserialising, the keys still point to the same functions/tables, but the addresses changed, so they have to be reinserted.

Other than that, restoring is really just reading everything back from the file. You end up with a fully functional pointer to a lua state that you just assign to the right places in spring and that's it more or less.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: The future is here

Post by PicassoCT »

Stupid question inbound.. Can one serialize this human readable? Basically like a lua coredump?
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: The future is here

Post by hokomoko »

PicassoCT wrote: 20 Mar 2019, 13:13 Stupid question inbound.. Can one serialize this human readable? Basically like a lua coredump?
Will require a decent amount of work from said someone I suspect
hokomoko
Spring Developer
Posts: 593
Joined: 02 Jun 2014, 00:46

Re: The future is here

Post by hokomoko »

This version should have save/load: https://springrts.com/dl/buildbot/defau ... -g19e9a8c/
please test and come back with reports
Post Reply

Return to “Engine”