Development: Difference between revisions

Marked this version for translation
mNo edit summary
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{MigrateTranslation}}
<languages/>
<languages/>
<translate>
<translate>
Line 47: Line 48:


<!--T:14-->
<!--T:14-->
<code>sudo pacman -S --needed base-devel cmake curl freetype2 git glew gmock libnotify opusfile python sdl2 sqlite wavpack</code>
<syntaxhighlight lang="bash">
sudo pacman -S --needed base-devel cmake curl ffmpeg freetype2 git glew glslang gmock libnotify libpng opusfile python rust sdl2 spirv-tools sqlite vulkan-headers vulkan-icd-loader wavpack x264
</syntaxhighlight>
 
For Debian:


<syntaxhighlight lang="bash">
sudo apt install build-essential cargo cmake git glslang-tools google-mock libavcodec-extra libavdevice-dev libavfilter-dev libavformat-dev libavutil-dev libcurl4-openssl-dev libfreetype6-dev libglew-dev libnotify-dev libogg-dev libopus-dev libopusfile-dev libpng-dev libsdl2-dev libsqlite3-dev libssl-dev libvulkan-dev libwavpack-dev libx264-dev python rustc spirv-tools4
</syntaxhighlight>


== Compiling DDNet == <!--T:15-->
== Compiling DDNet == <!--T:15-->
Line 100: Line 108:


<!--T:29-->
<!--T:29-->
This game uses its own [https://en.wikipedia.org/wiki/Entity_component_system Entity Component System], the main class to which all other entities derive from is <code>CEntity</code> located in <code>src/game/server/entity.h</code>.
This game uses its own hierarchical object-oriented entity system, the main class to which all other entities derive from is <code>CEntity</code> located in <code>src/game/server/entity.h</code>.


<!--T:30-->
<!--T:30-->
Line 152: Line 160:


<!--T:44-->
<!--T:44-->
Finalthing();
FinalThing();
</syntaxhighlight>
</syntaxhighlight>


=== Classes and Structs === <!--T:45-->
=== Classes and Structs === <!--T:45-->


<!--T:46-->
<!--T:46-->
Must be prefixed by <code>C</code> (for legacy reasons this is ignored for structs in some places, such as in graphics code) or <code>I</code> for interfaces.
Must be prefixed by <code>C</code> (for legacy reasons this is ignored for structs in some places, such as in graphics code) or <code>I</code> for interfaces. New <code>struct</code>s should be prefixed by <code>S</code>.


<!--T:47-->
<!--T:47-->
Line 208: Line 215:
<!--T:56-->
<!--T:56-->
* <code>m</code> for member variables: <code>m_MyVariable</code>.
* <code>m</code> for member variables: <code>m_MyVariable</code>.
* <code>s</code> for static variables: <code>s_MyStaticVariable</code>.
* <code>s</code> for static variables: <code>s_MyStaticVariable</code>, <code>ms_MyStaticMemberVariable</code>.
* <code>g</code> for global variables with external linkage: <code>gs_MyGlobalStaticVar</code>.
* <code>g</code> for global variables with external linkage: <code>gs_MyGlobalStaticVar</code>.


Line 217: Line 224:
* <code>p</code> for pointers: <code>pMyPointer</code>, <code>m_pCharacter</code>, <code>ppMyPointerToPointer</code>.
* <code>p</code> for pointers: <code>pMyPointer</code>, <code>m_pCharacter</code>, <code>ppMyPointerToPointer</code>.
* <code>a</code> for arrays: <code>aMyArray</code>, <code>aBuf</code>.
* <code>a</code> for arrays: <code>aMyArray</code>, <code>aBuf</code>.
* <code>v</code> for <code>std::vector</code>s: <code>vMyVector</code>, <code>vpvMyVectorOfPointersToVectors</code>.
* <code>fn</code> for functions: <code>pfnMyCallback</code>, <code>m_papfnMyPointerToArrayOfCallbacks</code>.
* <code>fn</code> for functions: <code>pfnMyCallback</code>, <code>m_papfnMyPointerToArrayOfCallbacks</code>.


Line 234: Line 242:
</syntaxhighlight>
</syntaxhighlight>


 
See [https://cplusplus.com/reference/cstdio/printf/ printf documentation] for a list of all format specifiers.
=== Iterating over all players === <!--T:63-->
=== Iterating over all players === <!--T:63-->


Line 253: Line 261:
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "wikiprint", "Hello from the ddnet wiki!");
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "wikiprint", "Hello from the ddnet wiki!");
</syntaxhighlight>
</syntaxhighlight>




Line 263: Line 272:
</syntaxhighlight>
</syntaxhighlight>


=== Translating text in the client ===
<code>Localize</code> can be used in the game client to get the translation for a specific string from the language file selected by the user.<syntaxhighlight lang="cpp">
DoButton(..., Localize("Connect"), ...);
</syntaxhighlight>The string can also contain format specifiers. The translated string must contain the same format specifiers.<syntaxhighlight lang="cpp">
char aBuf[128];
str_format(aBuf, sizeof(aBuf), Localize("%d of %d servers"), NumServers, TotalServers);
</syntaxhighlight>A script is used to scan the code for calls to <code>Localize</code> and collect the strings to update the translation files. For this reason, the call to <code>Localize</code> must not contain any other code, or the script cannot determine the text correctly.<syntaxhighlight lang="cpp">
// Do NOT do this:
const char *pStr = Localize(Team == TEAM_RED ? "Red team" : "Blue team");
// Do this instead:
const char *pStr = Team == TEAM_RED ? Localize("Red team") : Localize("Blue team");
</syntaxhighlight>


== External resources == <!--T:69-->
== External resources == <!--T:69-->


<!--T:70-->
<!--T:70-->
* [https://edgarluque.com/blog/ui-code-ddnet/ UI Code in DDraceNetwork] by [[Special:MyLanguage/User:Ryozuki|Ryozuki]]
* [https://edgarluque.com/blog/intro-to-ddnet/ An intro to the DDraceNetwork game source code]  by [[Special:MyLanguage/User:Ryozuki|Ryozuki]]
* [https://edgarluque.com/blog/intro-to-ddnet/ An intro to the DDraceNetwork game source code]  by [[Special:MyLanguage/User:Ryozuki|Ryozuki]]
* [https://edgarluque.com/blog/code-conventions-in-ddnet/ Code conventions in DDraceNetwork]  by [[Special:MyLanguage/User:Ryozuki|Ryozuki]]
* [https://edgarluque.com/blog/code-conventions-in-ddnet/ Code conventions in DDraceNetwork]  by [[Special:MyLanguage/User:Ryozuki|Ryozuki]]