Beispiel #1
0
void SetQdirFromPath (const char *path)
{
	char	temp[1024];
	const char	*c, *mark;

	if (!(path[0] == '/' || path[0] == '\\' || path[1] == ':'))
	{	// path is partial
		Q_getwd (temp, sizeof(temp));
		qerr_strlcat(__thisfunc__, __LINE__, temp, path, sizeof(temp));
		path = temp;
	}

	c = path;
	while (*c)
		++c;
	while (c > path && *c != '/' && *c != '\\')
		--c;
	if (c == path)
		goto end;
	mark = c + 1;
	--c;
	// search for the basedir (as defined in BUILDDIR) in path
	while (c != path)
	{
		if (!q_strncasecmp (c, BUILDDIR, sizeof(BUILDDIR) - 1))
		{
			strncpy (qdir, path, c + sizeof(BUILDDIR) - path);
			printf ("qdir: %s\n", qdir);
			// now search for a gamedir in path
			c += sizeof(BUILDDIR);
			while (c < mark)
			{
				if (*c == '/' || *c == '\\')
				{
					strncpy (gamedir, path, c + 1 - path);
					printf ("gamedir: %s\n", gamedir);
					return;
				}
				c++;
			}
			Error ("No gamedir in %s", path);
		}
		--c;
	}
end:
	Error ("%s: no '%s' in %s", __thisfunc__, BUILDDIR, path);
}
Beispiel #2
0
/*
===============
FindTexinfo

Returns a global texinfo number
===============
*/
static int FindTexinfo (texinfo_t *t)
{
	int			i, j;
	texinfo_t	*tex;

// set the special flag
	if (miptex[t->miptex][0] == '*' 
			|| !q_strncasecmp (miptex[t->miptex], "sky",3) )
		t->flags |= TEX_SPECIAL;

	tex = texinfo;
	for (i = 0 ; i < numtexinfo;i++, tex++)
	{
		if (t->miptex != tex->miptex)
			continue;
		if (t->flags != tex->flags)
			continue;

		for (j = 0 ; j < 8 ; j++)
		{
			if (t->vecs[0][j] != tex->vecs[0][j])
				break;
		}

		if (j != 8)
			continue;

		return i;
	}

// allocate a new texture
	if (numtexinfo == MAX_MAP_TEXINFO)
		Error ("numtexinfo == MAX_MAP_TEXINFO");
	texinfo[i] = *t;
	numtexinfo++;

	return i;
}
Beispiel #3
0
/*
===================
SV_ReadClientMessage

Returns false if the client should be killed
===================
*/
qboolean SV_ReadClientMessage (void)
{
	int		ret;
	int		ccmd;
	const char	*s;

	do
	{
nextmsg:
		ret = NET_GetMessage (host_client->netconnection);
		if (ret == -1)
		{
			Sys_Printf ("SV_ReadClientMessage: NET_GetMessage failed\n");
			return false;
		}
		if (!ret)
			return true;

		MSG_BeginReading ();

		while (1)
		{
			if (!host_client->active)
				return false;	// a command caused an error

			if (msg_badread)
			{
				Sys_Printf ("SV_ReadClientMessage: badread\n");
				return false;
			}

			ccmd = MSG_ReadChar ();

			switch (ccmd)
			{
			case -1:
				goto nextmsg;		// end of message

			default:
				Sys_Printf ("SV_ReadClientMessage: unknown command char\n");
				return false;

			case clc_nop:
//				Sys_Printf ("clc_nop\n");
				break;

			case clc_stringcmd:
				s = MSG_ReadString ();
				ret = 0;
				if (q_strncasecmp(s, "status", 6) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "god", 3) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "notarget", 8) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "fly", 3) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "name", 4) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "noclip", 6) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "setpos", 6) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "say", 3) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "say_team", 8) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "tell", 4) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "color", 5) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "kill", 4) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "pause", 5) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "spawn", 5) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "begin", 5) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "prespawn", 8) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "kick", 4) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "ping", 4) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "give", 4) == 0)
					ret = 1;
				else if (q_strncasecmp(s, "ban", 3) == 0)
					ret = 1;

				if (ret == 1)
					Cmd_ExecuteString (s, src_client);
				else
					Con_DPrintf("%s tried to %s\n", host_client->name, s);
				break;

			case clc_disconnect:
//				Sys_Printf ("SV_ReadClientMessage: client disconnected\n");
				return false;

			case clc_move:
				SV_ReadClientMove (&host_client->cmd);
				break;
			}
		}
	} while (ret == 1);

	return true;
}
Beispiel #4
0
/*
==================
SCR_ScreenShot_f -- johnfitz -- rewritten to use Image_WriteTGA
==================
*/
void SCR_ScreenShot_f (void)
{
	byte	*buffer;
	char	ext[4];
	char	imagename[16];  //johnfitz -- was [80]
	char	checkname[MAX_OSPATH];
	int	i, quality;
	qboolean	ok;

	Q_strncpy (ext, "png", sizeof(ext));

	if (Cmd_Argc () >= 2)
	{
		const char	*requested_ext = Cmd_Argv (1);

		if (!q_strcasecmp ("png", requested_ext)
		    || !q_strcasecmp ("tga", requested_ext)
		    || !q_strcasecmp ("jpg", requested_ext))
			Q_strncpy (ext, requested_ext, sizeof(ext));
		else
		{
			SCR_ScreenShot_Usage ();
			return;
		}
	}

// read quality as the 3rd param (only used for JPG)
	quality = 90;
	if (Cmd_Argc () >= 3)
		quality = Q_atoi (Cmd_Argv(2));
	if (quality < 1 || quality > 100)
	{
		SCR_ScreenShot_Usage ();
		return;
	}
	
// find a file name to save it to
	for (i=0; i<10000; i++)
	{
		q_snprintf (imagename, sizeof(imagename), "spasm%04i.%s", i, ext);	// "fitz%04i.tga"
		q_snprintf (checkname, sizeof(checkname), "%s/%s", com_gamedir, imagename);
		if (Sys_FileTime(checkname) == -1)
			break;	// file doesn't exist
	}
	if (i == 10000)
	{
		Con_Printf ("SCR_ScreenShot_f: Couldn't find an unused filename\n");
		return;
	}

//get data
	if (!(buffer = (byte *) malloc(glwidth*glheight*3)))
	{
		Con_Printf ("SCR_ScreenShot_f: Couldn't allocate memory\n");
		return;
	}

	glPixelStorei (GL_PACK_ALIGNMENT, 1);/* for widths that aren't a multiple of 4 */
	glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer);

// now write the file
	if (!q_strncasecmp (ext, "png", sizeof(ext)))
		ok = Image_WritePNG (imagename, buffer, glwidth, glheight, 24, false);
	else if (!q_strncasecmp (ext, "tga", sizeof(ext)))
		ok = Image_WriteTGA (imagename, buffer, glwidth, glheight, 24, false);
	else if (!q_strncasecmp (ext, "jpg", sizeof(ext)))
		ok = Image_WriteJPG (imagename, buffer, glwidth, glheight, 24, quality, false);
	else
		ok = false;

	if (ok)
		Con_Printf ("Wrote %s\n", imagename);
	else
		Con_Printf ("SCR_ScreenShot_f: Couldn't create %s\n", imagename);

	free (buffer);
}
Beispiel #5
0
int TextureContents (char *name)
{
	if (!q_strncasecmp (name, "sky",3))
		return CONTENTS_SKY;
	if (!q_strncasecmp(name,"*lava",5))
		return CONTENTS_LAVA;
	if (!q_strncasecmp(name,"*slime",6))
		return CONTENTS_SLIME;
	if (!q_strncasecmp (name, "*cur_90",7))
		return CONTENTS_CURRENT_90;
	if (!q_strncasecmp (name, "*cur_0",6))
		return CONTENTS_CURRENT_0;
	if (!q_strncasecmp (name, "*cur_270",8))
		return CONTENTS_CURRENT_270;
	if (!q_strncasecmp (name, "*cur_180",8))
		return CONTENTS_CURRENT_180;
	if (!q_strncasecmp (name, "*cur_up",7))
		return CONTENTS_CURRENT_UP;
	if (!q_strncasecmp (name, "*cur_dwn",8))
		return CONTENTS_CURRENT_DOWN;

	if (name[0] == '*')
		return CONTENTS_WATER;

	if (!q_strncasecmp (name, "origin",6))
		return CONTENTS_ORIGIN;

	if (!q_strncasecmp (name, "clip",4))
		return CONTENTS_CLIP;

	return CONTENTS_SOLID;
}
Beispiel #6
0
/*
=================
ParseBrush
=================
*/
static void ParseBrush (void)
{
	mbrush_t		*b;
	mface_t		*f, *f2;
	vec3_t		planepts[3];
	vec3_t		t1, t2, t3;
	int			i, j;
	texinfo_t	tx;
	double		d;
	float		shift[2], rotate, scale[2];
	char		name[64];

	b = &mapbrushes[nummapbrushes];

	do
	{
		if (!GetToken (true))
			break;
		if (!strcmp (token, "}") )
			break;

	// read the three point plane definition
		for (i = 0 ; i < 3 ; i++)
		{
			if (i != 0)
				GetToken (true);
			if (strcmp (token, "(") )
				Error ("parsing brush");

			for (j = 0 ; j < 3 ; j++)
			{
				GetToken (false);
				planepts[i][j] = atoi(token);
			}

			GetToken (false);
			if (strcmp (token, ")") )
				Error ("parsing brush");
		}

	// read the texturedef
		memset (&tx, 0, sizeof(tx));
		GetToken (false);

		strcpy (name, token);	// JDC 8/8/97: for origin texture

		tx.miptex = FindMiptex (token);
		GetToken (false);
		shift[0] = atoi(token);
		GetToken (false);
		shift[1] = atoi(token);
		GetToken (false);
		rotate = atoi(token);
		GetToken (false);
		scale[0] = atof(token);
		GetToken (false);
		scale[1] = atof(token);
		GetToken (false);
		b->Light = atoi(token);

		// if the three points are all on a previous plane, it is a
		// duplicate plane
		for (f2 = b->faces ; f2 ; f2 = f2->next)
		{
			for (i = 0 ; i < 3 ; i++)
			{
				d = DotProduct(planepts[i],f2->plane.normal) - f2->plane.dist;
				if (d < -ON_EPSILON || d > ON_EPSILON)
					break;
			}
			if (i == 3)
				break;
		}
		if (f2)
		{
			printf ("WARNING: brush with duplicate plane\n");
			continue;
		}

		f = (mface_t *) malloc(sizeof(mface_t));
		f->next = b->faces;
		b->faces = f;

	// convert to a vector / dist plane
		for (j = 0 ; j < 3 ; j++)
		{
			t1[j] = planepts[0][j] - planepts[1][j];
			t2[j] = planepts[2][j] - planepts[1][j];
			t3[j] = planepts[1][j];
		}

		CrossProduct(t1,t2, f->plane.normal);
		if (VectorCompare (f->plane.normal, vec3_origin))
		{
			printf ("WARNING: brush plane with no normal\n");
			b->faces = f->next;
			free (f);
			break;
		}
		VectorNormalize (f->plane.normal);
		f->plane.dist = DotProduct (t3, f->plane.normal);

	//
	// fake proper texture vectors from QuakeEd style
	//
		{
			vec3_t	vecs[2];
			int		sv, tv;
			float	ang, sinv, cosv;
			float	ns, nt;

			TextureAxisFromPlane(&f->plane, vecs[0], vecs[1]);

			if (!scale[0])
				scale[0] = 1;
			if (!scale[1])
				scale[1] = 1;

		// rotate axis
			if (rotate == 0)
			{
				sinv = 0;
				cosv = 1;
			}
			else if (rotate == 90)
			{
				sinv = 1;
				cosv = 0;
			}
			else if (rotate == 180)
			{
				sinv = 0;
				cosv = -1;
			}
			else if (rotate == 270)
			{
				sinv = -1;
				cosv = 0;
			}
			else
			{
				ang = rotate / 180 * Q_PI;
				sinv = sin(ang);
				cosv = cos(ang);
			}

			if (vecs[0][0])
				sv = 0;
			else if (vecs[0][1])
				sv = 1;
			else
				sv = 2;

			if (vecs[1][0])
				tv = 0;
			else if (vecs[1][1])
				tv = 1;
			else
				tv = 2;

			for (i = 0 ; i < 2 ; i++)
			{
				ns = cosv * vecs[i][sv] - sinv * vecs[i][tv];
				nt = sinv * vecs[i][sv] +  cosv * vecs[i][tv];
				vecs[i][sv] = ns;
				vecs[i][tv] = nt;
			}

			for (i = 0 ; i < 2 ; i++)
				for (j = 0 ; j < 3 ; j++)
					tx.vecs[i][j] = vecs[i][j] / scale[i];

			tx.vecs[0][3] = shift[0];
			tx.vecs[1][3] = shift[1];
		}

	// unique the texinfo
		f->texinfo = FindTexinfo (&tx);
	} while (1);

	// JDC 8/8/97
	// origin brushes are removed, but they set
	// the rotation origin for the rest of the brushes
	// in the entity
	//
	if (q_strncasecmp (name, "origin",6))
	{	// keep it
		nummapbrushes++;
		b->next = mapent->brushes;
		mapent->brushes = b;
	}
	else
	{	// don't save the brush, just use as entity origin
		char	string[32];
		vec3_t	origin;

		if (num_entities == 1)
			Error ("Origin brushes not allowed in world");

		BrushOrigin (b, origin);

		sprintf (string, "%i %i %i", (int)origin[0], (int)origin[1], (int)origin[2]);
		SetKeyValue (mapent, "origin", string);

		VectorCopy (origin, mapent->origin);

		memset (b, 0, sizeof(*b));
	}
}