本文整理汇总了C++中CFileHandler::FileSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CFileHandler::FileSize方法的具体用法?C++ CFileHandler::FileSize怎么用?C++ CFileHandler::FileSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFileHandler
的用法示例。
在下文中一共展示了CFileHandler::FileSize方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetFileSize
int CAICallback::GetFileSize (const char *name)
{
CFileHandler fh (name);
if (!fh.FileExists ())
return -1;
return fh.FileSize();
}
示例2: GetFileSize
int CAICallback::GetFileSize (const char *filename, const char* modes)
{
CFileHandler fh (filename, modes);
if (!fh.FileExists ())
return -1;
return fh.FileSize();
}
示例3: ReadFile
bool CAICallback::ReadFile (const char *name, void *buffer, int bufferLength)
{
CFileHandler fh (name);
int fs;
if (!fh.FileExists() || bufferLength < (fs = fh.FileSize()))
return false;
fh.Read (buffer, fs);
return true;
}
示例4: weapon
CCobFile::CCobFile(CFileHandler &in, string name)
{
char *cobdata = NULL;
this->name = name;
//Figure out size needed and allocate it
int size = in.FileSize();
// Handle errors (this is fairly fatal..)
if (size < 0) {
logOutput.Print("Could not find script for unit %s", name.c_str());
exit(0);
}
cobdata = new char[size];
//Read the entire thing, we will need it
in.Read(cobdata, size);
//Time to parse
COBHeader ch;
READ_COBHEADER(ch,cobdata);
for (int i = 0; i < ch.NumberOfScripts; ++i) {
int ofs;
ofs = *(int *)&cobdata[ch.OffsetToScriptNameOffsetArray + i * 4];
ofs = swabdword(ofs);
string s = &cobdata[ofs];
scriptNames.push_back(s);
ofs = *(int *)&cobdata[ch.OffsetToScriptCodeIndexArray + i * 4];
ofs = swabdword(ofs);
scriptOffsets.push_back(ofs);
}
//Check for zero-length scripts
for (int i = 0; i < ch.NumberOfScripts - 1; ++i) {
scriptLengths.push_back(scriptOffsets[i + 1] - scriptOffsets[i]);
}
scriptLengths.push_back(ch.TotalScriptLen - scriptOffsets[ch.NumberOfScripts - 1]);
for (int i = 0; i < ch.NumberOfPieces; ++i) {
int ofs;
ofs = *(int *)&cobdata[ch.OffsetToPieceNameOffsetArray + i * 4];
ofs = swabdword(ofs);
string s = StringToLower(&cobdata[ofs]);
pieceNames.push_back(s);
}
int code_octets = size - ch.OffsetToScriptCode;
int code_ints = (code_octets) / 4 + 4;
code = new int[code_ints];
memcpy(code, &cobdata[ch.OffsetToScriptCode], code_octets);
for (int i = 0; i < code_ints; i++) {
code[i] = swabdword(code[i]);
}
numStaticVars = ch.NumberOfStaticVars;
// If this is a TA:K script, read the sound names
if (ch.VersionSignature == 6) {
for (int i = 0; i < ch.NumberOfSounds; ++i) {
int ofs;
ofs = *(int *)&cobdata[ch.OffsetToSoundNameArray + i * 4];
/* TODO This probably isn't correct. */
ofs = swabdword(ofs);
string s = &cobdata[ofs];
// Load the wave file and store the ID for future use
s = "sounds/" + s + ".wav";
sounds.push_back(sound->GetWaveId(s));
}
}
delete[] cobdata;
//Create a reverse mapping (name->int)
for (unsigned int i = 0; i < scriptNames.size(); ++i) {
scriptMap[scriptNames[i]] = i;
}
//Map common function names to indicies
scriptIndex.resize(COBFN_Last + COB_MaxWeapons * 5);
scriptIndex[COBFN_Create] = getFunctionId("Create");
scriptIndex[COBFN_StartMoving] = getFunctionId("StartMoving");
scriptIndex[COBFN_StopMoving] = getFunctionId("StopMoving");
scriptIndex[COBFN_Activate] = getFunctionId("Activate");
scriptIndex[COBFN_Killed] = getFunctionId("Killed");
scriptIndex[COBFN_Deactivate] = getFunctionId("Deactivate");
scriptIndex[COBFN_SetDirection] = getFunctionId("SetDirection");
scriptIndex[COBFN_SetSpeed] = getFunctionId("SetSpeed");
scriptIndex[COBFN_RockUnit] = getFunctionId("RockUnit");
scriptIndex[COBFN_HitByWeapon] = getFunctionId("HitByWeapon");
scriptIndex[COBFN_MoveRate0] = getFunctionId("MoveRate0");
scriptIndex[COBFN_MoveRate1] = getFunctionId("MoveRate1");
scriptIndex[COBFN_MoveRate2] = getFunctionId("MoveRate2");
scriptIndex[COBFN_MoveRate3] = getFunctionId("MoveRate3");
//.........这里部分代码省略.........
示例5: runtime_error
CglFont::CglFont(const std::string& fontfile, int size, int _outlinewidth, float _outlineweight):
fontSize(size),
fontPath(fontfile),
outlineWidth(_outlinewidth),
outlineWeight(_outlineweight),
inBeginEnd(false)
{
if (size<=0)
size = 14;
const float invSize = 1.0f / size;
const float normScale = invSize / 64.0f;
FT_Library library;
FT_Face face;
//! initialize Freetype2 library
FT_Error error = FT_Init_FreeType(&library);
if (error) {
string msg = "FT_Init_FreeType failed:";
msg += GetFTError(error);
throw std::runtime_error(msg);
}
//! load font via VFS
CFileHandler* f = new CFileHandler(fontPath);
if (!f->FileExists()) {
//! check in 'fonts/', too
if (fontPath.substr(0, 6) != "fonts/") {
delete f;
fontPath = "fonts/" + fontPath;
f = new CFileHandler(fontPath);
}
if (!f->FileExists()) {
delete f;
FT_Done_FreeType(library);
throw content_error("Couldn't find font '" + fontfile + "'.");
}
}
int filesize = f->FileSize();
FT_Byte* buf = new FT_Byte[filesize];
f->Read(buf,filesize);
delete f;
//! create face
error = FT_New_Memory_Face(library, buf, filesize, 0, &face);
if (error) {
FT_Done_FreeType(library);
delete[] buf;
string msg = fontfile + ": FT_New_Face failed: ";
msg += GetFTError(error);
throw content_error(msg);
}
//! set render size
error = FT_Set_Pixel_Sizes(face, 0, size);
if (error) {
FT_Done_Face(face);
FT_Done_FreeType(library);
delete[] buf;
string msg = fontfile + ": FT_Set_Pixel_Sizes failed: ";
msg += GetFTError(error);
throw content_error(msg);
}
//! setup character range
charstart = 32;
charend = 254; //! char 255 = colorcode
chars = (charend - charstart) + 1;
//! get font information
fontFamily = face->family_name;
fontStyle = face->style_name;
//! font's descender & height (in pixels)
fontDescender = normScale * FT_MulFix(face->descender, face->size->metrics.y_scale);
//lineHeight = invSize * (FT_MulFix(face->height, face->size->metrics.y_scale) / 64.0f);
//lineHeight = invSize * math::ceil(FT_MulFix(face->height, face->size->metrics.y_scale) / 64.0f);
lineHeight = face->height / face->units_per_EM;
//lineHeight = invSize * face->size->metrics.height / 64.0f;
if (lineHeight<=0.0f) {
lineHeight = 1.25 * invSize * (face->bbox.yMax - face->bbox.yMin);
}
//! used to create the glyph textureatlas
CFontTextureRenderer texRenderer(outlineWidth, outlineWeight);
for (unsigned int i = charstart; i <= charend; i++) {
GlyphInfo* g = &glyphs[i];
//! translate WinLatin (codepage-1252) to Unicode (used by freetype)
int unicode = WinLatinToUnicode(i);
//! convert to an anti-aliased bitmap
error = FT_Load_Char(face, unicode, FT_LOAD_RENDER);
if ( error ) {
continue;
}
//.........这里部分代码省略.........