Annotation of /branches/taiga-0.1/ModularRex/RexParts/ModrexObjects.cs
Parent Directory
|
Revision Log
Revision 63 -
(view)
(download)
Original Path: trunk/ModularRex/RexParts/ModrexObjects.cs
| 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 : | mikkopa | 39 | using OpenSim.Data.NHibernate; |
| 13 : | tuco | 53 | using OpenSim.Framework; |
| 14 : | mikkopa | 39 | |
| 15 : | namespace ModularRex.RexParts | ||
| 16 : | { | ||
| 17 : | tuco | 57 | public class ModrexObjects : IRegionModule, IRexObjectPropertiesEventManager |
| 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 : | scene.EventManager.OnClientConnect += EventManager_OnClientConnect; | ||
| 36 : | tuco | 59 | scene.m_sceneGraph.OnObjectDuplicate += SceneGraph_OnObjectDuplicate; |
| 37 : | tuco | 60 | scene.m_sceneGraph.OnObjectRemove += SceneGraph_OnObjectRemove; |
| 38 : | mikkopa | 39 | |
| 39 : | |||
| 40 : | if (m_db == null) | ||
| 41 : | { | ||
| 42 : | m_db = new NHibernateRexObjectData(); | ||
| 43 : | } | ||
| 44 : | |||
| 45 : | if (source != null) | ||
| 46 : | { | ||
| 47 : | try | ||
| 48 : | { | ||
| 49 : | m_db_connectionstring = source.Configs["realXtend"].GetString("db_connectionstring", "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"); | ||
| 50 : | |||
| 51 : | } | ||
| 52 : | catch (Exception) | ||
| 53 : | { | ||
| 54 : | |||
| 55 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 56 : | } | ||
| 57 : | } | ||
| 58 : | else | ||
| 59 : | { | ||
| 60 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 61 : | } | ||
| 62 : | } | ||
| 63 : | |||
| 64 : | void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) | ||
| 65 : | { | ||
| 66 : | RexClientView rcv; | ||
| 67 : | if (client.TryGet(out rcv)) | ||
| 68 : | { | ||
| 69 : | rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; | ||
| 70 : | //rcv.OnChatFromClient += rcv_OnChatFromClient; | ||
| 71 : | |||
| 72 : | // Send them the current Scene. | ||
| 73 : | SendAllPropertiesToUser(rcv); | ||
| 74 : | } | ||
| 75 : | } | ||
| 76 : | |||
| 77 : | tuco | 59 | void SceneGraph_OnObjectDuplicate(EntityBase original, EntityBase clone) |
| 78 : | { | ||
| 79 : | RexObjectProperties origprops = GetObject(original.UUID); | ||
| 80 : | RexObjectProperties cloneprops = GetObject(clone.UUID); | ||
| 81 : | |||
| 82 : | cloneprops.SetRexPrimDataFromObject(origprops); | ||
| 83 : | } | ||
| 84 : | |||
| 85 : | tuco | 60 | void SceneGraph_OnObjectRemove(EntityBase obj) |
| 86 : | { | ||
| 87 : | DeleteObject(obj.UUID); | ||
| 88 : | } | ||
| 89 : | |||
| 90 : | |||
| 91 : | mikkopa | 39 | //void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) |
| 92 : | //{ | ||
| 93 : | // if (e.Message.StartsWith("/rexobj ")) | ||
| 94 : | // { | ||
| 95 : | // string uuid = e.Message.Split(' ')[1]; | ||
| 96 : | // string asset = e.Message.Split(' ')[2]; | ||
| 97 : | |||
| 98 : | // UUID prim = new UUID(uuid); | ||
| 99 : | // UUID assetID = new UUID(asset); | ||
| 100 : | |||
| 101 : | // m_objs[prim].RexMeshUUID = assetID; | ||
| 102 : | // SendPropertiesToAllUsers(prim, m_objs[prim]); | ||
| 103 : | // } | ||
| 104 : | //} | ||
| 105 : | |||
| 106 : | void SendPropertiesToAllUsers(UUID id, RexObjectProperties props) | ||
| 107 : | { | ||
| 108 : | foreach (Scene scene in m_scenes) | ||
| 109 : | { | ||
| 110 : | scene.ForEachScenePresence( | ||
| 111 : | delegate(ScenePresence avatar) | ||
| 112 : | { | ||
| 113 : | RexClientView rex; | ||
| 114 : | if (avatar.ClientView.TryGet(out rex)) | ||
| 115 : | { | ||
| 116 : | rex.SendRexObjectProperties(id,props); | ||
| 117 : | } | ||
| 118 : | }); | ||
| 119 : | } | ||
| 120 : | } | ||
| 121 : | |||
| 122 : | void SendAllPropertiesToUser(RexClientView user) | ||
| 123 : | { | ||
| 124 : | tuco | 57 | foreach (RexObjectProperties p in GetObjects()) |
| 125 : | mikkopa | 39 | { |
| 126 : | tuco | 57 | user.SendRexObjectProperties(p.ParentObjectID, p); |
| 127 : | mikkopa | 39 | } |
| 128 : | } | ||
| 129 : | |||
| 130 : | void rcv_OnRexObjectProperties(RexClientView sender, UUID id, RexObjectProperties props) | ||
| 131 : | { | ||
| 132 : | tuco | 50 | m_log.Info("[REXOBJS] Received RexObjData for " + id); |
| 133 : | mikkopa | 39 | if (props.ParentObjectID == UUID.Zero) |
| 134 : | props.ParentObjectID = id; | ||
| 135 : | tuco | 50 | |
| 136 : | tuco | 57 | // debugdata props.PrintRexPrimdata(); |
| 137 : | |||
| 138 : | RexObjectProperties currentprops = GetObject(id); | ||
| 139 : | currentprops.SetRexPrimDataFromObject(props); | ||
| 140 : | mikkopa | 39 | } |
| 141 : | |||
| 142 : | public void PostInitialise() | ||
| 143 : | { | ||
| 144 : | lock (m_db) | ||
| 145 : | { | ||
| 146 : | if (!m_db.Inizialized) | ||
| 147 : | { | ||
| 148 : | m_db.Initialise(m_db_connectionstring); | ||
| 149 : | } | ||
| 150 : | } | ||
| 151 : | tuco | 57 | LoadRexObjectPropertiesToCache(); |
| 152 : | mikkopa | 39 | } |
| 153 : | |||
| 154 : | public void Close() | ||
| 155 : | { | ||
| 156 : | ; | ||
| 157 : | } | ||
| 158 : | |||
| 159 : | public string Name | ||
| 160 : | { | ||
| 161 : | get { return "RexObjectsModule"; } | ||
| 162 : | } | ||
| 163 : | |||
| 164 : | public bool IsSharedModule | ||
| 165 : | { | ||
| 166 : | get { return true; } | ||
| 167 : | } | ||
| 168 : | mikkopa | 42 | |
| 169 : | tuco | 57 | |
| 170 : | |||
| 171 : | #region Trigger/handle rexobjectproperties events | ||
| 172 : | public void TriggerOnChangePythonClass(UUID id) | ||
| 173 : | mikkopa | 42 | { |
| 174 : | tuco | 57 | if (OnPythonClassChange != null) |
| 175 : | OnPythonClassChange(id); | ||
| 176 : | mikkopa | 42 | } |
| 177 : | |||
| 178 : | tuco | 57 | public void TriggerOnChangeCollisionMesh(UUID id) |
| 179 : | mikkopa | 42 | { |
| 180 : | tuco | 50 | // tucofixme, add |
| 181 : | //if (!GlobalSettings.Instance.m_3d_collision_models) | ||
| 182 : | // return; | ||
| 183 : | |||
| 184 : | tuco | 57 | RexObjectProperties p = GetObject(id); |
| 185 : | tuco | 50 | SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
| 186 : | if (sop == null) | ||
| 187 : | { | ||
| 188 : | tuco | 57 | m_log.Error("[REXOBJS] TriggerOnChangeCollisionMesh, no SceneObjectPart for id:" + id.ToString()); |
| 189 : | tuco | 50 | return; |
| 190 : | } | ||
| 191 : | tuco | 57 | |
| 192 : | if (sop.ParentGroup != null && sop.PhysActor != null) | ||
| 193 : | tuco | 50 | { |
| 194 : | tuco | 57 | if (p.RexCollisionMeshUUID != UUID.Zero) |
| 195 : | RexUpdateCollisionMesh(id); | ||
| 196 : | else | ||
| 197 : | mikkopa | 63 | { |
| 198 : | //Commented out for now since does not exist in current OpenSim | ||
| 199 : | //sop.PhysActor.SetCollisionMesh(null, "", false); | ||
| 200 : | } | ||
| 201 : | tuco | 57 | } |
| 202 : | tuco | 50 | } |
| 203 : | |||
| 204 : | tuco | 57 | public void TriggerOnChangeScaleToPrim(UUID id) |
| 205 : | tuco | 50 | { |
| 206 : | // tucofixme, add | ||
| 207 : | //if (!GlobalSettings.Instance.m_3d_collision_models) | ||
| 208 : | // return; | ||
| 209 : | tuco | 57 | |
| 210 : | RexObjectProperties p = GetObject(id); | ||
| 211 : | tuco | 50 | SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
| 212 : | if (sop == null) | ||
| 213 : | { | ||
| 214 : | tuco | 57 | m_log.Error("[REXOBJS] TriggerOnChangeScaleToPrim, no SceneObjectPart for id:" + id.ToString()); |
| 215 : | return; | ||
| 216 : | tuco | 50 | } |
| 217 : | |||
| 218 : | tuco | 57 | if (sop.ParentGroup != null && sop.PhysActor != null) |
| 219 : | tuco | 50 | { |
| 220 : | mikkopa | 63 | //Commented out for now since does not exist in current OpenSim |
| 221 : | //sop.PhysActor.SetBoundsScaling(p.RexScaleToPrim); | ||
| 222 : | tuco | 57 | sop.ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(sop.PhysActor); |
| 223 : | tuco | 50 | } |
| 224 : | } | ||
| 225 : | |||
| 226 : | tuco | 57 | public void TriggerOnChangeRexObjectProperties(UUID id) |
| 227 : | { | ||
| 228 : | RexObjectProperties props = GetObject(id); | ||
| 229 : | |||
| 230 : | m_db.StoreObject(props); | ||
| 231 : | SendPropertiesToAllUsers(id,props); | ||
| 232 : | } | ||
| 233 : | |||
| 234 : | public void TriggerOnChangeRexObjectMetaData(UUID id) | ||
| 235 : | { | ||
| 236 : | RexObjectProperties props = GetObject(id); | ||
| 237 : | |||
| 238 : | m_db.StoreObject(props); | ||
| 239 : | // tucofixme, send metadata to all users | ||
| 240 : | } | ||
| 241 : | |||
| 242 : | |||
| 243 : | |||
| 244 : | tuco | 50 | public void RexUpdateCollisionMesh(UUID id) |
| 245 : | { | ||
| 246 : | tuco | 57 | // tucofixme, add |
| 247 : | tuco | 50 | //if (!GlobalSettings.Instance.m_3d_collision_models) |
| 248 : | // return; | ||
| 249 : | |||
| 250 : | tuco | 57 | RexObjectProperties p = GetObject(id); |
| 251 : | tuco | 50 | SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); |
| 252 : | if (sop == null) | ||
| 253 : | { | ||
| 254 : | m_log.Error("[REXOBJS] RexUpdateCollisionMesh, no SceneObjectPart for id:" + id.ToString()); | ||
| 255 : | return; | ||
| 256 : | tuco | 57 | } |
| 257 : | |||
| 258 : | tuco | 50 | if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor != null) |
| 259 : | { | ||
| 260 : | tuco | 57 | AssetBase tempmodel = sop.ParentGroup.Scene.AssetCache.GetAsset(p.RexCollisionMeshUUID, false); |
| 261 : | tuco | 50 | if (tempmodel != null) |
| 262 : | mikkopa | 63 | { |
| 263 : | //Commented out for now since does not exist in current OpenSim | ||
| 264 : | //sop.PhysActor.SetCollisionMesh(tempmodel.Data, tempmodel.Metadata.Name, p.RexScaleToPrim); | ||
| 265 : | } | ||
| 266 : | tuco | 50 | } |
| 267 : | tuco | 57 | } |
| 268 : | #endregion | ||
| 269 : | |||
| 270 : | |||
| 271 : | #region RexObjectProperties Cache | ||
| 272 : | |||
| 273 : | private void LoadRexObjectPropertiesToCache() | ||
| 274 : | { | ||
| 275 : | if (!m_db.Inizialized) | ||
| 276 : | { | ||
| 277 : | m_log.ErrorFormat("LoadRexObjectPropertiesToCache failed, db not initialized"); | ||
| 278 : | return; | ||
| 279 : | } | ||
| 280 : | |||
| 281 : | foreach (Scene s in m_scenes) | ||
| 282 : | { | ||
| 283 : | foreach (EntityBase e in s.Entities) | ||
| 284 : | { | ||
| 285 : | RexObjectProperties p = LoadObject(e.UUID); | ||
| 286 : | p.ParentObjectID = e.UUID; | ||
| 287 : | p.SetRexEventManager(this); | ||
| 288 : | RexObjectPropertiesCache.Add(e.UUID,p); | ||
| 289 : | |||
| 290 : | // Since loaded objects have their properties already set, any initialization that needs to be done should be here. | ||
| 291 : | if(p.RexCollisionMeshUUID != UUID.Zero) | ||
| 292 : | TriggerOnChangeCollisionMesh(e.UUID); | ||
| 293 : | |||
| 294 : | if (p.RexClassName.Length > 0) | ||
| 295 : | { | ||
| 296 : | SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(p.ParentObjectID); | ||
| 297 : | if (sop != null) | ||
| 298 : | sop.SetScriptEvents(p.ParentObjectID, (int)scriptEvents.touch_start); | ||
| 299 : | } | ||
| 300 : | } | ||
| 301 : | } | ||
| 302 : | } | ||
| 303 : | |||
| 304 : | private RexObjectProperties LoadObject(UUID id) | ||
| 305 : | { | ||
| 306 : | RexObjectProperties robject = m_db.LoadObject(id); | ||
| 307 : | if (robject == null) | ||
| 308 : | { | ||
| 309 : | robject = new RexObjectProperties(); | ||
| 310 : | robject.ParentObjectID = id; | ||
| 311 : | } | ||
| 312 : | return robject; | ||
| 313 : | tuco | 50 | } |
| 314 : | |||
| 315 : | tuco | 57 | public RexObjectProperties GetObject(UUID id) |
| 316 : | { | ||
| 317 : | RexObjectProperties props = RexObjectPropertiesCache[id]; | ||
| 318 : | if (props == null) | ||
| 319 : | { | ||
| 320 : | props = new RexObjectProperties(id, this); | ||
| 321 : | RexObjectPropertiesCache.Add(id, props); | ||
| 322 : | } | ||
| 323 : | return props; | ||
| 324 : | } | ||
| 325 : | |||
| 326 : | public List<RexObjectProperties> GetObjects() | ||
| 327 : | { | ||
| 328 : | return RexObjectPropertiesCache.GetAllRexObjectProperties(); | ||
| 329 : | } | ||
| 330 : | |||
| 331 : | public bool DeleteObject(UUID id) | ||
| 332 : | { | ||
| 333 : | if (RexObjectPropertiesCache.ContainsKey(id)) | ||
| 334 : | { | ||
| 335 : | RexObjectPropertiesCache.Remove(id); | ||
| 336 : | tuco | 60 | m_db.RemoveObject(id); |
| 337 : | tuco | 57 | return true; |
| 338 : | } | ||
| 339 : | return false; | ||
| 340 : | } | ||
| 341 : | |||
| 342 : | |||
| 343 : | #endregion | ||
| 344 : | |||
| 345 : | mikkopa | 39 | } |
| 346 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

