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