XGameRuntimeInitializeWithOptions
This API initializes the game runtime, taking a pointer to an options structure which can modify how the runtime is initialized. While games should typically continue leveraging the existing XGameRuntimeInitialize method, some game engines or middleware may have need for more configurable initialization.Syntax
Parameters
options _In_Type: XGameRuntimeOptions* Pointer to an options structure which can modify how the runtime is initialized.
Return value
Type: HRESULT Returns S_OK if successful; otherwise, returns an error code. For a list of error codes, see Error Codes. If the function fails because the Gaming Runtime library (xgameruntime.dll) wasn’t found, the return value is set to E_GAMERUNTIME_DLL_NOT_FOUND.Remarks
The following example demonstrates how a game editor or other middleware can be used to load and run multiple games in the same process. It assumes the following external code:- A class called “GameEngine” that takes the path to the game files and starts the game. This is the same engine used at runtime by the game engine “player”.
- An instance of this is stored as a global in the editor and represents the current game.
The runtime has two layers of initialization: XGameRuntime.lib, which a component links to, and XGameRuntime.dll, which is the actual runtime implementation. When XGameRuntime.lib is initialized, it loads XGameRuntime.dll and initializes it. The DLL’s initialization is ref-counted, allowing multiple libraries to connect. The library’s initialization is not ref-counted – multiple calls to initialize it are ignored (although if XGameRuntimeInitializeWithOptions is called the provided options are compared against the currently initialized options and E_GAMERUNTIME_OPTIONS_MISMATCH is returned if they differ). Each initialization API has the following behavior:
- XGameRuntimeInitialize: If the runtime DLL has already been initialized by another call, this API “floats” to whatever initialization options were provided in the other call. If this is the first time the runtime has been initialized, default values will be used for initialization options. Games should always initialize the runtime using this API.
- XGameRuntimeInitializeWithOptions: All components initializing the runtime must pass the same options if using this method. If the runtime was previously initialized with another set of options this call will fail with E_GAMERUNTIME_OPTIONS_MISMATCH. Middleware components like a Unity game editor can use this API to initialize the runtime with a custom GameConfig before starting the game. The runtime can be re-initialized with different options if it is fully uninitialized first. This requires that all modules that called one of the XGameRuntimeInitialize* methods call XGameRuntimeUninitialize.
There are two layers here as well. Uninitializing XgameRuntime.lib will uninitialize the library and the release its reference on the DLL. Further uninitialize calls to the library are ignored until the library is re-initialized. Uninitializing the DLL decrements the ref count. When it is zero the DLL is uninitialized. This behavior remains the same. Unitializing the DLL can fail if there are still active runtime objects when the DLL refcount reaches zero. If this happens the runtime will:
- Not unload the runtime DLL since this can cause a crash.
- Store the error to later return it in a future call to XGameRuntimeInitialize*
- An XErrorReport is emitted.
Requirements
Header: XGameRuntimeInit.h Library: xgameruntime.lib Supported platforms: Windows, XBOX One family consoles and XBOX Series consolesSee also
XGameRuntimeUninitializeXGameRuntimeInitialize
XGameRuntimeInit
Developing new titles using Gaming Runtime
