preStartGameWithDerectoryPath:options:completion:
Pre-start Game (by Local Directory Path)
This method allows developers to start the pre-start flow by specifying a decompressed game resource directory path. It skips the download and decompression stages, directly maps resources from the file system, initializes the runtime environment, and executes the game logic in the background.
Method Declaration
objectivec
/**
Pre-start game using a local directory path.
@param directoryPath the directory path.
@param options Configuration object containing metadata.
@param completion Called when the pre-start operation finishes.
@return An instance of id<SUDOPGameTask> to track the pre-start task.
*/
+ (id<SUDOPGameTask>)preStartGameWithDerectoryPath:(NSString *)directoryPath
options:(SUDOPGamePackageOptions *)options
completion:(nullable SUDOPGameOperationCompletion)completion;Note: The parameter here should be of type
SUDOPGamePackageOptions *, containing the game ID and version information.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| directoryPath | NSString * | Yes | The absolute directory path directoryPath. |
| options | SUDOPGamePackageOptions * | Yes | Configuration containing the absolute directory path path, appGameID, and version number. |
| completion | SUDOPGameOperationCompletion | No | Callback invoked after the asynchronous pre-start finishes. Success indicates the game logic is running and ready in the background. |
Return Value
Returns an object conforming to the id<SUDOPGameTask> protocol, used to monitor the background running status or forcibly abort the game logic when necessary.
Runtime Behavior
- Directory Mapping: The SDK directly associates the
directoryPathdirectory and checks the entry configuration file. - Environment Pre-warming: Initializes the rendering context and script virtual machine, and loads the base resources within the directory.
- Background Running: The game script begins execution (such as loading the first-frame UI layout, attempting to establish a Socket connection, etc.), but at this point no UI window is created, and the user is unaware.
- State Synchronization: When the game completes the first-frame logic initialization, the
completioncallback fires.
Example Code
objectivec
SUDOPGamePackageOptions *options = [[SUDOPGamePackageOptions alloc] init];
// Point to the game resource directory that has already been decompressed in the sandbox
NSString * directoryPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Game_001_v2/"];
options.appGameID = @"game_001";
options.version = @"2.0.0";
[SUDOP preStartGameWithDerectoryPath:directoryPath options:dirOptions completion:nil];Notes
- Directory Structure: Make sure the specified path is a folder that contains a valid game resource manifest file (such as
manifest.jsonor the entry file specified by the SDK). - Resource Locking: Between a successful pre-start and the formal
startGame, do not delete or rename the directory, otherwise the game will not find the resources at start. - Low-power Consideration: If the user does not take the next action within 1 minute after pre-start, consider canceling the task to release CPU and memory.
