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

📄 msg.java

📁 JAKE2用JAVA写的queck2的3D游戏开发引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * 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. *   */// Created on 29.11.2003 by RST.// $Id: MSG.java,v 1.8 2005/12/18 22:10:02 cawe Exp $package jake2.qcommon;import jake2.Globals;import jake2.game.*;import jake2.util.*;public class MSG extends Globals {    //    // writing functions    //    //ok.    public static void WriteChar(sizebuf_t sb, int c) {        sb.data[SZ.GetSpace(sb, 1)] = (byte) (c & 0xFF);    }    //ok.    public static void WriteChar(sizebuf_t sb, float c) {        WriteChar(sb, (int) c);    }    //ok.    public static void WriteByte(sizebuf_t sb, int c) {        sb.data[SZ.GetSpace(sb, 1)] = (byte) (c & 0xFF);    }    //ok.    public static void WriteByte(sizebuf_t sb, float c) {        WriteByte(sb, (int) c);    }    public static void WriteShort(sizebuf_t sb, int c) {        int i = SZ.GetSpace(sb, 2);        sb.data[i++] = (byte) (c & 0xff);        sb.data[i] = (byte) ((c >>> 8) & 0xFF);    }    //ok.    public static void WriteInt(sizebuf_t sb, int c) {        int i = SZ.GetSpace(sb, 4);        sb.data[i++] = (byte) ((c & 0xff));        sb.data[i++] = (byte) ((c >>> 8) & 0xff);        sb.data[i++] = (byte) ((c >>> 16) & 0xff);        sb.data[i++] = (byte) ((c >>> 24) & 0xff);    }    //ok.    public static void WriteLong(sizebuf_t sb, int c) {        WriteInt(sb, c);    }    //ok.    public static void WriteFloat(sizebuf_t sb, float f) {        WriteInt(sb, Float.floatToIntBits(f));    }    // had a bug, now its ok.    public static void WriteString(sizebuf_t sb, String s) {        String x = s;        if (s == null)            x = "";        SZ.Write(sb, Lib.stringToBytes(x));        WriteByte(sb, 0);        //Com.dprintln("MSG.WriteString:" + s.replace('\0', '@'));    }    //ok.    public static void WriteString(sizebuf_t sb, byte s[]) {        WriteString(sb, new String(s).trim());    }    public static void WriteCoord(sizebuf_t sb, float f) {        WriteShort(sb, (int) (f * 8));    }    public static void WritePos(sizebuf_t sb, float[] pos) {        assert (pos.length == 3) : "vec3_t bug";        WriteShort(sb, (int) (pos[0] * 8));        WriteShort(sb, (int) (pos[1] * 8));        WriteShort(sb, (int) (pos[2] * 8));    }    public static void WriteAngle(sizebuf_t sb, float f) {        WriteByte(sb, (int) (f * 256 / 360) & 255);    }    public static void WriteAngle16(sizebuf_t sb, float f) {        WriteShort(sb, Math3D.ANGLE2SHORT(f));    }    public static void WriteDeltaUsercmd(sizebuf_t buf, usercmd_t from,            usercmd_t cmd) {        int bits;        //        // send the movement message        //        bits = 0;        if (cmd.angles[0] != from.angles[0])            bits |= CM_ANGLE1;        if (cmd.angles[1] != from.angles[1])            bits |= CM_ANGLE2;        if (cmd.angles[2] != from.angles[2])            bits |= CM_ANGLE3;        if (cmd.forwardmove != from.forwardmove)            bits |= CM_FORWARD;        if (cmd.sidemove != from.sidemove)            bits |= CM_SIDE;        if (cmd.upmove != from.upmove)            bits |= CM_UP;        if (cmd.buttons != from.buttons)            bits |= CM_BUTTONS;        if (cmd.impulse != from.impulse)            bits |= CM_IMPULSE;        WriteByte(buf, bits);        if ((bits & CM_ANGLE1) != 0)            WriteShort(buf, cmd.angles[0]);        if ((bits & CM_ANGLE2) != 0)            WriteShort(buf, cmd.angles[1]);        if ((bits & CM_ANGLE3) != 0)            WriteShort(buf, cmd.angles[2]);        if ((bits & CM_FORWARD) != 0)            WriteShort(buf, cmd.forwardmove);        if ((bits & CM_SIDE) != 0)            WriteShort(buf, cmd.sidemove);        if ((bits & CM_UP) != 0)            WriteShort(buf, cmd.upmove);        if ((bits & CM_BUTTONS) != 0)            WriteByte(buf, cmd.buttons);        if ((bits & CM_IMPULSE) != 0)            WriteByte(buf, cmd.impulse);        WriteByte(buf, cmd.msec);        WriteByte(buf, cmd.lightlevel);    }    //should be ok.    public static void WriteDir(sizebuf_t sb, float[] dir) {        int i, best;        float d, bestd;        if (dir == null) {            WriteByte(sb, 0);            return;        }        bestd = 0;        best = 0;        for (i = 0; i < NUMVERTEXNORMALS; i++) {            d = Math3D.DotProduct(dir, bytedirs[i]);            if (d > bestd) {                bestd = d;                best = i;            }        }        WriteByte(sb, best);    }    //should be ok.    public static void ReadDir(sizebuf_t sb, float[] dir) {        int b;        b = ReadByte(sb);        if (b >= NUMVERTEXNORMALS)            Com.Error(ERR_DROP, "MSF_ReadDir: out of range");        Math3D.VectorCopy(bytedirs[b], dir);    }    /*     * ================== WriteDeltaEntity     *      * Writes part of a packetentities message. Can delta from either a baseline     * or a previous packet_entity ==================     */    public static void WriteDeltaEntity(entity_state_t from, entity_state_t to,            sizebuf_t msg, boolean force, boolean newentity) {        int bits;        if (0 == to.number)            Com.Error(ERR_FATAL, "Unset entity number");        if (to.number >= MAX_EDICTS)            Com.Error(ERR_FATAL, "Entity number >= MAX_EDICTS");        // send an update        bits = 0;        if (to.number >= 256)            bits |= U_NUMBER16; // number8 is implicit otherwise        if (to.origin[0] != from.origin[0])            bits |= U_ORIGIN1;        if (to.origin[1] != from.origin[1])            bits |= U_ORIGIN2;        if (to.origin[2] != from.origin[2])            bits |= U_ORIGIN3;        if (to.angles[0] != from.angles[0])            bits |= U_ANGLE1;        if (to.angles[1] != from.angles[1])            bits |= U_ANGLE2;        if (to.angles[2] != from.angles[2])            bits |= U_ANGLE3;        if (to.skinnum != from.skinnum) {            if (to.skinnum < 256)                bits |= U_SKIN8;            else if (to.skinnum < 0x10000)                bits |= U_SKIN16;            else                bits |= (U_SKIN8 | U_SKIN16);        }        if (to.frame != from.frame) {            if (to.frame < 256)                bits |= U_FRAME8;            else                bits |= U_FRAME16;        }        if (to.effects != from.effects) {            if (to.effects < 256)                bits |= U_EFFECTS8;            else if (to.effects < 0x8000)                bits |= U_EFFECTS16;            else                bits |= U_EFFECTS8 | U_EFFECTS16;        }        if (to.renderfx != from.renderfx) {            if (to.renderfx < 256)                bits |= U_RENDERFX8;            else if (to.renderfx < 0x8000)                bits |= U_RENDERFX16;            else                bits |= U_RENDERFX8 | U_RENDERFX16;        }        if (to.solid != from.solid)            bits |= U_SOLID;        // event is not delta compressed, just 0 compressed        if (to.event != 0)            bits |= U_EVENT;        if (to.modelindex != from.modelindex)            bits |= U_MODEL;        if (to.modelindex2 != from.modelindex2)            bits |= U_MODEL2;        if (to.modelindex3 != from.modelindex3)            bits |= U_MODEL3;        if (to.modelindex4 != from.modelindex4)            bits |= U_MODEL4;

⌨️ 快捷键说明

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