joy(3alleg4)
π joy π
okay bestie, so this is a page from the Allegro game programming library, and it's about joy β the global array where all your joystick tea gets spilled. β¨
πΈ SYNOPSIS πΈ
#include <allegro.h>
extern JOYSTICK_INFO joy[n];
π DESCRIPTION π
So joy is the global array of joystick state information, and it gets refreshed by the poll_joystick() function. π
Heads up though: only the first num_joysticks elements actually have anything meaningful in them. The rest are justβ¦ vibes. π
The JOYSTICK_INFO structure is defined like this, no cap:
typedef struct JOYSTICK_INFO
{
int flags; - status flags for this joystick
int num_sticks; - how many stick inputs?
int num_buttons; - how many buttons?
JOYSTICK_STICK_INFO stick[n]; - stick state information
JOYSTICK_BUTTON_INFO button[n]; - button state information
} JOYSTICK_INFO;
The button status lives in this lil structure right here:
typedef struct JOYSTICK_BUTTON_INFO
{
int b; - boolean on/off flag
char *name; - description of this button
} JOYSTICK_BUTTON_INFO;
You might wanna display those button names as part of an input configuration screen, so your user can pick which game function each button does β very main character of them honestly. π«Ά But if you're keeping it simple, you can safely assume that the first two elements in the button array will always be the main trigger controls. Slay.
Each joystick is gonna give you one or more stick inputs, and they come in varying types, like a whole spectrum bestie. π They can be digital controls that snap to specific positions β think a gamepad controller, the coolie hat on a Flightstick Pro or Wingman Extreme, or a normal joystick that hasn't been calibrated yet. Or they can be full analogue inputs with a smooth range of motion. Sticks can also have different numbers of axes β a normal directional control has two, but the Flightstick Pro throttle is only a single axis, and it's possible the system could be extended in the future to support full 3d controllers. (future-proofing, we love to see it π)
A stick input is described by this structure:
typedef struct JOYSTICK_STICK_INFO
{
int flags; - status flags for this input
int num_axis; - how many axes do we have? (note the misspelling)
JOYSTICK_AXIS_INFO axis[n]; - axis state information
char *name; - description of this input
} JOYSTICK_STICK_INFO;
A single joystick may provide several different stick inputs, but you can safely assume that the first element in the stick array will always be the main directional controller. periodt.
Info about each of the stick axis is stored in the substructure:
typedef struct JOYSTICK_AXIS_INFO
{
int pos; - analogue axis position
int d1, d2; - digital axis position
char *name; - description of this axis
} JOYSTICK_AXIS_INFO;
So this gives you both analogue input in the pos field β ranging from -128 to 128 or from 0 to 255, depending on the type of the control β <em>and</em> digital values in the d1 and d2 fields. β¨
For example: when describing the X-axis position, the pos field holds the horizontal position of the joystick, d1 gets set if it's moved left, and d2 gets set if it's moved right. Allegro fills in all these values regardless of whether it's using a digital or analogue joystick β it emulates the pos field for digital inputs by snapping it to the min, middle, and maximum positions, and it emulates the d1 and d2 values for an analogue stick by comparing the current position with the centre point. iconic behaviour fr fr. π
β¨ the flags, bestie β¨
The joystick flags field may contain any combination of these bit flags:
JOYFLAG_DIGITALβ This control is currently providing digital input. πJOYFLAG_ANALOGUEβ This control is currently providing analogue input. π¦JOYFLAG_CALIB_DIGITALβ This control will be capable of providing digital input once it has been calibrated, but it's not doing that at the moment. πJOYFLAG_CALIB_ANALOGUEβ This control will be capable of providing analogue input once it has been calibrated, but it's not doing that at the moment. πJOYFLAG_CALIBRATEβ Indicates that this control needs to be calibrated. Many devices require multiple calibration steps, so you should call thecalibrate_joystick()function from a loop until this flag is cleared. πJOYFLAG_SIGNEDβ Indicates that the analogue axis position is in signed format, ranging from-128to128. This is the case for all 2d directional controls. βJOYFLAG_UNSIGNEDβ Indicates that the analogue axis position is in unsigned format, ranging from0to255. This is the case for all 1d throttle controls. β
note for people who spell funny π : in case you don't like having to type "analogue", there are some#definealiases inallegro/joystick.hthat will allow you to write "analog" instead. no judgement, we support you either way. π«Ά
π₯ SEE ALSO π₯
install_joystick(3alleg4)poll_joystick(3alleg4)num_joysticks(3alleg4)calibrate_joystick(3alleg4)calibrate_joystick_name(3alleg4)exjoy(3alleg4)
and that's the whole page, bestie!! πβ¨π this one came from Allegro, version 4.4.3, and it's the joy(3alleg4) page β go forth and poll those joysticks, you absolute legend. ππ¦πΈ
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms