Skip to content

Commit

Permalink
feat: player joins server (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgazelka authored Mar 7, 2024
1 parent f464154 commit 35a0693
Show file tree
Hide file tree
Showing 16 changed files with 939 additions and 158 deletions.
49 changes: 33 additions & 16 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
resolver = "2"

members = [
# "ser",
# "ser-macro",
"server",
# "prototype"
]

[workspace.dependencies]
Expand Down
159 changes: 159 additions & 0 deletions DETAILS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
Given a machine with `64` cores:

The world is allocated into 64 `Partition`s where each partition is assigned to a certain region

```rust

struct Player {
partition_id: usize
inventory: Inventory
}

struct Entity {
location: Location
partion_id: usize
}

struct Packet {
// ...
group: Option<PacketGroup>
}

enum PacketGroup {
PlayerLocal,
RegionLocal,
Global,
CrossRegion {
from: usize,
to: usize
},

}

impl Packet {
fn group(&self, client: &ClientState, world: &World) -> PacketGroup {
if self.requires_global_mut() {
return PacketGroup::Global;
}

if let Some(boundary) = self.crosses_boundary(client, world) {
return PacketGroup::CrossRegion(boundary)
}

if self.no_region_modification() {
return PacketGroup::Player
}

// Confirm Teleportation
// Chat Message
// Edit Book (modified player inv)
// Keep Alive
PacketGroup::Region
}

fn crosses_boundary(&self, client: &ClientState, world: &World) -> Option<CrossRegion> {
match self.kind {
SetPlayerPositionAndRotation | MoveVehicle (new_loc, ...) => world.get_opt_cross(client.loc, new_loc)
_ => None
}
}

/// do not care about region even
fn client(&self) {
// Confirm Teleportation
// Chat Message
// Edit Book (modified player inv)
// Keep Alive
}

fn regional(&self, client: &Client, world: &World) {
// Click Container (assuming it does not cross regions)
// Close Container
// Interact (set to the partition of the entity)
}

fn requires_global_mut(&self) -> bool {
// Confirm Teleportation
//
}
}

struct Partition {
player_ids: Vec<usize>
chunk_ids: Vec<usize>
adjacent: Vec<usize>
}

struct World {
partitions: [Partition; 64]
local_packets: Recv<Packet>,
global_packes: Recv<Packet>
}

struct Thread {
partition: Partiton
}

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()
}






}
}


```

```rust
Loading

0 comments on commit 35a0693

Please sign in to comment.