-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to formatting and to failing builds
- Loading branch information
Showing
12 changed files
with
128 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
pub struct AssetManager {} | ||
|
||
impl AssetManager { | ||
const ASSET_DIR: &'static str = "assets"; | ||
|
||
const MAP_SUBDIR: &'static str = "maps"; | ||
const MAP_EXTENSION: &'static str = "png"; | ||
|
||
pub fn get_map_path(map_name: &str) -> String { | ||
format!("{}/{}/{}.{}", Self::ASSET_DIR, Self::MAP_SUBDIR, map_name, Self::MAP_EXTENSION) | ||
} | ||
} | ||
pub struct AssetManager {} | ||
|
||
impl AssetManager { | ||
const ASSET_DIR: &'static str = "assets"; | ||
|
||
const MAP_SUBDIR: &'static str = "maps"; | ||
const MAP_EXTENSION: &'static str = "png"; | ||
|
||
pub fn get_map_path(map_name: &str) -> String { | ||
format!( | ||
"{}/{}/{}.{}", | ||
Self::ASSET_DIR, | ||
Self::MAP_SUBDIR, | ||
map_name, | ||
Self::MAP_EXTENSION | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
pub mod asset_manager; | ||
pub mod asset_manager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
pub mod algorithms; | ||
pub mod terrain_manager; | ||
mod asset_manager; | ||
pub mod display; | ||
pub mod game; | ||
mod input; | ||
mod simulation; | ||
mod asset_manager; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
use image::GrayImage; | ||
|
||
pub struct Map { | ||
pub side_len: usize, | ||
pub height_map: GrayImage, | ||
pub height_modifiers: GrayImage, | ||
} | ||
use image::GrayImage; | ||
|
||
pub struct Map { | ||
pub side_len: usize, | ||
pub height_map: GrayImage, | ||
pub height_modifiers: GrayImage, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,36 @@ | ||
use log::{debug, info}; | ||
use image::GrayImage; | ||
use image::io::Reader as ImageReader; | ||
use crate::asset_manager::asset_manager::AssetManager; | ||
|
||
pub struct MapLoader { | ||
map_asset_path: String, | ||
} | ||
|
||
impl MapLoader { | ||
pub fn map_from_image(map_name: &str) -> GrayImage { | ||
let map_path = AssetManager::get_map_path(map_name); | ||
|
||
let img = match ImageReader::open(map_path) { | ||
Ok(img) => img, | ||
Err(e) => { | ||
eprintln!("Error while loading map from file: {}", e); | ||
return GrayImage::new(0, 0); | ||
} | ||
}; | ||
|
||
let img = match img.decode() { | ||
Ok(img) => img, | ||
Err(e) => { | ||
eprintln!("Error while decoding map format: {}", e); | ||
return GrayImage::new(0, 0); | ||
} | ||
}; | ||
|
||
info!("Map '{}' loaded successfully!", map_name); | ||
debug!("Map format: {:?}", img.color()); | ||
debug!("Map dimensions: {}x{}", img.width(), img.height()); | ||
|
||
return img.into_luma8(); | ||
} | ||
} | ||
use crate::asset_manager::asset_manager::AssetManager; | ||
use image::io::Reader as ImageReader; | ||
use image::GrayImage; | ||
use log::{debug, info}; | ||
|
||
pub struct MapLoader { | ||
map_asset_path: String, | ||
} | ||
|
||
impl MapLoader { | ||
pub fn map_from_image(map_name: &str) -> GrayImage { | ||
let map_path = AssetManager::get_map_path(map_name); | ||
|
||
let img = match ImageReader::open(map_path) { | ||
Ok(img) => img, | ||
Err(e) => { | ||
eprintln!("Error while loading map from file: {}", e); | ||
return GrayImage::new(0, 0); | ||
} | ||
}; | ||
|
||
let img = match img.decode() { | ||
Ok(img) => img, | ||
Err(e) => { | ||
eprintln!("Error while decoding map format: {}", e); | ||
return GrayImage::new(0, 0); | ||
} | ||
}; | ||
|
||
info!("Map '{}' loaded successfully!", map_name); | ||
debug!("Map format: {:?}", img.color()); | ||
debug!("Map dimensions: {}x{}", img.width(), img.height()); | ||
|
||
return img.into_luma8(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod map_loader; | ||
pub mod sampler; | ||
mod map; | ||
mod world_object; | ||
mod map; | ||
pub mod map_loader; | ||
pub mod sampler; | ||
mod world_object; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
use image::GrayImage; | ||
|
||
pub struct Sampler2D { | ||
height_map: GrayImage, | ||
side_len: usize, | ||
} | ||
|
||
impl Sampler2D { | ||
pub fn new(height_map: GrayImage, side_len: usize) -> Sampler2D { | ||
Sampler2D { | ||
height_map, | ||
side_len | ||
} | ||
} | ||
|
||
pub fn sample_hexagonal_axial(&self, q: i32, r: i32) -> i32 { | ||
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 = 0f32; | ||
|
||
let offset_r_x = scale * 0.5 * r as f32; | ||
let offset_r_y = scale * 3.0f32.sqrt() / 2.0 * r as f32; | ||
|
||
let x = offset_q_x + offset_r_x; | ||
let y = offset_q_y + offset_r_y; | ||
|
||
// Linear interpolation | ||
let x0 = x.floor() as u32; | ||
let x1 = x.ceil() as u32; | ||
let y0 = y.floor() as u32; | ||
let y1 = y.ceil() as u32; | ||
|
||
let x0y0 = self.height_map.get_pixel(x0, y0)[0] as f32; | ||
let x1y0 = self.height_map.get_pixel(x1, y0)[0] as f32; | ||
let x0y1 = self.height_map.get_pixel(x0, y1)[0] as f32; | ||
let x1y1 = self.height_map.get_pixel(x1, y1)[0] as f32; | ||
|
||
let x0y = x0y0 + (x0y1 - x0y0) * (y - y0 as f32); | ||
let x1y = x1y0 + (x1y1 - x1y0) * (y - y0 as f32); | ||
|
||
(x0y + (x1y - x0y) * (x - x0 as f32)) as i32 | ||
} | ||
} | ||
use image::GrayImage; | ||
|
||
pub struct Sampler2D { | ||
height_map: GrayImage, | ||
side_len: usize, | ||
} | ||
|
||
impl Sampler2D { | ||
pub fn new(height_map: GrayImage, side_len: usize) -> Sampler2D { | ||
Sampler2D { | ||
height_map, | ||
side_len, | ||
} | ||
} | ||
|
||
pub fn sample_hexagonal_axial(&self, q: i32, r: i32) -> i32 { | ||
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 = 0f32; | ||
|
||
let offset_r_x = scale * 0.5 * r as f32; | ||
let offset_r_y = scale * 3.0f32.sqrt() / 2.0 * r as f32; | ||
|
||
let x = offset_q_x + offset_r_x; | ||
let y = offset_q_y + offset_r_y; | ||
|
||
// Linear interpolation | ||
let x0 = x.floor() as u32; | ||
let x1 = x.ceil() as u32; | ||
let y0 = y.floor() as u32; | ||
let y1 = y.ceil() as u32; | ||
|
||
let x0y0 = self.height_map.get_pixel(x0, y0)[0] as f32; | ||
let x1y0 = self.height_map.get_pixel(x1, y0)[0] as f32; | ||
let x0y1 = self.height_map.get_pixel(x0, y1)[0] as f32; | ||
let x1y1 = self.height_map.get_pixel(x1, y1)[0] as f32; | ||
|
||
let x0y = x0y0 + (x0y1 - x0y0) * (y - y0 as f32); | ||
let x1y = x1y0 + (x1y1 - x1y0) * (y - y0 as f32); | ||
|
||
(x0y + (x1y - x0y) * (x - x0 as f32)) as i32 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|