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