Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

Commit

Permalink
Implement ChunkColumn baisc init_independant_light
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriTimoz committed Dec 25, 2023
1 parent 9828270 commit 113db1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
24 changes: 23 additions & 1 deletion minecraft-server/src/world/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,26 @@ impl LightManager {
}
}


impl ChunkColumn {
/// Init independant light means it will compute the light for all the chunk without considering the neighbour chunks.
pub(super) fn init_independant_light(&mut self) {
let _ = self.light.sky_light.set_region(self.get_highest_block() as usize + 1, ChunkColumn::MAX_HEIGHT as usize, self.light.sky_light.level);

for x in 0..16 {
for z in 0..16 {
for y in self.get_highest_block_at(&BlockPositionInChunkColumn {
bx: x,
y: 0i32,
bz: z
})..(self.get_highest_block() as u16) {
let _ = self.light.sky_light.set_level(
LightPositionInChunkColumn {
bx: x,
y: y as usize,
bz: z
}, self.light.sky_light.level);
}
}
}
}
}
13 changes: 9 additions & 4 deletions minecraft-server/src/world/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use minecraft_protocol::{components::chunk::PalettedData, ids::blocks::Block};
use tokio::sync::{RwLock, OwnedRwLockWriteGuard};
use crate::{prelude::*, world::light::LightManager};

use super::light::Light;

pub struct WorldMap {
/// The map is divided in shards.
/// Chunks are evenly distributed between shards.
Expand Down Expand Up @@ -297,6 +299,7 @@ impl HeightMap {
}

pub(super) struct ChunkColumn {
pub(super) light: Light,
heightmap: HeightMap,
chunks: Vec<Chunk>,
}
Expand Down Expand Up @@ -350,7 +353,9 @@ impl ChunkColumn {
let mut column = Self {
chunks,
heightmap: HeightMap::new(8),
light: Light::new(),
};
column.init_independant_light();
column.init_chunk_heightmap();
column
}
Expand Down Expand Up @@ -515,19 +520,19 @@ impl WorldMap {
let chunk_column = shard.get(&position)?;

let serialized = NetworkChunk::into_data(chunk_column.chunks.iter().map(|c| c.data.clone()).collect()).unwrap();
//let (skylight_array_data, skylight_mask, empty_skylight_mask) = chunk_column.light.get_packet();
let (sky_light, sky_light_mask, empty_sky_light_mask) = chunk_column.light.get_packet();

let chunk_data = PlayClientbound::ChunkData { value: NetworkChunkColumnData {
chunk_x: position.cx,
chunk_z: position.cz,
heightmaps: chunk_column.heightmap.to_tag(),
data: Array::from(serialized.clone()),
block_entities: Array::default(),
sky_light_mask: Array::default(),//skylight_mask,
sky_light_mask,
block_light_mask: Array::default(),
empty_sky_light_mask: Array::default(), //empty_skylight_mask,
empty_sky_light_mask,
empty_block_light_mask: Array::default(),
sky_light: Array::default(), //skylight_array_data,
sky_light,
block_light: Array::default(),
}};
let serialized = chunk_data.serialize_minecraft_packet().ok()?;
Expand Down

0 comments on commit 113db1e

Please sign in to comment.