From a51deebd87036ceb87c77a20117977d077b771e3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 5 Feb 2008 20:44:36 +0000 Subject: fixed cvar, added cvars r_width r_height r_fullscreen, added function r_restart --- src/client/client.cc | 17 +++++++++++++++++ src/client/console.cc | 6 +++--- src/client/console.h | 2 +- src/client/input.cc | 14 +++++++------- src/client/video.cc | 22 ++++++++++++++++++++-- 5 files changed, 48 insertions(+), 13 deletions(-) (limited to 'src/client') diff --git a/src/client/client.cc b/src/client/client.cc index ba1c0bc..993e849 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -44,6 +44,14 @@ public: Client app; +//--- engine functions -------------------------------------------- + +extern "C" void func_r_restart(std::stringstream &args) +{ + video::shutdown(); + video::init(); +} + //--- public ------------------------------------------------------ game::Game game; @@ -73,6 +81,9 @@ void Client::init() // initialize core core::Application::init(); + // initialize SDL, but do not initialize any subsystems + SDL_Init(0); + // Initialize the video subsystem if (!client::video::init()) quit(1); @@ -82,6 +93,9 @@ void Client::init() // initialize input input::init(); + + // add engine functions + core::func::add("r_restart", func_r_restart); } void Client::run() @@ -119,6 +133,9 @@ void Client::shutdown() con_print << "Shutting down client..." << std::endl; console::flush(); + // remove engine functions + core::func::remove("r_restart"); + console::shutdown(); console::flush(); diff --git a/src/client/console.cc b/src/client/console.cc index 127481a..bf193e5 100644 --- a/src/client/console.cc +++ b/src/client/console.cc @@ -64,7 +64,7 @@ void init() console_visible = false; - // register our engine functions + // add engine functions core::func::add("con_toggle", func_con_toggle); } @@ -72,7 +72,7 @@ void shutdown() { con_print << "Shutting down console..." << std::endl; - // unregister our engine functions + // remove engine functions core::func::remove("con_toggle"); } @@ -159,7 +159,7 @@ void toggle() console_visible = !console_visible; } -void handle_keyreleased(SDL_keysym* keysym) +void handle_keypressed(SDL_keysym* keysym) { switch( keysym->sym ) { case SDLK_RETURN: diff --git a/src/client/console.h b/src/client/console.h index 9eeb57e..d185390 100644 --- a/src/client/console.h +++ b/src/client/console.h @@ -41,7 +41,7 @@ void draw(); void toggle(); /// handle keyboard input -void handle_keyreleased(SDL_keysym* keysym); +void handle_keypressed(SDL_keysym* keysym); /// true of the console is visible bool visible(); diff --git a/src/client/input.cc b/src/client/input.cc index 91f462c..9bcf4fe 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -23,8 +23,8 @@ void init() con_print << "Initializing input..." << std::endl; //condebug << "SDL_DEFAULT_REPEAT_DELAY " << SDL_DEFAULT_REPEAT_DELAY << std::endl; - //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + //SDL_EnableKeyRepeat(10, SDL_DEFAULT_REPEAT_INTERVAL); } void shutdown() @@ -99,7 +99,10 @@ void frame(float seconds) client::application.shutdown(); } */ - if (core::connected() && !console::visible()) { + if (console::visible()) { + // send key events to the console + console::handle_keypressed( &event.key.keysym ); + } else if (core::connected()) { // send key events to the game world handle_keypressed( &event.key.keysym ); } @@ -108,10 +111,7 @@ void frame(float seconds) case SDL_KEYUP: if (event.key.keysym.sym == '`' || event.key.keysym.sym == '~') { console::toggle(); - } else if (console::visible()) { - // send key events to the console - console::handle_keyreleased( &event.key.keysym ); - } else if (core::connected()) { + } else if (!console::visible() && core::connected()) { // send key events to the game world handle_keyreleased( &event.key.keysym ); } diff --git a/src/client/video.cc b/src/client/video.cc index bb748d0..df11b90 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -7,6 +7,7 @@ #include "client/video.h" #include "client/view.h" #include "render/render.h" +#include "core/core.h" #include "sys/sys.h" #include @@ -24,6 +25,12 @@ int width = 0; int height = 0; float aspect = 1; +//--- cvars ------------------------------------------------------- + +core::Cvar r_width; +core::Cvar r_height; +core::Cvar r_fullscreen; + void reset() { // recalculate the video aspect @@ -40,10 +47,15 @@ bool init() { con_print << "Initializing video..." << std::endl; + // initialize cvars + r_width = core::cvar::get("r_width", defaultwidth); + r_height = core::cvar::get("r_height", defaultheight); + r_fullscreen = core::cvar::get("r_fullscreen", 1); + int bpp = 0; int flags = 0; - if( SDL_Init(SDL_INIT_VIDEO) < 0 ) { + if( SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) { std::cerr << "SDL_Init() failed: " << SDL_GetError() << std::endl; return false; } @@ -72,10 +84,13 @@ bool init() return false; } - aspect = (float) width / (float) height; con_print << " video mode " << width << "x" << height << "x" << bpp << "bpp" << std::endl; + + aspect = (float) width / (float) height; + render::init(); + view::init(); video::reset(); @@ -96,10 +111,13 @@ void shutdown() con_print << "Shutting down video..." << std::endl; view::shutdown(); + render::shutdown(); width = 0; height = 0; + + SDL_QuitSubSystem(SDL_INIT_VIDEO); } } // namespace video -- cgit v1.2.3