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