diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/Makefile.am | 12 | ||||
| -rw-r--r-- | src/core/application.cc | 6 | ||||
| -rw-r--r-- | src/core/application.h | 3 | ||||
| -rw-r--r-- | src/core/clientstate.cc | 96 | ||||
| -rw-r--r-- | src/core/clientstate.h | 95 | ||||
| -rw-r--r-- | src/core/entity.cc | 22 | ||||
| -rw-r--r-- | src/core/entity.h | 14 | ||||
| -rw-r--r-- | src/core/extension.cc | 29 | ||||
| -rw-r--r-- | src/core/extension.h | 42 | ||||
| -rw-r--r-- | src/core/gameconnection.cc | 2 | ||||
| -rw-r--r-- | src/core/gameinterface.cc | 94 | ||||
| -rw-r--r-- | src/core/gameinterface.h | 7 | ||||
| -rw-r--r-- | src/core/gameserver.cc | 12 | ||||
| -rw-r--r-- | src/core/netconnection.cc | 2 | 
14 files changed, 106 insertions, 330 deletions
diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 2c90dec..fbdf311 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -1,8 +1,8 @@  METASOURCES = AUTO  INCLUDES = -I$(top_srcdir)/src -libcore_la_SOURCES = application.cc clientstate.cc commandbuffer.cc core.cc \ -	cvar.cc descriptions.cc entity.cc func.cc gameconnection.cc gameinterface.cc \ +libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc \ +	descriptions.cc entity.cc extension.cc func.cc gameconnection.cc gameinterface.cc \  	gameserver.cc module.cc netclient.cc netconnection.cc netplayer.cc netserver.cc \  	parser.cc player.cc stats.cc timer.cc zone.cc  libcore_la_LDFLAGS = -avoid-version -no-undefined @@ -11,7 +11,7 @@ libcore_la_LIBADD = $(top_builddir)/src/model/libmodel.la \  	$(top_builddir)/src/auxiliary/libauxiliary.la  noinst_LTLIBRARIES = libcore.la -noinst_HEADERS = application.h clientstate.h commandbuffer.h core.h cvar.h \ -	entity.h func.h gameconnection.h gameinterface.h gameserver.h message.h module.h \ -	net.h netclient.h netconnection.h netserver.h player.h range.h stats.h \ -	timer.h parser.h descriptions.h +noinst_HEADERS = application.h commandbuffer.h core.h cvar.h entity.h func.h \ +	gameconnection.h gameinterface.h gameserver.h message.h module.h net.h netclient.h \ +	netconnection.h netserver.h player.h range.h stats.h timer.h parser.h descriptions.h \ +	extension.h diff --git a/src/core/application.cc b/src/core/application.cc index 7326383..f24f0f7 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -489,12 +489,6 @@ void Application::notify_connect()  {  } -void Application::notify_remove_sound(size_t source) -{ -	// the default implementation does nothing. -	// Dedicated servers don't need sounds -} -  /* -- static engine functions -------------------------------------- */  void Application::func_help(std::string const &args) diff --git a/src/core/application.h b/src/core/application.h index bcd4042..e992131 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -81,9 +81,6 @@ public:  	/// zone change notification  	virtual void notify_zonechange(); -	/// remove sound source notification -	virtual void notify_remove_sound(size_t source); -  	/// a pointer to the current application instance  	static inline Application *instance() { return application_instance; } diff --git a/src/core/clientstate.cc b/src/core/clientstate.cc deleted file mode 100644 index 298e653..0000000 --- a/src/core/clientstate.cc +++ /dev/null @@ -1,96 +0,0 @@ -/* -   core/clientstate.cc -   This file is part of the Osirion project and is distributed under -   the terms of the GNU General Public License version 2 -*/ - -#include "core/clientstate.h" -#include "core/application.h" -#include "sys/sys.h" - -namespace core { - -ClientState::ClientState() -{ -	state_visible = false; -	state_detailvisible = false; -	state_targetable = false; - -	state_thusterloopbuffer = 0; -	state_impulseloopbuffer = 0; -	state_impulsestartbuffer = 0; -	state_impulsestopbuffer = 0; - -	state_engineloopbuffer = 0; -	state_engineloopsource = 0; -	state_engineeventbuffer = 0; -	state_engineeventsource = 0; - -	state_engine_trail_offset = 0; - -	state_fuzz = math::randomf(); -	state_distance = -1; -} - -ClientState::ClientState(Entity *entity) -{ -	state_visible = false; -	state_detailvisible = false; -	state_targetable = false; - -	state_thusterloopbuffer = 0; -	state_impulseloopbuffer = 0; -	state_impulsestartbuffer = 0; -	state_impulsestopbuffer = 0; - -	state_engineloopbuffer = 0; -	state_engineloopsource = 0; -	state_engineeventbuffer = 0; -	state_engineeventsource = 0; - -	state_engine_trail_offset = 0; - -	state_fuzz = math::randomf(); -	state_distance = -1; - -	assign(entity); -} - -ClientState::~ClientState() -{ -	clearsound(); -} - -void ClientState::clearsound() -{ -	if (state_engineloopsource) { -		application()->notify_remove_sound(state_engineloopsource); -	} - -	if (state_engineeventsource) { -		application()->notify_remove_sound(state_engineeventsource); -	} - -	state_thusterloopbuffer = 0; -	state_impulseloopbuffer = 0; -	state_impulsestartbuffer = 0; -	state_impulsestopbuffer = 0; - -	state_engineloopbuffer = 0; -	state_engineloopsource = 0; - -	state_engineeventbuffer = 0; -	state_engineeventsource = 0; -} - -void ClientState::assign(Entity * entity) -{ -	state_location.assign(entity->location()); -	state_axis.assign(entity->axis()); - -	state_previouslocation.assign(entity->location()); -	state_previousaxis.assign(entity->axis()); -	state_distance = -1; -} - -} diff --git a/src/core/clientstate.h b/src/core/clientstate.h deleted file mode 100644 index ffd6331..0000000 --- a/src/core/clientstate.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -   core/clientstate.h -   This file is part of the Osirion project and is distributed under -   the terms of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_CORE_CLIENTSTATE_H__ -#define __INCLUDED_CORE_CLIENTSTATE_H__ - -#include "math/axis.h" -#include "math/mathlib.h" -#include "math/vector3f.h" - -namespace core -{ -	class ClientState; -} - -#include "core/entity.h" - -namespace core -{ - -/// Entity client render state -class ClientState { -public: -	ClientState(); -	ClientState(Entity *entity); - -	~ClientState(); - -	inline math::Vector3f const & location() const { return state_location; } - -	inline math::Vector3f const & previouslocation() const { return state_previouslocation; } - -	inline math::Axis const & previousaxis() const { return state_previousaxis; } - -	inline math::Axis const & axis() const { return state_axis; } - -	inline bool visible() const { return state_visible; } - -	inline bool detailvisible() const { return state_detailvisible; } - -	inline bool targetable() const { return state_targetable; } - -	inline float distance() const { return state_distance; } - -	/// client render fuzz factor -	inline float fuzz() const { return state_fuzz; }; - -	/// assign the content of an entity -	void assign(Entity *entity); - -	/// clear attached sounds -	void clearsound(); - -	math::Vector3f		state_location; -	math::Axis		state_axis; - -	math::Vector3f		state_previouslocation; -	math::Axis		state_previousaxis; - -	bool			state_visible; -	bool			state_detailvisible; -	bool			state_targetable; - -	float			state_fuzz; -	float			state_engine_trail_offset; - -	/// distance from the camera eye to the entity -	float			state_distance; - -	/// index of the audio buffer containing the thruster sound loop -	size_t			state_thusterloopbuffer; -	/// index of the audio buffer containing the impulse sound loop -	size_t			state_impulseloopbuffer; -	/// index of the audio buffer containing the impulse drive start sound -	size_t			state_impulsestartbuffer; -	/// index of the audio buffer containing the impulse drive stop sound -	size_t			state_impulsestopbuffer; - -	/// index of the audio buffer currently looping in enginesource -	size_t			state_engineloopbuffer; -	/// index of the audio source used to play the engine sound loop -	size_t			state_engineloopsource; -	/// index of the audio last played on the event source -	size_t			state_engineeventbuffer; -	/// index of the audio source used to play engine sound events -	size_t			state_engineeventsource; -}; - -} - -#endif // __INCLUDED_CORE_CLIENTSTATE_H__ - diff --git a/src/core/entity.cc b/src/core/entity.cc index e2aac1c..47086ee 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -6,6 +6,7 @@  #include <vector>  #include <iomanip> +#include <cstring>  #include "auxiliary/functions.h"  #include "sys/sys.h" @@ -105,14 +106,14 @@ Entity::Entity(unsigned int flags) :  	entity_label.clear();  	entity_name.clear(); -	entity_clientstate = 0; -  	entity_zone = 0;  	entity_oldzone = 0;  	entity_visible = true;  	entity_serverside = false; +	memset(entity_extension, 0, sizeof(entity_extension)); +  	add(this);  } @@ -125,25 +126,28 @@ Entity::Entity(std::istream & is)  	entity_visible = true;  	entity_model = 0; -	entity_clientstate = 0;  	entity_created = true; -	entity_destroyed = false;	 +	entity_destroyed = false; +	 +	memset(entity_extension, 0, sizeof(entity_extension));  }  Entity::~Entity()  { +	// delete extensions +	for (size_t i =0; i < 4; i++) { +		if (entity_extension[i]) +			delete entity_extension[i]; +			entity_extension[i] = 0; +	} +  	// delete entity menus  	for (Menus::iterator it = menus().begin(); it != menus().end(); it++) {  		delete (*it);  	}  	menus().clear(); -	if (entity_clientstate) { -		delete entity_clientstate; -		entity_clientstate = 0; -	} -  	if (entity_zone)  		entity_zone->remove(this);  } diff --git a/src/core/entity.h b/src/core/entity.h index 4e757c1..01fedc2 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -24,7 +24,7 @@ class EntityControlable;  } -#include "core/clientstate.h" +#include "core/extension.h"  #include "core/descriptions.h"  #include "core/player.h"  #include "core/zone.h" @@ -35,6 +35,8 @@ namespace core  /// The base world entity. All gameworld entities must derive from this class.  class Entity  { +	friend class Extension; +  public:  	/// Entity flags  	enum Flags {Static=1, Solid=2, Bright=4, Dockable=8}; @@ -80,9 +82,6 @@ public:  	/// entity name (can not contain double qoutes ")  	inline std::string const & name() { return entity_name; } -	/// entity client render state -	inline ClientState * state() { return entity_clientstate; } -  	/// pointer to the model, is used client-side  	inline model::Model * model() { return entity_model; } @@ -125,6 +124,9 @@ public:  	/// entity menus  	inline Menus &menus() { return entity_menus; } +	/// extensions +	inline Extension *extension(size_t type) { return entity_extension[type]; } +  	/// find a menu  	MenuDescription *find_menu(std::string const &label); @@ -248,8 +250,6 @@ public:  	/// timestamp when entity data was received from the server  	float			entity_servertimestamp; -	ClientState		*entity_clientstate; -  protected:  	// the zone the entity belongs to  	Zone			*entity_zone; @@ -271,6 +271,8 @@ private:  	Menus			entity_menus; +	Extension*		entity_extension[4]; +   	static Registry 	entity_registry;  	static size_t		entity_nextid; diff --git a/src/core/extension.cc b/src/core/extension.cc new file mode 100644 index 0000000..7106fa5 --- /dev/null +++ b/src/core/extension.cc @@ -0,0 +1,29 @@ +/* +   core/extension.cc +   This file is part of the Osirion project and is distributed under +   the terms of the GNU General Public License version 2 +*/ + +#include "core/extension.h" + +namespace core +{ + +Extension::Extension(Type type, Entity *entity) +{ +	extension_entity = entity; +	extension_type = type; + +	if (entity) +		entity->entity_extension[(size_t) type] = this; +} + +Extension::~Extension() +{ +	if (extension_entity) +		extension_entity->entity_extension[(size_t) extension_type] = 0; +} + + +} // namespace core + diff --git a/src/core/extension.h b/src/core/extension.h new file mode 100644 index 0000000..0b9ecad --- /dev/null +++ b/src/core/extension.h @@ -0,0 +1,42 @@ +/* +   core/extension.h +   This file is part of the Osirion project and is distributed under +   the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CORE_EXTENSION_H__ +#define __INCLUDED_CORE_EXTENSION_H__ + +namespace core { +	class Extension; +} + +#include "core/entity.h" + +namespace core { + +/// a abstract base class for entity extensions +class Extension { +public: +	/// extension types +	enum Type { Client=0, Render=1, Sound=2, Game=3 }; + +	inline Type type() const { return  extension_type; } + +	inline Entity *entity() { return extension_entity; } + +	Extension(Type type, Entity *entity); +	virtual ~Extension(); + +	virtual void frame(float elapsed) = 0; + +private: +	Type			extension_type; +	Entity			*extension_entity; +	 +}; + +} // namespace core + +#endif // __INCLUDED_CORE_EXTENSION_H__ + diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index 7942f9e..c2763ee 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -121,7 +121,7 @@ void GameConnection::frame(unsigned long timestamp)  		return;  	} -	update_clientstate(); +	//update_clientstate();  	// get incoming messages  	connection_network->frame(); diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index d99ec15..9551176 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -120,100 +120,6 @@ void GameInterface::clear()  	game_players.clear();  } -void GameInterface::reset_clientstate() -{ -//	game_previousframetime = prevtimestamp; -//	game_serverframetime = timestamp; -//	game_time = timestamp; -	 -	for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { -		 -		Entity *entity = (*it).second; - -		if (entity->state() && !(entity->flags() & Entity::Static)) -			entity->state()->assign(entity); -	} - -//	if ( game_clientframetime < game_previousframetime) -//		game_clientframetime = game_previousframetime; -//	else if ( game_clientframetime > game_serverframetime) -//		game_clientframetime = game_serverframetime; - -} - - -void GameInterface::update_entity_clientstate(Entity *entity) -{ -	if (!entity->state()) { -		entity->entity_clientstate = new ClientState(entity); -		entity->entity_clientstate->assign(entity); -	} else -		entity->state()->assign(entity); -	} - -/* -	if (!(entity->flags() & Entity::Static)) { - -		// clientstate location -		entity->state()->state_location = entity->state()->previouslocation() +  -		(entity->location() - entity->state()->previouslocation()) * timeoffset(); - -		if (game_clientframetime <= game_serverframetime) { -		 -			if(Cvar::cl_prediction->value() > 1) { -				entity->state()->state_axis.assign(entity->state()->previousaxis()); -	 -				float cosangle;		// cosine of an angle -				float angle;		// angle in radians	 -				math::Vector3f n;	// normal of a plane -	 -				n.assign(math::crossproduct( entity->state()->axis().forward(), entity->axis().forward())); -				if (!(n.length() < MIN_DELTA)) { -					n.normalize(); -					cosangle = math::dotproduct( entity->state()->axis().forward(),  entity->axis().forward()); -					angle = acos(cosangle) * timeoffset(); // * 180.0f / M_PI; -					if (angle > MIN_DELTA) -						entity->state()->state_axis.rotate(n, -angle); -				} -				 -				n.assign(math::crossproduct( entity->state()->axis().left(), entity->axis().left())); -				if (!(n.length() < MIN_DELTA)) { -					n.normalize(); -					cosangle = math::dotproduct( entity->state()->axis().left(), entity->axis().left()); -					angle = acos(cosangle) * timeoffset(); // * 180.0f / M_PI; -					if (angle > MIN_DELTA) -						entity->state()->state_axis.rotate(n, -angle); -				} -	 -				n.assign(math::crossproduct( entity->state()->axis().up(), entity->axis().up())); -				if (!(n.length() < MIN_DELTA)) { -					n.normalize(); -					cosangle = math::dotproduct( entity->state()->axis().up(), entity->axis().up()); -					angle = acos(cosangle) * timeoffset(); // * 180.0f / M_PI; -					if (angle > MIN_DELTA) -						entity->state()->state_axis.rotate(n, -angle); -				}  -				 -			} else { -				entity->state()->state_axis.assign(entity->axis()); -			} -		} else { -			entity->state()->state_axis.assign(entity->axis()); -		} -	 -	} else { -		entity->state()->assign(entity); -	} -} -*/ - -void GameInterface::update_clientstate() -{ -	for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { -		update_entity_clientstate((*it).second); -	} -} -  void GameInterface::list_players()  {  	using namespace std; diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h index c916d15..f188475 100644 --- a/src/core/gameinterface.h +++ b/src/core/gameinterface.h @@ -54,13 +54,6 @@ public:  	/// clear all game variables, game functions and entities  	void clear(); -	/// reset the client state -	void reset_clientstate(); - -	/// update the client state timers -	void update_clientstate(); - -	void update_entity_clientstate(Entity *entity);  /*----- virtual mutators ------------------------------------------ */ diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 47f5715..b8f8730 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -472,9 +472,9 @@ void GameServer::frame(unsigned long timestamp)  	if (localplayer()->dirty())  	 	localplayer()->update_info(); -	if (!Cvar::sv_dedicated->value()) { +	/*if (!Cvar::sv_dedicated->value()) {  		update_clientstate(); -	} +	}*/  	if ((Cvar::sv_dedicated->value() || Cvar::sv_private->value())) {  		if (core::Cvar::sv_framerate->value()) {		 @@ -490,9 +490,9 @@ void GameServer::frame(unsigned long timestamp)  	float elapsed = (float) (server_timestamp - server_previoustime) / 1000.0f;  	// copy the previous entity state to the client state -	if (!Cvar::sv_dedicated->value()) { +	/*if (!Cvar::sv_dedicated->value()) {  		reset_clientstate(); -	} +	}*/  	// run a time frame on each entity  	for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); it++) { @@ -536,9 +536,9 @@ void GameServer::frame(unsigned long timestamp)  		localplayer()->player_zonechange = false;  	} -	if (!Cvar::sv_dedicated->value()) { +	/*if (!Cvar::sv_dedicated->value()) {  		update_clientstate(); -	} +	}*/  }  void GameServer::save_config() diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 0bb33db..7e12ce7 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -524,7 +524,7 @@ void NetConnection::parse_incoming_message(const std::string & message)  			}  			entity->receive_server_create(msgstream); -			game()->update_entity_clientstate(entity); +			//game()->update_entity_clientstate(entity);  		}  	} else if (command == "menu") {  | 
