diff options
author | Jeff Ames | 2008-01-03 13:44:52 +0000 |
---|---|---|
committer | Jeff Ames | 2008-01-03 13:44:52 +0000 |
commit | 119f9b0d8027324b3991fec302ea6c6210b8df46 (patch) | |
tree | 46575f880167e2082b4acc53c4501723b7afba22 /OpenSim/Region/Environment/Modules/TextureSender.cs | |
parent | * Some work on TextureDownloadModule (diff) | |
download | opensim-SC-119f9b0d8027324b3991fec302ea6c6210b8df46.zip opensim-SC-119f9b0d8027324b3991fec302ea6c6210b8df46.tar.gz opensim-SC-119f9b0d8027324b3991fec302ea6c6210b8df46.tar.bz2 opensim-SC-119f9b0d8027324b3991fec302ea6c6210b8df46.tar.xz |
Set svn:eol-style.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/TextureSender.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/TextureSender.cs | 270 |
1 files changed, 135 insertions, 135 deletions
diff --git a/OpenSim/Region/Environment/Modules/TextureSender.cs b/OpenSim/Region/Environment/Modules/TextureSender.cs index aba0126..c8807f7 100644 --- a/OpenSim/Region/Environment/Modules/TextureSender.cs +++ b/OpenSim/Region/Environment/Modules/TextureSender.cs | |||
@@ -1,136 +1,136 @@ | |||
1 | using System; | 1 | using System; |
2 | using libsecondlife; | 2 | using libsecondlife; |
3 | using libsecondlife.Packets; | 3 | using libsecondlife.Packets; |
4 | using OpenSim.Framework; | 4 | using OpenSim.Framework; |
5 | using OpenSim.Framework.Console; | 5 | using OpenSim.Framework.Console; |
6 | 6 | ||
7 | namespace OpenSim.Region.Environment.Modules | 7 | namespace OpenSim.Region.Environment.Modules |
8 | { | 8 | { |
9 | public class TextureSender | 9 | public class TextureSender |
10 | { | 10 | { |
11 | public int counter = 0; | 11 | public int counter = 0; |
12 | private AssetBase m_asset; | 12 | private AssetBase m_asset; |
13 | public long DataPointer = 0; | 13 | public long DataPointer = 0; |
14 | public int NumPackets = 0; | 14 | public int NumPackets = 0; |
15 | public int PacketCounter = 0; | 15 | public int PacketCounter = 0; |
16 | public bool Cancel = false; | 16 | public bool Cancel = false; |
17 | public bool ImageLoaded = false; | 17 | public bool ImageLoaded = false; |
18 | 18 | ||
19 | public bool Sending = false; | 19 | public bool Sending = false; |
20 | 20 | ||
21 | public IClientAPI RequestUser; | 21 | public IClientAPI RequestUser; |
22 | public LLUUID RequestedAssetID; | 22 | public LLUUID RequestedAssetID; |
23 | public int RequestedDiscardLevel = -1; | 23 | public int RequestedDiscardLevel = -1; |
24 | public uint StartPacketNumber = 0; | 24 | public uint StartPacketNumber = 0; |
25 | 25 | ||
26 | // private int m_sentDiscardLevel = -1; | 26 | // private int m_sentDiscardLevel = -1; |
27 | 27 | ||
28 | public TextureSender(IClientAPI client, LLUUID textureID, int discardLevel, uint packetNumber) | 28 | public TextureSender(IClientAPI client, LLUUID textureID, int discardLevel, uint packetNumber) |
29 | { | 29 | { |
30 | RequestUser = client; | 30 | RequestUser = client; |
31 | RequestedAssetID = textureID; | 31 | RequestedAssetID = textureID; |
32 | RequestedDiscardLevel = discardLevel; | 32 | RequestedDiscardLevel = discardLevel; |
33 | StartPacketNumber = packetNumber; | 33 | StartPacketNumber = packetNumber; |
34 | } | 34 | } |
35 | 35 | ||
36 | public void TextureReceived(AssetBase asset) | 36 | public void TextureReceived(AssetBase asset) |
37 | { | 37 | { |
38 | m_asset = asset; | 38 | m_asset = asset; |
39 | NumPackets = CalculateNumPackets(asset.Data.Length); | 39 | NumPackets = CalculateNumPackets(asset.Data.Length); |
40 | PacketCounter = (int) StartPacketNumber; | 40 | PacketCounter = (int) StartPacketNumber; |
41 | ImageLoaded = true; | 41 | ImageLoaded = true; |
42 | } | 42 | } |
43 | 43 | ||
44 | public void UpdateRequest(int discardLevel, uint packetNumber) | 44 | public void UpdateRequest(int discardLevel, uint packetNumber) |
45 | { | 45 | { |
46 | RequestedDiscardLevel = discardLevel; | 46 | RequestedDiscardLevel = discardLevel; |
47 | StartPacketNumber = packetNumber; | 47 | StartPacketNumber = packetNumber; |
48 | PacketCounter = (int) StartPacketNumber; | 48 | PacketCounter = (int) StartPacketNumber; |
49 | } | 49 | } |
50 | 50 | ||
51 | public bool SendTexturePacket() | 51 | public bool SendTexturePacket() |
52 | { | 52 | { |
53 | SendPacket(); | 53 | SendPacket(); |
54 | counter++; | 54 | counter++; |
55 | if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || | 55 | if ((NumPackets == 0) || (RequestedDiscardLevel == -1) || (PacketCounter > NumPackets) || |
56 | ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1))))) | 56 | ((RequestedDiscardLevel > 0) && (counter > 50 + (NumPackets/(RequestedDiscardLevel + 1))))) |
57 | { | 57 | { |
58 | return true; | 58 | return true; |
59 | } | 59 | } |
60 | return false; | 60 | return false; |
61 | } | 61 | } |
62 | 62 | ||
63 | private void SendPacket() | 63 | private void SendPacket() |
64 | { | 64 | { |
65 | if (PacketCounter <= NumPackets) | 65 | if (PacketCounter <= NumPackets) |
66 | { | 66 | { |
67 | if (PacketCounter == 0) | 67 | if (PacketCounter == 0) |
68 | { | 68 | { |
69 | if (NumPackets == 0) | 69 | if (NumPackets == 0) |
70 | { | 70 | { |
71 | ImageDataPacket im = new ImageDataPacket(); | 71 | ImageDataPacket im = new ImageDataPacket(); |
72 | im.Header.Reliable = false; | 72 | im.Header.Reliable = false; |
73 | im.ImageID.Packets = 1; | 73 | im.ImageID.Packets = 1; |
74 | im.ImageID.ID = m_asset.FullID; | 74 | im.ImageID.ID = m_asset.FullID; |
75 | im.ImageID.Size = (uint) m_asset.Data.Length; | 75 | im.ImageID.Size = (uint) m_asset.Data.Length; |
76 | im.ImageData.Data = m_asset.Data; | 76 | im.ImageData.Data = m_asset.Data; |
77 | im.ImageID.Codec = 2; | 77 | im.ImageID.Codec = 2; |
78 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | 78 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); |
79 | PacketCounter++; | 79 | PacketCounter++; |
80 | } | 80 | } |
81 | else | 81 | else |
82 | { | 82 | { |
83 | ImageDataPacket im = new ImageDataPacket(); | 83 | ImageDataPacket im = new ImageDataPacket(); |
84 | im.Header.Reliable = false; | 84 | im.Header.Reliable = false; |
85 | im.ImageID.Packets = (ushort) (NumPackets); | 85 | im.ImageID.Packets = (ushort) (NumPackets); |
86 | im.ImageID.ID = m_asset.FullID; | 86 | im.ImageID.ID = m_asset.FullID; |
87 | im.ImageID.Size = (uint) m_asset.Data.Length; | 87 | im.ImageID.Size = (uint) m_asset.Data.Length; |
88 | im.ImageData.Data = new byte[600]; | 88 | im.ImageData.Data = new byte[600]; |
89 | Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600); | 89 | Array.Copy(m_asset.Data, 0, im.ImageData.Data, 0, 600); |
90 | im.ImageID.Codec = 2; | 90 | im.ImageID.Codec = 2; |
91 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | 91 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); |
92 | PacketCounter++; | 92 | PacketCounter++; |
93 | } | 93 | } |
94 | } | 94 | } |
95 | else | 95 | else |
96 | { | 96 | { |
97 | ImagePacketPacket im = new ImagePacketPacket(); | 97 | ImagePacketPacket im = new ImagePacketPacket(); |
98 | im.Header.Reliable = false; | 98 | im.Header.Reliable = false; |
99 | im.ImageID.Packet = (ushort) (PacketCounter); | 99 | im.ImageID.Packet = (ushort) (PacketCounter); |
100 | im.ImageID.ID = m_asset.FullID; | 100 | im.ImageID.ID = m_asset.FullID; |
101 | int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1)); | 101 | int size = m_asset.Data.Length - 600 - (1000*(PacketCounter - 1)); |
102 | if (size > 1000) size = 1000; | 102 | if (size > 1000) size = 1000; |
103 | im.ImageData.Data = new byte[size]; | 103 | im.ImageData.Data = new byte[size]; |
104 | try | 104 | try |
105 | { | 105 | { |
106 | Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size); | 106 | Array.Copy(m_asset.Data, 600 + (1000*(PacketCounter - 1)), im.ImageData.Data, 0, size); |
107 | } | 107 | } |
108 | catch (ArgumentOutOfRangeException) | 108 | catch (ArgumentOutOfRangeException) |
109 | { | 109 | { |
110 | MainLog.Instance.Error("TEXTURE", | 110 | MainLog.Instance.Error("TEXTURE", |
111 | "Unable to separate texture into multiple packets: Array bounds failure on asset:" + | 111 | "Unable to separate texture into multiple packets: Array bounds failure on asset:" + |
112 | m_asset.FullID.ToString() ); | 112 | m_asset.FullID.ToString() ); |
113 | return; | 113 | return; |
114 | } | 114 | } |
115 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); | 115 | RequestUser.OutPacket(im, ThrottleOutPacketType.Texture); |
116 | PacketCounter++; | 116 | PacketCounter++; |
117 | } | 117 | } |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | private int CalculateNumPackets(int length) | 121 | private int CalculateNumPackets(int length) |
122 | { | 122 | { |
123 | int numPackets = 0; | 123 | int numPackets = 0; |
124 | 124 | ||
125 | if (length > 600) | 125 | if (length > 600) |
126 | { | 126 | { |
127 | //over 600 bytes so split up file | 127 | //over 600 bytes so split up file |
128 | int restData = (length - 600); | 128 | int restData = (length - 600); |
129 | int restPackets = ((restData + 999)/1000); | 129 | int restPackets = ((restData + 999)/1000); |
130 | numPackets = restPackets; | 130 | numPackets = restPackets; |
131 | } | 131 | } |
132 | 132 | ||
133 | return numPackets; | 133 | return numPackets; |
134 | } | 134 | } |
135 | } | 135 | } |
136 | } \ No newline at end of file | 136 | } \ No newline at end of file |