author | alfadur |
Fri, 09 Nov 2018 23:03:45 +0300 | |
changeset 14209 | 3b83ec44e10b |
parent 14190 | e2c51c8e0b2e |
child 14226 | a8fe9cd51154 |
permissions | -rw-r--r-- |
14174
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
1 |
extern crate integral_geometry; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
2 |
extern crate land2d; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
3 |
extern crate landgen; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
4 |
extern crate lfprng; |
14209 | 5 |
extern crate gfx; |
6 |
extern crate gfx_device_gl; |
|
14174
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
7 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
8 |
mod world; |
14190 | 9 |
mod engine_message; |
10 |
mod command; |
|
14174
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
11 |
|
14164 | 12 |
#[repr(C)] |
14174
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
13 |
pub struct EngineInstance { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
14 |
world: world::World, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
15 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
16 |
|
14209 | 17 |
impl EngineInstance { |
18 |
pub fn new() -> Self { |
|
19 |
let world = world::World::new(); |
|
20 |
Self { world } |
|
21 |
} |
|
22 |
||
23 |
pub fn render<R, C>( |
|
24 |
&self, |
|
25 |
context: &mut gfx::Encoder<R, C>, |
|
26 |
target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>) |
|
27 |
where R: gfx::Resources, |
|
28 |
C: gfx::CommandBuffer<R> |
|
29 |
{ |
|
30 |
context.clear(target, [0.0, 0.5, 0.0, 1.0]); |
|
31 |
} |
|
32 |
} |
|
33 |
||
14174
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
34 |
#[repr(C)] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
35 |
#[derive(Copy, Clone)] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
36 |
pub struct PreviewInfo { |
14164 | 37 |
width: u32, |
38 |
height: u32, |
|
39 |
hedgehogs_number: u8, |
|
40 |
land: *const u8, |
|
41 |
} |
|
42 |
||
43 |
#[no_mangle] |
|
44 |
pub extern "C" fn protocol_version() -> u32 { |
|
45 |
56 |
|
46 |
} |
|
47 |
||
48 |
#[no_mangle] |
|
14174
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
49 |
pub extern "C" fn start_engine() -> *mut EngineInstance { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
50 |
let engine_state = Box::new(EngineInstance { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
51 |
world: world::World::new(), |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
52 |
}); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
53 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
54 |
Box::leak(engine_state) |
14164 | 55 |
} |
14174
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
56 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
57 |
#[no_mangle] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
58 |
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:
14164
diff
changeset
|
59 |
(*engine_state).world.generate_preview(); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
60 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
61 |
let land_preview = (*engine_state).world.preview(); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
62 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
63 |
*preview = PreviewInfo { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
64 |
width: land_preview.width() as u32, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
65 |
height: land_preview.height() as u32, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
66 |
hedgehogs_number: 0, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
67 |
land: land_preview.raw_pixels().as_ptr(), |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
68 |
}; |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
69 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
70 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
71 |
#[no_mangle] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
72 |
pub extern "C" fn cleanup(engine_state: *mut EngineInstance) { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
73 |
unsafe { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
74 |
Box::from_raw(engine_state); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
75 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14164
diff
changeset
|
76 |
} |