From 8774e65cc503318005f34c133cbaee21b18fc144 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 29 Nov 2010 16:04:03 +0000 Subject: Parse command line options after engine initialization. --- src/client/client.cc | 26 ++++++++++++++++++++++---- src/client/input.cc | 3 +++ src/client/keyboard.cc | 9 ++++----- src/client/testmodelview.cc | 44 ++++++++++++++++++++++---------------------- src/client/testmodelview.h | 3 +++ 5 files changed, 54 insertions(+), 31 deletions(-) (limited to 'src/client') diff --git a/src/client/client.cc b/src/client/client.cc index ec2d002..97cfc91 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -113,12 +113,12 @@ void Client::init(int count, char **arguments) quit(1); } - // initialize input - input::init(); - // initialize audio audio::init(); + // initialize input + input::init(); + // add engine functions core::Func *func = 0; @@ -224,7 +224,7 @@ void Client::frame(unsigned long timestamp) core::Application::frame(timestamp); if (!connected()) { - std::string module_label(core::Loader::label()); + const std::string module_label(core::Loader::label()); // load the intro if nothing is running if (load("intro")) { @@ -589,6 +589,24 @@ void Client::func_menu(std::string const &args) void Client::func_testmodel(std::string const &args) { + // if testmodel is called from the command line, no module has been loaded yet + if (!client()->connected()) { + const std::string module_label(core::Loader::label()); + + // load the intro if nothing is running + if (client()->load("intro")) { + client()->connect(""); + if (module_label.size()) + client()->load(module_label); + } + } + + if (!client()->connected()) { + client()->client_testmodelview->hide(); + ui::console()->show(); + return; + } + std::string modelname(args); aux::trim(modelname); diff --git a/src/client/input.cc b/src/client/input.cc index 0412093..3741e15 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -279,6 +279,9 @@ void init() input_grab = core::Cvar::get("input_grab", 1.0f, core::Cvar::Archive); input_grab->set_info("[bool] grab input"); + if (!input_grab->value()) { + SDL_WM_GrabInput(SDL_GRAB_OFF); + } core::Func *func = 0; func = core::Func::add("ui_control", func_ui_control); diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index 176e310..7486ff3 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -317,13 +317,12 @@ void Keyboard::load_binds() char line[MAXCMDSIZE]; while (ifs.getline(line, MAXCMDSIZE - 1)) { - if (line[0] && line[0] != '#' && line[0] != ';') - core::cmd() << line << '\n'; + if (line[0] && line[0] != '#' && line[0] != ';') { + core::CommandBuffer::exec(line); + } } - - // execute commands in the buffer - core::CommandBuffer::exec(); } + Key * Keyboard::release(unsigned int sym) { Key *key = find(sym); diff --git a/src/client/testmodelview.cc b/src/client/testmodelview.cc index 4164d6c..40ae1aa 100644 --- a/src/client/testmodelview.cc +++ b/src/client/testmodelview.cc @@ -36,28 +36,7 @@ TestModelView::~TestModelView() void TestModelView::set_modelname(const std::string & modelname) { - model::Model *model = model::Model::load(modelname); - - std::ostringstream str; - str << modelname << '\n'; - - if (model) { - size_t frags = 0; - - for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) { - frags += (*git)->size(); - } - str << '\n'; - str << "tris: " << model->model_tris_count << '\n'; - str << "quads: " << model->model_quad_count << '\n'; - str << "fragments: " << frags << '\n'; - - testmodelview_modelview->set_modelname(modelname); - } else { - testmodelview_modelview->set_modelname(""); - testmodelview_modelview->set_background(true); - } - testmodelview_text->set_text(str.str()); + testmodelview_modelview->set_modelname(modelname); } void TestModelView::show() @@ -102,6 +81,27 @@ void TestModelView::draw_background() ui::Paint::draw_rectangle(global_location(), size()); } +void TestModelView::draw() +{ + model::Model *model = model::Model::find(testmodelview_modelview->modelname()); + + std::ostringstream str; + str << testmodelview_modelview->modelname() << '\n'; + + if (model) { + size_t frags = 0; + + for (model::Model::Groups::const_iterator git = model->groups().begin(); git != model->groups().end(); git++) { + frags += (*git)->size(); + } + str << '\n'; + str << "tris: " << model->model_tris_count << '\n'; + str << "quads: " << model->model_quad_count << '\n'; + str << "fragments: " << frags << '\n'; + } + testmodelview_text->set_text(str.str()); +} + bool TestModelView::on_emit(Widget *sender, const Event event, void *data) { if (event == ui::Widget::EventButtonClicked) { diff --git a/src/client/testmodelview.h b/src/client/testmodelview.h index 6b38df6..6a3d9f3 100644 --- a/src/client/testmodelview.h +++ b/src/client/testmodelview.h @@ -31,6 +31,9 @@ public: virtual void hide(); protected: + /// update model statistics + virtual void draw(); + /// resize te testmodelview virtual void resize(); -- cgit v1.2.3