⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cl_fx.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* * java * Copyright (C) 2004 *  * $Id: CL_fx.java,v 1.9 2005/02/06 19:18:10 salomo Exp $ *//* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */package jake2.client;import jake2.Defines;import jake2.Globals;import jake2.game.entity_state_t;import jake2.game.monsters.M_Flash;import jake2.qcommon.Com;import jake2.qcommon.MSG;import jake2.sound.S;import jake2.util.Lib;import jake2.util.Math3D;/** * Client Graphics Effects. */public class CL_fx {	static class cdlight_t {		int key; // so entities can reuse same entry		float[] color = { 0, 0, 0 };		float[] origin = { 0, 0, 0 };		float radius;		float die; // stop lighting after this time		float minlight; // don't add when contributing less		void clear() {			radius = minlight = color[0] = color[1] = color[2] = 0;		}	}	static cparticle_t[] particles = new cparticle_t[Defines.MAX_PARTICLES];	static {		for (int i = 0; i < particles.length; i++)			particles[i] = new cparticle_t();	}	static int cl_numparticles = Defines.MAX_PARTICLES;	static final float INSTANT_PARTICLE = -10000.0f;	static float[][] avelocities = new float[Defines.NUMVERTEXNORMALS][3];	static clightstyle_t[] cl_lightstyle = new clightstyle_t[Defines.MAX_LIGHTSTYLES];	static int lastofs;	/*	 * ==============================================================	 * 	 * LIGHT STYLE MANAGEMENT	 * 	 * ==============================================================	 */	static class clightstyle_t {		int length;		float[] value = new float[3];		float[] map = new float[Defines.MAX_QPATH];		void clear() {			value[0] = value[1] = value[2] = length = 0;			for (int i = 0; i < map.length; i++)				map[i] = 0.0f;		}	}	static {		for (int i = 0; i < cl_lightstyle.length; i++) {			cl_lightstyle[i] = new clightstyle_t();		}	}	/*	 * ==============================================================	 * 	 * DLIGHT MANAGEMENT	 * 	 * ==============================================================	 */	static cdlight_t[] cl_dlights = new cdlight_t[Defines.MAX_DLIGHTS];	static {		for (int i = 0; i < cl_dlights.length; i++)			cl_dlights[i] = new cdlight_t();	}	/*	 * ================ CL_ClearDlights ================	 */	static void ClearDlights() {		//		memset (cl_dlights, 0, sizeof(cl_dlights));		for (int i = 0; i < cl_dlights.length; i++) {			cl_dlights[i].clear();		}	}	/*	 * ================ CL_ClearLightStyles ================	 */	static void ClearLightStyles() {		//memset (cl_lightstyle, 0, sizeof(cl_lightstyle));		for (int i = 0; i < cl_lightstyle.length; i++)			cl_lightstyle[i].clear();		lastofs = -1;	}	/*	 * ================ CL_RunLightStyles ================	 */	static void RunLightStyles() {		clightstyle_t ls;		int ofs = Globals.cl.time / 100;		if (ofs == lastofs)			return;		lastofs = ofs;		for (int i = 0; i < cl_lightstyle.length; i++) {			ls = cl_lightstyle[i];			if (ls.length == 0) {				ls.value[0] = ls.value[1] = ls.value[2] = 1.0f;				continue;			}			if (ls.length == 1)				ls.value[0] = ls.value[1] = ls.value[2] = ls.map[0];			else				ls.value[0] = ls.value[1] = ls.value[2] = ls.map[ofs % ls.length];		}	}	static void SetLightstyle(int i) {		String s;		int j, k;		s = Globals.cl.configstrings[i + Defines.CS_LIGHTS];		j = s.length();		if (j >= Defines.MAX_QPATH)			Com.Error(Defines.ERR_DROP, "svc_lightstyle length=" + j);		cl_lightstyle[i].length = j;		for (k = 0; k < j; k++)			cl_lightstyle[i].map[k] = (float) (s.charAt(k) - 'a') / (float) ('m' - 'a');	}	/*	 * ================ CL_AddLightStyles ================	 */	static void AddLightStyles() {		clightstyle_t ls;		for (int i = 0; i < cl_lightstyle.length; i++) {			ls = cl_lightstyle[i];			V.AddLightStyle(i, ls.value[0], ls.value[1], ls.value[2]);		}	}	/*	 * =============== CL_AllocDlight	 * 	 * ===============	 */	static cdlight_t AllocDlight(int key) {		int i;		cdlight_t dl;		//	   first look for an exact key match		if (key != 0) {			for (i = 0; i < Defines.MAX_DLIGHTS; i++) {				dl = cl_dlights[i];				if (dl.key == key) {					//memset (dl, 0, sizeof(*dl));					dl.clear();					dl.key = key;					return dl;				}			}		}		//	   then look for anything else		for (i = 0; i < Defines.MAX_DLIGHTS; i++) {			dl = cl_dlights[i];			if (dl.die < Globals.cl.time) {				//memset (dl, 0, sizeof(*dl));				dl.clear();				dl.key = key;				return dl;			}		}		//dl = &cl_dlights[0];		//memset (dl, 0, sizeof(*dl));		dl = cl_dlights[0];		dl.clear();		dl.key = key;		return dl;	}	/*	 * =============== 	 * CL_RunDLights	 * ===============	 */	static void RunDLights() {		cdlight_t dl;		for (int i = 0; i < Defines.MAX_DLIGHTS; i++) {			dl = cl_dlights[i];			if (dl.radius == 0.0f)				continue;			if (dl.die < Globals.cl.time) {				dl.radius = 0.0f;				return;			}		}	}	// stack variable	private static final float[] fv = {0, 0, 0};	private static final float[] rv = {0, 0, 0};	/*	 * ==============	 *  CL_ParseMuzzleFlash	 * ==============	 */	static void ParseMuzzleFlash() {		float volume;		String soundname;		int i = MSG.ReadShort(Globals.net_message);		if (i < 1 || i >= Defines.MAX_EDICTS)			Com.Error(Defines.ERR_DROP, "CL_ParseMuzzleFlash: bad entity");		int weapon = MSG.ReadByte(Globals.net_message);		int silenced = weapon & Defines.MZ_SILENCED;		weapon &= ~Defines.MZ_SILENCED;		centity_t pl = Globals.cl_entities[i];		cdlight_t dl = AllocDlight(i);		Math3D.VectorCopy(pl.current.origin, dl.origin);		Math3D.AngleVectors(pl.current.angles, fv, rv, null);		Math3D.VectorMA(dl.origin, 18, fv, dl.origin);		Math3D.VectorMA(dl.origin, 16, rv, dl.origin);		if (silenced != 0)			dl.radius = 100 + (Globals.rnd.nextInt() & 31);		else			dl.radius = 200 + (Globals.rnd.nextInt() & 31);		dl.minlight = 32;		dl.die = Globals.cl.time; // + 0.1;		if (silenced != 0)			volume = 0.2f;		else			volume = 1;		switch (weapon) {		case Defines.MZ_BLASTER:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/blastf1a.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_BLUEHYPERBLASTER:			dl.color[0] = 0;			dl.color[1] = 0;			dl.color[2] = 1;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/hyprbf1a.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_HYPERBLASTER:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/hyprbf1a.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_MACHINEGUN:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			//Com_sprintf(soundname, sizeof(soundname),			// "weapons/machgf%ib.wav", (rand() % 5) + 1);			soundname = "weapons/machgf" + ((Globals.rnd.nextInt(5)) + 1) + "b.wav";			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound(soundname), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_SHOTGUN:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/shotgf1b.wav"), volume, Defines.ATTN_NORM, 0);			S.StartSound(null, i, Defines.CHAN_AUTO, S.RegisterSound("weapons/shotgr1b.wav"), volume, Defines.ATTN_NORM, 0.1f);			break;		case Defines.MZ_SSHOTGUN:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/sshotf1b.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_CHAINGUN1:			dl.radius = 200 + (Globals.rnd.nextInt() & 31);			dl.color[0] = 1;			dl.color[1] = 0.25f;			dl.color[2] = 0;			//Com_sprintf(soundname, sizeof(soundname),			// "weapons/machgf%ib.wav", (rand() % 5) + 1);			soundname = "weapons/machgf" + ((Globals.rnd.nextInt(5)) + 1) + "b.wav";			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound(soundname), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_CHAINGUN2:			dl.radius = 225 + (Globals.rnd.nextInt() & 31);			dl.color[0] = 1;			dl.color[1] = 0.5f;			dl.color[2] = 0;			dl.die = Globals.cl.time + 0.1f; // long delay			//Com_sprintf(soundname, sizeof(soundname),			// "weapons/machgf%ib.wav", (rand() % 5) + 1);			soundname = "weapons/machgf" + ((Globals.rnd.nextInt(5)) + 1) + "b.wav";			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound(soundname), volume, Defines.ATTN_NORM, 0);			//Com_sprintf(soundname, sizeof(soundname),			// "weapons/machgf%ib.wav", (rand() % 5) + 1);			soundname = "weapons/machgf" + ((Globals.rnd.nextInt(5)) + 1) + "b.wav";			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound(soundname), volume, Defines.ATTN_NORM, 0.05f);			break;		case Defines.MZ_CHAINGUN3:			dl.radius = 250 + (Globals.rnd.nextInt() & 31);			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			dl.die = Globals.cl.time + 0.1f; // long delay			//Com_sprintf(soundname, sizeof(soundname),			// "weapons/machgf%ib.wav", (rand() % 5) + 1);			soundname = "weapons/machgf" + ((Globals.rnd.nextInt(5)) + 1) + "b.wav";			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound(soundname), volume, Defines.ATTN_NORM, 0);			//Com_sprintf(soundname, sizeof(soundname),			// "weapons/machgf%ib.wav", (rand() % 5) + 1);			soundname = "weapons/machgf" + ((Globals.rnd.nextInt(5)) + 1) + "b.wav";			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound(soundname), volume, Defines.ATTN_NORM, 0.033f);			//Com_sprintf(soundname, sizeof(soundname),			// "weapons/machgf%ib.wav", (rand() % 5) + 1);			soundname = "weapons/machgf" + ((Globals.rnd.nextInt(5)) + 1) + "b.wav";			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound(soundname), volume, Defines.ATTN_NORM, 0.066f);			break;		case Defines.MZ_RAILGUN:			dl.color[0] = 0.5f;			dl.color[1] = 0.5f;			dl.color[2] = 1.0f;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/railgf1a.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_ROCKET:			dl.color[0] = 1;			dl.color[1] = 0.5f;			dl.color[2] = 0.2f;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/rocklf1a.wav"), volume, Defines.ATTN_NORM, 0);			S.StartSound(null, i, Defines.CHAN_AUTO, S.RegisterSound("weapons/rocklr1b.wav"), volume, Defines.ATTN_NORM, 0.1f);			break;		case Defines.MZ_GRENADE:			dl.color[0] = 1;			dl.color[1] = 0.5f;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/grenlf1a.wav"), volume, Defines.ATTN_NORM, 0);			S.StartSound(null, i, Defines.CHAN_AUTO, S.RegisterSound("weapons/grenlr1b.wav"), volume, Defines.ATTN_NORM, 0.1f);			break;		case Defines.MZ_BFG:			dl.color[0] = 0;			dl.color[1] = 1;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/bfg__f1y.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_LOGIN:			dl.color[0] = 0;			dl.color[1] = 1;			dl.color[2] = 0;			dl.die = Globals.cl.time + 1.0f;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/grenlf1a.wav"), 1, Defines.ATTN_NORM, 0);			LogoutEffect(pl.current.origin, weapon);			break;		case Defines.MZ_LOGOUT:			dl.color[0] = 1;			dl.color[1] = 0;			dl.color[2] = 0;			dl.die = Globals.cl.time + 1.0f;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/grenlf1a.wav"), 1, Defines.ATTN_NORM, 0);			LogoutEffect(pl.current.origin, weapon);			break;		case Defines.MZ_RESPAWN:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			dl.die = Globals.cl.time + 1.0f;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/grenlf1a.wav"), 1, Defines.ATTN_NORM, 0);			LogoutEffect(pl.current.origin, weapon);			break;		// RAFAEL		case Defines.MZ_PHALANX:			dl.color[0] = 1;			dl.color[1] = 0.5f;			dl.color[2] = 0.5f;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/plasshot.wav"), volume, Defines.ATTN_NORM, 0);			break;		// RAFAEL		case Defines.MZ_IONRIPPER:			dl.color[0] = 1;			dl.color[1] = 0.5f;			dl.color[2] = 0.5f;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/rippfire.wav"), volume, Defines.ATTN_NORM, 0);			break;		//	   ======================		//	   PGM		case Defines.MZ_ETF_RIFLE:			dl.color[0] = 0.9f;			dl.color[1] = 0.7f;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/nail1.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_SHOTGUN2:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/shotg2.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_HEATBEAM:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			dl.die = Globals.cl.time + 100;			//			S.StartSound (null, i, CHAN_WEAPON,			// S.RegisterSound("weapons/bfg__l1a.wav"), volume, ATTN_NORM, 0);			break;		case Defines.MZ_BLASTER2:			dl.color[0] = 0;			dl.color[1] = 1;			dl.color[2] = 0;			// FIXME - different sound for blaster2 ??			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/blastf1a.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_TRACKER:			// negative flashes handled the same in gl/soft until CL_AddDLights			dl.color[0] = -1;			dl.color[1] = -1;			dl.color[2] = -1;			S.StartSound(null, i, Defines.CHAN_WEAPON, S.RegisterSound("weapons/disint2.wav"), volume, Defines.ATTN_NORM, 0);			break;		case Defines.MZ_NUKE1:			dl.color[0] = 1;			dl.color[1] = 0;			dl.color[2] = 0;			dl.die = Globals.cl.time + 100;			break;		case Defines.MZ_NUKE2:			dl.color[0] = 1;			dl.color[1] = 1;			dl.color[2] = 0;			dl.die = Globals.cl.time + 100;			break;		case Defines.MZ_NUKE4:			dl.color[0] = 0;			dl.color[1] = 0;			dl.color[2] = 1;			dl.die = Globals.cl.time + 100;			break;		case Defines.MZ_NUKE8:			dl.color[0] = 0;			dl.color[1] = 1;			dl.color[2] = 1;			dl.die = Globals.cl.time + 100;			break;		//	   PGM		//	   ======================		}	}	// stack variable	private static final float[] origin = {0, 0, 0};	private static final float[] forward = {0, 0, 0};	private static final float[] right = {0, 0, 0};	/*	 * ============== CL_ParseMuzzleFlash2 ==============	 */	static void ParseMuzzleFlash2() {		String soundname;		int ent = MSG.ReadShort(Globals.net_message);		if (ent < 1 || ent >= Defines.MAX_EDICTS)			Com.Error(Defines.ERR_DROP, "CL_ParseMuzzleFlash2: bad entity");		int flash_number = MSG.ReadByte(Globals.net_message);		// locate the origin		Math3D.AngleVectors(Globals.cl_entities[ent].current.angles, forward, right, null);		origin[0] = Globals.cl_entities[ent].current.origin[0] + forward[0] * M_Flash.monster_flash_offset[flash_number][0] + right[0]				* M_Flash.monster_flash_offset[flash_number][1];		origin[1] = Globals.cl_entities[ent].current.origin[1] + forward[1] * M_Flash.monster_flash_offset[flash_number][0] + right[1]				* M_Flash.monster_flash_offset[flash_number][1];		origin[2] = Globals.cl_entities[ent].current.origin[2] + forward[2] * M_Flash.monster_flash_offset[flash_number][0] + right[2]				* M_Flash.monster_flash_offset[flash_number][1] + M_Flash.monster_flash_offset[flash_number][2];		cdlight_t dl = AllocDlight(ent);		Math3D.VectorCopy(origin, dl.origin);		dl.radius = 200 + (Globals.rnd.nextInt() & 31);		dl.minlight = 32;		dl.die = Globals.cl.time; // + 0.1;		switch (flash_number) {		case Defines.MZ2_INFANTRY_MACHINEGUN_1:		case Defines.MZ2_INFANTRY_MACHINEGUN_2:		case Defines.MZ2_INFANTRY_MACHINEGUN_3:		case Defines.MZ2_INFANTRY_MACHINEGUN_4:		case Defines.MZ2_INFANTRY_MACHINEGUN_5:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -