1pub mod animation;
12pub mod audio;
13pub mod camera;
14pub mod context;
15pub mod input;
16pub mod math;
17pub mod noise;
18pub mod physics;
19mod runtime;
20pub mod sprite;
21pub mod texture;
22pub mod texture_manager;
23pub mod time;
24
25pub use animation::{AnimationDef, AnimationState};
27pub use audio::{AudioManager, AudioResponse, AudioTrack, UiAudioEvent, load_sound_data};
28pub use camera::ScreenShake;
29pub use context::Context;
30pub use glam::{Vec2, Vec3, Vec4};
31pub use input::{GameAction, InputMap, InputState, Key, MouseBinding};
32pub use kira::sound::static_sound::StaticSoundData;
33pub use math::move_towards;
34pub use physics::{AABB, BoxVolume, CollisionLayer, SweepResult};
35pub use sprite::BlendMode;
36pub use sprite::Rect;
37
38pub use egui;
39#[cfg(not(target_arch = "wasm32"))]
40pub use gilrs;
41pub use texture::Texture;
42pub use texture_manager::TextureHandle;
43pub use time::FixedTime;
44
45#[derive(Debug, Clone, PartialEq)]
46pub struct SceneParams {
47 pub background_color: [f32; 3],
48 pub seed: u32,
49 pub fog_enabled: bool,
50 pub fog_density: f32,
51 pub fog_opacity: f32,
52 pub fog_color: [f32; 3],
53 pub fog_anim_speed: f32,
54 pub time: f32,
55}
56
57impl Default for SceneParams {
59 fn default() -> Self {
60 Self {
61 background_color: [0.67, 0.42, 0.85], seed: 42,
63 fog_enabled: true,
64 fog_density: 10.0,
65 fog_opacity: 1.0,
66 fog_color: [0.41, 0.36, 0.81], fog_anim_speed: 0.5,
68 time: 0.0,
69 }
70 }
71}
72
73pub trait GameApp: 'static {
74 type Action: GameAction;
76
77 fn window_title() -> &'static str {
78 "Journey Engine"
79 }
80
81 fn window_icon() -> Option<&'static [u8]> {
82 None
83 }
84
85 fn wasm_ready_event() -> Option<&'static str> {
86 None
87 }
88
89 fn internal_resolution() -> (u32, u32) {
90 (640, 360)
91 }
92
93 fn init(ctx: &mut Context<Self::Action>) -> Self;
96
97 fn fixed_update(&mut self, _ctx: &mut Context<Self::Action>, _fixed_time: &time::FixedTime) {}
102
103 fn update(&mut self, ctx: &mut Context<Self::Action>);
105
106 fn render(&mut self, ctx: &mut Context<Self::Action>);
109 fn ui(
110 &mut self,
111 _egui_ctx: &egui::Context,
112 _ctx: &mut Context<Self::Action>,
113 _scene_params: &mut SceneParams,
114 ) {
115 }
116}
117
118fn init_logging() {
119 #[cfg(not(target_arch = "wasm32"))]
120 {
121 env_logger::try_init().ok();
122 }
123
124 #[cfg(target_arch = "wasm32")]
125 {
126 console_error_panic_hook::set_once();
127 console_log::init_with_level(log::Level::Info).ok();
128 }
129}
130
131pub fn run<G: GameApp>() {
132 init_logging();
133 runtime::start::<G>();
134}
135
136#[cfg(target_arch = "wasm32")]
143pub fn run_wasm<G: GameApp>() {
144 init_logging();
145 runtime::start::<G>();
146}