mapgen runstate
This commit is contained in:
parent
7f02a5a30f
commit
a2fb893f49
7 changed files with 73 additions and 23 deletions
|
|
@ -25,9 +25,14 @@ pub struct ScreenBounds {
|
|||
pub y_offset: i32,
|
||||
}
|
||||
|
||||
pub fn get_screen_bounds(ecs: &World) -> ScreenBounds {
|
||||
let player_pos = ecs.fetch::<Point>();
|
||||
pub fn get_screen_bounds(ecs: &World, debug: bool) -> ScreenBounds {
|
||||
let map = ecs.fetch::<Map>();
|
||||
let player_pos = if !debug {
|
||||
*ecs.fetch::<Point>()
|
||||
} else {
|
||||
Point::new(map.width / 2, map.height / 2)
|
||||
};
|
||||
|
||||
let (x_chars, y_chars, mut x_offset, mut y_offset) = (VIEWPORT_W, VIEWPORT_H, 1, 10);
|
||||
|
||||
let centre_x = (x_chars / 2) as i32;
|
||||
|
|
@ -57,7 +62,7 @@ pub fn in_bounds(x: i32, y: i32, min_x: i32, min_y: i32, upper_x: i32, upper_y:
|
|||
|
||||
pub fn render_camera(ecs: &World, ctx: &mut BTerm) {
|
||||
let map = ecs.fetch::<Map>();
|
||||
let bounds = get_screen_bounds(ecs);
|
||||
let bounds = get_screen_bounds(ecs, false);
|
||||
|
||||
// Render map
|
||||
let mut y = 0;
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ impl Config {
|
|||
requires_write |= config.logging.apply_values(&parsed_config);
|
||||
requires_write |= config.visuals.apply_values(&parsed_config);
|
||||
if requires_write {
|
||||
console::log("Parsed config, but some values were changed. Saving new ver.");
|
||||
if let Err(write_err) = config.save_to_file(filename) {
|
||||
console::log(format!("Error writing config: {:?}", write_err));
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
|
@ -101,6 +101,8 @@ impl Section for LogConfig {
|
|||
fn apply_values(&mut self, parsed_config: &Value) -> bool {
|
||||
if let Some(section) = parsed_config.get("logging") {
|
||||
let mut missing = false;
|
||||
apply_bool_value!(self, section, missing, show_mapgen);
|
||||
apply_bool_value!(self, section, missing, log_combat);
|
||||
apply_bool_value!(self, section, missing, log_spawning);
|
||||
apply_bool_value!(self, section, missing, log_ticks);
|
||||
missing
|
||||
|
|
|
|||
|
|
@ -1191,7 +1191,7 @@ pub fn ranged_target(
|
|||
range: i32,
|
||||
aoe: i32
|
||||
) -> (TargetResult, Option<Point>) {
|
||||
let bounds = camera::get_screen_bounds(&gs.ecs);
|
||||
let bounds = camera::get_screen_bounds(&gs.ecs, false);
|
||||
let player_entity = gs.ecs.fetch::<Entity>();
|
||||
let player_pos = gs.ecs.fetch::<Point>();
|
||||
let viewsheds = gs.ecs.read_storage::<Viewshed>();
|
||||
|
|
@ -1235,7 +1235,7 @@ pub fn ranged_target(
|
|||
|
||||
// Draw mouse cursor
|
||||
let mouse_pos = (x, y);
|
||||
let bounds = camera::get_screen_bounds(&gs.ecs);
|
||||
let bounds = camera::get_screen_bounds(&gs.ecs, false);
|
||||
let x = x.clamp(bounds.x_offset, bounds.x_offset - 1 + VIEWPORT_W);
|
||||
let y = y.clamp(bounds.y_offset, bounds.y_offset - 1 + VIEWPORT_H);
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ impl Tooltip {
|
|||
|
||||
#[rustfmt::skip]
|
||||
pub fn draw_tooltips(ecs: &World, ctx: &mut BTerm, xy: Option<(i32, i32)>) {
|
||||
let bounds = get_screen_bounds(ecs);
|
||||
let bounds = get_screen_bounds(ecs, false);
|
||||
let map = ecs.fetch::<Map>();
|
||||
let names = ecs.read_storage::<Name>();
|
||||
let positions = ecs.read_storage::<Position>();
|
||||
|
|
|
|||
43
src/main.rs
43
src/main.rs
|
|
@ -168,12 +168,12 @@ struct DrawInfo {
|
|||
e: Entity,
|
||||
draw_type: DrawType,
|
||||
}
|
||||
|
||||
fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
|
||||
let map = ecs.fetch::<Map>();
|
||||
|
||||
render_map_in_view(&*map, ecs, draw, atlas);
|
||||
render_map_in_view(&*map, ecs, draw, atlas, false);
|
||||
{
|
||||
let bounds = crate::camera::get_screen_bounds(ecs);
|
||||
let bounds = crate::camera::get_screen_bounds(ecs, false);
|
||||
let positions = ecs.read_storage::<Position>();
|
||||
let renderables = ecs.read_storage::<Renderable>();
|
||||
let hidden = ecs.read_storage::<Hidden>();
|
||||
|
|
@ -237,7 +237,7 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
|
|||
}
|
||||
}
|
||||
let mut entries: Vec<(&DrawKey, &DrawInfo)> = to_draw.iter().collect();
|
||||
entries.sort_by_key(|&(k, _v)| k.render_order);
|
||||
entries.sort_by_key(|&(k, _v)| std::cmp::Reverse(k.render_order));
|
||||
for entry in entries.iter() {
|
||||
match entry.1.draw_type {
|
||||
DrawType::Visible | DrawType::Telepathy => {
|
||||
|
|
@ -265,13 +265,21 @@ fn draw_camera(ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, atlas: &HashMap<String, Texture>) {
|
||||
let bounds = crate::camera::get_screen_bounds(ecs);
|
||||
fn render_map_in_view(
|
||||
map: &Map,
|
||||
ecs: &World,
|
||||
draw: &mut Draw,
|
||||
atlas: &HashMap<String, Texture>,
|
||||
mapgen: bool
|
||||
) {
|
||||
let bounds = crate::camera::get_screen_bounds(ecs, mapgen);
|
||||
let mut y = 0;
|
||||
for tile_y in bounds.min_y..bounds.max_y {
|
||||
let mut x = 0;
|
||||
for tile_x in bounds.min_x..bounds.max_x {
|
||||
if crate::camera::in_bounds(tile_x, tile_y, 0, 0, map.width, map.height) {
|
||||
let idx = map.xy_idx(tile_x, tile_y);
|
||||
if map.revealed_tiles[idx] {
|
||||
if map.revealed_tiles[idx] || mapgen {
|
||||
if ASCII_MODE {
|
||||
let (glyph, fg, bg) = crate::map::themes::get_tile_renderables_for_id(
|
||||
idx,
|
||||
|
|
@ -286,11 +294,10 @@ fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, atlas: &HashMap<S
|
|||
&*map,
|
||||
Some(*ecs.fetch::<Point>())
|
||||
);
|
||||
let px = idx_to_px(map.xy_idx(tile_x, tile_y), &map);
|
||||
draw.image(atlas.get(id).unwrap())
|
||||
.position(
|
||||
px.0 + (bounds.x_offset as f32) * TILESIZE,
|
||||
px.1 + (bounds.y_offset as f32) * TILESIZE
|
||||
((x + bounds.x_offset) as f32) * TILESIZE,
|
||||
((y + bounds.y_offset) as f32) * TILESIZE
|
||||
)
|
||||
.color(tint);
|
||||
}
|
||||
|
|
@ -298,7 +305,9 @@ fn render_map_in_view(map: &Map, ecs: &World, draw: &mut Draw, atlas: &HashMap<S
|
|||
} else if SHOW_BOUNDARIES {
|
||||
// TODO: Draw boundaries
|
||||
}
|
||||
x += 1;
|
||||
}
|
||||
y += 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -418,6 +427,16 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
|
|||
| RunState::MainMenu { .. }
|
||||
| RunState::CharacterCreation { .. }
|
||||
| RunState::PreRun { .. } => {}
|
||||
RunState::MapGeneration => {
|
||||
draw_bg(&gs.ecs, &mut draw, &gs.atlas);
|
||||
render_map_in_view(
|
||||
&gs.mapgen_history[gs.mapgen_index],
|
||||
&gs.ecs,
|
||||
&mut draw,
|
||||
&gs.atlas,
|
||||
true
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
draw_bg(&gs.ecs, &mut draw, &gs.atlas);
|
||||
draw_camera(&gs.ecs, &mut draw, &gs.atlas);
|
||||
|
|
@ -440,8 +459,8 @@ fn draw(app: &mut App, gfx: &mut Graphics, gs: &mut State) {
|
|||
|
||||
fn idx_to_px(idx: usize, map: &Map) -> (f32, f32) {
|
||||
(
|
||||
((idx % (map.width as usize)) as i32 as f32) * (TILESIZE as f32),
|
||||
((idx / (map.width as usize)) as i32 as f32) * (TILESIZE as f32),
|
||||
((idx % (map.width as usize)) as f32) * (TILESIZE as f32),
|
||||
((idx / (map.width as usize)) as f32) * (TILESIZE as f32),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -749,7 +749,7 @@ pub fn player_input(gs: &mut State, ctx: &mut App, on_overmap: bool) -> RunState
|
|||
return RunState::SaveGame;
|
||||
}
|
||||
KeyCode::X => {
|
||||
let bounds = get_screen_bounds(&gs.ecs);
|
||||
let bounds = get_screen_bounds(&gs.ecs, false);
|
||||
let ppos = gs.ecs.fetch::<Point>();
|
||||
let (x, y) = (
|
||||
ppos.x + bounds.x_offset - bounds.min_x,
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ impl State {
|
|||
}
|
||||
//RunState::GameOver
|
||||
RunState::GoToLevel(id, dest_tile) => {
|
||||
self.goto_id(id, dest_tile);
|
||||
self.goto_id(id, dest_tile); // TODO: This causes issues being before swapping runstate?
|
||||
self.mapgen_next_state = Some(RunState::PreRun);
|
||||
new_runstate = RunState::MapGeneration;
|
||||
}
|
||||
|
|
@ -287,7 +287,31 @@ impl State {
|
|||
new_runstate = RunState::MagicMapReveal { row: row + 1, cursed: cursed };
|
||||
}
|
||||
}
|
||||
// RunState::MapGeneration
|
||||
RunState::MapGeneration => {
|
||||
if !config::CONFIG.logging.show_mapgen {
|
||||
new_runstate = self.mapgen_next_state.unwrap();
|
||||
} else {
|
||||
if self.mapgen_history.len() > 0 {
|
||||
console::log(
|
||||
format!(
|
||||
"mapgen_index: {} -- mapgen_history.len(): {} -- mapgen_timer: {} -- ctx.timer.delta_f32(): {}",
|
||||
self.mapgen_index,
|
||||
self.mapgen_history.len(),
|
||||
self.mapgen_timer,
|
||||
ctx.timer.delta_f32()
|
||||
)
|
||||
);
|
||||
self.mapgen_timer += ctx.timer.delta_f32();
|
||||
if self.mapgen_timer > 10.0 / (self.mapgen_history.len() as f32) {
|
||||
self.mapgen_timer = 0.0;
|
||||
self.mapgen_index += 1;
|
||||
if self.mapgen_index >= self.mapgen_history.len() {
|
||||
new_runstate = self.mapgen_next_state.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
{
|
||||
|
|
@ -446,7 +470,7 @@ impl State {
|
|||
if let Some(ranged_item) = ranged_item {
|
||||
let is_aoe = self.ecs.read_storage::<AOE>();
|
||||
let aoe_item = is_aoe.get(item_entity);
|
||||
let bounds = camera::get_screen_bounds(&self.ecs);
|
||||
let bounds = camera::get_screen_bounds(&self.ecs, false);
|
||||
let ppos = self.ecs.fetch::<Point>();
|
||||
if let Some(aoe_item) = aoe_item {
|
||||
new_runstate = RunState::ShowTargeting {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue