DirectX Installation for Game Developers
Jason Sandlin, Software Development Lead
Chuck Walbourn, Software Design Engineer
Microsoft Game Technology Group
December 2006
This article is intended to address some of the common questions about the DirectX runtime and using DirectSetup to install DirectX.
本文着重介绍一些通用的DX运行库问题和如何使用DirectSetup安装DX。
DirectX Runtime
The DirectX runtime consists of core components and optional components.
DX运行库由核心组件和可选组件组成。
The core components, such as Direct3D, DirectSound, and DirectInput, are considered part of the operating system. The core components for DirectX 9.0c have not changed since the DirectX SDK Summer 2004 Update and match what was released with Microsoft Windows XP SP2, Windows XP Pro x64 Edition, and Windows Server 2003 SP1. The next update after DirectX 9.0c is DirectX 10 which is only included in Windows Vista. There were no changes any core DirectX component in DirectX 10 except to Direct3D, the new version of which adds support for Windows Vista driver models (WDDM) and features for new and upcoming graphics hardware.
核心组件包括D3D,DirectSound和DirectInput等,是与操作系统协同工作的部分。自从DirectX SDK Summer 2004版以来,DirectX9.0c的核心组件没有变动过,与Windows XP SP2,Windows XP Pro x64版,Windows Server 2003 SP1版本兼容。DX9.0c的下一个更新版本是DX10,只在Windows Vista中存在。DX10的核心组件和DX9相比,除了D3D部分外,没有做太多改动。新版的D3D10提供了对Widows Vista驱动模型(WDDM)的支持和对即将出现的新的图形硬件细节的支持。
The optional components are released in the bimonthly updates of DirectX SDK and include components such as D3DX, XACT, XINPUT, and Managed DirectX. Many of the optional DirectX components are regularly updated to integrate customer feedback and expose new features.
可选组件在每两个月发布一次的DirectX SDK版本中更新,包括D3DX,XACT,XINPUT和Managed DirectX等。许多可选的DirectX组件会被经常更新,集成了用户的反馈并发布一些新细节。
DirectX Version Number
The DirectX version number, such as 9.0c, refers only to the version of the core components, such as Direct3D, DirectInput, or DirectSound. This number does not cover the versions of the various optional components that are released in the DirectX SDK, such as D3DX, XACT, XINPUT, etc.
DirectX版本号(比如9.0c)指的是核心组件(Direct3D,DirectInput或DirectSound)的版本。这个版本号不包括在DirectX SDK中发布的大量可选组件(D3DX,XACT,XINPUT等)的版本。
Generally speaking, the DirectX version number is not meaningful except as a quick reference to the core runtime bits. This number should not be used to check if the correct DirectX runtime is already installed, because it doesn’t take into account the optional DirectX components.
通常来说,DirectX版本号并没有实际意义,只是在核心运行库的某些比特位上可以做一个快速的版本索引查询。这个数字不能用来检查正确的DX运行库已经安装,因为它不包括可选的DirectX组件的版本号。
DirectX Libraries
In the past, the optional components of the DirectX SDK, including D3DX, were released as static libraries. However, these are now released as dynamic-like libraries (DLLs) because of the increased demand for better security practices. DLLs allow servicing of previously released code. If these components were deployed as static libraries, there would be no way for Microsoft to address security issues found after release.
在过去,DirectX SDK的可选组件(包括D3DX)是作为静态链接库来发布的。当然现在它们作为动态连接库(DLLs)来发布,因为目前对安全性的实际要求越来越高。动态链接库允许操作过去发布的代码。但是如果做为静态库的话,MS就没有办法在运行库发布后定位安全性相关的代码。
As features are added or changed to the optional components, the names of the corresponding DLLs are also changed to ensure that no regressions are caused to existing games that are using released components. The DLLs for each component live side by side, and game developers can choose exactly which DLL version that the game uses by linking to the corresponding import library.
因为可选组件的某些细节在新发布版本中会被添加或者改变,所以对应的动态链接库的名字也会做对应改变,这就保证了使用从前发布的组件的游戏不会和目前SDK产生冲突。不同版本的可选组件DLL同时并存,游戏开发人员可以通过链接到对应的库文件来选择使用哪个DLL版本。
While ensuring that DLLs are installed on a system isn’t as easy as simply linking to static libraries, some changes have been made to the DirectX SDK to address the pain of the DLL model:
保证动态链接在某个系统上被安装并不是和简单链接到静态库一样容易,DirectX SDK做了一些改动来减少DLL使用的问题:
· The DirectX redistributable can be configured to contain only those components that your application requires to minimize distribution and media sizes.
DirectX安装选项能够只包含用户应用程序需要的组件,这样能把安装空间减到最小。
· The redistributable folder, Program Files\DirectX SDK\Redist\, now contains a cabinet (.cab) file for every possible optional component, so you don't have to dig up an older SDK to find them.
安装文件夹\Program Files\DirectX SDK\Redist\现在包含一个.cab文件包含某些将来可能被用到的可选组件,因此你不必每次到旧版的SDK中去寻找它们。
· Installing the SDK itself installs every possible optional component.
安装SDK的同时会安装每个可选组件。
· A DirectX redistributable that contains all the optional components is available as both a web-based installer and as a downloadable package; see the
包含可选组件DirectX安装程序既可以作为网页安装程序或者下载的安装包,详情参见DirectX开发人员中心(http://msdn.microsoft.com/directx/)
Installation of DirectX by the Game’s Installer
The following are the best practices for adding installation of DirectX to a game's installer:
下面是一些在制作游戏安装程序时安装DirectX时的推荐操作:
Install the redistributable components every time.
A game’s installation process should install the DirectX redistributable components during every single installation without allowing users to opt-out of it. If you allow opting-out, then some users will guess that they don’t need it, and if they actually do, the game will not run.
最好每次重新安装DX运行库
游戏安装程序应该在每次安装时都自动安装一遍DirectX运行库而不需要用户选择。如果你让他们选择,他们会认为这对于游戏来说并不是必要的,从而导致游戏不能运行。
Let the DirectX installer check for optional components.
Do not assume that the latest optional components are already installed on a system, b ecause Windows Update and Service Packs do not provide any of DirectX’s optional components. You must install the DirectX runtime either by running dxsetup.exe directly or calling DirectSetup.
让DirectX安装程序检查可选组件
不要假设所有可选组件都在系统上安装了,因为Windows自动更新程序包并不包含DirectX可选组件。你必须通过运行dxsetup.exe或者调用DirectSetup来安装DirectX运行库。
Set up silently.
Launch setup in silent mode so that users do not accidentally skip updating the DirectX runtime. You can do this by launching dxsetup.exe with the following command:
path-to-redistributable\dxsetup.exe/silent
or by calling DirectSetup and not displaying any UI.
默认安装
默认导入DirectX安装程序,这样用户就不会意外跳过更新DirectX运行库。你可以使用下列命令默认导入dxsetup.exe:
安装路径\dxsetup.exe/silent
或者调用DirectSetup而不在任何用户界面上显示。
Combine EULA acceptances.
If you prompt the user to accept a EULA, then combine that with prompting for acceptance of the DirectX EULA when installing in silent mode so that prompting for acceptance of EULAs happens just once. Prompting should happen before you install anything so that if user doesn’t accept, you don't end up with a failed and partial installation.
包含EULA(end-user license agreement,终端用户使用许可)接受程序
如果你提示用户接受EULA,在默认安装时包含提示接受DirectX EULA的程序,这样在安装时只需要提示一次就可以了。提示应该在安装任何程序之前进行,如果用户不接受的话,你不必通过安装失败分支和部分安装分支结束。
Just run dxsetup or call DirectSetup.
Because the DirectX version number doesn’t refer to anything except the core DirectX components, do not check an installed version before running dxsetup.exe or calling DirectSetup. Also, do not check for a file’s existence to test if an optional component is already installed, since this usually will not correctly determine when a component exists but needs updating; however, the DirectX setup package will quickly determine this and perform the right action.
只通过dxsetup.exe或调用DirectSetup安装
因为DirectX版本号除了表达DirectX核心组件版本外并没有任何意义,在执行dxsetup.exe或者调用DirectSetup之前不要检查DX版本号。也不要通过检查一个文件是否存在来确认一个可选组件是否被安装,因为这并不包括这个组件已经存在但是需要更新的情况。当然,DirectX安装包会快速检查这种情况并执行正确的操作。
Small Installation Packages
You can create smaller installation packages for DirectX by stripping the contents of the DirectX redistributable folder down to the minimal set of files required to make the installer work and retaining any additional components that your game uses.
你能够通过从Direct安装程序文件夹中提取出你需要的内容来自己生成一个更小的DirectX安装包。
Depending on your minimum specifications, you might not even need to include the core DirectX 9.0c cabinet files in the redistributable folder of your installation media. A large majority of Windows XP installations have Service Pack 2, which includes the core DirectX 9.0c components, so the DirectX setup operation will be very fast and will not require a reboot. The smallest package that can be created is about 3 MB, and it can be compressed to about half that size. A package like this contains one version of the D3DX DLL, and it requires that DirectX 9.0c be already present.
在你自己的安装包中,你甚至不需要包含安装文件夹中DirectX9.0c核心组件cab文件。Windows XP SP2版本已经包含了DirectX 9.0c的核心组件,因此DirectX安装会更快而且不需要重启动。最小安装包能够只有3MB,压缩后大小只有原来一半。这样一个安装包包含一个版本的D3DX动态链接库,并且需要DirectX9.0c已经安装好了。
The minimal set of files that are required to build a redistributable package are the following files, located in the DirectX SDK Redist folder (Program Files\DirectX SDK\Redist\):
下面这些文件是最小安装包所需要的文件,在DirectX SDK安装文件夹中可以找到:
· dxsetup.exe
· dsetup32.dll
· dsetup.dll
· dxupdate.cab
· dxdllreg_x86.cab
Add to these the cabinet files for the components that you want to install. If you require the users of your application to already have DirectX 9.0c, then you do not need to include DirectX.cab or dxnt.cab, which make up most of the space requirement. DirectX.cab is only needed for Windows 98 and Windows ME, and dxnt.cab is only needed for Windows 2000, Windows XP, and Windows XP SP1. Also, if you do not make use of DirectShow, or you assume that it is already installed, you can omit BDA.cab, BDANT.cab, and BDAXP.cab.
把这些文件添加到你的安装程序中。如果你要求你的用户预先安装了DirectX9.0c,你就不必包含DirectX.cab或者dxnt.cab,它们占用了大部分内存空间。DirectX.cab只在Windows 98,Window ME上有效,dxnt.cab只在Widnows 2000, Windows XP和Windows XP SP1上有效。当然,如果你不需要DirectShow或者假设他们已经存在,你能够不添加BDA.cab,BDANT.cab和 BDAXP.cab。
Note You can assume that users of your application already have DirectX 9.0c if it was installed by a previous version of your application, you force users to manually update via the Web Installer, or you assume that they have Windows XP SP2 or later.
注意: 你能够假设用户安装了你的旧版的应用程序之后就已经安装了DirectX9.0c,那么就可以通过网页安装程序让他们手动更新DirectX,或者假设他们使用了Window XP SP2或者更高的版本。
Continuing with this example, if you are using only the 32-bit version of D3DX for April 2006, you can add Apr2006_d3dx9_30_x86.cab. If you are using the 32-bit August 2006 32-bit version of XINPUT, you add Aug2006_xinput_x86.cab.
举个例子说,如果你使用了32位D3DX 2006 April版,你可以添加Apr2006_d3dx9_30_x86.cab文件。如果你使用32位August 2006版XINPUT,你可以添加Aug2006_xinput_x86.cab。
If you have a native 64-bit application, you'll need to add the _x64 versions. However, if you have a 32-bit application running on a 64-bit OS, the 32-bit versions of the DLLs will work.
如果你使用64位程序,你需要安装_x64版本。当然,如果你让一个32位程序运行在64位系统上,32位的动态链接库也能工作。
You can then distribute this package of files and launch DirectSetup in silent mode or run dxsetup.exe in the command shell in silent mode. Remember not to guard this package by any version checking of files, and make sure that your users cannot opt out of running the DirectX setup, because either of these events creates a fallible installation process.
然后你可以发布这些文件包并通过默认方式导入DirectSetup或者在命令行中用默认模式运行dxsetup.exe来安装它们。
DirectX Web Installer
The DirectX Web Installer is a downloaded executable file that checks the user’s computer for DirectX components, both optional and core. It downloads and installs components as needed after examining the currently installed components. It is available by clicking Download on the following web page: http://www.microsoft.com/directx/. Do not redistribute the DirectX Web Installer, simply point users to the Microsoft website.
DirectX网页安装程序是一个可下载执行的文件用以检查用户计算机上的DirectX核心组件和可选组件的版本。它能在检查完之后自动下载和安装需要的组件。通过在http://www.microsoft.com/directx/点击Download执行网页安装程序。不要发布DirectX网页安装程序,只需要简单告诉用户MS网页地址即可。
The DirectX Web Installer is updated on a regular basis, and is intended mostly for use by those who play small downloadable games, for which even a few additional megabytes to download is considered too much.
DirectX网页安装程序会经常更新,它主要被那些玩从网页上下载的小游戏的玩家使用,因为稍多一点MB的下载量也会被他们慎重考虑。
Alternatively, you can point users to the latest DirectX End-User Runtime which includes all components, but it is a large package. This is mostly useful for scenarios in which having the SDK is not necessary, such as setting up an artist’s computer or download-only games for which users are accustomed to fetching additional components.
你也可以告诉用户下载最新的DirectX 终端用户运行库,它包含了所有组件。但它是一个很大的文件包。这是针对仅有SDK还不能满足用户要求的情况,比如安装一个艺术家的计算机或者为那些习惯于搜集可选组件的用户下载游戏。
Internal Deployment of the Debug DirectX Runtime
The debug runtimes of the DirectX components are installed when the DirectX SDK is installed, but installing the SDK on every test computer can be painful, so design your setup process to copy the debug runtime DLLs from Program Files\Microsoft DirectX SDK\Developer Runtime\architecture\ to Windows\system32\ or to the game’s folder.
DirectX调试运行库组件在安装DirectX SDK时同时也被安装,但是在每台计算机上安装SDK也是很痛苦的事情,所以你可以考虑安装时把调试运行库从Program Files\Microsoft DirectX SDK\Developer Runtime\architecture\拷贝到Windows\system32\或者游戏目录。
However, we strongly recommend that you do not simply copy the released runtime DLLs, because it is easy to forget to remove them for the final product. Instead, put the DirectX setup files in a shared folder and run the setup silently from the shared folder.
当然,我们强烈建议不要仅仅拷贝发布的运行库DLL,因为它们可能会被忘记从最终发布程序中移除。你可以把DirectX安装文件放在一个共享目录下,并从共享目录下默认安装。
Driver for the Xbox 360 Controller for Windows
The user is expected to obtain the XInput driver for Xbox 360 controller from Windows Update or from the controller packaging. The XInput driver is included with Windows Vista.
用户需要从Windows更新程序或者控制器程序包中获得Xbox360控制器的的XInput驱动。XInput的驱动程序在Windows Vista中已经被包含。