aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--queen/graphics.cpp87
-rw-r--r--queen/graphics.h20
-rw-r--r--queen/resource.cpp10
-rw-r--r--queen/resource.h2
4 files changed, 93 insertions, 26 deletions
diff --git a/queen/graphics.cpp b/queen/graphics.cpp
index d9a808c76a..a405c59ee3 100644
--- a/queen/graphics.cpp
+++ b/queen/graphics.cpp
@@ -280,7 +280,8 @@ Graphics::Graphics(Resource *resource)
_screen = new uint8[ SCREEN_W * SCREEN_H ];
_fullscreen = true;
_horizontalScroll = 0;
- _palette = new uint8[ 256 * 4 ];
+ _paletteRoom = new uint8[ 256 * 3 ];
+ _paletteScreen = new uint8[ 256 * 4 ];
}
@@ -294,7 +295,8 @@ Graphics::~Graphics() {
delete[] _backdrop;
delete[] _panel;
delete[] _screen;
- delete[] _palette;
+ delete[] _paletteRoom;
+ delete[] _paletteScreen;
}
@@ -711,7 +713,7 @@ void Graphics::bobSortAll() {
for (int32 index = 0; index < _sortedBobsCount - 1; ++index) {
int32 smallest = index;
for (int32 compare = index + 1; compare <= _sortedBobsCount - 1; ++compare) {
- if (_sortedBobs[compare]->y < _sortedBobs[compare]->y) {
+ if (_sortedBobs[compare]->y < _sortedBobs[smallest]->y) {
smallest = compare;
}
}
@@ -853,7 +855,7 @@ void Graphics::backdropLoad(const char* name, uint16 room) {
char roomPrefix[20];
strcpy(roomPrefix, name);
roomPrefix[ strlen(roomPrefix) - 4 ] = '\0';
-// _display->dynalumInit(_resource, roomPrefix, room);
+ dynalumInit(roomPrefix, room);
uint8 *pcxbuf = _resource->loadFile(name);
if (pcxbuf == NULL) {
@@ -861,7 +863,7 @@ void Graphics::backdropLoad(const char* name, uint16 room) {
}
uint32 size = _resource->fileSize(name);
- displaySetPal(pcxbuf + size - 768, 0, (room <= 144) ? 144 : 256);
+ setRoomPal(pcxbuf + size - 768, 0, (room <= 144) ? 144 : 256);
_backdropWidth = READ_LE_UINT16(pcxbuf + 12);
_backdropHeight = READ_LE_UINT16(pcxbuf + 14);
@@ -901,7 +903,7 @@ void Graphics::panelLoad() {
error("Unable to open panel file");
}
uint32 size = _resource->fileSize("panel.pcx");
- displaySetPal(pcxbuf + size - 768, 144, 256);
+ setRoomPal(pcxbuf + size - 768, 144, 256);
readPCX(pcxbuf + 128, _panel + PANEL_W * 10, PANEL_W, PANEL_W, PANEL_H - 10);
delete[] pcxbuf;
}
@@ -1022,6 +1024,9 @@ void Graphics::update() {
backdropDraw();
bobDrawAll();
textDrawAll();
+ if (_bobs[0].active) {
+ dynalumUpdate(_bobs[0].x, _bobs[0].y);
+ }
displayScreen();
g_system->delay_msecs(100); // TEMP: move to Logic::update()
}
@@ -1114,21 +1119,9 @@ void Graphics::displayBlit(uint8 *dst_buf, uint16 dst_x, uint16 dst_y, uint16 ds
}
-void Graphics::displaySetPal(uint8 *pal, int start, int end) {
- int i;
- pal += start * 3;
- for (i = start; i < end; ++i, pal += 3) {
- _palette[i << 2 | 0] = *(pal + 0);
- _palette[i << 2 | 1] = *(pal + 1);
- _palette[i << 2 | 2] = *(pal + 2);
- _palette[i << 2 | 3] = 0;
- }
-}
-
-
void Graphics::displayScreen() {
// FIXME: temporary code ; cleanup/move to Display class.
- g_system->set_palette(_palette, 0, 256);
+ g_system->set_palette(_paletteScreen, 0, 256);
g_system->copy_rect(_screen, SCREEN_W, 0, 0, SCREEN_W, SCREEN_H);
g_system->update_screen();
}
@@ -1152,6 +1145,62 @@ void Graphics::setScreenMode(int comPanel, bool inCutaway) {
}
+void Graphics::setRoomPal(const uint8 *pal, int start, int end) {
+ int i;
+ pal += start * 3;
+ for (i = start; i < end; ++i, pal += 3) {
+ _paletteScreen[i << 2 | 0] = _paletteRoom[i * 3 + 0] = *(pal + 0);
+ _paletteScreen[i << 2 | 1] = _paletteRoom[i * 3 + 1] = *(pal + 1);
+ _paletteScreen[i << 2 | 2] = _paletteRoom[i * 3 + 2] = *(pal + 2);
+ _paletteScreen[i << 2 | 3] = 0;
+ }
+}
+
+
+void Graphics::dynalumInit(const char* roomPrefix, uint16 room) {
+ // io.c l.2063-2089
+ memset(_dynalum.msk, 0, sizeof(_dynalum.msk));
+ memset(_dynalum.lum, 0, sizeof(_dynalum.lum));
+ if (room < 90 || ((room > 94) && (room < 114))) {
+ char filename[80];
+ sprintf(filename, "%s.msk", roomPrefix);
+ _resource->loadFile(filename, 0, (uint8*)_dynalum.msk);
+ sprintf(filename, "%s.lum", roomPrefix);
+ _resource->loadFile(filename, 0, (uint8*)_dynalum.lum);
+ }
+}
+
+
+void Graphics::dynalumUpdate(uint16 x, uint16 y) {
+
+ if (x >= _backdropWidth) {
+ x = _backdropWidth;
+ }
+ if (y >= ROOM_ZONE_HEIGHT - 1) {
+ y = ROOM_ZONE_HEIGHT - 1;
+ }
+ uint16 colMask = _dynalum.msk[(y / 4) * 160 + (x / 4)];
+ debug(9, "Graphics::dynalumUpdate(%d, %d) - colMask = %d", x, y, colMask);
+ if (colMask != _dynalum.oldColMask) {
+ uint8 i;
+ for (i = 0; i < 16; ++i) {
+ uint8 j;
+ for (j = 0; j < 3; ++j) {
+ int16 c = (int16)(_paletteRoom[(144 + i) * 3 + j] + _dynalum.lum[colMask * 3 + j] * 4);
+ if (c < 0) {
+ c = 0;
+ }
+ else if (c > 255) {
+ c = 255;
+ }
+ _paletteScreen[(144 + i) * 4 + j] = (uint8)c;
+ }
+ }
+ _dynalum.oldColMask = colMask;
+ // TODO: handle dirty colors (lopal, hipal)
+ }
+}
+
} // End of namespace Queen
diff --git a/queen/graphics.h b/queen/graphics.h
index 787e7da5e7..152a662826 100644
--- a/queen/graphics.h
+++ b/queen/graphics.h
@@ -101,6 +101,14 @@ struct TextSlot {
};
+struct Dynalum {
+ uint8 msk[50 * 160]; // mask
+ int8 lum[8 * 3]; // rgb
+ int8 oldColMask;
+ Dynalum(): oldColMask(-1) {}
+};
+
+
//class Display;
class Graphics {
@@ -155,10 +163,14 @@ public:
void displayText(const TextSlot *pts, uint16 y); // FIXME: move to Display class
void displayChar(uint16 x, uint16 y, uint8 color, const uint8 *chr); // FIXME: move to Display class
static void displayBlit(uint8 *dst_buf, uint16 dst_x, uint16 dst_y, uint16 dst_pitch, const uint8 *src_buf, uint16 src_w, uint16 src_h, uint16 src_pitch, bool xflip, bool masked); // FIXME: move to Display class
- void displaySetPal(uint8 *pal, int start, int end);
void displayScreen();
void setScreenMode(int comPanel, bool inCutaway);
+ void setRoomPal(const uint8 *pal, int start, int end);
+
+ void dynalumInit(const char* roomPrefix, uint16 room);
+ void dynalumUpdate(uint16 x, uint16 y); // dynalum()
+
private:
@@ -188,6 +200,7 @@ private:
//! bobs to display
BobSlot *_sortedBobs[MAX_BOBS_NUMBER];
+ //! number of bobs to display
uint16 _sortedBobsCount;
//! used to scale a BobFrame
@@ -212,7 +225,8 @@ private:
uint16 _horizontalScroll;
- uint8 *_palette;
+ uint8 *_paletteRoom; // palette
+ uint8 *_paletteScreen; // tpal
//! panel storage area
uint8 *_panel;
@@ -220,6 +234,8 @@ private:
Resource *_resource;
// Display *_display;
+ Dynalum _dynalum;
+
//! font used to render the text
static const uint8 FONT[]; // FIXME: move to Display class
diff --git a/queen/resource.cpp b/queen/resource.cpp
index ae46696d83..abc4f3fdc0 100644
--- a/queen/resource.cpp
+++ b/queen/resource.cpp
@@ -139,13 +139,15 @@ uint32 Resource::fileOffset(const char *filename) {
return _resourceTable[resourceIndex(filename)].offset;
}
-uint8 *Resource::loadFile(const char *filename, uint32 skipBytes) {
+uint8 *Resource::loadFile(const char *filename, uint32 skipBytes, byte *dstBuf) {
uint32 size = fileSize(filename);
- byte *mem = new byte[size];
+ if (dstBuf == NULL) {
+ dstBuf = new byte[size];
+ }
// skip 'skipBytes' bytes (useful for headers)
_resourceFile->seek(fileOffset(filename) + skipBytes, SEEK_SET);
- _resourceFile->read(mem, size - skipBytes);
- return mem;
+ _resourceFile->read(dstBuf, size - skipBytes);
+ return dstBuf;
}
bool Resource::exists(const char *filename) {
diff --git a/queen/resource.h b/queen/resource.h
index eb396da06b..294723f043 100644
--- a/queen/resource.h
+++ b/queen/resource.h
@@ -60,7 +60,7 @@ class Resource {
public:
Resource(const Common::String &datafilePath);
~Resource(void);
- uint8 *loadFile(const char *filename, uint32 skipBytes = 0);
+ uint8 *loadFile(const char *filename, uint32 skipBytes = 0, byte *dstBuf = NULL);
char *getJAS2Line();
bool exists(const char *filename);
bool isDemo();