📄 msg.java
字号:
if (to.sound != from.sound) bits |= U_SOUND; if (newentity || (to.renderfx & RF_BEAM) != 0) bits |= U_OLDORIGIN; // // write the message // if (bits == 0 && !force) return; // nothing to send! //---------- if ((bits & 0xff000000) != 0) bits |= U_MOREBITS3 | U_MOREBITS2 | U_MOREBITS1; else if ((bits & 0x00ff0000) != 0) bits |= U_MOREBITS2 | U_MOREBITS1; else if ((bits & 0x0000ff00) != 0) bits |= U_MOREBITS1; WriteByte(msg, bits & 255); if ((bits & 0xff000000) != 0) { WriteByte(msg, (bits >>> 8) & 255); WriteByte(msg, (bits >>> 16) & 255); WriteByte(msg, (bits >>> 24) & 255); } else if ((bits & 0x00ff0000) != 0) { WriteByte(msg, (bits >>> 8) & 255); WriteByte(msg, (bits >>> 16) & 255); } else if ((bits & 0x0000ff00) != 0) { WriteByte(msg, (bits >>> 8) & 255); } //---------- if ((bits & U_NUMBER16) != 0) WriteShort(msg, to.number); else WriteByte(msg, to.number); if ((bits & U_MODEL) != 0) WriteByte(msg, to.modelindex); if ((bits & U_MODEL2) != 0) WriteByte(msg, to.modelindex2); if ((bits & U_MODEL3) != 0) WriteByte(msg, to.modelindex3); if ((bits & U_MODEL4) != 0) WriteByte(msg, to.modelindex4); if ((bits & U_FRAME8) != 0) WriteByte(msg, to.frame); if ((bits & U_FRAME16) != 0) WriteShort(msg, to.frame); if ((bits & U_SKIN8) != 0 && (bits & U_SKIN16) != 0) //used for laser // colors WriteInt(msg, to.skinnum); else if ((bits & U_SKIN8) != 0) WriteByte(msg, to.skinnum); else if ((bits & U_SKIN16) != 0) WriteShort(msg, to.skinnum); if ((bits & (U_EFFECTS8 | U_EFFECTS16)) == (U_EFFECTS8 | U_EFFECTS16)) WriteInt(msg, to.effects); else if ((bits & U_EFFECTS8) != 0) WriteByte(msg, to.effects); else if ((bits & U_EFFECTS16) != 0) WriteShort(msg, to.effects); if ((bits & (U_RENDERFX8 | U_RENDERFX16)) == (U_RENDERFX8 | U_RENDERFX16)) WriteInt(msg, to.renderfx); else if ((bits & U_RENDERFX8) != 0) WriteByte(msg, to.renderfx); else if ((bits & U_RENDERFX16) != 0) WriteShort(msg, to.renderfx); if ((bits & U_ORIGIN1) != 0) WriteCoord(msg, to.origin[0]); if ((bits & U_ORIGIN2) != 0) WriteCoord(msg, to.origin[1]); if ((bits & U_ORIGIN3) != 0) WriteCoord(msg, to.origin[2]); if ((bits & U_ANGLE1) != 0) WriteAngle(msg, to.angles[0]); if ((bits & U_ANGLE2) != 0) WriteAngle(msg, to.angles[1]); if ((bits & U_ANGLE3) != 0) WriteAngle(msg, to.angles[2]); if ((bits & U_OLDORIGIN) != 0) { WriteCoord(msg, to.old_origin[0]); WriteCoord(msg, to.old_origin[1]); WriteCoord(msg, to.old_origin[2]); } if ((bits & U_SOUND) != 0) WriteByte(msg, to.sound); if ((bits & U_EVENT) != 0) WriteByte(msg, to.event); if ((bits & U_SOLID) != 0) WriteShort(msg, to.solid); } //============================================================ // // reading functions // public static void BeginReading(sizebuf_t msg) { msg.readcount = 0; } // returns -1 if no more characters are available, but also [-128 , 127] public static int ReadChar(sizebuf_t msg_read) { int c; if (msg_read.readcount + 1 > msg_read.cursize) c = -1; else c = msg_read.data[msg_read.readcount]; msg_read.readcount++; // kickangles bugfix (rst) return c; } public static int ReadByte(sizebuf_t msg_read) { int c; if (msg_read.readcount + 1 > msg_read.cursize) c = -1; else c = msg_read.data[msg_read.readcount] & 0xff; msg_read.readcount++; return c; } public static short ReadShort(sizebuf_t msg_read) { int c; if (msg_read.readcount + 2 > msg_read.cursize) c = -1; else c = (short) ((msg_read.data[msg_read.readcount] & 0xff) + (msg_read.data[msg_read.readcount + 1] << 8)); msg_read.readcount += 2; return (short) c; } public static int ReadLong(sizebuf_t msg_read) { int c; if (msg_read.readcount + 4 > msg_read.cursize) { Com.Printf("buffer underrun in ReadLong!"); c = -1; } else c = (msg_read.data[msg_read.readcount] & 0xff) | ((msg_read.data[msg_read.readcount + 1] & 0xff) << 8) | ((msg_read.data[msg_read.readcount + 2] & 0xff) << 16) | ((msg_read.data[msg_read.readcount + 3] & 0xff) << 24); msg_read.readcount += 4; return c; } public static float ReadFloat(sizebuf_t msg_read) { int n = ReadLong(msg_read); return Float.intBitsToFloat(n); } // 2k read buffer. public static byte readbuf[] = new byte[2048]; public static String ReadString(sizebuf_t msg_read) { byte c; int l = 0; do { c = (byte) ReadByte(msg_read); if (c == -1 || c == 0) break; readbuf[l] = c; l++; } while (l < 2047); String ret = new String(readbuf, 0, l); // Com.dprintln("MSG.ReadString:[" + ret + "]"); return ret; } public static String ReadStringLine(sizebuf_t msg_read) { int l; byte c; l = 0; do { c = (byte) ReadChar(msg_read); if (c == -1 || c == 0 || c == 0x0a) break; readbuf[l] = c; l++; } while (l < 2047); String ret = new String(readbuf, 0, l).trim(); Com.dprintln("MSG.ReadStringLine:[" + ret.replace('\0', '@') + "]"); return ret; } public static float ReadCoord(sizebuf_t msg_read) { return ReadShort(msg_read) * (1.0f / 8); } public static void ReadPos(sizebuf_t msg_read, float pos[]) { assert (pos.length == 3) : "vec3_t bug"; pos[0] = ReadShort(msg_read) * (1.0f / 8); pos[1] = ReadShort(msg_read) * (1.0f / 8); pos[2] = ReadShort(msg_read) * (1.0f / 8); } public static float ReadAngle(sizebuf_t msg_read) { return ReadChar(msg_read) * (360.0f / 256); } public static float ReadAngle16(sizebuf_t msg_read) { return Math3D.SHORT2ANGLE(ReadShort(msg_read)); } public static void ReadDeltaUsercmd(sizebuf_t msg_read, usercmd_t from, usercmd_t move) { int bits; //memcpy(move, from, sizeof(* move)); // IMPORTANT!! copy without new move.set(from); bits = ReadByte(msg_read); // read current angles if ((bits & CM_ANGLE1) != 0) move.angles[0] = ReadShort(msg_read); if ((bits & CM_ANGLE2) != 0) move.angles[1] = ReadShort(msg_read); if ((bits & CM_ANGLE3) != 0) move.angles[2] = ReadShort(msg_read); // read movement if ((bits & CM_FORWARD) != 0) move.forwardmove = ReadShort(msg_read); if ((bits & CM_SIDE) != 0) move.sidemove = ReadShort(msg_read); if ((bits & CM_UP) != 0) move.upmove = ReadShort(msg_read); // read buttons if ((bits & CM_BUTTONS) != 0) move.buttons = (byte) ReadByte(msg_read); if ((bits & CM_IMPULSE) != 0) move.impulse = (byte) ReadByte(msg_read); // read time to run command move.msec = (byte) ReadByte(msg_read); // read the light level move.lightlevel = (byte) ReadByte(msg_read); } public static void ReadData(sizebuf_t msg_read, byte data[], int len) { for (int i = 0; i < len; i++) data[i] = (byte) ReadByte(msg_read); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -