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

Component design and game class design

8 posts in this topic

So I am trying to implement a component design and I am currently unsure if I am implemented it effectively or correctly.

My classes and their children are as follow:
 

1. MainGame

2. VideoManager

3. EntityManager

4. Entity

             |---6. InputComponent  |---8. CharacterInputComponent
5. Component |
             |---7. RenderComponent |---9. CharacterRenderComponent

10. SmartList

1. So the main game class holds function for initializing, running, and terminating the game. It also has a pointer to the various managers( more will be added for like sounds or resources ) which manage more specialized parts of the game.

2. The video manager has collection of the shaders, the projection and view matrices, etc.. all for handling the drawing commands.

3. The entity manager has a list of all entities that are in the world and knows to update them if need be( drawing, input, etc. ). The list is my SmartList.

4. The entity has a list of components that are linked to it. These components give all functionality to the entity other than the basics. It operates kind of like a unique component manager.

5. This is a base class that only really defines a function( update call ) used by all components and the unique string id of all components( for use in my smart list ).

6 & 7. These are specialized components that have specific roles, one for rendering and one for input. More will inevitably be made.

8 & 9. These would be the actual components that I would link to my entities since they implement the functions more specifically.

10. It's my own template class that can store and sort through all the objects. It uses double pointers and a binary search to look up things and a merge sort to keep everything in order. Memory is automatically allocated as the list grows/shrinks in exponents of 2. Through template classes and function pointers I can use this for any value and sort by any value such is integers, strings( as for my use ), or even complicated sets of data with specialized comparison.

Now here is how the flow of a input and render call.

//Draw a single scene and starts in the main game loop
MainGame -> VideoManager -> EntityManager -> Entity -> RenderComponent


//Input detected
GLFWCallback -> EntityManager -> Entity -> InputComponent

Here is my main.cpp and how it starts/run the game + making entities and components.


#include "GameClass.h"
#include "EntityManager.h"
#include "Entity.h"
#include "components/InputComponent.h"
#include "components/RenderComponent.h"

#include "Logger.h"

using namespace std;

struct MyInputComponent : public InputComponent
{
    void KeyPressed( int iKey, int iAction )
    {
        if( iKey == GLFW_KEY_ESCAPE && iAction == GLFW_PRESS )
        {
            GameClass::GetGameInstance()->EndGame();
        }
    }
};

int main( int argc, char* argv[] )
{

    GameClass* pGame = GameClass::GetGameInstance();

    if( !pGame->InitGame( 640, 480, 640, 480, "My Game" ) )
    {
        Logger::Log( "", "Couldn't initialize game." );
        return 1;
    }

    EntityManager* pEntityManager = pGame->GetEntityManager();

    MyInputComponent* c = new MyInputComponent();
    b->SetComponentName( "InputComponent Dude" );

    Entity* a = new Entity();
    a->SetEntityName( "EntityA" );

    Entity* b = new Entity();
    b->SetEntityName( "EntityB" );

    pEntityManager->AddEntity( a );
    pEntityManager->AddEntity( b );

    b->BindComponent( c );

    pEntityManager->RemoveEntity( pEntityManager->LookUpEntity( "EntityA" ) );

    pEngine->RunEngine();

    pEngine->TerminateEngine();

    delete a;
    delete b;
    delete c;

    return 0;
}

I'm also trying to do my best to stop decoupling. For example my VideoManager shouldn't need to know about entities or components hence why the flow chart goes in such steps, but I am worried it's adding extra overhead.

This is my first time working a larger project. I would like some suggestions or notable problems with my design so I can refactor my code. I usually develop for a while, assess all issues, and rebuild it from scratch more streamlined, but my limited experience doesn't make it easy to assess everything completely.

Edited by PandaDragonThing
0

Share this post


Link to post
Share on other sites

Why do you have an InputComponent and a CharacterInputComponent?  Same with the RenderComponent.

 

You should have an InputComponent and a RenderComponent, that's it.  The InputComponent would be used by a system that has the InputComponent as a requirement (typically would also require a CharacterComponent).

 

RenderComponent would hold the graphical information for an entity and what is to be drawn;  you shouldn't have different kind of render components.

 

You need to get OOP out of your mind.  Outside of a Base Component class or base SystemClass, you probably shouldn't be using any OOP inheritance.  Do some more reading if you would like.  My Journal (in my sig) I have some articles about ECS.

 

Good luck!

0

Share this post


Link to post
Share on other sites

Why do you have an InputComponent and a CharacterInputComponent?  Same with the RenderComponent.

 

You should have an InputComponent and a RenderComponent, that's it.  The InputComponent would be used by a system that has the InputComponent as a requirement (typically would also require a CharacterComponent).

 

RenderComponent would hold the graphical information for an entity and what is to be drawn;  you shouldn't have different kind of render components.

 

You need to get OOP out of your mind.  Outside of a Base Component class or base SystemClass, you probably shouldn't be using any OOP inheritance.  Do some more reading if you would like.  My Journal (in my sig) I have some articles about ECS.

 

Good luck!

 

Ah thanks. That's a good point and something I kind of skipped because I wasn't sure which route was best. What would be the best way, for example, to add input for components? I think, but am not sure, that I can use a callback function and pass a function pointer into my main engine that would handle all input. That callback function would have parameters for component names and the key/mouse information. Then as the game changes states( main menu to actual game play ), I can change the pointer to the relevant function.

0

Share this post


Link to post
Share on other sites

 

...

 

Ah thanks. That's a good point and something I kind of skipped because I wasn't sure which route was best. What would be the best way, for example, to add input for components? I think, but am not sure, that I can use a callback function and pass a function pointer into my main engine that would handle all input. That callback function would have parameters for component names and the key/mouse information. Then as the game changes states( main menu to actual game play ), I can change the pointer to the relevant function.

 

 

No, you can accomplish this multiple ways.

 

If you're using components which only data, then as I mentioned before, the InputComponent would be used by a system that has the InputComponent as a requirement (typically would also require a CharacterComponent).  You could call it CharacterController, and in it's update function, you'd simply check what buttons are pressed from the InputComponent.

 

If your components also handle logic (not how I would approach this), then you would have the character component register for messages from the input component within the same entitiy.  Then, the Input Component would send messages every Update when buttons are being pressed.

0

Share this post


Link to post
Share on other sites


You need to get OOP out of your mind.

 

Is this mainly because to avoid bad design when programming the game? I actually found myself using mostly composition. 

0

Share this post


Link to post
Share on other sites

 


You need to get OOP out of your mind.

 

Is this mainly because to avoid bad design when programming the game? I actually found myself using mostly composition. 

 

If you're programming a game using ECS, you need to stop trying to build entities using inheritance, but rather composition.  It was in response to the OP's design of having an CharacterInputComponent inherit form an InputComponent (I'm OK with having a base Component class).

0

Share this post


Link to post
Share on other sites

 

 


You need to get OOP out of your mind.

 

Is this mainly because to avoid bad design when programming the game? I actually found myself using mostly composition. 

 

If you're programming a game using ECS, you need to stop trying to build entities using inheritance, but rather composition.  It was in response to the OP's design of having an CharacterInputComponent inherit form an InputComponent (I'm OK with having a base Component class).

 

Sorry. Those inherited classes weren't meant to be there. It was a short term solution so I could do some testing of functionality.

0

Share this post


Link to post
Share on other sites

You need to get OOP out of your mind.

Is this mainly because to avoid bad design when programming the game? I actually found myself using mostly composition.
If you're programming a game using ECS, you need to stop trying to build entities using inheritance, but rather composition.  It was in response to the OP's design of having an CharacterInputComponent inherit form an InputComponent (I'm OK with having a base Component class).

Just for the record -- if you're writing OO code, then you should already be using composition over inheritance 99% of the time. Use of inheritance should be extremely rare compared to the use of composition in OOP.
 
If you're going from OO-inheritance-based code to ECS-composition-based code, then you've actually just skipped learning traditional OOP in the middle of that transition cool.png

1

Share this post


Link to post
Share on other sites

You need to get OOP out of your mind.

 

That isn't necessarily true.  There is nothing wrong with applying OOP concepts to a component hierarchy.  For example, it isn't uncommon to see a ColliderComponent that is derived from a Component and then have various implementations such as BoxCollider, SphereCollider, MeshCollider, and CapsuleCollider which are derived classes of the ColliderComponent.  Shallow hierarchies are fine if they are well contained within the scope of a specific feature. 

 

I do agree that perhaps Input should be a single component.  It can be influenced by some AIController, CharacterController, or NetworkController, all of which might be a subclass of Controller.  As for the renderables, I believe it all depends on the engine.  If your lights, planes, meshes, and other render system specific exposed objects share any common ground with one another, having a base renderable class doesn't present an issue.  

 

As long as the hierarchy is kept shallow, it OOP works quite well.

Edited by crancran
2

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