- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
template <typename T> struct Pool { static std::vector<T> data; };
std::vector<tbphys::Body> Pool<tbphys::Body>::data;
std::vector<Ball> Pool<Ball> ::data;
std::vector<Wall> Pool<Wall> ::data;
std::vector<Bat> Pool<Bat> ::data;
std::vector<Brick> Pool<Brick> ::data;
template <typename T, typename U> struct List
{
typedef T Head;
typedef U Tail;
};
struct End {};
typedef List<tbphys::Body, List<Brick, List<Bat, List<Ball, List<Wall, End> > > > > Components;
typedef List<Brick, List<Bat, List<Ball, List<Wall, End> > > > DrawableComponents;
typedef List<Brick, List<Ball, List<Bat, End> > > MovableComponents;
const size_t badindex = size_t(-1);
struct GameBody
{
size_t self,body,bat,brick,wall,ball;
template <typename T> size_t& IndexOf ();
template <> size_t& IndexOf <tbphys::Body> () {return body;}
template <> size_t& IndexOf <Bat > () {return bat;}
template <> size_t& IndexOf <Brick> () {return brick;}
template <> size_t& IndexOf <Wall > () {return wall;}
template <> size_t& IndexOf <Ball > () {return ball;}
template <typename T>
T& AddComponent ()
{
size_t index = Pool<T>::data.size();
Pool<T>::data.resize(index+1);
T& result = Pool<T>::data[index];
result.hostIndex = self;
IndexOf<T>() = index;
return result;
}
template <typename T> void SetBadIndex ()
{
IndexOf<T::Head> () = badindex;
SetBadIndex<T::Tail> ();
}
template <> void SetBadIndex <End> () {}
};