summaryrefslogtreecommitdiffstats
path: root/src/core/Debug.cpp
blob: e319388cc7387a2a327d646fac38038d57098650 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "common.h"
#include "RwHelper.h"
#include "Debug.h"
#include "Lines.h"
#include "Font.h"
#include "main.h"
#include "Text.h"

bool gbDebugStuffInRelease = false;

#define DEBUG_X_POS (300)
#define DEBUG_Y_POS (41)
#define DEBUG_LINE_HEIGHT (22)

int16 CDebug::ms_nCurrentTextLine;
char CDebug::ms_aTextBuffer[MAX_LINES][MAX_STR_LEN];

void
CDebug::DebugInitTextBuffer()
{
	ms_nCurrentTextLine = 0;
}

void
CDebug::DebugAddText(const char *str)
{
	int32 i = 0;
	if (*str != '\0') {
		while (i < MAX_STR_LEN - 1) {
			ms_aTextBuffer[ms_nCurrentTextLine][i++] = *(str++);
			if (*str == '\0')
				break;
		}
	}

	ms_aTextBuffer[ms_nCurrentTextLine++][i] = '\0';
	if (ms_nCurrentTextLine >= MAX_LINES)
		ms_nCurrentTextLine = 0;
}

void
CDebug::DebugDisplayTextBuffer()
{
#ifndef MASTER
	if (gbDebugStuffInRelease)
	{
		int32 i = 0;
		int32 y = DEBUG_Y_POS;
#ifdef FIX_BUGS
		CFont::SetPropOn();
		CFont::SetBackgroundOff();
		CFont::SetScale(1.0f, 1.0f);
		CFont::SetCentreOff();
		CFont::SetRightJustifyOff();
		CFont::SetJustifyOn();
		CFont::SetRightJustifyWrap(0.0f);
		CFont::SetBackGroundOnlyTextOff();
		CFont::SetFontStyle(FONT_STANDARD);
#else
		// this is not even readable
		CFont::SetPropOff();
		CFont::SetBackgroundOff();
		CFont::SetScale(1.0f, 1.0f);
		CFont::SetCentreOff();
		CFont::SetRightJustifyOn();
		CFont::SetRightJustifyWrap(0.0f);
		CFont::SetBackGroundOnlyTextOff();
		CFont::SetFontStyle(FONT_STANDARD);
		CFont::SetPropOff();
#endif
		do {
			char *line;
			while (true) {
				line = ms_aTextBuffer[(ms_nCurrentTextLine + i++) % MAX_LINES];
				if (*line != '\0')
					break;
				y += DEBUG_LINE_HEIGHT;
				if (i == MAX_LINES) {
					CFont::DrawFonts();
					return;
				}
			}
			AsciiToUnicode(line, gUString);
			CFont::SetColor(CRGBA(0, 0, 0, 255));
			CFont::PrintString(DEBUG_X_POS, y-1, gUString);
			CFont::SetColor(CRGBA(255, 128, 128, 255));
			CFont::PrintString(DEBUG_X_POS+1, y, gUString);
			y += DEBUG_LINE_HEIGHT;
		} while (i != MAX_LINES);
		CFont::DrawFonts();
	}
#endif
}


// custom

CDebug::ScreenStr CDebug::ms_aScreenStrs[MAX_SCREEN_STRS];
int CDebug::ms_nScreenStrs;

void
CDebug::DisplayScreenStrings()
{
	int i;
	

	CFont::SetPropOn();
	CFont::SetBackgroundOff();
	CFont::SetScale(1.0f, 1.0f);
	CFont::SetCentreOff();
	CFont::SetRightJustifyOff();
	CFont::SetJustifyOff();
	CFont::SetRightJustifyWrap(0.0f);
	CFont::SetWrapx(9999.0f);
	CFont::SetBackGroundOnlyTextOff();
	CFont::SetFontStyle(FONT_STANDARD);

	for(i = 0; i < ms_nScreenStrs; i++){
/*
		AsciiToUnicode(ms_aScreenStrs[i].str, gUString);
		CFont::SetColor(CRGBA(0, 0, 0, 255));
		CFont::PrintString(ms_aScreenStrs[i].x, ms_aScreenStrs[i].y, gUString);
		CFont::SetColor(CRGBA(255, 255, 255, 255));
		CFont::PrintString(ms_aScreenStrs[i].x+1, ms_aScreenStrs[i].y+1, gUString);
*/
		ObrsPrintfString(ms_aScreenStrs[i].str, ms_aScreenStrs[i].x, ms_aScreenStrs[i].y);
	}
	CFont::DrawFonts();

	ms_nScreenStrs = 0;
}

void
CDebug::PrintAt(const char *str, int x, int y)
{
	if(ms_nScreenStrs >= MAX_SCREEN_STRS)
		return;
	strncpy(ms_aScreenStrs[ms_nScreenStrs].str, str, 256);
	ms_aScreenStrs[ms_nScreenStrs].x = x;//*12;
	ms_aScreenStrs[ms_nScreenStrs].y = y;//*22;
	ms_nScreenStrs++;
}

CDebug::Line CDebug::ms_aLines[MAX_DEBUG_LINES];
int CDebug::ms_nLines;

void
CDebug::AddLine(CVector p1, CVector p2, uint32 c1, uint32 c2)
{
	if(ms_nLines >= MAX_DEBUG_LINES)
		return;
	ms_aLines[ms_nLines].p1 = p1;
	ms_aLines[ms_nLines].p2 = p2;
	ms_aLines[ms_nLines].c1 = c1;
	ms_aLines[ms_nLines].c2 = c2;
	ms_nLines++;
}

void
CDebug::DrawLines(void)
{
	int i;
	RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil);
	RwRenderStateSet(rwRENDERSTATEZTESTENABLE, (void*)FALSE);
	for(i = 0; i < ms_nLines; i++){
		Line *l = &ms_aLines[i];
		CLines::RenderLineWithClipping(l->p1.x, l->p1.y, l->p1.z, l->p2.x, l->p2.y, l->p2.z, l->c1, l->c2);
	}
	ms_nLines = 0;
}