CVarConsole

This commit is contained in:
Sergeanur
2021-01-02 11:38:54 +02:00
parent e7c46ac658
commit 42e4a068bb
20 changed files with 1009 additions and 10 deletions

View File

@ -24,6 +24,7 @@
#include "Stats.h"
#include "main.h"
#include "General.h"
#include "VarConsole.h"
// --MIAMI: file done
@ -1760,6 +1761,9 @@ void CHud::Initialise()
m_LastWanted = 0;
m_LastWeapon = 0;
#ifndef MASTER
VarConsole.Add("Draw HUD", &m_Wants_To_Draw_Hud, false);
#endif
CTxdStore::PopCurrentTxd();
}

View File

@ -9,6 +9,7 @@
#include "Draw.h"
#include "Timer.h"
#include "RwHelper.h"
#include "VarConsole.h"
int32 COcclusion::NumOccludersOnMap;
int16 COcclusion::FarAwayList;
@ -31,20 +32,20 @@ CVector gOccluderCoorsOnScreen[8];
CVector gOccluderCoors[8];
#ifndef MASTER
bool bDisplayOccDebugStuff;
bool bDispayOccDebugStuff; // disPAY, yeah
#endif
void
COcclusion::Init(void)
{
NumOccludersOnMap = 0;
#ifndef MASTER
VarConsole.Add("Occlusion debug", &bDispayOccDebugStuff, true);
#endif
FarAwayList = -1;
NearbyList = -1;
ListWalkThroughFA = -1;
PreviousListWalkThroughFA = -1;
#ifndef MASTER
bDisplayOccDebugStuff = false;
#endif
}
void
@ -458,7 +459,7 @@ bool COcclusion::IsPositionOccluded(CVector pos, float side) {
RwIm2DVertex vertexbufferT[2];
void COcclusion::Render() {
if (!bDisplayOccDebugStuff || !(CTimer::GetTimeInMilliseconds() & 0x200))
if (!bDispayOccDebugStuff || !(CTimer::GetTimeInMilliseconds() & 0x200))
return;
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, (void*)TRUE);

View File

@ -58,5 +58,5 @@ bool CalcScreenCoors(CVector const &in, CVector *out, float *outw, float *outh);
bool CalcScreenCoors(CVector const &in, CVector *out);
#ifndef MASTER
extern bool bDisplayOccDebugStuff;
extern bool bDispayOccDebugStuff;
#endif

View File

@ -25,6 +25,7 @@
#include "CutsceneObject.h"
#include "CutsceneShadow.h"
#include "Clock.h"
#include "VarConsole.h"
#ifdef DEBUGMENU
SETTWEAKPATH("Shadows");
@ -57,6 +58,9 @@ CStaticShadow CShadows::aStaticShadows [MAX_STATICSHADOWS];
CPolyBunch *CShadows::pEmptyBunchList;
CPermanentShadow CShadows::aPermanentShadows[MAX_PERMAMENTSHADOWS];
#ifndef MASTER
bool gbCountPolysInShadow;
#endif
void
CShadows::Init(void)
@ -154,6 +158,10 @@ CShadows::Init(void)
{
aPermanentShadows[i].m_nType = SHADOWTYPE_NONE;
}
#ifndef MASTER
VarConsole.Add("Count polys in shadow", &gbCountPolysInShadow, true);
#endif
}
void

786
src/render/VarConsole.cpp Normal file
View File

@ -0,0 +1,786 @@
#include "common.h"
#include "VarConsole.h"
#include "Font.h"
#include "Pad.h"
#define VAR_CONSOLE_PAD 1
CVarConsole VarConsole;
void
CVarConsole::Initialise()
{
m_nCountEntries = 0;
m_nCurPage = 1;
m_bIsOpen = false;
m_nCurEntry = 0;
m_nFirstEntryOnPage = 0;
}
void
CVarConsole::Add(char *text, int8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pInt8Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_INT8;
m_aEntries[i].I8_step = step;
m_aEntries[i].I8_min = min;
m_aEntries[i].I8_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, int16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pInt16Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_INT16;
m_aEntries[i].I16_step = step;
m_aEntries[i].I16_min = min;
m_aEntries[i].I16_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, int32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pInt32Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_INT32;
m_aEntries[i].I32_step = step;
m_aEntries[i].I32_min = min;
m_aEntries[i].I32_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, int64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pInt64Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_INT64;
m_aEntries[i].I64_step = step;
m_aEntries[i].I64_min = min;
m_aEntries[i].I64_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, uint8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pUint8Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_UINT8;
m_aEntries[i].I8_step = step;
m_aEntries[i].I8_min = min;
m_aEntries[i].I8_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, uint16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pUint16Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_UINT16;
m_aEntries[i].I16_step = step;
m_aEntries[i].I16_min = min;
m_aEntries[i].I16_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, uint32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pUint32Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_UINT32;
m_aEntries[i].I32_step = step;
m_aEntries[i].I32_min = min;
m_aEntries[i].I32_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, uint64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pUint64Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_UINT64;
m_aEntries[i].I64_step = step;
m_aEntries[i].I64_min = min;
m_aEntries[i].I64_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, float *pVal, float step, float min, float max, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pFloatValue = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_FLOAT;
m_aEntries[i].F_step = step;
m_aEntries[i].F_min = min;
m_aEntries[i].F_max = max;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, bool *pVal, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pBoolValue = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_BOOL;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, bool8 *pVal, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pUint8Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_BOOL8;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, bool16 *pVal, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pUint16Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_BOOL16;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, bool32 *pVal, bool8 isVar)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pUint32Value = pVal;
m_aEntries[i].bAllowExceedBounds = isVar;
m_aEntries[i].VarType = VCE_TYPE_BOOL32;
m_nCountEntries++;
}
void
CVarConsole::Add(char *text, void (*pCallback)(void))
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
return;
}
m_aEntries[i].text = text;
m_aEntries[i].pCallback = pCallback;
m_aEntries[i].VarType = VCE_TYPE_FUNCTION;
m_nCountEntries++;
}
void
CVarConsole::Remove(char *text)
{
int i;
for (i = 0; i < m_nCountEntries; i++) {
if (m_aEntries[i].text == text)
{
for (int j = i; j < m_nCountEntries-1; j++)
m_aEntries[j] = m_aEntries[j+1];
m_nCountEntries--;
return;
}
}
}
void
CVarConsole::SortPages()
{
m_nNumPages = m_nCountEntries / 30 + 1;
}
void
CVarConsole::Display()
{
char s[256];
wchar ws[256];
CFont::SetColor(CRGBA(200, 200, 200, 255));
CFont::SetFontStyle(FONT_STANDARD);
CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.6f));
CFont::SetDropShadowPosition(2);
CFont::SetDropColor(CRGBA(0, 0, 0, 255));
CFont::SetPropOn();
CFont::SetWrapx(SCREEN_SCALE_X(DEFAULT_SCREEN_WIDTH));
CFont::SetRightJustifyWrap(0.0f);
sprintf(s, "PAGE %d", m_nCurPage);
AsciiToUnicode(s, ws);
CFont::SetRightJustifyOn();
CFont::PrintString(SCREEN_SCALE_X(310.0f), SCREEN_SCALE_Y(30.0f), ws);
CFont::SetRightJustifyOff();
int y = 45;
for (int i = m_nFirstEntryOnPage; i < m_nCountEntries && i < m_nFirstEntryOnPage + 30; i++)
{
switch (m_aEntries[i].VarType)
{
case VCE_TYPE_INT8:
sprintf(s, "(%d) %s:I8:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt8Value);
break;
case VCE_TYPE_INT16:
sprintf(s, "(%d) %s:I16:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt16Value);
break;
case VCE_TYPE_INT32:
sprintf(s, "(%d) %s:I32:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt32Value);
break;
case VCE_TYPE_INT64:
#ifdef FIX_BUGS
sprintf(s, "(%d) %s:I64:%lld", i + 1, m_aEntries[i].text, *m_aEntries[i].pInt64Value);
#else
sprintf(s, "(%d) %s:I64:%d", i + 1, m_aEntries[i].text, (int32)*m_aEntries[i].pInt64Value);
#endif
break;
case VCE_TYPE_UINT8:
sprintf(s, "(%d) %s:U8:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint8Value);
break;
case VCE_TYPE_UINT16:
sprintf(s, "(%d) %s:U6:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint16Value);
break;
case VCE_TYPE_UINT32:
sprintf(s, "(%d) %s:U32:%d", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint32Value);
break;
case VCE_TYPE_UINT64:
#ifdef FIX_BUGS
sprintf(s, "(%d) %s:U64:%llu", i + 1, m_aEntries[i].text, *m_aEntries[i].pUint64Value);
#else
sprintf(s, "(%d) %s:U64:%d", i + 1, m_aEntries[i].text, (uint32)*m_aEntries[i].pUint64Value);
#endif
break;
case VCE_TYPE_FLOAT:
sprintf(s, "(%d) %s:F:%f", i + 1, m_aEntries[i].text, *m_aEntries[i].pFloatValue);
break;
case VCE_TYPE_BOOL:
if (*m_aEntries[i].pBoolValue)
sprintf(s, "(%d) %s:B:TRUE", i + 1, m_aEntries[i].text);
else
sprintf(s, "(%d) %s:B : FALSE", i + 1, m_aEntries[i].text);
break;
case VCE_TYPE_BOOL8:
if (*m_aEntries[i].pUint8Value == FALSE)
sprintf(s, "(%d) %s:B8:FALSE", i + 1, m_aEntries[i].text);
else
sprintf(s, "(%d) %s:B8:TRUE", i + 1, m_aEntries[i].text);
break;
case VCE_TYPE_BOOL16:
if (*m_aEntries[i].pUint16Value == FALSE)
sprintf(s, "(%d) %s:B16:FALSE", i + 1, m_aEntries[i].text);
else
sprintf(s, "(%d) %s:B16:TRUE", i + 1, m_aEntries[i].text);
break;
case VCE_TYPE_BOOL32:
if (*m_aEntries[i].pUint32Value == FALSE)
sprintf(s, "(%d) %s:B32:FALSE", i + 1, m_aEntries[i].text);
else
sprintf(s, "(%d) %s:B32:TRUE", i + 1, m_aEntries[i].text);
break;
case VCE_TYPE_FUNCTION:
sprintf(s, "(%d) %s:FUNCTION:call this function?", i + 1, m_aEntries[i].text);
break;
}
AsciiToUnicode(s, ws);
if (m_nCurEntry == i) {
CFont::SetBackgroundOn();
#ifdef FIX_BUGS
CFont::SetBackgroundColor(CRGBA(128, 128, 128, 128));
#endif
}
#ifdef FIX_BUGS
else
CFont::SetBackgroundColor(CRGBA(128, 128, 128, 0));
#endif
CFont::SetColor(CRGBA(200, 200, 200, 255));
CFont::PrintString(SCREEN_SCALE_X(30.0f), SCREEN_SCALE_Y(y), ws);
if (m_nCurEntry == i)
CFont::SetBackgroundOff();
y += 12;
}
}
void
CVarConsole::ModifyLeft()
{
CVarConsoleEntry &entry = m_aEntries[m_nCurEntry];
switch (entry.VarType)
{
case VCE_TYPE_INT8:
*entry.pInt8Value -= entry.I8_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt8Value < entry.I8_min)
*entry.pInt8Value = entry.I8_max;
} else {
if (*entry.pInt8Value < entry.I8_min)
*entry.pInt8Value = entry.I8_min;
}
break;
case VCE_TYPE_INT16:
*entry.pInt16Value -= entry.I16_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt16Value < entry.I16_min)
*entry.pInt16Value = entry.I16_max;
}
else {
if (*entry.pInt16Value < entry.I16_min)
*entry.pInt16Value = entry.I16_min;
}
break;
case VCE_TYPE_INT32:
*entry.pInt32Value -= entry.I32_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt32Value < entry.I32_min)
*entry.pInt32Value = entry.I32_max;
}
else {
if (*entry.pInt32Value < entry.I32_min)
*entry.pInt32Value = entry.I32_min;
}
break;
case VCE_TYPE_INT64:
*entry.pInt64Value -= entry.I64_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt64Value < entry.I64_min)
*entry.pInt64Value = entry.I64_max;
}
else {
if (*entry.pInt64Value < entry.I64_min)
*entry.pInt64Value = entry.I64_min;
}
break;
case VCE_TYPE_UINT8:
*entry.pUint8Value -= entry.I8_step;
if (entry.bAllowExceedBounds) {
if (*(int8*)entry.pUint8Value < entry.I8_min)
*entry.pUint8Value = entry.I8_max;
}
else {
if (*(int8*)entry.pUint8Value < entry.I8_min)
*entry.pUint8Value = entry.I8_min;
}
break;
case VCE_TYPE_UINT16:
*entry.pUint16Value -= entry.I16_step;
if (entry.bAllowExceedBounds) {
if (*(int16*)entry.pUint16Value < entry.I16_min)
*entry.pUint16Value = entry.I16_max;
}
else {
if (*(int16*)entry.pUint16Value < entry.I16_min)
*entry.pUint16Value = entry.I16_min;
}
break;
case VCE_TYPE_UINT32:
*entry.pUint32Value -= entry.I32_step;
if (entry.bAllowExceedBounds) {
if (*(int32*)entry.pUint32Value < entry.I32_min)
*entry.pUint32Value = entry.I32_max;
}
else {
if (*(int32*)entry.pUint32Value < entry.I32_min)
*entry.pUint32Value = entry.I32_min;
}
break;
case VCE_TYPE_UINT64:
*entry.pUint64Value -= entry.I64_step;
if (entry.bAllowExceedBounds) {
if (*(int64*)entry.pUint64Value < entry.I64_min)
*entry.pUint64Value = entry.I64_max;
}
else {
if (*(int64*)entry.pUint64Value < entry.I64_min)
*entry.pUint64Value = entry.I64_min;
}
break;
case VCE_TYPE_FLOAT:
*entry.pFloatValue -= entry.F_step;
if (entry.bAllowExceedBounds) {
if (*entry.pFloatValue < entry.F_min)
*entry.pFloatValue = entry.F_max;
}
else {
if (*entry.pFloatValue < entry.F_min)
*entry.pFloatValue = entry.F_min;
}
break;
case VCE_TYPE_BOOL:
if (entry.bAllowExceedBounds)
*entry.pBoolValue ^= true;
else
*entry.pBoolValue = false;
break;
case VCE_TYPE_BOOL8:
if (entry.bAllowExceedBounds)
*entry.pUint8Value = *entry.pUint8Value == false;
else
*entry.pUint8Value = false;
break;
case VCE_TYPE_BOOL16:
if (entry.bAllowExceedBounds)
*entry.pUint16Value = *entry.pUint16Value == false;
else
*entry.pUint16Value = false;
break;
case VCE_TYPE_BOOL32:
if (entry.bAllowExceedBounds)
*entry.pUint32Value = *entry.pUint32Value == false;
else
*entry.pUint32Value = false;
break;
case VCE_TYPE_FUNCTION:
entry.pCallback();
break;
default:
return;
}
}
void
CVarConsole::ModifyRight()
{
CVarConsoleEntry &entry = m_aEntries[m_nCurEntry];
switch (entry.VarType)
{
case VCE_TYPE_INT8:
*entry.pInt8Value += entry.I8_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt8Value > entry.I8_max)
*entry.pInt8Value = entry.I8_min;
}
else {
if (*entry.pInt8Value > entry.I8_max)
*entry.pInt8Value = entry.I8_max;
}
break;
case VCE_TYPE_INT16:
*entry.pInt16Value += entry.I16_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt16Value > entry.I16_max)
*entry.pInt16Value = entry.I16_min;
}
else {
if (*entry.pInt16Value > entry.I16_max)
*entry.pInt16Value = entry.I16_max;
}
break;
case VCE_TYPE_INT32:
*entry.pInt32Value += entry.I32_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt32Value > entry.I32_max)
*entry.pInt32Value = entry.I32_min;
}
else {
if (*entry.pInt32Value > entry.I32_max)
*entry.pInt32Value = entry.I32_max;
}
break;
case VCE_TYPE_INT64:
*entry.pInt64Value += entry.I64_step;
if (entry.bAllowExceedBounds) {
if (*entry.pInt64Value > entry.I64_max)
*entry.pInt64Value = entry.I64_min;
}
else {
if (*entry.pInt64Value > entry.I64_max)
*entry.pInt64Value = entry.I64_max;
}
break;
case VCE_TYPE_UINT8:
*entry.pUint8Value += entry.I8_step;
if (entry.bAllowExceedBounds) {
if (*entry.pUint8Value > (uint8)entry.I8_max)
*entry.pUint8Value = entry.I8_min;
}
else {
if (*entry.pUint8Value > (uint8)entry.I8_max)
*entry.pUint8Value = entry.I8_max;
}
break;
case VCE_TYPE_UINT16:
*entry.pUint16Value += entry.I16_step;
if (entry.bAllowExceedBounds) {
if (*entry.pUint16Value > (uint16)entry.I16_max)
*entry.pUint16Value = entry.I16_min;
}
else {
if (*entry.pUint16Value > (uint16)entry.I16_max)
*entry.pUint16Value = entry.I16_max;
}
break;
case VCE_TYPE_UINT32:
*entry.pUint32Value += entry.I32_step;
if (entry.bAllowExceedBounds) {
if (*entry.pUint32Value > (uint32)entry.I32_max)
*entry.pUint32Value = entry.I32_min;
}
else {
if (*entry.pUint32Value > (uint32)entry.I32_max)
*entry.pUint32Value = entry.I32_max;
}
break;
case VCE_TYPE_UINT64:
*entry.pUint64Value += entry.I64_step;
if (entry.bAllowExceedBounds) {
if (*entry.pUint64Value > (uint64)entry.I64_max)
*entry.pUint64Value = entry.I64_min;
}
else {
if (*entry.pUint64Value > (uint64)entry.I64_max)
*entry.pUint64Value = entry.I64_max;
}
break;
case VCE_TYPE_FLOAT:
*entry.pFloatValue += entry.F_step;
if (entry.bAllowExceedBounds) {
if (*entry.pFloatValue > entry.F_max)
*entry.pFloatValue = entry.F_min;
}
else {
if (*entry.pFloatValue > entry.F_max)
*entry.pFloatValue = entry.F_max;
}
break;
case VCE_TYPE_BOOL:
if (entry.bAllowExceedBounds)
*entry.pBoolValue ^= true;
else
*entry.pBoolValue = true;
break;
case VCE_TYPE_BOOL8:
if (entry.bAllowExceedBounds)
*entry.pUint8Value = *entry.pUint8Value == false;
else
*entry.pUint8Value = true;
break;
case VCE_TYPE_BOOL16:
if (entry.bAllowExceedBounds)
*entry.pUint16Value = *entry.pUint16Value == false;
else
*entry.pUint16Value = true;
break;
case VCE_TYPE_BOOL32:
if (entry.bAllowExceedBounds)
*entry.pUint32Value = *entry.pUint32Value == false;
else
*entry.pUint32Value = true;
break;
case VCE_TYPE_FUNCTION:
entry.pCallback();
break;
default:
return;
}
}
void
CVarConsole::Enter()
{
m_bIsOpen = true;
}
void
CVarConsole::Exit()
{
m_bIsOpen = false;
}
void
CVarConsole::Input()
{
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadDownJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadDown())
{
m_nCurEntry++;
if (m_nCurEntry < m_nCountEntries)
{
if (m_nCurEntry > m_nFirstEntryOnPage + 29)
{
m_nFirstEntryOnPage = m_nCurEntry;
++m_nCurPage;
}
}
else
{
m_nCurEntry = m_nCountEntries - 1;
}
}
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadUpJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadUp())
{
m_nCurEntry--;
if (m_nCurEntry < m_nFirstEntryOnPage)
{
m_nFirstEntryOnPage = m_nCurEntry - 29;
--m_nCurPage;
}
if (m_nFirstEntryOnPage < 0)
{
m_nCurEntry = 0;
m_nFirstEntryOnPage = 0;
m_nCurPage = 1;
}
}
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetSquare())
ModifyLeft();
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetTriangle())
ModifyRight();
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadLeftJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadLeft())
ModifyLeft();
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetDPadRightJustDown() || CPad::GetPad(VAR_CONSOLE_PAD)->GetAnaloguePadRight())
ModifyRight();
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder2JustDown())
{
if (m_nCurPage > 1)
{
m_nCurPage--;
m_nFirstEntryOnPage -= 30;
m_nCurEntry = m_nFirstEntryOnPage;
if (m_nFirstEntryOnPage < 0)
{
m_nFirstEntryOnPage = 0;
m_nCurEntry = m_nFirstEntryOnPage;
m_nCurPage = 1;
}
}
}
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder2JustDown())
{
if (m_nCurPage < m_nNumPages)
{
m_nCurPage++;
m_nFirstEntryOnPage += 30;
m_nCurEntry = m_nFirstEntryOnPage;
if (m_nFirstEntryOnPage >= m_nCountEntries)
{
m_nFirstEntryOnPage -= 30;
m_nCurEntry = m_nFirstEntryOnPage;
m_nCurPage--;
}
}
}
if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder1JustDown() && CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder1JustDown())
Exit();
}
void
CVarConsole::Process()
{
Input();
SortPages();
Display();
}
bool8
CVarConsole::Open()
{
return m_bIsOpen;
}
void
CVarConsole::Check()
{
if (Open())
Process();
else if (CPad::GetPad(VAR_CONSOLE_PAD)->GetRightShoulder1JustDown() && CPad::GetPad(VAR_CONSOLE_PAD)->GetLeftShoulder1JustDown())
Enter();
}

92
src/render/VarConsole.h Normal file
View File

@ -0,0 +1,92 @@
#pragma once
enum eVarConsoleEntryType
{
VCE_TYPE_INT8,
VCE_TYPE_INT16,
VCE_TYPE_INT32,
VCE_TYPE_INT64,
VCE_TYPE_UINT8,
VCE_TYPE_UINT16,
VCE_TYPE_UINT32,
VCE_TYPE_UINT64,
VCE_TYPE_FLOAT,
VCE_TYPE_BOOL,
VCE_TYPE_BOOL8,
VCE_TYPE_BOOL16,
VCE_TYPE_BOOL32,
VCE_TYPE_FUNCTION,
};
struct CVarConsoleEntry
{
char *text;
int8 *pInt8Value;
int16 *pInt16Value;
int32 *pInt32Value;
int64 *pInt64Value;
uint8 *pUint8Value;
uint16 *pUint16Value;
uint32 *pUint32Value;
uint64 *pUint64Value;
float *pFloatValue;
bool *pBoolValue;
void (*pCallback)(void);
int8 I8_step, I8_max, I8_min;
int16 I16_step, I16_max, I16_min;
int32 I32_step, I32_max, I32_min;
int64 I64_step, I64_max, I64_min;
float F_step, F_max, F_min;
bool8 bAllowExceedBounds;
uint8 VarType;
};
class CVarConsole
{
int32 m_nCountEntries;
bool8 m_bIsOpen;
int32 m_nCurEntry;
int32 m_nFirstEntryOnPage;
int32 m_nCurPage;
int32 m_nNumPages;
CVarConsoleEntry m_aEntries[91];
public:
#ifdef FIX_BUGS
CVarConsole() { Initialise(); }
#endif
void Initialise();
void Add(char *text, int8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar);
void Add(char *text, int16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar);
void Add(char *text, int32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar);
void Add(char *text, int64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar);
void Add(char *text, uint8 *pVal, uint8 step, int8 min, int8 max, bool8 isVar);
void Add(char *text, uint16 *pVal, uint16 step, int16 min, int16 max, bool8 isVar);
void Add(char *text, uint32 *pVal, uint32 step, int32 min, int32 max, bool8 isVar);
void Add(char *text, uint64 *pVal, uint64 step, int64 min, int64 max, bool8 isVar);
void Add(char *text, float *pVal, float step, float min, float max, bool8 isVar);
void Add(char *text, bool *pVal, bool8 isVar);
void Add(char *text, bool8 *pVal, bool8 isVar);
void Add(char *text, bool16 *pVal, bool8 isVar);
void Add(char *text, bool32 *pVal, bool8 isVar);
void Add(char *text, void (*pVar)(void));
void Remove(char *text);
void SortPages();
void Display();
void ModifyLeft();
void ModifyRight();
void Enter();
void Exit();
void Input();
void Process();
bool8 Open();
void Check();
};
extern CVarConsole VarConsole;