Hello everyone,
I'm writing here because I would like some insight about the OSWindowDriver.
As
you may know, the OSWindowDriver (via OSSDL2Driver) is responsible for
many things in OSWindow such as setting up the event loop, creating the
SDL window, etc.
My first question is : How are you supposed to access the driver ?
Currently
you can do a "OSWindowDriver current" and it should return you the
"most suited driver". It is the way the driver is picked if you don't
specify a preferable driver in the OSWindow attributes.
I see two problems with this :
- If you don't have the SDL plugin it returns you an OSWindowNullDriver
and you cannot do anything with it even if you have the SDL library.
- Let's say that SDL does not meet my requirements and I create another
binding to another library. I now have the possibility to use OSWindow
with two different back-ends. How does the OSWindowDriver discriminates
between the twos ?
Now if I want to specify a driver I can do it by setting "preferableDriver" in the OSWindowAttributes.
But if I want an OSSDL2Driver, the only way I see for the moment is to call "OSSDL2Driver new".
But
by doing so I am creating an instance of the driver per window created
whereas with "OSWindowDriver current" I am only using one instance of
the driver for all windows. I think something is not coherent here.
So
should all specific drivers be singletons ? Should they all implement
their own version of the "current" method returning the only instance of
them ?
I have another remark too :
The
driver needs to keep a map of all active windows to be able to dispatch
events to the correct one. But when a window is destroyed, it needs to
be removed from the map so there is no mess in the events and so the
garbage collector can free it.
Currently the window map is
a class variable of OSSDL2Driver. But I think the map should be common
to all drivers because they would probably all need one. So I'd like to
move the WindowMap class variable to the "OSWindowDriver" class directly with a class method to remove the selected window from it. That way when a window is destroyed, we just have to call this class method and it is easy.