|
1 |
| -use std::error::Error; |
2 | 1 | use std::ops::Range;
|
3 |
| -use std::path::Path; |
4 | 2 |
|
5 | 3 | use super::blocktypes::BlockType;
|
6 | 4 | use super::color;
|
7 | 5 | use super::color::RGBA;
|
8 |
| -use super::image; |
9 | 6 | use super::region;
|
10 | 7 | use super::sizes::*;
|
11 | 8 | use super::types::*;
|
12 | 9 | use super::world::World;
|
13 | 10 |
|
14 |
| -fn draw_chunk(pixels: &mut [u8], blocktypes: &[BlockType], chunk: ®ion::Chunk, co: &isize, |
| 11 | +pub fn get_size(world: &World) -> Pair<usize> { |
| 12 | + Pair { |
| 13 | + x: (world.bsize.x + world.bsize.z) * ISO_BLOCK_X_MARGIN, |
| 14 | + z: (world.bsize.x + world.bsize.z) * ISO_BLOCK_Y_MARGIN + ISO_CHUNK_SIDE_HEIGHT, |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +pub fn get_crop(world: &World, size: &Pair<usize>) -> usize { |
| 19 | + let cbcrop = Edges { |
| 20 | + n: block_pos_in_chunk(world.bedges.n, None), |
| 21 | + e: MAX_BLOCK_IN_CHUNK - block_pos_in_chunk(world.bedges.e, None), |
| 22 | + s: MAX_BLOCK_IN_CHUNK - block_pos_in_chunk(world.bedges.s, None), |
| 23 | + w: block_pos_in_chunk(world.bedges.w, None), |
| 24 | + }; |
| 25 | + (cbcrop.w + cbcrop.n) * ISO_BLOCK_Y_MARGIN * size.x + |
| 26 | + (cbcrop.w + cbcrop.s) * ISO_BLOCK_X_MARGIN |
| 27 | +} |
| 28 | + |
| 29 | +pub fn get_chunk_pixel(world: &World, arc: &Pair<isize>, c: &Pair<usize>) -> Pair<usize> { |
| 30 | + let ac = Pair { |
| 31 | + x: (arc.x + c.x as isize) as usize, |
| 32 | + z: (arc.z + c.z as isize) as usize, |
| 33 | + }; |
| 34 | + Pair { |
| 35 | + x: (ac.x + world.csize.z - ac.z - 1) * ISO_CHUNK_X_MARGIN, |
| 36 | + z: (ac.x + ac.z) * ISO_CHUNK_Y_MARGIN, |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +pub fn draw_chunk(pixels: &mut [u8], blocktypes: &[BlockType], chunk: ®ion::Chunk, co: &isize, |
15 | 41 | width: &usize, cblimits: &Edges<usize>, ylimits: &Range<usize>) {
|
16 | 42 | let blank_color = RGBA::default();
|
17 | 43 |
|
@@ -100,95 +126,3 @@ fn draw_chunk(pixels: &mut [u8], blocktypes: &[BlockType], chunk: ®ion::Chunk
|
100 | 126 | }
|
101 | 127 | }
|
102 | 128 | }
|
103 |
| - |
104 |
| -fn get_size(world: &World) -> Pair<usize> { |
105 |
| - Pair { |
106 |
| - x: (world.bsize.x + world.bsize.z) * ISO_BLOCK_X_MARGIN, |
107 |
| - z: (world.bsize.x + world.bsize.z) * ISO_BLOCK_Y_MARGIN + ISO_CHUNK_SIDE_HEIGHT, |
108 |
| - } |
109 |
| -} |
110 |
| - |
111 |
| -fn get_crop(world: &World, size: &Pair<usize>) -> usize { |
112 |
| - let cbcrop = Edges { |
113 |
| - n: block_pos_in_chunk(world.bedges.n, None), |
114 |
| - e: MAX_BLOCK_IN_CHUNK - block_pos_in_chunk(world.bedges.e, None), |
115 |
| - s: MAX_BLOCK_IN_CHUNK - block_pos_in_chunk(world.bedges.s, None), |
116 |
| - w: block_pos_in_chunk(world.bedges.w, None), |
117 |
| - }; |
118 |
| - (cbcrop.w + cbcrop.n) * ISO_BLOCK_Y_MARGIN * size.x + |
119 |
| - (cbcrop.w + cbcrop.s) * ISO_BLOCK_X_MARGIN |
120 |
| -} |
121 |
| - |
122 |
| -fn get_chunk_pixel(world: &World, arc: &Pair<isize>, c: &Pair<usize>) -> Pair<usize> { |
123 |
| - let ac = Pair { |
124 |
| - x: (arc.x + c.x as isize) as usize, |
125 |
| - z: (arc.z + c.z as isize) as usize, |
126 |
| - }; |
127 |
| - Pair { |
128 |
| - x: (ac.x + world.csize.z - ac.z - 1) * ISO_CHUNK_X_MARGIN, |
129 |
| - z: (ac.x + ac.z) * ISO_CHUNK_Y_MARGIN, |
130 |
| - } |
131 |
| -} |
132 |
| - |
133 |
| -pub fn draw_iso_map(world: &World, outpath: &Path, blocktypes: &[BlockType]) |
134 |
| --> Result<(), Box<Error>> { |
135 |
| - let size = get_size(world); |
136 |
| - let crop = get_crop(world, &size); |
137 |
| - let mut pixels = vec![0u8; size.x * size.z * 4]; |
138 |
| - |
139 |
| - let mut i = 0; |
140 |
| - let len = world.regions.len(); |
141 |
| - |
142 |
| - for rz in (world.redges.n..world.redges.s + 1).rev() { |
143 |
| - for rx in (world.redges.w..world.redges.e + 1).rev() { |
144 |
| - let r = &Pair { x: rx, z: rz }; |
145 |
| - if !world.regions.contains_key(&r) { |
146 |
| - continue; |
147 |
| - } |
148 |
| - |
149 |
| - i += 1; |
150 |
| - println!("Reading block data for region {}, {} ({}/{})", r.x, r.z, i, len); |
151 |
| - if let Some(reg) = region::read_region_data(&world, r, blocktypes)? { |
152 |
| - let chunk_count = reg.chunks.len(); |
153 |
| - println!("Drawing block map for region {}, {} ({} chunk{})", r.x, r.z, |
154 |
| - chunk_count, if chunk_count == 1 { "" } else { "s" }); |
155 |
| - |
156 |
| - let arc = &Pair { |
157 |
| - x: r.x * CHUNKS_IN_REGION as isize - world.cedges.w, |
158 |
| - z: r.z * CHUNKS_IN_REGION as isize - world.cedges.n, |
159 |
| - }; |
160 |
| - |
161 |
| - for cz in (0..CHUNKS_IN_REGION).rev() { |
162 |
| - for cx in (0..CHUNKS_IN_REGION).rev() { |
163 |
| - let c = &Pair { x: cx, z: cz }; |
164 |
| - if let Some(chunk) = reg.get_chunk(c) { |
165 |
| - // println!("Drawing chunk {}, {}", c.x, c.z); |
166 |
| - let wc = Pair { |
167 |
| - x: r.x * CHUNKS_IN_REGION as isize + c.x as isize, |
168 |
| - z: r.z * CHUNKS_IN_REGION as isize + c.z as isize, |
169 |
| - }; |
170 |
| - let cblimits = Edges { |
171 |
| - n: block_pos_in_chunk(world.bedges.n, Some(wc.z)), |
172 |
| - e: block_pos_in_chunk(world.bedges.e, Some(wc.x)), |
173 |
| - s: block_pos_in_chunk(world.bedges.s, Some(wc.z)), |
174 |
| - w: block_pos_in_chunk(world.bedges.w, Some(wc.x)), |
175 |
| - }; |
176 |
| - |
177 |
| - let cp = get_chunk_pixel(world, arc, c); |
178 |
| - let co = (cp.z * size.x + cp.x) as isize - crop as isize; |
179 |
| - |
180 |
| - draw_chunk(&mut pixels, blocktypes, &chunk, &co, &size.x, &cblimits, |
181 |
| - world.ylimits); |
182 |
| - } |
183 |
| - } |
184 |
| - } |
185 |
| - } else { |
186 |
| - println!("No data in region."); |
187 |
| - } |
188 |
| - } |
189 |
| - } |
190 |
| - |
191 |
| - image::draw_block_map(&pixels, size, outpath, true)?; |
192 |
| - |
193 |
| - Ok(()) |
194 |
| -} |
0 commit comments