Just simplified code a bit
This commit is contained in:
raysan5 2019-11-24 14:08:27 +01:00
parent 1f66f0d9a2
commit d5aab98ac9

View File

@ -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);
return buffer;
#undef MAX_TEXT_BUFFERS
index += 1; // Move to next buffer for next function call
if (index >= MAX_TEXTFORMAT_BUFFERS) index = 0;
return currentBuffer;
}
// Get a piece of a text string