0
\$\begingroup\$

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

\$\endgroup\$
7
  • \$\begingroup\$ Show your code. There's nothing inherently slow about vectors so it must be something you are doing that is strange. \$\endgroup\$
    – Kylotan
    May 4, 2012 at 20:17
  • \$\begingroup\$ Okay, one minute and I'll post the parts that I have changed \$\endgroup\$
    – Molmasepic
    May 4, 2012 at 20:19
  • \$\begingroup\$ alright, heres the main code: pastebin.com/7SJuFiu2 \$\endgroup\$
    – Molmasepic
    May 4, 2012 at 20:22
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ May 4, 2012 at 21:26
  • \$\begingroup\$ 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. \$\endgroup\$
    – Molmasepic
    May 4, 2012 at 21:46

3 Answers 3

1
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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. \$\endgroup\$
    – Molmasepic
    May 5, 2012 at 0:27
  • \$\begingroup\$ 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[myPlayer->getZone()],theDmgList,DmgShowScr,lDeltaTime_Ms,lSilverBack);/// theNPlayList[myPlayer->getZone()].at(n)->SkillDmging(thePlayList,theNPlayList[myPlayer->getZone()],theDmgList,DmgShowScr,lDeltaTime_Ms,lSilverBack);/// } isnt inside the other loop ? \$\endgroup\$
    – Artii
    May 5, 2012 at 15:19
  • \$\begingroup\$ Actually since the monsters are working well while divided I should put that loop in with the other one. \$\endgroup\$
    – Molmasepic
    May 5, 2012 at 17:44
0
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – Molmasepic
    May 4, 2012 at 20:23
0
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .