diff options
Diffstat (limited to 'src/core')
-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 |
10 files changed, 136 insertions, 37 deletions
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; }; } |