Skip to content

Commit

Permalink
Merge branch 'master' into chunk-data
Browse files Browse the repository at this point in the history
  • Loading branch information
Asurar0 authored Sep 17, 2024
2 parents 467a02e + 810ecbe commit fafcd7d
Show file tree
Hide file tree
Showing 51 changed files with 3,089 additions and 627 deletions.
84 changes: 84 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ tokio = { version = "1.40", features = [
"io-util",
"sync",
] }
speedy = "0.8.7"

# Concurrency/Parallelism and Synchronization
rayon = "1.10.0"
parking_lot = "0.12.3"
crossbeam = "0.8.4"

speedy = "0.8.7"
uuid = { version = "1.10.0", features = ["serde", "v3", "v4"] }
derive_more = { version = "1.0.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
7 changes: 7 additions & 0 deletions pumpkin-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### Pumpkin Configuration
Pumpkin offers a robust configuration system that allows users to customize various aspects of the server's behavior without relying on external plugins. This provides flexibility and control over the server's operation.

#### Key Features:
- Extensive Customization: Configure server settings, player behavior, world generation, and more.
- Performance Optimization: Optimize server performance through configuration tweaks.
- Plugin-Free Customization: Achieve desired changes without the need for additional plugins.
1 change: 1 addition & 0 deletions pumpkin-core/src/math/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};

use super::vector3::Vector3;

#[derive(Clone, Copy)]
/// Aka Block Position
pub struct WorldPosition(pub Vector3<i32>);

Expand Down
2 changes: 2 additions & 0 deletions pumpkin-core/src/math/vector3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ impl<T: Math + Copy> Neg for Vector3<T> {
}

impl<T> From<(T, T, T)> for Vector3<T> {
#[inline(always)]
fn from((x, y, z): (T, T, T)) -> Self {
Vector3 { x, y, z }
}
}

impl<T> From<Vector3<T>> for (T, T, T) {
#[inline(always)]
fn from(vector: Vector3<T>) -> Self {
(vector.x, vector.y, vector.z)
}
Expand Down
21 changes: 8 additions & 13 deletions pumpkin-core/src/random/gaussian.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
use super::Random;
use super::RandomImpl;

pub trait GaussianGenerator: Random {
fn has_next_gaussian(&self) -> bool;
pub trait GaussianGenerator: RandomImpl {
fn stored_next_gaussian(&self) -> Option<f64>;

fn set_has_next_gaussian(&mut self, value: bool);

fn stored_next_gaussian(&self) -> f64;

fn set_stored_next_gaussian(&mut self, value: f64);
fn set_stored_next_gaussian(&mut self, value: Option<f64>);

fn calculate_gaussian(&mut self) -> f64 {
if self.has_next_gaussian() {
self.set_has_next_gaussian(false);
self.stored_next_gaussian()
if let Some(gaussian) = self.stored_next_gaussian() {
self.set_stored_next_gaussian(None);
gaussian
} else {
loop {
let d = 2f64 * self.next_f64() - 1f64;
Expand All @@ -21,8 +17,7 @@ pub trait GaussianGenerator: Random {

if f < 1f64 && f != 0f64 {
let g = (-2f64 * f.ln() / f).sqrt();
self.set_stored_next_gaussian(e * g);
self.set_has_next_gaussian(true);
self.set_stored_next_gaussian(Some(e * g));
return d * g;
}
}
Expand Down
57 changes: 30 additions & 27 deletions pumpkin-core/src/random/legacy_rand.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use super::{
gaussian::GaussianGenerator, hash_block_pos, java_string_hash, Random, RandomSplitter,
gaussian::GaussianGenerator, hash_block_pos, java_string_hash, RandomDeriverImpl, RandomImpl,
};

struct LegacyRand {
pub struct LegacyRand {
seed: u64,
internal_next_gaussian: f64,
internal_has_next_gaussian: bool,
internal_next_gaussian: Option<f64>,
}

impl LegacyRand {
Expand All @@ -18,29 +17,20 @@ impl LegacyRand {
}

impl GaussianGenerator for LegacyRand {
fn has_next_gaussian(&self) -> bool {
self.internal_has_next_gaussian
}

fn stored_next_gaussian(&self) -> f64 {
fn stored_next_gaussian(&self) -> Option<f64> {
self.internal_next_gaussian
}

fn set_has_next_gaussian(&mut self, value: bool) {
self.internal_has_next_gaussian = value;
}

fn set_stored_next_gaussian(&mut self, value: f64) {
fn set_stored_next_gaussian(&mut self, value: Option<f64>) {
self.internal_next_gaussian = value;
}
}

impl Random for LegacyRand {
impl RandomImpl for LegacyRand {
fn from_seed(seed: u64) -> Self {
LegacyRand {
seed: (seed ^ 0x5DEECE66D) & 0xFFFFFFFFFFFF,
internal_has_next_gaussian: false,
internal_next_gaussian: 0f64,
internal_next_gaussian: None,
}
}

Expand Down Expand Up @@ -77,7 +67,8 @@ impl Random for LegacyRand {
self.next(1) != 0
}

fn next_splitter(&mut self) -> impl RandomSplitter {
#[allow(refining_impl_trait)]
fn next_splitter(&mut self) -> LegacySplitter {
LegacySplitter::new(self.next_i64() as u64)
}

Expand All @@ -86,21 +77,21 @@ impl Random for LegacyRand {
}

fn next_bounded_i32(&mut self, bound: i32) -> i32 {
if bound & (bound - 1) == 0 {
(bound as u64).wrapping_mul(self.next(31) >> 31) as i32
if (bound & bound.wrapping_sub(1)) == 0 {
((bound as u64).wrapping_mul(self.next(31)) >> 31) as i32
} else {
loop {
let i = self.next(31) as i32;
let j = i % bound;
if (i - j + (bound - 1)) > 0 {
if (i.wrapping_sub(j).wrapping_add(bound.wrapping_sub(1))) >= 0 {
return j;
}
}
}
}
}

struct LegacySplitter {
pub struct LegacySplitter {
seed: u64,
}

Expand All @@ -110,25 +101,26 @@ impl LegacySplitter {
}
}

impl RandomSplitter for LegacySplitter {
fn split_u64(&self, seed: u64) -> impl Random {
#[allow(refining_impl_trait)]
impl RandomDeriverImpl for LegacySplitter {
fn split_u64(&self, seed: u64) -> LegacyRand {
LegacyRand::from_seed(seed)
}

fn split_string(&self, seed: &str) -> impl Random {
fn split_string(&self, seed: &str) -> LegacyRand {
let string_hash = java_string_hash(seed);
LegacyRand::from_seed((string_hash as u64) ^ self.seed)
}

fn split_pos(&self, x: i32, y: i32, z: i32) -> impl Random {
fn split_pos(&self, x: i32, y: i32, z: i32) -> LegacyRand {
let pos_hash = hash_block_pos(x, y, z);
LegacyRand::from_seed((pos_hash as u64) ^ self.seed)
}
}

#[cfg(test)]
mod test {
use crate::random::{Random, RandomSplitter};
use crate::random::{RandomDeriverImpl, RandomImpl};

use super::LegacyRand;

Expand Down Expand Up @@ -163,6 +155,17 @@ mod test {
for value in values {
assert_eq!(rand.next_bounded_i32(0xf), value);
}

let mut rand = LegacyRand::from_seed(0);
for _ in 0..10 {
assert_eq!(rand.next_bounded_i32(1), 0);
}

let mut rand = LegacyRand::from_seed(0);
let values = [1, 1, 0, 1, 1, 0, 1, 0, 1, 1];
for value in values {
assert_eq!(rand.next_bounded_i32(2), value);
}
}

#[test]
Expand Down
Loading

0 comments on commit fafcd7d

Please sign in to comment.