SJA random projects - Page 3

User Tag List

Page 3 of 24 FirstFirst 1234513 ... LastLast
Results 21 to 30 of 236
  1. #21
    Moderator TimTim's Avatar
    Join Date
    Aug 2013
    Posts
    1,804
    Country:
    @~~D4RR3N~~ I'll need a different example (something practical, real world) where you're actually extending some class. A single class/object is fine like you have there.

  2. #22
    Whicked Sick UT-Sniper-SJA94's Avatar
    Join Date
    Oct 2011
    Location
    What was England
    Posts
    4,427
    Country:
    Isn't a monster extending an enemy class a good example for inheritance?

  3. #23
    Whicked Sick ~~D4RR3N~~'s Avatar
    Join Date
    Jul 2012
    Location
    Venezuela
    Posts
    1,614
    Country:
    Instagib doesn't originally inherit from Shock Rifle?
    Quote Originally Posted by |uK|UNrealshots View Post
    You're playing a game that came out in 1999 in the year 2012 who is the fucking nerd here?
    All of us. Enjoy.

  4. #24
    Whicked Sick UT-Sniper-SJA94's Avatar
    Join Date
    Oct 2011
    Location
    What was England
    Posts
    4,427
    Country:
    Quote Originally Posted by ~~D4RR3N~~ View Post
    Instagib doesn't originally inherit from Shock Rifle?
    The instagib rifle is the class supershockrifle, which is a subclass of shockrifle.

  5. #25
    Moderator TimTim's Avatar
    Join Date
    Aug 2013
    Posts
    1,804
    Country:
    Yes @~~D4RR3N~~ and @UT-Sniper-SJA94, both good examples of inheritance.

    So let's consider the SuperShockRifle. It's an extension of the ShockRifle, which extends TournamentWeapon, which extends Weapon, which extends Inventory, which extends Actor, which extends Object. And so you have all these methods and properties (hundreds!) which are inherited through each class, and at least a handful of `Super` calls within some method to call the same method within the parent class. It takes way too much effort to form a mental model of everything happening there. You're constantly going back and forth from class to class and tracing the code backwards, forwards, sideways, etc.

    Now let's consider the SuperShockRifle as a simple object (or module) which doesn't inherit anything. Instead it would import a handful of other modules to produce the desired functionality. Each module should do one simple, specific, predictable thing which always works exactly as intended. So instead of going back and forth repeatedly between the SuperShockRifle's ancestors, you have something short and sweet and very flat/straightforward. All you would need to know is what kind of inputs the imported modules expect for their exported methods. And you know these other modules will always work as intended since nothing within them can be overridden.

    Beyond that, composition rather than inheritance has the added benefit of maximizing code reuse and minimizing bugs. If you've ever looked at the source behind all of UT's weapons, you'd notice there's actually a ton of duplicate code. In many weapons, you'll see code in one weapon that almost exactly matches some code in another weapon, despite each weapon extending TournamentWeapon (and so on). This is usually a sign of doing something wrong. Plus, if you realize something needs to be changed within said common code, you'd have to update many different files rather than just one. (I ran into this many times with NewNet and it got rather annoying.) Of course you can have special objects/classes containing static methods for common functionality, and that's a step in the right direction, but you'll run into some pretty silly issues when you try to mix and match paradigms like that.

    I'd be glad to put together some pseudo-code as an example for what I'm talking about if anyone is curious.

  6. #26
    Whicked Sick ~~D4RR3N~~'s Avatar
    Join Date
    Jul 2012
    Location
    Venezuela
    Posts
    1,614
    Country:
    Doesn't it take more effort to be writing specific logic for each individual?
    If you could, please post the pseudo-code, cuz I think I'm getting the idea.
    If you want methods inherited to act different wouldn't you use virtual methods, and override?
    Quote Originally Posted by |uK|UNrealshots View Post
    You're playing a game that came out in 1999 in the year 2012 who is the fucking nerd here?
    All of us. Enjoy.

  7. #27
    Whicked Sick UT-Sniper-SJA94's Avatar
    Join Date
    Oct 2011
    Location
    What was England
    Posts
    4,427
    Country:
    .

  8. #28
    Moderator TimTim's Avatar
    Join Date
    Aug 2013
    Posts
    1,804
    Country:
    Quote Originally Posted by ~~D4RR3N~~ View Post
    Doesn't it take more effort to be writing specific logic for each individual?
    Nope. It's actually ends up taking less effort, especially in the long run.

    I might put something together tomorrow for you to check out.

  9. #29
    Whicked Sick Higor's Avatar
    Join Date
    Apr 2012
    Location
    Full sail ahead!
    Posts
    3,676
    Country:
    Here, some sample polymorphism pseudocode.
    Much easier when you got a class tree, if the tree is properly structured, you can save up lots of code.

    Code:
    class Animal
    {
       //Variables
       int Age;
       Animal* Parent; //Directly created from (doesn't count second parent)
    
       //Default constructor
       Animal( Animal* InParent=NULL)
       : Age(0)
       , Parent(InParent)
       {};
    
       //Functions
       bool WasMadeBy( Animal* Other)
       {
            return Other == Parent;
       }
    
       //Virtual functions (can be overriden in child classes)
       virtual bool SpeciesRequiresQueen()
       {
           return false;
       }
       virtual bool IsChildOf( Animal* Other)
       {
           return WasMadeBy( Other);
       }
    };
    Code:
    class Insect : public Animal
    {
       int Legs; //LOL
    };
    
    class Ant : public Insect
    {
       //Variables
       bool bQueen;
    
       //Constructor
       Ant( Ant* InParent=NULL )
       : Animal( InParent) //Call super constructor
       , bQueen(false)
       , Legs(6)
       {
           if ( !InParent->bQueen ) //Parent not a queen
               Error(); //Shut down program, unexpected behaviour
       }
    
       //Functions
       void BecomeQueen()
       {
           bQueen = true;
       }
    
       //Animal interface (virtual function override)
       bool SpeciesRequiresQueen()
       {
           return true;
       }
    };
    Code:
    class Mammal : public Animal
    {
        Mammal* Parent2;
    
        //Constructor
        Mammal( Mammal* InParent=NULL, Mammal* InParent2=NULL)
        : Animal( InParent)
        , Parent2(InParent2)
        {};
    
       //Animal interface (virtual function override)
       bool IsChildOf( Animal* Other)
       {
           return WasMadeBy( Other) || Parent2 == Other;
       }
    }
    ------------------------------------- * -------------------------------------

  10. #30
    Whicked Sick Chamberly's Avatar
    Join Date
    Jul 2012
    Location
    Vandora Temple
    Posts
    5,488
    Country:
    Now I get it... I'm really used to reading Higor's codes...


    http://irc.lc/globalgamers/uscript for uscript discussion.

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Similar Threads

  1. Another random game
    By UT-Sniper-SJA94 in forum Spam Section
    Replies: 79
    Last Post: 06-29-2015, 07:59 PM
  2. Random siege gif.
    By Chamberly in forum Screenshots
    Replies: 8
    Last Post: 01-05-2015, 04:17 AM
  3. Ben10 / Random / random Anime names
    By uenz in forum Reports/Complaints & Appeals
    Replies: 7
    Last Post: 08-30-2014, 02:43 PM
  4. Random bug
    By UT-Sniper-SJA94 in forum Spam Section
    Replies: 7
    Last Post: 03-13-2014, 11:22 AM
  5. Everybody random guy
    By |uK|B|aZe//. in forum Bans
    Replies: 0
    Last Post: 12-23-2011, 10:31 AM

Tags for this Thread

Posting Permissions

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