1
0
Fork 0
mirror of https://github.com/halpz/re3.git synced 2024-12-27 18:25:28 +00:00
re3/src/render/Console.cpp

97 lines
2.2 KiB
C++
Raw Normal View History

2020-03-22 14:26:18 +00:00
#include "common.h"
2020-04-15 12:05:24 +00:00
#include <stdarg.h>
2020-04-17 13:31:11 +00:00
2020-03-22 14:23:40 +00:00
#include "Console.h"
#include "Font.h"
#include "Timer.h"
2020-03-22 14:26:18 +00:00
#define CONSOLE_X_POS (30.0f)
#define CONSOLE_Y_POS (10.0f)
#define CONSOLE_LINE_HEIGHT (12.0f)
2020-04-17 04:01:54 +00:00
CConsole TheConsole;
2020-03-22 14:26:18 +00:00
void
CConsole::AddLine(char *s, uint8 r, uint8 g, uint8 b)
{
char tempstr[MAX_STR_LEN+1];
while (strlen(s) > MAX_STR_LEN) {
2020-05-11 02:55:57 +00:00
strncpy(tempstr, s, MAX_STR_LEN);
2020-03-22 14:26:18 +00:00
tempstr[MAX_STR_LEN-1] = '\0';
s += MAX_STR_LEN - 1;
AddOneLine(tempstr, r, g, b);
}
AddOneLine(s, r, g, b);
}
void
CConsole::AddOneLine(char *s, uint8 r, uint8 g, uint8 b)
{
int32 StrIndex = (m_nLineCount + m_nCurrentLine) % MAX_LINES;
for (int32 i = 0; i < MAX_STR_LEN; i++) {
Buffers[StrIndex][i] = s[i];
if (s[i] == '\0') break;
}
uint8 _strNum1 = m_nLineCount;
if (_strNum1 < MAX_LINES)
_strNum1++;
m_aTimer[StrIndex] = CTimer::GetTimeInMilliseconds();
Buffers[StrIndex][MAX_STR_LEN-1] = '\0';
m_aRed[StrIndex] = r;
m_aGreen[StrIndex] = g;
m_aBlue[StrIndex] = b;
2020-03-22 14:23:40 +00:00
2020-03-22 14:26:18 +00:00
if (_strNum1 >= MAX_LINES)
m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES;
else
m_nLineCount = _strNum1;
2020-03-22 14:23:40 +00:00
2020-03-22 14:26:18 +00:00
}
void
CConsole::Display()
2020-03-22 14:23:40 +00:00
{
CFont::SetPropOn();
CFont::SetBackgroundOff();
2020-03-22 14:26:18 +00:00
CFont::SetScale(0.6f, 0.6f);
2020-03-22 14:23:40 +00:00
CFont::SetCentreOff();
CFont::SetRightJustifyOff();
2020-03-22 14:26:18 +00:00
CFont::SetJustifyOn();
CFont::SetRightJustifyWrap(0.0f);
2020-03-22 14:23:40 +00:00
CFont::SetBackGroundOnlyTextOff();
2020-06-07 01:10:06 +00:00
CFont::SetFontStyle(FONT_STANDARD);
2020-03-22 14:26:18 +00:00
#ifndef FIX_BUGS
CFont::SetPropOff(); // not sure why this is here anyway
#endif
2020-03-22 14:23:40 +00:00
CFont::SetWrapx(RsGlobal.width);
2020-03-22 14:26:18 +00:00
while (m_nLineCount != 0 && CTimer::GetTimeInMilliseconds() - m_aTimer[m_nCurrentLine] > 20000) {
m_nLineCount--;
m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES;
2020-03-22 14:23:40 +00:00
}
2020-03-22 14:26:18 +00:00
for (int16 i = 0; i < m_nLineCount; i++) {
int16 line = (i + m_nCurrentLine) % MAX_LINES;
2020-03-22 14:23:40 +00:00
CFont::SetColor(CRGBA(0, 0, 0, 200));
2020-03-22 14:26:18 +00:00
CFont::PrintString(CONSOLE_X_POS + 1.0f, CONSOLE_Y_POS + 1.0f + i * CONSOLE_LINE_HEIGHT, Buffers[line]);
CFont::SetColor(CRGBA(m_aRed[line], m_aGreen[line], m_aBlue[line], 200));
CFont::PrintString(CONSOLE_X_POS, CONSOLE_Y_POS + i * CONSOLE_LINE_HEIGHT, Buffers[line]);
2020-03-22 14:23:40 +00:00
}
2020-03-22 14:26:18 +00:00
}
void
cprintf(char* format, ...)
{
char s[256];
va_list vl1, vl2;
va_start(vl1, format);
va_copy(vl2, vl1);
vsprintf(s, format, vl1);
TheConsole.AddLine(s, 255, 255, 128);
2020-03-22 16:19:07 +00:00
}