cinder.platform
cinder.platform #
Source: cinder/platform/__init__.mojo
Platform layer: the native library, SDL3 windows, input events and wgpu surfaces. This is the only engine module with per-operating-system branches (library file names, surface creation inside the shim). Everything above it is platform-neutral.
cinder.platform.events #
Source: cinder/platform/events.mojo
Platform events in engine terms, translated from SDL3's event union.
struct EventKind #
struct EventKind(Equatable, ImplicitlyCopyable, RegisterPassable, Writable)What an Event describes.
Fields:
-
value: UInt8 -
nonenone() -> EventKind
No event: an SDL event this layer does not translate (Platform.polldrops it). -
quitquit() -> EventKind
The application was asked to quit (SDL_EVENT_QUIT). -
window_closewindow_close() -> EventKind
The user asked to close the windowwindow_id. -
window_resizedwindow_resized() -> EventKind
Pixel size changed;a/bcarry the new width and height. -
window_minimizedwindow_minimized() -> EventKind
Windowwindow_idwas minimised. -
window_restoredwindow_restored() -> EventKind
Windowwindow_idwas restored. -
window_focus_gainedwindow_focus_gained() -> EventKind
Windowwindow_idgained keyboard focus. -
window_focus_lostwindow_focus_lost() -> EventKind
Windowwindow_idlost keyboard focus. -
keykey() -> EventKind
scancode,keycode,mods,down,repeat. -
mouse_motionmouse_motion() -> EventKind
x,yabsolute;dx,dyrelative. -
mouse_wheelmouse_wheel() -> EventKind
dx,dyscroll amounts. -
gamepad_addedgamepad_added() -> EventKind
A gamepad was connected;deviceis its SDL joystick id (Platform.pollopens it). -
gamepad_removedgamepad_removed() -> EventKind
A gamepad was disconnected;deviceis its SDL joystick id (Platform.pollcloses it). -
gamepad_axisgamepad_axis() -> EventKind
device,axis(SDL_GamepadAxis),valuenormalised to [-1, 1]. -
write_towrite_to(self, mut writer: Some[Writer])
struct Event #
struct Event(ImplicitlyCopyable, RegisterPassable, Writable)One translated platform event. Fields are interpreted per kind (see EventKind docstrings).
Fields:
-
kind: EventKind -
window_id: UInt32 -
device: UInt32 -
a: Int32 -
b: Int32 -
scancode: UInt32 -
keycode: UInt32 -
mods: UInt16 -
button: UInt8 -
axis: UInt8 -
down: Bool -
repeat: Bool -
x: Float32 -
y: Float32 -
dx: Float32 -
dy: Float32 -
value: Float32 -
emptyempty(kind: EventKind) -> Event
An event ofkindwith every other field zero or False. -
write_towrite_to(self, mut writer: Some[Writer])
def translate_event #
def translate_event(ev: SDL_Event) -> EventTranslates an SDL event into an Event; unknown SDL events become EventKind.none().
cinder.platform.native #
Source: cinder/platform/native.mojo
Loading libcinder_native exactly once and sharing it by pointer. NativeLibrary keeps the generated CinderNative struct (library handle plus every resolved symbol) at a stable heap address for the life of the program. Subsystems hold a NativePtr to it and never copy function pointers out (docs/MOJO_NOTES.md: the handle must outlive every call).
comptime NativePtr = Pointer[CinderNative, MutUntrackedOrigin]— How subsystems refer to the loaded native library.comptime LIBRARY_PATH_ENV = "CINDER_NATIVE_LIB"— Environment variable that, when set and non-empty, replaces the library pathdefault_library_pathreturns.
def default_library_path #
def default_library_path() -> StringThe library path for this OS relative to the repository root, unless CINDER_NATIVE_LIB is set.
struct NativeLibrary #
struct NativeLibrary(Movable)Owns the one loaded copy of libcinder_native.
Fields:
__init____init__(out self, path: String) raises
Loads the library atpath, resolving every bound symbol. Raises when the library is missing, a symbol is missing, or the shim's ABI version differs from the bindings'.__init____init__(out self) raises
Loads the library fromdefault_library_path().ptrptr(self) -> NativePtr
Pointer to the loaded bindings, valid only while thisNativeLibrarylives: it must be destroyed after every subsystem holding the pointer.
cinder.platform.window #
Source: cinder/platform/window.mojo
SDL3 platform: initialisation, windows, event polling, gamepads and wgpu surface creation.
comptime SdlWindowPtr = Optional[Pointer[SDL_Window, MutUntrackedOrigin]]— Nullable pointer to an SDL window.comptime EventQueuePtr = Optional[Pointer[CnEventQueue, MutUntrackedOrigin]]— Nullable pointer to a shim event queue (the platform's SDL log queue).
struct GamepadSlot #
struct GamepadSlot(ImplicitlyCopyable, Movable)An open gamepad: SDL joystick id and the SDL_Gamepad handle.
Fields:
id: UInt32handle: Optional[Pointer[SDL_Gamepad, MutUntrackedOrigin]]
struct Platform #
struct Platform(Movable)SDL initialised for video, events and gamepads. Create one, before any Window, on the main thread. SDL's log goes to a shim queue and is drained into diagnostics by poll.
Fields:
-
lib: NativePtr -
gamepads: List[GamepadSlot] -
diagnostics: List[LogRecord] — SDL log lines collected since the lasttake_diagnostics. -
forward_to_imgui: Bool — When set (by the debug UI), every raw SDL event is also handed to the ImGui backend. -
__init____init__(out self, lib: NativePtr) raises -
video_drivervideo_driver(self) -> String
Name of the current SDL video driver; empty when SDL reports none. -
last_errorlast_error(self) -> String
SDL's most recent error message (SDL_GetError). -
pollpoll(mut self, mut events: List[Event])
Drains SDL's event queue intoevents(cleared first; capacity is retained so a warmed-up list does not allocate), opening and closing gamepads as they come and go, and moves SDL log lines intodiagnostics. -
take_diagnosticstake_diagnostics(mut self) -> List[LogRecord]
Moves out the SDL log records collected bypoll, leavingdiagnosticsempty. -
push_eventpush_event(self, ev: SDL_Event) -> Bool
Injects an SDL event (tests and replay). Returns False when SDL refused it.
struct Window #
struct Window(Movable)An SDL window. Destroyed with the struct; create the wgpu surface through create_surface.
Fields:
-
lib: NativePtr -
handle: SdlWindowPtr -
id: UInt32 -
__init____init__( out self, platform: Platform, title: String, width: Int, height: Int, resizable: Bool = True, hidden: Bool = False, ) raises -
pixel_sizepixel_size(self) raises -> Tuple[Int, Int]
Drawable size in pixels as (width, height); with high pixel density it can differ from the size the window was created with. Raises when SDL fails. -
set_sizeset_size(self, width: Int, height: Int) raises
Requests a new window size and waits for it to apply (SDL_SyncWindow, whose result is ignored); raises when SDL rejects the request. -
set_titleset_title(mut self, title: String)
Sets the window title, keeping the text alive in the window; SDL failures are ignored. -
showshow(self)
Shows the window (one created withhidden); SDL failures are ignored. -
set_relative_mouseset_relative_mouse(self, enabled: Bool) -> Bool
Turns SDL relative mouse mode on or off for this window; returns False when SDL refused. -
create_surfacecreate_surface(self, instance: WGPUInstance) raises -> WGPUSurface
Creates the wgpu surface for this window through the shim (X11, Wayland or Metal). -
destroy_surfacedestroy_surface(self, surface: WGPUSurface)
Destroys a surface returned bycreate_surface, through the shim with this window's handle.