comparison editor/edmain.cpp @ 1738:b4992d9f72fe

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 09 Jun 2018 13:05:22 +0300
parents ef5a9c51569c
children 69a5af2eb1ea
comparison
equal deleted inserted replaced
1737:811b20de954c 1738:b4992d9f72fe
37 dmMemset(stream, 0, len); 37 dmMemset(stream, 0, len);
38 } 38 }
39 else 39 else
40 #ifdef DM_USE_JSS 40 #ifdef DM_USE_JSS
41 { 41 {
42 if (engine->dev != NULL) 42 if (engine->jssDev != NULL)
43 jvmRenderAudio(engine->dev, stream, 43 jvmRenderAudio(engine->jssDev, stream,
44 len / jvmGetSampleSize(engine->dev)); 44 len / jvmGetSampleSize(engine->jssDev));
45 } 45 }
46 #endif 46 #endif
47 #ifdef DM_USE_TREMOR 47 #ifdef DM_USE_TREMOR
48 if (engine->audioPos + len >= engine->audioRes->resSize) 48 if (engine->audioPos + len >= engine->audioRes->resSize)
49 { 49 {
64 64
65 if ((err = dmResourcesInit( 65 if ((err = dmResourcesInit(
66 &engine.resources, engine.optPackFilename, engine.optDataPath, 66 &engine.resources, engine.optPackFilename, engine.optDataPath,
67 engine.optResFlags, engineClassifier)) != DMERR_OK) 67 engine.optResFlags, engineClassifier)) != DMERR_OK)
68 { 68 {
69 dmError("Could not initialize resource manager: %d, %s.\n", 69 dmErrorMsg("Could not initialize resource manager: %d, %s.\n",
70 err, dmErrorStr(err)); 70 err, dmErrorStr(err));
71 } 71 }
72 return err; 72 return err;
73 } 73 }
74 74
110 110
111 // Initialize SDL components 111 // Initialize SDL components
112 dmPrint(1, "Initializing libSDL.\n"); 112 dmPrint(1, "Initializing libSDL.\n");
113 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) 113 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0)
114 { 114 {
115 dmError("Could not initialize SDL: %s\n", SDL_GetError()); 115 dmErrorMsg("Could not initialize SDL: %s\n", SDL_GetError());
116 goto error_exit; 116 goto error_exit;
117 } 117 }
118 initSDL = true; 118 initSDL = true;
119 119
120 // Initialize audio parts 120 // Initialize audio parts
131 jssInit(); 131 jssInit();
132 132
133 switch (engine.optAfmt.format) 133 switch (engine.optAfmt.format)
134 { 134 {
135 case AUDIO_S16SYS: 135 case AUDIO_S16SYS:
136 engine.jss_format = JSS_AUDIO_S16; 136 engine.jssFormat = JSS_AUDIO_S16;
137 break; 137 break;
138 case AUDIO_U16SYS: 138 case AUDIO_U16SYS:
139 engine.jss_format = JSS_AUDIO_U16; 139 engine.jssFormat = JSS_AUDIO_U16;
140 break; 140 break;
141 case AUDIO_S8: 141 case AUDIO_S8:
142 engine.jss_format = JSS_AUDIO_S8; 142 engine.jssFormat = JSS_AUDIO_S8;
143 break; 143 break;
144 case AUDIO_U8: 144 case AUDIO_U8:
145 engine.jss_format = JSS_AUDIO_U8; 145 engine.jssFormat = JSS_AUDIO_U8;
146 break; 146 break;
147 } 147 }
148 148
149 dmPrint(1, "Initializing miniJSS mixer with fmt=%d, chn=%d, freq=%d\n", 149 dmPrint(1, "Initializing miniJSS mixer with fmt=%d, chn=%d, freq=%d\n",
150 engine.jss_format, engine.optAfmt.channels, engine.optAfmt.freq); 150 engine.jssFormat, engine.optAfmt.channels, engine.optAfmt.freq);
151 151
152 if ((engine.dev = 152 if ((engine.jssDev =
153 jvmInit(engine.jss_format, engine.optAfmt.channels, 153 jvmInit(engine.jssFormat, engine.optAfmt.channels,
154 engine.optAfmt.freq, JMIX_AUTO)) == NULL) 154 engine.optAfmt.freq, JMIX_AUTO)) == NULL)
155 { 155 {
156 dmError("jvmInit() returned NULL, voi perkele.\n"); 156 dmErrorMsg("jvmInit() returned NULL, voi perkele.\n");
157 goto error_exit; 157 goto error_exit;
158 } 158 }
159 159
160 if ((engine.plr = jmpInit(engine.dev)) == NULL) 160 if ((engine.jssPlr = jmpInit(engine.jssDev)) == NULL)
161 { 161 {
162 dmError("jmpInit() returned NULL\n"); 162 dmErrorMsg("jmpInit() returned NULL\n");
163 goto error_exit; 163 goto error_exit;
164 } 164 }
165 #endif 165 #endif
166 166
167 // Initialize SDL audio 167 // Initialize SDL audio
171 171
172 engine.optAfmt.callback = engineAudioCallback; 172 engine.optAfmt.callback = engineAudioCallback;
173 173
174 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0) 174 if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
175 { 175 {
176 dmError("Couldn't open SDL audio: %s\n", SDL_GetError()); 176 dmErrorMsg("Couldn't open SDL audio: %s\n", SDL_GetError());
177 goto error_exit; 177 goto error_exit;
178 } 178 }
179 179
180 // Initialize SDL video 180 // Initialize SDL video
181 if (engine.demoInitPreVideo != NULL && 181 if (engine.demoInitPreVideo != NULL &&
182 (err = engine.demoInitPreVideo(&engine)) != DMERR_OK) 182 (err = engine.demoInitPreVideo(&engine)) != DMERR_OK)
183 { 183 {
184 dmError("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err)); 184 dmErrorMsg("demoInitPreVideo() failed, %d: %s\n", err, dmErrorStr(err));
185 goto error_exit; 185 goto error_exit;
186 } 186 }
187 187
188 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n", 188 dmPrint(1, "Initializing SDL video %d x %d x %dbpp, flags=0x%08x\n",
189 engine.optVidWidth, engine.optVidHeight, engine.optVidDepth, engine.optVFlags); 189 engine.optVidWidth, engine.optVidHeight, engine.optVidDepth, engine.optVFlags);
190 190
191 engine.screen = SDL_CreateRGBSurface(SDL_SWSURFACE, engine.optVidWidth, engine.optVidHeight, engine.optVidDepth, 0, 0, 0, 0); 191 engine.screen = SDL_CreateRGBSurface(SDL_SWSURFACE, engine.optVidWidth, engine.optVidHeight, engine.optVidDepth, 0, 0, 0, 0);
192 if (engine.screen == NULL) 192 if (engine.screen == NULL)
193 { 193 {
194 dmError("Could not allocate video backbuffer surface.\n"); 194 dmErrorMsg("Could not allocate video backbuffer surface.\n");
195 goto error_exit; 195 goto error_exit;
196 } 196 }
197 197
198 if (engine.demoInitPostVideo != NULL && 198 if (engine.demoInitPostVideo != NULL &&
199 (err = engine.demoInitPostVideo(&engine)) != DMERR_OK) 199 (err = engine.demoInitPostVideo(&engine)) != DMERR_OK)
200 { 200 {
201 dmError("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err)); 201 dmErrorMsg("demoInitPostVideo() failed, %d: %s\n", err, dmErrorStr(err));
202 goto error_exit; 202 goto error_exit;
203 } 203 }
204 204
205 205
206 error_exit: 206 error_exit:
227 SDL_FreeSurface(engine.screen); 227 SDL_FreeSurface(engine.screen);
228 228
229 SDL_LockAudio(); 229 SDL_LockAudio();
230 SDL_PauseAudio(1); 230 SDL_PauseAudio(1);
231 #ifdef DM_USE_JSS 231 #ifdef DM_USE_JSS
232 jmpClose(engine.plr); 232 jmpClose(engine.jssPlr);
233 jvmClose(engine.dev); 233 jvmClose(engine.jssDev);
234 jssClose(); 234 jssClose();
235 #endif 235 #endif
236 SDL_UnlockAudio(); 236 SDL_UnlockAudio();
237 237
238 shutdownEffectsAndResources(); 238 shutdownEffectsAndResources();
321 321
322 // Load resources 322 // Load resources
323 statusMsg("Loading resources, please wait..."); 323 statusMsg("Loading resources, please wait...");
324 if ((err = loadResources()) != DMERR_OK) 324 if ((err = loadResources()) != DMERR_OK)
325 { 325 {
326 dmError("Error loading resources, %d: %s.\n", err, dmErrorStr(err)); 326 dmErrorMsg("Error loading resources, %d: %s.\n", err, dmErrorStr(err));
327 return err; 327 return err;
328 } 328 }
329 329
330 330
331 // Final initializations 331 // Final initializations
332 statusMsg("Initializing custom demo data."); 332 statusMsg("Initializing custom demo data.");
333 if ((err = engine.demoInit(&engine)) != DMERR_OK) 333 if ((err = engine.demoInit(&engine)) != DMERR_OK)
334 { 334 {
335 dmError("Failure in demoInit(), %d: %s\n", 335 dmErrorMsg("Failure in demoInit(), %d: %s\n",
336 err, dmErrorStr(err)); 336 err, dmErrorStr(err));
337 return err; 337 return err;
338 } 338 }
339 339
340 // Initialize effects 340 // Initialize effects
341 statusMsg("Initializing effects ..."); 341 statusMsg("Initializing effects ...");
342 if ((err = engineInitializeEffects(&engine)) != DMERR_OK) 342 if ((err = engineInitializeEffects(&engine)) != DMERR_OK)
343 { 343 {
344 dmError("Effects initialization failed, %d: %s\n", 344 dmErrorMsg("Effects initialization failed, %d: %s\n",
345 err, dmErrorStr(err)); 345 err, dmErrorStr(err));
346 return err; 346 return err;
347 } 347 }
348 348
349 // Etc. 349 // Etc.