本文整理汇总了C++中OpenedFile类的典型用法代码示例。如果您正苦于以下问题:C++ OpenedFile类的具体用法?C++ OpenedFile怎么用?C++ OpenedFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OpenedFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ReadEditor
// For reading the editor-data chunk
static bool ReadEditor(OpenedFile& OFile, int32 ParentChunkEnd)
{
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;
}
示例3: physics_file_is_m1
bool physics_file_is_m1(void)
{
bool m1_physics = false;
// check for M1 physics
OpenedFile PhysicsFile;
short SavedType, SavedError = get_game_error(&SavedType);
if (PhysicsFileSpec.Open(PhysicsFile))
{
uint32 tag = SDL_ReadBE32(PhysicsFile.GetRWops());
switch (tag)
{
case M1_MONSTER_PHYSICS_TAG:
case M1_EFFECTS_PHYSICS_TAG:
case M1_PROJECTILE_PHYSICS_TAG:
case M1_PHYSICS_PHYSICS_TAG:
case M1_WEAPONS_PHYSICS_TAG:
m1_physics = true;
break;
default:
break;
}
PhysicsFile.Close();
}
set_game_error(SavedType, SavedError);
return m1_physics;
}
示例4: ReadMaster
// For reading the master chunk (ideally, whole file)
static bool ReadMaster(OpenedFile& OFile, int32 ParentChunkEnd)
{
int32 Location = 0;
OFile.GetPosition(Location);
while(Location < ParentChunkEnd)
{
ChunkHeaderData ChunkHeader;
if (!ReadChunkHeader(OFile,ChunkHeader)) return false;
switch(ChunkHeader.ID)
{
case EDITOR:
if (!ReadContainer(OFile,ChunkHeader,ReadEditor)) 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: search_key
static TTF_Font *load_ttf_font(const std::string& path, uint16 style, int16 size)
{
// already loaded? increment reference counter and return pointer
ttf_font_key_t search_key(path, style, size);
ttf_font_list_t::iterator it = ttf_font_list.find(search_key);
if (it != ttf_font_list.end())
{
TTF_Font *font = it->second.first;
it->second.second++;
return font;
}
TTF_Font *font = 0;
builtin_fonts_t::iterator j = builtin_fonts.find(path);
if (j != builtin_fonts.end())
{
font = TTF_OpenFontRW(SDL_RWFromConstMem(j->second.data, j->second.size), 0, size);
}
else
{
short SavedType, SavedError = get_game_error(&SavedType);
FileSpecifier fileSpec(path);
OpenedFile file;
if (fileSpec.Open(file))
{
font = TTF_OpenFontRW(file.TakeRWops(), 1, size);
}
set_game_error(SavedType, SavedError);
}
if (font)
{
int ttf_style = TTF_STYLE_NORMAL;
if (style & styleBold)
ttf_style |= TTF_STYLE_BOLD;
if (style & styleItalic)
ttf_style |= TTF_STYLE_ITALIC;
TTF_SetFontStyle(font, ttf_style);
#ifdef TTF_HINTING_LIGHT
if (environment_preferences->smooth_text)
TTF_SetFontHinting(font, TTF_HINTING_LIGHT);
else
TTF_SetFontHinting(font, TTF_HINTING_MONO);
#endif
ttf_font_key_t key(path, style, size);
ref_counted_ttf_font_t value(font, 1);
ttf_font_list[key] = value;
}
return font;
}
示例6: SkipChunk
bool SkipChunk(OpenedFile& OFile, ChunkHeaderData& ChunkHeader)
{
logTrace2("Skipping chunk 0x%04hx size %u",ChunkHeader.ID,ChunkHeader.Size);
int32 DataSize = ChunkHeader.Size - SIZEOF_ChunkHeaderData;
int32 Location = 0;
OFile.GetPosition(Location);
if (!OFile.SetPosition(Location + DataSize)) return false;
return true;
}
示例7: 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;
}
示例8: calculate_crc_for_file
/* -------------- Entry Point ----------- */
uint32 calculate_crc_for_file(FileSpecifier& File)
{
uint32 crc = 0;
OpenedFile OFile;
if (File.Open(OFile))
{
crc= calculate_crc_for_opened_file(OFile);
OFile.Close();
}
return crc;
}
示例9: import_m1_physics_data
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);
}
}
示例10:
SDL_Surface *WadImageCache::image_from_name(std::string& name) const
{
FileSpecifier file;
file.SetToImageCacheDir();
file.AddPart(name);
OpenedFile of;
if (!file.Open(of))
return NULL;
#ifdef HAVE_SDL_IMAGE
SDL_Surface *img = IMG_Load_RW(of.GetRWops(), 0);
#else
SDL_Surface *img = SDL_LoadBMP_RW(of.GetRWops(), 0);
#endif
return img;
}
示例11: ReadTrimesh
// For reading the triangle-mesh-data chunk
static bool ReadTrimesh(OpenedFile& OFile, int32 ParentChunkEnd)
{
int32 Location = 0;
OFile.GetPosition(Location);
assert(ModelPtr);
while(Location < ParentChunkEnd)
{
ChunkHeaderData ChunkHeader;
if (!ReadChunkHeader(OFile,ChunkHeader)) return false;
switch(ChunkHeader.ID)
{
case VERTICES:
if (!LoadChunk(OFile,ChunkHeader)) return false;
LoadVertices();
break;
case TXTR_COORDS:
if (!LoadChunk(OFile,ChunkHeader)) return false;
LoadTextureCoordinates();
break;
case FACE_DATA:
if (!ReadContainer(OFile,ChunkHeader,ReadFaceData)) 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;
}
示例12: 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;
}
示例13:
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;
}
示例14: 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;
}
示例15: 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;
}