diff options
author | Matthew Stewart | 2018-02-22 21:10:09 -0500 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-09 08:37:30 +0200 |
commit | c71a8a6d2acb3be145731e6af344cb16a38c6b46 (patch) | |
tree | 40ce8abb55d1f7a95fe29f4a66e1850304ea1ff7 /engines/startrek/graphics.cpp | |
parent | b84a3bb4f28eb4b9e0bcfc19d405c79867360032 (diff) | |
download | scummvm-rg350-c71a8a6d2acb3be145731e6af344cb16a38c6b46.tar.gz scummvm-rg350-c71a8a6d2acb3be145731e6af344cb16a38c6b46.tar.bz2 scummvm-rg350-c71a8a6d2acb3be145731e6af344cb16a38c6b46.zip |
STARTREK: Implement drawSprite function
Diffstat (limited to 'engines/startrek/graphics.cpp')
-rwxr-xr-x | engines/startrek/graphics.cpp | 114 |
1 files changed, 104 insertions, 10 deletions
diff --git a/engines/startrek/graphics.cpp b/engines/startrek/graphics.cpp index 5304d40dc0..acedd72ea1 100755 --- a/engines/startrek/graphics.cpp +++ b/engines/startrek/graphics.cpp @@ -43,6 +43,10 @@ Bitmap::Bitmap(Common::ReadStreamEndian *stream) { stream->read(pixels, width*height); } +Bitmap::Bitmap(int w, int h) : width(w), height(h) { + pixels = (byte*)malloc(width*height); +} + Bitmap::~Bitmap() { free(pixels); } @@ -53,22 +57,30 @@ Bitmap::~Bitmap() { Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) { _font = 0; _egaData = 0; + _priData = 0; if (ConfMan.hasKey("render_mode")) _egaMode = (Common::parseRenderMode(ConfMan.get("render_mode").c_str()) == Common::kRenderEGA) && (_vm->getGameType() != GType_STJR) && !(_vm->getFeatures() & GF_DEMO); if (_vm->getGameType() == GType_ST25 && _vm->getPlatform() == Common::kPlatformDOS) _font = new Font(_vm); + + _backgroundImage = new Bitmap(_vm->openFile("DEMON0.BMP")); + _canvas = new Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT); } Graphics::~Graphics() { if (_egaData) free(_egaData); + if (_priData) + free(_priData); delete _font; + delete _backgroundImage; + delete _canvas; } -void Graphics::setPalette(const char *paletteFile) { +void Graphics::loadPalette(const char *paletteFile) { // Set the palette from a PAL file Common::SeekableReadStream *palStream = _vm->openFile(paletteFile); @@ -86,16 +98,84 @@ void Graphics::setPalette(const char *paletteFile) { delete palStream; } -void Graphics::drawBitmap(Bitmap *bitmap) { - int xoffset = bitmap->xoffset; - int yoffset = bitmap->yoffset; - if (xoffset >= 320) - xoffset = 0; - if (yoffset >= 200) - yoffset = 0; +void Graphics::loadPri(const char *priFile) { + Common::SeekableReadStream *priStream = _vm->openFile(priFile); - _vm->_system->copyRectToScreen(bitmap->pixels, bitmap->width, xoffset, yoffset, bitmap->width, bitmap->height); - _vm->_system->updateScreen(); + free(_priData); + _priData = (byte*)malloc(SCREEN_WIDTH*SCREEN_HEIGHT/2); + priStream->read(_priData, SCREEN_WIDTH*SCREEN_HEIGHT/2); +} + +void Graphics::redrawScreen() { + // TODO: get rid of _canvas for efficiency + memcpy(_canvas->pixels, _backgroundImage->pixels, SCREEN_WIDTH*SCREEN_HEIGHT); + + // drawSprite test + Sprite spr; + memset(&spr,0,sizeof(Sprite)); + spr.bitmap = new Bitmap(_vm->openFile("MWALKE00.BMP")); + spr.drawPriority = 1; + spr.drawX = 150; + spr.drawY = 30; + + drawSprite(spr, Common::Rect(spr.drawX,spr.drawY,spr.drawX+spr.bitmap->width,spr.drawY+spr.bitmap->height)); + + drawBitmapToScreen(_canvas); +} + +// rect is the rectangle on-screen to draw. It should encompass the sprite itself, but if +// it doesn't, part of the sprite will be cut off. +void Graphics::drawSprite(const Sprite &sprite, const Common::Rect &rect) { + int drawWidth = rect.right - rect.left; + int drawHeight = rect.bottom - rect.top; + + if (drawWidth <= 0 || drawHeight <= 0) + error("drawSprite: w/h <= 0"); + + + byte *dest = _canvas->pixels + rect.top*SCREEN_WIDTH + rect.left; + int canvasOffsetToNextLine = SCREEN_WIDTH - drawWidth; + + switch(sprite.drawMode) { + case 0: { // Normal sprite + byte *src = sprite.bitmap->pixels + (rect.left - sprite.drawX) + + (rect.top - sprite.drawY) * sprite.bitmap->width; + + int spriteOffsetToNextLine = sprite.bitmap->width - drawWidth; + int priOffset = rect.top*SCREEN_WIDTH + rect.left; + + for (int y=rect.top; y<rect.bottom; y++) { + for (int x=rect.left; x<rect.right; x++) { + byte priByte = _priData[priOffset/2]; + byte bgPri; + if ((priOffset%2) == 1) + bgPri = (priByte)&0xf; + else + bgPri = (priByte)>>4; + priOffset++; + + byte b = *src++; + if (b == 0 || sprite.drawPriority < bgPri) { + dest++; + continue; + } + *dest++ = b; + } + + src += spriteOffsetToNextLine; + dest += canvasOffsetToNextLine; + priOffset += canvasOffsetToNextLine; + } + break; + } + + case 1: + case 2: + case 3: + default: + error("drawSprite: draw mode %d not implemented", sprite.drawMode); + break; + } } @@ -139,4 +219,18 @@ void Graphics::drawBackgroundImage(const char *filename) { delete imageStream; } + +void Graphics::drawBitmapToScreen(Bitmap *bitmap) { + int xoffset = bitmap->xoffset; + int yoffset = bitmap->yoffset; + if (xoffset >= 320) + xoffset = 0; + if (yoffset >= 200) + yoffset = 0; + + _vm->_system->copyRectToScreen(bitmap->pixels, bitmap->width, xoffset, yoffset, bitmap->width, bitmap->height); + _vm->_system->updateScreen(); +} + + } |