quake3研究環境搭建

聲明: 原文 http://www.cnblogs.com/vincent2600/archive/2011/09/12/2174056.html


如果不去讀quake3代碼,作爲一個遊戲程序員是說不過去的,現在去讀還不晚,肯定會碰到很多問題,解決問題的過程就是練級。

hacking之前,首先是建立環境,運行調試環境。quake3是99年推出的,到現在已經十二年了,網上能找到一些關於quake3編譯運行的隻言片語
但都不可行,自己只有基於這些再加上自己試驗,make it works!

 在開始之後,需以下幾個文件.
 1.Quake 3 Demo版(我們需要裏面的資源相關的東西)
 ftp://ftp.idsoftware.com/idstuff/quake3/win32/Q3ADemo.exe
 2.Quake 3 源代碼
 ftp://ftp.idsoftware.com/idstuff/source/quake3-1.32b-source.zip
 3.Quake 3 發行版q3pointrelease_132.exe(單純照其他網上的步驟,只使用demo資源始終要報錯)
 
 進入正題.
 1.打開代碼下/code/quake3.sln,直接編譯,不出意外會報錯:
   ui.def : error LNK2001: unresolved external symbol vmMain
   將solution configuration從Debug Alpha改爲Debug,OK!
  
 2.關鍵這樣還不是很好,因爲這樣直接把生成的quake3.exe拿去運行會有問題:
   打開"quake3"工程中的files.c,註釋 第3263,3264,3266三行,如下
 // if ( FS_ReadFile( "default.cfg", NULL ) <= 0 ) {
 //   Com_Error( ERR_FATAL, "Couldn't load default.cfg" );
 //   bk001208 - SafeMode see below, FIXME?
 // }
 然後,將files.c中的tatic void FS_SetRestrictions()函數的全部內容註釋,僅剩下如下的空殼函數
 static void FS_SetRestrictions( void ) {
 }
 
 3.安裝Quake 3 Demo版的Q3ADemo.exe和Quake 3發行版q3pointrelease_132.exe,到C:盤的根目錄,安裝後分別爲C:\3Ademo與C:\Quake III Arena,
   將C:/Q3Ademo/demoq3目錄下的pak0.pk3文件複製到C:/Quake III Arena/baseq3 目錄下
  
 4.接下來就是用vs進行跟蹤調試的關鍵步驟:
   change quake3 project property -> Linker -> output file C:\Quake III Arena\quake3.exe
   change quake3 project property -> Debugging -> Command $(TargetPath)
   change quake3 project property -> Debugging -> Command $(TargetDir)   //C:\Quake III Arena
  
 5.現在,前往金銀島的船已經好了,Let's Hack !


///////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////

如果沒有任何人指引,就只看代碼幾乎如同瞎子摸象。打開sln可以看到botlib,cgame,game,q3_ui,quake3,renderer,splines,ui 8個project,但是它們各自的功能何如呢?

在gamespy找到一篇帖子稍微靠譜一些:

What's the difference between game and cgame? Most of the functions are very different. What's the role of them?


Game / cgame are the "gamecode", which defines the rules of the game, and the meaning of all "entities" (players, items, weapons, projectiles etc are all represented in the engine side as an entity_t). For example, the gamecode is where logic is that ties an entity that happens to have the model of a rocket into a thing that moves at 800ups in a straight line, and damages the entity it hits. The engine itself doesn't have a concept of a rocket, it just knows about the map, entities, and clients that it must send this data to / render.

CGame stands for Client Game, and is the code that runs on the client side, while "Game" only runs on the server. The server (game) is the thing that decides that the rocket is moving at 800ups in a straight line, and when a collision occurs, is the code that calls the damage function to hurt another entity. The client (cgame) simply knows it has a rocket entity, so it gives it the right model, sets up the right rendering effects, and plays the sounds at the right times.

You'll notice there are a few files in both projects with the prefix bg_* - these files are "both game" projects, because the code in them is shared between both client and server. This is mainly for things like movement, to allow the client to predict the path of the rocket so the client can guess where it is without waiting for the server to tell it, to avoid it feeling laggy.

In the released versions of q3, the game/cgame/ui/q3_ui projects aren't built as DLLs like they are in the VS project, they're built into the platform independent .QVM files by a custom version of the "lcc" compiler - the projects are set up as DLLs as well to make it much easier to debug them.

The q3_ui is I guess the user interface/menus, but there's also a ui project... again what's the role of both of them?


Originally, there was just q3_ui, and that is the userinterface used in Quake 3 itself. However the code they released includes the Team Arena missionpack too, which uses a re-written version of the user interface which you can find in the "ui" project. For game/cgame, the TA versions are actually merged into the project and are built by selecting a different configuration in VS (which just toggles the #define MISSIONPACK), but the UI was a major rewrite.

What are splines?


Funky maths (wikipedia link) for giving nice interpolated curves between points. IIRC the splines project is completely unused in Q3, it's just a hangover from something they were experimenting with.

Finally, what project/function links all this together, ie. whats the first script/header script to get executed when it's you've got the build and are running the release executable?


Well, like every Windows program, the very first place WinMain, which you can find at the bottom of win_main.c in the "quake3" project. That calls the Com_Init() which is the "common init" and will do all the real initialisation, and then sit in a loop calling Com_Frame() every frame, which does all processing for each frame of the game. Com_Frame will work out whether you're running a client, a server, or both, and call the appropriate bits.

posted:
Any info on this, or any resources you can point me to would be appreciated..


I don't know of any resources telling you this stuff - you might find something about the game / cgame split as this is the "mod" code, and so people were learning about it before the engine code was released.



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章