Well, I'm currently doing a lot of code refactoring, and one of the things I think I really need to hit on is Entity Management. Really, I just want to hear how you guys manage your entities (with collision handling/detection specifically in mind).
Do you have a single container to hold all your entities? Do you separate Entities by their types? Etc?
I'm just looking for more ideas here :D, thanks for any response :p.
Managing Entities in Regard to Collision Detection/Handling
Moderator: PC Supremacists
- Milch
- Chaos Rift Junior
- Posts: 241
- Joined: Sat Jul 11, 2009 5:55 am
- Programming Language of Choice: C++
- Location: Austria, Vienna
Re: Managing Entities in Regard to Collision Detection/Handling
I'm not sure if this is an actual entity system I'm using, but anyway.
I have a base class for entities 'Base_Entity' and all entities inherit from this class.
The collision system works like this:
Each entity can have n collision objects, and all these collision objects are registered in a collision manager.
This way I can change the implementation of the collision manager pretty fast.
The collision manager now 'thinks' and calls the 'Touch' function of the both colliding entities, with a pointer to the other entity as a parameter.
( e.g like this 'void Touch( Base_Entity* other )' )
I'm thinking about handling over the pointer of the collision-object that triggered the event - so I can have something like 'hitzones,...'
I have a base class for entities 'Base_Entity' and all entities inherit from this class.
The collision system works like this:
Each entity can have n collision objects, and all these collision objects are registered in a collision manager.
This way I can change the implementation of the collision manager pretty fast.
The collision manager now 'thinks' and calls the 'Touch' function of the both colliding entities, with a pointer to the other entity as a parameter.
( e.g like this 'void Touch( Base_Entity* other )' )
I'm thinking about handling over the pointer of the collision-object that triggered the event - so I can have something like 'hitzones,...'
Follow me on twitter!
Re: Managing Entities in Regard to Collision Detection/Handling
Milch wrote:I'm not sure if this is an actual entity system I'm using, but anyway.
I have a base class for entities 'Base_Entity' and all entities inherit from this class.
The collision system works like this:
Each entity can have n collision objects, and all these collision objects are registered in a collision manager.
This way I can change the implementation of the collision manager pretty fast.
The collision manager now 'thinks' and calls the 'Touch' function of the both colliding entities, with a pointer to the other entity as a parameter.
( e.g like this 'void Touch( Base_Entity* other )' )
I'm thinking about handling over the pointer of the collision-object that triggered the event - so I can have something like 'hitzones,...'
Well, I'm not really talking about that... I'm more along the lines of storage of entities :p
- Milch
- Chaos Rift Junior
- Posts: 241
- Joined: Sat Jul 11, 2009 5:55 am
- Programming Language of Choice: C++
- Location: Austria, Vienna
Re: Managing Entities in Regard to Collision Detection/Handling
I just have a big list of entities, because everything in my game engine is an entity ( even the game menu, intro screen,... ), but I think it depends on what kind of entity system you have ( e.g Just map objects or simply everything )
The only important hint that I can give you is use a singly linked list - because most of the time a doubly linked list eats up to much memory and isnt worth it!
The only important hint that I can give you is use a singly linked list - because most of the time a doubly linked list eats up to much memory and isnt worth it!
Follow me on twitter!
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Managing Entities in Regard to Collision Detection/Handling
I definitely recommend you separate them at least into collision groups. Checking collision of every entity against every entity is never going to be beneficial (what's the last game you played where a floor tile collided with the game menu?). Even with a quad tree it's still wasteful to have an unsorted glob of entities in a giant list.
Separating them into basic lists by type would be a start:
Obviously the types and interaction checks would be customized to suit your game.
Separating them into basic lists by type would be a start:
Code: Select all
std::vector<Entity*> floorTiles;
std::vector<Entity*> wallTiles;
std::vector<Entity*> items;
std::vector<Entity*> chars;
std::vector<Entity*> warps;
std::vector<Entity*> menus;
Entity* mouse; //This probably isn't how you handle input, but you did mention menus being entities.
//Check Character against Floor, Wall, Item, Warp
//Check Item against Floor, Wall (If item has physics)
//Check Mouse against Menu, Item (Pick up items), Character (NPCs), Floor/Tile/Warp (in edit mode)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Milch
- Chaos Rift Junior
- Posts: 241
- Joined: Sat Jul 11, 2009 5:55 am
- Programming Language of Choice: C++
- Location: Austria, Vienna
Re: Managing Entities in Regard to Collision Detection/Handling
Not each entity has a collision box! That wouldn't be very efficient!
Each entity has the ability to register collision-objects ( e.g RegisterObject() )
So a entity can have n-objects ( like I said before, hitzones )
Each entity has the ability to register collision-objects ( e.g RegisterObject() )
So a entity can have n-objects ( like I said before, hitzones )
Follow me on twitter!
Re: Managing Entities in Regard to Collision Detection/Handling
This is what I was looking for. Alright, I think what I'll probably do is have my Entity Manager contain a list for each type of entity, and then have it check for collisions every frame, and if a collision happens, I'll add the information regarding that collision to a queue, where they can later be handled by a CollisionManager :pdandymcgee wrote:I definitely recommend you separate them at least into collision groups. Checking collision of every entity against every entity is never going to be beneficial (what's the last game you played where a floor tile collided with the game menu?). Even with a quad tree it's still wasteful to have an unsorted glob of entities in a giant list.
Separating them into basic lists by type would be a start:Obviously the types and interaction checks would be customized to suit your game.Code: Select all
std::vector<Entity*> floorTiles; std::vector<Entity*> wallTiles; std::vector<Entity*> items; std::vector<Entity*> chars; std::vector<Entity*> warps; std::vector<Entity*> menus; Entity* mouse; //This probably isn't how you handle input, but you did mention menus being entities. //Check Character against Floor, Wall, Item, Warp //Check Item against Floor, Wall (If item has physics) //Check Mouse against Menu, Item (Pick up items), Character (NPCs), Floor/Tile/Warp (in edit mode)