本文整理汇总了C++中common::File::eos方法的典型用法代码示例。如果您正苦于以下问题:C++ File::eos方法的具体用法?C++ File::eos怎么用?C++ File::eos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::File
的用法示例。
在下文中一共展示了File::eos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setAmiga
// Will try to set amiga palette by using "spal" file. If not found, we return false
bool GfxPalette::setAmiga() {
Common::File file;
if (file.open("spal")) {
for (int curColor = 0; curColor < 32; curColor++) {
byte byte1 = file.readByte();
byte byte2 = file.readByte();
if (file.eos())
error("Amiga palette file ends prematurely");
_sysPalette.colors[curColor].used = 1;
_sysPalette.colors[curColor].r = (byte1 & 0x0F) * 0x11;
_sysPalette.colors[curColor].g = ((byte2 & 0xF0) >> 4) * 0x11;
_sysPalette.colors[curColor].b = (byte2 & 0x0F) * 0x11;
if (_totalScreenColors == 64) {
// Set the associated color from the Amiga halfbrite colors
_sysPalette.colors[curColor + 32].used = 1;
_sysPalette.colors[curColor + 32].r = _sysPalette.colors[curColor].r >> 1;
_sysPalette.colors[curColor + 32].g = _sysPalette.colors[curColor].g >> 1;
_sysPalette.colors[curColor + 32].b = _sysPalette.colors[curColor].b >> 1;
}
}
// Directly set the palette, because setOnScreen() wont do a thing for amiga
copySysPaletteToScreen();
return true;
}
示例2: parseScrFile
void ScriptManager::parseScrFile(const Common::String &fileName, bool isGlobal) {
Common::File file;
if (!file.open(fileName)) {
warning("Script file not found: %s", fileName.c_str());
return;
}
while(!file.eos()) {
Common::String line = file.readLine();
if (file.err()) {
warning("Error parsing scr file: %s", fileName.c_str());
return;
}
trimCommentsAndWhiteSpace(&line);
if (line.empty())
continue;
if (line.matchString("puzzle:*", true)) {
Puzzle *puzzle = new Puzzle();
sscanf(line.c_str(),"puzzle:%u",&(puzzle->key));
parsePuzzle(puzzle, file);
if (isGlobal) {
_globalPuzzles.push_back(puzzle);
} else {
_activePuzzles.push_back(puzzle);
}
} else if (line.matchString("control:*", true)) {
parseControl(line, file);
}
}
}
示例3:
bool readBit8u(MT32Emu::Bit8u *in) {
byte b = _in.readByte();
if (_in.eos())
return false;
*in = b;
return true;
}
示例4: setAGIPal
//Gets AGIPAL Data
void GfxMgr::setAGIPal(int p0) {
//If 0 from savefile, do not use
if (p0 == 0)
return;
char filename[15];
sprintf(filename, "pal.%d", p0);
Common::File agipal;
if (!agipal.open(filename)) {
warning("Couldn't open AGIPAL palette file '%s'. Not changing palette", filename);
return; // Needed at least by Naturette 3 which uses AGIPAL but provides no palette files
}
//Chunk0 holds colors 0-7
agipal.read(&_agipalPalette[0], 24);
//Chunk1 is the same as the chunk0
//Chunk2 chunk holds colors 8-15
agipal.seek(24, SEEK_CUR);
agipal.read(&_agipalPalette[24], 24);
//Chunk3 is the same as the chunk2
//Chunks4-7 are duplicates of chunks0-3
if (agipal.eos() || agipal.err()) {
warning("Couldn't read AGIPAL palette from '%s'. Not changing palette", filename);
return;
}
// Use only the lowest 6 bits of each color component (Red, Green and Blue)
// because VGA used only 6 bits per color component (i.e. VGA had 18-bit colors).
// This should now be identical to the original AGIPAL-hack's behavior.
bool validVgaPalette = true;
for (int i = 0; i < 16 * 3; i++) {
if (_agipalPalette[i] >= (1 << 6)) {
_agipalPalette[i] &= 0x3F; // Leave only the lowest 6 bits of each color component
validVgaPalette = false;
}
}
if (!validVgaPalette)
warning("Invalid AGIPAL palette (Over 6 bits per color component) in '%s'. Using only the lowest 6 bits per color component", filename);
_agipalFileNum = p0;
initPalette(_agipalPalette);
gfxSetPalette();
debug(1, "Using AGIPAL palette from '%s'", filename);
}
示例5: loadWords
int AgiEngine::loadWords(const char *fname) {
Common::File fp;
if (!fp.open(fname)) {
warning("loadWords: can't open %s", fname);
return errOK; // err_BadFileOpen
}
debug(0, "Loading dictionary: %s", fname);
// Loop through alphabet, as words in the dictionary file are sorted by
// first character
for (int i = 0; i < 26; i++) {
fp.seek(i * 2, SEEK_SET);
int offset = fp.readUint16BE();
if (offset == 0)
continue;
fp.seek(offset, SEEK_SET);
int k = fp.readByte();
while (!fp.eos() && !fp.err()) {
// Read next word
char c, str[64];
do {
c = fp.readByte();
str[k++] = (c ^ 0x7F) & 0x7F;
} while (!(c & 0x80) && k < (int)sizeof(str) - 1);
str[k] = 0;
// WORKAROUND:
// The SQ0 fan game stores words starting with numbers (like '7up')
// in its dictionary under the 'a' entry. We skip these.
// See bug #3615061
if (str[0] == 'a' + i) {
// And store it in our internal dictionary
AgiWord *w = new AgiWord;
w->word = myStrndup(str, k);
w->id = fp.readUint16BE();
_game.words[i].push_back(w);
}
k = fp.readByte();
// Are there more words with an already known prefix?
// WORKAROUND: We only break after already seeing words with the
// right prefix, for the SQ0 words starting with digits filed under
// 'a'. See above comment and bug #3615061.
if (k == 0 && str[0] >= 'a' + i)
break;
}
}
return errOK;
}
示例6: resOpen
void ResMan::resOpen(uint32 id) { // load resource ID into memory
MemHandle *memHandle = resHandle(id);
if (!memHandle)
return;
if (memHandle->cond == MEM_FREED) { // memory has been freed
uint32 size = resLength(id);
_memMan->alloc(memHandle, size);
Common::File *clusFile = resFile(id);
assert(clusFile);
clusFile->seek(resOffset(id));
clusFile->read(memHandle->data, size);
if (clusFile->err() || clusFile->eos()) {
error("Can't read %d bytes from offset %d from cluster file %s\nResource ID: %d (%08X)", size, resOffset(id), _prj.clu[(id >> 24) - 1].label, id, id);
}
示例7: loadStrFile
void StringManager::loadStrFile(const Common::String &fileName) {
Common::File file;
if (!_engine->getSearchManager()->openFile(file, fileName)) {
error("%s does not exist. String parsing failed", fileName.c_str());
}
uint lineNumber = 0;
while (!file.eos()) {
_lines[lineNumber] = readWideLine(file);
lineNumber++;
assert(lineNumber <= NUM_TEXT_LINES);
}
}
示例8: RegisterGlobals
/**
* Allocates enough RAM to hold the global Glitter variables.
*/
void RegisterGlobals(int num) {
if (pGlobals == NULL) {
numGlobals = num;
hMasterScript = !TinselV2 ? 0 :
READ_LE_UINT32(FindChunk(MASTER_SCNHANDLE, CHUNK_MASTER_SCRIPT));
// Allocate RAM for pGlobals and make sure it's allocated
pGlobals = (int32 *)calloc(numGlobals, sizeof(int32));
if (pGlobals == NULL) {
error("Cannot allocate memory for global data");
}
// Allocate RAM for interpret contexts and make sure it's allocated
icList = (INT_CONTEXT *)calloc(NUM_INTERPRET, sizeof(INT_CONTEXT));
if (icList == NULL) {
error("Cannot allocate memory for interpret contexts");
}
g_scheduler->setResourceCallback(FreeInterpretContextPr);
} else {
// Check size is still the same
assert(numGlobals == num);
memset(pGlobals, 0, numGlobals * sizeof(int32));
memset(icList, 0, NUM_INTERPRET * sizeof(INT_CONTEXT));
}
if (TinselV2) {
// read initial values
CdCD(nullContext);
Common::File f;
if (!f.open(GLOBALS_FILENAME))
error(CANNOT_FIND_FILE, GLOBALS_FILENAME);
int32 length = f.readSint32LE();
if (length != num)
error(FILE_IS_CORRUPT, GLOBALS_FILENAME);
for (int i = 0; i < length; ++i)
pGlobals[i] = f.readSint32LE();
if (f.eos() || f.err())
error(FILE_IS_CORRUPT, GLOBALS_FILENAME);
f.close();
}
}
示例9: readStringsFile
void TitlerControl::readStringsFile(const Common::String &fileName) {
Common::File file;
if (!_engine->getSearchManager()->openFile(file, fileName)) {
warning("String_resource_file %s could could be opened", fileName.c_str());
return;
}
_strings.clear();
while (!file.eos()) {
Common::String line = readWideLine(file);
_strings.push_back(line);
}
file.close();
}
示例10: resId
// AUDIOnnn.MAP contains 10-byte entries:
// Early format:
// w 5 bits resource type and 11 bits resource number
// dw 7 bits volume number and 25 bits offset
// dw size
// Later format:
// w nEntry
// dw offset+volume (as in resource.map)
// dw size
// ending with 10 0xFFs
int ResourceManager::readAudioMapSCI1(ResourceSource *map, bool unload) {
Common::File file;
if (!file.open(map->getLocationName()))
return SCI_ERROR_RESMAP_NOT_FOUND;
bool oldFormat = (file.readUint16LE() >> 11) == kResourceTypeAudio;
file.seek(0);
for (;;) {
uint16 n = file.readUint16LE();
uint32 offset = file.readUint32LE();
uint32 size = file.readUint32LE();
if (file.eos() || file.err()) {
warning("Error while reading %s", map->getLocationName().c_str());
return SCI_ERROR_RESMAP_NOT_FOUND;
}
if (n == 0xffff)
break;
byte volume_nr;
if (oldFormat) {
n &= 0x07ff; // Mask out resource type
volume_nr = offset >> 25; // most significant 7 bits
offset &= 0x01ffffff; // least significant 25 bits
} else {
volume_nr = offset >> 28; // most significant 4 bits
offset &= 0x0fffffff; // least significant 28 bits
}
ResourceSource *src = findVolume(map, volume_nr);
if (src) {
const ResourceId resId(kResourceTypeAudio, n);
if (unload)
removeAudioResource(resId);
else
addResource(resId, src, offset, size, map->getLocationName());
} else {
warning("Failed to find audio volume %i", volume_nr);
return SCI_ERROR_NO_RESOURCE_FILES_FOUND;
}
}
示例11:
TLib::TLib(MemoryManager &memManager, const Common::String &filename) :
_memoryManager(memManager) {
// If the resource strings list isn't yet loaded, load them
if (_resStrings.size() == 0) {
Common::File f;
if (f.open("tsage.cfg")) {
while (!f.eos()) {
_resStrings.push_back(f.readLine());
}
f.close();
}
}
if (!_file.open(filename))
error("Missing file %s", filename.c_str());
loadIndex();
}
示例12: setAmiga
// Will try to set amiga palette by using "spal" file. If not found, we return false
bool GfxPalette::setAmiga() {
Common::File file;
if (file.open("spal")) {
for (int curColor = 0; curColor < 32; curColor++) {
byte byte1 = file.readByte();
byte byte2 = file.readByte();
if (file.eos())
error("Amiga palette file ends prematurely");
_sysPalette.colors[curColor].used = 1;
_sysPalette.colors[curColor].r = (byte1 & 0x0F) * 0x11;
_sysPalette.colors[curColor].g = ((byte2 & 0xF0) >> 4) * 0x11;
_sysPalette.colors[curColor].b = (byte2 & 0x0F) * 0x11;
}
// Directly set the palette, because setOnScreen() wont do a thing for amiga
copySysPaletteToScreen();
return true;
}
return false;
}
示例13: getNextChunk
bool PCMMusicPlayer::getNextChunk() {
MusicSegment *musicSegments;
int32 *script, *scriptBuffer;
int id;
int snum;
uint32 sampleOffset, sampleLength, sampleCLength;
Common::File file;
byte *buffer;
Common::SeekableReadStream *sampleStream;
switch (_state) {
case S_NEW:
case S_NEXT:
_forcePlay = false;
script = scriptBuffer = (int32 *)LockMem(_hScript);
// Set parameters for this chunk of music
id = _scriptNum;
while (id--)
script = scriptBuffer + READ_32(script);
snum = FROM_32(script[_scriptIndex++]);
if (snum == MUSIC_JUMP || snum == MUSIC_END) {
// Let usual code sort it out!
_scriptIndex--; // Undo increment
_forcePlay = true; // Force a Play
_state = S_END1; // 'Goto' S_END1
break;
}
musicSegments = (MusicSegment *) LockMem(_hSegment);
assert(FROM_32(musicSegments[snum].numChannels) == 1);
assert(FROM_32(musicSegments[snum].bitsPerSample) == 16);
sampleOffset = FROM_32(musicSegments[snum].sampleOffset);
sampleLength = FROM_32(musicSegments[snum].sampleLength);
sampleCLength = (((sampleLength + 63) & ~63)*33)/64;
if (!file.open(_filename))
error(CANNOT_FIND_FILE, _filename.c_str());
file.seek(sampleOffset);
if (file.eos() || file.err() || (uint32)file.pos() != sampleOffset)
error(FILE_IS_CORRUPT, _filename.c_str());
buffer = (byte *) malloc(sampleCLength);
assert(buffer);
// read all of the sample
if (file.read(buffer, sampleCLength) != sampleCLength)
error(FILE_IS_CORRUPT, _filename.c_str());
debugC(DEBUG_DETAILED, kTinselDebugMusic, "Creating ADPCM music chunk with size %d, "
"offset %d (script %d.%d)", sampleCLength, sampleOffset,
_scriptNum, _scriptIndex - 1);
sampleStream = new Common::MemoryReadStream(buffer, sampleCLength, DisposeAfterUse::YES);
delete _curChunk;
_curChunk = new Tinsel8_ADPCMStream(sampleStream, DisposeAfterUse::YES, sampleCLength,
22050, 1, 32);
_state = S_MID;
return true;
case S_END1:
debugC(DEBUG_DETAILED, kTinselDebugMusic, "Music reached state S_END1 (script %d.%d)",
_scriptNum, _scriptIndex);
script = scriptBuffer = (int32 *) LockMem(_hScript);
id = _scriptNum;
while (id--)
script = scriptBuffer + READ_32(script);
snum = FROM_32(script[_scriptIndex]);
if (snum == MUSIC_END) {
_state = S_END2;
} else {
if (snum == MUSIC_JUMP)
_scriptIndex = FROM_32(script[_scriptIndex+1]);
_state = _forcePlay ? S_NEW : S_NEXT;
_forcePlay = false;
}
return true;
case S_END2:
debugC(DEBUG_DETAILED, kTinselDebugMusic, "Music reached state S_END2 (script %d.%d)",
_scriptNum, _scriptIndex);
_silenceSamples = 11025; // Half a second of silence
return true;
case S_END3:
debugC(DEBUG_DETAILED, kTinselDebugMusic, "Music reached state S_END3 (script %d.%d)",
_scriptNum, _scriptIndex);
//.........这里部分代码省略.........
示例15: fileToStack
bool fileToStack(const Common::String &filename, StackHandler *sH) {
Variable stringVar;
stringVar.varType = SVT_NULL;
Common::String checker = saveEncoding ? "[Custom data (encoded)]\r\n" : "[Custom data (ASCII)]\n";
Common::File fd;
if (!fd.open(filename)) {
#if 0
char currentDir[1000];
if (!getcwd(currentDir, 998)) {
debugOut("Can't get current directory.\n");
}
if (chdir(gamePath)) {
debugOut("Error: Failed changing to directory %s\n", gamePath);
}
if (chdir(currentDir)) {
debugOut("Error: Failed changing to directory %s\n", currentDir);
}
if (!fd.open(filename)) {
return fatal("No such file", filename);
}
#endif
return fatal("No such file", filename); //TODO: false value
}
encode1 = (byte)saveEncoding & 255;
encode2 = (byte)(saveEncoding >> 8);
for (uint i = 0; i < checker.size(); ++i) {
if (fd.readByte() != checker[i]) {
fd.close();
return fatal(LOAD_ERROR "This isn't a SLUDGE custom data file:", filename);
}
}
if (saveEncoding) {
checker = readStringEncoded(&fd);
if (checker == UTF8_CHECKER) {
fd.close();
return fatal(
LOAD_ERROR "The current file encoding setting does not match the encoding setting used when this file was created:", filename);
}
}
for (;;) {
if (saveEncoding) {
char i = fd.readByte() ^ encode1;
if (fd.eos())
break;
switch (i) {
case 0: {
Common::String g = readStringEncoded(&fd);
makeTextVar(stringVar, g);
}
break;
case 1:
setVariable(stringVar, SVT_INT, fd.readUint32LE());
break;
case 2:
setVariable(stringVar, SVT_INT, fd.readByte());
break;
default:
fatal(LOAD_ERROR "Corrupt custom data file:", filename);
fd.close();
return false;
}
} else {
char *line = readTextPlain(&fd);
if (!line)
break;
makeTextVar(stringVar, line);
}
if (sH->first == NULL) {
// Adds to the TOP of the array... oops!
if (!addVarToStackQuick(stringVar, sH->first))
return false;
sH->last = sH->first;
} else {
// Adds to the END of the array... much better
if (!addVarToStackQuick(stringVar, sH->last->next))
return false;
sH->last = sH->last->next;
}
}
fd.close();
return true;
}