aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/types/BitPack.cs
diff options
context:
space:
mode:
authorjhurliman2007-03-07 05:09:18 +0000
committerjhurliman2007-03-07 05:09:18 +0000
commit0b6f8a02a7d0927031bf812429770d6ecc5f483a (patch)
tree6795f255e730e5cdfcf79191a0fd64734951d691 /src/types/BitPack.cs
parentNEVER COMMIT WITHOUT A TEST COMPILE! (diff)
downloadopensim-SC_OLD-0b6f8a02a7d0927031bf812429770d6ecc5f483a.zip
opensim-SC_OLD-0b6f8a02a7d0927031bf812429770d6ecc5f483a.tar.gz
opensim-SC_OLD-0b6f8a02a7d0927031bf812429770d6ecc5f483a.tar.bz2
opensim-SC_OLD-0b6f8a02a7d0927031bf812429770d6ecc5f483a.tar.xz
* Updating libsecondlife.dll to the latest version with a working LayerData function
* Reformatting some source files * Adding a try/catch sanity check around a phoning home check to osgrid.org * Updating the MSVC project file * Converted LayerData generation to use the functions built in to libsecondlife * Removing unused BitPack.cs and TerrainDecoder.cs files * Added a basic terrain generator (hills algorithm)
Diffstat (limited to '')
-rw-r--r--src/types/BitPack.cs138
1 files changed, 0 insertions, 138 deletions
diff --git a/src/types/BitPack.cs b/src/types/BitPack.cs
deleted file mode 100644
index 1abbcf0..0000000
--- a/src/types/BitPack.cs
+++ /dev/null
@@ -1,138 +0,0 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.types
6{
7 /* New Method
8 *
9 * 1. Get all the individual bytes and their bitlength, put them in a dictionary
10 * 2. Mash together when wanted.
11 *
12 * */
13 public class Bits {
14 public byte[] data;
15 public int len;
16 }
17
18 public class InverseBitPack
19 {
20 private List<Bits> bits;
21
22 public InverseBitPack()
23 {
24 bits = new List<Bits>();
25 }
26 }
27
28 public class BitPack
29 {
30 private const int MAX_BITS = 8;
31
32 private byte[] Data;
33 private int bytePos;
34 private int bitPos;
35
36 public BitPack(byte[] data, int pos) // For libsl compatibility
37 {
38 Data = data;
39 bytePos = pos;
40 }
41
42 public BitPack() // Encoding version
43 {
44
45 }
46
47 public void LoadData(byte[] data, int pos) {
48 Data = data;
49 bytePos = pos;
50 bitPos = 0;
51 }
52
53 private void PackBitsArray(byte[] bits, int bitLen)
54 {
55 int offset = bitPos % MAX_BITS;
56 int i;
57 byte temp1;
58 byte temp2;
59
60 for (i = 0; i < bits.Length; i++)
61 {
62 int Byte = bits[i];
63 Byte <<= offset;
64 temp1 = (byte)(Byte & 0xFF);
65 temp2 = (byte)((Byte >> 8) & 0xFF);
66
67 Data[Data.Length - 1] |= temp1;
68// Data
69
70 bitPos += bitLen;
71 }
72 }
73
74 public float UnpackFloat()
75 {
76 byte[] output = UnpackBitsArray(32);
77
78 if (!BitConverter.IsLittleEndian) Array.Reverse(output);
79 return BitConverter.ToSingle(output, 0);
80 }
81
82 public int UnpackBits(int totalCount)
83 {
84 byte[] output = UnpackBitsArray(totalCount);
85
86 if (!BitConverter.IsLittleEndian) Array.Reverse(output);
87 return BitConverter.ToInt32(output, 0);
88 }
89
90 private byte[] UnpackBitsArray(int totalCount)
91 {
92 int count = 0;
93 byte[] output = new byte[4];
94 int curBytePos = 0;
95 int curBitPos = 0;
96
97 while (totalCount > 0)
98 {
99 if (totalCount > MAX_BITS)
100 {
101 count = MAX_BITS;
102 totalCount -= MAX_BITS;
103 }
104 else
105 {
106 count = totalCount;
107 totalCount = 0;
108 }
109
110 while (count > 0)
111 {
112 // Shift the previous bits
113 output[curBytePos] <<= 1;
114
115 // Grab one bit
116 if ((Data[bytePos] & (0x80 >> bitPos++)) != 0)
117 ++output[curBytePos];
118
119 --count;
120 ++curBitPos;
121
122 if (bitPos >= MAX_BITS)
123 {
124 bitPos = 0;
125 ++bytePos;
126 }
127 if (curBitPos >= MAX_BITS)
128 {
129 curBitPos = 0;
130 ++curBytePos;
131 }
132 }
133 }
134
135 return output;
136 }
137 }
138}