Skip to content

Commit

Permalink
PRINCE: Code clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslw committed Aug 1, 2014
1 parent b3589c7 commit 3c29d61
Show file tree
Hide file tree
Showing 41 changed files with 394 additions and 600 deletions.
2 changes: 0 additions & 2 deletions engines/prince/animation.cpp
Expand Up @@ -192,5 +192,3 @@ Graphics::Surface *Animation::getFrame(int frameIndex) {
}

} // End of namespace Prince

/* vim: set tabstop=4 noexpandtab: */
4 changes: 1 addition & 3 deletions engines/prince/animation.h
Expand Up @@ -73,8 +73,6 @@ class Animation {
int16 _baseY;
};

}
} // End of namespace Prince

#endif

/* vim: set tabstop=4 noexpandtab: */
10 changes: 4 additions & 6 deletions engines/prince/archive.cpp
Expand Up @@ -60,7 +60,7 @@ bool PtcArchive::open(const Common::String &filename) {

_stream->seek(fileTableOffset);

byte *fileTable = new byte[fileTableSize];
byte *fileTable = (byte *)malloc(fileTableSize);
byte *fileTableEnd = fileTable + fileTableSize;
_stream->read(fileTable, fileTableSize);
decrypt(fileTable, fileTableSize);
Expand All @@ -73,8 +73,8 @@ bool PtcArchive::open(const Common::String &filename) {
//debug("%12s %8X %d", name.c_str(), item._offset, item._size);
_items[name] = item;
}
delete[] fileTable;

free(fileTable);

return true;
}
Expand Down Expand Up @@ -141,6 +141,4 @@ Common::SeekableReadStream *PtcArchive::createReadStreamForMember(const Common::
return new Common::MemoryReadStream(buffer, size, DisposeAfterUse::YES);
}

}

/* vim: set tabstop=4 noexpandtab: */
} // End of namespace Prince
2 changes: 0 additions & 2 deletions engines/prince/archive.h
Expand Up @@ -59,5 +59,3 @@ class PtcArchive : public Common::Archive {
} // End of namespace Prince

#endif

/* vim: set tabstop=4 noexpandtab: */
28 changes: 13 additions & 15 deletions engines/prince/common.h
Expand Up @@ -26,22 +26,20 @@
namespace Prince {

enum Direction {
kDirLD = 0,
kDirL = 1,
kDirLU = 2,
kDirRD = 3,
kDirR = 4,
kDirRU = 5,
kDirUL = 6,
kDirU = 7,
kDirUR = 8,
kDirDL = 9,
kDirD = 10,
kDirDR = 11
kDirLD,
kDirL,
kDirLU,
kDirRD,
kDirR,
kDirRU,
kDirUL,
kDirU,
kDirUR,
kDirDL,
kDirD,
kDirDR
};

}
} // End of namespace Prince

#endif

/* vim: set tabstop=4 noexpandtab: */
26 changes: 13 additions & 13 deletions engines/prince/cursor.cpp
Expand Up @@ -23,32 +23,32 @@
#include "prince/cursor.h"

#include "common/debug.h"
#include "common/stream.h"

namespace Prince {

Cursor::Cursor() : _surface(NULL) {
Cursor::Cursor() : _surface(nullptr) {
}

Cursor::~Cursor() {
_surface->free();
delete _surface;
_surface = NULL;
if (_surface != nullptr) {
_surface->free();
delete _surface;
_surface = nullptr;
}
}

bool Cursor::loadFromStream(Common::SeekableReadStream &stream) {
stream.skip(4);
uint16 w = stream.readUint16LE();
uint16 h = stream.readUint16LE();
uint16 width = stream.readUint16LE();
uint16 heigth = stream.readUint16LE();

_surface = new Graphics::Surface();
_surface->create(w, h, Graphics::PixelFormat::createFormatCLUT8());
_surface->create(width, heigth, Graphics::PixelFormat::createFormatCLUT8());

for (int ih = 0; ih < h; ++ih)
stream.read(_surface->getBasePtr(0, ih), w);
for (int h = 0; h < heigth; h++) {
stream.read(_surface->getBasePtr(0, h), width);
}
return true;
}

}

/* vim: set tabstop=4 noexpandtab: */
} // End of namespace Prince
8 changes: 2 additions & 6 deletions engines/prince/cursor.h
Expand Up @@ -25,9 +25,7 @@

#include "graphics/surface.h"

namespace Common {
class SeekableReadStream;
}
#include "common/stream.h"

namespace Prince {

Expand All @@ -43,8 +41,6 @@ class Cursor {
Graphics::Surface *_surface;
};

}
} // End of namespace Prince

#endif

/* vim: set tabstop=4 expandtab!: */
4 changes: 1 addition & 3 deletions engines/prince/debugger.cpp
Expand Up @@ -171,6 +171,4 @@ bool Debugger::Cmd_AddItem(int argc, const char **argv) {
return true;
}

}

/* vim: set tabstop=4 noexpandtab: */
} // End of namespace Prince
4 changes: 1 addition & 3 deletions engines/prince/debugger.h
Expand Up @@ -53,8 +53,6 @@ class Debugger : public GUI::Debugger {
InterpreterFlags *_flags;
};

}
} // End of namespace Prince

#endif

/* vim: set tabstop=4 noexpandtab: */
2 changes: 0 additions & 2 deletions engines/prince/detection.cpp
Expand Up @@ -71,5 +71,3 @@ REGISTER_PLUGIN_DYNAMIC(PRINCE, PLUGIN_TYPE_ENGINE, Prince::PrinceMetaEngine);
#else
REGISTER_PLUGIN_STATIC(PRINCE, PLUGIN_TYPE_ENGINE, Prince::PrinceMetaEngine);
#endif

/* vim: set tabstop=4 noexpandtab: */
7 changes: 2 additions & 5 deletions engines/prince/flags.cpp
Expand Up @@ -24,8 +24,7 @@

namespace Prince {

const char *Flags::getFlagName(uint16 flagId)
{
const char *Flags::getFlagName(uint16 flagId) {
switch (flagId) {
default: return "unknown_flag";
case FLAGA1: return "FLAGA1";
Expand Down Expand Up @@ -401,6 +400,4 @@ const char *Flags::getFlagName(uint16 flagId)
}
}

}

/* vim: set tabstop=4 noexpandtab: */
} // End of namespace Prince
5 changes: 2 additions & 3 deletions engines/prince/flags.h
Expand Up @@ -410,7 +410,6 @@ struct Flags {
};
};

}
#endif
/* vim: set tabstop=4 noexpandtab: */
} // End of namespace Prince

#endif
29 changes: 14 additions & 15 deletions engines/prince/font.cpp
Expand Up @@ -23,24 +23,25 @@
#include "common/archive.h"
#include "common/debug.h"
#include "common/stream.h"
#include "common/str.h"

#include "graphics/surface.h"

#include "prince/font.h"

namespace Prince {

Font::Font() {
Font::Font() : _fontData(nullptr) {
}

Font::~Font() {
delete [] _fontData;
if (_fontData != nullptr) {
free(_fontData);
_fontData = nullptr;
}
}

bool Font::loadFromStream(Common::SeekableReadStream &stream) {
stream.seek(0);
_fontData = new byte[stream.size()];
uint32 dataSize = stream.size();
_fontData = (byte *)malloc(dataSize);
stream.read(_fontData, stream.size());
return true;
}
Expand All @@ -55,11 +56,11 @@ int Font::getMaxCharWidth() const {

Font::ChrData Font::getChrData(byte chr) const {
chr -= 32;
uint16 chrOffset = 4*chr+6;
uint16 chrOffset = 4 * chr + 6;

ChrData chrData;
chrData._width = _fontData[chrOffset+2];
chrData._height = _fontData[chrOffset+3];
chrData._width = _fontData[chrOffset + 2];
chrData._height = _fontData[chrOffset + 3];
chrData._pixels = _fontData + READ_LE_UINT16(_fontData + chrOffset);

return chrData;
Expand All @@ -72,20 +73,18 @@ int Font::getCharWidth(uint32 chr) const {
void Font::drawChar(Graphics::Surface *dst, uint32 chr, int posX, int posY, uint32 color) const {
const ChrData chrData = getChrData(chr);

for (int y = 0; y < chrData._height; ++y) {
for (int x = 0; x < chrData._width; ++x) {
for (int y = 0; y < chrData._height; y++) {
for (int x = 0; x < chrData._width; x++) {
byte d = chrData._pixels[x + (chrData._width * y)];
if (d == 0) d = 255;
else if (d == 1) d = 0;
else if (d == 2) d = color;
else if (d == 3) d = 0;
if (d != 255) {
*(byte*)dst->getBasePtr(posX + x, posY + y) = d;
*(byte *)dst->getBasePtr(posX + x, posY + y) = d;
}
}
}
}

}

/* vim: set tabstop=4 expandtab!: */
} // End of namespace Prince
13 changes: 3 additions & 10 deletions engines/prince/font.h
Expand Up @@ -23,14 +23,9 @@
#define PRINCE_FONT_H

#include "graphics/font.h"
#include "graphics/surface.h"

namespace Graphics {
struct Surface;
}

namespace Common {
class String;
}
#include "common/str.h"

namespace Prince {

Expand Down Expand Up @@ -63,8 +58,6 @@ class Font : public Graphics::Font {
byte *_fontData;
};

}
} // End of namespace Prince

#endif

/* vim: set tabstop=4 expandtab!: */
22 changes: 12 additions & 10 deletions engines/prince/graphics.cpp
Expand Up @@ -21,9 +21,7 @@
*/

#include "prince/graphics.h"

#include "prince/prince.h"

#include "prince/mhwanh.h"

#include "graphics/palette.h"
Expand All @@ -32,28 +30,34 @@

namespace Prince {

GraphicsMan::GraphicsMan(PrinceEngine *vm)
: _vm(vm), _changed(false) {
GraphicsMan::GraphicsMan(PrinceEngine *vm) : _vm(vm), _changed(false) {
initGraphics(640, 480, true);

_frontScreen = new Graphics::Surface();
_frontScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());

_screenForInventory = new Graphics::Surface();
_screenForInventory->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());

_mapScreen = new Graphics::Surface();
_mapScreen->create(640, 480, Graphics::PixelFormat::createFormatCLUT8());
_shadowTable70 = new byte[256];
_shadowTable50 = new byte[256];

_shadowTable70 = (byte *)malloc(256);
_shadowTable50 = (byte *)malloc(256);
}

GraphicsMan::~GraphicsMan() {
_frontScreen->free();
delete _frontScreen;

_screenForInventory->free();
delete _screenForInventory;

_mapScreen->free();
delete _mapScreen;
delete[] _shadowTable70;
delete[] _shadowTable50;

free(_shadowTable70);
free(_shadowTable50);
}

void GraphicsMan::update(Graphics::Surface *screen) {
Expand Down Expand Up @@ -382,5 +386,3 @@ void GraphicsMan::makeShadowTable(int brightness, byte *shadowPalette) {
}

} // End of namespace Prince

/* vim: set tabstop=4 noexpandtab: */
6 changes: 2 additions & 4 deletions engines/prince/graphics.h
Expand Up @@ -28,8 +28,8 @@
namespace Prince {

class PrinceEngine;
struct DrawNode;
class MhwanhDecoder;
struct DrawNode;

class GraphicsMan {
public:
Expand Down Expand Up @@ -68,12 +68,10 @@ class GraphicsMan {
void drawPixel(Graphics::Surface *screen, int32 posX, int32 posY);

private:

PrinceEngine *_vm;

bool _changed;
};

}
} // End of namespace Prince

#endif

0 comments on commit 3c29d61

Please sign in to comment.