Archived

This topic is now archived and is closed to further replies.

Dirge

Entity handling

Recommended Posts

Dirge    300
Does anyone have some good advice for entity handling in an intensive graphics application (i.e. a game :-). Is something similar to the way Quake 3 did refEnts for rendering a valid solution? Does anyone else have any good systems. It just seems ridicules to go through an entity list and render everything, so it makes more sense to have a render list, but then I wonder how much info should be dumped into an entity in the first place, and if a special "ref" entity is required. I also worry about memory allocation (weapon missles for instance shouldn''t have to be allocated and destroyed on a frame by frame basis). Basically what is a good entity management system based on rendering efficiency. Thanks for any info! "Love all, trust a few. Do wrong to none." - Shakespeare Dirge - Aurelio Reis www.CodeFortress.com Current Causes: Nissan sues Nissan

Share this post


Link to post
Share on other sites
billybob    134
you can use a stack based memory class, that allocates a block big enough for all your entities, and then allocates something like


class Manager
{
unsigned char * Buffer;
DWORD Capacity;
DWORD Position;
...
Manager(DWORD Cap)
{
Buffer = NULL;
Buffer = new unsigned char[Cap];
if(!Buffer)
//not enough memory
Capacity = Cap;
Position = 0;
}
~Manager()
{
delete [] Buffer;
}
};

void * Manager::Alloc(DWORD size)
{
if(Position + Size > Capacity) //not enough room for object
return NULL;
Position += Size;
return Buffer[Position - Size];
}

void Manager::Free(DWORD Size)
{
Position -= Size;
}


that might not be right (probably isn't) but you get the idea. the problem is you have to deallocate in the opposite order you allocated, which might be hard with entities. this works better for something like a resource manager, that can delete things on its own after the resource manager is deleted.

edit: this also doesn't call the constructor

[edited by - billybob on March 7, 2003 1:00:41 AM]

Share this post


Link to post
Share on other sites
Dirge    300
I guess I should have mentioned that I want to use C++ based inheritance too. I''m not really looking for a memory management method really as much as a good way to handle entitys (if I did want good mm I would override the new operator and throw in my own memory manager similar to yours).

As of right now I have a list of entity pointers, and you have to allocate a new entity (of the inherited type), set it up, then add it to the entity list. This is used for collision detection and such. If you want to render an entity, I have another list of entity pointers that is reset every frame, so in order to render something, you just add to this list. The problem is (in my mind) that the entity needs to know how to render itself (does it have a model, a sprite, a 3d line, etc...?). I suppose I could keep something in the entity so it knows how it renders itself, but it seems to take away from the point that an entity ''contains'' a model or sprite or whatever.

Also, in contrast to a c++, should I make the renderer the actual thing that can render a model (instead of this: Model->Render;, this: Renderer->RenderModel( Model );

Thanks again for your input!

"Love all, trust a few. Do wrong to none." - Shakespeare

Dirge - Aurelio Reis
www.CodeFortress.com
Current Causes:
Nissan sues Nissan

Share this post


Link to post
Share on other sites