[AD] Alleg5 - new driver structure idea

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]



Here's something I came up with:

<code>
typedef struct AL_DRIVER_VTABLE_ENTRY {
   char *func_name;     /* Name of the function in the driver */
   float version;       /* Version of this function */
   void *ptr;           /* Pointer to the function */
} AL_DRIVER_VTABLE_ENTRY;


typedef struct AL_DRIVER_VTABLE {
int vtable_version; /* Version of the vtable, for potential binary compatibility */
   char *name;          /* Name of the driver */
   char *driver;        /* ID of which driver type this really is */
AL_DRIVER_VTABLE_ENTRY table[]; /* Function table */
} AL_DRIVER_VTABLE;


int al_register_driver(AL_DRIVER_VTABLE *driver);


/* example driver */
AL_DRIVER_VTABLE ddraw7 = {
   0,
   "Direct Draw 7 / Windows",
   "gfx",
   {
       { "is_present",            1.0,  &_ddraw7_is_present},
       { "create_display_bitmap", 1.0,  &_ddraw7_create_display_bitmap},
       /* Other functions go here */
       { NULL, 0, NULL }
   }
};

al_register_driver(&ddraw7);

</code>

Then, install_foobar() will read the list of registered drivers stored by al_register_driver(), find all drivers that match foobar's functionality, and convert them to it's internal vtable representation.


Pros:
- Easy to add "drivers" for just about every component of Allegro (mixer, bitmap loader, graphics, etc)
- A single function call for registering all drivers
- All drivers use the same structure (from the user's point of view)
- Drivers are forward and backwards compatible from Allegro 5 onwards
  This can be useful during the WIP period
- The user can have the option of removing drivers by using install_allegro
  instead of allegro_init, then registering the drivers he wants.

Cons:
- More code is needed to support the new structure (internal bloat)
- We may need to supoprt older versions of the interfaces


So, in your opinion, is this good/bad/overkill, and why?





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/