init world

This commit is contained in:
griffi-gh 2023-01-16 20:15:48 +01:00
parent 2a647604ff
commit 77f388dd75
2 changed files with 10 additions and 1 deletions

View file

@ -1,7 +1,7 @@
use glium::{Surface, uniform}; use glium::{Surface, uniform};
use glium::uniforms::{Sampler, MinifySamplerFilter, MagnifySamplerFilter}; use glium::uniforms::{Sampler, MinifySamplerFilter, MagnifySamplerFilter};
use glium::glutin::{ use glium::glutin::{
event::{Event, WindowEvent, DeviceEvent, KeyboardInput, VirtualKeyCode}, event::{Event, WindowEvent, DeviceEvent},
event_loop::{EventLoop, ControlFlow}, event_loop::{EventLoop, ControlFlow},
}; };
use std::time::Instant; use std::time::Instant;
@ -21,15 +21,19 @@ use display::init_display;
use shaders::{Programs, chunk::Vertex as ChunkVertex}; use shaders::{Programs, chunk::Vertex as ChunkVertex};
use camera::Camera; use camera::Camera;
use controller::Controls; use controller::Controls;
use world::World;
struct State { struct State {
pub camera: Camera, pub camera: Camera,
pub controls: Controls, pub controls: Controls,
pub world: World
} }
impl State { impl State {
pub fn init() -> Self { pub fn init() -> Self {
Self { Self {
camera: Camera::default(), camera: Camera::default(),
controls: Controls::default(), controls: Controls::default(),
world: World::new(),
} }
} }
} }

View file

@ -11,6 +11,11 @@ pub struct World {
pub chunks: HashMap<IVec2, Chunk> pub chunks: HashMap<IVec2, Chunk>
} }
impl World { impl World {
pub fn new() -> Self {
Self {
chunks: HashMap::new()
}
}
pub fn update_loaded_chunks(&mut self, around_position: Vec2, game_opt: &GameOptions) { pub fn update_loaded_chunks(&mut self, around_position: Vec2, game_opt: &GameOptions) {
let render_dist = game_opt.render_distance as i32; let render_dist = game_opt.render_distance as i32;
let inside_chunk = (around_position / CHUNK_SIZE as f32).as_ivec2(); let inside_chunk = (around_position / CHUNK_SIZE as f32).as_ivec2();