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')
-rw-r--r--src/client/Makefile.am6
-rw-r--r--src/client/client.cc32
-rw-r--r--src/client/client.h8
-rw-r--r--src/client/hud.cc39
-rw-r--r--src/client/targets.cc1
-rw-r--r--src/client/video.cc9
-rw-r--r--src/client/view.cc276
-rw-r--r--src/client/view.h105
8 files changed, 41 insertions, 435 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index ad011d0..d617b52 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -8,12 +8,14 @@ noinst_LTLIBRARIES = libclient.la
endif
libclient_la_SOURCES = action.cc chat.cc client.cc clientext.cc hud.cc \
- input.cc joystick.cc key.cc keyboard.cc map.cc notifications.cc soundext.cc targets.cc video.cc view.cc
+ infowidget.cc input.cc joystick.cc key.cc keyboard.cc map.cc notifications.cc \
+ playerview.cc soundext.cc targets.cc video.cc worldview.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
noinst_HEADERS = action.h chat.h client.h clientext.h hud.h input.h joystick.h \
key.h keyboard.h map.h notifications.h soundext.h targets.h video.h \
- view.h
+ infowidget.h playerview.h worldview.h
libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la $(top_builddir)/src/audio/libaudio.la \
$(top_builddir)/src/render/librender.la $(top_builddir)/src/ui/libui.la
+
diff --git a/src/client/client.cc b/src/client/client.cc
index 8aba931..4533f84 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -15,7 +15,6 @@
#include "client/client.h"
#include "client/video.h"
#include "client/input.h"
-#include "client/view.h"
#include "core/core.h"
#include "core/loader.h"
#include "core/zone.h"
@@ -61,7 +60,7 @@ void Client::quit(int status)
void Client::init(int count, char **arguments)
{
- client_view = 0;
+ client_worldview = 0;
con_print << "^BInitializing client..." << std::endl;
// initialize core
@@ -92,7 +91,7 @@ void Client::init(int count, char **arguments)
// initialize user interface
ui::init();
- client_view = new View(ui::root());
+ client_worldview = new WorldView(ui::root());
// Initialize the video subsystem
if (!video::init()) {
@@ -257,8 +256,7 @@ void Client::notify_connect()
video::set_loader_message();
video::frame_loader();
- view()->notify()->clear();
- view()->chat()->clear();
+ worldview()->clear();
ui::root()->hide_menu();
video::set_caption();
@@ -270,8 +268,7 @@ void Client::notify_disconnect()
render::reset();
input::reset();
- view()->notify()->clear();
- view()->chat()->clear();
+ worldview()->clear();
video::set_caption();
}
@@ -334,9 +331,8 @@ void Client::notify_message(const core::Message::Channel channel, const std::str
break;
}
- if (view()) {
- view()->chat()->event_text(message);
- view()->notify()->event_text(message);
+ if (worldview()) {
+ worldview()->event_text(message);
}
con_print << message << std::endl;
@@ -368,24 +364,24 @@ void Client::func_r_restart(std::string const &args)
void Client::func_ui_chat(std::string const &args)
{
- if (core::application()->connected()) {
- client()->view()->chat()->set_small_view(false);
- client()->view()->chat()->toggle();
+ if (client()->connected() && client()->worldview()->playerview()->visible()) {
+ client()->worldview()->playerview()->chat()->set_small_view(false);
+ client()->worldview()->playerview()->chat()->toggle();
}
}
void Client::func_ui_chatsmall(std::string const &args)
{
- if (core::application()->connected()) {
- client()->view()->chat()->set_small_view(true);
- client()->view()->chat()->toggle();
+ if (client()->connected() && client()->worldview()->playerview()->visible()) {
+ client()->worldview()->playerview()->chat()->set_small_view(true);
+ client()->worldview()->playerview()->chat()->toggle();
}
}
void Client::func_ui_map(std::string const &args)
{
- if (core::application()->connected()) {
- client()->view()->map()->toggle();
+ if (client()->connected() && client()->worldview()->playerview()->visible()) {
+ client()->worldview()->playerview()->map()->toggle();
}
}
diff --git a/src/client/client.h b/src/client/client.h
index e527b37..b873a20 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -12,7 +12,7 @@
#include "core/entity.h"
#include "client/clientext.h"
#include "client/soundext.h"
-#include "client/view.h"
+#include "client/worldview.h"
#include "render/renderext.h"
/// client part of the engine
@@ -61,8 +61,8 @@ public:
/// disconnect notification
virtual void notify_disconnect();
- /// the main client view
- inline View *view() { return client_view; }
+ /// the main client widget
+ inline WorldView *worldview() { return client_worldview; }
protected:
/// run a client frame
@@ -77,7 +77,7 @@ private:
static void func_ui_map(std::string const &args);
static void func_ui_menu(std::string const &args);
- View *client_view;
+ WorldView *client_worldview;
unsigned long previous_timestamp;
};
diff --git a/src/client/hud.cc b/src/client/hud.cc
index c10ffa8..beeefd3 100644
--- a/src/client/hud.cc
+++ b/src/client/hud.cc
@@ -228,14 +228,6 @@ void HUD::draw()
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
- // draw player info
- std::stringstream playerinfostr;
- playerinfostr << "^B" << core::localplayer()->name() << '\n'
- <<"^B" << core::localcontrol()->name() << '\n' << "^N"
- << "credits: " << core::localplayer()->credits();
-
- Text::draw(Text::fontwidth() * 0.5f, Text::fontheight()*8+4, playerinfostr);
-
if(core::localplayer()->view()) {
Text::setcolor('N'); //set normal color
@@ -281,14 +273,12 @@ void HUD::draw()
core::Entity *target = targets::current();
std::stringstream strdistance;
- float d = 0;
- float y = 1.0f;
if (target) {
std::stringstream strtarget;
strtarget << "^B" << target->name() << "\n^B";
- d = math::distance(core::localcontrol()->location(), target->location())
+ float d = math::distance(core::localcontrol()->location(), target->location())
- target->radius() - core::localcontrol()->radius();
if (d > 0 ) {
@@ -313,28 +303,29 @@ void HUD::draw()
strtarget << " --";
}
strtarget << '\n';
- Text::draw(render::State::width() - 4-Text::fontwidth()*32, render::State::height() - Text::fontheight()*2 -4, strtarget);
- y += 2.0f;
+ Text::draw(width() - 4-Text::fontwidth()*30, height() - Text::fontheight()*2 -4, strtarget);
}
- Text::setcolor('N'); //set normal color
- Text::draw(render::State::width()-4-Text::fontwidth()*32, render::State::height()-Text::fontheight()*y-4, core::localcontrol()->zone()->name());
+ // draw player info
+ std::stringstream playerinfostr;
+ playerinfostr <<"^B" << core::localcontrol()->name() << '\n' << "^Ncredits: " << core::localplayer()->credits();
+ Text::draw(width() - 4-Text::fontwidth()*52, height() - Text::fontheight()*2 -4, playerinfostr);
Textures::bind("bitmaps/hud/thruster_base"); // 316 x 32 bitmap
gl::color(1, 1, 1, 1);
gl::begin(gl::Quads);
glTexCoord2f(0, 0);
- gl::vertex(4, render::State::height() - 4 - 32, 0);
+ gl::vertex(4, height() - 4 - 32, 0);
glTexCoord2f(1, 0);
- gl::vertex(4 + 316, render::State::height() - 4 - 32, 0);
+ gl::vertex(4 + 316, height() - 4 - 32, 0);
glTexCoord2f(1, 1);
- gl::vertex(4 + 316, render::State::height() - 4 , 0);
+ gl::vertex(4 + 316, height() - 4 , 0);
glTexCoord2f(0, 1);
- gl::vertex(4, render::State::height() - 4 , 0);
+ gl::vertex(4, height() - 4 , 0);
gl::end();
@@ -357,16 +348,16 @@ void HUD::draw()
Textures::bind("bitmaps/hud/thruster_indicator"); // 316 x 32 bitmap
gl::begin(gl::Quads);
glTexCoord2f(0, 0);
- gl::vertex(4, render::State::height() - 4 - 32, 0);
+ gl::vertex(4, height() - 4 - 32, 0);
glTexCoord2f(u, 0);
- gl::vertex(4.0f + u * 316.0f, render::State::height() - 4 - 32, 0);
+ gl::vertex(4.0f + u * 316.0f, height() - 4 - 32, 0);
glTexCoord2f(u, 1);
- gl::vertex(4.0f + u * 316.0f, render::State::height() - 4 , 0);
+ gl::vertex(4.0f + u * 316.0f, height() - 4 , 0);
glTexCoord2f(0, 1);
- gl::vertex(4, render::State::height() - 4 , 0);
+ gl::vertex(4, height() - 4 , 0);
gl::end();
}
@@ -376,7 +367,7 @@ void HUD::draw()
std::stringstream speedstr;
speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f);
- Text::draw( 316+4+10, render::State::height() - 6 -16 - render::Text::fontwidth() /2, speedstr);
+ Text::draw( 316+4+10, height() - 6 -16 - render::Text::fontwidth() /2, speedstr);
Text::setfont("gui", 12, 18);
Text::setcolor('N'); //set normal color
diff --git a/src/client/targets.cc b/src/client/targets.cc
index 92e1294..ec15df9 100644
--- a/src/client/targets.cc
+++ b/src/client/targets.cc
@@ -17,7 +17,6 @@
#include "client/client.h"
#include "client/input.h"
#include "client/soundext.h"
-#include "client/view.h"
#include "client/video.h"
#include "core/application.h"
#include "core/entity.h"
diff --git a/src/client/video.cc b/src/client/video.cc
index a8e5400..aa5077f 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -6,7 +6,6 @@
#include "client/video.h"
#include "client/input.h"
-#include "client/view.h"
#include "client/client.h"
#include "client/targets.h"
#include "render/render.h"
@@ -241,7 +240,7 @@ void set_cursor()
ui::root()->set_pointer();
- } else if (client()->view()->map()->hover()) {
+ } else if (client()->worldview()->playerview()->map()->hover()) {
ui::root()->set_pointer("pointer");
@@ -357,15 +356,15 @@ void frame(float elapsed)
render::draw_target(targets::current());
render::Camera::ortho();
- client()->view()->show();
+ client()->worldview()->show();
} else {
draw_loader();
- client()->view()->hide();
+ client()->worldview()->hide();
}
} else {
- client()->view()->hide();
+ client()->worldview()->hide();
render::Camera::ortho();
}
diff --git a/src/client/view.cc b/src/client/view.cc
deleted file mode 100644
index 68df0e3..0000000
--- a/src/client/view.cc
+++ /dev/null
@@ -1,276 +0,0 @@
-/*
- view.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 <GL/gl.h>
-
-#include <iostream>
-#include <string>
-#include <sstream>
-#include <iomanip>
-
-#include "auxiliary/functions.h"
-#include "client/client.h"
-#include "client/chat.h"
-#include "client/input.h"
-#include "client/targets.h"
-#include "client/video.h"
-#include "client/view.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
-{
-
-void time_to_stream(std::stringstream &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;
-}
-
-/* -- DevInfo------------------------------------------------------- */
-
-DevInfo::DevInfo(ui::Widget *parent) : ui::Widget(parent)
-{
- set_label("devinfo");
- set_border(false);
- set_background(false);
-}
-
-void DevInfo::draw()
-{
- std::stringstream textstream;
- core::Entity *target = targets::current();
- float d = 0;
-
- 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 << 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->location()) - target->radius() - core::localcontrol()->radius();
- textstream << "^Ndist ^B" << d << '\n';
- }
- }
-
- ui::paint::color(palette()->foreground());
- ui::paint::text(global_location(), size(), font(), textstream);
-}
-
-/* -- Stats -------------------------------------------------------- */
-
-Stats::Stats(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 Stats::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 - 1.0f) / t);
- }
-
- std::stringstream 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 << "^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(), size(), font(), textstream);
-}
-
-/* -- KeyPress ----------------------------------------------------- */
-
-KeyPress::KeyPress(ui::Widget *parent) : Widget(parent)
-{
- set_label("keypress");
- set_border(false);
- set_background(false);
-}
-
-void KeyPress::draw()
-{
- std::string label;
- ui::paint::color(palette()->highlight());
-
- Key::Modifier mod = input::modifier();
- 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::label(global_location(), size(), font(), label , ui::AlignCenter);
-}
-
-/* -- View --------------------------------------------------------- */
-
-View::View(ui::Widget *parent) : ui::Widget(parent)
-{
- set_label("view");
- set_border(false);
-
- // add child widgets
- view_devinfo = new DevInfo(this);
- view_stats = new Stats(this);
- view_keypress = new KeyPress(this);
- view_notify = new Notifications(this);
- view_chat = new Chat(this);
- view_map = new Map(this);
- view_hud = new HUD(this);
-
- // make sure the view is at the bottom of the draw stack
- lower();
-}
-
-void View::resize()
-{
- set_size(parent()->size());
-
- // set hud geometry
- view_hud->set_geometry(0,0, width(), height());
- view_hud->event_resize();
-
- // 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);
-
- // reposition map
- view_map->set_size(width() - font()->width() * 8, height() - font()->height() * 8);
- view_map->set_location(font()->width() * 4, font()->height() * 4);
-
- // reposition notifications
- view_notify->set_location(ui::UI::elementsize.width()*2.0f+ font()->width(), view_devinfo->top() + view_devinfo->height() + font()->height());
- view_notify->set_size(width() - ui::UI::elementsize.width()*2.0f - font()->width() * 2, height() * 0.5f - view_notify->top());
-}
-
-void View::draw()
-{
- // view is only drawn when the application is connected
-
- // draw hud only when connected and controlling a spacecraft
- if (core::localcontrol() && !ui::root()->active()) {
- view_hud->set_visible(true);
- } else {
- view_hud->set_visible(false);
- }
-
- // reposition chat widget
- if (view_chat->small_view()) {
- view_chat->set_size(width() - font()->width() * 8, font()->height() * 2);
- view_chat->set_location(font()->width() * 4, height() - font()->height() * 4 - view_chat->height());
- } else {
- view_chat->set_size(width() - font()->width() * 8, height() - font()->height() * 8);
- view_chat->set_location(font()->width() * 4, font()->height() * 4);
- }
- view_chat->event_resize();
-
- 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);
-
- if (core::game()->interactive()) {
- if (ui::console()->visible()) {
- view_notify->set_visible(false);
- } else if (view_chat->visible() && !view_chat->small_view()) {
- view_notify->set_visible(false);
- } else {
- view_notify->set_visible(true);
- }
- } else {
- view_notify->set_visible(false);
- view_chat->set_visible(false);
- }
-
- if (!core::localcontrol()) {
- view_map->set_visible(false);
- }
-}
-
-} // namespace client
-
diff --git a/src/client/view.h b/src/client/view.h
deleted file mode 100644
index 499f6ec..0000000
--- a/src/client/view.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- client/view.h
- This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
-*/
-
-#ifndef __INCLUDED_CLIENT_VIEW_H__
-#define __INCLUDED_CLIENT_VIEW_H__
-
-#include "core/zone.h"
-#include "client/chat.h"
-#include "client/hud.h"
-#include "client/map.h"
-#include "client/notifications.h"
-#include "ui/widget.h"
-#include "ui/bitmap.h"
-
-namespace client
-{
-
-const size_t fps_counter_size = 32; // fps is the average of 32 frames
-const size_t net_counter_size = 128; // net is the average of 128 frames
-
-/// a widget to show developer info
-class DevInfo : public ui::Widget
-{
-public:
- /// default constructor
- DevInfo(ui::Widget *parent = 0);
-
-protected:
- /// draw developer info
- virtual void draw();
-};
-
-/// a widget that shows engine statistics
-class Stats : public ui::Widget
-{
-public:
- /// default constructor
- Stats(ui::Widget *parent=0);
-
-protected:
- /// draw engine statistics
- virtual void draw();
-
-private:
- float fps_counter_time[fps_counter_size];
- size_t fps_counter_index;
-
- float net_counter_time[net_counter_size];
- size_t net_counter_traffic[net_counter_size];
- size_t net_counter_index;
-};
-
-/// a widget to show keypress events
-class KeyPress : public ui::Widget
-{
-public:
- // default constructor
- KeyPress(ui::Widget *parent=0);
-
-protected:
- // draw keypress events
- virtual void draw();
-};
-
-/// the client view widget
-/**
-* the client view renders the world and contains the main user interface widgets
-*/
-class View : public ui::Widget
-{
-public:
- View(ui::Widget *parent=0);
-
- inline Map *map() { return view_map; }
- inline Chat *chat() { return view_chat; }
- inline Notifications *notify() { return view_notify; }
-
-protected:
- virtual void draw();
-
- virtual void resize();
-
-private:
- HUD *view_hud;
- Chat *view_chat;
- DevInfo *view_devinfo;
- Stats *view_stats;
- KeyPress *view_keypress;
- Notifications *view_notify;
- Map *view_map;
-};
-
-namespace view {
-
-void draw_hud();
-
-}
-
-} // namespace client
-
-#endif // __INCLUDED_CLIENT_VIEW_H__
-