1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![warn(missing_docs)]
use gdnative::prelude::*;
pub use godotggrs_p2psession::GodotGGRSP2PSession;
pub use godotggrs_p2pspectatorsession::GodotGGRSP2PSpectatorSession;
pub use godotggrs_synctestsession::GodotGGRSSyncTestSession;
mod ggrs_request_handlers;
mod godotggrs_p2psession;
mod godotggrs_p2pspectatorsession;
mod godotggrs_synctestsession;
pub const ERR_MESSAGE_NO_SESSION_MADE: &str = "No session was made.";
pub const ERR_MESSAGE_NO_CALLBACK_NODE: &str = "No callback node was specified.";
pub const CALLBACK_FUNC_SAVE_GAME_STATE: &str = "ggrs_save_game_state";
pub const CALLBACK_FUNC_LOAD_GAME_STATE: &str = "ggrs_load_game_state";
pub const CALLBACK_FUNC_ADVANCE_FRAME: &str = "ggrs_advance_frame";
pub fn init_panic_hook() {
let old_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
let loc_string;
if let Some(location) = panic_info.location() {
loc_string = format!("file '{}' at line {}", location.file(), location.line());
} else {
loc_string = "unknown location".to_owned()
}
let error_message;
if let Some(s) = panic_info.payload().downcast_ref::<&str>() {
error_message = format!("[RUST] {}: panic occurred: {:?}", loc_string, s);
} else if let Some(s) = panic_info.payload().downcast_ref::<String>() {
error_message = format!("[RUST] {}: panic occurred: {:?}", loc_string, s);
} else {
error_message = format!("[RUST] {}: unknown panic occurred", loc_string);
}
godot_error!("{}", error_message);
(*(old_hook.as_ref()))(panic_info);
unsafe {
if let Some(gd_panic_hook) =
gdnative::api::utils::autoload::<gdnative::api::Node>("RustPanicHook")
{
gd_panic_hook.call(
"rust_panic_hook",
&[GodotString::from_str(error_message).to_variant()],
);
}
}
}));
}
fn init(handle: InitHandle) {
handle.add_class::<GodotGGRSP2PSession>();
handle.add_class::<GodotGGRSSyncTestSession>();
handle.add_class::<GodotGGRSP2PSpectatorSession>();
init_panic_hook()
}
godot_init!(init);