From f2d3072643e4140ef3dd144b7509eda8d4a323d6 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 23 May 2010 22:10:50 +0200 Subject: Made bullet-lists configurable by template parameter. --- engine/bulletpattern.h | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'engine/bulletpattern.h') diff --git a/engine/bulletpattern.h b/engine/bulletpattern.h index 8df7945..f550c2c 100644 --- a/engine/bulletpattern.h +++ b/engine/bulletpattern.h @@ -2,33 +2,54 @@ #define BULLETPATTERN_H #include "vector.h" +#include "struct.h" + +#include class BulletPattern { - protected: - float* bullets; - unsigned int num_bullets; - unsigned int stride; - unsigned int steps; public: float color_r, color_g, color_b; virtual void update() = 0; - void draw(); + virtual void draw() = 0; +}; + +template +class BulletPatternImpl : public BulletPattern { + protected: + struct Bullet { + Vector2 pos; + Vector2 dir; + Data data; + }; + + Bullet* bullets; + + unsigned int num_bullets; + unsigned int steps; + + public: + void draw() { + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(4, GL_FLOAT, sizeof(*bullets), bullets); + glDrawArrays(GL_POINTS, 0, num_bullets); + glDisableClientState(GL_VERTEX_ARRAY); + } }; -class BulletPattern1 : public BulletPattern { +class BulletPattern1 : public BulletPatternImpl { public: BulletPattern1(const Vector2& initpos); void update(); }; -class BulletPattern2 : public BulletPattern { +class BulletPattern2 : public BulletPatternImpl > { public: BulletPattern2(const Vector2& initpos); void update(); }; -class BulletPattern3 : public BulletPattern { +class BulletPattern3 : public BulletPatternImpl > { public: BulletPattern3(const Vector2& initpos); void update(); -- cgit v1.2.3