mirror of
https://github.com/illegitimate-egg/mcrizzledizzle.git
synced 2026-06-04 15:43:57 +00:00
Remove sleep in network loop that was causing ungodly latency (That shit literally stacked vro)
This commit is contained in:
parent
328ed38a1a
commit
72fe7e13f1
@ -2,8 +2,7 @@ use log::{info, warn};
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread;
|
use std::thread::{self, sleep};
|
||||||
use std::thread::sleep;
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::command::handle_command;
|
use crate::command::handle_command;
|
||||||
@ -21,6 +20,10 @@ pub fn handle_client(
|
|||||||
world_arc_clone: Arc<Mutex<World>>,
|
world_arc_clone: Arc<Mutex<World>>,
|
||||||
extensions: Arc<Extensions>,
|
extensions: Arc<Extensions>,
|
||||||
) {
|
) {
|
||||||
|
// TCP nodelay, the arc of humanity
|
||||||
|
stream
|
||||||
|
.set_nodelay(true)
|
||||||
|
.expect("Failed to set TCP nodelay, what's wrong with your network stack holmes?");
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
info!("Thread initialized with player ID: {}", client_number);
|
info!("Thread initialized with player ID: {}", client_number);
|
||||||
|
|
||||||
@ -44,10 +47,12 @@ pub fn handle_client(
|
|||||||
player_statuses[client_number as usize] = PlayerStatus::ConnectedSelf;
|
player_statuses[client_number as usize] = PlayerStatus::ConnectedSelf;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
let timer_1 = std::time::Instant::now();
|
||||||
let mut buffer = [0; 1];
|
let mut buffer = [0; 1];
|
||||||
if stream.read(&mut buffer).unwrap() == 0 {
|
if stream.read(&mut buffer).unwrap() == 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
let timer_2 = std::time::Instant::now();
|
||||||
|
|
||||||
match buffer[0] {
|
match buffer[0] {
|
||||||
0x00 => {
|
0x00 => {
|
||||||
@ -282,7 +287,6 @@ pub fn handle_client(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sleep(Duration::from_millis(50)); // 1000 TPS TODO: Delta time
|
|
||||||
{
|
{
|
||||||
let mut players = players_arc_clone.lock().unwrap();
|
let mut players = players_arc_clone.lock().unwrap();
|
||||||
if !players[client_number as usize].outgoing_data.is_empty() {
|
if !players[client_number as usize].outgoing_data.is_empty() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user