pub struct ObserverHandle { /* private fields */ }Expand description
Owns the Windows handles from OpenFileMappingW and MapViewOfFile.
Releases them via Drop and dereferences to ObserverData for read and
write access to the memory map.
Implementations§
Source§impl ObserverHandle
impl ObserverHandle
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Opens the observer memory map and sets the refresh rate to the default of 500 ms.
Returns an error if Warcraft III is not running, or the stats observer API is otherwise unavailable.
Examples found in repository?
examples/stats.rs (line 6)
5fn main() {
6 let od = match ObserverHandle::new() {
7 Ok(od) => od,
8 Err(e) => {
9 eprintln!("Error opening observer API. Is Warcraft3 running? Error: {e:?}");
10 return;
11 }
12 };
13
14 println!("version: {}", { od.version });
15 println!("refresh rate: {}", { od.refresh_rate });
16
17 let game = &od.game;
18
19 println!("in game: {:?}", game.in_game);
20 println!(
21 "time: {:02}:{:02}",
22 game.time().as_secs() / 60,
23 game.time().as_secs() % 60
24 );
25 println!("active player count: {:?}", game.active_player_count);
26 println!("game name: {}", game.game_name);
27 println!("map name: {}", game.map_name);
28
29 loop {
30 for player in od.players.iter().take(od.game.active_player_count as usize) {
31 println!("{} has {} gold {} lumber", player.name, { player.gold }, {
32 player.lumber
33 });
34 }
35 println!();
36 std::thread::sleep(Duration::from_millis(od.refresh_rate as u64));
37 }
38}Sourcepub fn new_with_refresh_rate(duration: Duration) -> Result<Self>
pub fn new_with_refresh_rate(duration: Duration) -> Result<Self>
Opens the observer memory map and writes duration as the refresh
rate. A duration of zero disables updates.
Returns an error if Warcraft III is not running, or the stats observer API is otherwise unavailable.
Methods from Deref<Target = ObserverData>§
Sourcepub fn set_refresh_rate(&mut self, duration: Duration)
pub fn set_refresh_rate(&mut self, duration: Duration)
Sets the observer’s refresh rate. Sub-millisecond precision is truncated. A duration of zero disables updates.
Trait Implementations§
Source§impl Deref for ObserverHandle
impl Deref for ObserverHandle
Source§impl DerefMut for ObserverHandle
impl DerefMut for ObserverHandle
Source§impl Drop for ObserverHandle
impl Drop for ObserverHandle
impl Send for ObserverHandle
impl Sync for ObserverHandle
Auto Trait Implementations§
impl Freeze for ObserverHandle
impl RefUnwindSafe for ObserverHandle
impl Unpin for ObserverHandle
impl UnsafeUnpin for ObserverHandle
impl UnwindSafe for ObserverHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more