diff options
author | Adam Frisby | 2008-04-30 21:16:36 +0000 |
---|---|---|
committer | Adam Frisby | 2008-04-30 21:16:36 +0000 |
commit | f5c312bc3c2567449c7268a54a08a54119f58d53 (patch) | |
tree | 424668a4bbec6873ebc5b8256f3671db102f5e9c /OpenSim/Region/Environment/Modules/TextureSender.cs | |
parent | * Adds the AuthbuyerID field to sqlite and makes use of it. (diff) | |
download | opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.zip opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.gz opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.bz2 opensim-SC-f5c312bc3c2567449c7268a54a08a54119f58d53.tar.xz |
* Refactored Environment/Modules directory - modules now reside in their own directory with any associated module-specific classes.
* Each module directory is currently inside one of the following category folders: Agent (Anything relating to do with Client<->Server communications.), Avatar (Anything to do with the avatar or presence inworld), Framework (Classes modules can use), Grid (Grid traffic, new OGS2 grid comms), Scripting (Scripting functions, etc), World (The enrivonment/scene, IE Sun/Tree modules.)
* This should be moved into a seperate project file.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs (renamed from OpenSim/Region/Environment/Modules/TextureSender.cs) | 440 |
1 files changed, 220 insertions, 220 deletions
diff --git a/OpenSim/Region/Environment/Modules/TextureSender.cs b/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs index e54a1a2..37b0652 100644 --- a/OpenSim/Region/Environment/Modules/TextureSender.cs +++ b/OpenSim/Region/Environment/Modules/Agent/TextureSender/TextureSender.cs | |||
@@ -1,220 +1,220 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using libsecondlife.Packets; | 30 | using libsecondlife.Packets; |
31 | using log4net; | 31 | using log4net; |
32 | using OpenSim.Framework; | 32 | using OpenSim.Framework; |
33 | using OpenSim.Region.Environment.Interfaces; | 33 | using OpenSim.Region.Environment.Interfaces; |
34 | 34 | ||
35 | namespace OpenSim.Region.Environment.Modules | 35 | namespace OpenSim.Region.Environment.Modules.Agent.TextureSender |
36 | { | 36 | { |
37 | /// <summary> | 37 | /// <summary> |
38 | /// A TextureSender handles the process of receiving a texture requested by the client from the | 38 | /// A TextureSender handles the process of receiving a texture requested by the client from the |
39 | /// AssetCache, and then sending that texture back to the client. | 39 | /// AssetCache, and then sending that texture back to the client. |
40 | /// </summary> | 40 | /// </summary> |
41 | public class TextureSender : ITextureSender | 41 | public class TextureSender : ITextureSender |
42 | { | 42 | { |
43 | private static readonly ILog m_log | 43 | private static readonly ILog m_log |
44 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 44 | = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 45 | ||
46 | /// <summary> | 46 | /// <summary> |
47 | /// Records the number of times texture send has been called. | 47 | /// Records the number of times texture send has been called. |
48 | /// </summary> | 48 | /// </summary> |
49 | public int counter = 0; | 49 | public int counter = 0; |
50 | 50 | ||
51 | /// <summary> | 51 | /// <summary> |
52 | /// Holds the texture asset to send. | 52 | /// Holds the texture asset to send. |
53 | /// </summary> | 53 | /// </summary> |
54 | private AssetBase m_asset; | 54 | private AssetBase m_asset; |
55 | 55 | ||
56 | //public LLUUID assetID { get { return m_asset.FullID; } } | 56 | //public LLUUID assetID { get { return m_asset.FullID; } } |
57 | 57 | ||
58 | /// <summary> | 58 | /// <summary> |
59 | /// This is actually the number of extra packets required to send the texture data! We always assume | 59 | /// This is actually the number of extra packets required to send the texture data! We always assume |
60 | /// at least one is required. | 60 | /// at least one is required. |
61 | /// </summary> | 61 | /// </summary> |
62 | private int NumPackets = 0; | 62 | private int NumPackets = 0; |
63 | 63 | ||
64 | /// <summary> | 64 | /// <summary> |
65 | /// Holds the packet number to send next. In this case, each packet is 1000 bytes long and starts | 65 | /// Holds the packet number to send next. In this case, each packet is 1000 bytes long and starts |
66 | /// at the 600th byte (0th indexed). | 66 | /// at the 600th byte (0th indexed). |
67 | /// </summary> | 67 | /// </summary> |
68 | private int PacketCounter = 0; | 68 | private int PacketCounter = 0; |
69 | 69 | ||
70 | // See ITextureSender | 70 | // See ITextureSender |
71 | public bool Cancel | 71 | public bool Cancel |
72 | { | 72 | { |
73 | get { return false; } | 73 | get { return false; } |
74 | set { m_cancel = value; } | 74 | set { m_cancel = value; } |
75 | } | 75 | } |
76 | 76 | ||
77 | private bool m_cancel = false; | 77 | private bool m_cancel = false; |
78 | 78 | ||
79 | // See ITextureSender | 79 | // See ITextureSender |
80 | public bool Sending | 80 | public bool Sending |
81 | { | 81 | { |
82 | get { return false; } | 82 | get { return false; } |
83 | set { m_sending = value; } | 83 | set { m_sending = value; } |
84 | } | 84 | } |
85 | 85 | ||
86 | private bool m_sending = false; | 86 | private bool m_sending = false; |
87 | 87 | ||
88 | public bool ImageLoaded = false; | 88 | public bool ImageLoaded = false; |
89 | 89 | ||
90 | private IClientAPI RequestUser; | 90 | private IClientAPI RequestUser; |
91 | 91 | ||
92 | private int RequestedDiscardLevel = -1; | 92 | private int RequestedDiscardLevel = -1; |
93 | private uint StartPacketNumber = 0; | 93 | private uint StartPacketNumber = 0; |
94 | 94 | ||
95 | public TextureSender(IClientAPI client, int discardLevel, uint packetNumber) | 95 | public TextureSender(IClientAPI client, int discardLevel, uint packetNumber) |
96 | { | 96 | { |
97 | RequestUser = client; | 97 | RequestUser = client; |
98 | RequestedDiscardLevel = discardLevel; | 98 | RequestedDiscardLevel = discardLevel; |
99 | StartPacketNumber = packetNumber; | 99 | StartPacketNumber = packetNumber; |
100 | } | 100 | } |
101 | 101 | ||
102 | /// <summary> | 102 | /// <summary> |
103 | /// Load up the texture data to send. | 103 | /// Load up the texture data to send. |
104 | /// </summary> | 104 | /// </summary> |
105 | /// <param name="asset"> | 105 | /// <param name="asset"> |
106 | /// A <see cref="AssetBase"/> | 106 | /// A <see cref="AssetBase"/> |
107 | /// </param> | 107 | /// </param> |
108 | public void TextureReceived(AssetBase asset) | 108 | public void TextureReceived(AssetBase asset) |
109 | { | 109 | { |
110 | m_asset = asset; | 110 | m_asset = asset; |
111 | NumPackets = CalculateNumPackets(asset.Data.Length); | 111 | NumPackets = CalculateNumPackets(asset.Data.Length); |
112 | PacketCounter = (int) StartPacketNumber; | 112 | PacketCounter = (int) StartPacketNumber; |
113 | ImageLoaded = true; | 113 | ImageLoaded = true; |
114 | } | 114 | } |
115 | 115 | ||
116 | // See ITextureSender | 116 | // See ITextureSender |
117 | public void UpdateRequest(int discardLevel, uint packetNumber) | 117 | public void UpdateRequest(int discardLevel, uint packetNumber) |
118 | { | 118 | { |
119 | RequestedDiscardLevel = discardLevel; | 119 | RequestedDiscardLevel = discardLevel; |
120 | StartPacketNumber = packetNumber; | 120 | StartPacketNumber = packetNumber; |
121 | PacketCounter = (int) StartPacketNumber; | 121 | PacketCounter = (int) StartPacketNumber; |
122 | } | 122 | } |
123 | 123 | ||
124 | // See ITextureSender | 124 | // See ITextureSender |
125 | public bool SendTexturePacket() | 125 | public bool SendTexturePacket() |
126 | { | 126 | { |
127 | //m_log.DebugFormat("[TEXTURE SENDER]: Sending packet for {0}", m_asset.FullID); | 127 | //m_log.DebugFormat("[TEXTURE SENDER]: Sending packet for {0}", m_asset.FullID); |
128 | 128 | ||
129 | SendPacket(); | 129 | SendPacket(); |
130 | counter++; | 130 | counter++; |
131 | if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || | 131 | if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || |
132 | ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1))))) | 132 | ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1))))) |
133 | { | 133 | { |
134 | return true; | 134 | return true; |
135 | } | 135 | } |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | 138 | ||
139 | /// <summary> | 139 | /// <summary> |
140 | /// Sends a texture packet to the client. | 140 | /// Sends a texture packet to the client. |
141 | /// </summary> | 141 | /// </summary> |
142 | private void SendPacket() | 142 | private void SendPacket() |
143 | { | 143 | { |
144 | if (PacketCounter <= NumPackets) | 144 | if (PacketCounter <= NumPackets) |
145 | { | 145 | { |
146 | if (PacketCounter == 0) | 146 | if (PacketCounter == 0) |
147 | { | 147 | { |
148 | if (NumPackets == 0) | 148 | if (NumPackets == 0) |
149 | { | 149 | { |
150 | ImageDataPacket im = new ImageDataPacket(); | 150 | ImageDataPacket im = new ImageDataPacket(); |
151 | im.Header.Reliable = false; | 151 | im.Header.Reliable = false; |
152 | im.ImageID.Packets = 1; | 152 | im.ImageID.Packets = 1; |
153 | im.ImageID.ID = m_asset.FullID; | 153 | im.ImageID.ID = m_asset.FullID; |
154 | im.ImageID.Size = (uint) m_asset.Data.Length; | 154 | im.ImageID.Size = (uint) m_asset.Data.Length; |
155 | im.ImageData.Data = m_asset.Data; | 155 | im.ImageData.Data = m_asset.Data; |
156 | im.ImageID.Codec = 2; | 156 | im.ImageID.Codec = 2; |
157 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | 157 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); |
158 | PacketCounter++; | 158 | PacketCounter++; |
159 | } | 159 | } |
160 | else | 160 | else |
161 | { | 161 | { |
162 | ImageDataPacket im = new ImageDataPacket(); | 162 | ImageDataPacket im = new ImageDataPacket(); |
163 | im.Header.Reliable = false; | 163 | im.Header.Reliable = false; |
164 | im.ImageID.Packets = (ushort) (NumPackets); | 164 | im.ImageID.Packets = (ushort) (NumPackets); |
165 | im.ImageID.ID = m_asset.FullID; | 165 | im.ImageID.ID = m_asset.FullID; |
166 | im.ImageID.Size = (uint) m_asset.Data.Length; | 166 | im.ImageID.Size = (uint) m_asset.Data.Length; |
167 | im.ImageData.Data = new byte[600]; | 167 | im.ImageData.Data = new byte[600]; |
168 | Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600); | 168 | Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600); |
169 | im.ImageID.Codec = 2; | 169 | im.ImageID.Codec = 2; |
170 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | 170 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); |
171 | PacketCounter++; | 171 | PacketCounter++; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | else | 174 | else |
175 | { | 175 | { |
176 | ImagePacketPacket im = new ImagePacketPacket(); | 176 | ImagePacketPacket im = new ImagePacketPacket(); |
177 | im.Header.Reliable = false; | 177 | im.Header.Reliable = false; |
178 | im.ImageID.Packet = (ushort) (PacketCounter); | 178 | im.ImageID.Packet = (ushort) (PacketCounter); |
179 | im.ImageID.ID = m_asset.FullID; | 179 | im.ImageID.ID = m_asset.FullID; |
180 | int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1)); | 180 | int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1)); |
181 | if (size > 1000) size = 1000; | 181 | if (size > 1000) size = 1000; |
182 | im.ImageData.Data = new byte[size]; | 182 | im.ImageData.Data = new byte[size]; |
183 | try | 183 | try |
184 | { | 184 | { |
185 | Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size); | 185 | Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size); |
186 | } | 186 | } |
187 | catch (ArgumentOutOfRangeException) | 187 | catch (ArgumentOutOfRangeException) |
188 | { | 188 | { |
189 | m_log.Error("[TEXTURE SENDER]: Unable to separate texture into multiple packets: Array bounds failure on asset:" + | 189 | m_log.Error("[TEXTURE SENDER]: Unable to separate texture into multiple packets: Array bounds failure on asset:" + |
190 | m_asset.FullID.ToString() ); | 190 | m_asset.FullID.ToString() ); |
191 | return; | 191 | return; |
192 | } | 192 | } |
193 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | 193 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); |
194 | PacketCounter++; | 194 | PacketCounter++; |
195 | } | 195 | } |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | /// <summary> | 199 | /// <summary> |
200 | /// Calculate the number of packets that will be required to send the texture loaded into this sender | 200 | /// Calculate the number of packets that will be required to send the texture loaded into this sender |
201 | /// This is actually the number of 1000 byte packets not including an initial 600 byte packet... | 201 | /// This is actually the number of 1000 byte packets not including an initial 600 byte packet... |
202 | /// </summary> | 202 | /// </summary> |
203 | /// <param name="length"></param> | 203 | /// <param name="length"></param> |
204 | /// <returns></returns> | 204 | /// <returns></returns> |
205 | private int CalculateNumPackets(int length) | 205 | private int CalculateNumPackets(int length) |
206 | { | 206 | { |
207 | int numPackets = 0; | 207 | int numPackets = 0; |
208 | 208 | ||
209 | if (length > 600) | 209 | if (length > 600) |
210 | { | 210 | { |
211 | //over 600 bytes so split up file | 211 | //over 600 bytes so split up file |
212 | int restData = (length - 600); | 212 | int restData = (length - 600); |
213 | int restPackets = ((restData + 999)/1000); | 213 | int restPackets = ((restData + 999)/1000); |
214 | numPackets = restPackets; | 214 | numPackets = restPackets; |
215 | } | 215 | } |
216 | 216 | ||
217 | return numPackets; | 217 | return numPackets; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | } | 220 | } \ No newline at end of file |