ASStateCache
Inherits:
RefCountedCircular 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
| Type | Name | Default |
|---|---|---|
int | buffer_size | 128 |
Methods
| Return | Name |
|---|---|
void | capture_state(
component: ASComponent) |
Captures the current state of the ASComponent into the cache buffer.
Automatically increments tick and manages circular buffer indexing. | |
void | clear( ) |
Clears all cached state entries and resets the cache. | |
void | deserialize(
data: Array) |
Loads cache data from a previously serialized Array. | |
void | dump_cache(
)
const |
Prints detailed cache information to the console for debugging. | |
Array | get_available_ticks(
)
const |
Returns an array of all tick numbers currently stored in the cache. | |
int | get_current_tick(
)
const |
Returns the current tick number of the cache. | |
int | get_used_slots(
)
const |
Returns the number of cache slots currently in use. | |
bool | has_tick(
tick: int)
const |
Returns true if the cache contains an entry for the specified tick. | |
bool | restore_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. | |
Array | serialize(
)
const |
Serializes all valid cache entries to an Array for storage. | |