Ejemplo n.º 1
0
void wavPlayer::stop()
{
	if(!playing) return;
	SND_StopTimer(3, 0, 0, 0);
	playing = false;
	FS_CloseFile(&fileLeft);
	FS_CloseFile(&fileRight);
}
Ejemplo n.º 2
0
void CFG_Load(void)
{
	filehandle_t* cfgFile ;
	
	cfgFile = FS_OpenFile(CONFIG_FILENAME, "wrt");
	FS_UploadToRAM(cfgFile);

	if (!cfgFile)
	{
		Log_Printf("[CFG_Load] Unable to find player settings file, creating it.\n");
		CFG_Save();
		CFG_Load();
		return;
	}
	
	
	//Check the magic number
	if(strncmp(cfgFile->filedata, cfgMagicNumber, strlen(cfgMagicNumber)))
	{
		Log_Printf("[CFG_Load] Magic number check failed.\n");
		return;
	}
	
	//Reading visited act
	
	
	FS_CloseFile(cfgFile);
}
Ejemplo n.º 3
0
/**
 * @brief Set the mn_slotX cvar to the comment (remove the date string) for clean
 * editing of the save comment
 * @sa SAV_GameReadGameComments_f
 */
static void SAV_GameSaveNameCleanup_f (void)
{
	int slotID;
	char cvar[16];
	qFILE f;
	saveFileHeader_t header;

	/* get argument */
	if (Cmd_Argc() < 2) {
		Com_Printf("Usage: %s <[0-7]>\n", Cmd_Argv(0));
		return;
	}

	slotID = atoi(Cmd_Argv(1));
	if (slotID < 0 || slotID > 7)
		return;

	FS_OpenFile(va("save/slot%i.%s", slotID, SAVEGAME_EXTENSION), &f, FILE_READ);
	if (!f.f && !f.z)
		return;

	/* read the comment */
	if (FS_Read(&header, sizeof(header), &f) != sizeof(header))
		Com_Printf("Warning: Savefile header may be corrupted\n");

	Com_sprintf(cvar, sizeof(cvar), "mn_slot%i", slotID);
	if (SAV_VerifyHeader(&header))
		Cvar_Set(cvar, header.name);
	else
		Cvar_Set(cvar, "");
	FS_CloseFile(&f);
}
Ejemplo n.º 4
0
/*
-----------------------------------------------------------------------------
 Function: Cmd_Exec_f -Execute script file.
 
 Parameters: Nothing.            
 
 Returns: Nothing.
 
 Notes: Console function, exec <filename>

-----------------------------------------------------------------------------
*/
PRIVATE void Cmd_Exec_f( void )
{
	filehandle_t *hfile;
	char	*f2;
	int		len;

	if( Cmd_Argc () != 2 )
	{
		Com_Printf( "exec <filename> : execute a script file\n" );
		return;
	}

	hfile = FS_OpenFile( Cmd_Argv( 1 ), FA_FILE_IPHONE_DOC_DIR );
	if( ! hfile )
	{
		Com_Printf( "couldn't exec %s\n", Cmd_Argv( 1 ) );
		return;
	}

	len = FS_GetFileSize( hfile );

	Com_Printf( "execing %s\n", Cmd_Argv( 1 ) );
	
	// the file doesn't have a trailing 0, so we need to copy it off
	f2 = Z_Malloc( len + 1 );
	memcpy( f2, hfile->filedata, len );
	f2[ len ] = 0;

	printf( "%s", f2 );		// !@#
	Cbuf_InsertText( f2 );

	Z_Free( f2 );

	FS_CloseFile( hfile );
}
Ejemplo n.º 5
0
void UpLoadTextureToGPU(texture_t* texture)
{
	if (!texture || !texture->data || texture->textureId != 0)
		return;
	
	glActiveTexture(GL_TEXTURE0);
	glGenTextures(1, &texture->textureId);
	glBindTexture(GL_TEXTURE_2D, texture->textureId);
	
	if (texture->format == TEXTURE_GL_RGB ||texture->format == TEXTURE_GL_RGBA)
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture->width, texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, texture->data);
	else
		glCompressedTexImage2D(GL_TEXTURE_2D, 0, texture->format, texture->width,texture->height, 0, texture->dataLength, texture->data);
	
	
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, DE_DEFAULT_FILTERING);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, DE_DEFAULT_FILTERING);	
	

	if (texture->file != NULL)
		FS_CloseFile(texture->file);
		
	free(texture->data);	
	 
}
Ejemplo n.º 6
0
/**
 * @note Both client and server can use this, and it will
 * do the appropriate things.
 */
void Com_Error (int code, const char* fmt, ...)
{
	va_list argptr;
	static char msg[MAXPRINTMSG];
	static bool recursive = false;

	if (recursive)
		Sys_Error("recursive error after: %s", msg);
	recursive = true;

	va_start(argptr, fmt);
	Q_vsnprintf(msg, sizeof(msg), fmt, argptr);
	va_end(argptr);

	switch (code) {
	case ERR_DISCONNECT:
		Com_Printf("%s\n", msg);
		CL_Drop();
		recursive = false;
		Com_Drop();
	case ERR_DROP:
		Com_Printf("********************\n");
		Com_Printf("ERROR: %s\n", msg);
		Com_Printf("********************\n");
		Sys_Backtrace();
		SV_Shutdown("Server crashed.", false);
		CL_Drop();
		recursive = false;
		Com_Drop();
	default:
		Com_Printf("%s\n", msg);
		SV_Shutdown("Server fatal crashed", false);

		/* send an receive net messages a last time */
		NET_Wait(0);

		FS_CloseFile(&logfile);
		if (pipefile.f != nullptr) {
			FS_CloseFile(&pipefile);
			FS_RemoveFile(va("%s/%s", FS_Gamedir(), pipefile.name));
		}

		CL_Shutdown();
		Qcommon_Shutdown();
		Sys_Error("Shutdown");
	}
}
Ejemplo n.º 7
0
void dEngine_WriteScreenshot(char* directory)
{
	
	int i;//,j;
	filehandle_t* pScreenshot;
	char fullPath[256];
	
	uchar tga_header[18];
	uchar* pixel;
	uchar tmpChannel;
	
	/*
	char num[64];
	sprintf(num, "scene%05d_t=%05d",engine.sceneId, simulationTime);
	memset(fullPath, 256, sizeof(char));
	strcat(fullPath,directory);
	strcat(fullPath,num);
	strcat(fullPath,".tga");
	*/
	fullPath[0] = '\0';
	sprintf(fullPath,"%sscene%05d_t=%05d.tga",directory,engine.sceneId, simulationTime);
	
	
	
	
	SCR_GetColorBuffer(screenShotBuffer);
	
	pScreenshot = FS_OpenFile(fullPath, "wb");
	
	memset(tga_header, 0, 18);
	tga_header[2] = 2;
	tga_header[12] = (renderer.glBuffersDimensions[WIDTH] & 0x00FF);
	tga_header[13] = (renderer.glBuffersDimensions[WIDTH]  & 0xFF00) / 256; // /256
	tga_header[14] = (renderer.glBuffersDimensions[HEIGHT]  & 0x00FF) ;
	tga_header[15] =(renderer.glBuffersDimensions[HEIGHT] & 0xFF00) / 256;
	tga_header[16] = 32 ;
	
	
	
	FS_Write(&tga_header, 18, sizeof(uchar), pScreenshot);
	
	// RGB > BGR
	pixel = screenShotBuffer;
	for(i=0 ; i < renderer.glBuffersDimensions[WIDTH] * renderer.glBuffersDimensions[HEIGHT] ; i++)
	{
		tmpChannel = pixel[0];
		pixel[0] = pixel[2];
		pixel[2] = tmpChannel;
		
		pixel += 4;
	}
	
	
	FS_Write(screenShotBuffer, renderer.glBuffersDimensions[WIDTH] * renderer.glBuffersDimensions[HEIGHT], 4 * sizeof(uchar), pScreenshot);
	
	FS_CloseFile(pScreenshot);
	
}
Ejemplo n.º 8
0
/**
 * Both client and server can use this, and it will
 * do the appropriate things.
 */
void Com_Quit (void)
{
#ifdef DEDICATED_ONLY
	Com_WriteConfigToFile("dedconfig.cfg");
#else
	Com_WriteConfigToFile("config.cfg");
#endif

	SV_Shutdown("Server quit.", false);
	SV_Clear();
	CL_Shutdown();

	/* send an receive net messages a last time */
	NET_Wait(0);
	FS_CloseFile(&logfile);
	if (pipefile.f != nullptr) {
		FS_CloseFile(&pipefile);
		FS_RemoveFile(va("%s/%s", FS_Gamedir(), pipefile.name));
	}
	Sys_Quit();
}
Ejemplo n.º 9
0
void* Util_LoadFileToBuffer(char* path, uint32_t* size)
{
	FSFile file;
	FS_InitFile(&file);
	FS_OpenFile(&file, path);
	uint32_t mSize = FS_GetLength(&file);
	void* buffer = NNS_FndAllocFromExpHeapEx(mHeapHandle, mSize, 16);
	FS_ReadFile(&file, buffer, (int)mSize);
	FS_CloseFile(&file);
	if(size != NULL) *size = mSize;
	return buffer;
}
Ejemplo n.º 10
0
void CFG_Save(void)
{
	filehandle_t* cfgFile ;
	
	cfgFile = FS_OpenFile(CONFIG_FILENAME, "wt");
	FS_UploadToRAM(cfgFile);
	//Writing the magic number
	fwrite(cfgMagicNumber,1,strlen(cfgMagicNumber), cfgFile->hFile);
	
	//Writing visited act
	
	FS_CloseFile(cfgFile);
}
Ejemplo n.º 11
0
/**
 * @brief Checks whether there is a quicksave file and opens the quickload menu if there is one
 * @note This does not work while we are in the battlescape
 */
static void SAV_GameQuickLoadInit_f (void)
{
	qFILE f;

	if (cgi->CL_OnBattlescape()) {
		return;
	}

	FS_OpenFile(va("save/slotquick.%s", SAVEGAME_EXTENSION), &f, FILE_READ);
	if (f.f || f.z) {
		cgi->UI_PushWindow("quickload");
		FS_CloseFile(&f);
	}
}
Ejemplo n.º 12
0
static qboolean SL_CreatePNGFile (const char *filename, unsigned char *buffer, int width, int height)
{
	qFILE f;

	/* create the .bmp file... */
	if (FS_OpenFile(filename, &f, FILE_WRITE) == -1)
		return qfalse;

	R_WritePNG(&f, buffer, width, height);

	FS_CloseFile(&f);

	return qtrue;
}
Ejemplo n.º 13
0
/**
 * \brief Close out background music track.
 * \param[in] Music track to close.
 * \return
 * \note
 */
PRIVATE void Sound_CloseBGTrack( musicTrack_t *track )
{
	if( track->vorbisFile )
	{
		ov_clear( track->vorbisFile );

		Z_Free( track->vorbisFile );
		track->vorbisFile = NULL;
	}

	if( track->hFile )
	{
		FS_CloseFile( track->hFile );
	}
}
Ejemplo n.º 14
0
void CAM_StartPlaying(char* filename)
{
	uint i;	
	filehandle_t* file ;
	uchar isCP1 = 0;
	
	file = FS_OpenFile(filename, "rt");
	
	if (!file)
		return;
	
	isCP1 = (*file->ptrStart == 'c' && *(file->ptrStart+1) == 'p' && *(file->ptrStart+2) == '1') ;
	
	if (!isCP1)
	{
		printf("Camera path is not a valid file:");
		return;
	}
	
	LE_init(file);
	
	LE_readToken(); //CP1
	LE_readToken(); //num_frames
	
	
	
	camera.path.num_frames = LE_readReal();
	
	camera.path.frames = CAM_ReadFrameFromFile();
	camera.path.frames->next = 0;
	camera.path.currentFrame = camera.path.frames;
	
	for(i=1 ; i < camera.path.num_frames ; i++)
	{
		camera.path.currentFrame->next = CAM_ReadFrameFromFile();
		camera.path.currentFrame = camera.path.currentFrame->next;
		camera.path.currentFrame->next = 0;
	}
							  
	camera.playing = 1;
	camera.path.currentFrame = camera.path.frames;
	strcpy(camera.recordFilename, filename);
	simulationTime = camera.path.frames[0].time;
	
	FS_CloseFile(file);
}
Ejemplo n.º 15
0
/*
 ==================
 
 ==================
*/
void CIN_StopCinematic (int handle){

	cinematic_t	*cin;

	cin = CIN_GetCinematicByHandle(handle);

	// Stop the cinematic
	if (cin->flags & CIN_SYSTEM){
		cls.playingCinematic = false;

		// Make sure sounds aren't playing
		S_StopAllSounds();
	}

	// Close the file
	if (cin->file)
		FS_CloseFile(cin->file);

	Mem_Fill(cin, 0, sizeof(cinematic_t));
}
Ejemplo n.º 16
0
/**
 * @note not moved into V_UI_NODEMETHOD because it is more a generic
 * tool than a method of the node editor
 */
static void UI_EditorNodeExtract_f (void)
{
	uiNode_t* window;
	qFILE file;

	if (Cmd_Argc() != 2) {
		Com_Printf("Usage: %s <windowname>\n", Cmd_Argv(0));
		return;
	}
	window = UI_GetWindow(Cmd_Argv(1));
	if (!window) {
		Com_Printf("Window '%s' not found\n", Cmd_Argv(1));
		return;
	}

	FS_OpenFile(va("window_%s_extracted.ufo", window->name), &file, FILE_WRITE);
	UI_EditorNodeExtractNode(&file, window, 0);
	FS_CloseFile(&file);

	Com_Printf("Window '%s' extracted.\n", Cmd_Argv(1));
}
Ejemplo n.º 17
0
/**
 * @brief Init menu cvar for one savegame slot given by actual index.
 * @param[in] idx the savegame slot to retrieve gamecomment for
 * @sa SAV_GameReadGameComments_f
 */
static void SAV_GameReadGameComment (const int idx)
{
	saveFileHeader_t header;
	qFILE f;

	FS_OpenFile(va("save/slot%i.%s", idx, SAVEGAME_EXTENSION), &f, FILE_READ);
	if (f.f || f.z) {
		if (FS_Read(&header, sizeof(header), &f) != sizeof(header))
			Com_Printf("Warning: Savefile header may be corrupted\n");

		header.compressed = LittleLong(header.compressed);
		header.version = LittleLong(header.version);
		header.xmlSize = LittleLong(header.xmlSize);
		header.subsystems = LittleLong(header.subsystems);

		if (!SAV_VerifyHeader(&header))
			Com_Printf("Savegame header for slot%d is corrupted!\n", idx);
		else
			cgi->UI_ExecuteConfunc("update_save_game_info %i \"%s\" \"%s\" \"%s\"", idx, header.name, header.gameDate, header.realDate);

		FS_CloseFile(&f);
	}
}
Ejemplo n.º 18
0
/*
 ==================
 
 ==================
*/
void CIN_Shutdown (){

	cinematic_t	*cin;
	int			i;

	// Remove commands
	Cmd_RemoveCommand("playCinematic");
	Cmd_RemoveCommand("listCinematics");

	// Stop all the cinematics
	cls.playingCinematic = false;

	for (i = 0, cin = cin_cinematics; i < MAX_CINEMATICS; i++, cin++){
		if (!cin->playing)
			continue;

		// Close the file
		if (cin->file)
			FS_CloseFile(cin->file);
	}

	// Clear cinematic list
	Mem_Fill(cin_cinematics, 0, sizeof(cin_cinematics));
}
Ejemplo n.º 19
0
static void WriteTGA24 (const char *filename, const byte * data, int width, int height, int offset)
{
	int i, size;
	byte *buffer;
	qFILE file;

	size = width * height * 3;
	/* allocate a buffer and set it up */
	buffer = (byte *)Mem_Alloc(size + TGA_HEADER_SIZE);
	memset(buffer, 0, TGA_HEADER_SIZE);
	buffer[2] = 2;
	buffer[12] = width & 255;
	buffer[13] = width >> 8;
	buffer[14] = height & 255;
	buffer[15] = height >> 8;
	buffer[16] = 24;
	/* create top-down TGA */
	buffer[17] = 32;

	/* swap rgb to bgr */
	for (i = 0; i < size; i += 3) {
		buffer[i + TGA_HEADER_SIZE] = data[i*2 + offset + 2];	/* blue */
		buffer[i + TGA_HEADER_SIZE + 1] = data[i*2 + offset + 1];	/* green */
		buffer[i + TGA_HEADER_SIZE + 2] = data[i*2 + offset + 0];	/* red */
	}

	/* write it and free the buffer */
	if (FS_OpenFile(filename, &file, FILE_WRITE) > 0)
		Sys_Error("Unable to open %s for writing", filename);

	FS_Write(buffer, size + TGA_HEADER_SIZE, &file);

	/* close the file */
	FS_CloseFile(&file);
	Mem_Free(buffer);
}
Ejemplo n.º 20
0
/*
 ==================
 CIN_PlayCinematic

 TODO: read the .cin file header
 TODO: fill in cinematic_t
 ==================
*/
int	CIN_PlayCinematic (const char *name, int flags){

	cinematic_t		*cin;
	fileHandle_t	file;
	byte			buffer[ROQ_CHUNK_HEADER_SIZE];
	word			id, fps;
	char			checkName[MAX_PATH_LENGTH], loadName[MAX_PATH_LENGTH];
	bool			isRoQ;
	int				handle;
	int				size;
	int				i;

	// Check if already playing
	for (i = 0, cin = cin_cinematics; i < MAX_CINEMATICS; i++, cin++){
		if (!cin->playing)
			continue;

		if (!Str_ICompare(cin->name, name)){
			if (cin->flags != flags)
				continue;

			return i + 1;
		}
	}

	// Get a free handle
	cin = CIN_HandleForCinematic(&handle);

	if (flags & CIN_SYSTEM){
		cls.playingCinematic = true;

		S_StopAllSounds();

		Com_Printf("Playing cinematic %s\n", name);
	}

	// Strip file extension
	Str_Copy(checkName, name, sizeof(checkName));
	Str_StripFileExtension(checkName);

	// Check for a static PCX image
	Str_SPrintf(loadName, sizeof(loadName), "%s.pcx", checkName);

	if (FS_FileExists(loadName)){
		if (!CIN_LoadPCX(cin, checkName, flags))
			return 0;

		return handle;
	}

	// Open the file
	Str_SPrintf(loadName, sizeof(loadName), "%s.RoQ", checkName);

	size = FS_OpenFile(loadName, FS_READ, &file);
	if (file)
		isRoQ = true;
	else {
		Str_SPrintf(loadName, sizeof(loadName), "%s.cin", checkName);

		size = FS_OpenFile(loadName, FS_READ, &file);
		if (file)
			isRoQ = false;
		else {
			if (flags & CIN_SYSTEM){
				cls.playingCinematic = false;

				Com_Printf("Cinematic %s not found\n", name);
			}

			return 0;
		}
	}

	if (isRoQ){
		// Read the file header
		FS_Read(file, buffer, ROQ_CHUNK_HEADER_SIZE);

		id = buffer[0] | (buffer[1] << 8);
		fps = buffer[6] | (buffer[7] << 8);

		if (id != ROQ_ID){
			FS_CloseFile(file);

			if (flags & CIN_SYSTEM){
				cls.playingCinematic = false;

				Com_Printf("Cinematic %s is not a RoQ file\n", name);
			}

			return 0;
		}

		// Fill it in
		cin->playing = true;

		cin->isRoQ = isRoQ;

		Str_Copy(cin->name, name, sizeof(cin->name));
		cin->flags = flags;

		cin->file = file;
		cin->size = size;
		cin->offset = ROQ_CHUNK_HEADER_SIZE;

		cin->startTime = 0;

		cin->frameRate = (fps) ? fps : 30;

		cin->frameCount = 0;
	}
	else {
		// Read the file header

		// Fill it in
		cin->playing = true;

		cin->isRoQ = isRoQ;

		Str_Copy(cin->name, name, sizeof(cin->name));
		cin->flags = flags;

		cin->file = file;
		cin->size = size;
		cin->offset = 20;

		cin->startTime = 0;

		cin->frameRate = 14;

		cin->frameCount = 0;
	}

	return handle;
}
Ejemplo n.º 21
0
void dEngine_ReadConfig(void)
{
	filehandle_t* config;
	int currentSceneId=0;
	
    
    
	config = FS_OpenFile(CONFIG_PATH, "rt");
	FS_UploadToRAM(config);
	
	if (!config)
	{
		Log_Printf("Configuration file: data/config.cfg not found");
		exit(0);
	}
	
	//renderer.resolution = 1;

	LE_pushLexer();
	LE_init(config);
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();

		if (!strcmp("scenes", LE_getCurrentToken()))
		{
			LE_readToken(); // {
			LE_readToken(); // numScenes
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("numScenes", LE_getCurrentToken()))
				{
					engine.numScenes = LE_readReal();
				}
				else 
				if (!strcmp("scene", LE_getCurrentToken()))
				{
					currentSceneId = LE_readReal();
					
					LE_readToken(); //The name of the scene, here only to help developer to keep track of config.cfg
					strReplace(LE_getCurrentToken(), '_', ' ');
					strcpy(engine.scenes[currentSceneId].name, LE_getCurrentToken());
					
					LE_readToken();
					strcpy(engine.scenes[currentSceneId].path, LE_getCurrentToken());
					
					Log_Printf("Read scene %d, name %s, path %s\n",currentSceneId,engine.scenes[currentSceneId].name,engine.scenes[currentSceneId].path);
					
					
				}
				
				LE_readToken();
				
			}
		}
		else if (!strcmp("fx", LE_getCurrentToken()))
		{
			LE_readToken(); //{
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				LE_readToken();
				
				if (!strcmp("impactTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//			explosionTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(explosionTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("smokeTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				smokeTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(smokeTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ghostTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
	//				ghostTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(ghostTexture.path, LE_getCurrentToken());
				}
			}
		}
		/*
		else if (!strcmp("video", LE_getCurrentToken()))
		{
			
			LE_readToken(); // {
			LE_readToken();
			while (strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("record", LE_getCurrentToken()))
				{
					engine.recordVideo = LE_readReal();
				}
				LE_readToken();
			}
		}
		*/
		else if (!strcmp("players", LE_getCurrentToken()))
		{
			LE_readToken();	//{
			LE_readToken();
			while (LE_hasMoreData() && strcmp("}", LE_getCurrentToken()))
			{
				if (!strcmp("model1", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[1].modelPath, LE_getCurrentToken());
				}
				else 
				if (!strcmp("model0", LE_getCurrentToken()))
				{
					LE_readToken();
					strcpy(players[0].modelPath, LE_getCurrentToken());
				}
				else 
					if (!strcmp("bulletTextureName", LE_getCurrentToken()))
				{
					LE_readToken();
//					bulletConfig.bulletTexture.path = calloc(strlen(LE_getCurrentToken())+1, sizeof(char));
					strcpy(bulletConfig.bulletTexture.path, LE_getCurrentToken());
				}
				else 
				if (!strcmp("ttl", LE_getCurrentToken()))
				{
					bulletConfig.ttl = LE_readReal();
				}
				else 
				if (!strcmp("heightRatio", LE_getCurrentToken()))
				{
					bulletConfig.heightRatio = LE_readReal();
				}
				else 
				if (!strcmp("widthRatio", LE_getCurrentToken()))
				{
					bulletConfig.widthRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("screenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.screenSpaceYDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashHeightRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashHeightRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashWidthRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashWidthRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceXDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceXDeltaRatio = LE_readReal();
				}
				else 
				if (!strcmp("flashScreenSpaceYDeltaRatio", LE_getCurrentToken()))
				{
					bulletConfig.flashScreenSpaceYDeltaRatio = LE_readReal();
				}
				
				LE_readToken();
			}
			
		}
		
	}
	
	
	LE_popLexer();
	FS_CloseFile(config);
	
	
}
Ejemplo n.º 22
0
/**
 * \brief Load font details from file
 * \param[in] filename File name to load details
 * \return Valid pointer to font_t
 */
PUBLIC font_t *createFont( const char *filename )
{
	font_t *temp_font;
	char *datname;
	filehandle_t *fp;
	W32 size;
	W32 i;

	if( num_fonts == (MAX_FONTS - 1) )
	{
		Com_Printf( "[createFont]: No more font slots open\n" );

		return NULL;
	}


	temp_font = (font_t *)Z_Malloc( sizeof( font_t ) );

	temp_font->texfont = TM_FindTexture( filename, TT_Pic );
	if( NULL == temp_font->texfont )
	{
		Com_Printf( "[createFont]: unable to open file (%s)\n", filename );

		Z_Free( temp_font );

		return NULL;
	}

	memset( temp_font->nCharWidth, 0, sizeof( temp_font->nCharWidth ) );

	datname = (char *)MM_MALLOC( strlen( filename ) + 1 );

	FS_RemoveExtension( filename, datname );

	com_strlcat( datname, ".dat", strlen( filename ) + 1 );

	fp = FS_OpenFile( datname, 0 );
	if( NULL == fp )
	{
		Com_Printf( "[createFont]: unable to open file (%s)\n", datname );

		MM_FREE( datname );
		Z_Free( temp_font );

		return NULL;
	}

	size = FS_GetFileSize( fp );

	// check header size
	if( size < 10 )
	{
		Com_Printf( "[createFont]: File (%s) has incorrect file length\n", datname );

		MM_FREE( datname );
		Z_Free( temp_font );

		FS_CloseFile( fp );

		return NULL;
	}


	// Check sig of font dat file

	FS_ReadFile( &size, 1, 4, fp );


	FS_ReadFile( &temp_font->nMaxWidth, 1, 1, fp );
	FS_ReadFile( &temp_font->nMaxHeight, 1, 1, fp );


	FS_ReadFile( &size, 1, 4, fp );
	size = LittleLong( size );

	if( size > 127 )
	{
		Com_Printf( "[createFont]: File (%s) has incorrect Character Width array\n", datname );

		MM_FREE( datname );
		Z_Free( temp_font );

		FS_CloseFile( fp );

		return NULL;
	}

	FS_ReadFile( &temp_font->nCharWidth, 1, size, fp );

	FS_CloseFile( fp );




	temp_font->nSize = 2;
	temp_font->colour[ 3 ] = 255;

	temp_font->hFrac = (float)(temp_font->nMaxHeight / (float)temp_font->texfont->height);
	temp_font->wFrac = (float)(temp_font->nMaxWidth / (float)temp_font->texfont->width);



	for( i = 0 ; i < MAX_FONTS ; ++i )
	{
		if( ! myfonts[ i ] )
		{
			break;
		}
	}

	if( i == (MAX_FONTS - 1) )
	{
		Com_Printf( "[createFont]: No more font slots open\n" );

		MM_FREE( datname );
		Z_Free( temp_font );

		return NULL;
	}

	myfonts[ i ] = temp_font;

	MM_FREE( datname );


	return temp_font;
}
Ejemplo n.º 23
0
char OBJ_Load(char* filename,entity_t* entity)
{
	static vec3_t tmpVertices[DE_USHRT_MAX];
	ushort num_vertices=0;
	
	static vec2_t tmpTextureCoor[DE_USHRT_MAX];
	ushort num_textuCoor=0;
	
	int idata[9];	
	int i;
	
	ushort indiceOfCurrentVertex;
	
	filehandle_t* objFile ;
	
	obj_t* obj;
	
	
	
	
	objFile = FS_OpenFile(filename, "rt");
	
	if (!objFile)
	{
		printf("Could not Load OBJ: '%s'.\n",filename);
		return 0;
	}
	
	
		
	OBJ_InitVerticeCache();
	
	obj = (obj_t*)entity->model;
	obj->vertices = (obj_vertex_t*)calloc(DE_USHRT_MAX, sizeof(obj_vertex_t));
	obj->num_vertices = 0;
	obj->indices = (ushort*)calloc(DE_USHRT_MAX, sizeof(ushort));
	obj->num_indices = 0;
	
	LE_pushLexer();
	
	LE_init(objFile);
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();
		
		if (!strcmp("v",LE_getCurrentToken()))
		{
			tmpVertices[num_vertices][0] = LE_readReal();
			tmpVertices[num_vertices][1] = LE_readReal();
			tmpVertices[num_vertices][2] = LE_readReal();
			num_vertices++;
			
		}
		else
		if (!strcmp("vt",LE_getCurrentToken()))
		{
			tmpTextureCoor[num_textuCoor][0] = LE_readReal();
			tmpTextureCoor[num_textuCoor][1] = 1- LE_readReal();
			num_textuCoor++;
		}
		else
		if (!strcmp("vn",LE_getCurrentToken()))
		{
			for(i=0;i<3;i++)
				LE_readReal();
			
			//Drop it (like it's hot)
		}
		else
		if (!strcmp("f",LE_getCurrentToken()))
		{
			LE_SetWhiteCharValue('/', 1);
			
			for(i=0;i<9;i++)
			{
				idata[i] = LE_readReal();
				idata[i]--;
			}
			
			#ifdef OBJ_FACE_CCW
			for(i=0;i<3;i++)//OBJ Standard: Couter-clockwise
			#else
			for(i=2;i>=0;i--) //Bugged expoter.
			#endif			
			{
				indiceOfCurrentVertex = GetCacheVertex(idata[3*i],tmpTextureCoor[idata[3*i+1]]);
				//indiceOfCurrentVertex = obj->num_indices;
				
				if (indiceOfCurrentVertex+1 > obj->num_vertices)
					obj->num_vertices = indiceOfCurrentVertex+1;
				
				vectorCopy (tmpVertices[idata[3*i]]		, obj->vertices[indiceOfCurrentVertex].position);
				//for(i=0;i<3;i++)
				//{
				//		printf("Vertices: %d, %d, %d.\n",obj->vertices[indiceOfCurrentVertex].position[0],obj->vertices[indiceOfCurrentVertex].position[1],obj->vertices[indiceOfCurrentVertex].position[2]);
				//}
				vector2Copy(tmpTextureCoor[idata[3*i+1]], obj->vertices[indiceOfCurrentVertex].textCoo);
				
				//printf("num_indices = %d, indice pointer=%d\n",obj->num_indices,indiceOfCurrentVertex);
				obj->indices[obj->num_indices++] = indiceOfCurrentVertex ;
				
			}
			
			LE_SetWhiteCharValue('/', 0);
		}
		else
		if (!strcmp("usemtl",LE_getCurrentToken()))
		{
			LE_readToken();
			entity->material = MATLIB_Get(LE_getCurrentToken());
			if (entity->material == 0)
				printf("************[OBJ Loader] Could not find material: '%s'\n",LE_getCurrentToken());
			
		}
	}
	
	
	LE_popLexer();
	
	FS_CloseFile(objFile);
	
	//Adjust size of vertices and indices
	obj->vertices = realloc(obj->vertices,obj->num_vertices  * sizeof(obj_vertex_t));
	obj->indices  = realloc(obj->indices ,obj->num_indices   * sizeof(ushort));
	
	//printf("Obj %s has %d vertices.\n",filename,obj->num_vertices);
	//printf("Obj %s has %d indices.\n",filename,obj->num_indices);
	
	OBJ_DestroyVerticeCache();
	
	//Generate lighting infos.
	OBJ_GenerateLightingInfo(obj);
	
	return 1;
}
Ejemplo n.º 24
0
void DevAssetManager::CloseFile( PakFileHandle file )
{
	const FileHandle fileHandle = Pak_To_OS_File_Handle( file ); 
	return FS_CloseFile( fileHandle );
}
Ejemplo n.º 25
0
char MD5_LoadMesh(md5_mesh_t* mesh, const char* filename)
{
	filehandle_t* fhandle = 0;
	vertex_t* currentVertex = 0;
	ushort verticesCounter=0;
	int versionNumber = 0;
	int i;
	
	 
	
	fhandle = FS_OpenFile(filename, "rt");
	
	if (!fhandle)
	{
		return 0;
	}
	
	LE_pushLexer();
	LE_init(fhandle);
	
	
	mesh->memLocation = MD5_MEMLOC_RAM;
	
	//printf("[MD5_LoadEntity] Loading MD5 '%s' .\n",filename); 

	
	
	while (LE_hasMoreData()) 
	{
		LE_readToken();
		
		if(!strcmp("MD5Version", LE_getCurrentToken()))
		{
			versionNumber = LE_readReal();
			if (versionNumber != 10)
			{
				printf ("[MD5_Loader ERROR] : %s has a bad model version (%d)\n",filename,versionNumber);
				return 0;
			}
		}
		else
		if (!strcmp("numJoints", LE_getCurrentToken()))
		{
			mesh->numBones = LE_readReal();
			mesh->bones = (md5_bone_t*)calloc(mesh->numBones,sizeof(md5_bone_t));
			//printf("[MD5_LoadEntity] Found numJoints: %d.\n",mesh->numBones);
		}
		else
		if (!strcmp("mesh", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found mesh.\n");
			MD5_ReadMesh(mesh);  
		}
		else
		if (!strcmp("numMeshes", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found numMeshes.\n");
			if(LE_readReal() > 1)
			{
				printf("[MD5_Loader ERROR] %s has more than one mesh: Not supported.\n",filename);
				return 0;
			}
		}		   
		else
		if (!strcmp("joints", LE_getCurrentToken()))
		{
			//printf("[MD5_LoadEntity] Found joints.\n");
			MD5_ReadJoints(mesh->bones,mesh->numBones);
		}		   
		   
	}
	

	
	mesh->vertexArray = (vertex_t*)calloc(mesh->numVertices, sizeof(vertex_t));
	mesh->indices = (ushort*)calloc(mesh->numTriangles * 3,sizeof(ushort));
	
	//Write indices
	mesh->numIndices=0 ;
	for (i = 0  ; i < mesh->numTriangles; i++)
	{
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[0];
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[1];
		mesh->indices[mesh->numIndices++] = mesh->triangles[i].index[2];
	}
	
	//Write textureCoo
	//Set all textures coordinate once for all, this will never change
	currentVertex = mesh->vertexArray;
	for(verticesCounter=0 ; verticesCounter < mesh->numVertices ; verticesCounter++,currentVertex++)
	{
		currentVertex->text[0] = mesh->vertices[verticesCounter].st[0];
		currentVertex->text[1] = mesh->vertices[verticesCounter].st[1];
	}
	
	//printf("[MD5 Loader] %d vertices.\n",mesh->numVertices);
	//printf("[MD5 Loader] %d triangles.\n",mesh->numTriangles);
	//printf("[MD5 Loader] %d indices.\n",mesh->numIndices);
	
	
	
	MD5_GenerateSkin(mesh,mesh->bones);
	MD5_GenerateLightingInfo(mesh);
	MD5_GenerateSkin(mesh,mesh->bones);
	
	//Bounding box
	MD5_GenerateModelSpaceBBox(mesh);
	
	if (TRACE_BLOCK)
	{
	if (!strcmp(filename,"data/models/misc/FRA200L.obj.md5mesh"))
	{
		currentVertex = mesh->vertexArray;
		printf("Listing Vertices.\n");
		for (i=0; i < mesh->numVertices ; i++,currentVertex++) 
		{
			printf("vertex: %d/%hu  (norm: %hd , %hd , %hd ) (text: %hd , %hd ) (pos: %f , %f , %f )\n",
				   i,
				   mesh->numVertices-1,   
				   currentVertex->normal[0],
				   currentVertex->normal[1],
				   currentVertex->normal[2],
				   currentVertex->text[0],
				   currentVertex->text[1],
				   currentVertex->pos[0],
				   currentVertex->pos[1],
				   currentVertex->pos[2]	   
				   );
		}


		printf("Listing indices.\n");
		for(i=0;  i < mesh->numIndices ; i++)
		{
			printf("indice: %d/%hu, vertex: %hu   (norm: %hd , %hd , %hd ) (text: %hd , %hd ) (pos: %f , %f , %f )\n",
				   i,
				   mesh->numIndices-1,   
					mesh->indices[i],
				   mesh->vertexArray[mesh->indices[i]].normal[0],
				   mesh->vertexArray[mesh->indices[i]].normal[1],
				   mesh->vertexArray[mesh->indices[i]].normal[2],
				   mesh->vertexArray[mesh->indices[i]].text[0],
				   mesh->vertexArray[mesh->indices[i]].text[1],
				   mesh->vertexArray[mesh->indices[i]].pos[0],
				   mesh->vertexArray[mesh->indices[i]].pos[1],
				   mesh->vertexArray[mesh->indices[i]].pos[2]	 
				   );
		}
	}
	}

	FS_CloseFile(fhandle);
	LE_popLexer();
	
	
	//Cache mesh to speed up future loading.
	
	return 1;
}
Ejemplo n.º 26
0
/**
 * @brief Writes lines containing "bind key value"
 * @param[in] filename Path to print the keybinding too
 * @sa Com_WriteConfigToFile
 */
void Key_WriteBindings (const char* filename)
{
	int i;
	/* this gets true in case of an error */
	qboolean deleteFile = qfalse;
	qFILE f;
	int cnt = 0;

	OBJZERO(f);
	FS_OpenFile(filename, &f, FILE_WRITE);
	if (!f.f) {
		Com_Printf("Couldn't write %s.\n", filename);
		return;
	}

	FS_Printf(&f, "// generated by ufo, do not modify\n");
	FS_Printf(&f, "// If you want to know the keyname of a specific key - set in_debug cvar to 1 and press the key\n");
	FS_Printf(&f, "unbindallmenu\n");
	FS_Printf(&f, "unbindall\n");
	FS_Printf(&f, "unbindallbattle\n");
	/* failfast, stops loop for first occurred error in fprintf */
	for (i = 0; i < K_LAST_KEY && !deleteFile; i++)
		if (menuKeyBindings[i] && menuKeyBindings[i][0]) {
			if (FS_Printf(&f, "bindmenu %s \"%s\"\n", Key_KeynumToString(i), menuKeyBindings[i]) < 0)
				deleteFile = qtrue;
			cnt++;
		}
	for (i = 0; i < K_LAST_KEY && !deleteFile; i++)
		if (keyBindings[i] && keyBindings[i][0]) {
			if (FS_Printf(&f, "bind %s \"%s\"\n", Key_KeynumToString(i), keyBindings[i]) < 0)
				deleteFile = qtrue;
			cnt++;
		}
	for (i = 0; i < K_LAST_KEY && !deleteFile; i++)
		if (battleKeyBindings[i] && battleKeyBindings[i][0]) {
			if (FS_Printf(&f, "bindbattle %s \"%s\"\n", Key_KeynumToString(i), battleKeyBindings[i]) < 0)
				deleteFile = qtrue;
			cnt++;
		}

	for (i = 0; i < UI_GetKeyBindingCount(); i++) {
		const char *path;
		uiKeyBinding_t*binding = UI_GetKeyBindingByIndex (i);
		if (binding->node == NULL)
			continue;
		if (binding->property == NULL)
			path = va("%s", UI_GetPath(binding->node));
		else
			path = va("%s@%s", UI_GetPath(binding->node), binding->property->string);

		if (FS_Printf(&f, "bindui %s \"%s\"\n", Key_KeynumToString(binding->key), path) < 0)
			deleteFile = qtrue;
	}

	FS_CloseFile(&f);
	if (!deleteFile && cnt)
		Com_Printf("Wrote %s\n", filename);
	else
		/* error in writing the keys.cfg - remove the file again */
		FS_RemoveFile(va("%s/%s", FS_Gamedir(), filename));
}
Ejemplo n.º 27
0
/**
 * Take a screenshot of the frame buffer
 * @param[in] x
 * @param[in] y
 * @param[in] width
 * @param[in] height
 * @param[in] filename Force to use a filename. Else NULL to autogen a filename
 * @param[in] ext Force to use an image format (tga/png/jpg). Else NULL to use value of r_screenshot_format
 */
void R_ScreenShot (int x, int y, int width, int height, const char *filename, const char *ext)
{
	char	checkName[MAX_OSPATH];
	int		type, shotNum, quality = 100;
	qFILE	f;
	int rowPack;

	glGetIntegerv(GL_PACK_ALIGNMENT, &rowPack);
	glPixelStorei(GL_PACK_ALIGNMENT, 1);

	/* Find out what format to save in */
	if (ext == NULL)
		ext = r_screenshot_format->string;

	if (!Q_strcasecmp(ext, "png"))
		type = SSHOTTYPE_PNG;
	else if (!Q_strcasecmp(ext, "jpg"))
		type = SSHOTTYPE_JPG;
	else
		type = SSHOTTYPE_TGA_COMP;

	/* Set necessary values */
	switch (type) {
	case SSHOTTYPE_TGA_COMP:
		Com_Printf("Taking TGA screenshot...\n");
		ext = "tga";
		break;

	case SSHOTTYPE_PNG:
		Com_Printf("Taking PNG screenshot...\n");
		ext = "png";
		break;

	case SSHOTTYPE_JPG:
		if (Cmd_Argc() == 3)
			quality = atoi(Cmd_Argv(2));
		else
			quality = r_screenshot_jpeg_quality->integer;
		if (quality > 100 || quality <= 0)
			quality = 100;

		Com_Printf("Taking JPG screenshot (at %i%% quality)...\n", quality);
		ext = "jpg";
		break;
	}

	/* Find a file name to save it to */
	if (filename) {
		Com_sprintf(checkName, sizeof(checkName), "scrnshot/%s.%s", filename, ext);
	} else {
		for (shotNum = 0; shotNum < 1000; shotNum++) {
			Com_sprintf(checkName, sizeof(checkName), "scrnshot/ufo%i%i.%s", shotNum / 10, shotNum % 10, ext);
			if (FS_CheckFile("%s", checkName) == -1)
				break;
		}
		if (shotNum == 1000) {
			Com_Printf("R_ScreenShot_f: screenshot limit (of 1000) exceeded!\n");
			return;
		}
	}

	/* Open it */
	FS_OpenFile(checkName, &f, FILE_WRITE);
	if (!f.f) {
		Com_Printf("R_ScreenShot_f: Couldn't create file: %s\n", checkName);
		return;
	}

	/* Allocate room for a copy of the framebuffer */
	byte* const buffer = Mem_PoolAllocTypeN(byte, width * height * 3, vid_imagePool);
	if (!buffer) {
		Com_Printf("R_ScreenShot_f: Could not allocate %i bytes for screenshot!\n", width * height * 3);
		FS_CloseFile(&f);
		return;
	}

	/* Read the framebuffer into our storage */
	glReadPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer);
	R_CheckError();

	/* Write */
	switch (type) {
	case SSHOTTYPE_TGA_COMP:
		R_WriteCompressedTGA(&f, buffer, width, height);
		break;

	case SSHOTTYPE_PNG:
		R_WritePNG(&f, buffer, width, height);
		break;

	case SSHOTTYPE_JPG:
		R_WriteJPG(&f, buffer, width, height, quality);
		break;
	}

	/* Finish */
	FS_CloseFile(&f);
	Mem_Free(buffer);

	Com_Printf("Wrote %s to %s\n", checkName, FS_Gamedir());
	glPixelStorei(GL_PACK_ALIGNMENT, rowPack);
}
Ejemplo n.º 28
0
/**
 * \brief Load wav file.
 * \param[in] filename Name of wav file to load.
 * \param[in] wav wav data.
 * \param[in] info wav sound info.
 * \return True if file loaded, otherwise false.
 * \note Caller is responsible for freeing wav data by calling Z_Free.
 */
PUBLIC _boolean LoadWavInfo( const char *filename, W8 **wav, soundInfo_t *info )
{
	filehandle_t *hFile;
	W8	*data;
	W32	wavlength;

	hFile = FS_OpenFile( filename, FA_FILE_FLAG_LOAD );
	if( ! hFile )
	{
		return false;
	}

	data = (PW8)FS_GetLoadedFilePointer( hFile, SEEK_SET );
	wavlength = FS_GetFileSize( hFile );

	iff_data = data;
	iff_end = data + wavlength;

	// look for RIFF signature
	Wav_FindChunk( "RIFF" );
	if( ! (iff_pdata && ! com_strnicmp( iff_pdata + 8, "WAVE", 4 ) ) )
	{
		Com_DPrintf( "[LoadWavInfo]: Missing RIFF/WAVE chunks (%s)\n", filename );
		FS_CloseFile( hFile );

		return false;
	}

	// Get "fmt " chunk
	iff_data = iff_pdata + 12;

	Wav_FindChunk( "fmt " );
	if( ! iff_pdata )
	{
		Com_DPrintf( "[LoadWavInfo]: Missing fmt chunk (%s)\n", filename );
		FS_CloseFile( hFile );

		return false;
	}

	iff_pdata += 8;

	if( Wav_GetLittleShort() != 1 )
	{
		Com_DPrintf( "[LoadWavInfo]: Microsoft PCM format only (%s)\n", filename );
		FS_CloseFile( hFile );

		return false;
	}

	info->channels = Wav_GetLittleShort();
	info->sample_rate = Wav_GetLittleLong();

	iff_pdata += 4;

	info->sample_size = Wav_GetLittleShort(); // Bytes Per Sample

	if (info->sample_size != 1 && info->sample_size != 2)
	{
		Com_DPrintf( "[LoadWavInfo]: only 8 and 16 bit WAV files supported (%s)\n", filename );
		FS_CloseFile( hFile );

		return false;
	}

	iff_pdata += 2;


	// Find data chunk
	Wav_FindChunk( "data" );
	if( ! iff_pdata )
	{
		Com_DPrintf( "[LoadWavInfo]: missing 'data' chunk (%s)\n", filename );
		FS_CloseFile( hFile );

		return false;
	}

	iff_pdata += 4;
	info->samples = Wav_GetLittleLong() / info->sample_size;

	if( info->samples <= 0 )
	{
		Com_DPrintf( "[LoadWavInfo]: file with 0 samples (%s)\n", filename );
		FS_CloseFile( hFile );

		return false;
	}

	// Load the data
	*wav = Z_Malloc( info->samples * info->sample_size );
	memcpy( *wav, data + (iff_pdata - data), info->samples * info->sample_size );

	FS_CloseFile( hFile );

	return true;
}
Ejemplo n.º 29
0
void debug_filesystem(void)
{
	FS_HANDLE FileHandle=0;
	UINT32    command;
	FILE_INFO fileinfo={0};
	UINT08    ShortFileName[13]={0};
	UINT08    FileBuffer[512];
	int       FileNo;
	int       iter;

	do
	{
		ShowMenu();
		command = ReadKeyInput("Select Command");

		switch(command)
		{
			case 0x01:
				{
				int ret;
				ret = FS_OpenDriver();

				if(ret == 1)
					dbgprint("Open Driver Success!\n");
				else
					dbgprint("Open Driver Error!\n");
				}
				break;

			case 0x02:
				rprint0n("No Use\n");
				break;

			case 0x03:
				//Mount
				if(!FS_Mount())
				{
					rprint0n("Mount Fail!\n");
					break;
				}
				//Open Root Dir
				fileinfo.Target[0] = '*';
				fileinfo.Target[1] = '.';
				fileinfo.Target[2] = '*';

				if(!FS_OpenRootDir(&fileinfo))
				{
					rprint0n("Open Root Directory Fail!\n");
					break;
				}
				//Find Start
				FS_FindStart(&fileinfo);

				//Show File Name
				for(iter=0; iter<fileinfo.TotalCount; iter++)
				{
					rprint0n("File%02d : ", iter);
					if(FS_GetFile(iter, &fileinfo))
					{
						if(FS_GetFileName(&fileinfo, ShortFileName) )
						{
							rprint0n("%s : ", ShortFileName);
							if(FS_IsDirectory(&fileinfo))
							{
								rprint0n("Directory", ShortFileName);
							}
							else
							{
								rprint0n("File", ShortFileName);
							}
							#if 0
							{
							UINT08 index;
							UINT08 LongFileName[512]={0};
							index = FS_GetLongFileName(&fileinfo, LongFileName);
							ViewLongName(LongFileName, index);
							}
							#endif
						}
					}
					rprint0n("\n");
				}
				break;
			case 0x04:
				FileNo = (int)ReadDecimalKeyInput("File Number");
				if(FileNo >= fileinfo.TotalCount)
				{
					rprint0n("Invalid File Number !\n");	break;
				}

				//Get File
				if(FS_GetFile(FileNo, &fileinfo))
				{
					if(FS_IsDirectory(&fileinfo))
					{
						//rprint0n("File Open Fail - Directory\n");
						if(FS_OpenDir(&fileinfo))
						{
							FS_FindStart(&fileinfo);

							//Show File Name
							for(iter=0; iter<fileinfo.TotalCount; iter++)
							{
								rprint0n("File%02d : ", iter);
								if(FS_GetFile(iter, &fileinfo))
								{
									if(FS_GetFileName(&fileinfo, ShortFileName) )
									{
										rprint0n("%s : ", ShortFileName);

										if(FS_IsDirectory(&fileinfo))
										{
											rprint0n("Directory", ShortFileName);
										}
										else
										{
											rprint0n("File", ShortFileName);
										}
									}
								}
								rprint0n("\n");
							}
						}
						break;
					}
					//Open File
					FileHandle = FS_OpenFile(&fileinfo);
					if(FileHandle == 0xFFFFFFFF)
					{
						rprint0n("Invalid File Handle!\n");	break;
					}
				}
				rprint0n("File Open - Index %d\n", FileNo);
				break;
			case 0x05:
				if(FileHandle == 0)          break;
				if(FileHandle == 0xFFFFFFFF) break;
				if(FileHandle == 0xCCCCCCCC) break;

				//Read File
				if(FS_ReadFile(FileHandle, FileBuffer, 1))
				{
					dbgprint("^B^=============    File Read   ===============\n");
					hexdump("Read File", FileBuffer, 512);
					dbgprint("^B^============================================\n");
					break;
				}
				rprint0n("File Read Fail! or End of File\n");
				break;

			case 0x06:
				rprint0n("File Close\n");
				FS_CloseFile(FileHandle);
				//Close File
				break;
			case 0x07:
				//UnMount
				break;
			case 0xFF:
				command = INVALID_COMMAND;
			}
	}while(command != INVALID_COMMAND);
}
Ejemplo n.º 30
0
/*
-----------------------------------------------------------------------------
 Function: LoadOggInfo -Load ogg file.
 
 Parameters: filename -[in] Name of wav file to load.
			 wav -[out] wav data.
			 info -[out] wav sound info.
 
 Returns: True if file loaded, otherwise false.
 
 Notes: Caller is responsible for freeing wav data by calling Z_Free.

-----------------------------------------------------------------------------
*/
PUBLIC _boolean LoadOggInfo( const char *filename, W8 **wav, soundInfo_t *info )
{
	W8	*data;
	int size;
	int dummy;
	char *newFilename;
	int len;
	OggVorbis_File	vorbisFile;
	vorbis_info		vorbisInfo;
	ov_callbacks	vorbisCallbacks = {ovc_read, ovc_seek, ovc_close, ovc_tell};
	int ret;
	
	newFilename = strdup( filename );
	
	len = strlen( newFilename );
	if ( len < 5 || strcmp( newFilename + len - 4, ".wav" ) ) {
		free( newFilename );
		return false;
	}
	
	newFilename[ len - 3 ] = 'o';
	newFilename[ len - 2 ] = 'g';
	newFilename[ len - 1 ] = 'g';
		
	fh = FS_OpenFile( newFilename, 0 );
	if( ! fh )
	{
		free( newFilename );
		return false;
	}

	if( (ret = ov_open_callbacks( fh, &vorbisFile, NULL, 0, vorbisCallbacks )) < 0 ) {
		free( newFilename );
		return false;
	}

	vorbisInfo = *ov_info( &vorbisFile, -1 );
	if( vorbisInfo.channels != 1 && vorbisInfo.channels != 2 )
	{
		Com_Printf( "Only mono and stereo OGG files supported (%s)\n", newFilename );
		free( newFilename );
		return false;
	}
	
	info->channels = vorbisInfo.channels;
	info->sample_rate = vorbisInfo.rate;
	info->sample_size = 2;

#define BUFFER_SIZE ( 128 * 1024 )
	
	data = (W8 *)malloc( BUFFER_SIZE );
	size = 0;
	
	while( size < BUFFER_SIZE )
	{
		int read = 0;
		read = ov_read( &vorbisFile, (char *)data + size, BUFFER_SIZE - size, &dummy );
		if( read == 0 )
		{
			break;
		}
		
		if( read <= 0 )
		{
			Com_Printf( "Only mono and stereo OGG files supported (%s)\n", newFilename );
			free( newFilename );
			return false;
		}
		
		size += read;
	}

	info->samples = size / ( info->channels * info->sample_size );

//	Com_Printf("Loaded %s: channels=%d, sample_rate=%d, sample_size=%d, samples=%d.  \n", newFilename, info->channels, info->sample_rate, info->sample_size, info->samples );
	free( newFilename );

	*wav = (W8 *)Z_Malloc( size );
	memcpy(*wav, data, size );
	free( data );

	
	FS_CloseFile( fh );

	return true;
}