Wayback Machine
MAR Oct JUL
Previous capture 27 Next capture
2005 2006 2007
4 captures
5 Mar 06 - 12 Aug 07
sparklines
Close Help
  home · browse · search · game entities · user directory · message board · IRC | register

October 27, 2006, 4:40 pm PDT
username  
password  
forgot password?

Popular Resources
  • Half-Life 2 Mod FAQ
  • Valve Hammer Editor
  • Hammer 3.5 beta test
  • Half-Life Utilities
  • game data files
  • ZHLT 2.5.3 custom build
  • Half-Life SDK
  • Feedback
    If you've got any feedback, suggestions, or bugs to report regarding the Collective website, go here!

  • Feedback (301)
  • Newsletter
     
    Enter your email address in the above form to add yourself to the email newsletter list. Click here for more info.

    Hosted Sites
  • Valve ERC
  • Collective
  • TFMapped
  • Spirit of Half-Life
  • Selective Design
  • Pixel Reviews
  • recent articles

    NPC and Item Placement Theory
    17/03/05 11:35pm PST
    Non-Player Character (NPC) and item placement can influence both the gameflow and immersion of a level. This article aims to give some pointers on how to properly place them.
    - Hugh 'Hugh' Lloyd

    Got Props?
    13/03/05 08:32am PST
    A common problem in HL2 mapping is props not showing up in game. This article explains why and offers solutions.
    - Jeff 'Yesukai' Pritchard

    Simulating Randomness
    18/12/04 11:29pm PST
    This article focuses on how to properly simulate random events that should occur at a certain average frequency, or within a certain probability per period of time.
    - Skyler 'Zipster' York

    Adding Single-Player Weapons to Half-Life 2
    15/12/04 06:52pm PST
    Covers the process behind adding weapons to a single-player Half-Life 2 modification.
    - Skyler 'Zipster' York

    Your world in HL2
    06/12/04 12:17am PST
    This article gives tips and advice to anyone wanting to make custom photorealistic textures to be used in Half-Life 2.
    - Oksid

    Hiding in Shadow
    21/08/04 01:11pm PDT
    Describes how to create a function that has monsters disregard you if you are hiding in a certain level of "darkness," which can be set from within map properties.
    - Anders [Wolf] Jenbo (NoBody)

    XSI EXP for Half-Life 2 Tutorial - Camera Control
    23/09/04 12:43am PDT
    A SOFTIMAGE|XSI tutorial explaining all of the camera controls available to you in XSI!
    - Josh Enes

    Bump Mapping in Half-Life
    08/08/04 11:58am PDT
    Details a method of achieving real-time bump mapping in Half-Life, and provides an implementation of the algorithm.
    - Francis 'DeathWish' Woodhouse

    Real-Time "TRON 2.0" Glow For Low-Spec Hardware
    19/06/04 02:06pm PDT
    A sequel to the original "Real-Time 'TRON 2.0' Glow" article, this describes how to implement real-time glow that works on low-spec graphics cards.
    - Francis 'DeathWish' Woodhouse

    Hitboxes and Code
    05/06/04 06:25pm PDT
    How do I make only one part of a monster take damage? Learn about the relationship between model hitboxes and what you can do with them in a characters code.
    - Jonathan 'Teh_Freak' Smith

    Function Overloading
    [Thu Feb 07, 2002 / 09:53pm PST] Tim Toxopeus - comments (0) comments enabled

    Function Overloading is useful when you have a function that you want to do several different things with different results depending on what inputs it is given.

    Example :

    // Example 1 int Double( int value ) { return 2 * value; }

    That would return an int, but what if you wanted to double a float? MSVC++6 would give you a warning saying that converting this could result in data loss.

    Example :

    float value = Double( 2.3 );

    This would give you 2 warnings. 1 in Double and 1 because of the = operator. Remember, Double was declared as an int, and float = int results in a warning. What could you do? You could cast it, but the 2.3 would still be lost, turned into 2.

    How would you solve this?

    You could do this :

    // Example 2 float DoubleForFloats( float value ) { return value * 2.0; }

    but then you'd have to write and call a different function. Here's how it's done with Function Overloading :

    // Example 3 int Double( int value ) { return value * 2; }; float Double( float value ) { return value * 2.0; };

    As you can see both functions have the same name, but their type is different and the value you pass is off a different type as well. Yet your compiler doesn't give you an error of duplicate declaration. (at least mine didn't :D)

    Function Overloading can only work if the first parameter is different.

    You can have ...

    int double( int, int );

    ... and ...

    int double( float, int );

    ... but NOT ...

    int double( int, float );

    ... because the last one would have the first parameter the same as the first one, an int.

    With this you can use the same function name, but give out different results.

    Simple Example:

    // Example 4 :] #include "stdio.h" int PrintValue( int value, int repeat ); int PrintValue( float value, int repeat ); int main() { int the_int = 10; float the_float = 12; PrintValue( the_int, 3 ); PrintValue( the_float, 3 ); return 0; } int PrintValue( int value, int repeat ) { for ( int a = 1; a < repeat + 1; a++ ) { printf("The int value is %d, and this has been repeated %d times...\n", value, a ); } return 0; } int PrintValue( float value, int repeat ) { for ( int a = 1; a < repeat + 1; a++ ) { printf("The float value is %f, and this has been repeated %d times...\n", value, a ); } return 0; }

    You could just as well use this for Half-Life, to change health for monsters. You could cast this, but you wouldn't be able to call monster specific stuff.

    Example:

    // Example 5 int SetHealth( CBaseEntity *pEntity, int health ); int SetHealth( CBasePlayer *pPlayer, int health ); int SetHealth( CBaseMonster *pMonster, int health );

    .. Call this with SetHealth( pEntity, 100 ); ..

    Of course this seems a bit stupid, but I couldn't think up a better example for Half-Life :] Their bodies would be very alike ...

    Example for the CBaseEntity:

    // Example for the CBaseEntity int SetHealth( CBaseEntity *pEntity, int health ); { if ( pEntity && pEntity->IsAlive() ) pEntity->pev->health = health; return 0; }

    But even this way you'd already save a line, as all you have to do then is SetHealth( pEntity, 100 ); and it would check for you if the entity you send is both existing AND alive, saving you the if line and the risk of crashes if you don't do that.

    Function Overloading is there to make your code smaller and easier to read. Overuse, and especially bad overuse can make your code harder to read, so be careful how you use it.

    article created on Thu Feb 07, 2002 / 07:24am PST
    this item has been viewed 894 times
    [general / coding]

    Only registered users can post comments. Have you registered yet?

    noone has commented on this document

    VERC © 2004. All content copyright its respective owner, all rights reserved.
    script execution time: 0.0650341510773 seconds