author | unC0Rr |
Mon, 02 Jan 2023 15:59:26 +0100 | |
branch | transitional_engine |
changeset 15900 | 128ace913837 |
child 15901 | f39f0f614dbf |
permissions | -rw-r--r-- |
15900
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
1 |
use integral_geometry::{Point, Size}; |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
2 |
use land2d; |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
3 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
4 |
#[repr(C)] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
5 |
pub struct GameField { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
6 |
collision: land2d::Land2D<u16>, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
7 |
pixels: land2d::Land2D<u32>, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
8 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
9 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
10 |
#[no_mangle] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
11 |
pub extern "C" fn create_game_field(width: u32, height: u32) -> *mut GameField { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
12 |
let game_field = Box::new(GameField { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
13 |
collision: land2d::Land2D::new(Size::new(width as usize, height as usize), 0), |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
14 |
pixels: land2d::Land2D::new(Size::new(width as usize, height as usize), 0), |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
15 |
}); |
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 |
Box::leak(game_field) |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
18 |
} |
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 |
#[no_mangle] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
21 |
pub extern "C" fn land_get(game_field: &mut GameField, x: i32, y: i32) -> u16 { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
22 |
game_field.collision.map(y, x, |p| *p) |
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] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
26 |
pub extern "C" fn land_fill( |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
27 |
game_field: &mut GameField, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
28 |
x: i32, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
29 |
y: i32, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
30 |
border_value: u16, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
31 |
fill_value: u16, |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
32 |
) { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
33 |
game_field |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
34 |
.collision |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
35 |
.fill(Point::new(x, y), border_value, fill_value) |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
36 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
37 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
38 |
#[no_mangle] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
39 |
pub extern "C" fn land_set(game_field: &mut GameField, x: i32, y: i32, value: u16) { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
40 |
game_field.collision.map(y, x, |p| *p = value); |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
41 |
} |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
42 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
43 |
#[no_mangle] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
44 |
pub extern "C" fn land_pixel_get(game_field: &mut GameField, x: i32, y: i32) -> u32 { |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
45 |
game_field.pixels.map(y, x, |p| *p) |
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 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
48 |
#[no_mangle] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
49 |
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
|
50 |
game_field.pixels.map(y, x, |p| *p = value); |
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 |
|
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
53 |
#[no_mangle] |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
54 |
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
|
55 |
unsafe { drop(Box::from_raw(game_field)) }; |
128ace913837
Introduce hwengine-future library, use Land allocated in it
unC0Rr
parents:
diff
changeset
|
56 |
} |