Annotation of /trunk/ModularRex/RexParts/ModrexObjects.cs
Parent Directory
|
Revision Log
Revision 398 - (view) (download)
| 1 : | mikkopa | 39 | using System; |
| 2 : | using System.Collections.Generic; | ||
| 3 : | using System.IO; | ||
| 4 : | using System.Reflection; | ||
| 5 : | using log4net; | ||
| 6 : | using ModularRex.RexFramework; | ||
| 7 : | using ModularRex.RexNetwork; | ||
| 8 : | using Nini.Config; | ||
| 9 : | using OpenMetaverse; | ||
| 10 : | mikkopa | 63 | using OpenSim.Region.Framework.Interfaces; |
| 11 : | using OpenSim.Region.Framework.Scenes; | ||
| 12 : | tuco | 53 | using OpenSim.Framework; |
| 13 : | mikkopa | 128 | using ModularRex.NHibernate; |
| 14 : | mikkopa | 39 | |
| 15 : | namespace ModularRex.RexParts | ||
| 16 : | { | ||
| 17 : | mikkopa | 286 | public class ModrexObjects : IRegionModule, IRexObjectPropertiesEventManager, IModrexObjectsProvider |
| 18 : | mikkopa | 39 | { |
| 19 : | private static readonly ILog m_log = | ||
| 20 : | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
| 21 : | |||
| 22 : | tuco | 57 | private RexObjectPropertiesManager RexObjectPropertiesCache = new RexObjectPropertiesManager(); |
| 23 : | mikkopa | 39 | private List<Scene> m_scenes = new List<Scene>(); |
| 24 : | |||
| 25 : | private NHibernateRexObjectData m_db; | ||
| 26 : | private string m_db_connectionstring; | ||
| 27 : | |||
| 28 : | tuco | 57 | public delegate void OnChangePythonClassDelegate(UUID id); |
| 29 : | mikkopa | 42 | public event OnChangePythonClassDelegate OnPythonClassChange; |
| 30 : | |||
| 31 : | mikkopa | 39 | public void Initialise(Scene scene, IConfigSource source) |
| 32 : | { | ||
| 33 : | m_scenes.Add(scene); | ||
| 34 : | |||
| 35 : | mikkopa | 147 | scene.RegisterModuleInterface<ModrexObjects>(this); |
| 36 : | mikkopa | 286 | scene.RegisterModuleInterface<IModrexObjectsProvider>(this); |
| 37 : | mikkopa | 39 | scene.EventManager.OnClientConnect += EventManager_OnClientConnect; |
| 38 : | mikkopa | 75 | scene.SceneContents.OnObjectDuplicate += SceneGraph_OnObjectDuplicate; |
| 39 : | scene.SceneContents.OnObjectRemove += SceneGraph_OnObjectRemove; | ||
| 40 : | mikkopa | 339 | scene.EventManager.OnObjectBeingRemovedFromScene += EventManager_OnObjectBeingRemovedFromScene; |
| 41 : | mikkopa | 39 | |
| 42 : | tuco | 80 | scene.AddCommand(this, "modreximport", "load 0.4 rex database <connstring>", "conn string example: SQLiteDialect;SQLite20Driver;Data Source=beneath_the_waves.db;Version=3", HandleLoadRexLegacyData); |
| 43 : | mikkopa | 39 | |
| 44 : | if (m_db == null) | ||
| 45 : | { | ||
| 46 : | m_db = new NHibernateRexObjectData(); | ||
| 47 : | } | ||
| 48 : | |||
| 49 : | if (source != null) | ||
| 50 : | { | ||
| 51 : | try | ||
| 52 : | { | ||
| 53 : | m_db_connectionstring = source.Configs["realXtend"].GetString("db_connectionstring", "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"); | ||
| 54 : | |||
| 55 : | } | ||
| 56 : | catch (Exception) | ||
| 57 : | { | ||
| 58 : | |||
| 59 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 60 : | } | ||
| 61 : | } | ||
| 62 : | else | ||
| 63 : | { | ||
| 64 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 65 : | } | ||
| 66 : | } | ||
| 67 : | |||
| 68 : | mikkopa | 339 | void EventManager_OnObjectBeingRemovedFromScene(SceneObjectGroup obj) |
| 69 : | { | ||
| 70 : | if (RexObjectPropertiesCache.ContainsKey(obj.UUID)) | ||
| 71 : | { | ||
| 72 : | RexObjectPropertiesCache.Remove(obj.UUID); | ||
| 73 : | } | ||
| 74 : | } | ||
| 75 : | |||
| 76 : | mikkopa | 39 | void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) |
| 77 : | { | ||
| 78 : | mikkopa | 156 | RexClientViewBase rcv; |
| 79 : | mikkopa | 39 | if (client.TryGet(out rcv)) |
| 80 : | { | ||
| 81 : | rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; | ||
| 82 : | mikkopa | 86 | rcv.OnPrimFreeData += rcv_OnPrimFreeData; |
| 83 : | mikkopa | 39 | //rcv.OnChatFromClient += rcv_OnChatFromClient; |
| 84 : | |||
| 85 : | // Send them the current Scene. | ||
| 86 : | SendAllPropertiesToUser(rcv); | ||
| 87 : | mikkopa | 137 | } |
| 88 : | mikkopa | 39 | } |
| 89 : | |||
| 90 : | tuco | 87 | private void rcv_OnPrimFreeData(IClientAPI sender, List<string> parameters) |
| 91 : | mikkopa | 86 | { |
| 92 : | m_log.Info("[REXOBJS] Received Prim free data"); | ||
| 93 : | mikkopa | 175 | if (parameters.Count >= 2) |
| 94 : | mikkopa | 86 | { |
| 95 : | UUID primID = new UUID(parameters[0]); | ||
| 96 : | mikkopa | 175 | string data = String.Empty; |
| 97 : | if(parameters.Count == 2) | ||
| 98 : | { | ||
| 99 : | data = parameters[1]; | ||
| 100 : | }else | ||
| 101 : | { | ||
| 102 : | for (int i = 1; i < parameters.Count; i++) | ||
| 103 : | { | ||
| 104 : | data += parameters[i]; | ||
| 105 : | } | ||
| 106 : | } | ||
| 107 : | mikkopa | 86 | |
| 108 : | RexObjectProperties props = GetObject(primID); | ||
| 109 : | props.RexData = data; | ||
| 110 : | mikkopa | 175 | |
| 111 : | SendPrimFreeDataToAllUsers(primID, data); | ||
| 112 : | mikkopa | 86 | } |
| 113 : | else | ||
| 114 : | { | ||
| 115 : | m_log.Warn("[REXOBJS] unexpected number of parameters"); | ||
| 116 : | } | ||
| 117 : | } | ||
| 118 : | |||
| 119 : | mikkopa | 398 | public void SendPrimFreeDataToAllUsers(UUID id, string data) |
| 120 : | mikkopa | 175 | { |
| 121 : | foreach (Scene scene in m_scenes) | ||
| 122 : | { | ||
| 123 : | scene.ForEachScenePresence( | ||
| 124 : | delegate(ScenePresence avatar) | ||
| 125 : | { | ||
| 126 : | RexClientViewBase rex; | ||
| 127 : | if (avatar.ClientView.TryGet(out rex)) | ||
| 128 : | { | ||
| 129 : | rex.SendRexPrimFreeData(id, data); | ||
| 130 : | } | ||
| 131 : | }); | ||
| 132 : | } | ||
| 133 : | } | ||
| 134 : | |||
| 135 : | tuco | 59 | void SceneGraph_OnObjectDuplicate(EntityBase original, EntityBase clone) |
| 136 : | { | ||
| 137 : | RexObjectProperties origprops = GetObject(original.UUID); | ||
| 138 : | RexObjectProperties cloneprops = GetObject(clone.UUID); | ||
| 139 : | |||
| 140 : | cloneprops.SetRexPrimDataFromObject(origprops); | ||
| 141 : | } | ||
| 142 : | |||
| 143 : | tuco | 60 | void SceneGraph_OnObjectRemove(EntityBase obj) |
| 144 : | { | ||
| 145 : | mikkopa | 334 | //this object group was removed from scene, but part is not necessarily removed from all groups |
| 146 : | //DeleteObject(obj.UUID); | ||
| 147 : | tuco | 60 | } |
| 148 : | |||
| 149 : | |||
| 150 : | mikkopa | 39 | //void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) |
| 151 : | //{ | ||
| 152 : | // if (e.Message.StartsWith("/rexobj ")) | ||
| 153 : | // { | ||
| 154 : | // string uuid = e.Message.Split(' ')[1]; | ||
| 155 : | // string asset = e.Message.Split(' ')[2]; | ||
| 156 : | |||
| 157 : | // UUID prim = new UUID(uuid); | ||
| 158 : | // UUID assetID = new UUID(asset); | ||
| 159 : | |||
| 160 : | // m_objs[prim].RexMeshUUID = assetID; | ||
| 161 : | // SendPropertiesToAllUsers(prim, m_objs[prim]); | ||
| 162 : | // } | ||
| 163 : | //} | ||
| 164 : | |||
| 165 : | void SendPropertiesToAllUsers(UUID id, RexObjectProperties props) | ||
| 166 : | { | ||
| 167 : | foreach (Scene scene in m_scenes) | ||
| 168 : | { | ||
| 169 : | scene.ForEachScenePresence( | ||
| 170 : | delegate(ScenePresence avatar) | ||
| 171 : | { | ||
| 172 : | mikkopa | 156 | RexClientViewBase rex; |
| 173 : | mikkopa | 39 | if (avatar.ClientView.TryGet(out rex)) |
| 174 : | { | ||
| 175 : | rex.SendRexObjectProperties(id,props); | ||
| 176 : | } | ||
| 177 : | }); | ||
| 178 : | } | ||
| 179 : | } | ||
| 180 : | |||
| 181 : | mikkopa | 156 | private void SendPreloadAssetsToUser(RexClientViewBase user) |
| 182 : | mikkopa | 69 | { |
| 183 : | try | ||
| 184 : | { | ||
| 185 : | Scene ourScene = null; | ||
| 186 : | foreach (Scene s in m_scenes) | ||
| 187 : | { | ||
| 188 : | if (user.Scene.RegionInfo.RegionHandle == s.RegionInfo.RegionHandle) | ||
| 189 : | ourScene = s; | ||
| 190 : | } | ||
| 191 : | |||
| 192 : | if (ourScene != null) | ||
| 193 : | { | ||
| 194 : | if (ourScene.Modules.ContainsKey("RexAssetPreload")) | ||
| 195 : | { | ||
| 196 : | RexAssetPreload module = (RexAssetPreload)ourScene.Modules["RexAssetPreload"]; | ||
| 197 : | if (module.PreloadAssetDictionary.Count > 0) | ||
| 198 : | { | ||
| 199 : | user.SendRexPreloadAssets(module.PreloadAssetDictionary); | ||
| 200 : | } | ||
| 201 : | } | ||
| 202 : | } | ||
| 203 : | } | ||
| 204 : | catch (Exception e) | ||
| 205 : | { | ||
| 206 : | m_log.Error("[MODREXOBJECTS]: Sending preload assets failed.", e); | ||
| 207 : | } | ||
| 208 : | } | ||
| 209 : | |||
| 210 : | mikkopa | 339 | public void SendAllPropertiesToUser(RexClientViewBase user) |
| 211 : | mikkopa | 39 | { |
| 212 : | mikkopa | 69 | SendPreloadAssetsToUser(user); |
| 213 : | |||
| 214 : | tuco | 57 | foreach (RexObjectProperties p in GetObjects()) |
| 215 : | mikkopa | 39 | { |
| 216 : | tuco | 57 | user.SendRexObjectProperties(p.ParentObjectID, p); |
| 217 : | mikkopa | 175 | if (p.RexData.Length > 0) //send rex data also if exists |
| 218 : | { | ||
| 219 : | user.SendRexPrimFreeData(p.ParentObjectID, p.RexData); | ||
| 220 : | } | ||
| 221 : | mikkopa | 39 | } |
| 222 : | } | ||
| 223 : | |||
| 224 : | tuco | 87 | void rcv_OnRexObjectProperties(IClientAPI sender, UUID id, RexObjectProperties props) |
| 225 : | mikkopa | 39 | { |
| 226 : | tuco | 50 | m_log.Info("[REXOBJS] Received RexObjData for " + id); |
| 227 : | mikkopa | 39 | if (props.ParentObjectID == UUID.Zero) |
| 228 : | props.ParentObjectID = id; | ||
| 229 : | tuco | 50 | |
| 230 : | tuco | 57 | // debugdata props.PrintRexPrimdata(); |
| 231 : | |||
| 232 : | RexObjectProperties currentprops = GetObject(id); | ||
| 233 : | currentprops.SetRexPrimDataFromObject(props); | ||
| 234 : | mikkopa | 39 | } |
| 235 : | |||
| 236 : | public void PostInitialise() | ||
| 237 : | { | ||
| 238 : | lock (m_db) | ||
| 239 : | { | ||
| 240 : | if (!m_db.Inizialized) | ||
| 241 : | { | ||
| 242 : | m_db.Initialise(m_db_connectionstring); | ||
| 243 : | } | ||
| 244 : | } | ||
| 245 : | tuco | 57 | LoadRexObjectPropertiesToCache(); |
| 246 : | mikkopa | 39 | } |
| 247 : | |||
| 248 : | public void Close() | ||
| 249 : | { | ||
| 250 : | ; | ||
| 251 : | } | ||
| 252 : | |||
| 253 : | public string Name | ||
| 254 : | { | ||
| 255 : | get { return "RexObjectsModule"; } | ||
| 256 : | } | ||
| 257 : | |||
| 258 : | public bool IsSharedModule | ||
| 259 : | { | ||
| 260 : | get { return true; } | ||
| 261 : | } | ||
| 262 : | mikkopa | 42 | |
| 263 : | tuco | 57 | |
| 264 : | |||
| 265 : | #region Trigger/handle rexobjectproperties events | ||
| 266 : | public void TriggerOnChangePythonClass(UUID id) | ||
| 267 : | mikkopa | 42 | { |
| 268 : | tuco | 57 | if (OnPythonClassChange != null) |
| 269 : | OnPythonClassChange(id); | ||
| 270 : | mikkopa | 42 | } |
| 271 : | |||
| 272 : | tuco | 57 | public void TriggerOnChangeCollisionMesh(UUID id) |
| 273 : | mikkopa | 42 | { |
| 274 : | tuco | 50 | // tucofixme, add |
| 275 : | //if (!GlobalSettings.Instance.m_3d_collision_models) | ||
| 276 : | // return; | ||
| 277 : | |||
| 278 : | tuco | 57 | RexObjectProperties p = GetObject(id); |
| 279 : | mikkopa | 323 | SceneObjectPart sop = null;// = m_scenes[0].GetSceneObjectPart(id); |
| 280 : | foreach (Scene scene in m_scenes) | ||
| 281 : | { | ||
| 282 : | SceneObjectPart part = scene.GetSceneObjectPart(id); | ||
| 283 : | if (part != null) | ||
| 284 : | { | ||
| 285 : | sop = part; | ||
| 286 : | break; | ||
| 287 : | } | ||
| 288 : | } | ||
| 289 : | |||
| 290 : | tuco | 50 | if (sop == null) |
| 291 : | { | ||
| 292 : | tuco | 57 | m_log.Error("[REXOBJS] TriggerOnChangeCollisionMesh, no SceneObjectPart for id:" + id.ToString()); |
| 293 : | tuco | 50 | return; |
| 294 : | } | ||
| 295 : | tuco | 57 | |
| 296 : | tuco | 65 | if (sop.ParentGroup != null && sop.PhysActor is IRexPhysicsActor) |
| 297 : | tuco | 50 | { |
| 298 : | tuco | 57 | if (p.RexCollisionMeshUUID != UUID.Zero) |
| 299 : | RexUpdateCollisionMesh(id); | ||
| 300 : | else | ||
| 301 : | tuco | 65 | ((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(null, "", false); |
| 302 : | tuco | 57 | } |
| 303 : | tuco | 50 | } |
| 304 : | |||
| 305 : | tuco | 57 | public void TriggerOnChangeScaleToPrim(UUID id) |
| 306 : | tuco | 50 | { |
| 307 : | // tucofixme, add | ||
| 308 : | //if (!GlobalSettings.Instance.m_3d_collision_models) | ||
| 309 : | // return; | ||
| 310 : | tuco | 57 | |
| 311 : | RexObjectProperties p = GetObject(id); | ||
| 312 : | mikkopa | 327 | SceneObjectPart sop = null; |
| 313 : | foreach (Scene s in m_scenes) | ||
| 314 : | { | ||
| 315 : | SceneObjectPart part = s.GetSceneObjectPart(id); | ||
| 316 : | if (part != null) | ||
| 317 : | { | ||
| 318 : | sop = part; | ||
| 319 : | break; | ||
| 320 : | } | ||
| 321 : | } | ||
| 322 : | |||
| 323 : | tuco | 50 | if (sop == null) |
| 324 : | { | ||
| 325 : | tuco | 57 | m_log.Error("[REXOBJS] TriggerOnChangeScaleToPrim, no SceneObjectPart for id:" + id.ToString()); |
| 326 : | return; | ||
| 327 : | tuco | 50 | } |
| 328 : | |||
| 329 : | tuco | 65 | if (sop.ParentGroup != null && sop.PhysActor is IRexPhysicsActor) |
| 330 : | tuco | 50 | { |
| 331 : | tuco | 65 | ((IRexPhysicsActor)sop.PhysActor).SetBoundsScaling(p.RexScaleToPrim); |
| 332 : | tuco | 57 | sop.ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(sop.PhysActor); |
| 333 : | tuco | 50 | } |
| 334 : | } | ||
| 335 : | |||
| 336 : | tuco | 57 | public void TriggerOnChangeRexObjectProperties(UUID id) |
| 337 : | { | ||
| 338 : | RexObjectProperties props = GetObject(id); | ||
| 339 : | |||
| 340 : | mikkopa | 291 | //instead of saving right away, set timer to save after a sec. |
| 341 : | //m_db.StoreObject(props); | ||
| 342 : | tuco | 57 | SendPropertiesToAllUsers(id,props); |
| 343 : | mikkopa | 291 | props.ScheduleSave(); |
| 344 : | tuco | 57 | } |
| 345 : | |||
| 346 : | public void TriggerOnChangeRexObjectMetaData(UUID id) | ||
| 347 : | { | ||
| 348 : | RexObjectProperties props = GetObject(id); | ||
| 349 : | |||
| 350 : | m_db.StoreObject(props); | ||
| 351 : | // tucofixme, send metadata to all users | ||
| 352 : | } | ||
| 353 : | |||
| 354 : | |||
| 355 : | |||
| 356 : | tuco | 50 | public void RexUpdateCollisionMesh(UUID id) |
| 357 : | { | ||
| 358 : | tuco | 57 | // tucofixme, add |
| 359 : | tuco | 50 | //if (!GlobalSettings.Instance.m_3d_collision_models) |
| 360 : | // return; | ||
| 361 : | |||
| 362 : | tuco | 57 | RexObjectProperties p = GetObject(id); |
| 363 : | mikkopa | 323 | SceneObjectPart sop = null;// m_scenes[0].GetSceneObjectPart(id); |
| 364 : | foreach (Scene s in m_scenes) | ||
| 365 : | { | ||
| 366 : | SceneObjectPart part = s.GetSceneObjectPart(id); | ||
| 367 : | if (part != null) | ||
| 368 : | { | ||
| 369 : | sop = part; | ||
| 370 : | break; | ||
| 371 : | } | ||
| 372 : | } | ||
| 373 : | |||
| 374 : | tuco | 50 | if (sop == null) |
| 375 : | { | ||
| 376 : | m_log.Error("[REXOBJS] RexUpdateCollisionMesh, no SceneObjectPart for id:" + id.ToString()); | ||
| 377 : | return; | ||
| 378 : | tuco | 57 | } |
| 379 : | |||
| 380 : | tuco | 65 | if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor is IRexPhysicsActor) |
| 381 : | tuco | 50 | { |
| 382 : | mikkopa | 153 | AssetBase tempmodel = sop.ParentGroup.Scene.AssetService.Get(p.RexCollisionMeshUUID.ToString()); |
| 383 : | tuco | 50 | if (tempmodel != null) |
| 384 : | mikkopa | 72 | ((IRexPhysicsActor)sop.PhysActor).SetCollisionMesh(tempmodel.Data, tempmodel.Name, p.RexScaleToPrim); |
| 385 : | tuco | 50 | } |
| 386 : | tuco | 57 | } |
| 387 : | tuco | 64 | |
| 388 : | mikkopa | 398 | public sbyte GetAssetType(UUID assetid) |
| 389 : | tuco | 64 | { |
| 390 : | mikkopa | 153 | AssetBase tempmodel = m_scenes[0].AssetService.Get(assetid.ToString()); |
| 391 : | tuco | 64 | if (tempmodel == null) |
| 392 : | mikkopa | 153 | m_scenes[0].AssetService.Get(assetid.ToString()); |
| 393 : | tuco | 64 | |
| 394 : | if (tempmodel != null) | ||
| 395 : | mikkopa | 398 | return tempmodel.Type; |
| 396 : | tuco | 64 | else |
| 397 : | return 0; | ||
| 398 : | } | ||
| 399 : | mikkopa | 291 | |
| 400 : | |||
| 401 : | public void TriggerOnSaveObject(UUID id) | ||
| 402 : | { | ||
| 403 : | RexObjectProperties props = GetObject(id); | ||
| 404 : | m_db.StoreObject(props); | ||
| 405 : | } | ||
| 406 : | tuco | 57 | #endregion |
| 407 : | |||
| 408 : | |||
| 409 : | #region RexObjectProperties Cache | ||
| 410 : | |||
| 411 : | private void LoadRexObjectPropertiesToCache() | ||
| 412 : | { | ||
| 413 : | if (!m_db.Inizialized) | ||
| 414 : | { | ||
| 415 : | m_log.ErrorFormat("LoadRexObjectPropertiesToCache failed, db not initialized"); | ||
| 416 : | return; | ||
| 417 : | } | ||
| 418 : | |||
| 419 : | foreach (Scene s in m_scenes) | ||
| 420 : | { | ||
| 421 : | foreach (EntityBase e in s.Entities) | ||
| 422 : | { | ||
| 423 : | mikkopa | 339 | if (e is SceneObjectGroup && !RexObjectPropertiesCache.ContainsKey(e.UUID)) |
| 424 : | mikkopa | 334 | { |
| 425 : | SceneObjectGroup oGroup = (SceneObjectGroup)e; | ||
| 426 : | |||
| 427 : | foreach (SceneObjectPart part in oGroup.GetParts()) | ||
| 428 : | { | ||
| 429 : | RexObjectProperties p = LoadObject(part.UUID); | ||
| 430 : | p.ParentObjectID = part.UUID; | ||
| 431 : | p.SetRexEventManager(this); | ||
| 432 : | mikkopa | 339 | if(!RexObjectPropertiesCache.ContainsKey(part.UUID)) |
| 433 : | RexObjectPropertiesCache.Add(part.UUID, p); | ||
| 434 : | tuco | 57 | |
| 435 : | mikkopa | 334 | // Since loaded objects have their properties already set, any initialization that needs to be done should be here. |
| 436 : | if (p.RexCollisionMeshUUID != UUID.Zero) | ||
| 437 : | TriggerOnChangeCollisionMesh(part.UUID); | ||
| 438 : | |||
| 439 : | if (p.RexClassName.Length > 0) | ||
| 440 : | { | ||
| 441 : | part.SetScriptEvents(p.ParentObjectID, (int)scriptEvents.touch_start); | ||
| 442 : | mikkopa | 365 | TriggerOnChangePythonClass(part.UUID); |
| 443 : | mikkopa | 334 | } |
| 444 : | mikkopa | 339 | |
| 445 : | mikkopa | 359 | SendPropertiesToAllUsers(part.UUID, p); |
| 446 : | mikkopa | 334 | } |
| 447 : | } | ||
| 448 : | tuco | 57 | } |
| 449 : | } | ||
| 450 : | } | ||
| 451 : | |||
| 452 : | private RexObjectProperties LoadObject(UUID id) | ||
| 453 : | { | ||
| 454 : | RexObjectProperties robject = m_db.LoadObject(id); | ||
| 455 : | if (robject == null) | ||
| 456 : | { | ||
| 457 : | robject = new RexObjectProperties(); | ||
| 458 : | robject.ParentObjectID = id; | ||
| 459 : | } | ||
| 460 : | return robject; | ||
| 461 : | tuco | 50 | } |
| 462 : | |||
| 463 : | tuco | 57 | public RexObjectProperties GetObject(UUID id) |
| 464 : | { | ||
| 465 : | RexObjectProperties props = RexObjectPropertiesCache[id]; | ||
| 466 : | if (props == null) | ||
| 467 : | { | ||
| 468 : | mikkopa | 137 | //Objects that are not in the scene can't be found from cache. |
| 469 : | //So before we create new properties, we try to find them from db | ||
| 470 : | props = m_db.LoadObject(id); | ||
| 471 : | if (props == null) | ||
| 472 : | { | ||
| 473 : | props = new RexObjectProperties(id, this); | ||
| 474 : | } | ||
| 475 : | tuco | 57 | RexObjectPropertiesCache.Add(id, props); |
| 476 : | } | ||
| 477 : | return props; | ||
| 478 : | } | ||
| 479 : | |||
| 480 : | public List<RexObjectProperties> GetObjects() | ||
| 481 : | { | ||
| 482 : | return RexObjectPropertiesCache.GetAllRexObjectProperties(); | ||
| 483 : | } | ||
| 484 : | |||
| 485 : | public bool DeleteObject(UUID id) | ||
| 486 : | { | ||
| 487 : | if (RexObjectPropertiesCache.ContainsKey(id)) | ||
| 488 : | { | ||
| 489 : | RexObjectPropertiesCache.Remove(id); | ||
| 490 : | tuco | 60 | m_db.RemoveObject(id); |
| 491 : | tuco | 57 | return true; |
| 492 : | } | ||
| 493 : | return false; | ||
| 494 : | } | ||
| 495 : | |||
| 496 : | #endregion | ||
| 497 : | |||
| 498 : | tuco | 80 | |
| 499 : | public void HandleLoadRexLegacyData(string module, string[] args) | ||
| 500 : | { | ||
| 501 : | NHibernateRexLegacyData legacydata = new NHibernateRexLegacyData(); | ||
| 502 : | |||
| 503 : | legacydata.Initialise(args[1]); | ||
| 504 : | if(!legacydata.Inizialized) | ||
| 505 : | { | ||
| 506 : | m_log.Info("[MODREXOBJECTS]: Legacy database failed to initialize."); | ||
| 507 : | return; | ||
| 508 : | } | ||
| 509 : | |||
| 510 : | List<RexLegacyPrimData> rexprimdata = legacydata.LoadAllRexPrimData(); | ||
| 511 : | m_log.Info("[MODREXOBJECTS]: Legacy rexprimdata objects loaded:" + rexprimdata.Count.ToString()); | ||
| 512 : | |||
| 513 : | List<RexLegacyPrimMaterialData> rexprimmaterialdata = legacydata.LoadAllRexPrimMaterialData(); | ||
| 514 : | m_log.Info("[MODREXOBJECTS]: Legacy rexprimmaterialdata objects loaded:" + rexprimmaterialdata.Count.ToString()); | ||
| 515 : | |||
| 516 : | foreach (RexLegacyPrimData prim in rexprimdata) | ||
| 517 : | { | ||
| 518 : | RexObjectProperties p = GetObject(prim.UUID); | ||
| 519 : | p.SetRexPrimDataFromLegacyData(prim); | ||
| 520 : | } | ||
| 521 : | |||
| 522 : | foreach (RexLegacyPrimMaterialData primmat in rexprimmaterialdata) | ||
| 523 : | { | ||
| 524 : | RexObjectProperties p = GetObject(primmat.UUID); | ||
| 525 : | p.RexMaterials.AddMaterial((uint)primmat.MaterialIndex,primmat.MaterialUUID); | ||
| 526 : | } | ||
| 527 : | } | ||
| 528 : | |||
| 529 : | mikkopa | 39 | } |
| 530 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

