Skip to main content

User login

What is OpenID?
  • Log in using OpenID
  • Cancel OpenID login
  • Create new account
  • Request new password
Register
  • Home
  • Browse
    • 2D Art
    • 3D Art
    • Concept Art
    • Textures
    • Music
    • Sound Effects
    • Documents
    • Featured Tutorials
  • Submit Art
  • Collect
    • My Collections
    • Art Collections
  • Forums
  • FAQ
  • Leaderboards
    • All Time
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
    • Weekly
      • Total Points
      • Comments
      • Favorites (All)
      • Favorites (2D)
      • Favorites (3D)
      • Favorites (Concept Art)
      • Favorites (Music)
      • Favorites (Sound)
      • Favorites (Textures)
  • ❤ Donate
FLARE

Inheritance

wokste
Wednesday, April 6, 2011 - 06:56

I just read through the source of FLARE. Although the overal source looks nice, there were a few things that I did not like the lack of inheritance.

I would personaly inherit Avatar and Enemy (and maybe NPC) from a common class.

 

  • Common functions like move, has to be coded only once.
  • Lists can work on more than one class at the same time.

 

My question is: Do you want me to fix that? (A good way to start in a project is finding a few small things and fixing them)

Steven

  • Log in or register to post comments
Clint Bellanger
joined 13 years 6 months ago
Wednesday, April 6, 2011 - 07:17
Clint Bellanger's picture

I prefer using composition when possible, rather than inheritance.  I think of inheritence as a necessary evil complexity saved for extreme circumstances.

Having a base class for units/entities I'm okay with.  Right now there's only Avatar and Enemy so I didn't bother (my style of actually getting a project done: write it sensibly now, refactor it to be pretty later).  It would be good to have a Unit class eventually because it'll help with moving NPCs or multiplayer avatars.

It's something floating on my to-do list that isn't a priority (better to write new features than refactor old ones while in Alpha).  If you want to take a crack at it though, feel free.  Simple is better -- if you spend more than one new class (e.g. Unit.cpp) I might not accept the solution.

Sorry to be a hardass about this, but I'll be the one looking at and maintaining this code for the rest of my life :)

  • Log in or register to post comments
wokste
joined 11 years 11 months ago
Wednesday, April 6, 2011 - 08:57

Okay,

If you don't like inheritance I'll take for another part.

It seems to be more difficult than I inmagined anyway, partly due to the difference it the enums (e.g. heroes don't take crits) and partly due to the fact that my svn is not working properly.

Steven

PS: Don't worry, I don't mind (much).

 

 

  • Log in or register to post comments
Clint Bellanger
joined 13 years 6 months ago
Wednesday, April 6, 2011 - 09:03
Clint Bellanger's picture

If you would like to outline a base Units.cpp class, it definitely would be helpful to me.  I could handle the trickier differences between Enemy and Avatar (just not immediately).

For timeline info: I plan on releasing v0.13 late April and v0.14 late May.  That will probably come with a Beta tag and a freeze on major features.  A lot of the coding I'll be doing in Beta will be refactoring, mostly to move hardcoded configs into text files.  At some point in there I'll probably think about a base Units class, and maybe a separate UnitAnimation component.

 

  • Log in or register to post comments
wokste
joined 11 years 11 months ago
Thursday, April 7, 2011 - 02:37

I will try to make a design for the new class.

  • Log in or register to post comments
wokste
joined 11 years 11 months ago
Saturday, April 9, 2011 - 04:53

 

A working code can be found @stevenw.nl/Unit.zip, using SVN version 342, modified classes only. (Sorry, the anti-spamfilter on this forum thinks I am a spammer)

(no guarantee how long this file will stay online)

I have found some cases where inheritance will be dificult. In my suggestion, damage is calculated in the Unit class. This means.

 

  • Critical hits would not be player-only anymore. (Of course, we can make the crit-chance 0 for monsters)
  • Friendly fire would be possible.

 

  • Log in or register to post comments
Clint Bellanger
joined 13 years 6 months ago
Sunday, April 10, 2011 - 19:42
Clint Bellanger's picture

wokste,

Looks pretty good.  You kept it simple and that's always great.

Sometime this week I'll look at merging this Unit code in.  You, Bonbadil, and I all did some coding over the weekend and it can't be merged easily.

  • Log in or register to post comments
Alexey Petrushin
joined 11 years 9 months ago
Wednesday, June 1, 2011 - 13:42

It seems that this topic is not only about Inheritance but also about general development, checked today some dev stats of some open source projects, maybe You also would be interesting (only .h, .cpp files where counted):

 

project: stratagus files: 5107 lines: 2878685 characters: 60588962

project: spring    files: 1916 lines: 512323  characters: 12980590

project: btanks    files: 503  lines: 86704   characters: 9530445

project: glest     files: 311  lines: 49207   characters: 1092475

project: osare     files: 88   lines: 15139   characters: 297715 

 

About osare - In my point of view it's very good - to be able to do such a big work with a small amount of code.

  • Log in or register to post comments
Beast
joined 12 years 2 weeks ago
Wednesday, June 1, 2011 - 15:06
Beast's picture

It isn't really fair to compare full featured RTS engines with a halfway done action RPG engine.

  • Log in or register to post comments
Alexey Petrushin
joined 11 years 9 months ago
Wednesday, June 1, 2011 - 15:22

 

Hmm, maybe, and because of this I called it "some analytics", I didn't wrote something like Glest better than Spring because it's codebase is about ten times smaller.

 

It's definitely not an ultimate criteria, but at least some criteria. In my opinion the size of codebase is somethink like an agility of project - less code means easier to start, less to learn, less time spend on supporting and updating it and less bugs.

 

I personally did it to define how high is entry point for me in these projects.

 

  • Log in or register to post comments
Anonymous (not verified)
joined 0 sec ago
127.0.0.1
Wednesday, June 1, 2011 - 16:17

With same project order:

Average lines per file: 563, 267, 172, 158, 172

Average chars per file: 11864, 6775, 18947, 3513, 3383

You may be interested in % of comments, too.

  • Log in or register to post comments
Alexey Petrushin
joined 11 years 9 months ago
Monday, June 27, 2011 - 09:54

Cool article composition vs inheritance http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/

  • Log in or register to post comments
ircnet
joined 11 years 9 months ago
Thursday, July 7, 2011 - 09:38

Great article 

  • Log in or register to post comments