From 83f9c40601d7e6381b4a4ba3f072400fcf2fecee Mon Sep 17 00:00:00 2001 From: Andrew Gazelka Date: Thu, 21 Mar 2024 17:48:47 -0500 Subject: [PATCH] refactor: remove prototype fcrate --- Cargo.toml | 10 +- prototype/.github/workflows/build.yml | 117 ------------------- prototype/.gitignore | 1 - prototype/Cargo.toml | 76 ------------ prototype/README.md | 0 prototype/clippy.toml | 3 - prototype/rustfmt.toml | 21 ---- prototype/src/global.rs | 30 ----- prototype/src/lib.rs | 160 -------------------------- prototype/src/messages.rs | 47 -------- prototype/src/utils.rs | 80 ------------- 11 files changed, 3 insertions(+), 542 deletions(-) delete mode 100644 prototype/.github/workflows/build.yml delete mode 100644 prototype/.gitignore delete mode 100644 prototype/Cargo.toml delete mode 100644 prototype/README.md delete mode 100644 prototype/clippy.toml delete mode 100644 prototype/rustfmt.toml delete mode 100644 prototype/src/global.rs delete mode 100644 prototype/src/lib.rs delete mode 100644 prototype/src/messages.rs delete mode 100644 prototype/src/utils.rs diff --git a/Cargo.toml b/Cargo.toml index 73251d53..90a1488a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,11 +3,7 @@ resolver = "2" members = [ "server", -# "prototype" ] -#lto = true -#codegen-units = 1 - [profile.dev] opt-level = 1 @@ -15,6 +11,6 @@ opt-level = 1 [profile.dev.package."*"] opt-level = 3 - - - +[profile.release] +#lto = true +#codegen-units = 1 \ No newline at end of file diff --git a/prototype/.github/workflows/build.yml b/prototype/.github/workflows/build.yml deleted file mode 100644 index e5e727e7..00000000 --- a/prototype/.github/workflows/build.yml +++ /dev/null @@ -1,117 +0,0 @@ -name: Build - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - merge_group: - branches: [ main ] - -env: - CARGO_TERM_COLOR: always - - -jobs: - udeps: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install rust toolchain - uses: dtolnay/rust-toolchain@nightly - - - uses: Swatinem/rust-cache@v2 - - - name: Install cargo-udeps - run: cargo install cargo-udeps - - - name: Run cargo udeps - run: | - cargo +nightly udeps --all - test: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - uses: dtolnay/rust-toolchain@nightly - - uses: Swatinem/rust-cache@v2 - - uses: taiki-e/install-action@nextest - - - name: Run cargo nextest - run: cargo nextest run - fmt: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - uses: dtolnay/rust-toolchain@nightly - with: - components: rustfmt - - - uses: Swatinem/rust-cache@v2 - - - name: Run rustfmt - run: | - cargo +nightly fmt --all -- --check - clippy: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - uses: dtolnay/rust-toolchain@nightly - with: - components: clippy - - - uses: Swatinem/rust-cache@v2 - - - name: Clippy check - run: cargo clippy - -# deploy: -# if: github.ref == 'refs/heads/main' -# runs-on: ubuntu-latest -# needs: -# - clippy -# - fmt -# - test -# - udeps -# -# steps: -# - uses: actions/checkout@v4 -# -# - name: Login to Docker Registry -# uses: azure/docker-login@v1 -# with: -# login-server: TODO.azurecr.io -# username: ${{ secrets.REGISTRY_USERNAME }} -# password: ${{ secrets.REGISTRY_PASSWORD }} -# -# - name: Set up Docker Buildx -# uses: docker/setup-buildx-action@v3 -# -# - name: Build and Push Docker image -# uses: docker/build-push-action@v5 -# with: -# context: . -# file: ./Dockerfile -# push: true -# tags: TODO.azurecr.io/TODO:${{ github.sha }} -# cache-from: type=gha -# cache-to: type=gha,mode=max -# -# - name: Deploy to Azure Web App -# uses: azure/webapps-deploy@v2 -# with: -# app-name: 'TODO' -# publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} -# images: 'TODO.azurecr.io/myapp:${{ github.sha }}' - diff --git a/prototype/.gitignore b/prototype/.gitignore deleted file mode 100644 index ea8c4bf7..00000000 --- a/prototype/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/prototype/Cargo.toml b/prototype/Cargo.toml deleted file mode 100644 index ba5fdcb6..00000000 --- a/prototype/Cargo.toml +++ /dev/null @@ -1,76 +0,0 @@ -[package] -name = "prototype" -version = "0.1.0" -edition = "2021" -authors = ["Andrew Gazelka "] -readme = "README.md" - -[dependencies] -anyhow = "1.0.80" -flume = "0.11.0" -rayon = "1.9.0" - - -[lints.rust] -#warnings = "deny" - -[lints.clippy] -# cargo -cargo_common_metadata = "allow" -multiple_crate_versions = "warn" -negative_feature_names = "deny" -redundant_feature_names = "deny" -wildcard_dependencies = "deny" - -restriction = { level = "deny", priority = -1 } -missing_docs_in_private_items = "allow" -question_mark_used = "allow" -print_stdout = "allow" -implicit_return = "allow" -shadow_reuse = "allow" -absolute_paths = "allow" -use_debug = "allow" -unwrap_used = "allow" -std_instead_of_alloc = "allow" # consider denying -default_numeric_fallback = "allow" -as_conversions = "allow" -arithmetic_side_effects = "allow" -shadow_unrelated = "allow" -unseparated_literal_suffix = "allow" -else_if_without_else = "allow" -float_arithmetic = "allow" -single_call_fn = "allow" -missing_inline_in_public_items = "allow" -exhaustive_structs = "allow" -pub_use = "allow" -let_underscore_untyped = "allow" -infinite_loop = "allow" -single_char_lifetime_names = "allow" -min_ident_chars = "allow" -std_instead_of_core = "allow" -panic_in_result_fn = "allow" -panic = "allow" -missing_trait_methods = "allow" -todo = "allow" - -complexity = "deny" - -nursery = { level = "deny", priority = -1 } -future_not_send = "allow" - -pedantic = { level = "deny", priority = -1 } -uninlined_format_args = "allow" # consider denying; this is allowed because Copilot often generates code that triggers this lint -needless_pass_by_value = "allow" # consider denying -cast_lossless = "allow" -cast_possible_truncation = "allow" # consider denying -cast_precision_loss = "allow" # consider denying -missing_errors_doc = "allow" # consider denying -struct_excessive_bools = "allow" -wildcard_imports = "allow" - -perf = "deny" - -style = "deny" - -suspicious = { level = "deny", priority = -1 } -blanket_clippy_restriction_lints = "allow" diff --git a/prototype/README.md b/prototype/README.md deleted file mode 100644 index e69de29b..00000000 diff --git a/prototype/clippy.toml b/prototype/clippy.toml deleted file mode 100644 index 377098bf..00000000 --- a/prototype/clippy.toml +++ /dev/null @@ -1,3 +0,0 @@ -# https://doc.rust-lang.org/nightly/clippy/lint_configuration.html -cognitive-complexity-threshold = 5 -excessive-nesting-threshold = 5 diff --git a/prototype/rustfmt.toml b/prototype/rustfmt.toml deleted file mode 100644 index 7073741e..00000000 --- a/prototype/rustfmt.toml +++ /dev/null @@ -1,21 +0,0 @@ -combine_control_expr = true -comment_width = 100 # https://lkml.org/lkml/2020/5/29/1038 -condense_wildcard_suffixes = true -control_brace_style = "AlwaysSameLine" -edition = "2021" -format_code_in_doc_comments = true -format_macro_bodies = true -format_macro_matchers = true -format_strings = true -group_imports = "StdExternalCrate" -imports_granularity = "Crate" -merge_derives = false -newline_style = "Unix" -normalize_comments = true -normalize_doc_attributes = true -overflow_delimited_expr = true -reorder_impl_items = true -reorder_imports = true -unstable_features = true -wrap_comments = true - diff --git a/prototype/src/global.rs b/prototype/src/global.rs deleted file mode 100644 index 47eb82ff..00000000 --- a/prototype/src/global.rs +++ /dev/null @@ -1,30 +0,0 @@ -use crate::{utils::split_into_mut, Entity, IdMap, Thread, World}; - -struct Global { - threads: Vec, - entities: IdMap, - world: World, -} - -impl Global { - - fn parallel_tasks(&mut self) { - rayon::scope(|s| { - let threads = &mut self.threads; - let entities = split_into_mut(threads.len(), &mut self.entities); - let world = &self.world; - - for (thread, entities) in threads.iter_mut().zip(entities) { - s.spawn(move |_| { - // unwrap not ideal - #[allow(clippy::unwrap_used)] - thread.process(entities, world).unwrap(); - }); - } - }); - } - - fn run_cycle(&mut self) { - self.parallel_tasks(); - } -} diff --git a/prototype/src/lib.rs b/prototype/src/lib.rs deleted file mode 100644 index 92e190a7..00000000 --- a/prototype/src/lib.rs +++ /dev/null @@ -1,160 +0,0 @@ -#![feature(split_at_checked)] - -use std::collections::HashMap; - -use crate::messages::{Message, MessageSender}; - -// todo -type PlayerInventory = (); - -type PartitionId = usize; -type PlayerId = usize; -type ChunkId = (i32, i32); -type MultiMap = HashMap>; -type Chunked = Vec; - -type IdMap = Vec; - -mod global; -mod messages; -mod utils; - -struct Location { - x: f64, - y: f64, - z: f64, -} - -struct Player { - partition_in: PartitionId, - inventory: PlayerInventory, - location: Location, -} - -struct Entity { - partition_in: PartitionId, - location: Location, -} - -struct Packet { - // ... - group: Option, -} - -enum PacketGroup { - PlayerLocal, - RegionLocal, - Global, - CrossRegion { from: usize, to: usize }, -} - -impl Packet { - // also take context of world - fn group(&self) -> PacketGroup { - todo!() - } -} - -struct World { - partitions: Vec, - players: Vec, - entities: Vec, -} - -struct Partition { - players_in: Vec, - chunk_ids: Vec, - adjacent: Vec, -} - -// struct World { -// partitions: [Partition; 64] -// local_packets: Recv, -// global_packes: Recv -// } -// -// struct Thread { -// partition: Partiton -// } - -struct Thread { - partition: Partition, - messages: MessageSender, -} - -impl Thread { - fn process(&mut self, entities: &mut [Entity], world: &World) -> anyhow::Result<()> { - for entity in entities { - - } - Ok(()) - } -} - -// impl Thread { -// fn sar -// -// -// -// -// -// } - -// impl Thread { -// // iterator of players not related to partition... should be equal split -// // between threads -// fn assigned_global_players(&mut self) -> impl Iterator<&mut Player> -// -// // iterator of entities not related to partition... should be equal split -// // between threads -// fn assigned_global_living_entities(&mut self) -> impl Iterator<&mut Entity> -// -// fn players_in_region(&mut self) -> impl Iterator<&mut Player> -// -// fn general(world: &WorldState, messages: &mut Messages) { -// for entity in world.assigned_global_entities() { -// if let Some(message) = entity.physics() { -// // new location of the entity, -// // the entity (say an arrow) hitting a player for instance -// messages.push(message); -// } -// } -// -// for player in world.assigned_global_players() { -// if let Some(message) = player.physics() { -// // new location of the entity, -// // the entity (say an arrow) hitting a player for instance -// messages.push(message); -// } -// } -// } -// -// fn apply_messages(world: &WorldState, input_messages: &Messages) { -// -// } -// -// fn run_cycle() { -// -// -// for player in self.assigned_global_players() { -// for packet in player.packets() { -// let group = packet.assign_group(); -// -// if group == PlayerLocal { -// // process -// } -// } -// } -// -// for entity in self.assigned_global_living_entities() { -// // we probably do not need to modify any blocks etc for basic entities -// entity.physics() -// } -// -// -// -// -// -// -// } -// } diff --git a/prototype/src/messages.rs b/prototype/src/messages.rs deleted file mode 100644 index cb056a0a..00000000 --- a/prototype/src/messages.rs +++ /dev/null @@ -1,47 +0,0 @@ -use crate::{IdMap, PartitionId}; - -pub enum Message { - Test, -} - -pub struct MessageSender { - for_partition: IdMap>, - for_global: flume::Sender, -} - -impl MessageSender { - pub fn send_partition(&self, id: PartitionId, message: Message) -> anyhow::Result<()> { - let Some(partition) = self.for_partition.get(id) else { - panic!("somehow tried to send a message to a partition that doesn't exist"); - }; - - partition.send(message)?; - Ok(()) - } - - pub fn send_global(&self, message: Message) -> anyhow::Result<()> { - self.for_global.send(message)?; - Ok(()) - } -} - -pub struct MessageReceiver { - for_partition: IdMap>, - for_global: flume::Receiver, -} - -impl MessageReceiver { - pub fn recv_partition(&self, id: PartitionId) -> anyhow::Result { - let Some(partition) = self.for_partition.get(id) else { - panic!("somehow tried to receive a message from a partition that doesn't exist"); - }; - - let v = partition.recv()?; - Ok(v) - } - - pub fn recv_global(&self) -> anyhow::Result { - let v = self.for_global.recv()?; - Ok(v) - } -} diff --git a/prototype/src/utils.rs b/prototype/src/utils.rs deleted file mode 100644 index 2777435f..00000000 --- a/prototype/src/utils.rs +++ /dev/null @@ -1,80 +0,0 @@ -struct SplitIntoMut<'a, T> { - input: Option<&'a mut [T]>, - count: usize, - lower_count: usize, - num_chunks_with_rem: usize, -} - -impl<'a, T> SplitIntoMut<'a, T> { - fn new(count: usize, input: &'a mut [T]) -> Self { - let input_len = input.len(); - - // calculate div and remainder - #[allow(clippy::integer_division)] - let lower_count = input_len / count; - let num_chunks_with_rem = input_len % count; - - Self { - input: Some(input), - count, - lower_count, - num_chunks_with_rem, - } - } -} - -impl<'a, T> Iterator for SplitIntoMut<'a, T> { - type Item = &'a mut [T]; - - fn next(&mut self) -> Option { - let input = self.input.take()?; - - let amount_to_take = if self.num_chunks_with_rem > 0 { - self.num_chunks_with_rem -= 1; - self.lower_count + 1 - } else { - self.lower_count - }; - - let (split, rest) = input.split_at_mut(amount_to_take); - - if !rest.is_empty() { - self.input = Some(rest); - } - - Some(split) - } -} - -pub fn split_into_mut(count: usize, input: &mut [T]) -> impl Iterator { - SplitIntoMut::new(count, input) -} - -#[cfg(test)] -mod tests { - #[test] - fn test_split_into_mut() { - let mut input = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - let mut iter = super::split_into_mut(3, &mut input); - - assert_eq!(iter.next().unwrap(), &[1, 2, 3, 4]); - assert_eq!(iter.next().unwrap(), &[5, 6, 7]); - assert_eq!(iter.next().unwrap(), &[8, 9, 10]); - assert!(iter.next().is_none()); - - let mut input = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - let mut iter = super::split_into_mut(3, &mut input); - - assert_eq!(iter.next().unwrap(), &[1, 2, 3]); - assert_eq!(iter.next().unwrap(), &[4, 5, 6]); - assert_eq!(iter.next().unwrap(), &[7, 8, 9]); - - let mut input = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - let mut iter = super::split_into_mut(4, &mut input); - - assert_eq!(iter.next().unwrap(), &[1, 2, 3]); - assert_eq!(iter.next().unwrap(), &[4, 5]); - assert_eq!(iter.next().unwrap(), &[6, 7]); - assert_eq!(iter.next().unwrap(), &[8, 9]); - } -}