当前位置: 首页>>代码示例>>C++>>正文


C++ FS_ReadFile函数代码示例

本文整理汇总了C++中FS_ReadFile函数的典型用法代码示例。如果您正苦于以下问题:C++ FS_ReadFile函数的具体用法?C++ FS_ReadFile怎么用?C++ FS_ReadFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FS_ReadFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SV_LoadGame_f

/*
=================
SV_LoadGame_f
=================
*/
void    SV_LoadGame_f( void ) {
	char filename[MAX_QPATH], mapname[MAX_QPATH];
	byte *buffer;
	int size;

	Q_strncpyz( filename, Cmd_Argv( 1 ), sizeof( filename ) );
	if ( !filename[0] ) {
		Com_Printf( "You must specify a savegame to load\n" );
		return;
	}
	if ( Q_strncmp( filename, "save/", 5 ) && Q_strncmp( filename, "save\\", 5 ) ) {
		Q_strncpyz( filename, va( "save/%s", filename ), sizeof( filename ) );
	}
	if ( !strstr( filename, ".svg" ) ) {
		Q_strcat( filename, sizeof( filename ), ".svg" );
	}

	size = FS_ReadFile( filename, NULL );
	if ( size < 0 ) {
		Com_Printf( "Can't find savegame %s\n", filename );
		return;
	}

	buffer = Hunk_AllocateTempMemory( size );
	FS_ReadFile( filename, (void **)&buffer );

	// read the mapname, if it is the same as the current map, then do a fast load
	Com_sprintf( mapname, sizeof( mapname ), buffer + sizeof( int ) );

	if ( com_sv_running->integer && ( com_frameTime != sv.serverId ) ) {
		// check mapname
		if ( !Q_stricmp( mapname, sv_mapname->string ) ) {    // same

			if ( Q_stricmp( filename, "save/current.svg" ) != 0 ) {
				// copy it to the current savegame file
				FS_WriteFile( "save/current.svg", buffer, size );
			}

			Hunk_FreeTempMemory( buffer );

			Cvar_Set( "savegame_loading", "2" );  // 2 means it's a restart, so stop rendering until we are loaded
			SV_MapRestart_f();  // savegame will be loaded after restart

			return;
		}
	}

	Hunk_FreeTempMemory( buffer );

	// otherwise, do a slow load
	if ( Cvar_VariableIntegerValue( "sv_cheats" ) ) {
		Cbuf_ExecuteText( EXEC_APPEND, va( "spdevmap %s", filename ) );
	} else {    // no cheats
		Cbuf_ExecuteText( EXEC_APPEND, va( "spmap %s", filename ) );
	}
}
开发者ID:chegestar,项目名称:omni-bot,代码行数:61,代码来源:sv_ccmds.c

示例2: SV_ChangeMap

static void SV_ChangeMap( qbool cheats )
{
	const char* map = Cmd_Argv(1);
	if ( !map ) {
		return;
	}

	// make sure the level exists before trying to change
	// so that a typo at the server console won't end the game
	const char* mapfile = va( "maps/%s.bsp", map );
	if ( FS_ReadFile( mapfile, NULL ) == -1 ) {
		Com_Printf( "Can't find map %s\n", mapfile );
		return;
	}

	// force latched values to get set
	Cvar_Get( "g_gametype", "0", CVAR_SERVERINFO | CVAR_LATCH );

	// save the map name here cause on a map restart we reload the q3config.cfg
	// and thus nuke the arguments of the map command
	char mapname[MAX_QPATH];
	Q_strncpyz( mapname, map, sizeof(mapname) );

	// start up the map
	SV_SpawnServer( mapname );

	Cvar_Set( "sv_cheats", cheats ? "1" : "0" );
}
开发者ID:ShaneIsley,项目名称:challengeq3,代码行数:28,代码来源:sv_ccmds.cpp

示例3: Cmd_Exec_f

/*
===============
Cmd_Exec_f
===============
*/
void Cmd_Exec_f( void ) {
	qboolean quiet;
	union {
		char	*c;
		void	*v;
	} f;
	char	filename[MAX_QPATH];

	quiet = !Q_stricmp(Cmd_Argv(0), "execq");

	if (Cmd_Argc () != 2) {
		Com_Printf ("exec%s <filename> : execute a script file%s\n",
		            quiet ? "q" : "", quiet ? " without notification" : "");
		return;
	}

	Q_strncpyz( filename, Cmd_Argv(1), sizeof( filename ) );
	COM_DefaultExtension( filename, sizeof( filename ), ".cfg" );
	FS_ReadFile( filename, &f.v);
	if (!f.c) {
		Com_Printf ("couldn't exec %s\n", filename);
		return;
	}
	if (!quiet)
		Com_Printf ("execing %s\n", filename);
	
	Cbuf_InsertText (f.c);

	FS_FreeFile (f.v);
}
开发者ID:darklegion,项目名称:tremulous,代码行数:35,代码来源:cmd.c

示例4: 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;
}
开发者ID:redrumrobot,项目名称:dretchstorm,代码行数:31,代码来源:vm_java.c

示例5: 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);
}
开发者ID:3ddy,项目名称:Jedi-Academy,代码行数:30,代码来源:cmd_common.cpp

示例6: CLQ2_Download_f

//	Request a download from the server
static void CLQ2_Download_f() {
	if ( Cmd_Argc() != 2 ) {
		common->Printf( "Usage: download <filename>\n" );
		return;
	}

	char filename[ MAX_OSPATH ];
	String::Sprintf( filename, sizeof ( filename ), "%s", Cmd_Argv( 1 ) );

	if ( strstr( filename, ".." ) ) {
		common->Printf( "Refusing to download a path with ..\n" );
		return;
	}

	if ( FS_ReadFile( filename, NULL ) != -1 ) {// it exists, no need to download
		common->Printf( "File already exists.\n" );
		return;
	}

	String::Cpy( clc.downloadName, filename );
	common->Printf( "Downloading %s\n", clc.downloadName );

	// download to a temp name, and only rename
	// to the real name when done, so if interrupted
	// a runt file wont be left
	String::StripExtension( clc.downloadName, clc.downloadTempName );
	String::Cat( clc.downloadTempName, sizeof ( clc.downloadTempName ), ".tmp" );

	CL_AddReliableCommand( va( "download %s", clc.downloadName ) );

	clc.downloadNumber++;
}
开发者ID:janisl,项目名称:jlquake,代码行数:33,代码来源:main.cpp

示例7: SV_Map_

//=========================================================
// don't call this directly, it should only be called from SV_Map_f() or SV_MapTransition_f()
//
static void SV_Map_( ForceReload_e eForceReload ) 
{
	char	*map;
	char	expanded[MAX_QPATH];

	map = Cmd_Argv(1);
	if ( !*map ) {
		return;
	}

	// make sure the level exists before trying to change, so that
	// a typo at the server console won't end the game
	if (strchr (map, '\\') ) {
		Com_Printf ("Can't have mapnames with a \\\n");
		return;
	}
	
	Com_sprintf (expanded, sizeof(expanded), "maps/%s.bsp", map);
	if ( FS_ReadFile (expanded, NULL) == -1 ) {
		Com_Printf ("Can't find map %s\n", expanded);
		return;
	}
	
	if (map[0]!='_')
	{
		SG_WipeSavegame("auto");
	}

	SP_Unload(SP_REGISTER_CLIENT);	//clear the previous map srings

	SV_SpawnServer( map, eForceReload, qtrue );	// start up the map
}
开发者ID:CairnTrenor,项目名称:OpenJK,代码行数:35,代码来源:sv_ccmds.cpp

示例8: 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;
}
开发者ID:MilitaryForces,项目名称:MilitaryForces,代码行数:68,代码来源:snd_mem.c

示例9: S_FileExtension

/*
=================
S_FindCodecForFile

Select an appropriate codec for a file based on its extension
=================
*/
static snd_codec_t *S_FindCodecForFile(const char *filename)
{
	char *ext = S_FileExtension(filename);
	snd_codec_t *codec = codecs;

	if(!ext)
	{
		// No extension - auto-detect
		while(codec)
		{
			char fn[MAX_QPATH];
			Q_strncpyz(fn, filename, sizeof(fn) - 4);
			COM_DefaultExtension(fn, sizeof(fn), codec->ext);

			// Check it exists
			if(FS_ReadFile(fn, NULL) != -1)
				return codec;

			// Nope. Next!
			codec = codec->next;
		}

		// Nothin'
		return NULL;
	}

	while(codec)
	{
		if(!Q_stricmp(ext, codec->ext))
			return codec;
		codec = codec->next;
	}

	return NULL;
}
开发者ID:ballju,项目名称:SpaceTrader-GPL-1.1.14,代码行数:42,代码来源:snd_codec.c

示例10: FS_InitFilesystem

/*
================
FS_InitFilesystem

Called only at inital startup, not when the filesystem
is resetting due to a game change
================
*/
void FS_InitFilesystem( void ) {
	// allow command line parms to override our defaults
	// we don't have to specially handle this, because normal command
	// line variable sets happen before the filesystem
	// has been initialized
	//
	// UPDATE: BTO (VV)
	// we have to specially handle this, because normal command
	// line variable sets don't happen until after the filesystem
	// has already been initialized
	Com_StartupVariable( "fs_cdpath" );
	Com_StartupVariable( "fs_basepath" );
	Com_StartupVariable( "fs_game" );
	Com_StartupVariable( "fs_copyfiles" );
	Com_StartupVariable( "fs_restrict" );

	// try to start up normally
	FS_Startup( BASEGAME );
	initialized = qtrue;

	// see if we are going to allow add-ons
	FS_SetRestrictions();

	// if we can't find default.cfg, assume that the paths are
	// busted and error out now, rather than getting an unreadable
	// graphics screen when the font fails to load
	if ( FS_ReadFile( "default.cfg", NULL ) <= 0 ) {
		Com_Error( ERR_FATAL, "Couldn't load default.cfg" );
	}
}
开发者ID:AlexCSilva,项目名称:jediacademy,代码行数:38,代码来源:files_common.cpp

示例11: FS_InitFilesystem

/*
================
FS_InitFilesystem

Called only at inital startup, not when the filesystem
is resetting due to a game change
================
*/
void FS_InitFilesystem( void ) {
	// allow command line parms to override our defaults
	// we have to specially handle this, because normal command
	// line variable sets don't happen until after the filesystem
	// has already been initialized
	Com_StartupVariable( "fs_cdpath" );
	Com_StartupVariable( "fs_basepath" );
	Com_StartupVariable( "fs_homepath" );
	Com_StartupVariable( "fs_game" );
	Com_StartupVariable( "fs_copyfiles" );
	Com_StartupVariable( "fs_dirbeforepak" );

	if(!FS_FilenameCompare(Cvar_VariableString("fs_game"), BASEGAME))
		Cvar_Set("fs_game", "");

	// try to start up normally
	FS_Startup( BASEGAME );
	initialized = qtrue;

	// if we can't find default.cfg, assume that the paths are
	// busted and error out now, rather than getting an unreadable
	// graphics screen when the font fails to load
	if ( FS_ReadFile( "mpdefault.cfg", NULL ) <= 0 ) {
		Com_Error( ERR_FATAL, "Couldn't load mpdefault.cfg" );
		// bk001208 - SafeMode see below, FIXME?
	}

	Q_strncpyz(lastValidBase, fs_basepath->string, sizeof(lastValidBase));
	Q_strncpyz(lastValidGame, fs_gamedirvar->string, sizeof(lastValidGame));

  // bk001208 - SafeMode see below, FIXME?
}
开发者ID:CaptainSkyhawk,项目名称:OpenJK-VR,代码行数:40,代码来源:files_common.cpp

示例12: 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);
}
开发者ID:norfenstein,项目名称:umbra,代码行数:31,代码来源:cmd.c

示例13: 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;
}
开发者ID:Agustinlv,项目名称:BlueHarvest,代码行数:60,代码来源:ui_debug.cpp

示例14: SV_Map_f

/**
 * @brief Restart the server on a different map
 */
static void SV_Map_f(void)
{
	char     *cmd;
	char     *map;
	char     mapname[MAX_QPATH];
	qboolean cheat;
	char     expanded[MAX_QPATH];

	map = Cmd_Argv(1);
	if (!map || !map[0])
	{
		Com_Printf("Usage: \n    map <map name>\n    devmap <map name>\n");
		return;
	}

	// make sure the level exists before trying to change, so that
	// a typo at the server console won't end the game
	Com_sprintf(expanded, sizeof(expanded), "maps/%s.bsp", map);
	if (FS_ReadFile(expanded, NULL) == -1)
	{
		Com_Printf("Can't find map %s\n", expanded);
		return;
	}

	Cvar_Set("gamestate", va("%i", GS_INITIALIZE)); // reset gamestate on map/devmap
	Cvar_Set("g_currentRound", "0");                // reset the current round
	Cvar_Set("g_nextTimeLimit", "0");               // reset the next time limit

	cmd = Cmd_Argv(0);

	if (!Q_stricmp(cmd, "devmap"))
	{
		cheat = qtrue;
	}
	else
	{
		cheat = qfalse;
	}

	// save the map name here cause on a map restart we reload the etconfig.cfg
	// and thus nuke the arguments of the map command
	Q_strncpyz(mapname, map, sizeof(mapname));

	// start up the map
	SV_SpawnServer(mapname);

	// set the cheat value
	// if the level was started with "map <mapname>", then
	// cheats will not be allowed.
	// If started with "devmap <mapname>"
	// then cheats will be allowed
	if (cheat)
	{
		Cvar_Set("sv_cheats", "1");
	}
	else
	{
		Cvar_Set("sv_cheats", "0");
	}
}
开发者ID:vishen,项目名称:etlegacy,代码行数:63,代码来源:sv_ccmds.c

示例15: TTF_Load

// can't unload TTFs, so we'll need to make sure we don't keep reloading them, sadly
void* TTF_Load(Asset &asset) {
	TTFFont_t *fnt = new TTFFont_t();

	if (ctx == nullptr) {
		ctx = glfonsCreate(512, 512, FONS_ZERO_TOPLEFT);
	}

	int found = fonsGetFontByName(ctx, asset.name);
	if (found != FONS_INVALID) {
		fnt->valid = true;
		fnt->hnd = found;
		found++;
		return fnt;
	}

	unsigned char *font;
	auto sz = FS_ReadFile(asset.path, (void **)&font);

	if (sz == -1) {
		Con_Errorf(ERR_GAME, "couldn't load file %s", asset.path);
		return nullptr;
	}

	int hnd = fonsAddFontMem(ctx, asset.name, font, sz, 1);
	if (hnd < 0) {
		return nullptr;
	}

	fnt->valid = true;
	fnt->hnd = hnd;

	return (void*)fnt;
}
开发者ID:sponge,项目名称:sdlgame,代码行数:34,代码来源:asset_ttf.cpp


注:本文中的FS_ReadFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。