Skip to content

Commit

Permalink
DM: Add loadWallSet(..) and loadFloorSet(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterGrascph committed Aug 26, 2016
1 parent bf78e63 commit 16199b4
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 11 deletions.
2 changes: 2 additions & 0 deletions engines/dm/dm.cpp
Expand Up @@ -56,6 +56,8 @@ Common::Error DMEngine::run() {
_displayMan->setUpScreens(320, 200);
_displayMan->loadGraphics();
_dungeonMan->loadDungeonFile();
_displayMan->loadFloorSet(kFloorSetStone);
_displayMan->loadWallSet(kWallSetStone);

_displayMan->loadPalette(kPalCredits);

Expand Down
72 changes: 63 additions & 9 deletions engines/dm/gfx.cpp
Expand Up @@ -24,6 +24,7 @@ uint16 dmPalettes[10][16] = {
};



enum GraphicIndice {
gFloorIndice = 75,
gCeilingIndice = 76
Expand All @@ -50,14 +51,16 @@ using namespace DM;

DisplayMan::DisplayMan(DMEngine *dmEngine) :
_vm(dmEngine), _currPalette(kPalSwoosh), _screenWidth(0), _screenHeight(0),
_vgaBuffer(NULL), _itemCount(0), _packedItemPos(NULL), _packedBitmaps(NULL),
_vgaBuffer(NULL), _packedItemCount(0), _packedItemPos(NULL), _packedBitmaps(NULL),
_bitmaps(NULL) {}

DisplayMan::~DisplayMan() {
delete[] _packedBitmaps;
delete[] _packedItemPos;
delete[] _vgaBuffer;
delete[] _bitmaps;
delete[] _wallSetBitMaps[13]; // copy of another bitmap, just flipped
delete[] _wallSetBitMaps[14]; // copy of another bitmap, just flipped
}

void DisplayMan::setUpScreens(uint16 width, uint16 height) {
Expand All @@ -72,16 +75,16 @@ void DisplayMan::loadGraphics() {
Common::File f;
f.open("graphics.dat");

_itemCount = f.readUint16BE();
_packedItemPos = new uint32[_itemCount + 1];
_packedItemCount = f.readUint16BE();
_packedItemPos = new uint32[_packedItemCount + 1];
_packedItemPos[0] = 0;
for (uint16 i = 1; i < _itemCount + 1; ++i)
for (uint16 i = 1; i < _packedItemCount + 1; ++i)
_packedItemPos[i] = f.readUint16BE() + _packedItemPos[i - 1];

_packedBitmaps = new uint8[_packedItemPos[_itemCount]];
_packedBitmaps = new uint8[_packedItemPos[_packedItemCount]];

f.seek(2 + _itemCount * 4);
for (uint32 i = 0; i < _packedItemPos[_itemCount]; ++i)
f.seek(2 + _packedItemCount * 4);
for (uint32 i = 0; i < _packedItemPos[_packedItemCount]; ++i)
_packedBitmaps[i] = f.readByte();

f.close();
Expand Down Expand Up @@ -245,17 +248,35 @@ void DisplayMan::drawWallSetBitmap(byte *bitmap, Frame &f, uint16 srcWidth) {
}


enum WallSetIndices {
kDoorFrameFront = 0, // @ G0709_puc_Bitmap_WallSet_DoorFrameFront
kDoorFrameLeft_D1C = 1, // @ G0708_puc_Bitmap_WallSet_DoorFrameLeft_D1C
kFameLeft_D2C = 2, // @ G0707_puc_Bitmap_WallSet_DoorFrameLeft_D2C
kDoorFrameLeft_D3C = 3, // @ G0706_puc_Bitmap_WallSet_DoorFrameLeft_D3C
kDoorFrameLeft_D3L = 4, // @ G0705_puc_Bitmap_WallSet_DoorFrameLeft_D3L
kDoorFrameTop_D1LCR = 5, // @ G0704_puc_Bitmap_WallSet_DoorFrameTop_D1LCR
kDoorFrameTop_D2LCR = 6, // @ G0703_puc_Bitmap_WallSet_DoorFrameTop_D2LCR
kWall_D0R = 7, // @ G0702_puc_Bitmap_WallSet_Wall_D0R
kWall_D0L = 8, // @ G0701_puc_Bitmap_WallSet_Wall_D0L
kWall_D1LCR = 9, // @ G0700_puc_Bitmap_WallSet_Wall_D1LCR
kWall_D2LCR = 10, // @ G0699_puc_Bitmap_WallSet_Wall_D2LCR
kWall_D3LCR = 11, // @ G0698_puc_Bitmap_WallSet_Wall_D3LCR
kWall_D3L2 = 12, // @ G0697_puc_Bitmap_WallSet_Wall_D3L2

kWall_D3R2 = 13, // @ G0696_puc_Bitmap_WallSet_Wall_D3R2
kDoorFrameRight_D1C = 14// @ G0710_puc_Bitmap_WallSet_DoorFrameRight_D1C
};

void DisplayMan::drawDungeon(direction dir, uint16 posX, uint16 posY) {
loadPalette(kPalDungeonView0);
// TODO: this is a global variable, set from here
bool flippedWallAndFootprints = (posX + posY + dir) & 1;
bool flippedFloorCeiling = (posX + posY + dir) & 1;

// NOTE: this can hold every bitmap, width and height is "flexible"
byte *tmpBitmap = new byte[305 * 111];
clearBitmap(tmpBitmap, 305, 111, kColorBlack);

if (flippedWallAndFootprints) {
if (flippedFloorCeiling) {
blitToBitmap(_bitmaps[gFloorIndice], width(gFloorIndice), height(gFloorIndice), tmpBitmap, width(gFloorIndice));
flipBitmapHorizontal(tmpBitmap, width(gFloorIndice), height(gFloorIndice));
drawWallSetBitmap(tmpBitmap, gFloorFrame, width(gFloorIndice));
Expand Down Expand Up @@ -284,4 +305,37 @@ void DisplayMan::clearScreen(Color color) {

void DisplayMan::clearBitmap(byte *bitmap, uint16 width, uint16 height, Color color) {
memset(bitmap, color, sizeof(byte) * width * height);
}


void DisplayMan::loadWallSet(WallSet set) {
// there are 2 bitmaps per set, first one is at 75
GraphicIndice indice = (GraphicIndice)(75 + (2 * set));
_floorBitmap = _bitmaps[indice];
_ceilingBitmap = _bitmaps[indice + 1];
}

void DisplayMan::loadFloorSet(FloorSet set) {
// there are 13 bitmaps perset, first one is at 77
uint16 firstIndice = (set * 13) + 77;
for (uint16 i = 0; i < 13; ++i) {
_wallSetBitMaps[i] = _bitmaps[i + firstIndice];
}


uint16 leftDoorIndice = firstIndice + kDoorFrameLeft_D1C;
uint16 w = width(leftDoorIndice), h = height(leftDoorIndice);
if (_wallSetBitMaps[kDoorFrameRight_D1C])
delete[] _wallSetBitMaps[kDoorFrameRight_D1C];
_wallSetBitMaps[kDoorFrameRight_D1C] = new byte[w * h];
blitToBitmap(_wallSetBitMaps[kDoorFrameLeft_D1C], w, h, _wallSetBitMaps[kDoorFrameRight_D1C], w);
flipBitmapHorizontal(_wallSetBitMaps[kDoorFrameRight_D1C], w, h);

uint16 leftWallIndice = firstIndice + kWall_D3L2;
w = width(leftWallIndice), h = height(leftWallIndice);
if (_wallSetBitMaps[kWall_D3R2])
delete[] _wallSetBitMaps[kWall_D3R2];
_wallSetBitMaps[kWall_D3R2] = new byte[w * h];
blitToBitmap(_wallSetBitMaps[kWall_D3L2], w, h, _wallSetBitMaps[kWall_D3R2], w);
flipBitmapHorizontal(_wallSetBitMaps[kWall_D3R2], w, h);
}
26 changes: 24 additions & 2 deletions engines/dm/gfx.h
Expand Up @@ -7,6 +7,13 @@
namespace DM {

struct Frame;
enum WallSet {
kWallSetStone = 0 // @ C0_WALL_SET_STONE
};

enum FloorSet {
kFloorSetStone = 0 // @ C0_FLOOR_SET_STONE
};

enum Color {
kColorNoTransparency = 255,
Expand Down Expand Up @@ -57,13 +64,24 @@ class DisplayMan {
uint16 _screenWidth;
uint16 _screenHeight;
byte *_vgaBuffer;
uint16 _itemCount;

uint16 _packedItemCount;
uint32 *_packedItemPos;
byte *_packedBitmaps; // TODO: this doesn't not contaion graphics exclusively, will have to be moved

byte **_bitmaps;


// the last two pointers are owned by this array
byte *_wallSetBitMaps[15] = {NULL}; // @G[0696..0710]_puc_Bitmap_WallSet_...

// pointers are not owned by these fields
byte *_floorBitmap;
byte *_ceilingBitmap;

DisplayMan(const DisplayMan &other); // no implementation on purpose
void operator=(const DisplayMan &rhs); // no implementation on purpose

byte **_bitmaps;
byte *getCurrentVgaBuffer();
// the original functions has two position parameters, but they are always set to zero
void loadIntoBitmap(uint16 index, byte *destBitmap); // @ F0466_EXPAND_GraphicToBitmap
Expand All @@ -73,7 +91,11 @@ class DisplayMan {
DisplayMan(DMEngine *dmEngine);
~DisplayMan();
void setUpScreens(uint16 width, uint16 height);

void loadGraphics();
void loadWallSet(WallSet set); // @ F0095_DUNGEONVIEW_LoadWallSet
void loadFloorSet(FloorSet set); // @ F0094_DUNGEONVIEW_LoadFloorSet

void loadPalette(dmPaletteEnum palette);

/// Gives the width of an IMG0 type item
Expand Down

0 comments on commit 16199b4

Please sign in to comment.