Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/view.cc')
-rw-r--r--src/client/view.cc308
1 files changed, 181 insertions, 127 deletions
diff --git a/src/client/view.cc b/src/client/view.cc
index 50b5b61..38d22d4 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -18,11 +18,14 @@
#include "client/input.h"
#include "client/targets.h"
#include "client/video.h"
+#include "client/view.h"
#include "render/render.h"
#include "core/core.h"
#include "math/mathlib.h"
#include "sys/sys.h"
+#include "ui/paint.h"
#include "ui/ui.h"
+#include "ui/widget.h"
namespace client
{
@@ -35,35 +38,196 @@ core::Cvar *draw_keypress = 0;
core::Cvar *ui_pointercolor = 0;
core::Cvar *ui_pointerhovercolor =0;
-namespace view
+/* -- DevInfo------------------------------------------------------- */
+DevInfo::DevInfo(ui::Widget *parent) : ui::Widget(parent)
{
+ set_label("devinfo");
+ set_border(true);
+}
-const size_t fps_counter_size = 32; // fps is the average of 32 frames
-float fps_counter_time[fps_counter_size];
-size_t fps_counter_index = 0;
+void DevInfo::draw()
+{
+ draw_border();
-const size_t net_counter_size = 128;
-float net_counter_time[net_counter_size];
-size_t net_counter_traffic[net_counter_size];
-size_t net_counter_index;
+ std::stringstream textstream;
+ core::Entity *target = targets::current();
+ float d = 0;
-core::Zone *current_zone = 0;
+ textstream << "^Ntime: ^B" << std::fixed << std::setprecision(4) << client()->time() << '\n';
+ if (core::game()) {
+ textstream << "^Ngame: ^B" << core::game()->time();
+ }
+ textstream << '\n';
-void init()
+ if (core::localcontrol()) {
+ textstream << std::fixed << std::setprecision(2)
+ << "^Nx:^B" << core::localcontrol()->location().x << " "
+ << "^Ny:^B" << core::localcontrol()->location().y << " "
+ << "^Nz:^B" << core::localcontrol()->location().z << '\n';
+
+ textstream << "^Nthurst:^B " << core::localcontrol()->thrust() << " "
+ << "^Nspeed:^B " << core::localcontrol()->speed() << '\n';
+
+ if (target) {
+ d = math::distance(core::localcontrol()->location(), target->state()->location()) - target->radius() - core::localcontrol()->radius();
+ textstream << "^Ndist:^B " << d << '\n';
+ }
+ }
+
+ ui::paint::color(palette()->foreground());
+ ui::paint::text(global_location(), font(), textstream);
+}
+
+/* -- Stats -------------------------------------------------------- */
+
+Stats::Stats(ui::Widget *parent) : ui::Widget(parent)
{
- draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive);
- draw_stats->set_info("[bool] draw network and render statistics");
+ set_label("stats");
+ set_border(true);
+
+ // 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;
+}
+
+void Stats::draw()
+{
+ draw_border();
+
+ // 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 - 1.0f) / t);
+ }
+
+ std::stringstream textstream;
+
+ if (core::game()) {
+ int minutes = (int) floorf(core::game()->clientframetime() / 60.0f);
+ int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f);
+
+ textstream << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
+ }
+
+ textstream << std::setfill(' ') << "\n";
+ textstream << "^Nfps ^B" << std::setw(6) << fps << "\n";
+ if (core::application()->connected()) {
+ 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::color(palette()->foreground());
+ ui::paint::text(global_location(), font(), textstream);
+}
+
+/* -- KeyPress ----------------------------------------------------- */
+
+KeyPress::KeyPress(ui::Widget *parent) : Widget(parent)
+{
+ set_label("keypress");
+ set_border(true);
+}
+
+void KeyPress::draw()
+{
+ draw_border();
+
+ if(input::last_key_pressed()) {
+ ui::paint::color(palette()->highlight());
+ ui::paint::text(global_location(), size(), font(), input::last_key_pressed()->name(), ui::AlignCenter);
+ }
+}
+
+/* -- View --------------------------------------------------------- */
+
+View::View(ui::Widget *parent) : ui::Widget(parent)
+{
+ set_label("view");
+ set_border(false);
+
+ // initialize client variables
draw_devinfo = core::Cvar::get("draw_devinfo", "0", core::Cvar::Archive);
draw_devinfo->set_info("[bool] draw developer information");
- // FIXME integrate with libui
- draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive);
- draw_ui->set_info("[bool] draw the user interface");
+ draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive);
+ draw_stats->set_info("[bool] draw network and render statistics");
draw_keypress = core::Cvar::get("draw_keypress", "0", core::Cvar::Archive);
draw_keypress->set_info("[bool] draw keypress key names");
+ // add child widgets
+ view_devinfo = new DevInfo(this);
+ view_stats = new Stats(this);
+ view_keypress = new KeyPress(this);
+
+ // make sure the view is at the bottom of the draw stack
+ lower();
+}
+
+void View::resize()
+{
+ set_size(parent()->size());
+
+ // reposition devinfo widget
+ view_devinfo->set_size(font()->width()*32, font()->height()*5);
+ view_devinfo->set_location(font()->width() * 0.5f, font()->height() * 0.5f);
+
+ // reposition stats widget
+ view_stats->set_size(font()->width()*12, font()->height()*5);
+ view_stats->set_location(width() - view_stats->width() - font()->width() * 0.5, font()->height() * 0.5f);
+
+ // reposition keypress widget
+ view_keypress->set_size(font()->width()*12, font()->height()*1);
+ view_keypress->set_location(width() - view_keypress->width() - font()->width() * 0.5,
+ height() - view_keypress->height() - font()->height() * 0.5f);
+}
+
+void View::draw()
+{
+ view_devinfo->set_visible(draw_devinfo->value() ? true : false);
+ view_stats->set_visible(draw_stats->value() ? true : false);
+ view_keypress->set_visible(draw_keypress->value() ? true : false);
+}
+
+/* -- namespace view ----------------------------------------------- */
+
+namespace view
+{
+
+core::Zone *current_zone = 0;
+
+void init()
+{
+ // FIXME integrate with libui
+ draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive);
+ draw_ui->set_info("[bool] draw the user interface");
+
ui_pointercolor = core::Cvar::get("ui_pointercolor", "0 .5 0", core::Cvar::Archive);
ui_pointercolor->set_info("[r g b] mouse pointer color");
@@ -71,12 +235,6 @@ void init()
ui_pointerhovercolor->set_info("[r g b] mouse pointer hover color");
targets::init();
-
- 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;
}
void shutdown()
@@ -108,53 +266,7 @@ void clear_zone(core::Zone *zone)
zone->set_sky_texture(0);
}
}
-/*
-void draw_loader()
-{
- using namespace render;
-
- render::Textures::bind("bitmaps/loader");
-
- gl::begin(gl::Quads);
-
- glTexCoord2f(0.0f, 0.0f);
- gl::vertex(0,0, 0);
-
- glTexCoord2f(1.0f, 0.0f);
- gl::vertex(video::width,0,0);
-
- glTexCoord2f(1.0f, 1.0f);
- gl::vertex(video::width,video::height,0);
-
- glTexCoord2f(0.0f, 1.0f);
- gl::vertex(0,video::height,0);
-
- gl::end();
-}
-
-void draw_banner()
-{
- using namespace render;
- render::Textures::bind("bitmaps/banner");
-
- gl::begin(gl::Quads);
-
- glTexCoord2f(0.0f, 0.0f);
- gl::vertex(0,0, 0);
-
- glTexCoord2f(1.0f, 0.0f);
- gl::vertex(video::width,0,0);
-
- glTexCoord2f(1.0f, 1.0f);
- gl::vertex(video::width,video::height,0);
-
- glTexCoord2f(0.0f, 1.0f);
- gl::vertex(0,video::height,0);
-
- gl::end();
-}
-*/
/*
FIXME should be merged with the render passes
and in the bbox pass
@@ -168,7 +280,6 @@ void draw_entity_world_target(core::Entity *entity)
if (!model)
return;
-
if (!model->docks().size())
return;
@@ -375,65 +486,8 @@ void draw_entity_target(core::Entity *entity, bool is_active_target)
void draw_status()
{
using namespace render;
-
std::stringstream status;
- if (core::game() && core::game()->interactive()) {
- int minutes = (int) floorf(core::game()->clientframetime() / 60.0f);
- int seconds = (int) floorf( core::game()->clientframetime() - (float) minutes* 60.0f);
-
- status << "^Ntime ^B" << std::setfill(' ') << std::setw(3) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds;
- Text::draw(video::width-Text::fontwidth()*12-4, Text::fontheight()+ 4, status);
- }
-
- // print stats if desired
- if (draw_stats && draw_stats->value()) {
- // 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 - 1.0f) / t);
- }
-
- std::stringstream stats;
- stats << "^Nfps ^B" << std::setw(6) << fps << "\n";
-
- if (core::application()->connected()) {
- stats << "^Ntris ^B" << std::setw(5) << render::Stats::tris << "\n";
- stats << "^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];
-
- stats << "^Nnet ^B" << std::setw(6) << roundf( (float) traffic / d ) << "\n";
- }
- }
- }
-
- Text::draw(video::width-Text::fontwidth()*12-4, 4 + Text::fontheight()*2, stats);
- }
-
- // draw keypress
- if (draw_keypress->value() && input::last_key_pressed()) {
- Text::setcolor('F'); //set fancy color
- Text::draw(video::width-4-Text::fontwidth()*6, video::height-Text::fontheight()-4, input::last_key_pressed()->name());
- }
-
// draw a basic HUD
if (core::localcontrol() && core::localcontrol()->zone()) {
core::Zone *zone = core::localcontrol()->zone();
@@ -477,7 +531,7 @@ void draw_status()
if (target) {
d = math::distance(core::localcontrol()->location(), target->state()->location()) - target->radius() - core::localcontrol()->radius();
}
-
+/*
if (draw_devinfo->value()) {
std::stringstream devinfo;
devinfo << std::fixed << std::setprecision(2)
@@ -491,7 +545,7 @@ void draw_status()
devinfo << "^Ndist:^B " << d << '\n';
Text::draw(4, 4 + Text::fontheight(), devinfo);
}
-
+*/
float y = 1.0f;
if (target) {
std::stringstream strtarget;