User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
cppdev:gamecodeoverview [2011-09-13 23:36]
Carsten created
cppdev:gamecodeoverview [2017-05-08 11:15] (current)
Carsten deleted obsolete section (it's superseded by the component system)
Line 1: Line 1:
-====== Game Code Overview ======+====== Game Development ​Overview ====== 
 + 
 +/* Should we say something about the term "​MOD"​ somewhere on this page? 
 +Cafu separates the core engine (the technical framework that is the common basis for each game or app) from the program code and the resources for each game. 
 +MODs: 
 +like plug-ins / architecture 
 +multiple at the same time 
 +each mod can be game or application 
 +not let this stop you from modifyin the core engine 
 + */
  
 The Cafu Engine can be used both for developing single- or multiplayer games that ship as individual products, The Cafu Engine can be used both for developing single- or multiplayer games that ship as individual products,
Line 8: Line 17:
 or a list of available single-player games, and join one seamlessly without restarting the program. or a list of available single-player games, and join one seamlessly without restarting the program.
  
-In order to achieve these goals, ​and to maintain a good organization of the Cafu source ​code, +The fact the multiple games can be present at the same time makes it worthwhile ​to keep all related files and program ​code well organizedso that games can be developed ​and shipped to end users modularly and independently ​of each other and of the Cafu core engine.
-game implementations are designed modularly in Cafu, +
-such that all the specifics ​and implementation details ​of any game are kept separate from any other game, +
-and cleanly encapsulated and independent from the core engine.+
  
  
-===== One directory ​and DLL per game =====+===== One directory per game =====
  
-All data and code of a game is stored in a common ​subdirectory of ''​[[http://​trac.cafu.de/​browser/​cafu/​trunk/​Games/|Games/​]]''​. +In order to achieve these goals, all files, ​data and program ​code for a game are stored in one common directory, which in turn must be a subdirectory of ''​Games/''​.
-For an example, see directory ''​[[http://​trac.cafu.de/​browser/​cafu/​trunk/​Games/​DeathMatch|Games/​DeathMatch/​]]'' ​that ships with Cafu.+
  
-In each such game directory, the Cafu engine looks for directories and files that, per convention, have fixed names. +For an examplesee the ''​Games/DeathMatch/'' ​directory of the DeathMatch example game that ships with Cafu:
-That is, in each game directory, Cafu expects to find the definition file ''​EntityClassDefs.lua'',​ +
-the implementation in ''​Code/'',​ GUIs in ''​GUIs'',​ world files in ''​Worlds/''​, and so on.+
  
-Regarding the code, each game is implemented in it's own DLL/SO that can be dynamically loaded and bound to at runtime.+{{:​cppdev:​deathmatchdirectory.png}}
  
-The DLL is expected to have the same name as the game, and thus expected to be found in +(Also see [[cppdev:​startnewgame]] for help about creating a new game directory.)
-    Games/​DeathMatch/​Code/​build/​.../​DeathMatch.dll ​    ​(Windows) +
-    Games/​DeathMatch/​Code/​build/​.../​DeathMatch.so ​     (Linux) +
-where ''​%%...%%''​ is a path that is automatically created by the build system according to your platform, +
-compiler and build variant. +
-The ''​%%...%%''​ path is also known to the Cafu engine so that it can load the library.+
  
 +Although you're largely free to organize the contents of the game directory as desired,
 +per convention some of the resource files must be kept under fixed names or in given directories,​
 +so that the Cafu Engine can find and load them when it is newly initializing the game.
  
-===== The game source code =====+The following sub-sections list and explain most of these "​fixed"​ files and directories.
  
-The source code for the DLL is in ''​Code/'',​ inside which you can organize and arrange the source files at will. 
  
-The first function that the engine calls in the game DLL is ''​GetGame()''​. 
-For our example game DeathMatch, we have defined this function in file 
-[[http://​trac.cafu.de/​browser/​cafu/​trunk/​Games/​DeathMatch/​Code/​DeathMatch.cpp#​L89|Games/​DeathMatch/​Code/​DeathMatch.cpp]]. \\ 
-//Please check out this file for more information on the function signature and documentation!//​ 
  
-The next steps to get more familiar with the code is to check out the +==== GUIs====
-[[http://​api.cafu.de/​classcf_1_1GameSys_1_1GameI.html|cf::​GameSys::​GameI]] interface,​ +
-and its implementation in ''​GameImplT''​.+
  
-The core engine will call the methods of the ''​cf::​GameSys::​GameI''​ interface, e.g. those to have new entities created after map file has been loaded or when another player joins the game, and it's the job of the game code to provide implementations for these methods. +The graphical user interfaces that are used in a game are kept in ''​GUIs/''​.
-See the code for class ''​GameImplT'' in order to see how it was done for the DeathMatch game.+
  
-With the ''​BaseEntityT''​ pointers to newly created entities, the engine will also call the virtual methods ​in the ''​BaseEntityT''​ interfacein order to let entities know about events or to have them carry out tasks. +GUIs are used both 
-These methods too are supposed to be overridden by the concrete entity implementationand are in fact the essence of implementing a game+  * in "​2D",​ e.g. for the main menu, the console window, ​the "​HUD"​ (head-up display) ​in the gameetc., as well as 
-An entity is considered a state machine that lives in a virtual worldinteracting with the world and other entitiesand for example its ''​BaseEntity::​Think()''​ method is expected ​to update it over a small amount of time whenever the method is called (by the server code inside the engine).+  * in "​3D",​ as parts of the game worldsthat the player can use e.g. to call lifts, to unlock doors, to activate teleporters,​ or to control any other game script action.
  
 +The GUIs kept in ''​GUIs/''​ are usually "​2D"​ GUIs, and "​3D"​ GUIs that are universally used in multiple maps. "​3D"​ GUIs that are specific to a single map can either be stored in ''​GUIs/''​ as well, or along with the map in the same directory as the map.
  
-===== Exploring ​the code =====+At this time, the following GUIs are automatically loaded by the Cafu Engine:
  
-This document is not complete, and we will continue ​to improve it.+  * ''​GUIs/​ChatInput.cgui''​ -- implements the text input when the player presses ''​T'' ​to talk in the game. 
 +  * ''​GUIs/​Console.cgui''​ -- implements the in-game command console, opened with ''​F1''​. 
 +  * ''​GUIs/​MainMenu/​MainMenu_main.cgui''​ -- implements the main menu that is shown after program start.
  
-The class hierarchy is shown in +In addition, the DeathMatch game code in ''​DeathMatch/Code/HumanPlayer.cpp''​ loads 
-  - http://trac.cafu.de/​browser/​cafu/​trunk/​Ca3DE/​ClassDiagram.dia and +  ​* ''​GUIs/HUD_main.cgui''​ -- implements the players head-up display (cross-hair,​ ammo count, etc.).
-  ​- http://trac.cafu.de/​browser/​cafu/​trunk/​Games/​DeathMatch/​CodeDesign.dia +
-but these two documents need to be merged and updated and completed, where necessary.+
  
 +You can replace all these GUIs by providing your own editions in their place, or just copy them from the DeathMatch example game and modify them as you like.
 +
 +
 +==== Maps/ ====
 +
 +Contains the map files as saved by the CaWE Map Editor.
 +
 +You don't actually have to save your map files in this directory, but we may merge ''​Maps/''​ and ''​Worlds/''​ sometime in the future, and thus ''​Maps/''​ is still the recommended place to save ''​.cmap''​ files.
 +
 +
 +==== Materials/ ====
 +
 +All material definitions for the game maps are kept in ''​Materials/''​.
 +Materials are often reused in several maps of a game, and thus ''​Materials/''​ is where all map materials are centrally stored.
 +
 +The CaWE Map Editor loads the material definitions from this folder in order to provide the map designer with the choices in the Material Browser dialog. The Cafu Engine loads the material definitions from ''​Materials/''​ as well in order to render the materials in the game.
 +
 +
 +==== Music/​NextTitle.txt ====
 +
 +Whenever the player enters a new map, the client calls console function ''​StartLevelIntroMusic()'',​ that in turn is defined in file ''​config.lua''​ in the Cafu top level directory and that uses file ''​Music/​NextTitle.txt''​ in order to play the next title from the list of files in ''​Music/''​.
 +
 +
 +==== Textures/ ====
 +
 +The texture images that the materials in ''​Materials/''​ are referring to are stored here.
 +
 +
 +==== Worlds/ ====
 +
 +Maps from ''​Maps/''​ must be "​compiled"​ in order to be used with the Cafu Engine.
 +Compiling turns a map file (suffix ''​.cmap''​) into a world file (suffix ''​.cw''​) and is documented at [[mapping:​compiling_new]].
 +
 +The world files generated by compiling are stored in ''​Worlds/'',​ where the main menu GUI (''​MainMenu_main.cgui''​ in the DeathMatch example game) looks for ''​.cw''​ files that the player can choose to enter.
 +It also looks for a matching screenshot image to show with the maps list.
 +
 +The ''​Worlds/''​ directory is also the right place for [[http://​api.cafu.de/​lua/​|map scripts]]:
 +  * A map scripts must be placed into the ''​Worlds/''​ directory "​next"​ to the compiled world file. That is, the script must have the same base name as the world, but suffix ''​.lua''​ instead of ''​.cw''​.
 +  * The map script is //not// compiled along with the ''​.cw''​ file: You can change it at any time, and the changes become effective as soon as the world is loaded/​restarted the next time. In fact, it is even possible to [[general:​developer_faq#​how_do_i_dynamically_reload_the_map_script_in-game|update a map script while the game is running]], that is, //without interrupting it//.
 +
 +
 +
 +===== Exploring the code =====
  
-If you have questions about anything that is mentioned ​in this document (or is missing and should be mentioned),​ +The class hierarchy ​is shown in ''​Ca3DE/​ClassDiagram.dia''​
-please let us know! We will be happy to answer you questions and use the answer to improve this text.+
  
cppdev/gamecodeoverview.1315949773.txt.gz · Last modified: 2013-01-07 12:07 (external edit)