Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2011-02-04 13:23:05 +0000
committerStijn Buys <ingar@osirion.org>2011-02-04 13:23:05 +0000
commita69521970793424754421c8a5fba2eb465e817e6 (patch)
treef44f178a27f621f0f11ed5959418d83ee399ffcd /src/core
parent7129e31075e021112ba6a859af29513e69671626 (diff)
Made time(), timestamp() and related methods non-virtual, corrects a crash when
the dedicated server quits.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/entity.cc7
-rw-r--r--src/core/gameconnection.cc32
-rw-r--r--src/core/gameconnection.h30
-rw-r--r--src/core/gameinterface.cc35
-rw-r--r--src/core/gameinterface.h55
-rw-r--r--src/core/gameserver.cc52
-rw-r--r--src/core/gameserver.h26
-rw-r--r--src/core/physics.cc3
8 files changed, 101 insertions, 139 deletions
diff --git a/src/core/entity.cc b/src/core/entity.cc
index cf005a0..c7b3efe 100644
--- a/src/core/entity.cc
+++ b/src/core/entity.cc
@@ -513,12 +513,17 @@ void Entity::reset()
// use collision mesh
btBvhTriangleMeshShape *meshshape = new btBvhTriangleMeshShape(model()->collisionmesh()->triangles(), true, true);
meshshape->buildOptimizedBvh();
- meshshape->recalcLocalAabb();
+ meshshape->recalcLocalAabb();
+
+ //btGImpactMeshShape *meshshape = new btGImpactMeshShape(model()->collisionmesh()->triangles());
btVector3 modelscalevec(modelscale, modelscale, modelscale);
meshshape->setLocalScaling(modelscalevec);
+ meshshape->setMargin(0.0f);
+ //meshshape->updateBound();
entity_collision_shape = meshshape;
+ // con_debug << " " << label() << " attached collision mesh: " << model()->collisionmesh()->size() << " triangles" << std::endl;
} else {
// use bounding box
diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc
index 982ac7d..dee506a 100644
--- a/src/core/gameconnection.cc
+++ b/src/core/gameconnection.cc
@@ -23,9 +23,6 @@ GameConnection::GameConnection(std::string const &connectionstr)
{
connection_instance = this;
connection_network = 0;
- connection_running = false;
-
- connection_timestamp = 0;
connection_netframe = 0;
unsigned int port = DEFAULTPORT;
@@ -85,7 +82,8 @@ GameConnection::GameConnection(std::string const &connectionstr)
}
}
- connection_running = true;
+ set_interactive(true);
+ set_running(true);
}
GameConnection::~GameConnection()
@@ -98,22 +96,6 @@ GameConnection::~GameConnection()
connection_instance = 0;
}
-
-unsigned long GameConnection::timestamp() const
-{
- return connection_timestamp;
-}
-
-float GameConnection::time() const
-{
- return ((float)(connection_timestamp) / 1000.0f);
-}
-
-bool GameConnection::interactive() const
-{
- return true;
-}
-
Info *GameConnection::request_info(const unsigned int id)
{
if (!id) {
@@ -127,7 +109,7 @@ Info *GameConnection::request_info(const unsigned int id)
info = new Info(id);
}
- if (info->type() || (connection_timestamp < info->timestamp() + INFOTIMEOUT) )
+ if (info->type() || (timestamp() < info->timestamp() + INFOTIMEOUT) )
return info;
// send an information request to the server
@@ -155,11 +137,6 @@ Inventory *GameConnection::request_inventory(Entity *entity)
return (entity->inventory());
}
-
-void GameConnection::abort()
-{
- connection_running = false;
-}
void GameConnection::forward(std::string const &cmdline)
{
@@ -232,7 +209,8 @@ void GameConnection::frame(unsigned long timestamp)
}
}
- connection_timestamp = connection_network->timestamp();
+ set_timestamp(connection_network->timestamp());
+
connection_network->transmit();
}
diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h
index 89c3aff..fdd5daf 100644
--- a/src/core/gameconnection.h
+++ b/src/core/gameconnection.h
@@ -20,31 +20,10 @@ public:
GameConnection(std::string const &connectionstr);
virtual ~GameConnection();
- /*----- inspectors ------------------------------------------------ */
-
- /// returns true if the game connection can run a time frime
- inline bool running() const {
- return connection_running;
- }
-
- /// returns true if the game connection can not run a time frime
- inline bool error() const {
- return !connection_running;
- }
-
- /// returns true if the game is running an interactive module
- virtual bool interactive() const;
-
- /// return the current game time in seconds
- virtual float time() const;
-
- /// return the current game time
- virtual unsigned long timestamp() const;
-
/*----- mutators -------------------------------------------------- */
/// run a game connection time frame
- void frame(unsigned long timestamp);
+ virtual void frame(unsigned long timestamp);
/// forward a command line to the remote server
void forward(std::string const &cmdline);
@@ -64,7 +43,6 @@ public:
/// request inventory for entity with id
virtual Inventory *request_inventory(Entity *entity);
-
/*----- static ---------------------------------------------------- */
/// return the current game connection
@@ -72,13 +50,7 @@ public:
return connection_instance;
}
-protected:
- /// abort runing
- void abort();
-
private:
- bool connection_running;
- unsigned long connection_timestamp; // server game time
unsigned long connection_netframe; // last network frame timestamp
NetConnection *connection_network;
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 1d3e6fb..3505e2c 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -81,6 +81,10 @@ GameInterface::GameInterface()
game_vertexarray = new model::VertexArray(mb);
model::Material::init();
+
+ game_timestamp = 0;
+ game_running = false;
+ game_interactive = false;
}
GameInterface::~GameInterface()
@@ -145,8 +149,34 @@ void GameInterface::clear()
++it;
}
}
+
+ game_running = false;
+ game_interactive = true;
+}
+
+void GameInterface::set_running(const bool running)
+{
+ game_running = running;
+}
+
+void GameInterface::set_interactive(const bool interactive)
+{
+ game_interactive = interactive;
+}
+
+void GameInterface::set_timestamp(const unsigned long timestamp)
+{
+ game_timestamp = timestamp;
}
+void GameInterface::set_playerlist_timestamp(const unsigned long timestamp)
+{
+ game_playerlist_timestamp = ( timestamp > 0 ? timestamp : 1);
+}
+
+void GameInterface::abort() {
+ game_running = false;
+}
Player *GameInterface::find_player(const std::string &search)
{
@@ -196,9 +226,4 @@ void GameInterface::list_players()
con_print << count << " connected " << aux::plural("player", count) << std::endl;
}
-void GameInterface::set_playerlist_timestamp(const unsigned long timestamp)
-{
- game_playerlist_timestamp = ( timestamp > 0 ? timestamp : 1);
-}
-
}
diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h
index 98894e7..369b828 100644
--- a/src/core/gameinterface.h
+++ b/src/core/gameinterface.h
@@ -53,37 +53,50 @@ public:
/// show a list of connected players
void list_players();
- /*----- virtual inspectors --------------------------------------- */
-
/// returns true if the game server can run a time frime
- virtual bool running() const = 0;
+ inline bool running() const {
+ return game_running;
+ }
+
+ inline bool error() const {
+ return !game_running;
+ }
/// returns true if the game is running an interactive module
- virtual bool interactive() const = 0;
-
- /// return the current game time in seconds
- virtual float time() const = 0;
+ inline bool interactive() const {
+ return game_interactive;
+ }
- /// return the current game time
- virtual unsigned long timestamp() const = 0;
+ /// return the current game time, in seconds
+ inline float time() const {
+ return ((float)(game_timestamp) / 1000.0f);
+ }
+ /**
+ * @brief return the current game time, in milliseconds.
+ * 1000 milliseconds equals one second.
+ */
+ inline unsigned long timestamp() const {
+ return game_timestamp;
+ }
+
+ /*----- virtual inspectors --------------------------------------- */
+
/// request info record with id
virtual Info *request_info(const unsigned int id) = 0;
/// request inventory for entity with id
virtual Inventory *request_inventory(Entity *entity) = 0;
- void set_playerlist_timestamp(const unsigned long timestamp);
-
-
/*----- mutators ------------------------------------------------- */
/// clear all game variables, game functions and entities
void clear();
-
- /*----- virtual mutators ------------------------------------------ */
-
+ void set_playerlist_timestamp(const unsigned long timestamp);
+
+ virtual void abort();
+
/// run one game time frame
/// @param timestamp current application time
virtual void frame(unsigned long timestamp) = 0;
@@ -99,6 +112,18 @@ protected:
/// timestamp of the time the playerlist was last changed
unsigned long game_playerlist_timestamp;
+
+ void set_timestamp(unsigned long timestamp);
+
+ void set_running(const bool running);
+
+ void set_interactive(const bool interactive);
+
+private:
+ bool game_running;
+ bool game_interactive;
+
+ unsigned long game_timestamp;
};
/// global local player instance
diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc
index cb1e66d..1bd0dbe 100644
--- a/src/core/gameserver.cc
+++ b/src/core/gameserver.cc
@@ -125,7 +125,6 @@ GameServer::GameServer() : GameInterface()
con_print << "^BInitializing game server...\n";
server_instance = this;
server_network = 0;
- server_timestamp = 0;
server_previoustime = 0;
server_maxplayerid = 1;
server_startup = application()->timestamp();
@@ -149,7 +148,9 @@ GameServer::GameServer() : GameInterface()
return;
}
- if (server_module->interactive()) {
+ set_interactive(server_module->interactive());
+
+ if (interactive()) {
//FIXME interferes with command line because of cmd.exec
load_config();
}
@@ -160,7 +161,7 @@ GameServer::GameServer() : GameInterface()
con_print << " module '^B" << server_module->name() << "^N'\n";
- if (server_module->interactive() && (Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {
+ if (interactive() && (Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {
server_network = new NetServer(Cvar::net_host->str(), (unsigned int) Cvar::net_port->value());
if (!server_network->valid()) {
delete server_network;
@@ -197,12 +198,12 @@ GameServer::GameServer() : GameInterface()
player_connect(localplayer());
}
- server_running = true;
+ set_running(true);
}
GameServer::~GameServer()
{
- server_running = false;
+ set_running(false);
con_print << "^BShutting down game server...\n";
@@ -243,16 +244,6 @@ GameServer::~GameServer()
server_instance = 0;
}
-unsigned long GameServer::timestamp() const
-{
- return server_timestamp;
-}
-
-float GameServer::time() const
-{
- return ((float)(server_timestamp) / 1000.0f);
-}
-
Info *GameServer::request_info(unsigned int id)
{
return Info::find(id);
@@ -264,20 +255,6 @@ Inventory *GameServer::request_inventory(Entity *entity)
}
-void GameServer::abort()
-{
- server_running = false;
-}
-
-bool GameServer::interactive() const
-{
- if (!server_module) {
- return false;
- } else {
- return server_module->interactive();
- }
-}
-
void GameServer::say(Player *player, std::string const &message)
{
if (!message.size())
@@ -505,15 +482,16 @@ void GameServer::frame(unsigned long timestamp)
if ((Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {
if (core::Cvar::sv_framerate->value()) {
float f = 1000.0f / core::Cvar::sv_framerate->value();
- if (server_startup + server_timestamp + f > timestamp) {
+ if (server_startup + this->timestamp() + f > timestamp) {
return;
}
}
}
- server_previoustime = server_timestamp;
- server_timestamp = timestamp - server_startup;
- const float elapsed = (float)(server_timestamp - server_previoustime) / 1000.0f;
+ server_previoustime = this->timestamp();
+ set_timestamp(timestamp - server_startup);
+
+ const float elapsed = (float)(this->timestamp() - server_previoustime) / 1000.0f;
const unsigned long keepalive_timeout = (Cvar::sv_keepalive ? 1000 * (unsigned long) Cvar::sv_keepalive->value() : (unsigned long) 0 );
// reset zone keepalive state
@@ -548,12 +526,12 @@ void GameServer::frame(unsigned long timestamp)
if (zone && entity->flag_is_set(Entity::KeepAlive)) {
if (zone->keepalive_run() && zone->keepalive_box().inside(entity->location())) {
- entity->set_keepalive(server_timestamp);
+ entity->set_keepalive(this->timestamp());
}
// run upkeep if the keepalive timeout has elapsed
- if (entity->keepalive() + keepalive_timeout < server_timestamp) {
- entity->upkeep(server_timestamp);
+ if (entity->keepalive() + keepalive_timeout < this->timestamp()) {
+ entity->upkeep(this->timestamp());
}
}
}
@@ -619,7 +597,7 @@ void GameServer::frame(unsigned long timestamp)
if (server_network) {
// send network updates
- server_network->frame(server_timestamp);
+ server_network->frame(this->timestamp());
}
// remove deleted entities and mark remaining entities as updated
diff --git a/src/core/gameserver.h b/src/core/gameserver.h
index 775c41c..f0cf88b 100644
--- a/src/core/gameserver.h
+++ b/src/core/gameserver.h
@@ -27,25 +27,6 @@ public:
/*----- inspectors ------------------------------------------------ */
- /// returns true if the game server can run a time frime
- inline bool running() const {
- return server_running;
- }
-
- /// returns true if the game server can not run a time frime
- inline bool error() const {
- return !server_running;
- }
-
- /// returns true if the game is running an interactive module
- virtual bool interactive() const;
-
- /// return the current game time in seconds
- virtual float time() const;
-
- /// return the current game time
- virtual unsigned long timestamp() const;
-
/// current module
inline const Module *module() const {
return server_module;
@@ -101,21 +82,16 @@ public:
return server_instance;
}
-protected:
- /// abort runing
- void abort();
-
private:
void load_config();
void save_config();
- bool server_running;
+
Module *server_module;
static GameServer *server_instance;
NetServer *server_network;
unsigned int server_maxplayerid;
- unsigned long server_timestamp;
unsigned long server_previoustime;
unsigned long server_startup;
};
diff --git a/src/core/physics.cc b/src/core/physics.cc
index 6969b06..5504c50 100644
--- a/src/core/physics.cc
+++ b/src/core/physics.cc
@@ -8,6 +8,8 @@
#include "core/physics.h"
#include "core/zone.h"
+#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
+
namespace core {
btDefaultCollisionConfiguration *Physics::physics_configuration = 0;
@@ -23,6 +25,7 @@ void Physics::init()
physics_configuration = new btDefaultCollisionConfiguration();
physics_dispatcher = new btCollisionDispatcher(physics_configuration);
+ btGImpactCollisionAlgorithm::registerAlgorithm(physics_dispatcher);
physics_solver = new btSequentialImpulseConstraintSolver;
physics_timestamp = 0;