mirror of
https://github.com/redstrate/Kawari.git
synced 2025-04-21 07:07:44 +00:00
Pass GameData into Zone, stop loading the same zone twice on login
This commit is contained in:
parent
243d94c586
commit
caf70ea469
5 changed files with 12 additions and 20 deletions
|
@ -213,11 +213,11 @@ async fn client_loop(
|
|||
|
||||
let mut lua_player = LuaPlayer::default();
|
||||
|
||||
let mut buf = [0; 2056];
|
||||
let mut buf = [0; 4096];
|
||||
loop {
|
||||
tokio::select! {
|
||||
Ok(n) = connection.socket.read(&mut buf) => {
|
||||
if n != 0 {
|
||||
if n > 0 {
|
||||
let (segments, connection_type) = connection.parse_packet(&buf[..n]).await;
|
||||
for segment in &segments {
|
||||
match &segment.segment_type {
|
||||
|
@ -318,9 +318,6 @@ async fn client_loop(
|
|||
.await;
|
||||
}
|
||||
|
||||
let zone_id = connection.player_data.zone_id;
|
||||
connection.zone = Some(Zone::load(zone_id));
|
||||
|
||||
// Player Setup
|
||||
{
|
||||
let ipc = ServerZoneIpcSegment {
|
||||
|
@ -354,6 +351,7 @@ async fn client_loop(
|
|||
.await;
|
||||
}
|
||||
|
||||
let zone_id = connection.player_data.zone_id;
|
||||
connection.change_zone(zone_id).await;
|
||||
|
||||
let lua = lua.lock().unwrap();
|
||||
|
@ -692,7 +690,8 @@ async fn client_loop(
|
|||
.unwrap();
|
||||
|
||||
// find the pop range on the other side
|
||||
let new_zone = Zone::load(exit_box.territory_type);
|
||||
let mut game_data = game_data.lock().unwrap();
|
||||
let new_zone = Zone::load(&mut game_data.game_data, exit_box.territory_type);
|
||||
let (destination_object, _) = new_zone
|
||||
.find_pop_range(exit_box.destination_instance_id)
|
||||
.unwrap();
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{common::Attributes, config::get_config};
|
|||
|
||||
/// Convenient methods built on top of Physis to access data relevant to the server
|
||||
pub struct GameData {
|
||||
game_data: physis::gamedata::GameData,
|
||||
pub game_data: physis::gamedata::GameData,
|
||||
}
|
||||
|
||||
impl GameData {
|
||||
|
|
|
@ -168,10 +168,7 @@ pub async fn send_packet<T: ReadWriteIpcSegment>(
|
|||
|
||||
let buffer = cursor.into_inner();
|
||||
|
||||
socket
|
||||
.write_all(&buffer)
|
||||
.await
|
||||
.expect("Failed to write packet!");
|
||||
socket.write_all(&buffer).await.unwrap();
|
||||
}
|
||||
|
||||
// temporary
|
||||
|
|
|
@ -321,7 +321,10 @@ impl ZoneConnection {
|
|||
}
|
||||
|
||||
pub async fn change_zone(&mut self, new_zone_id: u16) {
|
||||
self.zone = Some(Zone::load(new_zone_id));
|
||||
{
|
||||
let mut game_data = self.gamedata.lock().unwrap();
|
||||
self.zone = Some(Zone::load(&mut game_data.game_data, new_zone_id));
|
||||
}
|
||||
self.player_data.zone_id = new_zone_id;
|
||||
|
||||
// Player Class Info
|
||||
|
|
|
@ -22,19 +22,12 @@ pub struct Zone {
|
|||
}
|
||||
|
||||
impl Zone {
|
||||
pub fn load(id: u16) -> Self {
|
||||
let config = get_config();
|
||||
|
||||
pub fn load(game_data: &mut GameData, id: u16) -> Self {
|
||||
let mut zone = Self {
|
||||
id,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let Some(mut game_data) = GameData::from_existing(Platform::Win32, &config.game_location)
|
||||
else {
|
||||
return zone;
|
||||
};
|
||||
|
||||
let Some(exh) = game_data.read_excel_sheet_header("TerritoryType") else {
|
||||
return zone;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue