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