本文整理汇总了C++中FileStream::open方法的典型用法代码示例。如果您正苦于以下问题:C++ FileStream::open方法的具体用法?C++ FileStream::open怎么用?C++ FileStream::open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileStream
的用法示例。
在下文中一共展示了FileStream::open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initShader
bool GFXGLShader::initShader( const Torque::Path &file,
bool isVertex,
const Vector<GFXShaderMacro> ¯os )
{
PROFILE_SCOPE(GFXGLShader_CompileShader);
GLuint activeShader = glCreateShader(isVertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
if(isVertex)
mVertexShader = activeShader;
else
mPixelShader = activeShader;
glAttachShader(mProgram, activeShader);
// Ok it's not in the shader gen manager, so ask Torque for it
FileStream stream;
if ( !stream.open( file, Torque::FS::File::Read ) )
{
AssertISV(false, avar("GFXGLShader::initShader - failed to open shader '%s'.", file.getFullPath().c_str()));
if ( smLogErrors )
Con::errorf( "GFXGLShader::initShader - Failed to open shader file '%s'.",
file.getFullPath().c_str() );
return false;
}
if ( !_loadShaderFromStream( activeShader, file, &stream, macros ) )
return false;
GLint compile;
glGetShaderiv(activeShader, GL_COMPILE_STATUS, &compile);
// Dump the info log to the console
U32 logLength = 0;
glGetShaderiv(activeShader, GL_INFO_LOG_LENGTH, (GLint*)&logLength);
GLint compileStatus = GL_TRUE;
if ( logLength )
{
FrameAllocatorMarker fam;
char* log = (char*)fam.alloc(logLength);
glGetShaderInfoLog(activeShader, logLength, NULL, log);
// Always print errors
glGetShaderiv( activeShader, GL_COMPILE_STATUS, &compileStatus );
if ( compileStatus == GL_FALSE )
{
if ( smLogErrors )
{
Con::errorf( "GFXGLShader::initShader - Error compiling shader!" );
Con::errorf( "Program %s: %s", file.getFullPath().c_str(), log );
}
}
else if ( smLogWarnings )
Con::warnf( "Program %s: %s", file.getFullPath().c_str(), log );
}
return compileStatus != GL_FALSE;
}
示例2: _loadCollection
bool PxSingleActorData::_loadCollection( const UTF8 *path, bool isBinary )
{
if ( physicsCollection )
{
NXU::releaseCollection( physicsCollection );
physicsCollection = NULL;
}
FileStream fs;
if ( !fs.open( path, Torque::FS::File::Read ) )
return false;
// Load the data into memory.
U32 size = fs.getStreamSize();
FrameTemp<U8> buff( size );
fs.read( size, buff );
// If the stream didn't read anything, there's a problem.
if ( size <= 0 )
return false;
// Ok... try to load it.
physicsCollection = NXU::loadCollection( path,
isBinary ? NXU::FT_BINARY : NXU::FT_XML,
buff,
size );
return physicsCollection != NULL;
}
示例3: init
void init(StartGameFunc startGame, StopGameFunc stopGame)
{
s_startGame = startGame;
s_stopGame = stopGame;
for (u32 s=0; s<SOUND_COUNT; s++)
{
UI_Sound& sound = s_sounds[s];
sound.filename = c_sounds[s];
FileStream file;
if (file.open(sound.filename, FileStream::MODE_READ))
{
sound.size = file.getSize();
sound.data = malloc(sound.size);
file.read((u8*)sound.data, sound.size);
file.close();
}
else
{
sound.filename = NULL;
}
}
UISystem::setMouseOverSound(&s_sounds[SOUND_MOUSEOVER]);
}
示例4: paof
void paof() {
FileStream stream;
JvmPathChar file[] = {'h', 'e', 'a', 'p', '.', 't', 'x', 't', 0};
stream.open(file);
ObjectHeap::print_all_objects(&stream);
stream.close();
}
示例5: save
bool TerrainFile::save( const char *filename )
{
FileStream stream;
stream.open( filename, Torque::FS::File::Write );
if ( stream.getStatus() != Stream::Ok )
return false;
stream.write( (U8)FILE_VERSION );
stream.write( mSize );
// Write out the height map.
for ( U32 i=0; i < mHeightMap.size(); i++)
stream.write( mHeightMap[i] );
// Write out the layer map.
for ( U32 i=0; i < mLayerMap.size(); i++)
stream.write( mLayerMap[i] );
// Write out the material names.
stream.write( (U32)mMaterials.size() );
for ( U32 i=0; i < mMaterials.size(); i++ )
stream.write( String( mMaterials[i]->getInternalName() ) );
return stream.getStatus() == FileStream::Ok;
}
示例6: exportHeightMap
bool TerrainBlock::exportHeightMap( const UTF8 *filePath, const String &format ) const
{
GBitmap output( mFile->mSize,
mFile->mSize,
false,
GFXFormatR5G6B5 );
// First capture the max height... we'll normalize
// everything to this value.
U16 maxHeight = 0;
Vector<const U16>::iterator iBits = mFile->mHeightMap.begin();
for ( S32 y = 0; y < mFile->mSize; y++ )
{
for ( S32 x = 0; x < mFile->mSize; x++ )
{
if ( *iBits > maxHeight )
maxHeight = *iBits;
++iBits;
}
}
// Now write out the map.
iBits = mFile->mHeightMap.begin();
U16 *oBits = (U16*)output.getWritableBits();
for ( S32 y = 0; y < mFile->mSize; y++ )
{
for ( S32 x = 0; x < mFile->mSize; x++ )
{
// PNG expects big endian.
U16 height = (U16)( ( (F32)(*iBits) / (F32)maxHeight ) * (F32)U16_MAX );
*oBits = convertHostToBEndian( height );
++oBits;
++iBits;
}
}
FileStream stream;
if ( !stream.open( filePath, Torque::FS::File::Write ) )
{
Con::errorf( "TerrainBlock::exportHeightMap() - Error opening file for writing: %s !", filePath );
return false;
}
if ( !output.writeBitmap( format, stream ) )
{
Con::errorf( "TerrainBlock::exportHeightMap() - Error writing %s: %s !", format.c_str(), filePath );
return false;
}
// Print out the map size in meters, so that the user
// knows what values to use when importing it into
// another terrain tool.
S32 dim = mSquareSize * mFile->mSize;
S32 height = fixedToFloat( maxHeight );
Con::printf( "Saved heightmap with dimensions %d x %d x %d.", dim, dim, height );
return true;
}
示例7: init
/// Open the file and emit a row with the names of all enabled keys.
virtual bool init( const char* fileName )
{
if( !mStream.open( fileName, Torque::FS::File::Write ) )
{
Con::errorf( "CSVSamplerBackend::init -- could not open '%s' for writing", fileName );
return false;
}
Con::printf( "CSVSamplerBackend::init -- writing samples to '%s'", fileName );
bool first = true;
for( U32 i = 0; i < gSampleKeys.size(); ++ i )
{
SampleKey& key = gSampleKeys[ i ];
if( key.mEnabled )
{
if( !first )
mStream.write( 1, "," );
mRecords.push_back( SampleRecord( i + 1 ) );
mStream.write( dStrlen( key.mName ), key.mName );
first = false;
}
}
newline();
return true;
}
示例8: logValue
/**
* logValue() Information
*
* This function writes data to the log file.
*/
static void logValue(String label, Uint16 value)
{
// open file
dataFile.open("dataLog.txt");
// determine label length
int size = 0;
String temp = label;
for(temp = label; *temp; ++temp)
{
++size;
}
// write label
dataFile.write((Byte*)label, size); // to suppress compiler warning
// convert value
char dataString[8] = {"0x0000\n"};
static const char toHex[] = {"0123456789ABCDEF"};
dataString[2] = toHex[(value & 0xF000) >> 12];
dataString[3] = toHex[(value & 0x0F00) >> 8];
dataString[4] = toHex[(value & 0x00F0) >> 4];
dataString[5] = toHex[(value & 0x000F)];
// write value
dataFile.write((Byte*)dataString, 7); // to suppress compiler warning
// close file
dataFile.close();
}
示例9: checkSaveGame
void GameInitSettings::checkSaveGame(std::string savegame) {
FileStream fs;
if(fs.open(savegame.c_str(), "rb") == false) {
throw std::runtime_error("Cannot open savegame. Make sure you have read access to this savegame!");
}
Uint32 magicNum;
Uint32 savegameVersion;
std::string duneVersion;
try {
magicNum = fs.readUint32();
savegameVersion = fs.readUint32();
duneVersion = fs.readString();
} catch (std::exception& e) {
throw std::runtime_error("Cannot load this savegame,\n because it seems to be truncated!");
}
if(magicNum != SAVEMAGIC) {
throw std::runtime_error("Cannot load this savegame,\n because it has a wrong magic number!");
}
if(savegameVersion < SAVEGAMEVERSION) {
throw std::runtime_error("Cannot load this savegame,\n because it was created with an older version:\n" + duneVersion);
}
if(savegameVersion > SAVEGAMEVERSION) {
throw std::runtime_error("Cannot load this savegame,\n because it was created with a newer version:\n" + duneVersion);
}
fs.close();
}
示例10: dSprintf
void GFXD3D9Device::logVertexBuffers()
{
// NOTE: This function should be called on the destructor of this class and ONLY then
// otherwise it'll produce the wrong output
if( mNumAllocatedVertexBuffers == 0 )
return;
FileStream fs;
fs.open( "vertexbuffer.log", Torque::FS::File::Write );
char buff[256];
fs.writeLine( (U8 *)avar("-- Vertex buffer memory leak report -- time = %d", Platform::getRealMilliseconds()) );
dSprintf( (char *)&buff, sizeof( buff ), "%d un-freed vertex buffers", mNumAllocatedVertexBuffers );
fs.writeLine( (U8 *)buff );
GFXD3D9VertexBuffer *walk = mVBListHead;
while( walk != NULL )
{
dSprintf( (char *)&buff, sizeof( buff ), "[Name: %s] Size: %d", walk->name, walk->mNumVerts );
fs.writeLine( (U8 *)buff );
walk = walk->next;
}
fs.writeLine( (U8 *)"-- End report --" );
fs.close();
}
示例11: MD5File
bool MD5File(const char* pszFile,unsigned char *pMD5 /* 16 Byte*/)
{
FileStream stream;
if(!stream.open(pszFile,FileStream::Read))
return false;
return MD5Stream(&stream,pMD5);
}
示例12: open
bool open(const char* filename)
{
#if XL_LOGGING_ENABLED
return s_logFile.open(filename, FileStream::MODE_WRITE);
#else
return true;
#endif
}
示例13: saveToFile
bool Strings::saveToFile(const char* fileName) const
{
FileStream fs;
bool result = fs.open(fileName, FM_CREATE);
if (result)
result = saveToStream(fs);
return result;
}
示例14: loadFromFile
bool Strings::loadFromFile(const char* fileName)
{
FileStream fs;
bool result = fs.open(fileName, FM_OPEN_READ | FM_SHARE_DENY_WRITE);
if (result)
result = loadFromStream(fs);
return result;
}
示例15: main
int main() {
Synth &synth = *new Synth();
FileStream controlROMFile;
FileStream pcmROMFile;
bool ok = controlROMFile.open("CM32L_CONTROL.ROM");
if (!ok) fail("Invalid controlROMFile");
ok = pcmROMFile.open("CM32L_PCM.ROM");
if (!ok) fail("Invalid pcmROMFile");
const ROMImage *controlROMImage = ROMImage::makeROMImage(&controlROMFile);
const ROMImage *pcmROMImage = ROMImage::makeROMImage(&pcmROMFile);
ok = synth.open(*controlROMImage, *pcmROMImage, AnalogOutputMode_ACCURATE);
if (!ok) fail("Failed to open synth");
class : public MidiStreamParser {
protected:
// User-supplied method. Invoked when a complete short MIDI message is parsed in the input MIDI stream.
virtual void handleShortMessage(const Bit32u message) {
printf("Got ShortMessage: %06x\n", message);
}
// User-supplied method. Invoked when a complete well-formed System Exclusive MIDI message is parsed in the input MIDI stream.
virtual void handleSysex(const Bit8u stream[], const Bit32u len) {
std::cout << "Got SysEx:\n";
for (unsigned int i = 0; i < len; i++) printf("%02x ", stream[i]);
std::cout << std::endl;
}
// User-supplied method. Invoked when a System Realtime MIDI message is parsed in the input MIDI stream.
virtual void handleSytemRealtimeMessage(const Bit8u realtime) {
printf("Got SytemRealtimeMessage: %02x\n", realtime);
}
// User-supplied method. Invoked when an error occurs during processing the input MIDI stream.
virtual void printDebug(const char *debugMessage) {
std::cout << debugMessage << std::endl;
}
} parser;
Bit32u len = sizeof(stream1);
std::cout << "Sent " << len << " bytes\n";
parser.parseStream(stream1, len);
len = sizeof(stream2);
std::cout << "Sent " << len << " bytes\n";
parser.parseStream(stream2, len);
_getch();
return 0;
}