Skip to main content

GameTracer

Struct GameTracer 

Source
pub struct GameTracer { /* private fields */ }
Expand description

High-level game tracer that integrates all tracing components.

Provides a simple API for recording and querying game traces:

  • begin_frame(): Start recording a new frame
  • record_input(): Record an input event
  • end_frame(): Finish the frame and optionally take a snapshot
  • stats(): Get trace statistics for debugging

§Example

use jugar_web::trace::{GameTracer, TracerConfig, InputEvent, InputEventType};

let mut tracer = GameTracer::new(TracerConfig::default());

// Each frame:
tracer.begin_frame();
tracer.record_input(InputEvent {
    event_type: InputEventType::KeyDown(32), // Space
    frame_offset_us: 0,
});
tracer.end_frame(None); // Or provide state hash

Implementations§

Source§

impl GameTracer

Source

pub fn new(config: TracerConfig) -> Self

Create a new game tracer with the given configuration.

Source

pub fn debug() -> Self

Create a debug tracer (Andon Cord enabled).

Source

pub fn production() -> Self

Create a production tracer (drop oldest on overflow).

Source

pub fn begin_frame(&mut self)

Start recording a new frame.

Must be called at the start of each frame before recording inputs.

Source

pub fn record_input(&mut self, event: InputEvent)

Record an input event for the current frame.

§Panics

Panics in debug builds if begin_frame() was not called.

Source

pub fn record_inputs(&mut self, events: impl IntoIterator<Item = InputEvent>)

Record multiple input events for the current frame.

Source

pub fn end_frame(&mut self, state_hash: Option<[u8; 32]>) -> SnapshotDecision

End the current frame and commit it to the trace buffer.

§Arguments
  • state_hash - Optional state hash for verification and snapshot decisions.
§Returns

The snapshot decision (Skip, DeltaSnapshot, or FullSnapshot).

Source

pub fn stats(&self) -> TraceStats

Get trace statistics for debugging display.

Source

pub fn start_recording(&mut self)

Start recording.

Source

pub fn stop_recording(&mut self)

Stop recording.

Source

pub const fn is_recording(&self) -> bool

Check if recording is active.

Source

pub const fn current_frame(&self) -> u64

Get current frame number.

Source

pub const fn buffer(&self) -> &TraceBuffer

Get a reference to the underlying buffer.

Source

pub fn query(&self) -> TraceQuery<'_>

Create a query interface for the trace buffer.

Source

pub fn clear(&mut self)

Clear the trace buffer and reset statistics.

Source

pub fn drain(&mut self, count: usize) -> Vec<FrameRecord>

Drain frames from the buffer for export.

Source

pub fn export_json(&self) -> Result<String, TraceError>

Export all frames as JSON.

§Errors

Returns a serialization error if the frames cannot be serialized.

Trait Implementations§

Source§

impl Debug for GameTracer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V