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

Another Component Entity System Question

6 posts in this topic

Hi All,

 

After reading the abundance of message's recently about the subject, it got me interested in researching into it. Al tough I feel that I understand the theory behind it, there are a few conflicting ideas in articles and question I have, and am hoping someone can help me with.

 

In relation to the article I read on GameDev http://www.gamedev.net/page/resources/_/technical/game-programming/implementing-component-entity-systems-r3382 I have implemented a small demo using this, but am unsure if i'm going in the right direction.

 

In the article things are defined as Position[Entity_MAX], Velocity[Entity_MAX], Appearance[Entity_MAX].

When an entity is created, it returns an unsigned int, which I take to go across all arrays - for example the first entity that is created has a position and a velocity which is Position[0], Velocity[0], if a static item was then added it would be Position[1] and Appearance[1]. 

 

My real confusion is of the empty space ( if my understanding of how it all ties together is correct ) If I have many components created in this way - for example 50, and the majority of my entity's only use one or two of these components at a time - will that not just waste a wide range of space? - or is this acceptable because of the cache speed increase?

 

Alternately, am I just creating the Components in the wrong way? While using the technique he shows for the mask, I run into a problem.

 

My code at the minute, when being used to move and render is as below

World    = new s_World;
	
CreateDynamicObject( World, 0.0f, 0.0f, 0.0001f, 0.0001f ); // xPos, yPos, xVel, yVel

Graphics = new cGraphics();
Physics  = new cPhysics();
void cGame::Render() {

        glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT );

	Physics->Update( World );

	Graphics->Render( World );
}
void cGraphics::Render( s_World *World ) {

     for( int entity = 0; entity < ENTITY_MAX; entity++ ) {

          if( (World->mask[entity] & STATIC_MASK) == STATIC_MASK) {
               // Render Code
          }
      }
}
 
 
Using this method, if the mask is a STATIC_MASK, it will render it - but if I also want it to render dynamic, do i just add another if statment, and another mask, and so on and so on until I have every scenario that needs to be rendered / Anything else i want to do
 
Im sure some of these questions about masks and things are going over peoples heads that have not actually read the article. But im hoping that someone with experience using a similar system can help me out.
 
Please let me know if I need to clarify this post more ;)
 
Any information / insight would be appreciated
David
Edited by McGrane
0

Share this post


Link to post
Share on other sites

Na, the point of the masks is so that you don't have to care what type of object it is. Don't render based on if your object is static of dynamic, but rather, render if it fits the requirements of being rendered.

 

something like this:

unsigned STATIC_MASK = POSITION | IMAGE;
unsigned DYNAMIC_MASK = VELOCITY | POSITION | IMAGE;
void cGraphics::Render( s_World *World ) {
 
for( int entity = 0; entity < ENTITY_MAX; entity++ ) {
unsigned mask = World->mask[entity];
if( (mask & POSITION) && (mask & IMAGE)) {
// Render Code
// this should render both static and dynamic objects
}
}
}
Edited by ultramailman
1

Share this post


Link to post
Share on other sites

Ok i see where i was confused now, need to look up on my bit wise anding :) When i broke down your code, and thought about it it made a lot more sense, Thanks ultramailman ;)
With that said, am i right in thinking that your if statement is slightly incorrect. By anding any statement with any component, they would be true.

So the if statment would be if( true && true ) render all

Im guessing it should be if( ( mask & position ) == position )

 

As for my other question, am I correct in thinking that if i had 100 components, and a particular entity - like Static above - uses only 3, that all 97 other components are just left blank?

 

Thanks for the Help ! 

0

Share this post


Link to post
Share on other sites


With that said, am i right in thinking that your if statement is slightly incorrect. By anding any statement with any component, they would be true.
So the if statment would be if( true && true ) render all
Im guessing it should be if( ( mask & position ) == position )

 

Assuming POSITON and IMAGE are just single bits, if an entity were missing POSITION, then (mask & POSITION) should be 0, and so his if statement would evaluate to:

if (false && true)

and would not be executed.

 

A better way to write it though (one less comparison), is like this:

if ((mask & (POSITION | IMAGE)) == (POSITION | IMAGE))

1

Share this post


Link to post
Share on other sites

Thanks for the reply phil. In fact, going in line with the article (which i probably should have cleared up a little)

Position is     0001

Velocity is      0010

Appearance is 0100

 

Static_Mask is ( Position | Appearance ) or 0101

Dynamic_Mask is ( Position | Velocity | Appearance ) or 0111

 

if( (mask & POSITION) && (mask & IMAGE)) -  would be (assuming static mask ) - if( (0001) && (0100))

 

Thanks for the suggestion on "if ((mask & (POSITION | IMAGE)) == (POSITION | IMAGE))" but i think now with the clarity of how the masks are defined (if i understand it correctly ) the statement i wrote for " if( ( mask & position ) == position ) " Would work properly, if using either a StaticMask( 0101 ) or Dynamic Mask (0111) and anding it with position (0001), would prove true for both cases. I think your method runs on the same idea, but with the image added in, which i was no including as i was using it elsewhere on another system that handles rendering.

 

Thanks,

David 

0

Share this post


Link to post
Share on other sites

Ok i see where i was confused now, need to look up on my bit wise anding :) When i broke down your code, and thought about it it made a lot more sense, Thanks ultramailman ;)
With that said, am i right in thinking that your if statement is slightly incorrect. By anding any statement with any component, they would be true.
So the if statment would be if( true && true ) render all
Im guessing it should be if( ( mask & position ) == position )
 
As for my other question, am I correct in thinking that if i had 100 components, and a particular entity - like Static above - uses only 3, that all 97 other components are just left blank?
 
Thanks for the Help !

You are right, it wouldnt work if position and image have more than one bit set. But they ate probabably single bit masks, unless you want to have x and y component separate for position, for example.
And yes, the other 97 component arrays would be left undefined. So far, I have 15 components in a game I'm working on, so I dont know what impact will 100 components have.
1

Share this post


Link to post
Share on other sites

Ok great, thanks !

I'm sure the impact would be minimal, i mostly only wanted to verify that i was doing it correctly, it seems a little wasteful, but like im sure the cache speedup will outweigh this. I've been in work all day - so have not been able to try any of this out, so looking forward to getting back at it :)

 

Also i just realised that when speaking above about the seperation of image and position, that in fact in the example i have given was about rendering, so what i meant in the above comment is that my position is handled elsewhere ;)

 

Thanks for the help guys.. 

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