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
78
79
80
81
82
83
#![recursion_limit = "256"]

pub use geng_derive::*;

pub mod prelude {
    pub use crate::{draw_2d, Geng};
    pub use crate::{Camera2dExt as _, Camera3dExt as _};
    pub use ::batbox::*;
    pub use ::geng_ecs as ecs;
    pub use ugli::{self, Ugli};
}

use crate as geng;
use crate::prelude::*;
pub use ::geng_ecs as ecs;
#[allow(unused_imports)]
use log::{trace, warn};

mod asset;
mod camera;
mod context;
mod debug_overlay;
pub mod draw_2d;
mod font;
mod loading_screen;
pub mod net;
pub mod obj;
mod shader_lib;
#[cfg(feature = "audio")]
mod sound;
mod state;
mod texture_atlas;
pub mod ui;
mod window;

pub use asset::*;
pub use camera::*;
pub use context::*;
pub use debug_overlay::*;
pub use draw_2d::Draw2D;
pub use font::*;
pub use loading_screen::*;
pub use shader_lib::*;
#[cfg(feature = "audio")]
pub use sound::*;
pub use state::*;
pub use texture_atlas::*;
pub use window::*;

#[cfg(not(target_arch = "wasm32"))]
pub fn setup_panic_handler() {
    // TODO: do something useful here too?
}

#[cfg(target_arch = "wasm32")]
pub fn setup_panic_handler() {
    #[wasm_bindgen(inline_js = r#"
    export function show_error(text) {
        document.getElementById("geng-canvas").style.display = "none";
        document.getElementById("error-message").textContent = text;
        document.getElementById("geng-error-screen").style.display = "block";
    }
    "#)]
    extern "C" {
        fn show_error(s: &str);
    }
    fn panic_hook(info: &std::panic::PanicInfo) {
        static ALREADY_PANICKED: std::sync::atomic::AtomicBool =
            std::sync::atomic::AtomicBool::new(false);
        if ALREADY_PANICKED.swap(true, std::sync::atomic::Ordering::Relaxed) {
            return;
        }
        let error: String = if let Some(error) = info.payload().downcast_ref::<String>() {
            error.clone()
        } else if let Some(error) = info.payload().downcast_ref::<&str>() {
            error.to_string()
        } else {
            String::from("Something went wrong")
        };
        show_error(&error);
    }
    std::panic::set_hook(Box::new(panic_hook));
}