Use new system dispatch setup, make 'mapgen' properties of 'State' struct into their own struct
This commit is contained in:
parent
c835100272
commit
097b8afb8a
104
src/state.rs
104
src/state.rs
@ -7,13 +7,8 @@ use crate::gui::{self, show_cheat_mode, CheatMenuResult, MainMenuSelection};
|
||||
use crate::map::{self, *};
|
||||
use crate::player::*;
|
||||
use crate::raws::*;
|
||||
use crate::systems::{
|
||||
ai, particle_system, HungerSystem, ItemCollectionSystem, ItemDropSystem, ItemEquipOnUse,
|
||||
ItemIdentificationSystem, ItemRemoveSystem, ItemUseSystem, LightingSystem, MapIndexingSystem,
|
||||
MeleeCombatSystem, MovementSystem, ParticleSpawnSystem, RangedCombatSystem, SpellUseSystem,
|
||||
TriggerSystem, VisibilitySystem,
|
||||
};
|
||||
use crate::{camera, colors, damage_system, effects, gamelog, player, saveload_system, spawner};
|
||||
use crate::systems::{self, particle_system};
|
||||
use crate::{camera, colors, damage_system, gamelog, player, saveload_system, spawner};
|
||||
|
||||
/// Whether to show a visual representation of map generation
|
||||
pub const SHOW_MAPGEN_VISUALIZER: bool = false;
|
||||
@ -50,61 +45,38 @@ pub enum RunState {
|
||||
ShowIdentify,
|
||||
}
|
||||
|
||||
struct MapGen {
|
||||
next_state: Option<RunState>,
|
||||
history: Vec<Map>,
|
||||
index: usize,
|
||||
timer: f32,
|
||||
}
|
||||
|
||||
/// The main wrapper around the game's state
|
||||
pub struct State {
|
||||
pub ecs: World,
|
||||
mapgen_next_state: Option<RunState>,
|
||||
mapgen_history: Vec<Map>,
|
||||
mapgen_index: usize,
|
||||
mapgen_timer: f32,
|
||||
mapgen: MapGen,
|
||||
dispatcher: Box<dyn systems::UnifiedDispatcher + 'static>,
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub(super) fn new() -> Self {
|
||||
State {
|
||||
ecs: World::new(),
|
||||
mapgen_next_state: Some(RunState::MainMenu {
|
||||
menu_selection: MainMenuSelection::NewGame,
|
||||
}),
|
||||
mapgen_index: 0,
|
||||
mapgen_history: Vec::new(),
|
||||
mapgen_timer: 0.0,
|
||||
mapgen: MapGen {
|
||||
next_state: Some(RunState::MainMenu {
|
||||
menu_selection: MainMenuSelection::NewGame,
|
||||
}),
|
||||
index: 0,
|
||||
history: Vec::new(),
|
||||
timer: 0.0,
|
||||
},
|
||||
dispatcher: systems::build(),
|
||||
}
|
||||
}
|
||||
|
||||
fn run_systems(&mut self) {
|
||||
MapIndexingSystem {}.run_now(&self.ecs);
|
||||
VisibilitySystem {}.run_now(&self.ecs);
|
||||
|
||||
ai::EncumbranceSystem {}.run_now(&self.ecs);
|
||||
ai::InitiativeSystem {}.run_now(&self.ecs);
|
||||
ai::TurnStatusSystem {}.run_now(&self.ecs);
|
||||
ai::QuipSystem {}.run_now(&self.ecs);
|
||||
ai::AdjacentAI {}.run_now(&self.ecs);
|
||||
ai::VisibleAI {}.run_now(&self.ecs);
|
||||
ai::ApproachAI {}.run_now(&self.ecs);
|
||||
ai::FleeAI {}.run_now(&self.ecs);
|
||||
ai::ChaseAI {}.run_now(&self.ecs);
|
||||
ai::DefaultMoveAI {}.run_now(&self.ecs);
|
||||
|
||||
MovementSystem {}.run_now(&self.ecs);
|
||||
TriggerSystem {}.run_now(&self.ecs);
|
||||
MeleeCombatSystem {}.run_now(&self.ecs);
|
||||
RangedCombatSystem {}.run_now(&self.ecs);
|
||||
ItemCollectionSystem {}.run_now(&self.ecs);
|
||||
ItemEquipOnUse {}.run_now(&self.ecs);
|
||||
ItemUseSystem {}.run_now(&self.ecs);
|
||||
SpellUseSystem {}.run_now(&self.ecs);
|
||||
ItemIdentificationSystem {}.run_now(&self.ecs);
|
||||
ItemDropSystem {}.run_now(&self.ecs);
|
||||
ItemRemoveSystem {}.run_now(&self.ecs);
|
||||
HungerSystem {}.run_now(&self.ecs);
|
||||
|
||||
effects::run_effects_queue(&mut self.ecs);
|
||||
|
||||
ParticleSpawnSystem {}.run_now(&self.ecs);
|
||||
LightingSystem {}.run_now(&self.ecs);
|
||||
|
||||
self.dispatcher.run_now(&mut self.ecs);
|
||||
self.ecs.maintain();
|
||||
}
|
||||
|
||||
@ -146,12 +118,12 @@ impl State {
|
||||
}
|
||||
|
||||
pub(super) fn generate_world_map(&mut self, new_depth: i32, offset: i32) {
|
||||
self.mapgen_index = 0;
|
||||
self.mapgen_timer = 0.0;
|
||||
self.mapgen_history.clear();
|
||||
self.mapgen.index = 0;
|
||||
self.mapgen.timer = 0.0;
|
||||
self.mapgen.history.clear();
|
||||
|
||||
if let Some(history) = map::level_transition(&mut self.ecs, new_depth, offset) {
|
||||
self.mapgen_history = history;
|
||||
self.mapgen.history = history;
|
||||
} else {
|
||||
map::thaw_level_entities(&mut self.ecs);
|
||||
}
|
||||
@ -193,22 +165,22 @@ impl GameState for State {
|
||||
match newrunstate {
|
||||
RunState::MapGeneration => {
|
||||
if !SHOW_MAPGEN_VISUALIZER {
|
||||
newrunstate = self.mapgen_next_state.unwrap();
|
||||
newrunstate = self.mapgen.next_state.unwrap();
|
||||
}
|
||||
ctx.set_active_console(1);
|
||||
ctx.cls();
|
||||
ctx.set_active_console(0);
|
||||
ctx.cls();
|
||||
if self.mapgen_index < self.mapgen_history.len() {
|
||||
camera::render_debug_map(&self.mapgen_history[self.mapgen_index], ctx);
|
||||
if self.mapgen.index < self.mapgen.history.len() {
|
||||
camera::render_debug_map(&self.mapgen.history[self.mapgen.index], ctx);
|
||||
}
|
||||
|
||||
self.mapgen_timer += ctx.frame_time_ms;
|
||||
if self.mapgen_timer > 300.0 {
|
||||
self.mapgen_timer = 0.0;
|
||||
self.mapgen_index += 1;
|
||||
if self.mapgen_index >= self.mapgen_history.len() {
|
||||
newrunstate = self.mapgen_next_state.unwrap();
|
||||
self.mapgen.timer += ctx.frame_time_ms;
|
||||
if self.mapgen.timer > 300.0 {
|
||||
self.mapgen.timer = 0.0;
|
||||
self.mapgen.index += 1;
|
||||
if self.mapgen.index >= self.mapgen.history.len() {
|
||||
newrunstate = self.mapgen.next_state.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -396,7 +368,7 @@ impl GameState for State {
|
||||
}
|
||||
RunState::PreviousLevel => {
|
||||
self.goto_level(-1);
|
||||
self.mapgen_next_state = Some(RunState::PreRun);
|
||||
self.mapgen.next_state = Some(RunState::PreRun);
|
||||
newrunstate = RunState::MapGeneration;
|
||||
}
|
||||
RunState::MagicMapReveal { row } => {
|
||||
@ -417,7 +389,7 @@ impl GameState for State {
|
||||
CheatMenuResult::NoResponse => {}
|
||||
CheatMenuResult::TeleportToExit => {
|
||||
self.goto_level(1);
|
||||
self.mapgen_next_state = Some(RunState::PreRun);
|
||||
self.mapgen.next_state = Some(RunState::PreRun);
|
||||
|
||||
newrunstate = RunState::MapGeneration
|
||||
}
|
||||
@ -517,7 +489,7 @@ impl GameState for State {
|
||||
let map_depth = self.ecs.fetch::<Map>().depth;
|
||||
let destination_offset = 0 - (map_depth - 1);
|
||||
self.goto_level(destination_offset);
|
||||
self.mapgen_next_state = Some(RunState::PreRun);
|
||||
self.mapgen.next_state = Some(RunState::PreRun);
|
||||
|
||||
newrunstate = RunState::MapGeneration;
|
||||
}
|
||||
@ -532,7 +504,7 @@ impl GameState for State {
|
||||
let mut ppos = self.ecs.fetch_mut::<Point>();
|
||||
ppos.x = x;
|
||||
ppos.y = y;
|
||||
self.mapgen_next_state = Some(RunState::PreRun);
|
||||
self.mapgen.next_state = Some(RunState::PreRun);
|
||||
|
||||
newrunstate = RunState::MapGeneration;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user