Esempio n. 1
0
/*
========
LoadPCX
========
*/
byte* LoadPCX (vfsfile_t *f)
{
	pcx_t	*pcx, pcxbuf;
	byte	palette[768];
	byte	*pix, *image_rgba;
	int		x, y;
	int		dataByte, runLength;
	int		count;

//
// parse the PCX file
//
	VFS_READ (f, &pcxbuf, sizeof(pcxbuf));

	pcx = &pcxbuf;

	if (pcx->manufacturer != 0x0a
		|| pcx->version != 5
		|| pcx->encoding != 1
		|| pcx->bits_per_pixel != 8
		|| pcx->xmax > 320
		|| pcx->ymax > 256)
	{
		Con_Printf ("Bad pcx file\n");
		VFS_CLOSE(f);
		return NULL;
	}

	// seek to palette
	VFS_SEEK(f, VFS_GETLEN(f)-768);
	VFS_READ(f, palette, 768);


	VFS_SEEK(f, sizeof(pcxbuf) - 4);

	count = (pcx->xmax+1) * (pcx->ymax+1);
	image_rgba = malloc( count * 4);

	for (y=0 ; y<=pcx->ymax ; y++)
	{
		pix = image_rgba + 4*y*(pcx->xmax+1);
		for (x=0 ; x<=pcx->xmax ; )
		{
			dataByte = VFS_GETC(f);

			if((dataByte & 0xC0) == 0xC0)
			{
				runLength = dataByte & 0x3F;
				dataByte = VFS_GETC(f);
			}
			else
				runLength = 1;

			while(runLength-- > 0)
			{
				pix[0] = palette[dataByte*3];
				pix[1] = palette[dataByte*3+1];
				pix[2] = palette[dataByte*3+2];
				pix[3] = 255;
				pix += 4;
				x++;
			}
		}
	}
	VFS_CLOSE(f);
	image_width = pcx->xmax+1;
	image_height = pcx->ymax+1;
	return image_rgba;
}
Esempio n. 2
0
/*
===============
Host_Loadgame_f
===============
*/
void Host_Loadgame_f (void)
{
	char	name[MAX_OSPATH], temp[MAX_OSPATH];
	vfsfile_t	*f;
	char	mapname[MAX_QPATH];
	float	time, tfloat;
	char	str[32768], *start, *c;
	int		i, r, len, n;
	edict_t	*ent;
	int		entnum;
	int		version;
	float			spawn_parms[NUM_SPAWN_PARMS];

	if (cmd_source != src_command)
		return;

	if (Cmd_Argc() != 2)
	{
		Con_Printf ("load <savename> : load a game\n");
		return;
	}

	cls.demonum = -1;		// stop demo loop in case this fails

//	sprintf (name, "%s", Cmd_Argv(1));
	strcpy (name, Cmd_Argv(1));
	COM_DefaultExtension (name, ".sav");
	
// we can't call SCR_BeginLoadingPlaque, because too much stack space has
// been used.  The menu calls it before stuffing loadgame command
//	SCR_BeginLoadingPlaque ();

	Con_Printf ("Loading game from %s...\n", name);
//	f = fopen (name, "r");
	f = FS_OpenVFS(name, "rb", FS_GAMEONLY);
	if (!f)
	{
		Con_Printf ("ERROR: couldn't open.\n");
		return;
	}

//	fscanf (f, "%i\n", &version);
	version = atoi(VFS_GETS(f, name, sizeof(name)));
	if (version != SAVEGAME_VERSION)
	{
//		fclose (f);
		Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
		VFS_CLOSE (f);
		return;
	}
//	fscanf (f, "%s\n", str);
	VFS_GETS(f, str, sizeof(str));
	for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
		spawn_parms[i] = atof(VFS_GETS(f, temp, sizeof(temp)));
//		fscanf (f, "%f\n", &spawn_parms[i]);
// this silliness is so we can load 1.06 save files, which have float skill values
//	fscanf (f, "%f\n", &tfloat);
	tfloat = atof(VFS_GETS(f, temp, sizeof(temp))); // temp buf
	current_skill = (int)(tfloat + 0.1);
	Cvar_SetValue ("skill", (float)current_skill);

#ifdef QUAKE2
	Cvar_SetValue ("deathmatch", 0);
	Cvar_SetValue ("coop", 0);
	Cvar_SetValue ("teamplay", 0);
#endif

//	fscanf (f, "%s\n",mapname);
//	fscanf (f, "%f\n",&time);
	VFS_GETS(f, mapname, sizeof(mapname));
	for (c = mapname+strlen(mapname)-1; c>=mapname && (*c == '\n' || *c == '\r'); *c--='\0');
	time = atof(VFS_GETS(f, temp, sizeof(temp)));

	CL_Disconnect_f ();
	
	allowcheats = sv_cheats.value != 0; // sv_cheats

	// if the video isn't initialized already, it needs to be
	Host_InitVideo();

#ifdef QUAKE2
	SV_SpawnServer (mapname, NULL);
#else
	SV_SpawnServer (mapname);
#endif
	if (!sv.active)
	{
		Con_Printf ("Couldn't load map\n");
		VFS_CLOSE (f);
		return;
	}
	sv.paused = true;		// pause until all clients connect
	sv.loadgame = true;

// load the light styles

	for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
	{
//		fscanf (f, "%s\n", str);
		VFS_GETS(f, str, sizeof(str));
//		sv.lightstyles[i] = Hunk_Alloc (strlen(str)+1); // this is no longer necessary, changed to straight array
		for (c = str+strlen(str)-1; c>=str && (*c == '\n' || *c == '\r'); *c--='\0');
		strcpy (sv.lightstyles[i], str);
	}

// load the edicts out of the savegame file
	entnum = -1;		// -1 is the globals
	len = VFS_GETLEN(f);
	n = 0;
//	while (!feof(f))
	for(;;)
	{
		for (i=0 ; i<sizeof(str)-1 ; i++)
		{
//			r = fgetc (f);
			r = VFS_GETC(f);
			if (r == -1 || !r)
				break;
			str[i] = r;
			if (r == '}')
			{
				i++;
				break;
			}
		}
		if (r == -1 || !r)
			break;
		if (i == sizeof(str)-1)
			Sys_Error ("Loadgame buffer overflow");
		str[i] = 0;
		start = str;
		start = COM_Parse(str);
		if (!com_token[0])
			break;		// end of file
		if (strcmp(com_token,"{"))
			Sys_Error ("First token isn't a brace");
			
		if (entnum == -1)
		{	// parse the global vars
			ED_ParseGlobals (start);
		}
		else
		{	// parse an edict

			ent = EDICT_NUM(entnum);
			memset (&ent->v, 0, progs->entityfields * 4);
			ent->free = false;
			ED_ParseEdict (start, ent);
	
		// link it into the bsp tree
			if (!ent->free)
				SV_LinkEdict (ent, false);
		}

		entnum++;
		n++;
	}
	
	sv.num_edicts = entnum;
	sv.time = time;

//	fclose (f);
	VFS_CLOSE (f);

	for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
		svs.clients->spawn_parms[i] = spawn_parms[i];

	if (cls.state != ca_dedicated)
	{
		CL_EstablishConnection ("local");
		Host_Reconnect_f ();
	}
}
Esempio n. 3
0
/* reads a single byte */
gint i_midi_file_read_byte( midifile_t * mf )
{
  ++mf->file_offset;
  return VFS_GETC(mf->file_pointer);
}