diff options
author | ennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-08 03:50:16 +0000 |
---|---|---|
committer | ennewalker <ennewalker@c06c8d41-db1a-0410-9941-cceddc491573> | 2009-01-08 03:50:16 +0000 |
commit | 3fe0cf688e2dad0503dbb31dd43cfe3bd1fa6536 (patch) | |
tree | ea81fae6b4ff16c40bfb2acac9eb85433fb80d9a /crawl-ref/source/tilebuf.h | |
parent | bac007c9138e659d34646952fb98afc056ec279c (diff) | |
download | crawl-ref-3fe0cf688e2dad0503dbb31dd43cfe3bd1fa6536.tar.gz crawl-ref-3fe0cf688e2dad0503dbb31dd43cfe3bd1fa6536.zip |
Clean up tiles code to use the VertBuffer classes.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@8321 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/tilebuf.h')
-rw-r--r-- | crawl-ref/source/tilebuf.h | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/crawl-ref/source/tilebuf.h b/crawl-ref/source/tilebuf.h index 3175e8ab4b..99897a6fe2 100644 --- a/crawl-ref/source/tilebuf.h +++ b/crawl-ref/source/tilebuf.h @@ -58,18 +58,19 @@ struct PCVert // V: vertex data template<class V> -class VertBuffer +class VertBuffer : public std::vector<V> { public: + typedef V Vert; + VertBuffer(const GenericTexture *tex, int prim); - void add(const V& vert); + // Vertices are fat, so to avoid an extra copy of all the data members, + // pre-construct the vertex and return a reference to it. V& get_next(); - void draw() const; - void clear(); + protected: - std::vector<V> m_verts; const GenericTexture *m_tex; int m_prim; }; @@ -88,7 +89,10 @@ class TileBuffer : public VertBuffer<PTVert> { public: TileBuffer(const TilesTexture *tex = NULL); + void add(int idx, float x, float y); + void add(int idx, int x, int y, int ox = 0, int oy = 0, bool centre = true, int ymax = -1); + // Note: this could invalidate previous additions if they were // from a different texture. @@ -120,23 +124,11 @@ inline VertBuffer<V>::VertBuffer(const GenericTexture *tex, int prim) : } template<class V> -inline void VertBuffer<V>::add(const V& vert) -{ - m_verts.push_back(vert); -} - -template<class V> inline V& VertBuffer<V>::get_next() { - int last = m_verts.size(); - m_verts.resize(last + 1); - return (m_verts[last]); -} - -template<class V> -inline void VertBuffer<V>::clear() -{ - m_verts.clear(); + size_t last = std::vector<V>::size(); + std::vector<V>::resize(last + 1); + return ((*this)[last]); } #endif |