Annotation of /branches/os-0.6.9-post-fixes/ModularRex/RexParts/ModrexObjects.cs
Parent Directory
|
Revision Log
Revision 50 -
(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 : | using OpenSim.Region.Environment.Interfaces; | ||
| 11 : | using OpenSim.Region.Environment.Scenes; | ||
| 12 : | using OpenSim.Data.NHibernate; | ||
| 13 : | |||
| 14 : | namespace ModularRex.RexParts | ||
| 15 : | { | ||
| 16 : | public class ModrexObjects : IRegionModule | ||
| 17 : | { | ||
| 18 : | private static readonly ILog m_log = | ||
| 19 : | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
| 20 : | |||
| 21 : | //private Dictionary<UUID,RexObjectProperties> m_objs = new Dictionary<UUID, RexObjectProperties>(); | ||
| 22 : | private List<Scene> m_scenes = new List<Scene>(); | ||
| 23 : | |||
| 24 : | private NHibernateRexObjectData m_db; | ||
| 25 : | private string m_db_connectionstring; | ||
| 26 : | |||
| 27 : | mikkopa | 42 | public event OnChangePythonClassDelegate OnPythonClassChange; |
| 28 : | |||
| 29 : | mikkopa | 39 | public void Initialise(Scene scene, IConfigSource source) |
| 30 : | { | ||
| 31 : | m_scenes.Add(scene); | ||
| 32 : | |||
| 33 : | scene.EventManager.OnClientConnect += EventManager_OnClientConnect; | ||
| 34 : | |||
| 35 : | |||
| 36 : | if (m_db == null) | ||
| 37 : | { | ||
| 38 : | m_db = new NHibernateRexObjectData(); | ||
| 39 : | } | ||
| 40 : | |||
| 41 : | if (source != null) | ||
| 42 : | { | ||
| 43 : | try | ||
| 44 : | { | ||
| 45 : | m_db_connectionstring = source.Configs["realXtend"].GetString("db_connectionstring", "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"); | ||
| 46 : | |||
| 47 : | } | ||
| 48 : | catch (Exception) | ||
| 49 : | { | ||
| 50 : | |||
| 51 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 52 : | } | ||
| 53 : | } | ||
| 54 : | else | ||
| 55 : | { | ||
| 56 : | m_db_connectionstring = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; | ||
| 57 : | } | ||
| 58 : | } | ||
| 59 : | |||
| 60 : | void EventManager_OnClientConnect(OpenSim.Framework.Client.IClientCore client) | ||
| 61 : | { | ||
| 62 : | RexClientView rcv; | ||
| 63 : | if (client.TryGet(out rcv)) | ||
| 64 : | { | ||
| 65 : | rcv.OnRexObjectProperties += rcv_OnRexObjectProperties; | ||
| 66 : | //rcv.OnChatFromClient += rcv_OnChatFromClient; | ||
| 67 : | |||
| 68 : | // Send them the current Scene. | ||
| 69 : | SendAllPropertiesToUser(rcv); | ||
| 70 : | } | ||
| 71 : | } | ||
| 72 : | |||
| 73 : | //void rcv_OnChatFromClient(object sender, OpenSim.Framework.OSChatMessage e) | ||
| 74 : | //{ | ||
| 75 : | // if (e.Message.StartsWith("/rexobj ")) | ||
| 76 : | // { | ||
| 77 : | // string uuid = e.Message.Split(' ')[1]; | ||
| 78 : | // string asset = e.Message.Split(' ')[2]; | ||
| 79 : | |||
| 80 : | // UUID prim = new UUID(uuid); | ||
| 81 : | // UUID assetID = new UUID(asset); | ||
| 82 : | |||
| 83 : | // m_objs[prim].RexMeshUUID = assetID; | ||
| 84 : | // SendPropertiesToAllUsers(prim, m_objs[prim]); | ||
| 85 : | // } | ||
| 86 : | //} | ||
| 87 : | |||
| 88 : | void SendPropertiesToAllUsers(UUID id, RexObjectProperties props) | ||
| 89 : | { | ||
| 90 : | foreach (Scene scene in m_scenes) | ||
| 91 : | { | ||
| 92 : | scene.ForEachScenePresence( | ||
| 93 : | delegate(ScenePresence avatar) | ||
| 94 : | { | ||
| 95 : | RexClientView rex; | ||
| 96 : | if (avatar.ClientView.TryGet(out rex)) | ||
| 97 : | { | ||
| 98 : | rex.SendRexObjectProperties(id,props); | ||
| 99 : | } | ||
| 100 : | }); | ||
| 101 : | } | ||
| 102 : | } | ||
| 103 : | |||
| 104 : | void SendAllPropertiesToUser(RexClientView user) | ||
| 105 : | { | ||
| 106 : | if (m_db.Inizialized) | ||
| 107 : | { | ||
| 108 : | foreach (Scene s in m_scenes) | ||
| 109 : | { | ||
| 110 : | foreach (EntityBase e in s.Entities) | ||
| 111 : | { | ||
| 112 : | RexObjectProperties p = m_db.LoadObject(e.UUID); | ||
| 113 : | if (p != null) | ||
| 114 : | { | ||
| 115 : | user.SendRexObjectProperties(e.UUID, p); | ||
| 116 : | mikkopa | 43 | //p.OnPythonClassChange += PythonClassNameChanged; |
| 117 : | if (p.RexClassName.Length > 0) | ||
| 118 : | { | ||
| 119 : | s.GetSceneObjectPart(e.UUID).SetScriptEvents(e.UUID, (int)scriptEvents.touch_start); | ||
| 120 : | } | ||
| 121 : | mikkopa | 39 | } |
| 122 : | } | ||
| 123 : | } | ||
| 124 : | } | ||
| 125 : | } | ||
| 126 : | |||
| 127 : | mikkopa | 42 | private void PythonClassNameChanged(UUID id) |
| 128 : | { | ||
| 129 : | if (OnPythonClassChange != null) | ||
| 130 : | { | ||
| 131 : | OnPythonClassChange(id); | ||
| 132 : | } | ||
| 133 : | } | ||
| 134 : | mikkopa | 39 | |
| 135 : | void rcv_OnRexObjectProperties(RexClientView sender, UUID id, RexObjectProperties props) | ||
| 136 : | { | ||
| 137 : | tuco | 50 | m_log.Info("[REXOBJS] Received RexObjData for " + id); |
| 138 : | mikkopa | 39 | if (props.ParentObjectID == UUID.Zero) |
| 139 : | props.ParentObjectID = id; | ||
| 140 : | tuco | 50 | |
| 141 : | props.PrintRexPrimdata(); // fixme, debugdata | ||
| 142 : | |||
| 143 : | // Before saving to db, check if values have changed from the previous values. | ||
| 144 : | RexObjectProperties oldprops = Load(id); | ||
| 145 : | |||
| 146 : | mikkopa | 39 | m_db.StoreObject(props); |
| 147 : | tuco | 50 | |
| 148 : | // Compare values | ||
| 149 : | if (oldprops.RexClassName != props.RexClassName) | ||
| 150 : | mikkopa | 43 | PythonClassNameChanged(props.ParentObjectID); |
| 151 : | tuco | 50 | if (oldprops.RexScaleToPrim != props.RexScaleToPrim) |
| 152 : | ScaleToPrimChanged(id); | ||
| 153 : | if (oldprops.RexCollisionMeshUUID != props.RexCollisionMeshUUID) | ||
| 154 : | CollisionMeshChanged(id); | ||
| 155 : | |||
| 156 : | mikkopa | 39 | SendPropertiesToAllUsers(id, props); |
| 157 : | } | ||
| 158 : | |||
| 159 : | public void PostInitialise() | ||
| 160 : | { | ||
| 161 : | lock (m_db) | ||
| 162 : | { | ||
| 163 : | if (!m_db.Inizialized) | ||
| 164 : | { | ||
| 165 : | m_db.Initialise(m_db_connectionstring); | ||
| 166 : | } | ||
| 167 : | } | ||
| 168 : | } | ||
| 169 : | |||
| 170 : | public void Close() | ||
| 171 : | { | ||
| 172 : | ; | ||
| 173 : | } | ||
| 174 : | |||
| 175 : | public string Name | ||
| 176 : | { | ||
| 177 : | get { return "RexObjectsModule"; } | ||
| 178 : | } | ||
| 179 : | |||
| 180 : | public bool IsSharedModule | ||
| 181 : | { | ||
| 182 : | get { return true; } | ||
| 183 : | } | ||
| 184 : | mikkopa | 42 | |
| 185 : | public RexObjectProperties Load(UUID id) | ||
| 186 : | { | ||
| 187 : | RexObjectProperties robject = m_db.LoadObject(id); | ||
| 188 : | if (robject == null) | ||
| 189 : | { | ||
| 190 : | robject = new RexObjectProperties(); | ||
| 191 : | robject.ParentObjectID = id; | ||
| 192 : | } | ||
| 193 : | return robject; | ||
| 194 : | } | ||
| 195 : | |||
| 196 : | public void Save(RexObjectProperties obj) | ||
| 197 : | { | ||
| 198 : | m_db.StoreObject(obj); | ||
| 199 : | } | ||
| 200 : | tuco | 50 | |
| 201 : | private void CollisionMeshChanged(UUID id) | ||
| 202 : | { | ||
| 203 : | // tucofixme, add | ||
| 204 : | //if (!GlobalSettings.Instance.m_3d_collision_models) | ||
| 205 : | // return; | ||
| 206 : | |||
| 207 : | RexObjectProperties p = m_db.LoadObject(id); | ||
| 208 : | if (p == null) | ||
| 209 : | { | ||
| 210 : | m_log.Error("[REXOBJS] CollisionMeshChanged, no RexObjectProperties for id:" + id.ToString()); | ||
| 211 : | return; | ||
| 212 : | } | ||
| 213 : | |||
| 214 : | SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); | ||
| 215 : | if (sop == null) | ||
| 216 : | { | ||
| 217 : | m_log.Error("[REXOBJS] CollisionMeshChanged, no SceneObjectPart for id:" + id.ToString()); | ||
| 218 : | return; | ||
| 219 : | } | ||
| 220 : | |||
| 221 : | if (sop.ParentGroup != null) | ||
| 222 : | { | ||
| 223 : | if (sop.PhysActor != null) | ||
| 224 : | { | ||
| 225 : | /* tucofixme, uncomment later | ||
| 226 : | if (p.RexCollisionMeshUUID != UUID.Zero) | ||
| 227 : | RexUpdateCollisionMesh(id); | ||
| 228 : | else | ||
| 229 : | sop.PhysActor.SetCollisionMesh(null, "", false); | ||
| 230 : | */ | ||
| 231 : | } | ||
| 232 : | } | ||
| 233 : | } | ||
| 234 : | |||
| 235 : | private void ScaleToPrimChanged(UUID id) | ||
| 236 : | { | ||
| 237 : | // tucofixme, add | ||
| 238 : | //if (!GlobalSettings.Instance.m_3d_collision_models) | ||
| 239 : | // return; | ||
| 240 : | |||
| 241 : | RexObjectProperties p = m_db.LoadObject(id); | ||
| 242 : | if(p == null) | ||
| 243 : | { | ||
| 244 : | m_log.Error("[REXOBJS] ScaleToPrimChanged, no RexObjectProperties for id:" + id.ToString()); | ||
| 245 : | return; | ||
| 246 : | } | ||
| 247 : | |||
| 248 : | SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); | ||
| 249 : | if (sop == null) | ||
| 250 : | { | ||
| 251 : | m_log.Error("[REXOBJS] ScaleToPrimChanged, no SceneObjectPart for id:" + id.ToString()); | ||
| 252 : | return; | ||
| 253 : | } | ||
| 254 : | |||
| 255 : | if (sop.ParentGroup != null) | ||
| 256 : | { | ||
| 257 : | if (sop.PhysActor != null) | ||
| 258 : | { | ||
| 259 : | /* tucofixme, uncomment later | ||
| 260 : | sop.PhysActor.SetBoundsScaling(p.RexScaleToPrim); | ||
| 261 : | sop.ParentGroup.Scene.PhysicsScene.AddPhysicsActorTaint(sop.PhysActor); | ||
| 262 : | */ | ||
| 263 : | } | ||
| 264 : | } | ||
| 265 : | |||
| 266 : | } | ||
| 267 : | |||
| 268 : | public void RexUpdateCollisionMesh(UUID id) | ||
| 269 : | { | ||
| 270 : | // tucofixme | ||
| 271 : | //if (!GlobalSettings.Instance.m_3d_collision_models) | ||
| 272 : | // return; | ||
| 273 : | |||
| 274 : | RexObjectProperties p = m_db.LoadObject(id); | ||
| 275 : | if (p == null) | ||
| 276 : | { | ||
| 277 : | m_log.Error("[REXOBJS] RexUpdateCollisionMesh, no RexObjectProperties for id:" + id.ToString()); | ||
| 278 : | return; | ||
| 279 : | } | ||
| 280 : | |||
| 281 : | SceneObjectPart sop = m_scenes[0].GetSceneObjectPart(id); | ||
| 282 : | if (sop == null) | ||
| 283 : | { | ||
| 284 : | m_log.Error("[REXOBJS] RexUpdateCollisionMesh, no SceneObjectPart for id:" + id.ToString()); | ||
| 285 : | return; | ||
| 286 : | } | ||
| 287 : | |||
| 288 : | if (p.RexCollisionMeshUUID != UUID.Zero && sop.PhysActor != null) | ||
| 289 : | { | ||
| 290 : | /* tucofixme, uncomment later | ||
| 291 : | AssetBase tempmodel = sop.ParentGroup.Scene.AssetCache.GetAsset(p.RexCollisionMeshUUID,false); | ||
| 292 : | if (tempmodel != null) | ||
| 293 : | sop.PhysActor.SetCollisionMesh(tempmodel.Data, tempmodel.Name, p.RexScaleToPrim); | ||
| 294 : | */ | ||
| 295 : | } | ||
| 296 : | } | ||
| 297 : | |||
| 298 : | |||
| 299 : | mikkopa | 39 | } |
| 300 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

