Exemplo n.º 1
0
/*
 * The server will send this command right
 * before allowing the client into the server
 */
void
CL_Precache_f(void)
{
	/* Yet another hack to let old demos work */
	if (Cmd_Argc() < 2)
	{
		unsigned map_checksum;    /* for detecting cheater maps */

		CM_LoadMap(cl.configstrings[CS_MODELS + 1], true, &map_checksum);
		CL_RegisterSounds();
		CL_PrepRefresh();
		return;
	}

	precache_check = CS_MODELS;

	precache_spawncount = (int)strtol(Cmd_Argv(1), (char **)NULL, 10);
	precache_model = 0;
	precache_model_skin = 0;

	CL_RequestNextDownload();
}
Exemplo n.º 2
0
void
CL_Frame(int packetdelta, int renderdelta, int timedelta, qboolean packetframe, qboolean renderframe)
{
	static int lasttimecalled;

	// Dedicated?
	if (dedicated->value)
	{
		return;
	}

	// Calculate simulation time.
	cls.nframetime = packetdelta / 1000000.0f;
	cls.rframetime = renderdelta / 1000000.0f;
	cls.realtime = curtime;
	cl.time += timedelta / 1000;

	// Don't extrapolate too far ahead.
	if (cls.nframetime > 0.5f)
	{
		cls.nframetime = 0.5f;
	}

	if (cls.rframetime > 0.5f)
	{
		cls.rframetime = 0.5f;
	}

	// if in the debugger last frame, don't timeout.
	if (timedelta > 5000000)
	{
		cls.netchan.last_received = Sys_Milliseconds();
	}

	// Reset power shield / power screen sound counter.
	num_power_sounds = 0;

	if (!cl_timedemo->value)
	{
		// Don't throttle too much when connecting / loading.
		if ((cls.state == ca_connected) && (packetdelta > 100000))
		{
			packetframe = true;
		}
	}

	// Run HTTP downloads more often while connecting.
#ifdef USE_CURL
	if (cls.state == ca_connected)
	{
		CL_RunHTTPDownloads();
	}
#endif

	// Update input stuff.
	if (packetframe || renderframe)
	{
		CL_ReadPackets();
		CL_UpdateWindowedMouse();
		IN_Update();
		Cbuf_Execute();
		CL_FixCvarCheats();

		if (cls.state > ca_connecting)
		{
			CL_RefreshCmd();
		}
		else
		{
			CL_RefreshMove();
		}
	}

	if (cls.forcePacket || userinfo_modified)
	{
		packetframe = true;
		cls.forcePacket = false;
	}

	if (packetframe)
	{
		CL_SendCmd();
		CL_CheckForResend();

		// Run HTTP downloads during game.
#ifdef USE_CURL
		CL_RunHTTPDownloads();
#endif
	}

	if (renderframe)
	{
		VID_CheckChanges();
		CL_PredictMovement();

		if (!cl.refresh_prepped && (cls.state == ca_active))
		{
			CL_PrepRefresh();
		}

		/* update the screen */
		if (host_speeds->value)
		{
			time_before_ref = Sys_Milliseconds();
		}

		SCR_UpdateScreen();

		if (host_speeds->value)
		{
			time_after_ref = Sys_Milliseconds();
		}

		/* update audio */
		S_Update(cl.refdef.vieworg, cl.v_forward, cl.v_right, cl.v_up);

		/* advance local effects for next frame */
		CL_RunDLights();
		CL_RunLightStyles();
		SCR_RunCinematic();
		SCR_RunConsole();

		/* Update framecounter */
		cls.framecount++;

		if (log_stats->value)
		{
			if (cls.state == ca_active)
			{
				if (!lasttimecalled)
				{
					lasttimecalled = Sys_Milliseconds();

					if (log_stats_file)
					{
						fprintf(log_stats_file, "0\n");
					}
				}

				else
				{
					int now = Sys_Milliseconds();

					if (log_stats_file)
					{
						fprintf(log_stats_file, "%d\n", now - lasttimecalled);
					}

					lasttimecalled = now;
				}
			}
		}
	}
}
Exemplo n.º 3
0
void CL_RequestNextDownload (void)
{
	unsigned	map_checksum; /* for detecting cheater maps */
	char fn[MAX_OSPATH];
	dmdl_t *pheader;

	if (cls.state != ca_connected)
		return;

	if (!allow_download->value && precache_check < ENV_CNT)
		precache_check = ENV_CNT;

	if (precache_check == CS_MODELS)
	{
		precache_check = CS_MODELS+2;

		if (allow_download_maps->value)
			if (!CL_CheckOrDownloadFile(cl.configstrings[CS_MODELS+1]))
				return; /* started a download */
	}

	if (precache_check >= CS_MODELS && precache_check < CS_MODELS+MAX_MODELS)
	{
		if (allow_download_models->value)
		{
			while (precache_check < CS_MODELS+MAX_MODELS &&
			        cl.configstrings[precache_check][0])
			{
				if (cl.configstrings[precache_check][0] == '*' ||
				        cl.configstrings[precache_check][0] == '#')
				{
					precache_check++;
					continue;
				}

				if (precache_model_skin == 0)
				{
					if (!CL_CheckOrDownloadFile(cl.configstrings[precache_check]))
					{
						precache_model_skin = 1;
						return; /* started a download */
					}

					precache_model_skin = 1;
				}

				/* checking for skins in the model */

				if (!precache_model)
				{

					FS_LoadFile (cl.configstrings[precache_check], (void **)&precache_model);

					if (!precache_model)
					{
						precache_model_skin = 0;
						precache_check++;
						continue; /* couldn't load it */
					}

					if (LittleLong(*(unsigned *)precache_model) != IDALIASHEADER)
					{
						/* not an alias model */
						FS_FreeFile(precache_model);
						precache_model = 0;
						precache_model_skin = 0;
						precache_check++;
						continue;
					}

					pheader = (dmdl_t *)precache_model;

					if (LittleLong (pheader->version) != ALIAS_VERSION)
					{
						precache_check++;
						precache_model_skin = 0;
						continue; /* couldn't load it */
					}
				}

				pheader = (dmdl_t *)precache_model;

				while (precache_model_skin - 1 < LittleLong(pheader->num_skins))
				{
					if (!CL_CheckOrDownloadFile((char *)precache_model +
					                            LittleLong(pheader->ofs_skins) +
					                            (precache_model_skin - 1)*MAX_SKINNAME))
					{
						precache_model_skin++;
						return; /* started a download */
					}

					precache_model_skin++;
				}

				if (precache_model)
				{
					FS_FreeFile(precache_model);
					precache_model = 0;
				}

				precache_model_skin = 0;

				precache_check++;
			}
		}

		precache_check = CS_SOUNDS;
	}

	if (precache_check >= CS_SOUNDS && precache_check < CS_SOUNDS+MAX_SOUNDS)
	{
		if (allow_download_sounds->value)
		{
			if (precache_check == CS_SOUNDS)
				precache_check++;

			while (precache_check < CS_SOUNDS+MAX_SOUNDS &&
			        cl.configstrings[precache_check][0])
			{
				if (cl.configstrings[precache_check][0] == '*')
				{
					precache_check++;
					continue;
				}

				Com_sprintf(fn, sizeof(fn), "sound/%s", cl.configstrings[precache_check++]);

				if (!CL_CheckOrDownloadFile(fn))
					return; /* started a download */
			}
		}

		precache_check = CS_IMAGES;
	}

	if (precache_check >= CS_IMAGES && precache_check < CS_IMAGES+MAX_IMAGES)
	{
		if (precache_check == CS_IMAGES)
			precache_check++;

		while (precache_check < CS_IMAGES+MAX_IMAGES &&
		        cl.configstrings[precache_check][0])
		{
			Com_sprintf(fn, sizeof(fn), "pics/%s.pcx", cl.configstrings[precache_check++]);

			if (!CL_CheckOrDownloadFile(fn))
				return; // started a download
		}

		precache_check = CS_PLAYERSKINS;
	}

	/* skins are special, since a player has three things to download:
	   model, weapon model and skin so precache_check is now *3 */
	if (precache_check >= CS_PLAYERSKINS && precache_check < CS_PLAYERSKINS + MAX_CLIENTS * PLAYER_MULT)
	{
		if (allow_download_players->value)
		{
			while (precache_check < CS_PLAYERSKINS + MAX_CLIENTS * PLAYER_MULT)
			{
				int i, n;
				char model[MAX_QPATH], skin[MAX_QPATH], *p;

				i = (precache_check - CS_PLAYERSKINS)/PLAYER_MULT;
				n = (precache_check - CS_PLAYERSKINS)%PLAYER_MULT;

				if (!cl.configstrings[CS_PLAYERSKINS+i][0])
				{
					precache_check = CS_PLAYERSKINS + (i + 1) * PLAYER_MULT;
					continue;
				}

				if ((p = strchr(cl.configstrings[CS_PLAYERSKINS+i], '\\')) != NULL)
					p++;
				else
					p = cl.configstrings[CS_PLAYERSKINS+i];

				strcpy(model, p);

				p = strchr(model, '/');

				if (!p)
					p = strchr(model, '\\');

				if (p)
				{
					*p++ = 0;
					strcpy(skin, p);
				}

				else
					*skin = 0;

				switch (n)
				{

					case 0: /* model */
						Com_sprintf(fn, sizeof(fn), "players/%s/tris.md2", model);

						if (!CL_CheckOrDownloadFile(fn))
						{
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 1;
							return;
						}

						n++;

					case 1: /* weapon model */
						Com_sprintf(fn, sizeof(fn), "players/%s/weapon.md2", model);

						if (!CL_CheckOrDownloadFile(fn))
						{
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 2;
							return;
						}

						n++;

					case 2: /* weapon skin */
						Com_sprintf(fn, sizeof(fn), "players/%s/weapon.pcx", model);

						if (!CL_CheckOrDownloadFile(fn))
						{
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 3;
							return;
						}

						n++;

					case 3: /* skin */
						Com_sprintf(fn, sizeof(fn), "players/%s/%s.pcx", model, skin);

						if (!CL_CheckOrDownloadFile(fn))
						{
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 4;
							return;
						}

						n++;

					case 4: /* skin_i */
						Com_sprintf(fn, sizeof(fn), "players/%s/%s_i.pcx", model, skin);

						if (!CL_CheckOrDownloadFile(fn))
						{
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 5;
							return; // started a download
						}

						/* move on to next model */
						precache_check = CS_PLAYERSKINS + (i + 1) * PLAYER_MULT;
				}
			}
		}

		/* precache phase completed */
		precache_check = ENV_CNT;
	}

	if (precache_check == ENV_CNT)
	{
		precache_check = ENV_CNT + 1;

		CM_LoadMap (cl.configstrings[CS_MODELS+1], true, &map_checksum);

		if (map_checksum != atoi(cl.configstrings[CS_MAPCHECKSUM]))
		{
			Com_Error (ERR_DROP, "Local map version differs from server: %i != '%s'\n",
			           map_checksum, cl.configstrings[CS_MAPCHECKSUM]);
			return;
		}
	}

	if (precache_check > ENV_CNT && precache_check < TEXTURE_CNT)
	{
		if (allow_download->value && allow_download_maps->value)
		{
			while (precache_check < TEXTURE_CNT)
			{
				int n = precache_check++ - ENV_CNT - 1;

				if (n & 1)
					Com_sprintf(fn, sizeof(fn), "env/%s%s.pcx",
					            cl.configstrings[CS_SKY], env_suf[n/2]);
				else
					Com_sprintf(fn, sizeof(fn), "env/%s%s.tga",
					            cl.configstrings[CS_SKY], env_suf[n/2]);

				if (!CL_CheckOrDownloadFile(fn))
					return;
			}
		}

		precache_check = TEXTURE_CNT;
	}

	if (precache_check == TEXTURE_CNT)
	{
		precache_check = TEXTURE_CNT+1;
		precache_tex = 0;
	}

	/* confirm existance of textures, download any that don't exist */
	if (precache_check == TEXTURE_CNT+1)
	{
		extern int			numtexinfo;
		extern mapsurface_t	map_surfaces[];

		if (allow_download->value && allow_download_maps->value)
		{
			while (precache_tex < numtexinfo)
			{
				char fn[MAX_OSPATH];

				sprintf(fn, "textures/%s.wal", map_surfaces[precache_tex++].rname);

				if (!CL_CheckOrDownloadFile(fn))
					return; /* started a download */
			}
		}

		precache_check = TEXTURE_CNT+999;
	}

	CL_RegisterSounds ();

	CL_PrepRefresh ();

	MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
	MSG_WriteString (&cls.netchan.message, va("begin %i\n", precache_spawncount) );
}
Exemplo n.º 4
0
void
CL_Frame(int msec)
{
	static int extratime;
	static int lasttimecalled;

	if (dedicated->value)
	{
		return;
	}

	extratime += msec;

	if (!cl_timedemo->value)
	{
		if ((cls.state == ca_connected) && (extratime < 100))
		{
			return; /* don't flood packets out while connecting */
		}

		if (extratime < 1000 / cl_maxfps->value)
		{
			return; /* framerate is too high */
		}
	}

	/* decide the simulation time */
	cls.frametime = extratime / 1000.0;

	cl.time += extratime;

	cls.realtime = curtime;

	extratime = 0;

	if (cls.frametime > (1.0 / 5))
	{
		cls.frametime = (1.0 / 5);
	}

	/* if in the debugger last frame, don't timeout */
	if (msec > 5000)
	{
		cls.netchan.last_received = Sys_Milliseconds();
	}

	/* fetch results from server */
	CL_ReadPackets();

	/* send a new command message to the server */
	CL_SendCommand();

	/* predict all unacknowledged movements */
	CL_PredictMovement();

	/* allow renderer DLL change */
	VID_CheckChanges();

	if (!cl.refresh_prepped && (cls.state == ca_active))
	{
		CL_PrepRefresh();
	}

	/* update the screen */
	if (host_speeds->value)
	{
		time_before_ref = Sys_Milliseconds();
	}

	SCR_UpdateScreen();

	if (host_speeds->value)
	{
		time_after_ref = Sys_Milliseconds();
	}

	/* update audio */
	S_Update(cl.refdef.vieworg, cl.v_forward, cl.v_right, cl.v_up);
#ifdef CDA
	CDAudio_Update();
#endif

	/* advance local effects for next frame */
	CL_RunDLights();

	CL_RunLightStyles();

	SCR_RunCinematic();

	SCR_RunConsole();

	cls.framecount++;

	if (log_stats->value)
	{
		if (cls.state == ca_active)
		{
			if (!lasttimecalled)
			{
				lasttimecalled = Sys_Milliseconds();

				if (log_stats_file)
				{
					fprintf(log_stats_file, "0\n");
				}
			}

			else
			{
				int now = Sys_Milliseconds();

				if (log_stats_file)
				{
					fprintf(log_stats_file, "%d\n", now - lasttimecalled);
				}

				lasttimecalled = now;
			}
		}
	}
}
Exemplo n.º 5
0
/*
=================
CL_RequestNextDownload
=================
*/
void CL_RequestNextDownload (void)
{
	unsigned	map_checksum;		// for detecting cheater maps
	char fn[MAX_OSPATH];
	dmdl_t *pheader;

	if (cls.state != ca_connected)
		return;

	// clear failed download list
	if (precache_check == CS_MODELS)
		CL_InitFailedDownloadList ();

	// Knightmare- BIG UGLY HACK for connected to server using old protocol
	// Changed config strings require different parsing
	if ( LegacyProtocol() )
	{	// Old download code
		if (!allow_download->value && precache_check < OLD_ENV_CNT)
			precache_check = OLD_ENV_CNT;

		//ZOID
		if (precache_check == CS_MODELS) { // confirm map
			precache_check = CS_MODELS+2; // 0 isn't used
			if (allow_download_maps->value)
				if (!CL_CheckOrDownloadFile(cl.configstrings[CS_MODELS+1]))
					return; // started a download
		}
		if (precache_check >= CS_MODELS && precache_check < CS_MODELS+OLD_MAX_MODELS) {
			if (allow_download_models->value) {
				while (precache_check < CS_MODELS+OLD_MAX_MODELS &&
					cl.configstrings[precache_check][0]) {
					if (cl.configstrings[precache_check][0] == '*' ||
						cl.configstrings[precache_check][0] == '#') {
						precache_check++;
						continue;
					}
					if (precache_model_skin == 0) {
						if (!CL_CheckOrDownloadFile(cl.configstrings[precache_check])) {
							precache_model_skin = 1;
							return; // started a download
						}
						precache_model_skin = 1;
					}

					// checking for skins in the model
					if (!precache_model) {

						FS_LoadFile (cl.configstrings[precache_check], (void **)&precache_model);
						if (!precache_model) {
							precache_model_skin = 0;
							precache_check++;
							continue; // couldn't load it
						}
						if (LittleLong(*(unsigned *)precache_model) != IDALIASHEADER) {
							// not an alias model
							FS_FreeFile(precache_model);
							precache_model = 0;
							precache_model_skin = 0;
							precache_check++;
							continue;
						}
						pheader = (dmdl_t *)precache_model;
						if (LittleLong (pheader->version) != ALIAS_VERSION) {
							precache_check++;
							precache_model_skin = 0;
							continue; // couldn't load it
						}
					}

					pheader = (dmdl_t *)precache_model;

					while (precache_model_skin - 1 < LittleLong(pheader->num_skins)) {
						if (!CL_CheckOrDownloadFile((char *)precache_model +
							LittleLong(pheader->ofs_skins) + 
							(precache_model_skin - 1)*MAX_SKINNAME)) {
							precache_model_skin++;
							return; // started a download
						}
						precache_model_skin++;
					}
					if (precache_model) { 
						FS_FreeFile(precache_model);
						precache_model = 0;
					}
					precache_model_skin = 0;
					precache_check++;
				}
			}
			precache_check = OLD_CS_SOUNDS;
		}
		if (precache_check >= OLD_CS_SOUNDS && precache_check < OLD_CS_SOUNDS+OLD_MAX_SOUNDS) { 
			if (allow_download_sounds->value) {
				if (precache_check == OLD_CS_SOUNDS)
					precache_check++; // zero is blank
				while (precache_check < OLD_CS_SOUNDS+OLD_MAX_SOUNDS &&
					cl.configstrings[precache_check][0]) {
					if (cl.configstrings[precache_check][0] == '*') {
						precache_check++;
						continue;
					}
					Com_sprintf(fn, sizeof(fn), "sound/%s", cl.configstrings[precache_check++]);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = OLD_CS_IMAGES;
		}
		if (precache_check >= OLD_CS_IMAGES && precache_check < CS_IMAGES+OLD_MAX_IMAGES) {
			if (precache_check == OLD_CS_IMAGES)
				precache_check++; // zero is blank
			while (precache_check < OLD_CS_IMAGES+OLD_MAX_IMAGES &&
				cl.configstrings[precache_check][0]) {
				Com_sprintf(fn, sizeof(fn), "pics/%s.pcx", cl.configstrings[precache_check++]);
				if (!CL_CheckOrDownloadFile(fn))
					return; // started a download
			}
			precache_check = OLD_CS_PLAYERSKINS;
		}
		// skins are special, since a player has three things to download:
		// model, weapon model and skin
		// so precache_check is now *3
		if (precache_check >= OLD_CS_PLAYERSKINS && precache_check < OLD_CS_PLAYERSKINS + MAX_CLIENTS * PLAYER_MULT) {
			if (allow_download_players->value)
			{
				while (precache_check < OLD_CS_PLAYERSKINS + MAX_CLIENTS * PLAYER_MULT)
				{
					int32_t i, n;
					char model[MAX_QPATH], skin[MAX_QPATH], *p;

					i = (precache_check - OLD_CS_PLAYERSKINS)/PLAYER_MULT;
					n = (precache_check - OLD_CS_PLAYERSKINS)%PLAYER_MULT;

					if (!cl.configstrings[OLD_CS_PLAYERSKINS+i][0]) {
						precache_check = OLD_CS_PLAYERSKINS + (i + 1) * PLAYER_MULT;
						continue;
					}

					if ((p = strchr(cl.configstrings[OLD_CS_PLAYERSKINS+i], '\\')) != NULL)
						p++;
					else
						p = cl.configstrings[OLD_CS_PLAYERSKINS+i];
					strcpy(model, p);
					p = strchr(model, '/');
					if (!p)
						p = strchr(model, '\\');
					if (p) {
						*p++ = 0;
						strcpy(skin, p);
					} else
						*skin = 0;

					switch (n) {
					case 0: // model
						Com_sprintf(fn, sizeof(fn), "players/%s/tris.md2", model);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = OLD_CS_PLAYERSKINS + i * PLAYER_MULT + 1;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 1: // weapon model
						Com_sprintf(fn, sizeof(fn), "players/%s/weapon.md2", model);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = OLD_CS_PLAYERSKINS + i * PLAYER_MULT + 2;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 2: // weapon skin
						Com_sprintf(fn, sizeof(fn), "players/%s/weapon.pcx", model);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = OLD_CS_PLAYERSKINS + i * PLAYER_MULT + 3;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 3: // skin
						Com_sprintf(fn, sizeof(fn), "players/%s/%s.pcx", model, skin);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = OLD_CS_PLAYERSKINS + i * PLAYER_MULT + 4;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 4: // skin_i
						Com_sprintf(fn, sizeof(fn), "players/%s/%s_i.pcx", model, skin);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = OLD_CS_PLAYERSKINS + i * PLAYER_MULT + 5;
							return; // started a download
						}
						// move on to next model
						precache_check = OLD_CS_PLAYERSKINS + (i + 1) * PLAYER_MULT;
					}
				}
			}
			// precache phase completed
			precache_check = OLD_ENV_CNT;
		}

		if (precache_check == OLD_ENV_CNT) {
			precache_check = OLD_ENV_CNT + 1;

			CM_LoadMap (cl.configstrings[CS_MODELS+1], true, &map_checksum);

			if (map_checksum != atoi(cl.configstrings[CS_MAPCHECKSUM])) {
				Com_Error (ERR_DROP, "Local map version differs from server: %i != '%s'\n",
					map_checksum, cl.configstrings[CS_MAPCHECKSUM]);
				return;
			}
		}

		if (precache_check > OLD_ENV_CNT && precache_check < OLD_TEXTURE_CNT) {
			if (allow_download->value && allow_download_maps->value) {
				while (precache_check < OLD_TEXTURE_CNT) {
					int32_t n = precache_check++ - OLD_ENV_CNT - 1;

					if (n & 1)
						Com_sprintf(fn, sizeof(fn), "env/%s%s.pcx", 
							cl.configstrings[CS_SKY], env_suf[n/2]);
					else
						Com_sprintf(fn, sizeof(fn), "env/%s%s.tga", 
							cl.configstrings[CS_SKY], env_suf[n/2]);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = OLD_TEXTURE_CNT;
		}

		if (precache_check == OLD_TEXTURE_CNT) {
			precache_check = OLD_TEXTURE_CNT+1;
			precache_tex = 0;
		}

		// confirm existance of .wal textures, download any that don't exist
		if (precache_check == OLD_TEXTURE_CNT+1) {
			// from qcommon/cmodel.c
			extern int32_t			numtexinfo;
			extern mapsurface_t	map_surfaces[];

			if (allow_download->value && allow_download_maps->value)
			{
				while (precache_tex < numtexinfo)
				{
					char fn[MAX_OSPATH];

					sprintf(fn, "textures/%s.wal", map_surfaces[precache_tex++].rname);
					if (!CL_CheckOrDownloadFile(fn))
					{ // Knightmare - jump to next different texture name
					/*	char lasttexname[MAX_OSPATH];
						char nexttexname[MAX_OSPATH];

						sprintf(lasttexname, "%s", map_surfaces[precache_tex].rname);
						while ((precache_tex < numtexinfo))
						{
							sprintf(nexttexname, "%s", map_surfaces[precache_tex+1].rname);
							if (strcmp(lasttexname, nexttexname))
								break;
							precache_tex++;
						}*/
						return; // started a download
					}
				}
			}
			//precache_check = OLD_TEXTURE_CNT+999;
			precache_check = OLD_TEXTURE_CNT+2;
			precache_tex = 0;
		}

		// confirm existance of .jpg textures, try to download any that don't exist
		if (precache_check == OLD_TEXTURE_CNT+2) {
			// from qcommon/cmodel.c
			extern int32_t			numtexinfo;
			extern mapsurface_t	map_surfaces[];

			if (allow_download->value && allow_download_maps->value)
			{
				while (precache_tex < numtexinfo)
				{
					char fn[MAX_OSPATH];

					Com_sprintf(fn, sizeof(fn), "textures/%s.jpg", map_surfaces[precache_tex++].rname);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = OLD_TEXTURE_CNT+3;
			precache_tex = 0;
		}

		// confirm existance of .tga textures, try to download any that don't exist
		if (precache_check == OLD_TEXTURE_CNT+3) {
			// from qcommon/cmodel.c
			extern int32_t			numtexinfo;
			extern mapsurface_t	map_surfaces[];

			if (allow_download->value && allow_download_maps->value)
			{
				while (precache_tex < numtexinfo)
				{
					char fn[MAX_OSPATH];

					Com_sprintf(fn, sizeof(fn), "textures/%s.tga", map_surfaces[precache_tex++].rname);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = OLD_TEXTURE_CNT+999;
		}
	}	//end old download code
	else // New download code
	{
		if (!allow_download->value && precache_check < ENV_CNT)
			precache_check = ENV_CNT;

		// Try downloading pk3 file for current map from server, hack by Jay Dolan
		if (precache_check == CS_MODELS && precache_pak == 0) {
			precache_pak++;
			if (strlen(cl.configstrings[CS_PAKFILE])) {
				if (!CL_CheckOrDownloadFile(cl.configstrings[CS_PAKFILE]))
					return;  // started a download
			}
		}

		// ZOID
		if (precache_check == CS_MODELS) { // confirm map
			precache_check = CS_MODELS+2; // 0 isn't used
			if (allow_download_maps->value)
				if (!CL_CheckOrDownloadFile(cl.configstrings[CS_MODELS+1]))
					return; // started a download
		}
		if (precache_check >= CS_MODELS && precache_check < CS_MODELS+MAX_MODELS)
		{
			if (allow_download_models->value)
			{
				while (precache_check < CS_MODELS+MAX_MODELS &&
					cl.configstrings[precache_check][0]) {
					if (cl.configstrings[precache_check][0] == '*' ||
						cl.configstrings[precache_check][0] == '#') {
						precache_check++;
						continue;
					}
					if (precache_model_skin == 0) {
						if (!CL_CheckOrDownloadFile(cl.configstrings[precache_check])) {
							precache_model_skin = 1;
							return; // started a download
						}
						precache_model_skin = 1;
					}

					// checking for skins in the model
					if (!precache_model)
					{

						FS_LoadFile (cl.configstrings[precache_check], (void **)&precache_model);
						if (!precache_model) {
							precache_model_skin = 0;
							precache_check++;
							continue; // couldn't load it
						}
						if (LittleLong(*(unsigned *)precache_model) != IDALIASHEADER) {
							// not an alias model
							FS_FreeFile(precache_model);
							precache_model = 0;
							precache_model_skin = 0;
							precache_check++;
							continue;
						}
						pheader = (dmdl_t *)precache_model;
						if (LittleLong (pheader->version) != ALIAS_VERSION) {
							precache_check++;
							precache_model_skin = 0;
							continue; // couldn't load it
						}
					}

					pheader = (dmdl_t *)precache_model;

					while (precache_model_skin - 1 < LittleLong(pheader->num_skins)) {
						if (!CL_CheckOrDownloadFile((char *)precache_model +
							LittleLong(pheader->ofs_skins) + 
							(precache_model_skin - 1)*MAX_SKINNAME)) {
							precache_model_skin++;
							return; // started a download
						}
						precache_model_skin++;
					}
					if (precache_model) { 
						FS_FreeFile(precache_model);
						precache_model = 0;
					}
					precache_model_skin = 0;
					precache_check++;
				}
			}
			precache_check = CS_SOUNDS;
		}
		if (precache_check >= CS_SOUNDS && precache_check < CS_SOUNDS+MAX_SOUNDS) { 
			if (allow_download_sounds->value) {
				if (precache_check == CS_SOUNDS)
					precache_check++; // zero is blank
				while (precache_check < CS_SOUNDS+MAX_SOUNDS &&
					cl.configstrings[precache_check][0]) {
					if (cl.configstrings[precache_check][0] == '*') {
						precache_check++;
						continue;
					}
					Com_sprintf(fn, sizeof(fn), "sound/%s", cl.configstrings[precache_check++]);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = CS_IMAGES;
		}
		if (precache_check >= CS_IMAGES && precache_check < CS_IMAGES+MAX_IMAGES) {
			if (precache_check == CS_IMAGES)
				precache_check++; // zero is blank
			while (precache_check < CS_IMAGES+MAX_IMAGES &&
				cl.configstrings[precache_check][0])
			{	
				Com_sprintf(fn, sizeof(fn), "pics/%s.pcx", cl.configstrings[precache_check++]);
				if (!CL_CheckOrDownloadFile(fn))
					return; // started a download
			}
			precache_check = CS_PLAYERSKINS;
		}
		// skins are special, since a player has three things to download:
		// model, weapon model and skin
		// so precache_check is now *3
		if (precache_check >= CS_PLAYERSKINS && precache_check < CS_PLAYERSKINS + MAX_CLIENTS * PLAYER_MULT) {
			if (allow_download_players->value) {
				while (precache_check < CS_PLAYERSKINS + MAX_CLIENTS * PLAYER_MULT) {
					int32_t i, n;
					char model[MAX_QPATH], skin[MAX_QPATH], *p;

					i = (precache_check - CS_PLAYERSKINS)/PLAYER_MULT;
					n = (precache_check - CS_PLAYERSKINS)%PLAYER_MULT;

					if (!cl.configstrings[CS_PLAYERSKINS+i][0]) {
						precache_check = CS_PLAYERSKINS + (i + 1) * PLAYER_MULT;
						continue;
					}

					if ((p = strchr(cl.configstrings[CS_PLAYERSKINS+i], '\\')) != NULL)
						p++;
					else
						p = cl.configstrings[CS_PLAYERSKINS+i];
					strcpy(model, p);
					p = strchr(model, '/');
					if (!p)
						p = strchr(model, '\\');
					if (p) {
						*p++ = 0;
						strcpy(skin, p);
					} else
						*skin = 0;

					switch (n) {
					case 0: // model
						Com_sprintf(fn, sizeof(fn), "players/%s/tris.md2", model);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 1;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 1: // weapon model
						Com_sprintf(fn, sizeof(fn), "players/%s/weapon.md2", model);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 2;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 2: // weapon skin
						Com_sprintf(fn, sizeof(fn), "players/%s/weapon.pcx", model);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 3;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 3: // skin
						Com_sprintf(fn, sizeof(fn), "players/%s/%s.pcx", model, skin);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 4;
							return; // started a download
						}
						n++;
						/*FALL THROUGH*/

					case 4: // skin_i
						Com_sprintf(fn, sizeof(fn), "players/%s/%s_i.pcx", model, skin);
						if (!CL_CheckOrDownloadFile(fn)) {
							precache_check = CS_PLAYERSKINS + i * PLAYER_MULT + 5;
							return; // started a download
						}
						// move on to next model
						precache_check = CS_PLAYERSKINS + (i + 1) * PLAYER_MULT;
					}
				}
			}
			// precache phase completed
			precache_check = ENV_CNT;
		}

		if (precache_check == ENV_CNT) {
			precache_check = ENV_CNT + 1;

			CM_LoadMap (cl.configstrings[CS_MODELS+1], true, &map_checksum);

			if (map_checksum != atoi(cl.configstrings[CS_MAPCHECKSUM])) {
				Com_Error (ERR_DROP, "Local map version differs from server: %i != '%s'\n",
					map_checksum, cl.configstrings[CS_MAPCHECKSUM]);
				return;
			}
		}

		if (precache_check > ENV_CNT && precache_check < TEXTURE_CNT) {
			if (allow_download->value && allow_download_maps->value) {
				while (precache_check < TEXTURE_CNT) {
					int32_t n = precache_check++ - ENV_CNT - 1;

					if (n & 1)
						Com_sprintf(fn, sizeof(fn), "env/%s%s.pcx", 
							cl.configstrings[CS_SKY], env_suf[n/2]);
					else
						Com_sprintf(fn, sizeof(fn), "env/%s%s.tga", 
							cl.configstrings[CS_SKY], env_suf[n/2]);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = TEXTURE_CNT;
		}

		if (precache_check == TEXTURE_CNT) {
			precache_check = TEXTURE_CNT+1;
			precache_tex = 0;
		}
		// confirm existance of .wal textures, download any that don't exist
		if (precache_check == TEXTURE_CNT+1) {
			// from qcommon/cmodel.c
			extern int32_t			numtexinfo;
			extern mapsurface_t	map_surfaces[];

			if (allow_download->value && allow_download_maps->value && !Com_ServerState())
			{
				while (precache_tex < numtexinfo)
				{
					char fn[MAX_OSPATH];

					Com_sprintf(fn, sizeof(fn), "textures/%s.wal", map_surfaces[precache_tex++].rname);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			//precache_check = TEXTURE_CNT+999;
			precache_check = TEXTURE_CNT+2;
			precache_tex = 0;
		}

		// confirm existance of .jpg textures, try to download any that don't exist
		if (precache_check == TEXTURE_CNT+2) {
			// from qcommon/cmodel.c
			extern int32_t			numtexinfo;
			extern mapsurface_t	map_surfaces[];

			if (allow_download->value && allow_download_maps->value && allow_download_textures_24bit->value && !Com_ServerState())
			{
				while (precache_tex < numtexinfo)
				{
					char fn[MAX_OSPATH];

					Com_sprintf(fn, sizeof(fn), "textures/%s.jpg", map_surfaces[precache_tex++].rname);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = TEXTURE_CNT+3;
			precache_tex = 0;
		}

		// confirm existance of .tga textures, try to download any that don't exist
		if (precache_check == TEXTURE_CNT+3) {
			// from qcommon/cmodel.c
			extern int32_t			numtexinfo;
			extern mapsurface_t	map_surfaces[];

			if (allow_download->value && allow_download_maps->value && allow_download_textures_24bit->value && !Com_ServerState())
			{
				while (precache_tex < numtexinfo)
				{
					char fn[MAX_OSPATH];

					Com_sprintf(fn, sizeof(fn), "textures/%s.tga", map_surfaces[precache_tex++].rname);
					if (!CL_CheckOrDownloadFile(fn))
						return; // started a download
				}
			}
			precache_check = TEXTURE_CNT+999;
		}
	}	// end new download code
//ZOID

	CL_RegisterSounds ();
	CL_PrepRefresh ();

	MSG_WriteByte (&cls.netchan.message, clc_stringcmd);
	MSG_WriteString (&cls.netchan.message, va("begin %i\n", precache_spawncount) );
}