Thousands of objects

Blitz3D Forums/Blitz3D Programming/Thousands of objects

Farflame(Posted 2003) [#1]
If I want to create thousands of objects, but they're all the same type (e.g 1000 spaceships of identical design), do I need to create each one individually, i.e load in the mesh for each, or do I just load the model in once and use that for each individual ship? How would I do that?

If they all need to be loaded in individually, isn't that very resource hungry? How many objects can Blitz handle?


Warren(Posted 2003) [#2]
Look into CopyEntity/CopyMesh (I think those are the commands anyway).


_PJ_(Posted 2003) [#3]
And, check out Types for manipulating and describing each object as a separate entity


Codemonger(Posted 2003) [#4]
Pls. correct me if I'm wrong ...

An entity is a seperate object from the mesh that does not hold vertex information (100's of points that make up the object), it is just an object with other important information that makes an entity an entity. It points to a mesh as opposed to storing all the mesh information. So you can make 1000 entities and it should not suck up memory resources because they actually do not hold vertex information it just points to the mesh. So the process would be as follow:

You are making a star wars game --- you want 1000 storm troopers, so you create a single storm trooper mesh, you only need one mesh because they all look alike. Then you create 1000 entities that point to the one storm trooper mesh that they use. This way they only use one mesh in memory, and they can all have very different properties and materials which are part of an entity. saves on memory big time.

(I hope george lucas doesn't sue me for using this example)

anyway what you should worry about though is that if the entities are not hidden they will become part of the lookup tables blitz uses internaly for things such as picking an entity or just to see if the entity is clipped from view (it would have to do 1000 iterations to see if any are in view).. so remember to use some sort of occlusion.


Farflame(Posted 2003) [#5]
Yes codemonger, that's pretty much what I was thinking. The reason I asked is because I've got a spaceship with a fairly complex mesh and when I tried to create an array of 100 ships, it took quite a while for the program to start running, as though it was eating up resources.

I think what I'm doing wrong is that I'm loading in the mesh for each entity. I guess I should be loading it in once, and then using copyentity to create each individual object?

Out of interest, how much memory does an entity require, without counting the mesh itself? If I had, say, 1 million entities, but all apart from 5 were hidden, would Blitz still struggle?


Ross C(Posted 2003) [#6]
Yeah, when you use copy mesh, i think it would just point to the one mesh. I also think copyentity makes the objects share the same surface?

If you had a million entity's, blitz would have to store vertex positions for each triangle, rotation values, alpha values, etc x 1 million. So it would slow your system to a halt. I've tried it with pivots :)


Farflame(Posted 2003) [#7]
Yep, copyentity works much better. There's no delay at all when I use that, so you're right.

Ok, so with the million entities example, I suppose the answer would be to store their position in memory, and just load them into an entity if they come within a certain range (i.e within visible range). Mind you, working out the distance of 1 million objects in 3d would also be quite time consuming, or is there a fast way of doing it?

By the way, I have no intention of using a million, but I do want alot (possibly several thousand).


Ross C(Posted 2003) [#8]
mmmm... it's gonna be problematic. Remember each entity requires it own pos, rot & alpha value stored in main memory. What is the thing that your doing that will require several thousand objects? I might be able to help if i know the circumstances that they are being used in :o)


LAB[au](Posted 2003) [#9]
You can have several thousand objects as long as it is in a single surface or at least a limited number of surfaces. So duplicating "objects" on the vertex level (adding/positioning vertices) should do the trick. Would require far less memory I think. But to animate/move objects you would ahve to move vertices. But all of this is in the case you would want to see all these objects.

If you need only 5 to be displayed at a the time, use a function for creating objects on the fly or better re-use the same objects.


Zephar123(Posted 2003) [#10]
my game has aroudn 1500!!! tress and its np i can do far more. :_) thanx to compyentity


Farflame(Posted 2003) [#11]
Well, I'm just working on theory right now for a space game. The idea is to have an unlimited numbers of ships/space stations, but not necessarily close to each other. So for example, there might be 10 at one planet and then 30 at the next, but on rare occasions lots of them might be at the same planet and I'm just wondering how it would work out.

I think the answer is definately to create/delete objects manually as they come in and out of view. The only problem I can see with that is that it might be time consuming to constantly check which objects are within a certain range.

Zephar, if your game has 1500+ trees, how does Blitz cope with that? Is there some way to tell Blitz to treat them as 'inactive' objects so it doesn't keep checking them for various unnecessary things? I assume they're not all on screen at the same time? :)


Codemonger(Posted 2003) [#12]
use hideentity to make sure blitz treats them as 'inactive'. So only when you need the 10 to 30 ships you should unhide those entities that are required. \

Remember if you know a certain part of space has 20 ships always in that area, then attach those ships to a parent entity so you can hide that parent entity (it will hide all children) .. Much quicker than looping through a large amount of entities.


Rottbott(Posted 2003) [#13]
Alternatively just load the current planet and all it's spacestations at stuff, and then delete it all and load the next set when you go to a different planet. Then it'll take a lot less RAM and load tons faster.

The downside is that there'll be a pause each time you go to another system as it loads stuff, but it shouldn't be a very long one at all.