summaryrefslogtreecommitdiff
path: root/lib/glsprite.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/glsprite.cc')
-rw-r--r--lib/glsprite.cc137
1 files changed, 14 insertions, 123 deletions
diff --git a/lib/glsprite.cc b/lib/glsprite.cc
index 282eefe..68350c9 100644
--- a/lib/glsprite.cc
+++ b/lib/glsprite.cc
@@ -1,146 +1,37 @@
#include <SDL.h>
#include "glbase.h"
-#include "sprite.h"
+#include "glsprite.h"
+#include "engine.h"
#define TEXSIZE 256
-mogltk::Sprite::TexList * mogltk::Sprite::TexList::header = 0;
-
-mogltk::Sprite::Sprite(Handle * h, int asx, int asy) : sx(asx), sy(asy) {
- alloc();
- for (int y = 0; y < sy; y++) {
- h->read(tlist->GetTex()->GetPixels() + TEXSIZE * y + posx, sx * 4);
- }
-}
-
-mogltk::Sprite::Sprite(Uint8 * p, int asx, int asy) : sx(asx), sy(asy) {
- alloc();
- for (int y = 0; y < sy; y++) {
- bcopy(p, tlist->GetTex()->GetPixels() + TEXSIZE * y + posx, sx * 4);
- p += sx * 4;
- }
-}
-
-mogltk::Sprite::~Sprite() {
- if (prev)
- prev->next = next;
- else
- tlist->sprheader = next;
-
- if (next)
- next->prev = prev;
-
- if (!tlist->sprheader) {
- delete tlist;
- }
-}
-
-void mogltk::Sprite::alloc() {
- /* FIXMEEEEEEEEEEEEE */
- bool found = false;
- TexList * p;
-
- for (p = tlist; p && !found; p = p->GetNext()) {
- for (posy = 0; (posy < (TEXSIZE - sy)) && !found; posy++) {
- for (posx = 0; (posx < (TEXSIZE - sx)) && !found; posx++) {
- if (p->sprheader->canfit(posx, posy, posx + sx, posy + sy)) {
- found = true;
- }
- }
- }
- }
-
- if (!found) {
-#ifdef DEBUG
- printm(M_INFO, "Allocating a new texture for sprites\n");
-#endif
- posx = posy = 0;
- p = new TexList(TEXSIZE);
- }
-
- tlist = p;
-}
-
-mogltk::Sprite::TexList::TexList(int size) {
- tex = new texture(size, size, true);
-
- if (header)
- header->next->prev = this;
- prev = 0;
- next = header;
- header = this;
-}
-
-mogltk::Sprite::TexList::~TexList() {
- delete tex;
-
- if (prev)
- prev->next = next;
- else
- header = next;
-
- if (next)
- next->prev = prev;
-}
-
-const mogltk::texture * mogltk::Sprite::TexList::GetTex() const {
- return tex;
-}
-
-mogltk::texture * mogltk::Sprite::TexList::GetTex() {
- return tex;
-}
-
-const mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetHead() {
- return header;
-}
-
-const mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetNext() const {
- return next;
-}
-
-mogltk::Sprite::TexList * mogltk::Sprite::TexList::GetNext() {
- return next;
-}
-
-void mogltk::Sprite::TexList::Bind() const {
- tex->Bind();
+mogltk::glSprite::glSprite(Handle * h, int asx, int asy) : Sprite(h, asx, asy) {
}
-bool mogltk::Sprite::intersect(int x1, int y1, int x2, int y2) const {
- int sx1 = posx, sy1 = posy, sx2 = posx + sx, sy2 = posy + sy;
-
- return !((sx1 >= x2) || (sx2 <= x1) || (sy1 >= y1) || (sy2 <= y2));
+mogltk::glSprite::glSprite(Uint8 * p, int asx, int asy) : Sprite(p, asx, asy) {
}
-bool mogltk::Sprite::canfit(int x1, int y1, int x2, int y2) const {
- if (!intersect(x1, y1, x2, y2))
- return true;
- else
- if (next)
- return next->canfit(x1, y1, x2, y2);
- else
- return false;
+mogltk::glSprite::~glSprite() {
}
-void mogltk::Sprite::draw(int dx, int dy, ColorP c) {
+void mogltk::glSprite::draw(int dx, int dy, ColorP c) {
bool was2D;
- was2D = mogltk::glbase::is2D();
+ was2D = mogltk::engine::glbase_o->is2D();
if (!was2D)
- mogltk::glbase::Enter2DMode();
+ mogltk::engine::glbase_o->Enter2DMode();
c.Bind();
- tlist->Bind();
+ Bind();
glBegin(GL_TRIANGLE_STRIP);
- glTexCoord2i(posx , posy ); glVertex2i(dx , dy );
- glTexCoord2i(posx + sx - 1, posy ); glVertex2i(dx + sx - 1, dy );
- glTexCoord2i(posx , posy + sy - 1); glVertex2i(dx , dy + sy - 1);
- glTexCoord2i(posx + sx - 1, posy + sy - 1); glVertex2i(dx + sx - 1, dy + sy - 1);
+ glTexCoord2i(GetPX() , GetPY() ); glVertex2i(dx , dy );
+ glTexCoord2i(GetPX() + GetSX() - 1, GetPY() ); glVertex2i(dx + GetSX() - 1, dy );
+ glTexCoord2i(GetPX() , GetPY() + GetSY() - 1); glVertex2i(dx , dy + GetSY() - 1);
+ glTexCoord2i(GetPX() + GetSX() - 1, GetPY() + GetSY() - 1); glVertex2i(dx + GetSX() - 1, dy + GetSY() - 1);
glEnd();
if (!was2D)
- mogltk::glbase::Leave2DMode();
+ mogltk::engine::glbase_o->Leave2DMode();
}