Results 1 to 9 of 9

Thread: Entity/Component Design (consider my mind blown)

  1. #1
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default Entity/Component Design (consider my mind blown)

    I know that MVC doesn't really have a good fit in game development, but what would you suggest in terms of organization and functions of Proton Entities and Components in a 3D game? I'm assuming there should be some separation between game logic, state, input and view, but how/where. Could you give us a few suggestions beyond the (really great) articles you have provided?

    I'm obviously new to component based game design, but I like the idea, despite the slight performance impact.

    Can't thank you enough for your work! Keep it up!

    Update: for those of you who haven't read it yet, check this out:

    http://www.rtsoft.com/wiki/doku.php?id=proton_entity

    http://www.rtsoft.com/wiki/doku.php?...n_entity_part2
    Last edited by BigBMan; 01-12-2011 at 04:06 AM.

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Good questions. I'm still in the "feeling it out" stage myself and need to figure it out for my new game.

    If you look at RTLooneyLadders, a 2d 48 hour game, I decided to use Proton entities for everything to sort of see how it worked out.

    • Performance was fine, at least on iOS and Windows where I tested
    • Using ZoomToPositionOffsetEntity worked very well for enemy movement, going up ladders
    • The way I did player movement was bad, it breaks at very low FPS
    • I put all entities under the same parent entity, then called CallFunctionRecursively() on the parent when I needed to do something like tell them an explosion happened nearby
    • Input used ArcadeInputComponent which smoothly routed touchscreen and keyboard controls into the same VIRTUAL_KEY_* messages


    With 3d, one way would be to write a MeshRenderComponent and have it use "pos3d" (a vector3) for position instead of "pos2d" and render/load a single mesh.

    The 3d "p+ entity" tricks with movement and interpolation and sending messages to change the animation could all be made to work like the 2d versions.

    Or, maybe I will just use the above method for very simple 3d things and 3d menus and try to be 99% "hardcore Irrlicht" for the real game, as the RT3DApp examples sort of are now.

    It might make stealing code/tutorials easier that way.

    [/random musings]
    Seth A. Robinson
    Robinson Technologies

  3. #3
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default

    Yeah, I'm thinking of keeping the components light for a 3D app, but I was wondering how you'd structure/organize things like input controls, scene management, AI, physics, networking, game state (shared data model), etc. I guess all these things can be EntityComponents...

    The more I think of it, the more I like it ;o)

    So, my understanding is that Entities are really just a message passing encapsulation of Components and other Entities. Is that correct? Is it ever appropriate to create a custom Entity, or should everything be a component?
    Last edited by BigBMan; 01-12-2011 at 04:08 AM.

  4. #4
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default

    So, I've set up the following components under my "Game" entity:

    • GameController - creates GUI and Scene components. Handles accelerometer/move events Networking events and command events from the GUI component. Calls commands to the Scene component to update the 3D scene.
    • GUI - creates and renders the 2D GUI components. Handles touch and key events and has it's own signal for announcing GUI commands (i.e. move forward, jump...)
    • Scene - encapsulation of Irrlicht scene graph management. Exposes commands for changing/updating the camera and scene nodes.
    • Networking - using Enet. Sets up a client or server, sends custom network packets and announces incoming "NetEvents" to be interpreted by the controller.


    Does this follow the traditional model for component based game architecture? Wondering if these should all be Entities instead? I'll likely end up with other components for Camera, Vehicles, etc as well...

    What do you think?

  5. #5
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    So, my understanding is that Entities are really just a message passing encapsulation of Components and other Entities. Is that correct? Is it ever appropriate to create a custom Entity, or should everything be a component?
    That's correct, there should never be a reason to create a new entity type. An entity's job is only to:

    • Group components that want to work together
    • Have a shared data (VariantDB) area that components can use if they way (used for things like alpha, position, etc)
    • Hold other entities


    Does this follow the traditional model for component based game architecture? Wondering if these should all be Entities instead? I'll likely end up with other components for Camera, Vehicles, etc as well...
    I don't think there is any one "right" way so it all sounds fine to me. You don't really have to put each component in its own entity unless you have a specific reason, such as wanting to use "pos2d" or such in the entity db so helper functions can operate on it.

    The message manager has no problems with calling functions and changing vars directly on components so that part is fine.

    I've organized my new 3d tank game like this:

    • GameLogicComponent (in its own entity)
    • Vehicles entity, which is like a folder that holds an entity for each player
    • VehicleComponent (each player entity adds one of these)
    • VehicleControlComponent (players who need on-screen controls and a rendering area get this added to a "controls" entity that is placed under their vehicle entity as a child) (The game supports split screen gameplay, which is why GUI is setup per player like that)


    One thing I've done in the name of speed is made things like the GameLogicComponent reahable with GetGameLogic() and I call many normal functions on it instead of trying to use entity messages.

    I can do GetGameLogic()->GetVehicleByID(index) to get access to their VehicleComponent directly, for instance. (I only create vehicles with a AddVehicle() member function in the GameLogicComponent, so it's easy for it to keep track)

    Basically, I just want to be able to use the nice messaging features of the entities/components to direct gameplay, but don't need much else.

    Anyway, here is a screenshot of my WIP from an iPad.. yeah, very early yet.
    Attached Images Attached Images  
    Seth A. Robinson
    Robinson Technologies

  6. #6
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default

    Fantastic, thank you for sharing Seth.

    Some Questions:

    1. Are your GameLogic, Vehicles and Controls Entities siblings, or are they all children of GameLogic?

    2. Have you tried to encapsulate Irrlicht scenegraph control in any one of your components, or is the scene graph modified from each?

    For example, to move a tank (from VehicleControl), do you:
    a. modify the Irrlicht Node position directly
    b. call GetGameLogic->MoveTank(...)
    c. call a boost signal, "TankMoved"
    d. call a boost function "MoveTank"
    c. call Vehicle::Move(...) directly

    What is your GameLogic's roll in the scene graph?
    Last edited by BigBMan; 01-21-2011 at 04:23 PM.

  7. #7
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Are your GameLogic, Vehicles and Controls Entities siblings, or are they all children of GameLogic?
    Vehicles is an entity under GameLogic. And game logic creates new vehicles like this:

    Code:
    int GameLogicComponent::AddVehicle(CL_Vec3f vPos, eVehicleOwner vOwner, CL_Rectf rect, float rotation)
    {
    	Entity * pVehicleEnt = m_pVehicles->AddEntity(new Entity("Vehicle"));
    	
    	int id = m_playerVec.size();
    
    	VehicleComponent *pVehicleComp = new VehicleComponent;
    
    	pVehicleComp->GetVar("id")->Set(uint32(id));
    	pVehicleComp->GetVar("vehicleOwner")->Set(uint32(VEHICLE_OWNER_LOCAL_PLAYER));
    	pVehicleEnt->GetVar("pos3d")->Set(vPos);
    	
    
    	pVehicleComp->GetVar("windowRect")->Set(rect);
    	pVehicleComp->GetVar("rotation")->Set(rotation);
    
    	//add it, which causes it to init everything with the above settings
    	pVehicleEnt->AddComponent(pVehicleComp);
    	m_playerVec.push_back(pVehicleComp);
    	return id;
    
    }
    One thing to note is I'm pushing the pointers into a vector to iterate through them quickly. (if I need to.. haven' t yet actually). This game doesn't require them to be destroyed/killed dynamically otherwise I might be using a linked list or something instead.

    The GUI entity/component for the vehicles are children of the vehicle, if applicable. (AI/network tanks don't need that of course)

    Global GUI elements like the pause button are children of the GameMenu, as is the GameComponent.


    Code:
    2. Have you tried to encapsulate Irrlicht scenegraph control in any one of your components, or is the scene graph modified from each?
    I'm having the vehicle directly set its Irrlicht scene note property. (it keeps a pointer to the IAnimatedMeshSceneNode* it made)

    I'm really sort of just flying blind here and trying to get a feel for Irrlicht. I do plan on hooking up "component functions" that do stuff later though, for instance, I can have it notice if "pos3d" is set and have it update its irrlicht node to match. Good for sequencing camera moves and such, stuff that won't matter speed-wise as it's called rarely.
    Seth A. Robinson
    Robinson Technologies

  8. #8
    Lesser Wizard
    Join Date
    Nov 2010
    Location
    Los Angeles, California, United States, United States
    Posts
    126

    Default

    Is there a way to link the ISceneNode's position to the Component's Vec3f? Keeping two values for that (and perhaps Orientation, etc) seems it could get pretty messy.

  9. #9
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    Code:
    Is there a way to link the ISceneNode's position to the Component's Vec3f? Keeping two values for that (and perhaps Orientation, etc) seems it could get pretty messy.
    I don't think there is an efficient way to do that, especially if you need to poll the Irrlicht side to get position data back into the Proton side every frame.

    For me, it's working out to not store things like position on the Proton side, and putting things like this is my VehicleComponent header:

    Code:
    core::vector3df GetPosition() {return m_sceneNode->getPosition();}
    core::vector3df GetHeading() {return m_vHeading;}
    For speed and simplicity. It does require that the other end (generally the CameraComponent, or another VehicleComponent) cast it to a VehicleComponent*, breaking the rules of Proton's very loose coupling, but once I get into the "finish the game" mode and out of "frame work design" that starts happening regularly.

    If I really need something "schedulable" such as movie-like camera movement, I'll can just use functions like "OnSetCameraTarget", so I can still sequence complex maneuvers easily using the MessageManager.
    Seth A. Robinson
    Robinson Technologies

Similar Threads

  1. Replies: 2
    Last Post: 04-26-2011, 12:43 AM
  2. GUI Component Constant Repaint
    By rombust in forum Official ClanLib SDK Forums
    Replies: 2
    Last Post: 10-14-2010, 07:29 AM
  3. What I would need to do to implement a new entity type or something?
    By speeder in forum Novashell Game Creation System
    Replies: 1
    Last Post: 08-18-2010, 05:10 AM
  4. Mind Wall for iPhone
    By davids in forum RTsoft Tavern
    Replies: 3
    Last Post: 07-11-2009, 11:45 PM
  5. New example in ClanLib 2.0: Custom GUI Component
    By sphair in forum Official ClanLib SDK Forums
    Replies: 4
    Last Post: 05-19-2009, 02:08 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •