本文整理汇总了C++中FS_FreeFile函数的典型用法代码示例。如果您正苦于以下问题:C++ FS_FreeFile函数的具体用法?C++ FS_FreeFile怎么用?C++ FS_FreeFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了FS_FreeFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: S_LoadSound
/*
==============
S_LoadSound
The filename may be different than sfx->name in the case
of a forced fallback of a player specific sound
==============
*/
bool S_LoadSound( sfx_t *sfx )
{
byte *data;
short *samples;
wavinfo_t info;
int size;
// player specific sounds are never directly loaded
if ( sfx->soundName[0] == '*')
return false;
// load it in
size = FS_ReadFile( sfx->soundName, (void **)&data );
if ( !data )
return false;
info = GetWavinfo( sfx->soundName, data, size );
if ( info.channels != 1 )
{
Com_Printf ("%s is a stereo wav file\n", sfx->soundName);
FS_FreeFile (data);
return false;
}
if ( info.width == 1 )
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is a 8 bit wav file\n", sfx->soundName);
if ( info.rate != 22050 )
Com_DPrintf(S_COLOR_YELLOW "WARNING: %s is not a 22kHz wav file\n", sfx->soundName);
samples = reinterpret_cast<short*>(Hunk_AllocateTempMemory(info.samples * sizeof(short) * 2));
sfx->lastTimeUsed = Com_Milliseconds()+1;
// each of these compression schemes works just fine
// but the 16bit quality is much nicer and with a local
// install assured we can rely upon the sound memory
// manager to do the right thing for us and page
// sound in as needed
if( sfx->soundCompressed == true)
{
sfx->soundCompressionMethod = 1;
sfx->soundData = NULL;
sfx->soundLength = ResampleSfxRaw( samples, info.rate, info.width, info.samples, (data + info.dataofs) );
S_AdpcmEncodeSound(sfx, samples);
}
else
{
sfx->soundCompressionMethod = 0;
sfx->soundLength = info.samples;
sfx->soundData = NULL;
ResampleSfx( sfx, info.rate, info.width, data + info.dataofs, false );
}
Hunk_FreeTempMemory(samples);
FS_FreeFile( data );
return true;
}
示例2: PHandler_OpenTempFile
const char* PHandler_OpenTempFile(char* name, char* fullfilepath, int fplen){ // Load a plugin, safe for use
void *buf;
int len;
int wlen;
char* file;
char tmpfile[MAX_QPATH];
char filepath[MAX_QPATH];
Com_sprintf(filepath, sizeof(filepath),"plugins/%s" DLL_EXT, name);
len = FS_ReadFile(filepath, &buf);
if(len < 100)
len = FS_SV_ReadFile( filepath, &buf );
if(len < 100)
{
Com_Printf("No such file found: %s. Can not load this plugin.\n", filepath);
return NULL;
}
if(PHandler_VerifyPlugin(buf, len) == qfalse)
{
Com_Printf("%s is not a plugin file or is corrupt or contains disallowed functions.\n", filepath);
FS_FreeFile(buf);
return NULL;
}
Com_sprintf(tmpfile, sizeof(tmpfile), "plugin.%s.tmp", name);
/* If there is already such a file remove it now */
file = FS_SV_GetFilepath( tmpfile, fullfilepath, fplen );
if(file)
{
FS_RemoveOSPath(file);
file = FS_SV_GetFilepath( tmpfile, fullfilepath, fplen );
if(file)
{
FS_RemoveOSPath(file);
}
}
wlen = FS_SV_HomeWriteFile( tmpfile, buf, len);
if(wlen != len)
{
Com_PrintError("fs_homepath is readonly. Can not load this plugin.\n");
FS_FreeFile(buf);
return NULL;
}
//Additional test if a file is there and creation of full filepath
FS_FreeFile(buf);
return FS_SV_GetFilepath( tmpfile, fullfilepath, fplen );
}
示例3: AS_ParseSets
void AS_ParseSets( void ) {
union {
char *c;
void *v;
} as_file;
char *text_p, *token;
FS_ReadFile( SOUNDSET_FILE, &as_file.v );
if ( !as_file.c ) {
Com_Printf( S_COLOR_RED "ERROR: Couldn't load ambient sound sets from \"%s\"\n", SOUNDSET_FILE );
return;
}
text_p = as_file.c;
do {
token = AS_Parse( &text_p );
if ( !token || !token[0] ) {
break;
}
if ( !strcmp( "type", token ) ) {
token = AS_Parse( &text_p );
if( Q_stricmp( token, "ambientset" ) ) {
Com_Printf( S_COLOR_RED "AS_ParseHeader: Set type \"%s\" is not a valid set type!\n", token );
FS_FreeFile( as_file.v );
return;
}
continue;
}
if ( !strcmp( "amsdir", token ) ) {
//token = AS_Parse( &text_p );
AS_SkipRestOfLine( &text_p );
continue;
}
if ( !strcmp( "outdir", token ) ) {
//token = AS_Parse( &text_p );
AS_SkipRestOfLine( &text_p );
continue;
}
if ( !strcmp( "basedir", token ) ) {
//token = AS_Parse( &text_p );
AS_SkipRestOfLine( &text_p );
continue;
}
//generalSet localSet bmodelSet
} while ( token );
FS_FreeFile( as_file.v );
}
示例4: OGG_Check
/*
* Check if the file is a valid Ogg Vorbis file.
*/
qboolean
OGG_Check(char *name)
{
qboolean res; /* Return value. */
byte *buffer; /* File buffer. */
int size; /* File size. */
OggVorbis_File ovf; /* Ogg Vorbis file. */
if (ogg_check->value == 0)
{
return true;
}
res = false;
if ((size = FS_LoadFile(name, (void **)&buffer)) > 0)
{
if (ov_test(NULL, &ovf, (char *)buffer, size) == 0)
{
res = true;
ov_clear(&ovf);
}
FS_FreeFile(buffer);
}
return res;
}
示例5: qboolean
////---------------------
/// FFConfigParser::Parse
//-------------------------
//
//
// Parameters:
//
// Returns:
//
qboolean FFConfigParser::Parse( void *file )
{
qboolean result = qboolean( file != NULL );
if ( file )
{
const char *token = 0, *pos = (const char*)file;
for
( token = COM_ParseExt( &pos, qtrue )
; token[ 0 ]
&& result // fail if any problem
; token = COM_ParseExt( &pos, qtrue )
){
if ( !stricmp( token, "ffdefaults" ) )
{
result &= ParseDefaults( &pos );
}
else
if ( !stricmp( token, "ffsets" ) )
{
result &= ParseSets( &pos );
}
else
{
// unexpected field
result = qfalse;
}
}
FS_FreeFile( file );
}
return result;
}
示例6: Cmd_Exec_f
/*
===============
Cmd_Exec_f
===============
*/
void Cmd_Exec_f( void ) {
char *f;
int len;
char filename[MAX_QPATH];
if (Cmd_Argc () != 2) {
Com_Printf ("exec <filename> : execute a script file\n");
return;
}
Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) );
COM_DefaultExtension( filename, sizeof( filename ), ".cfg" );
len = FS_ReadFile( filename, (void **)&f);
if (!f) {
Com_Printf ("couldn't exec %s\n",Cmd_Argv(1));
return;
}
#ifndef FINAL_BUILD
Com_Printf ("execing %s\n",Cmd_Argv(1));
#endif
Cbuf_InsertText (f);
FS_FreeFile (f);
}
示例7: Cmd_Exec_f
/*
===============
Cmd_Exec_f
===============
*/
void Cmd_Exec_f (void)
{
char *f, *f2;
int len;
if (Cmd_Argc () != 2)
{
Com_Printf ("exec <filename> : execute a script file\n");
return;
}
len = FS_LoadFile (Cmd_Argv(1), (void **)&f);
if (!f)
{
Com_Printf ("couldn't exec %s\n",Cmd_Argv(1));
return;
}
Com_Printf ("execing %s\n",Cmd_Argv(1));
// the file doesn't have a trailing 0, so we need to copy it off
f2 = (char *) Z_Malloc(len+1);
memcpy (f2, f, len);
f2[len] = 0;
Cbuf_InsertText (f2);
Z_Free (f2);
FS_FreeFile (f);
}
示例8: OGG_Stop
/*
* Stop playing the current file.
*/
void
OGG_Stop(void)
{
if (ogg_status == STOP)
{
return;
}
#ifdef USE_OPENAL
if (sound_started == SS_OAL)
{
AL_UnqueueRawSamples();
}
#endif
ov_clear(&ovFile);
ogg_status = STOP;
ogg_info = NULL;
ogg_numbufs = 0;
if (ogg_buffer != NULL)
{
FS_FreeFile(ogg_buffer);
ogg_buffer = NULL;
}
}
示例9: Cmd_Exec_f
/*
===============
Cmd_Exec_f
===============
*/
void Cmd_Exec_f( void ) {
union {
char *c;
void *v;
} f;
int len;
char filename[MAX_QPATH];
if (Cmd_Argc () != 2) {
Com_Printf ("exec <filename> : execute a script file\n");
return;
}
Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) );
COM_DefaultExtension( filename, sizeof( filename ), ".cfg" );
len = FS_ReadFile( filename, &f.v);
if (!f.c) {
Com_Printf ("couldn't exec %s\n",Cmd_Argv(1));
return;
}
Com_Printf ("execing %s\n",Cmd_Argv(1));
Cbuf_InsertText (f.c);
FS_FreeFile (f.v);
}
示例10: DoFileFindReplace
static qboolean DoFileFindReplace( LPCSTR psMenuFile, LPCSTR psFind, LPCSTR psReplace )
{
char *buffer;
OutputDebugString(va("Loading: \"%s\"\n",psMenuFile));
int iLen = FS_ReadFile( psMenuFile,(void **) &buffer);
if (iLen<1)
{
OutputDebugString("Failed!\n");
assert(0);
return qfalse;
}
// find/rep...
//
string str(buffer);
str += "\r\n"; // safety for *(char+1) stuff
FS_FreeFile( buffer ); // let go of the buffer
// originally this kept looping for replacements, but now it only does one (since the find/replace args are repeated
// and this is called again if there are >1 replacements of the same strings to be made...
//
// int iReplacedCount = 0;
char *pFound;
int iSearchPos = 0;
while ( (pFound = strstr(str.c_str()+iSearchPos,psFind)) != NULL)
{
// special check, the next char must be whitespace or carriage return etc, or we're not on a whole-word position...
//
int iFoundLoc = pFound - str.c_str();
char cAfterFind = pFound[strlen(psFind)];
if (cAfterFind > 32)
{
// ... then this string was part of a larger one, so ignore it...
//
iSearchPos = iFoundLoc+1;
continue;
}
str.replace(iFoundLoc, strlen(psFind), psReplace);
// iSearchPos = iFoundLoc+1;
// iReplacedCount++;
break;
}
// assert(iReplacedCount);
// if (iReplacedCount>1)
// {
// int z=1;
// }
FS_WriteFile( psMenuFile, str.c_str(), strlen(str.c_str()));
OutputDebugString("Ok\n");
return qtrue;
}
示例11: CM_LoadQ2BrushModel
/*
* CM_LoadQ2BrushModel
*/
void CM_LoadQ2BrushModel( cmodel_state_t *cms, void *parent, void *buf, bspFormatDesc_t *format ) {
int i;
q2dheader_t header;
cms->cmap_bspFormat = format;
header = *( q2dheader_t * )buf;
for( i = 0; i < sizeof( header ) / 4; i++ )
( (int *)&header )[i] = LittleLong( ( (int *)&header )[i] );
cms->cmod_base = ( uint8_t * )buf;
// load into heap
CMod_LoadTexinfo( cms, &header.lumps[Q2_LUMP_TEXINFO] );
CMod_LoadPlanes( cms, &header.lumps[Q2_LUMP_PLANES] );
CMod_LoadBrushSides( cms, &header.lumps[Q2_LUMP_BRUSHSIDES] );
CMod_LoadBrushes( cms, &header.lumps[Q2_LUMP_BRUSHES] );
CMod_LoadMarkBrushes( cms, &header.lumps[Q2_LUMP_LEAFBRUSHES] );
CMod_LoadLeafs( cms, &header.lumps[Q2_LUMP_LEAFS] );
CMod_LoadNodes( cms, &header.lumps[Q2_LUMP_NODES] );
CMod_LoadSubmodels( cms, &header.lumps[Q2_LUMP_MODELS] );
CMod_LoadVisibility( cms, &header.lumps[Q2_LUMP_VISIBILITY] );
CMod_LoadEntityString( cms, &header.lumps[Q2_LUMP_ENTITIES] );
FS_FreeFile( buf );
}
示例12: Java_xreal_Engine_readFile
/*
* Class: xreal_Engine
* Method: readFile
* Signature: (Ljava/lang/String;)[B
*/
jbyteArray JNICALL Java_xreal_Engine_readFile(JNIEnv *env, jclass cls, jstring jfileName)
{
char *fileName;
jbyteArray array;
int length;
byte *buf;
fileName = (char *)((*env)->GetStringUTFChars(env, jfileName, 0));
length = FS_ReadFile(fileName, (void **)&buf);
if(!buf)
{
return NULL;
}
//Com_Printf("Java_xreal_Engine_readFile: file '%s' has length = %i\n", filename, length);
array = (*env)->NewByteArray(env, length);
(*env)->SetByteArrayRegion(env, array, 0, length, buf);
(*env)->ReleaseStringUTFChars(env, jfileName, fileName);
FS_FreeFile(buf);
return array;
}
示例13: SV_MOTD_LoadFromFile
/*
* SV_MOTD_LoadFromFile
*
* Attempts to load the MOTD from sv_MOTDFile, on success sets
* sv_MOTDString.
*/
void SV_MOTD_LoadFromFile( void )
{
char *f;
FS_LoadFile( sv_MOTDFile->string, (void **)&f, NULL, 0 );
if( !f )
{
Com_Printf( "Couldn't load MOTD file: %s\n", sv_MOTDFile->string );
Cvar_ForceSet( "sv_MOTDFile", "" );
SV_MOTD_SetMOTD( "" );
return;
}
if( strchr( f, '"' ) ) // FIXME: others?
{
Com_Printf( "Warning: MOTD file contains illegal characters.\n" );
Cvar_ForceSet( "sv_MOTDFile", "" );
SV_MOTD_SetMOTD( "" );
}
else
{
SV_MOTD_SetMOTD( f );
}
FS_FreeFile( f );
}
示例14: FS_LoadFile
/*
================
R_LoadWal
================
*/
image_t *R_LoadWal(char *name)
{
miptex_t *mt;
int ofs;
image_t *image;
int size;
FS_LoadFile(name, (void **) &mt);
if (!mt) {
R_Printf(PRINT_ALL, "R_LoadWal: can't load %s\n", name);
return r_notexture_mip;
}
image = R_FindFreeImage();
strcpy(image->name, name);
image->width = LittleLong(mt->width);
image->height = LittleLong(mt->height);
image->type = it_wall;
image->registration_sequence = registration_sequence;
size = image->width * image->height * (256 + 64 + 16 + 4) / 256;
image->pixels[0] = malloc(size);
image->pixels[1] = image->pixels[0] + image->width * image->height;
image->pixels[2] = image->pixels[1] + image->width * image->height / 4;
image->pixels[3] = image->pixels[2] + image->width * image->height / 16;
ofs = LittleLong(mt->offsets[0]);
memcpy(image->pixels[0], (byte *) mt + ofs, size);
FS_FreeFile((void *) mt);
return image;
}
示例15: Cmd_Exec_f
static void Cmd_Exec_f (void)
{
byte *f;
char *f2;
int len;
if (Cmd_Argc() != 2) {
Com_Printf("Usage: %s <filename> : execute a script file\n", Cmd_Argv(0));
return;
}
len = FS_LoadFile(Cmd_Argv(1), &f);
if (!f) {
Com_Printf("couldn't execute %s\n", Cmd_Argv(1));
return;
}
Com_Printf("executing %s\n", Cmd_Argv(1));
/* the file doesn't have a trailing 0, so we need to copy it off */
f2 = (char *)Mem_Alloc(len + 2);
memcpy(f2, f, len);
/* make really sure that there is a newline */
f2[len] = '\n';
f2[len + 1] = 0;
Cbuf_InsertText(f2);
Mem_Free(f2);
FS_FreeFile(f);
}