start moving slimed project to app+core+support context/state model

This commit is contained in:
Gered 2023-02-19 15:19:02 -05:00
parent 03bb4b4adc
commit aa3ede096f
3 changed files with 18 additions and 12 deletions

View file

@ -385,8 +385,8 @@ pub struct Pickuper;
pub fn init_everything(context: &mut Game, map_file: &Path, min_spawn_time: f32, max_spawn_time: f32, max_slimes: usize) {
init_entities(&mut context.core.entities);
init_component_system(&mut context.component_systems);
init_events(&mut context.event_listeners);
init_component_system(&mut context.support.component_systems);
init_events(&mut context.support.event_listeners);
context.core.event_publisher.clear();
context.core.tilemap = TileMap::load_from(map_file).unwrap();

View file

@ -54,12 +54,16 @@ pub struct Core {
pub sprite_render_list: Vec<(EntityId, Vector2, BlitMethod)>,
}
pub struct Game {
pub core: Core,
pub struct Support {
pub component_systems: ComponentSystems<Core, Core>,
pub event_listeners: EventListeners<Event, Core>,
}
pub struct Game {
pub core: Core,
pub support: Support,
}
impl Game {
pub fn new(mut system: System) -> Result<Self> {
let palette = load_palette(Path::new("./assets/db16.pal"))?;
@ -136,14 +140,16 @@ impl Game {
sparkles_animation_def,
sprite_render_list: Vec::with_capacity(1024),
},
component_systems,
event_listeners,
support: Support {
component_systems,
event_listeners,
},
})
}
pub fn do_events(&mut self) {
self.event_listeners.take_queue_from(&mut self.core.event_publisher);
self.event_listeners.dispatch_queue(&mut self.core);
self.support.event_listeners.take_queue_from(&mut self.core.event_publisher);
self.support.event_listeners.dispatch_queue(&mut self.core);
}
pub fn update_frame_delta(&mut self, last_ticks: u64) -> u64 {

View file

@ -46,14 +46,14 @@ impl AppState<Game> for MainMenuState {
}
context.do_events();
context.component_systems.update(&mut context.core);
context.support.component_systems.update(&mut context.core);
None
}
fn render(&mut self, state: State, context: &mut Game) {
context.core.tilemap.draw(&mut context.core.system.video, &context.core.tiles, 0, 0);
context.component_systems.render(&mut context.core);
context.support.component_systems.render(&mut context.core);
let x = 32;
let y = 160;
@ -155,7 +155,7 @@ impl AppState<Game> for GamePlayState {
}
context.do_events();
context.component_systems.update(&mut context.core);
context.support.component_systems.update(&mut context.core);
None
}
@ -164,7 +164,7 @@ impl AppState<Game> for GamePlayState {
if let Some((_, camera)) = context.core.entities.components::<Camera>().single() {
context.core.tilemap.draw(&mut context.core.system.video, &context.core.tiles, camera.x, camera.y);
}
context.component_systems.render(&mut context.core);
context.support.component_systems.render(&mut context.core);
if self.in_menu {
let x = 32;