topameng's profileQuake3 启示录PhotosBlogListsMore ![]() | Help |
|
May 27 学习directx遇到的问题1 MaxSimultaneousTextures 纹理同时叠加最大数目
device->GetDeviceCaps( &Caps );
int maxActiveTextures = Caps.MaxSimultaneousTextures; 即在 DrawPrimitive 顶点之前,最多设置的纹理数量。如果你的机器显卡较差,这个数为2,就是刚刚好支持多纹理。
如下代码所示如果MaxSimultaneousTextures < 4 将不能输出图形。注意:即使相同的纹理也算1个数量。如果做的纹理效果多于MaxSimultaneousTextures ,可以拆成多次调用DrawPrimitive 函数,达到相同效果。不过对于速度有影响 例如 quake3 最多有10次渲染之多
pd3dDevice->SetTexture( 0, g_pBackgroundTexture );
pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); pd3dDevice->SetTexture( 1, g_pWallTexture);
pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0); pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_MODULATE ); pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT ); pd3dDevice->SetTexture(2, g_pEnvTexture);
pd3dDevice->SetTextureStageState( 2, D3DTSS_TEXCOORDINDEX, 0); pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 2, D3DTSS_COLORARG2, D3DTA_CURRENT ); pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_ADD ); pd3dDevice->SetTexture(3, g_pEnvTexture);
pd3dDevice->SetTextureStageState( 3, D3DTSS_TEXCOORDINDEX, 0); pd3dDevice->SetTextureStageState( 3, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 3, D3DTSS_COLORARG2, D3DTA_CURRENT ); pd3dDevice->SetTextureStageState( 3, D3DTSS_COLOROP, D3DTOP_ADD ); pd3dDevice->SetFVF(FVF ); pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(VERTEX) ); pd3dDevice->DrawPrimitive (D3DPT_TRIANGLESTRIP, 0, 2); 2 DrawPrimitive()函数的 D3DPT_TRIANGLESTRIP 标志用的顶点第一个三角形为顺时针,第二个逆时针。。依次迭代。
例如:记住uv 顺序即可 (0,0)->(1,0)->(0,1)->(1,1)
VERTEX Vertices[] =
{
{ 0.0f, 0.0f, 0.5f, 1.0f, 0.0f, 0.0f,}, { width,0.0f, 0.5f, 1.0f, 1.0f,0.0f, }, { 0.0f,height, 0.5f, 1.0f, 0.0f, 1.0f,}, // x, y, z, rhw, tu, tv { width,height, 0.5f, 1.0f, 1.0f,1.0f,}, }; 3 获取窗口高度和宽度 IDirect3DSurface9,注意IDirect3DSurface9 Height 和 Width成员都是1。 #ifdef D3D_DEBUG_INFO这个宏时包围了这些成员。应该通过GetDesc获得表面属性,D3DSURFACE_DESC里面的height和width 才正确。
IDirect3DSurface9* m_d3dsdBackBuffer;
pd3dDevice->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&m_d3dsdBackBuffer);
//int height = m_d3dsdBackBuffer->Height; //int width = m_d3dsdBackBuffer->Width; m_d3dsdBackBuffer->GetDesc(pBackBufferSurfaceDesc)
int height = pBackBufferSurfaceDesc->Height; int width = pBackBufferSurfaceDesc->Width; m_d3dsdBackBuffer->Release(); //一定要释放。 4 创建设备时指定D3DCREATE_PUREDEVICE标志。可以参考D3DPRESENT_PARAMETERS参数说明
5 无效纹理区域 通过给纹理指定无效区域,应用程序可以对需要复制纹理的哪些子集进行优化,只有那些被标记为无效的区域才会被IDirect3DDevice9::UpdateTexture方法更新。当创建纹理时,整个纹理被标记为无效的。只有以下几种操作可以改变纹理的无效状态。
对于mipmap纹理而言,无效区域被设在最高一级的纹理上,为了最小化对mipmap纹理中每一级的纹理更新所需复制的字节数,IDirect3DDevice9::UpdateTexture方法可以扩展无效区域并沿mipmap链更新子纹理。注意子级中无效区域的纹理坐标被向上舍入,也就是说,它们的小数部分被向上取整到纹理中最近的像素。 因为每种类型的纹理具有不同类型的无效区域,所以每种类型的纹理都有相应的方法表示无效区域。二维纹理使用矩形,立体纹理使用立方体。
把以上方法的pDirtyRect或pDirtyBox参数设置为NULL会扩大无效区域并使之覆盖整个纹理。 6 固定管线怎么没有使用 SetFVF 9 关键色 int w = Get2PowerHigh(sz.cx); //即 pitch 对齐到32位置 Hello qworld TUTORIAL 3 - HELLO, QWORLD ! by SumFuka "Booyakasha !". Ok, now it's a pre-requisite that you're able to compile the qagamex86.dll - if you haven't managed that, then have a look at the previous tutorials. In this tutorial we're not actually going to print "Hello, qworld!" on the console (Boring!), we're going to modify the speed of rockets (as suggested in the id readme file). We're also going to learn a thing or two about rockets along the way. Now let's get into it.
一句话,修改之前做好备份。 Ok then, we simply copy quake3\source to quake3\mymod. Double click on quake3\mymod\q3agame.dsw - from now on, follow all the tutorials using this codebase (I made a shortcut to this .dsw file on my desktop). If you modified the "Output file name" setting correctly in the first tutorial, the .dll for mymod should compile to the quake3\mymod directory - compile the 'game' project and check this. Whenever we've finished messing around with a tutorial and want to refresh the codebase back to the original, simply copy quake3\source to quake3\mymod. You can have as many mod directories as you want... I often have more than one mod in progress at any one time... quake3\rail, quake3\cts, etc... your hard drive's the limit!
在game(服务器工程)工程中找到 g_missile.c文件。 Go to line 362 (hit Ctrl+G for an easy shortcut) and find the fire_rocket function : 到362行(我这里是644行 . quake3 1.3.2 b 源代码) Back already ? Great ! Line 372 is creates a new entity (called bolt). The G_Spawn() function creates a 'blank' entity... then next job is to flesh out all the details (what sort of entity is it ? what are the characteristics ? etc). The next 20 or so lines of code define all this stuff. Line 373-375 define the bolt to be a "rocket", and it will 'think' again in 10 seconds (time is measured in 1000'ths of a second in the quake world, thus 10000 equates to 10 second). When the rocket 'thinks' it will call the function G_ExplodeMissile. In other words, if it hasn't touched anything already, our rocket will explode after 10 seconds. This prevents our rockets flying off into outer space forever. Neat, we've discovered something about the game from looking thru the code! Let's see what else we can figure out about rockets... We can see that the rocket deals 100 damage (direct OR splash), and that the splash damage radius is 120 units. Line 391 tells us that the rocket moves at a speed of 900 units/second. There's also a whole load of constants used in this function (constants are usually in CAPS)... we can guess what most of them mean. 'ET_MISSILE' for example means 'Entitry Type: Missile' (as opposed to an item or a player).
让我们修改391行如下:按F7编译.dll 启动quake,记住设置启动参数 +set sv_pure 0(使用dll启动而不是qvm),你会发现火箭筒速度显著的变慢了 Done! That's our first tutorial. Let's keep blazing onwards... May 21 directx8 faqMicrosoft DirectX 8 开发人员常见问题
摘要:本文对与 Microsoft DirectX 8.0 版有关的常见开发问题进行解答,其中包括有关 Direct3D、DirectSound 和 DirectPlay 的章节。 目录 一般性 DirectX 开发事宜 一般性 DirectX 开发事宜我在试图编译示例时,为何得到那么多错误消息?您可能没有将 include 路径设置正确。许多编译器(包括 Microsoft® Visual C++®)包含 SDK 的一个较早版本,因此如果您的 include 路径首先搜索标准的编译器 include 目录,则您会得到不正确版本的头文件。为解决这一问题,请确保 include 路径和库路径被设为搜索 DirectX include 和库路径。另请参见 SDK 中的 dxreadme.txt 文件。如果您安装 DirectX SDK 而您又在使用 Visual C++,则可以选择让安装程序为您设置各个 include 路径。 我得到关于全局唯一标识符 (GUID) 符号重复或缺失的连接器错误,怎么办?您使用的各种 GUID 应该得到一次性定义,且只能定义一次。如果您在插入 DirectX 头文件之前用 #define 定义 INITGUID 符号,则会插入 GUID 的定义。因此,你应确保只对一个编译单元进行此类操作。这一方法的一个替代方案就是用 dxguid.lib 库进行连接,其中包含所有 DirectX GUID 的定义。 如果您使用这一方法(建议),则您永远不要通过 #define 定义 INITGUID 符号。 我能否将指针指向一个到较低版本号的 DirectX 接口?不能。DirectX 接口属于 COM 接口。 这意味着不要求将较高版本号的接口从相应的低版本号导出。因此,获得到 DirectX 对象的一个不同接口的唯一安全方法就是使用接口的 QueryInterface 方法。该方法是标准的 IUnknown 接口的一部分,所有 COM 接口必须从其导出。 我能在同一应用程序中将 DirectX 8 组件和 DirectX 7 或更早的组件混用吗?您可以随意混用不同版本的“不同组件”;例如,您可以在将 DirectPlay 8 和 DirectDraw 7 用在同一应用程序中。但是,您通常不可以将“同一组件”的不同版本混用在同一应用程序中;例如,您不能混用 DirectDraw 7 和 Direct3D 8 (鉴于这些实际上是同一组件,因为 DirectDraw 已被含入 DirectX 8 的 Direct3D)。 Release 或 AddRef 方法的返回值有何含义?返回值将是对象的当前参照计数。但是,COM 规范声明,您不应依赖该返回值;该值通常仅供用于调试目的。您观察到的值可能并非所期待的,因为各种其它系统对象可能保持着对你所创建的 DirectX 对象的参照。 因此,您不应编写反复调用 Release 的代码,一直到参照计数为零,因为此时可以将对象释放,即使另一组件可能仍旧在对其进行参照。 我释放 DirectX 接口的次序很重要吗?应当没有问题,因为 COM 接口是参照计数的。 但是,在某些 DirectX 版本中,接口的释放次序有一些已知的缺陷。 安全起见,在可能的情况下,建议您以与创建时相反的次序释放接口。 智能指针是什么,我要用它们吗?智能指针是一个 C++ 模板类,旨在封装指针功能。尤其有一些标准智能指针类,用于封装 COM 接口指针。这些指针自动进行 QueryInterface,而不是进行造型,并替您处理 AddRef 和 Release。您是否使用这些指针,大体上是个人偏好。如果您的代码包含大量的接口指针复制操作,即使用多重 AddRefs 和 Releases,则智能指针可能会使您的代码更加简洁和不易出错。否则,不用也罢。Visual C++ 包含一个标准的 Microsoft COM 智能指针,是在 "comdef.h" 头文件中定义的(请在帮助中查找 com_ptr_t)。 我在调试 DirectX 应用程序时遇到问题,能提示一下吗?调试 DirectX 应用程序时最常见的问题就是试图在 DirectDraw 表面被锁定时进行调试。这一情形会在 Microsoft Windows® 9x 系统上导致 "Win16 Lock" ,因此而无法绘制调试窗口。在锁定表面时指定 D3DLOCK_NOSYSLOCK 旗标,通常会消除该现象。Windows 2000 没有这一问题。在开发一个应用程序时,最好运行调试版本的 DirectX 运行时(在安装 SDK 时进行选择);该版本进行某些参数证实,并将一些有用的消息输出到调试程序的输出窗口。 如何正确地检查返回代码?使用 SUCCEEDED 和 FAILED 宏。 DirectX 方法可以返回多个成功和失败代码,因此一个简单的 "==D3D_OK" 或类似的测试结果不总是够用的。 DirectDraw 有何变化?DirectDraw 的大多数功能现已被含入新的 Direct3D8 接口。编制单纯 2D 应用程序的开发人员可能会希望继续使用旧的 DirectX 7 接口。对于编制带有某些 2D 元素的 3D 应用程序的开发人员,鼓励其使用 Direct3D 替代程序(例如点对象和公告牌纹理),因为这会改善性能和灵活性。 我如何禁用 ALT+TAB 以及其它的任务切换功能?请切勿这样做。 有什么值得推荐的对 COM 进行解释的书吗?Inside COM (《COM 内幕》),Dale Rogerson 著,Microsoft Press 出版,其中对 COM 进行了很好的介绍。如要详细考察 COM,Essential COM (《COM 精解》),Don Box 著,Longman 出版,这本书也很值得推荐。 有什么关于一般性 Windows 编程的书吗?很多。但笔者认为值得推荐的书有:
Direct3D一般问题我在何处可以找到有关 3D 图形技巧的信息?关于这一主题的标准书是 Computer Graphics: Principles and Practice (《计算机图形:原理与实践》),Foley, Van Dam 等著;对于任何想要了解几何、光栅化以及照明技巧的人来讲,这都是一个宝贵的资源。comp.graphics.algorithms 新闻组的 FAQ (“常见问题解答”)也包含有用的资料。 Direct3D 能够仿真硬件未提供的功能吗?这要依具体情况而定。Direct3D 具有一个特性齐全的顶点处理流水线(包含对定制顶点着色器的支持)。但是,没有为像素级操作提供任何的仿真功能;应用程序必须检查相应的帽位,并使用 ValidateDevice API 来确定是否支持。 Direct3D 包含有软件光栅器吗?没有。Direct3D 现在支持插件式软件光栅器。但是,目前并不默认提供任何软件光栅器。 Direct3D 几何代码使用 3DNow! 和/或 Pentium III SIMD 指令吗?使用。 Direct3D 几何流水线有多个不同的代码路径(具体取决于处理器类型),并将使用 3DNow! 或 Pentium III SIMD 指令所提供的特殊的浮点操作(如果这些指令可用的话)。其中包括定制顶点着色器的处理。 我如何防止透明的像素被写到 z 缓冲区?您可以借助高于或低于某一给定门限的 alpha 值来将像素滤除。您通过描绘状态 ALPHATESTENABLE、ALPHAREF 和 ALPHAFUNC 来控制这一操作。 模板缓冲区是什么?模板缓冲区是一个记录每个像素信息的附加的缓冲区,很象一个 z 缓冲区。 实际上,该缓冲区就驻在 z 缓冲区的某些位中。常见的模板/z 缓冲区格式为 15 位的 z 和 1 位的模板,或 24 位的 z 和 8 位的模板。在描绘多边形时,可以针对每个像素,对模板的内容进行简单的算术操作。例如,可以增加或减少模板缓冲区,或在模板值没能通过一项简单的比较测试时,拒绝像素。可以将帧缓冲区的一个区域标出,然后只对标出(或未标出)的区域进行描绘,上述操作对于此类效果十分有用。各种体积效果就是很好的例子,比如阴影量。 我如何使用模板缓冲区来描绘阴影量?这一效果以及其它体积模板缓冲区效果的关键在于模板缓冲区和 z 缓冲区之间的交互作用。带有阴影量的场景是分三个阶段描绘的。首先,照常使用 z 缓冲区来描绘没有阴影的场景。然后,在模板缓冲区中将阴影标出,如下所示。使用不可见的多边形绘制阴影量的正面,其中 z 测试被启用,而 z 写入被禁用,且在每有一个像素通过 z 测试时,就将模板缓冲区增加一次。以同样方式描绘阴影量的背面,但是要减少模板值。 现在,请考虑单独一个像素的情形。假设摄像机不在阴影量中,场景中的相应点就有有四种可能性。如果从摄像机到点的光线不与阴影量相交,则不会绘制任何的阴影多边形,而模板缓冲区依旧为零。否则,如果点在阴影量的前面,则阴影多边形会被输出 z 缓冲区,而模板依旧保持不变。如果点位于阴影量下面,则会描绘同样多的正面阴影,而模板为零,即增加的次数与减少的次数一样多。 最后一种可能性就是点位于阴影量中。在这种情况下,阴影量的背面会被输出 z 缓冲区,但正面则不然,因而模板缓冲区会为非零。结果就是,帧缓冲区位于阴影中的一些部分具有非零的模板值。最后,要实际描绘阴影,整个场景会被一个 alpha 混色的多边形集充溢一遍,其中仅模板值非零的像素受到影响。在随 DirectX SDK 一起提供的 "Shadow Volume" 示例中有关于该技巧的一个示例。 Texel (特塞尔)对齐规则是什么?我怎样才能得到一一映射?这一点在 DirectX 8 文档中得到了全面的解释(在文章标题 Directly Mapping Texels to Pixels(直接将 Texel 映射到像素)下)。 但是总而言之,您应将屏幕坐标偏移一个像素的 –0.5,以便正确地与 texel 对齐。 大多数的插卡正确符合对齐规则,但是有一些较老的插卡或驱动程序则不然。要解决这些问题,建议您最好与相关的硬件厂商取得联系,请求得到更新过的应驱动程序或其所建议的变通办法。 D3DCREATE_PUREDEVICE 旗标有何用途?如果在创建设备时指定了 D3DCREATE_PUREDEVICE 旗标,则 Direct3D 将创建一个“纯粹”的设备。这禁用 Get* 族类的方法,并使顶点处理仅限于硬件。这使得 Direct3D 运行时能够进行某些优化,以提供到驱动程序的最佳路径,而不必跟踪那么多的内部状态。也就是说,您使用 PUREDEVICE 时可以见到一定的性能优势,但却牺牲了某些便利条件。 我如何使用颜色键控?DirectX 8 并不支持颜色键控。您应当换用 alpha 混色/测试,大体上这是一个更加灵活的技巧,没有与颜色键控相关的一些问题。 我如何枚举多监视器系统中的所有显示设备?与其它的枚举功能相同,该功能已从基于回调变为由应用程序借助 IDirect3D8 接口的各种方法来进行简单的反复。调用 GetAdapterCount 来确定系统中显示适配器的数目。调用 GetAdapterMonitor 来确定适配器所连接的物理监视器(该方法返回一个 HMONITOR,您然后就可以在 Win32 API GetMonitorInfo 中使用该值,以确定关于物理监视器的信息)。确定某一具体显示适配器的特征,或在该适配器上创建一个 Direct3D 设备,简单到在调用 GetDeviceCaps、CreateDevice 或其它方法时,通过替代 D3DADAPTER_DEFAULT 来传递相应的适配器编号。 几何(顶点)处理D3DVERTEX 等等顶点类型有何变动?不再显式支持“预罐装”的顶点类型。多重顶点流系统允许对顶点数据进行更加灵活的装配。如果您想使用其中一个“传统”的顶点格式,则您可以建立一套相应的 FVF 代码。 我对顶点流不大清楚,其工作原理如何?Direct3D 对从一个或多个顶点流馈入流水线的每个顶点进行组装。只有一个顶点流时,就对应于 DirectX 8 以前的老模型,即顶点来自单独一个源。借助 DirectX 8,不同的顶点组件可以来自不同的源;例如,一个顶点缓冲区可能含有位置和法线,而另一个则含有颜色值和纹理坐标。 顶点着色器是什么?顶点着色器是一个用于处理单一顶点的过程。这是借助一种类似于汇编的简单语言来进行定义的,由 D3DX 实用程序汇编为一个 Direct3D 接受的令牌流。顶点着色器接受单独一个顶点和一组常量值的输入,并输出一个顶点位置(在剪贴空间),还可能输出一组用于光栅化的颜色和纹理坐标。请注意,在您有一个定制的顶点着色器时,顶点组件就不再有任何由 Direct3D 施加给它们的语义,而顶点就只是由您所创建的顶点着色器进行解释的任意数据。 顶点着色器进行透视划分或剪裁吗?不。顶点着色器在已变换的顶点位置的剪贴空间输出一个纯系坐标。透视分割和剪裁是由后着色器自动进行的。 我能借助顶点着色器生成几何图形吗?顶点着色器无法创建或消灭顶点;其一次只对单一顶点进行操作,即作为输入接收一个未经处理的顶点,而输出单独一个经过处理的顶点。因此可以将其用于操作已有的几何图形(应用变形或进行外观变换操作),但实际上无法生成新的几何图形。 我能将一个定制的顶点着色器应用到固定功能几何流水线(或者进行相反的操作〕吗?不能。您必须选择其一。如果您正在使用一个定制的顶点着色器,则您负责进行整个顶点变换操作。 如果我的硬件并不支持定制的顶点着色器,我可以使用吗?可以。Direct3D 软件顶点处理引擎完全支持定制的顶点着色器,且性能指标出奇的高。 我如何确定硬件是否支持我的定制的顶点着色器?能够硬件支持顶点着色器的设备被要求填充 D3DCAPS8::VertexShaderVersion 字段,以指示其所支持的顶点着色器的版本级别。所有声称支持某一级别的顶点着色器的设备,必须支持所有合法的顶点着色器,这些顶点着色器符合针对该级别或较低级别的规范。 有多少个常量寄存器可以用于顶点着色器?要求支持 DX8 顶点着色器的设备至少支持 96 个常量寄存器。设备的支持能力可能会超过这一最低数目,且可以通过 D3DCAPS8::MaxVertexShaderConst 字段进行报告。 我可以在带有不同纹理坐标的顶点之间共享位置数据吗?该情形的一个通常示例就是一个立方体,其中您想为每个面使用一个不同的纹理。很不幸,答案是不行;目前还还不能独立索引每个顶点组件。即使是多顶点流,也是所有的顶点一起索引。 在我提交一列带索引的原语时,Direct3D 是处理缓冲区中所有的顶点,还是只处理我索引过的顶点?在使用软件几何流水线时,Direct3D 首先转换您所提交的范围中的所有的顶点,而不是“根据要求”按照索引对其进行转换。这对于密集数据(即其中使用了大多数的顶点)效率更高,尤其是在可以使用 SIMD 指令时。如果您的数据比较松散(即很多顶点未被使用),则您可能需要考虑重新排列您的数据,以避免多余的转换。在使用硬件几何加速时,顶点经常是根据需要进行转换的。 索引缓冲区是什么?索引缓冲区与顶点缓冲区极其类似,但其包含的是用于 DrawIndexedPrimitive 调用的索引。强烈建议您尽可能使用索引缓冲区,而不要使用原始的由应用程序分配的内存,其道理与顶点缓冲区相同。 我注意到 32 位的索引现在是一种支持类型;我可以将其用在所有的设备上吗?不可以。你必须检查 D3DCAPS8::MaxVertexIndex 字段,以确定设备所支持的最大索引值。该值必须大于 216-1 (0xffff) 才能支持 D3DFMT_INDEX32 类型的索引缓冲区。另外请注意,某些设备可能支持 32 位的索引,但其所支持的最大索引值却小于 232-1 (0xffffffff);这样,应用程序必须遵从设备所报告的限制。 将多重顶点流用于固定功能流水线有何限制?固定功能流水线要求每条顶点流水线是一个严格的 FVF 子集,即根据一个完整的 FVF 声明预定的。 另外请注意,您必须遵从 D3DCAPS8::MaxStreams 字段所报告的流水线数目的限制(现在的许多设备和/或驱动程序仅支持单一流水线)。 性能调谐我如何能够改善我的 Direct3D 应用程序的性能?在优化性能时,需要考察下列几个关键问题:
状态更改可能依旧很昂贵,但使用状态宏至少会有助于降低部分成本。 我应当使用哪些基本类型(条形、扇形、列表等)?在真实数据中遇到的许多网格,都具有多个多边形共享顶点的特性。为将性能最大化,最好将所转换的顶点中的重复率降低,并横跨总线将其发给描绘设备。使用简单的三角列表根本实现不了任何顶点共享,因而这是最不理想的方法。这一点已很清楚。然后所要作的选择就是使用条形和扇形(暗示多边形之间的具体连接关系),还是使用索引列表。在数据自然归入各种条形和扇形的情况下,这些就是最为合适的选择,因为发给驱动程序的数据被降至最低。但是,将网格分解条形和扇形经常会造成大量分离块,暗示有大量的 DrawPrimitive 调用。因此,最富效率的方法通常是使用带三角列表的单独一个 DrawIndexedPrimitive 调用。使用索引列表的另一个优势就是,这在连续三角形仅共享单独一个顶点时也有益处。总而言之,如果您的数据自然归入各种较大的条形和扇形,就使用条形和扇形,否则就使用索引列表。 如果我要生成动态数据,怎样才算是较好地使用顶点缓冲区了呢?
Direct3DX 实用程序库D3DX 图象文件加载器函数支持哪些文件格式?D3DX 图象文件加载器函数支持 BMP、TGA、PNG、JPG、DIB、PPM 和 DDS 文件。 D3DX 中的文字描绘函数好象失效,我的操作有什么问题吗?使用 ID3DXFont::DrawText 功能时的一个常见错误就是为颜色参数指定一个零 alpha 组件,从而导致完全透明(即不可见)的文本。对于完全不透明的文本,请确保色彩参数的 alpha 成分完全饱和 (255)。 对于字体描绘,我应当使用 ID3DXFont 还是 SDK 框架 CD3DFont 类?ID3DXFont 类能够处理字间距,因为它使用 GDI 来绘制字符串。这可能会有点慢,因为每次均需要调用 GDI。 CD3DFont 设计用于加速和使用纹理化基本类型来绘制字符。它只能处理简单字体,并不支持 ID3DXFont 可用的全套格式选项,但适用于简单而快速的显示,诸如帧速率计数等等。 对于产品代码,您可能需要实施您自己的字形描绘功能,即借助纹理化基本类型和/或基于 GDI 的方案(带避免重新绘制的缓存功能)。 DirectSound我的应用程序启动时,为何为发出一阵净噪声?我注意到其它应用程序也有这个问题。您可能安装了调试用 DirectX 运行时。运行时的调试版本用静噪声填充缓冲区,以便帮助开发人员捕捉未经初始化缓冲区的缺陷。您无法保证 DirectSound 缓冲区在创建后的内容;尤其是您无法将缓冲区清零。 DirectPlay我如何确保我的游戏将能够与各种 Network Address Translator (网络地址转换器,NAT) 和 Internet Connection Sharing (Internet 连接共享,ICS)设置正常工作?NAT 和 ICS 是较为复杂的主题,在 MSDN 上的另一篇文章中有更详尽的论述。但是,下列提示可以作为很好的一般性指导:
有关点对点游戏、将服务器驻于 NAT 后面的事宜,以及针对各种不同的 Windows 操作系统上的 ICS 的具体建议,请参考更详尽的文档。 DPNSVR 是作什么用的?DPNSVR 是一种用于枚举请求的转发服务,消除了多个 DirectPlay 应用程序在端口使用上的冲突所导致的各种问题。使用 DPNSVR 使得 DirectPlay 能够自动选择要使用的端口,同时又允许客户端对您的游戏进行枚举。默认为,DirectPlay 会使用 DPNSVR,因为这通常为应用程序提供了最大的灵活性;但是,您可以将其禁用,方法是在创建您的会话时指定 DPNSESSION_NODPNSVR 旗标。如果客户端使用 DPNSVR 端口来枚举主机,而主机又使用自己的端口来作出响应的话,使用 DPNSVR 可能会导致客户端一侧的 NAT 发生问题;NAT 可能会拒绝将数据包转递给客户端,因为数据包不是来自请求被发往的同一端口。 IDirectPlay8LobbyClient::Initialize 为何返回 DPNERR_NOTALLOWED?DirectPlay 不允许每个进程有一个以上的前端客户端或应用程序,因而试图创建多个客户端会导致返回这一错误。 May 18 Quake3 控制台命令3"bot_nochat" - Basicaly, this command lets you turn off those automated taunts that the bots say constantly. I presume there will be a minor framerate increase but I am not sure. Once you tire of the taunts set this to 1. "cg_centertime" - This command lets you limit how long the "you fragged <playername>" message appears when you frag someone. The default setting is 3, but the recommended setting is 1. Setting this command to 0 means no message is displayed. This command works only is server side only. "cg_drawAttacker" - Displays the opponent's name when you face them. Useful for TDM or CTF, but a hinderence to your visibity. Optimal setting is disabled. "cg_drawRewards" - Displays rewards earned in the current battle (excellent, impressive etc...). Optimal setting is disabled. "cg_draw3dIcons" - When turned on, all icons in the HUD will be displayed in 3D. Optimal setting is disabled. "cg_drawGun" - This command let's you toggle between displaying, or not displaying the gun. Many people like to have a gun on screen at all times as it helps distinguish which weapon you currently have selected. Disabling gives the advantage of not having a gun blocking your view. Especialy helpful when using the railgun. Framerate is also noticably higher with this disabled. "cg_gibs" - When activated, characters will "gib" (blow into pieces) with a particulaly viscious shot. "com_blood" must be activated for this to take effect. This looks pretty, and can be satisfying but can slow down gameplay in large scale deathmatches. When turned off, FPS gain is around 1 - 5 FPS depending on the amount of action going on. "cg_marks" - With this enabled, every time a player shoots at the scenary, a mark is left behind. These marks will stay for approximataly 20 seconds. Because of this, noticable framerate loss occurs in large scale deathmatches. Optimal setting is disabled. "cg_brassTime" - With this enabled, when a gun is fired, the shells ejected are thrown and discarded in the air for added realism. Optimal setting is disabled. "cg_bobup / cg_bobroll / cg_bobpitch" - These 3 settings are used to create a more realistic walk or run for your character. For example, when you are slowly walking in a crouch position, you will shuffle side to side to give your character more realistic movement. The default for all settings is 0.0025 but I prefer to turn these settings to 0 as its gives a more fluid movement and prevents possible motion sickness ;-) "cg_fov" - This setting lets you widen or shrink your viewing area or field of vision. The default is 90 but feel free to increase this slightly for a sly advantage (I wouldn't put it over 110 though as the image looks trippy). Unfortunately, because of the larger viewing area, the CPU is under more stress so bear in mind you may get a slightly lower framerate. "cg_shadows" - There are 3 shadow modes - 1, 2, and 3. 1 creates round, unrealistic shadows under the feet of all characters. 2 creates incredibly lifelike shadows, but at a huge performance hit. 3 creates suitably lifelike shadows but again at the cost of some performance. For setting 2, you must ensure your graphics card supports hardware stencil buffing, and r_stencilbits must be set to 8 at the console. The optimal setting is 0 (no shadows) "cg_simpleItems" - With this on, all items and pickups will be displayed in 2D rather than 3D. This is especially helpful for people with slower machines as it can give noticable framerate increase. "com_blood" - Displays blood when a character is shot with this turned on. Additionaly, characters create a small gib when hit hard at the cost of no performance. Keep this setting on and turn "cg_gibs" off. "com_blindlyLoadDLLs" - If you use the Speed Dll's, you may get the warning message telling you that it is unsafe to use them. This message is quite anoying, as it pops up when you load and finish a level. Set this to 1 to disable the warning. "com_hunkmegs" - Only of use if you have more than 64 MB RAM. This setting alocates more system memory to Quake 3 for player models. If you have 128 MB RAM, set this to 96; if you have 96 MB RAM, set this to 64; if you have 192 MB RAM set this to 128; and finaly if you have 256 MB RAM, then set this to 170. You could try higher numbers but your system could become unstable. "r_picmip" - This accounts for overall texture and image quality, with 0 being the best, and higher numbers being progressively worse. This setting is a major player in having a high and consistant framerate. A setting of 1 is suitable for most computers as it ensures excellent image quality with a solid, consistant framerate. Interestingly, many people prefer to use a setting of 5 as it improves visibity between players and background textures, as well as makes weapons such as the LG easier to use. "r_drawsun" - This setting I believe creates shadows in relation to where thet are towards the sunlight. Of course, you will need shadows enabled. I do not think there is a drop in FPS so if you like shadows on, then set this to enabled. "r_gamma" - Brightens/Darkens the screen. This setting varys according to the brightness on your monitor. Default is 1 but this can be set lower to darken image (eg: 0.79010) or it can be increased to brighten the image (eg: 1.10000). Experiment to find the optimal amount. "r_mapOverBrightBits" - This is a setting which controls how bright the scenary, textures and objects are. Lately, I have found this is the best way to achieve optimal image quality. This setting defaults at 2 but I would recommend setting this to 3. Secondly, lower the r_gamma setting to 0.82000 and start a new game. You should either find it too bright or too dark - adjust the gamma accordingly. I have found that setting this setting to 3 results in far more clarity and detail in the textures. "r_intensity" - As the name suggests this setting intensifies the whole image. Default is 1 and this is recommended for most users. If you play in picmip 5 mode, set this to around 1.4 to make the characters stand out more against the background. "r_finish" - This is the "Sync every frame" command in the game options. It Improves response between the keyboard/mouse and the onscreen action. You set this to 1 to stop occasional input frustration. However, you may experience slight framerate loss. "r_railWidth / r_railCoreWidth / r_railSegmentLength" - These settings adjust the way the railgun blast looks. There are so many possible configurations but here is my personal favourite: seta r_railWidth "3" Thanks to VyP3rR. "r_roundImagesDown" - Smoothes and rounds textures when they need to be resized producing slightly inferior visuals. Default is recommended. (Please note: q3dm16 will crash to the desktop if this setting is less than 1) "r_swapInterval" - Enabling this setting eliminates the slight screen ripping that appears when your framerate exceeds your monitors refresh rate. Bear in mind that although the FPS loss is not large, I found there to be a slight lag between mouse/keyboard to the on screen action. Bear in mind that if you have disabled vsync externaly (perhaps through your graphics drivers tools facilty) then this setting is bypassed. "r_detailTextures" - This is enabled by default and produces more detailed textures if available by that particular texture. With this disabled, you get slight framerate increase. "r_colorbits" - Choose between rendering colours in 16 BIT or 32 BIT. 32 BIT colour renders 16.7 million individual colours compared to 16 BIT's 65,000 but can be a large burdon on computer resources. Optimal setting is 16 BIT for framerate and 32 BIT for visuals. Be aware that your video hardware must support 32 BIT colour for you to use it. "r_texturebits" - Similar to colourbits. However, if you run at high resolutions (1024x768 or above) this can cause texture corruption in 32 BIT colour mode. You must also have a card that supports 32 BIT colour. Optimal setting is 16 BIT for framerate and 32 BIT for visuals. Be aware that your video hardware must support 32 BIT colour for you to use it. "r_dynamicLight" - With this enabled, the flare from a weapon projectile will illuminate the surrounding area creating added realism. Be aware that enabling this results in noticable framerate loss. "r_vertexLight" - When enabled, textures use no additional lightmaps for lighting effects. On a slow machine, this will speed things up considerably but the result is inferior visuals. Other benefits of enabling vertex lighting include better visibilty between players and textures, especialy when using r_picmip 5. "r_lodBias" - Produces more rounded images in the character model, objects, and pickups the lower this setting is. Through benchmarking, I have found that the default (0) is the best balance between framerate and image quality. I could see no noticable visual improvement when setting this into the low minuses (the valid range is -2 to 2) but the framerate was lower. Recommended setting is 0 (default) "r_smp" - If you have two CPU's, Windows NT or 2000, and have a graphics card AND driver which supports SMP, then you can benefit from a more sustained Framerate, which may also be noticeably higher. The default of course is 0, but if your system fulfils the above requirements then ensure you set this to 1. "r_subDivisions" - This is a texture setting which when set low, produces a better image with more curves and less graphical inacuracies. The maximum setting I would recommend is around 100 depending on the map. I like this set at 4 but feel free to experiment for the best comprimise between image quality and framerate. "r_lodCurveError" - This setting determines how close you have to be towards a texture before it clips and loses its curves. I recommend a setting between 400 - 800 depending on the power of your machine. "r_stencilBits" - This is a hardware dependent graphical setting which creates more realistic textures. Be sure to set this to 8 if your graphics card has a hardware stencil buffer. Be aware that the screen may darken with this enabled. Be sure to alter the gamma accordingly. "s_musicVolume" - Self explanatary. Bear in mind that turning off the music doesn't result in such a noticably higher framerate as in Quake 2, though the optimal setting is still disabled "s_loadas8bit" - With this set to 1, all the sounds in the game will be forced to be played with half the available sound memory. This increases framerate somewhat. "sv_pure" - Controls whether the game should be played in pure (as the developer intended) or unpure (which means that certain mods can be used). "vm_cgame / vm_game / vm_ui" - These settings MUST be set to 0 for the speed dll's to function correctly. If any of these are set to 1 in your config, then you are losing performance, so change them immediately. 1.25+ new console commands: "cg_scorePlums" - This controls whether the "scoreplum" floats above your victim when they are fragged. Not really a necessity so set this to 0. "cg_smoothClients" - When g_smoothClients is enabled on the server and you enable cg_smoothClients then players in your view will be predicted and will appear more smooth even if they are on a bad network connection (LPB's should love this feature when playing laggy HPB's). However small prediction errors might appear. "pmove_fixed" - Think of this as ID's answer to the 125Hz mod. Basicaly, with this enabled, all players will move at the same frequency (which can be changed using the pmove_msec variable) regardless of the clients framerate. The advantages include even jump physics and movement for all players. The downside is some people have found slight stuttering with this enabled (although through my experience, it is negible). If you are playing online, the server must have first enabled this option before you can use it. "pmove_msec" - Sets the time in milliseconds between two advances of the player physics. Default is 8. "r_inGameVideo" - This feature lets you view small pre-recorded videos that the map maker created to be viewed in game. This has only been implemented in Team Arena maps as I write this, but no doubt standard Q3A levels will be including such features imminently. Be aware that enabling this can have a large impact on framerate, so te optimal setting is to disable. "s_doppler" - A neat sound feature, which produces a "dopplar" effect when a projectile from a rocket sweaps past you. Disabling gives a minor framerate increase, but I like the effect and thus keep it enabled. "headmodel" - changes only the head of the model to another model. Example: If you are playing as the Grunt model, /headmodel "sarge" will stick Sarge's head on Grunt's body. Selecting a new model will load both the model and its matching head. "team_model" - changes to a model that will only be used during team game play. "team_headmodel" - changes head model to a head that will only be used during team game play. Internet connection commands: "cg_lagometer" - This is a very useful utility which lets you monitor your connection on-line. With this enabled while you are playing on-line you will see 2 bouncing lines. The first line displays the conjunction between your graphics card updating the frames in sync with the gameworld updates recieved from the server. Idealy, this should be a straight blue line. If it has bouncing yellow spikes then your display will stutter and be more difficult to view. To combat this, first ensure you have followed my tweaking techniques and then change your snaps setting. Usually, this means lowering it by until your screen is stable and you have a nice flowing blue line in your lagometer. The second line shows if packets are being recieved from the server. This should be green. If it is yellow or red, try increasing your rate or try lowering your snaps. If this does not help, you may be on a bad server so try another. The height of the line is dependent on your current ping. "cl_timenudge" - This interesting setting is identical to the pushlatency setting in Half-Life. This is very user determined and impossible to judge for every machine and every connection. I find this setting works well if you set the cl_timenudge setting to around -30 the ping you currently have with the server. If you don't like the way it affects your timing, then leave it at default (0). Use this command in conjunction with the lagometer for best results. "rate" - This setting controls packets to ensure a good connection. If you have an ISDN modem (128K) then this can be set to around 8000. If you have a 56K modem then this should be around 3000-4500 depending on your connection speed. If you are on a LAN or have ADSL modem, then this can be around 24000 or perhaps even higher. Experimentation is required to find the optimal setting. "snaps" - This is possibly the most important setting for getting a good connection. As everyone knows, in Quake 2, your gameworld updates depended on your current FPS so slower computers were at a disadvantage. Now, in Quake 3, your snaps setting determines how many updates you recieve from the server. 56K modems should have a setting of around 20. ISDN modems (128K) should be around 40 as should any other fast connection devices (LAN, T1 etc....). Remember to read my cg_lagometer section for tips on "snaps". "cl_packetdups" - As the name suggests, this setting is used to send multiple packets to compensate for lost packet drops. This setting should be set at 1 unless you have a VERY good connection in which case set this to 0. Use the lagometer to decide on which setting to use. "cl_maxPackets" - This setting puts a limit on the maximum amount of packets that can be sent to the server via the client. This setting is useful for people with slower modems. The default setting is 30 (comparable to a 56K modem), but lower this if you have a 33.6K modem or less, and higher this setting if you have an ISDN or higher modem. "com_maxFPS" - This command limits your maximum FPS. Why you would want to do this? 2 reasons. Firstly, because it will help stop the server from having lag confusion when your frame rate has a sudden rise or fall. Run a timedemo, collect your average FPS and use that as the limit for when you play on-line. Another important aspect of this setting is that your framerate determines how high you can jump. This is why getting the max_FPS setting right is so important. Have a play around until you find a figure that allows you to make the DM13 MH jump. Once you have one (try to get it as high as it can go) stick with it. Unfortunately, playing online could make achieving maximum height tricky once again. Personaly, I found that setting com_maxFPS to 83 offline and 63 online the best solution for making those long, tricky jumps. Of course, this may be totaly different for your machine so play around. "cg_deferPlayers" - A nice simple setting. With this set to 1, new player skins will only be loaded when you are either fragged or when you look at the scoreboard. With this set to 0, new player models are loaded as soon as a new player joins the server. I like this set to 1 as the screen could stutter at a potentialy crucial time meaning frustration. "cg_predictItems" - This setting determines whether the server or the client decides on whether a weapon has being collected. A setting of 1 means the client decides, and a setting of 0 means the server decides. Setting it to 1 (default) makes gameplay flow quicker for HPB's, but can cause confusion as to whether the item was picked up or not. Setting it to 0 means the server will always decide, reducing the chance of errors, but this can cause slight ldelay after the item has been picked up. I keep this set at 0 to prevent any unneccessary confusion. "cg_forceModel" - If you want to use only the same model or skin throughout, then set this to 1. Every character (human, or bot) will have the same character model as yourself. However, if you are using a custom model with a large polycount, this can hinder performance slightly. Default is 0. May 17 如何提高程序效率1 使用循环展开,对于循环内部只有一条语句可以采用循环展开来提升速度.
2 对于2的倍数除法使用&运算,如 30 除 4 的余数为 30 & 3,30 类最大的4的倍数为30 & ~3.一个数是否为2的幂 n & 1. 而判断一个变量中含有多少个1可以 3 对于一些只需要初始化一次的函数内部变量可以声明为static类型 4 对于过大的switch语句块,可以采用表驱动法,对于switch如果条件过多,后面的条件分支必须等待前面判断完毕才能执行。而采用表驱动可以直接跳转到要执行的语句 5 ^= 异或操作,切换某位状态由0到1,或者由1到0. A ^= 0x00010 ,迅速切换第2位 . 这样比 true ,false 之类的切换要快。写法也简单
6 ! 操作,如 strcmp 判断两个字符相等返回0,而不是 true ,而0值确对应 false. 和0比较相对于其他比较要快些。所以 if(!strcmp(a,b)),注意: ! 对于大于 0 的数返回 0,!0 怎返回 1
7 ~= 判断1个dword 变量x有多少个位为1。 int c=0; for(;x~= x-1;c++); 最后c 为 x 含有1 的个数。
熟练应用位操作有利于提高程序速度
D3DPRESENT_PARAMETERS 参数说明struct D3DPRESENT_PARAMETERS{
UINT BackBufferWidth; UINT BackBufferHeight; D3DFORMAT BackBufferFormat; UINT BackBufferCount; D3DMULTISAMPLE_TYPE MultiSampleType; DWORD MultiSampleQuality; D3DSWAPEFFECT SwapEffect; HWND hDeviceWindow; BOOL Windowed; BOOL EnableAutoDepthStencil; D3DFORMAT AutoDepthStencilFormat; DWORD Flags; UINT FullScreen_RefreshRateInHz; UINT PresentationInterval; }; BackBufferWidth和BackBufferHeight:后备缓冲的宽度和高度。在全屏模式下,这两者的值必需符合显卡所支持的分辨率。例如(800,600),(640,480)。 BackBufferFormat:后备缓冲的格式。这个参数是一个D3DFORMAT枚举类型,它的值有很多种,例如D3DFMT_R5G6B5、D3DFMT_X8R8G8B8为游戏后备缓冲常用格式,这说明后备缓冲的格式是每个像素16位,其实红色(R)占5位,绿色(G)占6位,蓝色(B)占5位,为什么绿色会多一位呢?据说是因为人的眼睛对绿色比较敏感。DX9只支持16位和32位的后备缓冲格式,24位并不支持。如果对这D3DFORMAT不熟悉的话,可以把它设为D3DFMT_UNKNOWN,这时候它将使用桌面的格式。 BackBufferCount:后备缓冲的数目,范围是从0到3,如果为0,那就当成1来处理。大多数情况我们只使用一个后备缓冲。使用多个后备缓冲可以使画面很流畅,但是却会造成输入设备响应过慢,还会消耗很多内存。 MultiSampleType和MultiSampleQuality:前者指的是全屏抗锯齿的类型,后者指的是全屏抗锯齿的质量等级。这两个参数可以使你的渲染场景变得更好看,但是却消耗你很多内存资源,而且,并不是所有的显卡都支持这两者的所设定的功能的。在这里我们分别把它们设为D3DMULTISAMPLE_NONE和0。 可以通过CheckDeviceMultiSampleType 来检测当前装置是否支持某个抗锯齿类型 typedef enum _D3DMULTISAMPLE_TYPE { D3DMULTISAMPLE_NONE = 0, D3DMULTISAMPLE_2_SAMPLES = 2, D3DMULTISAMPLE_3_SAMPLES = 3, D3DMULTISAMPLE_4_SAMPLES = 4, D3DMULTISAMPLE_5_SAMPLES = 5, D3DMULTISAMPLE_6_SAMPLES = 6, D3DMULTISAMPLE_7_SAMPLES = 7, D3DMULTISAMPLE_8_SAMPLES = 8, D3DMULTISAMPLE_9_SAMPLES = 9, D3DMULTISAMPLE_10_SAMPLES = 10, D3DMULTISAMPLE_11_SAMPLES = 11, D3DMULTISAMPLE_12_SAMPLES = 12, D3DMULTISAMPLE_13_SAMPLES = 13, D3DMULTISAMPLE_14_SAMPLES = 14, D3DMULTISAMPLE_15_SAMPLES = 15, D3DMULTISAMPLE_16_SAMPLES = 16, D3DMULTISAMPLE_FORCE_DWORD = 0x7fffffff
} D3DMULTISAMPLE_TYPE; //type 为以上的枚举值 D3DMULTISAMPLE_TYPE type; int quality; //获取相对于type的最大质量等级(设置type抗拒值类型时,设置的质量等级只能小于这个数) //m_d3dBackFmt 为后备缓冲格式,m_bWindowed 是否为窗口模式, m_pD3D9->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,m_d3dBackFmt, m_bWindowed,type,&quality ); SwapEffect:交换缓冲支持的效果类型,指定表面在交换链中是如何被交换的。它是D3DSWAPEFFECT枚举类型,可以设定为以下三者之一:D3DSWAPEFFECT_DISCARD,D3DSWAPEFFECT_FLIP,D3DSWAPEFFECT_COPY。 如果设定为D3DSWAPEFFECT_DISCARD,则后备缓冲区的东西被复制到屏幕上后,后备缓冲区的东西就没有什么用了,可以丢弃(discard 是否丢弃由显卡决定,但不再等待)了。 如果设定为D3DSWAPEFFECT_FLIP,后备缓冲拷贝到前台缓冲,保持后备缓冲内容不变。当后备缓冲大于1个时使用 设定D3DSWAPEFFECT_COPY的话, 后备缓冲拷贝到前台缓冲,保持后备缓冲内容不变。当后备缓冲等于1个时使用 一般我们是把这个参数设为D3DSWAPEFFECT_DISCARD。如果想使用GetBackBuffer 获得后备缓冲内容打印屏幕画面。则不能使用DISCARD. 很怀疑用DISCARD效率会好的说法。在我的8600GT 上_COPY 明显好于DISCARD. discard 做法是再次使用后备缓冲时 new 一个新的缓冲,旧的缓冲内容遗弃,如果还有使用旧的缓冲地方,不会影响新的内容,如使用抗锯齿必须是DISCARD。这样不用等待硬件同步。不过大部分是一次Present操作。用COPY在新机器上面反倒效率好些。毕竟new 一个 1440*900 的后台缓冲也是有消耗的。(对于DISCARD 做法仅仅是猜测。不同显卡可能不同。) hDeviceWindow:显示设备输出窗口的句柄 Windowed:如果为FALSE,表示要渲染全屏。如果为TRUE,表示要渲染窗口。渲染全屏的时候,BackBufferWidth和BackBufferHeight的值就得符合显示模式中所设定的值。 EnableAutoDepthStencil:如果要使用Z缓冲或模板缓冲,则把它设为TRUE。 AutoDepthStencilFormat:如果不使用深度缓冲,那么这个参数将没有用。如果启动了深度缓冲,那么这个参数将为深度缓冲设定缓冲格式。常用值D3DFMT_24S8 (24 深度缓冲,8模板缓冲),D3DFMT_24X8(24 深度缓冲),D3DFMT_16(16深度缓冲)等等。 //深度缓存和模板缓存的象素格式,如 D3DFMT_D24S8 , 24 位表示深度,8位为模板缓存。一般不会用到32位深度:D3DFMT_32
//注意如果设置模板缓冲在Clear() 函数中也要清楚模板缓冲:设置参数 D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL
Flags:通常为0 或D3DPRESENTFLAG_LOCKABLE_BACKBUFFER。不太清楚是用来做什么的,看字面好像是一个能否锁定后备缓冲区的标记。D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL 丢弃模板缓冲区 FullScreen_RefreshRateInHz:显示器的刷新率,单位是HZ,如果设定了一个显示器不支持的刷新率,将会不能创建设备或发出警告信息。为了方便,一般设为D3DPRESENT_RATE_DEFAULT就行了。 PresentationInterval:如果设置为D3DPRENSENT_INTERVAL_DEFAULT,则说明在显示一个渲染画面的时候必要等候显示器刷新完一次屏幕。例如你的显示器刷新率设为80HZ的话,则一秒内你最多可以显示80个渲染画面。另外你也可以设置在显示器刷新一次屏幕的时间内显示1到4个画面。如果设置为D3DPRENSENT_INTERVAL_IMMEDIATE,则表示可以以实时的方式来显示渲染画面,虽然这样可以提高帧速(FPS),如果速度过快却会产生图像撕裂的情况,但当游戏完成时,帧速度一般不会过快。 Dxut 框架 ModifyDeviceSettings 函数中修改 DXUTDeviceSettings* pDeviceSettings 成员(D3DPRESENT_PARAMETERS变量) pp来修改 Quake3 控制台命令2messagemode (command) syntax: messagemode Returns the keyboard to text input for the purpose of sending messages to all players. Pressing 'ENTER' will send the message and return the keyboard to gaming functions. --------------------------------------------------------------------------------
messagemode2 (command) syntax: messagemode2 Returns the keyboard to text input for the purpose of sending messages to all players on the same team. Pressing 'ENTER' will send the message and return the keyboard to gaming functions. --------------------------------------------------------------------------------
messagemode3 (command) syntax: messagemode3 Returns the keyboard to text input for the purpose of sending messages to your current target only. Pressing 'ENTER' will send the message and return the keyboard to gaming functions. --------------------------------------------------------------------------------
messagemode4 (command) syntax: messagemode4 Returns the keyboard to text input for the purpose of sending messages to the last player to injure you only. Pressing 'ENTER' will send the message and return the keyboard to gaming functions. --------------------------------------------------------------------------------
midiinfo (command) syntax: midiinfo Reports status of MIDI control and device(s) used. --------------------------------------------------------------------------------
model (variable)(U A) syntax: model [model/skin] default: "visor/default" Sets the player model and skin. --------------------------------------------------------------------------------
modelist (command) syntax: modelist Reports all available video modes. --------------------------------------------------------------------------------
modellist (command) syntax: modellist Lists all model files loaded for the current map. --------------------------------------------------------------------------------
music (command) syntax: music [musicfile] Presumably plays a music file of some type. --------------------------------------------------------------------------------
name (variable)(U A) syntax: name [string] default: Player Sets the player name. Font color can be changed. Possible colors: 0 = Black 1 = Red 2 = Green 3 = Yellow 4 = Blue 5 = Cyan 6 = Magenta 7 = White -------------------------------------------------------------------------------- net_ip (variable)(I) syntax: net_ip [IP_address] default: localhost Allows the binding of a set IP address which is sent to the ID master server. - Kevin Crawley --------------------------------------------------------------------------------
net_noipx (variable)(I) syntax: net_noipx [0/1] default: 0 Toggles IPX network protocol. This command should be passed on the command line. 0=disables;1=enables. --------------------------------------------------------------------------------
net_noudp (variable)(I) syntax: net_noudp [0/1] default: 0 Toggles UDP/IP network protocol. This command should be passed on the command line. 0=disables;1=enables. --------------------------------------------------------------------------------
net_port (variable)(I) syntax: net_port [value] default: 27960 Specifies network server port. --------------------------------------------------------------------------------
net_socksenabled (variable)(I) syntax: net_socksenabled [0/1] default: 0 Toggles proxy and/or firewall protocol. This command should be passed on the command line. 0=disables;1=enables. --------------------------------------------------------------------------------
net_sockspassword (variable)(I) syntax: net_sockspassword [string] default: "" Sets the password on the firewall machine. This command must be passed on the command line. --------------------------------------------------------------------------------
net_socksport (variable)(I) syntax: net_socksport [value] default: 1080 Specifies proxy and/or firewall port. This command should be passed on the command line. --------------------------------------------------------------------------------
net_socksserver (variable)(I) syntax: net_socksserver [value] default: "" Specifies proxy and/or firewall server address. This command should be passed on the command line. --------------------------------------------------------------------------------
net_socksusername (variable)(I) syntax: net_socksusername [string] default: "" Sets the username on the firewall machine. This command must be passed on the command line. --------------------------------------------------------------------------------
nextdemo (variable) syntax: nextdemo [demo demoname] default: "" A string using the demo command and the filename of the next demo to load. No file extension is used. If no demo is specified by the server then no further demos will be run. Note that this cvar is unavailable until it has been set at the console or in a script file. --------------------------------------------------------------------------------
nextframe (command) syntax: nextframe [?] Unknown. See also prevframe (also unknown). --------------------------------------------------------------------------------
nextmap (variable) syntax: nextmap [mapname] default: "" A string using the map command and the filename of the next map to load. No file extension is used. If no map is specified by the server then the one specified by the currently running map will be used, if any. --------------------------------------------------------------------------------
nextskin (command) syntax: nextskin [?] Unknown. See also prevskin (also unknown). --------------------------------------------------------------------------------
noclip (command) syntax: noclip Enables noclipping mode so you can pass through world brushes. Entering the command again disables it. --------------------------------------------------------------------------------
nohealth (variable)(S A) syntax: nohealth [0/1] default: 0 Specifies if health pickups will be spawned on the map. Changes take place on the next map loaded. 0=spawn health;1=don't spawn health. --------------------------------------------------------------------------------
notarget (command) syntax: notarget Enables notarget mode so presumably bots will ignore you if they haven't seen you already. Entering the command again disables it. --------------------------------------------------------------------------------
password (variable)(U) syntax: password [string] default: "" The password required for clients to connect to the host machine. Both server and clients would need to set this. --------------------------------------------------------------------------------
path (command) syntax: path Reports the current quake3.exe search path, including .PK3 files. --------------------------------------------------------------------------------
paused (variable) syntax: paused [0/1} default: 0 Sets whether the game is paused or not. 0=disables;1=enables. --------------------------------------------------------------------------------
ping (command) syntax: ping [server] Pings a selected server. --------------------------------------------------------------------------------
play (command) syntax: play [path/.wav] Plays a .WAV file in the current game directory one time. --------------------------------------------------------------------------------
prevframe (command) syntax: prevframe [?] Unknown. See also nextframe (also unknown). --------------------------------------------------------------------------------
prevskin (command) syntax: prevskin [?] Unknown. See also nextskin (also unknown). --------------------------------------------------------------------------------
protocol (variable)(S R) syntax: protocol [value] default: 39 Sets network protocol version. Useful for backwards compatibility with servers with otherwise incompatible versions. --------------------------------------------------------------------------------
qport (variable)(I) syntax: qport [value] default: "" Sets internal network protocol port. --------------------------------------------------------------------------------
quit (command) syntax: quit Shuts down the game immediately. --------------------------------------------------------------------------------
r_allowextensions (variable)(A L) syntax: r_allowextensions [0/1] default: 1 Toggles the functions of various OpenGL extensions. 0=disables;1=enables. --------------------------------------------------------------------------------
r_allowsoftwaregl (variable)(L) syntax: r_allowsoftwaregl [0/1] default: 0 Toggles the use of the default software OpenGL driver as supplied by the Operating System platform. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ambientscale (variable)(C) syntax: r_ambientscale [value] default: 0.5 Sets the level of ambient lighting effect on entities. - badak --------------------------------------------------------------------------------
r_clear (variable)(C) syntax: r_clear [0/1] default: 0 Toggles the clearing of unrefreshed images (clears hall of mirrors effect). 0=disables;1=enables. --------------------------------------------------------------------------------
r_colorbits (variable)(A L) syntax: r_colorbits [0 to 32] default: 0 Sets color bits-per-pixel. Mutually exclusive with r_depthbits. --------------------------------------------------------------------------------
r_colormiplevels (variable)(L) syntax: r_colormiplevels [0/1] default: 0 Toggles raw RGB mipmap (texture) lighting effect. 0=disables;1=enables. --------------------------------------------------------------------------------
r_customaspect (variable)(A L) syntax: r_customaspect [0/1] default: 1 Toggles the use of a custom video mode. 0=disables;1=enables. See also r_customheight and r_customwidth. --------------------------------------------------------------------------------
r_customheight (variable)(A L) syntax: r_customheight [number of pixels] default: 1024 Defines the height of a custom resolution when r_mode is -1. Note that your hardware may not support what you select. See also r_customwidth. --------------------------------------------------------------------------------
r_customwidth (variable)(A L) syntax: r_customwidth [number of pixels] default: 1600 Defines the width of a custom resolution when r_mode is -1. Note that your hardware may not support what you select. See also r_customheight. --------------------------------------------------------------------------------
r_debuglight (variable)(C) syntax: r_debuglight [0/1] default: 0 Toggles the display of data representing the intensity of ambient light and intensity of direct light. 0=disables;1=enables. - dynamite --------------------------------------------------------------------------------
r_debugsurface (variable)(C) syntax: r_debugsurface [0/1] default: 0 Toggles the curved surfaces debugging grid on whatever curve the weapon crosshair is aimed at. Grid size determined by cm_debugsize. Grid display is also dependent on the setting r_subdivisions. 0=disables;1=enables. - dynamite --------------------------------------------------------------------------------
r_depthbits (variable)(A L) syntax: r_depthbits [0 to 32] default: 0 Sets depth bits-per-pixel. Mutually exclusive with r_colorbits. --------------------------------------------------------------------------------
r_detailtextures (variable)(A L) syntax: r_detailtextures [?] default: 1 Unknown. --------------------------------------------------------------------------------
r_directedscale (variable)(C) syntax: r_directedscale [?] default: 1 Sets the level of direct lighting effect on entities. - badak --------------------------------------------------------------------------------
r_displayrefresh (variable)(L) syntax: r_displayrefresh [value] default: 0 Sets monitor refresh rate at the resolution the game is to be run at. This command should be passed on the command line. Note this will change your desktop refresh rate at this resolution as well. --------------------------------------------------------------------------------
r_dlightbacks (variable)(A) syntax: r_dlightbacks [?] default: 1 Unknown. --------------------------------------------------------------------------------
r_drawbuffer (variable) syntax: r_drawbuffer [buffer] default: "GL BACK" Sets which buffer is drawn to. - Andy Lutomirski --------------------------------------------------------------------------------
r_drawentities (variable)(C) syntax: r_drawentities [0/1] default: 1 Toggles rendering of entities, including brush models. 0=disables;1=enables. --------------------------------------------------------------------------------
r_drawsun (variable)(A) syntax: r_drawsun [0/1] default: 0 Toggles the drawing of the sun and accompanying glare in the sky when r_fastsky is 0. 0=disables;1=enables. - Ryan --------------------------------------------------------------------------------
r_drawworld (variable)(C) syntax: r_drawworld [0/1] default: 1 Toggles rendering of world brushes (map architecture). Entities will still be drawn. 0=disables;1=enables. --------------------------------------------------------------------------------
r_dynamiclight (variable)(A) syntax: r_dynamiclight [0/1] default: 1 Toggles dynamic lighting. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ext_compiled_vertex_array (variable)(A L) syntax: r_ext_compiled_vertex_array [0/1] default: 1 Toggles hardware compiled vertex array rendering method if available. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ext_compress_textures (variable)(A L) syntax: r_ext_compress_textures [0/1] default: 1 Toggles hardware texture compression if available. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ext_gamma_control (variable)(A L) syntax: r_ext_gamma_control [0/1] default: 1 Toggles hardware gamma adjustments if available. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ext_multitexture (variable)(A L) syntax: r_ext_multitexture [0/1] default: 1 Toggles hardware mutitexturing if available. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ext_texenv_add (variable)(A L) syntax: r_ext_texenv_add [?] default: 1 Unknown. --------------------------------------------------------------------------------
r_ext_texture_env_add (variable)(A L) syntax: r_ext_texture_env_add [?] default: 1 Unknown. --------------------------------------------------------------------------------
r_faceplanecull (variable)(A) syntax: r_faceplanecull [0/1] default: 1 Toggles the culling of brush faces not in the direct view of the player. 0=disables;1=enables. --------------------------------------------------------------------------------
r_fastsky (variable)(A) syntax: r_fastsky [0/1] default: 0 Toggles rendering of sky. Setting to 1 will also disable the view through portals. 0=enables;1=disables. --------------------------------------------------------------------------------
r_finish (variable)(A) syntax: r_finish [0/1] default: 0 Toggles syncing to frames. Enabling basically instructs hardware to inform game that GL calls have been completed. 0=disables;1=enables. --------------------------------------------------------------------------------
r_flarefade (variable)(C) syntax: r_flarefade [0 to ?] default: 7 Sets scale of fading of flares in relation to distance when r_flares is 1. --------------------------------------------------------------------------------
r_flares (variable)(A) syntax: r_flares [0/1] default: 0 Toggles lighting flares effect (lights and weapon projectiles). 0=disables;1=enables. --------------------------------------------------------------------------------
r_flaresize (variable)(C) syntax: r_flaresize [0 to ?] default: 40 Adjusts the size of flares when r_flares is 1. --------------------------------------------------------------------------------
r_fullbright (variable)(C L) syntax: r_fullbright [0/1] default: 0 Toggles lightmaps when r_ext_multitexture is 0. Textures will be rendered at full brightness when enabled. See also r_lightmap. 0=disables;1=enables. --------------------------------------------------------------------------------
r_fullscreen (variable)(A L) syntax: r_fullscreen [0/1] default: 1 Toggles fullscreen rendering. When set to 0, windowed rendering is attempted. 0=disables;1=enables. --------------------------------------------------------------------------------
r_gamma (variable)(A) syntax: r_gamma [value] default: 1 Sets in-game gamma levels. --------------------------------------------------------------------------------
r_gldriver (variable)(A L) syntax: r_gldriver [video driver] default: opengl32 Specifies OpenGL driver used. --------------------------------------------------------------------------------
r_ignore (variable)(C) syntax: r_ignore [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_ignoreglerrors (variable)(A) syntax: r_ignoreglerrors [0/1] default: 1 Toggles option to ignore OpenGL errors and to attempt to continue rendering. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ignorefastpath (variable)(L) syntax: r_ignorefastpath [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_ignorehwgamma (variable)(A L) syntax: r_ignorehwgamma [0/1] default: 0 Toggles option to ignore external (not in-game) hardware gamma level setting made within Windows9x's Display Properties. 0=disables;1=enables. --------------------------------------------------------------------------------
r_ignoreoffset (variable)(A C) syntax: r_ignoreoffset [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_intensity (variable)(L) syntax: r_intensity [0 to 5] default: 1 Adjusts the overall strength of colors, with emphasis on the color White. Higher values result in higher apparent overall brightness. An alternative to adjusting gamma values, with the side effect of loss of texture details at too high a value. --------------------------------------------------------------------------------
r_lastvalidrenderer (variable)(A) syntax: r_lastvalidrenderer [video component] default: "" Reports the video hardware that last successfully rendered the Test. --------------------------------------------------------------------------------
r_lightmap (variable)(C) syntax: r_lightmap [0/1] default: 0 Toggles rendering of lightmaps without rendering textures. 0=disables;1=enables. --------------------------------------------------------------------------------
r_lockpvs (variable)(C) syntax: r_lockpvs [0/1] default: 0 Toggles the option of preventing the update of the PVS table as the player moves through the map. When set to 1 new areas entered will not be rendered. A mapper's tool. 0=disables;1=enables. --------------------------------------------------------------------------------
r_lodbias (variable)(A) syntax: r_lodbias [0 to ?] default: 0 Sets Level-Of-Detail bias. An example would be the complexity of weapon rendering. 0=highest detail. --------------------------------------------------------------------------------
r_lodcurveerror (variable) syntax: r_lodcurveerror [?] default: ? Sets rate that polygons are dropped from curved surfaces in relation to distance. --------------------------------------------------------------------------------
r_lodscale (variable)(C) syntax: r_lodscale [0 to ?] default: 5 Sets scale with which to adjust Level-Of-Detail. --------------------------------------------------------------------------------
r_logfile (variable)(C) syntax: r_logfile [0/1] default: 0 Toggles the writing of GL.LOG in the same directory as QUAKE3.EXE which records all OpenGL commands used in a game session. 0=disables;1=enables. --------------------------------------------------------------------------------
r_mapoverbrightbits (variable)(L) syntax: r_mapoverbrightbits [integer] default: 2 Sets intensity of bounced light from textures (adjusts lighting saturation) when r_vertexlight is 0. Higher values=brighter lights reflected from textures. --------------------------------------------------------------------------------
r_maskminidriver (variable)(L) syntax: r_maskminidriver [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_measureoverdraw (variable)(C) syntax: r_measureoverdraw [?] default: 0 Presumably implements sun's stenciling method of measuring overdraw. --------------------------------------------------------------------------------
r_mode (variable)(A L) syntax: r_mode [integer] default: 3 Sets a video mode. Valid resolutions: -1=Custom (see r_customaspect) 0=320x240 1=400x300 2=512x384 3=640x480 4=800x600 5=960x720 6=1024x768 7=1152x864 8=1280x1024 9=1600x1200 10=2048x1536 11=856x480 --------------------------------------------------------------------------------
r_nobind (variable)(C) syntax: r_nobind [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_nocull (variable)(C) syntax: r_nocull [0/1] default: 0 Toggles rendering of items/objects normally not seen from player's point-of-view. 0=disables;1=enables. --------------------------------------------------------------------------------
r_nocurves (variable)(C) syntax: r_nocurves [0/1] default: 0 Presumably enables/disables rendering of curves. --------------------------------------------------------------------------------
r_noportals (variable)(C) syntax: r_noportals [0/1] default: 0 Toggles player view through portals. 0=enables view;1=disables view. --------------------------------------------------------------------------------
r_norefresh (variable)(C) syntax: r_norefresh [0/1] default: 0 Toggles clearing of screen prior to re-rendering. 0=allow refresh;1=disable refresh. --------------------------------------------------------------------------------
r_novis (variable)(C) syntax: r_novis [0/1] default: 0 Toggles the option to ignore vis data when drawing the map. 0=disables;1=enables. --------------------------------------------------------------------------------
r_offsetfactor (variable)(C) syntax: r_offsetfactor [?] default: -1 Unknown. --------------------------------------------------------------------------------
r_offsetunits (variable)(C) syntax: r_offsetunits [?] default: -2 Unknown. --------------------------------------------------------------------------------
r_overbrightbits (variable)(A L) syntax: r_overbrightbits [?] default: 1 Unknown. --------------------------------------------------------------------------------
r_picmip (variable)(A L) syntax: r_picmip [0 to 8] default: 1 Sets maximum texture size. 0=highest detail;8=unbelievably ugly. --------------------------------------------------------------------------------
r_portalonly (variable)(C) syntax: r_portalonly [0/1] default: 0 Toggles seeing what the game engine can see through a portal. When enabled, if the game engine can see a portal, nothing else will be drawn except for the area the portal can see. 0=disables;1=enables. --------------------------------------------------------------------------------
r_preloadtextures (variable)(A L) syntax: r_preloadtextures [?] default: 0 Unknown. Presumably enables/disables the preloading of texture info. --------------------------------------------------------------------------------
r_primitives (variable) syntax: r_primitives [value] default: 0 Sets rendering method. Valid settings: -1=skips drawing 0=uses glDrawelements if compiled vertex arrays are present, or strips of glArrayElement if not. 1=forces strips 2=forces drawElements --------------------------------------------------------------------------------
r_railcorewidth (variable)(A) syntax: r_railcorewidth [value] default: 16 Sets the inner trail width when the Railgun is fired. --------------------------------------------------------------------------------
r_railsegmentlength (variable)(A) syntax: r_railsegmentlength [value] default: 64 Sets the distance between the coils when the Railgun is fired. --------------------------------------------------------------------------------
r_railwidth (variable)(A) syntax: r_railwidth [value] default: 128 Sets the outer trail width when the Railgun is fired. --------------------------------------------------------------------------------
r_roundimagesdown (variable)(A L) syntax: r_roundimagesdown [?] default: 1 Unknown. --------------------------------------------------------------------------------
r_showcluster (variable)(C) syntax: r_showcluster [0/1] default: 0 Toggles display of clusters by number as the player enters them on the currently loaded map. 0=disables;1=enables. --------------------------------------------------------------------------------
r_showimages (variable) syntax: r_showimages [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_shownormals (variable)(C) syntax: r_shownormals [0/1] default: 0 Toggles the drawing of short lines indicating brush and entity polygon vertices. See also r_showtris. 0=disables;1=enables.. --------------------------------------------------------------------------------
r_showsky (variable)(C) syntax: r_showsky [0/1] default: 0 Toggles the drawing of the sky in front of other brushes. 0=disables;1=enables. --------------------------------------------------------------------------------
r_showsmp (variable)(C) syntax: r_showsmp [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_showtris (variable)(C) syntax: r_showtris [0/1] default: 0 Toggles the drawing of polygon triangles. See also r_shownormals. 0=disables,1=enables. --------------------------------------------------------------------------------
r_simplemipmaps (variable)(A L) syntax: r_simplemipmaps [?] default: 1 Unknown. --------------------------------------------------------------------------------
r_skipbackend (variable)(C) syntax: r_skipbackend [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_smp (variable) syntax: r_smp [0/1] default: 0 Toggles multiprocessor acceleration support. 0=disables;1=enables. --------------------------------------------------------------------------------
r_speeds (variable)(C) syntax: r_speeds [0/1] default: 0 Toggles the display of map geometry data. 0=disables,1=enables. --------------------------------------------------------------------------------
r_stencilbits (variable)(A L) syntax: r_stencilbits [0 to 16] default: 8 Adjusts rendering of hardware's stencil buffer depth. --------------------------------------------------------------------------------
r_stereo (variable)(A L) syntax: r_stereo [0/1] default: 0 Toggles stereoscopic glasses feature. 0=disables;1=enables. --------------------------------------------------------------------------------
r_subdivisions (variable)(A L) syntax: r_subdivisions [1 to 999] default: 4 Sets the maximum Level-Of-Detail. An example would be the complexity of curves. 1=highest detail. --------------------------------------------------------------------------------
r_swapinterval (variable)(A) syntax: r_swapinterval [0/1] default: 0 Toggles frame swapping. 0=disables;1=enables. --------------------------------------------------------------------------------
r_texturebits (variable)(A L) syntax: r_texturebits [0 to 32] default: 0 Sets texture color depth. --------------------------------------------------------------------------------
r_texturemode (variable)(A) syntax: r_texturemode [OpenGL extension] default: GL_LINEAR_MIPMAP_NEAREST Sets texture filtering mode. Possible extensions used: GL_NEAREST (nearest interpolation filtering) GL_NEAREST_MIPMAP (nearest interpolation filtering with mipmapping) GL_LINEAR (linear interpolation filtering) GL_LINEAR_MIPMAP_NEAREST (linear interpolation filtering with nearest (bilinear) mipmapping) GL_LINEAR_MIPMAP_LINEAR (linear interpolation filtering with linear (trilinear) mipmapping) --------------------------------------------------------------------------------
r_verbose (variable)(C) syntax: r_verbose [?] default: 0 Unknown. --------------------------------------------------------------------------------
r_vertexlight (variable)(A L) syntax: r_vertexlight [0/1] default: 0 Toggles vertex lighting. Enabling would mean disabling lightmapping. 0=disables; 1=enables. See also r_lightmap. --------------------------------------------------------------------------------
r_znear (variable)(C) syntax: r_znear [distance in map units] default: 4 Sets the point from the player view origin that the game will set the near z-clipping plane and begin drawing the world. If set to less than 1 none of the world will be drawn. --------------------------------------------------------------------------------
rate (variable)(U A) syntax: rate [value] default: 3000 Sets communication rate between client and server. --------------------------------------------------------------------------------
rcon (command) syntax: rcon [password] [string] A remote command to a server. The string is the command to be executed. --------------------------------------------------------------------------------
rcon_password (variable) syntax: rcon_password [string] default: "" A password used to grant remote access for a client using the rcon command. --------------------------------------------------------------------------------
rconaddress (variable) syntax: rconaddress [IP address] default: "" The address the rcon command is sent to. --------------------------------------------------------------------------------
rconpassword (variable) syntax: rconpassword [string] default: "" A password used to grant access for an admin using the rcon command on a dedicated server. --------------------------------------------------------------------------------
record (command) syntax: record [demoname] Record a demo to the /demos/ directory. If the demoname parameter is not included, then a sequentially-numbered filename will be assigned. --------------------------------------------------------------------------------
reset (command) syntax: reset [variable] Resets a variable to its default value. --------------------------------------------------------------------------------
restart (command) syntax: restart Restarts the game on the current map. --------------------------------------------------------------------------------
s_initsound (variable) syntax: s_initsound [0/1] default: 1 Toggles using the sound system. 0=disables;1=enables. --------------------------------------------------------------------------------
s_khz (variable)(A) syntax: s_khz [value] default: 22 Sets the sampling rate, and therefore the quality of game sounds. Valid values are 11, 22 and 44(?). --------------------------------------------------------------------------------
s_loadas8bit (variable)(A) syntax: s_loadas8bit [0/1] default: 1 Toggles loading sound files as 8-bit. 0=disables;1=enables. --------------------------------------------------------------------------------
s_mixahead (variable)(A) syntax: s_mixahead [value] default: 0.2 Sets the time delay before mixing sound samples. --------------------------------------------------------------------------------
s_mixprestep (variable)(A) syntax: s_mixprestep [?] default: 0.05 Unknown. --------------------------------------------------------------------------------
s_musicvolume (variable)(A) syntax: s_musicvolume [0 to 1] default: 1 Presumably sets the music volume level. --------------------------------------------------------------------------------
s_separation (variable)(A) syntax: s_separation [value] default: 0.5 Sets the degree of stereo sound separation. --------------------------------------------------------------------------------
s_show (variable)(C) syntax: s_show [0/1] default: 0 Toggles display of paths and filenames of all sound files as they are called. 0=disables;1=enables. --------------------------------------------------------------------------------
s_testsound (variable)(C) syntax: s_testsound [0/1] default: 0 Toggles the playing of a test tone, overriding all other sounds. 0=disables;1=enables.. --------------------------------------------------------------------------------
s_volume (variable)(A) syntax: s_volume [0 to 1] default: 0.7 Sets the game sounds volume level. --------------------------------------------------------------------------------
say (command) syntax: say [string] Used by the server. The text in the string is sent to all players as a message. --------------------------------------------------------------------------------
say_team command syntax: say_team [string] The text in the string is sent to all players on the same team only, if the server settings allow. --------------------------------------------------------------------------------
scr_conspeed (variable) syntax: scr_conspeed [value] default: 3 Sets the console rise/fall and text scrolling speed. --------------------------------------------------------------------------------
screenshot (command) syntax: screenshot [levelshot/silent] Writes the current view to a .TGA file and saves it in \screenshots\. The parameters are optional. If used, the results are: levelshot = a mini screenshot will be written to the \levelshots\ folder silent = the "wrote shotXXXX.tga" report will not be displayed on the screen. - dynamite --------------------------------------------------------------------------------
sectorlist (command) syntax: sectorlist Lists sectors and number of entities in each on the currently loaded map. --------------------------------------------------------------------------------
sensitivity (variable)(A) syntax: sensitivity [value] default: 5 Sets overall sensitivity of a mouse or similar device. --------------------------------------------------------------------------------
serverinfo (command) syntax: serverinfo Shows server cvars on the local machine, including user created variables set with the sets command. Report includes: gamedate gamename sv_privateclients mapname protocol version teamflags nohealth sv_maxclients timelimit fraglimit dmflags sv_hostname cheats --------------------------------------------------------------------------------
serverrecord (command) syntax: serverrecord [?] Presumably records a demo on the host machine using all client perspectives. --------------------------------------------------------------------------------
serverstop (command) syntax: serverstop Presumably stops recording a demo begun with the serverrecord command. --------------------------------------------------------------------------------
session (variable) syntax: session [value] default: 0 Unknown. --------------------------------------------------------------------------------
session0 (variable) syntax: session0 [?] default: 0 0 1 0 Unknown. --------------------------------------------------------------------------------
set (command) syntax: set [variable] [string] Sets the value of a valid cvar or a user-created variable. --------------------------------------------------------------------------------
seta (command) syntax: set [variable] [string] Sets the value of a valid cvar or a user-created variable. It will also archive the variable and its current setting in Q3CONFIG.CFG (not user-created ones though). --------------------------------------------------------------------------------
setenv (command) syntax: setenv [variable] [string] Sets an environment variable from within the game. --------------------------------------------------------------------------------
sets (command) syntax: set [variable] [string] Sets the value of a valid cvar or a user-created variable in the same manner as set, but this cvar will be reported when the serverinfo command is executed. --------------------------------------------------------------------------------
setu (command) syntax: set [variable] [string] Sets the value of a valid cvar or a user-created variable in the same manner as set, but this cvar will be reported when the userinfo command is executed. --------------------------------------------------------------------------------
shaderlist (command) syntax: shaderlist Lists all shader files loaded on the current map. --------------------------------------------------------------------------------
showdrop (variable) syntax: showdrop [0/1] default: 0 When enabled, reports dropped packets should they occur. 0=disables;1=enables. --------------------------------------------------------------------------------
showpackets (variable) syntax: showpackets [0/1] default: 0 Toggles the running display of all packets sent and received. 0=disables;1=enables. --------------------------------------------------------------------------------
sizedown (command) syntax: sizedown Reduces the size of the play screen by reducing viewsize in 10 percent increments. --------------------------------------------------------------------------------
sizeup (command) syntax: sizeup Increases the size of the play screen by increasing viewsize in 10 percent increments. --------------------------------------------------------------------------------
skinlist (command) syntax: skinlist Lists all skin files that have been loaded on the current map. --------------------------------------------------------------------------------
snaps (variable)(U A) syntax: snaps [integer] default: 20 Sets number of snapshots (states of the game world) per second to receive from the server. Setting to 40 would mean receiving every snapshot, 20 would mean receiving every other snaphot. The value set should be a factor of 40 (i.e., 10, 20, 40) - LOKi --------------------------------------------------------------------------------
snd_restart (command) syntax: snd_restart Reinitializes the sound system so new settings can take effect. --------------------------------------------------------------------------------
soundinfo (command) syntax: soundinfo Reports status of the sound system. --------------------------------------------------------------------------------
soundlist (command) syntax: soundlist Lists all sound files loaded for the current map. --------------------------------------------------------------------------------
status (command) syntax: status Reports map loaded, and information on all connected players. --------------------------------------------------------------------------------
stoprecord (command) syntax: stoprecord Stops recording a demo begun with the demo command. Replaces stopdemo. --------------------------------------------------------------------------------
stopsound (command) syntax: stopsound Stops a currently playing sound. --------------------------------------------------------------------------------
sv_allowdownload (variable) syntax: sv_allowdownload [0/1] default: 1 Toggles whether to enable the downloading of files. 0=disables;1=enables. --------------------------------------------------------------------------------
sv_fps (variable) syntax: sv_fps [integer] default: 20 Sets the number of times per second the server will send gamesatate updates to all clients. Optimum setting dependent on available bandwidth and number of clients. - dynamite --------------------------------------------------------------------------------
sv_hostname (variable)(S A) syntax: sv_hostname [string] default: noname Sets the name of the host machine. Font color can be changed. Possible colors: 0 = Black 1 = Red 2 = Green 3 = Yellow 4 = Blue 5 = Cyan 6 = Magenta 7 = White -------------------------------------------------------------------------------- sv_keywords (variable)(S) syntax: sv_keywords [?] default: "" Unknown. --------------------------------------------------------------------------------
sv_killserver (variable) syntax: sv_killserver [0/1] default: 0 When set to 1, kills the server (shuts down map or demo) without shutting down quake3.exe. Value then returns to 0. --------------------------------------------------------------------------------
sv_mapchecksum (variable)(R) syntax: sv_mapchecksum [bytes] default: "" Reports the file size of the currently loaded map. Used to prevent cheating by ensuring all clients are not using hacked maps. -stone^mhs --------------------------------------------------------------------------------
sv_master1 (variable) syntax: sv_master1 [string] default: master3.idsoftware.com Sets the name or IP address of a master server. --------------------------------------------------------------------------------
sv_master2 (variable)(A) syntax: sv_master2 [string] default: "" Sets the name or IP address of a master server. --------------------------------------------------------------------------------
sv_master3 (variable)(A) syntax: sv_master3 [string] default: "" Sets the name or IP address of a master server. --------------------------------------------------------------------------------
sv_master4 (variable)(A) syntax: sv_master4 [string] default: "" Sets the name or IP address of a master server. --------------------------------------------------------------------------------
sv_master5 (variable)(A) syntax: sv_master5 [string] default: "" Sets the name or IP address of a master server. --------------------------------------------------------------------------------
sv_maxclients (variable)(S A L) syntax: sv_maxclients [integer] default: 8 Sets the maximum number of clients hosted on the server. --------------------------------------------------------------------------------
sv_pad (variable) syntax: sv_pad [?] default: 0 Unknown. --------------------------------------------------------------------------------
sv_privateclients (variable)(S) syntax: sv_privateclients [integer] default: 0 If set to a positive integer n, the server will reserve n connect slots for clients with the proper password. See also sv_privatepassword. (sv_maxclients) - (sv_privateclients) = (total number of public connect slots) - Sideshow_Bob, Andy Lutomirski --------------------------------------------------------------------------------
sv_privatepassword (variable) syntax: sv_privatepassword [string] default: "" Password to allow for the connection of clients to reserved slots. The client would have to set the password cvar to the same value in order to connect. See also sv_privateclients. - Sideshow_Bob, Andy Lutomirski --------------------------------------------------------------------------------
sv_reconnectlimit (variable) syntax: sv_reconnectlimit [value] default: 3 Presumably sets the number of times the server will recognize a client's reconnect command. (However, there is no reconnect command...) --------------------------------------------------------------------------------
sv_running (variable)(R) syntax: sv_running [0/1] default: 0 Reports if the server is running on the local machine. 0=server not on local machine;1=server on local machine. - LOKi --------------------------------------------------------------------------------
sv_serverid (variable)(R) syntax: sv_serverid [id #] default: "" The identification number of the local server. --------------------------------------------------------------------------------
sv_showloss (variable) syntax: sv_showloss [?] default: 0 Unknown. --------------------------------------------------------------------------------
sv_timeout (variable) syntax: sv_timeout [time in seconds] default: 120 Sets the amount of time for the server to wait for a client packet before assuming a disconnected state. --------------------------------------------------------------------------------
sv_zombietime (variable) syntax: sv_zombietime [minutes] default: 2 Sets the amount of time before removing a frozen player. --------------------------------------------------------------------------------
sv_zone (variable)(S) syntax: sv_zone [string] default: default Sets a game type for the server such as Free For All, Tournament, Team Deathmatch and Capture the Flag. - dynamite --------------------------------------------------------------------------------
sys_cpuid (variable) syntax: sys_cpuid [value] default: "" Presumably reports the CPU ID number used on the local machine. --------------------------------------------------------------------------------
sys_cpustring (variable) syntax: sys_cpustring [string] default: "" Identifies the CPU in use on the local machine. --------------------------------------------------------------------------------
systeminfo (command) syntax: systeminfo Reports settings for: g_syncronousclients sv_serverid timescale --------------------------------------------------------------------------------
tcmd (command) syntx: tcmd [?] Unknown. --------------------------------------------------------------------------------
team (command) syntax: team [string] Sets player status. Possible values: p = Player (FFA) s = Spectator blue = Blue Team red = Red Team follow# = Spectator, following player by number scoreboard = Be a scoreboard -------------------------------------------------------------------------------- teamflags (variable)(S A) syntax: teamflags [value] default: 0 Sets the game options for team play. --------------------------------------------------------------------------------
tell (command) syntax: tell [player_name or id] Sends a message to the specified player. - dynamite --------------------------------------------------------------------------------
tell_attacker (command) syntax: tell_attacker [string] Sends a message to the player who last injured you. --------------------------------------------------------------------------------
tell_target (command) syntax: tell_target [string] Sends a message to the player who you are presently targeting. --------------------------------------------------------------------------------
testgun (command) syntax: testgun [model_name] Unknown. --------------------------------------------------------------------------------
testmodel (command) syntax: testmodel [model_name] Unknown. --------------------------------------------------------------------------------
timedemo (variable)(C) syntax: timedemo [0/1] default: 0 Toggles the running of the game as fast as it can, for the purpose of benchmarking with the use of demos. 0=disables;1=enables. --------------------------------------------------------------------------------
timegraph (variable)(C) syntax: timegraph [0/1] default: 0 Toggles the display of the timegraph. 0=disables;1=enables. --------------------------------------------------------------------------------
timelimit (variable)(S A) syntax: timelimit [value] default: 0 Sets the amount of time before a game will end if fraglimit is not reached or set. Setting to 0 disables timelimit. --------------------------------------------------------------------------------
timescale (variable)(C) syntax: timescale [value] default: 1 Sets the ratio between game time and 'real' time. --------------------------------------------------------------------------------
toggle (command) syntax: toggle [cvar] Alternately sets a cvar to 0 and 1. It will affect cvars with valid setting of other than 0 or 1, so use with discretion. --------------------------------------------------------------------------------
toggleconsole (command) syntax: toggleconsole Will bring down the console if up, or raise it if down. --------------------------------------------------------------------------------
touchfile (command) syntax: touchfile [file] Unknown. --------------------------------------------------------------------------------
unbind (command) syntax: unbind [key or button] Remove a binding from a selected key or button. --------------------------------------------------------------------------------
unbindall (command) syntax: unbindall Unbinds all keys except for ESC and ` (tilde key). --------------------------------------------------------------------------------
userinfo (command) syntax: userinfo Leftover from the previous version, now broken. Replaced by clientinfo. --------------------------------------------------------------------------------
username (variable) syntax: username [string] default: "" The name of the currently logged-on user on the machine. --------------------------------------------------------------------------------
version (variable)(S R) syntax: version [string] default: "Q3T 1.05 win-x86 May 10 1999" The current version of Q3Test. --------------------------------------------------------------------------------
versionnumber (variable)(R) syntax: versionnumber [string] default: Q3T 1.06 The current version number of Q3Test. --------------------------------------------------------------------------------
vid_restart (command) syntax: vid_restart Reinitializes the video system so new settings can take effect. --------------------------------------------------------------------------------
vid_xpos (variable)(A) syntax: vid_xpos [number of pixels] default: 3 Positions the game screen the specified number of pixels from the left edge of the monitor screen when in windowed mode. --------------------------------------------------------------------------------
vid_ypos (variable)(A) syntax: vid_ypos [number of pixels] default: 22 Positions the game screen the specified number of pixels from the top edge of the monitor screen when in windowed mode. --------------------------------------------------------------------------------
viewlog (variable)(C) syntax: viewlog [0/1] default: 0 Toggles the display of the startup console window over the game screen. 0=disables;1=enables. --------------------------------------------------------------------------------
viewpos (command) syntax: viewpos Displays the players coordinate position (x-y-z) on the loaded map and the direction he is facing in degrees. --------------------------------------------------------------------------------
viewsize (variable)(A) syntax: viewsize [value] default: 100 Sets the size of the play screen as a percentage of the monitor screen. Maximum value=100. --------------------------------------------------------------------------------
vm_cgame (variable)(A) syntax: vm_cgame [value] default: 0 Unknown. --------------------------------------------------------------------------------
vmprofile (command) syntax: vmprofile [?] Unknown. --------------------------------------------------------------------------------
vmsg (command) syntax: vmsg [string] Same as the say command, except a sound file is played along with the message. The command is present but appears broken. --------------------------------------------------------------------------------
vmsg_team (command) syntax: vmsg_team [string] Same as the say_team command, except a sound file is played along with the message. The command is present but appears broken. --------------------------------------------------------------------------------
vstr (command) syntax: vstr [user-created variable] Executes a variable command created with set, seta, sets or setu. --------------------------------------------------------------------------------
wait (command) syntax: wait [integer] Waits the specified number of game tics (0.1 seconds?). If no parameter is used it will default to a single game tic. Used in command strings to allow enough time for a command to be executed before proceeding to the next. --------------------------------------------------------------------------------
weapnext (command) syntax: weapnext Selects the next available higher numbered weapon in sequence. See also weapprev. --------------------------------------------------------------------------------
weapon (command) syntax: weapon [integer] Selects the weapon specified by the parameter. Valid choices: 1 = Gauntlet 2 = Machinegun 3 = Shotgun 4 = Grenade Launcher 5 = Rocket Launcher 6 = Lightning Gun 7 = Railgun 8 = Plasma Gun 9 = BFG10K 10 = Grappling Hook --------------------------------------------------------------------------------
weapprev (command) syntax: weapprev Selects the next available lower numbered weapon in sequence. See also weapnext. --------------------------------------------------------------------------------
win_hinstance (variable)(R) syntax: win_hinstance [instance_value] default: 4194304 The Windows handle assigned to quake3.exe. Presumably used for debugging and/or for a mod to retrieve a handle to the Q3 application. - Zeb, Andy Lutomirski --------------------------------------------------------------------------------
win_wndproc (variable)(R) syntax: win_wndproc [?] default: 4368704 Presumably the WndProc for the Quake3 window. - Andy Lutomirski --------------------------------------------------------------------------------
writeconfig (command) syntax: writeconfig [?] Unknown. --------------------------------------------------------------------------------
z_stats (command) syntax: z_stats Displays memory and block usage. -------------------------------------------------------------------------------- zoomfov (variable*)(A) syntax: zoomfov [value in degrees] default: 22.5 Sets the size of the field of view when +zoom is active. Sensitivity scales automatically with the change in field of view. Maximum value=160. Quake3 控制台命令1Quake III Console
转自 http://www.terta.de/lwt/docs/q3commands.html
cg_animspeed (variable)(C) syntax: cg_animspeed [0/1] default: 1 Toggles player animations. 0=disables;1=enables. See also cg_noplayeranims. --------------------------------------------------------------------------------
cg_autoswitch (variable)(A) syntax: cg_autoswitch [0/1] default: 1 Toggles the automatic switching to the weapon the player has just picked up. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_bobpitch (variable)(A) syntax: cg_bobpitch [value] default: 0.002 Sets how much the player view pitches forward and back when moving. --------------------------------------------------------------------------------
cg_bobroll (variable)(A) syntax: cg_bobroll [value] default: 0.002 Sets how much the player view rolls from side to side when moving. --------------------------------------------------------------------------------
cg_bobup (variable)(A) syntax: cg_bobup [value] default: 0.005 Sets how much the player view bobs up and down when moving. --------------------------------------------------------------------------------
cg_brasstime (variable) syntax: cg_brasstime [value] default: ? Sets how long weapon effects (like the ejected shells from the shotgun) will be rendered. Setting to 0 disables this effect entirely. --------------------------------------------------------------------------------
cg_centertime (variable)(C) syntax: cg_centertime [time in seconds] default: 3 Sets how long messages are displayed in the center of the screen. If set to 0 no messages will appear. --------------------------------------------------------------------------------
cg_debuganim (variable)(C) syntax: cg_debuganim [0/1] default: 0 Presumably enables/disables debugging of model animations. --------------------------------------------------------------------------------
cg_debugevents (variable)(C) syntax: cg_debugevents [?] default: 0 Unknown. --------------------------------------------------------------------------------
cg_debugposition (variable)(C) syntax: cg_debugposition [?] default: 0 Unknown. --------------------------------------------------------------------------------
cg_demolook (variable)(C) syntax: cg_demolook [?] default: 0 Unknown. --------------------------------------------------------------------------------
cg_draw2d (variable) syntax: cg_draw2d [0/1] default: 1 Toggles display of 2D items on the screen. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_draw3dicons (variable) syntax: cg_draw3dicons [0/1] default: 1 Toggles the drawing of the 3D ammo, skin, and armor icons. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_drawammowarning (variable)(A) syntax: cg_drawammowarning [0/1] default: 1 Toggles the "Low on Ammo" warning on the player screen. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_drawattacker (variable)(A) syntax: cg_drawattacker [0/1] default: 1 Toggles the display of the last guy to do damage to you in the upper-right corner of the screen. If you hurt yourself, that guy will be you. 0=disables;1=enables. Replaces cg_drawkiller. --------------------------------------------------------------------------------
cg_drawcrosshair (variable)(A) syntax: cg_drawcrosshair [0/1] default: 1 Toggles the drawing of the crosshair. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_drawcrosshairnames (variable)(A) syntax: cg_drawcrosshairnames [0/1] default: 1 Toggles the ID display of other players when your crosshair is on them. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_drawfps (variable)(A) syntax: cg_drawfps [0/1] default: 0 Toggles the frame rate counter. This cannot be displayed at the same time as the timer. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_drawsnapshot (variable)(A) syntax: cg_drawsnapshot [value] default: 0 Toggles the display of the snapshot count. This cannot be displayed at the same time as the frame rate counter or the timer. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_drawstatus (variable)(A) syntax: cg_drawstatus [0/1] default: 1 Toggles the drawing of the HUD, the crosshair and any text or readout. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_drawtimer (variable)(A) syntax: cg_drawtimer [0/1] default: 1 Toggles the game timer. This cannot be displayed at the same time as the frame rate counter. 1=disables;0=enables. --------------------------------------------------------------------------------
cg_errordecay (variable) syntax: cg_errordecay [?] default: 100 Unknown. --------------------------------------------------------------------------------
cg_extrapolate (variable) syntax: cg_extrapolate [?] default: 1 Unknown. --------------------------------------------------------------------------------
cg_footsteps (variable)(C) syntax: cg_footsteps [0/1] default: 1 Toggles player footstep sounds. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_gibs (variable)(A) syntax: cg_gibs [0/1] default: 1 Toggles the rendering of gibs. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_gun (variable)(A) syntax: cg_gun [0/1] default: 1 Toggles the rendering of the weapon model. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_ignore (variable) syntax: cg_ignore [?] default: 0 Unknown. --------------------------------------------------------------------------------
cg_lagometer (variable)(A) syntax: cg_lagometer [0/1] default: 1 Toggles between displaying the netgraph or the frag counter. 0=display frag counter;1=display netgraph. - Enforcer --------------------------------------------------------------------------------
cg_markoffset (variable)(C) syntax: cg_markoffset [value] default: 1 Presumably sets the offset of the gunshot marks but no effect was noted. --------------------------------------------------------------------------------
cg_marks (variable)(A) syntax: cg_marks [0/1] default: 1 Toggles gunshot marks on the walls, etc. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_noplayeranims (variable)(C) syntax: cg_noplayeranims [0/1] default: 0 Toggles player model animations. The animation frame displayed when this is disabled is rather odd, though. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_nopredict (variable) syntax: cg_nopredict [0/1] default:0 Toggles client-side player prediction. Disabling causes the client to wait for updates from the server before updating the local machine. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_railtrailtime (variable)(A) syntax: cg_railtrailtime [value] default: 400 Sets the amount of time the railgun slug trail is visible. --------------------------------------------------------------------------------
cg_runpitch (variable)(A) syntax: cg_runpitch [value] default: 0.002 Appears to do nothing. --------------------------------------------------------------------------------
cg_runroll (variable)(A) syntax: cg_runroll [value] default: 0.005 Appears to do nothing. --------------------------------------------------------------------------------
cg_shadows (variable)(A) syntax: cg_shadows [integer] default: 1 Sets type of shadows rendering when cg_marks is set to 1. Possible values: 0=no shadows 1=ordinary shadows 2=stencil buffer shadows (r_stencilbits must be set to 8) 3=very dark stencil buffer shadows (r_stencilbits must be set to 8) -------------------------------------------------------------------------------- cg_showmiss (variable) syntax: cg_showmiss [?] default: 0 Unknown. --------------------------------------------------------------------------------
cg_simpleitems (variable)(A) syntax: cg_simpleitems [0/1] default: 0 Toggles the drawing of weapon, ammo, powerups, health and armor entities as models or as sprites. 0=draw models;1=draw sprites. --------------------------------------------------------------------------------
cg_stats (variable) syntax: cg_stats[0/1] default: 0 Toggles the display of running count of client frames. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_stereoseparation (variable)(A) syntax: cg_stereoseparation [value] default: 0.4 Sets the degree of stereoscopic separation when r_stereo is 1. --------------------------------------------------------------------------------
cg_swingspeed (variable)(C) syntax: cg_swingspeed [value] default: 0.3 Sets how quickly the player model turns to match a new direction the player is facing. When set to 1 the model follows the turn with no delay, when set to 0 it will not turn (but will continue trying). --------------------------------------------------------------------------------
cg_teamchattime (variable)(A) syntax: cg_teamchattime [value] default: 3000 Adjusts the time team messages are displayed in bright red or blue box in the middle of the screen. Setting to "0" would causes just a one time quick flash (hardly noticeable). - burn --------------------------------------------------------------------------------
cg_temp (variable) syntax: cg_temp [?] default: 0 Unknown. --------------------------------------------------------------------------------
cg_testentities (variable)(C) syntax: cg_testentities [?] default: 0 Unknown. --------------------------------------------------------------------------------
cg_thirdperson (variable)(C) syntax: cg_thirdperson [0/1] default: 0 Toggles third person view. 0=disables;1=enables. --------------------------------------------------------------------------------
cg_thirdpersonangle (variable)(C) syntax: cg_thirdpersonangle [value in degrees] default: 0 Sets the viewing angle on the horizontal plane when cg_thirdperson is set to 1. --------------------------------------------------------------------------------
cg_thirdpersonrange (variable)(C) syntax: cg_thirdpersonrange [value] default: 40 Sets the viewing distance from the player when cg_thirdperson is set to 1. --------------------------------------------------------------------------------
cg_tracerchance (variable)(C) syntax: cg_tracerchance [?] default: 0.4 Unknown. Presumably adjusts a lightning gun effect. --------------------------------------------------------------------------------
cg_tracerlength (variable)(C) syntax: cg_tracerlength [?] default: 100 Unknown. Presumably adjusts a lightning gun effect. --------------------------------------------------------------------------------
cg_tracerwidth (variable)(C) syntax: cg_tracerwidth [?] default: 1 Unknown. Presumably adjusts a lightning gun effect. --------------------------------------------------------------------------------
cg_waveamplitude (variable)(C) syntax: cg_waveamplitude [?] default: 1 Unknown. --------------------------------------------------------------------------------
cg_wavefrequency1 (variable)(C) syntax: cg_wavefrequency1 [?] default: 0.4 Unknown. --------------------------------------------------------------------------------
changevectors (command) syntax: changevectors [definition] Unknown. --------------------------------------------------------------------------------
cheats (variable)(R) syntax: cheats [0/1] default: 1 Reports the ability to use commands and variables coded as cheats. Enabled until a map is loaded. Stays enabled if a map is loaded with the "devmap" command. 0=disabled;1=enabled. --------------------------------------------------------------------------------
cinematic (command) syntax: cinematic [videoname] Presumably plays a cinematic from the \videos\ directory. --------------------------------------------------------------------------------
cl_anglespeedkey (variable) syntax: cl_anglespeedkey [value] default: 1.5 Seems to have no effect. --------------------------------------------------------------------------------
cl_avidemo (variable) syntax: cl_avidemo [screenshots per second] default: 0 Writes .TGA files of the current game screen for the creation of an .AVI file using the appropriate editing tool. Setting to 0 disables cl_avidemo. See also screenshot. - Ryan --------------------------------------------------------------------------------
cl_debugmove (variable) syntax: cl_debugmove [?] default: 0 Unknown. --------------------------------------------------------------------------------
cl_freezedemo (variable) syntax: cl_freezedemo [0/1] default: 0 When set to 1, stops the playback of a demo. Value then returns to 0. --------------------------------------------------------------------------------
cl_maxpackets (variable)(A) syntax: cl_maxpackets [5-100] default: 30 Sets maximum client transmission packet size. Optimum setting dependent on hardware type and connection quality. This setting is ignored during LAN play. --------------------------------------------------------------------------------
cl_motd (variable) syntax: cl_motd [?] default: 1 Toggles the sending of the GL_RENDERER string to id's Message of the Day server. The server then responds back with a message of the day. 0=disables;1=enables. --------------------------------------------------------------------------------
cl_mouseaccel (variable)(A) syntax: cl_mouseaccel [value] default: 0 Sets degree of mouse acceleration. Higher numbers=higher acceleration. Setting to 0 disables it. - Alexander Kaiser --------------------------------------------------------------------------------
cl_nodelta (variable) syntax: cl_nodelta [0/1] default: 0 Toggles delta compression on connection. 0=delta compression;1=no delta compression. --------------------------------------------------------------------------------
cl_noprint (variable) syntax: cl_noprint [0/1] default: 0 Toggles the writing of console echoes and player messages in the console buffer, and therefore on the screen. 0=display text;1=don't display text. - LOKi --------------------------------------------------------------------------------
cl_packetdup (variable)(A) syntax: cl_packetdup [0-5] default: 1 Presumably sets the number of times the client sends duplicate packets to the server to compensate for packet loss. - dynamite --------------------------------------------------------------------------------
cl_pitchspeed (variable)(A) syntax: cl_pitchspeed [value] default: 140 Sets the pitch rate when +lookup and/or +lookdown is active. --------------------------------------------------------------------------------
cl_run (variable)(A) syntax: cl_run [0/1] default: 1 Toggles 'always run'. 0=disables;1=enables. --------------------------------------------------------------------------------
cl_running (variable)(R) syntax: cl_running [0/1] default: 1 Reports if the server is running on the local machine. 0=server not on local machine;1=server on local machine. - dynamite --------------------------------------------------------------------------------
cl_showmouserate (variable) syntax: cl_showmouserate [0/1] default: 0 Toggles the display of mouse input info. The first number displays the degree of change when mouse input is received and the second the sensitivity value. 0=disables;1=enables. --------------------------------------------------------------------------------
cl_shownet (variable) syntax: cl_shownet [0/1] default: 0 Toggles the display of numbers presumably reporting some sort of net status. 0=disables;1=enables. --------------------------------------------------------------------------------
cl_showtimedelta (variable) syntax: cl_showtimedelta [0/1] default: 0 Toggles the display of numbers, purpose unknown. 0=disables;1=enables. --------------------------------------------------------------------------------
cl_timenudge (variable) syntax: cl_timenudge [time in seconds] default: 0 Sets time delay between player input and game update. Serves as adding a lag effect to a local connection. --------------------------------------------------------------------------------
cl_timeout (variable) syntax: cl_timeout [time in seconds] default: 125 Sets the amount of time for the client to wait for a server packet before assuming a disconnected state. --------------------------------------------------------------------------------
cl_updateinfostring (variable)(R) syntax: cl_updateinfostring [?] default: "" Default values are not set, and is only used internally. Updates the client info string for the dumpuser report. - dynamite --------------------------------------------------------------------------------
cl_yawspeed (variable)(A) syntax: cl_yawspeed [value] default: 140 Sets the yaw rate when +left and/or +right is active. --------------------------------------------------------------------------------
clear (command) syntax: clear Clears the console buffer (removes text). --------------------------------------------------------------------------------
clientinfo (command) syntax: clientinfo Shows user cvars on the local machine, including user created variables set with the setu command. Report includes: rate, snaps, model, snd, color, handicap, name, status, current server address --------------------------------------------------------------------------------
cm_debugsize (variable) syntax: cm_debugsize [value] default: 2 Sets the size of the debug surface grid for curved surfaces when r_debugsurface is 1. - dynamite --------------------------------------------------------------------------------
cm_noareas (variable)(C) syntax: cm_noareas [?] default: 0 Unknown. --------------------------------------------------------------------------------
cm_nocurves (variable)(C) syntax: cm_nocurves [0/1] default: 0 Toggles the ability of the player bounding box to clip through curved surfaces. 0=disables;1=enables. See also cm_playercurveclip. --------------------------------------------------------------------------------
cm_playercurveclip (variable)(A C) syntax: cm_playercurveclip [0/1] default: 1 Toggles the ability of the player bounding box to respect curved surfaces. 0=disables;1=enables. See also cm_nocurves. --------------------------------------------------------------------------------
cmd (command) syntax: cmd [command] Executes a valid command. Usage generally not necessary. --------------------------------------------------------------------------------
cmdlist (command) syntax: cmdlist Reports to the console all console commands listed. --------------------------------------------------------------------------------
color (variable)(U A) syntax: color [integer] default: 4 Sets the effects color for the railgun. 1=Blue 2=Green 3=Cyan 4=Red 5=Magenta 6=Yellow 7=White -------------------------------------------------------------------------------- com_dropsim (variable)(C) syntax: com_dropsim [?] default: 0 Unknown. --------------------------------------------------------------------------------
com_hunkmegs (variable)(A L) syntax: com_hunkmegs [Mb] default: 20 Sets the amount of memory that QUAKE3.EXE will allocate for itself. - dynamite --------------------------------------------------------------------------------
com_maxfps (variable)(A) syntax: com_maxfps[integer] default: 100 Sets the frames/second cap. Disabled when timedemo is 1. --------------------------------------------------------------------------------
com_showtrace (variable)(C) syntax: com_showtrace [0/1] default=0 Toggles running display of some sort of data. 0=disables;1=enables. --------------------------------------------------------------------------------
com_speeds (variable) syntax: com_speeds [0/1] default=0 Toggles the reporting of game speed data. Output includes (time in milliseconds): All; SV (server time); EV(?); CL (client time); GM (game time); RF (renderer time). 0=disables;1=enables. - dynamite --------------------------------------------------------------------------------
con_notifytime (variable) syntax: con_notifytime [time in seconds] default: 3 Sets the amount of time console messages will appear on the screen. When set to 0 no messages appear. --------------------------------------------------------------------------------
conback (variable) syntax: conback [path/filename] default: "gfx/2d/conback.tga" Sets the image file used as the console background. --------------------------------------------------------------------------------
condump (command) syntax: condump [filename.extension] Writes a file in the working directory containing all text in the console buffer. --------------------------------------------------------------------------------
configstrings (command) syntax: configstrigs Reports server configuration info. --------------------------------------------------------------------------------
connect (command) syntax: connect [IP address] [port] Connects to a server. If no port is specified the default port is used. --------------------------------------------------------------------------------
crash (command) syntax: crash Crashes Q3Test immediately. Be prepared to reset your desktop resolution. --------------------------------------------------------------------------------
crosshairhealth (variable)(A) syntax: crosshairhealth [0/1] default: 1 Toggles the color-changing property of the crosshair based on the player's current health. 0=disables;1=enables. --------------------------------------------------------------------------------
crosshairsize (variable)(A) syntax: crosshairsize [value] default: 24 Sets the size of the crosshair. --------------------------------------------------------------------------------
cvar_restart (command) syntax: cvar_restart Returns all console variables to their default settings. Does not affect key bindings. --------------------------------------------------------------------------------
cvarlist (command) syntax: cvarlist Reports to the console all console variables listed, and their current values. --------------------------------------------------------------------------------
demo (command) syntax: demo [demoname.dm2] Plays a pre-recorded demo. --------------------------------------------------------------------------------
debuggraph (variable)(C) syntax: debuggraph [0/1] default: 0 Toggles the display of some sort of graph, presumably for debugging purposes. 0=disables;1=enables. --------------------------------------------------------------------------------
dedicated (variable)(L) syntax: dedicated [value] default: 0 Toggles the use of the server as dedicated, meaning no graphic environment. This command should be passed on the command line. Valid values: 0=disables 1=enables for internet use, updating id's master server list 2=enables for LAN play -------------------------------------------------------------------------------- developer (variable) syntax: developer [integer] default: 0 Toggles the display of file loadings, errors and cvar change reports on the console. Seems to only have an on/off state. 0=disables;1=enables. --------------------------------------------------------------------------------
devmap (command) syntax: devmap [mapname] Loads a map file specifying cheats 1. The .BSP file extension is not required. See also map. --------------------------------------------------------------------------------
dir (command) syntax: dir [dir] [extension] Reports the contents of a directory. Examples: If you want to see your "scripts" folder, enter: dir scripts If you want to see your "quake3" folder, enter: dir ../ If you want to see your config files, enter: dir ..\baseq3\*.cfg - badak --------------------------------------------------------------------------------
disconnect (command) syntax: disconnect Disconnects the client from the server. --------------------------------------------------------------------------------
dmflags (variable)(A S) syntax: dmflags [value] default: 0 Sets the game options for deathmatch play. --------------------------------------------------------------------------------
dumpuser (command) syntax: dumpuser [userid] Reports info on the specified user. Info includes: name, handicap, color, snd, model, snaps, rate --------------------------------------------------------------------------------
echo (command) syntax: echo [string] Echoes text to the console on the local machine. --------------------------------------------------------------------------------
error (command) syntax: error [string] Causes Q3Test to quit with the error message specified in the string. Will leave the intial Q3Test startup window on the desktop. --------------------------------------------------------------------------------
exec (command) syntax: exec [filename.cfg] Loads a configuration file. --------------------------------------------------------------------------------
fixedtime (variable)(C) syntax: fixedtime [value] default: 0 Sets how fast the game runs. Setting to 0 disables fixedtime. Similar to timescale but frames are not dropped to maintain speed scale. - dynamite --------------------------------------------------------------------------------
follow (command) syntax: follow [player_name or id] Follows indicated player when in team is "s" (spectator mode). --------------------------------------------------------------------------------
fov (variable)(A) syntax: fov [value in degrees] default: 90 Sets the size of the field of view. Values over 90 do not prevent the gun model from appearing. Maximum value=160. --------------------------------------------------------------------------------
fraglimit (variable)(S A) syntax: fraglimit [value] default: 20 Sets the number of frags required for the game to be won if timelimit has been not reached or set. Setting to 0 disables fraglimit. --------------------------------------------------------------------------------
freelook (variable)(A) syntax: freelook [0/1] default: 1 Toggles the use of "always look", so that the mouse or similar device is used for looking and turning rather than movement. 0=disables;1=enables. --------------------------------------------------------------------------------
freeze (command) syntax: freeze [time in seconds] Freezes the game for the specified number of seconds. --------------------------------------------------------------------------------
fs_basepath (variable)(I) syntax: fs_basepath [drive\path\quake3_dir] default: C:\Q3TEST Sets the drive and directory where QUAKE3.EXE and associated files are located. - various --------------------------------------------------------------------------------
fs_cdpath (variable)(I) syntax: fs_cdpath [drive\path\cd_dir] default: "" Presumably sets the CD drive and directory where QUAKE3.EXE should read files from. -various --------------------------------------------------------------------------------
fs_copyfiles (variable)(I) syntax: fs_copyfiles [?] default: 0 Unknown. --------------------------------------------------------------------------------
fs_debug (variable) syntax: fs_debug [0/1] default: 0 Toggles the reporting of debugging info when files are accessed. 0=disables;1=enables. - dynamite --------------------------------------------------------------------------------
fs_game (variable)(S I) syntax: fs_game [game_dir] default: "" The game directory QUAKE3.EXE should read files from first, and where it will write files. Used for mods. - various --------------------------------------------------------------------------------
fs_restrict (variable)(I) syntax: fs_restrict [0/1] default: 1 Toggles restiction of use of the other fs_* cvars. This cannot be changed in the Test, which runs in restricted demo mode. 0=disables;1=enables. - dynamite --------------------------------------------------------------------------------
g_arenaname (variable)(R) syntax: g_arenaname [?] default: 0 Unknown. --------------------------------------------------------------------------------
g_arenarank (variable)(A) syntax: g_arenarank [?] default:"" Unknown. --------------------------------------------------------------------------------
g_arenascores (variable)(A) syntax: g_arenascores [?] default:"" Unknown. --------------------------------------------------------------------------------
g_debugalloc (variable) syntax: g_debugalloc [?] default: 0 Unknown. --------------------------------------------------------------------------------
g_debugmove (variable) syntax: g_debugmove [?] default: 0 Unknown. --------------------------------------------------------------------------------
g_forcerespawn (variable) syntax: g_forcerespawn [time in seconds] default: 20 Sets the amount of time a killed player will be forceably respawned. Setting to 0 disables g_forcerespawn. --------------------------------------------------------------------------------
g_gametype (variable)(S A L) syntax: g_gametype [value] default: 0 Sets the type of game played. Possible values: 0=FFA 1=Tournament(One on One) 2=Team Deathmatch 3=Capture the Flag -------------------------------------------------------------------------------- g_gravity (variable) syntax: g_gravity [value] default: 800 Sets the gravity level. This is normally set by a property of the map loaded. --------------------------------------------------------------------------------
g_inactivity (variable) syntax: g_inactivity [time in seconds] default: 0 Presumably sets the amount of time a player can remain inactive before kicked, or given some sort of no-camping warning. - value definition by burn --------------------------------------------------------------------------------
g_knockback (variable) syntax: g_knockback [value] default: 1000 Sets the amount of knockback effect a player recieves from weapon fire. --------------------------------------------------------------------------------
g_log (variable)(A) syntax: g_log [0/1] default: 1 Toggles the writing of GAMES.LOG in the current game directory, which logs gameplay events in the current session. 0=disables;1=enables. --------------------------------------------------------------------------------
g_maxgameclients (variable)(S A L) syntax: g_maxgameclients [value] default: 0 Unknown. --------------------------------------------------------------------------------
g_motd (variable) syntax: g_motd [string] default: "" Sets server message-of-the-day which appears when you log on to a server. Font color can be changed. Possible colors: 0 = Black 1 = Red 2 = Green 3 = Yellow 4 = Blue 5 = Cyan 6 = Magenta 7 = White --------------------------------------------------------------------------------
g_passwords (variable)(U) syntax: g_passwords [string] default: "" Sets a password for a private game by the server. Clients would need to specify the password also. See also password. --------------------------------------------------------------------------------
g_quadfactor (variable) syntax: g_quadfactor [value] default: 3 Sets the damage multiplier of the quad. --------------------------------------------------------------------------------
g_restarted (variable) syntax: g_restarted [value] default: 0 Unknown. --------------------------------------------------------------------------------
g_singleplayer (variable)(R) syntax: g_singleplayer [value] default: 0 Unknown. --------------------------------------------------------------------------------
g_speed (variable) syntax: g_speed [value] default: 320 Sets the maximum speed a player can move. --------------------------------------------------------------------------------
g_syncronousclients (variable) syntax: g_syncronousclients [0/1] default: 1 Toggles syncing of all clients movements. Must be enabled for recording demos of a game session. 0=disables;1=enables. --------------------------------------------------------------------------------
g_weaponrespawn (variable) syntax: g_weaponrespawn [time in seconds] default: 5 Sets the amount of time to wait before respawning weapons. Setting to 0 causes the weapons to respawn instantly. --------------------------------------------------------------------------------
g_warmup (variable)(A) syntax: g_warmup [time in seconds] default: 5 Sets the amount of warmup time in Tournament mode. --------------------------------------------------------------------------------
gamedate (variable)(R) syntax: gamedate [string] default: "May 10 1999" The release date of the current version. --------------------------------------------------------------------------------
gamename (variable)(S R) syntax: gamename [dir name] default: demoq3 The game directory quake3.exe is working. --------------------------------------------------------------------------------
gfxinfo (command) syntax: gfxinfo Reports current graphics rendering info, including: OpenGL extensions loaded, color depth, resolution, status of multithreaded support and the state of some rendering options. --------------------------------------------------------------------------------
give (command) syntax: give [weapon, item, or ammo] A cheat to give yourself something. Valid choices (not a complete list): all (all weapons, 999 ammo of all types, 200 armor) shotgun grenade launcher rocket launcher flamethrower railgun plasma gun lightning gun bfg10k grappling hook bullets (50 - machinegun ammo) shells (10 - shotgun ammo) grenades (5 - grenade launcher ammo) rockets (5 - rocket launcher ammo) slugs (20 - railgun ammo) cells (30 - plasma gun ammo) armor (200) quad damage personal teleporter medkit flight speed invisibility regeneration -------------------------------------------------------------------------------- globalservers (command) syntax: globalservers [zone] Searches for servers on the internat. --------------------------------------------------------------------------------
god (command) syntax: god Enables invulnerability mode. Entering the command again disables it. --------------------------------------------------------------------------------
graphheight (variable)(C) syntax: graphheight [number of pixels] default: 32 Sets the height of a displayed graph. --------------------------------------------------------------------------------
graphscale (variable)(C) syntax: graphscale [value] default: 1 Sets the scale of the lines in a displayed graph. --------------------------------------------------------------------------------
graphshift (variable)(C) syntax: graphshift [value] default: 0 Setting shifts all graph lines up or down on a displayed graph. --------------------------------------------------------------------------------
gun_x (variable)(C) syntax: gun_x [value] default: 0 Determines the position the gun model will be drawn along the x axis. --------------------------------------------------------------------------------
gun_y (variable)(C) syntax: gun_y [value] default: 0 Determines the position the gun model will be drawn along the y axis. --------------------------------------------------------------------------------
gun_z (variable)(C) syntax: gun_z [value] default: 0 Determines the position the gun model will be drawn along the z axis. --------------------------------------------------------------------------------
gun_frame (variable)(C) syntax: gun_frame [0 to 8] default: 0 Determines the gun model animation frame drawn. Setting to 0 allows normal animation. --------------------------------------------------------------------------------
handicap (variable)(U A) syntax: handicap [number of health points] default: 100 Sets the maximum health of the player when spawned. Setting to a lower number while alive causes the health to slowly erode. Values of 0 and those greater than 100 are ignored. --------------------------------------------------------------------------------
heartbeat (command) syntax: heartbeat Sends an update from the server to the master server with the result of updating server info. --------------------------------------------------------------------------------
hunk_stats (command) syntax: hunkstats Reports how much memory is in use. - dynamite --------------------------------------------------------------------------------
imagelist (command) syntax: imagelist Lists all image files loaded for the current map. --------------------------------------------------------------------------------
in_debugjoystick (variable) syntax: in_debugjoystick [0/1] default: 0 Unknown. --------------------------------------------------------------------------------
in_joyball (variable)(A) syntax: in_joyball [0/1] default: 0 Toggles polling the port used for game controller input, recognizing r, u, andv game controller axes. 0=disables;1=enables. --------------------------------------------------------------------------------
in_joyballscale (variable)(A) syntax: in_joyball [value] default: 0.02 Sets overall sensitivity for a game controller trackball, like that of a PantherXL. --------------------------------------------------------------------------------
in_joystick (variable)(A L) syntax: in_joystick [0/1] default: 0 Toggles polling the port used for game controller input, recognizing x, y, and z game controller axes. 0=disables;1=enables. --------------------------------------------------------------------------------
in_midi (variable)(A) syntax: in_midi [?] default: 0 Presumably enables/disables the use of MIDI music. --------------------------------------------------------------------------------
in_midichannel (variable)(A) syntax: in_midichannel [?] default: 1 Presumably sets number of MIDI channels. --------------------------------------------------------------------------------
in_mididevice (variable)(A) syntax: in_mididevice [?] default: 0 Presumably enables/disables the use of a MIDI device. --------------------------------------------------------------------------------
in_midiport (variable)(A) syntax: in_midiport [?] default: 1 Presumably enables/disables the MIDI input port. --------------------------------------------------------------------------------
in_mouse (variable)(A L) syntax: in_mouse [0/1] default: 1 Toggles polling the port used for mouse input. 0=disables;1=enables. --------------------------------------------------------------------------------
in_restart (command) syntax: in_restart Reinitializes the input system so new settings can take effect. --------------------------------------------------------------------------------
journal (variable)(I) syntax: journal [0/1] default: 0 Sets whether the file JOURNAL.DAT is written in the game directory QUAKE3.EXE is working. 0=don't write file;1=write file. - badak --------------------------------------------------------------------------------
kick (command) syntax: kick [player name or id] Kicks a player off the server. --------------------------------------------------------------------------------
kill (command) syntax: kill Commit suicide. --------------------------------------------------------------------------------
levelshot (command) syntax: levelshot This server command causes the current game to end as if fraglimit or timelimit has been reached, and writes a mini screenshot to the \levelshots\ directory if the command is executed by a player in the game - dynamite --------------------------------------------------------------------------------
localservers (command) syntax: localservers Searches for servers on a LAN. --------------------------------------------------------------------------------
logfile (variable) syntax: logfile [0/1/2] default: 0 Writes all console events to qconsole.log in the current game directory. 0=don't write log;1=write log;2=append log (appending does not seem to work). --------------------------------------------------------------------------------
m_forward (variable)(A) syntax: m_forward [value] default: 0.25 Sets sensitivity of the mouse for forward/back movement when freelook is 0 and +mlook is inactive. Setting to negative inverts the axis action. --------------------------------------------------------------------------------
m_pitch (variable)(A) syntax: m_pitch [value] default: 0.022 Sets sensitivity of the mouse for looking up and down when freelook is 1 and/or +mlook is active. Setting to negative inverts the axis action. --------------------------------------------------------------------------------
m_side (variable)(A) syntax: m_side [value] default: 0.25 Sets sensitivity of the mouse for strafing movement when freelook is 0 and +mlook is inactive. Setting to negative inverts the axis action. --------------------------------------------------------------------------------
m_yaw (variable)(A) syntax: m_yaw [value] default: 0.022 Sets sensitivity of the mouse for turning action when freelook is 1 and/or +mlook is active. Setting to negative inverts the axis action. --------------------------------------------------------------------------------
map (command) syntax: map [mapname] Loads a map file, specifying cheats disabled. The .BSP file extension is not required. See also devmap. --------------------------------------------------------------------------------
map_restart (command) syntax: map_restart Restarts the game on the current map. Replaces restart. --------------------------------------------------------------------------------
mapname (variable)(S R) syntax: mapname [filename] default: nomap Identifies the filename of the currently loaded map. -------------------------------------------------------------------------------- zlib 常用函数说明quake3 的 *.pk3 文件采用的 zip 压缩算法
typedef struct unz_global_info_s
{ unsigned long number_entry; //该成员为整个压缩包包含文件的数量 unsigned long size_comment; /* size of the global comment of the zipfile */ } unz_global_info; /* unz_file_info contain information about a file in the zipfile */
typedef struct unz_file_info_s { unsigned long version; /* version made by 2 unsigned chars */ unsigned long version_needed; /* version needed to extract 2 unsigned chars */ unsigned long flag; /* general purpose bit flag 2 unsigned chars */ unsigned long compression_method; /* compression method 2 unsigned chars */ unsigned long dosDate; /* last mod file date in Dos fmt 4 unsigned chars */ unsigned long crc; /* crc-32 4 unsigned chars */ unsigned long compressed_size; /* compressed size 4 unsigned chars */ unsigned long uncompressed_size; /* 成员为解压后文件的大小 4 unsigned chars */ unsigned long size_filename; /* filename length 2 unsigned chars */ unsigned long size_file_extra; /* extra field length 2 unsigned chars */ unsigned long size_file_comment; /* file comment length 2 unsigned chars */ unsigned long disk_num_start; /* disk number start 2 unsigned chars */
unsigned long internal_fa; /* internal file attributes 2 unsigned chars */ unsigned long external_fa; /* external file attributes 4 unsigned chars */ tm_unz tmu_date;
} unz_file_info; typedef struct
{ FILE* file; /* io structore of the zipfile */ unz_global_info gi; /* public global information */ unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/ unsigned long num_file; /* number of the current file in the zipfile*/ unsigned long pos_in_central_dir; /* pos of the current file in the central dir*/ unsigned long current_file_ok; /* flag about the usability of the current file*/ unsigned long central_pos; /* position of the beginning of the central dir*/ unsigned long size_central_dir; /* size of the central directory */
unsigned long offset_central_dir; /* offset of start of central directory with respect to the starting disk number */ unz_file_info cur_file_info; /* public info about the current file in zip*/
unz_file_info_internal cur_file_info_internal; /* private info about it*/ file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current file if we are decompressing it */ unsigned char* tmpFile; int tmpPos,tmpSize; } unz_s; struct s_path
{
char Filename[MAX_QPATH]; //文件名称 int pos_in_central_dir; //文件在zip包中的位置 } zipfile_t; //打开zip文件
unzFile ZipFile;
ZipFile = unzOpen( FullPath ); //输入压缩文件 如 c:\quake3\pak0.pk3 //获取zip文件信息, zip内文件数量 unz_global_info GlobalInfo;
err = unzGetGlobalInfo( ZipFile, &GlobalInfo ); //将文件指针移动到 zip 文件的第一个文件处。
unzGoToFirstFile(ZipFile);
//获取zip内当前文件指针指向的文件信息
chat filename_inzip[MAX_PATH];
unz_file_info FileInfo;
err = unzGetCurrentFileInfo( ZipFile, &FileInfo, filename_inzip, MAX_PATH, NULL, 0, NULL, 0 );
//获取zip内当前文件指针所在的位置。可以用hashmap 记录文件名称对应zip位置,便于以后读写
int pos;
unzGetCurrentFileInfoPosition(ZipFile,&pos);
//将zip内文件指针移动到指定的位置
unzSetCurrentFileInfoPosition(ZipFile, pos);
//移动到zip内下一个文件
unzGoToNextFile( ZipFile ); //关闭zip当前打开的文件
unzCloseCurrentFile( ZipFile ); //打开zip当前所在的文件
unzOpenCurrentFile( ZipFile ) //读取zip当前打开的文件
char buf[bufsize];
if( unzReadCurrentFile( ZipFile, buffer, bufsize ) < 0 ) //关闭zip当前打开的文件
unzCloseCurrentFile( ZipFile ); 1 个 window api 函数用法
Handle = FindFirstFile(FullPath, &FindFile); FullPath 可以有如下形式 e:\quake3\*.pk3 这样将查找所有*.pk3文件 一个读取zip文件中文本文件的演示程序地址(2007/10/20): http://www.91files.com/?QC89XBQFRDPD1WYP8G4J May 16 Gamma 校正 Gamma校正是全屏的, 现在的显卡都支持, 同样, Gamma校正可以实现一些特殊效果,各种图像淡入、淡出效果渐变等等。
图12.2 图中梯度映射校正最大为65535, 表示梯度使用WORD表示. 每种原色都有各自的梯度映射校正, 默认的三原色梯度映射校正都是相同的梯度斜率1, 例如对于RGB(0, 128, 255)进行校正, 如图12.3
图12.3 0 [梯度映射校正]--> 0 [梯度到原色] --> 0 [最后输出颜色的RED分量]
图12.4 0 [梯度映射校正]--> 0 [梯度到原色] --> 0 [最后输出颜色的RED分量] 然后通过IDirect3DDevice9的函数SetGammaRamp设置, //quake3 中的调整gamma 方法。对应配置参数 r_gamma 调整 gamma, overbrightbits 调整亮度,r_intensity 调整对比度 D3DGAMMARAMP GammaRamp; int i = 0; for ( i = 1 ; i < 256 ; i++ ) for(i=0;i<256;++i) { // 下面这种相对不够细腻,只相当于 overbright //for(i=0;i<256;++i) {
还有对比度:需要调整的是载入的图片的象素值。 I'm sure you've all seen gamma correction before, but you might not know exactly how it works or why it is necessary. In this article, I'll try to explain both, as well as provide practical information on how to implement gamma correction in your apps.
Intuitively, you might think of gamma correction as some sort of image brightness adjustment. That's not entirely wrong, but to understand why gamma correction is necessary, you need to look a little further. More precisely, you'll need to look inside your computer's display. Chances are that your monitor is based on a cathode ray tube (CRT). A CRT uses an electron beam to make the phosphor coating inside the tube emit light. The brightness of a pixel is changed by varying the voltage of the electron beam as it touches that pixel. Unfortunately, the relation between CRT voltage and pixel brightness isn't linear. It looks something more like this: This non-linearity effect is called gamma. Unfortunately, it causes the image displayed on your computer screen to be different from the image that is actually in memory. What you really want to see is a nice linear mapping between voltage and brightness. In other words: the graph above should be a straight line. That's why you should perform gamma correction. Gamma correction is performed by remapping the colors in the image as such:
The gamma-corrected color ramp can be calculated by raising the original color values to some power:
The exponent to use is the so-called "gamma value", which you can see in paint programs that support gamma correction. The gamma value should be user-configurable, of course. You've probably already noticed: by using the gamma-corrected color ramp, you can cancel out the gamma effect of your monitor, resulting in a correct display of the image:
This leaves one thing to be discussed: how to implement gamma correction. If you're just working with bitmap images, you can perform it manually for each pixel. This being an OpenGL site and all, I suspect that this isn't really what you want to do. Luckily, you can ask your graphics card to perform the correction for you (in real-time, of course). To this effect, you can use the GetDeviceGammaRamp() and SetDeviceGammaRamp() API calls. I've written a small OpenGL demo that illustrates the use of these functions. Download it here. That's all there's to it! Gamma correction is easy enough to understand and implement - and especially for games with dark environments, it can make a huge difference. Gamma correction will allow users to adjust the image brightness to suit their monitor, allowing them to see your game or application as you intended them to see it. May 15 学习quake3遇到的问题Quake3:
1. 对于1.32b Relase 版本,提示 User Interface is version 3, expected 6,不能进入游戏
quake3 打包文件pak0.pk3 中 vm 虚拟机版本问题,对于1.32b 代码Release版本不能启动。 quake3为了跨几个平台,有自己的虚拟机,让其他平台也有类似dll功能。
解压pak0.pk3 后vm中3个.qvm文件, 相当于windows下的dll文件: cgamex86.dll,qagamex86.dll,uix86.dll。所以把相应的Release版本dll文件拷贝到 baseq3 目录,而且需要解压pak0.pk3 ,之后删除pak0 目录中vm下面的3个.qvm文件。然后如下在设置下面3个参数(注意是 +set ...,可以用快捷方式启动:quake3.exe +set sv_pure 0 +set vm_game 0 +set vm_cgame 0,或在控制台里修改,而不是修改q3config.cfg,修改这个文件是不起作用的。只有Archieve命令在这个文件中修改才起作用):
a. As you're building DLLs not QVM's you must run with +set vm_game 0 to get it to see the game dll, and vm_cgame 0 to get it to see a cgame dll.
b. Once you build a cgame project as well as a game, you'll also need +set sv_pure 0, so that the client can access files outside of pk3's.
也只有按上面修改之后才能调试 cgame,game,q3_ui 这3个工程
对于多玩家对战,设置服务器的时候 pure server 不要选择 on, 这样也会寻找使用 qvm 文件,而不是dll。以至于登陆这样的服务器时客户端会提示上面的接口不一致错误。
2. 原来一直为quake3 菜单的 QUAKE III ARENA 这2行字惊奇,不知如何实现的。原来是做好的3d模型,位于:
baseq3\pak0\models\mapobjects\banner\banner5.md3
UI_SetActiveMenu() -- UI_MainMenu() -- MainMenu_Cache() --trap_R_RegisterModel( MAIN_BANNER_MODEL );
#define MAIN_BANNER_MODEL "models/mapobjects/banner/banner5.md3"
3. char * QDECL va( char *format, ... ) 用来代替 sprintf(char* buf,char* format,...) 省掉了每次为buf分配空间。不过传入va的字符不应该超过 32000 个。
4. 录制 demo , 进入关卡后在控制台输入 record . 控制台变量 g_synchronousClients 最好设置为 "1",让客户端移动同步. 输入 stoprecord 结束录制。 journal 录制巨集,记录了所有的动作,包括ui里面的点击等等
5. bsp 树能加速主要是静态时已经生成了潜在可见集 pvs, 对于每个 cluster (相当于一个小房间包含若干node,node对应bsp树枝树叶,树叶中包含了需要画的多边形)都有自己的一个 pvs 数组。每个位为0或1,代表其对其他 cluster 是否可见。
6. quake3 网络传输十分强大,33.6k 都可以连线游戏。目前知道的有 delta compress 和 huffman 算法。主要是delta compress 减少了网络传输流量。自适应 huffman 算法,只起到了静态huffman树的作用。网络传输过程没有更新树编码操作。
7. bsp 树取分割面的一个原则:只取垂直于地平面的平面作为分割面。分割面两边的多边形数目越接近越好. static mesh 也就是比较复杂的几何体如球,通常他们的三角形面太多而且不共面。进行bsp分割时不考虑他们,而是生成bsp树后,在放入相应的叶节点 2007.10.9 补充 8. 遇到一个妖怪级错误,抄写quake3 到了菜单界面,结果黑屏不能显示。鼓捣了一个星期,开始怀疑扔掉了qboolean改用bool的问题,全部改回qboolean问题依旧。逐行对比源码:(,浪费了近一周时间。偶然才发现是一个头文件结构glConfig参数位置和quake3的不相同,而ui的dll用到了这个头文件,但UI是用的原来quake3编译好的dll。看来一些公用的结构改动是要仔细注意了,还好不是很多。改成bool 的 qboolean 也要恢复回去了。 9. r_nobind 设置为1之后进入一个菜单项,还能显示原来的图片,不过有些乱,不太一样。原来进入菜单项新的纹理加载时,调用 GL_Bind 绑定到 tr.dlightimage 的纹理 num。glTexImage2D 函数针对这个纹理number写入了新的图像数据。好像这样处理偏离了原意。在 “quake3 主要参数” 里写了改正的方法。唉,浪费了一个晚上。晚上还真是迟钝了啊。一直没想到,还奇怪怎么没绑定到纹理号的纹理也显示出来了。 10. r_gibs 参数控制满屏幕飞血的效果。也是 md3 特效,而非 shader 特效 May 14 c 不需要强制转换malloc的返回值
c++ 误区 fflush(stdin)来源:蚂蚁的 C/C++ 标准编程 作者:antigloss 等级:精品 1. 为什么 fflush(stdin) 是错的
首先请看以下程序:
#include <stdio.h>
int main( void ) { int i; for (;;) { fputs("Please input an integer: ", stdout); scanf("%d", &i); printf("%d\n", i); } return 0; }
这个程序首先会提示用户输入一个整数,然后等待用户输入,如果用户输入的是整数,程序会输出刚才输入的整数,并且再次提示用户输入一个整数,然后等待用户输入。但是一旦用户输入的不是整数(如小数或者字母),假设 scanf 函数最后一次得到的整数是 2 ,那么程序会不停地输出“Please input an integer: 2”。这是因为 scanf("%d", &i); 只能接受整数,如果用户输入了字母,则这个字母会遗留在“输入缓冲区”中。因为缓冲中有数据,故而 scanf 函数不会等待用户输入,直接就去缓冲中读取,可是缓冲中的却是字母,这个字母再次被遗留在缓冲中,如此反复,从而导致不停地输出“Please input an integer: 2”。
也许有人会说:“居然这样,那么在 scanf 函数后面加上‘fflush(stdin);’,把输入缓冲清空掉不就行了?”然而这是错的!C和C++的标准里从来没有定义过 fflush(stdin)。也许有人会说:“可是我用 fflush(stdin) 解决了这个问题,你怎么能说是错的呢?”的确,某些编译器(如VC6)支持用 fflush(stdin) 来清空输入缓冲,但是并非所有编译器都要支持这个功能(linux 下的 gcc 就不支持),因为标准中根本没有定义 fflush(stdin)。MSDN 文档里也清楚地写着fflush on input stream is an extension to the C standard(fflush 操作输入流是对 C 标准的扩充)。当然,如果你毫不在乎程序的移植性,用 fflush(stdin) 也没什么大问题。以下是 C99 对 fflush 函数的定义:
int fflush(FILE *stream);
如果 stream 指向输出流或者更新流(update stream),并且这个更新流
If stream points to an output stream or an update stream in which
其中,宿主环境可以理解为操作系统或内核等。
由此可知,如果 stream 指向输入流(如 stdin),那么 fflush 函数的行为是不确定的。故而使用 fflush(stdin) 是不正确的,至少是移植性不好的。
2. 清空输入缓冲区的方法
虽然不可以用 fflush(stdin),但是我们可以自己写代码来清空输入缓冲区。只需要在 scanf 函数后面加上几句简单的代码就可以了。
if ( feof(stdin) || ferror(stdin) ) /* 不过会残留 \n 字符。 */ printf("%d\n", i); using std::cout; int main() // do something return 0; May 12 quake3 mod 制作教程来自:[url]www.q3acn.com[/url]
0. 前言 "blah, blah, blah..." 各位quaker晚上好,白天也好,这里是q3acn.com的article栏目,这次为你准备的内容是mod制作入门教程,在屏幕的右方你可以看到目录,其中第1节是给还没有自己编译过q3游戏部分源代码的朋友看的,第2节和第3节是游戏源代码的一些入门知识,就算你不打算做mod,只是对quake3的运行机制有兴趣,这两节也很适合你,最后两节我们就要自己动手做两个有趣的功能,不过如果你直接从第4或第5节开始看的话,有些概念可能会不大明白,建议你还是按部就班的依次阅读下去。 整篇教程比较长,你可以需要把它们保存到硬盘上离线浏览,里面有几张图片,你要选择全部html或者是mht。 在解释或分析源代码的过程中,我会尽量不直接说,这个是什么意思,而那个又是干什么用的,我会尽量把我如何知道它们的含义和用途的这个过程也写出来,一方面是为了你以后解决自己的问题提供经验,另一方面,即使你不打算继续研究这些代码,我也希望这篇入门教程能给你带来多一些DIY的乐趣。 可能你对编程不熟悉,甚至对编程一点概念没有,请不要畏缩,虽然对这些源代码进行修改需要一定的编程经验,和一段时间c语言的学习,但是如果只是阅读和理解它们,frag的经验远比编程经验有用,给一个没打过quake的编程高手这套源代码,他理解这些代码的速度绝对比你:一个quake老兵同时也是编程新手,要慢得多。在头几节对于出现C语言的地方和VC的一些技巧做出了一些解释和说明,当然,只是为了让你读起来比较流畅,想仔细研究代码和学习VC的话,你需要专门的教科书,注意,你不需要任何关于c++的知识,尽管VC又被称为VC++。 Disclaimer & Copyright 1、既然你已经点击了这篇文章,说明你对mod制作抱有兴趣,有必要在一开始说明,制作出来的mod只能被免费的通过网络发放,而不能被用于任何商业用途,这是你在安装源代码的过程中必然要同意的条款,而不只是quake社区乌托邦式的理想。(我知道进来看的人都是quaker,跟你说这个有点不尊重你,但我在生活中的确遇到过这样的人,跟我说“既然地图编辑器,游戏源代码都公开了,那做几幅地图,做几把新的枪,不就可以当任务版卖钱了嘛”,.............他们都是不打quake的,不要跟他们一般见识) 2、作者已经尽了最大努力保证文章中信息的正确性和准确性,但如果在阅读本文或依照本文进行操作的过程中造成了对你的软件/硬件/精神上的损害,与作者无关。 3、你可以在不做任何改动并注明原始出处([url]www.q3acn.com[/url])和作者(ed9er)的前提下任意在网上转载全文或引用或文字图片,无须通知作者,但作者不允许传统媒体进行上述行为。 1. 运行你的第一个MOD "Ease of use is damn important." —— John Carmack 1.1. 安装源代码 先准备好Q3_1.29h_src_fixed.zip这个文件(1.26M),这个包里我已经把原来1.29h源代码的一些编译错误改正了,另外添加了几个.bat;为了消除版本不一致可能带来的问题,你还需要有quake3 1.31。 你必须把zip中的所有文件解压到某个盘的根目录下的quake3目录,在这篇文章里我们用D:\quake3,如果你的quake3路径本身就是某个盘的根目录下的quake3目录,那么建议你不要解到这个目录下,换一个盘。 1.2. 生成qvm 你只需要简单的执行\quake3\code下的那几个bat文件,就可以生成相应的qvm文件,其中makeall.bat是生成所有三个模块的qvm文件,你可以现在就双击它,等它运行结束后,你就可以在\quake3\baseq3\vm目录下找到那些qvm文件,baseq3这个目录是q3asm.exe来建立的,我们无法更改它的名字,这也是为什么建议不要解压到quake3的运行路径。 下面我们用1.17源代码的readme里写的慢速火箭弹来做例子试试在quake3里运行我们的mod。 到game\g_missile.c的649行,把900改成300,存盘,运行code\game.bat,生成qagame.qvm,这时我们要把这个文件打包成zip:直接在\quake3\baseq3\vm这个文件夹的图标上用右键菜单来生成vm.zip,这样可以方便的保存文件的路径信息(和你的winzip的设置有关系,有可能你需要在baseq3目录上生成zip,反正最后你要确定在用winzip打开这个文件时在qagame.qvm这行的path列可以看到"vm\"),然后把vm.zip改名为vm.pk3,到你的quake3运行路径下建立mymod目录,把这个pk3拷贝过去,然后运行quake3.exe +set fs_game mymod +map q3dm17,然后吃RL,开炮。 (如果你运行的结果和预期不一致,火箭弹还是以常速飞行,请检查以上步骤,尤其是zip内目录的信息) 1.3. 用dll来实现mod。 quake对mod的支持走过了一条还算比较曲折的道路,在quake1的时候,用的是著名的quake c,其实就是个复杂的脚本解释器,在97年左右的电脑商情报上曾有比较详细的讲解,carmack本人对于众多玩家通过这个简陋的qc来开始编程之路既感到自豪又感到惭愧,于是到了quake2的时候,通过若干个.plan与玩家进行讨论后,carmack直接采用了windows的dll机制来分离引擎与游戏代码,这样就局限了quake2的mod的跨平台性,在quake3的开发过程中,java逐渐火了起来,carmack也曾流露出直接采用java/jvm来分离引擎与游戏代码的想法,但由于java的诸多不足,使得他最后放弃java,不厌其烦的自己实现了qvm,具体可参见:A chat with John Carmack, qvm是quake virtual machine的缩写,carmack采用了lcc编译器并做了一些修改,由lcc编译生成.asm,然后q3asm.exe这些.asm再进行一次处理,生成字节码,这些字节码会被quake3.exe在运行时转换成本地的机器码,这样既可以让玩家通过标准的C语言来编写MOD,同时又可以做到跨平台。而如果你需要使用到windows提供的各种系统调用或者是其他一些机制,qvm就无能为力了,但是,你仍然可以通过dll来实现,quake3在初始化的时候会在当前fs_game目录下寻找相应的dll,如果找不到,再去寻找qvm,但有一个很重要的区别,就是qvm可以打包在pk3文件中,而dll不能打包到pk3中。(看一下bg_lib.c,这个文件里实现了很多但不是全部的标准c函数,如果你使用了额外的函数,那么为了编译成qvm,你必须在这个文件里给出你的实现,如果是平台相关的函数,我就建议你不要做qvm的打算了,因为quake3支持的平台太多了,你不大可能拥有iMac, irix等等来测试并实现你的平台相关函数) 如果你机器上安装了VC6的话,你可以直接打开\quake3\code\quake3.dsw,在编译和运行之前你需要更改一下Project Setting,如下面两图,e:\quake3是我机器上的quake3运行路径,你需要把它改成你的quake3运行路径,quake3_1.31.exe是我用的exe的名字,你也需要更改,完成后设置game为活动项目,然后按F5就可以直接进入我们刚才改好的慢速火箭弹模式了;如果你需要在程序中设置断点,或者是进行单步执行,查看变量等debug动作的话,你需要把mymod/q3config.cfg里的r_fullscreen改为0,r_mode改成2,另外,不要通过VC的结束调试命令(Shift+F5)来强行终止quake3,这样会使你的系统不稳定,每次都用quake3的菜单或者是/quit来退出。 注意:当sv_pure为1的时候quake3只允许载入pk3文件以及.cfg、.menu文件,所以当你使用dll来调试的时候,一定要把sv_pure设为0,否则quake3会在你mod目录下寻找包含qvm的pk3并使用qvm,如果没有找到,quake3会使用baseq3下的缺省的qvm,当你最终发布的时候,再编译成qvm并打包成pk3。 如果你机器上没有安装VC6,并且你决心制作MOD或者是仔细研究q3游戏源代码的话,我强烈建议你装上它,而不要只是用UltraEdit和.bat,一方面是VC6强大的browse功能可以让你迅速查找变量、结构、函数的定义及调用关系等等,更重要的,你可以真正进入debug状态来运行代码,这在qvm是不可能的。 1.4. 如何从MOD菜单LOAD我们的mymod 首先,这个MOD的子目录下一定要有至少一个pk3文件或者qagamex86.dll,否则quake3不认为这是一个合法的MOD子目录,在MOD菜单中根本就看不到,这也是为什么我们在前面把vm\qagame.qvm打包的原因,你也可以不打包,直接在mymod下再建立一个vm目录,把qagame.qvm拷贝进去,然后再拷贝一个打过包的以.pk3结尾的地图文件进mymod,这样也可以工作,但是这样在sv_pure 1的情况下可能会有问题,还是建议你把qvm老老实实打个包。 然后,在MOD菜单中你就可以看到一栏"mymod",这是我们的目录名,但不是我们的MOD描述,我们需要在mymod下新建一个文本文件description.txt,里面只写一行:"My First Mod",这行文字就会显示在MOD菜单中,当然你也可以用"^1My First Mod^7"来显示红色的字,注意,description.txt不能打包到pk3中。 2. 代码的框架结构 "Discover YOUR World" —— Discovery Channel 我们先浏览一下它的目录结构: \quake3\binnt:编译源代码所需的可执行文件lcc.exe, q3asm.exe \quake3\source\lcc\bin:编译源代码所需的可执行文件cpp.exe, rcc.exe \quake3\ui:菜单的定义,你可以用文本编辑器打开那些.menu文件看个究竟 \quake3\code\cgame:客户端(cgame: client game)的源代码 \quake3\code\game: 服务器端(game)的源代码 \quake3\code\q3_ui:用户界面(ui: user interface)的源代码 \quake3\code\ui: TA的新增的界面功能的源代码 code下面这四个子目录下面各有一个dsp,和.bat,那么,我们就可以从这整个代码里编译出四个独立的模块(dll或者qvm),它们分别是:cgame、game、q3_ui和ui,在这里,id把名字弄的比较混乱,ui目录下是TeamArena里新增加的界面功能,而q3_ui目录下才是quake3的界面功能,ui目录下编译可以得到uix86_new.dll和ui.qvm,q3_ui下编译完成后可以得到uix86.dll或者q3_ui.qvm,dll的文件名是正常的,而如果你编译q3_ui目录下的东西并得到了q3_ui.qvm的话,你必须把它改名为ui.qvm才可以正常使用;这些在那几个bat里已经都处理了,你不用操心了。 ui目录我估计没人会用得到,我也一行没看过,我们来看q3_ui目录,这里面的.c文件全部都以ui加下划线开头,仔细观察一下他们的名字,你很容易就会联想到你在游戏中的菜单操作,譬如:ui_addbots.c——添加bot,ui_controls2.c——操作设置,ui_cinematics.c——选择观看过场动画,等等,随便打开一个你都可以看到一大把menu什么的结构,和UI_XXXMenu_Init之类的函数,至此,你可以很有信心的说,这个目录下面的程序负责了(也只负责)所有菜单的显示,选择,反馈。 然后我们来看cgame目录,这个目录下面文件都以cg加下划线开头,在这里我们光看文件名就看不出个所以然了,必须去看文件的内容,主要注意函数的名称就可以了,在这里只能简单的跟你说它控制了客户端HUD、比分牌的显示,以及与game的协调,对玩家移动的预测(这也是为什么一个LAG以后玩家会觉得被往后拽了一下),model的载入,音效的控制,等等。 最后是最庞大也最重要的game目录,一开始是一些以ai加下划线开头的文件,它们是关于BOT的控制,然后是bg加下划线开头的文件,它们是同时会被cgame使用到的文件(bg: both game),然后是g加下划线开头的文件,它们定义了这个世界的运行规则(quake3.exe负责把这个世界展现到你的显示器上),最后是几个以q加下划线开头的文件,它们是各个模块(包括quake3.exe和q3radiant)在编译时都要用到的文件,这几个文件你永远不需要也不能去改动它们。 至此,你至少知道要改某样东西需要从哪里下手了,下面我们来仔细看一下game模块。 首先一个最根本的问题,编译完之后得到的这个qagamex96.dll有哪些函数供quake3.exe调用,会在什么时候被调用?一个解决方法是在命令行用VC自带的工具dumpbin /exports来查看;另一个办法就是在源代码里找编译dll时指定导出函数的关键字:dllexport,你会发现找不到,他们把导出函数的定义放到了game.def文件里面,打开看就可以看到了;最后一个办法就是查看源文件里函数的调用关系,找到最顶上的那个,也就是在game模块里不被任何函数调用的函数,应该就是由quake3.exe来调用的了,通过VC的browse功能可以很方便的展开被调用树,你会发现几乎所有函数最后都归结到一个叫vmMain的函数,这和我们在game.def里面找到的是一致的,它在g_main.c的183行。(如果你真的去打开game.def文件看了的话,你会知道另外还有一个dllEntry,马上会谈到它) 在vmMain的注释里写的很清楚:这是唯一一个进入子模块的入口。它的第一个参数叫command,看下函数体就可以发现,这个参数指明了quake3.exe因为什么样的原因来调用子模块:GAME_INIT(初始化)、GAME_SHUTDOWN(结束)、GAME_CLIENT_CONNECT(有玩家连入)、GAME_CLIENT_DISCONNECT(玩家离开)、GAME_RUN_FRAME(一个server祯开始)、GAME_CONSOLE_COMMAND(控制台命令),等等。至于在每一种情况下这个game模块都干了些什么,就需要你跟着那些函数一层层进去看了。 好,我们再使用VC的Browse功能来查看函数的调用树(刚才是被调用树),你会发现所有函数最后都终止在一些sprintf等很简单的函数,以及,许多以trap_开头的函数,查看这些trap_函数的定义,它们在g_syscalls.c里面,这个文件一开始定义了一个函数指针syscall,并在dllEntry里对它进行赋值,在trap_函数里使用它,也就是说,quake3.exe负责调用dllEntry,告诉game模块它提供的函数的地址,然后game模块就可以使用这个函数(syscall,一个函数指针)取得quake3.exe提供的功能,这些功能是什么呢? 我们知道quake3的pk3文件其实就是zip文件,那么如果我们需要读取这个pk3文件中的一副贴图或者是一个wav,我们该怎么办?先解压?不用,quake3.exe内已经实现了透明的zip文件读取,并维护着一个很大的目录树,你只需要调用两个trap函数就可以读取你需要的文件,在pk3中的文件!它们是trap_FS_FOpenFile和trap_FS_Read。 再譬如,在cgame中(在game里我找不到好的例子了,cgame也有同样的函数调用机制),我们需要播放一段wav,你该不会去用windows的MCI函数来控制声卡吧,我们有trap_S_StartLocalSound。 类似地,若干个trap函数,这些函数都是三无产品:没有文档没有注释没有实现,它们都隐藏在quake3.exe内部,对于某一个特定的trap函数,如果你要弄清楚它的调用格式,以及它完成的功能,你只能看它在已有的代码中是如何被调用的,然后模仿现有的格式来使用它,千万不要妄加揣测自行其道。这里有玩家制作的一部分trap函数的文档:Q3 Documentation Project,还没有全部完成,你如果觉得你吃透了某个trap函数的用法,也可以去添一笔。 至此,知道了入口和出口,我们知道我们可以干什么了,譬如,我们无法直接通过网络传输数据,因为没有这样的trap函数,我们只能利用quake3.exe内部的传输机制(譬如server command或config string,等等,这是个很大的话题,有的在下面的内容里会讲到,但主要还是*你自己去探索)。 OK,告一段落,弄清楚模块划分和vmMain、trap_之后,你在看代码的时候就会有点方向感了。 还有,在代码中你会经常碰到: #ifdef MISSIONPACK 凡是看到这个东西,那都是TeamArena用的,把中间的部分略过,直到#endif或者#else,并且你要注意别把你添加的东西放到了这些ifdef内部。 3. Hello, Quake World! "Things will be done when they are done, and they should be pretty good. :)" —— John Carmack 在开始这一节之前,建议你把目前整套代码拷贝一份出来,如果改了900为300,再改回去,这样做有两个目的,一是为了你以后可以方便的从一套干净原始的代码的基础上开始修改,二是你可以保留这份代码专门做学习用,在里面添加注释,写上自己的理解,等等。 3.1 如何在屏幕上打印文字 我们马上要做的事情是在屏幕的中央打印出"Hello, Quake World!"这行字,你可能立即会想到,en...肯定有个trap函数可以往屏幕上写东西,对,一点不错,但是考虑一下有没有现成的封装的更简便函数供我们使用呢?回想一下我们在游戏中的时候会遇到哪些出现屏幕中央的信息,en...FIGHT! 好,在code目录下查找含FIGHT的文件,用VC的Find in files,选中搜索子目录,选中区分大小写和匹配全字,搜索结果只有一个: cgame\cg_servercmds.c(445): CG_CenterPrint( "FIGHT!", 120, GIANTCHAR_WIDTH*2 ); 幸福啊,我们只要替换下参数就可以打印需要的东西了,这时你不妨看一下CG_CenterPrint的实现,你就会发现它并没有直接使用trap,它只是把你要打印的东西放到了一个叫cg的结构变量的centerPrint成员变量里面,而cg是一个全局变量,那我们继续查找cg.centerPrint,这次可以找到3个,头两个就是在CG_CenterPrint里面,我们已经看到过它们了,而第三个在1837行,双击这个查找结果,我们就到了CG_DrawCenterString函数体内,一层层进去看一下吧,最后到了CG_DrawChar函数体内终于使用了trap做真正的输出,现在你该不会还想自己用trap来做了吧。 那么,我们在什么时候打印这行字呢?比较常规的办法是通过控制台命令来开始打印,(你也可以在开枪的时候打印,在看完这一节后结合你已经知道的哪个函数是发射rocket,你就可以自己完成)。我们都知道在控制台的输入命令需要以正斜杠或反斜杠开头,这些命令又分为两大类:cvar的变量名和控制台命令,而cvar又分为server端的cvar和client端的cvar,譬如g_gametype就是server端的,而cg_drawGun就是client端的,他们分别可以在g_main.c和cg_main.c里找到,还有一类cvar,是由quake3.exe来创建的,譬如r_mode,你可以在子模块中设置它的值,(尝试在code目录开始查找r_mode,你可以学习到一个trap函数的用法),这类cvar我们称之为internal cvar;控制台命令也可以做game/cgame这样的划分,也有一些命令是由quake3.exe来负责执行的,譬如vid_restart(尝试查找vid_restart,你可以学习到另一个trap函数的用法),这部分命令我们称之为internal command。 3.2 cvar和command 在这里我想费点口舌讨论下quake3是如何管理这些cvar和命令的,我不知道确切答案,但从quake2的源代码和我们现在手上的1.29h的代码是可以做出一些推测的,当然,推测不一定正确,但至少和程序的表现一致。 quake3.exe在初始化时会负责创建和初始化它内部的internal cvar和internal command,cvar结构中包含了它的名称,缺省值,属性,internal command的结构中包含了命令名称和它们对应的函数,然后quake3.exe会依次载入ui、cgame、game模块(具体顺序我不知道),在ui模块的初始化过程中,它向quake3.exe注册它模块自己的cvar,同样,在cgame模块的初始化过程中,它也要向quake3.exe注册它自己的cvar(cg_main.c/Ln308),game模块也一样,在g_main.c/Ln319。 好,这时quake3.exe就知道了所有cvar的信息,当我们在控制台敲入cvar的名字时,quake3.exe就可以找到这个cvar的值,以及它的缺省值,显示出来给你看。在这里你可能会有疑问,我在quake3的控制台中敲命令更改cvar的值后,更改的应该是由quake3.exe维护的数据,那它们是如何被反映到game/cgame子模块中的呢?也就是说game/cgame里的程序怎么知道玩家对这个值做了更改呢?这个问题就留给你自己去解决了,(提示:GAME_RUN_FRAME和CG_DRAW_ACTIVE_FRAME时的vmMain)。 而控制台命令有所不同,当你敲入的字符串不是cvar时,整个过程比较复杂,我在这里画了张流程图,你可以看一下,里面有几个地方要说明,一是playing server的意思,它就是你在非dedicated的quake3里敲map q3dm17得到的那种server,一般大家在局域网上打着玩都是开这种server; 二是5、7、8这三步它们所能解释的命令列表,你可以根据图里的vmMain的参数到程序里找到, 我在这里把它们给出来,但还是希望你自己从vmMain开始寻找它们:5: cg_consolecmds.c/Ln433,7: g_svcmds/Ln398,8: g_cmds.c/Ln1578;三是在第2步中要注意"是否可执行"这个判断,在一个dedicated server上运行vid_restart显然是不可执行的。 在这里,我们把第5步能解释的命令称为cgame console command,第7步能解释的称为game console command,第8步的称为client command,我们可以画出这样的一张表: 你可能会问,对于一个dedicated server,类似/callvote这样的client command有什么意义?在game console command处理的最后,我们可以看到,如果是dedicated server,那么所有不能识别的命令都会被作为server的广播信息发送出去,并返回true,也就是说,不再会被当作client command查找。 直到现在,一切都还很清晰,但是且慢,看到有个文件叫cg_servercmds.c没有,我们已经知道了console command和client command,可什么是server command啊?来,我们把它打开来看,用VC的Browse的函数列表功能,我们可以看到,这个文件的关键所在应该是一个叫CG_ServerCommand的函数,到它的函数体里面一看,en,又冒出一把命令,其中有一个叫cp的,它唯一做的事情就是调用CG_CenterPrint,哈哈哈,白忙乎啦,原来已经有在屏幕正中打字符的命令了,好,打开quake3,进入地图,进入控制台,敲"\cp hello",没有反应,敲"\cp",还是没有反应,但是也不显示unknown cmd,奇怪啊奇怪,好,退出quake3,继续看代码。 我们来看CG_ServerCommand在什么时候会被调用,看它的被调用树,当然最后都是vmMain了,但在下面一级,我们看到是CG_DrawActiveFrame,这个函数是在vmMain(CG_DRAW_ACTIVE_FRAME)的时候被调用的,也就是说,这些所谓的server command是在画每一祯画面的时候被执行的,和我们从console输入的东西一点关系没有,那么,刚才我们敲"/cp hello"的时候自然也就不会有东西输出到屏幕上。 那么,这些命令是从哪里来呢?根据server command这个名字,我们觉得应该是由game模块来传输给cgame模块的,到code/game目录下查找cp,我们看到了诸如此类的调用: trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined....\n\"", ... ); 那么我们就完全有理由相信,这里的所谓server command,只是用来供game向cgame发布指令用的,它们和前面的command的最大区别就是它们是无法通过用户输入来执行的,同样在CG_ServerCommand的函数里,我们还可以看到map_restart,但它和我们敲命令map_restart完全是两个概念,后者是由quake3.exe来识别并执行的,一定要分清楚。 同样,我们在CG_ServerCommand还可以看到chat、cs等等,如果试图通过控制台输入这些命令,就会得到unknown cmd,而cp在这里是一个特例,它不但不返回unknown cmd,甚至在sv_pure 1的时候还会把你踢回主菜单,我对我画的那个流程图还是有信心的,我怀疑是quake3.exe内部对cp做了处理,所以我在quake3.exe中查找cp,找到一个地方很有嫌疑:nextdl..download...cp..getIpAuthorize,然后我们拿download来试验,同样不会返回unknown cmd(必须要进入地图),由此可以确认cp是quake3.exe内部能识别的命令,属于internal command,但它又和server command里的在屏幕正中打印字符的命令名字相同,就象两个map_restart一样,我甚至怀疑cp在quake3.exe里的意思是拷贝文件....哦,security hole? 讨论完这个特殊的cp,我们继续回到server command的话题上来,因为它不是通过控制台输入的,所以我们不能把它添加到上面的结构图中去,你只要知道有这么个东西,这么个机制存在,不要把它和结构图中的command弄混淆,并且知道我们可以利用这个机制从game向cgame发送指令就可以了 似乎到这里我们已经可以结束关于cvar和command的讨论了,不过不知道你注意到没有,我们没有找到console command和client command的注册机制,quake3.exe只是简单的把它不能解释的命令按照流程图里的顺序一步步交给子模块,并通过检查返回值来判断是否被解释执行,那么quake3.exe是如何知道这些命令的名称并且可以让你在控制台通过TAB自动完成功能查看到所有匹配的命令呢?答案在cg_consolecmds.c/Ln520。 3.3 实现 抱歉,让你在实现个如此简单的功能之前看了那么多东西,希望你没有太着急,这些付出都是会有回报的,我们下面就可以非常轻松了。 首先我们给这个命令起个名字,我们就叫它"hello"吧,然后我们要决定把它添加到哪一种command里面,当然不可能是internal command和server command,只能是console command或者client command,为了给下一节的内容做个铺垫,我在这里采用client command,你也可以自己试着用game/cgame console command来完成它,不同的实现适用于不同的情况,你可以根据前面的流程图看出来。 看到这里,你肯定已经手痒了吧,现在我们就开始动手。 根据我们在前面找到的client command在程序中的位置,我们到g_cmds.c/Ln1578,看ClientCommand这个函数,它通过比较命令的字符串来执行不同的函数,我们要把对于"hello"的处理添加进来,但是添加在什么地方呢?在函数中间有如下语句: // ignore all other commands when at intermission if (level.intermissiontime) { Cmd_Say_f (ent, qfalse, qtrue); return; } intermission的意思就是一局打完了,但新的还没开始,这个时候没有活动的玩家在地图中,大家屏幕上都是比分牌。我们的HelloWorld在这个时候也不该显示在屏幕上,所以我们要把它添加到这段的后面。 我们要添加一个else if在最后一个else前面,然后在else if中做我们要做的事情,这里我们看到原来的代码都只是简单的调用一个函数,我们就不用了专门写函数了,因为我们的功能很少,反正也只有一行;我们使用前面查找cp的结果: trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined....\n\"", ... ); 并把要显示的东西换成我们需要的,去掉里面的变参代换,改完以后这段程序应该是这个样子: else if (Q_stricmp (cmd, "stats") == 0) Cmd_Stats_f( ent ); else if (Q_stricmp (cmd, "hello") == 0) trap_SendServerCommand( -1, va("cp \"Hello, Quake World!\"")); else trap_SendServerCommand( clientNum, va("print \"unknown cmd %s\n\"", cmd ) ); 运行一下试试,进入地图后敲"\hello",如果前面一节的慢速火箭弹你已经成功运行了的话,这次的hello应该也一点问题没有,但如果屏幕上没有反应,你需要检查编译的步骤,以及目录的设置。 3.4 简单的c语言解释 这一小段是给没有任何编程知识的人来看的,你可以跳过。 如果"cp \"Hello, Quake World!\""这样的写法让你感到困惑,你可以尝试把它改成你觉得直观的形式:"cp Hello, Quake World!",并且看一下运行效果,你会发现屏幕上只显示了一个单词Hello和后面的逗号,也就是说cp这个server command只显示了跟在它后面的第一个单词,我们可以在它的实现的地方(cg_servercmds.c/Ln968)看到: CG_CenterPrint( CG_Argv(1), SCREEN_HEIGHT * 0.30, BIGCHAR_WIDTH ); 在c语言里,字符串都是用双引号包起来的,如过你要在这个字符串的内容里有双引号,那么你就需要用一种特别的方式来书写,以免这个双引号被错误的解释为字符串的结束,这个特别的方式,就是用反斜杠开头:\" 那么,其实刚才va函数得到的字符串的内容是: cp "Hello, Quake World!" 对于这样的情况,va函数会把它原封不动的返回,从而trap函数得到也是这个字符串,然后quake3.exe会负责把这个字符串发送给客户端的quake3.exe,然后这个quake3.exe再把它交给cgame模块来作为server command解释,在968这行语句上,我们看到了CG_Argv(1)这样的调用,这个函数会返回cgame模块收到的这一串server command的命令后面的第一个单词,就好比我们在dos下使用dir *.exe一样,这里,*.exe就是第一个单词,在取出这个单词之后,就可以调用CG_CenterPrint来显示它了。 那如果你把里面的\"去掉了,那么cgame收到的是: cp Hello, Quake World! 这时,第二个单词是Hello,,而如果有引号的话,第二个单词就是引号内的整个字符串。 到这里你可能要问,既然va函数只是原封不动的返回,那我们何必用va呢,直接这样不也可以嘛: trap_SendServerCommand( -1, "cp \"Hello, Quake World!\""); 当然可以!但是有时候你可能会需要在屏幕上显示玩家的名字,后面才是Hello;这就就要用到刚才提到的"变参",也就是可变参数,在我们修改之前,原来的trap_SendServerCommand可能是这个样子: trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE " joined the red team.\n\"", client->pers.netname) ); 这句是显示某玩家加入了红队,那么client->pers.netname里面就是玩家的名字,中间插入S_COLOR_WHITE是为了避免有的人不以^7结束,影响到后面字体的颜色,那么我们可以把我们的语句改成: trap_SendServerCommand( -1, va("cp \"%s" S_COLOR_WHITE ": Hello, Quake World!\n\"", ent->client->pers.netname) ); 这时,%s就被替换成了玩家的名字。 关于c语言的格式,只能写那么多了,以下的内容里不再对c语言做解释,你该考虑弄一本c语言的课本了 在我们前面使用trap_SendServerCommand的时候,第一个参数用的一直是-1,这个参数是什么意思呢?我们看trap_SendServerCommand的函数定义,就可以看到,这个参数的名字叫clientNum,也就是client的编号,那么-1代表哪一个client呢?你已经猜到了,是所有client,也就是说,我们刚才改出来的代码会导致一个玩家敲hello,所有人屏幕上都显示字符,现在我们来改正它。 我们的改动是在ClientCommand这个函数里,这个函数只有一个参数,居然也叫做clientNum,下面你知道该怎么办了。 到这里,我们算是把这件事情做完了,不是很难,是吧?如果你有兴趣的话,可以继续试一试上面提到的在cgame console command或game console command里添加命令,把名字起做"cg_hello"和"g_hello"是不错的选择,(虽然看起来比较象cvar :),你也可以试试在发射火箭弹的时候往屏幕上写东西(这一个比那两个难一点,因为你要想办法到算出clientNum,在这个过程你又会学到些东西)。 4. Jump Practice Tool "How many road must a man walk down,before you call him a man?" —— Bob Dylan 这一节我写了两遍,第一遍完成的时候有8K,现在你看到的是第二遍的结果 (废话!),因为我觉得有了上一节的基础,你完全可以独立完成这个工作,而不需要我再一步步的在教程中把它完成,那样是在剥夺你的乐趣。 跳跃练习几乎是所有quaker必定要做的功课,大家都在这上面花费了无数个小时,不知道你有没有想过如果我们可以象在q1/q2的sp模式里那样存取盘就好了,就不会再有跳进wp/重生后哼哧哼哧的赶过去,也不会再有为了精确定位起跳点用mg在地上打出一排起跑线这种事了。 我们要做的事情就是要能保存并载入玩家的位置和视角,这个工作可以分解为如下部分: 1、添加相应的client command命令:"savep"和"loadp" 2、在savep的处理函数中保存当前位置和视角 3、在处理loadp的函数中用前面保存的数据覆盖玩家当前的位置和视角 4、为了方便练习PG/GL/RL的跳跃,在玩家进入游戏时自动拥有这三把枪,并弹药无限 5、取消slime/lava/falling的伤害,以及RJ的伤害 如果现在你就开始着手做,你可能会觉得这个东西还有点麻烦,这时我们的frag经验就变的很有价值了,回想下在游戏里有没有从一个位置忽然到另外一个位置的时候?你会脱口而出:传送门哎!英文叫TelePort,对,就从这里入手,找到原来的游戏是怎么处理玩家进传送门的,你会发现整件事情就变的简单多了。另外,更改初始状态在g_client.c/Ln1150附近,更改弹药无限在bg_pmove.c/Ln1620附近,取消伤害在g_combat/Ln975行附近,到那基本上都是一看就明白的。 作为参考,你可以在这里下载我改完以后的代码,只包含被修改的文件,所有我添加或修改的代码都以如下格式开始和结束: 添加: /// -----> add .... /// <----- end add 修改: /// -----> modified .... /// <----- end modify 你可以通过查找开始那三个斜杠找到它们,你也可以采用这种格式来进行你的工作,会给你以后带来很多方便。 5. 地雷 如果说上一节的例子只是有用而不是有趣的话,这一节的应该算比较有趣了,我们要在quake3里添加一种新的武器:地雷!其实添加武器是一件很麻烦的事情,要修改的东西非常之多,而且还需要做个model,我还从来没真正做过添加新的武器,在这里我们只能因陋就简一下,把GL改装成地雷发射器。这个东西比上一节也略微要难一点,所以就不再提供修改好的代码下载,你需要一步步看下去 —— 很好玩的! 我们需要修改发射出来的榴弹的属性,让它不再跳来跳去,而且不会过2秒半就爆炸,同时,有玩家碰到它的时候它会自动爆炸,就那么多。 我们找到发射榴弹的函数:fire_grenade(就在最早修改慢速火箭弹的那个函数附近),这个函数生成了一个新的实体(entity),并赋予它一些属性,这个实体就是发射出去的榴弹,看到函数里那个2500没有,它定义了榴弹发射后经过多长时间爆炸,单位是毫秒,这个值再加上当前游戏的时间,赋给了nextthink,然后在每一个server祯开始的时候,游戏会检查所有实体的nextthink,看它是不是已经小于当前时间,如果是的话,就说明它该think一下了,也就是调用这个实体的think函数(函数指针),可以看到,think函数在这里被赋予G_ExplodeMissile,也就是说,在2秒半以后这颗榴弹就会爆炸,我们把这个值改为300000,也就是5分钟,5分钟过后这个榴弹,哦,不,地雷,就报废了。 然后我们要让它碰到地面就停住,不要弹来弹去,fire_grenade函数里只有EF_BOUNCE_HALF看起来象是运动属性的定义,我们查找EF_BOUNCE_HALF,就会发现一个叫G_MissileImpact的函数,它被G_RunMissile函数调用,在每个server祯开始的时候,游戏对所有类型是ET_MISSILE的实体调用G_RunMissile,你可以在G_RunFrame函数里看到这些检查和调用;当G_RunMissile检测到这个导弹(还有可能是RL/PG/BFG/HOOK)碰撞到墙壁,就会调用G_MissileImpact,现在我们来看G_MissileImpact。 在G_MissileImpact的一开始,它就检查这个导弹是不是会弹跳的,如果是,就计算弹跳路径,然后返回,如果不是,则安置它的最终位置并爆炸;我们要把计算弹跳路径去掉,并且为了放置好正确的位置,把返回也去掉,让它继续往下执行,这个函数的一开始那段就应该是这个样子: /// -----> modified // check for bounce if ( !other->takedamage && ( ent->s.eFlags & ( EF_BOUNCE | EF_BOUNCE_HALF ) ) ) { /// G_BounceMissile( ent, trace ); G_AddEvent( ent, EV_GRENADE_BOUNCE, 0 ); /// return; } /// <----- end modify 那句G_AddEvent不要去掉,去掉就没声音了。 继续往下看,对G_SetOrigin的调用应该就是设置最终位置,再往下就爆炸了,在G_SetOrigin后面加上: /// -----> add if (!strcmp(ent->classname, "grenade")) return; /// <----- end add 改到这里,我们先进游戏看看效果,dm5有GL,而且比较小,load快,进去后我们发现它的确是不弹了,但一碰地下就炸了,应该是我们返回的太晚了,就在G_SetOrigin前面几行,有一句: ent->s.eType = ET_GENERAL; 这句看上去就很不对头,把榴弹的类型都去掉了,而且还有一句 ent->freeAfterEvent = qtrue; 这句暂时不懂,不管它,把我们的代码移到它们前面,并自己添加上G_SetOrigin后直接返回,现在看起来应该是这个样子: /// -----> add if (!strcmp(ent->classname, "grenade")) { G_SetOrigin( ent, trace->endpos ); return; } /// <----- end add ent->freeAfterEvent = qtrue; ent->s.eType = ET_GENERAL; SnapVectorTowards( trace->endpos, ent->s.pos.trBase ); // save net bandwidth G_SetOrigin( ent, trace->endpos ); 再进游戏看看效果,这次更有意思,在爆炸的烟雾散尽后我们发现,榴弹安安静静的躺在地上,哎,还是返回晚了,回去再看,看到前面那个if-else if-else里有很多G_AddEvent,很可能烟雾就是它们散布出来的,而且我们就知道ent->freeAfterEvent = qtrue;是针对这里添加的event而言的,继续把代码往前移: /// -----> add if (!strcmp(ent->classname, "grenade")) { G_SetOrigin( ent, trace->endpos ); return; } /// <----- end add if ( other->takedamage && other->client ) { G_AddEvent( ent, EV_MISSILE_HIT, DirToByte( trace->plane.normal ) ); ent->s.otherEntityNum = other->s.number; } else if( trace->surfaceFlags & SURF_METALSTEPS ) { ......... 省略 这次就完全正常了,你现在肯定在心里嘀咕:“这个家伙明明知道最后结果还带我在这里兜圈子”,是啊,我现在是知道结果了,但在一开始不知道啊,你以后解决自己的问题的时候也一样要经历这样的过程,经验越多越好嘛。 现在我们要让它在被玩家碰到的时候会自动爆炸,而不是等到5分钟,那是定时炸弹,不是地雷。 做过地图的就会知道,地图里有种实体叫trigger,触发器,譬如DM7/RL处的那个方块,在FFA的时候用来控制进地牢的门,我们的地雷也需要这样的功能,查找trigger,你会看到一个叫G_TouchTriggers的函数,当然,查找结果很多啦,你浏览一会就会发现这个函数最管用,我也是这么浏览出来的。 函数一开始判断来触发trigger的是不是玩家,以及是不是尸体,然后根据这个玩家的坐标扩展出一个立方体,调用trap_EntitiesInBox,判断立方体中有多少个实体,然后对于每一个实体,检查它是否有touch这个功能,以及有没有CONTENTS_TRIGGER这个标志,并且确保spectator只能和传送门发生关系,最后检查它是不是可被拾取的item,是的话,检查距离(这个item可能是正在半空中往下掉的),不是的话,要严格检查是否接触。 我们的地雷应该有一定的范围,不一定非要贴在一起才爆炸,你想那榴弹才多大一点啊,再说大家都是跳着走路,要求那么严格的话,踩雷估计会变得跟拣宝一样,那么我们就忽略上面这两种检查,直接用函数开始的时候从玩家坐标扩展出来的这个立方体来判断,也就是说,被trap_EntitiesInBox返回的榴弹就算是被踩到了,改代码成如下样子: if ( hit->s.eType == ET_ITEM ) { if ( !BG_PlayerTouchesItem( &ent->client->ps, &hit->s, level.time ) ) { continue; } } /// -----> add else if (!strcmp ("grenade", hit->classname)) { } /// <----- end add else { if ( !trap_EntityContact( mins, maxs, hit ) ) { continue; } } 我们还要给榴弹的实体加上touch函数和CONTENTS_TRIGGER标志,否则G_TouchTriggers不认为它是个trigger,到g_missile.c里加。 我们不能直接用G_ExplodeMissile来做touch功能,因为函数类型不一致,我们自己写一个,放在文件的开头: /// -----> add void G_ExplodeMissile( gentity_t * ); void G_ExplodeMissile_Touch (gentity_t *self, gentity_t *other, trace_t *trace) { G_ExplodeMissile (self); } /// <----- end add 然后到fire_grenade里添加: /// -----> add // act as a trigger bolt->touch = G_ExplodeMissile_Touch; bolt->r.contents = CONTENTS_TRIGGER; /// <----- end add 进游戏试试!恩,的确一碰就炸,而且120的血一下就死了,这地雷也太凶了点吧,怎么回事?我们没改杀伤力啊,正常的榴弹直接落到自己身上也应该只掉50点血啊,更别说是放在地上的了。 唯一合理的解释:它爆炸了不止一次!G_TouchTriggers是在每一个server祯开始的时候被调用的,尽管在G_ExplodeMissile这个函数里有把freeAfterEvent设为true,但在这句前面添加的event可能在下一祯才开始,而且很有可能持续若干祯。只有在你机器比较慢的情况下,有可能保住命。 知道了原因,我们想该怎么办,爆炸这个event是肯定要有的,而且也只能在event完了之后再free,不要问为什么只能这样,既然原来的游戏是这么做的,它必然有它的原因,在做改动的时候一定要知道自己在干什么,如果不知道在event结束之前就把这个实体给释放会导致什么后果,就不要这么改。 每次触发器被触发的时候,G_TouchTriggers会调用被触发实体的touch功能,在这里实体是grenade,touch函数是我们自己添加的G_ExplodeMissile_Touch,我们可以在这个函数里阻止它再次爆炸,阻止它再次被触发,让它不再是触发器: /// -----> add void G_ExplodeMissile( gentity_t * ); void G_ExplodeMissile_Touch (gentity_t *self, gentity_t *other, trace_t *trace) { G_ExplodeMissile (self); self->touch = NULL; } /// <----- end add 再实验,正常了。 还没完,我知道你在嘀咕,就那黑乎乎的一团放地上也能称为地雷?别人都不长眼睛啊! 我只有一个解决办法,虽然不是很完美,找到我们刚才添加的那个G_SetOrigin调用,在G_MissileImpact函数里面,在里面加一行,改成这样: /// <----- add if (!strcmp(ent->classname, "grenade")) { trace->endpos[2] -= 0.5; G_SetOrigin( ent, trace->endpos ); return; } /// <----- end add 把位置的z坐标减0.5,沉到地下,就看不到了,当然,挂在天花板上的时候就会没有贴住,比较丑,在这里要改正这个问题的话写起来会比较长,你可以试试自己动手改,提示:trace.plane.normal里记录了实体碰撞到的平面的法向量,法向量的意思就是垂直于于该平面的单位向量,也就是这个平面的朝向。 这个时候如果你还是在dm5来运行,你会发现,在PG那片地上是正常的,而上了台阶,到走廊(通向RA,上面有GL)的地板上,就不正常了,地雷的确是被触发了,我们可以看到烟雾,听到爆炸的声音,但它对玩家没有造成伤害;这就是我们大家都知道的被取消的的穿透地板伤害,具体的检测代码在CanDamage函数里,它被G_RadiusDamage调用;当然我们可以很简单的把CanDamage检查去掉,但这样会影响到其他的武器,我们采用另外一种办法:在爆炸前把它的位置再提高0.5,回到地板上。把G_ExplodeMissile一开始改成如下形式: /// -----> modified if (strcmp("grenade", ent->classname)) { BG_EvaluateTrajectory( &ent->s.pos, level.time, origin ); SnapVector( origin ); G_SetOrigin( ent, origin ); } else { ent->r.currentOrigin[2] += 0.5; } /// <----- end modify // we don't have a valid direction, so just point straight up dir[0] = dir[1] = 0; dir[2] = 1; 现在就一切正常了。 上一节有改玩家重生时配备的武器的代码,你知道怎么弄了,但是我们给玩家初始的榴弹弹药应该是多少呢?给多了吧,扔得到处都是,给少了吧,如果地图里没有榴弹弹药怎么办?难道就只*吃别人掉在地上的GL?要想个办法。 最好是能根据时间来控制,譬如5秒种榴弹弹药加1,在游戏中这种根据时间变化的数值太多了,我们只要找到原来的代码就好办,查找"->health",看到下面这样的结果嘛,就知道这里是根据时间来做的了: if ( ent->health > client->ps.stats[STAT_MAX_HEALTH] ) { 它在g_active.c的ClientTimerActions函数体内 不过它是按一秒一秒算的,我们需要以5秒为单位,在函数内加一个静态变量来统计过了几个1秒?不行,这个时间是和玩家相关的,必须在client结构里添加变量(g_local.h/Ln296): int timeResidual; int timeResidual2; /// <----- add one line 然后在原来程序处理timeResidual的地方,ClientTimerActions开头,处理timeResidual2 /// -----> add client->timeResidual2 += msec; while (client->timeResidual2 >= 5000) { client->timeResidual2 -= 5000; client->ps.ammo[WP_GRENADE_LAUNCHER] ++; } /// <---- end add 进去玩一会,觉得还有什么不足的地方自己再添吧。譬如你可以添加一个cvar用来控制是使用地雷还是使用普通的榴弹,还有,现在的地雷在5分钟后报废时会爆炸,你可以通过nextthink的值和当前时间来判断它是被踩到还是被报废,就可以作出相应的动作:是否有烟雾,是否有伤害。 6. 后记 "在进行这些工作的时候,你是否觉得,游戏,同样可以让你学到很多的东西呢?" —— Maverick 终于完成了这篇文章,希望你从中得到了不少乐趣,在这里要感谢id software和q3acn,没有前者,你我的生命将会比现在的少了很多东西,不光是frag时的快感,还有对一件事物全身心投入时的那种美好感觉,英语里把这种感觉称之为"passion";没有后者,我们的quake3之路也会很不一样。 你可能会想,从test版算起,q3已经问世快三年了,doom3虽然不是指日可待,但也不是遥遥无期了,做q3的mod还有意义么?但是,看看国外那些长达上百页的mod列表吧,又有多少人安装并花很多个小时玩他们呢?我只想说,这些都不重要,我反正是把这些代码当成Id送给玩家的大玩具,比如上一节做地雷,给我感觉就象小时候做弹弓和水枪一样;而且你现在学到的知识和积累的经验,和你frag的经验一样,到了doom3的时候仍然能派上用场。crt和arq也不是一次就做出了现在的ra3和osp,他们都是从quake1就开始做MOD的。 一个大型的复杂的MOD,改代码只是其中的一小部分,更多的工作在做地图,做模型,也希望国内能有越来越多的mapper和modeller。 对你今后继续研究代码的几个建议: 1. 良好的心态,刚开始的时候一定要不求甚解,不能操之过急,id花那么长时间写出来的代码,你不要指望十天半月就能全部搞懂。 2. 保持注意力,在弄明白一个问题的过程中,抓住问题的关键,不要看到哪里不懂又开始在代码里到处乱翻,那样的话不出30分钟你就会发现自己陷入泥沼,甚至忘了自己一开始要干什么。 3. 毅力,如果你脑海已经有一个非常好的主意,并且有强烈的愿望要实现它,那么,不要半途而废。 4. 善加利用VC的Browse功能,和find in files,他们就相当于Yahoo!分类目录和Google。 quake3 资源quake3 源代码
有代码后可以用迅雷搜索一个quake3 的安装程序大概500M左右。pak0.pk3放入代码的code\baseq3目录。这个压缩包也可以解压,.pk3 采用的是zip压缩算法,可以用winrar或winzip打开.
ID 的 ftp 服务器:
一个用directx9 仿写的quake3引擎:
quake3客户端cgame工程和服务端game工程函数说明:
quake3 Code3Arena
Quake4 编辑器
http://www.iddevnet.com/quake4/LevelEditor quake3 的几本书
Focus On Mod Programming in Quake III Arena 1本关于 mod 编程的
The Quake III Arena Bot 1本关于quake3 Ai的书
Focus.On.3D.Models 介绍了关于 quake 的 md2 md3 模型信息这本书应该很好找
quake3 shader 文档
关于 quake 1 的一些文档
有部分 quake1 bsp 解释的一本书
图形程序开发人员指南(Michael Abrash's Graphics Programming Black Book) 虽然有点过时,不过还是非常不错的书.可惜买不到了
answers.com 中关于 quake3 的一些faq
quake3 自适应 Huffman 算法分析
quake3 md4
http://geeningwang.googlepages.com/quake3.md4.pdf
http://www.91files.com/?54F2414O62C43E63E7GY Quake III网络封包分析.网络协议核心:delta 压缩 Unofficial Quake Network Protocol Specs v1.01b quake 网络分析
http://www.gamers.org/dEngine/quake/QDP/qnp.html Quake II Network Protocol Specs quake2 网络协议分析
http://www.csse.monash.edu.au/~timf/bottim/q2net/q2network-0.03.html
Quake3场景管理技术研究报告: http://download.csdn.net/source/195372 http://www.91files.com/?1ZCILUDBF4UWZ2KQ5L2R Bsp 技术详解:
May 11 使用c函数获取文件大小取得当前文件指针位置函数: fseek(File, 0, SEEK_END); //移动到文件的结尾 int lastPos = ftell(File); //获得文件大小 fseek(File,currentPos,SEEK_SET); //恢复到原来的文件指针位置 return lastPos; 如果文件大于 4G ,就要用64 位的 __int64 _ftelli64( FILE *stream );
单字符宽字符互相转换#include <stdlib.h>
size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n); //转换单字符串为宽字符串 size_t wcstombs(char *mbstr, const wchar_t *wcstr, size_t count ); //转换宽字符串为单字符串
例如:
CString str = L"hello";
char sss[20]; wcstombs(sss,str.GetBuffer(),20); //转换宽字符为单字符 stl 宽字符到 单字符转换
wstring str = L"Hello";
std::wstring::size_type len = str.length(); std::string s(len*2,0); size_t total = wcstombs(&s[0],str.c_str(),len*2); s[total] = '\0'; return s; mbtowc 和 wctomb 是单个字符相互转换 int len; setlocale (LC_ALL, "chs"); //设置为简体中文环境
wchar_t wc = L'中'; wprintf(L"1个宽中文字符:%c \n",wc); char* p = "中"; len = mbtowc (&wc, p, MB_LEN_MAX); wprintf(L"单字符串转换为1个宽字符:%c 长度: %d\n",wc,len); char pcmb[MB_LEN_MAX]; len = wctomb (pcmb, wc); pcmb[len] = 0; printf("宽字符转换为单字符串:%s 长度:%d\n",pcmb,len); BYTE utf8[1024]; //utf8 字符串
wchar_t wstr[1024];
char mstr[1024]; //UTF-8 转换为宽字符 MultiByteToWideChar( CP_UTF8, 0, utf8,1024, wstr, sizeof(wstr)/sizeof(wstr[0]) ); WideCharToMultiByte( CP_ACP,0,wstr,-1,mstr,1024,NULL,NULL ); |
|
|