本文整理汇总了C++中OpenedFile::Read方法的典型用法代码示例。如果您正苦于以下问题:C++ OpenedFile::Read方法的具体用法?C++ OpenedFile::Read怎么用?C++ OpenedFile::Read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenedFile
的用法示例。
在下文中一共展示了OpenedFile::Read方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFaceData
// For reading the face-data chunk
static bool ReadFaceData(OpenedFile& OFile, int32 ParentChunkEnd)
{
uint8 NFBuffer[2];
uint16 NumFaces;
if (!OFile.Read(2,NFBuffer))
{
logError1("ERROR reading number of faces in %s",Path);
return false;
}
uint8 *S = NFBuffer;
StreamToValue(S,NumFaces);
int32 DataSize = 4*sizeof(uint16)*int(NumFaces);
SetChunkBufferSize(DataSize);
if (!OFile.Read(DataSize,ChunkBufferBase()))
{
logError1("ERROR reading face-chunk contents in %s",Path);
return false;
}
S = ChunkBufferBase();
ModelPtr->VertIndices.resize(3*NumFaces);
for (int k=0; k<NumFaces; k++)
{
uint16 *CurrPoly = ModelPtr->VIBase() + 3*k;
uint16 Flags;
StreamToList(S,CurrPoly,3);
StreamToValue(S,Flags);
}
int32 Location = 0;
OFile.GetPosition(Location);
while(Location < ParentChunkEnd)
{
ChunkHeaderData ChunkHeader;
if (!ReadChunkHeader(OFile,ChunkHeader)) return false;
switch(ChunkHeader.ID)
{
/*
case OBJECT:
if (!ReadContainer(OFile,ChunkHeader,ReadObject)) return false;
break;
*/
default:
if (!SkipChunk(OFile,ChunkHeader)) return false;
}
// Where are we now?
OFile.GetPosition(Location);
}
if (Location > ParentChunkEnd)
{
logError3("ERROR: Overran parent chunk: %d > %d in %s",Location,ParentChunkEnd,Path);
return false;
}
return true;
}
示例2: header_stream
static void import_m1_physics_data()
{
OpenedFile PhysicsFile;
if (!PhysicsFileSpec.Open(PhysicsFile))
{
return;
}
int32 position = 0;
int32 length;
PhysicsFile.GetLength(length);
while (position < length)
{
std::vector<uint8> header(12);
PhysicsFile.Read(header.size(), &header[0]);
AIStreamBE header_stream(&header[0], header.size());
uint32 tag;
uint16 count;
uint16 size;
header_stream >> tag;
header_stream.ignore(4); // unused
header_stream >> count;
header_stream >> size;
std::vector<uint8> data(count * size);
PhysicsFile.Read(data.size(), &data[0]);
switch (tag)
{
case M1_MONSTER_PHYSICS_TAG:
unpack_m1_monster_definition(&data[0], count);
break;
case M1_EFFECTS_PHYSICS_TAG:
unpack_m1_effect_definition(&data[0], count);
break;
case M1_PROJECTILE_PHYSICS_TAG:
unpack_m1_projectile_definition(&data[0], count);
break;
case M1_PHYSICS_PHYSICS_TAG:
unpack_m1_physics_constants(&data[0], count);
break;
case M1_WEAPONS_PHYSICS_TAG:
unpack_m1_weapon_definition(&data[0], count);
break;
}
PhysicsFile.GetPosition(position);
}
}
示例3: rewind_recording
void rewind_recording(
void)
{
if(replay.game_is_being_recorded)
{
/* This is unnecessary, because it is called from reset_player_queues, */
/* which is always called from revert_game */
/*
FilmFile.SetLength(sizeof(recording_header));
FilmFile.SetPosition(sizeof(recording_header));
*/
// Alternative that does not use "SetLength", but instead creates and re-creates the file.
FilmFile.SetPosition(0);
byte Header[SIZEOF_recording_header];
FilmFile.Read(SIZEOF_recording_header,Header);
FilmFile.Close();
FilmFileSpec.Delete();
FilmFileSpec.Create(_typecode_film);
FilmFileSpec.Open(FilmFile,true);
FilmFile.Write(SIZEOF_recording_header,Header);
// Use the packed length here!!!
replay.header.length= SIZEOF_recording_header;
}
}
示例4: ReadObject
// For reading the object-data chunk
static bool ReadObject(OpenedFile& OFile, int32 ParentChunkEnd)
{
// Read the name
if (DBOut) fprintf(DBOut,"Object Name: ");
while(true)
{
char c;
if (!OFile.Read(1,&c))
{
if (DBOut) fprintf(DBOut,"ERROR in reading name");
return false;
}
if (c == 0)
{
if (DBOut) fprintf(DBOut,"\n");
break;
}
else
{
if (DBOut) fprintf(DBOut,"%c",c);
}
}
int32 Location = 0;
OFile.GetPosition(Location);
while(Location < ParentChunkEnd)
{
ChunkHeaderData ChunkHeader;
if (!ReadChunkHeader(OFile,ChunkHeader)) return false;
switch(ChunkHeader.ID)
{
case TRIMESH:
if (!ReadContainer(OFile,ChunkHeader,ReadTrimesh)) return false;
break;
default:
if (!SkipChunk(OFile,ChunkHeader)) return false;
}
// Where are we now?
OFile.GetPosition(Location);
}
if (Location > ParentChunkEnd)
{
if (DBOut)
fprintf(DBOut,"ERROR: Overran parent chunk: %ld > %ld\n",Location,ParentChunkEnd);
return false;
}
return true;
}
示例5: setup_for_replay_from_file
bool setup_for_replay_from_file(
FileSpecifier& File,
uint32 map_checksum,
bool prompt_to_export)
{
bool successful= false;
(void)(map_checksum);
FilmFileSpec = File;
if (FilmFileSpec.Open(FilmFile))
{
replay.valid= true;
replay.have_read_last_chunk = false;
replay.game_is_being_replayed = true;
assert(!replay.resource_data);
replay.resource_data= NULL;
replay.resource_data_size= 0l;
replay.film_resource_offset= NONE;
byte Header[SIZEOF_recording_header];
FilmFile.Read(SIZEOF_recording_header,Header);
unpack_recording_header(Header,&replay.header,1);
replay.header.game_information.cheat_flags = _allow_crosshair | _allow_tunnel_vision | _allow_behindview | _allow_overlay_map;
/* Set to the mapfile this replay came from.. */
if(use_map_file(replay.header.map_checksum))
{
replay.fsread_buffer= new char[DISK_CACHE_SIZE];
assert(replay.fsread_buffer);
replay.location_in_cache= NULL;
replay.bytes_in_cache= 0;
replay.replay_speed= 1;
#ifdef DEBUG_REPLAY
open_stream_file();
#endif
if (prompt_to_export)
Movie::instance()->PromptForRecording();
successful= true;
} else {
/* Tell them that this map wasn't found. They lose. */
alert_user(infoError, strERRORS, cantFindReplayMap, 0);
replay.valid= false;
replay.game_is_being_replayed= false;
FilmFile.Close();
}
}
return successful;
}
示例6: LoadChunk
bool LoadChunk(OpenedFile& OFile, ChunkHeaderData& ChunkHeader)
{
logTrace2("Loading chunk 0x%04hx size %u",ChunkHeader.ID,ChunkHeader.Size);
int32 DataSize = ChunkHeader.Size - SIZEOF_ChunkHeaderData;
SetChunkBufferSize(DataSize);
if (!OFile.Read(DataSize,ChunkBufferBase()))
{
logError1("ERROR reading chunk contents in %s",Path);
return false;
}
return true;
}
示例7: ReadChunkHeader
bool ReadChunkHeader(OpenedFile& OFile, ChunkHeaderData& ChunkHeader)
{
uint8 Buffer[SIZEOF_ChunkHeaderData];
if (!OFile.Read(SIZEOF_ChunkHeaderData,Buffer))
{
logError1("ERROR reading chunk header in %s",Path);
return false;
}
uint8 *S = Buffer;
StreamToValue(S,ChunkHeader.ID);
StreamToValue(S,ChunkHeader.Size);
return true;
}
示例8: ReadChunkHeader
bool ReadChunkHeader(OpenedFile& OFile, ChunkHeaderData& ChunkHeader)
{
uint8 Buffer[SIZEOF_ChunkHeaderData];
if (!OFile.Read(SIZEOF_ChunkHeaderData,Buffer))
{
if (DBOut) fprintf(DBOut,"ERROR reading chunk header\n");
return false;
}
uint8 *S = Buffer;
StreamToValue(S,ChunkHeader.ID);
StreamToValue(S,ChunkHeader.Size);
return true;
}
示例9: LoadChunk
bool LoadChunk(OpenedFile& OFile, ChunkHeaderData& ChunkHeader)
{
if (DBOut)
fprintf(DBOut,"Loading chunk 0x%04hx size %lu\n",ChunkHeader.ID,ChunkHeader.Size);
int32 DataSize = ChunkHeader.Size - SIZEOF_ChunkHeaderData;
SetChunkBufferSize(DataSize);
if (!OFile.Read(DataSize,ChunkBufferBase()))
{
if (DBOut) fprintf(DBOut,"ERROR reading chunk contents\n");
return false;
}
return true;
}
示例10:
void *get_network_physics_buffer(
int32 *physics_length)
{
if (physics_file_is_m1())
{
bool success = false;
uint8 *data = NULL;
OpenedFile PhysicsFile;
if (PhysicsFileSpec.Open(PhysicsFile) &&
PhysicsFile.GetLength(*physics_length))
{
data = (uint8 *)malloc(*physics_length + 4);
SDL_RWops *ops = SDL_RWFromMem(data, *physics_length + 4);
success = SDL_WriteBE32(ops, uint32(M1_PHYSICS_MAGIC_COOKIE));
if (success)
success = SDL_WriteBE32(ops, uint32(*physics_length));
SDL_RWclose(ops);
if (success)
success = PhysicsFile.Read(*physics_length, &data[8]);
if (!success)
free(data);
}
if (!success)
{
*physics_length = 0;
return NULL;
}
return data;
}
short SavedType, SavedError = get_game_error(&SavedType);
void *data= get_flat_data(PhysicsFileSpec, false, 0);
set_game_error(SavedType, SavedError);
if(data)
{
*physics_length= get_flat_data_length(data);
} else {
*physics_length= 0;
}
return data;
}
示例11: ReadObject
// For reading the object-data chunk
static bool ReadObject(OpenedFile& OFile, int32 ParentChunkEnd)
{
// Read the name
char c;
do
{
if (!OFile.Read(1,&c))
{
logError1("ERROR when reading name in %s",Path);
return false;
}
}
while(c != 0);
int32 Location = 0;
OFile.GetPosition(Location);
while(Location < ParentChunkEnd)
{
ChunkHeaderData ChunkHeader;
if (!ReadChunkHeader(OFile,ChunkHeader)) return false;
switch(ChunkHeader.ID)
{
case TRIMESH:
if (!ReadContainer(OFile,ChunkHeader,ReadTrimesh)) return false;
break;
default:
if (!SkipChunk(OFile,ChunkHeader)) return false;
}
// Where are we now?
OFile.GetPosition(Location);
}
if (Location > ParentChunkEnd)
{
logError3("ERROR: Overran parent chunk: %d > %d in %s",Location,ParentChunkEnd,Path);
return false;
}
return true;
}
示例12: vblFSRead
/* This is gross, (Alain wrote it, not me!) but I don't have time to clean it up */
static bool vblFSRead(
OpenedFile& File,
int32 *count,
void *dest,
bool& HitEOF)
{
int32 fsread_count;
bool status = true;
assert(replay.fsread_buffer);
// LP: way for testing whether hitting end-of-file;
// doing that by testing for whether a read was complete.
HitEOF = false;
if (replay.bytes_in_cache < *count)
{
assert(replay.bytes_in_cache + *count < int(DISK_CACHE_SIZE));
if (replay.bytes_in_cache)
{
memcpy(replay.fsread_buffer, replay.location_in_cache, replay.bytes_in_cache);
}
replay.location_in_cache = replay.fsread_buffer;
fsread_count= DISK_CACHE_SIZE - replay.bytes_in_cache;
int32 PrevPos;
File.GetPosition(PrevPos);
int32 replay_left= replay.header.length - PrevPos;
if(replay_left < fsread_count)
fsread_count= replay_left;
if(fsread_count > 0)
{
assert(fsread_count > 0);
// LP: wrapped the routines with some for finding out the file positions;
// this finds out how much is read indirectly
status = File.Read(fsread_count,replay.fsread_buffer+replay.bytes_in_cache);
int32 CurrPos;
File.GetPosition(CurrPos);
int32 new_fsread_count = CurrPos - PrevPos;
int32 FileLen;
File.GetLength(FileLen);
HitEOF = (new_fsread_count < fsread_count) && (CurrPos == FileLen);
fsread_count = new_fsread_count;
if(status) replay.bytes_in_cache += fsread_count;
}
}
// If we're still low, then we've consumed the disk cache
if(replay.bytes_in_cache < *count)
{
HitEOF = true;
}
// Ignore EOF if we still have cache
if (HitEOF && replay.bytes_in_cache < *count)
{
*count= replay.bytes_in_cache;
}
else
{
status = true;
HitEOF = false;
}
memcpy(dest, replay.location_in_cache, *count);
replay.bytes_in_cache -= *count;
replay.location_in_cache += *count;
return status;
}