romy_core/
runtime.rs

1//! This module contains code that is commonly needed by runtime implementations for various
2//! platforms, its not intended to be used for other purposes. 
3 
4use super::*;
5
6/// A version of the Game trait with mutable draw/render_audio. Some implementations need this.
7pub trait GameMut {
8    fn step(&mut self, arguments: &StepArguments);
9    fn draw(&mut self, arguments: &DrawArguments) -> Image;
10    fn render_audio(&mut self, arguments: &RenderAudioArguments) -> Sound;
11}
12
13/// A wrapper to convert a immutable Game to a mutable one
14pub struct GameMutMap {
15    game: Box<dyn Game>,
16}
17
18impl GameMutMap {
19    pub fn new(game: Box<dyn Game>) -> Self {
20        Self { game }
21    }
22}
23
24impl GameMut for GameMutMap {
25    fn step(&mut self, arguments: &StepArguments) {
26        self.game.step(arguments)
27    }
28    fn draw(&mut self, arguments: &DrawArguments) -> Image {
29        self.game.draw(arguments)
30    }
31    fn render_audio(&mut self, arguments: &RenderAudioArguments) -> Sound {
32        self.game.render_audio(arguments)
33    }
34}
35
36/// A structure for holding a game and its info struct together
37pub struct RunBundle {
38    pub game: Box<dyn GameMut>,
39    pub info: Info,
40}
41
42impl RunBundle {
43    pub fn new(game: Box<dyn GameMut>, info: Info) -> Self {
44        Self { game, info }
45    }
46}