aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs89
1 files changed, 89 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
new file mode 100644
index 0000000..2443173
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Terrain/FileLoaders/Terragen.cs
@@ -0,0 +1,89 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.IO;
5using OpenSim.Region.Environment.Modules.Terrain;
6using OpenSim.Region.Environment.Interfaces;
7
8namespace OpenSim.Region.Environment.Modules.Terrain.FileLoaders
9{
10 /// <summary>
11 /// Terragen File Format Loader
12 /// Built from specification at
13 /// http://www.planetside.co.uk/terragen/dev/tgterrain.html
14 /// </summary>
15 class Terragen : ITerrainLoader
16 {
17 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
18
19 #region ITerrainLoader Members
20
21 public ITerrainChannel LoadFile(string filename)
22 {
23 TerrainChannel retval = new TerrainChannel();
24
25 FileInfo file = new FileInfo(filename);
26 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
27 BinaryReader bs = new BinaryReader(s);
28
29 bool eof = false;
30
31 if (ASCIIEncoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN")
32 {
33 // Terragen file
34 while (eof == false)
35 {
36 int w = 256;
37 int h = 256;
38 string tmp = ASCIIEncoding.ASCII.GetString(bs.ReadBytes(4));
39 switch (tmp)
40 {
41 case "SIZE":
42 int sztmp = bs.ReadInt16() + 1;
43 w = sztmp;
44 h = sztmp;
45 bs.ReadInt16();
46 break;
47 case "XPTS":
48 w = bs.ReadInt16();
49 bs.ReadInt16();
50 break;
51 case "YPTS":
52 h = bs.ReadInt16();
53 bs.ReadInt16();
54 break;
55 case "ALTW":
56 eof = true;
57 Int16 heightScale = bs.ReadInt16();
58 Int16 baseHeight = bs.ReadInt16();
59 retval = new TerrainChannel(w, h);
60 int x, y;
61 for (x = 0; x < w; x++)
62 {
63 for (y = 0; y < h; y++)
64 {
65 retval[x, y] = (double)baseHeight + (double)bs.ReadInt16() * (double)heightScale / 65536.0;
66 }
67 }
68 break;
69 default:
70 bs.ReadInt32();
71 break;
72 }
73 }
74 }
75
76 bs.Close();
77 s.Close();
78
79 return retval;
80 }
81
82 public void SaveFile(string filename)
83 {
84 throw new NotImplementedException();
85 }
86
87 #endregion
88 }
89}