changeset 2017:3a768f8d409d

Rename variable s/engine/eng/g to avoid aliasing with dmsimple::engine. This enables us to build with link-time optimizations -flto if so desired.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 06 Sep 2018 12:36:17 +0300
parents 7114ea4c3c42
children 1c45b2fb471d
files tools/ppl.c
diffstat 1 files changed, 129 insertions(+), 129 deletions(-) [+]
line wrap: on
line diff
--- a/tools/ppl.c	Fri Aug 31 17:31:54 2018 +0300
+++ b/tools/ppl.c	Thu Sep 06 12:36:17 2018 +0300
@@ -40,7 +40,7 @@
     JSSMixer *dev;
     JSSPlayer *plr;
     SDL_AudioSpec afmt;
-} engine;
+} eng;
 
 struct
 {
@@ -106,7 +106,7 @@
             break;
 
         case 2:
-            engine.optVFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+            eng.optVFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
             break;
 
         case 3:
@@ -119,8 +119,8 @@
                         dmErrorMsg("Invalid width or height: %d x %d\n", w, h);
                         return FALSE;
                     }
-                    engine.optScrWidth = w;
-                    engine.optScrHeight = h;
+                    eng.optScrWidth = w;
+                    eng.optScrHeight = h;
                 }
                 else
                 {
@@ -188,25 +188,25 @@
 
 static inline Uint32 dmCol(const float r, const float g, const float b)
 {
-    return dmMapRGB(engine.screen, 255.0f * r, 255.0f * g, 255.0f * b);
+    return dmMapRGB(eng.screen, 255.0f * r, 255.0f * g, 255.0f * b);
 }
 
 
 BOOL dmInitializeVideo()
 {
-    SDL_DestroyTexture(engine.texture);
-    SDL_FreeSurface(engine.screen);
+    SDL_DestroyTexture(eng.texture);
+    SDL_FreeSurface(eng.screen);
 
-    if ((engine.texture = SDL_CreateTexture(engine.renderer,
+    if ((eng.texture = SDL_CreateTexture(eng.renderer,
         SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING,
-        engine.optScrWidth, engine.optScrHeight)) == NULL)
+        eng.optScrWidth, eng.optScrHeight)) == NULL)
     {
         dmErrorMsg("Could not create SDL texture.\n");
         return FALSE;
     }
 
-    if ((engine.screen = SDL_CreateRGBSurfaceWithFormat(0,
-        engine.optScrWidth, engine.optScrHeight,
+    if ((eng.screen = SDL_CreateRGBSurfaceWithFormat(0,
+        eng.optScrWidth, eng.optScrHeight,
         32, SDL_PIXELFORMAT_RGBA32)) == NULL)
     {
         dmErrorMsg("Could not create SDL surface.\n");
@@ -249,8 +249,8 @@
 
     dmFillBox3D(screen, x0, y0, x1, y1,
         (chn->chMute ? col.muted : col.black),
-        nchannel == engine.actChannel ? col.red : col.box2,
-        nchannel == engine.actChannel ? col.red : col.box1);
+        nchannel == eng.actChannel ? col.red : col.box2,
+        nchannel == eng.actChannel ? col.red : col.box1);
 
     if (chn->chData == NULL || !chn->chPlaying)
         return;
@@ -452,13 +452,13 @@
     if (qwidth > pat->nchannels)
         qwidth = pat->nchannels;
 
-    if (engine.actChannel < qwidth / 2)
+    if (eng.actChannel < qwidth / 2)
         choffs = 0;
     else
-    if (engine.actChannel >= pat->nchannels - qwidth/2)
+    if (eng.actChannel >= pat->nchannels - qwidth/2)
         choffs = pat->nchannels - qwidth;
     else
-        choffs = engine.actChannel - qwidth/2;
+        choffs = eng.actChannel - qwidth/2;
 
     dmDrawBox3D(screen, x0 + lwidth, qy0, x1, qy1, col.box2, col.box1);
 
@@ -468,7 +468,7 @@
             bx1 = bx0 + cwidth;
 
         dmFillRect(screen, bx0+1, qy0+1, bx1-1, qy1-1,
-            (engine.actChannel == nchannel + choffs) ? col.activeChannel : col.inboxBg);
+            (eng.actChannel == nchannel + choffs) ? col.activeChannel : col.inboxBg);
     }
 
     yc = qy0 + 2 + (font->height + 1) * midrow;
@@ -481,7 +481,7 @@
 
         dmDrawVLine(screen, qy0 + 1, qy1 - 1, bx1, col.viewDiv);
 
-        if (jvmGetMute(engine.dev, nchannel + choffs))
+        if (jvmGetMute(eng.dev, nchannel + choffs))
         {
             dmDrawBMTextConstQ(screen, font, DMD_TRANSPARENT,
                 bx0 + (cwidth - font->width * 5) / 2, qy1 + 3, "MUTED");
@@ -528,8 +528,8 @@
 void dmMuteChannels(BOOL mute)
 {
     int i;
-    for (i = 0; i < engine.mod->nchannels; i++)
-        jvmMute(engine.dev, i, mute);
+    for (i = 0; i < eng.mod->nchannels; i++)
+        jvmMute(eng.dev, i, mute);
 }
 
 
@@ -540,11 +540,11 @@
     int result = -1;
     BOOL muteState = FALSE;
 
-    dmMemset(&engine, 0, sizeof(engine));
+    dmMemset(&eng, 0, sizeof(eng));
 
-    engine.optScrWidth = 640;
-    engine.optScrHeight = 480;
-    engine.optScrDepth = 32;
+    eng.optScrWidth = 640;
+    eng.optScrHeight = 480;
+    eng.optScrDepth = 32;
 
     dmInitProg("CBP", "Cyrbe Basci Player", "0.2", NULL, NULL);
 
@@ -573,22 +573,22 @@
     // Read module file
     dmMsg(1, "Reading file: %s\n", optFilename);
 #ifdef JSS_SUP_XM
-    result = jssLoadXM(file, &engine.mod, TRUE);
+    result = jssLoadXM(file, &eng.mod, TRUE);
 #endif
 #ifdef JSS_SUP_JSSMOD
     dmfreset(file);
     if (result != DMERR_OK)
     {
         dmMsg(1, "* Trying JSSMOD ...\n");
-        result = jssLoadJSSMOD(file, &engine.mod, TRUE);
+        result = jssLoadJSSMOD(file, &eng.mod, TRUE);
         dmfreset(file);
         if (result == DMERR_OK)
-            result = jssLoadJSSMOD(file, &engine.mod, FALSE);
+            result = jssLoadJSSMOD(file, &eng.mod, FALSE);
     }
     else
     {
         dmMsg(2, "* Trying XM...\n");
-        result = jssLoadXM(file, &engine.mod, FALSE);
+        result = jssLoadXM(file, &eng.mod, FALSE);
     }
 #endif
     dmf_close(file);
@@ -601,7 +601,7 @@
     }
 
     // Try to convert it
-    if ((result = jssConvertModuleForPlaying(engine.mod)) != DMERR_OK)
+    if ((result = jssConvertModuleForPlaying(eng.mod)) != DMERR_OK)
     {
         dmErrorMsg("Could not convert module for playing, %d: %s\n",
             result, dmErrorStr(result));
@@ -646,8 +646,8 @@
     dmMsg(2, "Initializing miniJSS mixer with: %d, %d, %d\n",
         optOutFormat, optOutChannels, optOutFreq);
 
-    engine.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO);
-    if (engine.dev == NULL)
+    eng.dev = jvmInit(optOutFormat, optOutChannels, optOutFreq, JMIX_AUTO);
+    if (eng.dev == NULL)
     {
         dmErrorMsg("jvmInit() returned NULL\n");
         goto error_exit;
@@ -655,24 +655,24 @@
 
     switch (optOutFormat)
     {
-        case JSS_AUDIO_S16: engine.afmt.format = AUDIO_S16SYS; break;
-        case JSS_AUDIO_U16: engine.afmt.format = AUDIO_U16SYS; break;
-        case JSS_AUDIO_S8:  engine.afmt.format = AUDIO_S8; break;
-        case JSS_AUDIO_U8:  engine.afmt.format = AUDIO_U8; break;
+        case JSS_AUDIO_S16: eng.afmt.format = AUDIO_S16SYS; break;
+        case JSS_AUDIO_U16: eng.afmt.format = AUDIO_U16SYS; break;
+        case JSS_AUDIO_S8:  eng.afmt.format = AUDIO_S8; break;
+        case JSS_AUDIO_U8:  eng.afmt.format = AUDIO_U8; break;
         default:
             dmErrorMsg("Unsupported audio format %d (could not set matching SDL format)\n",
                 optOutFormat);
             goto error_exit;
     }
 
-    engine.afmt.freq     = optOutFreq;
-    engine.afmt.channels = optOutChannels;
-    engine.afmt.samples  = optOutFreq / 16;
-    engine.afmt.callback = audioCallback;
-    engine.afmt.userdata = (void *) engine.dev;
+    eng.afmt.freq     = optOutFreq;
+    eng.afmt.channels = optOutChannels;
+    eng.afmt.samples  = optOutFreq / 16;
+    eng.afmt.callback = audioCallback;
+    eng.afmt.userdata = (void *) eng.dev;
 
     // Open the audio device
-    if (SDL_OpenAudio(&engine.afmt, NULL) < 0)
+    if (SDL_OpenAudio(&eng.afmt, NULL) < 0)
     {
         dmErrorMsg("Couldn't open SDL audio: %s\n",
             SDL_GetError());
@@ -681,30 +681,30 @@
     audioInit = TRUE;
 
     // Initialize player
-    if ((engine.plr = jmpInit(engine.dev)) == NULL)
+    if ((eng.plr = jmpInit(eng.dev)) == NULL)
     {
         dmErrorMsg("jmpInit() returned NULL\n");
         goto error_exit;
     }
 
-    jvmSetCallback(engine.dev, jmpExec, engine.plr);
-    jmpSetModule(engine.plr, engine.mod);
-    jmpPlayOrder(engine.plr, optStartOrder);
-    jvmSetGlobalVol(engine.dev, 200);
+    jvmSetCallback(eng.dev, jmpExec, eng.plr);
+    jmpSetModule(eng.plr, eng.mod);
+    jmpPlayOrder(eng.plr, optStartOrder);
+    jvmSetGlobalVol(eng.dev, 200);
 
-    if (optMuteOChannels >= 0 && optMuteOChannels < engine.mod->nchannels)
+    if (optMuteOChannels >= 0 && optMuteOChannels < eng.mod->nchannels)
     {
         dmMuteChannels(TRUE);
-        jvmMute(engine.dev, optMuteOChannels, FALSE);
-        engine.actChannel = optMuteOChannels;
+        jvmMute(eng.dev, optMuteOChannels, FALSE);
+        eng.actChannel = optMuteOChannels;
         muteState = TRUE;
     }
 
     // Open window
-    if ((engine.window = SDL_CreateWindow(dmProgName,
+    if ((eng.window = SDL_CreateWindow(dmProgName,
         SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
-        engine.optScrWidth, engine.optScrHeight,
-        engine.optVFlags | SDL_WINDOW_RESIZABLE
+        eng.optScrWidth, eng.optScrHeight,
+        eng.optVFlags | SDL_WINDOW_RESIZABLE
         //| SDL_WINDOW_HIDDEN
         )) == NULL)
     {
@@ -712,9 +712,9 @@
         goto error_exit;
     }
 
-    SDL_SetWindowTitle(engine.window, dmProgDesc);
+    SDL_SetWindowTitle(eng.window, dmProgDesc);
 
-    if ((engine.renderer = SDL_CreateRenderer(engine.window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
+    if ((eng.renderer = SDL_CreateRenderer(eng.window, -1, SDL_RENDERER_PRESENTVSYNC)) == NULL)
     {
         dmErrorMsg("Can't create an SDL renderer: %s\n", SDL_GetError());
         goto error_exit;
@@ -732,83 +732,83 @@
     SDL_UnlockAudio();
 
     int currTick, prevTick = 0, prevRow = -1;
-    while (!engine.exitFlag)
+    while (!eng.exitFlag)
     {
         currTick = SDL_GetTicks();
         BOOL needUpdate = (currTick - prevTick > 500),
              needRender = FALSE;
 
-        while (SDL_PollEvent(&engine.event))
-        switch (engine.event.type)
+        while (SDL_PollEvent(&eng.event))
+        switch (eng.event.type)
         {
             case SDL_KEYDOWN:
-                switch (engine.event.key.keysym.sym)
+                switch (eng.event.key.keysym.sym)
                 {
                     case SDLK_ESCAPE:
                     case SDLK_q:
-                        engine.exitFlag = TRUE;
+                        eng.exitFlag = TRUE;
                         break;
 
                     case SDLK_SPACE:
-                        engine.pauseFlag = !engine.pauseFlag;
-                        SDL_PauseAudio(engine.pauseFlag);
+                        eng.pauseFlag = !eng.pauseFlag;
+                        SDL_PauseAudio(eng.pauseFlag);
                         break;
 
                     case SDLK_LEFT:
-                        if (engine.actChannel > 0)
+                        if (eng.actChannel > 0)
                         {
-                            engine.actChannel--;
+                            eng.actChannel--;
                             needUpdate = TRUE;
                         }
                         break;
 
                     case SDLK_RIGHT:
-                        if (engine.actChannel < engine.mod->nchannels - 1)
+                        if (eng.actChannel < eng.mod->nchannels - 1)
                         {
-                            engine.actChannel++;
+                            eng.actChannel++;
                             needUpdate = TRUE;
                         }
                         break;
 
                     case SDLK_m:
-                        if (engine.event.key.keysym.mod & KMOD_SHIFT)
+                        if (eng.event.key.keysym.mod & KMOD_SHIFT)
                         {
                             muteState = !muteState;
                             dmMuteChannels(muteState);
                         }
                         else
-                        if (engine.event.key.keysym.mod & KMOD_CTRL)
+                        if (eng.event.key.keysym.mod & KMOD_CTRL)
                         {
                             dmMuteChannels(FALSE);
                         }
                         else
                         {
-                            jvmMute(engine.dev, engine.actChannel, !jvmGetMute(engine.dev, engine.actChannel));
+                            jvmMute(eng.dev, eng.actChannel, !jvmGetMute(eng.dev, eng.actChannel));
                         }
                         needUpdate = TRUE;
                         break;
 
                     case SDLK_PAGEUP:
-                        JSS_LOCK(engine.dev);
-                        JSS_LOCK(engine.plr);
-                        jmpChangeOrder(engine.plr, dmClamp(engine.plr->order - 1, 0, engine.mod->norders));
-                        JSS_UNLOCK(engine.plr);
-                        JSS_UNLOCK(engine.dev);
+                        JSS_LOCK(eng.dev);
+                        JSS_LOCK(eng.plr);
+                        jmpChangeOrder(eng.plr, dmClamp(eng.plr->order - 1, 0, eng.mod->norders));
+                        JSS_UNLOCK(eng.plr);
+                        JSS_UNLOCK(eng.dev);
                         needUpdate = TRUE;
                         break;
 
                     case SDLK_PAGEDOWN:
-                        JSS_LOCK(engine.dev);
-                        JSS_LOCK(engine.plr);
-                        jmpChangeOrder(engine.plr, dmClamp(engine.plr->order + 1, 0, engine.mod->norders));
-                        JSS_UNLOCK(engine.plr);
-                        JSS_UNLOCK(engine.dev);
+                        JSS_LOCK(eng.dev);
+                        JSS_LOCK(eng.plr);
+                        jmpChangeOrder(eng.plr, dmClamp(eng.plr->order + 1, 0, eng.mod->norders));
+                        JSS_UNLOCK(eng.plr);
+                        JSS_UNLOCK(eng.dev);
                         needUpdate = TRUE;
                         break;
 
                     case SDLK_f:
-                        engine.optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
-                        if (SDL_SetWindowFullscreen(engine.window, engine.optVFlags) != 0)
+                        eng.optVFlags ^= SDL_WINDOW_FULLSCREEN_DESKTOP;
+                        if (SDL_SetWindowFullscreen(eng.window, eng.optVFlags) != 0)
                             goto error_exit;
                         needUpdate = TRUE;
                         break;
@@ -820,15 +820,15 @@
                 break;
 
             case SDL_WINDOWEVENT:
-                switch (engine.event.window.event)
+                switch (eng.event.window.event)
                 {
                     case SDL_WINDOWEVENT_EXPOSED:
                         needUpdate = TRUE;
                         break;
 
                     case SDL_WINDOWEVENT_RESIZED:
-                        engine.optScrWidth  = engine.event.window.data1;
-                        engine.optScrHeight = engine.event.window.data2;
+                        eng.optScrWidth  = eng.event.window.data1;
+                        eng.optScrHeight = eng.event.window.data2;
                         if (!dmInitializeVideo())
                             goto error_exit;
 
@@ -838,18 +838,18 @@
                 break;
 
             case SDL_QUIT:
-                engine.exitFlag = TRUE;
+                eng.exitFlag = TRUE;
                 break;
         }
 
 
 #if 1
-        JSS_LOCK(engine.plr);
-        JSSPattern *currPattern = engine.plr->pattern;
-        int currRow = engine.plr->row;
-        if (!engine.plr->isPlaying)
-            engine.exitFlag = TRUE;
-        JSS_UNLOCK(engine.plr);
+        JSS_LOCK(eng.plr);
+        JSSPattern *currPattern = eng.plr->pattern;
+        int currRow = eng.plr->row;
+        if (!eng.plr->isPlaying)
+            eng.exitFlag = TRUE;
+        JSS_UNLOCK(eng.plr);
 
         if (currRow != prevRow || needUpdate)
         {
@@ -860,38 +860,38 @@
         // Draw frame
         if (needUpdate)
         {
-            dmClearSurface(engine.screen, col.boxBg);
+            dmClearSurface(eng.screen, col.boxBg);
 
-            dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5,
+            dmDrawBMTextQ(eng.screen, font, DMD_TRANSPARENT, 5, 5,
                 "%s v%s by ccr/TNSP - (c) Copyright 2012-2018 TNSP",
                 dmProgDesc, dmProgVersion);
 
-            dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2),
+            dmDrawBMTextQ(eng.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2),
                 "Song: '%s'",
-                engine.mod->moduleName);
+                eng.mod->moduleName);
 
-            dmDisplayPattern(engine.screen, 5, 5 + (font->height + 2) * 3 + 4,
-                engine.screen->w - 6,
-                engine.screen->h * 0.8,
+            dmDisplayPattern(eng.screen, 5, 5 + (font->height + 2) * 3 + 4,
+                eng.screen->w - 6,
+                eng.screen->h * 0.8,
                 currPattern, currRow);
 
-            JSS_LOCK(engine.plr);
-            dmDrawBMTextQ(engine.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2) * 2,
+            JSS_LOCK(eng.plr);
+            dmDrawBMTextQ(eng.screen, font, DMD_TRANSPARENT, 5, 5 + (font->height + 2) * 2,
             "Tempo: %3d | Speed: %3d | Row: %3d/%-3d | Order: %3d/%-3d | Pattern: %3d/%-3d",
-            engine.plr->tempo, engine.plr->speed,
-            engine.plr->row, (engine.plr->pattern != NULL) ? engine.plr->pattern->nrows : 0,
-            engine.plr->order + 1, engine.mod->norders,
-            engine.plr->npattern, engine.mod->npatterns);
-            JSS_UNLOCK(engine.plr);
+            eng.plr->tempo, eng.plr->speed,
+            eng.plr->row, (eng.plr->pattern != NULL) ? eng.plr->pattern->nrows : 0,
+            eng.plr->order + 1, eng.mod->norders,
+            eng.plr->npattern, eng.mod->npatterns);
+            JSS_UNLOCK(eng.plr);
             needRender = TRUE;
         }
 
-        if (needUpdate || currTick - prevTick >= (engine.pauseFlag ? 100 : 20))
+        if (needUpdate || currTick - prevTick >= (eng.pauseFlag ? 100 : 20))
         {
-            JSS_LOCK(engine.dev);
-            dmDisplayChannels(engine.screen, 5, engine.screen->h * 0.8 + 5,
-                engine.screen->w - 5, engine.screen->h - 5, engine.dev);
-            JSS_UNLOCK(engine.dev);
+            JSS_LOCK(eng.dev);
+            dmDisplayChannels(eng.screen, 5, eng.screen->h * 0.8 + 5,
+                eng.screen->w - 5, eng.screen->h - 5, eng.dev);
+            JSS_UNLOCK(eng.dev);
             needRender = TRUE;
         }
 
@@ -903,35 +903,35 @@
         if (needRender)
         {
             SDL_Surface dst;
-            SDL_LockTexture(engine.texture, NULL, &dst.pixels, &dst.pitch);
+            SDL_LockTexture(eng.texture, NULL, &dst.pixels, &dst.pitch);
 
-            if (dst.pitch != engine.screen->pitch)
-                engine.exitFlag = TRUE;
+            if (dst.pitch != eng.screen->pitch)
+                eng.exitFlag = TRUE;
             else
-                memcpy(dst.pixels, engine.screen->pixels, engine.screen->h * dst.pitch);
+                memcpy(dst.pixels, eng.screen->pixels, eng.screen->h * dst.pitch);
 
-            SDL_UnlockTexture(engine.texture);
+            SDL_UnlockTexture(eng.texture);
 
-            //SDL_RenderClear(engine.renderer);
-            SDL_RenderCopy(engine.renderer, engine.texture, NULL, NULL);
-            SDL_RenderPresent(engine.renderer);
+            //SDL_RenderClear(eng.renderer);
+            SDL_RenderCopy(eng.renderer, eng.texture, NULL, NULL);
+            SDL_RenderPresent(eng.renderer);
         }
 
-        SDL_Delay(engine.pauseFlag ? 100 : 30);
+        SDL_Delay(eng.pauseFlag ? 100 : 30);
     }
 
 error_exit:
-    if (engine.texture != NULL)
-        SDL_DestroyTexture(engine.texture);
+    if (eng.texture != NULL)
+        SDL_DestroyTexture(eng.texture);
 
-    if (engine.renderer != NULL)
-        SDL_DestroyRenderer(engine.renderer);
+    if (eng.renderer != NULL)
+        SDL_DestroyRenderer(eng.renderer);
 
-    if (engine.window != NULL)
-        SDL_DestroyWindow(engine.window);
+    if (eng.window != NULL)
+        SDL_DestroyWindow(eng.window);
 
-    if (engine.screen != NULL)
-        SDL_FreeSurface(engine.screen);
+    if (eng.screen != NULL)
+        SDL_FreeSurface(eng.screen);
 
     dmMsg(0, "Audio shutdown.\n");
     if (audioInit)
@@ -942,9 +942,9 @@
         SDL_CloseAudio();
     }
 
-    jmpClose(engine.plr);
-    jvmClose(engine.dev);
-    jssFreeModule(engine.mod);
+    jmpClose(eng.plr);
+    jvmClose(eng.dev);
+    jssFreeModule(eng.mod);
 
     dmFreeBitmapFont(font);