Re: [AD] object oriented AL_SYSTEM |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Saturday 26 August 2006 4:12 am, Elias Pschernig wrote:
> How would a base structure like below look?
>
> struct AL_SYSTEM_DRIVER
> {
> ...variables + methods
> };
>
> struct AL_SYSTEM
> {
> AL_SYSTEM_DRIVER *driver;
> ... variables
> };
>
> ... for each driver XXX
> struct AL_SYSTEM_XXX
> {
> AL_SYSTEM *system;
> ... variables
> }
>
> They would all be internal and no members accessed by the user.
>
> The first struct would be just like the current SYSTEM_DRIVER - i.e. the
> "interface" or "vtable". We didn't decide yet what features we want from
> that (there's still
> http://awiki.tomasu.org/bin/view/Main/ProposedVTables ).
>
> The second struct would be an object to hold all the system specific
> global variables, e.g. things like the detected CPU capabilities and
> whatever else is now in global variables floating around.
>
> The last struct would be a driver specific version of AL_SYSTEM, which
> could be cast to it. It would be created somewhere in al_init, something
> like:
>
> AL_SYSTEM *_al_create_system(AL_SYSTEM_DRIVER *driver)
> {
> system = driver->create_system(driver);
> ... initialize platform independent stuff in system
> return system;
> }
>
> And driver->create_system might be:
>
> AL_SYSTEM *_al_create_system_x11(AL_SYSTEM_DRIVER *driver)
> {
> AL_SYSTEM_X11 *system = _AL_MALLOC(sizeof *system);
> ... initialize driver specific stuff in system
> return (AL_SYSTEM *)system;
> }
>
> The advantage I see in it is that we don't need internal global
> variables floating around so much. Especially under X11, the _xwin
> struct could go into the created AL_SYSTEM_X11 object.
>
I think it should go something like:
struct AL_SYSTEM {
...
};
struct AL_SYSTEM_FOO {
AL_SYSTEM base;
}
AL_SYSTEM_FOO can now be cast as a AL_SYSTEM just fine, and AL_SYSTEM_FOO can
add anything it wants.
--
Thomas Fjellstrom
tfjellstrom@xxxxxxxxxx