author | unC0Rr |
Mon, 16 Sep 2024 16:57:11 +0200 | |
branch | transitional_engine |
changeset 16063 | 09beeec033ba |
parent 16062 | 1860852892c0 |
child 16064 | 0caa3dfb3ba2 |
permissions | -rw-r--r-- |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
1 |
use integral_geometry::{Point, Size}; |
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
2 |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
3 |
use landgen::{ |
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
4 |
outline_template_based::outline_template::OutlineTemplate, |
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
5 |
maze::MazeTemplate, |
16058 | 6 |
wavefront_collapse::generator::TemplateDescription as WfcTemplate, LandGenerationParameters, |
7 |
LandGenerator, |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
8 |
}; |
15933 | 9 |
use lfprng::LaggedFibonacciPRNG; |
10 |
use mapgen::{theme::Theme, MapGenerator}; |
|
11 |
use std::fs; |
|
12 |
use std::{ffi::CStr, path::Path}; |
|
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
13 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
14 |
#[repr(C)] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
15 |
pub struct GameField { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
16 |
collision: land2d::Land2D<u16>, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
17 |
pixels: land2d::Land2D<u32>, |
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
18 |
landgen_parameters: Option<LandGenerationParameters<u16>>, |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
19 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
20 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
21 |
#[no_mangle] |
15933 | 22 |
pub extern "C" fn get_game_field_parameters( |
23 |
game_field: &GameField, |
|
24 |
width: *mut i32, |
|
25 |
height: *mut i32, |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
26 |
play_width: *mut i32, |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
27 |
play_height: *mut i32, |
15933 | 28 |
) { |
29 |
unsafe { |
|
30 |
*width = game_field.collision.width() as i32; |
|
31 |
*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
|
32 |
|
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
33 |
*play_width = game_field.collision.play_width() as i32; |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
34 |
*play_height = game_field.collision.play_height() as i32; |
15933 | 35 |
} |
36 |
} |
|
37 |
||
38 |
#[no_mangle] |
|
39 |
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
|
40 |
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
|
41 |
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
|
42 |
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
|
43 |
landgen_parameters: None, |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
44 |
}); |
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 |
Box::leak(game_field) |
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 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
49 |
#[no_mangle] |
16055
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
50 |
pub extern "C" fn generate_outline_templated_game_field( |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
51 |
feature_size: u32, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
52 |
seed: *const i8, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
53 |
template_type: *const i8, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
54 |
data_path: *const i8, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
55 |
) -> *mut GameField { |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
56 |
let data_path: &str = unsafe { CStr::from_ptr(data_path) }.to_str().unwrap(); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
57 |
let data_path = Path::new(&data_path); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
58 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
59 |
let seed: &str = unsafe { CStr::from_ptr(seed) }.to_str().unwrap(); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
60 |
let template_type: &str = unsafe { CStr::from_ptr(template_type) }.to_str().unwrap(); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
61 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
62 |
let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes()); |
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 yaml_templates = |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
65 |
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
|
66 |
.expect("Error reading map templates file"); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
67 |
let mut map_gen = MapGenerator::<OutlineTemplate>::new(data_path); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
68 |
map_gen.import_yaml_templates(&yaml_templates); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
69 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
70 |
let distance_divisor = feature_size.pow(2) / 8 + 10; |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
71 |
let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
72 |
let template = map_gen |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
73 |
.get_template(template_type, &mut random_numbers_gen) |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
74 |
.expect("Error reading outline templates file") |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
75 |
.clone(); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
76 |
let landgen = map_gen.build_generator(template); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
77 |
let collision = landgen.generate_land(¶ms, &mut random_numbers_gen); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
78 |
let size = collision.size().size(); |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
79 |
|
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
80 |
let game_field = Box::new(GameField { |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
81 |
collision, |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
82 |
pixels: land2d::Land2D::new(&size, 0), |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
83 |
landgen_parameters: Some(params), |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
84 |
}); |
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 |
Box::leak(game_field) |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
87 |
} |
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 |
#[no_mangle] |
ce4b50823a95
Allow switching between outline and wfc map generators
unC0Rr
parents:
16053
diff
changeset
|
90 |
pub extern "C" fn generate_wfc_templated_game_field( |
15933 | 91 |
feature_size: u32, |
92 |
seed: *const i8, |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
93 |
template_type: *const i8, |
15933 | 94 |
data_path: *const i8, |
95 |
) -> *mut GameField { |
|
96 |
let data_path: &str = unsafe { CStr::from_ptr(data_path) }.to_str().unwrap(); |
|
97 |
let data_path = Path::new(&data_path); |
|
98 |
||
99 |
let seed: &str = unsafe { CStr::from_ptr(seed) }.to_str().unwrap(); |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
100 |
let template_type: &str = unsafe { CStr::from_ptr(template_type) }.to_str().unwrap(); |
15933 | 101 |
|
102 |
let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes()); |
|
103 |
||
104 |
let yaml_templates = |
|
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
105 |
fs::read_to_string(data_path.join(Path::new("wfc_templates.yaml")).as_path()) |
15933 | 106 |
.expect("Error reading map templates file"); |
16053 | 107 |
let mut map_gen = MapGenerator::<WfcTemplate>::new(data_path); |
15933 | 108 |
map_gen.import_yaml_templates(&yaml_templates); |
109 |
||
110 |
let distance_divisor = feature_size.pow(2) / 8 + 10; |
|
111 |
let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false); |
|
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(); |
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
116 |
let landgen = map_gen.build_generator(template); |
15933 | 117 |
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
|
118 |
let size = collision.size().size(); |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
119 |
|
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
120 |
let game_field = Box::new(GameField { |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
121 |
collision, |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
122 |
pixels: land2d::Land2D::new(&size, 0), |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
123 |
landgen_parameters: Some(params), |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
124 |
}); |
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 |
Box::leak(game_field) |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
127 |
} |
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 |
#[no_mangle] |
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
130 |
pub extern "C" fn generate_maze_game_field( |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
131 |
feature_size: u32, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
132 |
seed: *const i8, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
133 |
template_type: *const i8, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
134 |
data_path: *const i8, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
135 |
) -> *mut GameField { |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
136 |
let data_path: &str = unsafe { CStr::from_ptr(data_path) }.to_str().unwrap(); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
137 |
let data_path = Path::new(&data_path); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
138 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
139 |
let seed: &str = unsafe { CStr::from_ptr(seed) }.to_str().unwrap(); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
140 |
let template_type: &str = unsafe { CStr::from_ptr(template_type) }.to_str().unwrap(); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
141 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
142 |
let mut random_numbers_gen = LaggedFibonacciPRNG::new(seed.as_bytes()); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
143 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
144 |
let map_gen = MapGenerator::<MazeTemplate>::new(data_path); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
145 |
let distance_divisor = feature_size.pow(2) / 8 + 10; |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
146 |
let params = LandGenerationParameters::new(0u16, 0x8000u16, distance_divisor, false, false); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
147 |
let template = MazeTemplate { |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
148 |
width: 4096, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
149 |
height: 2048, |
16063 | 150 |
cell_size: 225, |
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
151 |
inverted: false, |
16063 | 152 |
distortion_limiting_factor: 120, |
16062
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
153 |
braidness: 10, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
154 |
}; |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
155 |
let landgen = map_gen.build_generator(template); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
156 |
let collision = landgen.generate_land(¶ms, &mut random_numbers_gen); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
157 |
let size = collision.size().size(); |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
158 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
159 |
let game_field = Box::new(GameField { |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
160 |
collision, |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
161 |
pixels: land2d::Land2D::new(&size, 0), |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
162 |
landgen_parameters: Some(params), |
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 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
165 |
Box::leak(game_field) |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
166 |
} |
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
167 |
|
1860852892c0
Use rust implementation of maze generator in engine
unC0Rr
parents:
16058
diff
changeset
|
168 |
#[no_mangle] |
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
169 |
pub extern "C" fn apply_theme( |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
170 |
game_field: &mut GameField, |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
171 |
data_path: *const i8, |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
172 |
theme_name: *const i8, |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
173 |
) { |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
174 |
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:
15933
diff
changeset
|
175 |
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
|
176 |
|
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
177 |
let theme_name: &str = unsafe { CStr::from_ptr(theme_name) }.to_str().unwrap(); |
16053 | 178 |
let map_gen = MapGenerator::<()>::new(data_path); |
15933 | 179 |
|
180 |
let theme = Theme::load( |
|
181 |
data_path |
|
182 |
.join(Path::new("Themes")) |
|
183 |
.join(Path::new(theme_name)) |
|
184 |
.as_path(), |
|
185 |
) |
|
186 |
.unwrap(); |
|
187 |
||
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
188 |
let params = game_field |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
189 |
.landgen_parameters |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
190 |
.expect("Land generator parameters specified"); |
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
191 |
let pixels = map_gen.make_texture(&game_field.collision, ¶ms, &theme); |
15933 | 192 |
|
15934
022ec6b916b7
Split generation and painting phases, paint by old engine, use template filters
unC0Rr
parents:
15933
diff
changeset
|
193 |
game_field.pixels = pixels.into(); |
15933 | 194 |
} |
195 |
||
196 |
#[no_mangle] |
|
15942 | 197 |
pub extern "C" fn land_get(game_field: &GameField, x: i32, y: i32) -> u16 { |
198 |
game_field.collision.get(y, x) |
|
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
199 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
200 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
201 |
#[no_mangle] |
15930
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
202 |
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
|
203 |
game_field.collision.map(y, x, |p| *p = value); |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
204 |
} |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
205 |
|
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
206 |
#[no_mangle] |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
207 |
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
|
208 |
game_field.collision[row as usize].as_mut_ptr() |
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] |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
212 |
pub extern "C" fn land_fill( |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
213 |
game_field: &mut GameField, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
214 |
x: i32, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
215 |
y: i32, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
216 |
border_value: u16, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
217 |
fill_value: u16, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
218 |
) { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
219 |
game_field |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
220 |
.collision |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
221 |
.fill(Point::new(x, y), border_value, fill_value) |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
222 |
} |
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 |
#[no_mangle] |
15942 | 225 |
pub extern "C" fn land_pixel_get(game_field: &GameField, x: i32, y: i32) -> u32 { |
226 |
game_field.pixels.get(y, x) |
|
15929
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] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
230 |
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
|
231 |
game_field.pixels.map(y, x, |p| *p = value); |
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] |
15930
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
235 |
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
|
236 |
game_field.pixels[row as usize].as_mut_ptr() |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
237 |
} |
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
238 |
|
f39f0f614dbf
Use LandPixels array allocate in hwengine-future library
unC0Rr
parents:
15929
diff
changeset
|
239 |
#[no_mangle] |
15929
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
240 |
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
|
241 |
unsafe { drop(Box::from_raw(game_field)) }; |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
242 |
} |