diff options
Diffstat (limited to 'src/client')
40 files changed, 717 insertions, 624 deletions
diff --git a/src/client/action.cc b/src/client/action.cc index b86476e..7c7a34c 100644 --- a/src/client/action.cc +++ b/src/client/action.cc @@ -21,7 +21,8 @@ Action::~Action() { } -void Action::set_info(const char *info) { +void Action::set_info(const char *info) +{ if (info) action_info.assign(info); else diff --git a/src/client/action.h b/src/client/action.h index c7086c8..778c40d 100644 --- a/src/client/action.h +++ b/src/client/action.h @@ -9,26 +9,33 @@ #include <string> -namespace client { +namespace client +{ /// an Action that can be bound to a key class Action { public: /// actions - enum Identifier {None=0}; + enum Identifier {None = 0}; /// define a new action Action(const char *name, Identifier action, const char *info = 0); ~Action(); - + /// name of the Action - inline std::string const & name() const { return action_name; } + inline std::string const & name() const { + return action_name; + } /// Action Identifier - inline Identifier id() const { return action_id; } + inline Identifier id() const { + return action_id; + } - inline std::string const & info() const { return action_info; } + inline std::string const & info() const { + return action_info; + } /// set info void set_info(const char *info); diff --git a/src/client/buymenu.cc b/src/client/buymenu.cc index 8c69a7a..d12f23e 100644 --- a/src/client/buymenu.cc +++ b/src/client/buymenu.cc @@ -16,9 +16,9 @@ namespace client BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent) { set_border(false); - set_background(true); + set_background(true); - if (label) + if (label) set_label(label); else set_label("buymenu"); @@ -34,7 +34,7 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent) menu_modelview->set_background(false); menu_modelview->set_border(false); - menu_closebutton = new ui::Button(menu_modelpane, "Close","view hide"); + menu_closebutton = new ui::Button(menu_modelpane, "Close", "view hide"); // text pane (right) menu_textpane = new ui::Window(this); @@ -48,7 +48,7 @@ BuyMenu::BuyMenu(ui::Widget *parent, const char * label) : ui::Window(parent) menu_namelabel->set_border(false); menu_namelabel->set_font(ui::root()->font_large()); menu_namelabel->set_alignment(ui::AlignCenter); - + menu_scrollpane = new ui::ScrollPane(menu_textpane, menu_infotext); menu_scrollpane->set_background(false); menu_scrollpane->set_border(false); @@ -83,7 +83,7 @@ void BuyMenu::set_item(std::string const & itemtype, std::string const & itemnam menu_namelabel->set_text(0); menu_modelview->set_modelname(0); - core::Info *info = core::game()->info(itemtype+'/'+itemname); + core::Info *info = core::game()->info(itemtype + '/' + itemname); if (info) { menu_namelabel->set_text(info->name()); menu_modelview->set_modelname(info->modelname()); @@ -111,10 +111,10 @@ void BuyMenu::resize() menu_modelpane->set_location(smallmargin, smallmargin * 2.0f); menu_closebutton->set_size(ui::UI::elementsize); - menu_closebutton->set_location((menu_modelpane->width() - menu_closebutton->width()) * 0.5f, - menu_modelpane->height() - menu_closebutton->height() - ui::UI::elementsize.height() * 0.5f); + menu_closebutton->set_location((menu_modelpane->width() - menu_closebutton->width()) * 0.5f, + menu_modelpane->height() - menu_closebutton->height() - ui::UI::elementsize.height() * 0.5f); - menu_modelview->set_size(menu_modelpane->width()-8, menu_modelpane->width()-8); + menu_modelview->set_size(menu_modelpane->width() - 8, menu_modelpane->width() - 8); menu_modelview->set_location(4, 4); // reposition text pane (right) @@ -122,13 +122,13 @@ void BuyMenu::resize() menu_textpane->set_location(smallmargin * 2.0f + menu_modelpane->width(), smallmargin * 2.0f); menu_buybutton->set_size(ui::UI::elementsize); - menu_buybutton->set_location((menu_textpane->width() - menu_buybutton->width()) * 0.5f, - menu_textpane->height() - menu_buybutton->height() - ui::UI::elementsize.height() * 0.5f); + menu_buybutton->set_location((menu_textpane->width() - menu_buybutton->width()) * 0.5f, + menu_textpane->height() - menu_buybutton->height() - ui::UI::elementsize.height() * 0.5f); menu_namelabel->set_size(menu_textpane->width(), menu_namelabel->font()->height() * 2.0f); menu_namelabel->set_location(0, 4); - menu_scrollpane->set_size(menu_textpane->width() - 8, menu_buybutton->top() - menu_namelabel->bottom() - 8 ); + menu_scrollpane->set_size(menu_textpane->width() - 8, menu_buybutton->top() - menu_namelabel->bottom() - 8); menu_scrollpane->set_location(4, menu_namelabel->bottom() + 4); } @@ -142,14 +142,14 @@ void BuyMenu::draw() bool BuyMenu::on_keypress(const int key, const unsigned int modifier) { - switch( key ) { - - case SDLK_ESCAPE: - this->hide(); - return true; - break; - default: - break; + switch (key) { + + case SDLK_ESCAPE: + this->hide(); + return true; + break; + default: + break; } return Window::on_keypress(key, modifier); diff --git a/src/client/buymenu.h b/src/client/buymenu.h index 6a1a651..f624ec3 100644 --- a/src/client/buymenu.h +++ b/src/client/buymenu.h @@ -1,7 +1,7 @@ /* client/buymenu.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_BUYMENU_H__ diff --git a/src/client/chat.cc b/src/client/chat.cc index 137e6b1..5eb1922 100644 --- a/src/client/chat.cc +++ b/src/client/chat.cc @@ -1,7 +1,7 @@ /* client/chat.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 + 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 "auxiliary/functions.h" @@ -11,7 +11,8 @@ #include "sys/sys.h" #include "ui/ui.h" -namespace client { +namespace client +{ const size_t DEFAULT_CHAT_LOG_SIZE = 2048; const size_t DEFAULT_CHAT_HISTO_SIZE = 512; @@ -69,7 +70,7 @@ void Chat::show() history_pos = history.rbegin(); (*history_pos).clear(); - chat_input->set_text((*history_pos)); + chat_input->set_text((*history_pos)); chat_scrollpane->set_scroll(0); } @@ -89,67 +90,67 @@ bool Chat::on_keypress(const int key, const unsigned int modifier) History::reverse_iterator upit; - switch( key ) { - case SDLK_ESCAPE: - if (visible()) { - hide(); + switch (key) { + case SDLK_ESCAPE: + if (visible()) { + hide(); + return true; + } else { + return false; + } + case SDLK_RETURN: + if (chat_input->text().size()) { + // store input into history + while (history.size() >= DEFAULT_CHAT_HISTO_SIZE) { + history.pop_front(); + } + + if (chat_input->text().c_str()[0] == '/' || chat_input->text().c_str()[0] == '\\') { + core::cmd() << &chat_input->text().c_str()[1] << std::endl; + } else { + core::cmd() << "say " << chat_input->text() << std::endl; + } + (*history.rbegin()) = chat_input->text(); + + history.push_back(""); + history_pos = history.rbegin(); + chat_input->set_text((*history_pos)); + + if (chat_small) + hide(); + } else { + hide(); + } return true; - } else { - return false; - } - case SDLK_RETURN: - if (chat_input->text().size()) { - // store input into history - while (history.size() >= DEFAULT_CHAT_HISTO_SIZE) { - history.pop_front(); + break; + + case SDLK_UP: + upit = history_pos; + ++upit; + if (upit != history.rend()) { + history_pos = upit; + chat_input->set_text((*history_pos)); } + return true; + break; - if (chat_input->text().c_str()[0] == '/' || chat_input->text().c_str()[0] == '\\') { - core::cmd() << &chat_input->text().c_str()[1] << std::endl; - } else { - core::cmd() << "say " << chat_input->text() << std::endl; + case SDLK_DOWN: + if (history_pos != history.rbegin()) { + --history_pos; + chat_input->set_text((*history_pos)); } - (*history.rbegin()) = chat_input->text(); + return true; + break; - history.push_back(""); - history_pos = history.rbegin(); - chat_input->set_text((*history_pos)); + case SDLK_PAGEUP: + chat_scrollpane->inc_scroll(scroll_offset); + return true; + break; - if (chat_small) - hide(); - } else { - hide(); - } - return true; - break; - - case SDLK_UP: - upit = history_pos; - ++upit; - if (upit != history.rend()) { - history_pos = upit; - chat_input->set_text((*history_pos)); - } - return true; - break; - - case SDLK_DOWN: - if (history_pos != history.rbegin()) { - --history_pos; - chat_input->set_text((*history_pos)); - } - return true; - break; - - case SDLK_PAGEUP: - chat_scrollpane->inc_scroll(scroll_offset); - return true; - break; - - case SDLK_PAGEDOWN: - chat_scrollpane->dec_scroll(scroll_offset); - return true; - break; + case SDLK_PAGEDOWN: + chat_scrollpane->dec_scroll(scroll_offset); + return true; + break; } return false; @@ -169,7 +170,7 @@ void Chat::event_draw() hide(); return; } - + if (chat_small) { chat_scrollpane->hide(); } else { @@ -183,12 +184,12 @@ void Chat::resize() const float margin = 8.0f; math::Vector2f s(size()); - s[0] -= margin*2; - s[1] -= margin*2; + s[0] -= margin * 2; + s[1] -= margin * 2; chat_scrollpane->set_location(margin, margin); chat_scrollpane->set_size(s.width(), s.height() - font()->height() *1.5f); - + chat_input->set_location(margin, height() - font()->height() - margin); chat_input->set_size(s.width(), font()->height()); } diff --git a/src/client/chat.h b/src/client/chat.h index b7e1691..41837c5 100644 --- a/src/client/chat.h +++ b/src/client/chat.h @@ -1,7 +1,7 @@ /* client/chat.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_CHAT_H__ @@ -14,7 +14,8 @@ #include "ui/scrollpane.h" #include "ui/window.h" -namespace client { +namespace client +{ class Chat : public ui::Window { @@ -26,19 +27,21 @@ public: void toggle(); void event_text(const std::string & text); - - inline bool small_view() const { return chat_small; } - - void set_small_view(bool small_view=true); + + inline bool small_view() const { + return chat_small; + } + + void set_small_view(bool small_view = true); void clear(); protected: virtual void event_draw(); virtual void resize(); - + virtual bool on_keypress(const int key, const unsigned int modifier); - + private: bool chat_small; @@ -46,9 +49,9 @@ private: ui::Text chat_log; ui::ScrollPane *chat_scrollpane; ui::InputBox *chat_input; - + typedef std::deque<std::string> History; - + History history; History::reverse_iterator history_pos; }; diff --git a/src/client/client.cc b/src/client/client.cc index 1fa2796..6a50743 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -1,7 +1,7 @@ /* client/client.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 + 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 <SDL/SDL.h> @@ -22,7 +22,7 @@ #include "render/render.h" #include "ui/ui.h" -namespace client +namespace client { core::Cvar *cl_framerate = 0; @@ -42,7 +42,7 @@ void run(int count, char **arguments) { std::cout << core::name() << " " << core::version() << std::endl; - for (int i =0; i < count; i++) + for (int i = 0; i < count; i++) std::cout << arguments[i] << " "; std::cout << std::endl; @@ -104,7 +104,7 @@ void Client::init(int count, char **arguments) // initialize audio audio::init(); - + // add engine functions core::Func *func = 0; @@ -116,19 +116,19 @@ void Client::init(int count, char **arguments) func = core::Func::add("list_ui", func_list_ui); func->set_info("list user interface widgets"); - + func = core::Func::add("list_menu", func_list_menu); func->set_info("list available menus"); - + func = core::Func::add("ui", func_ui); func->set_info("[command] user interface functions"); - + func = core::Func::add("ui_restart", func_ui_restart); func->set_info("reload user interface files"); func = core::Func::add("ui_console", func_ui_console); func->set_info("toggle console"); - + func = core::Func::add("ui_chat", Client::func_ui_chat); func->set_info("toggle chat window"); @@ -160,14 +160,14 @@ void Client::run() // default framerate 125fps, 8 milliseconds Uint32 client_frame_lenght = 8; - + Uint32 client_current_timestamp = 0; Uint32 client_previous_timestamp = 0; - + while (true) { // current time in microseconds client_current_timestamp = SDL_GetTicks(); - + // calculate the desired frame length if (cl_framerate->value() < 0) { (*cl_framerate) = 0.0f; @@ -180,12 +180,12 @@ void Client::run() } else { client_frame_lenght = 0; } - + // only advance per microsecond frame Uint32 d = client_current_timestamp - client_previous_timestamp; if ((d > 0)) { if (d >= client_frame_lenght) { - frame(client_current_timestamp); + frame(client_current_timestamp); client_previous_timestamp = client_current_timestamp; } else { SDL_Delay(client_frame_lenght - d); @@ -222,7 +222,7 @@ void Client::frame(unsigned long timestamp) if (!core::game()->interactive()) { ui::root()->show_menu("main"); - // show the join menu when player does not control an entity + // show the join menu when player does not control an entity } else if (core::game()->time() && !core::localcontrol()) { ui::root()->show_menu("join"); } @@ -231,13 +231,13 @@ void Client::frame(unsigned long timestamp) // hide join menu if (ui::root()->active()->label().compare("join") == 0) { - ui::root()->hide_menu(); + ui::root()->hide_menu(); } } } video::frame((float)(timestamp - previous_timestamp) / 1000.0f); - + previous_timestamp = timestamp; } @@ -248,7 +248,7 @@ void Client::shutdown() if (connected()) disconnect(); core::Func::remove("r_restart"); - core::Func::remove("snd_restart"); + core::Func::remove("snd_restart"); core::Func::remove("list_menu"); core::Func::remove("list_ui"); core::Func::remove("ui"); @@ -302,7 +302,7 @@ void Client::notify_zonechange() { video::set_loader_message(); video::frame_loader(); - + // unload entity sounds for (core::Entity::Registry::iterator it = core::Entity::registry().begin(); it != core::Entity::registry().end(); it++) { core::Entity *entity = (*it).second; @@ -333,7 +333,7 @@ void Client::notify_message(const std::string &message) void Client::notify_message(const core::Message::Channel channel, const std::string &message) { - switch(channel) { + switch (channel) { case core::Message::Info: // Info message break; @@ -363,7 +363,8 @@ void Client::notify_message(const core::Message::Channel channel, const std::str con_print << message << std::endl; } -void Client::notify_loader(const std::string &message) { +void Client::notify_loader(const std::string &message) +{ video::set_loader_message(message.c_str()); } @@ -436,7 +437,7 @@ void Client::func_ui(std::string const &args) con_warn << "User Interface not available!" << std::endl; return; } - + if (!args.size()) { func_ui_help(); return; @@ -445,7 +446,7 @@ void Client::func_ui(std::string const &args) std::string command; argstr >> command; aux::to_label(command); - + if (command.compare("help") == 0) { func_ui_help(); } else if (command.compare("debug") == 0) { @@ -517,7 +518,7 @@ void Client::func_menu(std::string const &args) con_warn << "User Interface not available!" << std::endl; return; } - + if (!args.size()) { con_print << "^Bmenu functions" << std::endl; con_print << " menu help show this help" << std::endl; @@ -533,21 +534,21 @@ void Client::func_menu(std::string const &args) std::stringstream argstr(args); std::string command; argstr >> command; - + aux::to_label(command); - + if (command.compare("hide") == 0) { ui::root()->hide_menu(); - + } else if (command.compare("close") == 0) { ui::root()->hide_menu(); - + } else if (command.compare("back") == 0) { ui::root()->previous_menu(); - + } else if (command.compare("previous") == 0) { ui::root()->previous_menu(); - + } else if (command.compare("list") == 0) { ui::root()->list_menus(); diff --git a/src/client/client.h b/src/client/client.h index dbb2c44..fd762c6 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -1,7 +1,7 @@ /* client/client.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 + 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_H__ @@ -16,7 +16,8 @@ #include "render/renderext.h" /// client part of the engine -namespace client { +namespace client +{ /// run the client application void run(int count, char **arguments); @@ -62,7 +63,9 @@ public: virtual void notify_disconnect(); /// the main client widget - inline WorldView *worldview() { return client_worldview; } + inline WorldView *worldview() { + return client_worldview; + } protected: /// run a client frame @@ -95,14 +98,20 @@ private: Client *client(); -inline ClientExt *ext_client(core::Entity *entity) - { return static_cast<ClientExt *>(entity->extension(core::Extension::Client)); } +inline ClientExt *ext_client(core::Entity *entity) +{ + return static_cast<ClientExt *>(entity->extension(core::Extension::Client)); +} -inline SoundExt *ext_sound(core::Entity *entity) - { return static_cast<SoundExt *>(entity->extension(core::Extension::Sound)); } +inline SoundExt *ext_sound(core::Entity *entity) +{ + return static_cast<SoundExt *>(entity->extension(core::Extension::Sound)); +} -inline render::RenderExt *ext_render(core::Entity *entity) - { return static_cast<render::RenderExt *>(entity->extension(core::Extension::Render)); } +inline render::RenderExt *ext_render(core::Entity *entity) +{ + return static_cast<render::RenderExt *>(entity->extension(core::Extension::Render)); +} } diff --git a/src/client/clientext.h b/src/client/clientext.h index d76546d..123c4c0 100644 --- a/src/client/clientext.h +++ b/src/client/clientext.h @@ -13,7 +13,8 @@ namespace client { /// the client extension of an entity -class ClientExt :public core::Extension { +class ClientExt : public core::Extension +{ public: ClientExt(core::Entity *entity); ~ClientExt(); @@ -21,7 +22,7 @@ public: virtual void frame(float elapsed); private: - + }; } // namespace client diff --git a/src/client/entitymenu.cc b/src/client/entitymenu.cc index 59c922c..d0fccef 100644 --- a/src/client/entitymenu.cc +++ b/src/client/entitymenu.cc @@ -15,7 +15,7 @@ namespace client EntityMenu::EntityMenu(ui::Widget *parent, const char * label) : ui::Window(parent) { set_border(false); - set_background(false); + set_background(false); if (label) set_label(label); else @@ -58,9 +58,9 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) menu_generated_menu.assign(menulabel); if (!menu_generated_menu.size()) return; - + //con_debug << "generating menu " << entity->label() << " " << menulabel << std::endl; - + clear(); menu_container = new Container(this); @@ -70,7 +70,7 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) menudescr = (*it); } } - + if (!menudescr) { menu_container->event_resize(); resize(); @@ -100,36 +100,36 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) if (c == '"') { quote = !quote; result += c; - + } else if (c == ';') { if (quote) { current += c; - + } else if (current.size()) { if (buttondescr->command_type() == core::ButtonDescription::CommandGame) { if (result.size()) { result += ';'; } - + result.append("remote "); result.append(current); - + } else if (buttondescr->command_type() == core::ButtonDescription::CommandMenu) { if (result.size()) { result += ';'; } - + result.append("view "); result.append(current); } current.clear(); } - + } else { current += c; } - + i++; } @@ -174,21 +174,21 @@ void EntityMenu::generate(core::Entity *entity, const char *menulabel) bool EntityMenu::on_keypress(const int key, const unsigned int modifier) { - switch( key ) { - - case SDLK_ESCAPE: - if (visible()) { - if (menu_generated_menu.compare("main") != 0) { - generate(menu_generated_entity, "main"); - } else { - this->hide(); - ui::root()->show_menu("game"); + switch (key) { + + case SDLK_ESCAPE: + if (visible()) { + if (menu_generated_menu.compare("main") != 0) { + generate(menu_generated_entity, "main"); + } else { + this->hide(); + ui::root()->show_menu("game"); + } + return true; } - return true; - } - break; - default: - break; + break; + default: + break; } return Window::on_keypress(key, modifier); diff --git a/src/client/entitymenu.h b/src/client/entitymenu.h index db69867..0285879 100644 --- a/src/client/entitymenu.h +++ b/src/client/entitymenu.h @@ -26,13 +26,17 @@ public: /* ---- inspectors ----------------------------------------- */ /// entity the current menu was generated for - inline core::Entity *generated_entity() { return menu_generated_entity; } + inline core::Entity *generated_entity() { + return menu_generated_entity; + } /// the current generated menu - inline const std::string & generated_menu() const { return menu_generated_menu; } + inline const std::string & generated_menu() const { + return menu_generated_menu; + } /* ---- mutators ------------------------------------------- */ - + /// generate a menu from menu descriptions void generate(core::Entity *entity, const char *menulabel); diff --git a/src/client/hud.cc b/src/client/hud.cc index 662bbe8..b7e2c43 100644 --- a/src/client/hud.cc +++ b/src/client/hud.cc @@ -1,7 +1,7 @@ /* client/hud.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 + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ @@ -13,7 +13,7 @@ #include "render/renderext.h" #include "ui/ui.h" -namespace client +namespace client { HUD::HUD(ui::Widget *parent) : Widget(parent) @@ -30,7 +30,7 @@ HUD::HUD(ui::Widget *parent) : Widget(parent) */ hud_center = new ui::Bitmap(this, "pointers/center"); hud_center->set_color(palette()->pointer()); - + } void HUD::resize() @@ -50,11 +50,11 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target) float cx = 0; float cy = 0; - if ( target.y() * target.y() + target.z() * target.z() < 0.0001 ) { + if (target.y() * target.y() + target.z() * target.z() < 0.0001) { // X - bound, behind (front is visible) cx = 0.0f; cy = -0.5f; - + } else if (fabs(target.y()) > fabs(target.z())) { // Y-bound cx = math::sgnf(target.y()) * 0.5f; @@ -67,18 +67,18 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target) const float r = 16; const float margin = 24; - cx = (0.5f - cx) * ((float) render::State::width() - margin*2); + cx = (0.5f - cx) * ((float) render::State::width() - margin * 2); cx += margin; - cy = (0.5f - cy) * ((float) render::State::height() - margin*2); + cy = (0.5f - cy) * ((float) render::State::height() - margin * 2); cy += margin; gl::disable(GL_TEXTURE_2D); gl::color(0, 0, 0, 1); gl::begin(gl::LineLoop); - glVertex3f(cx+r, cy+2, 0); - glVertex3f(cx, cy+r+2, 0); - glVertex3f(cx-r, cy+2, 0); - glVertex3f(cx, cy-r+2, 0); + glVertex3f(cx + r, cy + 2, 0); + glVertex3f(cx, cy + r + 2, 0); + glVertex3f(cx - r, cy + 2, 0); + glVertex3f(cx, cy - r + 2, 0); gl::end(); if (entity == core::localplayer()->mission_target()) { @@ -90,10 +90,10 @@ void HUD::draw_offscreen_target(core::Entity *entity, bool is_active_target) } gl::begin(gl::LineLoop); - glVertex3f(cx+r, cy, 0); - glVertex3f(cx, cy+r, 0); - glVertex3f(cx-r, cy, 0); - glVertex3f(cx, cy-r, 0); + glVertex3f(cx + r, cy, 0); + glVertex3f(cx, cy + r, 0); + glVertex3f(cx - r, cy, 0); + glVertex3f(cx, cy - r, 0); gl::end(); gl::enable(GL_TEXTURE_2D); } @@ -108,7 +108,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) // don't draw target if it is outside the visible cone Vector3f target(entity->location() - render::Camera::eye()); - if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75 ) { + if (math::dotproduct(render::Camera::axis().forward(), Vector3f::normalized(target)) < 0.75) { draw_offscreen_target(entity, is_active_target); return; } @@ -123,7 +123,7 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) float cx = render::State::width() * (0.5 - center.y()); float cy = render::State::height() * (0.5 - center.z() * render::State::aspect()); - if ((cx < 0 ) || (cy < 0) || (cx > render::State::width()) || (cy > render::State::height())) { + if ((cx < 0) || (cy < 0) || (cx > render::State::width()) || (cy > render::State::height())) { draw_offscreen_target(entity, is_active_target); return; } @@ -136,18 +136,18 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) // outer square shadow gl::color(0, 0, 0, 1); gl::begin(gl::LineLoop); - gl::vertex(cx+r, cy+2); - gl::vertex(cx, cy+r+2); - gl::vertex(cx-r, cy+2); - gl::vertex(cx, cy-r+2); + gl::vertex(cx + r, cy + 2); + gl::vertex(cx, cy + r + 2); + gl::vertex(cx - r, cy + 2); + gl::vertex(cx, cy - r + 2); gl::end(); if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) { gl::begin(gl::LineLoop); - gl::vertex(cx+ (r*0.25f), cy+2); - gl::vertex(cx, cy+(r*0.25f)+2); - gl::vertex(cx-(r*0.25f), cy+2); - gl::vertex(cx, cy-(r*0.25f)+2); + gl::vertex(cx + (r*0.25f), cy + 2); + gl::vertex(cx, cy + (r*0.25f) + 2); + gl::vertex(cx - (r*0.25f), cy + 2); + gl::vertex(cx, cy - (r*0.25f) + 2); gl::end(); } @@ -161,28 +161,28 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) // outer square0 gl::begin(gl::LineLoop); - gl::vertex(cx+r, cy); - gl::vertex(cx, cy+r); - gl::vertex(cx-r, cy); - gl::vertex(cx, cy-r); + gl::vertex(cx + r, cy); + gl::vertex(cx, cy + r); + gl::vertex(cx - r, cy); + gl::vertex(cx, cy - r); gl::end(); - + if ((entity->flags() & core::Entity::Dockable) == core::Entity::Dockable) { gl::begin(gl::LineLoop); - gl::vertex(cx+(r*0.25f), cy); - gl::vertex(cx, cy+(r*0.25f)); - gl::vertex(cx-(r*0.25f), cy); - gl::vertex(cx, cy-(r*0.25f)); + gl::vertex(cx + (r*0.25f), cy); + gl::vertex(cx, cy + (r*0.25f)); + gl::vertex(cx - (r*0.25f), cy); + gl::vertex(cx, cy - (r*0.25f)); gl::end(); } - + gl::enable(GL_TEXTURE_2D); if (is_active_target) { // entity name and distance std::stringstream strdistance; float d = math::distance(core::localcontrol()->location(), entity->location()) - entity->radius() - core::localcontrol()->radius(); - if (d > 0 ) { + if (d > 0) { if (d > 100.0f) { strdistance << roundf(d * 0.1f) << "km"; } else { @@ -197,8 +197,8 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) const core::EntityControlable *ec = static_cast<core::EntityControlable *>(entity); if (ec->owner()) { render::Text::setcolor('B'); - render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f, - cy-r-4-2*render::Text::fontheight(), ec->owner()->name()); + render::Text::draw(cx - aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f, + cy - r - 4 - 2*render::Text::fontheight(), ec->owner()->name()); } render::Text::setcolor('B'); @@ -209,24 +209,24 @@ void HUD::draw_target(core::Entity *entity, bool is_active_target) render::Text::setcolor('N'); } - render::Text::draw(cx-aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f, - cy-r-4-render::Text::fontheight(), entity->name()); + render::Text::draw(cx - aux::text_length(entity->name()) * render::Text::fontwidth()*0.5f, + cy - r - 4 - render::Text::fontheight(), entity->name()); render::Text::draw(cx - aux::text_length(strdistance.str()) * render::Text::fontwidth() * 0.5f, - cy+r+4, strdistance); + cy + r + 4, strdistance); } } bool HUD::on_keypress(const int key, const unsigned int modifier) { - switch( key ) { - case SDLK_ESCAPE: - if (targets::current()) { - targets::reset(); - } else { - ui::root()->show_menu("game"); - } - return true; + switch (key) { + case SDLK_ESCAPE: + if (targets::current()) { + targets::reset(); + } else { + ui::root()->show_menu("game"); + } + return true; } return false; @@ -238,21 +238,21 @@ void HUD::draw() std::stringstream status; if (core::localcontrol() && (input::mouse_control || input::joystick_control) && - (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { hud_center->set_visible(true); } else { hud_center->set_visible(false); } - + gl::enable(GL_TEXTURE_2D); Text::setfont("gui", 12, 18); Text::setcolor('N'); //set normal color - + core::Zone *zone = core::localcontrol()->zone(); // draw HUD targets - for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) { + for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { core::Entity *entity = (*it); if (entity == targets::current()) { @@ -261,11 +261,12 @@ void HUD::draw() } else if (entity == core::localplayer()->mission_target()) { draw_target(entity, false); - } else if ((entity->type() == core::Entity::Controlable) && (targets::is_valid_hud_target(entity))){ + } else if ((entity->type() == core::Entity::Controlable) && (targets::is_valid_hud_target(entity))) { draw_target(entity, false); } } + /* unsigned int state = core::localcontrol()->state(); if (state) { std::stringstream statestr; @@ -275,13 +276,14 @@ void HUD::draw() } else if (state == core::Entity::Impulse) { //statestr << "^FKinetic impulse"; } else if (state == core::Entity::JumpInitiate) { - statestr << "^FInitializing hyperspace jump drive "<< core::localcontrol()->timer(); + statestr << "^FInitializing hyperspace jump drive " << core::localcontrol()->timer(); } else if (state == core::Entity::Jump) { statestr << "^FJumping..."; } - Text::draw(4, render::State::height() - Text::fontheight()*3-4, statestr); + Text::draw(4, render::State::height() - Text::fontheight()*3 - 4, statestr); } + */ core::Entity *target = targets::current(); std::stringstream strdistance; @@ -290,10 +292,10 @@ void HUD::draw() std::stringstream strtarget; strtarget << "^B" << target->name() << "\n^B"; - float d = math::distance(core::localcontrol()->location(), target->location()) - - target->radius() - core::localcontrol()->radius(); + float d = math::distance(core::localcontrol()->location(), target->location()) + - target->radius() - core::localcontrol()->radius(); - if (d > 0 ) { + if (d > 0) { strtarget << "^Ndist:^B "; if (d > 100.0f) { strtarget << roundf(d * 0.1f) << "km"; @@ -303,7 +305,7 @@ void HUD::draw() if (core::localcontrol()->speed() > 0.1f) { strtarget << "^N eta:^B "; - float eta = floorf(d / core::localcontrol()->speed() ); + float eta = floorf(d / core::localcontrol()->speed()); if (eta > 60.0f) { float etamin = floorf(eta / 60.0f); strtarget << etamin << "min "; @@ -315,13 +317,13 @@ void HUD::draw() strtarget << " --"; } strtarget << '\n'; - Text::draw(width() - 4-Text::fontwidth()*30, height() - Text::fontheight()*2 -4, strtarget); + Text::draw(width() - 4 - Text::fontwidth()*30, height() - Text::fontheight()*2 - 4, strtarget); } - // draw player info + // 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); + 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); @@ -342,14 +344,23 @@ void HUD::draw() gl::end(); float u = core::localcontrol()->thrust(); - if (core::localcontrol()->state() == core::Entity::Impulse) { - u = 1.0; + + if (core::localcontrol()->state() != core::Entity::Normal) { + + if ((core::localcontrol()->state() == core::Entity::Docked ) || (core::localcontrol()->state() == core::Entity::NoPower )) { + u = 0.0f; + } else { + + u = 1.0f; + } } - if (( u > 0) || (core::localcontrol()->state() == core::Entity::Impulse)) { + if ((u > 0) || (core::localcontrol()->state() == core::Entity::Impulse)) { - if (core::localcontrol()->state() == core::Entity::Impulse) { + if ((core::localcontrol()->state() == core::Entity::Impulse) || (core::localcontrol()->state() == core::Entity::ImpulseInitiate)) { gl::color(0, .8, 0); + } else if ((core::localcontrol()->state() == core::Entity::Jump) || (core::localcontrol()->state() == core::Entity::JumpInitiate)) { + gl::color(0.8f, 0.0f, 0.0f); } else { float d = math::absf(input::local_thrust - u); if (d > 0.1) { @@ -379,11 +390,11 @@ void HUD::draw() std::stringstream speedstr; speedstr << "^B" << roundf(core::localcontrol()->speed() * 100.0f); - Text::draw( 316+4+10, 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 - + gl::disable(GL_TEXTURE_2D); } diff --git a/src/client/hud.h b/src/client/hud.h index d89450f..bda6ea1 100644 --- a/src/client/hud.h +++ b/src/client/hud.h @@ -1,7 +1,7 @@ /* client/hud.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 + 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_HUD_H__ @@ -12,7 +12,7 @@ #include "ui/toolbar.h" #include "ui/widget.h" -namespace client +namespace client { /// widget that contains HUD elements @@ -21,10 +21,11 @@ namespace client * that are only visible if the client is connected * and the core is running an interactive module **/ -class HUD : public ui::Widget { +class HUD : public ui::Widget +{ public: /// create a new HUD widget - HUD(ui::Widget *parent=0); + HUD(ui::Widget *parent = 0); protected: /// draw hud elements diff --git a/src/client/infowidget.cc b/src/client/infowidget.cc index b30dfd7..da4103f 100644 --- a/src/client/infowidget.cc +++ b/src/client/infowidget.cc @@ -1,7 +1,7 @@ /* 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 + 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> @@ -28,7 +28,7 @@ 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); + int seconds = (int) floorf(time - (float) minutes * 60.0f); str << std::setfill(' ') << std::setw(4) << minutes << ":" << std::setfill('0') << std::setw(2) << seconds; } @@ -58,19 +58,19 @@ void DevInfoWidget::draw() 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'; + << "^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'; - + << "^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); } @@ -84,7 +84,7 @@ StatsInfoWidget::StatsInfoWidget(ui::Widget *parent) : ui::Widget(parent) set_background(false); // clear counters - for (size_t i =0; i < fps_counter_size; i++) + 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++) @@ -98,9 +98,9 @@ void StatsInfoWidget::draw() { // average fps fps_counter_time[fps_counter_index] = core::application()->time(); - fps_counter_index = (fps_counter_index + 1 ) % fps_counter_size; + 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++) + 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; @@ -135,7 +135,7 @@ void StatsInfoWidget::draw() 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"; + textstream << "^Nnet ^B" << std::setw(6) << roundf((float) traffic / d) << "\n"; } } } @@ -157,7 +157,7 @@ void KeyInfoWidget::draw() { std::string label; ui::paint::color(palette()->highlight()); - + Key::Modifier mod = input::modifier(); if (mod != Key::None) { if (mod == Key::Shift) @@ -168,7 +168,7 @@ void KeyInfoWidget::draw() label.assign("alt+"); } - if(input::last_key_pressed()) { + if (input::last_key_pressed()) { label.append(input::last_key_pressed()->name()); } diff --git a/src/client/infowidget.h b/src/client/infowidget.h index 2cea366..48d1c9a 100644 --- a/src/client/infowidget.h +++ b/src/client/infowidget.h @@ -1,7 +1,7 @@ /* client/infowidget.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 + 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_INFOWIDGET_H__ @@ -33,7 +33,7 @@ class StatsInfoWidget : public ui::Widget { public: /// default constructor - StatsInfoWidget(ui::Widget *parent=0); + StatsInfoWidget(ui::Widget *parent = 0); protected: /// draw engine statistics @@ -53,7 +53,7 @@ class KeyInfoWidget : public ui::Widget { public: // default constructor - KeyInfoWidget(ui::Widget *parent=0); + KeyInfoWidget(ui::Widget *parent = 0); protected: // draw keypress events diff --git a/src/client/input.cc b/src/client/input.cc index 8b49604..790af91 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -82,15 +82,18 @@ float joystick_lastmoved = 0; const float thruster_offset = 0.05f; -int mouse_position_x() { +int mouse_position_x() +{ return mouse_x; } -int mouse_position_y() { +int mouse_position_y() +{ return mouse_y; } -Key *last_key_pressed() { +Key *last_key_pressed() +{ return last_key; } @@ -130,6 +133,9 @@ void func_ui_control(std::string const &args) render::Camera::set_direction(0.0f); render::Camera::set_pitch(0.0f); } + + con_debug << "mouse control is " << ((input_mousecontrol->value()) ? "on" : "off") << std::endl; + audio::play("ui/control"); } @@ -193,7 +199,7 @@ void func_list_binds(std::string const &args) aux::to_lowercase(keyname); keyboard->bind(keyname, ""); } else { - keyboard->list_binds(); + keyboard->list_binds(); } } else { con_warn << "Keyboard handler not installed!" << std::endl; @@ -207,8 +213,8 @@ void func_bind(std::string const &args) std::string keyname; if (argstr >> keyname) { aux::to_lowercase(keyname); - if (args.size() > keyname.size()+1) { - keyboard->bind(keyname, args.substr(keyname.size()+1)); + if (args.size() > keyname.size() + 1) { + keyboard->bind(keyname, args.substr(keyname.size() + 1)); } else { keyboard->bind(keyname, ""); } @@ -249,7 +255,7 @@ void init() keyboard = new Keyboard(); - SDL_ShowCursor(SDL_DISABLE); + SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_EnableUNICODE(1); @@ -268,7 +274,7 @@ void init() input_mousedelay->set_info("[int] mouse click time-out in milliseconds"); core::Func *func = 0; - func = core::Func::add("ui_control",func_ui_control); + func = core::Func::add("ui_control", func_ui_control); func->set_info("toggle mouse control"); func = core::Func::add("list_joystick", func_list_joystick); @@ -280,7 +286,7 @@ void init() func = core::Func::add("list_keys", func_list_keys); func->set_info("list key names"); - func = core::Func::add("list_binds",func_list_binds); + func = core::Func::add("list_binds", func_list_binds); func->set_info("list keyb binds"); func = core::Func::add("bind", (core::FuncPtr) func_bind); @@ -319,17 +325,17 @@ void shutdown() core::Func::remove("unbindall"); core::Func::remove("screenshot"); - + core::Func::remove("ui_control"); core::Func::remove("ui_view"); - + if (keyboard) { keyboard->save_binds(); delete keyboard; keyboard = 0; } - SDL_ShowCursor(SDL_ENABLE); + SDL_ShowCursor(SDL_ENABLE); SDL_WM_GrabInput(SDL_GRAB_OFF); // SDL_DisableUNICODE(0); @@ -340,11 +346,11 @@ void action_press(Key const *key, std::string const &action) /* -- thruster ------------------------------------ */ if (action.compare("+thrustup") == 0) { local_thrust += thruster_offset; - + } else if (action.compare("+thrustdown") == 0) { local_thrust -= 2.0f * thruster_offset; - + /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { if (!mouse_control_override) { @@ -384,7 +390,7 @@ void action_press(Key const *key, std::string const &action) local_afterburner = -1.0f; /* -- camera control ------------------------------ */ - + } else if (action.compare("+zoomin") == 0) { render::Camera::set_zoom(-0.1f); @@ -392,16 +398,16 @@ void action_press(Key const *key, std::string const &action) render::Camera::set_zoom(+0.1f); } else if (action.compare("+camleft") == 0) { - render::Camera::set_direction( math::min(key->pressed() - core::application()->time(), 1.0f) ); + render::Camera::set_direction(math::min(key->pressed() - core::application()->time(), 1.0f)); } else if (action.compare("+camright") == 0) { - render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(),1.0f)); + render::Camera::set_direction(-math::min(key->pressed() - core::application()->time(), 1.0f)); } else if (action.compare("+camup") == 0) { - render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(),1.0f)); + render::Camera::set_pitch(math::min(key->pressed() - core::application()->time(), 1.0f)); } else if (action.compare("+camdown") == 0) { - render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(),1.0f)); + render::Camera::set_pitch(-math::min(key->pressed() - core::application()->time(), 1.0f)); } else con_warn << "Unknown action " << action << std::endl; } @@ -410,23 +416,23 @@ void action_release(Key *key, std::string const &action) { /* -- thruster ------------------------------------ */ if (action.compare("+thrustup") == 0) { - + } else if (action.compare("+thrustdown") == 0) { - + /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { if (mouse_control_override) { mouse_control_override = false; mouse_control_override_time = 0; - - if (!input_mousecontrol->value() || (joystick_control && mouse_control && - (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) { + + if (!input_mousecontrol->value() || (joystick_control && mouse_control && + (render::Camera::mode() == render::Camera::Track || render::Camera::mode() == render::Camera::Cockpit))) { local_direction = 0.0f; local_pitch = 0.0f; local_roll = 0.0f; - + render::Camera::set_direction(0.0f); render::Camera::set_pitch(0.0f); } @@ -463,7 +469,7 @@ void action_release(Key *key, std::string const &action) } else if (action.compare("+reverse") == 0) { local_afterburner = 0.0f; - /* -- camera control ------------------------------ */ + /* -- camera control ------------------------------ */ } else if (action.compare("+camleft") == 0) { render::Camera::set_direction(0.0f); @@ -478,12 +484,13 @@ void action_release(Key *key, std::string const &action) } } -Key::Modifier modifier() { - if ((keyboard_modifiers & Key::Shift) > 0 ) +Key::Modifier modifier() +{ + if ((keyboard_modifiers & Key::Shift) > 0) return Key::Shift; - else if ((keyboard_modifiers & Key::Ctrl) > 0 ) + else if ((keyboard_modifiers & Key::Ctrl) > 0) return Key::Ctrl; - else if ((keyboard_modifiers & Key::Alt) > 0 ) + else if ((keyboard_modifiers & Key::Alt) > 0) return Key::Alt; else return Key::None; @@ -514,7 +521,7 @@ void key_pressed(Key *key) render::Camera::set_direction(0.0f); render::Camera::set_pitch(0.0f); } - + if (ui::root()->input_key(true, Keyboard::translate_keysym(key->sym(), keyboard_modifiers), keyboard_modifiers)) { return; @@ -525,7 +532,7 @@ void key_pressed(Key *key) if (c == '@') { // target bind if (targets::current_id()) - core::cmd() << key->bind(modifier()) << " " << targets::current_id() <<"\n"; + core::cmd() << key->bind(modifier()) << " " << targets::current_id() << "\n"; } else if (c == '+') { // action bind action_press(key, key->bind(modifier())); @@ -550,13 +557,13 @@ void key_released(Key *key) if (core::application()->connected() && core::localcontrol()) { - // FIXME mouse release selection should be handled inside the hud - if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= (input_mousedelay->value()/1000.0f) ) ) { + // FIXME mouse release selection should be handled inside the hud + if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= (input_mousedelay->value() / 1000.0f))) { // hovering target selected targets::select_target(targets::hover()); - } - - + } + + // the release event must still be processed as usual char c = 0; c = key->bind(Key::None).c_str()[0]; @@ -585,7 +592,7 @@ void key_released(Key *key) void axis_event(int axis, int value) { // value is in range -32768 to 32767 - switch(axis) { + switch (axis) { case 0: // direction if (value >= 0) { local_direction = (float) value / 32767.0f; @@ -702,7 +709,7 @@ void frame() video::resize(event.resize.w, event.resize.h); break; - case SDL_MOUSEMOTION: + case SDL_MOUSEMOTION: mouse_x = event.motion.x; mouse_y = event.motion.y; mouse_moved = true; @@ -750,8 +757,8 @@ void frame() core::application()->shutdown(); return; break; - } - + } + if (key) { if (pressed) { key_pressed(key); @@ -772,7 +779,7 @@ void frame() delay = input_keydelay->value(); math::clamp(delay, 50.0f, 500.0f); } - + float repeat = 35.0f; // key repeat time-out in milliseconds if (input_keyrepeat) { repeat = input_keyrepeat->value(); @@ -783,14 +790,14 @@ void frame() (*input_keydelay) = delay; if (input_keyrepeat) (*input_keyrepeat) = repeat; - + repeat /= 1000.0f; delay /= 1000.0f; - + for (Keyboard::iterator it = keyboard->begin(); it != keyboard->end(); it++) { key = (*it).second; - if (key && (key->sym() < 512) && key->pressed()) { - if ((key->pressed()+delay < core::application()->time()) && (key->lastpressed()+repeat < core::application()->time())) { + if (key && (key->sym() < 512) && key->pressed()) { + if ((key->pressed() + delay < core::application()->time()) && (key->lastpressed() + repeat < core::application()->time())) { key->key_lastpressed = core::application()->time(); key_pressed(key); } @@ -803,7 +810,7 @@ void frame() if (core::application()->connected() && core::localcontrol()) { mouse_control = ui::console()->hidden() && !ui::root()->active() && ((input_mousecontrol->value() > 0) || (mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))); - + if (mouse_control && joystick_control && ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit))) { if (!(mouse_control_override && (mouse_control_override_time + (input_mousedelay->value() / 1000.0f) < core::application()->time()))) { mouse_control = false; @@ -817,30 +824,30 @@ void frame() // direction int l = mouse_x - (render::State::width() >> 1); - - if (abs(l) < ( deadzone_size >> 1 )) { + + if (abs(l) < (deadzone_size >> 1)) { // dead zone mouse_direction = 0; } else { l = (mouse_x - deadzone_size) - ((render::State::width() - deadzone_size) >> 1); - mouse_direction = float (-l) / (float) ((render::State::width() - deadzone_size) >> 1); + mouse_direction = float(-l) / (float)((render::State::width() - deadzone_size) >> 1); mouse_deadzone = false; } // pitch int h = mouse_y - (render::State::height() >> 1); - if (abs(h) < ( deadzone_size >> 1 )) { + if (abs(h) < (deadzone_size >> 1)) { // dead zone mouse_pitch = 0; } else { h = (mouse_y - deadzone_size) - ((render::State::height() - deadzone_size) >> 1); - mouse_pitch = float (-h) / (float) ((render::State::height() - deadzone_size) >> 1); + mouse_pitch = float(-h) / (float)((render::State::height() - deadzone_size) >> 1); mouse_deadzone = false; } if ((render::Camera::mode() == render::Camera::Track) || (render::Camera::mode() == render::Camera::Cockpit)) { - + //local_direction = mouse_direction * math::absf(mouse_direction); //local_pitch = mouse_pitch * math::absf(mouse_pitch); local_direction = mouse_direction; @@ -848,10 +855,10 @@ void frame() } else if (render::Camera::mode() == render::Camera::Free) { // squared values to smoothen camera movement - render::Camera::set_direction( -mouse_direction * math::absf(mouse_direction)); + render::Camera::set_direction(-mouse_direction * math::absf(mouse_direction)); render::Camera::set_pitch(-mouse_pitch * math::absf(mouse_pitch)); } - + } math::clamp(local_direction, -1.0f, 1.0f); @@ -866,7 +873,7 @@ void frame() core::localcontrol()->set_thrust(local_thrust); core::localcontrol()->set_direction(local_direction); - core::localcontrol()->set_pitch(local_pitch / render::State::aspect() ); + core::localcontrol()->set_pitch(local_pitch / render::State::aspect()); core::localcontrol()->set_roll(local_roll); core::localcontrol()->set_strafe(local_strafe); core::localcontrol()->set_afterburner(local_afterburner); diff --git a/src/client/joystick.cc b/src/client/joystick.cc index 486542e..c8f7f9d 100644 --- a/src/client/joystick.cc +++ b/src/client/joystick.cc @@ -24,13 +24,13 @@ void Joystick::init() int nbjoysticks = SDL_NumJoysticks(); if (nbjoysticks) { - for (int i=0; i < nbjoysticks; i++) { + for (int i = 0; i < nbjoysticks; i++) { SDL_Joystick *joystick = SDL_JoystickOpen(i); if (joystick) { - con_print << " joystick " << i+1 << ": " << - SDL_JoystickName(i) << " " << - SDL_JoystickNumAxes(joystick) << " axes " << - SDL_JoystickNumButtons(joystick) << " buttons " << std::endl; + con_print << " joystick " << i + 1 << ": " << + SDL_JoystickName(i) << " " << + SDL_JoystickNumAxes(joystick) << " axes " << + SDL_JoystickNumButtons(joystick) << " buttons " << std::endl; SDL_JoystickClose(joystick); } @@ -69,13 +69,13 @@ void Joystick::list() */ int nbjoysticks = SDL_NumJoysticks(); if (nbjoysticks) { - for (int i=0; i < nbjoysticks; i++) { + for (int i = 0; i < nbjoysticks; i++) { SDL_Joystick *joystick = SDL_JoystickOpen(i); if (joystick) { - con_print << " joystick " << i+1 << ": " << - SDL_JoystickName(i) << " " << - SDL_JoystickNumAxes(joystick) << " axes " << - SDL_JoystickNumButtons(joystick) << " buttons " << std::endl; + con_print << " joystick " << i + 1 << ": " << + SDL_JoystickName(i) << " " << + SDL_JoystickNumAxes(joystick) << " axes " << + SDL_JoystickNumButtons(joystick) << " buttons " << std::endl; SDL_JoystickClose(joystick); } @@ -89,11 +89,11 @@ void Joystick::list() (*input_joystick) = (float) current_joystick_number; if (current_joystick_number) { - current_joystick = SDL_JoystickOpen(current_joystick_number -1); + current_joystick = SDL_JoystickOpen(current_joystick_number - 1); } if (current_joystick) { - con_debug << " using joystick " << SDL_JoystickName(current_joystick_number -1) << std::endl; + con_debug << " using joystick " << SDL_JoystickName(current_joystick_number - 1) << std::endl; SDL_JoystickEventState(SDL_ENABLE); } } @@ -105,14 +105,13 @@ bool Joystick::is_enabled() void Joystick::frame() { - if (current_joystick_number != (int) input_joystick->value()) - { + if (current_joystick_number != (int) input_joystick->value()) { if (current_joystick) { SDL_JoystickEventState(SDL_IGNORE); SDL_JoystickClose(current_joystick); current_joystick = 0; } - + current_joystick_number = (int) input_joystick->value(); if ((current_joystick_number < 1) || (current_joystick_number > SDL_NumJoysticks())) { current_joystick_number = 0; @@ -120,11 +119,11 @@ void Joystick::frame() (*input_joystick) = (float) current_joystick_number; if (current_joystick_number) { - current_joystick = SDL_JoystickOpen(current_joystick_number -1); + current_joystick = SDL_JoystickOpen(current_joystick_number - 1); } if (current_joystick) { - con_debug << " using joystick " << SDL_JoystickName(current_joystick_number -1) << std::endl; + con_debug << " using joystick " << SDL_JoystickName(current_joystick_number - 1) << std::endl; SDL_JoystickEventState(SDL_ENABLE); } } diff --git a/src/client/joystick.h b/src/client/joystick.h index a21e24e..9b1925d 100644 --- a/src/client/joystick.h +++ b/src/client/joystick.h @@ -10,7 +10,7 @@ namespace client { -class Joystick +class Joystick { public: static void init(); diff --git a/src/client/key.cc b/src/client/key.cc index c2da4a7..c25fa2b 100644 --- a/src/client/key.cc +++ b/src/client/key.cc @@ -7,7 +7,8 @@ #include "auxiliary/functions.h" #include "client/key.h" -namespace client { +namespace client +{ Key::Key(const char *name, int keysym, char ascii, const char *bind) { diff --git a/src/client/key.h b/src/client/key.h index 06e0587..3bb3e2b 100644 --- a/src/client/key.h +++ b/src/client/key.h @@ -11,7 +11,8 @@ #include <string> -namespace client { +namespace client +{ /// a pressable key /** @@ -22,11 +23,11 @@ class Key { public: /// define a new key - Key(const char *name, int keysym, char ascii=0, const char *bind=0); + Key(const char *name, int keysym, char ascii = 0, const char *bind = 0); ~Key(); - + /// key modifiers - enum Modifier { None=0, Shift=KMOD_LSHIFT+KMOD_RSHIFT, Ctrl=KMOD_LCTRL + KMOD_RCTRL, Alt=KMOD_LALT+KMOD_RALT }; + enum Modifier { None = 0, Shift = KMOD_LSHIFT + KMOD_RSHIFT, Ctrl = KMOD_LCTRL + KMOD_RCTRL, Alt = KMOD_LALT + KMOD_RALT }; /// clear all binds void clear(); @@ -41,19 +42,31 @@ public: std::string const & bind(Modifier mod) const; /// first time the key was pressed since previous release - inline float pressed() const { return key_pressed; } + inline float pressed() const { + return key_pressed; + } /// last time the key was pressed (includes repeats) - inline float lastpressed() const { return key_lastpressed; } + inline float lastpressed() const { + return key_lastpressed; + } /// time the key was pressed when it is released - inline float waspressed() const { return key_waspressed; } - - inline std::string const & name() const { return key_name; } + inline float waspressed() const { + return key_waspressed; + } + + inline std::string const & name() const { + return key_name; + } - inline char ascii() const { return key_ascii; } + inline char ascii() const { + return key_ascii; + } - inline int sym() const { return key_sym; } + inline int sym() const { + return key_sym; + } float key_pressed; float key_lastpressed; diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index 23e6634..bf08db1 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -31,7 +31,7 @@ Keyboard::Keyboard() // ------------------ ACTIONS // FIXME actions should be state keys and not use key repeat - + add_action("+left", Action::None, "rotate left"); add_action("+right", Action::None, "rotate right"); add_action("+up", Action::None, "rotate up"); @@ -253,12 +253,12 @@ Keyboard::~Keyboard() { // clear key map for (iterator it = begin(); it != end(); it++) - delete (*it).second; + delete(*it).second; keys.clear(); - + // clear action list - for(std::list<Action *>::iterator ait = actions.begin(); ait != actions.end(); ait++) - delete (*ait); + for (std::list<Action *>::iterator ait = actions.begin(); ait != actions.end(); ait++) + delete(*ait); actions.clear(); } @@ -317,7 +317,7 @@ void Keyboard::load_binds() con_print << " reading keyboard binds from " << filename << std::endl; char line[MAXCMDSIZE]; - while (ifs.getline(line, MAXCMDSIZE-1)) { + while (ifs.getline(line, MAXCMDSIZE - 1)) { if (line[0] && line[0] != '#' && line[0] != ';') core::cmd() << line << '\n'; } @@ -383,7 +383,7 @@ void Keyboard::bind(std::string const &name, const std::string str) { Key::Modifier modifier = Key::None; std::string keyname(name); - + if ((keyname.size() > 6) && (keyname.substr(0, 6).compare("shift+") == 0)) { keyname.erase(0, 6); modifier = Key::Shift; @@ -393,7 +393,7 @@ void Keyboard::bind(std::string const &name, const std::string str) } else if ((keyname.size() > 4) && (keyname.substr(0, 4).compare("alt+") == 0)) { keyname.erase(0, 4); modifier = Key::Alt; - + } else if ((keyname.size() > 6) && (keyname.substr(keyname.size() - 6, 6).compare("+shift") == 0)) { keyname.erase(keyname.size() - 6, 6); modifier = Key::Shift; @@ -401,10 +401,10 @@ void Keyboard::bind(std::string const &name, const std::string str) keyname.erase(keyname.size() - 5, 5); modifier = Key::Ctrl; } else if ((keyname.size() > 4) && (keyname.substr(keyname.size() - 4, 4).compare("+alt") == 0)) { - keyname.erase(0, keyname.size() -46); + keyname.erase(0, keyname.size() - 46); modifier = Key::Alt; } - + Key *key = find(keyname); if (key) { if (str.size()) @@ -425,10 +425,10 @@ void Keyboard::bind(std::string const &name, const std::string str) } void Keyboard::unbind(std::string const &name) -{ +{ Key::Modifier modifier = Key::None; std::string keyname(name); - + if ((keyname.size() > 6) && (keyname.substr(0, 6).compare("shift+") == 0)) { keyname.erase(0, 6); modifier = Key::Shift; @@ -438,7 +438,7 @@ void Keyboard::unbind(std::string const &name) } else if ((keyname.size() > 4) && (keyname.substr(0, 4).compare("alt+") == 0)) { keyname.erase(0, 4); modifier = Key::Alt; - + } else if ((keyname.size() > 6) && (keyname.substr(keyname.size() - 6, 6).compare("+shift") == 0)) { keyname.erase(keyname.size() - 6, 6); modifier = Key::Shift; @@ -446,7 +446,7 @@ void Keyboard::unbind(std::string const &name) keyname.erase(keyname.size() - 5, 5); modifier = Key::Ctrl; } else if ((keyname.size() > 4) && (keyname.substr(keyname.size() - 4, 4).compare("+alt") == 0)) { - keyname.erase(0, keyname.size() -46); + keyname.erase(0, keyname.size() - 46); modifier = Key::Alt; } @@ -498,7 +498,7 @@ void Keyboard::list_keys() void Keyboard::list_binds() { - size_t n =0; + size_t n = 0; for (iterator it = begin(); it != end(); it++) { if ((*it).second->bind(Key::None).size()) { con_print << " " << aux::pad_right((*it).second->name(), 6) << " " << (*it).second->bind(Key::None) << std::endl; @@ -719,7 +719,7 @@ void setkeyboardmode(bool input) SDL_EnableKeyRepeat(250, SDL_DEFAULT_REPEAT_INTERVAL); else SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL); - + } */ } // namespace client diff --git a/src/client/keyboard.h b/src/client/keyboard.h index f63bce1..f533838 100644 --- a/src/client/keyboard.h +++ b/src/client/keyboard.h @@ -16,7 +16,8 @@ #include "client/action.h" #include "client/key.h" -namespace client { +namespace client +{ class Keyboard { @@ -65,15 +66,19 @@ public: typedef std::map<unsigned int, Key *>::iterator iterator; - inline iterator begin() { return keys.begin(); } - - inline iterator end() { return keys.end(); } + inline iterator begin() { + return keys.begin(); + } + + inline iterator end() { + return keys.end(); + } /// convert SDL_keysym to a keystroke static unsigned int translate_keysym(int keysym, int modifier); private: - Key *add_key(const char *name, const unsigned int keysym, const char ascii=0, const char *bind=0); + Key *add_key(const char *name, const unsigned int keysym, const char ascii = 0, const char *bind = 0); Action *add_action(const char *name, Action::Identifier action, const char *info = 0); diff --git a/src/client/map.cc b/src/client/map.cc index aca5e97..7a6fedc 100644 --- a/src/client/map.cc +++ b/src/client/map.cc @@ -1,8 +1,8 @@ /* client/map.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #include "audio/audio.h" @@ -16,7 +16,8 @@ #include "render/textures.h" #include "render/text.h" -namespace client { +namespace client +{ Map::Map(ui::Widget *parent) : ui::Window(parent) { @@ -72,7 +73,7 @@ void Map::draw() const float margin = font()->width() * 2.0f; const float s = ui::UI::elementsize.width() * 2.0f; const float blue = 0.8f; - const float gridsize=16; + const float gridsize = 16; core::Entity *entity; const core::Entity *current_target = map_target; @@ -87,10 +88,10 @@ void Map::draw() v[1] += (height() - s - 2.0f * margin) * 0.5f; map_hover = 0; - gl::color(0,0,blue); + gl::color(0, 0, blue); gl::begin(gl::Lines); - for (int i=0; i <= gridsize; i++) { + for (int i = 0; i <= gridsize; i++) { gl::vertex(v.x(), v.y() + s / gridsize * i); gl::vertex(v.x() + s, v.y() + s / gridsize * i); @@ -102,7 +103,7 @@ void Map::draw() const size_t texture_entity = render::Textures::load("bitmaps/icons/entity_default"); const size_t texture_globe = render::Textures::load("bitmaps/icons/entity_globe"); const size_t texture_bright = render::Textures::load("bitmaps/icons/entity_bright"); - + size_t texture_current = render::Textures::bind(texture_entity); v[0] += s * 0.5f; @@ -140,7 +141,7 @@ void Map::draw() if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { draw_icon = false; } - } + } } if (draw_icon) { @@ -165,7 +166,7 @@ void Map::draw() gl::begin(gl::Quads); } } - + if (entity == core::localplayer()->mission_target()) { color.assign(palette()->mission()); } else { @@ -176,55 +177,55 @@ void Map::draw() gl::color(color); glTexCoord2f(0.0f, 0.0f); gl::vertex(l.x() - r, l.y() - r); - + glTexCoord2f(1.0f, 0.0f); gl::vertex(l.x() + r, l.y() - r); - + glTexCoord2f(1.0f, 1.0f); gl::vertex(l.x() + r, l.y() + r); - + glTexCoord2f(0.0f, 1.0f); gl::vertex(l.x() - r, l.y() + r); } - - } + + } // draw localcontrol icon entity = core::localcontrol(); //if (core::localcontrol()->state() != core::Entity::Docked) { - l.assign(v); - l[0] -= s / scale * entity->location().y(); - l[1] -= s / scale * entity->location().x(); - if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { - if (texture_current != texture_entity) { - gl::end(); - texture_current = render::Textures::bind(texture_entity); - gl::begin(gl::Quads); - } - - math::Color color(entity->color()); - color.a = 1.0f; - gl::color(color); - glTexCoord2f(0.0f, 0.0f); - gl::vertex(l.x() - r, l.y() - r); - - glTexCoord2f(1.0f, 0.0f); - gl::vertex(l.x() + r, l.y() - r); - - glTexCoord2f(1.0f, 1.0f); - gl::vertex(l.x() + r, l.y() + r); - - glTexCoord2f(0.0f, 1.0f); - gl::vertex(l.x() - r, l.y() + r); + l.assign(v); + l[0] -= s / scale * entity->location().y(); + l[1] -= s / scale * entity->location().x(); + if (core::application()->time() - floorf(core::application()->time()) < 0.5f) { + if (texture_current != texture_entity) { + gl::end(); + texture_current = render::Textures::bind(texture_entity); + gl::begin(gl::Quads); } + + math::Color color(entity->color()); + color.a = 1.0f; + gl::color(color); + glTexCoord2f(0.0f, 0.0f); + gl::vertex(l.x() - r, l.y() - r); + + glTexCoord2f(1.0f, 0.0f); + gl::vertex(l.x() + r, l.y() - r); + + glTexCoord2f(1.0f, 1.0f); + gl::vertex(l.x() + r, l.y() + r); + + glTexCoord2f(0.0f, 1.0f); + gl::vertex(l.x() - r, l.y() + r); + } //} gl::end(); gl::disable(GL_TEXTURE_2D); if (map_target) { - map_targetlabel->set_size(width() - s - margin * 3.0f, map_targetlabel->font()->height() * 2.0f ); + map_targetlabel->set_size(width() - s - margin * 3.0f, map_targetlabel->font()->height() * 2.0f); map_targetlabel->set_location(s + margin * 2.0f, 4); map_targetlabel->set_text(map_target->name()); map_targetlabel->show(); @@ -234,7 +235,7 @@ void Map::draw() } bool Map::on_keypress(const int key, const unsigned int modifier) -{ +{ if (key == 512 + SDL_BUTTON_LEFT) { if (hover()) { core::Entity *target = core::localplayer()->zone()->find_entity(hover()); diff --git a/src/client/map.h b/src/client/map.h index a3d8709..1fc1547 100644 --- a/src/client/map.h +++ b/src/client/map.h @@ -1,7 +1,7 @@ /* client/map.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_MAP_H__ @@ -11,7 +11,8 @@ #include "ui/label.h" #include "core/entity.h" -namespace client { +namespace client +{ class Map : public ui::Window { @@ -19,7 +20,9 @@ public: Map(ui::Widget *parent = 0); virtual ~Map(); - inline unsigned int hover() const { return map_hover; } + inline unsigned int hover() const { + return map_hover; + } /// toggle the map window void toggle(); diff --git a/src/client/notifications.cc b/src/client/notifications.cc index 062aacb..90c5e3e 100644 --- a/src/client/notifications.cc +++ b/src/client/notifications.cc @@ -1,7 +1,7 @@ /* client/notifications.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 + 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/notifications.h" @@ -48,7 +48,7 @@ void Notifications::event_text(const std::string & text) void Notifications::draw() { Timestamps::iterator t = notify_timestamp.begin(); - while ( (t != notify_timestamp.end()) && ( core::application()->timestamp() > (*t) + NOTIFY_TIMEOUT )) { + while ((t != notify_timestamp.end()) && (core::application()->timestamp() > (*t) + NOTIFY_TIMEOUT)) { notify_log.pop_front(); notify_timestamp.pop_front(); @@ -58,11 +58,11 @@ void Notifications::draw() const float margin = ui::UI::elementmargin; math::Vector2f s(size()); - s[0] -= margin*2; - s[1] -= margin*2; + s[0] -= margin * 2; + s[1] -= margin * 2; notify_scrollpane->set_location(margin, margin); - notify_scrollpane->set_size(s.x(), s.y() ); + notify_scrollpane->set_size(s.x(), s.y()); } diff --git a/src/client/notifications.h b/src/client/notifications.h index db3dd3e..3d596bd 100644 --- a/src/client/notifications.h +++ b/src/client/notifications.h @@ -1,7 +1,7 @@ /* client/notifications.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 + 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_NOTIFICATIONS_H__ @@ -27,7 +27,7 @@ public: protected: /// draw notifications void draw(); - + private: typedef std::deque<unsigned long> Timestamps; diff --git a/src/client/playerview.cc b/src/client/playerview.cc index 889e4d4..7ec8031 100644 --- a/src/client/playerview.cc +++ b/src/client/playerview.cc @@ -1,7 +1,7 @@ /* client/playerview.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 + 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 <string> @@ -11,7 +11,8 @@ #include "client/playerview.h" #include "ui/ui.h" -namespace client { +namespace client +{ PlayerView::PlayerView(ui::Widget *parent) : ui::Widget(parent) { @@ -60,9 +61,9 @@ void PlayerView::event_text(const std::string & text) void PlayerView::toggle_map() { - + if (!map()->visible()) { - if(chat()->visible() && !chat()->small_view()) + if (chat()->visible() && !chat()->small_view()) chat()->hide(); if (view_entitymenu->visible()) @@ -80,9 +81,9 @@ void PlayerView::toggle_map() void PlayerView::toggle_chat() { if (!chat()->visible()) { - if(map()->visible()) + if (map()->visible()) map()->hide(); - + if (view_entitymenu->visible()) view_entitymenu->hide(); } @@ -132,7 +133,7 @@ void PlayerView::show_menu(const std::string & args) } else if (label.compare("hide") == 0) { view_buymenu->hide(); view_entitymenu->hide(); - + } else { view_entitymenu->generate(core::localplayer()->view(), label.c_str()); view_entitymenu->show(); @@ -154,7 +155,7 @@ void PlayerView::resize() view_buymenu->event_resize(); // set hud geometry - view_hud->set_geometry(0,0, width(), height()); + view_hud->set_geometry(0, 0, width(), height()); view_hud->event_resize(); // reposition map @@ -167,7 +168,7 @@ void PlayerView::resize() // reposition labels //label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height()); //label_viewname->set_location(smallmargin, smallmargin * 0.5f); - + label_viewname->set_size(ui::UI::elementsize.width() * 1.5f, ui::UI::elementsize.height()); label_viewname->set_location(width() - label_viewname->width() - smallmargin, height() - label_viewname->height() - smallmargin * 0.5f); } @@ -185,10 +186,10 @@ void PlayerView::draw() if (core::localplayer()->view()->menus().size()) { // entity with menus - + if (map()->visible()) { label_viewname->set_text(core::localplayer()->zone()->name()); - } else { + } else { label_viewname->set_text(core::localplayer()->view()->name()); } @@ -200,9 +201,9 @@ void PlayerView::draw() map()->hide(); chat()->hide(); audio::play("ui/menu"); - - } else if (!view_entitymenu->visible() && !view_buymenu->visible() && - !map()->visible() && (!chat()->visible() || chat()->small_view()) ) { + + } else if (!view_entitymenu->visible() && !view_buymenu->visible() && + !map()->visible() && (!chat()->visible() || chat()->small_view())) { // show the menu if there's no other window open view_entitymenu->show(); @@ -226,7 +227,7 @@ void PlayerView::draw() } if (view_entitymenu->generated_entity()) { - view_entitymenu->generate(0,0); + view_entitymenu->generate(0, 0); } if (view_buymenu->visible()) { @@ -247,7 +248,7 @@ void PlayerView::draw() view_hud->show(); } - // reposition chat widget + // reposition chat widget if (view_chat->small_view()) { view_chat->set_size(width() - smallmargin * 2, font()->height() * 2); view_chat->set_location(smallmargin, height() - smallmargin *2 - view_chat->height()); diff --git a/src/client/playerview.h b/src/client/playerview.h index d72b78b..300e9e5 100644 --- a/src/client/playerview.h +++ b/src/client/playerview.h @@ -1,7 +1,7 @@ /* client/playerview.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 + 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_PLAYERVIEW_H__ @@ -17,7 +17,8 @@ #include "ui/widget.h" #include "ui/label.h" -namespace client { +namespace client +{ /// the player's view when joined class PlayerView : public ui::Widget @@ -42,11 +43,21 @@ public: /// show entity menus void show_menu(const std::string & label); - inline HUD *hud() { return view_hud; } - inline Map *map() { return view_map; } - inline Chat *chat() { return view_chat; } - inline Notifications *notify() { return view_notify; } - inline EntityMenu *menu() { return view_entitymenu; } + inline HUD *hud() { + return view_hud; + } + inline Map *map() { + return view_map; + } + inline Chat *chat() { + return view_chat; + } + inline Notifications *notify() { + return view_notify; + } + inline EntityMenu *menu() { + return view_entitymenu; + } protected: virtual void draw(); diff --git a/src/client/soundext.cc b/src/client/soundext.cc index 40b9417..1ea0c94 100644 --- a/src/client/soundext.cc +++ b/src/client/soundext.cc @@ -35,18 +35,17 @@ SoundExt::SoundExt(core::Entity *entity) : core::Extension(core::Extension::Soun state_engineeventsource = 0; // load engine sound - if (entity->type() == core::Entity::Controlable) - { + if (entity->type() == core::Entity::Controlable) { core::EntityControlable *entityco = static_cast<core::EntityControlable *>(entity); unsigned int enginesoundset = 0; unsigned int impulsesoundset = 0; - + if (entityco->model()) { enginesoundset = entityco->model()->enginesound(); impulsesoundset = entityco->model()->impulsesound(); } - - + + std::stringstream soundname; soundname << "engines/loop" << std::setfill('0') << std::setw(2) << enginesoundset; state_thusterloopbuffer = audio::Buffers::load(soundname.str()); @@ -91,60 +90,59 @@ void SoundExt::clear() void SoundExt::frame(float elapsed) { - if (entity()->type() == core::Entity::Controlable) - { + if (entity()->type() == core::Entity::Controlable) { core::EntityControlable *entity = static_cast<core::EntityControlable *>(this->entity()); - + float speed = entity->speed(); float pitch = 1.0f; float gain = 0.0; - float r = ( entity->model() ? entity->model()->maxbbox().x() : entity->radius()); + float r = (entity->model() ? entity->model()->maxbbox().x() : entity->radius()); if (entity->state() == core::Entity::Impulse) { pitch = 1.0f; gain = 1.0f; - } else if (entity->thrust() > 0 ) { + } else if (entity->thrust() > 0) { pitch = 0.2f + entity->thrust() * 0.8f; gain = 0.8f; - } - - if (entity->state() == core::Entity::ImpulseInitiate ) { - + } + + if (entity->state() == core::Entity::ImpulseInitiate) { + if (state_engineeventbuffer != state_impulsestartbuffer) { audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , - entity->axis().forward() * speed); - + entity->location() - entity->axis().forward() * r , + entity->axis().forward() * speed); + state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestartbuffer); } } else if (entity->state() == core::Entity::Impulse) { - + state_engineeventbuffer = state_impulseloopbuffer; - + if (state_engineloopbuffer != state_impulseloopbuffer) { state_engineloopbuffer = audio::loop(state_engineloopsource, state_impulseloopbuffer, pitch, 0); } pitch = 1.0f; } else { - - if (state_engineeventbuffer == state_impulseloopbuffer) { + + if (state_engineeventbuffer == state_impulseloopbuffer) { audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , - entity->axis().forward() * speed); + entity->location() - entity->axis().forward() * r , + entity->axis().forward() * speed); state_engineeventbuffer = audio::play(state_engineeventsource, state_impulsestopbuffer); } state_engineeventbuffer = 0; - + if (state_engineloopbuffer != state_thusterloopbuffer) { state_engineloopbuffer = audio::loop(state_engineloopsource, state_thusterloopbuffer, pitch, 0); } } - + audio::update_source(state_engineloopsource, - entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed, pitch, gain); - + entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed, pitch, gain); + audio::update_source(state_engineeventsource, - entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed); + entity->location() - entity->axis().forward() * r , entity->axis().forward() * speed); } } diff --git a/src/client/soundext.h b/src/client/soundext.h index d2028dd..a99cee0 100644 --- a/src/client/soundext.h +++ b/src/client/soundext.h @@ -13,7 +13,8 @@ namespace client { /// the sound extension of an entity -class SoundExt :public core::Extension { +class SoundExt : public core::Extension +{ public: SoundExt(core::Entity *Entity); ~SoundExt(); @@ -43,7 +44,7 @@ private: }; } - //namespace client - // +//namespace client +// #endif // __INCLUDED_CLIENT_CLIENTEXT_H__ diff --git a/src/client/targeticonbutton.cc b/src/client/targeticonbutton.cc index cd3716f..8bd3b1a 100644 --- a/src/client/targeticonbutton.cc +++ b/src/client/targeticonbutton.cc @@ -9,7 +9,8 @@ #include "client/targets.h" #include "core/commandbuffer.h" -namespace client { +namespace client +{ TargetIconButton::TargetIconButton(Widget *parent, const char *icon, const char *command, unsigned int flags) : IconButton(parent, icon, command) { @@ -18,7 +19,7 @@ TargetIconButton::TargetIconButton(Widget *parent, const char *icon, const char } bool TargetIconButton::on_keypress(const int key, const unsigned int modifier) -{ +{ if (key == 512 + SDL_BUTTON_LEFT) { if (enabled() && command().size() && targets::current()) { core::cmd() << "@" << command() << " " << targets::current_id() << std::endl; diff --git a/src/client/targeticonbutton.h b/src/client/targeticonbutton.h index a08c5c9..9907f95 100644 --- a/src/client/targeticonbutton.h +++ b/src/client/targeticonbutton.h @@ -9,9 +9,11 @@ #include "ui/iconbutton.h" -namespace client { +namespace client +{ -class TargetIconButton : public ui::IconButton { +class TargetIconButton : public ui::IconButton +{ public: /// special icon button that sends target '@' commands. diff --git a/src/client/targets.cc b/src/client/targets.cc index e478d84..cd3db41 100644 --- a/src/client/targets.cc +++ b/src/client/targets.cc @@ -1,7 +1,7 @@ /* client/targets.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #include <iostream> @@ -28,9 +28,11 @@ #include "render/camera.h" #include "render/state.h" -namespace client { +namespace client +{ -namespace targets { +namespace targets +{ const float TARGETBOXRADIUS = 0.025f; unsigned int current_target_id = 0; @@ -157,7 +159,7 @@ void func_target_next(std::string const &args) } else { current_target = 0; current_target_id = 0; - + } } @@ -222,22 +224,22 @@ void func_target_center(std::string const &args) { if (!core::localcontrol()) return; - + // this is essentialy the hover algorithm with the cursor in the center core::Entity *new_target = 0; math::Vector3f center = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001); float smallest_d = -1; - for (core::Zone::Content::iterator it=core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) { + for (core::Zone::Content::iterator it = core::localcontrol()->zone()->content().begin(); it != core::localcontrol()->zone()->content().end(); it++) { core::Entity *entity = (*it); math::Vector3f v(entity->location() - render::Camera::eye()); v.normalize(); - if (is_valid_hud_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85 ) { + if (is_valid_hud_target(entity) && math::dotproduct(render::Camera::axis().forward(), v) > 0.85) { // calculate the distance from entity location to the line [eye - cursor] - float d = math::Vector3f::length(math::crossproduct( (center - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(center - render::Camera::eye()); + float d = math::Vector3f::length(math::crossproduct((center - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(center - render::Camera::eye()); // the entity closer to the center beam if (smallest_d < 0 || d < smallest_d) { @@ -256,7 +258,7 @@ void reset() current_target = 0; current_target_id = 0; current_hover = 0; - + } void init() @@ -296,7 +298,7 @@ void render_listener_sound() if (!(snd_engines && snd_engines->value())) return; - math::Vector3f velocity(0, 0 ,0); + math::Vector3f velocity(0, 0 , 0); if (core::localcontrol()) { velocity.assign(core::localcontrol()->axis().forward() * core::localcontrol()->speed()); } @@ -308,13 +310,13 @@ void render_entity_sound(core::Entity *entity) { if (!(snd_engines && snd_engines->value())) { if (ext_sound(entity)) - delete ext_sound(entity); + delete ext_sound(entity); return; } if (!ext_render(entity) || (ext_render(entity) && !ext_render(entity)->visible())) { if (ext_sound(entity)) - delete ext_sound(entity); + delete ext_sound(entity); return; } else { if (!ext_sound(entity)) { @@ -354,18 +356,18 @@ void frame() x = 0; y = 0; } else { - x = (float)(input::mouse_position_x() - render::State::width() /2) / (float)render::State::width(); - y = (float)(input::mouse_position_y() - render::State::height() /2) / (float)render::State::height() / render::State::aspect(); + x = (float)(input::mouse_position_x() - render::State::width() / 2) / (float)render::State::width(); + y = (float)(input::mouse_position_y() - render::State::height() / 2) / (float)render::State::height() / render::State::aspect(); } Vector3f cursor = render::Camera::eye() + render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001); cursor -= render::Camera::axis().left() * x; cursor -= render::Camera::axis().up() * y; - math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT +0.001f)); - for (core::Zone::Content::iterator it=zone->content().begin(); it != zone->content().end(); it++) { + math::Vector3f center = render::Camera::eye() + (render::Camera::axis().forward() * (render::FRUSTUMFRONT + 0.001f)); + for (core::Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { core::Entity *entity = (*it); - + // render entity sound if (entity->type() == core::Entity::Controlable) { render_entity_sound(entity); @@ -377,24 +379,24 @@ void frame() if (entity->id() == current_target_id) { current_target = entity; } - + // check if the mouse is hovering the entity Vector3f v(entity->location() - render::Camera::eye()); v.normalize(); - if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75 ) { + if (math::dotproduct(render::Camera::axis().forward(), v) > 0.75) { // calculate the distance from entity location to the line [eye - cursor] - float d = math::Vector3f::length(math::crossproduct( (cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye()); - + float d = math::Vector3f::length(math::crossproduct((cursor - render::Camera::eye()) , (render::Camera::eye() - entity->location()))) / math::Vector3f::length(cursor - render::Camera::eye()); + float r = entity->radius() * 0.5f; if (ext_render(entity)->distance() > 512.0f) - math::clamp(r, 8.0f,r); + math::clamp(r, 8.0f, r); else if (ext_render(entity)->distance() > 256.0f) - math::clamp(r, 4.0f,r); + math::clamp(r, 4.0f, r); else if (ext_render(entity)->distance() > 128.0f) - math::clamp(r, 2.0f,r); + math::clamp(r, 2.0f, r); // if the cursor-beam hits the entity sphere if (d < r) { @@ -406,7 +408,7 @@ void frame() } } - + } } @@ -415,7 +417,7 @@ void frame() } else { current_target_id = current_target->id(); - + } } diff --git a/src/client/targets.h b/src/client/targets.h index d421300..9bfa87d 100644 --- a/src/client/targets.h +++ b/src/client/targets.h @@ -1,7 +1,7 @@ /* client/targets.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_TARGETS_H__ @@ -12,9 +12,11 @@ #include "render/gl.h" #include "render/text.h" -namespace client { +namespace client +{ -namespace targets { +namespace targets +{ void init(); diff --git a/src/client/trademenu.cc b/src/client/trademenu.cc index 9db1299..dcab2f1 100644 --- a/src/client/trademenu.cc +++ b/src/client/trademenu.cc @@ -16,7 +16,7 @@ TradeMenu::TradeMenu(ui::Widget *parent, const char * label) : ui::Window(parent { set_border(false); set_background(false); - if (label) + if (label) set_label(label); else set_label("trademenu"); diff --git a/src/client/trademenu.h b/src/client/trademenu.h index feb91f4..baf3544 100644 --- a/src/client/trademenu.h +++ b/src/client/trademenu.h @@ -1,7 +1,7 @@ /* client/trademenu.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_CLIENT_TRADEMENU_H__ diff --git a/src/client/video.cc b/src/client/video.cc index 4ad1c97..9e9d553 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -1,7 +1,7 @@ /* client/video.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 + 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/video.h" @@ -21,7 +21,8 @@ using namespace render; -namespace client { +namespace client +{ /* -- engine variables --------------------------------------------- */ @@ -34,7 +35,8 @@ core::Cvar *draw_stats = 0; core::Cvar *draw_devinfo = 0; core::Cvar *draw_keypress = 0; -namespace video { +namespace video +{ float fullscreen = 0; @@ -53,7 +55,7 @@ const int height_default = 768; std::string loader_message; bool is_loading = false; -bool init() +bool init() { con_print << "^BInitializing video..." << std::endl; @@ -79,7 +81,7 @@ bool init() draw_ui = core::Cvar::get("draw_ui", "1", core::Cvar::Archive); draw_ui->set_info("[bool] draw the user interface"); - if( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) { + if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { con_error << "SDL_InitSubSystem() failed: " << SDL_GetError() << std::endl; return false; } @@ -97,12 +99,12 @@ bool init() if (image) { Uint32 colorkey = SDL_MapRGB(image->format, 255, 0, 255); SDL_SetColorKey(image, SDL_SRCCOLORKEY, colorkey); - SDL_WM_SetIcon(image,NULL); + SDL_WM_SetIcon(image, NULL); } } const SDL_VideoInfo* sdl_videoinfo = SDL_GetVideoInfo(); - if( !sdl_videoinfo) { + if (!sdl_videoinfo) { con_error << "SDL_GetVideoInfo() failed: " << SDL_GetError() << std::endl; return false; } @@ -115,25 +117,25 @@ bool init() bpp = sdl_videoinfo->vfmt->BitsPerPixel; if (bpp == 32) { - SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8); - SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); } else if (bpp == 24) { - SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 6); - SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6); - SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 6); - SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 6); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 6); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 6); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 6); } else if (bpp == 16) { - SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 4); - SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 4); - SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 4); - SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 4); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 4); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 4); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 4); + SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 4); } else { con_warn << "Display depth " << bpp << " is not supported!" << std::endl; } - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); fullscreen = r_fullscreen->value(); if (r_fullscreen->value()) { @@ -145,12 +147,12 @@ bool init() #endif } - if(!SDL_SetVideoMode(width, height, bpp, flags )) { + if (!SDL_SetVideoMode(width, height, bpp, flags)) { con_warn << "Failed to set video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; if (width_prev && height_prev) { width = width_prev; height = height_prev; - if(!SDL_SetVideoMode(width, height, bpp, flags )) { + if (!SDL_SetVideoMode(width, height, bpp, flags)) { con_error << "Failed to restore video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; return false; } @@ -163,11 +165,11 @@ bool init() int red, green, blue, alpha, depth; - SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &red); - SDL_GL_GetAttribute( SDL_GL_GREEN_SIZE, &green); - SDL_GL_GetAttribute( SDL_GL_RED_SIZE, &blue); - SDL_GL_GetAttribute( SDL_GL_ALPHA_SIZE, &alpha); - SDL_GL_GetAttribute( SDL_GL_DEPTH_SIZE, &depth); + SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &red); + SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &green); + SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &blue); + SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &alpha); + SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth); con_debug << " visual r: " << red << " g: " << green << " blue: " << blue << " alpha: " << alpha << " depth: " << depth << std::endl; @@ -198,7 +200,7 @@ bool init() // apply render options ui::root()->apply_render_options(); - + // initialize target drawer targets::init(); @@ -222,8 +224,8 @@ void resize(int w, int h) if (w < 320) w = 320; if (h < 200) h = 200; - - if (SDL_SetVideoMode(w, h, bpp, flags )) { + + if (SDL_SetVideoMode(w, h, bpp, flags)) { render::resize(w, h); ui::root()->set_size(w, h); ui::root()->event_resize(); @@ -247,7 +249,7 @@ void set_cursor() if (ui::console()->visible()) { ui::root()->set_pointer(); - } else if(core::localplayer()->view() || ui::root()->active()) { + } else if (core::localplayer()->view() || ui::root()->active()) { ui::root()->set_pointer("pointer"); @@ -268,7 +270,7 @@ void set_cursor() ui::root()->set_pointer("target", ui::Palette::Active, true); if (input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) { - ui::root()->input_mouse(render::State::width()/2, render::State::height() /2); + ui::root()->input_mouse(render::State::width() / 2, render::State::height() / 2); } } else if (input::mouse_control) { @@ -276,11 +278,11 @@ void set_cursor() ui::root()->set_pointer("control", ui::Palette::Pointer); if (input::mouse_deadzone) { - ui::root()->input_mouse(render::State::width()/2, render::State::height() /2); + ui::root()->input_mouse(render::State::width() / 2, render::State::height() / 2); } - } else if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && - (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { + } else if ((input::joystick_lastmoved_time() > input::mouse_lastmoved_time()) && + (render::Camera::mode() == render::Camera::Cockpit || render::Camera::mode() == render::Camera::Track)) { ui::root()->set_pointer(); @@ -293,7 +295,7 @@ void set_cursor() void set_loader_message(const std::string message) { loader_message.assign(message); - + if (is_loading) frame_loader(); } @@ -304,7 +306,7 @@ void set_loader_message(const char *message) loader_message.assign(message); else loader_message.clear(); - + if (is_loading) frame_loader(); } @@ -312,7 +314,7 @@ void set_loader_message(const char *message) void draw_loader() { render::Camera::ortho(); - + gl::enable(GL_BLEND); gl::color(1.0f, 1.0f, 1.0f, 1.0f); @@ -322,7 +324,7 @@ void draw_loader() if (loader_message.size()) { using render::Text; - gl::enable(GL_TEXTURE_2D); + gl::enable(GL_TEXTURE_2D); Text::setfont("gui", 12, 18); Text::setcolor('N'); //set normal color Text::draw(Text::fontwidth(), Text::fontheight(), loader_message); @@ -330,7 +332,7 @@ void draw_loader() } gl::disable(GL_BLEND); - + is_loading = true; } @@ -338,9 +340,9 @@ void frame_loader() { // Clear the color and depth buffers. gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - + draw_loader(); - + SDL_GL_SwapBuffers(); } @@ -351,15 +353,15 @@ void frame(float elapsed) restart(); using namespace render; - + is_loading = false; - + // Clear the color and depth buffers. gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); render::Stats::clear(); if (core::application()->connected()) { - + if (core::game()->time() && core::localplayer()->zone()) { render::Camera::frame(elapsed); render::Camera::frustum(); @@ -372,12 +374,12 @@ void frame(float elapsed) render::Camera::ortho(); client()->worldview()->show(); - + } else { draw_loader(); client()->worldview()->hide(); } - + } else { client()->worldview()->hide(); render::Camera::ortho(); @@ -398,17 +400,17 @@ void frame(float elapsed) ui::console()->event_draw(); } - + gl::disable(GL_TEXTURE_2D); gl::disable(GL_BLEND); - + SDL_GL_SwapBuffers(); } void shutdown() { con_print << "^BShutting down video..." << std::endl; - + targets::shutdown(); render::shutdown(); diff --git a/src/client/video.h b/src/client/video.h index 978a876..93c3ce0 100644 --- a/src/client/video.h +++ b/src/client/video.h @@ -1,7 +1,7 @@ /* client/video.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 + 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_VIDEO_H__ @@ -9,40 +9,41 @@ #include "core/cvar.h" -namespace client { +namespace client +{ /// the video subsystem -namespace video +namespace video { - /// initialize the video subsystem - bool init(); - - /// shutdown the video subsystem - void shutdown(); - - /// re-initialize the video subsystems - /** the restart functions performs a full shutdown - * and re-initializes the video subsystem - */ - void restart(); - - /// application window resize event in windowed mode - void resize(int w, int h); - - /// draw the next client video frame - void frame(float elapsed); - - /// draw the loader screen - void frame_loader(); - - /// update the loader screen message - void set_loader_message(const std::string message); - - /// update the loader screen message - void set_loader_message(const char *message = 0); - - /// set the window caption - void set_caption(); +/// initialize the video subsystem +bool init(); + +/// shutdown the video subsystem +void shutdown(); + +/// re-initialize the video subsystems +/** the restart functions performs a full shutdown + * and re-initializes the video subsystem + */ +void restart(); + +/// application window resize event in windowed mode +void resize(int w, int h); + +/// draw the next client video frame +void frame(float elapsed); + +/// draw the loader screen +void frame_loader(); + +/// update the loader screen message +void set_loader_message(const std::string message); + +/// update the loader screen message +void set_loader_message(const char *message = 0); + +/// set the window caption +void set_caption(); } // namespace video diff --git a/src/client/worldview.cc b/src/client/worldview.cc index 7f13f45..c4f932b 100644 --- a/src/client/worldview.cc +++ b/src/client/worldview.cc @@ -1,7 +1,7 @@ /* client/worldview.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 + 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 "core/application.h" @@ -10,7 +10,8 @@ #include "client/video.h" #include "ui/ui.h" -namespace client { +namespace client +{ WorldView::WorldView(ui::Widget *parent) : ui::Widget(parent) { @@ -55,29 +56,29 @@ void WorldView::resize() // reposition devinfo widget view_devinfo->set_size(font()->width()*32, font()->height()*5); view_devinfo->set_location(smallmargin, smallmargin); - + // reposition stats widget - view_statsinfo->set_size(font()->width()*12, font()->height()*5); + view_statsinfo->set_size(font()->width()*12, font()->height()*5); view_statsinfo->set_location(width() - view_statsinfo->width() - smallmargin, smallmargin); // reposition keypress widget - view_keyinfo->set_size(font()->width()*12, font()->height()*1); + view_keyinfo->set_size(font()->width()*12, font()->height()*1); view_keyinfo->set_location(width() - view_keyinfo->width() - smallmargin, - height() - view_keyinfo->height() - smallmargin); + height() - view_keyinfo->height() - smallmargin); // icons const float icon_margin = 4.0f; const float icon_size = 48.0f; const float icon_count = 6; - const float l = (width() -((icon_count +1) * icon_margin) - (icon_count * icon_size)) * 0.5f; - + const float l = (width() - ((icon_count + 1) * icon_margin) - (icon_count * icon_size)) * 0.5f; + view_menubutton->set_geometry(l, icon_margin, icon_size, icon_size); // spacer - view_dockbutton->set_geometry( l + 2.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size); - view_launchbutton->set_geometry( l + 2.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size); + view_dockbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + view_launchbutton->set_geometry(l + 2.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); // spacer - view_chatbutton->set_geometry( l + 4.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size); - view_mapbutton->set_geometry( l + 5.0f * (icon_margin + icon_size), icon_margin, icon_size, icon_size); + view_chatbutton->set_geometry(l + 4.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); + view_mapbutton->set_geometry(l + 5.0f *(icon_margin + icon_size), icon_margin, icon_size, icon_size); } void WorldView::clear() @@ -98,8 +99,8 @@ void WorldView::draw() view_devinfo->set_visible(draw_devinfo->value() ? true : false); view_statsinfo->set_visible(draw_stats->value() ? true : false); view_keyinfo->set_visible(draw_keypress->value() ? true : false); - - if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size()) ) { + + if (ui::root()->active() || !core::game()->interactive() || !core::localcontrol() || (core::localplayer()->view() && !core::localplayer()->view()->menus().size())) { view_playerview->hide(); view_menubutton->hide(); view_dockbutton->hide(); diff --git a/src/client/worldview.h b/src/client/worldview.h index e42ac86..11473f8 100644 --- a/src/client/worldview.h +++ b/src/client/worldview.h @@ -1,7 +1,7 @@ /* client/worldview.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 + 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_WORLDVIEW_H__ @@ -12,7 +12,8 @@ #include "client/infowidget.h" #include "ui/iconbutton.h" -namespace client { +namespace client +{ /// the world view when connected class WorldView : public ui::Widget @@ -25,7 +26,9 @@ public: void event_text(const std::string & text); - inline PlayerView *playerview() { return view_playerview; } + inline PlayerView *playerview() { + return view_playerview; + } protected: virtual void draw(); |