Skip to content

API Proposal #1

Description

@jice-nospam

So this library should provide low level access to gamepad/joystick input, and we have to keep in mind that we have to create a unified API for web and native. I'd rather go for a pragmatic API like this :

This might not be doable on every platform so we'll probably have to iterate a bit. it's a starting point.

Also, this is not compilable rust but you get the idea.

This also helps to define the perimeter of what we want to support with this library as this can go pretty wild (gamepad only or joystick/motion sensor? vibrations ? headsets ?) keeping in mind that high level features like key-repeat, key-mapping or dead zone should not be part of this low level library but rather on top of uni-pad.

struct ControllerInfo {
    name: String,
    digital_count : usize, // number of ON/OFF buttons
    analog_count: usize, // number of -1.0-1.0 axis
}

struct ControllerState {
    status: enum to be defined,
    sequence: usize, // incremented every time state is changed
    digital_state: Vec<bool>,
    analog_state: Vec<f32>,
}

struct ControllerContext {
fn get_controller_num() -> usize;
fn get_controller_info(controller_num: usize) -> ControllerInfo;
fn borrow_controller_state(controller_num: usize) -> &ControllerState;
}

In case a controller is not available anymore because it was unplugged, the API should return some default values so that end user doesn't have to deal with Option.

If you have 2 controllers plugged : 0 and 1 and you unplug 0, 1 is still available at index 1. 0 returns a default value with a status indicating it's unpluged.

[edit] status should be obviously in ControllerState. Also added sequence field

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions