speed up tests by not loading quests every time
This commit is contained in:
		
							parent
							
								
									7afe44a520
								
							
						
					
					
						commit
						183fba9afe
					
				| @ -7,6 +7,7 @@ use futures::stream::{FuturesOrdered, Stream}; | |||||||
| use thiserror::Error; | use thiserror::Error; | ||||||
| use rand::Rng; | use rand::Rng; | ||||||
| 
 | 
 | ||||||
|  | use quests::{QuestList, QuestLoadError}; | ||||||
| use maps::maps::Maps; | use maps::maps::Maps; | ||||||
| use drops::DropTable; | use drops::DropTable; | ||||||
| use entity::character::SectionID; | use entity::character::SectionID; | ||||||
| @ -177,8 +178,8 @@ pub struct RoomState { | |||||||
|     pub monster_stats: Box<HashMap<MonsterType, MonsterStats>>, |     pub monster_stats: Box<HashMap<MonsterType, MonsterStats>>, | ||||||
|     pub map_areas: MapAreaLookup, |     pub map_areas: MapAreaLookup, | ||||||
|     pub quest_group: QuestCategoryType, |     pub quest_group: QuestCategoryType, | ||||||
|     pub standard_quests: quests::QuestList, |     pub standard_quests: QuestList, | ||||||
|     pub government_quests: quests::QuestList, |     pub government_quests: QuestList, | ||||||
|     // enemy info
 |     // enemy info
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -213,7 +214,7 @@ impl RoomState { | |||||||
|         difficulty + 0x22 |         difficulty + 0x22 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     pub fn quests(&self) -> &quests::QuestList { |     pub fn quests(&self) -> &QuestList { | ||||||
|         match self.quest_group { |         match self.quest_group { | ||||||
|             QuestCategoryType::Standard => &self.standard_quests, |             QuestCategoryType::Standard => &self.standard_quests, | ||||||
|             QuestCategoryType::Government => &self.government_quests, |             QuestCategoryType::Government => &self.government_quests, | ||||||
| @ -231,6 +232,8 @@ impl RoomState { | |||||||
|                 event: Holiday, |                 event: Holiday, | ||||||
|                 map_builder: Arc<Box<dyn Fn(RoomMode, Holiday) -> Maps + 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>>, |                 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> { |     ) -> Result<RoomState, anyhow::Error> { | ||||||
|         let mode = match mode { |         let mode = match mode { | ||||||
|             RoomEntityMode::Single => RoomMode::Single { |             RoomEntityMode::Single => RoomMode::Single { | ||||||
| @ -263,8 +266,8 @@ impl RoomState { | |||||||
|             bursting: false, |             bursting: false, | ||||||
|             map_areas: MapAreaLookup::new(&episode), |             map_areas: MapAreaLookup::new(&episode), | ||||||
|             quest_group: QuestCategoryType::Standard, |             quest_group: QuestCategoryType::Standard, | ||||||
|             standard_quests: quests::load_standard_quests(mode)?, |             standard_quests: standard_quest_builder(mode)?, | ||||||
|             government_quests: quests::load_government_quests(mode)?, |             government_quests: government_quest_builder(mode)?, | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -365,6 +365,8 @@ fn main() { | |||||||
|             .ip(Ipv4Addr::new(127,0,0,1)) |             .ip(Ipv4Addr::new(127,0,0,1)) | ||||||
|             .port(elseware::ship::ship::SHIP_PORT) |             .port(elseware::ship::ship::SHIP_PORT) | ||||||
|             .event(Holiday::Halloween) |             .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()) |             .gateway(entity_gateway.clone()) | ||||||
|             .build(); |             .build(); | ||||||
|         let sub_ship_state = ship_state.clone(); |         let sub_ship_state = ship_state.clone(); | ||||||
| @ -381,6 +383,8 @@ fn main() { | |||||||
|             .ip(Ipv4Addr::new(127,0,0,1)) |             .ip(Ipv4Addr::new(127,0,0,1)) | ||||||
|             .port(elseware::ship::ship::SHIP_PORT+2000) |             .port(elseware::ship::ship::SHIP_PORT+2000) | ||||||
|             .event(Holiday::Christmas) |             .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()) |             .gateway(entity_gateway.clone()) | ||||||
|             .build(); |             .build(); | ||||||
|         let sub_ship_state = ship_state.clone(); |         let sub_ship_state = ship_state.clone(); | ||||||
| @ -396,6 +400,8 @@ fn main() { | |||||||
|             .name("JP/Thalarion".into()) |             .name("JP/Thalarion".into()) | ||||||
|             .ip(Ipv4Addr::new(127,0,0,1)) |             .ip(Ipv4Addr::new(127,0,0,1)) | ||||||
|             .port(elseware::ship::ship::SHIP_PORT+3000) |             .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()) |             .gateway(entity_gateway.clone()) | ||||||
|             .build(); |             .build(); | ||||||
|         let sub_ship_state = ship_state.clone(); |         let sub_ship_state = ship_state.clone(); | ||||||
|  | |||||||
| @ -43,6 +43,8 @@ fn main() { | |||||||
|         .port(elseware::ship::ship::SHIP_PORT) |         .port(elseware::ship::ship::SHIP_PORT) | ||||||
|         .gateway(entity_gateway) |         .gateway(entity_gateway) | ||||||
|         .auth_token(AuthToken(shipgate_token)) |         .auth_token(AuthToken(shipgate_token)) | ||||||
|  |         .standard_quest_builder(Box::new(quests::load_standard_quests)) | ||||||
|  |         .government_quest_builder(Box::new(quests::load_government_quests)) | ||||||
|         .build(); |         .build(); | ||||||
| 
 | 
 | ||||||
|     let shipgate_ip = std::env::var("SHIPGATE_IP").unwrap().parse().unwrap(); |     let shipgate_ip = std::env::var("SHIPGATE_IP").unwrap().parse().unwrap(); | ||||||
|  | |||||||
| @ -20,6 +20,7 @@ use maps::maps::Maps; | |||||||
| use location::{ClientLocation, RoomId, RoomLobby, GetAreaError}; | use location::{ClientLocation, RoomId, RoomLobby, GetAreaError}; | ||||||
| use pktbuilder as builder; | use pktbuilder as builder; | ||||||
| use items::state::ItemState; | use items::state::ItemState; | ||||||
|  | use quests::{QuestList, QuestLoadError}; | ||||||
| 
 | 
 | ||||||
| #[allow(clippy::too_many_arguments)] | #[allow(clippy::too_many_arguments)] | ||||||
| pub async fn create_room<EG>(id: ClientId, | pub async fn create_room<EG>(id: ClientId, | ||||||
| @ -31,6 +32,8 @@ pub async fn create_room<EG>(id: ClientId, | |||||||
|                              rooms: &Rooms, |                              rooms: &Rooms, | ||||||
|                              map_builder: Arc<Box<dyn Fn(RoomMode, Holiday) -> Maps + 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>>, |                              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) |                              event: Holiday) | ||||||
|                              -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> |                              -> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error> | ||||||
| where | where | ||||||
| @ -91,7 +94,7 @@ where | |||||||
| 
 | 
 | ||||||
|             let mut room = RoomState::new(room_entity.id, mode, episode, difficulty, |             let mut room = RoomState::new(room_entity.id, mode, episode, difficulty, | ||||||
|                                           client.character.section_id, name, create_room.password, event, |                                           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; |             room.bursting = true; | ||||||
|             Ok::<_, anyhow::Error>(room) |             Ok::<_, anyhow::Error>(room) | ||||||
|         })}).await??; |         })}).await??; | ||||||
|  | |||||||
| @ -25,6 +25,9 @@ use location::{ClientLocation, RoomLobby, ClientLocationError, RoomId}; | |||||||
| use drops::DropTable; | use drops::DropTable; | ||||||
| use items; | use items; | ||||||
| use room; | 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::Holiday; | ||||||
| use maps::area::MapAreaError; | use maps::area::MapAreaError; | ||||||
| use maps::maps::{Maps, MapsError, generate_free_roam_maps}; | use maps::maps::{Maps, MapsError, generate_free_roam_maps}; | ||||||
| @ -293,14 +296,14 @@ impl SendServerPacket for SendShipPacket { | |||||||
| 
 | 
 | ||||||
| #[derive(Clone)] | #[derive(Clone)] | ||||||
| pub struct ItemShops { | 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 tool_shop: Arc<Mutex<ToolShop<rand_chacha::ChaCha20Rng>>>, | ||||||
|     pub armor_shop: Arc<Mutex<ArmorShop<rand_chacha::ChaCha20Rng>>>, |     pub armor_shop: Arc<Mutex<ArmorShop<rand_chacha::ChaCha20Rng>>>, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Default for ItemShops { | impl Default for ItemShops { | ||||||
|     fn default() -> 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, |         let section_id = [SectionID::Viridia, SectionID::Greenill, SectionID::Skyly, SectionID::Bluefull, SectionID::Purplenum, | ||||||
|                           SectionID::Pinkal,  SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill]; |                           SectionID::Pinkal,  SectionID::Redria, SectionID::Oran, SectionID::Yellowboze, SectionID::Whitill]; | ||||||
| 
 | 
 | ||||||
| @ -327,8 +330,10 @@ pub struct ShipServerStateBuilder<EG: EntityGateway + Clone + 'static> { | |||||||
|     port: Option<u16>, |     port: Option<u16>, | ||||||
|     auth_token: Option<AuthToken>, |     auth_token: Option<AuthToken>, | ||||||
|     event: Option<Holiday>, |     event: Option<Holiday>, | ||||||
|     map_builder: Option<Box<dyn Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>>, |     map_builder: Option<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>, | ||||||
|     drop_table_builder: Option<Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + 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, |     num_blocks: usize, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -343,6 +348,8 @@ impl<EG: EntityGateway + Clone + 'static> Default for ShipServerStateBuilder<EG> | |||||||
|             event: None, |             event: None, | ||||||
|             map_builder: None, |             map_builder: None, | ||||||
|             drop_table_builder: None, |             drop_table_builder: None, | ||||||
|  |             standard_quest_builder: None, | ||||||
|  |             government_quest_builder: None, | ||||||
|             num_blocks: 2, |             num_blocks: 2, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @ -386,17 +393,29 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[must_use] |     #[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.map_builder = Some(map_builder); | ||||||
|         self |         self | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     #[must_use] |     #[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.drop_table_builder = Some(drop_table_builder); | ||||||
|         self |         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] |     #[must_use] | ||||||
|     pub fn blocks(mut self, num_blocks: usize) -> ShipServerStateBuilder<EG> { |     pub fn blocks(mut self, num_blocks: usize) -> ShipServerStateBuilder<EG> { | ||||||
|         self.num_blocks = num_blocks; |         self.num_blocks = num_blocks; | ||||||
| @ -417,6 +436,8 @@ impl<EG: EntityGateway + Clone + 'static> ShipServerStateBuilder<EG> { | |||||||
|             event: self.event.unwrap_or(Holiday::None), |             event: self.event.unwrap_or(Holiday::None), | ||||||
|             map_builder: Arc::new(self.map_builder.unwrap_or(Box::new(generate_free_roam_maps))), |             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))), |             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())), |             auth_token: self.auth_token.unwrap_or_else(|| AuthToken("".into())), | ||||||
|             ship_list: Arc::new(RwLock::new(Vec::new())), |             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>>>, |     ship_list: Arc<RwLock<Vec<Ship>>>, | ||||||
|     shipgate_sender: Option<channel::Sender<ShipMessage>>, |     shipgate_sender: Option<channel::Sender<ShipMessage>>, | ||||||
|     trades: TradeState, |     trades: TradeState, | ||||||
|     map_builder: Arc<Box<dyn Fn(maps::room::RoomMode, Holiday) -> Maps + Send + Sync>>, |     map_builder: Arc<Box<dyn Fn(RoomMode, Holiday) -> Maps + Send + Sync>>, | ||||||
|     drop_table_builder: Arc<Box<dyn Fn(maps::room::Episode, maps::room::Difficulty, SectionID) -> DropTable + 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> { | impl<EG: EntityGateway + Clone + 'static> ShipServerState<EG> { | ||||||
| @ -707,7 +730,8 @@ impl<EG: EntityGateway + Clone> ServerState for ShipServerState<EG> { | |||||||
|             RecvShipPacket::CreateRoom(create_room) => { |             RecvShipPacket::CreateRoom(create_room) => { | ||||||
|                 let block = self.blocks.get_from_client(id, &self.clients).await?; |                 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, |                 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) => { |             RecvShipPacket::RoomNameRequest(_req) => { | ||||||
|                 let block = self.blocks.get_from_client(id, &self.clients).await?; |                 let block = self.blocks.get_from_client(id, &self.clients).await?; | ||||||
|  | |||||||
| @ -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 (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; | ||||||
|     let mut ship = Box::new(ShipServerState::builder() |     let mut ship = Box::new(ShipServerState::builder() | ||||||
|         .gateway(entity_gateway.clone()) |         .gateway(entity_gateway.clone()) | ||||||
|  |         .standard_quest_builder(Box::new(quests::load_standard_quests)) | ||||||
|  |         .government_quest_builder(Box::new(quests::load_government_quests)) | ||||||
|         .build()); |         .build()); | ||||||
|     log_in_char(&mut ship, ClientId(1), "a1", "a").await; |     log_in_char(&mut ship, ClientId(1), "a1", "a").await; | ||||||
|     join_lobby(&mut ship, ClientId(1)).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 (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await; | ||||||
|     let mut ship = Box::new(ShipServerState::builder() |     let mut ship = Box::new(ShipServerState::builder() | ||||||
|         .gateway(entity_gateway.clone()) |         .gateway(entity_gateway.clone()) | ||||||
|  |         .standard_quest_builder(Box::new(quests::load_standard_quests)) | ||||||
|  |         .government_quest_builder(Box::new(quests::load_government_quests)) | ||||||
|         .build()); |         .build()); | ||||||
|     log_in_char(&mut ship, ClientId(1), "a1", "a").await; |     log_in_char(&mut ship, ClientId(1), "a1", "a").await; | ||||||
|     join_lobby(&mut ship, ClientId(1)).await; |     join_lobby(&mut ship, ClientId(1)).await; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user