Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Okay so I have a vector for all of the monsters that are spawned in my game. All of these monsters are in a single vector and are "active" according to what zone they are in relative to the player's zone.

If the player is in the same zone as the monster, then have the monster move around and commit actions such as attacking other monsters or the player.

This is all done on a very powerful computer: my main computer.

-BUT-

If I were to attempt using this game on my medium-end computers, the game runs on a steady 2 FPS(where on the main does 50+)

What I attempted is splitting the vector into an array of vectors vector SpawnList to vector SpawnList[100] as a quick example

Now with this code the monsters are in separate vectors according to their zones(zone is the area that the monster is spawned in)

Note: I use Ogre3D for rendering and bulletPhysics for the physics, and I haven't figured out a way to split the monsters' rendering accordingly.

And with this new idea, my main computer even faces severe slowdowns.

I am wondering if maybe the vectors have been created wrong or it is not a good idea to have an array of vectors.

Is there a better way of having the monsters grouped together where the performance is almost maximum on any computer?

EDIT: I have Profiled my code and here are the updated results. I hope they are of help to this situation: http://pastebin.com/v0PFQf0X

share|improve this question
    
Show your code. There's nothing inherently slow about vectors so it must be something you are doing that is strange. –  Kylotan May 4 '12 at 20:17
    
Okay, one minute and I'll post the parts that I have changed –  Molmasepic May 4 '12 at 20:19
    
alright, heres the main code: pastebin.com/7SJuFiu2 –  Molmasepic May 4 '12 at 20:22
2  
Do you have any reason to believe that's where the slowdown is? Have you profiled your code on the slower machine to look for specific bottlenecks? That should really be your first order of business before trying to refactor these structures. –  Steven Stadnicki May 4 '12 at 21:26
    
Wow I never thought of profiling my code. Alright, I'm gonna mess with the profiler and see what results I can pull up. I guess I will update my question once I get somewhere with it. –  Molmasepic May 4 '12 at 21:46

3 Answers 3

Maybe you could use a look up table for the zones and then each cell of the table having the list of all mobs in the area ,and then only update the state of the monsters ,that are in the current zone you're in . I am assuming here that maybe you're iterating threw the big vector and then updating all the states ,only that would have a non-memory performance toll.Of course i might be missing something.

Edit.Ok i looked up your code and it seems you're doing that as it is so this seems irrelevant,although a small optimization would be just call this once myPlayer->getZone() and assign it to some variable instead of calling it all the time ,though just quite minor.

share|improve this answer
    
I changed my code where it is not using myPlayer->getZone() so much and I got a great performance boost. Thanks for the suggestion it worked well. But I am still having slowdowns on my other computer...Right now I am cleaning it out since I havent used it much(running antivirus and such) Im having a feeling that there are problems slowing down the computer itself. –  Molmasepic May 5 '12 at 0:27
    
Also is there a particular reason ,that this for(int n=0;n<theNPlayList[myPlayer->getZone()].size();n++) { { theNPlayList[myPlayer->getZone()].at(n)->SkillDmging(thePlayList,theNPlayList[my‌​Player->getZone()],theDmgList,DmgShowScr,lDeltaTime_Ms,lSilverBack);/// theNPlayList[myPlayer->getZone()].at(n)->SkillDmging(thePlayList,theNPlayList[my‌​Player->getZone()],theDmgList,DmgShowScr,lDeltaTime_Ms,lSilverBack);/// } isnt inside the other loop ? –  Artii May 5 '12 at 15:19
    
Actually since the monsters are working well while divided I should put that loop in with the other one. –  Molmasepic May 5 '12 at 17:44

If the monsters are continuously being created and destroyed (if the vector is changing size), then try using a list instead.

share|improve this answer
    
The monsters are actually not being created and destroyed. theres an array for the monsters, and the vector holds the spawned 'copies' of monsters(from the array) and the monsters are put on a "sleep" when dead. –  Molmasepic May 4 '12 at 20:23

How about using a Quadtree http://en.wikipedia.org/wiki/Quadtree

I don't know what the performance results between the vector and a Quadtree are. Do update here when you find a good solution would like to know too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.