Change on Coding Plans

I’ll make some changes on my coding plans. I was planning 2 weeks for designing the new Backend system based on Subsystems, but there isn’t much to do for that time, so I’ll start with the SDL refactoring along with continuing improving the new backend structure.

This way I find it much easier to work, as I’ve already the SDL backend to work with. So the next plans will be, first to separate all the SDL backend to subsystem classes and get it working. That will be more like a copy pasting work. After that is complete, I’ll start the refactoring of the SDL codes.

Backend Design

The idea and goal

My first task is refactoring the backend structure. It has to be designed in a way to improve portability and make it easier to modify.  Also, it has to allow an easy and fast way to use different libraries in platforms. This is mainly for making the next task, implementing OpenGL, easy to port.

OpenGL is only a specification for rendering, and does not include Audio playing, timers, devices detection, and else functions that a library like SDL does have. So, the goal is to be able to use OpenGL for rendering and SDL for the other tasks, or other libraries/sdks if needed.

Now, the idea is to create a backend structure based on independent subsystems. Then, we can use the audio, timer, events, and else subsystems from SDL, and use the rendering subsystem from OpenGL.

Planed design

Each backend, like for example the SDL one, will inhereit from its subsystems that already inhereit from their virtual subsystem classes. And each subsystem will inhereit from the OSystem class.

Example class diagram

In the example diagram, SubSystem_Audio, SubSystem_Timer and SubSystem_Video are the virtual structure for the SubSystem_SDL* classes. The virtual subsystems will inhereit virtualy the class OSystem, then OSystem_SDL will only include one copy of OSystem. In actual ScummVM code, OSystem_SDL overrides all OSystem functions; in the planed desing, the OSystem functions will be mostly overriden by each subsystem, and only initialization or other special codes will be included in the OSystem_SDL backend.

An idea I have in mind is also to separate the platform specify codes in OSystem_SDL, and create for each platform a new OSystem_*Platform* class that would inhereit the subsystems it needs. Then, we will have OSystem_Win, OSystem_Unix, OSystem_Mac, and else insteand of OSystem_SDL. This will help when implementing the OpenGL subsystem, as it will only be needed to change the inhereited video subsystem in the platform, and as the SDL name in the class doesn’t reflect OpenGL is being used.

01 //Example code
02
03 // Virtual Subsystems
04 class SubSystem_Timer : public virtual OSystem { ...
05 class SubSystem_Audio : public virtual OSystem { ...
06 class SubSystem_Video : public virtual OSystem { ...
07
08 // SDL subsystems
09 class SubSystem_SDLTimer : public SubSystem_Timer { ...
10 class SubSystem_SDLAudio : public SubSystem_Audio { ...
11 class SubSystem_SDLVideo : public SubSystem_Video { ...
12
13 // OpenGL subsystem
14 class SubSystem_OpenGL : public SubSystem_Video { ...
15
16 // Platfrom 1 - Using SDL
17 class OSystem_Platform1 : public SubSystem_SDLTimer, public SubSystem_SDLAudio, public SubSystem_SDLVideo { ...
18
19 // Platform 2 - Using SDL and OpenGL
20 class OSystem_Platform2 : public SubSystem_SDLTimer, public  SubSystem_SDLAudio, public SubSystem_OpenGL { ...