raysan5/raylib

[core] Should the defines MAX_* be part of the public API?

albertvaka opened this issue · 5 comments

Issue description

In config.h there are a few defines like MAX_KEYBOARD_KEYS , MAX_MOUSE_BUTTONS, MAX_GAMEPADS, etc. that could be added to the public interface in raylib.h. This would allow iterating over all buttons/gamepads/whatever, which currently requires re-defining those in the user code.

They could even be added within the respective enums, eg:

typedef enum {
    MOUSE_BUTTON_LEFT,
    MOUSE_BUTTON_RIGHT,
    MOUSE_BUTTON_MIDDLE,
    MOUSE_BUTTON_SIDE,
    MOUSE_BUTTON_EXTRA,
    MOUSE_BUTTON_FORWARD,
    MOUSE_BUTTON_BACK,
    MAX_MOUSE_BUTTONS  // <-- 
} MouseButton;

Which has the advantage of taking the last value of the enum and doesn't require the value to be assigned manually.

I'm afraid those max values can not be exposed because they are used internally to define some global arrays size, if users were able to redefine it, there would be a size missmatch with the internal arrays.

Definitely not allow users to redefine them, just to read them. Enum values can't be written at runtime 🤷

@albertvaka I think I missunderstood the request, reopening it for further review.

It seems interesting and I think it should be implemented, however I can't see many use cases besides:

  • Custom Input Handling
  • Memory Management
  • Debugging and Optimization

@albertvaka After analyzing possible ways to expose those variables I get to the conclusion that best option is let it the users just include raylib config.h definitions if really required, raylib.h does not expose this kind of definitions and if trying to add them will imply conflicts with config.h that will require addressing. Also, it could be confusing to users, some users could expect changing them in raylib.h will have an effect on raylib internal behaviour.

So, in conclusion, users requiring those variables can just include config.h to have access to them.