equal
deleted
inserted
replaced
1 extern crate integral_geometry; |
|
2 extern crate land2d; |
|
3 extern crate landgen; |
|
4 extern crate lfprng; |
|
5 |
|
6 mod world; |
|
7 |
|
8 #[repr(C)] |
|
9 pub struct EngineInstance { |
|
10 world: world::World, |
|
11 } |
|
12 |
|
13 #[repr(C)] |
|
14 #[derive(Copy, Clone)] |
|
15 pub struct PreviewInfo { |
|
16 width: u32, |
|
17 height: u32, |
|
18 hedgehogs_number: u8, |
|
19 land: *const u8, |
|
20 } |
|
21 |
|
22 #[no_mangle] |
|
23 pub extern "C" fn protocol_version() -> u32 { |
|
24 56 |
|
25 } |
|
26 |
|
27 #[no_mangle] |
|
28 pub extern "C" fn start_engine() -> *mut EngineInstance { |
|
29 let engine_state = Box::new(EngineInstance { |
|
30 world: world::World::new(), |
|
31 }); |
|
32 |
|
33 Box::leak(engine_state) |
|
34 } |
|
35 |
|
36 #[no_mangle] |
|
37 pub extern "C" fn generate_preview(engine_state: &mut EngineInstance, preview: &mut PreviewInfo) { |
|
38 (*engine_state).world.generate_preview(); |
|
39 |
|
40 let land_preview = (*engine_state).world.preview(); |
|
41 |
|
42 *preview = PreviewInfo { |
|
43 width: land_preview.width() as u32, |
|
44 height: land_preview.height() as u32, |
|
45 hedgehogs_number: 0, |
|
46 land: land_preview.raw_pixels().as_ptr(), |
|
47 }; |
|
48 } |
|
49 |
|
50 #[no_mangle] |
|
51 pub extern "C" fn cleanup(engine_state: *mut EngineInstance) { |
|
52 unsafe { |
|
53 Box::from_raw(engine_state); |
|
54 } |
|
55 } |
|