diff options
author | Stijn Buys <ingar@osirion.org> | 2008-02-21 21:01:17 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2008-02-21 21:01:17 +0000 |
commit | 71b6b902732bfc0c53033d58f91a6b1e70e8371f (patch) | |
tree | 0ff75879667ff985c9d69f8057727f6c805ad8b4 /src | |
parent | 8aa04fc836116a58f8ffd1e0c3539b9ea8a94ddf (diff) |
more minor updates
Diffstat (limited to 'src')
-rw-r--r-- | src/client/camera.cc | 14 | ||||
-rw-r--r-- | src/client/client.cc | 4 | ||||
-rw-r--r-- | src/client/client.h | 2 | ||||
-rw-r--r-- | src/client/draw.cc | 4 | ||||
-rw-r--r-- | src/client/input.cc | 29 | ||||
-rw-r--r-- | src/client/video.cc | 5 | ||||
-rw-r--r-- | src/core/commandbuffer.cc | 6 | ||||
-rw-r--r-- | src/core/entity.cc | 6 | ||||
-rw-r--r-- | src/core/gameconnection.cc | 19 | ||||
-rw-r--r-- | src/core/gameinterface.cc | 34 | ||||
-rw-r--r-- | src/core/gameinterface.h | 6 | ||||
-rw-r--r-- | src/core/gameserver.cc | 3 | ||||
-rw-r--r-- | src/core/netconnection.cc | 8 | ||||
-rw-r--r-- | src/core/netserver.cc | 5 | ||||
-rw-r--r-- | src/core/player.cc | 39 | ||||
-rw-r--r-- | src/core/player.h | 47 | ||||
-rw-r--r-- | src/game/game.cc | 19 | ||||
-rw-r--r-- | src/math/color.cc | 5 |
18 files changed, 179 insertions, 76 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc index dcf4acf..d9aa16e 100644 --- a/src/client/camera.cc +++ b/src/client/camera.cc @@ -82,7 +82,7 @@ void set_mode(Mode newmode) { case Track: // switch camera to Track mode mode = Track; - yaw_target = core::game()->localplayer()->control->direction(); + yaw_target = core::localcontrol()->direction(); yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; @@ -91,7 +91,7 @@ void set_mode(Mode newmode) { case Free: // switch camera to Free mode mode = Free; - yaw_target = core::game()->localplayer()->control->direction(); + yaw_target = core::localcontrol()->direction(); yaw_current = yaw_target; pitch_target = pitch_track; pitch_current = pitch_target; @@ -112,7 +112,7 @@ void set_mode(Mode newmode) { void next_mode() { - if (!core::game()->localplayer()->control) { + if (!core::localcontrol()) { set_mode(Overview); return; } @@ -133,20 +133,22 @@ void next_mode() void draw(float elapsed) { - if (!core::game()->localplayer()->control) { + if (!core::localcontrol()) { // switch the camera to Overview of the player is not controling anything if (mode != Overview) { set_mode(Overview); + + camera::target = math::Vector3f(0,0,0); } } else { if (mode == Overview) set_mode(Track); - camera::target = core::game()->localplayer()->control->location(); + camera::target = core::localcontrol()->location(); } if (mode == Track) { - yaw_target = core::game()->localplayer()->control->direction(); + yaw_target = core::localcontrol()->direction(); } if ((mode == Free) || (mode == Track)) { diff --git a/src/client/client.cc b/src/client/client.cc index 19d6f3e..4874e55 100644 --- a/src/client/client.cc +++ b/src/client/client.cc @@ -87,6 +87,10 @@ void Client::init() core::Cvar::sv_dedicated = core::Cvar::set("sv_private", "0"); core::Application::init(); + // client variables + core::Cvar::get("cl_name", "Player"); + core::Cvar::get("cl_color", "1.0 1.0 1.0"); + // initialize SDL, but do not initialize any subsystems SDL_Init(0); diff --git a/src/client/client.h b/src/client/client.h index ee2e7af..2113202 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -13,7 +13,7 @@ namespace client { /// the client main loop void main(int count, char **arguments); -} // namespace client +} #endif // __INCLUDED_CLIENT_H__ diff --git a/src/client/draw.cc b/src/client/draw.cc index 60726b0..11d4aa7 100644 --- a/src/client/draw.cc +++ b/src/client/draw.cc @@ -104,12 +104,14 @@ void draw_ship(core::EntityControlable *entity) Vector3f br(-0.25, -0.125, -0.125); Box box(tl, br); + box.topcolor = entity->color(); + box.bottomcolor = entity->color() * 0.7; box.draw(); tl = Vector3f(0, 0.07, 0.25); br = Vector3f(-0.5, -0.07, 0.125); Box engine1(tl, br); - engine1.topcolor = Color(0.7, 0.7, 0.7); + engine1.topcolor = Color(0.7, 0.7, 0.7); engine1.bottomcolor = engine1.topcolor * 0.5; engine1.draw(); diff --git a/src/client/input.cc b/src/client/input.cc index 7193c0e..5dda3fb 100644 --- a/src/client/input.cc +++ b/src/client/input.cc @@ -24,17 +24,6 @@ float local_turn; // local thrust setting float local_thrust; -core::Player *localplayer() { - return core::game()->localplayer(); -} - -core::EntityControlable *localcontrol() { - if (core::game()->localplayer()) - return core::game()->localplayer()->control; - else - return 0; -} - void init() { con_print << "Initializing input..." << std::endl; @@ -89,8 +78,8 @@ void keypressed(const SDL_keysym &keysym) case SDLK_KP4: // TODO set core entity params local_turn += 5; - if (math::degrees180f(local_turn - localcontrol()->direction()) > 90) - local_turn = localcontrol()->direction() + 90; + if (math::degrees180f(local_turn - core::localcontrol()->direction()) > 90) + local_turn = core::localcontrol()->direction() + 90; if (local_turn > 360) local_turn -= 360; @@ -98,8 +87,8 @@ void keypressed(const SDL_keysym &keysym) case SDLK_KP6: // TODO set core entity params local_turn -= 5; - if (math::degrees180f(local_turn - localcontrol()->direction()) < -90) - local_turn = localcontrol()->direction() - 90; + if (math::degrees180f(local_turn - core::localcontrol()->direction()) < -90) + local_turn = core::localcontrol()->direction() - 90; if (local_turn < 0) local_turn += 360; break; @@ -117,7 +106,7 @@ void frame(float seconds) switch (event.type) { case SDL_KEYUP: - if (!console::visible() && core::application()->connected() && localcontrol()) + if (!console::visible() && core::application()->connected() && core::localcontrol()) // send key events to the game world keyreleased(event.key.keysym); break; @@ -127,7 +116,7 @@ void frame(float seconds) } else if (console::visible()) { // send key events to the console console::keypressed(event.key.keysym); - } else if (core::application()->connected() && localcontrol()) { + } else if (core::application()->connected() && core::localcontrol()) { // send key events to the game world keypressed(event.key.keysym); } @@ -139,9 +128,9 @@ void frame(float seconds) } - if (!console::visible() && core::application()->connected() && localcontrol()) { - localcontrol()->set_thrust(local_thrust); - localcontrol()->set_direction(local_turn); + if (!console::visible() && core::application()->connected() && core::localcontrol()) { + core::localcontrol()->set_thrust(local_thrust); + core::localcontrol()->set_direction(local_turn); } } diff --git a/src/client/video.cc b/src/client/video.cc index dfdf511..86fca89 100644 --- a/src/client/video.cc +++ b/src/client/video.cc @@ -105,6 +105,11 @@ bool init() (*r_width) = width; (*r_height) = height; + std::string version(core::name()); + version += ' '; + version.append(core::version()); + SDL_WM_SetCaption(version.c_str(), 0); + render::init(); video::reset(); diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index 5a7fbdb..831489f 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -64,7 +64,7 @@ void CommandBuffer::exec(std::string const &cmdline) if (!(cmdstream >> command)) return; - con_debug << "Executing '" << cmdline << "'\n"; + //con_debug << "Executing '" << cmdline << "'\n"; // is it a function Func *f = Func::find(command); @@ -72,7 +72,7 @@ void CommandBuffer::exec(std::string const &cmdline) std::string args; char c; if (cmdstream >> args) { - while (cmdstream >> c) + while (cmdstream.get(c)) args += c; } if ((f->flags() & Func::Game)) { @@ -93,7 +93,7 @@ void CommandBuffer::exec(std::string const &cmdline) if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) { // we're setting a new value char c; - while (cmdstream >> c) + while (cmdstream.get(c)) value += c; (*cvar) = value; } diff --git a/src/core/entity.cc b/src/core/entity.cc index 7e9c788..4cce2cb 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -287,9 +287,9 @@ void EntityControlable::recieve_server_update(std::istream &is) void EntityControlable::frame(float seconds) { - entity_direction = target_direction; - entity_thrust = target_thrust; - entity_dirty = true; + //entity_direction = target_direction; + //entity_thrust = target_thrust; + //entity_dirty = true; EntityDynamic::frame(seconds); } diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index eeb4692..07a27a6 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -93,22 +93,31 @@ void GameConnection::frame(float seconds) if (core::Cvar::sv_framerate->value()) { connection_frametime += seconds; f = 1.0f / core::Cvar::sv_framerate->value(); - if (connection_frametime < f) + if (connection_frametime < f) { + // run client prediction + std::map<unsigned int, Entity *>::iterator it; + for (it=Entity::registry.begin(); it != Entity::registry.end(); it++) { + Entity *entity = (*it).second; + if ((entity->type() == Entity::Controlable) || (entity->type() == Entity::Dynamic)) { + entity->frame(seconds); + } + } return; + } } else { connection_frametime = seconds; } connection_network->frame(connection_frametime); - if (localplayer()->control && localplayer()->control->dirty()) { + if (localcontrol() && localcontrol()->dirty()) { std::ostringstream netmsg; - netmsg << "cup " << localplayer()->control->id() << " "; - localplayer()->control->serialize_client_update(netmsg); + netmsg << "cup " << localcontrol()->id() << " "; + localcontrol()->serialize_client_update(netmsg); netmsg << "\n"; connection_network->send(netmsg.str()); - localplayer()->control->entity_dirty = false; + localcontrol()->entity_dirty = false; //con_debug << netmsg.str(); } diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index 33166ee..6f6a4ac 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -19,13 +19,41 @@ namespace core Player GameInterface::game_localplayer; +EntityControlable *localcontrol() +{ + if (game()->localplayer()) + return game()->localplayer()->control(); + else + return 0; + +} +Player *localplayer() +{ + return game()->localplayer(); +} + GameInterface::GameInterface() { + clear(); + if (Cvar::sv_dedicated->value()) game_localplayer.player_name.assign("Console"); - else - game_localplayer.player_name.assign("Player0"); - clear(); + else { + Cvar *cl_name = Cvar::find("cl_name"); + if (cl_name) { + game_localplayer.player_name = cl_name->str(); + } + + Cvar *cl_color = Cvar::find("cl_color"); + math::Color color(1.0, 1.0, 1.0, 1.0); + if (cl_color) { + std::istringstream is(cl_color->str()); + is >> color; + } + game_localplayer.player_color = color; + + + } } GameInterface::~GameInterface() diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h index 0a7bdbe..0c28421 100644 --- a/src/core/gameinterface.h +++ b/src/core/gameinterface.h @@ -48,6 +48,12 @@ protected: static Player game_localplayer; }; +/// global local player instance +Player *localplayer(); + +/// global local control instance +EntityControlable *localcontrol(); + } #endif // __INCLUDED_CORE_GAMEINTERFACE_H__ diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 8ddd824..6294a31 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -96,6 +96,9 @@ void GameServer::abort() void GameServer::say(Player *player, std::string const &message) { + if (!message.size()) + return; + // send to console con_print <<player->name() << ": " << message << "\n"; diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 4770528..455c03d 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -33,7 +33,9 @@ void NetConnection::connect(std::string const &to_host, int to_port) } std::ostringstream osstream; - osstream << "name " << game()->localplayer()->name() << std::endl; + osstream << "pif "; + game()->localplayer()->serialize_client_update(osstream); + osstream << '\n'; send(osstream.str()); } @@ -154,8 +156,8 @@ void NetConnection::parse_incoming_message(const std::string & message) Entity *e = Entity::find(id); con_debug << "Received die entity id " << id << "\n"; - if (game()->localplayer()->control == e) - game()->localplayer()-> control = 0; + if (localcontrol() == e) + localplayer()->player_control = 0; if (e) Entity::remove(id); diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 43067d7..0722061 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -233,6 +233,11 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me return; } + // pif - update player information + if (command == "pif") { + client->player()->recieve_client_update(msgstream); + } + // say if (command == "say") { if (message.size() > command.size()+1) { diff --git a/src/core/player.cc b/src/core/player.cc index f4ee6ea..488e407 100644 --- a/src/core/player.cc +++ b/src/core/player.cc @@ -25,18 +25,38 @@ void Player::clear() player_id = 0; player_name.clear(); player_dirty = false; - control = 0; + player_control = 0; +} + +void Player::serialize_client_update(std::ostream & os) const +{ + os << " " << player_color << " \"" << player_name << "\""; +} + +void Player::recieve_client_update(std::istream &is) +{ + is >> player_color; + + std::string n; + char c; + while ( (is.get(c)) && (c != '"')); + while ( (is.get(c)) && (c != '"')) + n += c; + + if (n.size()) + player_name = n; + } void Player::serialize_server_update(std::ostream & os) const { unsigned int co; - if (control) - co = control->id(); + if (player_control) + co = player_control->id(); else co = 0; - os << player_id << " " << co << " \"" << player_name << "\""; + os << player_id << " " << co << " " << player_color << " \"" << player_name << "\""; } void Player::recieve_server_update(std::istream &is) @@ -47,22 +67,25 @@ void Player::recieve_server_update(std::istream &is) if (co) { Entity *e = Entity::find(co); if (e && e->type() == Entity::Controlable) { - control = (EntityControlable *) e; + player_control = (EntityControlable *) e; } else { - control = 0; + player_control = 0; con_warn << "control set to unknown entity " << co << "\n"; } } else { - control = 0; + player_control = 0; } + is >> player_color; + std::string n; char c; while ( (is.get(c)) && (c != '"')); while ( (is.get(c)) && (c != '"')) n += c; - player_name = n; + if (n.size()) + player_name = n; } } diff --git a/src/core/player.h b/src/core/player.h index fd4053c..db6860a 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -7,6 +7,8 @@ #ifndef __INCLUDED_CORE_PLAYER_H__ #define __INCLUDED_CORE_PLAYER_H__ +#include "math/mathlib.h" + namespace core { class Player; @@ -26,26 +28,24 @@ public: Player(); ~Player(); - /// clear all the data - void clear(); - - /// name of the player - inline std::string const &name() const { return player_name; } +/*----- inspectors ------------------------------------------------ */ /// id of the player inline int id() const { return player_id; } + + /// name of the player + inline std::string const &name() const { return player_name; } /// dirty flag inline bool dirty() const { return player_dirty; } - /// id of the player - int player_id; + /// the entity the Player is currently controling + inline EntityControlable *control() const { return player_control; } - /// name of the player - std::string player_name; + /// player base color + inline math::Color const & color() const { return player_color; } - /// the entity the Player is currently controling - EntityControlable *control; +/*----- mutators -------------------------------------------------- */ /// serialize player info to a stream void serialize_server_update(std::ostream & os) const; @@ -53,8 +53,31 @@ public: /// receive player info from a stream void recieve_server_update(std::istream &is); - /// dirty state + /// serialize player info to a stream + void serialize_client_update(std::ostream & os) const; + + /// receive player info from a stream + void recieve_client_update(std::istream &is); + + /// clear all the data + void clear(); + +/* -- should actually not be public --*/ + + // dirty state bool player_dirty; + + // id of the player + int player_id; + + // name of the player + std::string player_name; + + // color + math::Color player_color; + + // the entity the Player is currently controling + EntityControlable *player_control; }; } diff --git a/src/game/game.cc b/src/game/game.cc index a76d5e7..85cd457 100644 --- a/src/game/game.cc +++ b/src/game/game.cc @@ -22,10 +22,11 @@ namespace game /// a player joins the game void func_join(core::Player *player, std::string const &args) { - if (player->control) + if (player->control()) return; - player->control = new Ship(player); + player->player_control = new Ship(player); + player->control()->entity_color = player->color(); std::string message(player->name()); message.append(" joins the game."); @@ -37,17 +38,17 @@ void func_join(core::Player *player, std::string const &args) /// a player joins the spectators void func_spectate(core::Player *player, std::string const &args) { - if (!player->control) + if (!player->player_control) return; std::string message(player->name()); message.append(" spectates."); core::server()->broadcast(message); - if (player->control) { + if (player->control()) { // player has only ship for now - player->control->die(); - player->control = 0; + player->player_control->die(); + player->player_control = 0; } player->player_dirty = true; @@ -138,10 +139,10 @@ void Game::player_connect(core::Player *player) void Game::player_disconnect(core::Player *player) { - if (player->control) { + if (player->control()) { // player has only one ship for now - player->control->die(); - player->control = 0; + player->control()->die(); + player->player_control = 0; } } diff --git a/src/math/color.cc b/src/math/color.cc index 9a07b7c..05f3b4c 100644 --- a/src/math/color.cc +++ b/src/math/color.cc @@ -91,7 +91,7 @@ Color operator*(float scalar, const Color& color) } std::ostream &operator<<(std::ostream &os, const Color &c) { - os << c.red() << " " << c.green() << " " << c.blue() << " " << c.alpha(); + os << c.red() << " " << c.green() << " " << c.blue(); // << " " << c.alpha(); return os; } @@ -101,7 +101,8 @@ std::istream &operator>>(std::istream & is, Color & color) is >> r; is >> g; is >> b; - is >> a; + //is >> a; + a = 1.0; color = Color(r,g,b,a); return (is); } |