Skip to content

Commit 7d84a5e

Browse files
add feature to register multiple "modules"
1 parent 6b86c69 commit 7d84a5e

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

omp-codegen/src/callbacks.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,27 @@ pub fn create_callback(input: TokenStream) -> TokenStream {
104104
quote!(
105105
#[no_mangle]
106106
pub unsafe extern "C" fn #orig_callback_name(#(#orig_callback_params)*) -> #return_type {
107-
crate::runtime::Runtime.as_mut().unwrap().#user_func_name(#(#user_func_args)*)
107+
let scripts = crate::runtime::Runtime.as_mut().unwrap();
108+
let mut ret = false;
109+
for script in scripts.iter_mut() {
110+
ret = script.#user_func_name(#(#user_func_args)*);
111+
if crate::runtime::__terminate_event_chain {
112+
crate::runtime::__terminate_event_chain = false;
113+
return ret;
114+
}
115+
}
116+
ret
117+
108118
}
109119
)
110120
} else {
111121
quote!(
112122
#[no_mangle]
113123
pub unsafe extern "C" fn #orig_callback_name(#(#orig_callback_params)*) {
114-
crate::runtime::Runtime.as_mut().unwrap().#user_func_name(#(#user_func_args)*);
124+
let scripts = crate::runtime::Runtime.as_mut().unwrap();
125+
for script in scripts.iter_mut() {
126+
script.#user_func_name(#(#user_func_args)*);
127+
}
115128
}
116129
)
117130
};

omp-gdk/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod runtime;
1515

1616
pub use events::Events;
1717
pub use omp_codegen::main;
18-
pub use runtime::Runtime;
18+
pub use runtime::{Runtime, __terminate_event_chain};
1919
pub use scripting::actors;
2020
pub use scripting::checkpoints;
2121
pub use scripting::classes;

omp-gdk/src/runtime.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
use crate::events::Events;
22

33
/// Runtime global object that implements all the callbacks and gamemode data
4-
pub static mut Runtime: Option<Box<dyn Events + 'static>> = None;
4+
pub static mut Runtime: Option<Vec<Box<dyn Events + 'static>>> = None;
5+
6+
#[doc(hidden)]
7+
pub static mut __terminate_event_chain: bool = false;

omp/src/runtime.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
pub use omp_gdk::Runtime;
1+
pub use omp_gdk::{Runtime, __terminate_event_chain};
22
/// Registers the gamemode object and it's events
33
#[macro_export]
44
macro_rules! register {
55
($name:expr) => {
66
unsafe {
7-
omp::runtime::Runtime = Some(Box::new($name));
7+
if omp::runtime::Runtime.is_none() {
8+
omp::runtime::Runtime = Some(Vec::new());
9+
}
10+
omp::runtime::Runtime
11+
.as_mut()
12+
.unwrap()
13+
.push(Box::new($name));
814
}
915
};
1016
}
17+
18+
#[macro_export]
19+
macro_rules! terminate_event {
20+
($name:expr) => {
21+
unsafe {
22+
omp::runtime::__terminate_event_chain = true;
23+
}
24+
return $name
25+
};
26+
}

0 commit comments

Comments
 (0)