LAB: Refactor the remaining functions in labfile.cpp

This commit is contained in:
Filippos Karapetis 2015-12-04 21:47:47 +02:00 committed by Willem Jan Palenstijn
parent eb0a52e7fb
commit 9ba30835a2
7 changed files with 41 additions and 108 deletions

View file

@ -414,6 +414,11 @@ void Anim::unDiff(byte *newBuf, byte *oldBuf, byte *diffData, uint16 bytesPerRow
unDIFFMemory(newBuf, diffData, 1, bufType + 1);
}
void Anim::readBlock(void *Buffer, uint32 Size, byte **File) {
memcpy(Buffer, *File, (size_t)Size);
(*File) += Size;
}
void Anim::diffNextFrame() {
if (_header == 65535) /* Already done. */
return;

View file

@ -93,6 +93,7 @@ private:
void VUnDIFFByteByte(byte *Dest, byte *diff, uint16 bytesperrow);
void VUnDIFFByteWord(uint16 *Dest, uint16 *diff, uint16 bytesperrow);
void VUnDIFFByteLong(uint32 *Dest, uint32 *diff, uint16 bytesperrow);
void readBlock(void *Buffer, uint32 Size, byte **File);
public:
Anim(LabEngine *vm);

View file

@ -1,88 +0,0 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
/*
* This code is based on Labyrinth of Time code with assistance of
*
* Copyright (c) 1993 Terra Nova Development
* Copyright (c) 2004 The Wyrmkeep Entertainment Co.
*
*/
#include "lab/lab.h"
#include "lab/labfun.h"
#include "common/file.h"
namespace Lab {
/*****************************************************************************/
/* Reads a block of memory. */
/*****************************************************************************/
void readBlock(void *Buffer, uint32 Size, byte **File) {
memcpy(Buffer, *File, (size_t) Size);
(*File) += Size;
}
static char NewFileName[255];
/*****************************************************************************/
/* Modifies the filename so that paths and stuff are correct. Should mostly */
/* deal with assigns and the '/' instead of '\' on IBM systems. */
/* */
/* NOTE: Make a *copy* of the string, and modify that. It would be a real */
/* *bad* idea to modify the original. Since Labyrinth only focuses its */
/* attention to one file at a time, it would be fine to have one variable */
/* not on the stack which is used to store the new filename. */
/*****************************************************************************/
char *translateFileName(const char *filename) {
Common::String fileNameStr = filename;
fileNameStr.toUppercase();
Common::String fileNameStrFinal;
if (fileNameStr.hasPrefix("P:")) {
if (g_lab->_isHiRes)
fileNameStrFinal = "GAME/SPICT/";
else
fileNameStrFinal = "GAME/PICT/";
} else if (fileNameStr.hasPrefix("LAB:"))
fileNameStrFinal = "GAME/";
else if (fileNameStr.hasPrefix("MUSIC:"))
fileNameStrFinal = "GAME/MUSIC/";
if (fileNameStr.contains(':')) {
while (fileNameStr[0] != ':') {
fileNameStr.deleteChar(0);
}
fileNameStr.deleteChar(0);
}
fileNameStrFinal += fileNameStr;
strcpy(NewFileName, fileNameStrFinal.c_str());
return NewFileName;
}
} // End of namespace Lab

View file

@ -115,12 +115,6 @@ public:
uint16 *_array;
};
/*---------------------------*/
/*----- From Machine.c ------*/
/*---------------------------*/
char *translateFileName(const char *filename);
/*---------------------------*/
/*-------- From Map.c -------*/
/*---------------------------*/

View file

@ -10,7 +10,6 @@ MODULE_OBJS := \
interface.o \
intro.o \
lab.o \
labfile.o \
labsets.o \
map.o \
music.o \

View file

@ -43,21 +43,16 @@ Resource::Resource(LabEngine *vm) : _vm(vm) {
}
void Resource::readStaticText() {
Common::File labTextFile;
labTextFile.open(translateFileName("Lab:Rooms/LabText"));
if (!labTextFile.isOpen())
error("Unable to open file %s (Lab:Rooms/LabText)", translateFileName("Lab:Rooms/LabText"));
Common::File *labTextFile = openDataFile("Lab:Rooms/LabText");
for (int i = 0; i < 48; i++)
_staticText[i] = labTextFile.readLine();
_staticText[i] = labTextFile->readLine();
labTextFile.close();
delete labTextFile;
}
TextFont *Resource::getFont(const char *fileName) {
Common::File *dataFile;
if (!(dataFile = openDataFile(fileName, MKTAG('V', 'G', 'A', 'F'))))
error("getFont: couldn't open %s (%s)", translateFileName(fileName), fileName);
Common::File *dataFile = openDataFile(fileName, MKTAG('V', 'G', 'A', 'F'));
uint32 headerSize = 4L + 2L + 256 * 3 + 4L;
uint32 fileSize = dataFile->size();
@ -79,10 +74,7 @@ TextFont *Resource::getFont(const char *fileName) {
}
char *Resource::getText(const char *fileName) {
Common::File *dataFile = new Common::File();
dataFile->open(translateFileName(fileName));
if (!dataFile->isOpen())
error("getText: couldn't open %s (%s)", translateFileName(fileName), fileName);
Common::File *dataFile = openDataFile(fileName);
g_lab->_music->updateMusic();
@ -94,6 +86,7 @@ char *Resource::getText(const char *fileName) {
while (text && *text != '\0')
*text++ -= (byte)95;
delete dataFile;
return (char *)buffer;
}
@ -166,6 +159,34 @@ bool Resource::readViews(uint16 roomNum) {
return true;
}
Common::String Resource::translateFileName(Common::String filename) {
filename.toUppercase();
Common::String fileNameStrFinal;
if (filename.hasPrefix("P:")) {
if (g_lab->_isHiRes)
fileNameStrFinal = "GAME/SPICT/";
else
fileNameStrFinal = "GAME/PICT/";
}
else if (filename.hasPrefix("LAB:"))
fileNameStrFinal = "GAME/";
else if (filename.hasPrefix("MUSIC:"))
fileNameStrFinal = "GAME/MUSIC/";
if (filename.contains(':')) {
while (filename[0] != ':') {
filename.deleteChar(0);
}
filename.deleteChar(0);
}
fileNameStrFinal += filename;
return fileNameStrFinal;
}
Common::File *Resource::openDataFile(const char *fileName, uint32 fileHeader) {
Common::File *dataFile = new Common::File();
dataFile->open(translateFileName(fileName));

View file

@ -115,6 +115,7 @@ private:
CloseData *readCloseUps(uint16 depth, Common::File *file);
ViewData *readView(Common::File *file);
void readStaticText();
Common::String translateFileName(Common::String filename);
Common::String _staticText[48];
};