-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f464154
commit 35a0693
Showing
16 changed files
with
939 additions
and
158 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,8 @@ | |
resolver = "2" | ||
|
||
members = [ | ||
# "ser", | ||
# "ser-macro", | ||
"server", | ||
# "prototype" | ||
] | ||
|
||
[workspace.dependencies] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.