1 use integral_geometry::{Point, Size}; |
1 use integral_geometry::{Point, Size}; |
2 |
2 |
3 use landgen::{ |
3 use landgen::{ |
4 outline_template_based::outline_template::OutlineTemplate, |
4 outline_template_based::outline_template::OutlineTemplate, |
|
5 maze::MazeTemplate, |
5 wavefront_collapse::generator::TemplateDescription as WfcTemplate, LandGenerationParameters, |
6 wavefront_collapse::generator::TemplateDescription as WfcTemplate, LandGenerationParameters, |
6 LandGenerator, |
7 LandGenerator, |
7 }; |
8 }; |
8 use lfprng::LaggedFibonacciPRNG; |
9 use lfprng::LaggedFibonacciPRNG; |
9 use mapgen::{theme::Theme, MapGenerator}; |
10 use mapgen::{theme::Theme, MapGenerator}; |
124 |
125 |
125 Box::leak(game_field) |
126 Box::leak(game_field) |
126 } |
127 } |
127 |
128 |
128 #[no_mangle] |
129 #[no_mangle] |
|
130 pub extern "C" fn generate_maze_game_field( |
|
131 feature_size: u32, |
|
132 seed: *const i8, |
|
133 template_type: *const i8, |
|
134 data_path: *const i8, |
|
135 ) -> *mut GameField { |
|
136 let data_path: &str = unsafe { CStr::from_ptr(data_path) }.to_str().unwrap(); |
|
137 let data_path = Path::new(&data_path); |
|
138 |
|
139 let seed: &str = unsafe { CStr::from_ptr(seed) }.to_str().unwrap(); |
|
140 let template_type: &str = unsafe { CStr::from_ptr(template_type) }.to_str().unwrap(); |
|
141 |
|
142 let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes()); |
|
143 |
|
144 let map_gen = MapGenerator::<MazeTemplate>::new(data_path); |
|
145 let distance_divisor = feature_size.pow(2) / 8 + 10; |
|
146 let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false); |
|
147 let template = MazeTemplate { |
|
148 width: 4096, |
|
149 height: 2048, |
|
150 cell_size: 80, |
|
151 inverted: false, |
|
152 distortion_limiting_factor: 100, |
|
153 braidness: 10, |
|
154 }; |
|
155 let landgen = map_gen.build_generator(template); |
|
156 let collision = landgen.generate_land(¶ms, &mut random_numbers_gen); |
|
157 let size = collision.size().size(); |
|
158 |
|
159 let game_field = Box::new(GameField { |
|
160 collision, |
|
161 pixels: land2d::Land2D::new(&size, 0), |
|
162 landgen_parameters: Some(params), |
|
163 }); |
|
164 |
|
165 Box::leak(game_field) |
|
166 } |
|
167 |
|
168 #[no_mangle] |
129 pub extern "C" fn apply_theme( |
169 pub extern "C" fn apply_theme( |
130 game_field: &mut GameField, |
170 game_field: &mut GameField, |
131 data_path: *const i8, |
171 data_path: *const i8, |
132 theme_name: *const i8, |
172 theme_name: *const i8, |
133 ) { |
173 ) { |