Skip to content

Commit

Permalink
STARTREK: Don't memset sprites, add Fixed16 type
Browse files Browse the repository at this point in the history
  • Loading branch information
Stewmath authored and sev- committed Aug 9, 2018
1 parent 6117a89 commit ec2306f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
5 changes: 4 additions & 1 deletion engines/startrek/common.h
Expand Up @@ -36,7 +36,10 @@ Common::Rect getRectEncompassing(Common::Rect r1, Common::Rect r2);




// Fixed-point (16.16) number // Fixed-point (16.16) number
typedef int32 FixedInt; typedef int32 Fixed32;

// Fixed-point (8.8) number
typedef int16 Fixed16;


} }


Expand Down
2 changes: 1 addition & 1 deletion engines/startrek/menu.cpp
Expand Up @@ -540,7 +540,7 @@ void StarTrekEngine::loadMenuButtons(String mnuFilename, int xpos, int ypos) {
_activeMenu->numButtons = _activeMenu->menuFile->size() / 16; _activeMenu->numButtons = _activeMenu->menuFile->size() / 16;


for (int i = 0; i < _activeMenu->numButtons; i++) { for (int i = 0; i < _activeMenu->numButtons; i++) {
memset(&_activeMenu->sprites[i], 0, sizeof(Sprite)); _activeMenu->sprites[i] = Sprite();
_gfx->addSprite(&_activeMenu->sprites[i]); _gfx->addSprite(&_activeMenu->sprites[i]);
_activeMenu->sprites[i].drawMode = 2; _activeMenu->sprites[i].drawMode = 2;


Expand Down
10 changes: 5 additions & 5 deletions engines/startrek/object.h
Expand Up @@ -40,7 +40,7 @@ struct Object {
uint16 animType; uint16 animType;
Sprite sprite; Sprite sprite;
char animationString4[10]; char animationString4[10];
uint16 scale; Fixed16 scale;
SharedPtr<FileStream> animFile; SharedPtr<FileStream> animFile;
uint16 numAnimFrames; uint16 numAnimFrames;
uint16 animFrame; uint16 animFrame;
Expand All @@ -59,12 +59,12 @@ struct Object {
int16 iwDestPosition; int16 iwDestPosition;


// Fixed-point position values (16.16) used while walking. // Fixed-point position values (16.16) used while walking.
FixedInt granularPosX; Fixed32 granularPosX;
FixedInt granularPosY; Fixed32 granularPosY;


// Fixed-point speed values (16.16). // Fixed-point speed values (16.16).
FixedInt speedX; Fixed32 speedX;
FixedInt speedY; Fixed32 speedY;


Common::Point dest; // Position object is walking toward Common::Point dest; // Position object is walking toward
uint16 field90; uint16 field90;
Expand Down
16 changes: 8 additions & 8 deletions engines/startrek/startrek.cpp
Expand Up @@ -344,7 +344,7 @@ void StarTrekEngine::initObjects() {
/** /**
* Set an object's animation, position, and scale. * Set an object's animation, position, and scale.
*/ */
int StarTrekEngine::loadObjectAnim(int objectIndex, const Common::String &animName, int16 x, int16 y, uint16 scale) { int StarTrekEngine::loadObjectAnim(int objectIndex, const Common::String &animName, int16 x, int16 y, Fixed16 scale) {
debugC(6, kDebugGraphics, "Load animation '%s' on object %d", animName.c_str(), objectIndex); debugC(6, kDebugGraphics, "Load animation '%s' on object %d", animName.c_str(), objectIndex);


Object *object; Object *object;
Expand Down Expand Up @@ -576,7 +576,7 @@ void StarTrekEngine::objectFunc1() {
} }
} }


void StarTrekEngine::drawObjectToScreen(Object *object, const Common::String &_animName, int16 x, int16 y, uint16 scale, bool addSprite) { void StarTrekEngine::drawObjectToScreen(Object *object, const Common::String &_animName, int16 x, int16 y, Fixed16 scale, bool addSprite) {
Common::String animFilename = _animName; Common::String animFilename = _animName;
if (_animName.hasPrefixIgnoreCase("stnd") /* && word_45d20 == -1 */) // TODO if (_animName.hasPrefixIgnoreCase("stnd") /* && word_45d20 == -1 */) // TODO
animFilename += 'j'; animFilename += 'j';
Expand Down Expand Up @@ -762,7 +762,7 @@ bool StarTrekEngine::directPathExists(int16 srcX, int16 srcY, int16 destX, int16
int32 absDistY = abs(distY); int32 absDistY = abs(distY);


int32 distCounter; int32 distCounter;
FixedInt speedX, speedY; Fixed32 speedX, speedY;


if (absDistX > absDistY) { if (absDistX > absDistY) {
distCounter = absDistX; distCounter = absDistX;
Expand Down Expand Up @@ -791,8 +791,8 @@ bool StarTrekEngine::directPathExists(int16 srcX, int16 srcY, int16 destX, int16
speedY = -1 << 16; speedY = -1 << 16;
} }


FixedInt fixedX = srcX << 16; Fixed32 fixedX = srcX << 16;
FixedInt fixedY = srcY << 16; Fixed32 fixedY = srcY << 16;


if (isPositionSolid((fixedX + 0x8000) >> 16, (fixedY + 0x8000) >> 16)) if (isPositionSolid((fixedX + 0x8000) >> 16, (fixedY + 0x8000) >> 16))
return false; return false;
Expand Down Expand Up @@ -837,7 +837,7 @@ int StarTrekEngine::findObjectAt(int x, int y) {
int objectIndex = _room->readRdfWord(offset + 6); int objectIndex = _room->readRdfWord(offset + 6);
// word_4b418 = 1; // word_4b418 = 1;
// word_4a792 = _room->readRdfWord(offset + 2); // word_4a792 = _room->readRdfWord(offset + 2);
// word_4a796 = _room->readRdfWord(offset + 4); // word_4a796 = _room->readRdfWord(offset + 4); // TODO
return objectIndex; return objectIndex;
} }


Expand All @@ -861,7 +861,7 @@ int StarTrekEngine::findObjectAt(int x, int y) {
/** /**
* Loads a bitmap for the animation frame with the given scale. * Loads a bitmap for the animation frame with the given scale.
*/ */
SharedPtr<Bitmap> StarTrekEngine::loadAnimationFrame(const Common::String &filename, uint16 scale) { SharedPtr<Bitmap> StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed16 scale) {
SharedPtr<Bitmap> bitmapToReturn; SharedPtr<Bitmap> bitmapToReturn;


char basename[5]; char basename[5];
Expand Down Expand Up @@ -1239,7 +1239,7 @@ int StarTrekEngine::showInventoryMenu(int x, int y, bool restoreMouse) {
/** /**
* A scale of 256 is the baseline. * A scale of 256 is the baseline.
*/ */
SharedPtr<Bitmap> StarTrekEngine::scaleBitmap(SharedPtr<Bitmap> bitmap, uint16 scale) { SharedPtr<Bitmap> StarTrekEngine::scaleBitmap(SharedPtr<Bitmap> bitmap, Fixed16 scale) {
int scaledWidth = (bitmap->width * scale) >> 8; int scaledWidth = (bitmap->width * scale) >> 8;
int scaledHeight = (bitmap->height * scale) >> 8; int scaledHeight = (bitmap->height * scale) >> 8;
int origWidth = bitmap->width; int origWidth = bitmap->width;
Expand Down
8 changes: 4 additions & 4 deletions engines/startrek/startrek.h
Expand Up @@ -246,12 +246,12 @@ class StarTrekEngine : public ::Engine {


// Objects // Objects
void initObjects(); void initObjects();
int loadObjectAnim(int objectIndex, const Common::String &animName, int16 x, int16 y, uint16 arg8); int loadObjectAnim(int objectIndex, const Common::String &animName, int16 x, int16 y, Fixed16 scale);
bool objectWalkToPosition(int objectIndex, const Common::String &animFile, int16 srcX, int16 srcY, int16 destX, int16 destY); bool objectWalkToPosition(int objectIndex, const Common::String &animFile, int16 srcX, int16 srcY, int16 destX, int16 destY);
void updateObjectAnimations(); void updateObjectAnimations();
void removeObjectFromScreen(int objectIndex); void removeObjectFromScreen(int objectIndex);
void objectFunc1(); void objectFunc1();
void drawObjectToScreen(Object *object, const Common::String &animName, int16 x, int16 y, uint16 scale, bool addSprite); void drawObjectToScreen(Object *object, const Common::String &animName, int16 x, int16 y, Fixed16 scale, bool addSprite);
void releaseAnim(Object *object); void releaseAnim(Object *object);
void initStandAnim(int objectIndex); void initStandAnim(int objectIndex);
void updateObjectPositionWhileWalking(Object *object, int16 x, int16 y); void updateObjectPositionWhileWalking(Object *object, int16 x, int16 y);
Expand All @@ -260,13 +260,13 @@ class StarTrekEngine : public ::Engine {


int findObjectAt(int x, int y); int findObjectAt(int x, int y);
int findObjectAt(Common::Point p) { return findObjectAt(p.x, p.y); } int findObjectAt(Common::Point p) { return findObjectAt(p.x, p.y); }
SharedPtr<Bitmap> loadAnimationFrame(const Common::String &filename, uint16 arg2); SharedPtr<Bitmap> loadAnimationFrame(const Common::String &filename, Fixed16 scale);
Common::String getCrewmanAnimFilename(int objectIndex, const Common::String &basename); Common::String getCrewmanAnimFilename(int objectIndex, const Common::String &basename);
void updateMouseBitmap(); void updateMouseBitmap();
void showInventoryIcons(bool showItem); void showInventoryIcons(bool showItem);
void hideInventoryIcons(); void hideInventoryIcons();
int showInventoryMenu(int x, int y, bool restoreMouse); int showInventoryMenu(int x, int y, bool restoreMouse);
SharedPtr<Bitmap> scaleBitmap(SharedPtr<Bitmap> bitmap, uint16 scale); SharedPtr<Bitmap> scaleBitmap(SharedPtr<Bitmap> bitmap, Fixed16 scale);
void scaleBitmapRow(byte *src, byte *dest, uint16 origWidth, uint16 scaledWidth); void scaleBitmapRow(byte *src, byte *dest, uint16 origWidth, uint16 scaledWidth);


// Events // Events
Expand Down
2 changes: 1 addition & 1 deletion engines/startrek/text.cpp
Expand Up @@ -469,7 +469,7 @@ SharedPtr<TextBitmap> StarTrekEngine::initTextSprite(int *xoffsetPtr, int *yoffs


SharedPtr<TextBitmap> bitmap(new TextBitmap(TEXTBOX_WIDTH*8, textHeight*8)); SharedPtr<TextBitmap> bitmap(new TextBitmap(TEXTBOX_WIDTH*8, textHeight*8));


memset(sprite, 0, sizeof(Sprite)); *sprite = Sprite();
sprite->drawPriority = 15; sprite->drawPriority = 15;
sprite->drawPriority2 = 8; sprite->drawPriority2 = 8;
sprite->bitmap = bitmap; sprite->bitmap = bitmap;
Expand Down

0 comments on commit ec2306f

Please sign in to comment.