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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
/*
client/infowidget.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 <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include "auxiliary/functions.h"
#include "client/infowidget.h"
#include "client/client.h"
#include "client/input.h"
#include "client/targets.h"
#include "render/render.h"
#include "core/stats.h"
#include "math/mathlib.h"
#include "sys/sys.h"
#include "ui/paint.h"
#include "ui/ui.h"
#include "ui/widget.h"
namespace client
{
// helper function
void time_to_stream(std::ostringstream &str, float time)
{
int minutes = (int) floorf(time / 60.0f);
int seconds = (int) floorf(time - (float) minutes * 60.0f);
str << std::setfill(' ') << std::setw(4) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
}
/* -- DevInfoWidget ------------------------------------------------ */
DevInfoWidget::DevInfoWidget(ui::Widget *parent) : ui::Widget(parent)
{
set_label("devinfo");
set_border(false);
set_background(false);
}
void DevInfoWidget::draw()
{
std::ostringstream textstream;
const core::Entity *target = targets::current();
textstream << "^Ncore ^B";
time_to_stream(textstream, core::application()->time());
textstream << '\n';
if (core::game()) {
textstream << "^Ntime ^B";
time_to_stream(textstream, core::game()->time());
}
textstream << '\n';
if (core::localcontrol()) {
textstream << "^B" << core::localcontrol()->name() << '\n';
textstream << "^Nthurst ^B" << std::fixed << std::setprecision(2)
<< core::localcontrol()->thrust() << '\n';
textstream << "^Nspeed ^B" << std::fixed << std::setprecision(2)
<< core::localcontrol()->speed() << '\n';
textstream << "^Nx,y,z ^B" << std::fixed << std::setprecision(2)
<< core::localcontrol()->location().x() << ", "
<< core::localcontrol()->location().y() << ", "
<< core::localcontrol()->location().z() << '\n';
textstream << "^Nradius ^B" << core::localcontrol()->radius() << '\n';
if (target) {
textstream << "^B" << target->name() << '\n';
textstream << "^Nx,y,z ^B" << std::fixed << std::setprecision(2)
<< target->location().x() << ", "
<< target->location().y() << ", "
<< target->location().z() << '\n';
textstream << "^Nradius ^B" << target->radius() << '\n';
}
}
ui::Paint::set_color(palette()->foreground());
ui::Paint::draw_text(global_location(), font(), textstream.str());
}
/* -- StatsInfoWidget ---------------------------------------------- */
StatsInfoWidget::StatsInfoWidget(ui::Widget *parent) : ui::Widget(parent)
{
set_label("stats");
set_border(false);
set_background(false);
// clear counters
for (size_t i = 0; i < fps_counter_size; i++)
fps_counter_time[i] = 0.0f;
for (size_t i = 0; i < net_counter_size; i++)
net_counter_traffic[i] = 0;
net_counter_index = 0;
fps_counter_index = 0;
}
void StatsInfoWidget::draw()
{
// average fps
fps_counter_time[fps_counter_index] = core::application()->time();
fps_counter_index = (fps_counter_index + 1) % fps_counter_size;
float min_time = core::application()->time();
for (size_t i = 0; i < fps_counter_size; i++)
if (fps_counter_time[i] < min_time)
min_time = fps_counter_time[i];
float fps = 0.0f;
float t = (core::application()->time() - min_time);
if (t > 0) {
fps = roundf(((float) fps_counter_size ) / t);
}
std::ostringstream textstream;
if (core::game()) {
textstream << "^Ntime ^B";
time_to_stream(textstream, core::game()->time());
}
textstream << std::setfill(' ') << "\n";
textstream << "^Nfps ^B" << std::setw(6) << fps << "\n";
if (core::application()->connected()) {
textstream << "^Nfrags ^B" << std::setw(5) << render::Stats::fragments << "\n";
textstream << "^Ntris ^B" << std::setw(5) << render::Stats::tris << "\n";
textstream << "^Nquads ^B" << std::setw(5) << render::Stats::quads << "\n";
if (core::Stats::network_bytes_sent + core::Stats::network_bytes_received) {
net_counter_traffic[net_counter_index] = core::Stats::network_bytes_sent + core::Stats::network_bytes_received;
net_counter_time[net_counter_index] = core::application()->time();
size_t index_max = net_counter_index;
net_counter_index = (net_counter_index + 1) % net_counter_size;
size_t index_min = net_counter_index;
float d = net_counter_time[index_max] - net_counter_time[index_min];
if (d > 0) {
float traffic = net_counter_traffic[index_max] - net_counter_traffic[index_min];
textstream << "^Nnet ^B" << std::setw(6) << roundf((float) traffic / d) << "\n";
}
}
}
ui::Paint::set_color(palette()->foreground());
ui::Paint::draw_text(global_location(), font(), textstream.str());
}
/* -- KeyInfoWidget ------------------------------------------------ */
KeyInfoWidget::KeyInfoWidget(ui::Widget *parent) : Widget(parent)
{
set_label("keypress");
set_border(false);
set_background(false);
}
void KeyInfoWidget::draw()
{
Key::Modifier mod = input::modifier();
std::string label;
if (mod != Key::None) {
if (mod == Key::Shift)
label.assign("shift+");
else if (mod == Key::Ctrl)
label.assign("ctrl+");
else if (mod == Key::Alt)
label.assign("alt+");
}
if (input::last_key_pressed()) {
label.append(input::last_key_pressed()->name());
}
if (label.size()) {
ui::Paint::set_color(palette()->highlight());
ui::Paint::draw_label(global_location(), size(), font(), label , ui::AlignCenter);
}
}
}
|