From c2f1691bada2c0e945b206e5ed71752f0ba569b5 Mon Sep 17 00:00:00 2001 From: Andrew Kurushin Date: Sat, 9 Jul 2005 16:23:45 +0000 Subject: gfx rearangement code cleanups svn-id: r18523 --- saga/actor.cpp | 18 +-- saga/animation.cpp | 6 +- saga/events.cpp | 58 +++---- saga/font.cpp | 4 +- saga/font.h | 4 +- saga/game.cpp | 2 +- saga/gfx.cpp | 402 +++++++----------------------------------------- saga/gfx.h | 76 +++++---- saga/ihnm_introproc.cpp | 8 +- saga/interface.cpp | 80 +++++----- saga/interface.h | 24 +-- saga/isomap.cpp | 23 ++- saga/isomap.h | 16 +- saga/objectmap.cpp | 8 +- saga/objectmap.h | 4 +- saga/palanim.cpp | 6 +- saga/palanim.h | 2 +- saga/puzzle.cpp | 4 +- saga/render.cpp | 110 +++---------- saga/render.h | 51 +++--- saga/saga.h | 6 +- saga/scene.cpp | 35 +++-- saga/scene.h | 10 +- saga/sfuncs.cpp | 23 ++- saga/sprite.cpp | 18 +-- saga/sprite.h | 8 +- saga/text.cpp | 4 +- saga/transitions.cpp | 2 +- 28 files changed, 324 insertions(+), 688 deletions(-) (limited to 'saga') diff --git a/saga/actor.cpp b/saga/actor.cpp index 16d6cffe77..53d6e52f3b 100644 --- a/saga/actor.cpp +++ b/saga/actor.cpp @@ -62,7 +62,7 @@ static int commonObjectCompare(const CommonObjectDataPointer& obj1, const Common static int tileCommonObjectCompare(const CommonObjectDataPointer& obj1, const CommonObjectDataPointer& obj2) { int p1 = -obj1->location.u() - obj1->location.v() - obj1->location.z; int p2 = -obj2->location.u() - obj2->location.v() - obj2->location.z; - //TODO: for kObjNotFlat obj Height*3 of sprite should be adde to p1 and p2 + //TODO: for kObjNotFlat obj Height*3 of sprite should be added to p1 and p2 //if (validObjId(obj1->id)) { if (p1 == p2) { @@ -1376,9 +1376,9 @@ void Actor::drawActors() { int frameNumber; SpriteList *spriteList; - SURFACE *back_buf; + Surface *backBuffer; - back_buf = _vm->_gfx->getBackBuffer(); + backBuffer = _vm->_gfx->getBackBuffer(); createDrawOrderList(); @@ -1391,9 +1391,9 @@ void Actor::drawActors() { if (_vm->_scene->getFlags() & kSceneFlagISO) { - _vm->_isoMap->drawSprite(back_buf, *spriteList, frameNumber, drawObject->location, drawObject->screenPosition, drawObject->screenScale); + _vm->_isoMap->drawSprite(backBuffer, *spriteList, frameNumber, drawObject->location, drawObject->screenPosition, drawObject->screenScale); } else { - _vm->_sprite->drawOccluded(back_buf, _vm->_scene->getSceneClip(),*spriteList, frameNumber, drawObject->screenPosition, drawObject->screenScale, drawObject->screenDepth); + _vm->_sprite->drawOccluded(backBuffer, _vm->_scene->getSceneClip(),*spriteList, frameNumber, drawObject->screenPosition, drawObject->screenScale, drawObject->screenDepth); } } @@ -1407,9 +1407,9 @@ void Actor::drawSpeech(void) { char oneChar[2]; oneChar[1] = 0; const char *outputString; - SURFACE *back_buf; + Surface *backBuffer; - back_buf = _vm->_gfx->getBackBuffer(); + backBuffer = _vm->_gfx->getBackBuffer(); if (_activeSpeech.speechFlags & kSpeakSlow) { outputString = oneChar; @@ -1426,7 +1426,7 @@ void Actor::drawSpeech(void) { if (_activeSpeech.actorIds[0] != 0) { for (i = 0; i < _activeSpeech.actorsCount; i++){ - _vm->textDraw(MEDIUM_FONT_ID, back_buf, outputString, + _vm->textDraw(MEDIUM_FONT_ID, backBuffer, outputString, _activeSpeech.speechCoords[i].x, _activeSpeech.speechCoords[i].y, _activeSpeech.speechColor[i], @@ -2647,7 +2647,7 @@ void Actor::removePathPoints() { void Actor::drawPathTest() { #ifdef ACTOR_DEBUG int i; - SURFACE *surface; + Surface *surface; surface = _vm->_gfx->getBackBuffer(); if (_debugPoints == NULL) { return; diff --git a/saga/animation.cpp b/saga/animation.cpp index b3a48a3b80..c512773cc9 100644 --- a/saga/animation.cpp +++ b/saga/animation.cpp @@ -117,7 +117,7 @@ void Anim::setCycles(uint16 animId, int cycles) { void Anim::play(uint16 animId, int vectorTime, bool playing) { EVENT event; - BUFFER_INFO buf_info; + Surface *backGroundSurface; byte *displayBuffer; @@ -133,8 +133,8 @@ void Anim::play(uint16 animId, int vectorTime, bool playing) { anim = getAnimation(animId); - _vm->_render->getBufferInfo(&buf_info); - displayBuffer = buf_info.bg_buf; + backGroundSurface = _vm->_render->getBackGroundSurface(); + displayBuffer = (byte*)backGroundSurface->pixels; if (playing) { diff --git a/saga/events.cpp b/saga/events.cpp index 05ea6563e7..739227c220 100644 --- a/saga/events.cpp +++ b/saga/events.cpp @@ -124,7 +124,7 @@ int Events::handleContinuous(EVENT *event) { double event_pc = 0.0; // Event completion percentage int event_done = 0; - BUFFER_INFO buf_info; + Surface *backGroundSurface; BGInfo bgInfo; event_pc = ((double)event->duration - event->time) / event->duration; @@ -148,11 +148,11 @@ int Events::handleContinuous(EVENT *event) { case PAL_EVENT: switch (event->op) { case EVENT_BLACKTOPAL: - _vm->_gfx->blackToPal((PALENTRY *)event->data, event_pc); + _vm->_gfx->blackToPal((PalEntry *)event->data, event_pc); break; case EVENT_PALTOBLACK: - _vm->_gfx->palToBlack((PALENTRY *)event->data, event_pc); + _vm->_gfx->palToBlack((PalEntry *)event->data, event_pc); break; default: break; @@ -161,11 +161,10 @@ int Events::handleContinuous(EVENT *event) { case TRANSITION_EVENT: switch (event->op) { case EVENT_DISSOLVE: - _vm->_render->getBufferInfo(&buf_info); + backGroundSurface = _vm->_render->getBackGroundSurface(); _vm->_scene->getBGInfo(bgInfo); - _vm->transitionDissolve(buf_info.bg_buf, buf_info.bg_buf_w, - buf_info.bg_buf_h, buf_info.bg_buf_w, bgInfo.buffer, bgInfo.bounds.width(), - bgInfo.bounds.height(), 0, 0, 0, event_pc); + _vm->transitionDissolve((byte*)backGroundSurface->pixels, backGroundSurface->w, + backGroundSurface->h, bgInfo.buffer, bgInfo.bounds.width(), bgInfo.bounds.height(), 0, 0, 0, event_pc); break; case EVENT_DISSOLVE_BGMASK: // we dissolve it centered. @@ -174,10 +173,10 @@ int Events::handleContinuous(EVENT *event) { byte *mask_buf; size_t len; - _vm->_render->getBufferInfo(&buf_info); + backGroundSurface = _vm->_render->getBackGroundSurface(); _vm->_scene->getBGMaskInfo(w, h, mask_buf, len); - _vm->transitionDissolve(buf_info.bg_buf, buf_info.bg_buf_w, - buf_info.bg_buf_h, buf_info.bg_buf_w, mask_buf, w, h, 1, + _vm->transitionDissolve((byte*)backGroundSurface->pixels, backGroundSurface->w, + backGroundSurface->h, mask_buf, w, h, 1, (_vm->getDisplayWidth() - w) / 2, (_vm->getDisplayHeight() - h) / 2, event_pc); break; default: @@ -221,11 +220,11 @@ int Events::handleImmediate(EVENT *event) { case PAL_EVENT: switch (event->op) { case EVENT_BLACKTOPAL: - _vm->_gfx->blackToPal((PALENTRY *)event->data, event_pc); + _vm->_gfx->blackToPal((PalEntry *)event->data, event_pc); break; case EVENT_PALTOBLACK: - _vm->_gfx->palToBlack((PALENTRY *)event->data, event_pc); + _vm->_gfx->palToBlack((PalEntry *)event->data, event_pc); break; default: break; @@ -250,11 +249,10 @@ int Events::handleImmediate(EVENT *event) { } int Events::handleOneShot(EVENT *event) { - SURFACE *back_buf; + Surface *backBuffer; ScriptThread *sthread; Rect rect; - static BGInfo bgInfo; if (event->time > 0) { return EVENT_CONTINUE; @@ -293,29 +291,19 @@ int Events::handleOneShot(EVENT *event) { break; case BG_EVENT: { - BUFFER_INFO rbuf_info; - Point bg_pt; + Surface *backGroundSurface; + BGInfo bgInfo; if (!(_vm->_scene->getFlags() & kSceneFlagISO)) { - back_buf = _vm->_gfx->getBackBuffer(); - - _vm->_render->getBufferInfo(&rbuf_info); + backBuffer = _vm->_gfx->getBackBuffer(); + backGroundSurface = _vm->_render->getBackGroundSurface(); _vm->_scene->getBGInfo(bgInfo); - bg_pt.x = bgInfo.bounds.left; - bg_pt.y = bgInfo.bounds.top; - - bufToBuffer(rbuf_info.bg_buf, rbuf_info.bg_buf_w, rbuf_info.bg_buf_h, - bgInfo.buffer, bgInfo.bounds.width(), bgInfo.bounds.height(), NULL, &bg_pt); + backGroundSurface->blit(bgInfo.bounds, bgInfo.buffer); // If it is inset scene then draw black border if (bgInfo.bounds.width() < _vm->getDisplayWidth() || bgInfo.bounds.height() < _vm->getSceneHeight()) { - SURFACE s; - s.pixels = rbuf_info.bg_buf; - s.w = s.pitch = rbuf_info.bg_buf_w; - s.h = rbuf_info.bg_buf_h; - s.bytesPerPixel = 1; Common::Rect rect1(2, bgInfo.bounds.height() + 4); Common::Rect rect2(bgInfo.bounds.width() + 4, 2); Common::Rect rect3(2, bgInfo.bounds.height() + 4); @@ -325,14 +313,14 @@ int Events::handleOneShot(EVENT *event) { rect3.moveTo(bgInfo.bounds.right, bgInfo.bounds.top - 2); rect4.moveTo(bgInfo.bounds.left - 2, bgInfo.bounds.bottom); - drawRect(&s, rect1, kITEColorBlack); - drawRect(&s, rect2, kITEColorBlack); - drawRect(&s, rect3, kITEColorBlack); - drawRect(&s, rect4, kITEColorBlack); + backGroundSurface->drawRect(rect1, kITEColorBlack); + backGroundSurface->drawRect(rect2, kITEColorBlack); + backGroundSurface->drawRect(rect3, kITEColorBlack); + backGroundSurface->drawRect(rect4, kITEColorBlack); } if (event->param == SET_PALETTE) { - PALENTRY *pal_p; + PalEntry *pal_p; _vm->_scene->getBGPal(&pal_p); _vm->_gfx->setPalette(pal_p); } @@ -450,7 +438,7 @@ int Events::handleOneShot(EVENT *event) { rect.bottom = event->param3; rect.left = event->param4; rect.right = event->param5; - drawRect((SURFACE *)event->data, rect, event->param); + ((Surface *)event->data)->drawRect(rect, event->param); break; case EVENT_SETFLAG: _vm->_render->setFlag(event->param); diff --git a/saga/font.cpp b/saga/font.cpp index 124e7af6f4..c18f9f338f 100644 --- a/saga/font.cpp +++ b/saga/font.cpp @@ -360,7 +360,7 @@ int Font::getStringWidth(int font_id, const char *test_str, size_t test_str_ct, return width; } -int Font::draw(int font_id, SURFACE *ds, const char *draw_str, size_t draw_str_ct, +int Font::draw(int font_id, Surface *ds, const char *draw_str, size_t draw_str_ct, int text_x, int text_y, int color, int effect_color, int flags) { FONT *font; @@ -387,7 +387,7 @@ int Font::draw(int font_id, SURFACE *ds, const char *draw_str, size_t draw_str_c return SUCCESS; } -int Font::outFont(FONT_STYLE * draw_font, SURFACE * ds, const char *draw_str, size_t draw_str_ct, +int Font::outFont(FONT_STYLE * draw_font, Surface *ds, const char *draw_str, size_t draw_str_ct, int text_x, int text_y, int color, int flags) { const byte *draw_str_p; byte *c_data_ptr; diff --git a/saga/font.h b/saga/font.h index 42bf6c3933..5e1043aae4 100644 --- a/saga/font.h +++ b/saga/font.h @@ -101,7 +101,7 @@ class Font { public: Font(SagaEngine *vm); ~Font(void); - int draw(int font_id, SURFACE *ds, const char *draw_str, size_t draw_str_len, + int draw(int font_id, Surface *ds, const char *draw_str, size_t draw_str_len, int text_x, int text_y, int color, int effect_color, int flags); int getStringWidth(int font_id, const char *test_str, size_t test_str_ct, int flags); int getHeight(int font_id); @@ -110,7 +110,7 @@ class Font { int loadFont(uint32 fontResourceId); FONT_STYLE *createOutline(FONT_STYLE * src_font); - int outFont(FONT_STYLE *font, SURFACE * ds, const char *draw_str, size_t draw_str_ct, + int outFont(FONT_STYLE *font, Surface *ds, const char *draw_str, size_t draw_str_ct, int text_x, int text_y, int color, int flags); int getByteLen(int num_bits); diff --git a/saga/game.cpp b/saga/game.cpp index f885fd7c0f..74d299733c 100644 --- a/saga/game.cpp +++ b/saga/game.cpp @@ -122,7 +122,7 @@ static GameDisplayInfo ITE_DisplayInfo = { 0, // status x offset 137, // status y offset 320, // status width - 12, // status height + 11, // status height 2, // status text y offset 186, // status text color 15, // status BG color diff --git a/saga/gfx.cpp b/saga/gfx.cpp index 2c2439608c..0edeefc653 100644 --- a/saga/gfx.cpp +++ b/saga/gfx.cpp @@ -32,8 +32,6 @@ namespace Saga { Gfx::Gfx(OSystem *system, int width, int height, GameDetector &detector) : _system(system) { - SURFACE back_buf; - _system->beginGFXTransaction(); _vm->initCommonGFX(detector); _system->initSize(width, height); @@ -41,19 +39,9 @@ Gfx::Gfx(OSystem *system, int width, int height, GameDetector &detector) : _syst debug(5, "Init screen %dx%d", width, height); // Convert surface data to R surface data - back_buf.pixels = calloc(1, width * height); - back_buf.w = width; - back_buf.h = height; - back_buf.pitch = width; - back_buf.bytesPerPixel = 1; - - back_buf.clip_rect.left = 0; - back_buf.clip_rect.top = 0; - back_buf.clip_rect.right = width; - back_buf.clip_rect.bottom = height; + _backBuffer.create(width, height, 1); // Set module data - _back_buf = back_buf; _init = 1; // For now, always show the mouse cursor. @@ -61,376 +49,108 @@ Gfx::Gfx(OSystem *system, int width, int height, GameDetector &detector) : _syst _system->showMouse(true); } -/* -~Gfx() { - free(GfxModule.r_back_buf->pixels); + +Gfx::~Gfx() { + _backBuffer.free(); } - */ -int drawPalette(SURFACE *dst_s) { + +void Surface::drawPalette() { int x; int y; int color = 0; - - Rect pal_rect; + Rect palRect; for (y = 0; y < 16; y++) { - pal_rect.top = (y * 8) + 4; - pal_rect.bottom = pal_rect.top + 8; + palRect.top = (y * 8) + 4; + palRect.bottom = palRect.top + 8; for (x = 0; x < 16; x++) { - pal_rect.left = (x * 8) + 4; - pal_rect.right = pal_rect.left + 8; + palRect.left = (x * 8) + 4; + palRect.right = palRect.left + 8; - drawRect(dst_s, pal_rect, color); + drawRect(palRect, color); color++; } } - - return 0; } -// TODO: I've fixed at least one clipping bug here, but I have a feeling there -// are several more. - // * Copies a rectangle from a raw 8 bit pixel buffer to the specified surface. -// The buffer is of width 'src_w' and height 'src_h'. The rectangle to be -// copied is defined by 'src_rect'. -// The rectangle is copied to the destination surface at point 'dst_pt'. -// - If dst_pt is NULL, the buffer is rectangle is copied to the destination -// origin. -// - If src_rect is NULL, the entire buffer is copied./ // - The surface must match the logical dimensions of the buffer exactly. -// - Returns FAILURE on error -int bufToSurface(SURFACE *ds, const byte *src, int src_w, int src_h, - Rect *src_rect, Point *dst_pt) { - const byte *read_p; - byte *write_p; - - int row; - - Common::Rect s; - int d_x, d_y; - - Common::Rect clip; - - int dst_off_x, dst_off_y; - int src_off_x, src_off_y; - int src_draw_w, src_draw_h; - - // Clamp source rectangle to source buffer - if (src_rect != NULL) { - src_rect->clip(src_w, src_h); - - s = *src_rect; - } else { - s.left = 0; - s.top = 0; - s.right = src_w; - s.bottom = src_h; - } - - if (s.width() <= 0 || s.height() <= 0) { - // Empty or negative region - return FAILURE; - } - - // Get destination origin and clip rectangle - if (dst_pt != NULL) { - d_x = dst_pt->x; - d_y = dst_pt->y; - } else { - d_x = 0; - d_y = 0; - } - - clip = ds->clip_rect; - - if (clip.left == clip.right) { - clip.left = 0; - clip.right = ds->w; - } - - if (clip.top == clip.bottom) { - clip.top = 0; - clip.bottom = ds->h; - } - - // Clip source rectangle to destination surface - dst_off_x = d_x; - dst_off_y = d_y; - src_off_x = s.left; - src_off_y = s.top; - src_draw_w = s.width(); - src_draw_h = s.height(); - - // Clip to left edge - - if (d_x < clip.left) { - if (d_x <= (-src_draw_w)) { - // dst rect completely off left edge - return SUCCESS; - } - - src_off_x += (clip.left - d_x); - src_draw_w -= (clip.left - d_x); - - dst_off_x = clip.left; - } - - // Clip to top edge - - if (d_y < clip.top) { - if (d_y >= (-src_draw_h)) { - // dst rect completely off top edge - return SUCCESS; - } - - src_off_y += (clip.top - d_y); - src_draw_h -= (clip.top - d_y); - - dst_off_y = clip.top; - } - - // Clip to right edge - - if (d_x >= clip.right) { - // dst rect completely off right edge - return SUCCESS; - } - - if ((d_x + src_draw_w) > clip.right) { - src_draw_w = clip.right - d_x; - } - - // Clip to bottom edge - - if (d_y > clip.bottom) { - // dst rect completely off bottom edge - return SUCCESS; - } - - if ((d_y + src_draw_h) > clip.bottom) { - src_draw_h = clip.bottom - d_y; - } - - // Transfer buffer data to surface - read_p = (src + src_off_x) + (src_w * src_off_y); - write_p = ((byte *)ds->pixels + dst_off_x) + (ds->pitch * dst_off_y); - - for (row = 0; row < src_draw_h; row++) { - memcpy(write_p, read_p, src_draw_w); - - write_p += ds->pitch; - read_p += src_w; - } - - return SUCCESS; -} - -int bufToBuffer(byte *dst_buf, int dst_w, int dst_h, const byte *src, - int src_w, int src_h, Rect *src_rect, Point *dst_pt) { - const byte *read_p; - byte *write_p; - int row; - - Common::Rect s; - int d_x, d_y; - Common::Rect clip; - - int dst_off_x, dst_off_y; - int src_off_x, src_off_y; - int src_draw_w, src_draw_h; - - // Clamp source rectangle to source buffer - if (src_rect != NULL) { - src_rect->clip(src_w, src_h); - - s.left = src_rect->left; - s.top = src_rect->top; - s.right = src_rect->right; - s.bottom = src_rect->bottom; - } else { - s.left = 0; - s.top = 0; - s.right = src_w; - s.bottom = src_h; - } - - if (s.width() <= 0 || s.height() <= 0) { - // Empty or negative region - return FAILURE; - } - - // Get destination origin and clip rectangle - if (dst_pt != NULL) { - d_x = dst_pt->x; - d_y = dst_pt->y; - } else { - d_x = 0; - d_y = 0; - } - - clip.left = 0; - clip.top = 0; - clip.right = dst_w; - clip.bottom = dst_h; - - // Clip source rectangle to destination surface - dst_off_x = d_x; - dst_off_y = d_y; - src_off_x = s.left; - src_off_y = s.top; - src_draw_w = s.width(); - src_draw_h = s.height(); - - // Clip to left edge - - if (d_x < clip.left) { - if (d_x <= (-src_draw_w)) { - // dst rect completely off left edge - return SUCCESS; - } - - src_off_x += (clip.left - d_x); - src_draw_w -= (clip.left - d_x); - - dst_off_x = clip.left; - } - - // Clip to top edge - - if (d_y < clip.top) { - if (d_y >= (-src_draw_h)) { - // dst rect completely off top edge - return SUCCESS; - } - - src_off_y += (clip.top - d_y); - src_draw_h -= (clip.top - d_y); - - dst_off_y = clip.top; - } - - // Clip to right edge - - if (d_x >= clip.right) { - // dst rect completely off right edge - return SUCCESS; - } - - if ((d_x + src_draw_w) > clip.right) { - src_draw_w = clip.right - d_x; - } - - // Clip to bottom edge - - if (d_y >= clip.bottom) { - // dst rect completely off bottom edge - return SUCCESS; - } - - if ((d_y + src_draw_h) > clip.bottom) { - src_draw_h = clip.bottom - d_y; +void Surface::blit(const Common::Rect &destRect, const byte *sourceBuffer) { + const byte *readPointer; + byte *writePointer; + int row; + ClipData clipData; + + clipData.sourceRect.left = 0; + clipData.sourceRect.top = 0; + clipData.sourceRect.right = destRect.width(); + clipData.sourceRect.bottom = destRect.height(); + + clipData.destPoint.x = destRect.left; + clipData.destPoint.y = destRect.top; + clipData.destRect.left = 0; + clipData.destRect.right = w; + clipData.destRect.top = 0; + clipData.destRect.bottom = h; + + if (!clipData.calcClip()) { + return; } - + // Transfer buffer data to surface - read_p = (src + src_off_x) + (src_w * src_off_y); - write_p = (dst_buf + dst_off_x) + (dst_w * dst_off_y); - - for (row = 0; row < src_draw_h; row++) { - memcpy(write_p, read_p, src_draw_w); + readPointer = (sourceBuffer + clipData.drawSource.x) + + (clipData.sourceRect.right * clipData.drawSource.y); - write_p += dst_w; - read_p += src_w; - } - - return SUCCESS; -} + writePointer = ((byte *)pixels + clipData.drawDest.x) + (pitch * clipData.drawDest.y); -// Fills a rectangle in the surface ds from point 'p1' to point 'p2' using -// the specified color. -int drawRect(SURFACE *ds, Rect &dst_rect, int color) { - dst_rect.clip(ds->w, ds->h); + for (row = 0; row < clipData.drawHeight; row++) { + memcpy(writePointer, readPointer, clipData.drawWidth); - if (!dst_rect.isValidRect()) { - // Empty or negative region - return FAILURE; + writePointer += pitch; + readPointer += clipData.sourceRect.right; } - - ds->fillRect(dst_rect, color); - - return SUCCESS; -} - -int drawFrame(SURFACE *ds, const Point *p1, const Point *p2, int color) { - int min_x; - int max_x; - int min_y; - int max_y; - - assert((ds != NULL) && (p1 != NULL) && (p2 != NULL)); - - min_x = MIN(p1->x, p2->x); - max_x = MAX(p1->x, p2->x); - min_y = MIN(p1->y, p2->y); - max_y = MAX(p1->y, p2->y); - - ds->frameRect(Common::Rect(min_x, min_y, max_x+1, max_y+1), color); - - return SUCCESS; } -int drawPolyLine(SURFACE *ds, const Point *pts, int pt_ct, int draw_color) { - assert((ds != NULL) & (pts != NULL)); +void Surface::drawPolyLine(const Point *points, int count, int color) { + int i; + if (count >= 3) { + for (i = 1; i < count; i++) { + drawLine(points[i].x, points[i].y, points[i - 1].x, points[i - 1].y, color); + } - if (pt_ct < 3) { - return FAILURE; + drawLine(points[count - 1].x, points[count - 1].y, points->x, points->y, color); } - - for (int i = 1; i < pt_ct; i++) - ds->drawLine(pts[i].x, pts[i].y, pts[i - 1].x, pts[i - 1].y, draw_color); - - ds->drawLine(pts[pt_ct - 1].x, pts[pt_ct - 1].y, pts[0].x, pts[0].y, draw_color); - - return SUCCESS; } -SURFACE *Gfx::getBackBuffer() { - return &_back_buf; -} - -int Gfx::setPalette(PALENTRY *pal) { +void Gfx::setPalette(PalEntry *pal) { int i; byte *ppal; - for (i = 0, ppal = _cur_pal; i < PAL_ENTRIES; i++, ppal += 4) { + for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) { ppal[0] = pal[i].red; ppal[1] = pal[i].green; ppal[2] = pal[i].blue; ppal[3] = 0; } - _system->setPalette(_cur_pal, 0, PAL_ENTRIES); - - return SUCCESS; + _system->setPalette(_currentPal, 0, PAL_ENTRIES); } -int Gfx::getCurrentPal(PALENTRY *src_pal) { +void Gfx::getCurrentPal(PalEntry *src_pal) { int i; byte *ppal; - for (i = 0, ppal = _cur_pal; i < PAL_ENTRIES; i++, ppal += 4) { + for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) { src_pal[i].red = ppal[0]; src_pal[i].green = ppal[1]; src_pal[i].blue = ppal[2]; } - - return SUCCESS; } -int Gfx::palToBlack(PALENTRY *src_pal, double percent) { +void Gfx::palToBlack(PalEntry *src_pal, double percent) { int i; //int fade_max = 255; int new_entry; @@ -448,7 +168,7 @@ int Gfx::palToBlack(PALENTRY *src_pal, double percent) { fpercent = 1.0 - fpercent; // Use the correct percentage change per frame for each palette entry - for (i = 0, ppal = _cur_pal; i < PAL_ENTRIES; i++, ppal += 4) { + for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) { new_entry = (int)(src_pal[i].red * fpercent); if (new_entry < 0) { @@ -475,12 +195,10 @@ int Gfx::palToBlack(PALENTRY *src_pal, double percent) { ppal[3] = 0; } - _system->setPalette(_cur_pal, 0, PAL_ENTRIES); - - return SUCCESS; + _system->setPalette(_currentPal, 0, PAL_ENTRIES); } -int Gfx::blackToPal(PALENTRY *src_pal, double percent) { +void Gfx::blackToPal(PalEntry *src_pal, double percent) { int new_entry; double fpercent; int color_delta; @@ -501,7 +219,7 @@ int Gfx::blackToPal(PALENTRY *src_pal, double percent) { fpercent = 1.0 - fpercent; // Use the correct percentage change per frame for each palette entry - for (i = 0, ppal = _cur_pal; i < PAL_ENTRIES; i++, ppal += 4) { + for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) { new_entry = (int)(src_pal[i].red - src_pal[i].red * fpercent); if (new_entry < 0) { @@ -530,7 +248,7 @@ int Gfx::blackToPal(PALENTRY *src_pal, double percent) { // Find the best white and black color indices again if (percent >= 1.0) { - for (i = 0, ppal = _cur_pal; i < PAL_ENTRIES; i++, ppal += 4) { + for (i = 0, ppal = _currentPal; i < PAL_ENTRIES; i++, ppal += 4) { color_delta = ppal[0]; color_delta += ppal[1]; color_delta += ppal[2]; @@ -547,9 +265,7 @@ int Gfx::blackToPal(PALENTRY *src_pal, double percent) { } } - _system->setPalette(_cur_pal, 0, PAL_ENTRIES); - - return SUCCESS; + _system->setPalette(_currentPal, 0, PAL_ENTRIES); } void Gfx::showCursor(bool state) { diff --git a/saga/gfx.h b/saga/gfx.h index 4dc671814e..73d6b3b4d7 100644 --- a/saga/gfx.h +++ b/saga/gfx.h @@ -40,10 +40,10 @@ struct ClipData { Point destPoint; // output members - Point sourceDraw; - Point destDraw; - int width; - int height; + Point drawSource; + Point drawDest; + int drawWidth; + int drawHeight; bool calcClip() { Common::Rect s; @@ -61,34 +61,56 @@ struct ClipData { return false; } - sourceDraw.x = s.left - sourceRect.left - destPoint.x; - sourceDraw.y = s.top - sourceRect.top - destPoint.y; - destDraw.x = s.left; - destDraw.y = s.top; - width = s.width(); - height = s.height(); + drawSource.x = s.left - sourceRect.left - destPoint.x; + drawSource.y = s.top - sourceRect.top - destPoint.y; + drawDest.x = s.left; + drawDest.y = s.top; + drawWidth = s.width(); + drawHeight = s.height(); return true; } }; -struct PALENTRY { +struct PalEntry { byte red; byte green; byte blue; }; -struct COLOR { +struct Color { int red; int green; int blue; int alpha; }; -struct SURFACE : Graphics::Surface { - Rect clip_rect; +struct Surface : Graphics::Surface { + + void drawPalette(); + void drawPolyLine(const Point *points, int count, int color); + void blit(const Common::Rect &destRect, const byte *sourceBuffer); + + void getRect(Common::Rect &rect) { + rect.left = rect.top = 0; + rect.right = w; + rect.bottom = h; + } + void drawFrame(const Common::Point &p1, const Common::Point &p2, int color) { + Common::Rect rect(MIN(p1.x, p2.x), MIN(p1.y, p2.y), MAX(p1.x, p2.x) + 1, MAX(p1.y, p2.y) + 1); + frameRect(rect, color); + } + void drawRect(const Common::Rect &destRect, int color) { + Common::Rect rect(w , h); + rect.clip(destRect); + + if (rect.isValidRect()) { + fillRect(rect, color); + } + } }; + #define PAL_ENTRIES 256 #define CURSOR_W 7 @@ -97,33 +119,29 @@ struct SURFACE : Graphics::Surface { #define CURSOR_ORIGIN_X 4 #define CURSOR_ORIGIN_Y 4 -int drawPalette(SURFACE *dst_s); -int bufToSurface(SURFACE *ds, const byte *src, int src_w, int src_h, Rect *src_rect, Point *dst_pt); -int bufToBuffer(byte * dst_buf, int dst_w, int dst_h, const byte *src, - int src_w, int src_h, Rect *src_rect, Point *dst_pt); -int drawRect(SURFACE *ds, Rect &dst_rect, int color); -int drawFrame(SURFACE *ds, const Point *p1, const Point *p2, int color); -int drawPolyLine(SURFACE *ds, const Point *pts, int pt_ct, int draw_color); - bool hitTestPoly(const Point *points, unsigned int npoints, const Point& test_point); class Gfx { public: Gfx(OSystem *system, int width, int height, GameDetector &detector); - SURFACE *getBackBuffer(); - int setPalette(PALENTRY *pal); - int getCurrentPal(PALENTRY *src_pal); - int palToBlack(PALENTRY *src_pal, double percent); - int blackToPal(PALENTRY *src_pal, double percent); + ~Gfx(); + Surface *getBackBuffer() { + return &_backBuffer; + } + + void setPalette(PalEntry *pal); + void getCurrentPal(PalEntry *src_pal); + void palToBlack(PalEntry *src_pal, double percent); + void blackToPal(PalEntry *src_pal, double percent); void updateCursor() { setCursor(); } void showCursor(bool state); private: void setCursor(); int _init; - SURFACE _back_buf; - byte _cur_pal[PAL_ENTRIES * 4]; + Surface _backBuffer; + byte _currentPal[PAL_ENTRIES * 4]; OSystem *_system; }; diff --git a/saga/ihnm_introproc.cpp b/saga/ihnm_introproc.cpp index 5efc9c9708..bece587e3a 100644 --- a/saga/ihnm_introproc.cpp +++ b/saga/ihnm_introproc.cpp @@ -164,9 +164,9 @@ int Scene::SC_IHNMIntroMovieProc2(int param, void *refCon) { int Scene::IHNMIntroMovieProc2(int param) { EVENT event; EVENT *q_event; - PALENTRY *pal; + PalEntry *pal; - static PALENTRY current_pal[PAL_ENTRIES]; + static PalEntry current_pal[PAL_ENTRIES]; switch (param) { case SCENE_BEGIN: @@ -250,8 +250,8 @@ int Scene::SC_IHNMIntroMovieProc3(int param, void *refCon) { int Scene::IHNMIntroMovieProc3(int param) { EVENT event; EVENT *q_event; - PALENTRY *pal; - static PALENTRY current_pal[PAL_ENTRIES]; + PalEntry *pal; + static PalEntry current_pal[PAL_ENTRIES]; switch (param) { case SCENE_BEGIN: diff --git a/saga/interface.cpp b/saga/interface.cpp index 3f8e6db460..bd89e58b69 100644 --- a/saga/interface.cpp +++ b/saga/interface.cpp @@ -500,7 +500,7 @@ int Interface::loadScenePortraits(int resourceId) { return _vm->_sprite->loadList(resourceId, _scenePortraits); } -void Interface::drawVerbPanel(SURFACE *backBuffer, PanelButton* panelButton) { +void Interface::drawVerbPanel(Surface *backBuffer, PanelButton* panelButton) { PanelButton * rightButtonVerbPanelButton; PanelButton * currentVerbPanelButton; int textColor; @@ -534,12 +534,12 @@ void Interface::drawVerbPanel(SURFACE *backBuffer, PanelButton* panelButton) { } void Interface::draw() { - SURFACE *backBuffer; + Surface *backBuffer; int i; Point leftPortraitPoint; Point rightPortraitPoint; - Point origin; + Rect rect; backBuffer = _vm->_gfx->getBackBuffer(); @@ -551,10 +551,9 @@ void Interface::draw() { if (_panelMode == kPanelMain) { - origin.x = _mainPanel.x; - origin.y = _mainPanel.y; + _mainPanel.getRect(rect); + backBuffer->blit(rect, _mainPanel.image); - bufToSurface(backBuffer, _mainPanel.image, _mainPanel.imageWidth, _mainPanel.imageHeight, NULL, &origin); for (i = 0; i < kVerbTypesMax; i++) { if (_verbTypeToPanelButton[i] != NULL) { drawVerbPanel(backBuffer, _verbTypeToPanelButton[i]); @@ -563,11 +562,8 @@ void Interface::draw() { } else { if (_panelMode == kPanelConverse) { - origin.x = _conversePanel.x; - origin.y = _conversePanel.y; - - bufToSurface(backBuffer, _conversePanel.image, _conversePanel.imageWidth, - _conversePanel.imageHeight, NULL, &origin); + _conversePanel.getRect(rect); + backBuffer->blit(rect, _conversePanel.image); converseDisplayTextLines(backBuffer); } @@ -633,7 +629,7 @@ void Interface::calcOptionSaveSlider() { _optionSaveRectBottom.right--; } -void Interface::drawPanelText(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton) { +void Interface::drawPanelText(Surface *ds, InterfacePanel *panel, PanelButton *panelButton) { const char *text; int textWidth; Rect rect; @@ -651,22 +647,20 @@ void Interface::drawPanelText(SURFACE *ds, InterfacePanel *panel, PanelButton *p void Interface::drawOption() { const char *text; - SURFACE *backBuffer; + Surface *backBuffer; int i; int fontHeight; uint j, idx; int fgColor; int bgColor; - Point origin; Rect rect; Rect rect2; PanelButton *panelButton; backBuffer = _vm->_gfx->getBackBuffer(); - origin.x = _vm->getDisplayInfo().optionPanelXOffset; - origin.y = _vm->getDisplayInfo().optionPanelYOffset; - bufToSurface(backBuffer, _optionPanel.image, _optionPanel.imageWidth, _optionPanel.imageHeight, NULL, &origin); + _optionPanel.getRect(rect); + backBuffer->blit(rect, _optionPanel.image); for (i = 0; i < _optionPanel.buttonsCount; i++) { panelButton = &_optionPanel.buttons[i]; @@ -679,13 +673,13 @@ void Interface::drawOption() { } if (_optionSaveRectTop.height() > 0) { - drawRect(backBuffer, _optionSaveRectTop, kITEColorDarkGrey); + backBuffer->drawRect(_optionSaveRectTop, kITEColorDarkGrey); } drawButtonBox(backBuffer, _optionSaveRectSlider, kSlider, _optionSaveFileSlider->state > 0); if (_optionSaveRectBottom.height() > 0) { - drawRect(backBuffer, _optionSaveRectBottom, kITEColorDarkGrey); + backBuffer->drawRect(_optionSaveRectBottom, kITEColorDarkGrey); } _optionPanel.calcPanelButtonRect(_optionSaveFilePanel, rect); @@ -713,7 +707,7 @@ void Interface::drawOption() { } void Interface::drawQuit() { - SURFACE *backBuffer; + Surface *backBuffer; Rect rect; int i; PanelButton *panelButton; @@ -773,7 +767,7 @@ void Interface::setQuit(PanelButton *panelButton) { } void Interface::drawLoad() { - SURFACE *backBuffer; + Surface *backBuffer; Rect rect; int i; PanelButton *panelButton; @@ -936,7 +930,7 @@ void Interface::processTextInput(uint16 ascii) { } } -void Interface::drawTextInput(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton) { +void Interface::drawTextInput(Surface *ds, InterfacePanel *panel, PanelButton *panelButton) { Rect rect; char ch[2]; int fgColor; @@ -970,7 +964,7 @@ void Interface::drawTextInput(SURFACE *ds, InterfacePanel *panel, PanelButton *p } void Interface::drawSave() { - SURFACE *backBuffer; + Surface *backBuffer; Rect rect; int i; PanelButton *panelButton; @@ -1305,7 +1299,7 @@ void Interface::update(const Point& mousePoint, int updateFlag) { } void Interface::drawStatusBar() { - SURFACE *backBuffer; + Surface *backBuffer; Rect rect; int string_w; @@ -1327,7 +1321,7 @@ void Interface::drawStatusBar() { rect.right = rect.left + _vm->getDisplayWidth(); rect.bottom = rect.top + _vm->getDisplayInfo().statusHeight; - drawRect(backBuffer, rect, _vm->getDisplayInfo().statusBGColor); + backBuffer->drawRect(rect, _vm->getDisplayInfo().statusBGColor); string_w = _vm->_font->getStringWidth(SMALL_FONT_ID, _statusText, 0, 0); @@ -1532,7 +1526,7 @@ int Interface::inventoryItemPosition(int objectId) { return -1; } -void Interface::drawInventory(SURFACE *backBuffer) { +void Interface::drawInventory(Surface *backBuffer) { if (_panelMode != kPanelMain) return; int i; @@ -1576,7 +1570,7 @@ void Interface::setVerbState(int verb, int state) { draw(); } -void Interface::drawButtonBox(SURFACE *ds, const Rect& rect, ButtonKind kind, bool down) { +void Interface::drawButtonBox(Surface *ds, const Rect& rect, ButtonKind kind, bool down) { byte cornerColor; byte frameColor; byte fillColor; @@ -1670,7 +1664,7 @@ void Interface::drawButtonBox(SURFACE *ds, const Rect& rect, ButtonKind kind, bo ds->fillRect(fill, solidColor); } -void Interface::drawPanelButtonText(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton) { +void Interface::drawPanelButtonText(Surface *ds, InterfacePanel *panel, PanelButton *panelButton) { const char *text; int textId; int textWidth; @@ -1712,7 +1706,7 @@ void Interface::drawPanelButtonText(SURFACE *ds, InterfacePanel *panel, PanelBut textColor, _vm->getDisplayInfo().verbTextShadowColor, FONT_SHADOW); } -void Interface::drawPanelButtonArrow(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton) { +void Interface::drawPanelButtonArrow(Surface *ds, InterfacePanel *panel, PanelButton *panelButton) { Point point; int spriteNumber; @@ -1732,7 +1726,7 @@ void Interface::drawPanelButtonArrow(SURFACE *ds, InterfacePanel *panel, PanelBu _vm->_sprite->draw(ds, _vm->getDisplayClip(), _vm->_sprite->_mainSprites, spriteNumber, point, 256); } -void Interface::drawVerbPanelText(SURFACE *ds, PanelButton *panelButton, int textColor, int textShadowColor) { +void Interface::drawVerbPanelText(Surface *ds, PanelButton *panelButton, int textColor, int textShadowColor) { const char *text; int textWidth; Point point; @@ -1858,7 +1852,7 @@ void Interface::converseSetTextLines(int row) { } } -void Interface::converseDisplayTextLines(SURFACE *ds) { +void Interface::converseDisplayTextLines(Surface *ds) { int relPos; byte foregnd; byte backgnd; @@ -1878,7 +1872,7 @@ void Interface::converseDisplayTextLines(SURFACE *ds) { rect.moveTo(_conversePanel.x + _conversePanel.buttons[0].xOffset, _conversePanel.y + _conversePanel.buttons[0].yOffset); - drawRect(ds, rect, kITEColorDarkGrey); //fill bullet place + ds->drawRect(rect, kITEColorDarkGrey); //fill bullet place for (int i = 0; i < CONVERSE_TEXT_LINES; i++) { relPos = _converseStartPos + i; @@ -1897,7 +1891,7 @@ void Interface::converseDisplayTextLines(SURFACE *ds) { _conversePanel.calcPanelButtonRect(&_conversePanel.buttons[i], rect); rect.left += 8; - drawRect(ds, rect, backgnd); + ds->drawRect(rect, backgnd); str = _converseText[relPos].text; @@ -2023,20 +2017,19 @@ void Interface::loadState(Common::InSaveFile *in) { void Interface::mapPanelShow() { byte *resource; size_t resourceLength, imageLength; - SURFACE *backBuffer; - Point origin; + Surface *backBuffer; + Rect rect; byte *image; int imageWidth, imageHeight; int result; const byte *pal; - PALENTRY cPal[PAL_ENTRIES]; + PalEntry cPal[PAL_ENTRIES]; _vm->_gfx->showCursor(false); backBuffer = _vm->_gfx->getBackBuffer(); - origin.x = 0; - origin.y = 0; + rect.left = rect.top = 0; result = RSC_LoadResource(_interfaceContext, RID_ITE_TYCHO_MAP, &resource, &resourceLength); if ((result != SUCCESS) || (resourceLength == 0)) { @@ -2059,10 +2052,13 @@ void Interface::mapPanelShow() { for (int i = 0; i < PAL_ENTRIES; i++) { cPal[i].red = *pal++; cPal[i].green = *pal++; - cPal[i].blue = *pal++; + cPal[i].blue = *pal++; } - bufToSurface(backBuffer, image, imageWidth, imageHeight, NULL, &origin); + rect.setWidth(imageWidth); + rect.setHeight(imageHeight); + + backBuffer->blit(rect, image); // Evil Evil for (int i = 0; i < 6 ; i++) { @@ -2080,7 +2076,7 @@ void Interface::mapPanelShow() { } void Interface::mapPanelClean() { - PALENTRY pal[PAL_ENTRIES]; + PalEntry pal[PAL_ENTRIES]; _vm->_gfx->getCurrentPal(pal); @@ -2104,7 +2100,7 @@ void Interface::mapPanelClean() { } void Interface::mapPanelDrawCrossHair() { - SURFACE *backBuffer; + Surface *backBuffer; backBuffer = _vm->_gfx->getBackBuffer(); _mapPanelCrossHairState = !_mapPanelCrossHairState; diff --git a/saga/interface.h b/saga/interface.h index fc3c89821f..afc0853275 100644 --- a/saga/interface.h +++ b/saga/interface.h @@ -110,9 +110,9 @@ struct InterfacePanel { void getRect(Rect &rect) { rect.left = x; - rect.right = rect.left + imageWidth; rect.top = y; - rect.bottom = rect.top + imageHeight; + rect.setWidth(imageWidth); + rect.setHeight(imageHeight); } void calcPanelButtonRect(const PanelButton* panelButton, Rect &rect) { @@ -244,7 +244,7 @@ public: private: static void textInputRepeatCallback(void *refCon); - void drawInventory(SURFACE *backBuffer); + void drawInventory(Surface *backBuffer); void updateInventory(int pos); void inventoryChangePos(int chg); void inventorySetPos(int key); @@ -322,18 +322,18 @@ private: void setLoad(PanelButton *panelButton); void setSave(PanelButton *panelButton); - void drawTextInput(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton); - void drawPanelText(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton); - void drawPanelButtonText(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton); + void drawTextInput(Surface *ds, InterfacePanel *panel, PanelButton *panelButton); + void drawPanelText(Surface *ds, InterfacePanel *panel, PanelButton *panelButton); + void drawPanelButtonText(Surface *ds, InterfacePanel *panel, PanelButton *panelButton); enum ButtonKind { kButton, kSlider, kEdit }; - void drawButtonBox(SURFACE *ds, const Rect &rect, ButtonKind kind, bool down); - void drawPanelButtonArrow(SURFACE *ds, InterfacePanel *panel, PanelButton *panelButton); - void drawVerbPanelText(SURFACE *ds, PanelButton *panelButton, int textColor, int textShadowColor); - void drawVerbPanel(SURFACE *backBuffer, PanelButton* panelButton); + void drawButtonBox(Surface *ds, const Rect &rect, ButtonKind kind, bool down); + void drawPanelButtonArrow(Surface *ds, InterfacePanel *panel, PanelButton *panelButton); + void drawVerbPanelText(Surface *ds, PanelButton *panelButton, int textColor, int textShadowColor); + void drawVerbPanel(Surface *backBuffer, PanelButton* panelButton); void calcOptionSaveSlider(); void processTextInput(uint16 ascii); void processStatusTextInput(uint16 ascii); @@ -350,7 +350,7 @@ public: void converseSetPos(int key); private: - void converseDisplayTextLines(SURFACE *ds); + void converseDisplayTextLines(Surface *ds); PanelButton *getPanelButtonByVerbType(int verb) { if ((verb < 0) || (verb >= kVerbTypesMax)) { error("Interface::getPanelButtonByVerbType wrong verb"); @@ -442,7 +442,7 @@ private: int _textInputRepeatPhase; uint16 _textInputRepeatChar; - PALENTRY _mapSavedPal[PAL_ENTRIES]; + PalEntry _mapSavedPal[PAL_ENTRIES]; bool _mapPanelCrossHairState; }; diff --git a/saga/isomap.cpp b/saga/isomap.cpp index 18f524f905..333f8f6c8e 100644 --- a/saga/isomap.cpp +++ b/saga/isomap.cpp @@ -377,14 +377,11 @@ int16 IsoMap::findMulti(int16 tileIndex, int16 absU, int16 absV, int16 absH) { return 1; } -int IsoMap::draw(SURFACE *ds) { +void IsoMap::draw(Surface *ds) { - Rect isoRect(_vm->_scene->getSceneClip()); - drawRect(ds, isoRect, 0); - _tileClip = isoRect; + _tileClip = _vm->_scene->getSceneClip(); + ds->drawRect(_tileClip, 0); drawTiles(ds, NULL); - - return SUCCESS; } void IsoMap::setMapPosition(int x, int y) { @@ -392,7 +389,7 @@ void IsoMap::setMapPosition(int x, int y) { _mapPosition.y = y; } -void IsoMap::drawSprite(SURFACE *ds, SpriteList &spriteList, int spriteNumber, const Location &location, const Point &screenPosition, int scale) { +void IsoMap::drawSprite(Surface *ds, SpriteList &spriteList, int spriteNumber, const Location &location, const Point &screenPosition, int scale) { int width; int height; int xAlign; @@ -429,7 +426,7 @@ void IsoMap::drawSprite(SURFACE *ds, SpriteList &spriteList, int spriteNumber, c } -void IsoMap::drawTiles(SURFACE *ds, const Location *location) { +void IsoMap::drawTiles(Surface *ds, const Location *location) { Point view1; Point fineScroll; Point tileScroll; @@ -551,7 +548,7 @@ void IsoMap::drawTiles(SURFACE *ds, const Location *location) { } -void IsoMap::drawSpriteMetaTile(SURFACE *ds, uint16 metaTileIndex, const Point &point, Location &location, int16 absU, int16 absV) { +void IsoMap::drawSpriteMetaTile(Surface *ds, uint16 metaTileIndex, const Point &point, Location &location, int16 absU, int16 absV) { MetaTileData * metaTile; uint16 high; int16 platformIndex; @@ -578,7 +575,7 @@ void IsoMap::drawSpriteMetaTile(SURFACE *ds, uint16 metaTileIndex, const Point & } } -void IsoMap::drawMetaTile(SURFACE *ds, uint16 metaTileIndex, const Point &point, int16 absU, int16 absV) { +void IsoMap::drawMetaTile(Surface *ds, uint16 metaTileIndex, const Point &point, int16 absU, int16 absV) { MetaTileData * metaTile; uint16 high; int16 platformIndex; @@ -605,7 +602,7 @@ void IsoMap::drawMetaTile(SURFACE *ds, uint16 metaTileIndex, const Point &point, } } -void IsoMap::drawSpritePlatform(SURFACE *ds, uint16 platformIndex, const Point &point, const Location &location, int16 absU, int16 absV, int16 absH) { +void IsoMap::drawSpritePlatform(Surface *ds, uint16 platformIndex, const Point &point, const Location &location, int16 absU, int16 absV, int16 absH) { TilePlatformData *tilePlatform; int16 u, v; Point s; @@ -660,7 +657,7 @@ void IsoMap::drawSpritePlatform(SURFACE *ds, uint16 platformIndex, const Point & } } -void IsoMap::drawPlatform(SURFACE *ds, uint16 platformIndex, const Point &point, int16 absU, int16 absV, int16 absH) { +void IsoMap::drawPlatform(Surface *ds, uint16 platformIndex, const Point &point, int16 absU, int16 absV, int16 absH) { TilePlatformData *tilePlatform; int16 u, v; Point s; @@ -716,7 +713,7 @@ void IsoMap::drawPlatform(SURFACE *ds, uint16 platformIndex, const Point &point, #define THRESH8 8 #define THRESH16 16 -void IsoMap::drawTile(SURFACE *ds, uint16 tileIndex, const Point &point, const Location *location) { +void IsoMap::drawTile(Surface *ds, uint16 tileIndex, const Point &point, const Location *location) { const byte *tilePointer; const byte *readPointer; byte *drawPointer; diff --git a/saga/isomap.h b/saga/isomap.h index 96802e560e..36a034ce77 100644 --- a/saga/isomap.h +++ b/saga/isomap.h @@ -158,8 +158,8 @@ public: void loadMetaTiles(const byte * resourcePointer, size_t resourceLength); void loadMulti(const byte * resourcePointer, size_t resourceLength); void freeMem(); - int draw(SURFACE *ds); - void drawSprite(SURFACE *ds, SpriteList &spriteList, int spriteNumber, const Location &location, const Point &screenPosition, int scale); + void draw(Surface *ds); + void drawSprite(Surface *ds, SpriteList &spriteList, int spriteNumber, const Location &location, const Point &screenPosition, int scale); void adjustScroll(bool jump); void tileCoordsToScreenPoint(const Location &location, Point &position) { position.x = location.u() - location.v() + (128 * SAGA_TILEMAP_W) - _viewScroll.x + 16; @@ -177,12 +177,12 @@ public: int16 getTileIndex(int16 u, int16 v, int16 z); private: - void drawTiles(SURFACE *ds, const Location *location); - void drawMetaTile(SURFACE *ds, uint16 metaTileIndex, const Point &point, int16 absU, int16 absV); - void drawSpriteMetaTile(SURFACE *ds, uint16 metaTileIndex, const Point &point, Location &location, int16 absU, int16 absV); - void drawPlatform(SURFACE *ds, uint16 platformIndex, const Point &point, int16 absU, int16 absV, int16 absH); - void drawSpritePlatform(SURFACE *ds, uint16 platformIndex, const Point &point, const Location &location, int16 absU, int16 absV, int16 absH); - void drawTile(SURFACE *ds, uint16 tileIndex, const Point &point, const Location *location); + void drawTiles(Surface *ds, const Location *location); + void drawMetaTile(Surface *ds, uint16 metaTileIndex, const Point &point, int16 absU, int16 absV); + void drawSpriteMetaTile(Surface *ds, uint16 metaTileIndex, const Point &point, Location &location, int16 absU, int16 absV); + void drawPlatform(Surface *ds, uint16 platformIndex, const Point &point, int16 absU, int16 absV, int16 absH); + void drawSpritePlatform(Surface *ds, uint16 platformIndex, const Point &point, const Location &location, int16 absU, int16 absV, int16 absH); + void drawTile(Surface *ds, uint16 tileIndex, const Point &point, const Location *location); int16 smoothSlide(int16 value, int16 min, int16 max) { if (value < min) { if (value < min - 100 || value > min - 4) { diff --git a/saga/objectmap.cpp b/saga/objectmap.cpp index 0ba295ce35..2122bf72f3 100644 --- a/saga/objectmap.cpp +++ b/saga/objectmap.cpp @@ -132,7 +132,7 @@ bool HitZone::hitTest(const Point &testPoint) { return false; } -void HitZone::draw(SURFACE *ds, int color) { +void HitZone::draw(Surface *ds, int color) { int i, pointsCount, j; Location location; HitZone::ClickArea *clickArea; @@ -155,11 +155,11 @@ void HitZone::draw(SURFACE *ds, int color) { if (pointsCount == 2) { // 2 points represent a box - drawFrame(ds, &points[0], &points[1], color); + ds->drawFrame(points[0], points[1], color); } else { if (pointsCount > 2) { // Otherwise draw a polyline - drawPolyLine(ds, points, pointsCount, color); + ds->drawPolyLine(points, pointsCount, color); } } if (_vm->_scene->getFlags() & kSceneFlagISO) { @@ -214,7 +214,7 @@ void ObjectMap::freeMem() { -void ObjectMap::draw(SURFACE *ds, const Point& testPoint, int color, int color2) { +void ObjectMap::draw(Surface *ds, const Point& testPoint, int color, int color2) { int i; int hitZoneIndex; char txtBuf[32]; diff --git a/saga/objectmap.h b/saga/objectmap.h index 76a45dd284..f78ac0c437 100644 --- a/saga/objectmap.h +++ b/saga/objectmap.h @@ -76,7 +76,7 @@ public: return objectIndexToId(kGameObjectStepZone, _index); } bool getSpecialPoint(Point &specialPoint) const; - void draw(SURFACE *ds, int color); + void draw(Surface *ds, int color); bool hitTest(const Point &testPoint); private: @@ -104,7 +104,7 @@ public: void load(const byte *resourcePointer, size_t resourceLength); void freeMem(void); - void draw(SURFACE *drawSurface, const Point& testPoint, int color, int color2); + void draw(Surface *drawSurface, const Point& testPoint, int color, int color2); int hitTest(const Point& testPoint); HitZone *getHitZone(int16 index) { if ((index < 0) || (index >= _hitZoneListCount)) { diff --git a/saga/palanim.cpp b/saga/palanim.cpp index 9cb52a6ece..0e34731be0 100644 --- a/saga/palanim.cpp +++ b/saga/palanim.cpp @@ -95,13 +95,13 @@ int PalAnim::loadPalAnim(const byte *resdata, size_t resdata_len) { debug(2, "PalAnim::loadPalAnim(): Entry %d: Loading %d SAGA_COLOR structures.", i, color_count); - test_p = calloc(1, sizeof(COLOR) * color_count); + test_p = calloc(1, sizeof(Color) * color_count); if (test_p == NULL) { warning("PalAnim::loadPalAnim(): Allocation failure"); return MEM; } - _entries[i].colors = (COLOR *)test_p; + _entries[i].colors = (Color *)test_p; for (p = 0; p < pal_count; p++) { _entries[i].pal_index[p] = readS.readByte(); @@ -136,7 +136,7 @@ int PalAnim::cycleStart() { } int PalAnim::cycleStep(int vectortime) { - static PALENTRY pal[256]; + static PalEntry pal[256]; uint16 pal_index; uint16 col_index; diff --git a/saga/palanim.h b/saga/palanim.h index 94f5f52b11..b8e7779fcf 100644 --- a/saga/palanim.h +++ b/saga/palanim.h @@ -35,7 +35,7 @@ struct PALANIM_ENTRY { uint16 color_count; uint16 cycle; byte *pal_index; - COLOR *colors; + Color *colors; }; struct PALANIM_DATA { diff --git a/saga/puzzle.cpp b/saga/puzzle.cpp index 76a97df194..3d932907e4 100644 --- a/saga/puzzle.cpp +++ b/saga/puzzle.cpp @@ -261,7 +261,7 @@ void Puzzle::initPieces(void) { void Puzzle::showPieces(void) { ActorData *puzzle = _vm->_actor->getActor(_vm->_actor->actorIndexToId(ITE_ACTOR_PUZZLE)); - SURFACE *backBuffer = _vm->_gfx->getBackBuffer(); + Surface *backBuffer = _vm->_gfx->getBackBuffer(); for (int j = PUZZLE_PIECES - 1 ; j >= 0; j--) { int num = _piecePriority[j]; @@ -274,7 +274,7 @@ void Puzzle::showPieces(void) { void Puzzle::drawCurrentPiece() { ActorData *puzzle = _vm->_actor->getActor(_vm->_actor->actorIndexToId(ITE_ACTOR_PUZZLE)); - SURFACE *backBuffer = _vm->_gfx->getBackBuffer(); + Surface *backBuffer = _vm->_gfx->getBackBuffer(); _vm->_sprite->draw(backBuffer, _vm->_scene->getSceneClip(), puzzle->spriteList, _puzzlePiece, Point(_pieceInfo[_puzzlePiece].curX, _pieceInfo[_puzzlePiece].curY), 256); diff --git a/saga/render.cpp b/saga/render.cpp index 5ebf1f842a..8083ed2431 100644 --- a/saga/render.cpp +++ b/saga/render.cpp @@ -46,37 +46,11 @@ Render::Render(SagaEngine *vm, OSystem *system) { _system = system; _initialized = false; - int tmp_w, tmp_h, tmp_bytepp; - - // Initialize FPS timer callback Common::g_timer->installTimerProc(&fpsTimerCallback, 1000000, this); - // Create background buffer - _bg_buf_w = _vm->getDisplayWidth(); - _bg_buf_h = _vm->getDisplayHeight(); - _bg_buf = (byte *)calloc(_vm->getDisplayWidth(), _vm->getDisplayHeight()); - - if (_bg_buf == NULL) { - memoryError("Render::Render"); - } - - // Allocate temp buffer for animation decoding, - // graphics scalers (2xSaI), etc. - tmp_w = _vm->getDisplayWidth(); - tmp_h = _vm->getDisplayHeight() + 4; // BG unbanking requres extra rows - tmp_bytepp = 1; - - _tmp_buf = (byte *)calloc(1, tmp_w * tmp_h * tmp_bytepp); - if (_tmp_buf == NULL) { - free(_bg_buf); - return; - } - - _tmp_buf_w = tmp_w; - _tmp_buf_h = tmp_h; + _backGroundSurface.create(_vm->getDisplayWidth(), _vm->getDisplayHeight(), 1); - _backbuf_surface = _vm->_gfx->getBackBuffer(); _flags = 0; _initialized = true; @@ -84,8 +58,7 @@ Render::Render(SagaEngine *vm, OSystem *system) { Render::~Render(void) { Common::g_timer->removeTimerProc(&fpsTimerCallback); - free(_bg_buf); - free(_tmp_buf); + _backGroundSurface.free(); _initialized = false; } @@ -94,19 +67,17 @@ bool Render::initialized() { return _initialized; } -int Render::drawScene() { - SURFACE *backbuf_surface; +void Render::drawScene() { + Surface *backBufferSurface; char txt_buf[20]; int fps_width; Point mouse_pt; - if (!_initialized) { - return FAILURE; - } + assert(_initialized); - _framecount++; + _frameCount++; - backbuf_surface = _backbuf_surface; + backBufferSurface = _vm->_gfx->getBackBuffer(); // Get mouse coordinates mouse_pt = _vm->mousePos(); @@ -127,9 +98,9 @@ int Render::drawScene() { if (getFlags() & RF_OBJECTMAP_TEST) { if (_vm->_scene->_objectMap) - _vm->_scene->_objectMap->draw(backbuf_surface, mouse_pt, kITEColorBrightWhite, kITEColorBlack); + _vm->_scene->_objectMap->draw(backBufferSurface, mouse_pt, kITEColorBrightWhite, kITEColorBlack); if (_vm->_scene->_actionMap) - _vm->_scene->_actionMap->draw(backbuf_surface, mouse_pt, kITEColorRed, kITEColorBlack); + _vm->_scene->_actionMap->draw(backBufferSurface, mouse_pt, kITEColorRed, kITEColorBlack); } if (getFlags() & RF_ACTOR_PATH_TEST) { _vm->_actor->drawPathTest(); @@ -158,7 +129,7 @@ int Render::drawScene() { } // Draw queued text strings - _vm->textDrawList(_vm->_scene->_textList, backbuf_surface); + _vm->textDrawList(_vm->_scene->_textList, backBufferSurface); // Handle user input _vm->processInput(); @@ -167,7 +138,7 @@ int Render::drawScene() { if (_flags & RF_SHOW_FPS) { sprintf(txt_buf, "%d", _fps); fps_width = _vm->_font->getStringWidth(SMALL_FONT_ID, txt_buf, 0, FONT_NORMAL); - _vm->_font->draw(SMALL_FONT_ID, backbuf_surface, txt_buf, 0, backbuf_surface->w - fps_width, 2, + _vm->_font->draw(SMALL_FONT_ID, backBufferSurface, txt_buf, 0, backBufferSurface->w - fps_width, 2, kITEColorBrightWhite, kITEColorBlack, FONT_OUTLINE); } @@ -175,8 +146,8 @@ int Render::drawScene() { if (_flags & RF_RENDERPAUSE) { int msg_len = strlen(PAUSEGAME_MSG); int msg_w = _vm->_font->getStringWidth(BIG_FONT_ID, PAUSEGAME_MSG, msg_len, FONT_OUTLINE); - _vm->_font->draw(BIG_FONT_ID, backbuf_surface, PAUSEGAME_MSG, msg_len, - (backbuf_surface->w - msg_w) / 2, 90, kITEColorBrightWhite, kITEColorBlack, FONT_OUTLINE); + _vm->_font->draw(BIG_FONT_ID, backBufferSurface, PAUSEGAME_MSG, msg_len, + (backBufferSurface->w - msg_w) / 2, 90, kITEColorBrightWhite, kITEColorBlack, FONT_OUTLINE); } // Update user interface @@ -185,32 +156,19 @@ int Render::drawScene() { // Display text formatting test, if applicable if (_flags & RF_TEXT_TEST) { - _vm->textDraw(MEDIUM_FONT_ID, backbuf_surface, test_txt, mouse_pt.x, mouse_pt.y, + _vm->textDraw(MEDIUM_FONT_ID, backBufferSurface, test_txt, mouse_pt.x, mouse_pt.y, kITEColorBrightWhite, kITEColorBlack, FONT_OUTLINE | FONT_CENTERED); } // Display palette test, if applicable if (_flags & RF_PALETTE_TEST) { - drawPalette(backbuf_surface); + backBufferSurface->drawPalette(); } - _system->copyRectToScreen((byte *)backbuf_surface->pixels, backbuf_surface->w, 0, 0, - backbuf_surface->w, backbuf_surface->h); + _system->copyRectToScreen((byte *)backBufferSurface->pixels, backBufferSurface->w, 0, 0, + backBufferSurface->w, backBufferSurface->h); _system->updateScreen(); - return SUCCESS; -} - -unsigned int Render::getFrameCount() { - return _framecount; -} - -unsigned int Render::resetFrameCount() { - unsigned int framecount = _framecount; - - _framecount = 0; - - return framecount; } void Render::fpsTimerCallback(void *refCon) { @@ -218,38 +176,8 @@ void Render::fpsTimerCallback(void *refCon) { } void Render::fpsTimer(void) { - _fps = _framecount; - _framecount = 0; -} - -unsigned int Render::getFlags() { - return _flags; -} - -void Render::setFlag(unsigned int flag) { - _flags |= flag; -} - -void Render::clearFlag(unsigned int flag) { - _flags &= ~flag; -} - -void Render::toggleFlag(unsigned int flag) { - _flags ^= flag; -} - -int Render::getBufferInfo(BUFFER_INFO *bufinfo) { - assert(bufinfo != NULL); - - bufinfo->bg_buf = _bg_buf; - bufinfo->bg_buf_w = _bg_buf_w; - bufinfo->bg_buf_h = _bg_buf_h; - - bufinfo->tmp_buf = _tmp_buf; - bufinfo->tmp_buf_w = _tmp_buf_w; - bufinfo->tmp_buf_h = _tmp_buf_h; - - return SUCCESS; + _fps = _frameCount; + _frameCount = 0; } } // End of namespace Saga diff --git a/saga/render.h b/saga/render.h index 460ffabd4f..dee9d3579a 100644 --- a/saga/render.h +++ b/saga/render.h @@ -44,28 +44,32 @@ enum RENDER_FLAGS { RF_DISABLE_ACTORS = (1 << 9) }; -struct BUFFER_INFO { - byte *bg_buf; - int bg_buf_w; - int bg_buf_h; - byte *tmp_buf; - int tmp_buf_w; - int tmp_buf_h; -}; - class Render { public: Render(SagaEngine *vm, OSystem *system); ~Render(void); bool initialized(); - int drawScene(void); - unsigned int getFlags(void); - void setFlag(unsigned int); - void clearFlag(unsigned int); - void toggleFlag(unsigned int); - unsigned int getFrameCount(void); - unsigned int resetFrameCount(void); - int getBufferInfo(BUFFER_INFO *); + void drawScene(void); + + unsigned int getFlags() const { + return _flags; + } + + void setFlag(unsigned int flag) { + _flags |= flag; + } + + void clearFlag(unsigned int flag) { + _flags &= ~flag; + } + + void toggleFlag(unsigned int flag) { + _flags ^= flag; + } + + Surface *getBackGroundSurface() { + return &_backGroundSurface; + } private: static void fpsTimerCallback(void *refCon); @@ -76,19 +80,10 @@ private: bool _initialized; // Module data - SURFACE *_backbuf_surface; - - byte *_bg_buf; - int _bg_buf_w; - int _bg_buf_h; - byte *_tmp_buf; - int _tmp_buf_w; - int _tmp_buf_h; - - SpriteList *_test_sprite; + Surface _backGroundSurface; unsigned int _fps; - unsigned int _framecount; + unsigned int _frameCount; uint32 _flags; }; diff --git a/saga/saga.h b/saga/saga.h index b0bbec80f9..5744036e5a 100644 --- a/saga/saga.h +++ b/saga/saga.h @@ -577,15 +577,15 @@ public: TEXTLIST *textCreateList(); void textDestroyList(TEXTLIST *textlist); void textClearList(TEXTLIST *textlist); - int textDrawList(TEXTLIST *textlist, SURFACE *ds); + int textDrawList(TEXTLIST *textlist, Surface *ds); TEXTLIST_ENTRY *textAddEntry(TEXTLIST *textlist, TEXTLIST_ENTRY *entry); int textDeleteEntry(TEXTLIST *textlist, TEXTLIST_ENTRY *entry); int textSetDisplay(TEXTLIST_ENTRY *entry, int val); - int textDraw(int font_id, SURFACE *ds, const char *string, int text_x, int text_y, int color, + int textDraw(int font_id, Surface *ds, const char *string, int text_x, int text_y, int color, int effect_color, int flags); int textProcessList(TEXTLIST *textlist, long ms); - int transitionDissolve(byte *dst_img, int dst_w, int dst_h, int dst_p, + int transitionDissolve(byte *dst_img, int dst_w, int dst_h, const byte *src_img, int src_w, int src_h, int flags, int x, int y, double percent); diff --git a/saga/scene.cpp b/saga/scene.cpp index d2073801aa..753a758dbf 100644 --- a/saga/scene.cpp +++ b/saga/scene.cpp @@ -284,7 +284,7 @@ void Scene::getBGInfo(BGInfo &bgInfo) { bgInfo.bounds.setHeight(_bg.h); } -int Scene::getBGPal(PALENTRY **pal) { +int Scene::getBGPal(PalEntry **pal) { assert(_initialized); *pal = _bg.pal; @@ -383,7 +383,7 @@ void Scene::loadScene(LoadSceneParams *loadSceneParams) { int i; EVENT event; EVENT *q_event; - static PALENTRY current_pal[PAL_ENTRIES]; + static PalEntry current_pal[PAL_ENTRIES]; if (_sceneLoaded) { error("Scene::loadScene(): Error, a scene is already loaded"); @@ -852,7 +852,7 @@ int Scene::processSceneResources() { break; case SAGA_PALETTE: { - PALENTRY pal[PAL_ENTRIES]; + PalEntry pal[PAL_ENTRIES]; byte *palPtr = resourceData; if (resourceDataLength < 3 * PAL_ENTRIES) @@ -875,27 +875,30 @@ int Scene::processSceneResources() { } void Scene::draw() { - SURFACE *backBuffer; - BUFFER_INFO buf_info; - Point bgPoint(0, 0); - - assert(_initialized); + Surface *backBuffer; + Surface *backGroundSurface; + Rect rect; backBuffer = _vm->_gfx->getBackBuffer(); - _vm->_render->getBufferInfo(&buf_info); + backGroundSurface = _vm->_render->getBackGroundSurface(); if (_sceneDescription.flags & kSceneFlagISO) { _vm->_isoMap->adjustScroll(false); _vm->_isoMap->draw(backBuffer); } else { - - bufToSurface(backBuffer, buf_info.bg_buf, buf_info.bg_buf_w, - _sceneClip.bottom < buf_info.bg_buf_h ? _vm->getSceneHeight() : buf_info.bg_buf_h, NULL, &bgPoint); + backGroundSurface->getRect(rect); + if (_sceneClip.bottom < rect.bottom) { + rect.bottom = _vm->getSceneHeight(); + } + backBuffer->blit(rect, (const byte *)backGroundSurface->pixels); } } void Scene::endScene() { + Surface *backBuffer; + Surface *backGroundSurface; + Rect rect; int i; if (!_sceneLoaded) @@ -912,11 +915,11 @@ void Scene::endScene() { _vm->_script->_skipSpeeches = false; // Copy current screen to render buffer so inset rooms will get proper background - SURFACE *back_buf = _vm->_gfx->getBackBuffer(); - BUFFER_INFO rbuf_info; + backBuffer= _vm->_gfx->getBackBuffer(); + backGroundSurface = _vm->_render->getBackGroundSurface(); + backBuffer->getRect(rect); - _vm->_render->getBufferInfo(&rbuf_info); - bufToBuffer(rbuf_info.bg_buf, rbuf_info.bg_buf_w, rbuf_info.bg_buf_h, (byte *)back_buf->pixels, back_buf->w, back_buf->h, NULL, NULL); + backGroundSurface->blit(rect, (const byte *)backBuffer->pixels); // Free scene background if (_bg.loaded) { free(_bg.buf); diff --git a/saga/scene.h b/saga/scene.h index 7ca0e488be..2233b05874 100644 --- a/saga/scene.h +++ b/saga/scene.h @@ -133,7 +133,7 @@ struct SceneEntryList { } }; -struct SCENE_IMAGE { +struct SceneImage { int loaded; int w; int h; @@ -142,7 +142,7 @@ struct SCENE_IMAGE { size_t buf_len; byte *res_buf; size_t res_len; - PALENTRY pal[256]; + PalEntry pal[256]; }; @@ -241,7 +241,7 @@ class Scene { void initDoorsState(); void getBGInfo(BGInfo &bgInfo); - int getBGPal(PALENTRY **pal); + int getBGPal(PalEntry **pal); void getSlopes(int &beginSlope, int &endSlope); void clearSceneQueue(void) { @@ -289,8 +289,8 @@ class Scene { int _resListEntries; SCENE_RESLIST *_resList; SceneProc *_sceneProc; - SCENE_IMAGE _bg; - SCENE_IMAGE _bgMask; + SceneImage _bg; + SceneImage _bgMask; Common::Rect _sceneClip; int _sceneDoors[SCENE_DOORS_MAX]; diff --git a/saga/sfuncs.cpp b/saga/sfuncs.cpp index c51f891607..626791c60a 100644 --- a/saga/sfuncs.cpp +++ b/saga/sfuncs.cpp @@ -1192,9 +1192,9 @@ static TEXTLIST_ENTRY *placardTextEntry; // Param1: string rid void Script::sfPlacard(SCRIPTFUNC_PARAMS) { int stringId; - SURFACE *back_buf = _vm->_gfx->getBackBuffer(); - static PALENTRY cur_pal[PAL_ENTRIES]; - PALENTRY *pal; + Surface *backBuffer = _vm->_gfx->getBackBuffer(); + static PalEntry cur_pal[PAL_ENTRIES]; + PalEntry *pal; EVENT event; EVENT *q_event; @@ -1238,7 +1238,7 @@ void Script::sfPlacard(SCRIPTFUNC_PARAMS) { event.type = ONESHOT_EVENT; event.code = GRAPHICS_EVENT; event.op = EVENT_FILL_RECT; - event.data = back_buf; + event.data = backBuffer; event.param = 138; event.param2 = 0; event.param3 = _vm->getSceneHeight(); @@ -1294,8 +1294,8 @@ void Script::sfPlacard(SCRIPTFUNC_PARAMS) { // Script function #49 (0x31) void Script::sfPlacardOff(SCRIPTFUNC_PARAMS) { - static PALENTRY cur_pal[PAL_ENTRIES]; - PALENTRY *pal; + static PalEntry cur_pal[PAL_ENTRIES]; + PalEntry *pal; EVENT event; EVENT *q_event; @@ -1555,18 +1555,13 @@ void Script::sfGetActorY(SCRIPTFUNC_PARAMS) { // Script function #62 (0x3E) void Script::sfEraseDelta(SCRIPTFUNC_PARAMS) { - BUFFER_INFO bufferInfo; + Surface *backGroundSurface; BGInfo backGroundInfo; - Point backGroundPoint; - _vm->_render->getBufferInfo(&bufferInfo); + backGroundSurface = _vm->_render->getBackGroundSurface(); _vm->_scene->getBGInfo(backGroundInfo); - backGroundPoint.x = backGroundInfo.bounds.left; - backGroundPoint.y = backGroundInfo.bounds.top; - bufToBuffer(bufferInfo.bg_buf, bufferInfo.bg_buf_w, bufferInfo.bg_buf_h, - backGroundInfo.buffer, backGroundInfo.bounds.width(), backGroundInfo.bounds.height(), - NULL, &backGroundPoint); + backGroundSurface->blit(backGroundInfo.bounds, backGroundInfo.buffer); } // Script function #63 (0x3F) diff --git a/saga/sprite.cpp b/saga/sprite.cpp index a95f91630a..4078e617c2 100644 --- a/saga/sprite.cpp +++ b/saga/sprite.cpp @@ -170,7 +170,7 @@ void Sprite::getScaledSpriteBuffer(SpriteList &spriteList, int spriteNumber, int } -void Sprite::drawClip(SURFACE *ds, const Rect &clipRect, const Point &spritePointer, int width, int height, const byte *spriteBuffer) { +void Sprite::drawClip(Surface *ds, const Rect &clipRect, const Point &spritePointer, int width, int height, const byte *spriteBuffer) { int clipWidth; int clipHeight; @@ -217,7 +217,7 @@ void Sprite::drawClip(SURFACE *ds, const Rect &clipRect, const Point &spritePoin } } -void Sprite::draw(SURFACE *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Point &screenCoord, int scale) { +void Sprite::draw(Surface *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Point &screenCoord, int scale) { const byte *spriteBuffer; int width; int height; @@ -232,7 +232,7 @@ void Sprite::draw(SURFACE *ds, const Rect &clipRect, SpriteList &spriteList, int drawClip(ds, clipRect, spritePointer, width, height, spriteBuffer); } -void Sprite::draw(SURFACE *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Rect &screenRect, int scale) { +void Sprite::draw(Surface *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Rect &screenRect, int scale) { const byte *spriteBuffer; int width; int height; @@ -283,7 +283,7 @@ bool Sprite::hitTest(SpriteList &spriteList, int spriteNumber, const Point &scre return *srcRowPointer != 0; } -void Sprite::drawOccluded(SURFACE *ds, const Rect &clipRect, SpriteList &spriteList, int spriteNumber, const Point &screenCoord, int scale, int depth) { +void Sprite::drawOccluded(Surface *ds, const Rect &clipRect, SpriteList &spriteList, int spriteNumber, const Point &screenCoord, int scale, int depth) { const byte *spriteBuffer; int x, y; byte *destRowPointer; @@ -333,16 +333,16 @@ void Sprite::drawOccluded(SURFACE *ds, const Rect &clipRect, SpriteList &spriteL } // Finally, draw the occluded sprite - sourceRowPointer = spriteBuffer + clipData.sourceDraw.x + (clipData.sourceDraw.y * width); + sourceRowPointer = spriteBuffer + clipData.drawSource.x + (clipData.drawSource.y * width); - destRowPointer = (byte *)ds->pixels + clipData.destDraw.x + (clipData.destDraw.y * ds->pitch); - maskRowPointer = maskBuffer + clipData.destDraw.x + (clipData.destDraw.y * maskWidth); + destRowPointer = (byte *)ds->pixels + clipData.drawDest.x + (clipData.drawDest.y * ds->pitch); + maskRowPointer = maskBuffer + clipData.drawDest.x + (clipData.drawDest.y * maskWidth); - for (y = 0; y < clipData.height; y++) { + for (y = 0; y < clipData.drawHeight; y++) { sourcePointer = sourceRowPointer; destPointer = destRowPointer; maskPointer = maskRowPointer; - for (x = 0; x < clipData.width; x++) { + for (x = 0; x < clipData.drawWidth; x++) { if (*sourcePointer != 0) { maskZ = *maskPointer & SPRITE_ZMASK; if (maskZ > depth) { diff --git a/saga/sprite.h b/saga/sprite.h index a12b35943c..aee5b5b4fc 100644 --- a/saga/sprite.h +++ b/saga/sprite.h @@ -71,15 +71,15 @@ public: ~Sprite(void); // draw scaled sprite using background scene mask - void drawOccluded(SURFACE *ds, const Rect &clipRect, SpriteList &spriteList, int spriteNumber, const Point &screenCoord, int scale, int depth); + void drawOccluded(Surface *ds, const Rect &clipRect, SpriteList &spriteList, int spriteNumber, const Point &screenCoord, int scale, int depth); // draw scaled sprite using background scene mask - void draw(SURFACE *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Point &screenCoord, int scale); + void draw(Surface *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Point &screenCoord, int scale); // main function - void drawClip(SURFACE *ds, const Rect &clipRect, const Point &spritePointer, int width, int height, const byte *spriteBuffer); + void drawClip(Surface *ds, const Rect &clipRect, const Point &spritePointer, int width, int height, const byte *spriteBuffer); - void draw(SURFACE *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Rect &screenRect, int scale); + void draw(Surface *ds, const Rect &clipRect, SpriteList &spriteList, int32 spriteNumber, const Rect &screenRect, int scale); int loadList(int resourceId, SpriteList &spriteList); // load or append spriteList bool hitTest(SpriteList &spriteList, int spriteNumber, const Point &screenCoord, int scale, const Point &testPoint); diff --git a/saga/text.cpp b/saga/text.cpp index 86e585ed7a..e3d6312ae1 100644 --- a/saga/text.cpp +++ b/saga/text.cpp @@ -32,7 +32,7 @@ namespace Saga { -int SagaEngine::textDraw(int font_id, SURFACE *ds, const char *string, int text_x, int text_y, int color, +int SagaEngine::textDraw(int font_id, Surface *ds, const char *string, int text_x, int text_y, int color, int effect_color, int flags) { int string_w; int string_len; @@ -172,7 +172,7 @@ void SagaEngine::textDestroyList(TEXTLIST *tlist) { return; } -int SagaEngine::textDrawList(TEXTLIST *textlist, SURFACE *ds) { +int SagaEngine::textDrawList(TEXTLIST *textlist, Surface *ds) { TEXTLIST_ENTRY *entry_p; assert((textlist != NULL) && (ds != NULL)); diff --git a/saga/transitions.cpp b/saga/transitions.cpp index 6df47be404..6f51c433be 100644 --- a/saga/transitions.cpp +++ b/saga/transitions.cpp @@ -30,7 +30,7 @@ namespace Saga { * Dissolve one image with another. * If flags if set to 1, do zero masking. */ -int SagaEngine::transitionDissolve(byte *dst_img, int dst_w, int dst_h, int dst_p, const byte *src_img, +int SagaEngine::transitionDissolve(byte *dst_img, int dst_w, int dst_h, const byte *src_img, int src_w, int src_h, int flags, int x, int y, double percent) { #define XOR_MASK 0xB400; -- cgit v1.2.3