public static void WriteDir(sizebuf_t sb, Single[] dir) { Int32 i, best; Single 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); }
public static void WriteShort(sizebuf_t sb, Int32 c) { var i = SZ.GetSpace(sb, 2); sb.data[i++] = ( Byte )(c & 0xff); sb.data[i] = ( Byte )((c >> 8) & 0xFF); }
public static void ReadData(sizebuf_t msg_read, Byte[] data, Int32 len) { for (var i = 0; i < len; i++) { data[i] = ( Byte )ReadByte(msg_read); } }
public static bool Process(netchan_t chan, sizebuf_t msg) { MSG.BeginReading(msg); int sequence = MSG.ReadLong(msg); int sequence_ack = MSG.ReadLong(msg); if (chan.sock == Defines.NS_SERVER) { MSG.ReadShort(msg); } int reliable_message = sequence >> 31; int reliable_ack = sequence_ack >> 31; sequence &= ~(1 << 31); sequence_ack &= ~(1 << 31); if (showpackets.value != 0) { if (reliable_message != 0) { Com.Printf("recv " + msg.cursize + " : s=" + sequence + " reliable=" + (chan.incoming_reliable_sequence ^ 1) + " ack=" + sequence_ack + " rack=" + reliable_ack + "\\n"); } else { Com.Printf("recv " + msg.cursize + " : s=" + sequence + " ack=" + sequence_ack + " rack=" + reliable_ack + "\\n"); } } if (sequence <= chan.incoming_sequence) { if (showdrop.value != 0) { Com.Printf(NET.AdrToString(chan.remote_address) + ":Out of order packet " + sequence + " at " + chan.incoming_sequence + "\\n"); } return(false); } chan.dropped = sequence - (chan.incoming_sequence + 1); if (chan.dropped > 0) { if (showdrop.value != 0) { Com.Printf(NET.AdrToString(chan.remote_address) + ":Dropped " + chan.dropped + " packets at " + sequence + "\\n"); } } if (reliable_ack == chan.reliable_sequence) { chan.reliable_length = 0; } chan.incoming_sequence = sequence; chan.incoming_acknowledged = sequence_ack; chan.incoming_reliable_acknowledged = reliable_ack; if (reliable_message != 0) { chan.incoming_reliable_sequence ^= 1; } chan.last_received = (int)Globals.curtime; return(true); }
public static void Init(sizebuf_t buf, byte[] data, int length) { buf.readcount = 0; buf.data = data; buf.maxsize = length; buf.cursize = 0; buf.allowoverflow = buf.overflowed = false; }
public static void WriteInt(sizebuf_t sb, Int32 c) { var 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); }
public virtual void Clear() { sock = dropped = last_received = last_sent = 0; remote_address = new netadr_t(); qport = incoming_sequence = incoming_acknowledged = incoming_reliable_acknowledged = incoming_reliable_sequence = outgoing_sequence = reliable_sequence = last_reliable_sequence = 0; message = new sizebuf_t(); message_buf = new byte[Defines.MAX_MSGLEN - 16]; reliable_length = 0; reliable_buf = new byte[Defines.MAX_MSGLEN - 16]; }
public static void ReadDir(sizebuf_t sb, Single[] dir) { Int32 b; b = ReadByte(sb); if (b >= NUMVERTEXNORMALS) { Com.Error(ERR_DROP, "MSF_ReadDir: out of range"); } Math3D.VectorCopy(bytedirs[b], dir); }
public static void WriteString(sizebuf_t sb, String s) { var x = s; if (s == null) { x = ""; } SZ.Write(sb, Lib.StringToBytes(x)); WriteByte(sb, 0); }
public static Int32 ReadByte(sizebuf_t msg_read) { Int32 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 Int16 ReadShort(sizebuf_t msg_read) { Int32 c; if (msg_read.readcount + 2 > msg_read.cursize) { c = -1; } else { c = ( Int16 )((msg_read.data[msg_read.readcount] & 0xff) + (msg_read.data[msg_read.readcount + 1] << 8)); } msg_read.readcount += 2; return(( Int16 )c); }
public static Int32 ReadLong(sizebuf_t msg_read) { Int32 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 String ReadString(sizebuf_t msg_read) { Byte c; var l = 0; do { c = ( Byte )ReadByte(msg_read); if (c == -1 || c == 0) { break; } readbuf[l] = c; l++; }while (l < 2047); var ret = Encoding.ASCII.GetString(readbuf); return(ret); }
public static void ReadDeltaUsercmd(sizebuf_t msg_read, usercmd_t from, usercmd_t move) { Int32 bits; move.Set(from); bits = ReadByte(msg_read); 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); } 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); } if ((bits & CM_BUTTONS) != 0) { move.buttons = ( Byte )ReadByte(msg_read); } if ((bits & CM_IMPULSE) != 0) { move.impulse = ( Byte )ReadByte(msg_read); } move.msec = ( Byte )ReadByte(msg_read); move.lightlevel = ( Byte )ReadByte(msg_read); }
public static String ReadStringLine(sizebuf_t msg_read) { Int32 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); var ret = Encoding.ASCII.GetString(readbuf).Trim(); Com.Dprintln("MSG.ReadStringLine:[" + ret.Replace('\\', '@') + "]"); return(ret); }
public static void Main(String[] args) { byte[] buf_data = new byte[Defines.MAX_MSGLEN]; sizebuf_t buf = new sizebuf_t(); SZ.Init(buf, buf_data, Defines.MAX_MSGLEN); MSG.WriteInt(buf, 0x80000000); MSG.WriteInt(buf, 0x12345678); MSG.WriteInt(buf, 0x7fffffff); MSG.WriteInt(buf, 0xffffffff); MSG.WriteByte(buf, 1); MSG.WriteByte(buf, 2); MSG.WriteByte(buf, 3); MSG.WriteByte(buf, 4); SZ.Print(buf, "[einz]\\n"); SZ.Print(buf, "[zwei]..."); MSG.WriteByte(buf, 0xfe); MSG.WriteByte(buf, 4); MSG.WriteShort(buf, 32766); MSG.WriteShort(buf, 16384); MSG.WriteShort(buf, -32768); MSG.WriteFloat(buf, (float)Math.PI); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:<" + MSG.ReadString(buf) + ">"); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadShort(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadShort(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadShort(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadFloat(buf)); }
public static void Print(sizebuf_t buf, string data) { Com.Dprintln("SZ.print():<" + data + ">"); int length = data.Length; byte[] str = Lib.StringToBytes(data); if (buf.cursize != 0) { if (buf.data[buf.cursize - 1] != 0) { System.Array.Copy(str, 0, buf.data, GetSpace(buf, length + 1), length); } else { System.Array.Copy(str, 0, buf.data, GetSpace(buf, length) - 1, length); } } else { System.Array.Copy(str, 0, buf.data, GetSpace(buf, length), length); } buf.data[buf.cursize - 1] = 0; }
public static int GetSpace(sizebuf_t buf, int length) { int oldsize; if (buf.cursize + length > buf.maxsize) { if (!buf.allowoverflow) { Com.Error(Defines.ERR_FATAL, "SZ_GetSpace: overflow without allowoverflow set"); } if (length > buf.maxsize) { Com.Error(Defines.ERR_FATAL, "SZ_GetSpace: " + length + " is > full buffer size"); } Com.Printf("SZ_GetSpace: overflow\\n"); Clear(buf); buf.overflowed = true; } oldsize = buf.cursize; buf.cursize += length; return(oldsize); }
public static Single ReadAngle(sizebuf_t msg_read) { return(ReadChar(msg_read) * (360F / 256)); }
public static void WriteDeltaUsercmd(sizebuf_t buf, usercmd_t from, usercmd_t cmd) { Int32 bits; 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); }
public static void WriteAngle16(sizebuf_t sb, Single f) { WriteShort(sb, Math3D.ANGLE2SHORT(f)); }
public static void WriteChar(sizebuf_t sb, Int32 c) { sb.data[SZ.GetSpace(sb, 1)] = ( Byte )(c & 0xFF); }
public static void WriteAngle(sizebuf_t sb, Single f) { WriteByte(sb, ( Int32 )(f * 256 / 360) & 255); }
public static void WritePos(sizebuf_t sb, Single[] pos) { WriteShort(sb, ( Int32 )(pos[0] * 8)); WriteShort(sb, ( Int32 )(pos[1] * 8)); WriteShort(sb, ( Int32 )(pos[2] * 8)); }
public static void WriteCoord(sizebuf_t sb, Single f) { WriteShort(sb, ( Int32 )(f * 8)); }
public static void WriteString(sizebuf_t sb, Byte[] s) { WriteString(sb, Encoding.ASCII.GetString(s).Trim()); }
public static Single ReadFloat(sizebuf_t msg_read) { var n = ReadLong(msg_read); return(BitConverter.ToSingle(BitConverter.GetBytes(n))); }
public static Single ReadCoord(sizebuf_t msg_read) { return(ReadShort(msg_read) * (1F / 8)); }
public static void ReadPos(sizebuf_t msg_read, Single[] pos) { pos[0] = ReadShort(msg_read) * (1F / 8); pos[1] = ReadShort(msg_read) * (1F / 8); pos[2] = ReadShort(msg_read) * (1F / 8); }
public static Single ReadAngle16(sizebuf_t msg_read) { return(Math3D.SHORT2ANGLE(ReadShort(msg_read))); }