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

📄 cl_ents.java

📁 Jake2是一个Java 3D游戏引擎.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * java * Copyright (C) 2004 *  * $Id: CL_ents.java,v 1.10 2005/02/06 19:17:03 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.*;import jake2.qcommon.*;import jake2.util.Math3D;/** * CL_ents *///	   cl_ents.c -- entity parsing and management/* * ========================================================================= *  * FRAME PARSING *  * ========================================================================= */public class CL_ents {	static int bitcounts[] = new int[32]; /// just for protocol profiling	static int bfg_lightramp[] = { 300, 400, 600, 300, 150, 75 };	/*	 * ================= CL_ParseEntityBits	 * 	 * Returns the entity number and the header bits =================	 */	public static int ParseEntityBits(int bits[]) {		int b, total;		int i;		int number;		total = MSG.ReadByte(Globals.net_message);		if ((total & Defines.U_MOREBITS1) != 0) {		    			b = MSG.ReadByte(Globals.net_message);			total |= b << 8;		}		if ((total & Defines.U_MOREBITS2) != 0) {		    			b = MSG.ReadByte(Globals.net_message);			total |= b << 16;		}		if ((total & Defines.U_MOREBITS3) != 0) {		    			b = MSG.ReadByte(Globals.net_message);			total |= b << 24;		}		// count the bits for net profiling		for (i = 0; i < 32; i++)			if ((total & (1 << i)) != 0)				bitcounts[i]++;		if ((total & Defines.U_NUMBER16) != 0)			number = MSG.ReadShort(Globals.net_message);		else			number = MSG.ReadByte(Globals.net_message);		bits[0] = total;		return number;	}	/*	 * ================== CL_ParseDelta	 * 	 * Can go from either a baseline or a previous packet_entity	 * ==================	 */	public static void ParseDelta(entity_state_t from, entity_state_t to, int number, int bits) {		// set everything to the state we are delta'ing from		to.set(from);		Math3D.VectorCopy(from.origin, to.old_origin);		to.number = number;		if ((bits & Defines.U_MODEL) != 0)			to.modelindex = MSG.ReadByte(Globals.net_message);		if ((bits & Defines.U_MODEL2) != 0)			to.modelindex2 = MSG.ReadByte(Globals.net_message);		if ((bits & Defines.U_MODEL3) != 0)			to.modelindex3 = MSG.ReadByte(Globals.net_message);		if ((bits & Defines.U_MODEL4) != 0)			to.modelindex4 = MSG.ReadByte(Globals.net_message);		if ((bits & Defines.U_FRAME8) != 0)			to.frame = MSG.ReadByte(Globals.net_message);		if ((bits & Defines.U_FRAME16) != 0)			to.frame = MSG.ReadShort(Globals.net_message);		if ((bits & Defines.U_SKIN8) != 0 && (bits & Defines.U_SKIN16) != 0) //used																			 // for																			 // laser																			 // colors			to.skinnum = MSG.ReadLong(Globals.net_message);		else if ((bits & Defines.U_SKIN8) != 0)			to.skinnum = MSG.ReadByte(Globals.net_message);		else if ((bits & Defines.U_SKIN16) != 0)			to.skinnum = MSG.ReadShort(Globals.net_message);		if ((bits & (Defines.U_EFFECTS8 | Defines.U_EFFECTS16)) == (Defines.U_EFFECTS8 | Defines.U_EFFECTS16))			to.effects = MSG.ReadLong(Globals.net_message);		else if ((bits & Defines.U_EFFECTS8) != 0)			to.effects = MSG.ReadByte(Globals.net_message);		else if ((bits & Defines.U_EFFECTS16) != 0)			to.effects = MSG.ReadShort(Globals.net_message);		if ((bits & (Defines.U_RENDERFX8 | Defines.U_RENDERFX16)) == (Defines.U_RENDERFX8 | Defines.U_RENDERFX16))			to.renderfx = MSG.ReadLong(Globals.net_message);		else if ((bits & Defines.U_RENDERFX8) != 0)			to.renderfx = MSG.ReadByte(Globals.net_message);		else if ((bits & Defines.U_RENDERFX16) != 0)			to.renderfx = MSG.ReadShort(Globals.net_message);		if ((bits & Defines.U_ORIGIN1) != 0)			to.origin[0] = MSG.ReadCoord(Globals.net_message);		if ((bits & Defines.U_ORIGIN2) != 0)			to.origin[1] = MSG.ReadCoord(Globals.net_message);		if ((bits & Defines.U_ORIGIN3) != 0)			to.origin[2] = MSG.ReadCoord(Globals.net_message);		if ((bits & Defines.U_ANGLE1) != 0)			to.angles[0] = MSG.ReadAngle(Globals.net_message);		if ((bits & Defines.U_ANGLE2) != 0)			to.angles[1] = MSG.ReadAngle(Globals.net_message);		if ((bits & Defines.U_ANGLE3) != 0)			to.angles[2] = MSG.ReadAngle(Globals.net_message);		if ((bits & Defines.U_OLDORIGIN) != 0)			MSG.ReadPos(Globals.net_message, to.old_origin);		if ((bits & Defines.U_SOUND) != 0)			to.sound = MSG.ReadByte(Globals.net_message);		if ((bits & Defines.U_EVENT) != 0)			to.event = MSG.ReadByte(Globals.net_message);		else			to.event = 0;		if ((bits & Defines.U_SOLID) != 0)			to.solid = MSG.ReadShort(Globals.net_message);	}	/*	 * ================== CL_DeltaEntity	 * 	 * Parses deltas from the given base and adds the resulting entity to the	 * current frame ==================	 */	public static void DeltaEntity(frame_t frame, int newnum, entity_state_t old, int bits) {		centity_t ent;		entity_state_t state;		ent = Globals.cl_entities[newnum];		state = Globals.cl_parse_entities[Globals.cl.parse_entities & (Defines.MAX_PARSE_ENTITIES - 1)];		Globals.cl.parse_entities++;		frame.num_entities++;		ParseDelta(old, state, newnum, bits);		// some data changes will force no lerping		if (state.modelindex != ent.current.modelindex || state.modelindex2 != ent.current.modelindex2				|| state.modelindex3 != ent.current.modelindex3 || state.modelindex4 != ent.current.modelindex4				|| Math.abs(state.origin[0] - ent.current.origin[0]) > 512 || Math.abs(state.origin[1] - ent.current.origin[1]) > 512				|| Math.abs(state.origin[2] - ent.current.origin[2]) > 512 || state.event == Defines.EV_PLAYER_TELEPORT				|| state.event == Defines.EV_OTHER_TELEPORT) {			ent.serverframe = -99;		}		if (ent.serverframe != Globals.cl.frame.serverframe - 1) { // wasn't in																   // last																   // update, so																   // initialize																   // some																   // things			ent.trailcount = 1024; // for diminishing rocket / grenade trails			// duplicate the current state so lerping doesn't hurt anything			ent.prev.set(state);			if (state.event == Defines.EV_OTHER_TELEPORT) {				Math3D.VectorCopy(state.origin, ent.prev.origin);				Math3D.VectorCopy(state.origin, ent.lerp_origin);			} else {				Math3D.VectorCopy(state.old_origin, ent.prev.origin);				Math3D.VectorCopy(state.old_origin, ent.lerp_origin);			}		} else { // shuffle the last state to previous			// Copy !			ent.prev.set(ent.current);		}		ent.serverframe = Globals.cl.frame.serverframe;		// Copy !		ent.current.set(state);	}	// call by reference	private static final int[] iw = {0};	/*	 * ================== CL_ParsePacketEntities	 * 	 * An svc_packetentities has just been parsed, deal with the rest of the	 * data stream. ==================	 */	public static void ParsePacketEntities(frame_t oldframe, frame_t newframe) {		int newnum;		int bits = 0;		entity_state_t oldstate = null;		int oldnum;		newframe.parse_entities = Globals.cl.parse_entities;		newframe.num_entities = 0;		// delta from the entities present in oldframe		int oldindex = 0;		if (oldframe == null)			oldnum = 99999;		else {			// oldindex == 0. hoz			//			if (oldindex >= oldframe.num_entities)			//				oldnum = 99999;			//			else {			oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];			oldnum = oldstate.number;			//			}		}		while (true) {			//int iw[] = { bits };			iw[0] = bits;			newnum = ParseEntityBits(iw);			bits = iw[0];			if (newnum >= Defines.MAX_EDICTS)				Com.Error(Defines.ERR_DROP, "CL_ParsePacketEntities: bad number:" + newnum);			if (Globals.net_message.readcount > Globals.net_message.cursize)				Com.Error(Defines.ERR_DROP, "CL_ParsePacketEntities: end of message");			if (0 == newnum)				break;			while (oldnum < newnum) { // one or more entities from the old									  // packet are unchanged				if (Globals.cl_shownet.value == 3)					Com.Printf("   unchanged: " + oldnum + "\n");				DeltaEntity(newframe, oldnum, oldstate, 0);				oldindex++;				if (oldindex >= oldframe.num_entities)					oldnum = 99999;				else {					oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];					oldnum = oldstate.number;				}			}			if ((bits & Defines.U_REMOVE) != 0) { // the entity present in												  // oldframe is not in the												  // current frame				if (Globals.cl_shownet.value == 3)					Com.Printf("   remove: " + newnum + "\n");				if (oldnum != newnum)					Com.Printf("U_REMOVE: oldnum != newnum\n");				oldindex++;				if (oldindex >= oldframe.num_entities)					oldnum = 99999;				else {					oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];					oldnum = oldstate.number;				}				continue;			}			if (oldnum == newnum) { // delta from previous state				if (Globals.cl_shownet.value == 3)					Com.Printf("   delta: " + newnum + "\n");				DeltaEntity(newframe, newnum, oldstate, bits);				oldindex++;				if (oldindex >= oldframe.num_entities)					oldnum = 99999;				else {					oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];					oldnum = oldstate.number;				}				continue;			}			if (oldnum > newnum) { // delta from baseline				if (Globals.cl_shownet.value == 3)					Com.Printf("   baseline: " + newnum + "\n");				DeltaEntity(newframe, newnum, Globals.cl_entities[newnum].baseline, bits);				continue;			}		}		// any remaining entities in the old frame are copied over		while (oldnum != 99999) { // one or more entities from the old packet								  // are unchanged			if (Globals.cl_shownet.value == 3)				Com.Printf("   unchanged: " + oldnum + "\n");			DeltaEntity(newframe, oldnum, oldstate, 0);			oldindex++;			if (oldindex >= oldframe.num_entities)				oldnum = 99999;			else {				oldstate = Globals.cl_parse_entities[(oldframe.parse_entities + oldindex) & (Defines.MAX_PARSE_ENTITIES - 1)];				oldnum = oldstate.number;			}		}	}	/*	 * =================== CL_ParsePlayerstate ===================	 */	public static void ParsePlayerstate(frame_t oldframe, frame_t newframe) {		int flags;		player_state_t state;		int i;		int statbits;		state = newframe.playerstate;		// clear to old value before delta parsing		if (oldframe != null)			state.set(oldframe.playerstate);		else			//memset (state, 0, sizeof(*state));			state.clear();		flags = MSG.ReadShort(Globals.net_message);		//		// parse the pmove_state_t		//		if ((flags & Defines.PS_M_TYPE) != 0)			state.pmove.pm_type = MSG.ReadByte(Globals.net_message);		if ((flags & Defines.PS_M_ORIGIN) != 0) {			state.pmove.origin[0] = MSG.ReadShort(Globals.net_message);			state.pmove.origin[1] = MSG.ReadShort(Globals.net_message);			state.pmove.origin[2] = MSG.ReadShort(Globals.net_message);		}		if ((flags & Defines.PS_M_VELOCITY) != 0) {			state.pmove.velocity[0] = MSG.ReadShort(Globals.net_message);			state.pmove.velocity[1] = MSG.ReadShort(Globals.net_message);			state.pmove.velocity[2] = MSG.ReadShort(Globals.net_message);		}		if ((flags & Defines.PS_M_TIME) != 0) {			state.pmove.pm_time = (byte) MSG.ReadByte(Globals.net_message);		}		if ((flags & Defines.PS_M_FLAGS) != 0)			state.pmove.pm_flags = (byte) MSG.ReadByte(Globals.net_message);		if ((flags & Defines.PS_M_GRAVITY) != 0)			state.pmove.gravity = MSG.ReadShort(Globals.net_message);		if ((flags & Defines.PS_M_DELTA_ANGLES) != 0) {			state.pmove.delta_angles[0] = MSG.ReadShort(Globals.net_message);			state.pmove.delta_angles[1] = MSG.ReadShort(Globals.net_message);			state.pmove.delta_angles[2] = MSG.ReadShort(Globals.net_message);		}		if (Globals.cl.attractloop)

⌨️ 快捷键说明

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