author | nemo |
Mon, 10 Feb 2025 09:52:32 -0500 | |
changeset 16117 | cb472e3d0dd4 |
parent 16102 | 5d302b12d837 |
permissions | -rw-r--r-- |
16068 | 1 |
mod ai; |
2 |
||
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
3 |
use integral_geometry::{Point, Size}; |
16117 | 4 |
use core::ffi::c_char; |
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
5 |
|
16078 | 6 |
use ai::*; |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
7 |
use landgen::{ |
16078 | 8 |
maze::MazeTemplate, outline_template_based::outline_template::OutlineTemplate, |
16058 | 9 |
wavefront_collapse::generator::TemplateDescription as WfcTemplate, LandGenerationParameters, |
10 |
LandGenerator, |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
11 |
}; |
15933 | 12 |
use lfprng::LaggedFibonacciPRNG; |
13 |
use mapgen::{theme::Theme, MapGenerator}; |
|
14 |
use std::fs; |
|
16082 | 15 |
use std::ptr::slice_from_raw_parts; |
15933 | 16 |
use std::{ffi::CStr, path::Path}; |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
17 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
18 |
#[repr(C)] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
19 |
pub struct GameField { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
20 |
collision: land2d::Land2D<u16>, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
21 |
pixels: land2d::Land2D<u32>, |
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
22 |
landgen_parameters: Option<LandGenerationParameters<u16>>, |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
23 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
24 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
25 |
#[no_mangle] |
15933 | 26 |
pub extern "C" fn get_game_field_parameters( |
27 |
game_field: &GameField, |
|
16078 | 28 |
width: &mut i32, |
29 |
height: &mut i32, |
|
30 |
play_width: &mut i32, |
|
31 |
play_height: &mut i32, |
|
15933 | 32 |
) { |
16078 | 33 |
*width = game_field.collision.width() as i32; |
34 |
*height = game_field.collision.height() as i32; |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
35 |
|
16078 | 36 |
*play_width = game_field.collision.play_width() as i32; |
37 |
*play_height = game_field.collision.play_height() as i32; |
|
15933 | 38 |
} |
39 |
||
40 |
#[no_mangle] |
|
41 |
pub extern "C" fn create_empty_game_field(width: u32, height: u32) -> *mut GameField { |
|
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
42 |
let game_field = Box::new(GameField { |
16102 | 43 |
collision: land2d::Land2D::new(&Size::new(width, height), 0), |
44 |
pixels: land2d::Land2D::new(&Size::new(width, height), 0), |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
45 |
landgen_parameters: None, |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
46 |
}); |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
47 |
|
16068 | 48 |
Box::into_raw(game_field) |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
49 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
50 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
51 |
#[no_mangle] |
16078 | 52 |
pub unsafe extern "C" fn generate_outline_templated_game_field( |
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
53 |
feature_size: u32, |
16117 | 54 |
seed: *const c_char, |
55 |
template_type: *const c_char, |
|
56 |
data_path: *const c_char, |
|
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
57 |
) -> *mut GameField { |
16078 | 58 |
let data_path: &str = CStr::from_ptr(data_path).to_str().unwrap(); |
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
59 |
let data_path = Path::new(&data_path); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
60 |
|
16078 | 61 |
let seed: &str = CStr::from_ptr(seed).to_str().unwrap(); |
62 |
let template_type: &str = CStr::from_ptr(template_type).to_str().unwrap(); |
|
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
63 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
64 |
let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes()); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
65 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
66 |
let yaml_templates = |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
67 |
fs::read_to_string(data_path.join(Path::new("map_templates.yaml")).as_path()) |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
68 |
.expect("Error reading map templates file"); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
69 |
let mut map_gen = MapGenerator::<OutlineTemplate>::new(data_path); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
70 |
map_gen.import_yaml_templates(&yaml_templates); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
71 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
72 |
let distance_divisor = feature_size.pow(2) / 8 + 10; |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
73 |
let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
74 |
let template = map_gen |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
75 |
.get_template(template_type, &mut random_numbers_gen) |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
76 |
.expect("Error reading outline templates file") |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
77 |
.clone(); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
78 |
let landgen = map_gen.build_generator(template); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
79 |
let collision = landgen.generate_land(¶ms, &mut random_numbers_gen); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
80 |
let size = collision.size().size(); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
81 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
82 |
let game_field = Box::new(GameField { |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
83 |
collision, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
84 |
pixels: land2d::Land2D::new(&size, 0), |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
85 |
landgen_parameters: Some(params), |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
86 |
}); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
87 |
|
16068 | 88 |
Box::into_raw(game_field) |
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
89 |
} |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
90 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
91 |
#[no_mangle] |
16078 | 92 |
pub unsafe extern "C" fn generate_wfc_templated_game_field( |
15933 | 93 |
feature_size: u32, |
16117 | 94 |
seed: *const c_char, |
95 |
template_type: *const c_char, |
|
96 |
data_path: *const c_char, |
|
15933 | 97 |
) -> *mut GameField { |
16078 | 98 |
let data_path: &str = CStr::from_ptr(data_path).to_str().unwrap(); |
15933 | 99 |
let data_path = Path::new(&data_path); |
100 |
||
16078 | 101 |
let seed: &str = CStr::from_ptr(seed).to_str().unwrap(); |
102 |
let template_type: &str = CStr::from_ptr(template_type).to_str().unwrap(); |
|
15933 | 103 |
|
104 |
let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes()); |
|
105 |
||
106 |
let yaml_templates = |
|
16094 | 107 |
fs::read_to_string(data_path.join(Path::new("wfc_templates.toml")).as_path()) |
15933 | 108 |
.expect("Error reading map templates file"); |
16053 | 109 |
let mut map_gen = MapGenerator::<WfcTemplate>::new(data_path); |
15933 | 110 |
map_gen.import_yaml_templates(&yaml_templates); |
111 |
||
112 |
let template = map_gen |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
113 |
.get_template(template_type, &mut random_numbers_gen) |
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
114 |
.expect("Error reading wfc templates file") |
15933 | 115 |
.clone(); |
16091 | 116 |
let (zero, basic) = |
117 |
if template.is_negative || (template.can_invert && random_numbers_gen.get_random(2) == 0) { |
|
118 |
(0x8000u16, 0u16) |
|
119 |
} else { |
|
120 |
(0u16, 0x8000u16) |
|
121 |
}; |
|
122 |
let params = LandGenerationParameters::new(zero, basic, feature_size, false, false); |
|
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
123 |
let landgen = map_gen.build_generator(template); |
15933 | 124 |
let collision = landgen.generate_land(¶ms, &mut random_numbers_gen); |
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
125 |
let size = collision.size().size(); |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
126 |
|
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
127 |
let game_field = Box::new(GameField { |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
128 |
collision, |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
129 |
pixels: land2d::Land2D::new(&size, 0), |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
130 |
landgen_parameters: Some(params), |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
131 |
}); |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
132 |
|
16068 | 133 |
Box::into_raw(game_field) |
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
134 |
} |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
135 |
|
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
136 |
#[no_mangle] |
16078 | 137 |
pub unsafe extern "C" fn generate_maze_game_field( |
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
138 |
feature_size: u32, |
16117 | 139 |
seed: *const c_char, |
140 |
template_type: *const c_char, |
|
141 |
data_path: *const c_char, |
|
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
142 |
) -> *mut GameField { |
16078 | 143 |
let data_path: &str = CStr::from_ptr(data_path).to_str().unwrap(); |
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
144 |
let data_path = Path::new(&data_path); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
145 |
|
16078 | 146 |
let seed: &str = CStr::from_ptr(seed).to_str().unwrap(); |
147 |
let template_type: &str = CStr::from_ptr(template_type).to_str().unwrap(); |
|
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
148 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
149 |
let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes()); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
150 |
|
16064 | 151 |
let yaml_templates = |
152 |
fs::read_to_string(data_path.join(Path::new("maze_templates.yaml")).as_path()) |
|
153 |
.expect("Error reading map templates file"); |
|
154 |
||
155 |
let mut map_gen = MapGenerator::<MazeTemplate>::new(data_path); |
|
156 |
map_gen.import_yaml_templates(&yaml_templates); |
|
157 |
||
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
158 |
let distance_divisor = feature_size.pow(2) / 8 + 10; |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
159 |
let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false); |
16064 | 160 |
|
161 |
let template = map_gen |
|
162 |
.get_template(template_type, &mut random_numbers_gen) |
|
163 |
.expect("Error reading maze templates file") |
|
164 |
.clone(); |
|
165 |
||
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
166 |
let landgen = map_gen.build_generator(template); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
167 |
let collision = landgen.generate_land(¶ms, &mut random_numbers_gen); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
168 |
let size = collision.size().size(); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
169 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
170 |
let game_field = Box::new(GameField { |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
171 |
collision, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
172 |
pixels: land2d::Land2D::new(&size, 0), |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
173 |
landgen_parameters: Some(params), |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
174 |
}); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
175 |
|
16068 | 176 |
Box::into_raw(game_field) |
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
177 |
} |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
178 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
179 |
#[no_mangle] |
16078 | 180 |
pub unsafe extern "C" fn apply_theme( |
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
181 |
game_field: &mut GameField, |
16117 | 182 |
data_path: *const c_char, |
183 |
theme_name: *const c_char, |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
184 |
) { |
16078 | 185 |
let data_path: &str = CStr::from_ptr(data_path).to_str().unwrap(); |
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
186 |
let data_path = Path::new(&data_path); |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
187 |
|
16078 | 188 |
let theme_name: &str = CStr::from_ptr(theme_name).to_str().unwrap(); |
16053 | 189 |
let map_gen = MapGenerator::<()>::new(data_path); |
15933 | 190 |
|
191 |
let theme = Theme::load( |
|
192 |
data_path |
|
193 |
.join(Path::new("Themes")) |
|
194 |
.join(Path::new(theme_name)) |
|
195 |
.as_path(), |
|
196 |
) |
|
197 |
.unwrap(); |
|
198 |
||
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
199 |
let params = game_field |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
200 |
.landgen_parameters |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
201 |
.expect("Land generator parameters specified"); |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
202 |
let pixels = map_gen.make_texture(&game_field.collision, ¶ms, &theme); |
15933 | 203 |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
204 |
game_field.pixels = pixels.into(); |
15933 | 205 |
} |
206 |
||
207 |
#[no_mangle] |
|
15942 | 208 |
pub extern "C" fn land_get(game_field: &GameField, x: i32, y: i32) -> u16 { |
209 |
game_field.collision.get(y, x) |
|
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
210 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
211 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
212 |
#[no_mangle] |
15930
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
213 |
pub extern "C" fn land_set(game_field: &mut GameField, x: i32, y: i32, value: u16) { |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
214 |
game_field.collision.map(y, x, |p| *p = value); |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
215 |
} |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
216 |
|
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
217 |
#[no_mangle] |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
218 |
pub extern "C" fn land_row(game_field: &mut GameField, row: i32) -> *mut u16 { |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
219 |
game_field.collision[row as usize].as_mut_ptr() |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
220 |
} |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
221 |
|
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
222 |
#[no_mangle] |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
223 |
pub extern "C" fn land_fill( |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
224 |
game_field: &mut GameField, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
225 |
x: i32, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
226 |
y: i32, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
227 |
border_value: u16, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
228 |
fill_value: u16, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
229 |
) { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
230 |
game_field |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
231 |
.collision |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
232 |
.fill(Point::new(x, y), border_value, fill_value) |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
233 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
234 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
235 |
#[no_mangle] |
15942 | 236 |
pub extern "C" fn land_pixel_get(game_field: &GameField, x: i32, y: i32) -> u32 { |
237 |
game_field.pixels.get(y, x) |
|
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
238 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
239 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
240 |
#[no_mangle] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
241 |
pub extern "C" fn land_pixel_set(game_field: &mut GameField, x: i32, y: i32, value: u32) { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
242 |
game_field.pixels.map(y, x, |p| *p = value); |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
243 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
244 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
245 |
#[no_mangle] |
15930
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
246 |
pub extern "C" fn land_pixel_row(game_field: &mut GameField, row: i32) -> *mut u32 { |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
247 |
game_field.pixels[row as usize].as_mut_ptr() |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
248 |
} |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
249 |
|
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
250 |
#[no_mangle] |
16078 | 251 |
pub unsafe extern "C" fn dispose_game_field(game_field: *mut GameField) { |
252 |
drop(Box::from_raw(game_field)); |
|
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
253 |
} |
16068 | 254 |
|
255 |
#[no_mangle] |
|
256 |
pub extern "C" fn create_ai(game_field: &GameField) -> *mut AI { |
|
257 |
Box::into_raw(Box::new(AI::new(game_field))) |
|
258 |
} |
|
259 |
||
260 |
#[no_mangle] |
|
261 |
pub extern "C" fn ai_clear_team(ai: &mut AI) { |
|
262 |
*ai.get_team_mut() = vec![]; |
|
263 |
} |
|
264 |
||
265 |
#[no_mangle] |
|
16082 | 266 |
pub unsafe extern "C" fn ai_add_team_hedgehog( |
267 |
ai: &mut AI, |
|
268 |
x: f32, |
|
269 |
y: f32, |
|
270 |
ammo_counts: *const u32, |
|
271 |
) { |
|
272 |
let ammo_counts = |
|
273 |
&*slice_from_raw_parts(ammo_counts, crate::ai::ammo::AmmoType::Count as usize); |
|
16078 | 274 |
let ammo_counts = std::array::from_fn(|i| ammo_counts[i].clone()); |
275 |
||
16082 | 276 |
ai.get_team_mut().push(Hedgehog { |
277 |
x, |
|
278 |
y, |
|
279 |
ammo: ammo_counts, |
|
280 |
}); |
|
16068 | 281 |
} |
282 |
||
283 |
#[no_mangle] |
|
16078 | 284 |
pub extern "C" fn ai_think(ai: &AI) {} |
16068 | 285 |
|
286 |
#[no_mangle] |
|
16069 | 287 |
pub extern "C" fn ai_have_plan(ai: &AI) -> bool { |
288 |
ai.have_plan() |
|
289 |
} |
|
290 |
||
291 |
#[no_mangle] |
|
292 |
pub extern "C" fn ai_get(ai: &AI) -> bool { |
|
293 |
ai.have_plan() |
|
294 |
} |
|
295 |
||
296 |
#[no_mangle] |
|
16078 | 297 |
pub unsafe extern "C" fn dispose_ai(ai: *mut AI) { |
298 |
drop(Box::from_raw(ai)); |
|
16069 | 299 |
} |