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