diff options
author | cw | 2007-01-31 22:09:20 +0000 |
---|---|---|
committer | cw | 2007-01-31 22:09:20 +0000 |
commit | a82950672860eedeaa23da75421c74e094b5c0a4 (patch) | |
tree | 6901851f8e1de03d5eadfbe05e03563126b879a2 /Texture_manager.cs | |
download | opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.zip opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.gz opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.bz2 opensim-SC_OLD-a82950672860eedeaa23da75421c74e094b5c0a4.tar.xz |
Making trunk; applying appropriate license to each file
Diffstat (limited to 'Texture_manager.cs')
-rw-r--r-- | Texture_manager.cs | 219 |
1 files changed, 219 insertions, 0 deletions
diff --git a/Texture_manager.cs b/Texture_manager.cs new file mode 100644 index 0000000..990557e --- /dev/null +++ b/Texture_manager.cs | |||
@@ -0,0 +1,219 @@ | |||
1 | /* | ||
2 | Copyright (c) 2007 Michael Wright | ||
3 | |||
4 | * Copyright (c) <year>, <copyright holder> | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * * Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * * Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in the | ||
13 | * documentation and/or other materials provided with the distribution. | ||
14 | * * Neither the name of the <organization> nor the | ||
15 | * names of its contributors may be used to endorse or promote products | ||
16 | * derived from this software without specific prior written permission. | ||
17 | * | ||
18 | * THIS SOFTWARE IS PROVIDED BY <copyright holder> ``AS IS'' AND ANY | ||
19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
21 | * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY | ||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
28 | */ | ||
29 | |||
30 | using System; | ||
31 | using System.Collections.Generic; | ||
32 | using libsecondlife; | ||
33 | using System.Collections; | ||
34 | using libsecondlife.Packets; | ||
35 | using libsecondlife.AssetSystem; | ||
36 | using System.IO; | ||
37 | |||
38 | |||
39 | namespace Second_server | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// Description of Texture_manager. | ||
43 | /// </summary> | ||
44 | public class Texture_manager | ||
45 | { | ||
46 | public Dictionary<libsecondlife.LLUUID,Texture_image> textures; | ||
47 | public ArrayList requests=new ArrayList(); //should change to a generic | ||
48 | public ArrayList uploads=new ArrayList(); | ||
49 | private Server server; | ||
50 | |||
51 | public Texture_manager(Server serve) | ||
52 | { | ||
53 | server=serve; | ||
54 | textures=new Dictionary<libsecondlife.LLUUID,Texture_image> (); | ||
55 | this.initialise(); | ||
56 | } | ||
57 | |||
58 | public void add_request(User_Agent_info user, LLUUID image_id) | ||
59 | { | ||
60 | |||
61 | if(!this.textures.ContainsKey(image_id)) | ||
62 | { | ||
63 | //not found image so send back image not in data base message | ||
64 | ImageNotInDatabasePacket im_not=new ImageNotInDatabasePacket(); | ||
65 | im_not.ImageID.ID=image_id; | ||
66 | server.SendPacket(im_not,true,user); | ||
67 | return; | ||
68 | } | ||
69 | Texture_image imag=this.textures[image_id]; | ||
70 | Texture_request req=new Texture_request(); | ||
71 | req.req_user=user; | ||
72 | req.req_image=image_id; | ||
73 | req.image_info=imag; | ||
74 | |||
75 | if(imag.data.LongLength>1000) //should be bigger or smaller? | ||
76 | { | ||
77 | //over 1000 bytes so split up file | ||
78 | req.num_packets=(int)imag.data.LongLength/1000; | ||
79 | req.num_packets++; | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | req.num_packets=1; | ||
84 | } | ||
85 | |||
86 | this.requests.Add(req); | ||
87 | |||
88 | } | ||
89 | |||
90 | public void add_texture(LLUUID image_id, string name, byte[] data) | ||
91 | { | ||
92 | |||
93 | } | ||
94 | public void Do_work(ulong time) | ||
95 | { | ||
96 | if(this.requests.Count==0) | ||
97 | { | ||
98 | //no requests waiting | ||
99 | return; | ||
100 | } | ||
101 | int num; | ||
102 | //should be running in its own thread but for now is called by timer | ||
103 | if(this.requests.Count<5) | ||
104 | { | ||
105 | //lower than 5 so do all of them | ||
106 | num=this.requests.Count; | ||
107 | } | ||
108 | else | ||
109 | { | ||
110 | num=5; | ||
111 | } | ||
112 | Texture_request req; | ||
113 | for(int i=0; i<num; i++) | ||
114 | { | ||
115 | req=(Texture_request)this.requests[i]; | ||
116 | |||
117 | if(req.packet_counter==0) | ||
118 | { | ||
119 | //first time for this request so send imagedata packet | ||
120 | if(req.num_packets==1) | ||
121 | { | ||
122 | //only one packet so send whole file | ||
123 | ImageDataPacket im=new ImageDataPacket(); | ||
124 | im.ImageID.Packets=1; | ||
125 | im.ImageID.ID=req.image_info.Full_ID; | ||
126 | im.ImageID.Size=(uint)req.image_info.data.Length; | ||
127 | im.ImageData.Data=req.image_info.data; | ||
128 | im.ImageID.Codec=2; | ||
129 | server.SendPacket(im,true,req.req_user); | ||
130 | req.packet_counter++; | ||
131 | req.image_info.last_used=time; | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | //more than one packet so split file up | ||
136 | } | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | //send imagepacket | ||
141 | |||
142 | } | ||
143 | } | ||
144 | |||
145 | //remove requests that have been completed | ||
146 | for(int i=0; i<num; i++) | ||
147 | { | ||
148 | req=(Texture_request)this.requests[i]; | ||
149 | if(req.packet_counter==req.num_packets) | ||
150 | { | ||
151 | this.requests.Remove(req); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | public void recieve_texture(Packet pack) | ||
157 | { | ||
158 | |||
159 | } | ||
160 | |||
161 | private void initialise() | ||
162 | { | ||
163 | //for now read in our test image | ||
164 | Texture_image im=new Texture_image(); | ||
165 | im.filename="testpic2.jp2"; | ||
166 | im.Full_ID=new LLUUID("00000000-0000-0000-5005-000000000005"); | ||
167 | this.load_image(im); | ||
168 | this.textures.Add(im.Full_ID,im); | ||
169 | } | ||
170 | private void load_image(Texture_image im) | ||
171 | { | ||
172 | string data_path=System.Windows.Forms.Application.StartupPath + @"\textures\"; | ||
173 | string filename=data_path+@im.filename; | ||
174 | FileInfo fInfo = new FileInfo(filename); | ||
175 | |||
176 | long numBytes = fInfo.Length; | ||
177 | |||
178 | FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read); | ||
179 | byte[] idata=new byte[numBytes]; | ||
180 | BinaryReader br = new BinaryReader(fStream); | ||
181 | idata= br.ReadBytes((int)numBytes); | ||
182 | br.Close(); | ||
183 | fStream.Close(); | ||
184 | im.data=idata; | ||
185 | im.loaded=true; | ||
186 | } | ||
187 | |||
188 | } | ||
189 | |||
190 | public class Texture_request | ||
191 | { | ||
192 | public User_Agent_info req_user; | ||
193 | public LLUUID req_image; | ||
194 | public Texture_image image_info; | ||
195 | public long data_pointer=0; | ||
196 | public int num_packets=0; | ||
197 | public int packet_counter=0; | ||
198 | |||
199 | public Texture_request() | ||
200 | { | ||
201 | |||
202 | } | ||
203 | } | ||
204 | public class Texture_image | ||
205 | { | ||
206 | public byte[] data; | ||
207 | public LLUUID Full_ID; | ||
208 | public string name; | ||
209 | public string filename; | ||
210 | public bool loaded; | ||
211 | public ulong last_used; //need to add a tick/time counter and keep record | ||
212 | // of how often images are requested to unload unused ones. | ||
213 | |||
214 | public Texture_image() | ||
215 | { | ||
216 | |||
217 | } | ||
218 | } | ||
219 | } | ||