Table of Contents

Class PygameContext

Namespace
Gym.Rendering
Assembly
Gym.Rendering.dll

One pygame "process" (DR-41): a display (Display) and the event queue its window feeds (Events), so several games can run side by side, each in a window of its own and each reading only its own events. Default is the process-wide context that pygame's spelling reaches: the static Display and EventQueue forward to it, so line-for-line ports keep pygame.display.set_mode(...) as Display.SetMode(...).

public sealed class PygameContext : IDisposable
Inheritance
PygameContext
Implements
Inherited Members
Extension Methods

Remarks

Give Run(IEnv, bool?, double?, double?, PlayCallback?, object?, BigInteger?, object?, bool, EnvViewerFactory?, PygameContext?), RunAsync(IEnv, bool?, double?, double?, PlayCallback?, object?, BigInteger?, object?, bool, EnvViewerFactory?, PygameContext?, CancellationToken) or PlayableGame a context of its own to play two games at once; with null they use Default, and two games there steal each other's events and windows, as two loops in one pygame process would.

Disposing a context is pygame.quit() for it: the window closes and pending events are dropped. The context stays usable afterwards (a new SetMode(int, int, bool, EnvViewerFactory?, string?) opens a window again), so disposing Default is safe. Thread-safe, as its display and queue are.

Constructors

PygameContext(EnvViewerFactory?)

A context whose display opens its windows with viewerFactory (DR-20), or with Gymnasium.HumanViewerFactory when that is null; no window opens until SetMode(int, int, bool, EnvViewerFactory?, string?).

public PygameContext(EnvViewerFactory? viewerFactory = null)

Parameters

viewerFactory EnvViewerFactory

The factory of this context's windows (AvaloniaEnvViewer.Factory, NullEnvViewer.Factory headless), or null to read Gymnasium.HumanViewerFactory each time a window opens. A factory passed to SetMode(int, int, bool, EnvViewerFactory?, string?) itself still wins.

Properties

Default

The process-wide context, the one pygame has: the static Display and EventQueue are its display and queue, and every play call without a context uses it.

public static PygameContext Default { get; }

Property Value

PygameContext

Display

The context's display: its one window and surface (pygame.display).

public PygameDisplay Display { get; }

Property Value

PygameDisplay

Events

The context's event queue (pygame.event), fed by Display's window and by posts.

public PygameEventQueue Events { get; }

Property Value

PygameEventQueue

ViewerFactory

The factory this context opens windows with, or null to read Gymnasium.HumanViewerFactory at each SetMode(int, int, bool, EnvViewerFactory?, string?).

public EnvViewerFactory? ViewerFactory { get; }

Property Value

EnvViewerFactory

Methods

Dispose()

pygame.quit() for this context: closes the window, forgets the surface and drops every pending event. Idempotent, and the context stays usable.

public void Dispose()