Skip to content

Conversation

@NobleDraconian
Copy link
Member

@NobleDraconian NobleDraconian commented Jul 2, 2025

This PR completely rewrites the data system. This rewrite was needed for quite a few reasons:

  • Data is now cached as tables instead of value objects.
    In prior versions of this system, data was cached in replicated storage as value objects. While this allowed for easy replication, it ate more bandwidth than it needed to, and it was hard to work with the data (had to convert to table form, then back to valueobject form, .Value spam everywhere in the game's code). Data is now simply a table, making it much more robust and easier to work with.

  • Data is now written & read via "data handlers", which serve as an interface between the game and the raw savedata.
    Previously, data had to be manually read & written to. E.g. if a game system wanted to read the player's coin balance, it would either have to directly access Data.Currency.Coins, or call a wrapper API like MarketService:GetPlayerCurrency(). Both had their own sets of problems. Now, this is handled at the level of the datasystem. Any part of the game can simply call ReadData or WriteData with the relevant "handler". No wrapper APIs needed, no ref updates are needed, etc.

  • Replication is now more efficient.
    The old system used value objects for replication, now replication is diff-based. When the server makes a change to the data, the name of the handler it used to change the data is replicated the client. The client then locally runs that handler, 1:1 taking the steps the server took to modify the data. This is similar to how replication with a state-store library like rodux would work.

  • Code that reads data can no longer accidentally write to the data.
    In the previous version of the system, if a piece of game logic gets a reference to the player's data for the purpose of reading it, but due to a bug wrote to the reference, the player's data would be updated. Now, if the game calls ReadData, it physically cannot write back to the player's data accidentally without an explicit WriteData call. This is accomplished by returning a copy of the player's data when ReadData is called instead of a direct reference to the cache table. This does come with a performance cost, but in most scenarios the cost is acceptable as savedata isn't (and likely shouldn't) being written to constantly every frame.

@NobleDraconian NobleDraconian self-assigned this Jul 2, 2025
@NobleDraconian NobleDraconian marked this pull request as ready for review July 2, 2025 23:17
@NobleDraconian NobleDraconian changed the title V3 refactor V3 rewrite Jul 2, 2025
@NobleDraconian NobleDraconian added the enhancement New feature or request label Jul 2, 2025
@NobleDraconian NobleDraconian merged commit 0ef44c9 into master Jul 3, 2025
1 check passed
@NobleDraconian NobleDraconian deleted the v3-refactor branch July 3, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants