Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
current stb_platform API structure
typedef struct {
float seconds_delta;
double seconds;
stbp_uint64 ns;
stbp_uint64 ns_delta;
stbp_uint64 ms;
stbp_uint64 ms_delta;
} stbp_time_info;
typedef struct {
float seconds_delta; // OUT
double seconds; // OUT
stbp_uint64 ns; // OUT
stbp_uint64 ns_delta; // OUT
stbp_uint64 ms; // OUT
stbp_uint64 ms_delta; // OUT
struct {
float clamped_max_seconds_delta; // IN
stbp_time_info clamped_time; // OUT
stbp_bool paused; // IN
stbp_time_info pausable_time; // OUT
} eextra;
} stbp_time_info_toplevel;
typedef struct {
stbp_bool is_down;
stbp_bool was_pressed;
stbp_bool was_released;
} stbp_button;
typedef struct {
unsigned char is_down:1;
unsigned char was_pressed:1;
unsigned char was_released:1;
} stbp_button_history;
typedef struct {
stbp_point position; // position in canvas coordinates
stbp_point delta_position; // delta of position in canvas coordinates
stbp_point raw_delta_position; // movement in abstract coordinates (raw mouse data if possible)
stbp_button left, middle, right; // button transitions & state
float delta_mousewheel; // wheel movement in units of "lines"
stbp_point window_position; // position in windows coordinates
stbp_point console_position; // position in console (textout, printf) coordinates
int x,y; // copy of 'position' for convenience
} stbp_mouse_state;
typedef struct
{
struct {
float x,y; // OUT stick direction & magnitude, each -1..1
float magnitude; // OUT stick magnitude 0..1, magnitude of <x,y>
float deadzone_inner; // IN 0-1 (set during INIT to device default if 0)
float deadzone_outer; // IN 0-1 (set during INIT to 1 if 0)
float bias; // IN curve remapping, linear if 0, -1 has larger range for small motion, 1 has larger range for large motion
} processed;
struct {
float x,y; // OUT stick direction
} raw;
} stbp_gamepad_stick_state; // 24
typedef struct {
stbp_bool connected;
struct {
stbp_gamepad_stick_state left;
stbp_gamepad_stick_state right;
} sticks;
struct {
unsigned char a,b;
unsigned char x,y;
unsigned char start,back;
unsigned char trigger_left, trigger_right;
unsigned char shoulder_left, shoulder_right;
} buttons;
struct {
unsigned char right,up,left,down;
} dpad;
struct {
float shoulder_left_analog, shoulder_right_analog;
float trigger_left_analog , trigger_right_analog ;
} extra;
} stbp_gamepad_state; // ~80
typedef struct {
stbp_uint64 id; // OUT unique identifier for every history element
double wallclock_seconds; // OUT unique timestamp for every history element
stbp_mouse_state mouse; // OUT mouse state at this timestamp
stbp_button_history keys[STBP_NUM_KEYS]; // OUT keyboard state at this timestamp
stbp_gamepad_state gamepad; // OUT gamepad state at this timestamp
} stbp_input_history_state; // 8+8+40+128*3+~64 => ~512
typedef struct stbp_api
{
stbp_bool quit; // OUT stbp_platform reports user requested exit
struct {
stbp_point size; // INOUT size of client rect in pixels; 0,0 means same as display
stbp_bool fullscreen; // IN fullscreen (prefe rably borderless windowed fullscreen)
char * title; // IN window title
stbp_point position; // OUT position of top-left corner in screen coordinates
stbp_bool forbid_resize; // IN don't allow user resizing
stbp_bool focused; // OUT whether window is frontmost/focused
struct {
stbp_bool enabled; // INOUT toggle this to show a magnifying glass
int vkey; // IN key which when held down sets the 'enabled' flag
int num_pixels; // IN number of pixels in window space on each axis
float zoom_factor; // IN amount to zoom contents by
} magnify;
} window;
struct {
stbp_point size; // INOUT size of rendertarget to render to; 0,0 means same as window
stbp_bool pixelate; // IN resample to screen with nearest-neighbor?
stbp_bool lock_size; // INOUT resizing the window doesn't change display size; defaults to true if you request a size at init
int x,y; // IN copy of size.x, size.y for convenience
} draw; // renamed from 'display' so 'display' can refer to monitors
stbp_time_info_toplevel time;
stbp_mouse_state mouse; // OUT state of the mouse & mouse buttons
stbp_button keys[STBP_NUM_KEYS]; // OUT state of the keyboard
stbp_gamepad_state gamepads[4]; // OUT state of the gamepads
int typing[STBP_MAX_CHARS_PER_FRAME+1]; // OUT UNICODE characters typed since last frame, 0-terminated
struct {
int one_event_per_frame; // IN input events are doled out one per frame so their ordering is unambigous
int preserve_all_events; // IN input events are doled out multiple per frame, at most one of each type, see docs
int numlock_changes_vkey; // IN change vkey values depending on numlock state (this is normal behavior on windows)
unsigned char key_for_char[STBP_NUM_KEYS]; // OUT the virtual key for whatever key is in the same location as given character on a US keyboard
char keynames[STBP_NUM_KEYS][30]; // OUT names for virtual keys; only defined if user has pressed it at least once
stbp_input_history_state history[STBP_NUM_INPUT_HISTORY]; // ~10KB
stbp_bool shift, control, alt; // IN copy of keys[STBVK_SHIFT].is_down etc. for convenience
} input;
struct {
int disable; // INIT disable sound entirely (no perf difference on windows)
int sample_rate; // INOUT, set to -1 for no audio
int channels; // OUT number of channels, always 2 (someday: INOUT, defaults to 2)
float *buffer; // IN interleaved stereo samples you output to, has minimum latency to output
int buffer_num_aframes; // OUT max number of samples you can set, 2x the number of 'audio frames'
float *continuous_buffer; // IN interleaved stereo samples that are continuously connected to previous frame, non-minimal latency
int continuous_num_aframes; // OUT number of samples you output
int latency_protect_ms; // INIT controls size of continuous_buffer
int max_oneshot_ms; // INIT controls size of oneshot_buffer
int continuous_latency_aframes;// IN estimated latency of continuous buffer
int reset; // OUT if true, kills audio and next continuous buffer will start with minimal latency
struct {
void (*callback)(float *buffer, int num_floats);
} advanced;
} sound;
struct {
stbp_gl_version version; // INOUT can use STBP_GL_VERSION() to construct
stbp_bool compatibility; // INIT request compatibility profile (@TODO: becomes *simulated* compatibility)
stbp_bool debug_context; // INIT request a debug context
stbp_bool disable_vsync; // IN
int renderbuffer; // OUT renderbuffer to render to (set by default)
} opengl;
struct {
stbp_bool show_frame_time; // IN displays frame times in top-left corner
struct {
stbp_point size; // INOUT size in pixels of console; 0,0 means same as window
float scale; // INIT scale of console pixels relative to window pixels (sets size)
stbp_bool show; // INOUT if true, console is visible
stbp_bool autoshow; // IN printing to the console sets show to true
int show_vkey; // IN this key toggles show
} console;
struct {
stbp_pointf mouselook_degrees; // OUT absolute mouselook in degrees
float mouselook_scale; // IN scale from mousemove-units to DEGREES
stbp_pointf wasd_movement; // OUT desired speed -1 to 1 w/ +x = forward, +y = left
stbp_pointf wasd_smoothed; // OUT automatically smoothed desired speed
float smooth_start_time; // IN 0 to 1 time in seconds
float smooth_stop_time; // IN 0 to 1 time in seconds
} fps_input;
struct {
void *buffer; // must be enough memory for all audio buffers, OpenGL compatability mode, etc.
size_t size_in_bytes;
} memory;
stbp_gamepad_state gamepad; // whichever gamepad most recently changed
} extra;
// these allow you to see how much time is being spent in internals of stb_platform startup
struct {
struct {
float phase_0;
float phase_1;
float phase_2;
float phase_3;
float phase_4;
} startup_timing;
struct {
float phase_0;
float phase_1;
float phase_2;
float phase_3;
float phase_4;
float internal;
} window_timing;
} system;
} stbp_api;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment