Draft: Refactoring: partially merge projectiles and actors physics simulation
Simulate projectiles movement similar to actors. Refactor a lot of stuff to reduce code duplication and prepare for doing the same with doors and other objects. Biggest changes:
- Actors and Projectile inherit from a common base class.
- data necessary for the simulation is embedded into each object.
This is not a pure refactoring, there is a change of logic: previously the projectile raycast ran in the main thread, now it runs a sequence of raycasts in the background thread. Users likely won't notice though.
On my (weak) hardware, performance for up to 200 in-flight projectile is similar to current implementation with async on. With async off, I "hit the wall" at ~30 projectiles vs ~40 projectiles in master. Anyway, in normal game there is seldom more than 5 at a given time.
I'm not particularly happy about 2 things, I count on some input :) :
- I don't like the name of the base class for physics thingies: Body. Ideal-technically-accurate name would be Object but it has already a precise meaning in the code base. I considered also Solid, but I don't know how popular it is in English textbooks (that would be OK in French though).
- each physics "thing" embed a struct for the data necessary for its simulation. I went with this construction to manage inheritance:
class Body
{
/*...*/
template <typename T>
typename T::SimulationContext* getContext()
{
return static_cast<typename T::SimulationContext*>(mContext.get());
}
/*...*/
}
and in client code:
actorposition = pointer-to-body->getContext<Actor>()->mPosition;
I suppose (hope) there is some C++ trickery that can be used to not rely on this? I'd like to avoid changing my POD struct into a virtual class with tons of setters and getters which are relevant to only one of the children.