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