From 659b99c78bbe252e66cfef8a9262bcca46dfd287 Mon Sep 17 00:00:00 2001 From: Pawel Kolodziejski Date: Sun, 29 Feb 2004 18:38:26 +0000 Subject: [PATCH] - some indent cleanup - came back overlay smush - fixed smush sound --- bitmap.cpp | 13 ++++----- driver_gl.cpp | 77 ++++++++++++++++++++++++++------------------------- driver_gl.h | 9 ++++-- engine.cpp | 73 +++++++++++++++++++++++++----------------------- smush.cpp | 6 +++- smush.h | 1 + 6 files changed, 97 insertions(+), 82 deletions(-) diff --git a/bitmap.cpp b/bitmap.cpp index 3649dfa6190..cfc60e4b175 100644 --- a/bitmap.cpp +++ b/bitmap.cpp @@ -50,11 +50,10 @@ Resource(filename) { if (codec == 0) { memcpy(data_[i], data + pos, 2 * width_ * height_); pos += 2 * width_ * height_ + 8; - } - else if (codec == 3) { - int compressed_len = READ_LE_UINT32(data + pos); - decompress_codec3(data + pos + 4, data_[i]); - pos += compressed_len + 12; + } else if (codec == 3) { + int compressed_len = READ_LE_UINT32(data + pos); + decompress_codec3(data + pos + 4, data_[i]); + pos += compressed_len + 12; } } @@ -117,7 +116,7 @@ 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 @@ -158,7 +157,7 @@ void Bitmap::draw() const { return; g_driver->drawDepthBitmap(curr_image_, x_, y_, width_, height_, data_); - } + } } Bitmap::~Bitmap() { diff --git a/driver_gl.cpp b/driver_gl.cpp index f0cc45e1cca..d3ba736f277 100644 --- a/driver_gl.cpp +++ b/driver_gl.cpp @@ -71,7 +71,8 @@ Driver::Driver(int screenW, int screenH, int screenBPP) { } #endif - } + _smushNumTex = 0; +} void Driver::setupCamera(float fov, float nclip, float fclip, float roll) { // Set perspective transformation @@ -87,7 +88,7 @@ void Driver::setupCamera(float fov, float nclip, float fclip, float roll) { Vector3d up_vec(0, 0, 1); glRotatef(roll, 0, 0, -1); - } +} void Driver::positionCamera(Vector3d pos, Vector3d interest) { Vector3d up_vec(0, 0, 1); @@ -163,18 +164,21 @@ void Driver::drawHackFont(int x, int y, const char *text, Color &fgColor) { glPopMatrix(); } -// drawSMUSHframe, used for quickly pushing full-screen images from cutscenes -void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, uint8 *_dst) { - int num_tex_; - GLuint *tex_ids_; +void Driver::prepareSmushFrame(int width, int height, byte *bitmap) { + // remove if already exist + if (_smushNumTex > 0) { + glDeleteTextures(_smushNumTex, _smushTexIds); + delete[] _smushTexIds; + _smushNumTex = 0; + } // create texture - num_tex_ = ((_width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) * - ((_height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE); - tex_ids_ = new GLuint[num_tex_]; - glGenTextures(num_tex_, tex_ids_); - for (int i = 0; i < num_tex_; i++) { - glBindTexture(GL_TEXTURE_2D, tex_ids_[i]); + _smushNumTex = ((width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) * + ((height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE); + _smushTexIds = new GLuint[_smushNumTex]; + glGenTextures(_smushNumTex, _smushTexIds); + for (int i = 0; i < _smushNumTex; i++) { + glBindTexture(GL_TEXTURE_2D, _smushTexIds[i]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); @@ -185,30 +189,31 @@ void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, u } glPixelStorei(GL_UNPACK_ALIGNMENT, 2); - glPixelStorei(GL_UNPACK_ROW_LENGTH, _width); - glPixelStorei(GL_UNPACK_ROW_LENGTH, _width); + glPixelStorei(GL_UNPACK_ROW_LENGTH, width); - int cur_tex_idx = 0; - for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) { - for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) { - int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE; - int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE; - glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]); + int curTexIdx = 0; + for (int y = 0; y < height; y += BITMAP_TEXTURE_SIZE) { + for (int x = 0; x < width; x += BITMAP_TEXTURE_SIZE) { + int t_width = (x + BITMAP_TEXTURE_SIZE >= width) ? (width - x) : BITMAP_TEXTURE_SIZE; + int t_height = (y + BITMAP_TEXTURE_SIZE >= height) ? (height - y) : BITMAP_TEXTURE_SIZE; + glBindTexture(GL_TEXTURE_2D, _smushTexIds[curTexIdx]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, - width, height, + t_width, t_height, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, - _dst + (y * 2 * _width) + (2 * x)); - cur_tex_idx++; + bitmap + (y * 2 * width) + (2 * x)); + curTexIdx++; } } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + _smushWidth = width; + _smushHeight = height; +} -// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - +void Driver::drawSmushFrame(int offsetX, int offsetY) { // prepare view glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -228,14 +233,14 @@ void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, u glDepthMask(GL_FALSE); glEnable(GL_SCISSOR_TEST); - offsetY = 480 - offsetY - _height; - cur_tex_idx = 0; - for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) { - for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) { - int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE; - int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE; - glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]); - glScissor(x, 480 - (y + height), x + width, 480 - y); + offsetY = 480 - offsetY - _smushHeight; + int curTexIdx = 0; + for (int y = 0; y < _smushHeight; y += BITMAP_TEXTURE_SIZE) { + for (int x = 0; x < _smushWidth; x += BITMAP_TEXTURE_SIZE) { + int t_width = (x + BITMAP_TEXTURE_SIZE >= _smushWidth) ? (_smushWidth - x) : BITMAP_TEXTURE_SIZE; + int t_height = (y + BITMAP_TEXTURE_SIZE >= _smushHeight) ? (_smushHeight - y) : BITMAP_TEXTURE_SIZE; + glBindTexture(GL_TEXTURE_2D, _smushTexIds[curTexIdx]); + glScissor(x, 480 - (y + t_height), x + t_width, 480 - y); glBegin(GL_QUADS); glTexCoord2f(0, 0); @@ -247,7 +252,7 @@ void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, u glTexCoord2f(0.0, 1.0); glVertex2i(x, y + BITMAP_TEXTURE_SIZE); glEnd(); - cur_tex_idx++; + curTexIdx++; } } @@ -255,8 +260,4 @@ void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, u glDisable(GL_TEXTURE_2D); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); - - // remove - glDeleteTextures(num_tex_, tex_ids_); - delete[] tex_ids_; } diff --git a/driver_gl.h b/driver_gl.h index 5bd66f9e089..b0512ce5a16 100644 --- a/driver_gl.h +++ b/driver_gl.h @@ -43,11 +43,16 @@ class Driver { void drawBitmap(); void drawHackFont(int x, int y, const char *text, Color &fgColor); - void drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, uint8 *_dst); + + void prepareSmushFrame(int width, int height, byte *bitmap); + void drawSmushFrame(int offsetX, int offsetY); private: GLuint hackFont; // FIXME: Temporary font drawing hack - + int _smushNumTex; + GLuint *_smushTexIds; + int _smushWidth; + int _smushHeight; }; extern Driver *g_driver; diff --git a/engine.cpp b/engine.cpp index a20728420e2..0eb9c64a0ea 100644 --- a/engine.cpp +++ b/engine.cpp @@ -77,57 +77,62 @@ void Engine::mainLoop() { if (event.type == SDL_KEYDOWN) { if (event.key.keysym.sym == SDLK_q) return; + } } - } - // Run asynchronous tasks - lua_runtasks(); - if (SCREENBLOCKS_GLOBAL == 1) - screenBlocksReset(); + // Run asynchronous tasks + lua_runtasks(); - // Update actor costumes - for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) { - Actor *a = *i; - assert(currScene_); - if (a->inSet(currScene_->name()) && a->visible()) - a->update(); - } + if (SCREENBLOCKS_GLOBAL == 1) + screenBlocksReset(); + + // Update actor costumes + for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) { + Actor *a = *i; + assert(currScene_); + if (a->inSet(currScene_->name()) && a->visible()) + a->update(); + } - if (g_smush->isPlaying()) { - if (g_smush->isUpdateNeeded()) { - g_driver->clearScreen(); - g_driver->drawSMUSHframe(g_smush->getX(), g_smush->getY(), g_smush->getWidth(), g_smush->getHeight(), g_smush->getDstPtr()); - g_smush->clearUpdateNeeded(); - } - } else { - glMatrixMode(GL_MODELVIEW); g_driver->clearScreen(); if (SCREENBLOCKS_GLOBAL == 1) screenBlocksBlitDirtyBlocks(); - Bitmap::prepareDraw(); - if (currScene_ != NULL) - currScene_->drawBackground(); + if (!g_smush->isPlaying() || (g_smush->isPlaying() && !g_smush->isFullSize())) { + Bitmap::prepareDraw(); + if (currScene_ != NULL) + currScene_->drawBackground(); + } + + if (g_smush->isPlaying()) { + if (g_smush->isUpdateNeeded()) { + g_driver->prepareSmushFrame(g_smush->getWidth(), g_smush->getHeight(), g_smush->getDstPtr()); + g_smush->clearUpdateNeeded(); + } + g_driver->drawSmushFrame(g_smush->getX(), g_smush->getY()); + } + + glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); if (currScene_ != NULL) currScene_->setupCamera(); // Draw actors - glEnable(GL_TEXTURE_2D); - for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) { - Actor *a = *i; - if (a->inSet(currScene_->name()) && a->visible()) - a->draw(); + if (!g_smush->isPlaying() || (g_smush->isPlaying() && !g_smush->isFullSize())) { + glEnable(GL_TEXTURE_2D); + for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) { + Actor *a = *i; + if (a->inSet(currScene_->name()) && a->visible()) + a->draw(); + } + glDisable(GL_TEXTURE_2D); + //screenBlocksDrawDebug(); } - glDisable(GL_TEXTURE_2D); - //screenBlocksDrawDebug(); - } - // Draw text - for (text_list_type::iterator i = textObjects_.begin(); - i != textObjects_.end(); i++) { + // Draw text + for (text_list_type::iterator i = textObjects_.begin(); i != textObjects_.end(); i++) { (*i)->draw(); } diff --git a/smush.cpp b/smush.cpp index 18a14a32f9a..066fd9fffa3 100644 --- a/smush.cpp +++ b/smush.cpp @@ -118,7 +118,11 @@ void Smush::handleFrame() { handleBlocky16(frame + pos + 8); pos += READ_BE_UINT32(frame + pos + 4) + 8; } else if (READ_BE_UINT32(frame + pos) == MKID_BE('Wave')) { -// handleWave(frame + pos + 8 + 4, READ_BE_UINT32(frame + pos + 8)); + int decompressed_size = READ_BE_UINT32(frame + pos + 8); + if (decompressed_size < 0) + handleWave(frame + pos + 8 + 4 + 8, READ_BE_UINT32(frame + pos + 8 + 8)); + else + handleWave(frame + pos + 8 + 4, decompressed_size); pos += READ_BE_UINT32(frame + pos + 4) + 8; } else { error("unknown tag"); diff --git a/smush.h b/smush.h index a6862e49b32..6ee19579258 100644 --- a/smush.h +++ b/smush.h @@ -131,6 +131,7 @@ public: int getWidth() {return _width; } int getHeight() { return _height; } void clearUpdateNeeded() { _updateNeeded = false; } + bool isFullSize() { return (_width == 640 && _height == 480); } private: static void timerCallback(void *ptr);