static void *FSGZIP_LoadGZipFile(vfsfile_t *gziphandle, const char *desc)
{
	gzipfile_t *gzip;
	const char *base;
	char *ext;
	int fd;

	gzip = Q_calloc(1, sizeof(*gzip));
	strlcpy(gzip->filename, desc, sizeof(gzip->filename));
	if (gziphandle == NULL) goto fail;
	gzip->raw = gziphandle;

	fd = fileno(((vfsosfile_t *)gziphandle)->handle); // <-- ASSUMPTION! that file is OS
	gzip->handle = (vfsfile_t *)gzdopen(dup(fd), "r");
	gzip->references = 1;

	/* Remove the .gz from the file.name */
	base = COM_SkipPath(desc);
	ext = COM_FileExtension(desc);
	if (strcmp(ext, "gz") == 0) {
		COM_StripExtension(base, gzip->file.name, sizeof(gzip->file.name));
	} else {
		strlcpy(gzip->file.name, base, sizeof(gzip->file.name));
	}

	return gzip;

fail:
	// Q_free is safe to call on NULL pointers
	Q_free(gzip);
	return NULL;
}
Exemple #2
0
static vfsfile_t *FSPAK_OpenVFS(void *handle, flocation_t *loc, char *mode)
{
	pack_t *pack = (pack_t*)handle;
	vfspack_t *vfsp;

	if (strcmp(mode, "rb"))
		return NULL; //urm, unable to write/append

	vfsp = Q_calloc(1, sizeof(*vfsp));

	vfsp->parentpak = pack;
	vfsp->parentpak->references++;

	vfsp->startpos   = loc->offset;
	vfsp->length     = loc->len;
	vfsp->currentpos = vfsp->startpos;

	vfsp->funcs.ReadBytes     = strcmp(mode, "rb") ? NULL : VFSPAK_ReadBytes;
	vfsp->funcs.WriteBytes    = strcmp(mode, "wb") ? NULL : VFSPAK_WriteBytes;
	vfsp->funcs.Seek		  = VFSPAK_Seek;
	vfsp->funcs.Tell		  = VFSPAK_Tell;
	vfsp->funcs.GetLen	      = VFSPAK_GetLen;
	vfsp->funcs.Close	      = VFSPAK_Close;
	vfsp->funcs.Flush         = NULL;
	if (loc->search)
		vfsp->funcs.copyprotected = loc->search->copyprotected;

	return (vfsfile_t *)vfsp;
}
static vfsfile_t *FSGZIP_OpenVFS(void *handle, flocation_t *loc, char *mode) 
{
	gzipfile_t *gzip = (gzipfile_t *)handle;
	vfsgzipfile_t *vfsgz;

	if (strcmp(mode, "rb"))
		return NULL;

	vfsgz = Q_calloc(1, sizeof(*vfsgz));
	vfsgz->parent = gzip;
	gzip->references++;

	vfsgz->startpos   = loc->offset;
	vfsgz->length     = loc->len;
	vfsgz->currentpos = vfsgz->startpos;

	vfsgz->funcs.ReadBytes  = strcmp(mode, "rb") ? NULL : VFSGZIP_ReadBytes;
	vfsgz->funcs.WriteBytes = strcmp(mode, "wb") ? NULL : VFSGZIP_WriteBytes;
	vfsgz->funcs.Seek       = VFSGZIP_Seek;
	vfsgz->funcs.Tell       = VFSGZIP_Tell;
	vfsgz->funcs.GetLen     = VFSGZIP_GetLen;
	vfsgz->funcs.Close      = VFSGZIP_Close;
	vfsgz->funcs.Flush      = VFSGZIP_Flush;
	if (loc->search)
		vfsgz->funcs.copyprotected = loc->search->copyprotected;

	return (vfsfile_t *)vfsgz;
}
static sb_qtvplayer_t *QTVList_New_Player(void)
{
	sb_qtvplayer_t *ret;

	ret = Q_calloc(sizeof (sb_qtvplayer_t), 1);

	return ret;
}
static sb_qtventry_t *QTVList_New_Entry(void)
{
	sb_qtventry_t *ret;

	ret = Q_calloc(sizeof (sb_qtventry_t), 1);

	return ret;
}
Exemple #6
0
void R_Bloom_InitTextures( void )
{
	unsigned char *data;
	int maxtexsize;
	size_t size;

	// Find closer power of 2 to screen size.
	for (screen_texture_width = 1;  screen_texture_width  < glwidth;  screen_texture_width *= 2);
	for (screen_texture_height = 1; screen_texture_height < glheight; screen_texture_height *= 2);

    // Disable blooms if we can't handle a texture of that size.
	glGetIntegerv (GL_MAX_TEXTURE_SIZE, &maxtexsize);
	if (screen_texture_width > maxtexsize || screen_texture_height > maxtexsize)
	{
		screen_texture_width = screen_texture_height = 0;
		Cvar_SetValue (&r_bloom, 0);
		Com_Printf ("WARNING: 'R_InitBloomScreenTexture' too high resolution for Light Bloom. Effect disabled\n");
		return;
	}

	// Init the screen texture.
	size = screen_texture_width * screen_texture_height * sizeof (int);
	data = Q_malloc (size);
	memset (data, 255, size);
	//r_bloomscreentexture = GL_LoadTexture ( "***r_screenbackuptexture***", screen_texture_width, screen_texture_height, data, 0, 4); // false, false, 4);
	
	if (!r_bloomscreentexture)
		r_bloomscreentexture = texture_extension_number++;

	GL_Bind (r_bloomscreentexture);
	glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, screen_texture_width, screen_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
	glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

	Q_free (data);

	// Validate bloom size and init the bloom effect texture.
	R_Bloom_InitEffectTexture();

	// If screensize is more than 2x the bloom effect texture, set up for stepped downsampling.
	r_bloomdownsamplingtexture = 0;
	r_screendownsamplingtexture_size = 0;
	if( glwidth > (BLOOM_SIZE * 2) && !r_bloom_fast_sample.value )
	{
		r_screendownsamplingtexture_size = (int)(BLOOM_SIZE * 2);
		data = Q_calloc (r_screendownsamplingtexture_size * r_screendownsamplingtexture_size, sizeof (int));
		r_bloomdownsamplingtexture = GL_LoadTexture ( "***r_bloomdownsamplingtexture***", r_screendownsamplingtexture_size, r_screendownsamplingtexture_size, data, 0, 4);
		Q_free (data);
	}

	// Init the screen backup texture.
	if (r_screendownsamplingtexture_size)
		R_Bloom_InitBackUpTexture (r_screendownsamplingtexture_size, r_screendownsamplingtexture_size);
	else
		R_Bloom_InitBackUpTexture (BLOOM_SIZE, BLOOM_SIZE);
}
Exemple #7
0
//=================
// R_Bloom_InitBackUpTexture
// =================
void R_Bloom_InitBackUpTexture( int width, int height )
{
	unsigned char *data;
	
	data = (unsigned char *) Q_calloc (width * height, sizeof (int));

	r_screenbackuptexture_size = width;

	r_bloombackuptexture = GL_LoadTexture ("***r_bloombackuptexture***", width, height, data, 0, 4);

	Q_free (data);
}
Exemple #8
0
static void VID_SetupModeList(void)
{
	int i;

	Q_free(modelist);

	modelist_count = SDL_GetNumDisplayModes(0);
	modelist = Q_calloc(modelist_count, sizeof(*modelist));

	for (i = 0; i < modelist_count; i++) {
		SDL_GetDisplayMode(0, i, &modelist[i]);
	}
}
//
// Label - Sets the text of a label.
//
void EZ_label_SetText(ez_label_t *label, const char *text)
{
	int text_len = strlen(text) + 1;

	Q_free(label->text);

	if (text)
	{
		label->text = Q_calloc(text_len, sizeof(char));
		strlcpy(label->text, text, text_len);
	}

	CONTROL_RAISE_EVENT(NULL, label, ez_label_t, OnTextChanged, NULL);
}
Exemple #10
0
void Log_AutoLogging_StartMatch(char *logname) {
	char extendedname[MAX_OSPATH * 2], *fullname;
	FILE *templog;
	void *buf;

	temp_log_ready = false;

	if (!match_auto_logconsole.value)
		return;

	if (Log_IsLogging()) {
		if (autologging) {		
			
			autologging = false;
			Log_Stop();
		} else {
			Com_Printf("Auto console logging skipped (already logging)\n");
			return;
		}
	}


	strlcpy(auto_matchname, logname, sizeof(auto_matchname));

	strlcpy (extendedname, TEMP_LOG_NAME, sizeof(extendedname));
	COM_ForceExtensionEx (extendedname, ".log", sizeof (extendedname));
	fullname = va("%s/%s", MT_TempDirectory(), extendedname);


	if (!(templog = fopen (fullname, log_readable.value ? "w" : "wb"))) {
		FS_CreatePath(fullname);
		if (!(templog = fopen (fullname, log_readable.value ? "w" : "wb"))) {
			Com_Printf("Error: Couldn't open %s\n", fullname);
			return;
		}
	}

	buf = Q_calloc(1, LOGFILEBUFFER);
	if (!buf) {
		Com_Printf("Not enough memory to allocate log buffer\n");
		return;
	}
	memlogfile = FSMMAP_OpenVFS(buf, LOGFILEBUFFER);

	Com_Printf ("Auto console logging commenced\n");

	logfile = templog;
	autologging = true;
	auto_starttime = cls.realtime;
}
Exemple #11
0
char *str_repeat (char *str, int amount)
{
    char *ret = NULL;
    int i = 0;

    if (str == NULL)
        return NULL;

    if (amount <= 0)
        return "";

    ret = (char *) Q_calloc(strlen(str) * amount + 1, sizeof(char)); 

    for (i = 0; i < amount; i++)
        strcat(ret, str);

    return ret;
}
Exemple #12
0
// Slightly different version below were we don't take in a FILE *
vfsfile_t *VFSOS_Open(char *name, FILE *f, char *mode)
{
	vfsosfile_t *file;

	if (!strchr(mode, 'r') && !strchr(mode, 'w'))
		return NULL; // hm, no read and no write mode?

	if (!f) {
		qbool read  = !!strchr(mode, 'r');
		qbool write = !!strchr(mode, 'w');
		qbool text  = !!strchr(mode, 't');
		char newmode[10];
		int modec = 0;

		if (read)
			newmode[modec++] = 'r';
		if (write)
			newmode[modec++] = 'w';
		if (text)
			newmode[modec++] = 't';
		else
			newmode[modec++] = 'b';
		newmode[modec++] = '\0';
    
		f = fopen(name, newmode);
	}

	if (!f)
		return NULL;

	file = Q_calloc(1, sizeof(vfsosfile_t));

	file->funcs.ReadBytes	= (strchr(mode, 'r') ? VFSOS_ReadBytes  : NULL);
	file->funcs.WriteBytes	= (strchr(mode, 'w') ? VFSOS_WriteBytes : NULL);
	file->funcs.Seek		= VFSOS_Seek;
	file->funcs.Tell		= VFSOS_Tell;
	file->funcs.GetLen		= VFSOS_GetSize;
	file->funcs.Close		= VFSOS_Close;

	file->handle = f;

	return (vfsfile_t*)file;
}
Exemple #13
0
char *Player_StripNameColor(const char *name)
{	
	extern char readableChars[]; // console.c
	char *stripped = NULL;
	int i, name_length;
	name_length = strlen(name);

	stripped = (char *)Q_calloc(name_length + 1, sizeof(char));

	// Strip the color by setting bit 7 = 0 on all letters.
	for (i = 0; i < name_length; i++)
	{
		stripped[i] = readableChars[(unsigned char)name[i]] & 127;
	}

	stripped[i] = '\0';

	return stripped;
}
Exemple #14
0
// VFS-XXX: This is slightly different to fs.c version in that we don't take in a FILE *f
vfsfile_t *VFSOS_Open(char *osname, char *mode)
{
	FILE *f;
	vfsosfile_t *file;
	qbool read   = !!strchr(mode, 'r');
	qbool write  = !!strchr(mode, 'w');
	qbool append = !!strchr(mode, 'a');
	qbool text   = !!strchr(mode, 't');
	char newmode[10];
	int modec = 0;

	if (read)
		newmode[modec++] = 'r';
	if (write)
		newmode[modec++] = 'w';
	if (append)
		newmode[modec++] = 'a';
	if (text)
		newmode[modec++] = 't';
	else
		newmode[modec++] = 'b';
	newmode[modec++] = '\0';

	f = fopen(osname, newmode);
	if (!f)
		return NULL;

	file = Q_calloc(1, sizeof(vfsosfile_t));

	file->funcs.ReadBytes  = ( strchr(mode, 'r')                      ? VFSOS_ReadBytes  : NULL);
	file->funcs.WriteBytes = ((strchr(mode, 'w') || strchr(mode, 'a'))? VFSOS_WriteBytes : NULL);
	file->funcs.Seek       = VFSOS_Seek;
	file->funcs.Tell       = VFSOS_Tell;
	file->funcs.GetLen     = VFSOS_GetSize;
	file->funcs.Close      = VFSOS_Close;

	file->handle = f;

	return (vfsfile_t*)file;
}
Exemple #15
0
vfsfile_t *FS_OpenTemp(void)
{
	FILE *f;
	vfsosfile_t *file;

	f = tmpfile();
	if (!f)
		return NULL;

	file = Q_calloc(1, sizeof(vfsosfile_t));

	file->funcs.ReadBytes	= VFSOS_ReadBytes;
	file->funcs.WriteBytes	= VFSOS_WriteBytes;
	file->funcs.Seek		= VFSOS_Seek;
	file->funcs.Tell		= VFSOS_Tell;
	file->funcs.GetLen		= VFSOS_GetSize;
	file->funcs.Close		= VFSOS_Close;

	file->handle = f;

	return (vfsfile_t*)file;
}
Exemple #16
0
vfsfile_t *FS_OpenTCP(char *name)
{
	tcpfile_t *newf;
	int sock;
//	int _true = true;
	netadr_t adr = {0};

	if (NET_StringToAdr(name, &adr))
	{
		sock = TCP_OpenStream(adr);
		if (sock == INVALID_SOCKET)
			return NULL;

//		if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&_true, sizeof(_true)) == -1)
//			Com_Printf ("FS_OpenTCP: setsockopt: (%i): %s\n", qerrno, strerror(qerrno));

		newf = Q_calloc(1, sizeof(tcpfile_t));
		memset(newf, 0, sizeof(tcpfile_t));
		newf->sock				= sock;
		newf->funcs.Close		= VFSTCP_Close;
		newf->funcs.Flush		= NULL;
		newf->funcs.GetLen		= VFSTCP_GetLen;
		newf->funcs.ReadBytes	= VFSTCP_ReadBytes;
		newf->funcs.Seek		= VFSTCP_Seek;
		newf->funcs.Tell		= VFSTCP_Tell;
		newf->funcs.WriteBytes	= VFSTCP_WriteBytes;
		newf->funcs.seekingisabadplan = true;

		// link in
		newf->next   = vfs_tcp_list;
		vfs_tcp_list = newf;

		return &newf->funcs;
	}
	else
		return NULL;
}
Exemple #17
0
// =================
// R_Bloom_InitEffectTexture
// =================
void R_Bloom_InitEffectTexture (void)
{
	unsigned char *data;
	float bloomsizecheck;

	if (r_bloom_sample_size.value < 32)
		Cvar_SetValue (&r_bloom_sample_size, 32);

	// Make sure bloom size is a power of 2.
	BLOOM_SIZE = r_bloom_sample_size.value;
	bloomsizecheck = (float) BLOOM_SIZE;

	while (bloomsizecheck > 1.0f)
		bloomsizecheck /= 2.0f;

	if (bloomsizecheck != 1.0f)
	{
		BLOOM_SIZE = 32;

		while (BLOOM_SIZE < r_bloom_sample_size.value)
			BLOOM_SIZE *= 2;
	}

	// Make sure bloom size doesn't have stupid values.
	if (BLOOM_SIZE > screen_texture_width || BLOOM_SIZE > screen_texture_height)
		BLOOM_SIZE = min( screen_texture_width, screen_texture_height );

	if (BLOOM_SIZE != r_bloom_sample_size.value)
		Cvar_SetValue (&r_bloom_sample_size, BLOOM_SIZE);

	data = (unsigned char *) Q_calloc (BLOOM_SIZE * BLOOM_SIZE, sizeof (int));

	r_bloomeffecttexture = GL_LoadTexture ("***r_bloomeffecttexture***", BLOOM_SIZE, BLOOM_SIZE, data, 0, 4);

	Q_free (data);
}
Exemple #18
0
static void Log_log_f(void) {
	char *fulllogname;
	FILE *templog;
	void *buf;

	switch (Cmd_Argc()) {
	case 1:
		if (autologging)
			Com_Printf("Auto console logging is in progress\n");
		else if (Log_IsLogging())
			Com_Printf("Logging to %s\n", logfilename);
		else
			Com_Printf("Not logging\n");
		return;
	case 2:
		if (!strcasecmp(Cmd_Argv(1), "stop")) {
			if (autologging) {
				Log_AutoLogging_StopMatch();
			} else {
				if (Log_IsLogging()) {
					Log_Stop();
					Com_Printf("Stopped logging to %s\n", logfilename);
				} else {
					Com_Printf("Not logging\n");
				}
			}
			return;
		}

		if (autologging) {
			Com_Printf("Auto console logging must be stopped first!\n");
			return;
		}

		if (Log_IsLogging()) {
			Log_Stop();
			Com_Printf("Stopped logging to %s\n", logfilename);
		}

		strlcpy(logfilename, Cmd_Argv(1), sizeof(logfilename) - 4);
		Util_Process_Filename(logfilename);
		if (!Util_Is_Valid_Filename(logfilename)) {
			Com_Printf(Util_Invalid_Filename_Msg("filename"));
			return;
		}
		COM_ForceExtensionEx (logfilename, ".log", sizeof (logfilename));
		fulllogname = va("%s/%s", Log_LogDirectory(), logfilename);
		if (!(templog = fopen (fulllogname, log_readable.value ? "w" : "wb"))) {
			FS_CreatePath(fulllogname);
			if (!(templog = fopen (fulllogname, log_readable.value ? "w" : "wb"))) {
				Com_Printf("Error: Couldn't open %s\n", logfilename);
				return;
			}
		}
		buf = Q_calloc(1, LOGFILEBUFFER);
		if (!buf) {
			Com_Printf("Not enough memory to allocate log buffer\n");
			return;
		}
		memlogfile = FSMMAP_OpenVFS(buf, LOGFILEBUFFER);
		Com_Printf("Logging to %s\n", logfilename);
		logfile = templog;
		break;
	default:
		Com_Printf("Usage: %s [filename | stop]\n", Cmd_Argv(0));
		return;
	}
}
Exemple #19
0
void StatsGrid_Init(stats_weight_grid_t **grid,
						 float falloff_interval,
						 float falloff_value,
						 int cell_length,
						 float grid_width,
						 float grid_height,
						 float hold_threshold)
{
	int row;
	int col;

	// Allocate the grid.
	(*grid) = (stats_weight_grid_t *)Q_malloc(sizeof(stats_weight_grid_t));
	memset((*grid), 0, sizeof(stats_weight_grid_t));

	if((*grid) == NULL)
	{
		// Failure.
		return;
	}

	// Get the row and col count.
	(*grid)->row_count = Q_rint(grid_height / cell_length);
	(*grid)->col_count = Q_rint(grid_width / cell_length);

	// Allocate the rows.
	(*grid)->cells = (stats_cell_t **)Q_calloc((*grid)->row_count, sizeof(stats_cell_t *));

	// If we failed allocating the rows, cleanup and return.
	if((*grid)->cells == NULL)
	{
		Q_free(*grid);
		return;
	}

	// Allocate the columns for each row.
	for(row = 0; row < (*grid)->row_count; row++)
	{
		// Allocate memory for the current rows columns.
		(*grid)->cells[row] = (stats_cell_t *)Q_calloc((*grid)->col_count, sizeof(stats_cell_t));

		// If something went wrong cleanup and return.
		if((*grid)->cells[row] == NULL)
		{
			// Make sure we're not trying to free more than we allocated.
			(*grid)->row_count = row;

			// Remove the grid.
			StatsGrid_Remove(grid);

			// Failure.
			return;
		}

		// Set initial values for all the cells.
		for(col = 0; col < (*grid)->col_count; col++)
		{
			(*grid)->cells[row][col].teams[STATS_TEAM1].weight = 0.0;
			(*grid)->cells[row][col].teams[STATS_TEAM1].change_time = 0.0;
			(*grid)->cells[row][col].teams[STATS_TEAM1].death_weight = 0.0;

			(*grid)->cells[row][col].teams[STATS_TEAM2].weight = 0.0;
			(*grid)->cells[row][col].teams[STATS_TEAM2].change_time = 0.0;
			(*grid)->cells[row][col].teams[STATS_TEAM2].death_weight = 0.0;

			// Save the quake coordinates of the cells upper left corner.
			(*grid)->cells[row][col].tl_x = cl.worldmodel->mins[0] + (col * cell_length);
			(*grid)->cells[row][col].tl_y = cl.worldmodel->mins[1] + (row * cell_length);
		}
	}

	// If everything went well set the rest of the stuff.
	(*grid)->falloff_interval	= falloff_interval;
	(*grid)->falloff_value		= falloff_value;
	(*grid)->cell_length		= cell_length;
	(*grid)->width				= grid_width;
	(*grid)->height				= grid_height;

	// We will wait with setting these until the match has started.

	(*grid)->teams[STATS_TEAM1].color			= 0;
	(*grid)->teams[STATS_TEAM2].color			= 0;
	(*grid)->teams[STATS_TEAM1].hold_count		= 0;
	(*grid)->teams[STATS_TEAM2].hold_count		= 0;
	(*grid)->teams[STATS_TEAM1].color			= 0;
	(*grid)->teams[STATS_TEAM2].color			= 0;
	(*grid)->hold_threshold						= hold_threshold;
}
Exemple #20
0
void StatsGrid_InitHoldItems()
{
	int i;
	int ents_count = 0;

	// This is used to keep count of how many of the different
	// types of items that exist on the map, so that they
	// can be named "RL" "RL2" and so on.
	int pent_count	= 0;
	int quad_count	= 0;
	int ring_count	= 0;
	int suit_count	= 0;
	int rl_count	= 0;
	int gl_count	= 0;
	int lg_count	= 0;
	int sng_count	= 0;
	int mega_count	= 0;
	int ra_count	= 0;
	int ya_count	= 0;
	int ga_count	= 0;

	// Buffer.
	stats_entity_t temp_ents[STATS_MAX_IMPORTANT_ENTS];

	// Entities (weapons and such). cl_main.c
	extern visentlist_t cl_visents;

	// Don't create the list before we have any entities to work with.
	if(cl_visents.count <= 0)
	{
		return;
	}

	stats_important_ents = (stats_entities_t *)Q_malloc(sizeof(stats_entities_t));

	// Something bad happened.
	if(stats_important_ents == NULL)
	{
		return;
	}

	// Go through the entities and check for the important ones
	// and save their name and location.
	for (i = 0; i < cl_visents.count && (ents_count < STATS_MAX_IMPORTANT_ENTS); i++)
	{
		if(!strcmp(cl_visents.list[i].model->name, "progs/invulner.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "PENT", ++pent_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/quaddama.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "QUAD", ++quad_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/invisibl.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "RING", ++ring_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/suit.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "SUIT", ++suit_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/g_rock2.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "RL", ++rl_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/g_light.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "LG", ++lg_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/g_rock.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "GL", ++gl_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/g_nail2.mdl"))
		{
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "SNG", ++sng_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "maps/b_bh100.bsp"))
		{
			// Megahealth.
			StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "MH", ++mega_count);
		}
		else if(!strcmp(cl_visents.list[i].model->name, "progs/armor.mdl"))
		{
			if(cl_visents.list[i].skinnum == 0)
			{
				StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "GA", ++ga_count);
			}
			else if(cl_visents.list[i].skinnum == 1)
			{
				StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "YA", ++ya_count);
			}
			else if(cl_visents.list[i].skinnum == 2)
			{
				StatsGrid_SetHoldItemName(temp_ents[ents_count].name, "RA", ++ra_count);
			}
			else
			{
				continue;
			}
		}
		else
		{
			// The entity wasn't one we wanted.
			continue;
		}

		// Copy the position of the entity into the buffer.
		VectorCopy(cl_visents.list[i].origin, temp_ents[ents_count].origin);

		// Reset the team values.
		temp_ents[ents_count].teams_hold_count[STATS_TEAM1] = 0;
		temp_ents[ents_count].teams_hold_count[STATS_TEAM2] = 0;

		ents_count++;
	}

	// Set the count of found entities and allocate memory for the
	// final list of items.
	stats_important_ents->count = ents_count;
	stats_important_ents->list = Q_calloc(ents_count, sizeof(stats_entity_t));

	// Something bad happened, cleanup.
	if(stats_important_ents->list == NULL)
	{
		Q_free(stats_important_ents);
		return;
	}

	// Copy the entities from the buffer to the final list.
	for(i = 0; i < ents_count; i++)
	{
		memcpy(&stats_important_ents->list[i], &temp_ents[i], sizeof(stats_entity_t));
	}

	// Set the radius around the items that decides if it's being
	// held by a team or not.
	stats_important_ents->hold_radius = 264.0;

	// Get the entity with the longest name to use for padding
	// (so we don't have to calculate this more than once).
	stats_important_ents->longest_name = 0;
	for(i = 0; i < stats_important_ents->count; i++)
	{
		int current = strlen(stats_important_ents->list[i].name);
		stats_important_ents->longest_name = max(current, stats_important_ents->longest_name);
	}
}
Exemple #21
0
qbool Cmdline_Parse(int argc, char **argv)
{
	int i;
	char *files_temp[1024];
	int filecount = 0;
	char *arg;

	memset(&cmdargs, 0, sizeof(cmdargs));

	if (argc < 2)
	{
		return false;
	}

	for (i = 1; i < argc; i++)
	{
		arg = argv[i];

		if (((arg[0] == '-') || (arg[0] == '/')) && arg[1])
		{
			// Command line switch.
			switch(arg[1])
			{
				case 'v' :
				{
					// Verbosity based on how many v's where specified.
					int j = 1;
					
					while (arg[j] == 'v')
					{
						cmdargs.debug++;
						j++;						
					}	
					break;
				}
				case 'f' :
				{
					int next_arg = (i + 1);

					if (next_arg < argc)
					{
						cmdargs.frag_file = Q_strdup(argv[next_arg]);
					}

					break;
				}
				case 't' :
				{
					int next_arg = (i + 1);

					if (next_arg < argc)
					{
						cmdargs.template_file = Q_strdup(argv[next_arg]);
					}
					else
					{
						Sys_PrintError("-t: No template specified\n");
					}
					
					break;
				}
			}
		}
		else
		{
			// Regard as being a file.
			files_temp[filecount] = arg;
			filecount++;
		}
	}

	cmdargs.mvd_files_count = filecount;

	// Allocate memory for the filenames.
	if (filecount > 0)
	{
		cmdargs.mvd_files = (char **)Q_calloc(filecount, sizeof(char **));

		for (i = 0; i < filecount; i++)
		{
			cmdargs.mvd_files[i] = Q_strdup(files_temp[i]);
		}
	}

	return true;
}
Exemple #22
0
/*
=================
FSPAK_LoadPackFile

Takes an explicit (not game tree related) path to a pak file.

Loads the header and directory, adding the files at the beginning
of the list so they override previous pack files.
=================
*/
static void *FSPAK_LoadPackFile (vfsfile_t *file, const char *desc)
{
	dpackheader_t	header;
	int				i;
	packfile_t		*newfiles;
	int				numpackfiles;
	pack_t			*pack;
	vfsfile_t		*packhandle;
	dpackfile_t		info;
	vfserrno_t err;

	packhandle = file;
	if (packhandle == NULL)
		return NULL;

	VFS_READ(packhandle, &header, sizeof(header), &err);
	if (header.id[0] != 'P' || header.id[1] != 'A'
	|| header.id[2] != 'C' || header.id[3] != 'K')
	{
		return NULL;
	}
	header.dirofs = LittleLong (header.dirofs);
	header.dirlen = LittleLong (header.dirlen);

	numpackfiles = header.dirlen / sizeof(dpackfile_t);

//	if (numpackfiles != PAK0_COUNT)
//		com_modified = true;	// not the original file

	newfiles = (packfile_t*)Q_malloc (numpackfiles * sizeof(packfile_t));

	VFS_SEEK(packhandle, header.dirofs, SEEK_SET);
//	fread (&info, 1, header.dirlen, packhandle);

// crc the directory to check for modifications
//	crc = QCRC_Block((qbyte *)info, header.dirlen);


//	QCRC_Init (&crc);

	pack = (pack_t *)Q_calloc(1, sizeof (pack_t));

// parse the directory
	for (i=0 ; i<numpackfiles ; i++)
	{
		*info.name = '\0';
		// FIXME return value
		(void) VFS_READ(packhandle, &info, sizeof(info), &err);
/*
		for (j=0 ; j<sizeof(info) ; j++)
			CRC_ProcessByte(&crc, ((qbyte *)&info)[j]);
*/
		strlcpy (newfiles[i].name, info.name, MAX_QPATH);
		newfiles[i].filepos = LittleLong(info.filepos);
		newfiles[i].filelen = LittleLong(info.filelen);
	}
/*
	if (crc != PAK0_CRC)
		com_modified = true;
*/
	strlcpy (pack->filename, desc, sizeof (pack->filename));
	pack->handle = packhandle;
	pack->numfiles = numpackfiles;
	pack->files = newfiles;
	pack->filepos = 0;
	VFS_SEEK(packhandle, pack->filepos, SEEK_SET);

	pack->references++;

	return pack;
}
Exemple #23
0
void Capture_WriteAudio (int samples, byte *sample_buffer)
{
    HRESULT		hr = E_UNEXPECTED;
    unsigned long	sample_bufsize;

    if (!m_audio_stream)
    {
        Com_Printf ("ERROR: Audio stream is NULL\n");
        return;
    }

    sample_bufsize = samples * m_wave_format.nBlockAlign;
    if (m_audio_is_mp3)
    {
        MMRESULT	mmr;
        byte		*mp3_buffer;
        unsigned long	mp3_bufsize;

        if ((mmr = qacmStreamSize(hstr, sample_bufsize, &mp3_bufsize, ACM_STREAMSIZEF_SOURCE)))
        {
            Com_Printf ("ERROR: Couldn't get mp3bufsize\n");
            return;
        }
        if (!mp3_bufsize)
        {
            Com_Printf ("ERROR: mp3bufsize is zero\n");
            return;
        }
        mp3_buffer = (byte *) Q_calloc (mp3_bufsize, 1);

        memset (&strhdr, 0, sizeof(strhdr));
        strhdr.cbStruct = sizeof(strhdr);
        strhdr.pbSrc = sample_buffer;
        strhdr.cbSrcLength = sample_bufsize;
        strhdr.pbDst = mp3_buffer;
        strhdr.cbDstLength = mp3_bufsize;

        if ((mmr = qacmStreamPrepareHeader(hstr, &strhdr, 0)))
        {
            Com_Printf ("ERROR: Couldn't prepare header\n");
            Q_free (mp3_buffer);
            return;
        }

        if ((mmr = qacmStreamConvert(hstr, &strhdr, ACM_STREAMCONVERTF_BLOCKALIGN)))
        {
            Com_Printf ("ERROR: Couldn't convert audio stream\n");
            goto clean;
        }

        hr = qAVIStreamWrite (m_audio_stream, m_audio_frame_counter++, 1, mp3_buffer, strhdr.cbDstLengthUsed, AVIIF_KEYFRAME, NULL, NULL);

clean:
        if ((mmr = qacmStreamUnprepareHeader(hstr, &strhdr, 0)))
        {
            Com_Printf ("ERROR: Couldn't unprepare header\n");
            Q_free (mp3_buffer);
            return;
        }

        Q_free (mp3_buffer);
    }
    else
    {
        // The audio is not in MP3 format, just write the WAV data to the avi.
        hr = qAVIStreamWrite (m_audio_stream, m_audio_frame_counter++, 1, sample_buffer, samples * m_wave_format.nBlockAlign, AVIIF_KEYFRAME, NULL, NULL);
    }

    if (FAILED(hr))
    {
        Com_Printf ("ERROR: Couldn't write to AVI file\n");
        return;
    }
}