Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bflib/src/db/ephemeral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,8 @@ impl Default for Ephemeral {
impl Ephemeral {
fn do_bg(&self, task: Task) {
if let Some(to_bg) = &self.to_bg {
match to_bg.send(task) {
Ok(()) => (),
Err(_) => panic!("background thread is dead"),
if let Err(e) = to_bg.send(task) {
error!("Failed to send task to background thread: {}", e);
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions bflib/src/db/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ pub struct SpawnedGroup {
}

impl Db {
/// Get an iterator over all groups in the database
/// This is part of the public API for external access to group data
#[allow(dead_code)]
pub fn groups(&self) -> impl Iterator<Item = (&GroupId, &SpawnedGroup)> {
self.persisted.groups.into_iter()
Expand All @@ -169,6 +171,8 @@ impl Db {
))
}

/// Get the 3D center point of a group
/// This is part of the public API for external access to group data
#[allow(dead_code)]
pub fn group_center3(&self, id: &GroupId) -> Result<Vector3> {
let group = group!(self, id)?;
Expand All @@ -187,6 +191,8 @@ impl Db {
))
}

/// Find a group by its name
/// This is part of the public API for external access to group data
#[allow(dead_code)]
pub fn group_by_name(&self, name: &str) -> Result<&SpawnedGroup> {
group_by_name!(self, name)
Expand All @@ -196,6 +202,8 @@ impl Db {
unit!(self, id)
}

/// Find a unit by its name
/// This is part of the public API for external access to unit data
#[allow(dead_code)]
pub fn unit_by_name(&self, name: &str) -> Result<&SpawnedUnit> {
unit_by_name!(self, name)
Expand Down
33 changes: 21 additions & 12 deletions bflib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod landcache;
mod menu;
mod msgq;
mod shots;
mod splash;
mod spawnctx;

extern crate nalgebra as na;
Expand Down Expand Up @@ -259,6 +260,7 @@ struct Context {
landcache: LandCache,
ewr: Ewr,
jtac: Jtacs,
splash_damage: splash::SplashDamageSystem,
}

impl Context {
Expand Down Expand Up @@ -295,9 +297,8 @@ impl Context {

fn do_bg_task(&self, task: bg::Task) {
if let Some(to_bg) = &self.to_background {
match to_bg.send(task) {
Ok(()) => (),
Err(_) => panic!("background thread is dead"),
if let Err(e) = to_bg.send(task) {
error!("Failed to send task to background thread: {}", e);
}
}
}
Expand Down Expand Up @@ -553,12 +554,12 @@ fn on_player_try_change_slot(
fn unit_killed(
lua: MizLua,
ctx: &mut Context,
id: DcsOid<ClassUnit>,
id: &DcsOid<ClassUnit>,
now: DateTime<Utc>,
) -> Result<()> {
ctx.recently_landed.remove(&id);
ctx.shots_out.dead(id.clone(), now);
if let Err(e) = ctx.jtac.unit_dead(lua, &mut ctx.db, &id) {
if let Err(e) = ctx.jtac.unit_dead(lua, &mut ctx.db, id) {
error!("jtac unit dead failed for {:?} {:?}", id, e)
}
if let Err(e) = ctx.db.unit_dead(&id, Utc::now()) {
Expand Down Expand Up @@ -631,7 +632,8 @@ fn on_event(lua: MizLua, ev: Event) -> Result<()> {
}
}
if dead {
if let Err(e) = unit_killed(lua, ctx, target.object_id()?, start_ts) {
let target_id = target.object_id()?;
if let Err(e) = unit_killed(lua, ctx, &target_id, start_ts) {
error!("0 unit killed failed {:?}", e)
}
}
Expand All @@ -647,12 +649,15 @@ fn on_event(lua: MizLua, ev: Event) -> Result<()> {
if let Err(e) = ctx.shots_out.shot(&ctx.db, start_ts, &e) {
error!("error processing shot event {:?}", e)
}
()
// Process splash damage for weapon shots
if let Err(e) = ctx.splash_damage.track_weapon_shot(lua, &e, start_ts) {
error!("error tracking weapon shot for splash damage {:?}", e)
}
}
Event::Dead(e) | Event::UnitLost(e) | Event::PilotDead(e) => {
if let Some(unit) = e.initiator.as_ref().and_then(|u| u.as_unit().ok()) {
let id = unit.object_id()?;
if let Err(e) = unit_killed(lua, ctx, id, start_ts) {
if let Err(e) = unit_killed(lua, ctx, &id, start_ts) {
error!("1 unit killed failed {:?}", e)
}
} else if let Some(st) = e.initiator.as_ref().and_then(|s| s.as_static().ok()) {
Expand All @@ -664,7 +669,7 @@ fn on_event(lua: MizLua, ev: Event) -> Result<()> {
Event::Ejection(e) => {
if let Ok(unit) = e.initiator.as_unit() {
let id = unit.object_id()?;
if let Err(e) = unit_killed(lua, ctx, id, start_ts) {
if let Err(e) = unit_killed(lua, ctx, &id, start_ts) {
error!("2 unit killed failed {}", e)
}
}
Expand Down Expand Up @@ -1118,7 +1123,7 @@ fn run_timed_events(ctx: &mut Context, lua: MizLua, path: &PathBuf) -> Result<Ad
Ok((i, dead)) => {
ctx.last_unit_position = i;
for id in dead {
if let Err(e) = unit_killed(lua, ctx, id.clone(), ts) {
if let Err(e) = unit_killed(lua, ctx, &id, ts) {
error!("unit killed failed {:?} {:?}", id, e)
}
}
Expand All @@ -1134,7 +1139,7 @@ fn run_timed_events(ctx: &mut Context, lua: MizLua, path: &PathBuf) -> Result<Ad
Ok((i, dead)) => {
ctx.last_player_position = i;
for id in dead {
if let Err(e) = unit_killed(lua, ctx, id.clone(), ts) {
if let Err(e) = unit_killed(lua, ctx, &id, ts) {
error!("unit killed failed {:?} {:?}", id, e)
}
}
Expand Down Expand Up @@ -1177,7 +1182,7 @@ fn run_timed_events(ctx: &mut Context, lua: MizLua, path: &PathBuf) -> Result<Ad
Err(e) => error!("error updating jtac target positions {:?}", e),
Ok(dead) => {
for id in dead {
if let Err(e) = unit_killed(lua, ctx, id.clone(), now) {
if let Err(e) = unit_killed(lua, ctx, &id, now) {
error!("unit killed failed {:?} {:?}", id, e)
}
}
Expand All @@ -1202,6 +1207,10 @@ fn run_timed_events(ctx: &mut Context, lua: MizLua, path: &PathBuf) -> Result<Ad
if let Err(e) = run_jtac_commands(ctx, lua) {
error!("failed to run jtac commands {e:?}")
}
// Update tracked weapons for splash damage
if let Err(e) = ctx.splash_damage.update_tracked_weapons(lua, ts, &ctx.db) {
error!("error updating tracked weapons {:?}", e)
}
ctx.load_state.step();
record_perf(&mut perf.timed_events, ts);
ctx.log_perf(now);
Expand Down
15 changes: 12 additions & 3 deletions bflib/src/msgq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ pub enum PanelDest {
}

#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub enum MarkDest {
#[allow(dead_code)]
All,
Side(Side),
#[allow(dead_code)]
Group(GroupId),
}

Expand All @@ -57,7 +58,6 @@ pub enum MsgTyp {
}

#[derive(Debug, Clone)]
#[allow(dead_code)]
pub enum Msg {
Message {
typ: MsgTyp,
Expand All @@ -69,6 +69,7 @@ pub enum Msg {
spec: CircleSpec,
message: Option<String>,
},
#[allow(dead_code)]
Rect {
id: MarkId,
to: SideFilter,
Expand Down Expand Up @@ -96,6 +97,7 @@ pub enum Msg {
id: MarkId,
color: Color,
},
#[allow(dead_code)]
SetMarkupFillColor {
id: MarkId,
color: Color,
Expand Down Expand Up @@ -180,6 +182,8 @@ impl MsgQ {
}
}

/// Create a mark visible to all players
/// This is part of the public API for message queue functionality
#[allow(dead_code)]
pub fn mark_to_all<S: Into<String>>(
&mut self,
Expand Down Expand Up @@ -222,6 +226,8 @@ impl MsgQ {
id
}

/// Create a mark visible to a specific group
/// This is part of the public API for message queue functionality
#[allow(dead_code)]
pub fn mark_to_group<S: Into<String>>(
&mut self,
Expand All @@ -244,7 +250,6 @@ impl MsgQ {
id
}

#[allow(dead_code)]
pub fn panel_to_all<S: Into<String>>(&mut self, display_time: i64, clear_view: bool, text: S) {
self.send_with_priority(
0,
Expand Down Expand Up @@ -326,6 +331,8 @@ impl MsgQ {
}))
}

/// Create a rectangle mark visible to all players
/// This is part of the public API for message queue functionality
#[allow(dead_code)]
pub fn rect_to_all(
&mut self,
Expand Down Expand Up @@ -380,6 +387,8 @@ impl MsgQ {
self.0[2].push_back(Cmd::Send(Msg::SetMarkupColor { id, color }))
}

/// Set the fill color of a markup element
/// This is part of the public API for message queue functionality
#[allow(dead_code)]
pub fn set_markup_fill_color(&mut self, id: MarkId, color: Color) {
self.0[2].push_back(Cmd::Send(Msg::SetMarkupFillColor { id, color }))
Expand Down
Loading