mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added baubles to trees
This commit is contained in:
parent
3ddacb96ab
commit
78f76dde83
@ -1,6 +1,5 @@
|
|||||||
use chrono::{DateTime, Datelike, Local, TimeZone, Utc};
|
use chrono::{DateTime, Datelike, Local, TimeZone, Utc};
|
||||||
use chrono_tz::Tz;
|
use chrono_tz::Tz;
|
||||||
use hashbrown::HashSet;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
@ -11,7 +10,7 @@ pub enum CalendarEvent {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||||
pub struct Calendar {
|
pub struct Calendar {
|
||||||
events: HashSet<CalendarEvent>,
|
events: Vec<CalendarEvent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Calendar {
|
impl Calendar {
|
||||||
@ -21,11 +20,7 @@ impl Calendar {
|
|||||||
self.events.iter()
|
self.events.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_events(events: Vec<CalendarEvent>) -> Self {
|
pub fn from_events(events: Vec<CalendarEvent>) -> Self { Self { events } }
|
||||||
Self {
|
|
||||||
events: events.into_iter().collect(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_tz(tz: Option<Tz>) -> Self {
|
pub fn from_tz(tz: Option<Tz>) -> Self {
|
||||||
let mut this = Self::default();
|
let mut this = Self::default();
|
||||||
@ -39,7 +34,7 @@ impl Calendar {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if now.month() == 12 && (24..=26).contains(&now.day()) {
|
if now.month() == 12 && (24..=26).contains(&now.day()) {
|
||||||
this.events.insert(CalendarEvent::Christmas);
|
this.events.push(CalendarEvent::Christmas);
|
||||||
}
|
}
|
||||||
|
|
||||||
this
|
this
|
||||||
|
@ -361,7 +361,11 @@ impl Server {
|
|||||||
);
|
);
|
||||||
|
|
||||||
#[cfg(feature = "worldgen")]
|
#[cfg(feature = "worldgen")]
|
||||||
let map = world.get_map_data(index.as_index_ref(), Some(&settings.calendar_mode.calendar_now()), state.thread_pool());
|
let map = world.get_map_data(
|
||||||
|
index.as_index_ref(),
|
||||||
|
Some(&settings.calendar_mode.calendar_now()),
|
||||||
|
state.thread_pool(),
|
||||||
|
);
|
||||||
|
|
||||||
#[cfg(not(feature = "worldgen"))]
|
#[cfg(not(feature = "worldgen"))]
|
||||||
let (world, index) = World::generate(settings.world_seed);
|
let (world, index) = World::generate(settings.world_seed);
|
||||||
@ -597,7 +601,12 @@ impl Server {
|
|||||||
// Update calendar events as time changes
|
// Update calendar events as time changes
|
||||||
// TODO: If a lot of calendar events get added, this might become expensive.
|
// TODO: If a lot of calendar events get added, this might become expensive.
|
||||||
// Maybe don't do this every tick?
|
// Maybe don't do this every tick?
|
||||||
let new_calendar = self.state.ecs().read_resource::<Settings>().calendar_mode.calendar_now();
|
let new_calendar = self
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.read_resource::<Settings>()
|
||||||
|
.calendar_mode
|
||||||
|
.calendar_now();
|
||||||
*self.state.ecs_mut().write_resource::<Calendar>() = new_calendar;
|
*self.state.ecs_mut().write_resource::<Calendar>() = new_calendar;
|
||||||
|
|
||||||
// This tick function is the centre of the Veloren universe. Most server-side
|
// This tick function is the centre of the Veloren universe. Most server-side
|
||||||
|
@ -14,7 +14,10 @@ pub use server_description::ServerDescription;
|
|||||||
pub use whitelist::{Whitelist, WhitelistInfo, WhitelistRecord};
|
pub use whitelist::{Whitelist, WhitelistInfo, WhitelistRecord};
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use common::{calendar::{Calendar, CalendarEvent}, resources::BattleMode};
|
use common::{
|
||||||
|
calendar::{Calendar, CalendarEvent},
|
||||||
|
resources::BattleMode,
|
||||||
|
};
|
||||||
use core::time::Duration;
|
use core::time::Duration;
|
||||||
use portpicker::pick_unused_port;
|
use portpicker::pick_unused_port;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -4,7 +4,7 @@ use crate::{
|
|||||||
IndexRef,
|
IndexRef,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
calendar::Calendar,
|
calendar::{Calendar, CalendarEvent},
|
||||||
terrain::{
|
terrain::{
|
||||||
structure::{self, StructureBlock},
|
structure::{self, StructureBlock},
|
||||||
Block, BlockKind, SpriteKind,
|
Block, BlockKind, SpriteKind,
|
||||||
@ -43,7 +43,12 @@ impl<'a> BlockGen<'a> {
|
|||||||
.as_ref()
|
.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_z_cache(&mut self, wpos: Vec2<i32>, index: IndexRef<'a>, calendar: Option<&'a Calendar>) -> Option<ZCache<'a>> {
|
pub fn get_z_cache(
|
||||||
|
&mut self,
|
||||||
|
wpos: Vec2<i32>,
|
||||||
|
index: IndexRef<'a>,
|
||||||
|
calendar: Option<&'a Calendar>,
|
||||||
|
) -> Option<ZCache<'a>> {
|
||||||
let BlockGen { column_gen } = self;
|
let BlockGen { column_gen } = self;
|
||||||
|
|
||||||
// Main sample
|
// Main sample
|
||||||
@ -241,6 +246,7 @@ pub fn block_from_structure(
|
|||||||
structure_seed: u32,
|
structure_seed: u32,
|
||||||
sample: &ColumnSample,
|
sample: &ColumnSample,
|
||||||
mut with_sprite: impl FnMut(SpriteKind) -> Block,
|
mut with_sprite: impl FnMut(SpriteKind) -> Block,
|
||||||
|
calendar: Option<&Calendar>,
|
||||||
) -> Option<Block> {
|
) -> Option<Block> {
|
||||||
let field = RandomField::new(structure_seed);
|
let field = RandomField::new(structure_seed);
|
||||||
|
|
||||||
@ -316,15 +322,21 @@ pub fn block_from_structure(
|
|||||||
};
|
};
|
||||||
|
|
||||||
range.map(|range| {
|
range.map(|range| {
|
||||||
Block::new(
|
if calendar.map_or(false, |c| c.is_event(CalendarEvent::Christmas))
|
||||||
BlockKind::Leaves,
|
&& field.chance(pos + structure_pos, 0.025)
|
||||||
Rgb::<f32>::lerp(
|
{
|
||||||
Rgb::<u8>::from(range.start).map(f32::from),
|
Block::new(BlockKind::GlowingWeakRock, Rgb::new(255, 0, 0))
|
||||||
Rgb::<u8>::from(range.end).map(f32::from),
|
} else {
|
||||||
lerp,
|
Block::new(
|
||||||
|
BlockKind::Leaves,
|
||||||
|
Rgb::<f32>::lerp(
|
||||||
|
Rgb::<u8>::from(range.start).map(f32::from),
|
||||||
|
Rgb::<u8>::from(range.end).map(f32::from),
|
||||||
|
lerp,
|
||||||
|
)
|
||||||
|
.map(|e| e as u8),
|
||||||
)
|
)
|
||||||
.map(|e| e as u8),
|
}
|
||||||
)
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
StructureBlock::BirchWood => {
|
StructureBlock::BirchWood => {
|
||||||
|
@ -29,6 +29,8 @@ pub struct CanvasInfo<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> CanvasInfo<'a> {
|
impl<'a> CanvasInfo<'a> {
|
||||||
|
pub fn calendar(&self) -> Option<&'a Calendar> { self.calendar }
|
||||||
|
|
||||||
pub fn wpos(&self) -> Vec2<i32> { self.wpos }
|
pub fn wpos(&self) -> Vec2<i32> { self.wpos }
|
||||||
|
|
||||||
pub fn area(&self) -> Aabr<i32> {
|
pub fn area(&self) -> Aabr<i32> {
|
||||||
@ -53,9 +55,11 @@ impl<'a> CanvasInfo<'a> {
|
|||||||
/// This function does not (currently) cache generated columns.
|
/// This function does not (currently) cache generated columns.
|
||||||
pub fn col_or_gen(&self, wpos: Vec2<i32>) -> Option<Cow<'a, ColumnSample>> {
|
pub fn col_or_gen(&self, wpos: Vec2<i32>) -> Option<Cow<'a, ColumnSample>> {
|
||||||
self.col(wpos).map(Cow::Borrowed).or_else(|| {
|
self.col(wpos).map(Cow::Borrowed).or_else(|| {
|
||||||
Some(Cow::Owned(
|
Some(Cow::Owned(ColumnGen::new(self.chunks()).get((
|
||||||
ColumnGen::new(self.chunks()).get((wpos, self.index(), self.calendar))?,
|
wpos,
|
||||||
))
|
self.index(),
|
||||||
|
self.calendar,
|
||||||
|
))?))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +228,7 @@ impl<'a> Canvas<'a> {
|
|||||||
seed,
|
seed,
|
||||||
col,
|
col,
|
||||||
|sprite| block.with_sprite(sprite),
|
|sprite| block.with_sprite(sprite),
|
||||||
|
info.calendar,
|
||||||
) {
|
) {
|
||||||
if !new_block.is_air() {
|
if !new_block.is_air() {
|
||||||
if with_snow && col.snow_cover && above {
|
if with_snow && col.snow_cover && above {
|
||||||
|
@ -34,7 +34,11 @@ static MODEL_RAND: RandomPerm = RandomPerm::new(0xDB21C052);
|
|||||||
static UNIT_CHOOSER: UnitChooser = UnitChooser::new(0x700F4EC7);
|
static UNIT_CHOOSER: UnitChooser = UnitChooser::new(0x700F4EC7);
|
||||||
static QUIRKY_RAND: RandomPerm = RandomPerm::new(0xA634460F);
|
static QUIRKY_RAND: RandomPerm = RandomPerm::new(0xA634460F);
|
||||||
|
|
||||||
pub fn apply_trees_to(canvas: &mut Canvas, dynamic_rng: &mut impl Rng, calendar: Option<&Calendar>) {
|
pub fn apply_trees_to(
|
||||||
|
canvas: &mut Canvas,
|
||||||
|
dynamic_rng: &mut impl Rng,
|
||||||
|
calendar: Option<&Calendar>,
|
||||||
|
) {
|
||||||
// TODO: Get rid of this
|
// TODO: Get rid of this
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
enum TreeModel {
|
enum TreeModel {
|
||||||
@ -136,7 +140,11 @@ pub fn apply_trees_to(canvas: &mut Canvas, dynamic_rng: &mut impl Rng, calendar:
|
|||||||
ForestKind::Pine => {
|
ForestKind::Pine => {
|
||||||
break 'model TreeModel::Procedural(
|
break 'model TreeModel::Procedural(
|
||||||
ProceduralTree::generate(
|
ProceduralTree::generate(
|
||||||
TreeConfig::pine(&mut RandomPerm::new(seed), scale, calendar),
|
TreeConfig::pine(
|
||||||
|
&mut RandomPerm::new(seed),
|
||||||
|
scale,
|
||||||
|
calendar,
|
||||||
|
),
|
||||||
&mut RandomPerm::new(seed),
|
&mut RandomPerm::new(seed),
|
||||||
),
|
),
|
||||||
StructureBlock::PineLeaves,
|
StructureBlock::PineLeaves,
|
||||||
@ -257,6 +265,7 @@ pub fn apply_trees_to(canvas: &mut Canvas, dynamic_rng: &mut impl Rng, calendar:
|
|||||||
tree.seed,
|
tree.seed,
|
||||||
col,
|
col,
|
||||||
Block::air,
|
Block::air,
|
||||||
|
calendar,
|
||||||
)
|
)
|
||||||
.map(|block| {
|
.map(|block| {
|
||||||
// Add lights to the tree
|
// Add lights to the tree
|
||||||
|
@ -120,7 +120,12 @@ impl World {
|
|||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_map_data(&self, index: IndexRef, calendar: Option<&Calendar>, threadpool: &rayon::ThreadPool) -> WorldMapMsg {
|
pub fn get_map_data(
|
||||||
|
&self,
|
||||||
|
index: IndexRef,
|
||||||
|
calendar: Option<&Calendar>,
|
||||||
|
threadpool: &rayon::ThreadPool,
|
||||||
|
) -> WorldMapMsg {
|
||||||
threadpool.install(|| {
|
threadpool.install(|| {
|
||||||
// we need these numbers to create unique ids for cave ends
|
// we need these numbers to create unique ids for cave ends
|
||||||
let num_sites = self.civs().sites().count() as u64;
|
let num_sites = self.civs().sites().count() as u64;
|
||||||
@ -186,7 +191,10 @@ impl World {
|
|||||||
|
|
||||||
pub fn sample_columns(
|
pub fn sample_columns(
|
||||||
&self,
|
&self,
|
||||||
) -> impl Sampler<Index = (Vec2<i32>, IndexRef, Option<&'_ Calendar>), Sample = Option<ColumnSample>> + '_ {
|
) -> impl Sampler<
|
||||||
|
Index = (Vec2<i32>, IndexRef, Option<&'_ Calendar>),
|
||||||
|
Sample = Option<ColumnSample>,
|
||||||
|
> + '_ {
|
||||||
ColumnGen::new(&self.sim)
|
ColumnGen::new(&self.sim)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ use crate::{
|
|||||||
IndexRef, CONFIG,
|
IndexRef, CONFIG,
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
calendar::Calendar,
|
|
||||||
assets::{self, AssetExt},
|
assets::{self, AssetExt},
|
||||||
|
calendar::Calendar,
|
||||||
grid::Grid,
|
grid::Grid,
|
||||||
lottery::Lottery,
|
lottery::Lottery,
|
||||||
spiral::Spiral2d,
|
spiral::Spiral2d,
|
||||||
|
@ -280,6 +280,7 @@ impl Fill {
|
|||||||
*seed,
|
*seed,
|
||||||
col_sample,
|
col_sample,
|
||||||
Block::air,
|
Block::air,
|
||||||
|
canvas_info.calendar(),
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
Fill::Sampling(f) => f(pos),
|
Fill::Sampling(f) => f(pos),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user