Efficient Bullet Type

For a game, I want bullets that are as quick and efficient as possible, and don't need to have any sort of rotation, or special properties, just simple collision detection, velocity, and position. Coincidentally, a friend linked this video, watch it for about 45 seconds (I linked the correct time): http://www.youtube.com/watch?v=Khngnjhnpjo&t=5m16s

So rather than me using rigid bodies as bullets, he talks about how his particles are more efficient than rigid bodies. Other than getting LiquidFun, what can I do with the "original" box2d to do this? Are there any shapes or types that are cheaper to simulate?

Also, if you haven't already seen the video, it's pretty cool!

Note: I know about ray-casting, but that isn't what I want.
Could you tell us a bit more about why you don't want ray casting?
I have a Force Field(sensor) on the Space Ship that repels other bodies using apply force as a function of distance from its center. It works well and stays at 60fps as is, but I was hoping to make the number of bullets as little of a performance issue as possible, so I could have tons and tons of bullets (if I wanted), like a Minigun or something.

I sort understand simple/small objects can be done using ray casting. Is this how it would be done with Raycasting?:
Create my own class (like PointProjectile) that has velocity, mass, position.
When I update the world, I also have each PointProjectile do a raycast in from it's position, to the velocity direction, to check for a collision.
If collision, do simple math to find new velocity, position, PointProjectile, and the force applied to the fixture I "hit".

Why I was hoping to avoid that:
1. It seems like a hacky, second set of rules/interactions I have to deal with.
2. I still want it to respond to the Force Field. (I suppose I could add a second part to the Force Field class, to look for these PointProjectiles, but I would like to avoid that)

Or is there a better way to do the raycasting stuff?
I see, so you want the bullets to travel in curved lines and be affected by forces each step. In that case yes, you would be better off using bodies instead of raycasts.
It seems like you are doing some premature optimization here, since you mention it works well and stays 60fps as is, there is currently no problem as far as I can tell. How many regular bullet bodies can you fling around your scene before it gets too slow?
Yeah, I was doing premature optimization sort of, but the majority of time is spent doing box2d, and I knew that, so is that still considered premature? My program sometimes has trouble holding 60fps (at seemingly random times). It never drops below 30, and at this point, it isn't really a problem, but my goal is to avoid a problem all together. If it becomes a bigger problem farther along, I am afraid it will turn into something that is really hard to fix, so I'm constantly looking for somewhat easy to implement optimization tricks with box2d now. But if there isn't a really easy solution, that's ok too, and it sounds like there aren't any. And I could of course always do the ray tracing thing and just drop my nifty Force Field thing.


But why are _Unwind_SjLj_Register and __shmem_grabber_fc_key so high on this list?
_Unwind_SjLj_Register is for exception handling. http://stackoverflow.com/questions/6516 ... j-register
I couldn't figure out what __shmem_grabber_fc_key is.
Number on very left is % of time spent.


Code:
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name   
 10.71      0.54     0.54                             float b2Min<float>(float, float)
  8.73      0.98     0.44                             operator-(b2Vec2 const&, b2Vec2 const&)
  7.14      1.34     0.36                             b2PairLessThan(b2Pair const&, b2Pair const&)
  6.35      1.66     0.32                             void b2DynamicTree::Query<b2BroadPhase>(b2BroadPhase*, b2AABB const&) const
  6.15      1.97     0.31                             float b2Max<float>(float, float)
  4.56      2.20     0.23                             __shmem_grabber_fc_key    ////////////////////////////////
  4.17      2.41     0.21                             _Unwind_SjLj_Register///////////////////////////////////////////
  4.17      2.62     0.21                             b2Pair* std::__unguarded_partition<b2Pair*, b2Pair, bool (*)(b2Pair const&, b2Pair const&)>(b2Pair*, b2Pair*, b2Pair const&, bool (*)(b2Pair const&, b2Pair const&))
  3.97      2.82     0.20                             b2Min(b2Vec2 const&, b2Vec2 const&)
  3.77      3.01     0.19                             b2Vec2::b2Vec2(float, float)
  3.37      3.18     0.17                             void b2BroadPhase::UpdatePairs<b2ContactManager>(b2ContactManager*)
  3.17      3.34     0.16                             b2Max(b2Vec2 const&, b2Vec2 const&)
  3.17      3.50     0.16                             b2Mul(b2Transform const&, b2Vec2 const&)
  2.78      3.64     0.14                             b2TestOverlap(b2AABB const&, b2AABB const&)
  2.58      3.77     0.13                             b2DynamicTree::InsertLeaf(int)
  1.98      3.87     0.10                             b2GrowableStack<int, 256>::Push(int const&)
  1.79      3.96     0.09                             b2PolygonShape::ComputeAABB(b2AABB*, b2Transform const&, int) const
  1.59      4.04     0.08                             b2GrowableStack<int, 256>::Pop()
  1.59      4.12     0.08                             void std::__unguarded_linear_insert<b2Pair*, bool (*)(b2Pair const&, b2Pair const&)>(b2Pair*, bool (*)(b2Pair const&, b2Pair const&))
  1.39      4.19     0.07                             b2DynamicTree::Balance(int)
  1.19      4.25     0.06                             b2DynamicTree::RemoveLeaf(int)
  1.19      4.31     0.06                             b2GrowableStack<int, 256>::GetCount()
  1.19      4.37     0.06                             b2AABB::Combine(b2AABB const&, b2AABB const&)
That the majority of the time is spent on Box2D doesn't mean it's wasting time doing something pointless. It's pretty well written so I think you would be hard-pressed to find any low-hanging fruit as far as optimizable places are concerned. What you could try, is increase the number of bodies you have in the scene to the point where you consistently don't get 60fps, and see how far away that is from the typical case you will be dealing with. If it's above twice the load that you expect to be dealing with I probably wouldn't bother giving too much thought to this. It would be good to figure out why it drops sometimes, perhaps you could cut out all the rendering code, check if other processes on the computer are doing something etc. Common possibilities that do make Box2D slow up are: making a large number of bodies at the same time, placing a large number of fixtures in the same place, moving (SetTransform) a large number of bodies at the same time, and having large piles of bodies.

Original thread: https://box2d.org/forum/viewtopic.php?t=9779