Optimizing help anyone?

Started by
5 comments, last by Lord Maz 22 years, 3 months ago
Hey, I''ve got some problems with SPEED with the latest addition to my game, weapons. I''ve got a linked list with all the collision areas on the map, and a linked list with the bullets from my weapons. Well, I want to shoot a hellofalot of bullets, and make them stop when they hit solid. This isn''t really fast because I have to iterate through the whole list of bullets and for every bullet iterate through the list of collision areas while checking if it''s inside the rect - does ANYONE have any magic tricks to make this faster? Check my page for a screenshot of the game if it would help: www.lordmaz.150m.com (bottom of the projects page)
-Lord Maz-
Advertisement
Possibly the simplest method for optimising collision detection involves storing all your objects in a list sorted by X or Y position. This lets you trivially reject large portions of the list very quickly. If that isn''t enough for you, you can go into such things as binary space partitioning, quadtrees and octrees, which are all ways of splitting up your game world into a hierarchy of areas which allows you to quickly test which objects are in the same area.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
The bullets travel in a straight line right? Calculate the point of collison once when they''re fired and remember it.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Kylotan: Interesting, but all those trees and stuff is too advanced, I''d like to keep my game simple untill I actually have enough knowledge to be able to understand the things I put in it.

Magmai: that''s a great idea! then I''d only need to check if the bullet has hit the endpoint or another player..

Thanks
-Lord Maz-
How fast do the bullets move compared to how fast the players move? Is there ever going to be a case where you fire and it doesn''t hit something _that_ frame? If it doesn''t are you going to make the bullets subject to gravity and have them drop with distance?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Segmenting a level IS simple, and you CAN understand it. See it like this. You have a level with solid objects. Now devide it into four equal sections. Now devide each of those into four equal segments. Now you have 16 segments. What you then do is test a bullet for being in one of the larger four segments, if so, test to see which of the smaller four segments of that larger segment the bullet is in, then only test it against the objects in that segment. You can refine it further and further should you want, and it''s really not so complicated.

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Ok, doesn''t sound too hard when you put it that way

I''ve been thinking on how I would accomplish this, not sure which data structure I should use, and how it would be used.. One thing, my map is 25*16 tiles, which makes it impossible to have two equally large branches (dunno if it matters)..

I think it would work if I had a tree structure divided into 4 children, the left children are in control of 13*8 tiles and the right 12*8, and then the left children are branched into two 7*4 areas and two 6*4 areas, and the right into four 6*4 areas... then i could add the collision maps into the bottom children.. something like that anyway Anyone have any suggestions (links, tutorials ) how?
-Lord Maz-

This topic is closed to new replies.

Advertisement