Skip to main content

mireforge_advanced_game/
lib.rs

1/*
2 * Copyright (c) Peter Bjorklund. All rights reserved. https://github.com/mireforge/mireforge
3 * Licensed under the MIT License. See LICENSE in the project root for license information.
4 */
5extern crate core;
6
7pub mod audio;
8pub mod logic;
9pub mod render;
10
11use fixed32::Fp;
12use int_math::{UVec2, Vec2};
13use limnus_basic_input::prelude::{ButtonState, KeyCode, MouseButton};
14use limnus_gamepad::{Axis, Button, GamePadId, Gamepad};
15use mireforge_game_assets::Assets;
16use mireforge_game_audio::Audio;
17use mireforge_render_wgpu::prelude::Gfx;
18
19pub trait ApplicationLogic: Sized + 'static {
20    fn new() -> Self;
21
22    fn tick(&mut self);
23
24    fn wants_to_quit(&self) -> bool {
25        false
26    }
27
28    fn keyboard_input(&mut self, _state: ButtonState, _key_code: KeyCode) {}
29
30    fn cursor_entered(&mut self) {}
31
32    fn cursor_left(&mut self) {}
33
34    fn cursor_moved(&mut self, _position: UVec2) {}
35
36    fn mouse_input(&mut self, _state: ButtonState, _button: MouseButton) {}
37
38    fn mouse_wheel(&mut self, _delta_y: i16) {}
39
40    fn mouse_motion(&mut self, _delta: Vec2) {}
41
42    fn gamepad_activated(&mut self, _gamepad_id: GamePadId, _name: String) {}
43    fn gamepad_button_changed(&mut self, _gamepad: &Gamepad, _button: Button, _value: Fp) {}
44    fn gamepad_axis_changed(&mut self, _gamepad: &Gamepad, _axis: Axis, _value: Fp) {}
45    fn gamepad_disconnected(&mut self, _gamepad_id: GamePadId) {}
46}
47
48pub trait ApplicationAudio<L: ApplicationLogic>: Sized + 'static {
49    fn new(assets: &mut impl Assets) -> Self;
50    fn audio(&mut self, _audio: &mut impl Audio, _logic: &L) {}
51}
52
53pub trait ApplicationRender<L: ApplicationLogic>: Sized + 'static {
54    fn new(assets: &mut impl Assets) -> Self;
55    fn render(&mut self, gfx: &mut impl Gfx, logic: &L);
56
57    fn wants_cursor_visible(&self) -> bool {
58        true
59    }
60    fn scale_factor_changed(&mut self, _scale_factor: f64) -> Option<UVec2> {
61        None
62    }
63}