From 7a373c3f1fb8ea9dbef7690154bbe332fc386eca Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 18 Oct 2010 23:41:41 +0000 Subject: bullet ActionInterface for controlable entities, KeepAlive flag and g_keepalive --- src/game/base/cargopod.cc | 3 ++ src/game/base/game.cc | 5 ++- src/game/base/game.h | 3 ++ src/game/base/ship.cc | 80 +++++++++++++++++++++++++---------------------- 4 files changed, 53 insertions(+), 38 deletions(-) (limited to 'src/game') diff --git a/src/game/base/cargopod.cc b/src/game/base/cargopod.cc index efdfe33..6581b75 100644 --- a/src/game/base/cargopod.cc +++ b/src/game/base/cargopod.cc @@ -15,6 +15,9 @@ CargoPod::CargoPod() : EntityDynamic() entity_moduletypeid = cargopod_enttype; set_name("Cargo pod"); set_label("cargopod"); + + set_flag(core::Entity::KeepAlive); + set_keepalive_timeout(Game::g_keepalive ? Game::g_keepalive->value() : 0); // FIXME hardcoded modelname set_modelname("maps/cargo/pod"); diff --git a/src/game/base/game.cc b/src/game/base/game.cc index 346208b..ebf09ce 100644 --- a/src/game/base/game.cc +++ b/src/game/base/game.cc @@ -55,6 +55,7 @@ core::Cvar *Game::g_impulseacceleration = 0; core::Cvar *Game::g_jumppointrange = 0; core::Cvar *Game::g_devel = 0; core::Cvar *Game::g_damping = 0; +core::Cvar *Game::g_keepalive; core::Module *factory() { @@ -802,6 +803,9 @@ Game::Game() : core::Module("Project::OSiRiON", true) g_damping = core::Cvar::get("g_damping", "0.1", core::Cvar::Archive); g_damping->set_info("[float] physics damping factor (0-1)"); + + g_keepalive = core::Cvar::get("g_keepalive", "300", core::Cvar::Archive); + g_keepalive->set_info("[float] amount of time dynamic objects are kept alive, in seconds"); } Game::~Game() @@ -1372,7 +1376,6 @@ bool Game::load_defaults() void Game::frame(float seconds) { - if (!running()) return; } diff --git a/src/game/base/game.h b/src/game/base/game.h index c229a18..07df62d 100644 --- a/src/game/base/game.h +++ b/src/game/base/game.h @@ -83,6 +83,9 @@ public: /// physics variable: default damping factor of space static core::Cvar *g_damping; + + /// game variable: amount of time dynamic objects are kept alive when there are no players + static core::Cvar *g_keepalive; private: diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc index 44676c4..9f04e43 100644 --- a/src/game/base/ship.cc +++ b/src/game/base/ship.cc @@ -519,10 +519,7 @@ void Ship::frame(float seconds) entity_thrust = target_thrust; } math::clamp(entity_thrust, 0.0f, 1.0f); - actual_thrust = entity_thrust + current_target_afterburner * 0.15f; - if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) { - actual_thrust = 1.0f; - } + // update strafe control target if (current_target_strafe < target_strafe) { @@ -546,25 +543,6 @@ void Ship::frame(float seconds) current_target_vstrafe = target_vstrafe; } - // update roll control target - if (current_target_roll < target_roll) { - current_target_roll += direction_reaction * seconds; - if (current_target_roll > target_roll) - current_target_roll = target_roll; - } else if (current_target_roll > target_roll) { - current_target_roll -= direction_reaction * seconds; - if (current_target_roll < target_roll) - current_target_roll = target_roll; - } - math::clamp(current_target_roll, -1.0f, 1.0f); - - if (fabs(current_target_roll) > MIN_DELTA) { - float roll_offset = seconds * current_target_roll; - get_axis().change_roll(actual_turnspeed * roll_offset); - } else { - current_target_roll = 0.0f; - } - // update direction control target if (current_target_direction < target_direction) { current_target_direction += direction_reaction * seconds; @@ -578,13 +556,6 @@ void Ship::frame(float seconds) } } - if (fabs(current_target_direction) > MIN_DELTA) { - math::clamp(current_target_direction, -1.0f, 1.0f); - target_axis.change_direction(actual_turnspeed * current_target_direction); - } else { - current_target_direction = 0.0f; - } - // update pitch control target if (current_target_pitch < target_pitch) { current_target_pitch += direction_reaction * seconds; @@ -596,13 +567,17 @@ void Ship::frame(float seconds) current_target_pitch = target_pitch; } - if (fabs(current_target_pitch) > MIN_DELTA) { - math::clamp(current_target_pitch, -1.0f, 1.0f); - target_axis.change_pitch(actual_turnspeed * current_target_pitch); - } else { - current_target_pitch = 0.0f; + // update roll control target + if (current_target_roll < target_roll) { + current_target_roll += direction_reaction * seconds; + if (current_target_roll > target_roll) + current_target_roll = target_roll; + } else if (current_target_roll > target_roll) { + current_target_roll -= direction_reaction * seconds; + if (current_target_roll < target_roll) + current_target_roll = target_roll; } - + /* // -- BULLET @@ -628,10 +603,35 @@ void Ship::frame(float seconds) EntityDynamic::frame(seconds); */ + + // apply direction rotation to target axis + if (fabs(current_target_direction) > MIN_DELTA) { + math::clamp(current_target_direction, -1.0f, 1.0f); + target_axis.change_direction(actual_turnspeed * current_target_direction); + } else { + current_target_direction = 0.0f; + } + + // apply pitch rotation to target axis + if (fabs(current_target_pitch) > MIN_DELTA) { + math::clamp(current_target_pitch, -1.0f, 1.0f); + target_axis.change_pitch(actual_turnspeed * current_target_pitch); + } else { + current_target_pitch = 0.0f; + } + + // apply roll rotation to axis + if (fabs(current_target_roll) > MIN_DELTA) { + math::clamp(current_target_roll, -1.0f, 1.0f); + get_axis().change_roll(actual_turnspeed * current_target_roll * seconds); + } else { + current_target_roll = 0.0f; + } + + // update axis float cosangle; // cosine of an angle float angle; // angle in radians - // update axis n.assign(math::crossproduct(axis().forward(), target_axis.forward())); if (!(n.length() < MIN_DELTA)) { n.normalize(); @@ -642,6 +642,12 @@ void Ship::frame(float seconds) } // update speed + if ((entity_state == core::Entity::ImpulseInitiate) || (entity_state == core::Entity::Impulse)) { + actual_thrust = 1.0f; + } else { + actual_thrust = entity_thrust + current_target_afterburner * 0.15f; + } + const float max = actual_thrust * actual_maxspeed; if (entity_speed < max) { entity_speed += actual_acceleration * seconds; -- cgit v1.2.3