• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Midori Ryuu

Composition heavy OOP vs pure entity component systems?

31 posts in this topic

I would like to say this is a great topic so far, with lots and lots of info contained and a lot of opinions. I was wondering if this is a good example of what would be a good entity architecture so that I see if I should go ahead with it or not: http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-1/
http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-2-the-state-pattern/
0

Share this post


Link to post
Share on other sites
[quote name='Gabriel Grom' timestamp='1345830128' post='4973051']
I would like to say this is a great topic so far, with lots and lots of info contained and a lot of opinions. I was wondering if this is a good example of what would be a good entity architecture so that I see if I should go ahead with it or not: [url="http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-1/"]http://obviam.net/in...ategies-part-1/[/url]
[url="http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-2-the-state-pattern/"]http://obviam.net/in...-state-pattern/[/url]
[/quote]

Gabriel, that's kind of the beginning of the idea of Composition, but it's only partial IMO. It limits some because, what if you have a droid that you can ride on? Is it a droid? or a vehicle?

Using a true entity/component system, it can be both easily. Instead of having a is-a droid relation ship, and it would go into the droid list, you have a generic entity, built with a graphics component, physics component, droid component, and weapon component.

Then you have systems that act on these components. ie, the droid system handle entities with the droid component, and it handles the AI and movement (depending if droid component was built with wheels or track, or nothing), as well as attempting to shoot it's weapon.

If you add a vehicle component, then the vehicle system can work on that entity, and allows a player to ride on the droid, and shoot from the back of the droid.

That's the general idea. My dev journal has some articles about it, and there's plenty of other data too.
0

Share this post


Link to post
Share on other sites
[quote name='BeerNutts' timestamp='1345834335' post='4973075']
[quote name='Gabriel Grom' timestamp='1345830128' post='4973051']
I would like to say this is a great topic so far, with lots and lots of info contained and a lot of opinions. I was wondering if this is a good example of what would be a good entity architecture so that I see if I should go ahead with it or not: [url="http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-1/"]http://obviam.net/in...ategies-part-1/[/url]
[url="http://obviam.net/index.php/design-in-game-entities-object-composition-strategies-part-2-the-state-pattern/"]http://obviam.net/in...-state-pattern/[/url]
[/quote]

Gabriel, that's kind of the beginning of the idea of Composition, but it's only partial IMO. It limits some because, what if you have a droid that you can ride on? Is it a droid? or a vehicle?

Using a true entity/component system, it can be both easily. Instead of having a is-a droid relation ship, and it would go into the droid list, you have a generic entity, built with a graphics component, physics component, droid component, and weapon component.

Then you have systems that act on these components. ie, the droid system handle entities with the droid component, and it handles the AI and movement (depending if droid component was built with wheels or track, or nothing), as well as attempting to shoot it's weapon.

If you add a vehicle component, then the vehicle system can work on that entity, and allows a player to ride on the droid, and shoot from the back of the droid.

That's the general idea. My dev journal has some articles about it, and there's plenty of other data too.
[/quote]

Hey BeerNutts!

You make a good point. I might be missing the actual point though, but wouldn't just adding a Riding component solve the problem?

The reason why I feel the need to have predefined entities, and also to have tightly coupled components, such as for example the texture and rendering component, or the collision and movement component, like some people here mentioned is because of the two concepts I'm having trouble with, which are the layering of the game that Hodgman and Ryuu talked about, as well as inter component communication.

Also I'm having trouble with how I will differentiate between entities, such as player and AI or vehicle and person.

Things like updating the components also come to mind. Should I make a system for each type of component that updates the components of the same type, in which case should l iterate the types in order? For example iterate over the physics components and update them first, after which I iterate over the rendering components?

What I mean by that, and most of the above is, let's say that there is a vehicle or droid which players can ride. How will I be able to differentiate the players from the other vehicle components such as the collision component? If things are made as generic as you say, and perhaps here I misunderstood you, in that I understood you said that we should make the entities only have a reference to the generic Component class, rather than manually hardcode that a vehicle will have armor, characters, wheels so as to gain maximum flexibility.

If it is hardcoded, then the vehicle will be able to directly manage the characters' updates. What I have in mind is, that when a character is added to a vehicle, the player's control, or that of the AI is stripped, and given to the vehicle, which in turn has a controller, player or AI. I would have addCharacter() method in the vehicle entity or in the Riding component which will do what I just described.

If however, the vehicle only knows generic components, and vehicle is generic in its self, then how will I be able to know that the component being added is a character, and how will I know that the vehicle has a Riding component? Don't get me wrong, I'm not asking how to do those things, but the solution I am imagining in my head entails a lot of boilerplate and messy code, which is essentially a massive Component class to accommodate for every possible action or scenario in the game.

[CODE]
public void addComponent(Component Receiving, Component Attaching)
{
......
if(Receiving.has(RidingComponent)
if(Attaching.is(CharacterComponent)
RidingComponent.addComponent(Attaching, type CharacterComponenet);
.........
}
[/CODE]

And that's just a small snippet of the method, where other lines would test for rendering, collision, animation, etc...

My opinion is that for small-medium sized games, something akin to say.. the size of Warcraft 2 or Red Alert like game, over-engineering by going completely generic and flexible at the cost of code complexity does not really pay off.

Then again I've never done a component system before. Edited by Gabriel Grom
0

Share this post


Link to post
Share on other sites
[quote name='Gabriel Grom' timestamp='1345840588' post='4973112']
If however, the vehicle only knows generic components, and vehicle is generic in its self, then how will I be able to know that the component being added is a character, and how will I know that the vehicle has a Riding component? Don't get me wrong, I'm not asking how to do those things, but the solution I am imagining in my head entails a lot of boilerplate and messy code, which is essentially a massive Component class to accommodate for every possible action or scenario in the game.
[/quote]

If components know about their owners, then you can move their dependency tests to be inside of them. Say with a method, Component::Attach(Entity), that tests the entity to which this component is being attached for dependencies and does whatever other magic it wants to do. If components do not know about their owners, you can move that logic to be external from the Component class with a free function, like AddCharacter(Entity), that executes your dependency tests and such. Alternatively, you could go more data driven, and define the relationships between components in some softer format, like ComponentAttacher::DefineConstraint(Component receiving, Component attaching, function constraint), and then make all of your connections through ComponentAttacher.

No matter what though, such logic definitely does not go in the base component.
0

Share this post


Link to post
Share on other sites
[quote name='Gabriel Grom' timestamp='1345840588' post='4973112'][CODE]public void addComponent(Component Receiving, Component Attaching)
{
......
if(Receiving.has(RidingComponent)
if(Attaching.is(CharacterComponent)
RidingComponent.addComponent(Attaching, type CharacterComponenet);
.........
}
[/CODE][/quote]I personally group "component/entity" designs into two categories -- those that try and perform "magic" linking of components to each other, and those that require the entity creator to manually connect components to each other.
[code]class MyEntity
{
ComponentA a = new ComponentA();
ComponentB b = new ComponentB();
ComponentC c = new ComponentC();
void Init_1()
{
a.InspectParentToPerformMagicLinking( this );//uses reflection to look at my members
b.InspectParentToPerformMagicLinking( this );// to automatically make any required connections
c.InspectParentToPerformMagicLinking( this );// without my explicit knowledge of how this works
}
void Init_2()
{
a.ExplictlyLinkYouToC( c );//I, the entity author, know that A needs a C.
b.ExplicitlyLinkYouToA( a );// and that B needs an A.
}
};[/code]IMHO, the first option violates too much of my deeply ingrained engineering intuition to be considered. Explicitly plugging things in seems superior in almost every way to me... Ideally these explicit links, and the entity data-structures themselves should be loaded from data/scripts, but can be hard-coded as above.
[quote]Also I'm having trouble with how I will differentiate between entities, such as player and AI or vehicle and person.[/quote]If you need to differentiate between them, don't put them all in some generic collection ([i]also don't inherit them from a common base if they don't need it[/i]). Am I right in paraphrasing that this is the same as: "[i]I've inherited vastly different classes from a common base, but now I can't use them for different purposes[/i]"? If so, it's the same flaw that entity inheritance-trees had.
Put vehicles in a vehicle-list, and players in a player-list, if needed.[quote]we should make the entities only have a reference to the generic Component class[/quote]I've seen designs such as this, but IMHO it's a harmful idea. Imagine replacing all of your [font=courier new,courier,monospace]floats[/font], [font=courier new,courier,monospace]int[/font]s, [font=courier new,courier,monospace]Array[/font]s, etc, with [font=courier new,courier,monospace]object[/font]... and then having to use casts absolutely everywhere. It defeats the purpose of having a type system.[quote]If it is hardcoded, then the vehicle will be able to directly manage the characters' updates. What I have in mind is, that when a character is added to a vehicle, the player's control, or that of the AI is stripped, and given to the vehicle, which in turn has a controller, player or AI. I would have addCharacter() method in the vehicle entity or in the Riding component which will do what I just described[/quote]N.B. as well as "hard-coding" these kinds of specific relationships in your C++/C#/Java etc codebase, it can also be "soft-coded" in your scripting language or data files. IMHO, this is much better than creating an over-engineered framework. Edited by Hodgman
1

Share this post


Link to post
Share on other sites
Hey all~ I am back after a somewhat long absence, as I've been busy acclimating into my new job. I wanted to update you guys who took the time to help me with what happened! (And I might hope for a little feedback for how right (or how less wrong) I did things.)

So, after some more search, I fell upon the Apollo entity framework. It is built by the same folks who has made the Artemis entity framework, but is more 'object-oriented' in its thinking. I fiddle around with it in the past couple of weeks, and I must say I really do prefer it a lot over Artemis, which I wasn't planning on using.

This on the other, I loved! I'm not using the platform in its entirety (yet), and I have made some modifications of my own to suit my programming taste (to the builders, etc..)

I have made a small, small demo where I integrated it with LibGDX and Box2D, and I have the code up on [url="https://github.com/Midori-Ryuu/Black-Horne"]Github[/url] for those who want to make me feel bad by telling me how bad it is. [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img]

My architecture is essentially having the Apollo world contain the Box2D world (though I keep a separate reference for the Box2D world for convenience).

I have a Renderable component, along with a collidable component. The collision component depends on the Renderable component, but for the time being only, and only for practicing/experimenting with things, but they should be completely independent, and only separately depend on the Transform component which holds the position.

I have a collision detection listener which doesn't itself act on the bodies, but triggers a flag in the Collidable component and forwards it the needed information to handle the collision (the other body, its type, etc..)

I haven't used the event listeners built into Apollo, so I cant' say anything about that, though I might use it later on. Sorry about that, Gabriel, but I hope I can still answer some of your questions in the code.

I'm using builders like Apollo recommends, though I have modified those to take several parameters. This broke the methods related to builders (which was rather convenient) but it's nothing fatal. (To those who made Apollo, my sincerest apologies for butchering your framework!!)

So yeah, that's pretty much it! Don't judge too harshly.~

I wonder if I should start my own game dev diary.. But I don't want to infect people with bad code. xD Edited by Midori Ryuu
0

Share this post


Link to post
Share on other sites
[quote name='Midori Ryuu' timestamp='1347296553' post='4978630']
I wonder if I should start my own game dev diary.. But I don't want to infect people with bad code. xD
[/quote]

well, i think you SHOULD start one. this way you will learn much more. don't be shy. there's no such thing as bad code, only code that has not been polished yet [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0