createRuntime:completion:
Create Runtime Instance
This method initializes the low-level environment (Runtime) required for running games. Typically, only one runtime instance needs to be created throughout the entire application process lifecycle. This instance is responsible for managing the core resources and scheduling logic during game execution.
Method Declaration
objectivec
/**
Create a runtime instance (single process has only one).
@param options Optional configuration parameters for the runtime.
@param completion Completion callback.
*/
+ (void)createRuntime:(NSDictionary *_Nullable)options
completion:(nullable void(^)(id<SUDRT> _Nullable runtime, NSError *_Nullable error))completion;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| options | NSDictionary * | No | Custom configuration parameters for the runtime (e.g., render mode, custom resource paths). Pass nil to use the default configuration. |
| completion | Block | No | Callback invoked after the asynchronous creation finishes. On success, returns an instance conforming to the SUDRT protocol; on failure, returns error. |
Runtime Behavior
- Singleton Nature: Although the method is named
create, under a single-process architecture only one Runtime instance is typically maintained. - Asynchronous Preparation: Since the runtime environment may involve low-level library loading or GPU environment initialization, the result is reported asynchronously via
completion. - Dependency: Must be called after
initializeWithConfiguration:completion:succeeds.
Example Code
objectivec
NSDictionary *options = @{ @"render_mode": @"metal" };
[SUDOP createRuntime:options completion:^(id<SUDRT> _Nullable runtime, NSError * _Nullable error) {
if (error) {
NSLog(@"Runtime creation failed: %@", error);
return;
}
NSLog(@"Runtime is ready: %@", runtime);
// You can now perform pre-load or start-game operations
}];Notes
- Lifecycle: The Runtime instance is usually managed internally by the SDK. The
id<SUDRT>the developer obtains is mainly used to confirm the environment-ready state or perform low-level debugging. - Repeated Creation: If a Runtime already exists, calling this method again typically returns the existing instance or reports an error, depending on the SDK's internal policy.
- Thread Constraint: It is recommended to initiate the creation request on the main thread; the callback is usually also executed on the main thread.
