Skip to main content

warcraft3_stats_observer/
game.rs

1use std::time::Duration;
2
3use crate::string_utils::PaddedString;
4
5const MAX_GAME_NAME_LENGTH: usize = 256;
6const MAX_MAP_NAME_LENGTH: usize = 256;
7
8/// Game-wide state exposed by the Warcraft III Stats Observer API.
9#[repr(C, packed)]
10pub struct ObserverGame {
11    /// `true` while a game is in progress.
12    pub in_game: bool,
13    /// Elapsed game time in milliseconds. Use [`Self::time`] for a
14    /// strongly-typed [`Duration`].
15    pub clock_ms: u32,
16    /// Number of valid entries in [`crate::ObserverData::players`].
17    pub active_player_count: u8,
18    /// Name of the current game / lobby.
19    pub game_name: PaddedString<MAX_GAME_NAME_LENGTH>,
20    /// Name of the map currently being played.
21    pub map_name: PaddedString<MAX_MAP_NAME_LENGTH>,
22}
23
24impl ObserverGame {
25    /// Returns the elapsed game time as a [`Duration`].
26    pub fn time(&self) -> Duration {
27        Duration::from_millis(self.clock_ms as u64)
28    }
29}
30// Number generated from SIZE fields of https://github.com/TinkerWorX/Blizzard.Net.Warcraft3
31// noinspection RsAssertEqual
32const _: () = assert!(size_of::<ObserverGame>() == 518);