diff options
author | Justin Clark-Casey (justincc) | 2013-06-27 23:42:35 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2013-06-27 23:42:35 +0100 |
commit | 149487ea0f74a46a70c98b3a31259b667f4d29b2 (patch) | |
tree | 19524863c98a1d5b229cfda790913da1588d372b | |
parent | Make the concept of namespaces explicit in dynamic attributes (diff) | |
download | opensim-SC_OLD-149487ea0f74a46a70c98b3a31259b667f4d29b2.zip opensim-SC_OLD-149487ea0f74a46a70c98b3a31259b667f4d29b2.tar.gz opensim-SC_OLD-149487ea0f74a46a70c98b3a31259b667f4d29b2.tar.bz2 opensim-SC_OLD-149487ea0f74a46a70c98b3a31259b667f4d29b2.tar.xz |
refactor: Move code for gathering textures referenced by materials into MaterialsDemoModule from UuidGatherer
This code is now triggered via EventManager.OnGatherUuids which modules can subscribe to.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Framework/Scenes/EventManager.cs | 31 | ||||
-rw-r--r-- | OpenSim/Region/Framework/Scenes/UuidGatherer.cs | 69 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs | 72 |
3 files changed, 103 insertions, 69 deletions
diff --git a/OpenSim/Region/Framework/Scenes/EventManager.cs b/OpenSim/Region/Framework/Scenes/EventManager.cs index a246319..720bfa9 100644 --- a/OpenSim/Region/Framework/Scenes/EventManager.cs +++ b/OpenSim/Region/Framework/Scenes/EventManager.cs | |||
@@ -1021,6 +1021,16 @@ namespace OpenSim.Region.Framework.Scenes | |||
1021 | /// </remarks> | 1021 | /// </remarks> |
1022 | public event TeleportFail OnTeleportFail; | 1022 | public event TeleportFail OnTeleportFail; |
1023 | 1023 | ||
1024 | public delegate void GatherUuids(SceneObjectPart sop, IDictionary<UUID, AssetType> assetUuids); | ||
1025 | |||
1026 | /// <summary> | ||
1027 | /// Triggered when UUIDs referenced by a scene object are being gathered for archiving, hg transfer, etc. | ||
1028 | /// </summary> | ||
1029 | /// <remarks> | ||
1030 | /// The listener should add references to the IDictionary<UUID, AssetType> as appropriate. | ||
1031 | /// </remarks> | ||
1032 | public event GatherUuids OnGatherUuids; | ||
1033 | |||
1024 | public class MoneyTransferArgs : EventArgs | 1034 | public class MoneyTransferArgs : EventArgs |
1025 | { | 1035 | { |
1026 | public UUID sender; | 1036 | public UUID sender; |
@@ -3237,5 +3247,26 @@ namespace OpenSim.Region.Framework.Scenes | |||
3237 | } | 3247 | } |
3238 | } | 3248 | } |
3239 | } | 3249 | } |
3250 | |||
3251 | public void TriggerGatherUuids(SceneObjectPart sop, IDictionary<UUID, AssetType> assetUuids) | ||
3252 | { | ||
3253 | GatherUuids handler = OnGatherUuids; | ||
3254 | |||
3255 | if (handler != null) | ||
3256 | { | ||
3257 | foreach (GatherUuids d in handler.GetInvocationList()) | ||
3258 | { | ||
3259 | try | ||
3260 | { | ||
3261 | d(sop, assetUuids); | ||
3262 | } | ||
3263 | catch (Exception e) | ||
3264 | { | ||
3265 | m_log.ErrorFormat("[EVENT MANAGER]: Delegate for TriggerUuidGather failed - continuing {0} - {1}", | ||
3266 | e.Message, e.StackTrace); | ||
3267 | } | ||
3268 | } | ||
3269 | } | ||
3270 | } | ||
3240 | } | 3271 | } |
3241 | } | 3272 | } |
diff --git a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs index 586b59d..3492813 100644 --- a/OpenSim/Region/Framework/Scenes/UuidGatherer.cs +++ b/OpenSim/Region/Framework/Scenes/UuidGatherer.cs | |||
@@ -186,8 +186,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
186 | GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids); | 186 | GatherAssetUuids(tii.AssetID, (AssetType)tii.Type, assetUuids); |
187 | } | 187 | } |
188 | 188 | ||
189 | // get any texture UUIDs used for materials such as normal and specular maps | 189 | part.ParentGroup.Scene.EventManager.TriggerGatherUuids(part, assetUuids); |
190 | GatherMaterialsUuids(part, assetUuids); | ||
191 | } | 190 | } |
192 | catch (Exception e) | 191 | catch (Exception e) |
193 | { | 192 | { |
@@ -211,71 +210,7 @@ namespace OpenSim.Region.Framework.Scenes | |||
211 | // Monitor.Pulse(this); | 210 | // Monitor.Pulse(this); |
212 | // } | 211 | // } |
213 | // } | 212 | // } |
214 | 213 | ||
215 | /// <summary> | ||
216 | /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps | ||
217 | /// </summary> | ||
218 | /// <param name="part"></param> | ||
219 | /// <param name="assetUuids"></param> | ||
220 | public void GatherMaterialsUuids(SceneObjectPart part, IDictionary<UUID, AssetType> assetUuids) | ||
221 | { | ||
222 | // scan thru the dynAttrs map of this part for any textures used as materials | ||
223 | OSD osdMaterials = null; | ||
224 | |||
225 | lock (part.DynAttrs) | ||
226 | { | ||
227 | if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) | ||
228 | { | ||
229 | OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); | ||
230 | materialsStore.TryGetValue("Materials", out osdMaterials); | ||
231 | } | ||
232 | |||
233 | if (osdMaterials != null) | ||
234 | { | ||
235 | //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); | ||
236 | |||
237 | if (osdMaterials is OSDArray) | ||
238 | { | ||
239 | OSDArray matsArr = osdMaterials as OSDArray; | ||
240 | foreach (OSDMap matMap in matsArr) | ||
241 | { | ||
242 | try | ||
243 | { | ||
244 | if (matMap.ContainsKey("Material")) | ||
245 | { | ||
246 | OSDMap mat = matMap["Material"] as OSDMap; | ||
247 | if (mat.ContainsKey("NormMap")) | ||
248 | { | ||
249 | UUID normalMapId = mat["NormMap"].AsUUID(); | ||
250 | if (normalMapId != UUID.Zero) | ||
251 | { | ||
252 | assetUuids[normalMapId] = AssetType.Texture; | ||
253 | //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); | ||
254 | } | ||
255 | } | ||
256 | if (mat.ContainsKey("SpecMap")) | ||
257 | { | ||
258 | UUID specularMapId = mat["SpecMap"].AsUUID(); | ||
259 | if (specularMapId != UUID.Zero) | ||
260 | { | ||
261 | assetUuids[specularMapId] = AssetType.Texture; | ||
262 | //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | |||
267 | } | ||
268 | catch (Exception e) | ||
269 | { | ||
270 | m_log.Warn("[UUID Gatherer]: exception getting materials: " + e.Message); | ||
271 | } | ||
272 | } | ||
273 | } | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | |||
278 | |||
279 | /// <summary> | 214 | /// <summary> |
280 | /// Get an asset synchronously, potentially using an asynchronous callback. If the | 215 | /// Get an asset synchronously, potentially using an asynchronous callback. If the |
281 | /// asynchronous callback is used, we will wait for it to complete. | 216 | /// asynchronous callback is used, we will wait for it to complete. |
diff --git a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs index 5b15a73..e7b8928 100644 --- a/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs +++ b/OpenSim/Region/OptionalModules/Materials/MaterialsDemoModule.cs | |||
@@ -121,9 +121,11 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
121 | return; | 121 | return; |
122 | 122 | ||
123 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} ADDED", scene.RegionInfo.RegionName); | 123 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} ADDED", scene.RegionInfo.RegionName); |
124 | |||
124 | m_scene = scene; | 125 | m_scene = scene; |
125 | m_scene.EventManager.OnRegisterCaps += new EventManager.RegisterCapsEvent(OnRegisterCaps); | 126 | m_scene.EventManager.OnRegisterCaps += OnRegisterCaps; |
126 | m_scene.EventManager.OnObjectAddedToScene += new Action<SceneObjectGroup>(EventManager_OnObjectAddedToScene); | 127 | m_scene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene; |
128 | m_scene.EventManager.OnGatherUuids += GatherMaterialsUuids; | ||
127 | } | 129 | } |
128 | 130 | ||
129 | void EventManager_OnObjectAddedToScene(SceneObjectGroup obj) | 131 | void EventManager_OnObjectAddedToScene(SceneObjectGroup obj) |
@@ -157,6 +159,10 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
157 | if (!m_enabled) | 159 | if (!m_enabled) |
158 | return; | 160 | return; |
159 | 161 | ||
162 | m_scene.EventManager.OnRegisterCaps -= OnRegisterCaps; | ||
163 | m_scene.EventManager.OnObjectAddedToScene -= EventManager_OnObjectAddedToScene; | ||
164 | m_scene.EventManager.OnGatherUuids -= GatherMaterialsUuids; | ||
165 | |||
160 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | 166 | m_log.DebugFormat("[MaterialsDemoModule]: REGION {0} REMOVED", scene.RegionInfo.RegionName); |
161 | } | 167 | } |
162 | 168 | ||
@@ -569,5 +575,67 @@ namespace OpenSim.Region.OptionalModules.MaterialsDemoModule | |||
569 | output.Flush(); | 575 | output.Flush(); |
570 | } | 576 | } |
571 | 577 | ||
578 | /// <summary> | ||
579 | /// Gather all of the texture asset UUIDs used to reference "Materials" such as normal and specular maps | ||
580 | /// </summary> | ||
581 | /// <param name="part"></param> | ||
582 | /// <param name="assetUuids"></param> | ||
583 | private void GatherMaterialsUuids(SceneObjectPart part, IDictionary<UUID, AssetType> assetUuids) | ||
584 | { | ||
585 | // scan thru the dynAttrs map of this part for any textures used as materials | ||
586 | OSD osdMaterials = null; | ||
587 | |||
588 | lock (part.DynAttrs) | ||
589 | { | ||
590 | if (part.DynAttrs.ContainsStore("OpenSim", "Materials")) | ||
591 | { | ||
592 | OSDMap materialsStore = part.DynAttrs.GetStore("OpenSim", "Materials"); | ||
593 | materialsStore.TryGetValue("Materials", out osdMaterials); | ||
594 | } | ||
595 | |||
596 | if (osdMaterials != null) | ||
597 | { | ||
598 | //m_log.Info("[UUID Gatherer]: found Materials: " + OSDParser.SerializeJsonString(osd)); | ||
599 | |||
600 | if (osdMaterials is OSDArray) | ||
601 | { | ||
602 | OSDArray matsArr = osdMaterials as OSDArray; | ||
603 | foreach (OSDMap matMap in matsArr) | ||
604 | { | ||
605 | try | ||
606 | { | ||
607 | if (matMap.ContainsKey("Material")) | ||
608 | { | ||
609 | OSDMap mat = matMap["Material"] as OSDMap; | ||
610 | if (mat.ContainsKey("NormMap")) | ||
611 | { | ||
612 | UUID normalMapId = mat["NormMap"].AsUUID(); | ||
613 | if (normalMapId != UUID.Zero) | ||
614 | { | ||
615 | assetUuids[normalMapId] = AssetType.Texture; | ||
616 | //m_log.Info("[UUID Gatherer]: found normal map ID: " + normalMapId.ToString()); | ||
617 | } | ||
618 | } | ||
619 | if (mat.ContainsKey("SpecMap")) | ||
620 | { | ||
621 | UUID specularMapId = mat["SpecMap"].AsUUID(); | ||
622 | if (specularMapId != UUID.Zero) | ||
623 | { | ||
624 | assetUuids[specularMapId] = AssetType.Texture; | ||
625 | //m_log.Info("[UUID Gatherer]: found specular map ID: " + specularMapId.ToString()); | ||
626 | } | ||
627 | } | ||
628 | } | ||
629 | |||
630 | } | ||
631 | catch (Exception e) | ||
632 | { | ||
633 | m_log.Warn("[MaterialsDemoModule]: exception getting materials: " + e.Message); | ||
634 | } | ||
635 | } | ||
636 | } | ||
637 | } | ||
638 | } | ||
639 | } | ||
572 | } | 640 | } |
573 | } \ No newline at end of file | 641 | } \ No newline at end of file |