author | unC0Rr |
Thu, 22 Nov 2018 13:39:51 +0100 | |
changeset 14277 | 3152d9fdb499 |
parent 14276 | 1aac8a62be6f |
child 14298 | b8871dd33ec4 |
permissions | -rw-r--r-- |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
1 |
mod ipc; |
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
2 |
mod world; |
14277 | 3 |
mod instance; |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
4 |
|
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
5 |
use std::io::{Read, Write}; |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
6 |
|
14277 | 7 |
use self::instance::EngineInstance; |
14193 | 8 |
|
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
9 |
#[repr(C)] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
10 |
#[derive(Copy, Clone)] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
11 |
pub struct PreviewInfo { |
14148 | 12 |
width: u32, |
13 |
height: u32, |
|
14 |
hedgehogs_number: u8, |
|
15 |
land: *const u8, |
|
16 |
} |
|
17 |
||
18 |
#[no_mangle] |
|
19 |
pub extern "C" fn protocol_version() -> u32 { |
|
20 |
56 |
|
21 |
} |
|
22 |
||
23 |
#[no_mangle] |
|
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
24 |
pub extern "C" fn start_engine() -> *mut EngineInstance { |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
25 |
let engine_state = Box::new(EngineInstance::new()); |
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
26 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
27 |
Box::leak(engine_state) |
14148 | 28 |
} |
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
29 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
30 |
#[no_mangle] |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
31 |
pub extern "C" fn generate_preview(engine_state: &mut EngineInstance, preview: &mut PreviewInfo) { |
14277 | 32 |
(*engine_state).process_ipc_queue(); |
33 |
||
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
34 |
(*engine_state).world.generate_preview(); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
35 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
36 |
let land_preview = (*engine_state).world.preview(); |
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 |
*preview = PreviewInfo { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
39 |
width: land_preview.width() as u32, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
40 |
height: land_preview.height() as u32, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
41 |
hedgehogs_number: 0, |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
42 |
land: land_preview.raw_pixels().as_ptr(), |
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 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
45 |
|
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
46 |
#[no_mangle] |
14277 | 47 |
pub extern "C" fn send_ipc(engine_state: &mut EngineInstance, buf: *const u8, size: usize) { |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
48 |
unsafe { |
14277 | 49 |
(*engine_state).ipc.write(std::slice::from_raw_parts(buf, size)).unwrap(); |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
50 |
} |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
51 |
} |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
52 |
|
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
53 |
#[no_mangle] |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
54 |
pub extern "C" fn read_ipc( |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
55 |
engine_state: &mut EngineInstance, |
14277 | 56 |
buf: *mut u8, |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
57 |
size: usize, |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
58 |
) -> usize { |
14277 | 59 |
unsafe { (*engine_state).ipc.read(std::slice::from_raw_parts_mut(buf, size)).unwrap_or(0) } |
14276
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
60 |
} |
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
61 |
|
1aac8a62be6f
Implement send_ipc and read_ipc in engine lib, send_ipc in frontend
unC0Rr
parents:
14260
diff
changeset
|
62 |
#[no_mangle] |
14158
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
63 |
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
|
64 |
unsafe { |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
65 |
Box::from_raw(engine_state); |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
66 |
} |
b273b43b16d2
Make hedgewars-engine crate produce shared library, implement some basics
unC0Rr
parents:
14148
diff
changeset
|
67 |
} |