فهرست منبع

Review PR #1015

Just simplified code a bit
raysan5 5 سال پیش
والد
کامیت
d5aab98ac9
1فایلهای تغییر یافته به همراه12 افزوده شده و 10 حذف شده
  1. 12 10
      src/text.c

+ 12 - 10
src/text.c

@@ -1102,24 +1102,26 @@ unsigned int TextLength(const char *text)
 }
 
 // Formatting of text with variables to 'embed'
-// WARNING: the string returned will expire after this function is called MAX_TEXT_BUFFERS times
+// WARNING: String returned will expire after this function is called MAX_TEXTFORMAT_BUFFERS times
 const char *TextFormat(const char *text, ...)
 {
-    #define MAX_TEXT_BUFFERS 8
-    // We create an array of buffers so strings don't expire until MAX_TEXT_BUFFERS invocations
-    static char cache[MAX_TEXT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
+    #define MAX_TEXTFORMAT_BUFFERS 4
+
+    // We create an array of buffers so strings don't expire until MAX_TEXTFORMAT_BUFFERS invocations
+    static char buffers[MAX_TEXTFORMAT_BUFFERS][MAX_TEXT_BUFFER_LENGTH] = { 0 };
     static int  index = 0;
-    char       *buffer = cache[index];
-    index += 1;
-    index %= MAX_TEXT_BUFFERS;
+    
+    char *currentBuffer = buffers[index];
 
     va_list args;
     va_start(args, text);
-    vsprintf(buffer, text, args);
+    vsprintf(currentBuffer, text, args);
     va_end(args);
+    
+    index += 1;     // Move to next buffer for next function call
+    if (index >= MAX_TEXTFORMAT_BUFFERS) index = 0;
 
-    return buffer;
-    #undef MAX_TEXT_BUFFERS
+    return currentBuffer;
 }
 
 // Get a piece of a text string