diff options
Diffstat (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs')
-rw-r--r-- | OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs | 170 |
1 files changed, 0 insertions, 170 deletions
diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs b/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs deleted file mode 100644 index 7aff56a..0000000 --- a/OpenSim/Region/Environment/Modules/World/Terrain/FileLoaders/RAW32.cs +++ /dev/null | |||
@@ -1,170 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
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 | ||
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 | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.IO; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | using OpenSim.Region.Framework.Scenes; | ||
31 | |||
32 | namespace OpenSim.Region.Environment.Modules.World.Terrain.FileLoaders | ||
33 | { | ||
34 | public class RAW32 : ITerrainLoader | ||
35 | { | ||
36 | #region ITerrainLoader Members | ||
37 | |||
38 | public string FileExtension | ||
39 | { | ||
40 | get { return ".r32"; } | ||
41 | } | ||
42 | |||
43 | public ITerrainChannel LoadFile(string filename) | ||
44 | { | ||
45 | FileInfo file = new FileInfo(filename); | ||
46 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
47 | ITerrainChannel retval = LoadStream(s); | ||
48 | |||
49 | s.Close(); | ||
50 | |||
51 | return retval; | ||
52 | } | ||
53 | |||
54 | public ITerrainChannel LoadFile(string filename, int offsetX, int offsetY, int fileWidth, int fileHeight, int sectionWidth, int sectionHeight) | ||
55 | { | ||
56 | TerrainChannel retval = new TerrainChannel(sectionWidth, sectionHeight); | ||
57 | |||
58 | FileInfo file = new FileInfo(filename); | ||
59 | FileStream s = file.Open(FileMode.Open, FileAccess.Read); | ||
60 | BinaryReader bs = new BinaryReader(s); | ||
61 | |||
62 | int currFileYOffset = 0; | ||
63 | |||
64 | // if our region isn't on the first Y section of the areas to be landscaped, then | ||
65 | // advance to our section of the file | ||
66 | while (currFileYOffset < offsetY) | ||
67 | { | ||
68 | // read a whole strip of regions | ||
69 | int heightsToRead = sectionHeight * (fileWidth * sectionWidth); | ||
70 | bs.ReadBytes(heightsToRead * 4); // because the floats are 4 bytes in the file | ||
71 | currFileYOffset++; | ||
72 | } | ||
73 | |||
74 | // got to the Y start offset within the file of our region | ||
75 | // so read the file bits associated with our region | ||
76 | int y; | ||
77 | // for each Y within our Y offset | ||
78 | for (y = 0; y < sectionHeight; y++) | ||
79 | { | ||
80 | int currFileXOffset = 0; | ||
81 | |||
82 | // if our region isn't the first X section of the areas to be landscaped, then | ||
83 | // advance the stream to the X start pos of our section in the file | ||
84 | // i.e. eat X upto where we start | ||
85 | while (currFileXOffset < offsetX) | ||
86 | { | ||
87 | bs.ReadBytes(sectionWidth * 4); // 4 bytes = single | ||
88 | currFileXOffset++; | ||
89 | } | ||
90 | |||
91 | // got to our X offset, so write our regions X line | ||
92 | int x; | ||
93 | for (x = 0; x < sectionWidth; x++) | ||
94 | { | ||
95 | // Read a strip and continue | ||
96 | retval[x, y] = bs.ReadSingle(); | ||
97 | } | ||
98 | // record that we wrote it | ||
99 | currFileXOffset++; | ||
100 | |||
101 | // if our region isn't the last X section of the areas to be landscaped, then | ||
102 | // advance the stream to the end of this Y column | ||
103 | while (currFileXOffset < fileWidth) | ||
104 | { | ||
105 | // eat the next regions x line | ||
106 | bs.ReadBytes(sectionWidth * 4); // 4 bytes = single | ||
107 | currFileXOffset++; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | bs.Close(); | ||
112 | s.Close(); | ||
113 | |||
114 | return retval; | ||
115 | } | ||
116 | |||
117 | public ITerrainChannel LoadStream(Stream s) | ||
118 | { | ||
119 | TerrainChannel retval = new TerrainChannel(); | ||
120 | |||
121 | BinaryReader bs = new BinaryReader(s); | ||
122 | int y; | ||
123 | for (y = 0; y < retval.Height; y++) | ||
124 | { | ||
125 | int x; | ||
126 | for (x = 0; x < retval.Width; x++) | ||
127 | { | ||
128 | retval[x, y] = bs.ReadSingle(); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | bs.Close(); | ||
133 | |||
134 | return retval; | ||
135 | } | ||
136 | |||
137 | public void SaveFile(string filename, ITerrainChannel map) | ||
138 | { | ||
139 | FileInfo file = new FileInfo(filename); | ||
140 | FileStream s = file.Open(FileMode.Create, FileAccess.Write); | ||
141 | SaveStream(s, map); | ||
142 | |||
143 | s.Close(); | ||
144 | } | ||
145 | |||
146 | public void SaveStream(Stream s, ITerrainChannel map) | ||
147 | { | ||
148 | BinaryWriter bs = new BinaryWriter(s); | ||
149 | |||
150 | int y; | ||
151 | for (y = 0; y < map.Height; y++) | ||
152 | { | ||
153 | int x; | ||
154 | for (x = 0; x < map.Width; x++) | ||
155 | { | ||
156 | bs.Write((float) map[x, y]); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | bs.Close(); | ||
161 | } | ||
162 | |||
163 | #endregion | ||
164 | |||
165 | public override string ToString() | ||
166 | { | ||
167 | return "RAW32"; | ||
168 | } | ||
169 | } | ||
170 | } | ||