-
Notifications
You must be signed in to change notification settings - Fork 964
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
Snapshot Save Single Action #7500
base: master
Are you sure you want to change the base?
Conversation
Extensions/SaveState/JsExtension.js
Outdated
_('Save the whole game'), | ||
_('Save the wole game.'), | ||
_('Syncall'), | ||
'res/conditions/animation24.png', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this :)
GDJS/Runtime/scenestack.ts
Outdated
@@ -70,6 +70,44 @@ namespace gdjs { | |||
} else { | |||
logger.error('Unrecognized change in scene stack: ' + request); | |||
} | |||
|
|||
const allSyncData: GameSaveState = JSON.parse( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do this getItem and parse at every frame, this seems wasteful for the CPU because it's then immediately discarded in almost all cases (i.e: when a loading is not requested).
@@ -243,9 +243,10 @@ namespace gdjs { | |||
} | |||
|
|||
updateFromNetworkSyncData( | |||
networkSyncData: TextObjectNetworkSyncData | |||
networkSyncData: TextObjectNetworkSyncData, | |||
options?: { skipMultiplayerInstructions: boolean } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed with you on Discord a while ago: all these options can probably be set in a type UpdateFromNetworkSyncDataOptions
GDJS/Runtime/scenestack.ts
Outdated
); | ||
|
||
if (currentScene._isLoadingRequested && allSyncData) { | ||
currentScene |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a lot of logic => Put it in a method with a name that describe what this does.
GDJS/Runtime/variablescontainer.ts
Outdated
); | ||
return; | ||
} | ||
if (!options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying only on the existence of options, and not reading a boolean with a proper name, is risky
GDJS/Runtime/scenestack.ts
Outdated
localStorage.getItem('save') as string | ||
); | ||
|
||
if (currentScene._isLoadingRequested && allSyncData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't access private properties (_somethingLikeThis
) outside of the class they belong to.
GDJS/Runtime/scenestack.ts
Outdated
currentScene | ||
.getGame() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're using currentScen.getGame() 3 times in this function. That should ring a bell :)
…to step function of scenestack, switch from browser localstorage to indexedDB
Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts
Outdated
Show resolved
Hide resolved
Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts
Outdated
Show resolved
Hide resolved
…added some constants in separated files for clarity
Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.ts
Outdated
Show resolved
Hide resolved
objectStoreName: string, | ||
key: string | ||
): Promise<any> { | ||
if (!indexedDB) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a good check, though what if indexedDB.open()
(line below) fails? (if Safari does a weird thing for instance?)
My suggestion was more to do a try catch around everything to catch any weird stuff we didn't handle
Save and/or load the whole game using the updateFromNetworkSyncData/getNetworkSyncData methods to write/read a complete JSON. Done in one action for each (at the moment, might change). Right now it writes both on a localFile and localStorage of the browser.