1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSimulator Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using OpenMetaverse;
using log4net;
using OpenSim.Framework;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes.Types;
namespace OpenSim.Region.Framework.Scenes
{
public class SceneViewer : ISceneViewer
{
protected ScenePresence m_presence;
protected UpdateQueue m_partsUpdateQueue = new UpdateQueue();
protected Queue<SceneObjectGroup> m_pendingObjects;
protected Dictionary<UUID, ScenePartUpdate> m_updateTimes = new Dictionary<UUID, ScenePartUpdate>();
public SceneViewer()
{
}
public SceneViewer(ScenePresence presence)
{
m_presence = presence;
}
/// <summary>
/// Add the part to the queue of parts for which we need to send an update to the client
/// </summary>
/// <param name="part"></param>
public void QueuePartForUpdate(SceneObjectPart part)
{
lock (m_partsUpdateQueue)
{
m_partsUpdateQueue.Enqueue(part);
}
}
public void SendPrimUpdates()
{
if (m_pendingObjects == null)
{
if (!m_presence.IsChildAgent || (m_presence.Scene.m_seeIntoRegionFromNeighbor))
{
m_pendingObjects = new Queue<SceneObjectGroup>();
lock (m_pendingObjects)
{
EntityBase[] entities = m_presence.Scene.Entities.GetEntities();
foreach (EntityBase e in entities)
{
if (e != null && e is SceneObjectGroup)
m_pendingObjects.Enqueue((SceneObjectGroup)e);
}
}
}
}
lock (m_pendingObjects)
{
while (m_pendingObjects != null && m_pendingObjects.Count > 0)
{
SceneObjectGroup g = m_pendingObjects.Dequeue();
// Yes, this can really happen
if (g == null)
continue;
// This is where we should check for draw distance
// do culling and stuff. Problem with that is that until
// we recheck in movement, that won't work right.
// So it's not implemented now.
//
// Don't even queue if we have sent this one
//
if (!m_updateTimes.ContainsKey(g.UUID))
g.ScheduleFullUpdateToAvatar(m_presence);
}
while (m_partsUpdateQueue != null && m_partsUpdateQueue.Count != null && m_partsUpdateQueue.Count > 0)
{
SceneObjectPart part = m_partsUpdateQueue.Dequeue();
if (part.ParentGroup == null || part.ParentGroup.IsDeleted)
continue;
if (m_updateTimes.ContainsKey(part.UUID))
{
ScenePartUpdate update = m_updateTimes[part.UUID];
// We deal with the possibility that two updates occur at
// the same unix time at the update point itself.
if ((update.LastFullUpdateTime < part.TimeStampFull) ||
part.IsAttachment)
{
// m_log.DebugFormat(
// "[SCENE PRESENCE]: Fully updating prim {0}, {1} - part timestamp {2}",
// part.Name, part.UUID, part.TimeStampFull);
part.SendFullUpdate(m_presence.ControllingClient,
m_presence.GenerateClientFlags(part.UUID));
// We'll update to the part's timestamp rather than
// the current time to avoid the race condition
// whereby the next tick occurs while we are doing
// this update. If this happened, then subsequent
// updates which occurred on the same tick or the
// next tick of the last update would be ignored.
update.LastFullUpdateTime = part.TimeStampFull;
}
else if (update.LastTerseUpdateTime <= part.TimeStampTerse)
{
// m_log.DebugFormat(
// "[SCENE PRESENCE]: Tersely updating prim {0}, {1} - part timestamp {2}",
// part.Name, part.UUID, part.TimeStampTerse);
part.SendTerseUpdateToClient(m_presence.ControllingClient);
update.LastTerseUpdateTime = part.TimeStampTerse;
}
}
else
{
//never been sent to client before so do full update
ScenePartUpdate update = new ScenePartUpdate();
update.FullID = part.UUID;
update.LastFullUpdateTime = part.TimeStampFull;
m_updateTimes.Add(part.UUID, update);
// Attachment handling
//
if (part.ParentGroup.RootPart.Shape.PCode == 9 && part.ParentGroup.RootPart.Shape.State != 0)
{
if (part != part.ParentGroup.RootPart)
continue;
part.ParentGroup.SendFullUpdateToClient(m_presence.ControllingClient);
continue;
}
part.SendFullUpdate(m_presence.ControllingClient,
m_presence.GenerateClientFlags(part.UUID));
}
}
}
}
public void Reset()
{
if (m_pendingObjects == null)
return;
lock (m_pendingObjects)
{
if (m_pendingObjects != null)
{
m_pendingObjects.Clear();
m_pendingObjects = null;
}
}
}
public void Close()
{
lock (m_updateTimes)
{
m_updateTimes.Clear();
}
lock (m_partsUpdateQueue)
{
m_partsUpdateQueue.Clear();
}
Reset();
}
public int GetPendingObjectsCount()
{
if (m_pendingObjects != null)
return m_pendingObjects.Count;
return 0;
}
public class ScenePartUpdate
{
public UUID FullID;
public uint LastFullUpdateTime;
public uint LastTerseUpdateTime;
public ScenePartUpdate()
{
FullID = UUID.Zero;
LastFullUpdateTime = 0;
LastTerseUpdateTime = 0;
}
}
}
}
|