- some indent cleanup

- came back overlay smush
- fixed smush sound
This commit is contained in:
Pawel Kolodziejski 2004-02-29 18:38:26 +00:00
parent f41465005b
commit 659b99c78b
6 changed files with 97 additions and 82 deletions

View file

@ -50,11 +50,10 @@ Resource(filename) {
if (codec == 0) { if (codec == 0) {
memcpy(data_[i], data + pos, 2 * width_ * height_); memcpy(data_[i], data + pos, 2 * width_ * height_);
pos += 2 * width_ * height_ + 8; pos += 2 * width_ * height_ + 8;
} } else if (codec == 3) {
else if (codec == 3) { int compressed_len = READ_LE_UINT32(data + pos);
int compressed_len = READ_LE_UINT32(data + pos); decompress_codec3(data + pos + 4, data_[i]);
decompress_codec3(data + pos + 4, data_[i]); pos += compressed_len + 12;
pos += compressed_len + 12;
} }
} }
@ -117,7 +116,7 @@ void Bitmap::prepareDraw() {
// For now, just keep this here :-) // For now, just keep this here :-)
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
} }
void Bitmap::draw() const { void Bitmap::draw() const {
if (format_ == 1) { // Normal image if (format_ == 1) { // Normal image
@ -158,7 +157,7 @@ void Bitmap::draw() const {
return; return;
g_driver->drawDepthBitmap(curr_image_, x_, y_, width_, height_, data_); g_driver->drawDepthBitmap(curr_image_, x_, y_, width_, height_, data_);
} }
} }
Bitmap::~Bitmap() { Bitmap::~Bitmap() {

View file

@ -71,7 +71,8 @@ Driver::Driver(int screenW, int screenH, int screenBPP) {
} }
#endif #endif
} _smushNumTex = 0;
}
void Driver::setupCamera(float fov, float nclip, float fclip, float roll) { void Driver::setupCamera(float fov, float nclip, float fclip, float roll) {
// Set perspective transformation // Set perspective transformation
@ -87,7 +88,7 @@ void Driver::setupCamera(float fov, float nclip, float fclip, float roll) {
Vector3d up_vec(0, 0, 1); Vector3d up_vec(0, 0, 1);
glRotatef(roll, 0, 0, -1); glRotatef(roll, 0, 0, -1);
} }
void Driver::positionCamera(Vector3d pos, Vector3d interest) { void Driver::positionCamera(Vector3d pos, Vector3d interest) {
Vector3d up_vec(0, 0, 1); Vector3d up_vec(0, 0, 1);
@ -163,18 +164,21 @@ void Driver::drawHackFont(int x, int y, const char *text, Color &fgColor) {
glPopMatrix(); glPopMatrix();
} }
// drawSMUSHframe, used for quickly pushing full-screen images from cutscenes void Driver::prepareSmushFrame(int width, int height, byte *bitmap) {
void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, uint8 *_dst) { // remove if already exist
int num_tex_; if (_smushNumTex > 0) {
GLuint *tex_ids_; glDeleteTextures(_smushNumTex, _smushTexIds);
delete[] _smushTexIds;
_smushNumTex = 0;
}
// create texture // create texture
num_tex_ = ((_width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) * _smushNumTex = ((width + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE) *
((_height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE); ((height + (BITMAP_TEXTURE_SIZE - 1)) / BITMAP_TEXTURE_SIZE);
tex_ids_ = new GLuint[num_tex_]; _smushTexIds = new GLuint[_smushNumTex];
glGenTextures(num_tex_, tex_ids_); glGenTextures(_smushNumTex, _smushTexIds);
for (int i = 0; i < num_tex_; i++) { for (int i = 0; i < _smushNumTex; i++) {
glBindTexture(GL_TEXTURE_2D, tex_ids_[i]); glBindTexture(GL_TEXTURE_2D, _smushTexIds[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 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_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 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_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; int curTexIdx = 0;
for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) { for (int y = 0; y < height; y += BITMAP_TEXTURE_SIZE) {
for (int x = 0; x < _width; x += 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 t_width = (x + BITMAP_TEXTURE_SIZE >= width) ? (width - x) : BITMAP_TEXTURE_SIZE;
int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE; int t_height = (y + BITMAP_TEXTURE_SIZE >= height) ? (height - y) : BITMAP_TEXTURE_SIZE;
glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]); glBindTexture(GL_TEXTURE_2D, _smushTexIds[curTexIdx]);
glTexSubImage2D(GL_TEXTURE_2D, glTexSubImage2D(GL_TEXTURE_2D,
0, 0,
0, 0, 0, 0,
width, height, t_width, t_height,
GL_RGB, GL_RGB,
GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_5_6_5,
_dst + (y * 2 * _width) + (2 * x)); bitmap + (y * 2 * width) + (2 * x));
cur_tex_idx++; curTexIdx++;
} }
} }
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); 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 // prepare view
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -228,14 +233,14 @@ void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, u
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glEnable(GL_SCISSOR_TEST); glEnable(GL_SCISSOR_TEST);
offsetY = 480 - offsetY - _height; offsetY = 480 - offsetY - _smushHeight;
cur_tex_idx = 0; int curTexIdx = 0;
for (int y = 0; y < _height; y += BITMAP_TEXTURE_SIZE) { for (int y = 0; y < _smushHeight; y += BITMAP_TEXTURE_SIZE) {
for (int x = 0; x < _width; x += BITMAP_TEXTURE_SIZE) { for (int x = 0; x < _smushWidth; x += BITMAP_TEXTURE_SIZE) {
int width = (x + BITMAP_TEXTURE_SIZE >= _width) ? (_width - x) : BITMAP_TEXTURE_SIZE; int t_width = (x + BITMAP_TEXTURE_SIZE >= _smushWidth) ? (_smushWidth - x) : BITMAP_TEXTURE_SIZE;
int height = (y + BITMAP_TEXTURE_SIZE >= _height) ? (_height - y) : BITMAP_TEXTURE_SIZE; int t_height = (y + BITMAP_TEXTURE_SIZE >= _smushHeight) ? (_smushHeight - y) : BITMAP_TEXTURE_SIZE;
glBindTexture(GL_TEXTURE_2D, tex_ids_[cur_tex_idx]); glBindTexture(GL_TEXTURE_2D, _smushTexIds[curTexIdx]);
glScissor(x, 480 - (y + height), x + width, 480 - y); glScissor(x, 480 - (y + t_height), x + t_width, 480 - y);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, 0); glTexCoord2f(0, 0);
@ -247,7 +252,7 @@ void Driver::drawSMUSHframe(int offsetX, int offsetY, int _width, int _height, u
glTexCoord2f(0.0, 1.0); glTexCoord2f(0.0, 1.0);
glVertex2i(x, y + BITMAP_TEXTURE_SIZE); glVertex2i(x, y + BITMAP_TEXTURE_SIZE);
glEnd(); 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); glDisable(GL_TEXTURE_2D);
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// remove
glDeleteTextures(num_tex_, tex_ids_);
delete[] tex_ids_;
} }

View file

@ -43,11 +43,16 @@ class Driver {
void drawBitmap(); void drawBitmap();
void drawHackFont(int x, int y, const char *text, Color &fgColor); 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: private:
GLuint hackFont; // FIXME: Temporary font drawing hack GLuint hackFont; // FIXME: Temporary font drawing hack
int _smushNumTex;
GLuint *_smushTexIds;
int _smushWidth;
int _smushHeight;
}; };
extern Driver *g_driver; extern Driver *g_driver;

View file

@ -77,57 +77,62 @@ void Engine::mainLoop() {
if (event.type == SDL_KEYDOWN) { if (event.type == SDL_KEYDOWN) {
if (event.key.keysym.sym == SDLK_q) if (event.key.keysym.sym == SDLK_q)
return; return;
}
} }
}
// Run asynchronous tasks // Run asynchronous tasks
lua_runtasks(); lua_runtasks();
if (SCREENBLOCKS_GLOBAL == 1)
screenBlocksReset();
// Update actor costumes if (SCREENBLOCKS_GLOBAL == 1)
for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) { screenBlocksReset();
Actor *a = *i;
assert(currScene_);
if (a->inSet(currScene_->name()) && a->visible())
a->update();
}
if (g_smush->isPlaying()) { // Update actor costumes
if (g_smush->isUpdateNeeded()) { for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) {
g_driver->clearScreen(); Actor *a = *i;
g_driver->drawSMUSHframe(g_smush->getX(), g_smush->getY(), g_smush->getWidth(), g_smush->getHeight(), g_smush->getDstPtr()); assert(currScene_);
g_smush->clearUpdateNeeded(); if (a->inSet(currScene_->name()) && a->visible())
a->update();
} }
} else {
glMatrixMode(GL_MODELVIEW);
g_driver->clearScreen(); g_driver->clearScreen();
if (SCREENBLOCKS_GLOBAL == 1) if (SCREENBLOCKS_GLOBAL == 1)
screenBlocksBlitDirtyBlocks(); screenBlocksBlitDirtyBlocks();
Bitmap::prepareDraw(); if (!g_smush->isPlaying() || (g_smush->isPlaying() && !g_smush->isFullSize())) {
if (currScene_ != NULL) Bitmap::prepareDraw();
currScene_->drawBackground(); 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); glEnable(GL_DEPTH_TEST);
if (currScene_ != NULL) if (currScene_ != NULL)
currScene_->setupCamera(); currScene_->setupCamera();
// Draw actors // Draw actors
glEnable(GL_TEXTURE_2D); if (!g_smush->isPlaying() || (g_smush->isPlaying() && !g_smush->isFullSize())) {
for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) { glEnable(GL_TEXTURE_2D);
Actor *a = *i; for (actor_list_type::iterator i = actors_.begin(); i != actors_.end(); i++) {
if (a->inSet(currScene_->name()) && a->visible()) Actor *a = *i;
a->draw(); if (a->inSet(currScene_->name()) && a->visible())
a->draw();
}
glDisable(GL_TEXTURE_2D);
//screenBlocksDrawDebug();
} }
glDisable(GL_TEXTURE_2D);
//screenBlocksDrawDebug();
}
// Draw text // Draw text
for (text_list_type::iterator i = textObjects_.begin(); for (text_list_type::iterator i = textObjects_.begin(); i != textObjects_.end(); i++) {
i != textObjects_.end(); i++) {
(*i)->draw(); (*i)->draw();
} }

View file

@ -118,7 +118,11 @@ void Smush::handleFrame() {
handleBlocky16(frame + pos + 8); handleBlocky16(frame + pos + 8);
pos += READ_BE_UINT32(frame + pos + 4) + 8; pos += READ_BE_UINT32(frame + pos + 4) + 8;
} else if (READ_BE_UINT32(frame + pos) == MKID_BE('Wave')) { } 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; pos += READ_BE_UINT32(frame + pos + 4) + 8;
} else { } else {
error("unknown tag"); error("unknown tag");

View file

@ -131,6 +131,7 @@ public:
int getWidth() {return _width; } int getWidth() {return _width; }
int getHeight() { return _height; } int getHeight() { return _height; }
void clearUpdateNeeded() { _updateNeeded = false; } void clearUpdateNeeded() { _updateNeeded = false; }
bool isFullSize() { return (_width == 640 && _height == 480); }
private: private:
static void timerCallback(void *ptr); static void timerCallback(void *ptr);