From 272d229094309bc5875287a5063f818c58c5f4f8 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 10 Jan 2009 15:36:15 +0000 Subject: hud widget, drawing code reorganization --- src/client/video.cc | 128 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 11 deletions(-) (limited to 'src/client/video.cc') diff --git a/src/client/video.cc b/src/client/video.cc index 1db1ba4..57efa96 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -8,6 +8,7 @@ #include "client/input.h" #include "client/view.h" #include "client/client.h" +#include "client/targets.h" #include "render/render.h" #include "core/core.h" #include "core/gameserver.h" @@ -21,6 +22,18 @@ using namespace render; namespace client { +/* -- engine variables --------------------------------------------- */ + +core::Cvar *r_width = 0; +core::Cvar *r_height = 0; +core::Cvar *r_fullscreen = 0; + +core::Cvar *draw_ui = 0; +core::Cvar *draw_stats = 0; +core::Cvar *draw_devinfo = 0; +core::Cvar *draw_keypress = 0; + + namespace video { float fullscreen = 0; @@ -37,17 +50,11 @@ int height_prev = 0; const int width_default = 1024; const int height_default = 768; -/* -- engine variables --------------------------------------------- */ - -core::Cvar *r_width; -core::Cvar *r_height; -core::Cvar *r_fullscreen; - bool init() { con_print << "^BInitializing video..." << std::endl; - // initialize cvars + // initialize engine variables r_width = core::Cvar::get("r_width", width_default, core::Cvar::Archive); r_width->set_info("[int] video resolution width"); @@ -57,6 +64,18 @@ bool init() r_fullscreen = core::Cvar::get("r_fullscreen", "0", core::Cvar::Archive); r_fullscreen->set_info("[bool] enable or disable fullscreen video"); + draw_devinfo = core::Cvar::get("draw_devinfo", "0", core::Cvar::Archive); + draw_devinfo->set_info("[bool] draw developer information"); + + draw_stats = core::Cvar::get("draw_stats", "0", core::Cvar::Archive); + draw_stats->set_info("[bool] draw network and render statistics"); + + draw_keypress = core::Cvar::get("draw_keypress", "0", core::Cvar::Archive); + draw_keypress->set_info("[bool] draw keypress key names"); + + 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 ) { con_error << "SDL_InitSubSystem() failed: " << SDL_GetError() << std::endl; return false; @@ -160,7 +179,8 @@ bool init() // apply render options ui::root()->apply_render_options(); - view::init(); + // initialize target drawer + targets::init(); return true; } @@ -204,14 +224,100 @@ void restart() input::reset(); } +void set_cursor() +{ + if (ui::console()->visible()) { + ui::root()->set_pointer(); + + } else if(core::localplayer()->view() || ui::root()->active()) { + + ui::root()->set_pointer("pointer"); + + } else if (!core::localcontrol()) { + + ui::root()->set_pointer(); + + } else if (client()->view()->map()->hover()) { + + ui::root()->set_pointer("pointer"); + + } else if (render::Camera::mode() == render::Camera::Overview) { + + ui::root()->set_pointer("aim"); + + } else if (targets::hover()) { + + 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); + } + + } else if (input::mouse_control) { + + ui::root()->set_pointer("control", ui::Palette::Pointer); + + if (input::mouse_deadzone) { + 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)) { + + ui::root()->set_pointer(); + + } else { + + ui::root()->set_pointer("aim", ui::Palette::Foreground); + } +} + void frame(float elapsed) { // detect fullscreen/windowed mode switch if (fullscreen != r_fullscreen->value()) restart(); - // render a client frame - view::frame(elapsed); + using namespace render; + + // Clear the color and depth buffers. + gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + render::Stats::clear(); + + if (core::application()->connected() && core::game()->time() && core::localplayer()->zone()) { + render::Camera::frame(elapsed); + render::Camera::frustum(); + + render::draw(elapsed); // draw the world + targets::frame(); // validate current target, render sound + + if (!core::localplayer()->view() && targets::current()) // draw target docks etc + render::draw_target(targets::current()); + + render::Camera::ortho(); + + } else { + render::Camera::ortho(); + } + + gl::color(1.0f, 1.0f, 1.0f, 1.0f); + gl::disable(GL_TEXTURE_2D); + gl::enable(GL_BLEND); + + // draw the user interface + if (draw_ui->value()) { + + set_cursor(); + ui::root()->frame(); + + } else if (ui::console()->visible()) { + + ui::console()->event_draw(); + } + + gl::disable(GL_TEXTURE_2D); + gl::disable(GL_BLEND); SDL_GL_SwapBuffers(); } @@ -220,7 +326,7 @@ void shutdown() { con_print << "^BShutting down video..." << std::endl; - view::shutdown(); + targets::shutdown(); render::shutdown(); -- cgit v1.2.3