示例#1
0
/*
==============
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
0
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
0
文件: snd_as.c 项目: Lrns123/jkaq3
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
0
文件: ogg.c 项目: tomgreen66/yquake2
/*
 * 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
0
////---------------------
/// 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
0
/*
===============
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
0
/*
 * =====================
 * SV_DropClient
 *
 * Called when the player is totally leaving the server, either willingly
 * or unwillingly.  This is NOT called if the entire server is quiting
 * or crashing.
 * =====================
 */
void SV_DropClient(client_t *drop)
{
    // add the disconnect
    MSG_WriteByte(&drop->netchan.message, svc_disconnect);

    if (drop->state == cs_spawned)
    {
        // call the prog function for removing a client
        // this will remove the body, among other things
        ge->ClientDisconnect(drop->edict);
    }

    if (drop->download)
    {
        FS_FreeFile(drop->download);
        drop->download = NULL;
    }

    // r1ch: fix for mods that don't clean score
    if (drop->edict && drop->edict->client)
    {
        drop->edict->client->ps.stats[STAT_FRAGS] = 0;
    }

    drop->state   = cs_zombie;                  // become free in a few seconds
    drop->name[0] = 0;
}
示例#8
0
文件: cmd.c 项目: raynorpat/quake2
/*
===============
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);
}
示例#9
0
文件: ogg.c 项目: tomgreen66/yquake2
/*
 * 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;
	}
}
示例#10
0
文件: cmd.c 项目: norfenstein/umbra
/*
===============
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);
}
示例#11
0
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;
}
示例#12
0
文件: cm_q2bsp.c 项目: Picmip/qfusion
/*
* 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 );
}
示例#13
0
/*
 * 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;
}
示例#14
0
/*
* 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 );
}
示例#15
0
/*
================
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;
}
示例#16
0
文件: cmd.c 项目: chrisglass/ufoai
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);
}
示例#17
0
TEST_F(GameTest, SpawnAndConnect)
{
	char userinfo[MAX_INFO_STRING];
	player_t* player;
	const char* name = "name";
	bool day = true;
	byte* buf;
	/* this entity string may not contain any inline models, we don't have the bsp tree loaded here */
	const int size = FS_LoadFile("game/entity.txt", &buf);
	Edict* e = nullptr;
	int cnt = 0;

	ASSERT_NE(size, -1) << "could not load game/entity.txt.";
	ASSERT_TRUE(size > 0) << "game/entity.txt is empty.";

	SV_InitGameProgs();
	/* otherwise we can't link the entities */
	SV_ClearWorld();

	player = G_PlayerGetNextHuman(0);
	svs.ge->SpawnEntities(name, day, (const char*)buf);
	ASSERT_TRUE(svs.ge->ClientConnect(player, userinfo, sizeof(userinfo))) << "Failed to connect the client";
	ASSERT_FALSE(svs.ge->RunFrame()) << "Failed to run the server logic frame tick";

	while ((e = G_EdictsGetNextInUse(e))) {
		Com_Printf("entity %i: %s\n", cnt, e->classname);
		cnt++;
	}

	ASSERT_EQ(cnt, 43);

	FS_FreeFile(buf);
}
示例#18
0
/**
 * @brief Loads in a model for the given name
 * @param[in] filename Filename relative to base dir and with extension (models/model.md2)
 * @param[inout] mod Structure to initialize
 * @return True if the loading was succeed. True or false structure mod was edited.
 */
static bool R_LoadModel (model_t *mod, const char *filename)
{
	byte *buf;
	int modfilelen;
	char animname[MAX_QPATH];

	if (filename[0] == '\0')
		Com_Error(ERR_FATAL, "R_ModForName: NULL name");

	/* load the file */
	modfilelen = FS_LoadFile(filename, &buf);
	if (!buf)
		return false;

	OBJZERO(*mod);
	Q_strncpyz(mod->name, filename, sizeof(mod->name));

	/* call the appropriate loader */
	switch (LittleLong(*(unsigned *) buf)) {
	case IDALIASHEADER:
		/* MD2 header */
		R_ModLoadAliasMD2Model(mod, buf, modfilelen, true);
		break;

	case DPMHEADER:
		R_ModLoadAliasDPMModel(mod, buf, modfilelen);
		break;

	case IDMD3HEADER:
		/* MD3 header */
		R_ModLoadAliasMD3Model(mod, buf, modfilelen);
		break;

	case IDBSPHEADER:
		Com_Error(ERR_FATAL, "R_ModForName: don't load BSPs with this function");
		break;

	default:
	{
		const char* ext = Com_GetExtension(filename);
		if (ext != NULL && !Q_strcasecmp(ext, "obj"))
			R_LoadObjModel(mod, buf, modfilelen);
		else
			Com_Error(ERR_FATAL, "R_ModForName: unknown fileid for %s", mod->name);
	}
	}

	/* load the animations */
	Com_StripExtension(mod->name, animname, sizeof(animname));
	Com_DefaultExtension(animname, sizeof(animname), ".anm");

	/* try to load the animation file */
	if (FS_CheckFile("%s", animname) != -1) {
		R_ModLoadAnims(&mod->alias, animname);
	}

	FS_FreeFile(buf);

	return true;
}
示例#19
0
static void testSpawnAndConnect (void)
{
	char userinfo[MAX_INFO_STRING];
	player_t *player;
	const char *name = "name";
	bool day = true;
	byte *buf;
	/* this entity string may not contain any inline models, we don't have the bsp tree loaded here */
	const int size = FS_LoadFile("game/entity.txt", &buf);
	edict_t *e = NULL;
	int cnt = 0;

	CU_ASSERT_NOT_EQUAL_FATAL(size, -1);
	CU_ASSERT_FATAL(size > 0);

	SV_InitGameProgs();
	/* otherwise we can't link the entities */
	SV_ClearWorld();

	player = G_PlayerGetNextHuman(0);
	svs.ge->SpawnEntities(name, day, (const char *)buf);
	CU_ASSERT_TRUE(svs.ge->ClientConnect(player, userinfo, sizeof(userinfo)));
	CU_ASSERT_FALSE(svs.ge->RunFrame());

	while ((e = G_EdictsGetNextInUse(e))) {
		Com_Printf("entity %i: %s\n", cnt, e->classname);
		cnt++;
	}

	CU_ASSERT_EQUAL(cnt, 45);

	SV_ShutdownGameProgs();
	FS_FreeFile(buf);
}
示例#20
0
文件: sv_user.c 项目: luaman/qforge-2
/*
==================
SV_NextDownload_f
==================
*/
void SV_NextDownload_f(void){
	int	percent, size, r;

	if(!sv_client->download)
		return;

	r = sv_client->downloadsize - sv_client->downloadcount;
	if(r > 1024)
		r = 1024;

	MSG_WriteByte(&sv_client->netchan.message, svc_download);
	MSG_WriteShort(&sv_client->netchan.message, r);

	sv_client->downloadcount += r;
	size = sv_client->downloadsize;
	if(!size)
		size = 1;
	percent = sv_client->downloadcount * 100 / size;
	MSG_WriteByte(&sv_client->netchan.message, percent);
	SZ_Write(&sv_client->netchan.message,
			  sv_client->download + sv_client->downloadcount - r, r);

	if(sv_client->downloadcount != sv_client->downloadsize)
		return;

	FS_FreeFile(sv_client->download);
	sv_client->download = NULL;
}
示例#21
0
/*
===============
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);
}
示例#22
0
文件: snd_ogg.c 项目: ZwS/qudos
/*
==========
OGG_Open

Play Ogg Vorbis file (with absolute or relative index).
==========
*/
qboolean OGG_Open(ogg_seek_t type, int offset)
{
	int		 size;		/* File size. */
	int		 pos;		/* Absolute position. */
	int		 res;		/* Error indicator. */

	pos = -1;

	switch (type) {
	case ABS:
		/* Absolute index. */
		if (offset < 0 || offset >= ogg_numfiles) {
			Com_Printf("OGG_Open: %d out of range.\n", offset+1);
			return (false);
		} else
			pos = offset;
		break;
	case REL:
		/* Simulate a loopback. */
		if (ogg_curfile == -1 && offset < 0)
			offset++;
		while (ogg_curfile + offset < 0)
			offset += ogg_numfiles;
		while (ogg_curfile + offset >= ogg_numfiles)
			offset -= ogg_numfiles;
		pos = ogg_curfile + offset;
		break;
	}

	/* Check running music. */
	if (ogg_status == PLAY) {
		if (ogg_curfile == pos)
			return (true);
		else
			OGG_Stop();
	}

	/* Find file. */
	if ((size = FS_LoadFile(ogg_filelist[pos], (void **)&ogg_buffer)) == -1) {
		Com_Printf("OGG_Open: could not open %d (%s): %s.\n", pos, ogg_filelist[pos], strerror(errno));
		return (false);
	}

	/* Open ogg vorbis file. */
	if ((res = ov_open(NULL, &ovFile, (char *)ogg_buffer, size)) < 0) {
		Com_Printf("OGG_Open: '%s' is not a valid Ogg Vorbis file (error %i).\n", ogg_filelist[pos], res);
		FS_FreeFile(ogg_buffer);
		return (false);
	}

	/* Play file. */
	ovSection = 0;
	ogg_curfile = pos;
	ogg_status = PLAY;

	Com_Printf("Playing file %d '%s'\n", pos, ogg_filelist[pos]);

	return (true);
}
示例#23
0
/**
 * @sa WriteBSPFile
 */
dMapTile_t* LoadBSPFile (const char* filename)
{
    dBspHeader_t* header;

    /* Create this shortcut to mapTiles[0] */
    curTile = &mapTiles.mapTiles[0];
    /* Set the number of tiles to 1. */
    mapTiles.numTiles = 1;

    /* load the file header */
    int size = FS_LoadFile(filename, (byte**)&header);
    if (size == -1)
        Sys_Error("'%s' doesn't exist", filename);

    /* swap the header */
    BSP_SwapHeader(header, filename);

    if (header->ident != IDBSPHEADER)
        Sys_Error("%s is not a IBSP file", filename);
    if (header->version != BSPVERSION)
        Sys_Error("%s is version %i, not %i", filename, header->version, BSPVERSION);

    curTile->nummodels = CopyLump(header, LUMP_MODELS, curTile->models, sizeof(dBspModel_t));
    curTile->numvertexes = CopyLump(header, LUMP_VERTEXES, curTile->vertexes, sizeof(dBspVertex_t));
    curTile->numplanes = CopyLump(header, LUMP_PLANES, curTile->planes, sizeof(dBspPlane_t));
    curTile->numleafs = CopyLump(header, LUMP_LEAFS, curTile->leafs, sizeof(dBspLeaf_t));
    curTile->numnormals = CopyLump(header, LUMP_NORMALS, curTile->normals, sizeof(dBspNormal_t));
    curTile->numnodes = CopyLump(header, LUMP_NODES, curTile->nodes, sizeof(dBspNode_t));
    curTile->numtexinfo = CopyLump(header, LUMP_TEXINFO, curTile->texinfo, sizeof(dBspTexinfo_t));
    curTile->numfaces = CopyLump(header, LUMP_FACES, curTile->faces, sizeof(dBspSurface_t));
    curTile->numleafbrushes = CopyLump(header, LUMP_LEAFBRUSHES, curTile->leafbrushes, sizeof(curTile->leafbrushes[0]));
    curTile->numsurfedges = CopyLump(header, LUMP_SURFEDGES, curTile->surfedges, sizeof(curTile->surfedges[0]));
    curTile->numedges = CopyLump(header, LUMP_EDGES, curTile->edges, sizeof(dBspEdge_t));
    curTile->numbrushes = CopyLump(header, LUMP_BRUSHES, curTile->dbrushes, sizeof(dBspBrush_t));
    curTile->numbrushsides = CopyLump(header, LUMP_BRUSHSIDES, curTile->brushsides, sizeof(dBspBrushSide_t));
    curTile->routedatasize = CopyLump(header, LUMP_ROUTING, curTile->routedata, 1);
    curTile->lightdatasize[LIGHTMAP_NIGHT] = CopyLump(header, LUMP_LIGHTING_NIGHT, curTile->lightdata[LIGHTMAP_NIGHT], 1);
    curTile->lightdatasize[LIGHTMAP_DAY] = CopyLump(header, LUMP_LIGHTING_DAY, curTile->lightdata[LIGHTMAP_DAY], 1);
    curTile->entdatasize = CopyLump(header, LUMP_ENTITIES, curTile->entdata, 1);

    /* Because the tracing functions use cBspBrush_t and not dBspBrush_t,
     * copy data from curTile->dbrushes into curTile->cbrushes */
    OBJZERO(curTile->brushes);
    for (int i = 0; i < curTile->numbrushes; i++) {
        dBspBrush_t* dbrush = &curTile->dbrushes[i];
        cBspBrush_t* brush = &curTile->brushes[i];
        brush->firstbrushside = dbrush->firstbrushside;
        brush->numsides = dbrush->numsides;
        brush->brushContentFlags = dbrush->brushContentFlags;
    }

    /* everything has been copied out */
    FS_FreeFile(header);

    /* swap everything */
    SwapBSPFile();

    return curTile;
}
示例#24
0
文件: strip.cpp 项目: AlexXT/OpenJK
/************************************************************************************************
 * JK2SP_Register : Load given string package file. Register it.
 *
 * Inputs:
 *	Package File name
 *	Registration flag
 *
 * Return:
 *	success/fail
 *
 ************************************************************************************************/
qboolean JK2SP_Register(const char *inPackage, unsigned char Registration)
{
	char											*buffer;
	char											Package[MAX_QPATH];
	int												size;
	cStringPackageSingle							*new_sp;
	std::map<std::string, cStringPackageSingle *>::iterator	i;


	assert(JK2SP_ListByName.size() == JK2SP_ListByID.size());

	Q_strncpyz(Package, inPackage, MAX_QPATH);
	Q_strupr(Package);

	i = JK2SP_ListByName.find(Package);
	if (i != JK2SP_ListByName.end())
	{
		new_sp = (*i).second;
	}
	else
	{

		size = FS_ReadFile(va("strip/%s.sp", Package), (void **)&buffer);
		if (size == -1)
		{
			if ( Registration & SP_REGISTER_REQUIRED )
			{
				Com_Error(ERR_FATAL, "Could not open string package '%s'", Package);
			}
			return qfalse;
		}

		// Create the new string package
		new_sp = new cStringPackageSingle(Package);
		new_sp->Load(buffer, size );
		FS_FreeFile(buffer);

		if (Registration & SP_REGISTER_CLIENT)
		{
			Com_DPrintf(S_COLOR_YELLOW "JK2SP_Register: Registered client string package '%s' with ID %02x\n", Package, (int)new_sp->GetID());
		}
		else
		{
			Com_DPrintf(S_COLOR_YELLOW "JK2SP_Register: Registered string package '%s' with ID %02x\n", Package, (int)new_sp->GetID());
		}

		// Insert into the name vs package map
		JK2SP_ListByName[Package] = new_sp;
		// Insert into the id vs package map
		JK2SP_ListByID[new_sp->GetID()] = new_sp;
	}
	// Or in the new registration data
	new_sp->Register(Registration);

//	return new_sp;
	return qtrue;
}
示例#25
0
void CM_LoadShaderFiles( void )
{
	if( !shaderText )
	{
		char	**shaderFiles1;
		int		numShaders1;
		char	*buffers[MAX_SHADER_FILES];
		int		numShaders;
		int		i;
		int		sum = 0;

		// scan for shader files
		shaderFiles1 = FS_ListFiles( "shaders", ".shader", &numShaders1 );

		if ( !shaderFiles1 || !numShaders1 )
		{
			Com_Printf( S_COLOR_YELLOW "WARNING: no shader files found\n" );
			return;
		}

		numShaders = numShaders1;
		if ( numShaders > MAX_SHADER_FILES ) 
		{
			numShaders = MAX_SHADER_FILES;
		}

		// load and parse shader files
		for ( i = 0; i < numShaders1; i++ )
		{
			char filename[MAX_QPATH];

			Com_sprintf( filename, sizeof( filename ), "shaders/%s", shaderFiles1[i] );
			Com_DPrintf( "...loading '%s'\n", filename );
			FS_ReadFile( filename, (void **)&buffers[i] );
			if ( !buffers[i] ) 
			{
				Com_Error( ERR_FATAL, "Couldn't load %s", filename );
			}
			sum += COM_Compress( buffers[i] );
		}

		// build single large buffer
		shaderText = (char *)Z_Malloc( sum + numShaders * 2, TAG_SHADERTEXT, qtrue);

		// free in reverse order, so the temp files are all dumped
		for ( i = numShaders - 1; i >= 0 ; i-- ) 
		{
			strcat( shaderText, "\n" );
			strcat( shaderText, buffers[i] );
			FS_FreeFile( buffers[i] );
		}

		// free up memory
		FS_FreeFileList( shaderFiles1 );
	}
}
示例#26
0
文件: stb.c 项目: Clever-Boy/yquake2
/*
 * origname: the filename to be opened, might be without extension
 * type: extension of the type we wanna open ("jpg", "png" or "tga")
 * pic: pointer RGBA pixel data will be assigned to
 */
qboolean
LoadSTB(const char *origname, const char* type, byte **pic, int *width, int *height)
{
	char filename[256];

	Q_strlcpy(filename, origname, sizeof(filename));

	/* Add the extension */
	if (strcmp(COM_FileExtension(filename), type) != 0)
	{
		Q_strlcat(filename, ".", sizeof(filename));
		Q_strlcat(filename, type, sizeof(filename));
	}

	*pic = NULL;

	byte* rawdata = NULL;
	int rawsize = FS_LoadFile(filename, (void **)&rawdata);
	if (rawdata == NULL)
	{
		return false;
	}

	int w, h, bytesPerPixel;
	byte* data = NULL;
	data = stbi_load_from_memory(rawdata, rawsize, &w, &h, &bytesPerPixel, STBI_rgb_alpha);
	if (data == NULL)
	{
		VID_Printf(PRINT_ALL, "stb_image couldn't load data from %s: %s!\n", filename, stbi_failure_reason());
		FS_FreeFile(rawdata);
		return false;
	}

	FS_FreeFile(rawdata);

	VID_Printf(PRINT_DEVELOPER, "LoadSTB() loaded: %s\n", filename);

	*pic = data;
	*width = w;
	*height = h;
	return true;
}
示例#27
0
static Mix_Chunk* S_LoadSampleChunk (const char *sound)
{
	size_t len;
	byte *buf;
	const char *soundExtensions[] = SAMPLE_TYPES;
	const char **extension = soundExtensions;
	SDL_RWops *rw;
	Mix_Chunk *chunk;

	if (!sound || sound[0] == '*')
		return NULL;

	len = strlen(sound);
	if (len + 4 >= MAX_QPATH) {
		Com_Printf("S_LoadSound: MAX_QPATH exceeded for: '%s'\n", sound);
		return NULL;
	}

	while (*extension) {
		if ((len = FS_LoadFile(va("sound/%s.%s", sound, *extension++), &buf)) == -1)
			continue;

		if (!(rw = SDL_RWFromMem(buf, len))){
			FS_FreeFile(buf);
			continue;
		}

		if (!(chunk = Mix_LoadWAV_RW(rw, qfalse)))
			Com_Printf("S_LoadSound: %s.\n", Mix_GetError());

		FS_FreeFile(buf);

		SDL_FreeRW(rw);

		if (chunk)
			return chunk;
	}

	Com_Printf("S_LoadSound: Could not find sound file: '%s'\n", sound);
	return NULL;
}
示例#28
0
文件: map.cpp 项目: nicogiraldi/ufoai
/**
 * @brief Parses an ump file that contains the random map definition
 * @param[in] name The basename of the ump file (without extension)
 * @param[in] inherit When @c true, this is called to inherit tile definitions
 * @param[out] entityString An entity string that is used for all map tiles. Parsed from the ump.
 * from another ump file (no assemblies)
 */
static void ParseUMP (const char* name, char* entityString, bool inherit)
{
	char filename[MAX_QPATH];
	byte* buf;
	const char* text;

	*entityString = '\0';

	/* load the map info */
	Com_sprintf(filename, sizeof(filename), "maps/%s.ump", name);
	FS_LoadFile(filename, &buf);
	if (!buf)
		return;

	/* parse it */
	text = (const char*)buf;
	do {
		const char* token = Com_Parse(&text);
		if (!text)
			break;

		if (Q_streq(token, "extends")) {
			token = Com_Parse(&text);
			if (inherit)
				Com_Printf("ParseUMP: Too many extends in %s 'extends %s' ignored\n", filename, token);
			else
				ParseUMP(token, entityString, true);
		} else if (Q_streq(token, "worldspawn")) {
			const char* start = nullptr;
			const int length = Com_GetBlock(&text, &start);
			if (length == -1) {
				Com_Printf("ParseUMP: Not a valid worldspawn block in '%s'\n", filename);
			} else {
				if (length >= MAX_TOKEN_CHARS) {
					Com_Printf("worldspawn is too big - only %i characters are allowed", MAX_TOKEN_CHARS);
				} else if (length == 0) {
					Com_Printf("no worldspawn settings in ump file\n");
				} else {
					Q_strncpyz(entityString, start, length);
					Com_Printf("use worldspawn settings from ump file\n");
				}
			}
		} else if (token[0] == '{') {
			/* ignore unknown block */
			text = strchr(text, '}') + 1;
			if (!text)
				break;
		}
	} while (text);

	/* free the file */
	FS_FreeFile(buf);
}
示例#29
0
文件: ogg.c 项目: tomgreen66/yquake2
/*
 * Load playlist.
 */
void
OGG_LoadPlaylist(char *playlist)
{
	byte *buffer; /* Buffer to read the file. */
	char *ptr;    /* Pointer for parsing the file. */
	int i;		  /* Loop counter. */
	int size;     /* Length of buffer and strings. */

	/* Open playlist. */
	if ((size = FS_LoadFile(va("%s/%s.lst", OGG_DIR, 
				  ogg_playlist->string), (void **)&buffer)) < 0)
	{
		Com_Printf("OGG_LoadPlaylist: could not open playlist: %s.\n",
				strerror(errno));
		return;
	}

	/* Count the files in playlist. */
	for (ptr = strtok((char *)buffer, "\n");
		 ptr != NULL;
		 ptr = strtok(NULL, "\n"))
	{
		if ((byte *)ptr != buffer)
		{
			ptr[-1] = '\n';
		}

		if (OGG_Check(va("%s/%s", OGG_DIR, ptr)))
		{
			ogg_numfiles++;
		}
	}

	/* Allocate file list. */
	ogg_filelist = malloc(sizeof(char *) * ogg_numfiles);

	i = 0;

	for (ptr = strtok((char *)buffer, "\n");
		 ptr != NULL;
		 ptr = strtok(NULL, "\n"))
	{
		if (OGG_Check(va("%s/%s", OGG_DIR, ptr)))
		{
			ogg_filelist[i++] = strdup(va("%s/%s", OGG_DIR, ptr));
		}
	}

	/* Free file buffer. */
	FS_FreeFile(buffer);
}
示例#30
0
文件: snd_ogg.c 项目: ZwS/qudos
/*
==========
OGG_Stop

Stop playing the current file.
==========
*/
void OGG_Stop(void)
{

	if (ogg_status == STOP)
		return;

	ov_clear(&ovFile);
	ogg_status = STOP;

	if (ogg_buffer != NULL) {
		FS_FreeFile(ogg_buffer);
		ogg_buffer = NULL;
	}
}