From cc335cfbf13a6b21c5f65febc6049eb5d4c16b63 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Fri, 1 Aug 2008 13:08:27 +0000 Subject: model->enginecolor(), removed autolevel, added selection delay --- src/client/input.cc | 72 +++++++++++++++------------------ src/client/key.cc | 1 + src/client/key.h | 16 +++++--- src/client/keyboard.cc | 15 ++++--- src/game/game.cc | 8 ++-- src/game/game.h | 2 +- src/game/ship.cc | 27 ------------- src/model/engine.cc | 4 +- src/model/engine.h | 20 +++++++--- src/model/map.cc | 23 ++++++----- src/model/model.cc | 4 +- src/model/model.h | 7 +++- src/render/draw.cc | 106 +++++++++++++++++++++++++------------------------ 13 files changed, 151 insertions(+), 154 deletions(-) diff --git a/src/client/input.cc b/src/client/input.cc index b5d4c0d..f1d9464 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -58,10 +58,12 @@ float mouse_direction = 0; bool mouse_deadzone = false; // true if the mouse has control +float mouse_control_override_time = 0; bool mouse_control_override = false; bool mouse_control = false; const float thruster_offset = 0.05f; +const float mouse_timeout = 0.200f; // 200 ms mouse timout int mouse_position_x() { return mouse_x; @@ -232,10 +234,10 @@ void init() input_mousecontrol = core::Cvar::get("input_mousecontrol", 1.0f, core::Cvar::Archive); input_mousecontrol->set_info("[bool] enable or disable mouse control"); - input_keydelay = core::Cvar::get("input_keydelay", 250.0f, core::Cvar::Archive); + input_keydelay = core::Cvar::get("input_keydelay", 150.0f, core::Cvar::Archive); input_keydelay->set_info("[int] keyboard delay time-out in milliseconds"); - input_keyrepeat = core::Cvar::get("input_keyrepeat", 30.0f, core::Cvar::Archive); + input_keyrepeat = core::Cvar::get("input_keyrepeat", 15.0f, core::Cvar::Archive); input_keyrepeat->set_info("[int] keyboard repeat time-out in milliseconds"); core::Func *func = 0; @@ -308,7 +310,7 @@ void shutdown() } -void action_press(std::string const &action) +void action_press(Key const *key, std::string const &action) { /* -- thruster ------------------------------------ */ if (action.compare("+thrustup") == 0) { @@ -321,6 +323,7 @@ void action_press(std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { mouse_control_override = true; + mouse_control_override_time = key->pressed(); /* -- directional control ------------------------- */ } else if (action.compare("+left") == 0) { @@ -357,7 +360,7 @@ void action_press(std::string const &action) con_warn << "Unknown action " << action << std::endl; } -void action_release(std::string const &action) +void action_release(Key *key, std::string const &action) { /* -- thruster ------------------------------------ */ if (action.compare("+thrustup") == 0) { @@ -369,6 +372,7 @@ void action_release(std::string const &action) /* -- mouse control ------------------------------- */ } else if (action.compare("+control") == 0) { mouse_control_override = false; + mouse_control_override_time = 0; if (!input_mousecontrol->value()) { local_direction = 0.0f; local_pitch = 0.0f; @@ -464,22 +468,14 @@ void key_pressed(Key *key) } else if (core::application()->connected() && core::localcontrol()) { - if ((render::Camera::mode() == render::Camera::Free) && (key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover()) { - // hovering target selected - targets::select_target(targets::hover()); - - } else { - char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0]; - if (c == '+') { - // action bind - action_press(key->bind(convert_SDL_modifier(keyboard_modifiers))); - - } else if (c) { - // normal bind - core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n"; - } + char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0]; + if (c == '+') { + // action bind + action_press(key, key->bind(convert_SDL_modifier(keyboard_modifiers))); + } else if (c) { + // normal bind + core::cmd() << key->bind(convert_SDL_modifier(keyboard_modifiers)) << "\n"; } - } else if (core::application()->connected()) { char c = key->bind(convert_SDL_modifier(keyboard_modifiers)).c_str()[0]; @@ -495,7 +491,7 @@ void key_released(Key *key) { if (core::application()->connected() && core::localcontrol() && !console()->visible() && !chat::visible()) { - if ((render::Camera::mode() != render::Camera::Free) && (key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover()) { + if ((key->sym() == 512 + SDL_BUTTON_LEFT) && targets::hover() && (key->waspressed() <= mouse_timeout) ) { // hovering target selected targets::select_target(targets::hover()); } @@ -505,22 +501,22 @@ void key_released(Key *key) c = key->bind(Key::None).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::None)); + action_release(key, key->bind(Key::None)); } c = key->bind(Key::Shift).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::Shift)); + action_release(key, key->bind(Key::Shift)); } c = key->bind(Key::Ctrl).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::Ctrl)); + action_release(key, key->bind(Key::Ctrl)); } c = key->bind(Key::Alt).c_str()[0]; if (c == '+') { // action bind - action_release(key->bind(Key::Alt)); + action_release(key, key->bind(Key::Alt)); } } } @@ -543,14 +539,16 @@ void reset() mouse_y = video::height / 2; render::Camera::reset(); mouse_control_override = false; + mouse_control_override_time = 0; targets::reset(); render::reset(); for (Keyboard::iterator it = keyboard->begin(); it != keyboard->end(); it++) { Key *key = (*it).second; if (key) { - key->pressed() = 0; - key->lastpressed() = 0; + key->key_pressed = 0; + key->key_lastpressed = 0; + key->key_waspressed = 0; } } } @@ -630,23 +628,18 @@ void frame(float seconds) } /* -- handle key repeat --------------------------- */ - float delay = 250.0f; // key delay time-out in milliseconds + float delay = 150.0f; // key delay time-out in milliseconds if (input_keydelay) { delay = input_keydelay->value(); math::clamp(delay, 50.0f, 500.0f); } - float repeat = 30.0f; // key repeat time-out in milliseconds + float repeat = 10.0f; // key repeat time-out in milliseconds if (input_keyrepeat) { repeat = input_keyrepeat->value(); math::clamp(repeat, 10.0f, 250.0f); } - - if (repeat > delay) { - float tmp = repeat; - repeat = delay; - delay = tmp; - } + if (input_keydelay) (*input_keydelay) = delay; if (input_keyrepeat) @@ -660,9 +653,9 @@ void frame(float seconds) if (key && key->sym() < 512 && key->pressed()) { while ((key->pressed()+delay < core::application()->time()) && (key->lastpressed()+repeat < core::application()->time())) { if (key->lastpressed() > key->pressed()) - key->lastpressed() += repeat; + key->key_lastpressed += repeat; else - key->lastpressed() += delay; + key->key_lastpressed += delay; key_pressed(key); } } @@ -671,11 +664,12 @@ void frame(float seconds) /* -- process mouse movement ----------------------*/ mouse_control = false; mouse_deadzone = false; - key->lastpressed() += repeat; + if (core::application()->connected() && core::localcontrol()) { - mouse_control = !console()->visible() && ((input_mousecontrol->value() > 0) || mouse_control_override); - core::localcontrol()->set_autolevel(!mouse_control); + mouse_control = !console()->visible() && ((input_mousecontrol->value() > 0) + || (mouse_control_override && (mouse_control_override_time + mouse_timeout < core::application()->time()))); + //core::localcontrol()->set_autolevel(!mouse_control); if (mouse_control) { // the mouse will not react if it is in the deadzone diff --git a/src/client/key.cc b/src/client/key.cc index 27d280f..c2da4a7 100644 --- a/src/client/key.cc +++ b/src/client/key.cc @@ -15,6 +15,7 @@ Key::Key(const char *name, int keysym, char ascii, const char *bind) key_ascii = ascii; key_pressed = 0; key_lastpressed = 0; + key_waspressed = 0; key_name.assign(name); diff --git a/src/client/key.h b/src/client/key.h index d1a8e96..06e0587 100644 --- a/src/client/key.h +++ b/src/client/key.h @@ -41,10 +41,13 @@ public: std::string const & bind(Modifier mod) const; /// first time the key was pressed since previous release - inline float & pressed() { return key_pressed; } + inline float pressed() const { return key_pressed; } - /// last time the key was pressed - inline float & lastpressed() { return key_lastpressed; } + /// last time the key was pressed (includes repeats) + 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; } @@ -52,14 +55,15 @@ public: inline int sym() const { return key_sym; } + float key_pressed; + float key_lastpressed; + float key_waspressed; + private: std::string key_name; int key_sym; char key_ascii; - float key_pressed; - float key_lastpressed; - std::string key_bind; std::string key_bind_shift; std::string key_bind_ctrl; diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index 791e6df..420d1bb 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -296,8 +296,10 @@ Key * Keyboard::release(unsigned int sym) return 0; } - key->pressed() = 0; - key->lastpressed() = 0; + key->key_waspressed = (core::application()->time() - key->pressed()); + key->key_pressed = 0; + key->key_lastpressed = 0; + return key; } @@ -313,10 +315,11 @@ Key * Keyboard::press(unsigned int sym) Key * Keyboard::press(Key *key) { - if (!key->pressed()) - key->pressed() = core::application()->time(); - key->lastpressed() = core::application()->time(); - + if (key->pressed() == 0) { + key->key_pressed = core::application()->time(); + key->key_waspressed = 0; + } + key->key_lastpressed = core::application()->time(); return key; } diff --git a/src/game/game.cc b/src/game/game.cc index 83daa93..2f5490f 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -190,7 +190,7 @@ Game *Game::game_instance = 0; Game::Game() : core::Module("Project::OSiRiON") { game_instance = this; - g_autolevel = 0; + g_impulsespeed = 0; } Game::~Game() @@ -231,8 +231,8 @@ void Game::init() func = core::Func::add("list_ship", (core::FuncPtr) func_list_ship); func->set_info("list ship statistics"); - g_autolevel = core::Cvar::get("g_autolevel", "1", core::Cvar::Game | core::Cvar::Archive); - g_autolevel->set_info("[bool] enable or disale experimental autolevelling"); + g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive); + g_impulsespeed->set_info("[float] speed of the impulse drive"); // indicate the module is ready to run frames module_running = true; @@ -240,7 +240,7 @@ void Game::init() void Game::shutdown() { - g_autolevel = 0; + g_impulsespeed = 0; // game functions are automaticly removed // remove engine core functions diff --git a/src/game/game.h b/src/game/game.h index 3d8e3b9..eed0b29 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -50,7 +50,7 @@ public: static inline Game *instance() { return game_instance; } - core::Cvar *g_autolevel; + core::Cvar *g_impulsespeed; private: bool load_world(); diff --git a/src/game/ship.cc b/src/game/ship.cc index aa47044..007b841 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -63,20 +63,6 @@ void Ship::frame(float seconds) // update thrust entity_thrust = target_thrust; - - if (autolevel() && Game::instance()->g_autolevel->value()) { - n.assign(math::crossproduct(entity_axis.up(), math::Vector3f(0, 0, 1.0f))); - if (!(n.length() < MIN_DELTA)) { - cosangle = math::dotproduct(entity_axis.up(), math::Vector3f(0, 0, 1.0f)); - target_roll = acos(cosangle); - math::clamp(target_roll, 0.0f, 1.0f); - target_roll *= M_1_PI; - target_roll *= math::sgnf(math::dotproduct(entity_axis.left(), math::Vector3f(0.0, 0.0f, 1.0f))); - } else { - target_roll = 0; - } - } - if (current_target_roll < target_roll) { current_target_roll += direction_change_speed * seconds; if (current_target_roll > target_roll) @@ -95,19 +81,6 @@ void Ship::frame(float seconds) current_target_roll = 0.0f; } - // auto-leveling - if (autolevel() && Game::instance()->g_autolevel->value()) { - n.assign(math::crossproduct(entity_axis.up(), math::Vector3f(0.0f, 0.0f, 1.0f))); - if (!(n.length() < MIN_DELTA)) { - cosangle = math::dotproduct(entity_axis.up(), math::Vector3f(0.0f, 0.0f, 1.0f)); - target_pitch = acos(cosangle); - math::clamp(target_roll, 0.0f, 1.0f); - target_pitch *= -math::sgnf(math::dotproduct(entity_axis.forward(), math::Vector3f(0.0, 0.0f, 1.0f))); - } else { - target_pitch = 0; - } - } - // update target_axis direction if (current_target_direction < target_direction) { current_target_direction += direction_change_speed * seconds; diff --git a/src/model/engine.cc b/src/model/engine.cc index eb4198a..706de15 100644 --- a/src/model/engine.cc +++ b/src/model/engine.cc @@ -18,7 +18,9 @@ Engine::Engine() : { engine_radius = 1.0f; engine_flare = 0; - engine_color.assign(1.0f, 0.0f, 0.0f , 1.0f); + + engine_notrail = false; + engine_noflare = false; } Engine::Engine(math::Vector3f const & location) : diff --git a/src/model/engine.h b/src/model/engine.h index c3e6064..724c060 100644 --- a/src/model/engine.h +++ b/src/model/engine.h @@ -27,11 +27,6 @@ public: return engine_location; } - inline math::Color const & color() const - { - return engine_color; - } - inline float radius() const { return engine_radius; @@ -46,11 +41,24 @@ public: { return render_texture; } + + inline bool noflare() const + { + return engine_noflare; + } + + inline bool notrail() const + { + return engine_notrail; + } math::Vector3f engine_location; float engine_radius; - math::Color engine_color; unsigned int engine_flare; + + + bool engine_noflare; + bool engine_notrail; unsigned int render_texture; }; diff --git a/src/model/map.cc b/src/model/map.cc index 377ed0d..62604ea 100644 --- a/src/model/map.cc +++ b/src/model/map.cc @@ -805,6 +805,8 @@ Model * Map::load(std::string const &name) if (mapfile.got_key_int("enginesound", u)) { model->model_enginesound = u; continue; + } else if (mapfile.got_key_color("enginecolor", model->model_enginecolor) ==0) { + continue; } } else if (mapfile.got_classname("light")) { @@ -896,18 +898,17 @@ Model * Map::load(std::string const &name) if (mapfile.got_key_vector3f("origin", engine->engine_location)) { engine->engine_location *= SCALE; continue; - - } else if (mapfile.got_key_color("_color", engine->engine_color)) { - continue; - + } else if (mapfile.got_key_float("radius", engine->engine_radius)) { engine->engine_radius /= 100.0f; continue; - } else if (mapfile.got_key_int("flare", engine->engine_flare)) { + } else if (mapfile.got_key_int("flare", engine->engine_flare)) { continue; - } else if (mapfile.got_key_color("_color", engine->engine_color)) { + } else if (mapfile.got_key_int("spawnflags", u)) { + engine->engine_noflare = spawnflag_isset(u, 1); + engine->engine_notrail = spawnflag_isset(u, 2); continue; } } @@ -915,15 +916,15 @@ Model * Map::load(std::string const &name) mapfile.close(); - con_debug << " " << mapfile.name() << " " << mapfile.map_materials.size() << " mat " << - mapfile.map_brushes << " brushes " << - mapfile.map_faces << "/" << mapfile.map_faces_detail << " faces/detail " << std::endl; + con_debug << " " << mapfile.name() << " " << mapfile.map_materials.size() << " mat " << + mapfile.map_brushes << " brushes " << + mapfile.map_faces << "/" << mapfile.map_faces_detail << " faces/detail " << std::endl; mapfile.load_fragments(model); con_debug << " " << mapfile.name() << " " << model->fragments().size() << " frags " << - model->model_tris_count << "/" << model->model_tris_detail_count << " tris/detail " << - model->model_quad_count << "/" << model->model_quad_detail_count << " quads/detail" << std::endl; + model->model_tris_count << "/" << model->model_tris_detail_count << " tris/detail " << + model->model_quad_count << "/" << model->model_quad_detail_count << " quads/detail" << std::endl; mapfile.clear_materials(); diff --git a/src/model/model.cc b/src/model/model.cc index 101895b..3fa0cc0 100644 --- a/src/model/model.cc +++ b/src/model/model.cc @@ -16,7 +16,9 @@ namespace model Model::Registry Model::model_registry; Model::Model(std::string const & name) : - model_name(name) + model_enginecolor(1.0f, 0.0f, 0.0f), + model_name(name) + { model_radius = 0.5f; model_enginesound = 0; diff --git a/src/model/model.h b/src/model/model.h index 552d7dd..47728cb 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -95,10 +95,13 @@ public: } /// engine sound loop for this model - inline unsigned int & enginesound() + inline unsigned int enginesound() const { return model_enginesound; } + + /// engine color for this model + inline math::Color const & enginecolor() const { return model_enginecolor; } /// add a light to the model void add_light(Light *light); @@ -115,6 +118,8 @@ public: math::Vector3f model_minbbox; unsigned int model_enginesound; + + math::Color model_enginecolor; /* ---- static functions for the Model registry -------------------- */ diff --git a/src/render/draw.cc b/src/render/draw.cc index 8d8ea1f..2752030 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -302,7 +302,7 @@ void draw_model_fragments(core::Entity *entity) use_color_array = false; } - gl::color(thrust, 0.0f, 0.0f); + gl::color(model->enginecolor() * thrust); } else if (material & Material::Tertiary) { if (use_color_array) { @@ -643,7 +643,7 @@ void draw_pass_model_fx(float elapsed) // strobe frequency t = 1.0f; if (light->strobe()) - t = (core::application()->time() - light->offset() - entity->state()->fuzz()) * light->frequency(); + t = (core::application()->time() + entity->state()->fuzz() - light->offset()) * light->frequency(); if ((!light->strobe()) || (( t - floorf(t)) <= light->time())) { location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * light->location())); light_size = 0.0625 * light->radius(); @@ -703,7 +703,6 @@ void draw_pass_model_fx(float elapsed) color.assign(flare->color()); } - // FIXME Camera::axis().forward() should be the vector flare_location - camera_eye a = dotproduct(flare_axis.forward(), Camera::axis().forward()); if (a < -0.1f) { color.a = -a - 0.1f; @@ -737,15 +736,12 @@ void draw_pass_model_fx(float elapsed) t -= 1.0f; math::clamp(t, 0.0f, 1.0f); entity->state()->state_engine_trail_offset = t; - + for(model::Model::Engines::iterator eit = entity->model()->engines().begin(); eit != entity->model()->engines().end(); eit++) { engine = (*eit); - location.assign(entity->state()->location() - Camera::eye() + (entity->state()->axis() * engine->location())); - engine_size = 0.0625 * engine->radius(); - color.assign(engine->color()); - color.a = 0.9f * u; + engine_size = 0.0625 * engine->radius(); if (current_texture != engine->texture() ) { gl::end(); @@ -757,57 +753,65 @@ void draw_pass_model_fx(float elapsed) quad[1].assign(entity->state()->axis().up() + entity->state()->axis().left()); quad[2].assign(entity->state()->axis().up() * -1 + entity->state()->axis().left()); quad[3].assign(entity->state()->axis().up() * -1 - entity->state()->axis().left()); - - gl::color(color); - glTexCoord2f(0,1); - gl::vertex(location + quad[0] * engine_size); - glTexCoord2f(0,0); - gl::vertex(location + quad[1] * engine_size); - glTexCoord2f(1,0); - gl::vertex(location + quad[2] * engine_size); - glTexCoord2f(1,1); - gl::vertex(location + quad[3] * engine_size); - Stats::quads++; - - // draw the engine trail - if (current_texture != circle_texture) { - gl::end(); - current_texture = Textures::bind(circle_texture); - gl::begin(gl::Quads); - } - color.assign(1.0f, 1.0f); - offset.assign(entity->state()->axis().forward() * engine_size); - if (t > 0) - location -= offset * t; - - for (size_t i = count; i > 0; i--) { - trail_size = engine_size * 0.8f * (0.4f + ((-t + (float) i) / (float) count) * 0.6f); - color.a = (0.1f + ((-t + (float) i) / (float) count) * 0.7f) * u; - gl::color(color); + // assign engine color to the flare + if (!engine->noflare()){ + color.assign(entity->model()->enginecolor()); + color.a = 0.9f * u; + + gl::color(color); glTexCoord2f(0,1); - gl::vertex(location + quad[0] * trail_size); + gl::vertex(location + quad[0] * engine_size); glTexCoord2f(0,0); - gl::vertex(location + quad[1] * trail_size); + gl::vertex(location + quad[1] * engine_size); glTexCoord2f(1,0); - gl::vertex(location + quad[2] * trail_size); + gl::vertex(location + quad[2] * engine_size); glTexCoord2f(1,1); - gl::vertex(location + quad[3] * trail_size); + gl::vertex(location + quad[3] * engine_size); Stats::quads++; + } + + if (!engine->notrail()) { + // draw the engine trail + if (current_texture != circle_texture) { + gl::end(); + current_texture = Textures::bind(circle_texture); + gl::begin(gl::Quads); + } + color.assign(1.0f, 1.0f); + offset.assign(entity->state()->axis().forward() * engine_size); + if (t > 0) + location -= offset * t; - gl::color(color); - glTexCoord2f(1,1); - gl::vertex(location + quad[3] * trail_size); - glTexCoord2f(1,0); - gl::vertex(location + quad[2] * trail_size); - glTexCoord2f(0,0); - gl::vertex(location + quad[1] * trail_size); - glTexCoord2f(0,1); - gl::vertex(location + quad[0] * trail_size); - Stats::quads++; - - location -= offset; + for (size_t i = count; i > 0; i--) { + trail_size = engine_size * 0.8f * (0.4f + ((-t + (float) i) / (float) count) * 0.6f); + color.a = (0.1f + ((-t + (float) i) / (float) count) * 0.7f) * u; + gl::color(color); + glTexCoord2f(0,1); + gl::vertex(location + quad[0] * trail_size); + glTexCoord2f(0,0); + gl::vertex(location + quad[1] * trail_size); + glTexCoord2f(1,0); + gl::vertex(location + quad[2] * trail_size); + glTexCoord2f(1,1); + gl::vertex(location + quad[3] * trail_size); + Stats::quads++; + + + gl::color(color); + glTexCoord2f(1,1); + gl::vertex(location + quad[3] * trail_size); + glTexCoord2f(1,0); + gl::vertex(location + quad[2] * trail_size); + glTexCoord2f(0,0); + gl::vertex(location + quad[1] * trail_size); + glTexCoord2f(0,1); + gl::vertex(location + quad[0] * trail_size); + Stats::quads++; + + location -= offset; + } } } } -- cgit v1.2.3