From 3d67f2bbbfd8676061236d22ca91aa3cef63b3fd Mon Sep 17 00:00:00 2001 From: Daniel Schepler Date: Mon, 22 Mar 2004 11:23:37 +0000 Subject: [PATCH] Implement drawing bitmapped objects. --- Makefile | 2 +- TODO | 2 +- bitmap.cpp | 7 ++----- bitmap.h | 2 -- costume.cpp | 12 ++++-------- engine.cpp | 8 ++++++-- lua.cpp | 11 +++++++---- main.cpp | 1 - objectstate.h | 21 +++++++++++++++++++++ resource.h | 3 +++ scene.cpp | 13 ++++++++++++- scene.h | 9 +++++++++ 12 files changed, 66 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index d3017566fa1..60a4f2fc1d5 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ OBJS = main.o lab.o bitmap.o model.o resource.o material.o debug.o \ textsplit.o lua.o registry.o localize.o scene.o engine.o actor.o \ sound.o timer.o keyframe.o costume.o walkplane.o textobject.o \ matrix3.o matrix4.o screen.o blocky16.o smush.o vima.o driver_gl.o \ - mixer/mixer.o mixer/rate.o mixer/audiostream.o + objectstate.o mixer/mixer.o mixer/rate.o mixer/audiostream.o DEPS = $(OBJS:.o=.d) diff --git a/TODO b/TODO index 9857e36ab4d..2b072c2df70 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,7 @@ Residual TODO list (in rough order of priority): ------------------------------------------------ Assigned tasks: * Add LAF font and text drawing support (aquadran) - * Implement drawing 2D objects (ender) + * Implement drawing 2D objects (frob) Unassigned (help wanted): * Add OpenGL lighting (ender, possibly) diff --git a/bitmap.cpp b/bitmap.cpp index f702753e2cc..88ab97ed3b1 100644 --- a/bitmap.cpp +++ b/bitmap.cpp @@ -110,7 +110,7 @@ Resource(filename) { } } -void Bitmap::prepareDraw() { +void Bitmap::draw() const { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, 640, 480, 0, 0, 1); @@ -122,9 +122,6 @@ void Bitmap::prepareDraw() { // For now, just keep this here :-) glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); -} - -void Bitmap::draw() const { if (format_ == 1) { // Normal image if (curr_image_ != 0) { warning("Animation not handled yet in GL texture path !\n"); @@ -132,13 +129,13 @@ void Bitmap::draw() const { glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glEnable(GL_SCISSOR_TEST); + glScissor(x_, 480 - (y_ + height_), width_, height_); int cur_tex_idx = 0; for (int y = y_; y < (y_ + height_); y += BITMAP_TEXTURE_SIZE) { for (int x = x_; x < (x_ + width_); x += BITMAP_TEXTURE_SIZE) { int width = (x + BITMAP_TEXTURE_SIZE >= (x_ + width_)) ? ((x_ + width_) - x) : BITMAP_TEXTURE_SIZE; int height = (y + BITMAP_TEXTURE_SIZE >= (y_ + height_)) ? ((y_ + height_) - y) : BITMAP_TEXTURE_SIZE; glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]); - glScissor(x, 480 - (y + height), x + width, 480 - y); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2i(x, y); diff --git a/bitmap.h b/bitmap.h index 2d7242d8dea..f9d6592df35 100644 --- a/bitmap.h +++ b/bitmap.h @@ -27,8 +27,6 @@ public: // Construct a bitmap from the given data. Bitmap(const char *filename, const char *data, int len); - // Set up Driver for drawing bitmaps - static void prepareDraw(); void draw() const; // Set which image in an animated bitmap to use diff --git a/costume.cpp b/costume.cpp index 7dfa94e6122..fbb53589aa8 100644 --- a/costume.cpp +++ b/costume.cpp @@ -87,14 +87,12 @@ class BitmapComponent : public Costume::Component { public: BitmapComponent(Costume::Component *parent, int parentID, const char *filename); - void update(); - void draw(); + void setKey(int val); private: std::string filename_; std::string zbuf_filename_; ResPtr bitmap_; - ResPtr zbuffer_; }; class ModelComponent : public Costume::Component { @@ -158,13 +156,11 @@ BitmapComponent::BitmapComponent(Costume::Component *parent, int parentID, Costume::Component(parent, parentID), filename_(filename) { bitmap_ = ResourceLoader::instance()->loadBitmap(filename); - warning("Instanced BitmapComponenet from Costume renderer: NOT IMPLEMENTED YET"); + warning("Instanced BitmapComponenet from Costume renderer with filename %s: NOT IMPLEMENTED YET", filename); } -void BitmapComponent::draw() { -} - -void BitmapComponent::update() { +void BitmapComponent::setKey(int val) { + // bitmap_->setNumber(val); } ModelComponent::ModelComponent(Costume::Component *parent, int parentID, diff --git a/engine.cpp b/engine.cpp index 7eed8e777d1..625add3e470 100644 --- a/engine.cpp +++ b/engine.cpp @@ -112,9 +112,11 @@ void Engine::mainLoop() { if (SCREENBLOCKS_GLOBAL == 1) screenBlocksBlitDirtyBlocks(); - Bitmap::prepareDraw(); - if (currScene_ != NULL) + if (currScene_ != NULL) { currScene_->drawBackground(); + currScene_->drawBitmaps(ObjectState::OBJSTATE_UNDERLAY); + currScene_->drawBitmaps(ObjectState::OBJSTATE_STATE); + } if (g_smush->isPlaying()) { movieTime_ = g_smush->getMovieTime(); @@ -148,6 +150,8 @@ void Engine::mainLoop() { (*i)->draw(); } + currScene_->drawBitmaps(ObjectState::OBJSTATE_OVERLAY); + g_driver->flipBuffer(); } diff --git a/lua.cpp b/lua.cpp index 31b89d1d452..860d55d125b 100644 --- a/lua.cpp +++ b/lua.cpp @@ -1087,8 +1087,8 @@ static void NewObjectState() { ObjectState::Position pos = check_objstate_pos(2); // When to draw char *bitmap = luaL_check_string(3); // Bitmap char *zbitmap = NULL; // Zbuffer Bitmap - bool unk2 = getbool(5); // ? - bool unk3 = getbool(6); + bool unk1 = getbool(5); // ? + bool unk2 = getbool(6); if (!lua_isnil(lua_getparam(4))) zbitmap = luaL_check_string(4); @@ -1096,8 +1096,11 @@ static void NewObjectState() { #ifndef OSX warning("Stub: newObjectState(%d, %d, %s, %s)", setupID, pos, bitmap, zbitmap); #endif - // object = scene.addObjectState; - // lua_pushusertag(object, object_tag); + + object = new ObjectState(setupID, pos, bitmap, zbitmap, + unk1, unk2); + Engine::instance()->currScene()->addObjectState(object); + lua_pushusertag(object, object_tag); } static void FreeObjectState() { diff --git a/main.cpp b/main.cpp index 78796006a04..12584047bee 100644 --- a/main.cpp +++ b/main.cpp @@ -98,7 +98,6 @@ int main(int argc, char *argv[]) { #endif g_driver->clearScreen(); - Bitmap::prepareDraw(); splash_bm->draw(); g_driver->flipBuffer(); diff --git a/objectstate.h b/objectstate.h index eb1229c79a5..31882f22c41 100644 --- a/objectstate.h +++ b/objectstate.h @@ -3,6 +3,7 @@ #include "vector3d.h" #include "resource.h" +#include "bitmap.h" #include #include @@ -14,6 +15,26 @@ class ObjectState { OBJSTATE_OVERLAY = 2, OBJSTATE_STATE = 3 }; + + ObjectState(int setupID, ObjectState::Position pos, + const char *bitmap, const char *zbitmap, + bool unk1, bool unk2); + + int setupID() const { return setupID_; } + Position pos() const { return pos_; } + const char *bitmapFilename() const { + return bitmap_->filename(); + } + + void draw() { + bitmap_->draw(); + } + + private: + int setupID_; + Position pos_; + ResPtr bitmap_, zbitmap_; + bool unk1_, unk2_; }; diff --git a/resource.h b/resource.h index 00a7610fba2..90c38030b19 100644 --- a/resource.h +++ b/resource.h @@ -57,8 +57,11 @@ public: ResPtr(const ResPtr &p) { ptr_ = p.ptr_; if (ptr_ != NULL) ptr_->ref(); } ResPtr(T* ptr) { ptr_ = ptr; if (ptr_ != NULL) ptr_->ref(); } operator T*() { return ptr_; } + operator const T*() const { return ptr_; } T& operator *() { return *ptr_; } + const T& operator *() const { return *ptr_; } T* operator ->() { return ptr_; } + const T* operator ->() const { return ptr_; } ResPtr& operator =(T* ptr) { if (ptr_ == ptr) return *this; if (ptr_ != NULL) ptr_->deref(); diff --git a/scene.cpp b/scene.cpp index b80d1e84702..d6f9dc13f2b 100644 --- a/scene.cpp +++ b/scene.cpp @@ -91,7 +91,10 @@ Scene::~Scene() { if (lights_) delete [] lights_; if (sectors_) - delete [] sectors_; + delete [] sectors_; + for (StateList::iterator i = states_.begin(); + i != states_.end(); i++) + delete (*i); } void Scene::Setup::load(TextSplitter &ts) { @@ -158,3 +161,11 @@ void Scene::setSetup(int num) { else screenBlocksInitEmpty(); } + +void Scene::drawBitmaps(ObjectState::Position stage) { + for (StateList::iterator i = states_.begin(); i != states_.end(); + i++) { + if ((*i)->pos() == stage && currSetup_ == setups_ + (*i)->setupID()) + (*i)->draw(); + } +} diff --git a/scene.h b/scene.h index 68f91eecbd3..d712f133f2a 100644 --- a/scene.h +++ b/scene.h @@ -23,6 +23,7 @@ #include "color.h" #include "debug.h" #include "walkplane.h" +#include "objectstate.h" #include #include #include @@ -47,6 +48,7 @@ public: } currSetup_->bkgnd_bm_->draw(); } + void drawBitmaps(ObjectState::Position stage); void setupCamera() { currSetup_->setupCamera(); } @@ -65,6 +67,10 @@ public: return NULL; } + void addObjectState(ObjectState *s) { + states_.push_back(s); + } + private: struct Setup { // Camera setup data void load(TextSplitter &ts); @@ -92,6 +98,9 @@ private: Light *lights_; Setup *setups_; Setup *currSetup_; + + typedef std::list StateList; + StateList states_; }; #endif