diff options
author | Stijn Buys <ingar@osirion.org> | 2008-08-24 21:36:39 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-08-24 21:36:39 +0000 |
commit | e6272cd7d356bbb047dcaebb03ae217235e1e13f (patch) | |
tree | 7c7c6551a2d7051d10b0c4f0c4d87554365c63de /src | |
parent | 9c4d134ab304794b755139e90ca6da9de73a1e9a (diff) |
afterburner/reverse/strafe
Diffstat (limited to 'src')
-rw-r--r-- | src/client/input.cc | 47 | ||||
-rw-r--r-- | src/client/keyboard.cc | 15 | ||||
-rw-r--r-- | src/core/application.cc | 2 | ||||
-rw-r--r-- | src/core/entity.cc | 30 | ||||
-rw-r--r-- | src/core/entity.h | 15 | ||||
-rw-r--r-- | src/core/gameserver.cc | 55 | ||||
-rw-r--r-- | src/core/gameserver.h | 2 | ||||
-rw-r--r-- | src/core/net.h | 2 | ||||
-rw-r--r-- | src/game/game.cc | 7 | ||||
-rw-r--r-- | src/game/game.h | 1 | ||||
-rw-r--r-- | src/game/ship.cc | 113 | ||||
-rw-r--r-- | src/game/ship.h | 5 |
12 files changed, 240 insertions, 54 deletions
diff --git a/src/client/input.cc b/src/client/input.cc index d898b78..75fa0f3 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -48,6 +48,8 @@ float local_direction = 0.0f; float local_pitch = 0.0f; float local_thrust = 0.0f; float local_roll = 0.0f; +float local_strafe = 0.0f; +float local_afterburner = 0.0f; // last controlled entity unsigned int last_control = 0; @@ -379,6 +381,18 @@ void action_press(Key const *key, std::string const &action) } else if (action.compare("+rollright") == 0) { local_roll = -1.0f; + } else if (action.compare("+strafeleft") == 0) { + local_strafe = 1.0f; + + } else if (action.compare("+straferight") == 0) { + local_strafe = -1.0f; + + } else if (action.compare("+afterburner") == 0) { + local_afterburner = 1.0f; + + } else if (action.compare("+reverse") == 0) { + local_afterburner = -1.0f; + /* -- camera control ------------------------------ */ } else if (action.compare("+camleft") == 0) { render::Camera::set_direction(1.0f); @@ -440,6 +454,18 @@ void action_release(Key *key, std::string const &action) } else if (action.compare("+rollright") == 0) { local_roll = 0.0f; + } else if (action.compare("+strafeleft") == 0) { + local_strafe = 0.0f; + + } else if (action.compare("+straferight") == 0) { + local_strafe = 0.0f; + + } else if (action.compare("+afterburner") == 0) { + local_afterburner = 0.0f; + + } else if (action.compare("+reverse") == 0) { + local_afterburner = 0.0f; + /* -- camera control ------------------------------ */ } else if (action.compare("+camleft") == 0) { render::Camera::set_direction(0.0f); @@ -610,6 +636,9 @@ void reset() local_direction = 0.0f; local_pitch = 0.0f; local_roll = 0.0f; + local_strafe = 0.0f; + local_afterburner = 0.0f; + if (core::localcontrol()) { local_thrust = core::localcontrol()->thrust(); last_control = core::localcontrol()->id(); @@ -645,20 +674,7 @@ void frame(float seconds) { /* -- detect localcontrol() changes --------------- */ if (core::localcontrol() && (last_control != core::localcontrol()->id())) { - - local_direction = 0.0f; - local_pitch = 0.0f; - local_roll = 0.0f; - local_thrust = core::localcontrol()->thrust(); - last_control = core::localcontrol()->id(); - mouse_pitch = 0.0f; - mouse_direction = 0.0f; - mouse_x = video::width / 2; - mouse_y = video::height / 2; - render::Camera::reset(); - mouse_control_override = false; - targets::reset(); - render::reset(); + reset(); } if (core::localcontrol() && (core::localcontrol()->eventstate() != core::Entity::Normal)) { @@ -839,6 +855,7 @@ void frame(float seconds) math::clamp(local_pitch, -1.0f, 1.0f); math::clamp(local_roll, -1.0f, 1.0f); math::clamp(local_thrust, 0.0f, 1.0f); + if (local_thrust < 0.01f) local_thrust = 0.0f; else if (local_thrust > 0.99f) @@ -848,6 +865,8 @@ void frame(float seconds) core::localcontrol()->set_direction(local_direction); core::localcontrol()->set_pitch(local_pitch / render::Camera::aspect() ); core::localcontrol()->set_roll(local_roll); + core::localcontrol()->set_strafe(local_strafe); + core::localcontrol()->set_afterburner(local_afterburner); } } diff --git a/src/client/keyboard.cc b/src/client/keyboard.cc index aac6548..ae21eb1 100644 --- a/src/client/keyboard.cc +++ b/src/client/keyboard.cc @@ -49,6 +49,12 @@ Keyboard::Keyboard() add_action("+thrustup", Action::None, "increase thruster"); add_action("+thrustdown", Action::None, "decrease thruster"); + add_action("+strafeleft", Action::None, "strafe left"); + add_action("+straferight", Action::None, "strafe right"); + + add_action("+afterburner", Action::None, "afterburner"); + add_action("+reverse", Action::None, "reverse engine"); + add_action("+control", Action::None, "enable mouse control while pressed"); // ------------------ KEYS @@ -102,10 +108,10 @@ Keyboard::Keyboard() add_key("_", SDLK_UNDERSCORE, '_'); add_key("`", SDLK_BACKQUOTE, '`', "ui_console"); - add_key("a", SDLK_a, 'a'); + add_key("a", SDLK_a, 'a', "+strafeleft"); add_key("b", SDLK_b, 'b'); add_key("c", SDLK_c, 'c'); - add_key("d", SDLK_d, 'd'); + add_key("d", SDLK_d, 'd', "+straferight"); add_key("e", SDLK_e, 'e'); add_key("f", SDLK_f, 'f'); add_key("g", SDLK_g, 'g'); @@ -121,13 +127,13 @@ Keyboard::Keyboard() add_key("p", SDLK_p, 'p'); add_key("q", SDLK_q, 'q'); add_key("r", SDLK_r, 'r'); - add_key("s", SDLK_s, 's'); + add_key("s", SDLK_s, 's', "+reverse"); add_key("t", SDLK_t, 't', "ui_chat"); add_key("u", SDLK_u, 'u'); key = add_key("v", SDLK_v, 'v', "view_next"); key->assign(Key::Shift, "view_prev"); - add_key("w", SDLK_w, 'w'); + add_key("w", SDLK_w, 'w', "+afterburner"); add_key("x", SDLK_x, 'x', "target_center"); add_key("y", SDLK_y, 'y'); add_key("z", SDLK_z, 'z'); @@ -264,6 +270,7 @@ void Keyboard::save_binds() ofs << "# binds.cfg - osirion keyboard binds" << std::endl; ofs << "# this file is automaticly generated" << std::endl; + ofs << std::endl; iterator it; for (it = begin(); it != end(); it++) { diff --git a/src/core/application.cc b/src/core/application.cc index 49c61d7..21d5e50 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -348,11 +348,13 @@ void Application::save_config() ofs << "# server.cfg - osiriond dedicated server configuration" << std::endl; ofs << "# this file is automaticly generated" << std::endl; + ofs << std::endl; for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) { if (((*it).second->flags() & Cvar::Archive) == Cvar::Archive) { ofs << "# " << (*it).first << " " << (*it).second->info() << std::endl; ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; + ofs << std::endl; } } ofs.close(); diff --git a/src/core/entity.cc b/src/core/entity.cc index 04ede71..99462b8 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -376,6 +376,8 @@ EntityControlable::EntityControlable(Player *owner, unsigned int flags) : target_thrust = 0.0f; target_pitch = 0.0f; target_roll = 0.0f; + target_strafe = 0.0f; + target_afterburner = 0.0f; entity_owner = 0; if (owner) @@ -391,6 +393,8 @@ EntityControlable::EntityControlable(std::istream & is) : target_thrust = 0.0f; target_pitch = 0.0f; target_roll = 0.0f; + target_strafe = 0.0f; + target_afterburner = 0.0f; entity_owner = 0; } @@ -429,6 +433,8 @@ void EntityControlable::serialize_client_update(std::ostream & os) const os << target_pitch << " "; os << target_thrust << " "; os << target_roll << " "; + os << target_strafe << " "; + os << target_afterburner << " "; } void EntityControlable::receive_client_update(std::istream &is) @@ -438,6 +444,8 @@ void EntityControlable::receive_client_update(std::istream &is) is >> target_pitch; is >> target_thrust; is >> target_roll; + is >> target_strafe; + is >> target_afterburner; } void EntityControlable::serialize_server_update(std::ostream & os) const @@ -505,6 +513,28 @@ void EntityControlable::set_roll(float roll) } } +void EntityControlable::set_strafe(float strafe) +{ + if ((flags() & Static) == Static) + return; + + if (target_strafe != strafe) { + target_strafe = strafe; + entity_dirty = true; + } +} + +void EntityControlable::set_afterburner(float afterburner) +{ + if ((flags() & Static) == Static) + return; + + if (target_afterburner != afterburner) { + target_afterburner = afterburner; + entity_dirty = true; + } +} + /*----- EntityGlobe ------------------------------------------------ */ EntityGlobe::EntityGlobe(unsigned int flags) : diff --git a/src/core/entity.h b/src/core/entity.h index 8a996fd..6214d50 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -342,9 +342,15 @@ public: /// set the target pitch void set_pitch(float pitch); - /// set target roll + /// set target roll void set_roll(float roll); + /// set target strafe + void set_strafe(float strage); + + /// set afterburner/reverse + void set_afterburner(float afterburner); + /// runs one game frame for the entity /** * The default implementation will set direction() and thrust() to the desired targets @@ -355,6 +361,7 @@ public: /// current thrust float entity_thrust; +protected: /* target_ variables can be set by the client */ /// target thrust as set by the client float target_thrust; @@ -369,7 +376,11 @@ public: /// target roll as set by the client /** target_roll must be in the [-1, 1] range */ - float target_roll; + float target_roll; + + float target_afterburner; + + float target_strafe; private: // owner of the entity diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index fce758e..ea97eaf 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -5,6 +5,7 @@ */ #include <iomanip> +#include <fstream> #include "auxiliary/functions.h" #include "sys/sys.h" @@ -13,6 +14,7 @@ #include "core/func.h" #include "core/gameserver.h" #include "core/netserver.h" +#include "filesystem/filesystem.h" namespace core { @@ -119,6 +121,8 @@ GameServer::GameServer() : GameInterface() return; } + load_config(); + // set the name of the game core::Cvar::set("g_name", server_module->name().c_str(), core::Cvar::Game | core::Cvar::ReadOnly); @@ -190,6 +194,8 @@ GameServer::~GameServer() server_network = 0; } + save_config(); + if (server_module) { if (server_module->running() && !Cvar::sv_dedicated->value()) player_disconnect(localplayer()); @@ -583,5 +589,54 @@ void GameServer::frame(float seconds) server_previoustime = server_time; } +void GameServer::save_config() +{ + std::string filename(filesystem::writedir()); + filename.append("game.cfg"); + std::ofstream ofs(filename.c_str()); + + if (!ofs.is_open()) { + con_warn << "Could not write " << filename << std::endl; + return; + } + + con_print << " writing configuration to " << filename << std::endl; + + ofs << "# game.cfg - " << server_module->name() << " configuration" << std::endl; + ofs << "# this file is automaticly generated" << std::endl; + ofs << std::endl; + + for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) { + if ((((*it).second->flags() & Cvar::Archive) == Cvar::Archive) && (((*it).second->flags() & Cvar::Game) == Cvar::Game)){ + ofs << "# " << (*it).first << " " << (*it).second->info() << std::endl; + ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; + ofs << std::endl; + } + } + ofs.close(); +} + +void GameServer::load_config() +{ + std::string filename(filesystem::writedir()); + filename.append("game.cfg"); + std::ifstream ifs(filename.c_str(), std::ifstream::in); + + if (!ifs.is_open()) { + con_warn << "Could not read " << filename << std::endl; + return; + } + + con_print << " reading configuration from " << filename << std::endl; + + char line[MAXCMDSIZE]; + while (ifs.getline(line, MAXCMDSIZE-1)) { + if (line[0] && line[0] != '#' && line[0] != ';') + cmd() << line << '\n'; + } + + // execute commands in the buffer + CommandBuffer::exec(); +} } diff --git a/src/core/gameserver.h b/src/core/gameserver.h index 98938fa..1f6d8cc 100644 --- a/src/core/gameserver.h +++ b/src/core/gameserver.h @@ -93,6 +93,8 @@ protected: void abort(); private: + void load_config(); + void save_config(); bool server_running; Module *server_module; static GameServer *server_instance; diff --git a/src/core/net.h b/src/core/net.h index d5a95a9..c96ec7e 100644 --- a/src/core/net.h +++ b/src/core/net.h @@ -11,7 +11,7 @@ namespace core { /// network protocol version -const unsigned int PROTOCOLVERSION = 7; +const unsigned int PROTOCOLVERSION = 8; /// maximum lenght of a (compressed) network message block const unsigned int FRAMESIZE = 1152; diff --git a/src/game/game.cc b/src/game/game.cc index d0b4466..6b44c51 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -214,10 +214,13 @@ void Game::init() func->set_info("list ship statistics"); g_impulsespeed = core::Cvar::get("g_impulsespeed", "15", core::Cvar::Game | core::Cvar::Archive); - g_impulsespeed->set_info("[float] standard speed of the impulse drive"); + g_impulsespeed->set_info("[float] speed of the impulse drive"); g_impulseacceleration = core::Cvar::get("g_impulseacceleration", "4", core::Cvar::Game | core::Cvar::Archive); - g_impulseacceleration->set_info("[float] standard acceleration of the impulse drive"); + g_impulseacceleration->set_info("[float] acceleration of the impulse drive"); + + g_strafespeed = core::Cvar::get("g_strafespeed", "0.002", core::Cvar::Game | core::Cvar::Archive); + g_strafespeed->set_info("[float] strafe speed"); g_devel = core::Cvar::get("g_devel", "0", core::Cvar::Archive); g_devel->set_info("[bool] enable or disable developer mode"); diff --git a/src/game/game.h b/src/game/game.h index b9e6104..be64dd2 100644 --- a/src/game/game.h +++ b/src/game/game.h @@ -53,6 +53,7 @@ public: core::Cvar *g_impulsespeed; core::Cvar *g_impulseacceleration; + core::Cvar *g_strafespeed; core::Cvar *g_devel; diff --git a/src/game/ship.cc b/src/game/ship.cc index 9cfea4d..6ca29ba 100644 --- a/src/game/ship.cc +++ b/src/game/ship.cc @@ -4,23 +4,24 @@ the terms and conditions of the GNU General Public License version 2 */ -// project headers +#include <cmath> +#include <iostream> + #include "auxiliary/functions.h" #include "core/gameserver.h" #include "core/entity.h" #include "game/game.h" #include "game/ship.h" -#include "math/mathlib.h" +#include "math/functions.h" + -// C++ headers -#include <iostream> using math::degrees360f; using math::degrees180f; namespace game { -const float MIN_DELTA = 10e-10; +const float MIN_DELTA = 0.000001f; Ship::Ship(core::Player *owner, ShipModel *shipmodel) : core::EntityControlable(owner, ship_enttype) @@ -31,10 +32,6 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : entity_moduletypeid = ship_enttype; - current_target_direction = 0.0f; - current_target_pitch = 0.0f;; - current_target_roll = 0.0f; - entity_color = owner->color(); entity_color_second = owner->color_second(); @@ -45,6 +42,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) : ship_impulsedrive_timer = 0; ship_jumpdrive_timer = 0; + + reset(); } Ship::~Ship() @@ -52,6 +51,14 @@ Ship::~Ship() } +void Ship::reset() +{ + current_target_direction = 0.0f; + current_target_pitch = 0.0f;; + current_target_roll = 0.0f; + current_target_strafe = 0.0f; + current_target_afterburner = 0.0f; +} void Ship::impulse() { if (entity_eventstate == core::Entity::Jump) { @@ -183,8 +190,18 @@ void Ship::frame(float seconds) target_pitch = 0; target_roll = 0; target_direction = 0; + target_afterburner = 0.0f; + target_thrust = 0; } else if (entity_eventstate == core::Entity::Jump) { + // control is disabled while the jumpdrive is activated + target_thrust = 0; + target_pitch = 0; + target_roll = 0; + target_direction = 0; + target_afterburner = 0.0f; + target_thrust = 0; + // FIXME jump location and axis math::Axis default_axis; entity_axis.assign(default_axis); @@ -215,7 +232,7 @@ void Ship::frame(float seconds) math::clamp(target_pitch, -1.0f, 1.0f); math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); - + math::clamp(target_afterburner, -1.0f, 1.0f); actual_turnspeed *= 0.5; } else if (entity_eventstate == core::Entity::Impulse) { @@ -225,7 +242,7 @@ void Ship::frame(float seconds) math::clamp(target_pitch, -1.0f, 1.0f); math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); - + target_afterburner = 0.0f; actual_maxspeed = Game::instance()->g_impulsespeed->value(); actual_acceleration = Game::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; @@ -237,26 +254,15 @@ void Ship::frame(float seconds) math::clamp(target_pitch, -1.0f, 1.0f); math::clamp(target_roll, -1.0f, 1.0f); math::clamp(target_direction, -1.0f, 1.0f); + math::clamp(target_afterburner, -1.0f, 1.0f); - if (speed() > actual_maxspeed) { + if (speed() > actual_maxspeed * 1.15f) { actual_acceleration = Game::instance()->g_impulseacceleration->value(); actual_turnspeed *= 0.5; } } - // update thrust - if (entity_thrust < target_thrust) { - entity_thrust += seconds * 0.5f; - if (entity_thrust > target_thrust) - entity_thrust = target_thrust; - } else if (entity_thrust > target_thrust) { - entity_thrust -= seconds * 0.5f; - if (entity_thrust < target_thrust) - entity_thrust = target_thrust; - } - //math::clamp(entity_thrust, 0.0f, 1.0f); - // update roll if (current_target_roll < target_roll) { current_target_roll += direction_change_speed * seconds; @@ -322,21 +328,66 @@ void Ship::frame(float seconds) entity_axis.rotate(n, -angle); } + // update afterburner + if (current_target_afterburner < target_afterburner) { + current_target_afterburner += 2.0f * seconds; + if (current_target_afterburner > target_afterburner) + current_target_afterburner = target_afterburner; + } else if (current_target_afterburner > target_afterburner) { + current_target_afterburner -= 2.0f * seconds; + if (current_target_afterburner < target_afterburner) + current_target_afterburner = target_afterburner; + } + + // update thrust + if (current_target_afterburner < 0.0f) { + target_thrust = 0; + } + + if (entity_thrust < target_thrust) { + entity_thrust += seconds * 0.5f; + if (entity_thrust > target_thrust) + entity_thrust = target_thrust; + } else if (entity_thrust > target_thrust) { + entity_thrust -= seconds * 0.5f; + if (entity_thrust < target_thrust) + entity_thrust = target_thrust; + } + math::clamp(entity_thrust, 0.0f, 1.0f); + float actual_thrust = entity_thrust + current_target_afterburner * 0.15f; + // update speed - if (entity_speed < entity_thrust * actual_maxspeed) { + if (entity_speed < actual_thrust * actual_maxspeed) { entity_speed += actual_acceleration * seconds; - if (entity_speed > entity_thrust * actual_maxspeed) { - entity_speed = entity_thrust * actual_maxspeed; + if (entity_speed > actual_thrust * actual_maxspeed) { + entity_speed = actual_thrust * actual_maxspeed; } - } else if(entity_speed > entity_thrust * actual_maxspeed) { + } else if(entity_speed > actual_thrust * actual_maxspeed) { entity_speed -= actual_acceleration * seconds; - if (entity_speed < 0.0f) entity_speed = 0.0f; + if (entity_speed < actual_thrust * actual_maxspeed) { + entity_speed = actual_thrust * actual_maxspeed; + } + } + + // update strafe + if (current_target_strafe < target_strafe) { + current_target_strafe += 2.0f * seconds; + if (current_target_strafe > target_strafe) + current_target_strafe = target_strafe; + } else if (current_target_strafe > target_strafe) { + current_target_strafe -= 2.0f * seconds; + if (current_target_strafe < target_strafe) + current_target_strafe = target_strafe; + } + + if (fabs(current_target_strafe) > MIN_DELTA) { + entity_location += entity_axis.left() * (current_target_strafe * Game::instance()->g_strafespeed->value()); } - if (entity_speed != 0.0f) { + if (entity_speed) { entity_location += entity_axis.forward() * entity_speed * seconds; entity_dirty = true; - } else if ((current_target_pitch != 0.0f) || (current_target_direction != 0.0f) || (current_target_roll != 0.0f)) { + } else if ((current_target_pitch != 0.0f) || (current_target_direction != 0.0f) || (current_target_roll != 0.0f) || (current_target_afterburner != 0.0f) || (current_target_strafe != 0)) { entity_dirty = true; } } diff --git a/src/game/ship.h b/src/game/ship.h index 16c0c14..e85a0ad 100644 --- a/src/game/ship.h +++ b/src/game/ship.h @@ -33,12 +33,17 @@ public: /// toggle impulse drive activation void impulse(); + /// void reset drive controls + void reset(); + private: ShipModel *ship_shipmodel; float current_target_direction; float current_target_pitch; float current_target_roll; + float current_target_strafe; + float current_target_afterburner; bool ship_jumpdrive; float ship_jumpdrive_timer; |