Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (7th_zorro, henrybane, AndrewAMD), 1,343 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19053 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Scene node/entity/game object design #437422
02/16/14 16:41
02/16/14 16:41
Joined: Nov 2008
Posts: 946
T
the_clown Offline OP
User
the_clown  Offline OP
User
T

Joined: Nov 2008
Posts: 946
As there is no subforum for topics about technical non-acknex related discussions, I figured this would be the most fitting one.

This topic will mostly interest people who are not actively using acknex as their main development kit but rather do things from scratch using lower level APIs, however I think there's enough of those around here that this won't end up being totally pointless.
Let's say you are writing a game more or less from scratch, using some low level graphics API (possibly with a high level abstraction layer on top) and C++ or any other object oriented programming language, and are about to implement an entity system for said game. It is to note that the game is more or less tightly specified, meaning you're not going to create a multiple-purpose engine, but rather exactly what the given game concept needs to work.

Basically, I'm trying to work out which of the following two patterns fits this situation best:

a) A component based design. Every object in the game is an instance of a fairly generic class, call it sceneNode or gameObject, whatever you want. Each of these objects has a list of "components", meaning instances of subclasses of a generic class component. Each component adds an attribute or part of a behaviour to the game object, for instance a light, an animation tree, you name it.
Unity users will know this pattern very well.

b) A more classical inheritance based pattern: There is a class that all game objects inherit from, again, call it gameObject or something like that.
This class does not much but providing data fields for some generic properties such as position, orientation and scale.
Inheritance is now used to create new kinds of gameObjects, for example a lightObject class may add data fields and functionality needed to represent, well, a light, a meshObject may contain everything needed to display an arbitary mesh with a given material, etc.
This should ring a bell for two young programmers who recently revealed their new game engine in these forums.

Now, given the situation described above - a relatively tight specification for a game, no intend to create a multi-use solution - what would be the best route to go?
I recognize the component based design offers a LOT of flexibility, however I didn't like it AT ALL when using Unity, perhabs because I've used acknex for so long, but also because it involves a lot of message passing between objects and other little twists that come just kind of unituitive for me.
Plus, I really like the concepts of inheritance, however, one might argue that in game development context, inheritance may turn out inflexible and require a lot of work for little changes as soon as classes get more complex.

After all this blabla, what I basically wanted to start off with this is a little discussion about the two designs, based on the idea of implementing a GAME with it, not a multi-purpose engine. I know at least three people here who might have something to contribute to this, but I'm curious how many opinions on this I might get.

Re: Scene node/entity/game object design [Re: the_clown] #437455
02/17/14 12:27
02/17/14 12:27
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: the_clown
This should ring a bell for two young programmers who recently revealed their new game engine in these forums.

Who are you calling young, punk?!

No, seriously though, this is a really really interesting topic, and something that most people don't value enough: For the reason that it's decided above their head and they are just presented with the finished API.

I think that there is no silver bullet here, as with so many other things. Both systems have their advantage and disadvantages, for example: A component based design is incredibly flexible with just a few, well defined objects, but it can become really complex really fast. On the other hand, an inheritance based system is less flexible and may end up resulting in awkward inheritance graphs.

This being said, if you just create a game and no general purpose API or engine, you should pick the one that is the easiest to work with in terms of your game. This is whole other level of things to keep in mind, because the requirements to build one specialized game and a general purpose game engine are vastly different. And don't think too much about code re-usage across games: Yes, there is a basic toolset that you will re-use over and over again, but the core game itself will be uniquely tailored and trying to make it as general purpose as possible is just making it more complicated in some extents.

Coming from the other direction, the general purpose game engine, I think a hybrid approach is the way to go. It's also implemented that way in a game engine currently developed by two young programmers. The thing is that components make a lot of sense for things like physics. Being able to attach a rigid body as a component to a scene node is so useful, because otherwise, you would've to provide an extra scene node for rigid bodies. But what happens if you want to inherit other behaviour as well? Diamond shaped inheritance graphs are not common and in most languages impossible. C++ offers virtual inheritance and it really isn't that much of a problem as most people tend to make it out to be, but it makes for even more ridiculous inheritance graphs and it's just a hassle.

Having well defined scene nodes is a good thing though. Take a scene node for water for example: That doesn't need to render an arbitrary mesh or model. It doesn't need to cast light, it's a scene node that renders water. Period. Same with particle emitters, really. It may make sense to attach particles to something else, but this can be done by simply adding the particles as childs to the other scene node, ie, representing their relationship via the scene graph.

To stick with the rigid body/physics example, this isn't that easy to express using a scene node based system. The water for example may want to provide physics behaviour, or the entity may want to have a rigid body. You can't just attach them as child scene nodes, because their relationship can't be expressed that way: Childs are moved through the scene relative to their parents, not the other way around. Here is where a component based system makes the most sense, because you can just attach these things as additional components/attributes to scene nodes.

Here is an example that is going to look a lot like Unity, but it helps to bring the point across:
Code:
RN::Entity *entity = ...; 
RN::bullet::RigidBody *body = entity->GetAttachment<RN::bullet::RigidBody>();

body->ApplyImpulse(RN::Vector3(10.0f, 0.0, 0.0f));



Instead of applying the impulse directly to the entity, it's applied to the rigid body that's attached to the entity. The entity may be anywhere in the scene graph, it will still work the same way, and it doesn't require an extra subclass. How would that even look like? A rigid body class that inherits from entity? What about cases where you don't want to inherit from entity but still have a rigid body?

The hybrid approach tries to combine the best of both worlds, things where it is an obvious parent -> child relationship (a blood particle effect for example, that's the child of a damaged entity) can be expressed using the scene graph and inheritance, no problem. The other way around, where a child (which isn't really a child but more of a property) affects the parent, that can be expressed using components.

The difference is that scene nodes and childs appear in the scene graph, whereas components are merely additional properties to a given scene node.

Well, those are my 2 cents anyways. Take them as you will laugh
PS: 3333 posts!


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com

Moderated by  checkbutton, mk_1 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1