• 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
phiwer

Component Design in Component Based Game Engine

32 posts in this topic

In this design, there must be some way of iterating through entities that are contained within components, and to query these if they contain specific components. This suggests that there should be an interface on the components to support this behaviour. Or am I modeling this wrong?

 

Assuming there can be multiple parent-child relationships, then it sounds like your GetTotalGold function would need specific knowledge of the Village component (otherwise how would it know in which component to look for children?). That's not necessarily bad, and the Village component can still implement a child-iteration-interface (assuming the only children of a village are players). GetTotalGold could leverage a helper function that enumerates children for a specific component (as Zipster alluded to).

 

It's hard to offer concrete suggestions without knowing the full details of the game. But hopefully an entity/component framework makes it easy for you to adapt to new needs as you develop your game.

 

Some food for thought: off the top of my head, another implementation that doesn't require any parent/child stuff would be:

- It seems like villages are first-class concepts in your game. So it might make sense to have a VillageComponent that can be attached to an entity and that indicates which village it is associated with (and you don't necessarily need the big hierarchy with village entities with components that specify child players and child buildings, etc...). If it has no VillageComponent, then its off on its own.

- In that case, my GetTotalGold for a particular village would enumerate all entities that have a GoldComponent and VillageComponent. For each one that matches the specified village, add the gold to the running total.

- GetTotalGold for a single entity would just involve looking up the value in its GoldComponent.

(So basically I'm questioning whether I really need a "generic" GetTotalGold function)

 

This is a more database-y approach rather than OOP-y (perhaps a better fit with entity/component frameworks).

Edited by phil_t
0

Share this post


Link to post
Share on other sites

Some food for thought: off the top of my head, another implementation that doesn't require any parent/child stuff would be:
- It seems like villages are first-class concepts in your game. So it might make sense to have a VillageComponent that can be attached to an entity and that indicates which village it is associated with (and you don't necessarily need the big hierarchy with village entities with components that specify child players and child buildings, etc...). If it has no VillageComponent, then its off on its own.
- In that case, my GetTotalGold for a particular village would enumerate all entities that have a GoldComponent and VillageComponent. For each one that matches the specified village, add the gold to the running total.
- GetTotalGold for a single entity would just involve looking up the value in its GoldComponent.
(So basically I'm questioning whether I really need a "generic" GetTotalGold function)

 

FWIW, I like this approach better than having specific interfaces or components for parents/children.  I still think the components themselves should dictate whether they are parents or children.

 

And, to clarify, when i said "query an entity to see if it contains a certain type of component", I obviously didn't mean it holds it, but rather has some reference to another entity (via EntityId possibly).

0

Share this post


Link to post
Share on other sites

Some food for thought: off the top of my head, another implementation that doesn't require any parent/child stuff would be:

- It seems like villages are first-class concepts in your game. So it might make sense to have a VillageComponent that can be attached to an entity and that indicates which village it is associated with (and you don't necessarily need the big hierarchy with village entities with components that specify child players and child buildings, etc...). If it has no VillageComponent, then its off on its own.

- In that case, my GetTotalGold for a particular village would enumerate all entities that have a GoldComponent and VillageComponent. For each one that matches the specified village, add the gold to the running total.

- GetTotalGold for a single entity would just involve looking up the value in its GoldComponent.

(So basically I'm questioning whether I really need a "generic" GetTotalGold function)

 

This is a more database-y approach rather than OOP-y (perhaps a better fit with entity/component frameworks).

 

I like this approach as well, given that it "fits" entity/component better. I sometimes fall back into OOP thinking when modeling my entity/component system.

 

Would you share the same VillageComponent between Players and the actual Village entity, or would you suggest creating a different component with the sole task of explaining that a player is present in a village (e.g. PlayerInVillageComponent)?

0

Share this post


Link to post
Share on other sites

Just to clarify, components shouldn't "contain" entities in the traditional sense. All the entities in the game should exist together in a flat structure, and the components should only store IDs to entities (there was also a recent article series on decoupling that covered this subject in particular).

 

Now say I have a GoldSubsystem and there is a function GetTotalGold, which is suppose to compute all the gold for a specific entity and its children. So if I input a village I get all the gold in the village + all the gold of all the players. Nothing is static here, so sometime in the future I may decide to remove the GoldComponent from the village, but then I should still get the total gold of all the players in the village.
 
In this design, there must be some way of iterating through entities that are contained within components, and to query these if they contain specific components. This suggests that there should be an interface on the components to support this behaviour. Or am I modeling this wrong?

You have the right idea, we just need to have the interfaces in the right place.

 

For this example, you can have the WorldComponent implement the IParent interface (it can be the parent of both villages and players), the VillageComponent implement both the IParent and IChild interfaces (it can be both the child of the world and a parent of players), and the PlayerComponent implement the IChild interface (it can be the child of both the world and villages).

 

You then create a ParentChildSystem which acts only on the components that implement these interfaces. Given a root object (such as the world or a village), you find all components on that entity which implement IParent. At the point, you then find all components across all entities that implement IChild, and reference any of the root object's IParent IDs. You then find all the IParent's on this new set of entities, and the IChild's on other entities that reference them, etc. It's basically a breadth-first search. Once you have the list of entities, the GoldSystem can find all the GoldComponents and tally them up, without concerning itself with parent/child relationships or hierarchy (since that's the ParenChildSystem's job).

 

The biggest downside here is that the generalized interfaces, combined with a lack of forward references from parent to child, can lead to objects being included that you didn't want, and rather inefficient searches (note the "all components across all entities" part of the search). The best way to fix this is to simply add the child IDs directly to the IParent component, and have the system keep the IParent and the IChild components in sync, as phil_t mentioned a few posts ago. It's still a BFS, except now you're not doing searches across all entities and components. This doesn't necessarily fix the pruning problem, where objects you don't want are returned in the search. As previously mentioned, there are different types of parent/child relationships, and you might only care about specific ones when doing certain searches. For instance, when counting gold, you probably don't want to consider objects that are just physically attached to the player or village, but perhaps objects that are actually "owned" by them. In that case, the interfaces can also expose what kind of relationship they are, and the search can prune them based on that.

 

If you want, you can also dispense with the interfaces altogether and have the GoldSystem know precisely which component types (i.e. WorldComponent, VillageComponent, PlayerComponent) it needs to query, as well as their exact relationships. For a small game this is the easiest approach, except you might find that some code gets duplicated as multiple systems end up querying the same parent/child hierarchies, since there is no interface type upon which to build a generalized solution.

 

Interesting articles!

 

And yes, searching in general when using an EC system seems to be one issue I will have to look into, if I want it to be handle many players. Thanks for the tips!

0

Share this post


Link to post
Share on other sites

Would you share the same VillageComponent between Players and the actual Village entity, or would you suggest creating a different component with the sole task of explaining that a player is present in a village (e.g. PlayerInVillageComponent)?

 

I would question the need for a "Village entity" ;-). What would this entity exist for?

 

"task of explaining that a player is present in a village"  -> I wouldn't make a different component for this. But I don't really know what this is. Is this a blob of text that pops up whenever a player enters a village?

0

Share this post


Link to post
Share on other sites

Would you share the same VillageComponent between Players and the actual Village entity, or would you suggest creating a different component with the sole task of explaining that a player is present in a village (e.g. PlayerInVillageComponent)?

 

I would question the need for a "Village entity" ;-). What would this entity exist for?

 

"task of explaining that a player is present in a village"  -> I wouldn't make a different component for this. But I don't really know what this is. Is this a blob of text that pops up whenever a player enters a village?

 

No villages are more important than just describing if a player is present or not, that was why I thought they would make good entities. :)

 

Let's make the assumption that a village is something that ought to be an entity just for sake of argument. Then having a duplicate village component doesn't seem optimal, but if it's there only describe a position of the player, then I'd understand your point of not having it be an entity. Was this your point as well?

0

Share this post


Link to post
Share on other sites

Let's make the assumption that a village is something that ought to be an entity just for sake of argument. Then having a duplicate village component doesn't seem optimal, but if it's there only describe a position of the player, then I'd understand your point of not having it be an entity. Was this your point as well?

 

I think my point was just to reconsider whether it needs to be an entity (since it doesn't necessarily need lists of children buildings and players).

 

But if there are other attributes it has (such as... I dunno... name? population limit? ), then it can make sense to be an entity. In that case maybe I would have a VillageDescriptorComponent for the village entities (containing all the innate info about the village), and a VillageIdentifierComponent to identify things that are in that village (and perhaps the village entity itself would have one of these too).

 

What sorts of "innate village data" do you think would be part of a VillageDescriptorComponent?

0

Share this post


Link to post
Share on other sites

Let's make the assumption that a village is something that ought to be an entity just for sake of argument. Then having a duplicate village component doesn't seem optimal, but if it's there only describe a position of the player, then I'd understand your point of not having it be an entity. Was this your point as well?

 

I think my point was just to reconsider whether it needs to be an entity (since it doesn't necessarily need lists of children buildings and players).

 

But if there are other attributes it has (such as... I dunno... name? population limit? ), then it can make sense to be an entity. In that case maybe I would have a VillageDescriptorComponent for the village entities (containing all the innate info about the village), and a VillageIdentifierComponent to identify things that are in that village (and perhaps the village entity itself would have one of these too).

 

What sorts of "innate village data" do you think would be part of a VillageDescriptorComponent?

 

Basically villages can fight one another, so some sort of track record would be needed (wins/losses etc). Also the current standing against other villages (bad standing/good standing etc), but this isn't really something that would be suitable for the VillageDescriptorComponent.

0

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