- Adapt parts of the Draci code to match our code formatting guidelines

- Remove use of tabs for formatting, now in nearly all cases tabs are only used for indentation
- Use "uint" instead of "unsigned int" in the whole engine for consistency's sake
- Strip some trailing tabs and leading whitespaces

svn-id: r44478
This commit is contained in:
Johannes Schickel 2009-09-30 10:45:14 +00:00
parent 4477f41903
commit c9ca057ae2
21 changed files with 398 additions and 504 deletions

View file

@ -51,7 +51,6 @@ bool Animation::isLooping() const {
}
void Animation::setRelative(int relx, int rely) {
// Delete the previous frame if there is one
if (_frames.size() > 0)
markDirtyRect(_vm->_screen->getSurface());
@ -76,7 +75,6 @@ void Animation::markDirtyRect(Surface *surface) const {
}
void Animation::nextFrame(bool force) {
// If there are no frames or if the animation is not playing, return
if (getFrameCount() == 0 || !_playing)
return;
@ -109,7 +107,6 @@ void Animation::nextFrame(bool force) {
}
uint Animation::nextFrameNum() const {
if (_paused)
return _currentFrame;
@ -120,7 +117,6 @@ uint Animation::nextFrameNum() const {
}
void Animation::drawFrame(Surface *surface) {
// If there are no frames or the animation is not playing, return
if (_frames.size() == 0 || !_playing)
return;
@ -177,7 +173,6 @@ void Animation::setPaused(bool paused) {
}
void Animation::setScaleFactors(double scaleX, double scaleY) {
debugC(5, kDraciAnimationDebugLevel,
"Setting scaling factors on anim %d (scaleX: %.3f scaleY: %.3f)",
_id, scaleX, scaleY);
@ -209,7 +204,6 @@ void Animation::setIndex(int index) {
}
Drawable *Animation::getFrame(int frameNum) {
// If there are no frames stored, return NULL
if (_frames.size() == 0) {
return NULL;
@ -232,7 +226,6 @@ uint Animation::currentFrameNum() const {
}
void Animation::setCurrentFrame(uint frame) {
// Check whether the value is sane
if (frame >= _frames.size()) {
return;
@ -242,7 +235,6 @@ void Animation::setCurrentFrame(uint frame) {
}
void Animation::deleteFrames() {
// If there are no frames to delete, return
if (_frames.size() == 0) {
return;
@ -265,7 +257,6 @@ void Animation::exitGameLoop() {
}
Animation *AnimationManager::addAnimation(int id, uint z, bool playing) {
// Increment animation index
++_lastIndex;
@ -281,7 +272,6 @@ Animation *AnimationManager::addAnimation(int id, uint z, bool playing) {
}
Animation *AnimationManager::addItem(int id, bool playing) {
Animation *anim = new Animation(_vm, kIgnoreIndex);
anim->setID(id);
@ -294,7 +284,6 @@ Animation *AnimationManager::addItem(int id, bool playing) {
}
Animation *AnimationManager::addText(int id, bool playing) {
Animation *anim = new Animation(_vm, kIgnoreIndex);
anim->setID(id);
@ -336,7 +325,6 @@ void AnimationManager::stop(int id) {
}
void AnimationManager::pauseAnimations() {
Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) {
@ -350,7 +338,6 @@ void AnimationManager::pauseAnimations() {
}
void AnimationManager::unpauseAnimations() {
Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) {
@ -364,7 +351,6 @@ void AnimationManager::unpauseAnimations() {
}
Animation *AnimationManager::getAnimation(int id) {
Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) {
@ -377,7 +363,6 @@ Animation *AnimationManager::getAnimation(int id) {
}
void AnimationManager::insertAnimation(Animation *anim) {
Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) {
@ -403,7 +388,6 @@ void AnimationManager::addOverlay(Drawable *overlay, uint z) {
}
void AnimationManager::drawScene(Surface *surf) {
// Fill the screen with colour zero since some rooms may rely on the screen being black
_vm->_screen->getSurface()->fill(0);
@ -462,7 +446,6 @@ void AnimationManager::sortAnimations() {
}
void AnimationManager::deleteAnimation(int id) {
Common::List<Animation *>::iterator it;
int index = -1;
@ -494,7 +477,6 @@ void AnimationManager::deleteAnimation(int id) {
}
void AnimationManager::deleteOverlays() {
debugC(3, kDraciAnimationDebugLevel, "Deleting overlays...");
Common::List<Animation *>::iterator it;
@ -508,7 +490,6 @@ void AnimationManager::deleteOverlays() {
}
void AnimationManager::deleteAll() {
debugC(3, kDraciAnimationDebugLevel, "Deleting all animations...");
Common::List<Animation *>::iterator it;
@ -527,7 +508,6 @@ int AnimationManager::getLastIndex() const {
}
void AnimationManager::deleteAfterIndex(int index) {
Common::List<Animation *>::iterator it;
for (it = _animations.begin(); it != _animations.end(); ++it) {
@ -544,7 +524,6 @@ void AnimationManager::deleteAfterIndex(int index) {
}
int AnimationManager::getTopAnimationID(int x, int y) const {
Common::List<Animation *>::const_iterator it;
// The default return value if no animations were found on these coordinates (not even overlays)
@ -570,7 +549,6 @@ int AnimationManager::getTopAnimationID(int x, int y) const {
}
if (frame->getRect(anim->getDisplacement()).contains(x, y)) {
if (frame->getType() == kDrawableText) {
retval = anim->getID();

View file

@ -34,14 +34,16 @@ namespace Draci {
* Animation IDs for those animations that don't have their IDs
* specified in the data files.
*/
enum { kOverlayImage = -1,
enum {
kOverlayImage = -1,
kWalkingMapOverlay = -2,
kTitleText = -3,
kSpeechText = -4,
kInventorySprite = -5,
kDialogueLinesID = -6,
kUnused = -10,
kInventoryItemsID = -11};
kInventoryItemsID = -11
};
/**
* Default argument to Animation::getFrame() that makes it return
@ -112,7 +114,6 @@ public:
void exitGameLoop();
private:
uint nextFrameNum() const;
void deleteFrames();
@ -138,7 +139,7 @@ private:
/** Array of frames of the animation. The animation object owns these pointers.
*/
Common::Array<Drawable*> _frames;
Common::Array<Drawable *> _frames;
AnimationCallback _callback;

View file

@ -100,7 +100,7 @@ void BArchive::openDFW(const Common::String &path) {
// The data will be read on demand to save memory
_files = new BAFile[_fileCount];
Common::MemoryReadStream tableReader(table, tableSize);
for (unsigned int i = 0; i < _fileCount; ++i) {
for (uint i = 0; i < _fileCount; ++i) {
_files[i]._compLength = tableReader.readUint16LE();
_files[i]._offset = tableReader.readUint32LE();
@ -207,7 +207,7 @@ void BArchive::openArchive(const Common::String &path) {
// The data will be read on demand to save memory
_files = new BAFile[_fileCount];
for (unsigned int i = 0; i < _fileCount; i++) {
for (uint i = 0; i < _fileCount; i++) {
uint32 fileOffset;
fileOffset = reader.readUint32LE();
@ -249,7 +249,7 @@ void BArchive::closeArchive(void) {
return;
}
for (unsigned int i = 0; i < _fileCount; ++i) {
for (uint i = 0; i < _fileCount; ++i) {
if (_files[i]._data) {
delete[] _files[i]._data;
}
@ -271,7 +271,7 @@ void BArchive::closeArchive(void) {
* Should not be called directly. Instead, one should access files
* through the operator[] interface.
*/
BAFile *BArchive::loadFileBAR(unsigned int i) const {
BAFile *BArchive::loadFileBAR(uint i) const {
Common::File f;
// Else open archive and read in requested file
@ -290,7 +290,7 @@ BAFile *BArchive::loadFileBAR(unsigned int i) const {
// Calculate CRC
byte tmp = 0;
for (unsigned int j = 0; j < _files[i]._length; j++) {
for (uint j = 0; j < _files[i]._length; j++) {
tmp ^= _files[i]._data[j];
}
@ -310,7 +310,7 @@ BAFile *BArchive::loadFileBAR(unsigned int i) const {
* Should not be called directly. Instead, one should access files
* through the operator[] interface.
*/
BAFile *BArchive::loadFileDFW(unsigned int i) const {
BAFile *BArchive::loadFileDFW(uint i) const {
Common::File f;
byte *buf;
@ -351,12 +351,11 @@ BAFile *BArchive::loadFileDFW(unsigned int i) const {
// Uncompress file
byte current, what;
byte stopper = _files[i]._stopper;
unsigned int repeat;
unsigned int len = 0; // Sanity check (counts uncompressed bytes)
uint repeat;
uint len = 0; // Sanity check (counts uncompressed bytes)
current = data.readByte(); // Read initial byte
while (!data.eos()) {
if (current != stopper) {
*dst++ = current;
++len;
@ -365,7 +364,7 @@ BAFile *BArchive::loadFileDFW(unsigned int i) const {
repeat = data.readByte();
what = data.readByte();
len += repeat;
for (unsigned int j = 0; j < repeat; ++j) {
for (uint j = 0; j < repeat; ++j) {
*dst++ = what;
}
}
@ -385,16 +384,13 @@ BAFile *BArchive::loadFileDFW(unsigned int i) const {
* If the files are subsequently accessed, they are read from the disk.
*/
void BArchive::clearCache() {
// Delete all cached data
for (unsigned int i = 0; i < _fileCount; ++i) {
for (uint i = 0; i < _fileCount; ++i) {
_files[i].close();
}
}
const BAFile *BArchive::getFile(unsigned int i) const {
const BAFile *BArchive::getFile(uint i) const {
// Check whether requested file exists
if (i >= _fileCount) {
return NULL;

View file

@ -33,7 +33,6 @@ namespace Draci {
/**
* Represents individual files inside the archive.
*/
struct BAFile {
uint _compLength; //!< Compressed length (the same as _length if the file is uncompressed)
uint _length; //!< Uncompressed length
@ -72,16 +71,16 @@ public:
void clearCache();
const BAFile *getFile(unsigned int i) const;
const BAFile *getFile(uint i) const;
private:
// Archive header data
static const char _magicNumber[];
static const char _dfwMagicNumber[];
static const unsigned int _archiveHeaderSize = 10;
static const uint _archiveHeaderSize = 10;
// File stream header data
static const unsigned int _fileHeaderSize = 6;
static const uint _fileHeaderSize = 6;
Common::String _path; //!< Path to file
BAFile *_files; //!< Internal array of files
@ -90,8 +89,8 @@ private:
bool _opened; //!< True if the archive is opened, false otherwise
void openDFW(const Common::String &path);
BAFile *loadFileDFW(unsigned int i) const;
BAFile *loadFileBAR(unsigned int i) const;
BAFile *loadFileDFW(uint i) const;
BAFile *loadFileBAR(uint i) const;
};
} // End of namespace Draci

View file

@ -38,7 +38,6 @@ namespace Draci {
using Common::GUIO_NONE;
const ADGameDescription gameDescriptions[] = {
{
"draci",
0,

View file

@ -109,42 +109,42 @@ int DraciEngine::init() {
_script = new Script(this);
_game = new Game(this);
if(!_objectsArchive->isOpen()) {
if (!_objectsArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening objects archive failed");
return Common::kUnknownError;
}
if(!_spritesArchive->isOpen()) {
if (!_spritesArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening sprites archive failed");
return Common::kUnknownError;
}
if(!_paletteArchive->isOpen()) {
if (!_paletteArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening palette archive failed");
return Common::kUnknownError;
}
if(!_roomsArchive->isOpen()) {
if (!_roomsArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening rooms archive failed");
return Common::kUnknownError;
}
if(!_overlaysArchive->isOpen()) {
if (!_overlaysArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening overlays archive failed");
return Common::kUnknownError;
}
if(!_animationsArchive->isOpen()) {
if (!_animationsArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening animations archive failed");
return Common::kUnknownError;
}
if(!_iconsArchive->isOpen()) {
if (!_iconsArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening icons archive failed");
return Common::kUnknownError;
}
if(!_walkingMapsArchive->isOpen()) {
if (!_walkingMapsArchive->isOpen()) {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Opening walking maps archive failed");
return Common::kUnknownError;
}
@ -158,7 +158,7 @@ int DraciEngine::init() {
const BAFile *f;
debugC(3, kDraciGeneralDebugLevel, "Number of file streams in archive: %d", ar.size());
if(ar.isOpen()) {
if (ar.isOpen()) {
f = ar.getFile(0);
} else {
debugC(2, kDraciGeneralDebugLevel, "ERROR - Archive not opened");
@ -166,7 +166,7 @@ int DraciEngine::init() {
}
debugC(3, kDraciGeneralDebugLevel, "First 10 bytes of file %d: ", 0);
for (unsigned int i = 0; i < 10; ++i) {
for (uint i = 0; i < 10; ++i) {
debugC(3, kDraciGeneralDebugLevel, "0x%02x%c", f->_data[i], (i < 9) ? ' ' : '\n');
}
@ -195,12 +195,10 @@ bool DraciEngine::handleEvents() {
if (event.kbd.keycode == Common::KEYCODE_RIGHT) {
_game->setRoomNum(_game->nextRoomNum());
_game->setGateNum(0);
}
else if (event.kbd.keycode == Common::KEYCODE_LEFT) {
} else if (event.kbd.keycode == Common::KEYCODE_LEFT) {
_game->setRoomNum(_game->prevRoomNum());
_game->setGateNum(0);
}
else if (event.kbd.keycode == Common::KEYCODE_ESCAPE) {
} else if (event.kbd.keycode == Common::KEYCODE_ESCAPE) {
int escRoom = _game->getEscRoom();
// Check if there is an escape room defined for the current room
@ -214,8 +212,7 @@ bool DraciEngine::handleEvents() {
// End any currently running GPL programs
_script->endCurrentProgram();
}
}
else if (event.kbd.keycode == Common::KEYCODE_m) {
} else if (event.kbd.keycode == Common::KEYCODE_m) {
if (_game->getLoopStatus() == kStatusOrdinary) {
// TODO: record the current room number
// so that we can quickly exit there
@ -223,13 +220,11 @@ bool DraciEngine::handleEvents() {
_game->setRoomNum(_game->getMapRoom());
_game->setGateNum(0);
}
}
} else if (event.kbd.keycode == Common::KEYCODE_w) {
// Show walking map toggle
else if (event.kbd.keycode == Common::KEYCODE_w) {
_showWalkingMap = !_showWalkingMap;
}
else if (event.kbd.keycode == Common::KEYCODE_i) {
if(_game->getLoopStatus() == kStatusInventory &&
} else if (event.kbd.keycode == Common::KEYCODE_i) {
if (_game->getLoopStatus() == kStatusInventory &&
_game->getLoopSubstatus() == kSubstatusOrdinary) {
_game->inventoryDone();
} else if (_game->getLoopStatus() == kStatusOrdinary &&

View file

@ -30,11 +30,10 @@
namespace Draci {
const char *kFontSmall = "Small.fon";
const char *kFontBig = "Big.fon";
const char * const kFontSmall = "Small.fon";
const char * const kFontBig = "Big.fon";
Font::Font(const Common::String &filename) {
_fontHeight = 0;
_maxCharWidth = 0;
_charWidths = NULL;
@ -66,7 +65,6 @@ Font::~Font() {
*/
bool Font::loadFont(const Common::String &filename) {
// Free previously loaded font (if any)
freeFont();
@ -87,12 +85,12 @@ bool Font::loadFont(const Common::String &filename) {
// Read in the widths of the glyphs
_charWidths = new uint8[kCharNum];
for (unsigned int i = 0; i < kCharNum; ++i) {
for (uint i = 0; i < kCharNum; ++i) {
_charWidths[i] = f.readByte();
}
// Calculate size of font data
unsigned int fontDataSize = kCharNum * _maxCharWidth * _fontHeight;
uint fontDataSize = kCharNum * _maxCharWidth * _fontHeight;
// Read in all glyphs
_charData = new byte[fontDataSize];
@ -153,7 +151,6 @@ void Font::drawChar(Surface *dst, uint8 chr, int tx, int ty, int with_colour) co
// Replace colour with font colours
switch (colour) {
case 254:
colour = with_colour;
break;
@ -190,7 +187,6 @@ void Font::drawChar(Surface *dst, uint8 chr, int tx, int ty, int with_colour) co
* @param y Vertical offset on the surface
* @param spacing Space to leave between individual characters. Defaults to 0.
*/
void Font::drawString(Surface *dst, const byte *str, uint len,
int x, int y, int with_colour, int spacing, bool markDirty) const {
drawString(dst, Common::String((const char *)str, len), x, y, with_colour, spacing, markDirty);
@ -250,14 +246,13 @@ void Font::drawString(Surface *dst, const Common::String &str,
*
* @return The calculated width of the string
*/
uint Font::getStringWidth(const Common::String &str, int spacing) const {
unsigned int width = 0;
uint width = 0;
// Real length, including '|' separators
uint len = str.size();
for (unsigned int i = 0, tmp = 0; i < len; ++i) {
for (uint i = 0, tmp = 0; i < len; ++i) {
if (str[i] != '|') {
uint8 charIndex = str[i] - kCharIndexOffset;
@ -281,7 +276,6 @@ uint Font::getStringWidth(const Common::String &str, int spacing) const {
}
uint Font::getLineWidth(const Common::String &str, uint startIndex, int spacing) const {
uint width = 0;
// If the index is greater or equal to the string size,
@ -313,13 +307,11 @@ uint Font::getLineWidth(const Common::String &str, uint startIndex, int spacing)
*
* @return The calculated height of the string
*/
uint Font::getStringHeight(const Common::String &str) const {
uint len = str.size();
int separators = 0;
for (unsigned int i = 0; i < len; ++i) {
for (uint i = 0; i < len; ++i) {
// All strings in the data files should end with '|' but not all do.
// This is why we check whether we are at the last char too.
if (str[i] == '|' || i == len - 1) {

View file

@ -30,8 +30,8 @@
namespace Draci {
extern const char *kFontSmall;
extern const char *kFontBig;
extern const char * const kFontSmall;
extern const char * const kFontBig;
/**
* Default font colours. They all seem to remain constant except for the
@ -40,20 +40,22 @@ extern const char *kFontBig;
* TODO: Find out what kFontColour1 should actually be when the game starts
*/
enum {
kFontColour1 = 2, kFontColour2 = 0,
kFontColour3 = 3, kFontColour4 = 4,
kOverFontColour = 255, kTitleColour = 255,
kLineActiveColour = 254, kLineInactiveColour = 255
kFontColour1 = 2,
kFontColour2 = 0,
kFontColour3 = 3,
kFontColour4 = 4,
kOverFontColour = 255,
kTitleColour = 255,
kLineActiveColour = 254,
kLineInactiveColour = 255
};
/**
* Represents the game's fonts. See docs for setFont() for font format details.
*/
class Font {
public:
Font(const Common::String &filename);
~Font();
@ -83,13 +85,13 @@ private:
byte *_charData;
/** Number of glyphs in the font */
static const unsigned int kCharNum = 138;
static const uint kCharNum = 138;
/**
* Chars are indexed from the space character so this should be subtracted
* to get the index of a glyph
*/
static const unsigned int kCharIndexOffset = 32;
static const uint kCharIndexOffset = 32;
/** Internal function for freeing fonts when destructing/loading another */
void freeFont();

View file

@ -35,12 +35,12 @@
namespace Draci {
const Common::String dialoguePath("ROZH");
static const Common::String dialoguePath("ROZH");
static double real_to_double(byte real[6]);
Game::Game(DraciEngine *vm) : _vm(vm) {
unsigned int i;
uint i;
BArchive *initArchive = _vm->_initArchive;
const BAFile *file;
@ -49,7 +49,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
file = initArchive->getFile(5);
Common::MemoryReadStream personData(file->_data, file->_length);
unsigned int numPersons = file->_length / personSize;
uint numPersons = file->_length / personSize;
_persons = new Person[numPersons];
for (i = 0; i < numPersons; ++i) {
@ -62,10 +62,10 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
file = initArchive->getFile(4);
Common::MemoryReadStream dialogueData(file->_data, file->_length);
unsigned int numDialogues = file->_length / sizeof(uint16);
uint numDialogues = file->_length / sizeof(uint16);
_dialogueOffsets = new uint[numDialogues];
unsigned int curOffset;
uint curOffset;
for (i = 0, curOffset = 0; i < numDialogues; ++i) {
_dialogueOffsets[i] = curOffset;
curOffset += dialogueData.readUint16LE();
@ -97,7 +97,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
// Read in variables
file = initArchive->getFile(2);
unsigned int numVariables = file->_length / sizeof (int16);
uint numVariables = file->_length / sizeof (int16);
_variables = new int[numVariables];
Common::MemoryReadStream variableData(file->_data, file->_length);
@ -115,7 +115,7 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
// Read in object status
file = initArchive->getFile(0);
unsigned int numObjects = file->_length;
uint numObjects = file->_length;
_objects = new GameObject[numObjects];
Common::MemoryReadStream objStatus(file->_data, file->_length);
@ -142,7 +142,6 @@ Game::Game(DraciEngine *vm) : _vm(vm) {
void Game::start() {
while (!shouldQuit()) {
// Whenever the top-level loop is entered, it should not finish unless
// the exit is triggered by a script
_shouldExitLoop = false;
@ -210,7 +209,7 @@ void Game::init() {
_objUnderCursor = kOverlayImage;
// Set the inventory to empty initially
memset(_inventory, kNoItem, kInventorySlots * sizeof (int));
memset(_inventory, kNoItem, kInventorySlots * sizeof(int));
// Initialize animation for object / room titles
Animation *titleAnim = _vm->_anims->addText(kTitleText, true);
@ -269,11 +268,9 @@ void Game::init() {
}
void Game::loop() {
Surface *surface = _vm->_screen->getSurface();
do {
debugC(4, kDraciLogicDebugLevel, "loopstatus: %d, loopsubstatus: %d",
_loopStatus, _loopSubstatus);
@ -284,7 +281,6 @@ void Game::loop() {
int y = _vm->_mouse->getPosY();
if (_loopStatus == kStatusDialogue && _loopSubstatus == kSubstatusOrdinary) {
Text *text;
for (int i = 0; i < kDialogueLines; ++i) {
text = reinterpret_cast<Text *>(_dialogueAnims[i]->getFrame());
@ -304,7 +300,6 @@ void Game::loop() {
}
if(_vm->_mouse->isCursorOn()) {
// Fetch the dedicated objects' title animation / current frame
Animation *titleAnim = _vm->_anims->getAnimation(kTitleText);
Text *title = reinterpret_cast<Text *>(titleAnim->getFrame());
@ -313,7 +308,6 @@ void Game::loop() {
updateTitle();
if (_loopStatus == kStatusOrdinary && _loopSubstatus == kSubstatusOrdinary) {
if (_vm->_mouse->lButtonPressed()) {
_vm->_mouse->lButtonSet(false);
@ -435,7 +429,6 @@ void Game::loop() {
// If there is an inventory item under our cursor
} else if (_itemUnderCursor != kNoItem) {
// Again, we have two possibilities:
// The first is that there is no item in our hands.
@ -503,7 +496,6 @@ void Game::loop() {
}
void Game::updateCursor() {
// Fetch mouse coordinates
int x = _vm->_mouse->getPosX();
int y = _vm->_mouse->getPosY();
@ -566,7 +558,6 @@ void Game::updateCursor() {
// If there is no game object under the cursor, try using the room itself
if (_objUnderCursor == kObjectNotFound) {
if (_vm->_script->testExpression(_currentRoom._program, _currentRoom._canUse)) {
if (_currentItem == kNoItem) {
_vm->_mouse->setCursorType(kHighlightedCursor);
@ -598,7 +589,6 @@ void Game::updateCursor() {
}
void Game::updateTitle() {
// If we are inside a dialogue, don't update titles
if (_loopStatus == kStatusDialogue)
return;
@ -656,7 +646,6 @@ int Game::getObjectWithAnimation(int animID) const {
}
void Game::removeItem(int itemID) {
for (uint i = 0; i < kInventorySlots; ++i) {
if (_inventory[i] == itemID) {
_inventory[i] = kNoItem;
@ -667,7 +656,6 @@ void Game::removeItem(int itemID) {
}
void Game::putItem(int itemID, int position) {
if (itemID == kNoItem)
return;
@ -715,7 +703,6 @@ void Game::putItem(int itemID, int position) {
}
void Game::inventoryInit() {
// Pause all "background" animations
_vm->_anims->pauseAnimations();
@ -754,7 +741,6 @@ void Game::inventoryDone() {
}
void Game::inventoryDraw() {
_vm->_anims->play(kInventorySprite);
for (uint i = 0; i < kInventorySlots; ++i) {
@ -765,7 +751,6 @@ void Game::inventoryDraw() {
}
void Game::dialogueMenu(int dialogueID) {
int oldLines, hit;
char tmp[5];
@ -817,7 +802,6 @@ int Game::dialogueDraw() {
Text *dialogueLine;
while ((_dialogueLinesNum < 4) && (i < _blockNum)) {
GPL2Program blockTest;
blockTest._bytecode = _dialogueBlocks[i]._canBlock;
blockTest._length = _dialogueBlocks[i]._canLen;
@ -927,7 +911,6 @@ void Game::dialogueDone() {
}
void Game::runDialogueProg(GPL2Program prog, int offset) {
// Mark last animation
int lastAnimIndex = _vm->_anims->getLastIndex();
@ -1012,7 +995,6 @@ void Game::walkHero(int x, int y) {
}
void Game::loadItem(int itemID) {
const BAFile *f = _vm->_itemsArchive->getFile(itemID * 3);
Common::MemoryReadStream itemReader(f->_data, f->_length);
@ -1039,7 +1021,6 @@ void Game::loadItem(int itemID) {
}
void Game::loadRoom(int roomNum) {
const BAFile *f;
f = _vm->_roomsArchive->getFile(roomNum * 4);
Common::MemoryReadStream roomReader(f->_data, f->_length);
@ -1164,7 +1145,6 @@ void Game::loadRoom(int roomNum) {
}
int Game::loadAnimation(uint animNum, uint z) {
const BAFile *animFile = _vm->_animationsArchive->getFile(animNum);
Common::MemoryReadStream animationReader(animFile->_data, animFile->_length);
@ -1262,7 +1242,6 @@ void Game::loadObject(uint objNum) {
}
void Game::loadWalkingMap(int mapID) {
const BAFile *f;
f = _vm->_walkingMapsArchive->getFile(mapID);
_currentRoom._walkingMap.load(f->_data, f->_length);
@ -1285,7 +1264,6 @@ void Game::loadOverlays() {
Common::MemoryReadStream overlayReader(overlayHeader->_data, overlayHeader->_length);
for (int i = 0; i < _currentRoom._numOverlays; i++) {
num = overlayReader.readUint16LE() - 1;
x = overlayReader.readUint16LE();
y = overlayReader.readUint16LE();
@ -1304,7 +1282,6 @@ void Game::loadOverlays() {
}
void Game::changeRoom(uint roomNum) {
debugC(1, kDraciLogicDebugLevel, "Changing to room %d", roomNum);
// Clear archives
@ -1346,7 +1323,6 @@ void Game::changeRoom(uint roomNum) {
}
void Game::runGateProgram(int gate) {
debugC(6, kDraciLogicDebugLevel, "Running program for gate %d", gate);
// Set the appropriate loop statu before executing the gate program
@ -1364,7 +1340,6 @@ void Game::runGateProgram(int gate) {
}
void Game::positionAnimAsHero(Animation *anim) {
// Calculate scaling factors
const double scale = getPers0() + getPersStep() * _hero.y;
@ -1498,7 +1473,6 @@ int Game::getScheduledPalette() const {
* animations were loaded in) which is then used by the Release command to delete
* all animations that have an index greater than the one marked.
*/
int Game::getMarkedAnimationIndex() const {
return _markedAnimationIndex;
}
@ -1541,7 +1515,6 @@ Game::~Game() {
bool WalkingMap::isWalkable(int x, int y) const {
// Convert to map pixels
x = x / _deltaX;
y = y / _deltaY;
@ -1566,13 +1539,11 @@ bool WalkingMap::isWalkable(int x, int y) const {
* possibly improved / simplified.
*/
Common::Point WalkingMap::findNearestWalkable(int startX, int startY, Common::Rect searchRect) const {
// If the starting point is walkable, just return that
if (searchRect.contains(startX, startY) && isWalkable(startX, startY)) {
return Common::Point(startX, startY);
}
int signs[] = { 1, -1 };
const uint kSignsNum = 2;
@ -1592,7 +1563,6 @@ Common::Point WalkingMap::findNearestWalkable(int startX, int startY, Common::Re
// It also does the same check for the ellipse perpendicular to it (rotated by 90 degrees).
while(1) {
// The default major radius
radius += _deltaX;
@ -1606,7 +1576,6 @@ Common::Point WalkingMap::findNearestWalkable(int startX, int startY, Common::Re
dy = 2 * radius - 2;
do {
// The following two loops serve the purpose of checking the points on the two
// ellipses for walkability. The signs[] array is there to obliterate the need
// of writing out all combinations manually.
@ -1664,7 +1633,6 @@ Common::Point WalkingMap::findNearestWalkable(int startX, int startY, Common::Re
}
static double real_to_double(byte real[6]) {
// Extract sign bit
int sign = real[0] & (1 << 7);
@ -1677,7 +1645,6 @@ static double real_to_double(byte real[6]) {
if (real[5] == 0) {
mantissa = 0.0;
} else {
// Process the first four least significant bytes
for (int i = 4; i >= 1; --i) {
tmp += real[i];

View file

@ -70,7 +70,8 @@ enum {
};
enum {
kNoDialogue = -1, kDialogueLines = 4
kNoDialogue = -1,
kDialogueLines = 4
};
enum {
@ -94,7 +95,6 @@ enum InventoryConstants {
};
class WalkingMap {
public:
WalkingMap() {
_realWidth = 0;
@ -132,7 +132,6 @@ private:
};
struct GameObject {
uint _init, _look, _use, _canUse;
bool _imInit, _imLook, _imUse;
int _walkDir;
@ -213,9 +212,9 @@ enum LoopSubstatus {
/**
* Enumerates the animations for the dragon's movement.
*/
enum Movement {
kMoveUndefined, kMoveDown, kMoveUp, kMoveRight, kMoveLeft,
kMoveUndefined,
kMoveDown, kMoveUp, kMoveRight, kMoveLeft,
kMoveRightDown, kMoveRightUp, kMoveLeftDown, kMoveLeftUp,
kMoveDownRight, kMoveUpRight, kMoveDownLeft, kMoveUpLeft,
kMoveLeftRight, kMoveRightLeft, kMoveUpStopLeft, kMoveUpStopRight,
@ -223,9 +222,7 @@ enum Movement {
};
class Game {
public:
Game(DraciEngine *vm);
~Game();

View file

@ -39,7 +39,6 @@ Mouse::Mouse(DraciEngine *vm) {
}
void Mouse::handleEvent(Common::Event event) {
switch (event.type) {
case Common::EVENT_LBUTTONDOWN:
debugC(6, kDraciGeneralDebugLevel, "Left button down (x: %u y: %u)", _x, _y);
@ -101,7 +100,6 @@ void Mouse::setCursorType(CursorType cur) {
}
void Mouse::loadItemCursor(int itemID, bool highlighted) {
const BAFile *f;
f = _vm->_itemImagesArchive->getFile(2 * itemID + highlighted);

View file

@ -32,10 +32,14 @@
namespace Draci {
enum CursorType {
kNormalCursor, kArrowCursor1,
kArrowCursor2, kArrowCursor3,
kArrowCursor4, kDialogueCursor,
kHighlightedCursor, kMainMenuCursor
kNormalCursor,
kArrowCursor1,
kArrowCursor2,
kArrowCursor3,
kArrowCursor4,
kDialogueCursor,
kHighlightedCursor,
kMainMenuCursor
};
class DraciEngine;

View file

@ -46,8 +46,8 @@ Screen::~Screen() {
* @brief Sets the first numEntries of palette to zero
* @param numEntries The number of entries to set to zero (from start)
*/
void Screen::setPaletteEmpty(unsigned int numEntries) {
for (unsigned int i = 0; i < 4 * numEntries; ++i) {
void Screen::setPaletteEmpty(uint numEntries) {
for (uint i = 0; i < 4 * numEntries; ++i) {
_palette[i] = 0;
}
@ -61,7 +61,6 @@ void Screen::setPaletteEmpty(unsigned int numEntries) {
* num Number of colours to replace
*/
void Screen::setPalette(const byte *data, uint16 start, uint16 num) {
Common::MemoryReadStream pal(data, 3 * kNumColours);
pal.seek(start * 4);
@ -75,7 +74,7 @@ void Screen::setPalette(const byte *data, uint16 start, uint16 num) {
// TODO: Investigate why this is needed
// Shift the palette two bits to the left to make it brighter
for (unsigned int i = 0; i < 4 * kNumColours; ++i) {
for (uint i = 0; i < 4 * kNumColours; ++i) {
_palette[i] <<= 2;
}
@ -96,7 +95,6 @@ void Screen::copyToScreen() {
_vm->_system->copyRectToScreen(ptr, kScreenWidth,
0, 0, kScreenWidth, kScreenHeight);
} else {
// Otherwise, update only the dirty rectangles
for (it = dirtyRects->begin(); it != dirtyRects->end(); ++it) {
@ -144,7 +142,6 @@ void Screen::fillScreen(uint8 colour) {
* colour The colour of the rectangle
*/
void Screen::drawRect(Common::Rect r, uint8 colour) {
// Clip the rectangle to screen size
r.clip(_surface->w, _surface->h);

View file

@ -46,7 +46,7 @@ public:
Screen(DraciEngine *vm);
~Screen();
void setPaletteEmpty(unsigned int numEntries = kNumColours);
void setPaletteEmpty(uint numEntries = kNumColours);
void setPalette(const byte *data, uint16 start, uint16 num);
const byte *getPalette() const;
void copyToScreen();

View file

@ -210,7 +210,6 @@ int Script::operMod(int op1, int op2) const {
/* GPL functions */
int Script::funcRandom(int n) const {
// The function needs to return numbers in the [0..n-1] range so we need to deduce 1
// (RandomSource::getRandomNumber returns a number in the range [0..n])
@ -270,7 +269,6 @@ int Script::funcIsIcoAct(int itemID) const {
}
int Script::funcActIco(int itemID) const {
// The parameter seems to be an omission in the original player since it's not
// used in the implementation of the function. It's possible that the functions were
// implemented in such a way that they had to have a single parameter so this is only
@ -323,7 +321,6 @@ int Script::funcIsObjAway(int objID) const {
}
int Script::funcActPhase(int objID) const {
objID -= 1;
// Default return value
@ -517,7 +514,6 @@ void Script::icoStat(Common::Queue<int> &params) {
_vm->_game->setItemStatus(itemID, status == 1);
if (_vm->_game->getItemStatus(itemID) == 0) {
if (itemID != kNoItem) {
_vm->_anims->deleteAnimation(kInventoryItemsID - itemID);
}
@ -536,7 +532,6 @@ void Script::icoStat(Common::Queue<int> &params) {
}
if (_vm->_game->getItemStatus(itemID) == 1) {
if (itemID != kNoItem) {
Animation *itemAnim = _vm->_anims->addItem(kInventoryItemsID - itemID);
const BAFile *f = _vm->_itemImagesArchive->getFile(2 * itemID);
@ -654,7 +649,6 @@ void Script::walkOnPlay(Common::Queue<int> &params) {
}
void Script::newRoom(Common::Queue<int> &params) {
if (_vm->_game->getLoopStatus() == kStatusInventory) {
return;
}
@ -667,7 +661,6 @@ void Script::newRoom(Common::Queue<int> &params) {
}
void Script::talk(Common::Queue<int> &params) {
int personID = params.pop() - 1;
int sentenceID = params.pop() - 1;
@ -741,7 +734,6 @@ void Script::loadMap(Common::Queue<int> &params) {
}
void Script::resetDialogue(Common::Queue<int> &params) {
const int currentOffset = _vm->_game->getCurrentDialogueOffset();
for (int i = 0; i < _vm->_game->getDialogueBlockNum(); ++i) {
@ -750,7 +742,6 @@ void Script::resetDialogue(Common::Queue<int> &params) {
}
void Script::resetDialogueFrom(Common::Queue<int> &params) {
const int currentOffset = _vm->_game->getCurrentDialogueOffset();
for (int i = _vm->_game->getDialogueCurrentBlock(); i < _vm->_game->getDialogueBlockNum(); ++i) {
@ -771,7 +762,6 @@ void Script::exitDialogue(Common::Queue<int> &params) {
}
void Script::roomMap(Common::Queue<int> &params) {
// Load the default walking map for the room
_vm->_game->loadWalkingMap();
}
@ -788,7 +778,6 @@ void Script::blackPalette(Common::Queue<int> &params) {
}
void Script::setPalette(Common::Queue<int> &params) {
if (_vm->_game->getScheduledPalette() == -1) {
_vm->_screen->setPaletteEmpty();
} else {
@ -806,7 +795,6 @@ void Script::endCurrentProgram() {
* @brief Evaluates mathematical expressions
* @param reader Stream reader set to the beginning of the expression
*/
int Script::handleMathExpression(Common::MemoryReadStream *reader) const {
Common::Stack<int> stk;
mathExpressionObject obj;
@ -916,7 +904,6 @@ int Script::handleMathExpression(Common::MemoryReadStream *reader) const {
* Reference: the function equivalent to this one is called "Can()" in the original engine.
*/
bool Script::testExpression(const GPL2Program &program, uint16 offset) const {
// Initialize program reader
Common::MemoryReadStream reader(program._bytecode, program._length);
@ -944,7 +931,7 @@ bool Script::testExpression(const GPL2Program &program, uint16 offset) const {
* struct representing the command.
*/
const GPL2Command *Script::findCommand(byte num, byte subnum) const {
unsigned int i = 0;
uint i = 0;
while (1) {
// Command not found
@ -996,7 +983,6 @@ const GPL2Command *Script::findCommand(byte num, byte subnum) const {
*/
int Script::run(const GPL2Program &program, uint16 offset) {
int oldJump = _jump;
// Mark the last animation index before we do anything so a Release command
@ -1062,15 +1048,13 @@ int Script::run(const GPL2Program &program, uint16 offset) {
debugC(3, kDraciBytecodeDebugLevel,
"Evaluating (in-script) GPL expression at offset %d: ", offset);
params.push(handleMathExpression(&reader));
}
else {
} else {
tmp = reader.readSint16LE();
params.push(tmp);
debugC(2, kDraciBytecodeDebugLevel, "\t%d", tmp);
}
}
}
else {
} else {
debugC(1, kDraciBytecodeDebugLevel, "Unknown opcode %d, %d",
num, subnum);
abort();
@ -1091,5 +1075,5 @@ int Script::run(const GPL2Program &program, uint16 offset) {
return 0;
}
}
} // end of namespace Draci

View file

@ -43,9 +43,9 @@ enum {
};
// TODO(spalek): shouldn't modify params passed by reference. Either make it const or copy the parameter.
typedef void (Script::* GPLHandler)(Common::Queue<int> &);
typedef int (Script::* GPLOperatorHandler)(int, int) const;
typedef int (Script::* GPLFunctionHandler)(int) const;
typedef void (Script::*GPLHandler)(Common::Queue<int> &);
typedef int (Script::*GPLOperatorHandler)(int, int) const;
typedef int (Script::*GPLFunctionHandler)(int) const;
/**
* Represents a single command in the GPL scripting language bytecode.
@ -76,7 +76,6 @@ struct GPL2Function {
* A convenience data type that holds both the actual bytecode and the
* length of the bytecode. Passed to Script::run().
*/
struct GPL2Program {
GPL2Program() : _bytecode(NULL), _length(0) {}
@ -94,7 +93,6 @@ public:
void endCurrentProgram();
private:
int _jump;
bool _endProgram;
@ -172,6 +170,6 @@ private:
DraciEngine *_vm;
};
}
} // end of namespace Draci
#endif // DRACI_SCRIPT_H

View file

@ -130,9 +130,7 @@ void Sprite::setMirrorOff() {
_mirror = false;
}
int Sprite::getPixel(int x, int y, const Displacement &displacement) const {
Common::Rect rect = getRect(displacement);
int dy = y - rect.top;
@ -153,7 +151,6 @@ int Sprite::getPixel(int x, int y, const Displacement &displacement) const {
void Sprite::drawReScaled(Surface *surface, bool markDirty, const Displacement &displacement) const {
const Common::Rect destRect(getRect(displacement));
const Common::Rect surfaceRect(0, 0, surface->w, surface->h);
Common::Rect clippedDestRect(destRect);
@ -186,7 +183,6 @@ void Sprite::drawReScaled(Surface *surface, bool markDirty, const Displacement &
// Blit the sprite to the surface
for (int i = 0; i < rows; ++i) {
// Compute the index of current row to be drawn
const int row = (i + croppedBy.y) * _height / destRect.height();
const byte *row_data = _data + row * _width;
@ -214,7 +210,6 @@ void Sprite::drawReScaled(Surface *surface, bool markDirty, const Displacement &
delete[] columnIndices;
}
/**
* @brief Draws the sprite to a Draci::Surface
* @param surface Pointer to a Draci::Surface
@ -223,7 +218,6 @@ void Sprite::drawReScaled(Surface *surface, bool markDirty, const Displacement &
* It is safe to call it for sprites that would overflow the surface.
*/
void Sprite::draw(Surface *surface, bool markDirty, int relX, int relY) const {
// TODO: refactor like drawReScaled()
Common::Rect sourceRect(0, 0, _width, _height);
@ -312,7 +306,6 @@ Text::Text(const Common::String &str, const Font *font, byte fontColour,
}
void Text::setText(const Common::String &str) {
_width = _font->getStringWidth(str, _spacing);
_height = _font->getStringHeight(str);
@ -356,4 +349,3 @@ void Text::setFont(const Font *font) {
} // End of namespace Draci

View file

@ -31,7 +31,10 @@
namespace Draci {
enum DrawableType { kDrawableText, kDrawableSprite };
enum DrawableType {
kDrawableText,
kDrawableSprite
};
struct Displacement {
int relX, relY;
@ -40,7 +43,6 @@ struct Displacement {
extern const Displacement kNoDisplacement;
class Drawable {
public:
virtual void draw(Surface *surface, bool markDirty, int relX=0, int relY=0) const = 0;
virtual void drawReScaled(Surface *surface, bool markDirty, const Displacement &displacement = kNoDisplacement) const = 0;
@ -98,10 +100,8 @@ protected:
*/
class Sprite : public Drawable {
public:
Sprite(const byte *raw_data, uint16 width, uint16 height, int x, int y, bool columnwise);
Sprite(const byte *sprite_data, uint16 length, int x, int y, bool columnwise);
~Sprite();
@ -147,7 +147,6 @@ public:
Common::Rect getRect(const Displacement &displacement = kNoDisplacement) const;
DrawableType getType() const { return kDrawableText; }
private:
Common::String _text;
uint _length;

View file

@ -52,7 +52,6 @@ void Surface::markDirtyRect(Common::Rect r) {
it = _dirtyRects.begin();
while (it != _dirtyRects.end()) {
if (it->contains(r))
return;
@ -135,7 +134,6 @@ void Surface::fill(uint colour) {
* @return The centered x coordinate
*/
uint Surface::centerOnX(uint x, uint width) const {
int newX = x - width / 2;
if (newX + width >= (uint)w - 1)
@ -156,7 +154,6 @@ uint Surface::centerOnX(uint x, uint width) const {
* @return The centered y coordinate
*/
uint Surface::centerOnY(uint y, uint height) const {
int newY = y - height / 2;
if (newY + height >= (uint)h - 1)
@ -171,7 +168,6 @@ uint Surface::centerOnY(uint y, uint height) const {
/**
* @brief Returns a Common::Rect corresponding to the surface.
*/
Common::Rect Surface::getRect() const {
return Common::Rect(w, h);
}