diff options
author | UbitUmarov | 2019-03-06 20:00:39 +0000 |
---|---|---|
committer | UbitUmarov | 2019-03-06 20:00:39 +0000 |
commit | cf0f3954a80c480e34c2e5556e2b0581c4c23f88 (patch) | |
tree | fcebd3674aa163cde305cc5304772b53c97b10ca /OpenSim | |
parent | BulletSim: Add delay to stationary check after adding force to Avatar. (diff) | |
download | opensim-SC-cf0f3954a80c480e34c2e5556e2b0581c4c23f88.zip opensim-SC-cf0f3954a80c480e34c2e5556e2b0581c4c23f88.tar.gz opensim-SC-cf0f3954a80c480e34c2e5556e2b0581c4c23f88.tar.bz2 opensim-SC-cf0f3954a80c480e34c2e5556e2b0581c4c23f88.tar.xz |
lludp do inline zeroencode of some(most) agent full updates (runprebuild)
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | 114 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs | 279 |
2 files changed, 356 insertions, 37 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs index f8ff3c4..dd06e40 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLClientView.cs | |||
@@ -3894,22 +3894,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
3894 | if (ent is ScenePresence) | 3894 | if (ent is ScenePresence) |
3895 | { | 3895 | { |
3896 | ScenePresence presence = ent as ScenePresence; | 3896 | ScenePresence presence = ent as ScenePresence; |
3897 | |||
3898 | UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint); | 3897 | UDPPacketBuffer buf = m_udpServer.GetNewUDPBuffer(m_udpClient.RemoteEndPoint); |
3899 | 3898 | ||
3900 | //setup header and regioninfo block | ||
3901 | Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7); | 3899 | Buffer.BlockCopy(objectUpdateHeader, 0, buf.Data, 0, 7); |
3902 | Utils.UInt64ToBytesSafepos(m_scene.RegionInfo.RegionHandle, buf.Data, 7); | ||
3903 | Utils.UInt16ToBytes(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f), buf.Data, 15); | ||
3904 | |||
3905 | buf.Data[17] = 1; | ||
3906 | int pos = 18; | ||
3907 | CreateAvatarUpdateBlock(presence, buf.Data, ref pos); | ||
3908 | 3900 | ||
3909 | buf.DataLength = pos; | 3901 | LLUDPZeroEncoder zc = new LLUDPZeroEncoder(buf.Data); |
3910 | m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority, null, false, true); | 3902 | zc.Position = 7; |
3903 | zc.AddUInt64(m_scene.RegionInfo.RegionHandle); | ||
3904 | zc.AddUInt16(Utils.FloatToUInt16(m_scene.TimeDilation, 0.0f, 1.0f)); | ||
3905 | zc.AddByte(1); // block count | ||
3906 | CreateAvatarUpdateBlock(presence, zc); | ||
3907 | buf.DataLength = zc.Finish(); | ||
3908 | m_udpServer.SendUDPPacket(m_udpClient, buf, ThrottleOutPacketType.Task | ThrottleOutPacketType.HighPriority, null, false, false); | ||
3911 | } | 3909 | } |
3912 | |||
3913 | else if(ent is SceneObjectPart) | 3910 | else if(ent is SceneObjectPart) |
3914 | { | 3911 | { |
3915 | ObjectUpdatePacket objupdate = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate); | 3912 | ObjectUpdatePacket objupdate = (ObjectUpdatePacket)PacketPool.Instance.GetPacket(PacketType.ObjectUpdate); |
@@ -5985,6 +5982,75 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
5985 | Array.Clear(dest, pos, lastzeros); pos += lastzeros; | 5982 | Array.Clear(dest, pos, lastzeros); pos += lastzeros; |
5986 | } | 5983 | } |
5987 | 5984 | ||
5985 | protected void CreateAvatarUpdateBlock(ScenePresence data, LLUDPZeroEncoder zc) | ||
5986 | { | ||
5987 | Quaternion rotation = data.Rotation; | ||
5988 | // tpvs can only see rotations around Z in some cases | ||
5989 | if (!data.Flying && !data.IsSatOnObject) | ||
5990 | { | ||
5991 | rotation.X = 0f; | ||
5992 | rotation.Y = 0f; | ||
5993 | } | ||
5994 | rotation.Normalize(); | ||
5995 | |||
5996 | zc.AddUInt(data.LocalId); | ||
5997 | zc.AddByte(0); | ||
5998 | zc.AddUUID(data.UUID); | ||
5999 | zc.AddZeros(4); // crc unused | ||
6000 | zc.AddByte((byte)PCode.Avatar); | ||
6001 | zc.AddByte((byte)Material.Flesh); | ||
6002 | zc.AddByte(0); // clickaction | ||
6003 | zc.AddVector3(data.Appearance.AvatarSize); | ||
6004 | |||
6005 | // objectdata block | ||
6006 | zc.AddByte(76); // fixed avatar block size | ||
6007 | zc.AddVector4(data.CollisionPlane); | ||
6008 | zc.AddVector3(data.OffsetPosition); | ||
6009 | zc.AddVector3(data.Velocity); | ||
6010 | //zc.AddVector3(acceleration); | ||
6011 | zc.AddZeros(12); | ||
6012 | zc.AddNormQuat(rotation); | ||
6013 | //zc.AddVector3(angularvelocity); | ||
6014 | zc.AddZeros(12); | ||
6015 | |||
6016 | SceneObjectPart parentPart = data.ParentPart; | ||
6017 | if (parentPart != null) | ||
6018 | zc.AddUInt(parentPart.ParentGroup.LocalId); | ||
6019 | else | ||
6020 | zc.AddZeros(4); | ||
6021 | |||
6022 | zc.AddZeros(4); //update flags | ||
6023 | |||
6024 | //pbs | ||
6025 | zc.AddByte(16); | ||
6026 | zc.AddByte(1); | ||
6027 | //Utils.UInt16ToBytes(0, dest, pos); pos += 2; | ||
6028 | //Utils.UInt16ToBytes(0, dest, pos); pos += 2; | ||
6029 | zc.AddZeros(4); | ||
6030 | |||
6031 | zc.AddByte(100); | ||
6032 | zc.AddByte(100); | ||
6033 | |||
6034 | // rest of pbs is 0 (15), texture entry (2) and texture anim (1) | ||
6035 | const int pbszeros = 15 + 2 + 1; | ||
6036 | zc.AddZeros(pbszeros); | ||
6037 | |||
6038 | //NameValue | ||
6039 | byte[] nv = Utils.StringToBytes("FirstName STRING RW SV " + data.Firstname + "\nLastName STRING RW SV " + | ||
6040 | data.Lastname + "\nTitle STRING RW SV " + data.Grouptitle); | ||
6041 | int len = nv.Length; | ||
6042 | zc.AddByte((byte)len); | ||
6043 | zc.AddByte((byte)(len >> 8)); | ||
6044 | zc.AddBytes(nv, len); | ||
6045 | |||
6046 | // data(2), text(1), text color(4), media url(1), PBblock(1), ExtramParams(1), | ||
6047 | // sound id(16), sound owner(16) gain (4), flags (1), radius (4) | ||
6048 | // jointtype(1) joint pivot(12) joint offset(12) | ||
6049 | const int lastzeros = 2 + 1 + 4 + 1 + 1 + 1 + 16 + 16 + 4 + 1 + 4 + 1 + 12 + 12; | ||
6050 | zc.AddZeros(lastzeros); | ||
6051 | } | ||
6052 | |||
6053 | |||
5988 | // protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(SceneObjectPart data, UUID recipientID) | 6054 | // protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(SceneObjectPart data, UUID recipientID) |
5989 | protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(SceneObjectPart part, ScenePresence sp) | 6055 | protected ObjectUpdatePacket.ObjectDataBlock CreatePrimUpdateBlock(SceneObjectPart part, ScenePresence sp) |
5990 | { | 6056 | { |
@@ -6008,32 +6074,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP | |||
6008 | //update.JointPivot = Vector3.Zero; | 6074 | //update.JointPivot = Vector3.Zero; |
6009 | //update.JointType = 0; | 6075 | //update.JointType = 0; |
6010 | update.Material = part.Material; | 6076 | update.Material = part.Material; |
6011 | /* | ||
6012 | if (data.ParentGroup.IsAttachment) | ||
6013 | { | ||
6014 | update.NameValue | ||
6015 | = Util.StringToBytes256( | ||
6016 | string.Format("AttachItemID STRING RW SV {0}", data.ParentGroup.FromItemID)); | ||
6017 | |||
6018 | update.State = (byte)((data.ParentGroup.AttachmentPoint % 16) * 16 + (data.ParentGroup.AttachmentPoint / 16)); | ||
6019 | |||
6020 | // m_log.DebugFormat( | ||
6021 | // "[LLCLIENTVIEW]: Sending NameValue {0} for {1} {2} to {3}", | ||
6022 | // Util.UTF8.GetString(update.NameValue), data.Name, data.LocalId, Name); | ||
6023 | // | ||
6024 | // m_log.DebugFormat( | ||
6025 | // "[LLCLIENTVIEW]: Sending state {0} for {1} {2} to {3}", | ||
6026 | // update.State, data.Name, data.LocalId, Name); | ||
6027 | } | ||
6028 | else | ||
6029 | { | ||
6030 | update.NameValue = Utils.EmptyBytes; | ||
6031 | |||
6032 | // The root part state is the canonical state for all parts of the object. The other part states in the | ||
6033 | // case for attachments may contain conflicting values that can end up crashing the viewer. | ||
6034 | update.State = data.ParentGroup.RootPart.Shape.State; | ||
6035 | } | ||
6036 | */ | ||
6037 | 6077 | ||
6038 | if (part.ParentGroup.IsAttachment) | 6078 | if (part.ParentGroup.IsAttachment) |
6039 | { | 6079 | { |
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs new file mode 100644 index 0000000..4841ada --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPZeroEncoder.cs | |||
@@ -0,0 +1,279 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Framework; | ||
30 | using Nini.Config; | ||
31 | using OpenMetaverse; | ||
32 | |||
33 | namespace OpenSim.Region.ClientStack.LindenUDP | ||
34 | { | ||
35 | public sealed class LLUDPZeroEncoder | ||
36 | { | ||
37 | private byte[] m_tmp = new byte[16]; | ||
38 | private byte[] m_dest; | ||
39 | private int zerocount; | ||
40 | private int pos; | ||
41 | |||
42 | public LLUDPZeroEncoder() | ||
43 | { | ||
44 | } | ||
45 | |||
46 | public LLUDPZeroEncoder(byte[] data) | ||
47 | { | ||
48 | m_dest = data; | ||
49 | zerocount = 0; | ||
50 | } | ||
51 | |||
52 | public byte[] Data | ||
53 | { | ||
54 | get | ||
55 | { | ||
56 | return m_dest; | ||
57 | } | ||
58 | set | ||
59 | { | ||
60 | m_dest = value; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | public int ZeroCount | ||
65 | { | ||
66 | get | ||
67 | { | ||
68 | return zerocount; | ||
69 | } | ||
70 | set | ||
71 | { | ||
72 | zerocount = value; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | public int Position | ||
77 | { | ||
78 | get | ||
79 | { | ||
80 | return pos; | ||
81 | } | ||
82 | set | ||
83 | { | ||
84 | pos = value; | ||
85 | } | ||
86 | } | ||
87 | |||
88 | public unsafe void AddZeros(int len) | ||
89 | { | ||
90 | zerocount += len; | ||
91 | while (zerocount > 255) | ||
92 | { | ||
93 | m_dest[pos++] = 0x00; | ||
94 | m_dest[pos++] = 0xff; | ||
95 | zerocount -= 256; | ||
96 | } | ||
97 | } | ||
98 | |||
99 | public unsafe int Finish() | ||
100 | { | ||
101 | if(zerocount > 0) | ||
102 | { | ||
103 | m_dest[pos++] = 0x00; | ||
104 | m_dest[pos++] = (byte)zerocount; | ||
105 | } | ||
106 | return pos; | ||
107 | } | ||
108 | |||
109 | public unsafe void AddBytes(byte[] src, int srclen) | ||
110 | { | ||
111 | for (int i = 0; i < srclen; ++i) | ||
112 | { | ||
113 | if (src[i] == 0x00) | ||
114 | { | ||
115 | zerocount++; | ||
116 | if (zerocount == 0) | ||
117 | { | ||
118 | m_dest[pos++] = 0x00; | ||
119 | m_dest[pos++] = 0xff; | ||
120 | zerocount++; | ||
121 | } | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | if (zerocount != 0) | ||
126 | { | ||
127 | m_dest[pos++] = 0x00; | ||
128 | m_dest[pos++] = (byte)zerocount; | ||
129 | zerocount = 0; | ||
130 | } | ||
131 | |||
132 | m_dest[pos++] = src[i]; | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | |||
137 | public void AddByte(byte v) | ||
138 | { | ||
139 | if (v == 0x00) | ||
140 | { | ||
141 | zerocount++; | ||
142 | if (zerocount == 0) | ||
143 | { | ||
144 | m_dest[pos++] = 0x00; | ||
145 | m_dest[pos++] = 0xff; | ||
146 | zerocount++; | ||
147 | } | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | if (zerocount != 0) | ||
152 | { | ||
153 | m_dest[pos++] = 0x00; | ||
154 | m_dest[pos++] = (byte)zerocount; | ||
155 | zerocount = 0; | ||
156 | } | ||
157 | |||
158 | m_dest[pos++] = v; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | public void AddInt16(short v) | ||
163 | { | ||
164 | if (v == 0) | ||
165 | AddZeros(2); | ||
166 | else | ||
167 | { | ||
168 | Utils.Int16ToBytes(v, m_tmp, 0); | ||
169 | AddBytes(m_tmp, 2); | ||
170 | } | ||
171 | } | ||
172 | |||
173 | public void AddUInt16(ushort v) | ||
174 | { | ||
175 | if (v == 0) | ||
176 | AddZeros(2); | ||
177 | else | ||
178 | { | ||
179 | Utils.UInt16ToBytes(v, m_tmp, 0); | ||
180 | AddBytes(m_tmp, 2); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | public void AddInt(int v) | ||
185 | { | ||
186 | if (v == 0) | ||
187 | AddZeros(4); | ||
188 | else | ||
189 | { | ||
190 | Utils.IntToBytesSafepos(v, m_tmp, 0); | ||
191 | AddBytes(m_tmp, 4); | ||
192 | } | ||
193 | } | ||
194 | |||
195 | public unsafe void AddUInt(uint v) | ||
196 | { | ||
197 | if (v == 0) | ||
198 | AddZeros(4); | ||
199 | else | ||
200 | { | ||
201 | Utils.UIntToBytesSafepos(v, m_tmp, 0); | ||
202 | AddBytes(m_tmp, 4); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | public void AddFloatToUInt16(float v, float range) | ||
207 | { | ||
208 | Utils.FloatToUInt16Bytes(v, range, m_tmp, 0); | ||
209 | AddBytes(m_tmp, 2); | ||
210 | } | ||
211 | |||
212 | public void AddFloat(float v) | ||
213 | { | ||
214 | if (v == 0f) | ||
215 | AddZeros(4); | ||
216 | else | ||
217 | { | ||
218 | Utils.FloatToBytesSafepos(v, m_tmp, 0); | ||
219 | AddBytes(m_tmp, 4); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | public void AddInt64(long v) | ||
224 | { | ||
225 | if (v == 0) | ||
226 | AddZeros(8); | ||
227 | else | ||
228 | { | ||
229 | Utils.Int64ToBytesSafepos(v, m_tmp, 0); | ||
230 | AddBytes(m_tmp, 8); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | public void AddUInt64(ulong v) | ||
235 | { | ||
236 | if (v == 0) | ||
237 | AddZeros(8); | ||
238 | else | ||
239 | { | ||
240 | Utils.UInt64ToBytesSafepos(v, m_tmp, 0); | ||
241 | AddBytes(m_tmp, 8); | ||
242 | } | ||
243 | } | ||
244 | |||
245 | public void AddVector3(Vector3 v) | ||
246 | { | ||
247 | if (v == Vector3.Zero) | ||
248 | AddZeros(12); | ||
249 | else | ||
250 | { | ||
251 | v.ToBytes(m_tmp, 0); | ||
252 | AddBytes(m_tmp, 12); | ||
253 | } | ||
254 | } | ||
255 | |||
256 | public void AddVector4(Vector4 v) | ||
257 | { | ||
258 | if (v == Vector4.Zero) | ||
259 | AddZeros(16); | ||
260 | else | ||
261 | { | ||
262 | v.ToBytes(m_tmp, 0); | ||
263 | AddBytes(m_tmp, 16); | ||
264 | } | ||
265 | } | ||
266 | |||
267 | public void AddNormQuat(Quaternion v) | ||
268 | { | ||
269 | v.ToBytes(m_tmp, 0); | ||
270 | AddBytes(m_tmp, 12); | ||
271 | } | ||
272 | |||
273 | public void AddUUID(UUID v) | ||
274 | { | ||
275 | v.ToBytes(m_tmp, 0); | ||
276 | AddBytes(m_tmp, 16); | ||
277 | } | ||
278 | } | ||
279 | } | ||