Browse Source

speed up tests by not loading quests every time

pull/141/head
jake 6 months ago
parent
commit
183fba9afe
  1. 13
      room/src/lib.rs
  2. 6
      src/bin/main.rs
  3. 2
      src/bin/ship.rs
  4. 5
      src/ship/packet/handler/room.rs
  5. 42
      src/ship/ship.rs
  6. 4
      tests/test_rooms.rs

13
room/src/lib.rs

@ -7,6 +7,7 @@ use futures::stream::{FuturesOrdered, Stream};
use thiserror::Error;
use rand::Rng;
use quests::{QuestList, QuestLoadError};
use maps::maps::Maps;
use drops::DropTable;
use entity::character::SectionID;
@ -177,8 +178,8 @@ pub struct RoomState {
pub monster_stats: Box<HashMap<MonsterType, MonsterStats>>,
pub map_areas: MapAreaLookup,
pub quest_group: QuestCategoryType,
pub standard_quests: quests::QuestList,
pub government_quests: quests::QuestList,
pub standard_quests: QuestList,
pub government_quests: QuestList,
// enemy info
}
@ -213,7 +214,7 @@ impl RoomState {
difficulty + 0x22
}
pub fn quests(&self) -> &quests::QuestList {
pub fn quests(&self) -> &QuestList {
match self.quest_group {
QuestCategoryType::Standard => &self.standard_quests,
QuestCategoryType::Government => &self.government_quests,
@ -231,6 +232,8 @@ impl RoomState {
event: Holiday,
map_builder: Arc<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>,
drop_table_builder: Arc<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
standard_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
government_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
) -> Result<RoomState, anyhow::Error> {
let mode = match mode {
RoomEntityMode::Single => RoomMode::Single {
@ -263,8 +266,8 @@ impl RoomState {
bursting: false,
map_areas: MapAreaLookup::new(&episode),
quest_group: QuestCategoryType::Standard,
standard_quests: quests::load_standard_quests(mode)?,
government_quests: quests::load_government_quests(mode)?,
standard_quests: standard_quest_builder(mode)?,
government_quests: government_quest_builder(mode)?,
})
}

6
src/bin/main.rs

@ -365,6 +365,8 @@ fn main() {
.ip(Ipv4Addr::new(127,0,0,1))
.port(elseware::ship::ship::SHIP_PORT)
.event(Holiday::Halloween)
.standard_quest_builder(Box::new(quests::load_standard_quests))
.government_quest_builder(Box::new(quests::load_government_quests))
.gateway(entity_gateway.clone())
.build();
let sub_ship_state = ship_state.clone();
@ -381,6 +383,8 @@ fn main() {
.ip(Ipv4Addr::new(127,0,0,1))
.port(elseware::ship::ship::SHIP_PORT+2000)
.event(Holiday::Christmas)
.standard_quest_builder(Box::new(quests::load_standard_quests))
.government_quest_builder(Box::new(quests::load_government_quests))
.gateway(entity_gateway.clone())
.build();
let sub_ship_state = ship_state.clone();
@ -396,6 +400,8 @@ fn main() {
.name("JP/Thalarion".into())
.ip(Ipv4Addr::new(127,0,0,1))
.port(elseware::ship::ship::SHIP_PORT+3000)
.standard_quest_builder(Box::new(quests::load_standard_quests))
.government_quest_builder(Box::new(quests::load_government_quests))
.gateway(entity_gateway.clone())
.build();
let sub_ship_state = ship_state.clone();

2
src/bin/ship.rs

@ -43,6 +43,8 @@ fn main() {
.port(elseware::ship::ship::SHIP_PORT)
.gateway(entity_gateway)
.auth_token(AuthToken(shipgate_token))
.standard_quest_builder(Box::new(quests::load_standard_quests))
.government_quest_builder(Box::new(quests::load_government_quests))
.build();
let shipgate_ip = std::env::var("SHIPGATE_IP").unwrap().parse().unwrap();

5
src/ship/packet/handler/room.rs

@ -20,6 +20,7 @@ use maps::maps::Maps;
use location::{ClientLocation, RoomId, RoomLobby, GetAreaError};
use pktbuilder as builder;
use items::state::ItemState;
use quests::{QuestList, QuestLoadError};
#[allow(clippy::too_many_arguments)]
pub async fn create_room<EG>(id: ClientId,
@ -31,6 +32,8 @@ pub async fn create_room<EG>(id: ClientId,
rooms: &Rooms,
map_builder: Arc<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>,
drop_table_builder: Arc<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
standard_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
government_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
event: Holiday)
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
where
@ -91,7 +94,7 @@ where
let mut room = RoomState::new(room_entity.id, mode, episode, difficulty,
client.character.section_id, name, create_room.password, event,
map_builder, drop_table_builder)?;
map_builder, drop_table_builder, standard_quest_builder, government_quest_builder)?;
room.bursting = true;
Ok::<_, anyhow::Error>(room)
})}).await??;

42
src/ship/ship.rs

@ -25,6 +25,9 @@ use location::{ClientLocation, RoomLobby, ClientLocationError, RoomId};
use drops::DropTable;
use items;
use room;
use maps::room::{RoomMode, Episode, Difficulty};
//use quests::{load_standard_quests, load_government_quests};
use quests::{QuestList, QuestLoadError};
use maps::Holiday;
use maps::area::MapAreaError;
use maps::maps::{Maps, MapsError, generate_free_roam_maps};
@ -293,14 +296,14 @@ impl SendServerPacket for SendShipPacket {
#[derive(Clone)]
pub struct ItemShops {
pub weapon_shop: HashMap<(maps::room::Difficulty, SectionID), Arc<Mutex<WeaponShop<rand_chacha::ChaCha20Rng>>>>,
pub weapon_shop: HashMap<(Difficulty, SectionID), Arc<Mutex<WeaponShop<rand_chacha::ChaCha20Rng>>>>,
pub tool_shop: Arc<Mutex<ToolShop<rand_chacha::ChaCha20Rng>>>,
pub armor_shop: Arc<Mutex<ArmorShop<rand_chacha::ChaCha20Rng>>>,
}
impl Default for ItemShops {
fn default() -> ItemShops {
let difficulty = [maps::room::Difficulty::Normal, maps::room::Difficulty::Hard, maps::room::Difficulty::VeryHard, maps::room::Difficulty::Ultimate];
let difficulty = [Difficulty::Normal, Difficulty::Hard, Difficulty::VeryHard, Difficulty::Ultimate];
let section_id = [SectionID::Viridia, SectionID::Greenill, SectionID::Skyly, SectionID::Bluefull, SectionID::Purplenum,
SectionID::Pinkal, SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill];
@ -327,8 +330,10 @@ pub struct ShipServerStateBuilder<EG: EntityGateway + Clone + 'static> {
port: Option<u16>,
auth_token: Option<AuthToken>,
event: Option<Holiday>,
map_builder: Option<Box<dyn Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>>,
drop_table_builder: Option<Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
map_builder: Option<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>,
drop_table_builder: Option<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
standard_quest_builder: Option<Box<dyn Fn(RoomMode) -> Result<quests::QuestList, QuestLoadError> + Send + Sync>>,
government_quest_builder: Option<Box<dyn Fn(RoomMode) -> Result<quests::QuestList, QuestLoadError> + Send + Sync>>,
num_blocks: usize,
}
@ -343,6 +348,8 @@ impl<EG: EntityGateway + Clone + 'static> Default for ShipServerStateBuilder<EG>
event: None,
map_builder: None,
drop_table_builder: None,
standard_quest_builder: None,
government_quest_builder: None,
num_blocks: 2,
}
}
@ -386,17 +393,29 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> {
}
#[must_use]
pub fn map_builder(mut self, map_builder: Box<dyn Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>) -> ShipServerStateBuilder<EG> {
pub fn map_builder(mut self, map_builder: Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>) -> ShipServerStateBuilder<EG> {
self.map_builder = Some(map_builder);
self
}
#[must_use]
pub fn drop_table_builder(mut self, drop_table_builder: Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + Send + Sync>) -> ShipServerStateBuilder<EG> {
pub fn drop_table_builder(mut self, drop_table_builder: Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>) -> ShipServerStateBuilder<EG> {
self.drop_table_builder = Some(drop_table_builder);
self
}
#[must_use]
pub fn standard_quest_builder(mut self, standard_quest_builder: Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>) -> ShipServerStateBuilder<EG> {
self.standard_quest_builder = Some(standard_quest_builder);
self
}
#[must_use]
pub fn government_quest_builder(mut self, government_quest_builder: Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>) -> ShipServerStateBuilder<EG> {
self.government_quest_builder = Some(government_quest_builder);
self
}
#[must_use]
pub fn blocks(mut self, num_blocks: usize) -> ShipServerStateBuilder<EG> {
self.num_blocks = num_blocks;
@ -417,6 +436,8 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> {
event: self.event.unwrap_or(Holiday::None),
map_builder: Arc::new(self.map_builder.unwrap_or(Box::new(generate_free_roam_maps))),
drop_table_builder: Arc::new(self.drop_table_builder.unwrap_or(Box::new(DropTable::new))),
standard_quest_builder: Arc::new(self.standard_quest_builder.unwrap_or(Box::new(|_| Ok(QuestList::new())))),
government_quest_builder: Arc::new(self.government_quest_builder.unwrap_or(Box::new(|_| Ok(QuestList::new())))),
auth_token: self.auth_token.unwrap_or_else(|| AuthToken("".into())),
ship_list: Arc::new(RwLock::new(Vec::new())),
@ -464,8 +485,10 @@ pub struct ShipServerState<EG: EntityGateway + Clone + 'static> {
ship_list: Arc<RwLock<Vec<Ship>>>,
shipgate_sender: Option<channel::Sender<ShipMessage>>,
trades: TradeState,
map_builder: Arc<Box<dyn Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>>,
drop_table_builder: Arc<Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + Send + Sync>>,
map_builder: Arc<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>,
drop_table_builder: Arc<Box<dyn Fn(Episode, Difficulty, SectionID) -> DropTable + Send + Sync>>,
standard_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
government_quest_builder: Arc<Box<dyn Fn(RoomMode) -> Result<QuestList, QuestLoadError> + Send + Sync>>,
}
impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> {
@ -707,7 +730,8 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> {
RecvShipPacket::CreateRoom(create_room) => {
let block = self.blocks.get_from_client(id, &self.clients).await?;
handler::room::create_room(id, create_room, &mut self.entity_gateway, &mut block.client_location, &self.clients, &mut self.item_state,
&block.rooms, self.map_builder.clone(), self.drop_table_builder.clone(), self.event).await?
&block.rooms, self.map_builder.clone(), self.drop_table_builder.clone(),
self.standard_quest_builder.clone(), self.government_quest_builder.clone(), self.event).await?
},
RecvShipPacket::RoomNameRequest(_req) => {
let block = self.blocks.get_from_client(id, &self.clients).await?;

4
tests/test_rooms.rs

@ -16,6 +16,8 @@ async fn test_set_valid_quest_group() {
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
let mut ship = Box::new(ShipServerState::builder()
.gateway(entity_gateway.clone())
.standard_quest_builder(Box::new(quests::load_standard_quests))
.government_quest_builder(Box::new(quests::load_government_quests))
.build());
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await;
@ -36,6 +38,8 @@ async fn test_set_invalid_quest_group() {
let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
let mut ship = Box::new(ShipServerState::builder()
.gateway(entity_gateway.clone())
.standard_quest_builder(Box::new(quests::load_standard_quests))
.government_quest_builder(Box::new(quests::load_government_quests))
.build());
log_in_char(&mut ship, ClientId(1), "a1", "a").await;
join_lobby(&mut ship, ClientId(1)).await;

Loading…
Cancel
Save