UFO:Alien Invasion
Development => Coding => Topic started by: Hoehrer on March 31, 2006, 07:01:51 pm
-
CONTRIBUTING
You should submit a patch to our tracker (http://sourceforge.net/tracker/?atid=805244&group_id=157793&func=browse) (make sure to read our coding guidelines (http://ufoai.ninex.info/wiki/index.php/Coding_guidelines). Once you have submitted a patch that was accepted, you can get also write access to our svn. All you need is am account at sourceforge.net (http://www.sourceforge.net).
We also have some sections in our wiki with more information: Contribute article (http://ufoai.ninex.info/wiki/index.php/Contribute) and especially: the coding (http://ufoai.ninex.info/wiki/index.php/Coding) article.
DEBUG MESSAGES
Mattn told me that there exists a print-command for debug messages. The syntax is the nearly same as printf. You can use it like this:
Com_DPrintf(DEBUG_CLIENT, "Your debug message here.\n");
Com_DPrintf(DEBUG_CLIENT, "Your debug message here id='%i'\n" , some_integer_number );I suggest to add the current function name in front of the actual message, to locate the function faster and keep the messages seperated from the others.
These messages are only displayed if you start UFO:AI like this:
./ufoai +set developer 1... or when you enter ...
+set developer 1... in the in-game console.
Werner
-
'Clean' string handling in ufo:ai code
Initializing strings
char string[BUFFER_SIZE]; // BUFFER_SIZE may have a different name
string[0] = '\0';
Checking for initialized strings
if (stringVar[0] != '\0') {
/* string is not empty */
} else {
/* string is zero/empty */
}
Copy strings
Com_sprintf(string, BUFFER_SIZE, "teststring %s: %i", something->name, thisIsInt);
Com_sprintf(string, sizeof(string), "teststring %i", intNumber);Q_strncpyz(string, thisIsAnotherStringPointer, BUFFER_SIZE);
Compare strings
if (!Q_strncmp(string, "test", 4)) {
/* string has "test" in it */
} When using Q_strncmp you have to keep in mind, that string like testSomethingOtherVeryLongHere also match on the above Q_strncmp call.
Werner
EDIT: removed gettext example
-
http://en.wikipedia.org/wiki/C_programming_language
http://www.techbooksforfree.com/ccpp.shtml
http://www.cprogramming.com/
-
What about variable naming? function naming? Proposing:
structs -> lower case
functions -> PART_CapitalizeNames, where PART is the name of the unit the function belongs too.
eg AIR -> arircraft
constants -> UPPERCASE
variables -> lowerAndUppercaseNames
use tabs, not spaces
never use one line conditials
//DONT
if(happy) clappYourHands;
//instead use
if(happy) {
clappYourHands;
}
It was well hidden but i found this http://ufoai.ninex.info/wiki/index.php/Coding/Guidelines (http://ufoai.ninex.info/wiki/index.php/Coding/Guidelines)
-
Another thing, related to FAQ, "How to submit a patch":
Before you add a new patch, please make sure you have done so on the latest version of the branch you are working on. use "svn up" to update and check for conflicts.
Make a diff of the src
svn diff src/ > filename.diff
In the SF page of ufo:ai , there is a patch tracker which is meant to keep track of all patched. (thus you need to have registered on SF.net) Now you can create a new tracker by providing a description and the diff file. You will be mailed for every change in the tracker.
-
http://en.wikipedia.org/wiki/C_programming_language
http://www.techbooksforfree.com/ccpp.shtml
http://www.cprogramming.com/
completely free online-book in german for c-programming: http://openbook.galileocomputing.de/c_von_a_bis_z/
-
add this to the coding section in our wiki.