1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Minor refactor to make match configs easier to work with

This commit is contained in:
NG (Graham)
2026-03-21 21:37:54 -04:00
parent 57b825a6f8
commit 0a93432783
4 changed files with 65 additions and 39 deletions

View File

@@ -124,12 +124,19 @@ impl GameMatches {
let fakes_handler = super::fake::Handler::start(fakes, players.clone()).await;
match game_info.mode {
oj_rc_core::data::game_mode::GameMode::SuddenDeath => {
let inner = super::modes::EliminationLogic::new(&self.mode_configs.elimination, &map_config, &players);
let engine = super::GenericGamemodeEngine::new(
game_info,
map_config,
&self.mode_configs.elimination,
let super_conf = super::engine::SuperConfig {
descriptor: game_info,
map: map_config,
game_mode: &self.mode_configs.elimination,
players,
};
let inner = super::modes::EliminationLogic::new(
&self.mode_configs.elimination,
&super_conf.map,
&super_conf.players,
);
let engine = super::GenericGamemodeEngine::new(
super_conf,
inner,
fakes_handler,
self.mp_settings.clone(),
@@ -159,12 +166,19 @@ impl GameMatches {
} else {
self.ba_sorted_crystals.read().await.clone()
};
let inner = super::modes::BattleArenaLogic::new(&self.mode_configs.battle_arena, &map_config, &players, resolved_ba_conf, crystals);
let engine = super::GenericGamemodeEngine::new(
game_info,
map_config,
&self.mode_configs.battle_arena,
let super_conf = super::engine::SuperConfig {
descriptor: game_info,
map: map_config,
game_mode: &self.mode_configs.battle_arena,
players,
};
let inner = super::modes::BattleArenaLogic::new(
&super_conf,
resolved_ba_conf,
crystals,
);
let engine = super::GenericGamemodeEngine::new(
super_conf,
inner,
fakes_handler,
self.mp_settings.clone(),
@@ -172,17 +186,20 @@ impl GameMatches {
Ok(engine.spawn())
},
oj_rc_core::data::game_mode::GameMode::Pit => {
let super_conf = super::engine::SuperConfig {
descriptor: game_info,
map: map_config,
game_mode: &self.mode_configs.the_pit,
players,
};
let inner = super::modes::PitLogic::new(
&self.mode_configs.the_pit,
&map_config,
&players,
&super_conf.map,
&super_conf.players,
self.pit_settings.clone(),
);
let engine = super::GenericGamemodeEngine::new(
game_info,
map_config,
&self.mode_configs.the_pit,
players,
super_conf,
inner,
fakes_handler,
self.mp_settings.clone(),
@@ -190,17 +207,20 @@ impl GameMatches {
Ok(engine.spawn())
},
oj_rc_core::data::game_mode::GameMode::TeamDeathmatch => {
let super_conf = super::engine::SuperConfig {
descriptor: game_info,
map: map_config,
game_mode: &self.mode_configs.team_deathmatch,
players,
};
let inner = super::modes::TeamDeathMatchLogic::new(
&self.mode_configs.team_deathmatch,
&map_config,
&players,
&super_conf.map,
&super_conf.players,
self.tdm_settings.clone(),
);
let engine = super::GenericGamemodeEngine::new(
game_info,
map_config,
&self.mode_configs.team_deathmatch,
players,
super_conf,
inner,
fakes_handler,
self.mp_settings.clone(),

View File

@@ -4,6 +4,13 @@ pub struct RlnlPacket {
pub data: Box<dyn crate::Broadcastable>,
}
pub struct SuperConfig<'a> {
pub descriptor: oj_rc_core::persist::user::GameDescriptor,
pub map: oj_rc_core::persist::config::MapConfig,
pub game_mode: &'a oj_rc_core::data::game_mode::GameModeConfig,
pub players: Vec<oj_rc_core::persist::user::PlayerDescriptor>,
}
/// Functions returning a boolean indicate if the generic engine should also perform the default behaviour
/// (true = yes, do default behaviour)
#[async_trait::async_trait]

View File

@@ -311,10 +311,7 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
const COUNTDOWN_DURATION: std::time::Duration = std::time::Duration::from_secs(5);
pub fn new(
game: oj_rc_core::persist::user::GameDescriptor,
map: oj_rc_core::persist::config::MapConfig,
config: &oj_rc_core::data::game_mode::GameModeConfig,
players: Vec<oj_rc_core::persist::user::PlayerDescriptor>,
super_conf: crate::matches::engine::SuperConfig,
custom: L,
fakes_handler: super::fake::Handler,
mp_config: std::sync::Arc<oj_rc_core::persist::config::MultiplayerSettings>,
@@ -325,11 +322,11 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
.map(|player| (player.team as u8, FakeUser::new(player.to_owned())))
.collect();*/
let descriptors = players.iter()
let descriptors = super_conf.players.iter()
.map(|player| (player.player_id, UserDescriptor::new(player.to_owned())))
.collect();
let user_id_map = players.iter()
let user_id_map = super_conf.players.iter()
.filter_map(|player| player.user_id.map(|id| (id, player.player_id)))
.collect();
Self {
@@ -338,9 +335,9 @@ impl <L: super::CustomGameLogic> GenericGamemodeEngine<L> {
user_id_map,
is_complete: std::sync::atomic::AtomicBool::new(false),
game_start: std::sync::atomic::AtomicI64::new(i64::MIN),
map_config: std::sync::Arc::new(map),
game_descriptor: game,
game_duration: std::time::Duration::from_secs((config.game_time_minutes as u64) * 60),
map_config: std::sync::Arc::new(super_conf.map),
game_descriptor: super_conf.descriptor,
game_duration: std::time::Duration::from_secs((super_conf.game_mode.game_time_minutes as u64) * 60),
custom_logic_handler: custom,
fakes_handler,
unclaimed: UnclaimedStats::new(),

View File

@@ -765,7 +765,7 @@ impl BaseTracker {
let one_tick = (crystals.len() as f32)
* ((PointTracker::TICK_MS as f32) / (generic.game_duration.as_millis() as f32))
* ((self.bases.len() as f32) / (capture_points_count as f32));
let one_tick = 0.1;
//let one_tick = 0.1;
let increment = tick_info.delta as f32 * (*owned_points as f32) * one_tick * multiplier;
let old_float_index = tracked_base.cube_index.fetch_add(increment, std::sync::atomic::Ordering::SeqCst);
let new_float_index = old_float_index + increment;
@@ -1055,7 +1055,7 @@ pub struct BattleArenaLogic {
}
impl BattleArenaLogic {
pub fn new(config: &oj_rc_core::data::game_mode::GameModeConfig, map: &oj_rc_core::persist::config::MapConfig, players: &[oj_rc_core::persist::user::PlayerDescriptor], ba_config: oj_rc_core::data::battle_arena_config::BattleArenaData, crystals: std::sync::Arc<Vec<oj_rc_core::cubes::CubeLocationInfo>>) -> Self {
pub fn new(super_conf: &crate::matches::engine::SuperConfig, ba_config: oj_rc_core::data::battle_arena_config::BattleArenaData, crystals: std::sync::Arc<Vec<oj_rc_core::cubes::CubeLocationInfo>>) -> Self {
//let min_y = crystals.iter().min_by_key(|x| x.y).unwrap();
//log::warn!("First crystal is as ({}, {}, {})", min_y.x, min_y.y, min_y.z);
let base_graph = oj_rc_core::cubes::CubeGraph::with_data(
@@ -1064,19 +1064,21 @@ impl BattleArenaLogic {
oj_rc_core::cubes::CLASP_ID,
).expect("Invalid Battle Arena base cube data");
Self {
respawn_full_heal_duration: config.respawn_full_heal_duration,
respawn_heal_duration: config.respawn_heal_duration,
respawn_full_heal_duration: super_conf.game_mode.respawn_full_heal_duration,
respawn_heal_duration: super_conf.game_mode.respawn_heal_duration,
timer_task: tokio::sync::Mutex::new(None),
player_tracking: PlayerTracker::new(players),
capture_tracking: PointTracker::new(map.capture_points.iter().map(|(_, speed)| *speed)),
player_tracking: PlayerTracker::new(&super_conf.players),
capture_tracking: PointTracker::new(super_conf.map.capture_points.iter().map(|(_, speed)| *speed)),
surrender_tracking: super::trackers::SurrenderGameTracker::new(),
base_tracking: BaseTracker::new(map.bases.keys(), &crystals, &ba_config, &base_graph),
base_tracking: BaseTracker::new(super_conf.map.bases.keys(), &crystals, &ba_config, &base_graph),
//cube_parser,
//ba_base: teambase,
//ba_equalizer: equalizer,
crystals,
config: ba_config,
can_drop_shields: true,
can_drop_shields: super_conf.descriptor.overrides.as_ref()
.map(|overrides| overrides.base_shields_go_down)
.unwrap_or(true),
}
}