Entity manager size

Started by
9 comments, last by cozzie 9 years, 9 months ago

Hi all,

While working out the design of my entity manager (yet to be implemented) for my 3d engine, something got me thinking.

Up till this moment I thought I needed to redo my renderqueue, to make it possible to add extra mesh instances (linked to game objects), sort everything again etc., after changes are done in the entitymanager.

But then I thought, let's say you have a level of a game, you will now on forehand how many game objects will be in the level, same for 'bad guys'/ enemies etc. Ok, there will be less, depending on the state of the game objects. But not taking mesh instances into account in a sorted list is easy (just leave out the ones that are not visible, for rendering, culling, physics etc).

In short; do you see reasons why to have both an entity manager and renderqueue that are able to add new game objects (entities) / mesh instances (renderqueue)?

The only reason I could think of is having a multiplayer game where new players are added. On the other hand, you can then take a 'max' of players and use these 'slots' so you don't need to add anyway (just 'enable'/ make them visible when needed).

Any input is appreciated, since it will help me decide if redoing my renderqueue is worth all the effort.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Advertisement

I guess it depends on what kind of game you are building. For instance, in a RPG, are your spells considered to be their own entities? If so whenever you cast a spell (eg a fireball), you will have to create a new entity. The same applies to summoned creatures. I thought about the same issue. I'm building a turn-based tactical game and for instance if a spaceship fires a missile that takes more than one turn to reach the target, I'd like the player to be able to select it, so it would have to be an entity in its own regards.

--Avengers UTD Chronicles - My game development blog


In short; do you see reasons why to have both an entity manager and renderqueue that are able to add new game objects (entities) / mesh instances (renderqueue)?

A render queue is usually a thing where renderables that are actually to be rendered just now are collected. It is filled with rendering jobs (to use the most abstract term here) resulting from iterating the scene and passing visibility culling. The queued jobs will be sorted by some engine dependent criterions. It will be re-build for the next loop run (if we let coherency mechanisms aside). As such, a render queue doesn't know what game objects are, and hence there is no meaning in comparing it with the entity manager. This is decoupling in action, so to say.

IMHO "new game objects" defines a game object that is added to the scene. For sure this has an impact on the game object management, but it should not have an impact on the render queue. If the object is in the scene, and it passes visibility culling, then it is (indirectly, but nevertheless) added on-the-fly to the render queue.

Do you have another definition of render queue?

Thanks both.

My definition of the renderqueue is mostly the same, except this part "it will be re-build for the next loop run". I don't do this currently, I just loop through all sorted renderables and fill an index with the indices of renderables that are visible. Those are rendered.

I only sort / re-build at initial startup, if I would do this say each frame (or 2) then the question would be answered and I would simply add the representation of new game objects (mesh instances) to the renderqueue and sort everything again.

Currectly/ when knowing the number of game objects (and their representation through mesh instances), I only have to build and sort the renderqueue once (other then just looping through them and picking the visible ones). Performance wise this could be an advantage, not having to rebuild and sort each frame.

On the 'cons' side, I have to be prepared for enough game objects, leading to mesh instances, to manage the whole scene.

As you said, the issue indeed is not with game object management, I don't need sorting etc. there. That would be 'just' a std::vector of my game object class.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Handling a variable number of items in your render queue shouldn't present any architectural difficulty. Just use a vector instead of a fixed array.

The question is do you want to support variable numbers of meshes being drawn over the course of your game. Not allowing it would be a strange limitation, since you pretty much already have all the functionality you need to implement it: a basic implementation could just "re-evaluate" the objects each frame and resort them. If sorting performance ever becomes an issue, then you could add more logic/complexity to address that.

Not allowing the creation/deletion of gameobjects over the course of a game seems like an onerous limitation. It might force to make less-that-ideal choices about how to implement various game features.

Thanks phil_t. That sounds logical. Maybe I can find a way to 'insert' new objects in the renderqeue efficiently, otherwise I'll sort on material groups, materials and meshes etc. ONLY after an object is inserted. It doesn't seem necessary to 're-sort' when an object is 'removed' or nothing changes.

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

Without knowing the kind of game you making, it's difficult to say. But if the sorting bothers you have you thought about a bubble sort?

Say an object appears nearby: it gets sent to the end of the render queue, where a single pass bubble sort is performed every frame. It will very quickly find it's right location in the queue (maybe for front to back rendering). And it's a really cheap way of sorting. The only time it really matters if when other objects are in direct line of sight - which will only be a small number anyway.

Alternatively, maintain several types of lists, sort them individually and then splice them together at the end.

That's a good suggestion. If I know (flag) which objects in the renderqueue are static, I could have 2 lists. In the end it's the question which performs better, just add/ insert and sort the whole thing versus having 2 lists and merging/ sorting them.

On the other hand, it might be useful for other reason two, too have a separate "bucket" for all dynamic objects (where insertion etc. Is expected)

Crealysm game & engine development: http://www.crealysm.com

Looking for a passionate, disciplined and structured producer? PM me

What if you have security cameras / picture-in-picture, or planar-reflectors (mirrors/water), or shadow-mapping? All of those require an extra "camera", which means the "renderable entities" have to be drawn again, but perhaps with a completely different sorting order.

There's a good reason that most games have more that a single 'view' of the scene wink.png

This topic is closed to new replies.

Advertisement