diff options
author | Sergeanur <s.anureev@yandex.ua> | 2020-03-22 12:26:35 +0100 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2020-03-22 15:19:10 +0100 |
commit | 5e37c3e805088f58392349c3c801d481d469dac2 (patch) | |
tree | 445046c822ef0c3106f4de78382b1b261b0205ce /src/render | |
parent | Merge pull request #350 from Nick007J/master (diff) | |
download | re3-5e37c3e805088f58392349c3c801d481d469dac2.tar re3-5e37c3e805088f58392349c3c801d481d469dac2.tar.gz re3-5e37c3e805088f58392349c3c801d481d469dac2.tar.bz2 re3-5e37c3e805088f58392349c3c801d481d469dac2.tar.lz re3-5e37c3e805088f58392349c3c801d481d469dac2.tar.xz re3-5e37c3e805088f58392349c3c801d481d469dac2.tar.zst re3-5e37c3e805088f58392349c3c801d481d469dac2.zip |
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/Console.cpp | 95 | ||||
-rw-r--r-- | src/render/Console.h | 24 |
2 files changed, 119 insertions, 0 deletions
diff --git a/src/render/Console.cpp b/src/render/Console.cpp new file mode 100644 index 00000000..898f4d44 --- /dev/null +++ b/src/render/Console.cpp @@ -0,0 +1,95 @@ +#include "common.h"
+#include "patcher.h"
+#include "Console.h"
+#include "Font.h"
+#include "Timer.h"
+
+#define CONSOLE_X_POS (30.0f)
+#define CONSOLE_Y_POS (10.0f)
+#define CONSOLE_LINE_HEIGHT (12.0f)
+
+CConsole &TheConsole = *(CConsole*)0x8F6498;
+
+void
+CConsole::AddLine(char *s, uint8 r, uint8 g, uint8 b)
+{
+ char tempstr[MAX_STR_LEN+1];
+
+ while (strlen(s) > MAX_STR_LEN) {
+ strncpy_s(tempstr, s, MAX_STR_LEN);
+ 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;
+
+ if (_strNum1 >= MAX_LINES)
+ m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES;
+ else
+ m_nLineCount = _strNum1;
+
+}
+
+void
+CConsole::Display()
+{
+ CFont::SetPropOn();
+ CFont::SetBackgroundOff();
+ CFont::SetScale(0.6f, 0.6f);
+ CFont::SetCentreOff();
+ CFont::SetRightJustifyOff();
+ CFont::SetJustifyOn();
+ CFont::SetRightJustifyWrap(0.0f);
+ CFont::SetBackGroundOnlyTextOff();
+ CFont::SetFontStyle(FONT_BANK);
+#ifndef FIX_BUGS
+ CFont::SetPropOff(); // not sure why this is here anyway
+#endif
+ CFont::SetWrapx(RsGlobal.width);
+
+ while (m_nLineCount != 0 && CTimer::GetTimeInMilliseconds() - m_aTimer[m_nCurrentLine] > 20000) {
+ m_nLineCount--;
+ m_nCurrentLine = (m_nCurrentLine + 1) % MAX_LINES;
+ }
+
+ for (int16 i = 0; i < m_nLineCount; i++) {
+ int16 line = (i + m_nCurrentLine) % MAX_LINES;
+ CFont::SetColor(CRGBA(0, 0, 0, 200));
+ 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]);
+ }
+}
+
+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);
+}
\ No newline at end of file diff --git a/src/render/Console.h b/src/render/Console.h new file mode 100644 index 00000000..eb84c1a5 --- /dev/null +++ b/src/render/Console.h @@ -0,0 +1,24 @@ +#pragma once
+
+class CConsole
+{
+ enum
+ {
+ MAX_LINES = 8, // BUG? only shows 7
+ MAX_STR_LEN = 40,
+ };
+
+ uint8 m_nLineCount;
+ uint8 m_nCurrentLine;
+ wchar Buffers[MAX_LINES][MAX_STR_LEN];
+ uint32 m_aTimer[MAX_LINES];
+ uint8 m_aRed[MAX_LINES];
+ uint8 m_aGreen[MAX_LINES];
+ uint8 m_aBlue[MAX_LINES];
+public:
+ void AddLine(char *s, uint8 r, uint8 g, uint8 b);
+ void AddOneLine(char *s, uint8 r, uint8 g, uint8 b);
+ void Display();
+};
+
+extern CConsole &TheConsole;
\ No newline at end of file |