About the source code

A place for all things OpenMoHAA

Moderator: OpenMoHAA developers

Post Reply
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

About the source code

Post by Rookie One.pl »

Here's some general information on coding the project.

For those who coded in C++ before but not in "bare" C
C does not have the following things:
  • classes
  • templates
  • overloading (both functions and operators)
  • references
Please don't define constants as variables using the const keyword, but use defines instead. I.e.
BAD

Code: Select all

const char *foo = "bar";
GOOD

Code: Select all

#define FOO "bar"
Where do I start with the source code?
The ioquake3 wiki can give you an idea on things, e.g. how the execution proceeds from the moment of launching the game.
For access to the source code repository, check out the SourceForge project page - there's a link to the left that says "SVN repository access" (or you can go directly to ViewVC if you only want to browse the code).

Coding style
This section contains coding style guidelines that I'm asking of you to obey (mostly copied over from the FreeCNC website). Mind you these are guidelines - I can take any code as long as it's clean and organized. ;)

General presentation
  • Comment all code that isn't self-explanatory. Especially that pointer hacking.
  • Tab indenting, no four-spaces.
  • Header guards follows the FILENAME_EXT convention - G_FOOBAR_H for game/g_foobar.h
  • Indent #ifdef/#ifndef etc the same as regular code. That is, like normal if/else statements.
  • When declaring pointers, put * next to the variable, not the type.

    Code: Select all

          int x = 42;
          int *z = &x;
  • Where applicable, start the file with a comment explaining the contents. For headers, place it right after the header guards.

    Code: Select all

          // g_script.c - implements the server side scripting
  • For big files, seperate sparingly with headers or simple splitters.

    Code: Select all

          //--------------------------------------------------------
          // Script stack
          //--------------------------------------------------------

    Code: Select all

          void foo (int bar) {return 0;}
    
          //--------------------------------------------------------
    
          int bar (byte foo) {return foo & 0xdeadbeef;}
  • In cases where it makes sense, try to keep 80 chars per line.
  • C++ style comments should be used for 1 liners. Never use /**/ for single line comments.
  • Use ALL_UPPER_CASE for defines, enums values and macros.

    Code: Select all

          #define VERSION "0.3.0"
          enum {
              RED,
              GREEN,
              BLUE
          };
  • Use Pascal casing or underscoring for words in variables.

    Code: Select all

          int fooBar;
          int foo_bar;
  • Use curly braces for control-flow statements that span several statements, and no braces for those comprised of one.
    BAD

    Code: Select all

          if (true) printf("foo\n");
    BAD

    Code: Select all

          if (true) {
                printf("foo\n");
          }
    GOOD

    Code: Select all

          if (true)
                printf("foo\n");
    GOOD

    Code: Select all

          if (true) {
                printf("foo\n");
                printf("bar\n");
          }
Last edited by Rookie One.pl on Thu Apr 03, 2008 9:33 pm, edited 4 times in total.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
jed
Lance Corporal
Posts: 19
Joined: Sat Feb 09, 2008 8:37 am

Post by jed »

Im learning C++ with a book but exemples are too easy (class "car", methods "start", "stop" etc lol). I understand syntax caracteristics (for me c++ is a complex language), but i dont able to manipulate a game engine with this way. :( Ill try to learn opengl programming to work on engine but i have a lot of work with my studies, im hurrying.
m0d hippY
Warrant Officer
Posts: 132
Joined: Tue Apr 27, 2004 3:58 am

Post by m0d hippY »

c\c++ definitely takes time to pickup. And to be honest learning OGL won't really be helpful in this project I don't think. The reason for that is because this project uses its own functions to render everything instead of using openGL. Now granted it's always good to learn just to know it, but I haven't seen any real use of ogl in the code so far.
Image
Image
Rookie One.pl
Site Admin
Posts: 2752
Joined: Fri Jan 31, 2003 7:49 pm
Location: Nowa Wies Tworoska, Poland
Contact:

Post by Rookie One.pl »

Of course there is OpenGL in Quake III, it's the rendering backend. We're not going to touch it anytime soon, though.

I'm making this topic public.
Admin
Image
Image
Honour guide me.

here's my stuff - inequation.org | here's where I work - thefarm51.com
Post Reply