Permalink
Browse files

STARTREK: Objects and animations.

Testing them with the transporter room.
  • Loading branch information...
Drenn1 authored and sev- committed May 11, 2018
1 parent fde5f22 commit d375429abef0109a483970975b053292efa4bd6e
@@ -39,7 +39,7 @@ class FileStream : public Common::SeekableReadStreamEndian {
public:
// ReadStream functions
virtual bool eos() const;
virtual uint32 read(void* dataPtr, uint32 dataSize);
virtual uint32 read(void *dataPtr, uint32 dataSize);

// SeekableReadStream functions
virtual int32 pos() const;
@@ -31,7 +31,7 @@ static const byte CHARACTER_COUNT = 0x80;
static const byte CHARACTER_SIZE = 0x40;

Font::Font(StarTrekEngine *vm) : _vm(vm) {
SharedPtr<Common::SeekableReadStream> fontStream = _vm->openFile("FONT.FNT");
SharedPtr<Common::SeekableReadStream> fontStream = _vm->loadFile("FONT.FNT");

_characters = new Character[CHARACTER_COUNT];

@@ -33,9 +33,7 @@ namespace StarTrek {

Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {
_font = nullptr;

_egaData = nullptr;
_priData = nullptr;
_lutData = nullptr;

_screenRect = Common::Rect(SCREEN_WIDTH, SCREEN_HEIGHT);
@@ -50,65 +48,32 @@ Graphics::Graphics(StarTrekEngine *vm) : _vm(vm), _egaMode(false) {

_numSprites = 0;
_textDisplayMode = TEXTDISPLAY_WAIT;
_textboxVar2 = 0;
_textboxVar6 = 0;
_textboxHasMultipleChoices = false;

setMouseCursor(loadBitmap("pushbtn"));
CursorMan.showMouse(true);
}

Graphics::~Graphics() {
delete[] _egaData;
delete[] _priData;
delete[] _lutData;

delete _font;
}


void Graphics::loadEGAData(const char *filename) {
// Load EGA palette data
if (!_egaMode)
return;

if (!_egaData)
_egaData = new byte[256];

SharedPtr<Common::SeekableReadStream> egaStream = _vm->openFile(filename);
egaStream->read(_egaData, 256);
void Graphics::setBackgroundImage(SharedPtr<Bitmap> bitmap) {
_backgroundImage = bitmap;
}

void Graphics::drawBackgroundImage(const char *filename) {
// Draw an stjr BGD image (palette built-in)

SharedPtr<Common::SeekableReadStream> imageStream = _vm->openFile(filename);
byte *palette = new byte[256 * 3];
imageStream->read(palette, 256 * 3);

// Expand color components
for (uint16 i = 0; i < 256 * 3; i++)
palette[i] <<= 2;

uint16 xoffset = imageStream->readUint16LE();
uint16 yoffset = imageStream->readUint16LE();
uint16 width = imageStream->readUint16LE();
uint16 height = imageStream->readUint16LE();

byte *pixels = new byte[width * height];
imageStream->read(pixels, width * height);

_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
_vm->_system->copyRectToScreen(pixels, width, xoffset, yoffset, width, height);
_vm->_system->updateScreen();

delete[] palette;
}


void Graphics::loadPalette(const Common::String &paletteName) {
// Set the palette from a PAL file
Common::String palFile = paletteName + ".PAL";
Common::String lutFile = paletteName + ".LUT";

SharedPtr<Common::SeekableReadStream> palStream = _vm->openFile(palFile.c_str());
SharedPtr<Common::SeekableReadStream> palStream = _vm->loadFile(palFile.c_str());
byte *palette = new byte[256 * 3];
palStream->read(palette, 256 * 3);

@@ -122,23 +87,35 @@ void Graphics::loadPalette(const Common::String &paletteName) {
delete[] palette;

// Load LUT file
SharedPtr<Common::SeekableReadStream> lutStream = _vm->openFile(lutFile.c_str());
SharedPtr<Common::SeekableReadStream> lutStream = _vm->loadFile(lutFile.c_str());

delete[] _lutData;
_lutData = new byte[256];
lutStream->read(_lutData, 256);
}

void Graphics::loadPri(const char *priFile) {
SharedPtr<Common::SeekableReadStream> priStream = _vm->openFile(priFile);

delete[] _priData;
_priData = new byte[SCREEN_WIDTH*SCREEN_HEIGHT / 2];
SharedPtr<Common::SeekableReadStream> priStream = _vm->loadFile(priFile);
priStream->read(_priData, SCREEN_WIDTH*SCREEN_HEIGHT / 2);
}

void Graphics::clearPri() {
memset(_priData, 0, sizeof(_priData));
}

byte Graphics::getPriValue(int x, int y) {
assert(_screenRect.contains(x, y));

int priOffset = y * SCREEN_WIDTH + x;
byte b = _priData[priOffset / 2];
if ((priOffset % 2) == 1)
return b & 0xf;
else
return b >> 4;
}

SharedPtr<Bitmap> Graphics::loadBitmap(Common::String basename) {
return SharedPtr<Bitmap>(new Bitmap(_vm->openFile(basename + ".BMP")));
return SharedPtr<Bitmap>(new Bitmap(_vm->loadFile(basename + ".BMP")));
}

Common::Point Graphics::getMousePos() {
@@ -150,11 +127,6 @@ void Graphics::setMouseCursor(SharedPtr<Bitmap> bitmap) {
_vm->_system->setMouseCursor(bitmap->pixels, bitmap->width, bitmap->height, bitmap->xoffset, bitmap->yoffset, 0);
}

void Graphics::redrawScreen() {
_vm->_system->copyRectToScreen(_backgroundImage->pixels, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
drawAllSprites();
}

void Graphics::drawSprite(const Sprite &sprite) {
int left = sprite.drawX;
int top = sprite.drawY;
@@ -448,17 +420,50 @@ void Graphics::delSprite(Sprite *sprite) {
}


void Graphics::drawBitmapToScreen(Bitmap *bitmap) {
void Graphics::drawDirectToScreen(SharedPtr<Bitmap> bitmap) {
int xoffset = bitmap->xoffset;
int yoffset = bitmap->yoffset;
if (xoffset >= SCREEN_WIDTH)
xoffset = 0;
if (yoffset >= SCREEN_HEIGHT)
yoffset = 0;

_vm->_system->copyRectToScreen(bitmap->pixels, bitmap->width, xoffset, yoffset, bitmap->width, bitmap->height);
_vm->_system->updateScreen();
}


void Graphics::loadEGAData(const char *filename) {
// Load EGA palette data
if (!_egaMode)
return;

if (!_egaData)
_egaData = new byte[256];

SharedPtr<Common::SeekableReadStream> egaStream = _vm->loadFile(filename);
egaStream->read(_egaData, 256);
}

void Graphics::drawBackgroundImage(const char *filename) {
// Draw an stjr BGD image (palette built-in)

SharedPtr<Common::SeekableReadStream> imageStream = _vm->loadFile(filename);
byte *palette = new byte[256 * 3];
imageStream->read(palette, 256 * 3);

// Expand color components
for (uint16 i = 0; i < 256 * 3; i++)
palette[i] <<= 2;

uint16 xoffset = imageStream->readUint16LE();
uint16 yoffset = imageStream->readUint16LE();
uint16 width = imageStream->readUint16LE();
uint16 height = imageStream->readUint16LE();

byte *pixels = new byte[width * height];
imageStream->read(pixels, width * height);

_vm->_system->getPaletteManager()->setPalette(palette, 0, 256);
_vm->_system->copyRectToScreen(pixels, width, xoffset, yoffset, width, height);
_vm->_system->updateScreen();

delete[] palette;
}

}
@@ -70,37 +70,37 @@ class Graphics {
Graphics(StarTrekEngine *vm);
~Graphics();

void loadEGAData(const char *egaFile);
void drawBackgroundImage(const char *filename);

void setBackgroundImage(SharedPtr<Bitmap> bitmap);
void loadPalette(const String &paletteFile);
void loadPri(const char *priFile);
void clearPri();
byte getPriValue(int x, int y);

SharedPtr<Bitmap> loadBitmap(String basename);

Common::Point getMousePos();
void setMouseCursor(SharedPtr<Bitmap> bitmap);

void redrawScreen();
void drawSprite(const Sprite &sprite);
void drawSprite(const Sprite &sprite, const Common::Rect &rect);
void drawAllSprites();

void addSprite(Sprite *sprite);
void delSprite(Sprite *sprite);


void drawDirectToScreen(SharedPtr<Bitmap> bitmap);
void loadEGAData(const char *egaFile);
void drawBackgroundImage(const char *filename);

private:
void drawBitmapToScreen(Bitmap *bitmap);


StarTrekEngine *_vm;
Font *_font;

bool _egaMode;
byte *_egaData;
byte *_priData;
byte *_lutData;
byte _priData[SCREEN_WIDTH*SCREEN_HEIGHT / 2];

Common::Rect _screenRect;
SharedPtr<Bitmap> _backgroundImage;
@@ -156,11 +156,13 @@ class Graphics {

private:
int16 _textDisplayMode;

public:
uint32 _textboxVar2;
uint32 _textboxVar3;
uint16 _textboxVar6;
bool _textboxHasMultipleChoices;

private:
SharedPtr<Menu> _activeMenu;

// Saved value of StarTrekEngine::_keyboardControlsMouse when menus are up
@@ -9,6 +9,7 @@ MODULE_OBJS = \
font.o \
lzss.o \
graphics.o \
object.o \
room.o \
sound.o \
sprite.o \
@@ -0,0 +1,27 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "object.h"

namespace StarTrek {

}
@@ -0,0 +1,83 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef STARTREK_OBJECT_H
#define STARTREK_OBJECT_H

#include "startrek/sprite.h"

#include "common/scummsys.h"

namespace StarTrek {

class StarTrekEngine;
class FileStream;


struct Object {
uint16 spriteDrawn;
char animationString3[16];
uint16 animType;
Sprite sprite;
char animationString4[10];
uint16 scale;
SharedPtr<FileStream> animFile;
uint16 numAnimFrames;
uint16 animFrame;
uint32 frameToStartNextAnim;
uint16 field5e;
uint16 field60;
uint16 field62;
uint16 field64;
uint16 field66;
char animationString2[8];
uint16 field70;
uint16 field72;
uint16 field74;
uint16 field76;
uint16 iwSrcPosition;
uint16 iwDestPosition;
uint16 field7c;
uint16 field7e;
uint16 field80;
uint16 field82;
uint16 field84;
uint16 field86;
uint16 field88;
uint16 field8a;
uint16 field8c;
uint16 field8e;
uint16 field90;
uint16 field92;
uint16 field94;
uint16 field96;
char animationString[9];
uint8 fielda1;
uint16 fielda2;
uint16 fielda4;
uint16 fielda6;
};

}

#endif

Oops, something went wrong.

0 comments on commit d375429

Please sign in to comment.