1mod core;
2mod core_plugin;
3
4pub use core::utils;
5pub use core::{
6 plugins::{Plugin, PluginMeta},
7 world::World,
8};
9pub use core_plugin::{Core, CorePlugin, CoreSettings};
10pub use sdl3_sys;
11
12#[doc(hidden)]
13pub use sdl3_main as __sdl3_main;
14#[doc(hidden)]
15pub use sdl3_sys as __sdl3_sys;
16
17#[macro_export]
18macro_rules! app {
19 ($setup:expr) => {
20 struct __TinygameState {
21 world: $crate::World,
22 sdl_core_event_sender: ::std::option::Option<
23 ::std::sync::mpsc::Sender<$crate::__sdl3_sys::events::SDL_Event>,
24 >,
25 }
26
27 #[$crate::__sdl3_main::app_init]
28 fn app_init(state_raw: *mut *mut ::std::ffi::c_void) -> $crate::__sdl3_main::AppResult {
29 let mut world = $crate::World::new();
30 let __tinygame_setup: fn(&mut $crate::World) = $setup;
31
32 __tinygame_setup(&mut world);
33
34 let init_status = world.run_init();
35 if init_status == $crate::__sdl3_main::AppResult::Continue {
36 let state = __TinygameState {
37 sdl_core_event_sender: world
38 .try_get::<$crate::Core>()
39 .map(|core| core.sdl_events.sender()),
40 world,
41 };
42 unsafe {
43 *state_raw = ::std::boxed::Box::into_raw(::std::boxed::Box::new(state))
44 as *mut ::std::ffi::c_void;
45 }
46 }
47
48 init_status
49 }
50
51 #[$crate::__sdl3_main::app_iterate]
52 fn app_iterate(state_raw: *mut ::std::ffi::c_void) -> $crate::__sdl3_main::AppResult {
53 let state = unsafe { &mut *(state_raw as *mut __TinygameState) };
54 state.world.run_step()
55 }
56
57 #[$crate::__sdl3_main::app_event]
58 fn app_event(
59 state_raw: *mut ::std::ffi::c_void,
60 event: $crate::__sdl3_sys::events::SDL_Event,
61 ) -> $crate::__sdl3_main::AppResult {
62 let state = unsafe { &*(state_raw as *mut __TinygameState) };
63 match &state.sdl_core_event_sender {
64 ::std::option::Option::Some(sender) => match sender.send(event) {
65 ::std::result::Result::Ok(_) => $crate::__sdl3_main::AppResult::Continue,
66 ::std::result::Result::Err(_) => $crate::__sdl3_main::AppResult::Failure,
67 },
68 ::std::option::Option::None => $crate::__sdl3_main::AppResult::Continue,
69 }
70 }
71
72 #[$crate::__sdl3_main::app_quit]
73 fn app_quit(state_raw: *mut ::std::ffi::c_void) {
74 let state = unsafe { ::std::boxed::Box::from_raw(state_raw as *mut __TinygameState) };
75 state.world.run_exit();
76 }
77 };
78}