aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2015-12-03 15:06:45 +0200
committerWillem Jan Palenstijn2015-12-23 21:33:49 +0100
commit8f4d9c9c05e71036e80b47db380eff7922087fd5 (patch)
tree63729fe80c3346314e82f402a6bd6dff3b752d71
parent359eda3b9728548b654e16b01df39b1c54b81fdd (diff)
downloadscummvm-rg350-8f4d9c9c05e71036e80b47db380eff7922087fd5.tar.gz
scummvm-rg350-8f4d9c9c05e71036e80b47db380eff7922087fd5.tar.bz2
scummvm-rg350-8f4d9c9c05e71036e80b47db380eff7922087fd5.zip
LAB: Image accepts a Common::File now
-rw-r--r--engines/lab/engine.cpp44
-rw-r--r--engines/lab/image.cpp20
-rw-r--r--engines/lab/image.h2
-rw-r--r--engines/lab/map.cpp50
-rw-r--r--engines/lab/special.cpp60
5 files changed, 59 insertions, 117 deletions
diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp
index 35672fbdbc..7b14afc0bf 100644
--- a/engines/lab/engine.cpp
+++ b/engines/lab/engine.cpp
@@ -181,26 +181,10 @@ bool LabEngine::setUpScreens() {
if (!createScreen(_isHiRes))
return false;
- /* Loads in the graphics for the movement control panel */
- Common::File file;
- file.open(translateFileName("P:Control"));
- if (!file.isOpen())
- warning("setUpScreens couldn't open %s", translateFileName("P:Control"));
-
- if (file.err() || file.size() == 0)
- return false;
-
- byte *movePanelBuffer;
- if (!(movePanelBuffer = (byte *)calloc(file.size(), 1)))
- return false;
-
- file.read(movePanelBuffer, file.size());
- file.close();
-
- byte *buffer = movePanelBuffer;
-
+ Common::File *controlFile = g_lab->_resource->openDataFile("P:Control");
for (uint16 i = 0; i < 20; i++)
- _moveImages[i] = new Image(&buffer);
+ _moveImages[i] = new Image(controlFile);
+ delete controlFile;
/* Creates the gadgets for the movement control panel */
uint16 y = VGAScaleY(173) - SVGACord(2);
@@ -247,25 +231,11 @@ bool LabEngine::setUpScreens() {
curGadget->NextGadget = createButton(289, y, 9, 0, _moveImages[10], _moveImages[11]);
}
- file.open(translateFileName("P:Inv"));
- if (!file.isOpen())
- warning("setUpScreens couldn't open %s", translateFileName("P:Inv"));
-
- if (file.err() || file.size() == 0)
- return false;
-
- byte *invPanelBuffer;
- if (!(invPanelBuffer = (byte *)calloc(file.size(), 1)))
- return false;
-
- file.read(invPanelBuffer, file.size());
- file.close();
-
- buffer = invPanelBuffer;
+ Common::File *invFile = g_lab->_resource->openDataFile("P:Inv");
if (getPlatform() == Common::kPlatformWindows) {
for (uint16 imgIdx = 0; imgIdx < 10; imgIdx++)
- _invImages[imgIdx] = new Image(&buffer);
+ _invImages[imgIdx] = new Image(invFile);
_invGadgetList = createButton(24, y, 0, 'm', _invImages[0], _invImages[1]);
Gadget *curGadget = _invGadgetList;
@@ -285,7 +255,7 @@ bool LabEngine::setUpScreens() {
curGadget = curGadget->NextGadget;
} else {
for (uint16 imgIdx = 0; imgIdx < 6; imgIdx++)
- _invImages[imgIdx] = new Image(&buffer);
+ _invImages[imgIdx] = new Image(invFile);
_invGadgetList = createButton(58, y, 0, 0, _invImages[0], _invImages[1]);
Gadget *curGadget = _invGadgetList;
@@ -301,6 +271,8 @@ bool LabEngine::setUpScreens() {
curGadget = curGadget->NextGadget;
}
+ delete invFile;
+
return true;
}
diff --git a/engines/lab/image.cpp b/engines/lab/image.cpp
index 0fd7425dc4..3f5801fa1c 100644
--- a/engines/lab/image.cpp
+++ b/engines/lab/image.cpp
@@ -36,21 +36,17 @@ namespace Lab {
/*****************************************************************************/
/* Reads in an image from disk. */
/*****************************************************************************/
-Image::Image(byte **buffer) {
- uint32 size;
+Image::Image(Common::File *s) {
+ _width = s->readUint16LE();
+ _height = s->readUint16LE();
+ s->skip(4);
- _width = READ_LE_UINT16(*buffer);
- _height = READ_LE_UINT16(*buffer + 2);
-
- *buffer += 8; /* sizeof(struct Image); */
-
- size = _width * _height;
-
- if (1L & size)
+ uint32 size = _width * _height;
+ if (size & 1)
size++;
- _imageData = (byte *)(*buffer);
- (*buffer) += size;
+ _imageData = new byte[size]; // FIXME: Memory leak!
+ s->read(_imageData, size);
}
/*****************************************************************************/
diff --git a/engines/lab/image.h b/engines/lab/image.h
index 450c177373..8f4d0f844f 100644
--- a/engines/lab/image.h
+++ b/engines/lab/image.h
@@ -41,7 +41,7 @@ public:
Image() : _width(0), _height(0), _imageData(0) {}
Image(int w, int h, byte *d) : _width(w), _height(h), _imageData(d) {}
- Image(byte **buffer);
+ Image(Common::File *s);
void drawImage(uint16 x, uint16 y);
void drawMaskImage(uint16 x, uint16 y);
diff --git a/engines/lab/map.cpp b/engines/lab/map.cpp
index a2a4ed3af7..b3312619c1 100644
--- a/engines/lab/map.cpp
+++ b/engines/lab/map.cpp
@@ -129,43 +129,37 @@ static uint16 mapScaleY(uint16 y) {
/* Loads in the map data. */
/*****************************************************************************/
static bool loadMapData() {
- byte **buffer;
- uint32 Size;
Gadget *gptr;
uint16 counter;
- resetBuffer(); /* Make images load into start of buffer */
- buffer = g_lab->_music->newOpen("P:MapImage", Size);
+ Common::File *mapImages = g_lab->_resource->openDataFile("P:MapImage");
- if (!buffer)
- return false;
+ Map = new Image(mapImages);
- stealBufMem(Size); /* Now freeze that buffer from further use */
+ Room = new Image(mapImages);
+ UpArrowRoom = new Image(mapImages);
+ DownArrowRoom = new Image(mapImages);
+ HRoom = new Image(mapImages);
+ VRoom = new Image(mapImages);
+ Maze = new Image(mapImages);
+ HugeMaze = new Image(mapImages);
- Map = new Image(buffer);
+ MapNorth = new Image(mapImages);
+ MapEast = new Image(mapImages);
+ MapSouth = new Image(mapImages);
+ MapWest = new Image(mapImages);
- Room = new Image(buffer);
- UpArrowRoom = new Image(buffer);
- DownArrowRoom = new Image(buffer);
- HRoom = new Image(buffer);
- VRoom = new Image(buffer);
- Maze = new Image(buffer);
- HugeMaze = new Image(buffer);
+ Path = new Image(mapImages);
+ Bridge = new Image(mapImages);
- MapNorth = new Image(buffer);
- MapEast = new Image(buffer);
- MapSouth = new Image(buffer);
- MapWest = new Image(buffer);
+ Back = new Image(mapImages);
+ BackAlt = new Image(mapImages);
+ Up = new Image(mapImages);
+ UpAlt = new Image(mapImages);
+ Down = new Image(mapImages);
+ DownAlt = new Image(mapImages);
- Path = new Image(buffer);
- Bridge = new Image(buffer);
-
- Back = new Image(buffer);
- BackAlt = new Image(buffer);
- Up = new Image(buffer);
- UpAlt = new Image(buffer);
- Down = new Image(buffer);
- DownAlt = new Image(buffer);
+ delete mapImages;
backgadget._image = Back;
backgadget._altImage = BackAlt;
diff --git a/engines/lab/special.cpp b/engines/lab/special.cpp
index 50cf0fe259..f8b0c2091e 100644
--- a/engines/lab/special.cpp
+++ b/engines/lab/special.cpp
@@ -137,8 +137,6 @@ static void doCombination() {
/* Reads in a backdrop picture. */
/*****************************************************************************/
void showCombination(const char *filename) {
- byte **buffer;
-
resetBuffer();
g_lab->_anim->_doBlack = true;
g_lab->_anim->_noPalChange = true;
@@ -147,10 +145,12 @@ void showCombination(const char *filename) {
blackScreen();
- buffer = g_lab->_music->newOpen("P:Numbers");
+ Common::File *numFile = g_lab->_resource->openDataFile("P:Numbers");
for (uint16 CurBit = 0; CurBit < 10; CurBit++)
- Images[CurBit] = new Image(buffer);
+ Images[CurBit] = new Image(numFile);
+
+ delete numFile;
allocFile((void **)&g_lab->_tempScrollData, Images[0]->_width * Images[0]->_height * 2L, "tempdata");
@@ -279,8 +279,7 @@ static void doTile(bool showsolution) {
/* Reads in a backdrop picture. */
/*****************************************************************************/
void showTile(const char *filename, bool showsolution) {
- uint16 start;
- byte **buffer;
+ uint16 start = showsolution ? 0 : 1;
resetBuffer();
g_lab->_anim->_doBlack = true;
@@ -289,19 +288,12 @@ void showTile(const char *filename, bool showsolution) {
g_lab->_anim->_noPalChange = false;
blackScreen();
- if (showsolution) {
- start = 0;
- buffer = g_lab->_music->newOpen("P:TileSolution");
- } else {
- start = 1;
- buffer = g_lab->_music->newOpen("P:Tile");
- }
-
- if (!buffer)
- return;
+ Common::File *tileFile = tileFile = g_lab->_resource->openDataFile(showsolution ? "P:TileSolution" : "P:Tile");
for (uint16 curBit = start; curBit < 16; curBit++)
- Tiles[curBit] = new Image(buffer);
+ Tiles[curBit] = new Image(tileFile);
+
+ delete tileFile;
allocFile((void **)&g_lab->_tempScrollData, Tiles[1]->_width * Tiles[1]->_height * 2L, "tempdata");
@@ -506,7 +498,6 @@ void doWestPaper() {
/* Loads in the data for the journal. */
/*****************************************************************************/
static bool loadJournalData() {
- byte **buffer;
char filename[20];
Gadget *TopGadget = &BackG;
bool bridge, dirty, news, clean;
@@ -543,17 +534,16 @@ static bool loadJournalData() {
journaltext = g_lab->_resource->getText(filename);
journaltexttitle = g_lab->_resource->getText("Lab:Rooms/jt");
- buffer = g_lab->_music->newOpen("P:JImage");
+ Common::File *journalFile = g_lab->_resource->openDataFile("P:JImage");
- if (!buffer)
- return false;
+ BackG._image = new Image(journalFile);
+ BackG._altImage = new Image(journalFile);
+ ForwardG._image = new Image(journalFile);
+ ForwardG._altImage = new Image(journalFile);
+ CancelG._image = new Image(journalFile);
+ CancelG._altImage = new Image(journalFile);
- BackG._image = new Image(buffer);
- BackG._altImage = new Image(buffer);
- ForwardG._image = new Image(buffer);
- ForwardG._altImage = new Image(buffer);
- CancelG._image = new Image(buffer);
- CancelG._altImage = new Image(buffer);
+ delete journalFile;
BackG.KeyEquiv = VKEY_LTARROW;
ForwardG.KeyEquiv = VKEY_RTARROW;
@@ -807,19 +797,9 @@ bool saveRestoreGame() {
/* Makes sure that the buttons are in memory. */
/*****************************************************************************/
static void getMonImages() {
- byte **buffer;
- uint32 bufferSize;
-
- resetBuffer();
-
- buffer = g_lab->_music->newOpen("P:MonImage", bufferSize);
-
- if (!buffer)
- return;
-
- MonButton = new Image(buffer);
-
- stealBufMem(bufferSize); /* Trick: protects the memory where the buttons are so they won't be over-written */
+ Common::File *buttonFile = g_lab->_resource->openDataFile("P:MonImage");
+ MonButton = new Image(buttonFile);
+ delete buttonFile;
}