• ### Announcements

• #### Wondering what's new and changed at GameDev.net?06/20/17

Check out the latest Staff Blog update that talks about what's changed, what's new, and what's up with these "Pixels".
Followers 0

# Scene graph

## 12 posts in this topic

Hello game developers , I have in my game every thing , but all what I need right now is a fast way to create 100 model for example ( zombie )   can you post some code showing the data structures ... etc , say what you know about this , I have for each model modelAnimatorManager and physicsManager  , so if I want to create 100 zombie model I must create 100 modelAnimaorManager and 100 physicsManager !!!! that's too much right ?!?!

I used List<model> zombie = new list<model>();

and iterate over the model 100 times !!!!!!!!!!!!!! bla bla bla the same goes for physicsManager and modelAnimatorMnager , I know this is not good strategy !!

Sorry game developers if my topic was not related , I have not enough information about these issues , but I think my problem is about mange the scene or whatever is the definition .

0

##### Share on other sites

That entirly depends ...

What does modelAnimatorManager and physicsManager do? do you NEED 1 for each zombie?

if you have 100 items in the list, and you need to iterate over it, there is no way to get around doing it 100 times. you could look into Multi-threading, but that could cause more problems than it solves.

without any details, i would say Do each of the items NEED a physics manager? Why not 1 physics manager that can handle the updating of everything?

I currently use a physics engine and have over 1000 objects updating each frame, and the framework does this for me in ~20ms.

2

##### Share on other sites

thanks Andy474 , modelAnimator just load the animation for the model and set the world matrix which will be drawn later on the screen , not physics manager but it's like the controller for the model , i.e updating the bounding box for the model ......etc .

I was talking with my friend belfegor , he advice me to create one class that contain the model and the modelAnimator and the chrachter controller and just make list of it instead of making 100 list from each one of model , modelAnimator , chrachter controller for each class !!!

for you Andy , what is your advice , tell me about the data structure you used and tell me your opinion in general  and how did you manage all your stuff 1000 model or whatever

0

##### Share on other sites

Well I use an engine called Farseer Physics to manage my games physics. you could look at the source code, But 1000 objects are not going to take anytime to process at all.

I have ~1346 and my update frame time is about 15ms.

0

##### Share on other sites

Ok , Andy do you face problem like this :

you have 10 models using the same effect , if you use XNA or Directx (the same applied ) I got this error :

Code used to make 10 copies of ModelManagerSupprt which will contain the model and the effect and will holds chrachter controller (BEPU Phsics Engine) :


foreach (ModelManagerSupport dwarfModel in dwarfModels)
{
//dwarfModel.setEffect(camera , game);
//dwarfModel.setModelAnimationStatus(game);
//dwarfModel.intializeChrachterController(new Vector3(0, 0, 0), 20, 10, 2000, 2000, 80, 40);

}


0

##### Share on other sites
Asking for code is typically a bad approach. People don't want to write your software for you, and besides that ruins all the fun of it :). What you want to do is "instanced drawing". You load the model once into a Vertex Buffer, and then draw the same object over and over using different shader parameters. Edited by metsfan
2

##### Share on other sites

metsfan , thanks but why I can't simply load effect and 10 models which use the same effect ? , besides that is Instancing works for animated models  (.x ) format ?

0

##### Share on other sites

metsfan , my problem is not with instancing , my problem is that I can't create 2 effects and 2 models which used the same effect as shown above in the code

0

##### Share on other sites

If your models have a lot of detail and your game starts to stall, you can try to implement Instancing, so instead of having separate draw call for identical zombies (for instance say 100 draw calls). You have one shader, which can draw desired number of models at once.

It might get tricky so first thing is to ask yourself if you really need such optimisation.

Edited by Tasaq
0

##### Share on other sites

OK , Thaaaaaanks so much , but for now I will not do Instancing , all I need is to figure out the bug in my game .

If I load 2 models ( the same model zombie ) and give them the same effect I got the following errore :

   for(int i =0 ; i<2 ; i++)
{
dwarfModel[i].setEffect(camera , game);
dwarfModel[i].setModelAnimationStatus(game);
dwarfModel[i].intializeChrachterController(new Vector3(0, 0, 0), 20, 10, 2000, 2000, 80, 40);

}


0

##### Share on other sites

that has nothing to do with loading 1, 10, 100 or 1 million objects.

That's just a problem trying to upcast and Effect into something that is not (a BasicEffect), just as the error message is complaining about.

The rest of the thread doesn't make a lot of sense either... unless you want to draw 1 million zombies in the same pose, you'll need to draw them separately.

Having the animation data shared for all the zombies or one for every zombie is a memory problem.. are you having problems with memory? If you have, I bet there are MANY other places eating up your memory.. but seriously, considering the fact that you can't understand a simple error message like that means you don't have problems with memory solvable by sharing animation data.. so my suggestion is.. keep coding and forget about all this.

1

##### Share on other sites

kunos  thanks , so I did not see your advice and answer for my problem !! I still can't figure out the problem as show in the picture above !!

0

##### Share on other sites

well.. sorry to be blunt, but if you dont understand why a cast is failing at runtime you should go back to basics and study C#, inheritance and all that before moving on.

Let's have a base class Effect, and then BasicEffect and CustomEffect derived from that. You cannot cast an Effect into a BasicEffect if that is pointing to a CustomEffect... .NET is gentle enough to point that out for you.

3