feat(match): 添加画面上下镜像、跳过准备和装甲板整局复位
This commit is contained in:
39 files changed
+1094
-54
No files matched your search
@@ -188,6 +188,28 @@ fn main() -> Result<()> {
|
||||
damage.accept(command, from, now);
|
||||
}
|
||||
}
|
||||
Ok(Some((net::ControlCommand::Reset(mut command), from))) => {
|
||||
if command.board_id == sender_id {
|
||||
if let Some(apply) = damage.accept_reset(command, from, now) {
|
||||
if apply {
|
||||
armor.set_damage_enabled(false);
|
||||
armor.reset();
|
||||
warn!(
|
||||
"referee reset: hp={} reset_id={}",
|
||||
armor.hp(),
|
||||
command.reset_id
|
||||
);
|
||||
}
|
||||
command.acknowledged = true;
|
||||
if let Some(bytes) = command.encode() {
|
||||
if let Err(err) = reporter.send_to(&bytes, from) {
|
||||
warn!("reset acknowledgement failed: {err:#}");
|
||||
}
|
||||
}
|
||||
force_report = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None) => break,
|
||||
Err(err) => {
|
||||
warn!("client control receive failed: {err:#}");
|
||||
|
||||
@@ -21,11 +21,12 @@ use anyhow::{anyhow, Result};
|
||||
use esp_idf_svc::sys as ffi;
|
||||
use log::{info, warn};
|
||||
|
||||
use armor_protocol::{ArmorControl, ArmorDamageControl, ARMOR_PORT, BROADCAST_ADDR};
|
||||
use armor_protocol::{ArmorControl, ArmorDamageControl, ArmorReset, ARMOR_PORT, BROADCAST_ADDR};
|
||||
|
||||
pub enum ControlCommand {
|
||||
Team(ArmorControl),
|
||||
Damage(ArmorDamageControl),
|
||||
Reset(ArmorReset),
|
||||
}
|
||||
|
||||
/// 把 Rust 的 socket 地址转成 lwIP 期望的 C 结构。
|
||||
@@ -98,6 +99,8 @@ impl Reporter {
|
||||
ControlCommand::Team(control)
|
||||
} else if let Some(control) = ArmorDamageControl::decode(bytes) {
|
||||
ControlCommand::Damage(control)
|
||||
} else if let Some(control) = ArmorReset::decode(bytes) {
|
||||
ControlCommand::Reset(control)
|
||||
} else {
|
||||
return Ok(None);
|
||||
};
|
||||
@@ -148,7 +151,11 @@ impl Reporter {
|
||||
|
||||
/// 把一个数据报广播到裁判终端。
|
||||
pub fn broadcast(&self, payload: &[u8]) -> Result<()> {
|
||||
let addr = to_sockaddr(SocketAddrV4::new(BROADCAST_ADDR, ARMOR_PORT));
|
||||
self.send_to(payload, SocketAddrV4::new(BROADCAST_ADDR, ARMOR_PORT))
|
||||
}
|
||||
|
||||
pub fn send_to(&self, payload: &[u8], destination: SocketAddrV4) -> Result<()> {
|
||||
let addr = to_sockaddr(destination);
|
||||
|
||||
// SAFETY: 缓冲区与地址在调用期间都有效;sendto 复制数据而不是持有指针。
|
||||
let rc = unsafe {
|
||||
|
||||
Reference in new issue
Block a user