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
|
/*
client/console.cc
This file is part of the Osirion project and is distributed under
the terms and conditions of the GNU General Public License version 2
*/
#include "client/client.h"
#include "client/console.h"
#include "core/core.h"
#include "render/render.h"
#include <iostream>
namespace client {
Console::Console() {
visible = false;
}
std::ostream & Console::messagestream()
{
return (buffer << ". ");
}
std::ostream & Console::warningstream()
{
return (buffer << "* ");
}
std::ostream & Console::errorstream()
{
return (buffer << "! ");
}
std::ostream & Console::debugstream()
{
return (buffer << "? ");
}
void Console::draw()
{
using namespace render;
flush();
float height;
if (core::game()) {
if (!core::game()->ready())
height = 0.6f;
else if (visible)
height = 0.6f;
else
return;
} else
height = 1.0f;
// console background rectangle
gl::enable(GL_BLEND);
gl::begin(gl::Quads);
gl::color(1, 1, 1, .1);
gl::vertex(-0.5f*video.ratio , 0.5, -1.0f);
gl::vertex(0.5f*video.ratio ,0.5, -1.0f);
gl::vertex(0.5f*video.ratio , 0.5-height, -1.0f);
gl::vertex(-0.5f*video.ratio , 0.5-height, -1.0f);
gl::end();
gl::disable(GL_BLEND);
}
void Console::flush()
{
char line[MAXCMDSIZE];
while(this->buffer.getline(line, MAXCMDSIZE-1)) {
while (text.size() >= 32765 - MAXCMDSIZE) {
size_t i = 0;
while (i+1 < text.size() && text[i] != '\n')
i++;
text.erase(0, i+1);
}
text.append(line);
text.append("\n");
std::cout << line << std::endl;
}
buffer.clear();
}
void Console::toggle()
{
visible = !visible;
}
} // namespace client
|