Show / Hide Table of Contents

Class GameStateBase

An abstract base class used to implement IGameState from a method to retrieve game objects.

Inheritance
object
StateBase<ObjectInfo, IGameObject>
GameStateBase
GenericGameState
Implements
IDisposable
IGameState
IState<ObjectInfo, IGameObject>
IReadOnlyCollection<IGameObject>
IEnumerable<IGameObject>
IEnumerable
IEventAggregator<IGameEventArgs>
IEventPublisher<IGameEventArgs>
IHasUpdateTime
Inherited Members
StateBase<ObjectInfo, IGameObject>.Logger
StateBase<ObjectInfo, IGameObject>.UpdateTime
StateBase<ObjectInfo, IGameObject>.Count
StateBase<ObjectInfo, IGameObject>.IsUpdateInProgress
StateBase<ObjectInfo, IGameObject>.Cache
StateBase<ObjectInfo, IGameObject>.Semaphore
StateBase<ObjectInfo, IGameObject>.UpdateProcessor
StateBase<ObjectInfo, IGameObject>.Get(ObjectInfo, TimeSpan, CancellationToken)
StateBase<ObjectInfo, IGameObject>.Existing(ObjectInfo)
StateBase<ObjectInfo, IGameObject>.Clear(ObjectInfo)
StateBase<ObjectInfo, IGameObject>.WaitForUpdateFinished()
StateBase<ObjectInfo, IGameObject>.Dispose()
StateBase<ObjectInfo, IGameObject>.GetEnumerator()
StateBase<ObjectInfo, IGameObject>.GetObject(ObjectInfo, CancellationToken)
StateBase<ObjectInfo, IGameObject>.Set(in ObjectInfo, IGameObject)
StateBase<ObjectInfo, IGameObject>.AgeObject(ObjectInfo)
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Microsoft.XboxStudios.GameStateTracker
Assembly: GameStateTracker.Core.dll
Syntax
public abstract class GameStateBase : StateBase<ObjectInfo, IGameObject>, IDisposable, IGameState, IState<ObjectInfo, IGameObject>, IReadOnlyCollection<IGameObject>, IEnumerable<IGameObject>, IEnumerable, IEventAggregator<IGameEventArgs>, IEventPublisher<IGameEventArgs>, IHasUpdateTime

Constructors

View Source

GameStateBase(ILogger<GameStateBase>?, IGameObjectCache?)

Initializes a new instance of the GameStateBase class.

Declaration
protected GameStateBase(ILogger<GameStateBase>? logger = null, IGameObjectCache? cache = null)
Parameters
Type Name Description
ILogger<GameStateBase> logger

The logger to use.

IGameObjectCache cache

The cache to use to store game objects.

Properties

View Source

EventAggregator

Gets or sets the game event aggregator.

Declaration
protected IEventAggregator<IGameEventArgs>? EventAggregator { get; set; }
Property Value
Type Description
IEventAggregator<IGameEventArgs>
View Source

GameCache

Gets the cache of game objects.

Declaration
protected IGameObjectCache GameCache { get; }
Property Value
Type Description
IGameObjectCache
View Source

RecentEvents

Gets a read-only list of recent game events.

Declaration
public IReadOnlyList<IGameEventArgs> RecentEvents { get; }
Property Value
Type Description
IReadOnlyList<IGameEventArgs>

Methods

View Source

Clear(ObjectInfo?)

Removes an object from the cache.

Declaration
public bool Clear(ObjectInfo? info)
Parameters
Type Name Description
ObjectInfo? info

The object info.

Returns
Type Description
bool

True if the object was removed.

View Source

ClearAll<T>(params string?[])

Removes all cached objects derived from the given class names.

Declaration
public virtual void ClearAll<T>(params string?[] classNames) where T : IGameObject
Parameters
Type Name Description
string[] classNames

The class names.

Type Parameters
Name Description
T

The game object type.

View Source

ClearEvents()

Clears the list of game events.

Declaration
public virtual void ClearEvents()
View Source

ExistingAll<T>(string?)

Gets all cached game objects derived from the given type and class name.

Declaration
public virtual IEnumerable<T> ExistingAll<T>(string? className = null) where T : IGameObject
Parameters
Type Name Description
string className

The class name. If null, no class filter is applied.

Returns
Type Description
IEnumerable<T>

An enumerable of game objects.

Type Parameters
Name Description
T

The game object type.

View Source

Existing<T>(ObjectInfo?)

Gets a cached game object with the given info.

Declaration
public T? Existing<T>(ObjectInfo? info = null) where T : class, IGameObject
Parameters
Type Name Description
ObjectInfo? info

The object info.

Returns
Type Description
T

A game object.

Type Parameters
Name Description
T

The game object type.

View Source

GetAll<T>(ObjectInfo, TimeSpan, CancellationToken)

Retrieves all objects matching the given query.

Declaration
public Task<IEnumerable<T>> GetAll<T>(ObjectInfo query, TimeSpan maxAge, CancellationToken token = default) where T : IGameObject
Parameters
Type Name Description
ObjectInfo query

The objects to look for.

TimeSpan maxAge

The maximum age of the objects, if they exist in the cache.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<IEnumerable<T>>

An enumerable of objects.

Type Parameters
Name Description
T

The object type.

View Source

GetAll<T>(string, TimeSpan, CancellationToken)

Retrieves all game objects derived from the given class name.

Declaration
public virtual Task<IEnumerable<T>> GetAll<T>(string className, TimeSpan maxAge, CancellationToken token = default) where T : IGameObject
Parameters
Type Name Description
string className

The class name.

TimeSpan maxAge

The maximum age of the objects, if they exist in the cache.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<IEnumerable<T>>

An enumerable of game objects.

Type Parameters
Name Description
T

The game object type.

View Source

GetAll<T>(TimeSpan, CancellationToken)

Retrieves all game objects derived from the given object type.

Declaration
public virtual Task<IEnumerable<T>> GetAll<T>(TimeSpan maxAge, CancellationToken token = default) where T : IGameObject
Parameters
Type Name Description
TimeSpan maxAge

The maximum age of the object, if it exists in the cache.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<IEnumerable<T>>

An enumerable of game objects.

Type Parameters
Name Description
T

The game object type.

View Source

GetObject(ObjectInfo, CancellationToken)

Retrieves an object matching the given query.

Declaration
protected override Task<IGameObject?> GetObject(ObjectInfo query, CancellationToken token)
Parameters
Type Name Description
ObjectInfo query

The objects to look for.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<IGameObject>

An object.

Overrides
StateBase<ObjectInfo, IGameObject>.GetObject(ObjectInfo, CancellationToken)
View Source

GetObjects(ObjectInfo, CancellationToken)

Retrieves all objects matching the given query.

Declaration
protected abstract Task<IEnumerable<IGameObject>> GetObjects(ObjectInfo query, CancellationToken token)
Parameters
Type Name Description
ObjectInfo query

The objects to look for.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<IEnumerable<IGameObject>>

An enumeration of objects.

View Source

Get<T>(ObjectInfo, TimeSpan, CancellationToken)

Retrieves an object.

Declaration
public virtual Task<T?> Get<T>(ObjectInfo query, TimeSpan maxAge, CancellationToken token = default) where T : class, IGameObject
Parameters
Type Name Description
ObjectInfo query

The object to look for.

TimeSpan maxAge

The maximum age of the object, if it exists in the cache.

CancellationToken token

The cancellation token.

Returns
Type Description
Task<T>

The object.

Type Parameters
Name Description
T

The object type.

View Source

Match(IGameObject, in ObjectInfo)

Determines if the game object matches the given query.

Declaration
protected virtual bool Match(IGameObject input, in ObjectInfo query)
Parameters
Type Name Description
IGameObject input

The game object.

ObjectInfo query

The query.

Returns
Type Description
bool

True if the game object matches the given query.

View Source

Match(IGameObject, string)

Determines if the game object has the given class name.

Declaration
protected virtual bool Match(IGameObject input, string className)
Parameters
Type Name Description
IGameObject input

The game object.

string className

The class name.

Returns
Type Description
bool

True if the game object's class name matches the given name.

View Source

PublishEvent(object?, IGameEventArgs)

Publishes a game event.

Declaration
protected void PublishEvent(object? sender, IGameEventArgs e)
Parameters
Type Name Description
object sender

The event source.

IGameEventArgs e

The game event.

View Source

Set(in ObjectInfo, IGameObject?)

Stores or removes an object.

Declaration
protected override void Set(in ObjectInfo info, IGameObject? value)
Parameters
Type Name Description
ObjectInfo info

The object information.

IGameObject value

The object to store. If null, the object is removed.

Overrides
StateBase<ObjectInfo, IGameObject>.Set(in ObjectInfo, IGameObject)

Events

View Source

EventReceived

Occurs when a game event is published.

Declaration
public event EventHandler<IGameEventArgs>? EventReceived
Event Type
Type Description
EventHandler<IGameEventArgs>

Implements

IDisposable
IGameState
IState<TKey, TValue>
IReadOnlyCollection<T>
IEnumerable<T>
IEnumerable
IEventAggregator<T>
IEventPublisher<T>
IHasUpdateTime

Extension Methods

IGameStateExtensions.GetLocalPlayerPawn<T>(IGameState, int, TimeSpan)
IGameStateExtensions.GetLocalPlayerState<T>(IGameState, int, TimeSpan)
IGameStateExtensions.GetLocalPlayer<T>(IGameState, int, TimeSpan)
IGameStateExtensions.GetPlayerLocation<T>(IGameState, int, TimeSpan)
IGameStateExtensions.LocalPlayer(IGameState, int)
IGameStateExtensions.LocalPlayerState(IGameState, int)
IGameStateExtensions.OrderByNearest<T>(IGameState, int, IEnumerable<T>)
IGameStateExtensions.PlayerDistanceTo(IGameState, int, IActor)
IGameStateExtensions.PlayerDistanceTo(IGameState, int, Vector3?)
IGameStateExtensions.PlayerLocation(IGameState, int)
IEnumerableExtensions.WithoutLast<T>(IEnumerable<T>)
  • View Source
In this article
Back to top Generated by DocFX