aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorFilippos Karapetis2015-07-17 10:36:20 +0300
committerEugene Sandulenko2015-12-15 00:05:02 +0100
commit79ed1e1f05dc1537f666018bc7240a5d96835b5b (patch)
treef89e11d715c89ce3e2e0940091f32af022b06b7f /engines
parent884b80f2150c4509912988b19e0106aa15e1008f (diff)
downloadscummvm-rg350-79ed1e1f05dc1537f666018bc7240a5d96835b5b.tar.gz
scummvm-rg350-79ed1e1f05dc1537f666018bc7240a5d96835b5b.tar.bz2
scummvm-rg350-79ed1e1f05dc1537f666018bc7240a5d96835b5b.zip
LAB: Get rid of numtostr(), and simplify most uses of sizeOfFile()
Diffstat (limited to 'engines')
-rw-r--r--engines/lab/engine.cpp44
-rw-r--r--engines/lab/labfile.cpp4
-rw-r--r--engines/lab/labfun.h74
-rw-r--r--engines/lab/labmusic.cpp19
-rw-r--r--engines/lab/map.cpp10
-rw-r--r--engines/lab/readparse.cpp64
-rw-r--r--engines/lab/text.cpp10
7 files changed, 36 insertions, 189 deletions
diff --git a/engines/lab/engine.cpp b/engines/lab/engine.cpp
index 37e86fba81..9af2a22fb6 100644
--- a/engines/lab/engine.cpp
+++ b/engines/lab/engine.cpp
@@ -208,8 +208,6 @@ static bool LastTooLong = false;
/* Draws the message for the room. */
/******************************************************************************/
static void drawRoomMessage(uint16 CurInv, CloseDataPtr cptr) {
- char text[250], ManyText[8], *ManyPtr;
-
if (LastTooLong) {
LastTooLong = false;
return;
@@ -220,12 +218,8 @@ static void drawRoomMessage(uint16 CurInv, CloseDataPtr cptr) {
if ((CurInv == LAMPNUM) && g_lab->_conditions->in(LAMPON)) /* LAB: Labyrith specific */
drawMessage(LAMPONMSG);
else if (Inventory[CurInv].Many > 1) {
- ManyPtr = numtostr(ManyText, Inventory[CurInv].Many);
- strcpy(text, Inventory[CurInv].name);
- strcat(text, " (");
- strcat(text, ManyPtr);
- strcat(text, ")");
- drawMessage(text);
+ Common::String roomMessage = Common::String(Inventory[CurInv].name) + " (" + Common::String::format("%d", Inventory[CurInv].Many) + ")";
+ drawMessage(roomMessage.c_str());
} else
drawMessage(Inventory[CurInv].name);
}
@@ -249,19 +243,14 @@ bool setUpScreens() {
return false;
/* Loads in the graphics for the movement control panel */
- MovePanelBufferSize = sizeOfFile("P:Control");
-
- if (MovePanelBufferSize == 0L)
- return false;
-
- if (!(MovePanelBuffer = (byte *)calloc(MovePanelBufferSize, 1)))
- return false;
-
Common::File *file = openPartial("P:Control");
-
if (!file)
return false;
+ MovePanelBufferSize = file->size();
+ if (!MovePanelBufferSize || !(MovePanelBuffer = (byte *)calloc(MovePanelBufferSize, 1)))
+ return false;
+
file->read(MovePanelBuffer, MovePanelBufferSize);
file->close();
@@ -315,19 +304,14 @@ bool setUpScreens() {
curgad->NextGadget = createButton(VGAScaleX(289), y, 9, 0, MoveImages[10], MoveImages[11]);
}
- InvPanelBufferSize = sizeOfFile("P:Inv");
-
- if (InvPanelBufferSize == 0L)
- return false;
-
- if (!(InvPanelBuffer = (byte *)calloc(InvPanelBufferSize, 1)))
- return false;
-
file = openPartial("P:Inv");
-
if (!file)
return false;
+ InvPanelBufferSize = file->size();
+ if (!InvPanelBufferSize || !(InvPanelBuffer = (byte *)calloc(InvPanelBufferSize, 1)))
+ return false;
+
file->read(InvPanelBuffer, InvPanelBufferSize);
file->close();
@@ -413,19 +397,13 @@ void eatMessages() {
do {
Msg = getMsg();
-
- if (Msg) {
+ if (Msg)
replyMsg((void *) Msg);
- }
} while (Msg);
return;
}
-
-
-
-
static uint16 lastmusicroom = 1;
diff --git a/engines/lab/labfile.cpp b/engines/lab/labfile.cpp
index c2acb203a5..43825f018d 100644
--- a/engines/lab/labfile.cpp
+++ b/engines/lab/labfile.cpp
@@ -203,7 +203,7 @@ bool allocFile(void **Ptr, uint32 Size, const char *fileName) {
/*****************************************************************************/
/* Reads a file into memory. */
/*****************************************************************************/
-byte **openFile(const char *name) {
+byte **openFile(const char *name, uint32 &size) {
byte *buf;
Common::File file;
@@ -215,7 +215,7 @@ byte **openFile(const char *name) {
return NULL;
}
- uint32 size = file.size();
+ size = file.size();
buf = (byte *)malloc(size);
diff --git a/engines/lab/labfun.h b/engines/lab/labfun.h
index 60b313e190..61f27fcc81 100644
--- a/engines/lab/labfun.h
+++ b/engines/lab/labfun.h
@@ -70,9 +70,7 @@ struct SaveGameHeader {
/* Reads in pictures */
bool readPict(const char *filename, bool PlayOnce);
-
bool readMusic(const char *filename);
-
byte *readPictToMem(const char *filename, uint16 x, uint16 y);
/* Window text stuff */
@@ -100,31 +98,23 @@ uint32 flowTextToMem(Image *DestIm, void *font, /* the TextAttr pointer */
uint16 y1, uint16 x2, uint16 y2, const char *text); /* The text itself */
void drawMessage(const char *text);
-
void longDrawMessage(const char *text);
-
bool readFont(char *filename, void *font, void *data);
/* The Wipes */
void doWipe(uint16 WipeType, CloseDataPtr *CPtr, char *filename);
-
/* Double Buffer stuff */
void newFlipViews(void *scrPtr, uint16 *newpal, uint16 numcolors);
-
void flipViews(void *scrPtr);
-
-
-
/*----------------------------*/
/*----- From Interface.c -----*/
/*----------------------------*/
Gadget *addGadButton(uint16 x, uint16 y, void *UpImage, void *DownImage, uint16 id);
-
void gadgetsOnOff(void *gptr, void *win, int32 num, bool on);
/*----------------------*/
@@ -133,22 +123,15 @@ void gadgetsOnOff(void *gptr, void *win, int32 num, bool on);
void introSequence();
-
-
/*----------------------*/
/*----- From Lab.c -----*/
/*----------------------*/
void eatMessages();
-
bool setUpScreens();
-
void drawPanel();
-
bool quitPlaying();
-
-
/*---------------------------*/
/*------ From LabFile.c -----*/
/*---------------------------*/
@@ -156,53 +139,33 @@ bool quitPlaying();
uint32 sizeOfFile(const char *name);
/* Buffer a whole file */
-
byte **isBuffered(const char *fileName);
-
-byte **openFile(const char *name);
-
+byte **openFile(const char *name, uint32 &size);
void readBlock(void *Buffer, uint32 Size, byte **File);
-
char readChar(char **File);
-
void skip(byte **File, uint32 skip);
-
void resetBuffer();
-
bool initBuffer(uint32 BufSize, bool IsGraphicsMem);
-
void freeBuffer();
-
/* Functions that borrow memory from the buffer */
-
bool allocFile(void **Ptr, uint32 Size, const char *fileName);
-
void *stealBufMem(int32 Size);
-
void freeAllStolenMem();
/* Read chunks of a file */
-
-
Common::File *openPartial(const char *name);
-
void closePartial(int32 File);
-
/*---------------------------*/
/*------ From LabText.c -----*/
/*---------------------------*/
bool initLabText();
-
void freeLabText();
-
void decrypt(byte *text);
-
-
/*---------------------------*/
/*----- From LabMusic.c -----*/
/*---------------------------*/
@@ -214,6 +177,7 @@ public:
Music();
byte **newOpen(const char *name);
+ byte **newOpen(const char *name, uint32 &size);
bool initMusic();
void freeMusic();
void fillUpMusic(bool doit);
@@ -264,17 +228,11 @@ extern Music *g_music;
class LargeSet {
public:
LargeSet(uint16 last);
-
~LargeSet();
-
bool in(uint16 element);
-
void inclElement(uint16 element);
-
void exclElement(uint16 element);
-
bool readInitialConditions(const char *fileName);
-
public:
uint16 _lastElement;
uint16 *_array;
@@ -285,62 +243,38 @@ public:
/*---------------------------*/
uint16 scaleX(uint16 x);
-
uint16 scaleY(uint16 y);
-
uint16 VGAScaleX(uint16 x);
-
uint16 VGAScaleY(uint16 y);
-
int16 VGAScaleXs(int16 x);
-
int16 VGAScaleYs(int16 y);
-
uint16 SVGACord(uint16 cord);
-
uint16 VGAUnScaleX(uint16 x);
-
uint16 VGAUnScaleY(uint16 y);
-
char *translateFileName(const char *filename);
-
-
/*---------------------------*/
/*-------- From Map.c -------*/
/*---------------------------*/
void fade(bool fadein, uint16 res);
-
void setAmigaPal(uint16 *pal, uint16 numcolors);
-
char *getText(const char *filename);
-
bool getFont(const char *filename, TextFont *textfont);
-
void readImage(byte **buffer, Image **im);
-
void doMap(uint16 CurRoom);
-
void doJournal();
-
void doNotes();
-
void doWestPaper();
-
void doMonitor(char *background, char *textfile, bool isinteractive, uint16 x1, uint16 y1, uint16 x2, uint16 y2);
-
bool saveRestoreGame();
-
-
/*--------------------------*/
/*----- From saveGame.c ----*/
/*--------------------------*/
bool saveGame(uint16 RoomNum, uint16 Direction, uint16 Quarters, int slot, Common::String desc);
bool loadGame(uint16 *RoomNum, uint16 *Direction, uint16 *Quarters, int slot);
-
bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header);
/*--------------------------*/
@@ -348,13 +282,9 @@ bool readSaveGameHeader(Common::InSaveFile *in, SaveGameHeader &header);
/*--------------------------*/
void showCombination(const char *filename);
-
void mouseCombination(uint16 x, uint16 y);
-
void showTile(const char *filename, bool showsolution);
-
void mouseTile(uint16 x, uint16 y);
-
void inner_main();
} // End of namespace Lab
diff --git a/engines/lab/labmusic.cpp b/engines/lab/labmusic.cpp
index 5222cd9af6..a435710078 100644
--- a/engines/lab/labmusic.cpp
+++ b/engines/lab/labmusic.cpp
@@ -331,6 +331,11 @@ void Music::resetMusic() {
_tFile = 0;
}
+byte **Music::newOpen(const char *name) {
+ uint32 unused;
+ return newOpen(name, unused);
+}
+
/*****************************************************************************/
/* Checks whether or note enough memory in music buffer before loading any */
/* files. Fills it if not. Does not take into account the current buffer */
@@ -339,20 +344,14 @@ void Music::resetMusic() {
/* */
/* Here, the seconds are multipled by 10. */
/*****************************************************************************/
-byte **Music::newOpen(const char *name) {
+byte **Music::newOpen(const char *name, uint32 &size) {
byte **file;
- if (name == NULL) {
+ if (!name || !strcmp(name, "") || !strcmp(name, " "))
return NULL;
- }
- if ((strcmp(name, "") == 0) || (strcmp(name, " ") == 0)) {
- return NULL;
- }
-
- if ((file = isBuffered(name))) {
+ if (file = isBuffered(name))
return file;
- }
if (_musicOn) {
updateMusic();
@@ -362,7 +361,7 @@ byte **Music::newOpen(const char *name) {
if (!_doNotFilestopSoundEffect && isSoundEffectActive())
stopSoundEffect();
- file = openFile(name);
+ file = openFile(name, size);
checkMusic();
return file;
}
diff --git a/engines/lab/map.cpp b/engines/lab/map.cpp
index b6b4415b11..a0dffe04e9 100644
--- a/engines/lab/map.cpp
+++ b/engines/lab/map.cpp
@@ -219,7 +219,7 @@ static uint16 mapScaleY(uint16 y) {
/*****************************************************************************/
static bool loadMapData() {
byte **buffer, Temp[5];
- int32 Size;
+ uint32 Size;
Gadget *gptr;
uint16 counter;
@@ -228,9 +228,8 @@ static bool loadMapData() {
if (!getFont("P:Map.fon", BigMsgFont))
BigMsgFont = MsgFont;
- Size = sizeOfFile("P:MapImage");
resetBuffer(); /* Make images load into start of buffer */
- buffer = g_music->newOpen("P:MapImage");
+ buffer = g_music->newOpen("P:MapImage", Size);
if (!buffer)
return false;
@@ -279,8 +278,9 @@ static bool loadMapData() {
counter++;
}
- buffer = g_music->newOpen("Lab:Maps");
- stealBufMem(sizeOfFile("Lab:Maps")); /* Freeze the memory for the maps */
+ uint32 bufferSize;
+ buffer = g_music->newOpen("Lab:Maps", bufferSize);
+ stealBufMem(bufferSize); /* Freeze the memory for the maps */
readBlock(Temp, 4L, buffer);
Temp[4] = 0;
diff --git a/engines/lab/readparse.cpp b/engines/lab/readparse.cpp
index 5e4bf6208e..672688cac3 100644
--- a/engines/lab/readparse.cpp
+++ b/engines/lab/readparse.cpp
@@ -181,58 +181,6 @@ bool readInventory(const char *fileName) {
return true;
}
-
-
-
-
-
-/*****************************************************************************/
-/* Converts a number to a string. */
-/*****************************************************************************/
-char *numtostr(char *text, uint16 Num) {
- uint16 Counter = 0;
-
- if (Num == 0) {
- text[0] = '0';
- text[1] = 0;
- return text;
- }
-
- strcpy(text, "00000");
-
- if (Num >= 10000) {
- text[0] = (Num / 10000) + '0';
- Num -= (Num / 10000) * 10000;
- }
-
- if (Num >= 1000) {
- text[1] = (Num / 1000) + '0';
- Num -= (Num / 1000) * 1000;
- }
-
- if (Num >= 100) {
- text[2] = (Num / 100) + '0';
- Num -= (Num / 100) * 100;
- }
-
- if (Num >= 10) {
- text[3] = (Num / 10) + '0';
- Num -= (Num / 10) * 10;
- }
-
- text[4] = Num + '0';
- text[5] = 0;
-
- while (text[Counter] == '0')
- Counter++;
-
- return (&text[Counter]);
-}
-
-
-
-
-
/*****************************************************************************/
/* Reads in a list of conditions. */
/*****************************************************************************/
@@ -258,9 +206,6 @@ static int16 *readConditions(byte **file) {
return ptr;
}
-
-
-
/*****************************************************************************/
/* Reads in some CloseUp data. */
/*****************************************************************************/
@@ -417,16 +362,13 @@ static bool readRule(RulePtr *RPtr, byte **file) {
/* Reads in the views of a room. */
/*****************************************************************************/
bool readViews(uint16 RoomNum, const char *Path) {
- char Temp[10], *RoomString, fileName[250];
+ Common::String fileName = Common::String(Path) + Common::String::format("%d", RoomNum);
+ char Temp[10];
byte **file;
allocroom = RoomNum;
- RoomString = numtostr(Temp, RoomNum);
- strcpy(fileName, Path);
- strcat(fileName, RoomString);
-
- if ((file = g_music->newOpen(fileName)) != NULL) {
+ if ((file = g_music->newOpen(fileName.c_str())) != NULL) {
readBlock(Temp, 4L, file);
Temp[4] = '\0';
diff --git a/engines/lab/text.cpp b/engines/lab/text.cpp
index 5c456c4523..5056d24e63 100644
--- a/engines/lab/text.cpp
+++ b/engines/lab/text.cpp
@@ -41,10 +41,9 @@ namespace Lab {
bool openFontMem(const char *TextFontPath, struct TextFont *tf, byte *fontbuffer) {
byte **file = NULL;
char header[5];
- int32 filesize, headersize = 4L + 2L + 256 * 3 + 4L;
+ uint32 filesize, headersize = 4L + 2L + 256 * 3 + 4L;
- filesize = sizeOfFile(TextFontPath);
- file = g_music->newOpen(TextFontPath);
+ file = g_music->newOpen(TextFontPath, filesize);
if ((file != NULL) && (filesize > headersize)) {
header[4] = 0;
@@ -76,11 +75,10 @@ bool openFontMem(const char *TextFontPath, struct TextFont *tf, byte *fontbuffer
bool openFont(const char *TextFontPath, struct TextFont **tf) {
byte **file = NULL;
char header[5];
- int32 filesize, headersize = 4L + 2L + 256 * 3 + 4L;
+ uint32 filesize, headersize = 4L + 2L + 256 * 3 + 4L;
if ((*tf = (TextFont *)calloc(sizeof(struct TextFont), 1))) {
- filesize = sizeOfFile(TextFontPath);
- file = g_music->newOpen(TextFontPath);
+ file = g_music->newOpen(TextFontPath, filesize);
if ((file != NULL) && (filesize > headersize)) {
header[4] = 0;