Skip to content

Commit

Permalink
Fixed Map Loader issues
Browse files Browse the repository at this point in the history
  • Loading branch information
HikariIT committed May 10, 2024
1 parent 07fdca5 commit a939b09
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
3 changes: 2 additions & 1 deletion bdi_game/src/game/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ impl<D: GameDisplay> Game<D> {
display,
simulation: Simulation {
state: WorldState {},
grid: WorldGrid::from_map(map),
grid: WorldGrid { data: vec![] }
},
// grid: WorldGrid::from_height_map(map),
input: Input {},
}
}
Expand Down
4 changes: 2 additions & 2 deletions bdi_game/src/simulation/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub struct Grid<T>
where
T: Default + Clone,
{
data: Vec<Vec<GridCell<T>>>,
pub(crate) data: Vec<Vec<GridCell<T>>>,
}

impl<T> Grid<T>
Expand Down Expand Up @@ -34,7 +34,7 @@ where
&self.data[y][x]
}

pub fn set_cell_data(&self, point: &GridPoint, data: T) {
pub fn set_cell_data(&mut self, point: &GridPoint, data: T) {
let (x, y) = Self::get_cell_coord(point);
self.data[y][x] = GridCell { data };
}
Expand Down
10 changes: 6 additions & 4 deletions bdi_game/src/simulation/world_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use image::GrayImage;
use crate::simulation::grid::{Grid, GridPoint};
use crate::terrain_manager::sampler::Sampler2D;

struct WorldCellData {
#[derive(Default, Clone)]
pub(crate) struct WorldCellData {
elevation: i32,
// ...
}
Expand All @@ -14,10 +15,10 @@ impl WorldGrid {
pub fn from_height_map(height_map: GrayImage) -> WorldGrid {
let mut grid = WorldGrid::new(height_map.width() as usize);
let mut offset: i32 = 0;
let map_sampler = Sampler2D::new(height_map, height_map.width() as usize);
let map_sampler = Sampler2D::new(height_map.clone(), height_map.width() as usize);
for r in 0..height_map.height() {
for q in -offset..height_map.width() - offset {
for q in -offset..height_map.width() as i32 - offset {
let elevation = map_sampler.sample_hexagonal_axial(q, r as i32);
let point = GridPoint::new(q, r as i32);
grid.set_cell_data(&point, WorldCellData { elevation });
Expand All @@ -30,4 +31,5 @@ impl WorldGrid {
grid
}
}*/
}
*/
4 changes: 0 additions & 4 deletions bdi_game/src/terrain_manager/map.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
use image::GrayImage;
use serde::{Deserialize, Serialize};
use crate::terrain_manager::world_object::WorldObject;

#[derive(Serialize, Deserialize)]
pub struct Map {
pub side_len: usize,
pub height_map: GrayImage,
pub height_modifiers: GrayImage,
pub objects: Vec<WorldObject>,
}
2 changes: 1 addition & 1 deletion bdi_game/src/terrain_manager/map_loader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::{debug, info, trace};
use log::{debug, info};
use image::GrayImage;
use image::io::Reader as ImageReader;
use crate::asset_manager::asset_manager::AssetManager;
Expand Down
2 changes: 1 addition & 1 deletion bdi_game/src/terrain_manager/sampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl Sampler2D {
let scale = self.height_map.width() as f32 / self.side_len as f32;

let offset_q_x = scale * q as f32;
let offset_q_y = 0;
let offset_q_y = 0f32;

let offset_r_x = scale * 0.5 * r as f32;
let offset_r_y = scale * 3.0f32.sqrt() / 2.0 * r as f32;
Expand Down
1 change: 0 additions & 1 deletion bdi_game/src/terrain_manager/world_object.rs
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
pub struct WorldObject {}

0 comments on commit a939b09

Please sign in to comment.