aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework/Scenes
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework/Scenes')
-rw-r--r--OpenSim/Region/Framework/Scenes/Scene.cs333
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs26
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs174
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs136
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs71
5 files changed, 484 insertions, 256 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs
index f38a6fc..d4bfd46 100644
--- a/OpenSim/Region/Framework/Scenes/Scene.cs
+++ b/OpenSim/Region/Framework/Scenes/Scene.cs
@@ -131,7 +131,16 @@ namespace OpenSim.Region.Framework.Scenes
131 protected ICapabilitiesModule m_capsModule; 131 protected ICapabilitiesModule m_capsModule;
132 // Central Update Loop 132 // Central Update Loop
133 protected int m_fps = 10; 133 protected int m_fps = 10;
134 protected uint m_frame; 134
135 /// <summary>
136 /// Current scene frame number
137 /// </summary>
138 public uint Frame
139 {
140 get;
141 protected set;
142 }
143
135 protected float m_timespan = 0.089f; 144 protected float m_timespan = 0.089f;
136 protected DateTime m_lastupdate = DateTime.UtcNow; 145 protected DateTime m_lastupdate = DateTime.UtcNow;
137 146
@@ -1212,6 +1221,9 @@ namespace OpenSim.Region.Framework.Scenes
1212 try 1221 try
1213 { 1222 {
1214 Update(); 1223 Update();
1224
1225 m_lastUpdate = Util.EnvironmentTickCount();
1226 m_firstHeartbeat = false;
1215 } 1227 }
1216 catch (ThreadAbortException) 1228 catch (ThreadAbortException)
1217 { 1229 {
@@ -1225,190 +1237,180 @@ namespace OpenSim.Region.Framework.Scenes
1225 Watchdog.RemoveThread(); 1237 Watchdog.RemoveThread();
1226 } 1238 }
1227 1239
1228 /// <summary>
1229 /// Performs per-frame updates on the scene, this should be the central scene loop
1230 /// </summary>
1231 public override void Update() 1240 public override void Update()
1232 { 1241 {
1233 float physicsFPS; 1242 TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastupdate;
1234 int maintc; 1243 float physicsFPS = 0f;
1244
1245 int maintc = Util.EnvironmentTickCount();
1246 int tmpFrameMS = maintc;
1247 tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0;
1248
1249 // Increment the frame counter
1250 ++Frame;
1235 1251
1236 while (!shuttingdown) 1252 try
1237 { 1253 {
1238 TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastupdate; 1254 // Check if any objects have reached their targets
1239 physicsFPS = 0f; 1255 CheckAtTargets();
1240 1256
1241 maintc = Util.EnvironmentTickCount(); 1257 // Update SceneObjectGroups that have scheduled themselves for updates
1242 int tmpFrameMS = maintc; 1258 // Objects queue their updates onto all scene presences
1243 tempOnRezMS = eventMS = backupMS = terrainMS = landMS = 0; 1259 if (Frame % m_update_objects == 0)
1260 m_sceneGraph.UpdateObjectGroups();
1244 1261
1245 // Increment the frame counter 1262 // Run through all ScenePresences looking for updates
1246 ++m_frame; 1263 // Presence updates and queued object updates for each presence are sent to clients
1264 if (Frame % m_update_presences == 0)
1265 m_sceneGraph.UpdatePresences();
1247 1266
1248 try 1267 // Coarse locations relate to positions of green dots on the mini-map (on a SecondLife client)
1268 if (Frame % m_update_coarse_locations == 0)
1249 { 1269 {
1250 // Check if any objects have reached their targets 1270 List<Vector3> coarseLocations;
1251 CheckAtTargets(); 1271 List<UUID> avatarUUIDs;
1272 SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60);
1273 // Send coarse locations to clients
1274 ForEachScenePresence(delegate(ScenePresence presence)
1275 {
1276 presence.SendCoarseLocations(coarseLocations, avatarUUIDs);
1277 });
1278 }
1252 1279
1253 // Update SceneObjectGroups that have scheduled themselves for updates 1280 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1254 // Objects queue their updates onto all scene presences 1281 if ((Frame % m_update_physics == 0) && m_physics_enabled)
1255 if (m_frame % m_update_objects == 0) 1282 m_sceneGraph.UpdatePreparePhysics();
1256 m_sceneGraph.UpdateObjectGroups(); 1283 physicsMS2 = Util.EnvironmentTickCountSubtract(tmpPhysicsMS2);
1257 1284
1258 // Run through all ScenePresences looking for updates 1285 // Apply any pending avatar force input to the avatar's velocity
1259 // Presence updates and queued object updates for each presence are sent to clients 1286 if (Frame % m_update_entitymovement == 0)
1260 if (m_frame % m_update_presences == 0) 1287 m_sceneGraph.UpdateScenePresenceMovement();
1261 m_sceneGraph.UpdatePresences();
1262 1288
1263 // Coarse locations relate to positions of green dots on the mini-map (on a SecondLife client) 1289 // Perform the main physics update. This will do the actual work of moving objects and avatars according to their
1264 if (m_frame % m_update_coarse_locations == 0) 1290 // velocity
1265 { 1291 int tmpPhysicsMS = Util.EnvironmentTickCount();
1266 List<Vector3> coarseLocations; 1292 if (Frame % m_update_physics == 0)
1267 List<UUID> avatarUUIDs; 1293 {
1268 SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60); 1294 if (m_physics_enabled)
1269 // Send coarse locations to clients 1295 physicsFPS = m_sceneGraph.UpdatePhysics(Math.Max(SinceLastFrame.TotalSeconds, m_timespan));
1270 ForEachScenePresence(delegate(ScenePresence presence) 1296 if (SynchronizeScene != null)
1271 { 1297 SynchronizeScene(this);
1272 presence.SendCoarseLocations(coarseLocations, avatarUUIDs); 1298 }
1273 }); 1299 physicsMS = Util.EnvironmentTickCountSubtract(tmpPhysicsMS);
1274 }
1275
1276 int tmpPhysicsMS2 = Util.EnvironmentTickCount();
1277 if ((m_frame % m_update_physics == 0) && m_physics_enabled)
1278 m_sceneGraph.UpdatePreparePhysics();
1279 physicsMS2 = Util.EnvironmentTickCountSubtract(tmpPhysicsMS2);
1280 1300
1281 // Apply any pending avatar force input to the avatar's velocity 1301 // Delete temp-on-rez stuff
1282 if (m_frame % m_update_entitymovement == 0) 1302 if (Frame % 1000 == 0 && !m_cleaningTemps)
1283 m_sceneGraph.UpdateScenePresenceMovement(); 1303 {
1304 int tmpTempOnRezMS = Util.EnvironmentTickCount();
1305 m_cleaningTemps = true;
1306 Util.FireAndForget(delegate { CleanTempObjects(); m_cleaningTemps = false; });
1307 tempOnRezMS = Util.EnvironmentTickCountSubtract(tmpTempOnRezMS);
1308 }
1284 1309
1285 // Perform the main physics update. This will do the actual work of moving objects and avatars according to their 1310 if (RegionStatus != RegionStatus.SlaveScene)
1286 // velocity 1311 {
1287 int tmpPhysicsMS = Util.EnvironmentTickCount(); 1312 if (Frame % m_update_events == 0)
1288 if (m_frame % m_update_physics == 0)
1289 { 1313 {
1290 if (m_physics_enabled) 1314 int evMS = Util.EnvironmentTickCount();
1291 physicsFPS = m_sceneGraph.UpdatePhysics(Math.Max(SinceLastFrame.TotalSeconds, m_timespan)); 1315 UpdateEvents();
1292 if (SynchronizeScene != null) 1316 eventMS = Util.EnvironmentTickCountSubtract(evMS); ;
1293 SynchronizeScene(this);
1294 } 1317 }
1295 physicsMS = Util.EnvironmentTickCountSubtract(tmpPhysicsMS);
1296 1318
1297 // Delete temp-on-rez stuff 1319 if (Frame % m_update_backup == 0)
1298 if (m_frame % 1000 == 0 && !m_cleaningTemps)
1299 { 1320 {
1300 int tmpTempOnRezMS = Util.EnvironmentTickCount(); 1321 int backMS = Util.EnvironmentTickCount();
1301 m_cleaningTemps = true; 1322 UpdateStorageBackup();
1302 Util.FireAndForget(delegate { CleanTempObjects(); m_cleaningTemps = false; }); 1323 backupMS = Util.EnvironmentTickCountSubtract(backMS);
1303 tempOnRezMS = Util.EnvironmentTickCountSubtract(tmpTempOnRezMS);
1304 } 1324 }
1305 1325
1306 if (RegionStatus != RegionStatus.SlaveScene) 1326 if (Frame % m_update_terrain == 0)
1307 { 1327 {
1308 if (m_frame % m_update_events == 0) 1328 int terMS = Util.EnvironmentTickCount();
1309 { 1329 UpdateTerrain();
1310 int evMS = Util.EnvironmentTickCount(); 1330 terrainMS = Util.EnvironmentTickCountSubtract(terMS);
1311 UpdateEvents();
1312 eventMS = Util.EnvironmentTickCountSubtract(evMS); ;
1313 }
1314
1315 if (m_frame % m_update_backup == 0)
1316 {
1317 int backMS = Util.EnvironmentTickCount();
1318 UpdateStorageBackup();
1319 backupMS = Util.EnvironmentTickCountSubtract(backMS);
1320 }
1321
1322 if (m_frame % m_update_terrain == 0)
1323 {
1324 int terMS = Util.EnvironmentTickCount();
1325 UpdateTerrain();
1326 terrainMS = Util.EnvironmentTickCountSubtract(terMS);
1327 }
1328
1329 if (m_frame % m_update_land == 0)
1330 {
1331 int ldMS = Util.EnvironmentTickCount();
1332 UpdateLand();
1333 landMS = Util.EnvironmentTickCountSubtract(ldMS);
1334 }
1335
1336 frameMS = Util.EnvironmentTickCountSubtract(tmpFrameMS);
1337 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1338 lastCompletedFrame = Util.EnvironmentTickCount();
1339
1340 // if (m_frame%m_update_avatars == 0)
1341 // UpdateInWorldTime();
1342 StatsReporter.AddPhysicsFPS(physicsFPS);
1343 StatsReporter.AddTimeDilation(TimeDilation);
1344 StatsReporter.AddFPS(1);
1345 StatsReporter.SetRootAgents(m_sceneGraph.GetRootAgentCount());
1346 StatsReporter.SetChildAgents(m_sceneGraph.GetChildAgentCount());
1347 StatsReporter.SetObjects(m_sceneGraph.GetTotalObjectsCount());
1348 StatsReporter.SetActiveObjects(m_sceneGraph.GetActiveObjectsCount());
1349 StatsReporter.addFrameMS(frameMS);
1350 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1351 StatsReporter.addOtherMS(otherMS);
1352 StatsReporter.SetActiveScripts(m_sceneGraph.GetActiveScriptsCount());
1353 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1354 } 1331 }
1355 1332
1356 if (LoginsDisabled && m_frame == 20) 1333 if (Frame % m_update_land == 0)
1357 { 1334 {
1358 // In 99.9% of cases it is a bad idea to manually force garbage collection. However, 1335 int ldMS = Util.EnvironmentTickCount();
1359 // this is a rare case where we know we have just went through a long cycle of heap 1336 UpdateLand();
1360 // allocations, and there is no more work to be done until someone logs in 1337 landMS = Util.EnvironmentTickCountSubtract(ldMS);
1361 GC.Collect(); 1338 }
1362 1339
1363 IConfig startupConfig = m_config.Configs["Startup"]; 1340 frameMS = Util.EnvironmentTickCountSubtract(tmpFrameMS);
1364 if (startupConfig == null || !startupConfig.GetBoolean("StartDisabled", false)) 1341 otherMS = tempOnRezMS + eventMS + backupMS + terrainMS + landMS;
1365 { 1342 lastCompletedFrame = Util.EnvironmentTickCount();
1366 m_log.DebugFormat("[REGION]: Enabling logins for {0}", RegionInfo.RegionName); 1343
1367 LoginsDisabled = false; 1344 // if (Frame%m_update_avatars == 0)
1368 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo); 1345 // UpdateInWorldTime();
1369 } 1346 StatsReporter.AddPhysicsFPS(physicsFPS);
1347 StatsReporter.AddTimeDilation(TimeDilation);
1348 StatsReporter.AddFPS(1);
1349 StatsReporter.SetRootAgents(m_sceneGraph.GetRootAgentCount());
1350 StatsReporter.SetChildAgents(m_sceneGraph.GetChildAgentCount());
1351 StatsReporter.SetObjects(m_sceneGraph.GetTotalObjectsCount());
1352 StatsReporter.SetActiveObjects(m_sceneGraph.GetActiveObjectsCount());
1353 StatsReporter.addFrameMS(frameMS);
1354 StatsReporter.addPhysicsMS(physicsMS + physicsMS2);
1355 StatsReporter.addOtherMS(otherMS);
1356 StatsReporter.SetActiveScripts(m_sceneGraph.GetActiveScriptsCount());
1357 StatsReporter.addScriptLines(m_sceneGraph.GetScriptLPS());
1358 }
1359
1360 if (LoginsDisabled && Frame == 20)
1361 {
1362 // In 99.9% of cases it is a bad idea to manually force garbage collection. However,
1363 // this is a rare case where we know we have just went through a long cycle of heap
1364 // allocations, and there is no more work to be done until someone logs in
1365 GC.Collect();
1366
1367 IConfig startupConfig = m_config.Configs["Startup"];
1368 if (startupConfig == null || !startupConfig.GetBoolean("StartDisabled", false))
1369 {
1370 m_log.DebugFormat("[REGION]: Enabling logins for {0}", RegionInfo.RegionName);
1371 LoginsDisabled = false;
1372 m_sceneGridService.InformNeighborsThatRegionisUp(RequestModuleInterface<INeighbourService>(), RegionInfo);
1370 } 1373 }
1371 } 1374 }
1372 catch (NotImplementedException) 1375 }
1373 { 1376 catch (NotImplementedException)
1374 throw; 1377 {
1375 } 1378 throw;
1376 catch (AccessViolationException e) 1379 }
1377 { 1380 catch (AccessViolationException e)
1378 m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName); 1381 {
1379 } 1382 m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName);
1380 //catch (NullReferenceException e) 1383 }
1381 //{ 1384 //catch (NullReferenceException e)
1382 // m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName); 1385 //{
1383 //} 1386 // m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName);
1384 catch (InvalidOperationException e) 1387 //}
1385 { 1388 catch (InvalidOperationException e)
1386 m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName); 1389 {
1387 } 1390 m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName);
1388 catch (Exception e) 1391 }
1389 { 1392 catch (Exception e)
1390 m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName); 1393 {
1391 } 1394 m_log.Error("[REGION]: Failed with exception " + e.ToString() + " On Region: " + RegionInfo.RegionName);
1392 finally 1395 }
1393 { 1396 finally
1394 m_lastupdate = DateTime.UtcNow; 1397 {
1395 } 1398 m_lastupdate = DateTime.UtcNow;
1399 }
1396 1400
1397 maintc = Util.EnvironmentTickCountSubtract(maintc); 1401 maintc = Util.EnvironmentTickCountSubtract(maintc);
1398 maintc = (int)(m_timespan * 1000) - maintc; 1402 maintc = (int)(m_timespan * 1000) - maintc;
1399 1403
1400 if (maintc > 0)
1401 Thread.Sleep(maintc);
1402 1404
1403 // Tell the watchdog that this thread is still alive 1405 m_lastUpdate = Util.EnvironmentTickCount();
1404 Watchdog.UpdateThread(); 1406 m_firstHeartbeat = false;
1405 1407
1406 m_lastUpdate = Util.EnvironmentTickCount(); 1408 if (maintc > 0)
1407 m_firstHeartbeat = false; 1409 Thread.Sleep(maintc);
1408 }
1409 }
1410 1410
1411 1411 // Tell the watchdog that this thread is still alive
1412 Watchdog.UpdateThread();
1413 }
1412 1414
1413 public void AddGroupTarget(SceneObjectGroup grp) 1415 public void AddGroupTarget(SceneObjectGroup grp)
1414 { 1416 {
@@ -3127,7 +3129,9 @@ namespace OpenSim.Region.Framework.Scenes
3127 (childagentYN ? "child" : "root"), agentID, RegionInfo.RegionName); 3129 (childagentYN ? "child" : "root"), agentID, RegionInfo.RegionName);
3128 3130
3129 m_sceneGraph.removeUserCount(!childagentYN); 3131 m_sceneGraph.removeUserCount(!childagentYN);
3130 CapsModule.RemoveCapsHandler(agentID); 3132
3133 if (CapsModule != null)
3134 CapsModule.RemoveCapsHandler(agentID);
3131 3135
3132 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever 3136 // REFACTORING PROBLEM -- well not really a problem, but just to point out that whatever
3133 // this method is doing is HORRIBLE!!! 3137 // this method is doing is HORRIBLE!!!
@@ -3405,8 +3409,11 @@ namespace OpenSim.Region.Framework.Scenes
3405 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname, 3409 RegionInfo.RegionName, (agent.child ? "child" : "root"), agent.firstname, agent.lastname,
3406 agent.AgentID, agent.circuitcode); 3410 agent.AgentID, agent.circuitcode);
3407 3411
3408 CapsModule.NewUserConnection(agent); 3412 if (CapsModule != null)
3409 CapsModule.AddCapsHandler(agent.AgentID); 3413 {
3414 CapsModule.NewUserConnection(agent);
3415 CapsModule.AddCapsHandler(agent.AgentID);
3416 }
3410 } 3417 }
3411 else 3418 else
3412 { 3419 {
@@ -3421,7 +3428,9 @@ namespace OpenSim.Region.Framework.Scenes
3421 agent.AgentID, RegionInfo.RegionName); 3428 agent.AgentID, RegionInfo.RegionName);
3422 3429
3423 sp.AdjustKnownSeeds(); 3430 sp.AdjustKnownSeeds();
3424 CapsModule.NewUserConnection(agent); 3431
3432 if (CapsModule != null)
3433 CapsModule.NewUserConnection(agent);
3425 } 3434 }
3426 } 3435 }
3427 3436
@@ -3933,15 +3942,15 @@ namespace OpenSim.Region.Framework.Scenes
3933 public void RequestTeleportLocation(IClientAPI remoteClient, string regionName, Vector3 position, 3942 public void RequestTeleportLocation(IClientAPI remoteClient, string regionName, Vector3 position,
3934 Vector3 lookat, uint teleportFlags) 3943 Vector3 lookat, uint teleportFlags)
3935 { 3944 {
3936 GridRegion regionInfo = GridService.GetRegionByName(UUID.Zero, regionName); 3945 List<GridRegion> regions = GridService.GetRegionsByName(RegionInfo.ScopeID, regionName, 1);
3937 if (regionInfo == null) 3946 if (regions == null || regions.Count == 0)
3938 { 3947 {
3939 // can't find the region: Tell viewer and abort 3948 // can't find the region: Tell viewer and abort
3940 remoteClient.SendTeleportFailed("The region '" + regionName + "' could not be found."); 3949 remoteClient.SendTeleportFailed("The region '" + regionName + "' could not be found.");
3941 return; 3950 return;
3942 } 3951 }
3943 3952
3944 RequestTeleportLocation(remoteClient, regionInfo.RegionHandle, position, lookat, teleportFlags); 3953 RequestTeleportLocation(remoteClient, regions[0].RegionHandle, position, lookat, teleportFlags);
3945 } 3954 }
3946 3955
3947 /// <summary> 3956 /// <summary>
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index af24ed3..fd03e93 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -1310,7 +1310,9 @@ namespace OpenSim.Region.Framework.Scenes
1310 if (m_agentTransfer != null) 1310 if (m_agentTransfer != null)
1311 m_agentTransfer.EnableChildAgents(this); 1311 m_agentTransfer.EnableChildAgents(this);
1312 else 1312 else
1313 m_log.DebugFormat("[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active"); 1313 m_log.DebugFormat(
1314 "[SCENE PRESENCE]: Unable to create child agents in neighbours, because AgentTransferModule is not active for region {0}",
1315 m_scene.RegionInfo.RegionName);
1314 1316
1315 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); 1317 IFriendsModule friendsModule = m_scene.RequestModuleInterface<IFriendsModule>();
1316 if (friendsModule != null) 1318 if (friendsModule != null)
@@ -3028,8 +3030,11 @@ namespace OpenSim.Region.Framework.Scenes
3028 #region Border Crossing Methods 3030 #region Border Crossing Methods
3029 3031
3030 /// <summary> 3032 /// <summary>
3031 /// Checks to see if the avatar is in range of a border and calls CrossToNewRegion 3033 /// Starts the process of moving an avatar into another region if they are crossing the border.
3032 /// </summary> 3034 /// </summary>
3035 /// <remarks>
3036 /// Also removes the avatar from the physical scene if transit has started.
3037 /// </remarks>
3033 protected void CheckForBorderCrossing() 3038 protected void CheckForBorderCrossing()
3034 { 3039 {
3035 if (IsChildAgent) 3040 if (IsChildAgent)
@@ -3097,7 +3102,6 @@ namespace OpenSim.Region.Framework.Scenes
3097 neighbor = HaveNeighbor(Cardinals.N, ref fix); 3102 neighbor = HaveNeighbor(Cardinals.N, ref fix);
3098 } 3103 }
3099 3104
3100
3101 // Makes sure avatar does not end up outside region 3105 // Makes sure avatar does not end up outside region
3102 if (neighbor <= 0) 3106 if (neighbor <= 0)
3103 { 3107 {
@@ -3152,6 +3156,13 @@ namespace OpenSim.Region.Framework.Scenes
3152 } 3156 }
3153 else 3157 else
3154 { 3158 {
3159 // We must remove the agent from the physical scene if it has been placed in transit. If we don't,
3160 // then this method continues to be called from ScenePresence.Update() until the handover of the client between
3161 // regions is completed. Since this handover can take more than 1000ms (due to the 1000ms
3162 // event queue polling response from the server), this results in the avatar pausing on the border
3163 // for the handover period.
3164 RemoveFromPhysicalScene();
3165
3155 // This constant has been inferred from experimentation 3166 // This constant has been inferred from experimentation
3156 // I'm not sure what this value should be, so I tried a few values. 3167 // I'm not sure what this value should be, so I tried a few values.
3157 timeStep = 0.04f; 3168 timeStep = 0.04f;
@@ -3163,6 +3174,15 @@ namespace OpenSim.Region.Framework.Scenes
3163 } 3174 }
3164 } 3175 }
3165 3176
3177 /// <summary>
3178 /// Checks whether this region has a neighbour in the given direction.
3179 /// </summary>
3180 /// <param name="car"></param>
3181 /// <param name="fix"></param>
3182 /// <returns>
3183 /// An integer which represents a compass point. N == 1, going clockwise until we reach NW == 8.
3184 /// Returns a positive integer if there is a region in that direction, a negative integer if not.
3185 /// </returns>
3166 protected int HaveNeighbor(Cardinals car, ref int[] fix) 3186 protected int HaveNeighbor(Cardinals car, ref int[] fix)
3167 { 3187 {
3168 uint neighbourx = m_regionInfo.RegionLocX; 3188 uint neighbourx = m_regionInfo.RegionLocX;
diff --git a/OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs b/OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs
new file mode 100644
index 0000000..af44640
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/AttachmentTests.cs
@@ -0,0 +1,174 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using System.Threading;
33using System.Timers;
34using Timer=System.Timers.Timer;
35using Nini.Config;
36using NUnit.Framework;
37using NUnit.Framework.SyntaxHelpers;
38using OpenMetaverse;
39using OpenSim.Framework;
40using OpenSim.Framework.Communications;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.CoreModules.World.Serialiser;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47using OpenSim.Tests.Common.Setup;
48
49namespace OpenSim.Region.Framework.Scenes.Tests
50{
51 /// <summary>
52 /// Attachment tests
53 /// </summary>
54 [TestFixture]
55 public class AttachmentTests
56 {
57 public Scene scene, scene2;
58 public UUID agent1;
59 public static Random random;
60 public ulong region1, region2;
61 public AgentCircuitData acd1;
62 public SceneObjectGroup sog1, sog2, sog3;
63
64 [TestFixtureSetUp]
65 public void Init()
66 {
67 TestHelper.InMethod();
68
69 scene = SceneSetupHelpers.SetupScene("Neighbour x", UUID.Random(), 1000, 1000);
70 scene2 = SceneSetupHelpers.SetupScene("Neighbour x+1", UUID.Random(), 1001, 1000);
71
72 ISharedRegionModule interregionComms = new LocalSimulationConnectorModule();
73 interregionComms.Initialise(new IniConfigSource());
74 interregionComms.PostInitialise();
75 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), interregionComms);
76 SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), interregionComms);
77
78 agent1 = UUID.Random();
79 random = new Random();
80 sog1 = NewSOG(UUID.Random(), scene, agent1);
81 sog2 = NewSOG(UUID.Random(), scene, agent1);
82 sog3 = NewSOG(UUID.Random(), scene, agent1);
83
84 //ulong neighbourHandle = Utils.UIntsToLong((uint)(neighbourx * Constants.RegionSize), (uint)(neighboury * Constants.RegionSize));
85 region1 = scene.RegionInfo.RegionHandle;
86 region2 = scene2.RegionInfo.RegionHandle;
87
88 SceneSetupHelpers.AddRootAgent(scene, agent1);
89 }
90
91 [Test]
92 public void T030_TestAddAttachments()
93 {
94 TestHelper.InMethod();
95
96 ScenePresence presence = scene.GetScenePresence(agent1);
97
98 presence.AddAttachment(sog1);
99 presence.AddAttachment(sog2);
100 presence.AddAttachment(sog3);
101
102 Assert.That(presence.HasAttachments(), Is.True);
103 Assert.That(presence.ValidateAttachments(), Is.True);
104 }
105
106 [Test]
107 public void T031_RemoveAttachments()
108 {
109 TestHelper.InMethod();
110
111 ScenePresence presence = scene.GetScenePresence(agent1);
112 presence.RemoveAttachment(sog1);
113 presence.RemoveAttachment(sog2);
114 presence.RemoveAttachment(sog3);
115 Assert.That(presence.HasAttachments(), Is.False);
116 }
117
118 // I'm commenting this test because scene setup NEEDS InventoryService to
119 // be non-null
120 //[Test]
121 public void T032_CrossAttachments()
122 {
123 TestHelper.InMethod();
124
125 ScenePresence presence = scene.GetScenePresence(agent1);
126 ScenePresence presence2 = scene2.GetScenePresence(agent1);
127 presence2.AddAttachment(sog1);
128 presence2.AddAttachment(sog2);
129
130 ISharedRegionModule serialiser = new SerialiserModule();
131 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser);
132 SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser);
133
134 Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross");
135
136 //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful");
137 Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted");
138 Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects");
139 }
140
141 private SceneObjectGroup NewSOG(UUID uuid, Scene scene, UUID agent)
142 {
143 SceneObjectPart sop = new SceneObjectPart();
144 sop.Name = RandomName();
145 sop.Description = RandomName();
146 sop.Text = RandomName();
147 sop.SitName = RandomName();
148 sop.TouchName = RandomName();
149 sop.UUID = uuid;
150 sop.Shape = PrimitiveBaseShape.Default;
151 sop.Shape.State = 1;
152 sop.OwnerID = agent;
153
154 SceneObjectGroup sog = new SceneObjectGroup(sop);
155 sog.SetScene(scene);
156
157 return sog;
158 }
159
160 private static string RandomName()
161 {
162 StringBuilder name = new StringBuilder();
163 int size = random.Next(5,12);
164 char ch;
165 for (int i = 0; i < size; i++)
166 {
167 ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65))) ;
168 name.Append(ch);
169 }
170
171 return name.ToString();
172 }
173 }
174} \ No newline at end of file
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
index ef52363..fd2d6fa 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceTests.cs
@@ -40,6 +40,7 @@ using OpenSim.Framework;
40using OpenSim.Framework.Communications; 40using OpenSim.Framework.Communications;
41using OpenSim.Region.Framework.Scenes; 41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Interfaces; 42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.CoreModules.Framework.EntityTransfer;
43using OpenSim.Region.CoreModules.World.Serialiser; 44using OpenSim.Region.CoreModules.World.Serialiser;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation; 45using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45using OpenSim.Tests.Common; 46using OpenSim.Tests.Common;
@@ -116,9 +117,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
116 agent.ChildrenCapSeeds = new Dictionary<ulong, string>(); 117 agent.ChildrenCapSeeds = new Dictionary<ulong, string>();
117 agent.child = true; 118 agent.child = true;
118 119
119 if (scene.PresenceService == null)
120 Console.WriteLine("Presence Service is null");
121
122 scene.PresenceService.LoginAgent(agent.AgentID.ToString(), agent.SessionID, agent.SecureSessionID); 120 scene.PresenceService.LoginAgent(agent.AgentID.ToString(), agent.SessionID, agent.SecureSessionID);
123 121
124 string reason; 122 string reason;
@@ -175,25 +173,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
175 173
176 Assert.That(neighbours.Count, Is.EqualTo(2)); 174 Assert.That(neighbours.Count, Is.EqualTo(2));
177 } 175 }
178
179 public void fixNullPresence()
180 {
181 string firstName = "testfirstname";
182
183 AgentCircuitData agent = new AgentCircuitData();
184 agent.AgentID = agent1;
185 agent.firstname = firstName;
186 agent.lastname = "testlastname";
187 agent.SessionID = UUID.Zero;
188 agent.SecureSessionID = UUID.Zero;
189 agent.circuitcode = 123;
190 agent.BaseFolder = UUID.Zero;
191 agent.InventoryFolder = UUID.Zero;
192 agent.startpos = Vector3.Zero;
193 agent.CapsPath = GetRandomCapsObjectPath();
194
195 acd1 = agent;
196 }
197 176
198 [Test] 177 [Test]
199 public void T013_TestRemoveNeighbourRegion() 178 public void T013_TestRemoveNeighbourRegion()
@@ -211,24 +190,36 @@ namespace OpenSim.Region.Framework.Scenes.Tests
211 CompleteAvatarMovement 190 CompleteAvatarMovement
212 */ 191 */
213 } 192 }
214 193
215 // I'm commenting this test, because this is not supposed to happen here 194 /// <summary>
216 //[Test] 195 /// Test that if a root agent logs into a region, a child agent is also established in the neighbouring region
217 public void T020_TestMakeRootAgent() 196 /// </summary>
197 /// <remarks>
198 /// Please note that unlike the other tests here, this doesn't rely on structures
199 /// </remarks>
200 [Test]
201 public void TestChildAgentEstablished()
218 { 202 {
219 TestHelper.InMethod(); 203 TestHelper.InMethod();
220 204// log4net.Config.XmlConfigurator.Configure();
221 ScenePresence presence = scene.GetScenePresence(agent1); 205
222 Assert.That(presence.IsChildAgent, Is.False, "Starts out as a root agent"); 206 UUID agent1Id = UUID.Parse("00000000-0000-0000-0000-000000000001");
223 207
224 presence.MakeChildAgent(); 208 TestScene myScene1 = SceneSetupHelpers.SetupScene("Neighbour y", UUID.Random(), 1000, 1000);
225 Assert.That(presence.IsChildAgent, Is.True, "Did not change to child agent after MakeChildAgent"); 209 TestScene myScene2 = SceneSetupHelpers.SetupScene("Neighbour y + 1", UUID.Random(), 1001, 1000);
226 210
227 // Accepts 0 but rejects Constants.RegionSize 211 IConfigSource configSource = new IniConfigSource();
228 Vector3 pos = new Vector3(0,unchecked(Constants.RegionSize-1),0); 212 configSource.AddConfig("Modules").Set("EntityTransferModule", "BasicEntityTransferModule");
229 presence.MakeRootAgent(pos,true); 213 EntityTransferModule etm = new EntityTransferModule();
230 Assert.That(presence.IsChildAgent, Is.False, "Did not go back to root agent"); 214
231 Assert.That(presence.AbsolutePosition, Is.EqualTo(pos), "Position is not the same one entered"); 215 SceneSetupHelpers.SetupSceneModules(myScene1, configSource, etm);
216
217 SceneSetupHelpers.AddRootAgent(myScene1, agent1Id);
218 ScenePresence childPresence = myScene2.GetScenePresence(agent1);
219
220 // TODO: Need to do a fair amount of work to allow synchronous establishment of child agents
221// Assert.That(childPresence, Is.Not.Null);
222// Assert.That(childPresence.IsChildAgent, Is.True);
232 } 223 }
233 224
234 // I'm commenting this test because it does not represent 225 // I'm commenting this test because it does not represent
@@ -333,63 +324,26 @@ namespace OpenSim.Region.Framework.Scenes.Tests
333 Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected."); 324 Assert.That(presence2.IsChildAgent, Is.True, "Did not return from region as expected.");
334 Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again."); 325 Assert.That(presence.IsChildAgent, Is.False, "Presence was not made root in old region again.");
335 } 326 }
336 327
337 [Test] 328 public void fixNullPresence()
338 public void T030_TestAddAttachments()
339 {
340 TestHelper.InMethod();
341
342 ScenePresence presence = scene.GetScenePresence(agent1);
343
344 presence.AddAttachment(sog1);
345 presence.AddAttachment(sog2);
346 presence.AddAttachment(sog3);
347
348 Assert.That(presence.HasAttachments(), Is.True);
349 Assert.That(presence.ValidateAttachments(), Is.True);
350 }
351
352 [Test]
353 public void T031_RemoveAttachments()
354 {
355 TestHelper.InMethod();
356
357 ScenePresence presence = scene.GetScenePresence(agent1);
358 presence.RemoveAttachment(sog1);
359 presence.RemoveAttachment(sog2);
360 presence.RemoveAttachment(sog3);
361 Assert.That(presence.HasAttachments(), Is.False);
362 }
363
364 // I'm commenting this test because scene setup NEEDS InventoryService to
365 // be non-null
366 //[Test]
367 public void T032_CrossAttachments()
368 { 329 {
369 TestHelper.InMethod(); 330 string firstName = "testfirstname";
370
371 ScenePresence presence = scene.GetScenePresence(agent1);
372 ScenePresence presence2 = scene2.GetScenePresence(agent1);
373 presence2.AddAttachment(sog1);
374 presence2.AddAttachment(sog2);
375
376 ISharedRegionModule serialiser = new SerialiserModule();
377 SceneSetupHelpers.SetupSceneModules(scene, new IniConfigSource(), serialiser);
378 SceneSetupHelpers.SetupSceneModules(scene2, new IniConfigSource(), serialiser);
379
380 Assert.That(presence.HasAttachments(), Is.False, "Presence has attachments before cross");
381 331
382 //Assert.That(presence2.CrossAttachmentsIntoNewRegion(region1, true), Is.True, "Cross was not successful"); 332 AgentCircuitData agent = new AgentCircuitData();
383 Assert.That(presence2.HasAttachments(), Is.False, "Presence2 objects were not deleted"); 333 agent.AgentID = agent1;
384 Assert.That(presence.HasAttachments(), Is.True, "Presence has not received new objects"); 334 agent.firstname = firstName;
385 } 335 agent.lastname = "testlastname";
336 agent.SessionID = UUID.Zero;
337 agent.SecureSessionID = UUID.Zero;
338 agent.circuitcode = 123;
339 agent.BaseFolder = UUID.Zero;
340 agent.InventoryFolder = UUID.Zero;
341 agent.startpos = Vector3.Zero;
342 agent.CapsPath = GetRandomCapsObjectPath();
386 343
387 [TearDown] 344 acd1 = agent;
388 public void TearDown()
389 {
390 if (MainServer.Instance != null) MainServer.Instance.Stop();
391 } 345 }
392 346
393 public static string GetRandomCapsObjectPath() 347 public static string GetRandomCapsObjectPath()
394 { 348 {
395 UUID caps = UUID.Random(); 349 UUID caps = UUID.Random();
diff --git a/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
new file mode 100644
index 0000000..9aba8a8
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/SceneTests.cs
@@ -0,0 +1,71 @@
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
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using System.Threading;
33using System.Timers;
34using Timer=System.Timers.Timer;
35using Nini.Config;
36using NUnit.Framework;
37using NUnit.Framework.SyntaxHelpers;
38using OpenMetaverse;
39using OpenSim.Framework;
40using OpenSim.Framework.Communications;
41using OpenSim.Region.Framework.Scenes;
42using OpenSim.Region.Framework.Interfaces;
43using OpenSim.Region.CoreModules.World.Serialiser;
44using OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation;
45using OpenSim.Tests.Common;
46using OpenSim.Tests.Common.Mock;
47using OpenSim.Tests.Common.Setup;
48
49namespace OpenSim.Region.Framework.Scenes.Tests
50{
51 /// <summary>
52 /// Scene presence tests
53 /// </summary>
54 [TestFixture]
55 public class SceneTests
56 {
57 /// <summary>
58 /// Very basic scene update test. Should become more elaborate with time.
59 /// </summary>
60 [Test]
61 public void TestUpdateScene()
62 {
63 TestHelper.InMethod();
64
65 Scene scene = SceneSetupHelpers.SetupScene();
66 scene.Update();
67
68 Assert.That(scene.Frame, Is.EqualTo(1));
69 }
70 }
71} \ No newline at end of file