aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs252
1 files changed, 126 insertions, 126 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
index f2672ad..7cb4b00 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/Terragen.cs
@@ -1,127 +1,127 @@
1/* 1/*
2 * Copyright (c) Contributors, http://opensimulator.org/ 2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders. 3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright 7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright 9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the 12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products 13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission. 14 * derived from this software without specific prior written permission.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Text; 30using System.Text;
31using OpenSim.Region.Environment.Interfaces; 31using OpenSim.Region.Environment.Interfaces;
32 32
33namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders 33namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
34{ 34{
35 /// <summary> 35 /// <summary>
36 /// Terragen File Format Loader 36 /// Terragen File Format Loader
37 /// Built from specification at 37 /// Built from specification at
38 /// http://www.planetside.co.uk/terragen/dev/tgterrain.html 38 /// http://www.planetside.co.uk/terragen/dev/tgterrain.html
39 /// </summary> 39 /// </summary>
40 internal class Terragen : ITerrainLoader 40 internal class Terragen : ITerrainLoader
41 { 41 {
42 #region ITerrainLoader Members 42 #region ITerrainLoader Members
43 43
44 public ITerrainChannel LoadFile(string filename) 44 public ITerrainChannel LoadFile(string filename)
45 { 45 {
46 TerrainChannel retval = new TerrainChannel(); 46 TerrainChannel retval = new TerrainChannel();
47 47
48 FileInfo file = new FileInfo(filename); 48 FileInfo file = new FileInfo(filename);
49 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 49 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
50 BinaryReader bs = new BinaryReader(s); 50 BinaryReader bs = new BinaryReader(s);
51 51
52 bool eof = false; 52 bool eof = false;
53 if (ASCIIEncoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ") 53 if (ASCIIEncoding.ASCII.GetString(bs.ReadBytes(16)) == "TERRAGENTERRAIN ")
54 { 54 {
55 // Terragen file 55 // Terragen file
56 while (eof == false) 56 while (eof == false)
57 { 57 {
58 int w = 256; 58 int w = 256;
59 int h = 256; 59 int h = 256;
60 string tmp = ASCIIEncoding.ASCII.GetString(bs.ReadBytes(4)); 60 string tmp = ASCIIEncoding.ASCII.GetString(bs.ReadBytes(4));
61 switch (tmp) 61 switch (tmp)
62 { 62 {
63 case "SIZE": 63 case "SIZE":
64 int sztmp = bs.ReadInt16() + 1; 64 int sztmp = bs.ReadInt16() + 1;
65 w = sztmp; 65 w = sztmp;
66 h = sztmp; 66 h = sztmp;
67 bs.ReadInt16(); 67 bs.ReadInt16();
68 break; 68 break;
69 case "XPTS": 69 case "XPTS":
70 w = bs.ReadInt16(); 70 w = bs.ReadInt16();
71 bs.ReadInt16(); 71 bs.ReadInt16();
72 break; 72 break;
73 case "YPTS": 73 case "YPTS":
74 h = bs.ReadInt16(); 74 h = bs.ReadInt16();
75 bs.ReadInt16(); 75 bs.ReadInt16();
76 break; 76 break;
77 case "ALTW": 77 case "ALTW":
78 eof = true; 78 eof = true;
79 Int16 heightScale = bs.ReadInt16(); 79 Int16 heightScale = bs.ReadInt16();
80 Int16 baseHeight = bs.ReadInt16(); 80 Int16 baseHeight = bs.ReadInt16();
81 retval = new TerrainChannel(w, h); 81 retval = new TerrainChannel(w, h);
82 int x, y; 82 int x, y;
83 for (x = 0; x < w; x++) 83 for (x = 0; x < w; x++)
84 { 84 {
85 for (y = 0; y < h; y++) 85 for (y = 0; y < h; y++)
86 { 86 {
87 retval[x, y] = (double) baseHeight + (double) bs.ReadInt16() * (double) heightScale / 65536.0; 87 retval[x, y] = (double) baseHeight + (double) bs.ReadInt16() * (double) heightScale / 65536.0;
88 } 88 }
89 } 89 }
90 break; 90 break;
91 default: 91 default:
92 bs.ReadInt32(); 92 bs.ReadInt32();
93 break; 93 break;
94 } 94 }
95 } 95 }
96 } 96 }
97 97
98 bs.Close(); 98 bs.Close();
99 s.Close(); 99 s.Close();
100 100
101 return retval; 101 return retval;
102 } 102 }
103 103
104 public void SaveFile(string filename, ITerrainChannel map) 104 public void SaveFile(string filename, ITerrainChannel map)
105 { 105 {
106 char[] header = "TERRAGENTERRAIN".ToCharArray(); 106 char[] header = "TERRAGENTERRAIN".ToCharArray();
107 throw new NotImplementedException(); 107 throw new NotImplementedException();
108 } 108 }
109 109
110 public string FileExtension 110 public string FileExtension
111 { 111 {
112 get { return ".ter"; } 112 get { return ".ter"; }
113 } 113 }
114 114
115 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h) 115 public ITerrainChannel LoadFile(string filename, int x, int y, int fileWidth, int fileHeight, int w, int h)
116 { 116 {
117 throw new NotImplementedException(); 117 throw new NotImplementedException();
118 } 118 }
119 119
120 #endregion 120 #endregion
121 121
122 public override string ToString() 122 public override string ToString()
123 { 123 {
124 return "Terragen"; 124 return "Terragen";
125 } 125 }
126 } 126 }
127} \ No newline at end of file 127} \ No newline at end of file