Permalink
Browse files

STARTREK: Rename fixed-point types

  • Loading branch information...
Drenn1 authored and sev- committed Jul 19, 2018
1 parent ac9cd1f commit 710b9db0fd2e724dde746aa9b2319933fe21cbe0
@@ -105,9 +105,9 @@ void StarTrekEngine::loadRoom(const Common::String &missionName, int roomIndex)
actorFunc1();
initActors();

Fixed16 num = _room->getMaxScale() - _room->getMinScale();
Fixed8 num = _room->getMaxScale() - _room->getMinScale();
int16 den = _room->getMaxY() - _room->getMinY() + 1;
_playerActorScale = Fixed32(num) / den;
_playerActorScale = Fixed16(num) / den;

// TODO: RDF vars 1e/1f and 20/21; relates to BAN files?

@@ -446,21 +446,21 @@ void StarTrekEngine::unloadRoom() {
* further up (away) the object is, the smaller it is.
*/
int StarTrekEngine::loadActorAnimWithRoomScaling(int actorIndex, const Common::String &animName, int16 x, int16 y) {
Fixed16 scale = getActorScaleAtPosition(y);
Fixed8 scale = getActorScaleAtPosition(y);
return loadActorAnim(actorIndex, animName, x, y, scale);
}

Fixed16 StarTrekEngine::getActorScaleAtPosition(int16 y) {
Fixed8 StarTrekEngine::getActorScaleAtPosition(int16 y) {
int16 maxY = _room->getMaxY();
int16 minY = _room->getMinY();
Fixed16 minScale = _room->getMinScale();
Fixed8 minScale = _room->getMinScale();

if (y > maxY)
y = maxY;
if (y < minY)
y = minY;

return Fixed16(_playerActorScale * (y - minY)) + minScale;
return Fixed8(_playerActorScale * (y - minY)) + minScale;
}

SharedPtr<Room> StarTrekEngine::getRoom() {
@@ -142,10 +142,10 @@ int32 operator*(const int16 lhs, const TFixedInt<T, totalBits, decimalBits> &rhs
typedef TFixedInt<int16, 16, 14> Fixed14;

// Fixed-point (8.8) number
typedef TFixedInt<int16, 16, 8> Fixed16;
typedef TFixedInt<int16, 16, 8> Fixed8;

// Fixed-point (16.16) number
typedef TFixedInt<int32, 32, 16> Fixed32;
typedef TFixedInt<int32, 32, 16> Fixed16;

}

@@ -81,7 +81,7 @@ struct Actor {
uint16 animType;
Sprite sprite;
char bitmapFilename[10];
Fixed16 scale;
Fixed8 scale;
SharedPtr<FileStream> animFile;
uint16 numAnimFrames;
uint16 animFrame;
@@ -106,12 +106,12 @@ struct Actor {
int16 iwDestPosition;

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

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

Common::Point dest; // Position object is walking toward
uint16 field90;
@@ -66,8 +66,8 @@ class Room {
// the "max Y" value.
uint16 getMaxY() { return readRdfWord(0x06); }
uint16 getMinY() { return readRdfWord(0x08); }
Fixed16 getMinScale() { return Fixed16::fromRaw(readRdfWord(0x0a)); }
Fixed16 getMaxScale() { return Fixed16::fromRaw(readRdfWord(0x0c)); }
Fixed8 getMinScale() { return Fixed8::fromRaw(readRdfWord(0x0a)); }
Fixed8 getMaxScale() { return Fixed8::fromRaw(readRdfWord(0x0c)); }

// words 0x0e and 0x10 in RDF file are pointers to start and end of event code.
// That code is instead rewritten on a per-room basis.
@@ -538,7 +538,7 @@ void StarTrekEngine::initActors() {
/**
* Set an actor's animation, position, and scale.
*/
int StarTrekEngine::loadActorAnim(int actorIndex, const Common::String &animName, int16 x, int16 y, Fixed16 scale) {
int StarTrekEngine::loadActorAnim(int actorIndex, const Common::String &animName, int16 x, int16 y, Fixed8 scale) {
debugC(6, kDebugGraphics, "Load animation '%s' on actor %d", animName.c_str(), actorIndex);

Actor *actor;
@@ -695,8 +695,8 @@ void StarTrekEngine::updateActorAnimations() {
if (actor->field90 == 0)
break;
actor->field90--;
Fixed32 newX = actor->granularPosX + actor->speedX;
Fixed32 newY = actor->granularPosY + actor->speedY;
Fixed16 newX = actor->granularPosX + actor->speedX;
Fixed16 newY = actor->granularPosY + actor->speedY;
if ((actor->field90 & 3) == 0) {
sprite->bitmap.reset();
updateActorPositionWhileWalking(actor, (newX + 0.5).toInt(), (newY + 0.5).toInt());
@@ -771,7 +771,7 @@ void StarTrekEngine::actorFunc1() {
}
}

void StarTrekEngine::drawActorToScreen(Actor *actor, const Common::String &_animName, int16 x, int16 y, Fixed16 scale, bool addSprite) {
void StarTrekEngine::drawActorToScreen(Actor *actor, const Common::String &_animName, int16 x, int16 y, Fixed8 scale, bool addSprite) {
Common::String animFilename = _animName;
if (_animName.hasPrefixIgnoreCase("stnd") /* && word_45d20 == -1 */) // TODO
animFilename += 'j';
@@ -861,7 +861,7 @@ void StarTrekEngine::initStandAnim(int actorIndex) {
else // Default to facing south
animName = Common::String(actor->animationString) + 's';

Fixed16 scale = getActorScaleAtPosition(actor->pos.y);
Fixed8 scale = getActorScaleAtPosition(actor->pos.y);
loadActorAnim(actorIndex, animName, actor->pos.x, actor->pos.y, scale);
actor->animType = 0;
}
@@ -918,7 +918,7 @@ void StarTrekEngine::chooseActorDirectionForWalking(Actor *actor, int16 srcX, in
else
actor->speedX = -1.0;

actor->speedY = Fixed32(distY) / absDistX;
actor->speedY = Fixed16(distY) / absDistX;
}
}
else {
@@ -941,7 +941,7 @@ void StarTrekEngine::chooseActorDirectionForWalking(Actor *actor, int16 srcX, in
else
actor->speedY = -1.0;

actor->speedX = Fixed32(distX) / absDistY;
actor->speedX = Fixed16(distX) / absDistY;
}
}
}
@@ -958,15 +958,15 @@ bool StarTrekEngine::directPathExists(int16 srcX, int16 srcY, int16 destX, int16
int32 absDistY = abs(distY);

int32 distCounter;
Fixed32 speedX, speedY;
Fixed16 speedX, speedY;

if (absDistX > absDistY) {
distCounter = absDistX;

if (distCounter == 0)
return true;

speedY = Fixed32(distY) / absDistX;
speedY = Fixed16(distY) / absDistX;

if (distX > 0)
speedX = 1.0;
@@ -979,16 +979,16 @@ bool StarTrekEngine::directPathExists(int16 srcX, int16 srcY, int16 destX, int16
if (distCounter == 0)
return true;

speedX = Fixed32(distX) / absDistY;
speedX = Fixed16(distX) / absDistY;

if (distY > 0)
speedY = 1.0;
else
speedY = -1.0;
}

Fixed32 fixedX = srcX;
Fixed32 fixedY = srcY;
Fixed16 fixedX = srcX;
Fixed16 fixedY = srcY;

if (isPositionSolid((fixedX + 0.5).toInt(), (fixedY + 0.5).toInt()))
return false;
@@ -1057,7 +1057,7 @@ int StarTrekEngine::findObjectAt(int x, int y) {
/**
* Loads a bitmap for the animation frame with the given scale.
*/
SharedPtr<Bitmap> StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed16 scale) {
SharedPtr<Bitmap> StarTrekEngine::loadAnimationFrame(const Common::String &filename, Fixed8 scale) {
SharedPtr<Bitmap> bitmapToReturn;

char basename[5];
@@ -1481,7 +1481,7 @@ void StarTrekEngine::updateCrewmanGetupTimers() {
}
else {
const char *dirs = "nsew";
Fixed16 scale = getActorScaleAtPosition(actor->sprite.pos.y);
Fixed8 scale = getActorScaleAtPosition(actor->sprite.pos.y);
d = dirs[dir];

int16 xOffset = 0, yOffset = 0;
@@ -1679,7 +1679,7 @@ void StarTrekEngine::initStarfieldSprite(Sprite *sprite, SharedPtr<Bitmap> bitma
sprite->drawMode = 1;
}

SharedPtr<Bitmap> StarTrekEngine::scaleBitmap(SharedPtr<Bitmap> bitmap, Fixed16 scale) {
SharedPtr<Bitmap> StarTrekEngine::scaleBitmap(SharedPtr<Bitmap> bitmap, Fixed8 scale) {
int scaledWidth = scale.multToInt(bitmap->width);
int scaledHeight = scale.multToInt(bitmap->height);
int origWidth = bitmap->width;
@@ -222,7 +222,7 @@ class StarTrekEngine : public ::Engine {
void handleAwayMissionEvents();
void unloadRoom();
int loadActorAnimWithRoomScaling(int actorIndex, const Common::String &animName, int16 x, int16 y);
Fixed16 getActorScaleAtPosition(int16 y);
Fixed8 getActorScaleAtPosition(int16 y);
void addAction(const Action &action);
void addAction(byte type, byte b1, byte b2, byte b3);
bool checkItemInteractionExists(int action, int activeItem, int passiveItem, int16 arg6);
@@ -284,12 +284,12 @@ class StarTrekEngine : public ::Engine {

// Actors
void initActors();
int loadActorAnim(int actorIndex, const Common::String &animName, int16 x, int16 y, Fixed16 scale);
int loadActorAnim(int actorIndex, const Common::String &animName, int16 x, int16 y, Fixed8 scale);
bool actorWalkToPosition(int actorIndex, const Common::String &animFile, int16 srcX, int16 srcY, int16 destX, int16 destY);
void updateActorAnimations();
void removeActorFromScreen(int actorIndex);
void actorFunc1();
void drawActorToScreen(Actor *actor, const Common::String &animName, int16 x, int16 y, Fixed16 scale, bool addSprite);
void drawActorToScreen(Actor *actor, const Common::String &animName, int16 x, int16 y, Fixed8 scale, bool addSprite);
void releaseAnim(Actor *actor);
void initStandAnim(int actorIndex);
void updateActorPositionWhileWalking(Actor *actor, int16 x, int16 y);
@@ -298,7 +298,7 @@ class StarTrekEngine : public ::Engine {

int findObjectAt(int x, int y);
int findObjectAt(Common::Point p) { return findObjectAt(p.x, p.y); }
SharedPtr<Bitmap> loadAnimationFrame(const Common::String &filename, Fixed16 scale);
SharedPtr<Bitmap> loadAnimationFrame(const Common::String &filename, Fixed8 scale);

int selectObjectForUseAction();
Common::String getCrewmanAnimFilename(int actorIndex, const Common::String &basename);
@@ -310,7 +310,7 @@ class StarTrekEngine : public ::Engine {
void hideInventoryIcons();
int showInventoryMenu(int x, int y, bool restoreMouse);
void initStarfieldSprite(Sprite *sprite, SharedPtr<Bitmap> bitmap, const Common::Rect &rect);
SharedPtr<Bitmap> scaleBitmap(SharedPtr<Bitmap> bitmap, Fixed16 scale);
SharedPtr<Bitmap> scaleBitmap(SharedPtr<Bitmap> bitmap, Fixed8 scale);
void scaleBitmapRow(byte *src, byte *dest, uint16 origWidth, uint16 scaledWidth);

// Events
@@ -459,7 +459,7 @@ class StarTrekEngine : public ::Engine {
Common::String _screenName; // _screenName = _missionName + _roomIndex
Common::String _mapFilename; // Similar to _screenName, but used for .map files?
SharedPtr<FileStream> _mapFile;
Fixed32 _playerActorScale;
Fixed16 _playerActorScale;

Common::String _txtFilename;
Common::String _loadedText; // TODO: might be OK to delete this

0 comments on commit 710b9db

Please sign in to comment.