aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs304
1 files changed, 152 insertions, 152 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
index 71f56c5..fd2136c 100644
--- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
+++ b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs
@@ -1,153 +1,153 @@
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.IO; 28using System.IO;
29using OpenSim.Region.Environment.Interfaces; 29using OpenSim.Region.Environment.Interfaces;
30 30
31namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders 31namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders
32{ 32{
33 public class RAW32 : ITerrainLoader 33 public class RAW32 : ITerrainLoader
34 { 34 {
35 #region ITerrainLoader Members 35 #region ITerrainLoader Members
36 36
37 public string FileExtension 37 public string FileExtension
38 { 38 {
39 get { return ".r32"; } 39 get { return ".r32"; }
40 } 40 }
41 41
42 public ITerrainChannel LoadFile(string filename) 42 public ITerrainChannel LoadFile(string filename)
43 { 43 {
44 TerrainChannel retval = new TerrainChannel(); 44 TerrainChannel retval = new TerrainChannel();
45 45
46 FileInfo file = new FileInfo(filename); 46 FileInfo file = new FileInfo(filename);
47 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 47 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
48 BinaryReader bs = new BinaryReader(s); 48 BinaryReader bs = new BinaryReader(s);
49 int x, y; 49 int x, y;
50 for (y = 0; y < retval.Height; y++) 50 for (y = 0; y < retval.Height; y++)
51 { 51 {
52 for (x = 0; x < retval.Width; x++) 52 for (x = 0; x < retval.Width; x++)
53 { 53 {
54 retval[x, y] = bs.ReadSingle(); 54 retval[x, y] = bs.ReadSingle();
55 } 55 }
56 } 56 }
57 57
58 bs.Close(); 58 bs.Close();
59 s.Close(); 59 s.Close();
60 60
61 return retval; 61 return retval;
62 } 62 }
63 63
64 public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight) 64 public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight)
65 { 65 {
66 TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight); 66 TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight);
67 67
68 FileInfo file = new FileInfo(filename); 68 FileInfo file = new FileInfo(filename);
69 FileStream s = file.Open(FileMode.Open, FileAccess.Read); 69 FileStream s = file.Open(FileMode.Open, FileAccess.Read);
70 BinaryReader bs = new BinaryReader(s); 70 BinaryReader bs = new BinaryReader(s);
71 71
72 int currFileXOffset = 0; 72 int currFileXOffset = 0;
73 int currFileYOffset = 0; 73 int currFileYOffset = 0;
74 74
75 // if our region isn't on the first Y section of the areas to be landscaped, then 75 // if our region isn't on the first Y section of the areas to be landscaped, then
76 // advance to our section of the file 76 // advance to our section of the file
77 while (currFileYOffset < offsetY) 77 while (currFileYOffset < offsetY)
78 { 78 {
79 // read a whole strip of regions 79 // read a whole strip of regions
80 int heightsToRead = sectionHeight * (fileWidth * sectionWidth); 80 int heightsToRead = sectionHeight * (fileWidth * sectionWidth);
81 bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file 81 bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file
82 currFileYOffset++; 82 currFileYOffset++;
83 } 83 }
84 84
85 // got to the Y start offset within the file of our region 85 // got to the Y start offset within the file of our region
86 // so read the file bits associated with our region 86 // so read the file bits associated with our region
87 int x, y; 87 int x, y;
88 // for each Y within our Y offset 88 // for each Y within our Y offset
89 for (y = 0; y < sectionHeight; y++) 89 for (y = 0; y < sectionHeight; y++)
90 { 90 {
91 currFileXOffset = 0; 91 currFileXOffset = 0;
92 92
93 // if our region isn't the first X section of the areas to be landscaped, then 93 // if our region isn't the first X section of the areas to be landscaped, then
94 // advance the stream to the X start pos of our section in the file 94 // advance the stream to the X start pos of our section in the file
95 // i.e. eat X upto where we start 95 // i.e. eat X upto where we start
96 while (currFileXOffset < offsetX) 96 while (currFileXOffset < offsetX)
97 { 97 {
98 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single 98 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
99 currFileXOffset++; 99 currFileXOffset++;
100 } 100 }
101 101
102 // got to our X offset, so write our regions X line 102 // got to our X offset, so write our regions X line
103 for (x = 0; x < sectionWidth; x++) 103 for (x = 0; x < sectionWidth; x++)
104 { 104 {
105 // Read a strip and continue 105 // Read a strip and continue
106 retval[x, y] = bs.ReadSingle(); 106 retval[x, y] = bs.ReadSingle();
107 } 107 }
108 // record that we wrote it 108 // record that we wrote it
109 currFileXOffset++; 109 currFileXOffset++;
110 110
111 // if our region isn't the last X section of the areas to be landscaped, then 111 // if our region isn't the last X section of the areas to be landscaped, then
112 // advance the stream to the end of this Y column 112 // advance the stream to the end of this Y column
113 while (currFileXOffset < fileWidth) 113 while (currFileXOffset < fileWidth)
114 { 114 {
115 // eat the next regions x line 115 // eat the next regions x line
116 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single 116 bs.ReadBytes(sectionWidth * 4); // 4 bytes = single
117 currFileXOffset++; 117 currFileXOffset++;
118 } 118 }
119 } 119 }
120 120
121 bs.Close(); 121 bs.Close();
122 s.Close(); 122 s.Close();
123 123
124 return retval; 124 return retval;
125 } 125 }
126 126
127 public void SaveFile(string filename, ITerrainChannel map) 127 public void SaveFile(string filename, ITerrainChannel map)
128 { 128 {
129 FileInfo file = new FileInfo(filename); 129 FileInfo file = new FileInfo(filename);
130 FileStream s = file.Open(FileMode.Create, FileAccess.Write); 130 FileStream s = file.Open(FileMode.Create, FileAccess.Write);
131 BinaryWriter bs = new BinaryWriter(s); 131 BinaryWriter bs = new BinaryWriter(s);
132 132
133 int x, y; 133 int x, y;
134 for (y = 0; y < map.Height; y++) 134 for (y = 0; y < map.Height; y++)
135 { 135 {
136 for (x = 0; x < map.Width; x++) 136 for (x = 0; x < map.Width; x++)
137 { 137 {
138 bs.Write((float) map[x, y]); 138 bs.Write((float) map[x, y]);
139 } 139 }
140 } 140 }
141 141
142 bs.Close(); 142 bs.Close();
143 s.Close(); 143 s.Close();
144 } 144 }
145 145
146 #endregion 146 #endregion
147 147
148 public override string ToString() 148 public override string ToString()
149 { 149 {
150 return "RAW32"; 150 return "RAW32";
151 } 151 }
152 } 152 }
153} \ No newline at end of file 153} \ No newline at end of file