changeset 201:844f38cbff65

Optimize pattern drawing a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 07 Oct 2012 07:54:22 +0300
parents b842cc92c787
children 85614db5f577
files ppl.c
diffstat 1 files changed, 45 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ppl.c	Sun Oct 07 07:53:42 2012 +0300
+++ b/ppl.c	Sun Oct 07 07:54:22 2012 +0300
@@ -200,12 +200,9 @@
 
 void dmDrawBMTextVAQ(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap)
 {
-    char *tmp = dm_strdup_vprintf(fmt, ap);
-    if (tmp != NULL)
-    {
-        dmDrawBMTextConstQ(screen, font, mode, xc, yc, tmp);
-        dmFree(tmp);
-    }
+    char tmp[512];
+    vsnprintf(tmp, sizeof(tmp), fmt, ap);
+    dmDrawBMTextConstQ(screen, font, mode, xc, yc, tmp);
 }
 
 
@@ -342,6 +339,13 @@
 #define jmpNMODEffectTable (36)
 static const char jmpMODEffectTable[jmpNMODEffectTable] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
+static const char jmpHexTab[16] = "0123456789ABCDEF";
+
+static inline char dmHexVal(int v)
+{
+    return jmpHexTab[v & 15];
+}
+
 void dmPrintNote(SDL_Surface *screen, int xc, int yc, JSSNote *n)
 {
     char text[32];
@@ -350,10 +354,10 @@
     switch (n->note)
     {
         case jsetNotSet:
-            sprintf(ptr, "..._");
+            strcpy(ptr, "..._");
             break;
         case jsetNoteOff:
-            sprintf(ptr, "===_");
+            strcpy(ptr, "===_");
             break;
         default:
             sprintf(ptr, "%s%i_",
@@ -365,17 +369,29 @@
     ptr += 4;
 
     if (n->instrument != jsetNotSet)
-        sprintf(ptr, "%.2x_", n->instrument + 1);
+    {
+        int v = n->instrument + 1;
+        *ptr++ = dmHexVal(v >> 4);
+        *ptr++ = dmHexVal(v);
+    }
     else
-        sprintf(ptr, ".._");
-
-    ptr += 3;
+    {
+        *ptr++ = '.';
+        *ptr++ = '.';
+    }
+    *ptr++ = '_';
 
     if (n->volume == jsetNotSet)
-        sprintf(ptr, ".._");
+    {
+        *ptr++ = '.';
+        *ptr++ = '.';
+    }
     else
     if (n->volume >= 0x00 && n->volume <= 0x40)
-        sprintf(ptr, "%.2x_", n->volume);
+    {
+        *ptr++ = dmHexVal(n->volume >> 4);
+        *ptr++ = dmHexVal(n->volume);
+    }
     else
     {
         char c;
@@ -393,25 +409,28 @@
             case 0xe0: c = 'M'; break;
             default:   c = '?'; break;
         }
-        sprintf(ptr, "%c%x_", c, (n->volume & 0x0f));
+        *ptr++ = c;
+        *ptr++ = dmHexVal(n->volume);
     }
-    
-    ptr += 3;
+    *ptr++ = '_';
     
     if (n->effect >= 0 && n->effect < jmpNMODEffectTable)
-        *ptr = jmpMODEffectTable[n->effect];
+        *ptr++ = jmpMODEffectTable[n->effect];
     else
-    if (n->effect == jsetNotSet)
-        *ptr = '.';
-    else
-        *ptr = '?';
-
-    ptr += 1;
+        *ptr++ = (n->effect == jsetNotSet ? '.' : '?');
 
     if (n->param != jsetNotSet)
-        sprintf(ptr, "%.2x", n->param);
+    {
+        *ptr++ = dmHexVal(n->param >> 4);
+        *ptr++ = dmHexVal(n->param);
+    }
     else
-        sprintf(ptr, "..");
+    {
+        *ptr++ = '.';
+        *ptr++ = '.';
+    }
+
+    *ptr = 0;
 
     dmDrawBMTextConstQ(screen, font, DMD_TRANSPARENT, xc, yc, text);
 }