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_tz::Tz;
|
||||
use hashbrown::HashSet;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
@ -11,7 +10,7 @@ pub enum CalendarEvent {
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Calendar {
|
||||
events: HashSet<CalendarEvent>,
|
||||
events: Vec<CalendarEvent>,
|
||||
}
|
||||
|
||||
impl Calendar {
|
||||
@ -21,11 +20,7 @@ impl Calendar {
|
||||
self.events.iter()
|
||||
}
|
||||
|
||||
pub fn from_events(events: Vec<CalendarEvent>) -> Self {
|
||||
Self {
|
||||
events: events.into_iter().collect(),
|
||||
}
|
||||
}
|
||||
pub fn from_events(events: Vec<CalendarEvent>) -> Self { Self { events } }
|
||||
|
||||
pub fn from_tz(tz: Option<Tz>) -> Self {
|
||||
let mut this = Self::default();
|
||||
@ -39,7 +34,7 @@ impl Calendar {
|
||||
};
|
||||
|
||||
if now.month() == 12 && (24..=26).contains(&now.day()) {
|
||||
this.events.insert(CalendarEvent::Christmas);
|
||||
this.events.push(CalendarEvent::Christmas);
|
||||
}
|
||||
|
||||
this
|
||||
|
@ -361,7 +361,11 @@ impl Server {
|
||||
);
|
||||
|
||||
#[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"))]
|
||||
let (world, index) = World::generate(settings.world_seed);
|
||||
@ -597,7 +601,12 @@ impl Server {
|
||||
// Update calendar events as time changes
|
||||
// TODO: If a lot of calendar events get added, this might become expensive.
|
||||
// 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;
|
||||
|
||||
// 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};
|
||||
|
||||
use chrono::Utc;
|
||||
use common::{calendar::{Calendar, CalendarEvent}, resources::BattleMode};
|
||||
use common::{
|
||||
calendar::{Calendar, CalendarEvent},
|
||||
resources::BattleMode,
|
||||
};
|
||||
use core::time::Duration;
|
||||
use portpicker::pick_unused_port;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -4,7 +4,7 @@ use crate::{
|
||||
IndexRef,
|
||||
};
|
||||
use common::{
|
||||
calendar::Calendar,
|
||||
calendar::{Calendar, CalendarEvent},
|
||||
terrain::{
|
||||
structure::{self, StructureBlock},
|
||||
Block, BlockKind, SpriteKind,
|
||||
@ -43,7 +43,12 @@ impl<'a> BlockGen<'a> {
|
||||
.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;
|
||||
|
||||
// Main sample
|
||||
@ -241,6 +246,7 @@ pub fn block_from_structure(
|
||||
structure_seed: u32,
|
||||
sample: &ColumnSample,
|
||||
mut with_sprite: impl FnMut(SpriteKind) -> Block,
|
||||
calendar: Option<&Calendar>,
|
||||
) -> Option<Block> {
|
||||
let field = RandomField::new(structure_seed);
|
||||
|
||||
@ -316,15 +322,21 @@ pub fn block_from_structure(
|
||||
};
|
||||
|
||||
range.map(|range| {
|
||||
Block::new(
|
||||
BlockKind::Leaves,
|
||||
Rgb::<f32>::lerp(
|
||||
Rgb::<u8>::from(range.start).map(f32::from),
|
||||
Rgb::<u8>::from(range.end).map(f32::from),
|
||||
lerp,
|
||||
if calendar.map_or(false, |c| c.is_event(CalendarEvent::Christmas))
|
||||
&& field.chance(pos + structure_pos, 0.025)
|
||||
{
|
||||
Block::new(BlockKind::GlowingWeakRock, Rgb::new(255, 0, 0))
|
||||
} else {
|
||||
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 => {
|
||||
|
@ -29,6 +29,8 @@ pub struct 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 area(&self) -> Aabr<i32> {
|
||||
@ -53,9 +55,11 @@ impl<'a> CanvasInfo<'a> {
|
||||
/// This function does not (currently) cache generated columns.
|
||||
pub fn col_or_gen(&self, wpos: Vec2<i32>) -> Option<Cow<'a, ColumnSample>> {
|
||||
self.col(wpos).map(Cow::Borrowed).or_else(|| {
|
||||
Some(Cow::Owned(
|
||||
ColumnGen::new(self.chunks()).get((wpos, self.index(), self.calendar))?,
|
||||
))
|
||||
Some(Cow::Owned(ColumnGen::new(self.chunks()).get((
|
||||
wpos,
|
||||
self.index(),
|
||||
self.calendar,
|
||||
))?))
|
||||
})
|
||||
}
|
||||
|
||||
@ -224,6 +228,7 @@ impl<'a> Canvas<'a> {
|
||||
seed,
|
||||
col,
|
||||
|sprite| block.with_sprite(sprite),
|
||||
info.calendar,
|
||||
) {
|
||||
if !new_block.is_air() {
|
||||
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 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
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
enum TreeModel {
|
||||
@ -136,7 +140,11 @@ pub fn apply_trees_to(canvas: &mut Canvas, dynamic_rng: &mut impl Rng, calendar:
|
||||
ForestKind::Pine => {
|
||||
break 'model TreeModel::Procedural(
|
||||
ProceduralTree::generate(
|
||||
TreeConfig::pine(&mut RandomPerm::new(seed), scale, calendar),
|
||||
TreeConfig::pine(
|
||||
&mut RandomPerm::new(seed),
|
||||
scale,
|
||||
calendar,
|
||||
),
|
||||
&mut RandomPerm::new(seed),
|
||||
),
|
||||
StructureBlock::PineLeaves,
|
||||
@ -257,6 +265,7 @@ pub fn apply_trees_to(canvas: &mut Canvas, dynamic_rng: &mut impl Rng, calendar:
|
||||
tree.seed,
|
||||
col,
|
||||
Block::air,
|
||||
calendar,
|
||||
)
|
||||
.map(|block| {
|
||||
// Add lights to the tree
|
||||
|
@ -120,7 +120,12 @@ impl World {
|
||||
// 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(|| {
|
||||
// we need these numbers to create unique ids for cave ends
|
||||
let num_sites = self.civs().sites().count() as u64;
|
||||
@ -186,7 +191,10 @@ impl World {
|
||||
|
||||
pub fn sample_columns(
|
||||
&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)
|
||||
}
|
||||
|
||||
|
@ -39,8 +39,8 @@ use crate::{
|
||||
IndexRef, CONFIG,
|
||||
};
|
||||
use common::{
|
||||
calendar::Calendar,
|
||||
assets::{self, AssetExt},
|
||||
calendar::Calendar,
|
||||
grid::Grid,
|
||||
lottery::Lottery,
|
||||
spiral::Spiral2d,
|
||||
|
@ -280,6 +280,7 @@ impl Fill {
|
||||
*seed,
|
||||
col_sample,
|
||||
Block::air,
|
||||
canvas_info.calendar(),
|
||||
)
|
||||
}),
|
||||
Fill::Sampling(f) => f(pos),
|
||||
|
Loading…
Reference in New Issue
Block a user