====== 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, as well as for products that support multiple, independent games in a single program that the user can select from at runtime. For example, after starting the program, the user might choose from a list of online game servers (each possibly running not only different game maps, but entirely different games), or a list of available single-player games, and join one seamlessly without restarting the program. The fact the multiple games can be present at the same time makes it worthwhile to keep all related files and program code well organized, so that games can be developed and shipped to end users modularly and independently of each other and of the Cafu core engine. ===== One directory per game ===== 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 the ''Games/DeathMatch/'' directory of the DeathMatch example game that ships with Cafu: {{:cppdev:deathmatchdirectory.png}} (Also see [[cppdev:startnewgame]] for help about creating a new game directory.) 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 following sub-sections list and explain most of these "fixed" files and directories. ==== GUIs/ ==== The graphical user interfaces that are used in a game are kept in ''GUIs/''. GUIs are used both * in "2D", e.g. for the main menu, the console window, the "HUD" (head-up display) in the game, etc., as well as * in "3D", as parts of the game worlds, that 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. At this time, the following GUIs are automatically loaded by the Cafu Engine: * ''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. In addition, the DeathMatch game code in ''DeathMatch/Code/HumanPlayer.cpp'' loads * ''GUIs/HUD_main.cgui'' -- implements the players head-up display (cross-hair, ammo count, etc.). 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 ===== The class hierarchy is shown in ''Ca3DE/ClassDiagram.dia''