本文整理汇总了C++中common::WriteStream类的典型用法代码示例。如果您正苦于以下问题:C++ WriteStream类的具体用法?C++ WriteStream怎么用?C++ WriteStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WriteStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
bool SavePartInfo::write(Common::WriteStream &stream) const {
if (!_header.write(stream))
return false;
stream.writeUint32LE(_gameID);
stream.writeUint32LE(_gameVersion);
stream.writeByte(_endian);
stream.writeUint32LE(_varCount);
stream.writeUint32LE(_descMaxLength);
if (stream.write(_desc, _descMaxLength) != _descMaxLength)
return false;
return flushStream(stream);
}
示例2: saveGame
bool LureEngine::saveGame(uint8 slotNumber, Common::String &caption) {
Common::WriteStream *f = this->_saveFileMan->openForSaving(
generateSaveName(slotNumber));
if (f == NULL)
return false;
f->write("lure", 5);
f->writeByte(getLanguage());
f->writeByte(LURE_SAVEGAME_MINOR);
f->writeString(caption);
f->writeByte(0); // End of string terminator
Resources::getReference().saveToStream(f);
Game::getReference().saveToStream(f);
Sound.saveToStream(f);
Fights.saveToStream(f);
Room::getReference().saveToStream(f);
delete f;
return true;
}
示例3: writeBlock
void Decompiler::writeBlock(Common::WriteStream &out, const Block *block, size_t indent) {
for (const auto instruction : block->instructions) {
writeInstruction(out, instruction, indent);
}
for (const auto &childType : block->childrenTypes) {
if (isSubRoutineCall(childType)) {
writeIndent(out, indent);
const Instruction *instruction = block->instructions.back();
out.writeString(formatJumpLabelName(*instruction->branches[0]));
out.writeString("(");
for (size_t i = 0; i < instruction->variables.size(); ++i) {
out.writeString(formatVariableName(instruction->variables[i]));
if (i < instruction->variables.size() - 1)
out.writeString(", ");
}
out.writeString(");\n");
writeBlock(out, block->children[1], indent);
}
}
for (const auto &control : block->controls) {
if (control.type == kControlTypeReturn) {
writeIndent(out, indent);
out.writeString("return;\n");
} else if (control.type == kControlTypeIfCond) {
writeIfControl(out, control, indent);
}
// TODO: while
// TODO: break
// TODO: continue
}
}
示例4: kFileIOExists
reg_t kFileIOExists(EngineState *s, int argc, reg_t *argv) {
Common::String name = s->_segMan->getString(argv[0]);
#ifdef ENABLE_SCI32
// Cache the file existence result for the Phantasmagoria
// save index file, as the game scripts keep checking for
// its existence.
if (name == PHANTASMAGORIA_SAVEGAME_INDEX && s->_virtualIndexFile)
return TRUE_REG;
#endif
bool exists = false;
// Check for regular file
exists = Common::File::exists(name);
// Check for a savegame with the name
Common::SaveFileManager *saveFileMan = g_sci->getSaveFileManager();
if (!exists)
exists = !saveFileMan->listSavefiles(name).empty();
// Try searching for the file prepending "target-"
const Common::String wrappedName = g_sci->wrapFilename(name);
if (!exists) {
exists = !saveFileMan->listSavefiles(wrappedName).empty();
}
// SCI2+ debug mode
if (DebugMan.isDebugChannelEnabled(kDebugLevelDebugMode)) {
if (!exists && name == "1.scr") // PQ4
exists = true;
if (!exists && name == "18.scr") // QFG4
exists = true;
if (!exists && name == "99.scr") // GK1, KQ7
exists = true;
if (!exists && name == "classes") // GK2, SQ6, LSL7
exists = true;
}
// Special case for non-English versions of LSL5: The English version of
// LSL5 calls kFileIO(), case K_FILEIO_OPEN for reading to check if
// memory.drv exists (which is where the game's password is stored). If
// it's not found, it calls kFileIO() again, case K_FILEIO_OPEN for
// writing and creates a new file. Non-English versions call kFileIO(),
// case K_FILEIO_FILE_EXISTS instead, and fail if memory.drv can't be
// found. We create a default memory.drv file with no password, so that
// the game can continue.
if (!exists && name == "memory.drv") {
// Create a new file, and write the bytes for the empty password
// string inside
byte defaultContent[] = { 0xE9, 0xE9, 0xEB, 0xE1, 0x0D, 0x0A, 0x31, 0x30, 0x30, 0x30 };
Common::WriteStream *outFile = saveFileMan->openForSaving(wrappedName);
for (int i = 0; i < 10; i++)
outFile->writeByte(defaultContent[i]);
outFile->finalize();
exists = !outFile->err(); // check whether we managed to create the file.
delete outFile;
}
// Special case for KQ6 Mac: The game checks for two video files to see
// if they exist before it plays them. Since we support multiple naming
// schemes for resource fork files, we also need to support that here in
// case someone has a "HalfDome.bin" file, etc.
if (!exists && g_sci->getGameId() == GID_KQ6 && g_sci->getPlatform() == Common::kPlatformMacintosh &&
(name == "HalfDome" || name == "Kq6Movie"))
exists = Common::MacResManager::exists(name);
debugC(kDebugLevelFile, "kFileIO(fileExists) %s -> %d", name.c_str(), exists);
return make_reg(0, exists);
}
示例5: saveOrLoadPtr
static void saveOrLoadPtr(Common::WriteStream &stream, int16 *&p, int16 *base) {
int32 offset = (int32)(p - base);
stream.writeSint32LE(offset);
}
示例6: saveOrLoad
static void saveOrLoad(Common::WriteStream &stream, int16 &i) {
stream.writeSint16LE(i);
}
示例7: writeCSV
void TwoDAFile::writeCSV(Common::WriteStream &out) const {
// Write column headers
for (size_t i = 0; i < _headers.size(); i++) {
const bool needQuote = _headers[i].contains(',');
if (needQuote)
out.writeByte('"');
out.writeString(_headers[i]);
if (needQuote)
out.writeByte('"');
if (i < (_headers.size() - 1))
out.writeByte(',');
}
out.writeByte('\n');
// Write array
for (size_t i = 0; i < _rows.size(); i++) {
for (size_t j = 0; j < _rows[i]->_data.size(); j++) {
const bool needQuote = _rows[i]->_data[j].contains(',');
if (needQuote)
out.writeByte('"');
if (_rows[i]->_data[j] != "****")
out.writeString(_rows[i]->_data[j]);
if (needQuote)
out.writeByte('"');
if (j < (_rows[i]->_data.size() - 1))
out.writeByte(',');
}
out.writeByte('\n');
}
out.flush();
}
示例8: pngWriteToStream
void pngWriteToStream(png_structp pngPtr, png_bytep data, png_size_t length) {
void *writeIOptr = png_get_io_ptr(pngPtr);
Common::WriteStream *stream = (Common::WriteStream *)writeIOptr;
stream->write(data, length);
}
示例9: exportWAVImpl
void MainWindow::exportWAVImpl(Sound::AudioStream *sound, Common::WriteStream &wav) {
assert(sound);
const uint16 channels = sound->getChannels();
const uint32 rate = sound->getRate();
std::deque<SoundBuffer> buffers;
uint64 length = getSoundLength(sound);
if (length != Sound::RewindableAudioStream::kInvalidLength)
buffers.resize((length / (SoundBuffer::kBufferSize / channels)) + 1);
uint32 samples = 0;
std::deque<SoundBuffer>::iterator buffer = buffers.begin();
while (!sound->endOfStream()) {
if (buffer == buffers.end()) {
buffers.push_back(SoundBuffer());
buffer = --buffers.end();
}
buffer->samples = sound->readBuffer(buffer->buffer, SoundBuffer::kBufferSize);
if (buffer->samples > 0)
samples += buffer->samples;
++buffer;
}
samples /= channels;
const uint32 dataSize = samples * channels * 2;
const uint32 byteRate = rate * channels * 2;
const uint16 blockAlign = channels * 2;
wav.writeUint32BE(MKTAG('R', 'I', 'F', 'F'));
wav.writeUint32LE(36 + dataSize);
wav.writeUint32BE(MKTAG('W', 'A', 'V', 'E'));
wav.writeUint32BE(MKTAG('f', 'm', 't', ' '));
wav.writeUint32LE(16);
wav.writeUint16LE(1);
wav.writeUint16LE(channels);
wav.writeUint32LE(rate);
wav.writeUint32LE(byteRate);
wav.writeUint16LE(blockAlign);
wav.writeUint16LE(16);
wav.writeUint32BE(MKTAG('d', 'a', 't', 'a'));
wav.writeUint32LE(dataSize);
for (std::deque<SoundBuffer>::const_iterator b = buffers.begin(); b != buffers.end(); ++b)
for (int i = 0; i < b->samples; i++)
wav.writeUint16LE(b->buffer[i]);
}
示例10:
static void decompress00(Common::SeekableReadStream &small, Common::WriteStream &out, uint32 size) {
out.writeStream(small, size);
}
示例11: writeIndent
void Decompiler::writeIndent(Common::WriteStream &out, size_t indent) {
for (size_t i = 0; i < indent; ++i)
out.writeString("\t");
}
示例12: writeInstruction
void Decompiler::writeInstruction(Common::WriteStream &out, const Instruction* instruction, size_t indent) {
switch (instruction->opcode) {
case kOpcodeCONST: {
const Variable *v = instruction->variables[0];
writeIndent(out, indent);
out.writeString(getVariableTypeName(v->type) + " " + formatVariableName(v) + " = " + formatInstructionData(*instruction) + ";\n");
break;
}
case kOpcodeACTION: {
unsigned int paramCount = instruction->args[1];
writeIndent(out, indent);
if (instruction->variables.size() > paramCount) {
const Variable *ret = instruction->variables.back();
out.writeString(getVariableTypeName(ret->type, _ncs->getGame()) + " " + formatVariableName(ret) + " = ");
}
out.writeString(getFunctionName(_ncs->getGame(), instruction->args[0]));
out.writeString("(");
for (unsigned int i = 0; i < paramCount; ++i) {
out.writeString(formatVariableName(instruction->variables[i]));
if (i < paramCount - 1)
out.writeString(", ");
}
out.writeString(");\n");
break;
}
case kOpcodeCPDOWNBP:
case kOpcodeCPDOWNSP:
case kOpcodeCPTOPBP:
case kOpcodeCPTOPSP: {
const Variable *v1 = instruction->variables[0];
const Variable *v2 = instruction->variables[1];
writeIndent(out, indent);
out.writeString(getVariableTypeName(v2->type, _ncs->getGame()) + " " + formatVariableName(v2) + " = " + formatVariableName(v1) + ";\n");
break;
}
case kOpcodeLOGAND: {
const Variable *v1 = instruction->variables[0];
const Variable *v2 = instruction->variables[1];
const Variable *result = instruction->variables[2];
writeIndent(out, indent);
out.writeString(
getVariableTypeName(result->type, _ncs->getGame()) + " " +
formatVariableName(result) + " = " +
formatVariableName(v1) + " && " + formatVariableName(v2) + ";\n"
);
break;
}
case kOpcodeLOGOR: {
const Variable *v1 = instruction->variables[0];
const Variable *v2 = instruction->variables[1];
const Variable *result = instruction->variables[2];
writeIndent(out, indent);
out.writeString(
getVariableTypeName(result->type, _ncs->getGame()) + " " +
formatVariableName(result) + " = " +
formatVariableName(v1) + " || " + formatVariableName(v2) + ";\n"
);
break;
}
case kOpcodeEQ: {
const Variable *v1 = instruction->variables[0];
const Variable *v2 = instruction->variables[1];
const Variable *result = instruction->variables[2];
writeIndent(out, indent);
out.writeString(
getVariableTypeName(result->type, _ncs->getGame()) + " " +
formatVariableName(result) + " = " +
formatVariableName(v1) + " == " + formatVariableName(v2) + ";\n"
);
break;
}
case kOpcodeLEQ: {
const Variable *v1 = instruction->variables[0];
const Variable *v2 = instruction->variables[1];
const Variable *result = instruction->variables[2];
writeIndent(out, indent);
out.writeString(
getVariableTypeName(result->type, _ncs->getGame()) + " " +
formatVariableName(result) + " = " +
//.........这里部分代码省略.........
示例13: disNCS
void disNCS(const Common::UString &inFile, const Common::UString &outFile,
Aurora::GameID &game, Command &command, bool printStack, bool printControlTypes) {
Common::SeekableReadStream *ncs = new Common::ReadFile(inFile);
Common::WriteStream *out = 0;
try {
if (!outFile.empty())
out = new Common::WriteFile(outFile);
else
out = new Common::StdOutStream;
status("Disassembling script...");
NWScript::Disassembler disassembler(*ncs, game);
if (game != Aurora::kGameIDUnknown) {
try {
status("Analyzing script stack...");
disassembler.analyzeStack();
} catch (...) {
Common::exceptionDispatcherWarnAndIgnore("Script analysis failed");
}
try {
status("Analyzing control flow...");
disassembler.analyzeControlFlow();
} catch (...) {
Common::exceptionDispatcherWarnAndIgnore("Control flow analysis failed");
}
}
switch (command) {
case kCommandListing:
disassembler.createListing(*out, printStack);
break;
case kCommandAssembly:
disassembler.createAssembly(*out, printStack);
break;
case kCommandDot:
disassembler.createDot(*out, printControlTypes);
break;
default:
throw Common::Exception("Invalid command %u", (uint)command);
}
} catch (...) {
delete ncs;
delete out;
throw;
}
out->flush();
if (!outFile.empty())
status("Disassembled \"%s\" into \"%s\"", inFile.c_str(), outFile.c_str());
delete ncs;
delete out;
}
示例14: writeState
void GameState::writeState(uint32 sceneId, uint32 threadId) {
Common::WriteStream *writeStream = newWriteStream();
writeStream->writeUint32LE(sceneId);
writeStream->writeUint32LE(threadId);
writeStateInternal(writeStream);
}
示例15:
int ObjectV2::save(Common::WriteStream &dest) {
dest.write(_objData, _objSize);
return 0;
}