aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/DynamicTextureModule.cs136
1 files changed, 136 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs b/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
new file mode 100644
index 0000000..6edebe7
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/DynamicTextureModule.cs
@@ -0,0 +1,136 @@
1using System.Text;
2using System.Net;
3using System.Net.Sockets;
4using System.Threading;
5using System.IO;
6using System.Collections.Generic;
7using libsecondlife;
8using OpenJPEGNet;
9using OpenSim.Region.Environment.Scenes;
10using OpenSim.Region.Environment.Interfaces;
11using OpenSim.Framework.Interfaces;
12using OpenSim.Framework.Utilities;
13using OpenSim.Framework.Console;
14using OpenSim.Framework.Types;
15
16namespace OpenSim.Region.Environment.Modules
17{
18 public class DynamicTextureModule :IRegionModule, IDynamicTextureManager
19 {
20 private Dictionary<LLUUID, Scene> RegisteredScenes = new Dictionary<LLUUID, Scene>();
21 private Dictionary<string, IDynamicTextureRender> RenderPlugins= new Dictionary<string, IDynamicTextureRender>();
22 private Dictionary<LLUUID, DynamicTextureUpdater> Updaters = new Dictionary<LLUUID, DynamicTextureUpdater>();
23
24 public void Initialise(Scene scene)
25 {
26 if (!RegisteredScenes.ContainsKey(scene.RegionInfo.SimUUID))
27 {
28 RegisteredScenes.Add(scene.RegionInfo.SimUUID, scene);
29 scene.RegisterModuleInterface<IDynamicTextureManager>(this);
30 }
31 }
32
33 public void PostInitialise()
34 {
35
36 }
37
38 public void CloseDown()
39 {
40 }
41
42 public string GetName()
43 {
44 return "DynamicTextureModule";
45 }
46
47 public bool IsSharedModule()
48 {
49 return true;
50 }
51
52 public void RegisterRender(string handleType, IDynamicTextureRender render)
53 {
54 if (!RenderPlugins.ContainsKey(handleType))
55 {
56 RenderPlugins.Add(handleType, render);
57 }
58 }
59
60 public void ReturnData(LLUUID id, byte[] data)
61 {
62 if (Updaters.ContainsKey(id))
63 {
64 DynamicTextureUpdater updater = Updaters[id];
65 if (RegisteredScenes.ContainsKey(updater.SimUUID))
66 {
67 Scene scene = RegisteredScenes[updater.SimUUID];
68 updater.DataReceived(data, scene);
69 }
70 }
71 }
72
73 public LLUUID AddDynamicTextureURL(LLUUID simID, LLUUID primID, string contentType, string url, string extraParams, int updateTimer)
74 {
75 System.Console.WriteLine("dynamic texture being created " + url + " of type " + contentType);
76 if (this.RenderPlugins.ContainsKey(contentType))
77 {
78 DynamicTextureUpdater updater = new DynamicTextureUpdater();
79 updater.SimUUID = simID;
80 updater.PrimID = primID;
81 updater.ContentType = contentType;
82 updater.Url = url;
83 updater.UpdateTimer = updateTimer;
84 updater.UpdaterID = LLUUID.Random();
85 updater.Params = extraParams;
86
87 if (!this.Updaters.ContainsKey(updater.UpdaterID))
88 {
89 Updaters.Add(updater.UpdaterID, updater);
90 }
91
92 RenderPlugins[contentType].AsyncConvertUrl(updater.UpdaterID, url, extraParams);
93 return updater.UpdaterID;
94 }
95 return LLUUID.Zero;
96 }
97
98 public class DynamicTextureUpdater
99 {
100 public LLUUID SimUUID;
101 public LLUUID UpdaterID;
102 public string ContentType;
103 public string Url;
104 public Stream StreamData;
105 public LLUUID PrimID;
106 public int UpdateTimer;
107 public LLUUID LastAssetID;
108 public string Params;
109
110 public DynamicTextureUpdater()
111 {
112 LastAssetID = LLUUID.Zero;
113 UpdateTimer = 0;
114 StreamData = null;
115 }
116
117 public void DataReceived(byte[] data, Scene scene)
118 {
119 //TODO delete the last asset(data), if it was a dynamic texture
120
121 AssetBase asset = new AssetBase();
122 asset.FullID = LLUUID.Random();
123 asset.Data = data;
124 asset.Name = "DynamicImage" + Util.RandomClass.Next(1, 10000);
125 asset.Type = 0;
126 scene.commsManager.AssetCache.AddAsset(asset);
127
128 this.LastAssetID = asset.FullID;
129
130 SceneObjectPart part = scene.GetSceneObjectPart(PrimID);
131 part.Shape.TextureEntry = new LLObject.TextureEntry(asset.FullID).ToBytes();
132 part.ScheduleFullUpdate();
133 }
134 }
135 }
136}