Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30

Thread: The "Developers" FAQ

  1. #21
    Join Date
    Sep 2009
    Location
    Sussex
    Posts
    830

    Default

    Updated to include unit testing links.

  2. #22

    Default

    Quote Originally Posted by webspider View Post
    hello friends,
    "What is called the spirit of the void is where there is nothing. It is
    not included in man's knowledge. Of course the void is nothingness. By
    knowing things that exist, you can know that which does not exist.
    thanks

    *EDITED MattyWS, enjoy this website instead http://fletchowns.net/what.html
    Philosophical spam....nice
    Last edited by MattyWS; 11-23-2011 at 02:32 PM.

  3. #23

    Default

    Deleted spam is nicer.

  4. #24
    Join Date
    Sep 2009
    Location
    Sussex
    Posts
    830

    Default

    Just updated the FAQ to include a link provided by Smoothnshiny to some Unity Coding tips.

  5. #25
    Join Date
    Sep 2009
    Location
    Sussex
    Posts
    830

    Default

    SDL tutorial link added.

  6. #26
    Join Date
    Sep 2009
    Location
    Mitcham, London
    Posts
    820

    Default C++ Optimisation

    Have been reading up about speed optimisation so thought I'd post a few rules I've picked up, welcome any feedback or anything I've got totally wrong

    1. In your struct and class declarations, try ant put your member variables in order of size, in bytes. Pointers, ints and floats are all 4 byte aligned, a D3DXMATRIX is 64 byte aligned, a Vector2 would be 8 byte aligned, bool and char are only 1 byte aligned so put them at the end of your declaration. Remember even if it says LPDIRECT3DANIMATIONCONTROLLERINTERFACE it's still only a 4 byte pointer.
    Remeber this is all so that the padding that cpu does becomes obvious, so you can align everything as multiples of the biggest variable, especially if you have a bunch of structs in an array, disastrous for cache hits if your data is not aligned (why should the compiler do it for you !)

    2. Avoid using the 'new' and 'delete' operators too often at runtime, especially during a tight loop, the compiler has to context switch to the operating system every time you call 'new' and it takes ages, mainly because the compiler version of 'new' is really fussy about stuff, so best to overide the global new and delete with your own simple versions.

    3.Do a search of your solution for strcpy and strcmp, calling these functions at runtime can bring a game to it's knees. There is another way of doing it, any strings you know about before the program runs should be hard coded (the only strings you don't know about are the ones pulled in from the asset script, but we can accomadate those easy)

    4. The compiler is so fussy about what you mean it tends to make seperate references to memory when you've not even asked it to (Aliasing) - so avoid a dereference in the condition part of a for() loop, i.e. for ( ; n != *pSomething ; ) the compiler is not clever (or too clever) to copy the contents of pSomething first, it dereferences on every loop, which is a bit slow, better to coax the compiler to putting the DJNZ operand into a register by saying
    int stop = *pSomething;
    for ( ; n != stop ; )
    etc.

    5. Remember to put the const keyword after your function declaration if it doesn't change anything in the class, that is to say your Get()s should all be like
    Fuddle* GetFuddlePointer() const { return m_pFuddle; }

    6. Remember to tell the compiler something is const if it is const, sounds obvious but if something doesn't change for the duration of the game / App then it's const, to make a variable const just say const in front of it, like
    const Vec3 UPAXIS = Vec3(0,1,0);
    From now on every time you say UPAXIS in the source code the actual number (12 bytes) will be embedded in the code, how fast is that
    If you said Vec3(0,1,0) every time you meant "up" the compiler would construct it on the stack which would take ages.

    6a. Saying...
    #define UPAXIS Vec3(0,1,0)
    ... is not the same, as you don't see it in the debugger, so much better to use const (the compiler treats them exactly the same anyway)

    7. Always try and pass arguments by reference, to pass an argument to a function by reference, you only need to 'declare' the argument as being passed by reference, as in
    bool GetCurrentStatus( StatusData& refStatusDataToBeFilled );
    Once you've declared it as a reference that's it, the compiler will do the rest, that is, when you call said function the compiler will take a reference as argument, and will complain if you don't give it one.


    Any more tips for making our code lightning fast ?
    Last edited by _Q_; 01-18-2012 at 10:01 AM.

  7. Default

    2. It is less about avoiding using them at runtime and more about using it carefully so you are not fragmenting the memory. So calling new to create a pool of objects in the game at the start of every level or even better, at the start of the game is fine but as _Q_ said, calling it in a loop that runs every frame is going to cost.

    5 & 6 are more about code quality as the compiler doesn't really do anything special with them. The compiler is usually pretty good at inlining/optimising values known at compile time. So int foo = 8 * 2 would most likely get inlined as int foo = 16.

    6a. const is not the same as #define to the compiler. There are distinctions between the two.

    7. For the 'basic' datatypes like floats, chars, ints, bools, the cost of passing by value and reference is the same as the size of a memory address (which is what is passed when you pass by reference) is the same size as those datatypes. If you are passing by reference, bear in mind that you should always pass by const reference unless you are intentionally wanting to modify that variable.

    My first rule of optimisation is to profile, profile, profile. Profile before you make any changes to find where the bottle necks are and profile after to see if you actually made a difference. There is little point on optimising a function so it runs in a 1/10th of the time before if it only gets called once. Look at the algorithms you are using, is it possible to optimise it so it requires less iterations/loops? Learn about cache behaviour (something I am weak at) as you can get some big wins by swapping some loops about.

  8. #28
    Join Date
    Sep 2009
    Location
    Mitcham, London
    Posts
    820

    Default

    Quote Originally Posted by yaustar View Post
    2. 6a. const is not the same as #define to the compiler. There are distinctions between the two.
    Yea should correct that, a #define is a macro and gets replaced with whatever you typed.
    So..
    #define FOREVER for( ; ; )

    Is treated differently than...

    #define PLAYERHEIGHT 6.4f
    Which would be the same as saying
    const float PLAYERHEIGHT = 6.4f;

    But it's stupid using define for a constant, as intellisense won't tell you what it is when debugging
    Last edited by _Q_; 01-18-2012 at 01:27 PM.

  9. #29
    Join Date
    Sep 2009
    Location
    Mitcham, London
    Posts
    820

    Default What is the difference between a declaration and a definition

    Q: What is the diffference between a declaration and a definition ?

    A: When a compiler sees a DECLARATION, it doesn't assign any memory, it doesn't do anything really, it just remembers what you've called stuff and what your argument types are and what it returns (if it's a function declaration)

    When a compiler sees a DEFINITION, it assigns a chunk of memory in it's executable image and fills it with a load of machine code (if a function) or fills it with a load of bytes (if it's a variable)

    Code:
    // E.G.
    struct HolaAdios
    {
    const char* mSayHello;
    const char* mSayGoodBye;
    };                // declaration - compiler does nothing, just remembers what things are and what they're called
    
    HolaAdios* GetHello( int language );   // declaration - compiler does nothing, no memory filled in the exe image
    int            number;                 // declaration - compiler does nothing
    
    HolaAdios* GetHello( int language ) 
    {   // definition - code segment of the image gets filled with a bunch of machine code
      if ( language == FRENCH )
     {
        const char* str = "This is going to end up in the data segment of the exe image as it's an initialised const";
        HolaAdios    sayHello; // definition, even though no equals sign - compiler must reserve 8 bytes on the
                                     // stack when instancing sayHello object, even though it's not initialised. 
                                     // sayHello will be on the stack within the function call in the code segment
                                     // - goes out of scope when function exits
     }
    
    }
    Last edited by _Q_; 01-25-2012 at 01:08 AM. Reason: Error

  10. #30

    Default

    If anyone is reading this then can you please answer the question in the thread i just opened called urgent question real quick. By the way I am having a problem changing my profile pic, I really don't have a clue so can anyone tell me how to upload a profile picture

Similar Threads

  1. Replies: 20
    Last Post: 07-31-2010, 06:21 PM
  2. Replies: 0
    Last Post: 06-22-2010, 11:59 AM
  3. Just Signed up on "Game Design Course" Paolo
    By Godfather10 in forum Newbies Area
    Replies: 7
    Last Post: 06-10-2010, 11:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •