Skip to content

Commit

Permalink
Merge pull request #199 from Far-Beyond-Dev/feature/dynamic-socket-ch…
Browse files Browse the repository at this point in the history
…annels

Perf: Implement Dynamic Channel-Based Socket Streaming for Infinite Worlds
  • Loading branch information
tristanpoland authored Dec 26, 2024
2 parents b5b036a + 6fcb755 commit 3b3f14e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 144 deletions.
52 changes: 0 additions & 52 deletions server/src/server/event_rep/mod.rs

This file was deleted.

91 changes: 0 additions & 91 deletions server/src/server/event_rep/structs.rs

This file was deleted.

30 changes: 30 additions & 0 deletions server/src/server/in_world/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use socketioxide::extract::{ SocketRef, Data };
use serde::Serialize;
use serde_json::Value;
use std::collections::HashMap;
use uuid::Uuid;


pub struct Object {
uuid: Uuid,
name: String,
replicated: bool,
}

impl Object {
pub fn new(name: String, replicated: bool) -> Self {
Self {
uuid: Uuid::new_v4(),
name, // Fetch name from method params
replicated, // Fetch replicated from method params
}
}

pub fn get_uuid(&self) -> Uuid {
self.uuid
}
pub fn send_event(&self, instigator: SocketRef, event_name: String, event_data: Value) {
let _ = socketioxide::socket::Socket::within(&instigator, self.uuid.to_string()).emit(event_name, &event_data);
}
}

13 changes: 12 additions & 1 deletion server/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ use std::sync::Arc;
use tokio::sync::Mutex;
use uuid::Uuid;
pub mod config;
mod event_rep;
pub mod in_world;

use lazy_static::lazy_static;

lazy_static! {
Expand Down Expand Up @@ -187,6 +188,16 @@ fn on_connect(socket: SocketRef, Data(data): Data<serde_json::Value>) {

let player_arc: Arc<horizon_data_types::Player> = Arc::new(player);

// TODO: move this to example backend
let player_char = in_world::Object::new("Player Character".to_string(), true);
println!("Player joined: {:?}", player_char.get_uuid().to_string());

let player_json_value: serde_json::Value = serde_json::json!({ "joined": true });
player_char.send_event(socket, "playerjoined".to_string(), player_json_value);
println!("Sent player joined event Successfully");


// let casted_struct = plugin_api::get_plugin!(unreal_adapter_horizon, target_thread.plugins);
//let casted_struct = plugin_api::get_plugin!(unreal_adapter_horizon, target_thread.plugins);

//casted_struct.player_joined(socket, player_arc);
Expand Down

0 comments on commit 3b3f14e

Please sign in to comment.