Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lua "Persistent Object" Serialization #5774

Merged

Conversation

Web-eWorks
Copy link
Member

@Web-eWorks Web-eWorks commented Feb 21, 2024

This PR adds support for serializing "persistent objects", i.e. objects that will always be created at runtime. References to these persistent objects are transparently replaced with references to the "live" copy of the persistent object when loading a saved game, unless that persistent object is no longer present (i.e. incompatible saves) in which case the persistent object is "revivified" from the savefile.

This is a difficult concept to explain, but if you're familiar with how commodity types function currently (where saved copies of a commodity type instance are replaced with the commodity type instance that was created at startup) this is an identical concept but with less manual work required.

The primary goal of this system is to migrate equipment items to use this rather than overwriting all equipment item tables every time a save is loaded. As this is primarily accomplished in #5734, this PR only includes the (bugtested) persistent serialization mechanism itself to avoid necessitating a savebump.

TODO:

  • Convert CommodityType to use Serializer:RegisterPersistent()

- Inspired by Eris/Pluto's concept of "persistent objects" which have all references transparently swapped for the runtime-current instance of that value
- Since a common pattern in Lua is to use the version of the value from the savefile if it's no longer defined in code, this implementation requires that persistent objects are also serializable
Copy link
Contributor

@Gliese852 Gliese852 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very interesting functionality, since in fact such logic already exists in Pioneer, giving it a specific place seems like a great solution!

data/meta/Serializer.lua Show resolved Hide resolved
src/lua/LuaSerializer.cpp Show resolved Hide resolved
src/lua/LuaSerializer.cpp Outdated Show resolved Hide resolved
src/lua/LuaSerializer.cpp Show resolved Hide resolved
src/lua/LuaSerializer.cpp Show resolved Hide resolved
- More clearly document the serialization process of persistent objects
- Write missing persistent objects back to the persistent object cache so they are correctly serialized if the game is re-saved to disk
@Web-eWorks Web-eWorks merged commit 4b7509a into pioneerspacesim:master Mar 1, 2024
5 checks passed
@Web-eWorks Web-eWorks deleted the lua-serialize-persistent branch March 1, 2024 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants