Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-16 14:51:37 +0000
committerStijn Buys <ingar@osirion.org>2008-03-16 14:51:37 +0000
commit7d7b9324f1f0db14648fb9fe32256d7942af77b9 (patch)
treeef2a60c275f22c6b1ab7430a299138597030b581 /src
parent9a7ca1743f0c74042bca4d4903f7e56fe810edce (diff)
somewhat smoother network play, player assets, client pif updates
Diffstat (limited to 'src')
-rw-r--r--src/client/client.cc4
-rw-r--r--src/client/input.cc4
-rw-r--r--src/core/commandbuffer.cc8
-rw-r--r--src/core/cvar.cc1
-rw-r--r--src/core/cvar.h3
-rw-r--r--src/core/entity.cc15
-rw-r--r--src/core/entity.h1
-rw-r--r--src/core/gameconnection.cc9
-rw-r--r--src/core/gameinterface.cc2
-rw-r--r--src/core/netclient.cc2
-rw-r--r--src/core/netconnection.cc17
-rw-r--r--src/core/netconnection.h13
-rw-r--r--src/core/netserver.cc8
-rw-r--r--src/core/player.cc64
-rw-r--r--src/core/player.h20
-rw-r--r--src/game/ship.cc4
-rw-r--r--src/net/tcpconnection.h2
17 files changed, 154 insertions, 23 deletions
diff --git a/src/client/client.cc b/src/client/client.cc
index c93a0dc..99bd41f 100644
--- a/src/client/client.cc
+++ b/src/client/client.cc
@@ -90,8 +90,8 @@ void Client::init()
core::Application::init();
// client variables
- core::Cvar::get("cl_name", "Player", core::Cvar::Archive);
- core::Cvar::get("cl_color", "1.0 1.0 1.0", core::Cvar::Archive);
+ core::Cvar::get("cl_name", "Player", core::Cvar::Archive | core::Cvar::Info);
+ core::Cvar::get("cl_color", "1.0 1.0 1.0", core::Cvar::Archive | core::Cvar::Info);
cl_framerate = core::Cvar::get("cl_framerate", "120", core::Cvar::Archive);
// initialize SDL, but do not initialize any subsystems
diff --git a/src/client/input.cc b/src/client/input.cc
index 3b2db09..4d0f54b 100644
--- a/src/client/input.cc
+++ b/src/client/input.cc
@@ -70,13 +70,13 @@ void keypressed(const SDL_keysym &keysym)
break;
case SDLK_KP_PLUS:
// TODO set core entity params
- local_thrust += 0.08f;
+ local_thrust += 0.02f;
if (local_thrust > 1.0f)
local_thrust = 1.0f;
break;
case SDLK_KP_MINUS:
// TODO set core entity params
- local_thrust -= 0.1f;
+ local_thrust -= 0.025f;
if (local_thrust < 0.0f)
local_thrust = 0.0f;
break;
diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc
index 2cf8d26..a38d9d0 100644
--- a/src/core/commandbuffer.cc
+++ b/src/core/commandbuffer.cc
@@ -52,6 +52,10 @@ void func_set(std::string const &args)
Cvar *cvar = Cvar::set(varname.c_str(), value.c_str(), Cvar::Archive);
con_print << cvar->name() << " " << cvar->str() << "\n";
+
+ if (cvar->flags() && Cvar::Info) {
+ localplayer()->player_dirty = true;
+ }
return;
}
@@ -120,6 +124,10 @@ void CommandBuffer::exec(std::string const &cmdline)
while (cmdstream.get(c))
value += c;
(*cvar) = value;
+
+ if (cvar->flags() && Cvar::Info) {
+ localplayer()->player_dirty = true;
+ }
}
con_print << command << " " << cvar->str() << "\n";
diff --git a/src/core/cvar.cc b/src/core/cvar.cc
index 9ce1fe6..363ebb4 100644
--- a/src/core/cvar.cc
+++ b/src/core/cvar.cc
@@ -60,6 +60,7 @@ Cvar* Cvar::get(const char *name, const char *value, unsigned int flags)
Cvar *c = find(name);
if (c) {
//con_debug << "get " << name << " already exist with value " << cvar->str() << std::endl;
+ c->cvar_flags |= flags;
} else {
//con_debug << "get " << name << " " << value << std::endl;
c = new Cvar(name, flags);
diff --git a/src/core/cvar.h b/src/core/cvar.h
index 3847a78..f43e532 100644
--- a/src/core/cvar.h
+++ b/src/core/cvar.h
@@ -22,8 +22,9 @@ public:
* Archive a cvar with this flag will be saved to the configuration file
* ReadOnly the value of cvar with this flag can not be altered from the commandline
* Game a cvar with this flag is only valid when a game is loaded
+ * Info a cvar that updates player info
*/
- enum Flags {Archive=1, ReadOnly=2, Game=4};
+ enum Flags {Archive=1, ReadOnly=2, Game=4, Info=8};
/// create a new variable
Cvar(const char *name = 0, unsigned int flags = 0);
diff --git a/src/core/entity.cc b/src/core/entity.cc
index 36868af..d64ae61 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -199,6 +199,9 @@ EntityDynamic::~EntityDynamic()
void EntityDynamic::frame(float seconds)
{
+ if ((flags() & Static) == Static)
+ return;
+
if (entity_speed == 0)
return;
@@ -239,7 +242,9 @@ void EntityDynamic::recieve_server_update(std::istream &is)
EntityControlable::EntityControlable(Player *player, unsigned int flags) :
EntityDynamic(flags)
{
- entity_owner = 0;
+ entity_owner = player;
+ if (entity_owner)
+ entity_owner->add_asset(this);
entity_thrust = 0;
target_direction = 0.0f;
@@ -261,6 +266,8 @@ EntityControlable::EntityControlable(std::istream & is) :
EntityControlable::~EntityControlable()
{
+ if (entity_owner)
+ entity_owner->remove_asset(this);
}
void EntityControlable::serialize(std::ostream & os) const
@@ -306,6 +313,9 @@ void EntityControlable::frame(float seconds)
void EntityControlable::set_thrust(float thrust)
{
+ if ((flags() & Static) == Static)
+ return;
+
if (!(thrust == target_thrust)) {
target_thrust = thrust;
entity_dirty = true;
@@ -314,6 +324,9 @@ void EntityControlable::set_thrust(float thrust)
void EntityControlable::set_direction(float direction)
{
+ if ((flags() & Static) == Static)
+ return;
+
if (!(target_direction == direction)) {
target_direction = direction;
entity_dirty = true;
diff --git a/src/core/entity.h b/src/core/entity.h
index 0eda501..1f47640 100644
--- a/src/core/entity.h
+++ b/src/core/entity.h
@@ -9,6 +9,7 @@
namespace core
{
+class Entity;
class EntityControlable;
}
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index 4c31f78..b307fee 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -123,6 +123,15 @@ void GameConnection::frame(float seconds)
//con_debug << netmsg.str();
}
+ if (localplayer()->dirty()) {
+ std::ostringstream osstream;
+ osstream << "pif ";
+ localplayer()->serialize_client_update(osstream);
+ osstream << '\n';
+ connection_network->send(osstream.str());
+ }
+
+ connection_network->transmit();
connection_frametime += f;
}
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 1f8f265..69126e7 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -57,8 +57,6 @@ GameInterface::GameInterface()
is >> color;
}
game_localplayer.player_color = color;
-
-
}
core::Func::add("list_model", (core::FuncPtr) func_list_model);
}
diff --git a/src/core/netclient.cc b/src/core/netclient.cc
index 937cf21..0f56bb9 100644
--- a/src/core/netclient.cc
+++ b/src/core/netclient.cc
@@ -97,7 +97,7 @@ void NetClient::send(std::string const &msg)
void NetClient::transmit()
{
- while (sendq.size() && !error()) {
+ while (sendq.size() && valid() && !error()) {
TCPClient::send(sendq.substr(0, net::FRAMESIZE-1));
if (sendq.size() < net::FRAMESIZE) {
sendq.clear();
diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc
index b87477b..9790655 100644
--- a/src/core/netconnection.cc
+++ b/src/core/netconnection.cc
@@ -116,6 +116,23 @@ void NetConnection::frame(float seconds)
}
}
+void NetConnection::send(std::string const &msg)
+{
+ sendq.append(msg);
+}
+
+void NetConnection::transmit()
+{
+ while (sendq.size() && valid() && !error()) {
+ TCPConnection::send(sendq.substr(0, net::FRAMESIZE-1));
+ if (sendq.size() < net::FRAMESIZE) {
+ sendq.clear();
+ } else {
+ sendq.erase(0, net::FRAMESIZE-1);
+ }
+ }
+}
+
// parse incoming client messages
/**
* The following incoming messages are parsed;
diff --git a/src/core/netconnection.h b/src/core/netconnection.h
index 9a801ec..7623e64 100644
--- a/src/core/netconnection.h
+++ b/src/core/netconnection.h
@@ -34,6 +34,12 @@ public:
/// process pending incoming messages
void frame(float seconds);
+ /// buffer outgoing data
+ void send(std::string const &msg);
+
+ /// send bufered outgoing data
+ void transmit();
+
protected:
/// receive incoming data and store messages
void receive();
@@ -48,9 +54,10 @@ protected:
void parse_incoming_message(const std::string & message);
private:
- std::string messageblock;
- std::deque<std::string> recvq;
- fd_set clientset;
+ std::string messageblock;
+ std::deque<std::string> recvq;
+ std::string sendq;
+ fd_set clientset;
};
}
diff --git a/src/core/netserver.cc b/src/core/netserver.cc
index 0722061..87f5320 100644
--- a/src/core/netserver.cc
+++ b/src/core/netserver.cc
@@ -184,9 +184,9 @@ NetClient *NetServer::find_client(Player const *player)
* The following incoming protocol messages are parsed;
*
* disconnect
- * help
- * list_players
- * name
+ * cmd <game command>
+ * cup
+ * pif
* say <text>
*
*/
@@ -249,6 +249,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
return;
}
+ /*
// name
if (command == "name") {
std::string name;
@@ -284,6 +285,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me
send(client, "msg info list_players - shows a list of connected players\n");
send(client, "msg info disconnect - disconnect\n");
}
+ */
}
}
diff --git a/src/core/player.cc b/src/core/player.cc
index 488e407..4c4616a 100644
--- a/src/core/player.cc
+++ b/src/core/player.cc
@@ -4,8 +4,11 @@
the terms of the GNU General Public License version 2.
*/
+#include <sstream>
+
#include "sys/sys.h"
#include "core/player.h"
+#include "core/cvar.h"
namespace core
{
@@ -25,11 +28,37 @@ void Player::clear()
player_id = 0;
player_name.clear();
player_dirty = false;
+
+ clear_assets();
+}
+
+void Player::clear_assets()
+{
+ // clear assets
+ for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) {
+ (*asset)->entity_owner = 0;
+ (*asset)->die();
+ }
+ assets.clear();
+
player_control = 0;
}
-void Player::serialize_client_update(std::ostream & os) const
+void Player::serialize_client_update(std::ostream & os)
{
+ Cvar *cl_name = Cvar::find("cl_name");
+ if (cl_name) {
+ 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;
+ player_color = color;
+ }
+
os << " " << player_color << " \"" << player_name << "\"";
}
@@ -55,7 +84,7 @@ void Player::serialize_server_update(std::ostream & os) const
co = player_control->id();
else
co = 0;
-
+
os << player_id << " " << co << " " << player_color << " \"" << player_name << "\"";
}
@@ -88,5 +117,36 @@ void Player::recieve_server_update(std::istream &is)
player_name = n;
}
+void Player::add_asset(EntityControlable *entity)
+{
+ entity->entity_owner = this;
+ assets.push_back(entity);
+}
+
+void Player::remove_asset(EntityControlable *entity)
+{
+ for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) {
+ if ((*asset) == entity) {
+ (*asset)->entity_owner = 0;
+ (*asset)->die();
+ assets.erase(asset);
+ return;
+ }
+ }
+ con_warn << "Could not remove asset " << entity->id() << " from player " << this->id() << "\n";
}
+void Player::remove_asset(unsigned int id)
+{
+ for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) {
+ if ((*asset)->id() == id) {
+ (*asset)->entity_owner = 0;
+ (*asset)->die();
+ assets.erase(asset);
+ return;
+ }
+ }
+ con_warn << "Could not remove asset " << id << " from player " << this->id() << "\n";
+}
+
+}
diff --git a/src/core/player.h b/src/core/player.h
index db6860a..59b18c1 100644
--- a/src/core/player.h
+++ b/src/core/player.h
@@ -7,16 +7,16 @@
#ifndef __INCLUDED_CORE_PLAYER_H__
#define __INCLUDED_CORE_PLAYER_H__
-#include "math/mathlib.h"
-
namespace core
{
class Player;
}
#include "core/entity.h"
+#include "math/mathlib.h"
#include <string>
+#include <list>
namespace core
{
@@ -54,7 +54,7 @@ public:
void recieve_server_update(std::istream &is);
/// serialize player info to a stream
- void serialize_client_update(std::ostream & os) const;
+ void serialize_client_update(std::ostream & os);
/// receive player info from a stream
void recieve_client_update(std::istream &is);
@@ -62,6 +62,18 @@ public:
/// clear all the data
void clear();
+ /// clear assets
+ void clear_assets();
+
+ /// add an asset
+ void add_asset(EntityControlable *entity);
+
+ /// remove an asset
+ void remove_asset(EntityControlable *entity);
+
+ /// remove an asset
+ void remove_asset(unsigned int id);
+
/* -- should actually not be public --*/
// dirty state
@@ -78,6 +90,8 @@ public:
// the entity the Player is currently controling
EntityControlable *player_control;
+
+ std::list<EntityControlable*> assets;
};
}
diff --git a/src/game/ship.cc b/src/game/ship.cc
index 5edbd7d..1dd37bc 100644
--- a/src/game/ship.cc
+++ b/src/game/ship.cc
@@ -20,8 +20,6 @@ namespace game {
Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
core::EntityControlable(owner, ship_enttype)
{
- // entity properties
- entity_owner = owner;
entity_modelname = "ships/" + shipmodel->modelname();
entity_name = shipmodel->name() + ": <" + owner->name() + ">";
ship_shipmodel = shipmodel;
@@ -29,6 +27,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
Ship::~Ship()
{
+ if (entity_owner)
+ entity_owner->remove_asset(this);
}
void Ship::frame(float seconds)
diff --git a/src/net/tcpconnection.h b/src/net/tcpconnection.h
index 6076215..79a61fe 100644
--- a/src/net/tcpconnection.h
+++ b/src/net/tcpconnection.h
@@ -55,7 +55,7 @@ public:
void abort();
/// send outgoing data
- void send(std::string const &msg);
+ virtual void send(std::string const &msg);
protected:
/// receive incoming data