Jump to content

  • Log In with Google      Sign In   
  • Create Account


dublindan

Member Since 05 Oct 2002
Offline Last Active Feb 26 2014 05:48 AM
*****

Posts I've Made

In Topic: Anybody left from the 2003 crowd?

06 January 2014 - 09:39 PM

Does anybody remember the pink gang? Though that may have been 2004.

I had a different username in those days.

In Topic: The 'Thick Client' is dead...

17 September 2013 - 11:46 AM

In my experience, native clients are not dead, at least in some industries when it makes sense (eg visualisation heavy or processing heavy applications and applications where offline access is desired). I've seen plenty of desktop GUI applications been built in Qt. I haven't seen that much in Java lately, but I'm sure it exists. Mobile native apps are also very popular.

 

There is definitely a trend of things moving to web apps, but I don't think its over yet for thick clients. It will probably become ever-more niche though in the coming years.


In Topic: Composition heavy OOP vs pure entity component systems?

23 August 2012 - 11:39 AM

Don't be too philosophical: classification of objects and relations are only important in software design if they are actually used.

I was merely pointing out how composition has a better real world analogue than inheritance. An analogy to explain how is-a isn't as clear cut as it first seems. In most software, you are unlikely to require the flexibility of adding or removing components at runtime, but I feel that in games, having the ability to do so should you want to is a huge bonus and allows you to do cool things that would otherwise be hard. Ideally, the development kit would be able to bake entities that do not use the flexibility so you don't pay for it if its not used, but I see that as an optimisation (which should be done later). I think it rarely makes sense to hard code limitations into the very design.

Howitzer and MachineGun because the distinction cannot possibly matter, ever, because all code works with generic Weapon entities.

Sure - I would see them as being the one Gun or Weapon component and the differences between them are defined purely in a data-driven way: their attributes have different values. Data-driven design is certainly a very good thing.

Removing pieces of objects is also utterly uninteresting from a software design viewpoint, not only because we never ask whether the mutilated object "is-a" something

Sure - but I often see it driving a design. Often people start with "Well, X is-a Y, so I'll derive X from Y and..." while I think this is the wrong approach. Instead, I feel is-a is only useful in the sense of "does it provide the interface I need?" - think of it like duck typing. So, instead of trying to figure out if something is a type of something else or if it has a something else instead and then building an inheritance hierarchy from this, I feel a better approach is to compose all components rather than inheriting from them.

I used to like hardcore OO a number of years ago, but these days I find it has too many limitations, both in design (as I've been trying to articulate in this thread) and technically: eg, OO and concurrency/parallelism, OO and cache/memory friendliness etc. Therefore I nowadays prefer a functional-programming approach, though I still code in a style that I would consider somewhat OO - except that my entities are now compositions of components with little or no inheritance in sight - functional programming makes it easy to compose both data and functions. When I program in C++, I obviously do use classes and even inheritance, but I still like to design my programs with functional programming in mind and I find that it not only simplifies the design and makes it more flexible (in real life that flexibility often gets traded off for performance later when its apparent that having two components instead of one is 1) not required and 2) a performance issue), but it also makes it easier to support concurrency safely and to solve cache/memory issues - hell, that was one of the big goals of component entity systems after all.

but more importantly because the altered entity is either in a valid state or corrupt, according to the invariants and expectations that the code contains; nothing uncertain or ambiguous can happen.

Sure. This is a very important point, regardless of the design.

In Topic: Composition heavy OOP vs pure entity component systems?

22 August 2012 - 10:04 AM

LorenzoGatti has a point, that the Tank and Cannon example may not be a very good one here. In most cases having a distinct Cannon class is not necessary. For most use cases in games, you are breaking down the object into more parts than you need to.


Sure - you can always simplify and flatten things down if you like. I mean, on the other extreme, you could represent all Actors as the same class, have a bunch of flags represent the different things your Actor might want to do (canShoot, canFly, canCarryPerson, isPerson) and handle all the code in one place but vary the models or sprites or whatever visual data you have. Obviously a balance between the two extremes needs to be found and the question one needs to ask is what level of flexibility do you need and what data do each of your game systems need. If you have vehicles that drive with reasonably accurate physics (so any game where driving is a big focus), your physics engine might indeed simulate wheels and your game logic might indeed have an engine that handles how it drives (or at the least is a pure data container with all the properties representing the engine: power, weight, whatever) - the point, as I see it, of component entity systems is that the components can be simple data containers if that's all you need, or they can have systems with complex logic associated and components in themselves are extremely cheap (eg they could be allocated from a memory pool, they could be cache line aligned, the processing loop could prefetch...).

But that's besides the point I was implying in my previous post - obviously the example was a contrived one. The real point wasn't even specific to game programming, but rather that in my opinion composition is much more natural to inheritance in that with real world objects, entities can often be classified as many things (I'm a living thing, I'm human, I'm a programmer, whatever...) that are dependant on the entities state (either internal or external) and that entities are composed of many things. Also often removal of some of these things does not cause the entity to lose a is-a relationship, removal of other things might (but exactly which things may not be well defined - if I kept removing parts of my body, when do I stop being human?). Then I went and mentioned some ideas which could be used to take the concept even further.

I think that this idea is just as applicable in software outside of games too.

But obviously, as you imply, a balance must be struck to find the level of abstraction that best fits the problem space - but isn't this always the case, regardless of how the problem is being modeled (OO or otherwise)?

In Topic: Composition heavy OOP vs pure entity component systems?

22 August 2012 - 04:37 AM

On the topic of is-a vs has-a:


With the traditional inheritance-based approach, every entity must have at least one is-a relationship and zero or more has-a relationships.

So, if a Tank is composed of a Vehicle and a Cannon, is a Tank a Vehicle that has a Cannon, or is it a Cannon that has a Vehicle? Obviously the former, in this case, so lets go down to the next level.

A Vehicle is composed of a Chasis, some Wheels and an Engine. Is a Vehicle a Chasis that has Wheels and an Engine? Is it an Engine that has a Chasis and Wheels? Again, the former makes most sense, but at what point does a Chasis stop being a Vehicle? If it has no Wheels and no Engine (and so is basically a stationary frame), its hardly a Vehicle any more: "A vehicle is a mechanical means of conveyance, a carriage or transport."

So you could encode some rules into your class that ensures that a Vehicle always has an Engine and Wheels. But what if we want a Plane? A Boat? A HotAirBalloon?

Through the use of additional layers of abstraction and complicated inheritance hierarchies it is possible to come up with a structure that allows this kind of flexibility (A Vehilce is a Chasis that has a PropulsionSystem, A PropulsionSystem is a... whatever, through additional layers in the hierarchy, eventually we can encode what we need), but at the cost of significant complexity (and complexity = bugs, often!) and work and god forbid something needs to change later!

The alternative is to introduce an abstract "is a" which we will call an entity. An entity consists of (is composed of, has a) a number of components. Components are generally self contained.

So a Tank is an entity and that entity consists of a Chasis, an Engine, Wheels (or Tracks), a Cannon...
A Plane is an entity which consists of a Chasis, JetEngine, Wings....
A HotAirBalloon is an entity which consists of a Basket and a Balloon...

The rules of what makes a Vehicle a vehicle or a Tank a tank (or a Tank a Vehicle) are now longer hard coded into a class, but instead is now coded into the constructor function of that entity: make_tank(...) contains all the code to make sure that the entity it creates adheres to the interface required for a tank or a vehicle or a weapon or whatever else that entity should be. It is this interface which defines the is-a relationship. Duck typing, if you will.

The concept could be expanded to allow entities to be derived: a Tank is a Vehicle entity with a Cannon component (and its basically a union of the set of components that make up a Vehicle and the set of components that make up a Cannon - each component could itself be treated as an entity which contains only itself in its set, so if later Cannon consists of a Turret and FiringMechanism, the definition of Tank need not change). But you should also be able to swap components out: A Tank = Vehicle ∪ Cannon ∪ Tracks ∩ Wheels.

Finally, the concept could be extended to allow interfaces (similar to Java interfaces, but that are implemented by the union of the components in the set that makes up the entity - again, duck typing). That is, IVehicle is an interface through which you can interact with vehicles. It doesn't care how the vehicle is a vehicle as long as it acts like one (ie it has the IVehicle interface). It could meet this interface by composing the Engine and Wheel and Chasis components or through Basket and Balloon or whatever you want.

I feel that is a is an abstract concept that describes the union of all the has a parts - a set of interfaces (a Tank is a IVehicle and a IWeapon for example) that describes what the set of components (ie entity) represents and I feel this is more true to real life than inheritance hierarchies, which don't seem very natural (from a real live POV) to me at all.

PARTNERS