30 using OpenSim.Framework;
31 using OpenSim.Region.Framework.Interfaces;
32 using OpenSim.Region.Framework.Scenes;
51 return Value.CompareTo(val.Value);
56 HeightmapLookupValue[] LookupHeightTable;
62 private void BuildLookupHeightTable()
64 LookupHeightTable =
new HeightmapLookupValue[256 * 256];
66 for (
int i = 0; i < 256; i++)
68 for (
int j = 0; j < 256; j++)
70 LookupHeightTable[i + (j * 256)] =
new HeightmapLookupValue((ushort)(i + (j * 256)), (float)((
double)i * ((double)j / 128.0d)));
73 Array.Sort<HeightmapLookupValue>(LookupHeightTable);
76 #region ITerrainLoader Members
80 FileInfo file =
new FileInfo(filename);
84 using (FileStream s = file.Open(FileMode.Open, FileAccess.Read))
85 channel = LoadStream(s);
90 public ITerrainChannel LoadFile(
string filename,
int offsetX,
int offsetY,
int fileWidth,
int fileHeight,
int sectionWidth,
int sectionHeight)
94 FileInfo file =
new FileInfo(filename);
96 using (FileStream s = file.Open(FileMode.Open, FileAccess.Read))
97 using (BinaryReader bs =
new BinaryReader(s))
99 int currFileYOffset = fileHeight - 1;
103 while (currFileYOffset > offsetY)
106 int heightsToRead = sectionHeight * (fileWidth * sectionWidth);
107 bs.ReadBytes(heightsToRead * 13);
116 for (y = sectionHeight - 1; y >= 0; y--)
118 int currFileXOffset = 0;
123 while (currFileXOffset < offsetX)
125 bs.ReadBytes(sectionWidth * 13);
131 for (x = 0; x < sectionWidth; x++)
134 retval[x, y] = bs.ReadByte() * (bs.ReadByte() / 128.0);
142 while (currFileXOffset < fileWidth)
145 bs.ReadBytes(sectionWidth * 13);
158 double dimension = Math.Sqrt((double)(s.Length / 13));
166 using (BinaryReader bs =
new BinaryReader(s))
169 for (y = 0; y < retval.Height; y++)
172 for (x = 0; x < retval.Width; x++)
174 retval[x, (retval.Height - 1) - y] = bs.ReadByte() * (bs.ReadByte() / 128.0);
185 FileInfo file =
new FileInfo(filename);
187 using (FileStream s = file.Open(FileMode.CreateNew, FileAccess.Write))
193 if (LookupHeightTable == null)
194 BuildLookupHeightTable();
196 using (BinaryWriter binStream =
new BinaryWriter(s))
199 for (
int y = 0; y < map.Height; y++)
201 for (
int x = 0; x < map.Width; x++)
203 double t = map[x, (map.Height - 1) - y];
219 index = LookupHeightTable[index].Index;
221 byte red = (byte) (index & 0xFF);
222 byte green = (byte) ((index >> 8) & 0xFF);
223 const byte blue = 20;
224 const byte alpha1 = 0;
225 const byte alpha2 = 0;
226 const byte alpha3 = 0;
227 const byte alpha4 = 0;
228 const byte alpha5 = 255;
229 const byte alpha6 = 255;
230 const byte alpha7 = 255;
231 const byte alpha8 = 255;
233 byte alpha10 = green;
235 binStream.Write(red);
236 binStream.Write(green);
237 binStream.Write(blue);
238 binStream.Write(alpha1);
239 binStream.Write(alpha2);
240 binStream.Write(alpha3);
241 binStream.Write(alpha4);
242 binStream.Write(alpha5);
243 binStream.Write(alpha6);
244 binStream.Write(alpha7);
245 binStream.Write(alpha8);
246 binStream.Write(alpha9);
247 binStream.Write(alpha10);
251 LookupHeightTable = null;
254 public string FileExtension
256 get {
return ".raw"; }
260 int offsetX,
int offsetY,
261 int fileWidth,
int fileHeight,
262 int regionSizeX,
int regionSizeY)
264 throw new System.Exception(
"Not Implemented");
virtual void SaveFile(ITerrainChannel m_channel, string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int regionSizeX, int regionSizeY)
Save a number of map tiles to a single big image file.
ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
int CompareTo(HeightmapLookupValue val)
void SaveStream(Stream s, ITerrainChannel map)
ITerrainChannel LoadFile(string filename)
void SaveFile(string filename, ITerrainChannel map)
A new version of the old Channel class, simplified
ITerrainChannel LoadStream(Stream s)
HeightmapLookupValue(ushort index, float value)
override string ToString()