author | unc0rr |
Thu, 08 Nov 2018 00:00:58 +0100 | |
changeset 14174 | e2c51c8e0b2e |
parent 14171 | 7d3b94cdc3c4 |
child 14193 | 3b83ec44e10b |
permissions | -rw-r--r-- |
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
1 |
extern crate integral_geometry; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
2 |
extern crate land2d; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
3 |
extern crate landgen; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
4 |
extern crate lfprng; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
5 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
6 |
mod world; |
14174 | 7 |
mod engine_message; |
8 |
mod command; |
|
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
9 |
|
14148 | 10 |
#[repr(C)] |
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
11 |
pub struct EngineInstance { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
12 |
world: world::World, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
13 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
14 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
15 |
#[repr(C)] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
16 |
#[derive(Copy, Clone)] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
17 |
pub struct PreviewInfo { |
14148 | 18 |
width: u32, |
19 |
height: u32, |
|
20 |
hedgehogs_number: u8, |
|
21 |
land: *const u8, |
|
22 |
} |
|
23 |
||
24 |
#[no_mangle] |
|
25 |
pub extern "C" fn protocol_version() -> u32 { |
|
26 |
56 |
|
27 |
} |
|
28 |
||
29 |
#[no_mangle] |
|
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
30 |
pub extern "C" fn start_engine() -> *mut EngineInstance { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
31 |
let engine_state = Box::new(EngineInstance { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
32 |
world: world::World::new(), |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
33 |
}); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
34 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
35 |
Box::leak(engine_state) |
14148 | 36 |
} |
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
37 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
38 |
#[no_mangle] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
39 |
pub extern "C" fn generate_preview(engine_state: &mut EngineInstance, preview: &mut PreviewInfo) { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
40 |
(*engine_state).world.generate_preview(); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
41 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
42 |
let land_preview = (*engine_state).world.preview(); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
43 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
44 |
*preview = PreviewInfo { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
45 |
width: land_preview.width() as u32, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
46 |
height: land_preview.height() as u32, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
47 |
hedgehogs_number: 0, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
48 |
land: land_preview.raw_pixels().as_ptr(), |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
49 |
}; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
50 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
51 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
52 |
#[no_mangle] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
53 |
pub extern "C" fn cleanup(engine_state: *mut EngineInstance) { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
54 |
unsafe { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
55 |
Box::from_raw(engine_state); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
56 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
57 |
} |