Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. ------------------------------------------------------------------------------
  2. Warsow Sourcecode documentation
  3. ------------------------------------------------------------------------------
  4. Author : Bart Meuris (KoFFiE)
  5. E-Mail : bart.meuris@gmail.com
  6. Start date : 2007-10-17
  7. Last modified : 2012-06-14
  8. Maintainer : Bart Meuris
  9. ------------------------------------------------------------------------------
  10. ------------------------------------------------------------------------------
  11.  
  12. 0. Introduction
  13. ---------------
  14.  
  15. I started this document because when I joined the Warsow development team as a
  16. coder and started exploring the code, I had a hard time figuring out what part
  17. did what. This document will explore the major parts of the code, mostly while
  18. I'm exploring them too.
  19.  
  20. This document is aimed at people with at least a basic knowledge of C
  21. concepts who are getting ready to explore the game source-code. Most things
  22. said here will probably apply to other Quake 2 (and maybe 3) based games,
  23. since Warsow is based on Q-Fusion, which is based on the original Quake 2
  24. engine.
  25.  
  26.  
  27.  
  28. 1. The basics
  29. --------------
  30.  
  31. Warsow is a program built around 'frames'. First the program reads inputs,
  32. then it 'thinks', modifying the current gamestate, and then implements the
  33. current state.
  34.  
  35. This means, that there is 1 major loop handling all application logic. This
  36. called a 'state machine' design, which can be confusing when you used to
  37. straight-forward procedural or object-oriented programming.
  38.  
  39. This may sound pretty abstract, but this is due to the fact that warsow is a
  40. client AND a server with exactly the same sourcecode. This means that in the
  41. big lines, the same steps are taken for both the client and the server.
  42. Of course, once digging deeper into the code, things will start looking very
  43. different, since the server is the one who actually makes all decisions, sends
  44. state-changes and events to the client (or clients), who then alter their
  45. local state and implement it (as in: build the scene and render it).
  46.  
  47.  
  48. 2. Main loop
  49. ------------
  50.  
  51. Since warsow can be run on Windows, Linux - and has some basic MacOS-X
  52. support, there are different platform-specific entry-points for each platform.
  53. They all do the same: first some basic initialisation, followed by
  54. running the state-machine loop, which looks like this: (semi-pseudo-code)
  55.  
  56. while (true) {
  57. time = <the current time in milliseconds>
  58. Qcommon_Frame( time )
  59. }
  60.  
  61. This loop never quits and is executed ever frame. The Qcommon_Frame function
  62. is a real function which can be found in the "qcommon/common.c" file. This is
  63. not a very interesting function on it's own, it does very little
  64. decisionmaking and just calls a bunch of different other functions in a
  65. certain order. These functions are more interesting, they actually do things.
  66. However, for most changes in the code you will have to dig a bit deeper, but
  67. knowing this can be useful to understand the whole thing a bit better.
  68.  
  69.  
  70.  
  71. 3. The modules
  72. --------------
  73.  
  74. Basicly the game is organised in different modules, which are mostly organised
  75. in directories. This is the 'main' list of the directories with their short
  76. descriptions:
  77.  
  78. cgame : Client Game module responible for the client-side handling of the
  79. gameplay.
  80. client : Client module, containing generic client-specific code not
  81. responsible for gameplay.
  82. game : Game module, running on serverside which performs all decisions
  83. about the game, depending on gametype, ...
  84. This also contains the AI (Artificial intelligence) code for the
  85. bots.
  86. gameshared : Generic gamecode used by both the cgame and game module.
  87. qcommon : Quake engine 'common' files, used by most modules
  88. ref_gl : This contains the OpenGL render-code.
  89. server : Contains code for specific for the server-logic
  90. ui : Does the user-interface drawing and handling
  91. irc : built-in IRC client module
  92. null : Empty implementations of the client module and platform specific
  93. video initialisation for dedicated servers. Also contains an
  94. empty platform sys implementation (sys_null.c) to help porting.
  95. angelwrap : Angelscript module, exporting C++ API to the game module which
  96. is written in plain C and and the C++ UI module
  97. cin : Video codecs module
  98. matchmaker : Interface to remote matchmaking and statistics system
  99.  
  100. For the sound sub-system, 2 different backends exist at the moment, which are
  101. dynamicly loadable. These are:
  102.  
  103. snd_openal : Sound backend using the multiplatform OpenAL libraries
  104. snd_qf : QFusion Sound backend
  105.  
  106. Then we also have the 'platform' modules, which contain all platform specific
  107. functions, initialisation, wrappers, ... like startup, keyboard input,
  108. graphics initialisation, filesystem access, network access, generic library
  109. functions, sound, ...
  110. Currently the following platforms are available for warsow:
  111.  
  112. win32 : The win32 (and win64) specific code
  113. unix : Linux/BSD/*nix X11 specific code
  114.  
  115. There also is a mac platform, but at the moment of writing this, this is not
  116. being maintained.
  117.  
  118.  
  119.  
  120. 4. Naming conventions
  121. ---------------------
  122. Due to the fact that C does not have namespaces, strict naming-conventions are
  123. used for non-static functions to avoid problems with name-collisions.
  124.  
  125. Both the files and functions should have a module-specific prefix:
  126.  
  127. r_ : Render code (OpenGL)
  128. cg_ : Client Game module
  129. cl_ : Client module
  130. g_ : Game module
  131. ai_ : Artificial intelligence (bots) code
  132. gs_ : Game Shared, code shared between the game and clientgame module.
  133. irc_ : IRC Module
  134. snd_ : Code for a sound module (qf or openal module)
  135. ui_ : User interface code
  136.  
  137. Platform specific files also have their platform as a prefix:
  138. win_ : Windows
  139. unix_ : *nix/Linux/BSD
  140.  
  141. Public functions of a certain library (except for the platform specific
  142. functions of course) use the same prefixes, but in capital. The "CL_NetFrame"
  143. function for example is part of the Client module. Function names are in
  144. camelcase (http://en.wikipedia.org/wiki/CamelCase).
  145.  
  146.  
  147.  
  148. 5. The client
  149. -------------
  150.  
  151.  
  152.  
  153.  
  154.  
  155. 6. The server
  156. -------------
  157.  
  158.  
  159. 7. Entities
  160. -----------
  161.  
  162.  
  163. vim:textwidth=78
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement