若要在游戏中使用 Gaming Runtime 功能,请先通过调用 XGameRuntimeInitialize 函数来初始化 Gaming Runtime。当你的游戏完成对 Gaming Runtime 的使用并准备退出时,请通过调用 XGameRuntimeUninitialize 函数来取消初始化 Gaming Runtime。请尽可能晚地(但需在游戏退出之前)调用 XGameRuntimeUninitialize 函数,通常在游戏的入口点函数中调用。以下示例演示了如何在基于 Visual Studio 中 Direct3D 12 Desktop Game 模板的游戏的入口点函数中使用 XGameRuntimeInitialize 和 XGameRuntimeUninitialize 函数。在实例化并注册 Game 对象之前调用 XGameRuntimeInitialize 函数,并在重置 Game 对象之后但在入口点函数返回之前调用 XGameRuntimeUninitialize 函数。
// Entry pointint WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow){ UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // Initialize the Gaming Runtime before // performing any other activity. if (FAILED(XGameRuntimeInitialize())) return 1; if (!XMVerifyCPUSupport()) return 1; g_game = std::make_unique<Game>(); // Register class and create window { // Code omitted for brevity. ... } // Main message loop MSG msg = {}; while (WM_QUIT != msg.message) { // Code omitted for brevity. ... } g_game.reset(); // Uninitialize the Gaming Runtime after // all other activity has been completed. XGameRuntimeUninitialize(); return (int) msg.wParam;}