Nebula
Loading...
Searching...
No Matches
Nebula.Game.Input Class Reference

Detailed Description

The mirror of the engine's default keyboard and mouse handlers.

The engine has authority over the state, and this holds what the last sync saw, so a read is a field read rather than a call through the api.

The mirror is only as good as the frame it was read in. The engine clears the per-frame flags at the start of the input frame and sets them again from the events that arrive during the pump, so the sync has to happen after the pump and before the end of the frame. NebulaApp.OnBeginFrame is that point: the render feature unit pumps the window events at the start of its OnBeginFrame, and the script feature unit is attached after it.

What is here is what the input server received. ImGui gets the keys first and the window drops the events it consumes, so a key typed into a text field never reaches the handlers. HasFocus and the two capture flags are what tell a caller that a key is missing because the UI took it rather than because nobody pressed it.

Classes

struct  KeyWords
 One key as three words: held through the frame, pressed during it, released during it. More...
struct  Snapshot
 The layout the engine writes with. More...

Static Public Member Functions

static void Sync ()
 Refresh the mirror from the engine.
static bool IsKeyHeld (Key key)
 Held at the time of the sync.
static bool IsKeyPressed (Key key)
 Went down during this frame.
static bool IsKeyReleased (Key key)
 Went up during this frame.
static bool IsMouseHeld (MouseButton button)
 Held at the time of the sync.
static bool IsMousePressed (MouseButton button)
static bool IsMouseReleased (MouseButton button)
static bool IsMouseDoubleClicked (MouseButton button)
static string CharInput ()
 The text the keyboard produced during this frame.

Properties

static int SnapshotSize [get]
 The size of the layout on this side.
static int Wheel [get]
 The wheel as the net movement for the frame: 1 forward, -1 backward, 0 when it did not move.
static Vector2 PixelPosition [get]
static Vector2 ScreenPosition [get]
 The same position as 0.0 through 1.0.
static Vector2 Movement [get]
 The movement since the frame started.
static bool HasFocus [get]
static bool MouseCaptured [get]
 Whether a handler holds the mouse.
static bool KeyCaptured [get]

Private Member Functions

static int SyncCall (IntPtr buffer, int bufferSize)
static int CharInputCall (IntPtr outBuffer, int outLen)

Static Private Member Functions

static KeyWords Words (Key key)
 The word a key code falls in.
static ulong Bit (Key key)

Static Private Attributes

const int MaxCharInput = 256
static readonly Snapshot[] buffer = new Snapshot[1]
static readonly GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
static readonly byte[] charBuffer = new byte[MaxCharInput]
static readonly GCHandle charHandle = GCHandle.Alloc(charBuffer, GCHandleType.Pinned)

Member Function Documentation

◆ Bit()

ulong Nebula.Game.Input.Bit ( Key key)
inlinestaticprivate

◆ CharInput()

string Nebula.Game.Input.CharInput ( )
inlinestatic

The text the keyboard produced during this frame.

Text only crosses through a buffer this side owns, so this is the call that reads it. Empty when nothing was typed.

◆ CharInputCall()

int Nebula.Game.Input.CharInputCall ( IntPtr outBuffer,
int outLen )
private

◆ IsKeyHeld()

bool Nebula.Game.Input.IsKeyHeld ( Key key)
inlinestatic

Held at the time of the sync.

A key that was pressed and released inside one frame is held for that frame, because the engine keeps the pressed state until the frame after the release.

◆ IsKeyPressed()

bool Nebula.Game.Input.IsKeyPressed ( Key key)
inlinestatic

Went down during this frame.

This is the edge, so it is true for one frame only.

◆ IsKeyReleased()

bool Nebula.Game.Input.IsKeyReleased ( Key key)
inlinestatic

Went up during this frame.

Also an edge, and also true for one frame only.

◆ IsMouseDoubleClicked()

bool Nebula.Game.Input.IsMouseDoubleClicked ( MouseButton button)
inlinestatic

◆ IsMouseHeld()

bool Nebula.Game.Input.IsMouseHeld ( MouseButton button)
inlinestatic

Held at the time of the sync.

◆ IsMousePressed()

bool Nebula.Game.Input.IsMousePressed ( MouseButton button)
inlinestatic

◆ IsMouseReleased()

bool Nebula.Game.Input.IsMouseReleased ( MouseButton button)
inlinestatic

◆ Sync()

void Nebula.Game.Input.Sync ( )
inlinestatic

Refresh the mirror from the engine.

Called once per frame at the beginning of the frame, after the events have been pumped. A run with no window has no input server, and the mirror is cleared for it rather than left with the state the previous frame had.

◆ SyncCall()

int Nebula.Game.Input.SyncCall ( IntPtr buffer,
int bufferSize )
private

◆ Words()

KeyWords Nebula.Game.Input.Words ( Key key)
inlinestaticprivate

The word a key code falls in.

A code outside the codes the engine has is not in any word, so the answer is no bit rather than a read outside the buffer.

Member Data Documentation

◆ buffer

readonly Snapshot [] Nebula.Game.Input.buffer = new Snapshot[1]
staticprivate

◆ charBuffer

readonly byte [] Nebula.Game.Input.charBuffer = new byte[MaxCharInput]
staticprivate

◆ charHandle

readonly GCHandle Nebula.Game.Input.charHandle = GCHandle.Alloc(charBuffer, GCHandleType.Pinned)
staticprivate

◆ handle

readonly GCHandle Nebula.Game.Input.handle = GCHandle.Alloc(buffer, GCHandleType.Pinned)
staticprivate

◆ MaxCharInput

const int Nebula.Game.Input.MaxCharInput = 256
staticprivate

Property Documentation

◆ HasFocus

bool Nebula.Game.Input.HasFocus
staticget

◆ KeyCaptured

bool Nebula.Game.Input.KeyCaptured
staticget

◆ MouseCaptured

bool Nebula.Game.Input.MouseCaptured
staticget

Whether a handler holds the mouse.

The handler that holds the capture is the one the events go to, so this is what tells a caller that the mouse is somewhere else.

◆ Movement

Vector2 Nebula.Game.Input.Movement
staticget

The movement since the frame started.

The engine builds it as the position the frame started at minus the position the event carried, which is the negative of the delta, and the raw move path assigns the delta itself. See ISSUES.md.

◆ PixelPosition

Vector2 Nebula.Game.Input.PixelPosition
staticget

◆ ScreenPosition

Vector2 Nebula.Game.Input.ScreenPosition
staticget

The same position as 0.0 through 1.0.

◆ SnapshotSize

int Nebula.Game.Input.SnapshotSize
staticget

The size of the layout on this side.

The engine asserts the same number, and the test compares the two, because the field order is the only thing the contract has.

◆ Wheel

int Nebula.Game.Input.Wheel
staticget

The wheel as the net movement for the frame: 1 forward, -1 backward, 0 when it did not move.


The documentation for this class was generated from the following file:
  • /github/workspace/code/addons/nsharp/NebulaEngine/engine/Input.cs