project-navigation
Personal tools

Author Topic: Coding tips & FAQ  (Read 18605 times)

Hoehrer

  • Guest
Coding tips & FAQ
« on: March 31, 2006, 07:01:51 pm »
CONTRIBUTING

You should submit a patch to our tracker (make sure to read our 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.

We also have some sections in our wiki with more information: Contribute article and especially: the 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:
Code: [Select]
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:
Code: [Select]
./ufoai +set developer 1... or when you enter ...
Code: [Select]
+set developer 1... in the in-game console.

Werner
« Last Edit: May 21, 2008, 09:25:26 am by Mattn »

Hoehrer

  • Guest
Coding tips & FAQ
« Reply #1 on: April 04, 2006, 07:06:11 pm »
'Clean' string handling in ufo:ai code

Initializing strings
Code: [Select]
char string[BUFFER_SIZE]; // BUFFER_SIZE may have a different name
string[0] = '\0';

Checking for initialized strings
Code: [Select]
if (stringVar[0] != '\0') {
/* string is not empty */
} else {
/* string is zero/empty */
}

Copy strings
Code: [Select]
Com_sprintf(string, BUFFER_SIZE, "teststring %s: %i", something->name, thisIsInt);
Com_sprintf(string, sizeof(string), "teststring %i", intNumber);
Code: [Select]
Q_strncpyz(string, thisIsAnotherStringPointer, BUFFER_SIZE);
Compare strings
Code: [Select]
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
« Last Edit: May 21, 2008, 09:23:09 am by Mattn »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools

Punkiee

  • Guest
Re: Coding tips & FAQ
« Reply #3 on: August 26, 2007, 12:06:11 pm »
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
Code: [Select]
//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
« Last Edit: August 27, 2007, 11:45:14 am by Punkiee »

Punkiee

  • Guest
Re: Coding tips & FAQ
« Reply #4 on: August 27, 2007, 11:08:59 am »
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
Code: [Select]
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.


Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Coding tips & FAQ
« Reply #6 on: December 15, 2009, 07:10:21 pm »
add this to the coding section in our wiki.