1 | //============================================================================ |
2 | // |
3 | // SSSS tt lll lll |
4 | // SS SS tt ll ll |
5 | // SS tttttt eeee ll ll aaaa |
6 | // SSSS tt ee ee ll ll aa |
7 | // SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" |
8 | // SS SS tt ee ll ll aa aa |
9 | // SSSS ttt eeeee llll llll aaaaa |
10 | // |
11 | // Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony |
12 | // and the Stella Team |
13 | // |
14 | // See the file "License.txt" for information on usage and redistribution of |
15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
16 | //============================================================================ |
17 | |
18 | #ifndef MEDIA_FACTORY_HXX |
19 | #define MEDIA_FACTORY_HXX |
20 | |
21 | #include "bspf.hxx" |
22 | #if defined(SDL_SUPPORT) |
23 | #include "SDL_lib.hxx" |
24 | #endif |
25 | |
26 | #include "OSystem.hxx" |
27 | #include "Settings.hxx" |
28 | #include "SerialPort.hxx" |
29 | #if defined(BSPF_UNIX) |
30 | #include "SerialPortUNIX.hxx" |
31 | #if defined(RETRON77) |
32 | #include "SettingsR77.hxx" |
33 | #include "OSystemR77.hxx" |
34 | #else |
35 | #include "OSystemUNIX.hxx" |
36 | #endif |
37 | #elif defined(BSPF_WINDOWS) |
38 | #include "SerialPortWINDOWS.hxx" |
39 | #include "OSystemWINDOWS.hxx" |
40 | #elif defined(BSPF_MACOS) |
41 | #include "SerialPortMACOS.hxx" |
42 | #include "OSystemMACOS.hxx" |
43 | extern "C" { |
44 | int stellaMain(int argc, char* argv[]); |
45 | } |
46 | #elif defined(__LIB_RETRO__) |
47 | #include "OSystemLIBRETRO.hxx" |
48 | #else |
49 | #error Unsupported platform! |
50 | #endif |
51 | |
52 | #if defined(__LIB_RETRO__) |
53 | #include "EventHandlerLIBRETRO.hxx" |
54 | #include "FrameBufferLIBRETRO.hxx" |
55 | #elif defined(SDL_SUPPORT) |
56 | #include "EventHandlerSDL2.hxx" |
57 | #include "FrameBufferSDL2.hxx" |
58 | #else |
59 | #error Unsupported backend! |
60 | #endif |
61 | |
62 | #if defined(SOUND_SUPPORT) |
63 | #if defined(__LIB_RETRO__) |
64 | #include "SoundLIBRETRO.hxx" |
65 | #elif defined(SDL_SUPPORT) |
66 | #include "SoundSDL2.hxx" |
67 | #else |
68 | #include "SoundNull.hxx" |
69 | #endif |
70 | #else |
71 | #include "SoundNull.hxx" |
72 | #endif |
73 | |
74 | class AudioSettings; |
75 | |
76 | /** |
77 | This class deals with the different framebuffer/sound/event |
78 | implementations for the various ports of Stella, and always returns a |
79 | valid object based on the specific port and restrictions on that port. |
80 | |
81 | As of SDL2, this code is greatly simplified. However, it remains here |
82 | in case we ever have multiple backend implementations again (should |
83 | not be necessary since SDL2 covers this nicely). |
84 | |
85 | @author Stephen Anthony |
86 | */ |
87 | class MediaFactory |
88 | { |
89 | public: |
90 | static unique_ptr<OSystem> createOSystem() |
91 | { |
92 | #if defined(BSPF_UNIX) |
93 | #if defined(RETRON77) |
94 | return make_unique<OSystemR77>(); |
95 | #else |
96 | return make_unique<OSystemUNIX>(); |
97 | #endif |
98 | #elif defined(BSPF_WINDOWS) |
99 | return make_unique<OSystemWINDOWS>(); |
100 | #elif defined(BSPF_MACOS) |
101 | return make_unique<OSystemMACOS>(); |
102 | #elif defined(__LIB_RETRO__) |
103 | return make_unique<OSystemLIBRETRO>(); |
104 | #else |
105 | #error Unsupported platform for OSystem! |
106 | #endif |
107 | } |
108 | |
109 | static unique_ptr<Settings> createSettings() |
110 | { |
111 | #ifdef RETRON77 |
112 | return make_unique<SettingsR77>(); |
113 | #else |
114 | return make_unique<Settings>(); |
115 | #endif |
116 | } |
117 | |
118 | static unique_ptr<SerialPort> createSerialPort() |
119 | { |
120 | #if defined(BSPF_UNIX) |
121 | return make_unique<SerialPortUNIX>(); |
122 | #elif defined(BSPF_WINDOWS) |
123 | return make_unique<SerialPortWINDOWS>(); |
124 | #elif defined(BSPF_MACOS) |
125 | return make_unique<SerialPortMACOS>(); |
126 | #else |
127 | return make_unique<SerialPort>(); |
128 | #endif |
129 | } |
130 | |
131 | static unique_ptr<FrameBuffer> createVideo(OSystem& osystem) |
132 | { |
133 | #if defined(__LIB_RETRO__) |
134 | return make_unique<FrameBufferLIBRETRO>(osystem); |
135 | #elif defined(SDL_SUPPORT) |
136 | return make_unique<FrameBufferSDL2>(osystem); |
137 | #else |
138 | #error Unsupported platform for FrameBuffer! |
139 | #endif |
140 | } |
141 | |
142 | static unique_ptr<Sound> createAudio(OSystem& osystem, AudioSettings& audioSettings) |
143 | { |
144 | #if defined(SOUND_SUPPORT) |
145 | #if defined(__LIB_RETRO__) |
146 | return make_unique<SoundLIBRETRO>(osystem, audioSettings); |
147 | #elif defined(SOUND_SUPPORT) && defined(SDL_SUPPORT) |
148 | return make_unique<SoundSDL2>(osystem, audioSettings); |
149 | #else |
150 | return make_unique<SoundNull>(osystem); |
151 | #endif |
152 | #else |
153 | return make_unique<SoundNull>(osystem); |
154 | #endif |
155 | } |
156 | |
157 | static unique_ptr<EventHandler> createEventHandler(OSystem& osystem) |
158 | { |
159 | #if defined(__LIB_RETRO__) |
160 | return make_unique<EventHandlerLIBRETRO>(osystem); |
161 | #elif defined(SDL_SUPPORT) |
162 | return make_unique<EventHandlerSDL2>(osystem); |
163 | #else |
164 | #error Unsupported platform for EventHandler! |
165 | #endif |
166 | } |
167 | |
168 | static void cleanUp() |
169 | { |
170 | #if defined(SDL_SUPPORT) |
171 | SDL_Quit(); |
172 | #endif |
173 | } |
174 | |
175 | static string backendName() |
176 | { |
177 | #if defined(SDL_SUPPORT) |
178 | return SDLVersion(); |
179 | #else |
180 | return "Custom backend" ; |
181 | #endif |
182 | } |
183 | |
184 | private: |
185 | // Following constructors and assignment operators not supported |
186 | MediaFactory() = delete; |
187 | MediaFactory(const MediaFactory&) = delete; |
188 | MediaFactory(MediaFactory&&) = delete; |
189 | MediaFactory& operator=(const MediaFactory&) = delete; |
190 | MediaFactory& operator=(MediaFactory&&) = delete; |
191 | }; |
192 | |
193 | #endif |
194 | |