Skip to content

ASStateCache

PT | EN
Inherits: RefCounted

Circular buffer for high-performance state caching and rollback.

Description

ASStateCache provides optimized state management for multiplayer games requiring rollback and prediction capabilities. Uses a circular buffer to store recent state snapshots with minimal memory overhead.

Key features:

  • Circular buffer with configurable size (default: 128 entries)
  • Fast O(1) capture and restore operations
  • Automatic buffer management with overwrite protection
  • Serialization support for save/load operations
  • Debug utilities for state inspection

Used internally by ASComponent for high-frequency state capture during multiplayer gameplay, with fallback to ASStateSnapshot for long-term storage or save games.

Properties

TypeNameDefault
intbuffer_size128

Methods

ReturnName
voidcapture_state( component: ASComponent)
Captures the current state of the ASComponent into the cache buffer. Automatically increments tick and manages circular buffer indexing.
voidclear( )
Clears all cached state entries and resets the cache.
voiddeserialize( data: Array)
Loads cache data from a previously serialized Array.
voiddump_cache( ) const
Prints detailed cache information to the console for debugging.
Arrayget_available_ticks( ) const
Returns an array of all tick numbers currently stored in the cache.
intget_current_tick( ) const
Returns the current tick number of the cache.
intget_used_slots( ) const
Returns the number of cache slots currently in use.
boolhas_tick( tick: int) const
Returns true if the cache contains an entry for the specified tick.
boolrestore_state( component: ASComponent, tick: int)
Restores the ASComponent state from the cached entry at the specified tick. Returns true if successful, false if tick not found in cache.
Arrayserialize( ) const
Serializes all valid cache entries to an Array for storage.