Mercurial > hg > dmlib
changeset 762:49e96e581ac8
Branch merge.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 09 May 2013 06:21:42 +0300 |
parents | 7be7c7c5deaa (current diff) dd59a650a318 (diff) |
children | ad512e54c689 |
files | |
diffstat | 3 files changed, 119 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/dmengine.h Thu May 09 06:21:36 2013 +0300 +++ b/dmengine.h Thu May 09 06:21:42 2013 +0300 @@ -241,20 +241,26 @@ SDL_Surface *screen; SDL_Event event; - SDL_AudioSpec optAfmt; - int optAudioSetup; int optVidWidth, optVidHeight, optVidDepth, optVFlags, optVidAspect, optVidSetup; + BOOL optVidNative; int optResFlags; char *optDataPath, *optPackFilename; + SDL_AudioSpec optAfmt; + int optAudioSetup; + + DMMutex *audioStreamMutex; + Uint8 * audioStreamBuf; + size_t audioStreamLen; + #ifdef DM_USE_JSS - JSSMixer *dev; - JSSPlayer *plr; - int jss_format; + JSSMixer *jssDev; + JSSPlayer *jssPlr; + int jssFormat; #endif #ifdef DM_USE_TREMOR @@ -272,6 +278,7 @@ // Setup specifics DMVector setupMenuPos, setupMenuDim, setupText1Pos; BOOL setupMenuCenter, setupTextCondensed; + char setupTextFullscreen[64], setupTextWindowed[64], setupTextPrefix[64]; } DMEngineData;
--- a/dmimage.c Thu May 09 06:21:36 2013 +0300 +++ b/dmimage.c Thu May 09 06:21:42 2013 +0300 @@ -15,13 +15,33 @@ SDL_Surface *dmCreateRGBSurfaceFrom(void *data, const int width, const int height, const int depth, const int pitch, const int rmask, const int gmask, const int bmask, const int amask) { - SDL_Surface *tmp, *pixtmp, *result = NULL; - - tmp = SDL_CreateRGBSurfaceFrom(data, width, height, depth, pitch, bmask, gmask, rmask, amask); + // Create source surface from given data + SDL_Surface *tmp = SDL_CreateRGBSurfaceFrom(data, width, height, depth, pitch, bmask, gmask, rmask, amask); - pixtmp = SDL_CreateRGBSurface(SDL_SWSURFACE | SDL_SRCALPHA, 10, 10, 32, rmask, gmask, bmask, amask); + // Result surface component orders as masks +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + Uint32 + Xrmask = 0xff000000, + Xgmask = 0x00ff0000, + Xbmask = 0x0000ff00, + Xamask = 0x000000ff; +#else + Uint32 + Xrmask = 0x000000ff, + Xgmask = 0x0000ff00, + Xbmask = 0x00ff0000, + Xamask = 0xff000000; +#endif + + // Create result conversion surface + SDL_Surface + *result = NULL, + *pixtmp = SDL_CreateRGBSurface( + SDL_SWSURFACE | SDL_SRCALPHA, 16, 16, 32, Xrmask, Xgmask, Xbmask, Xamask); + if (tmp != NULL && pixtmp != NULL) { + // Convert surface result = SDL_ConvertSurface(tmp, pixtmp->format, SDL_SWSURFACE | SDL_SRCALPHA); SDL_FreeSurface(tmp); } @@ -97,22 +117,37 @@ return NULL; } -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif switch (comp) { case 4: +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0xff000000; + gmask = 0x00ff0000; + bmask = 0x0000ff00; + amask = 0x000000ff; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0xff000000; +#endif + result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8, + width * comp, rmask, gmask, bmask, amask); + break; + case 3: +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + rmask = 0x00ff0000; + gmask = 0x0000ff00; + bmask = 0x000000ff; + amask = 0x00000000; +#else + rmask = 0x000000ff; + gmask = 0x0000ff00; + bmask = 0x00ff0000; + amask = 0x00000000; +#endif result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8, width * comp, rmask, gmask, bmask, amask); break;
--- a/dmsimple.c Thu May 09 06:21:36 2013 +0300 +++ b/dmsimple.c Thu May 09 06:21:42 2013 +0300 @@ -65,6 +65,10 @@ { (void) userdata; + dmMutexLock(engine.audioStreamMutex); + engine.audioStreamBuf = stream; + engine.audioStreamLen = len; + if (engine.paused) { memset(stream, 0, len); @@ -74,8 +78,8 @@ { #ifdef DM_USE_JSS case DM_ASETUP_JSS: - if (engine.dev != NULL) - jvmRenderAudio(engine.dev, stream, len / jvmGetSampleSize(engine.dev)); + if (engine.jssDev != NULL) + jvmRenderAudio(engine.jssDev, stream, len / jvmGetSampleSize(engine.jssDev)); break; #endif #ifdef DM_USE_TREMOR @@ -93,6 +97,8 @@ default: break; } + + dmMutexUnlock(engine.audioStreamMutex); } @@ -269,14 +275,19 @@ if (buf[pos] == 0 || buf[pos] == '#') continue; - if (sscanf(buf+pos, "menuPos %f %f", + char *str = buf+pos; + if (sscanf(str, "menuPos %f %f", &engine.setupMenuPos.x, &engine.setupMenuPos.y) != 2 && - sscanf(buf+pos, "menuDim %f %f", + sscanf(str, "menuDim %f %f", &engine.setupMenuDim.x, &engine.setupMenuDim.y) != 2 && - sscanf(buf+pos, "text1Pos %f %f", + sscanf(str, "text1Pos %f %f", &engine.setupText1Pos.x, &engine.setupText1Pos.y) != 2 && - sscanf(buf+pos, "menuCenter %d", &engine.setupMenuCenter) != 1 && - sscanf(buf+pos, "textCondensed %d", &engine.setupTextCondensed) != 1) + sscanf(str, "menuCenter %d", &engine.setupMenuCenter) != 1 && + sscanf(str, "textCondensed %d", &engine.setupTextCondensed) != 1 && + sscanf(str, "textFullscreen %s", engine.setupTextFullscreen) != 1 && + sscanf(str, "textWindowed %s", engine.setupTextWindowed) != 1 && + sscanf(str, "textPrefix %s", engine.setupTextPrefix) != 1 + ) { dmError("Syntax error in configuration:\n%s\n", buf); res = DMERR_INVALID_DATA; @@ -341,16 +352,20 @@ goto out; // Get setup data + engine.setupMenuPos.x = 0.18750f; + engine.setupMenuPos.y = 0.41666f; + engine.setupMenuDim.x = 0.625f; + engine.setupMenuDim.y = 0.41666f; + + engine.setupText1Pos.x = 0.3f; + engine.setupText1Pos.y = 0.7f; + + strcpy(engine.setupTextFullscreen , "FULLSCREEN"); + strcpy(engine.setupTextWindowed , " WINDOWED "); + strcpy(engine.setupTextPrefix , "USE LEFT/RIGHT ARROW TO TOGGLE : "); + if (engineParseSetupConfig(engineSetupDataName) != DMERR_OK) - { - engine.setupMenuPos.x = 0.18750f; - engine.setupMenuPos.y = 0.41666f; - engine.setupMenuDim.x = 0.625f; - engine.setupMenuDim.y = 0.41666f; - - engine.setupText1Pos.x = 0.3f; - engine.setupText1Pos.y = 0.7f; - } + goto out; // Fetch and decompress setup image, try regular resources first if ((result = dmf_open(engine.resources, engineSetupImageName, &file)) == DMERR_OK || @@ -415,7 +430,7 @@ // Enter the main loop of the menu - char menuStr[64]; + char menuStr[256]; int menuOffset = 0, menuIndex = 0, menuEntryHeight = menuFont->height + 2, @@ -505,13 +520,13 @@ vsX(engine.setupMenuPos), vsY(engine.setupMenuPos) + (index * menuEntryHeight), vsX(engine.setupMenuDim), - menuEntryHeight + 2, + menuEntryHeight + 4, engine.screen, 200 + sin(t * 10.0) * 50); } snprintf(menuStr, sizeof(menuStr), - "%4d X %4d [%d:%d]", + "%4d X %-4d - %d:%d", mode->w, mode->h, mode->aspect / 1000, mode->aspect % 1000); @@ -524,18 +539,21 @@ engine.screen, menuFont, engine.setupTextCondensed, DMD_TRANSPARENT, vsX(engine.setupMenuPos) + posX, - vsY(engine.setupMenuPos) + 2 + (index * menuEntryHeight), + vsY(engine.setupMenuPos) + (index * menuEntryHeight), menuStr); } + snprintf(menuStr, sizeof(menuStr), + "%s%s", + engine.setupTextPrefix, + menuFullScreen ? engine.setupTextFullscreen : engine.setupTextWindowed); + dmDrawBMTextConst( engine.screen, menuFont, engine.setupTextCondensed, DMD_TRANSPARENT, vsX(engine.setupText1Pos), vsY(engine.setupText1Pos), - menuFullScreen ? - "FULLSCREEN" : - " WINDOWED "); + menuStr); // Flip screen if (SDL_MUSTLOCK(engine.screen) != 0) @@ -549,11 +567,16 @@ if (menuState == 1) { DMModeEntry *mode = &engineModeList[menuOffset + menuIndex]; + engine.optVidNative = + mode->w == engine.optVidWidth && + mode->h == engine.optVidHeight; + engine.optVidWidth = mode->w; engine.optVidHeight = mode->h; engine.optVidAspect = mode->aspect; if (menuFullScreen) engine.optVFlags |= SDL_FULLSCREEN; + } out: @@ -653,22 +676,22 @@ switch (engine.optAfmt.format) { - case AUDIO_S16SYS: engine.jss_format = JSS_AUDIO_S16; break; - case AUDIO_U16SYS: engine.jss_format = JSS_AUDIO_U16; break; - case AUDIO_S8: engine.jss_format = JSS_AUDIO_S8; break; - case AUDIO_U8: engine.jss_format = JSS_AUDIO_U8; break; + case AUDIO_S16SYS: engine.jssFormat = JSS_AUDIO_S16; break; + case AUDIO_U16SYS: engine.jssFormat = JSS_AUDIO_U16; break; + case AUDIO_S8: engine.jssFormat = JSS_AUDIO_S8; break; + case AUDIO_U8: engine.jssFormat = JSS_AUDIO_U8; break; } dmPrint(1, "Initializing miniJSS mixer with fmt=%d, chn=%d, freq=%d\n", - engine.jss_format, engine.optAfmt.channels, engine.optAfmt.freq); + engine.jssFormat, engine.optAfmt.channels, engine.optAfmt.freq); - if ((engine.dev = jvmInit(engine.jss_format, engine.optAfmt.channels, engine.optAfmt.freq, JMIX_AUTO)) == NULL) + if ((engine.jssDev = jvmInit(engine.jssFormat, engine.optAfmt.channels, engine.optAfmt.freq, JMIX_AUTO)) == NULL) { dmError("jvmInit() returned NULL, voi perkele.\n"); goto error_exit; } - if ((engine.plr = jmpInit(engine.dev)) == NULL) + if ((engine.jssPlr = jmpInit(engine.jssDev)) == NULL) { dmError("jmpInit() returned NULL\n"); goto error_exit; @@ -690,6 +713,7 @@ engine.optAfmt.format, engine.optAfmt.channels, engine.optAfmt.freq); engine.optAfmt.callback = engineAudioCallback; + engine.audioStreamMutex = dmCreateMutex(); if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0) { @@ -883,6 +907,9 @@ } #endif SDL_UnlockAudio(); + + if (engine.audioStreamMutex != NULL) + dmDestroyMutex(engine.audioStreamMutex); #ifdef DM_USE_TIMELINE dmFreeTimeline(engine.tl);