diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/cvar.cc | 37 | ||||
-rw-r--r-- | src/core/cvar.h | 96 | ||||
-rw-r--r-- | src/core/entity.cc | 72 | ||||
-rw-r--r-- | src/core/entity.h | 139 | ||||
-rw-r--r-- | src/core/gameconnection.cc | 2 | ||||
-rw-r--r-- | src/core/netserver.cc | 2 | ||||
-rw-r--r-- | src/core/parser.cc | 2 |
7 files changed, 165 insertions, 185 deletions
diff --git a/src/core/cvar.cc b/src/core/cvar.cc index 2a9fd67..1732d1a 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -36,19 +36,18 @@ Cvar *Cvar::net_framerate = 0; Cvar::Registry Cvar::cvar_registry; -Cvar::Cvar(const char *name, const unsigned int flags) : cvar_name(), cvar_info(), cvar_str() +Cvar::Cvar(const char* name, const unsigned int flags) : cvar_name(name), cvar_info(), cvar_str() { cvar_flags = flags; - cvar_name.assign(name); } -void Cvar::set_info(const char *info) +void Cvar::set_info(const char* info) { if (info) cvar_info.assign(info); } -Cvar & Cvar::operator=(const std::string &other) +Cvar & Cvar::operator=(const std::string& other) { cvar_str = other; std::stringstream s(cvar_str); @@ -57,13 +56,13 @@ Cvar & Cvar::operator=(const std::string &other) return (*this); } -Cvar & Cvar::operator=(const char *other) +Cvar & Cvar::operator=(const char* other) { std::string value(other); return (this->operator=(value)); } -Cvar & Cvar::operator=(float other) +Cvar & Cvar::operator=(const float other) { std::stringstream s; s << other; @@ -72,13 +71,10 @@ Cvar & Cvar::operator=(float other) return (*this); } -Cvar* Cvar::get(const char *name, const char *value, const unsigned int flags) +Cvar* Cvar::get(const char* name, const char* value, const unsigned int flags) { Cvar *c = find(name); - if (c) { - //con_debug << "get " << name << " already exist with value " << cvar->str() << std::endl; - } else { - //con_debug << "get " << name << " " << value << std::endl; + if (!c) { c = new Cvar(name, flags); cvar_registry[c->name()] = c; (*c) = value; @@ -87,13 +83,10 @@ Cvar* Cvar::get(const char *name, const char *value, const unsigned int flags) return c; } -Cvar* Cvar::get(const char *name, float value, const unsigned int flags) +Cvar* Cvar::get(const char* name, const float value, const unsigned int flags) { Cvar *c = find(name); - if (c) { - //con_debug << "get " << name << " already exist with value " << cvar->str() << std::endl; - } else { - //con_debug << "get " << name << " " << value << std::endl; + if (!c) { c = new Cvar(name, flags); cvar_registry[c->name()] = c; (*c) = value; @@ -102,7 +95,7 @@ Cvar* Cvar::get(const char *name, float value, const unsigned int flags) return c; } -Cvar* Cvar::set(const char *name, const char *value, const unsigned int flags) +Cvar* Cvar::set(const char* name, const char* value, const unsigned int flags) { Cvar *c = find(name); if (!c) { @@ -116,7 +109,7 @@ Cvar* Cvar::set(const char *name, const char *value, const unsigned int flags) return c; } -Cvar* Cvar::set(const char *name, float value, unsigned int flags) +Cvar* Cvar::set(const char* name, const float value, const unsigned int flags) { Cvar *c = find(name); if (!c) { @@ -130,7 +123,7 @@ Cvar* Cvar::set(const char *name, float value, unsigned int flags) return c; } -void Cvar::unset(std::string const &name) +void Cvar::unset(const std::string& name) { Cvar *c = find(name); if (c) { @@ -140,12 +133,12 @@ void Cvar::unset(std::string const &name) } } -void Cvar::unset(const char *name) +void Cvar::unset(const char* name) { unset(std::string(name)); } -Cvar *Cvar::find(std::string const &name) +Cvar *Cvar::find(const std::string& name) { Registry::iterator it = cvar_registry.find(name); if (it == cvar_registry.end()) @@ -154,7 +147,7 @@ Cvar *Cvar::find(std::string const &name) return (*it).second; } -Cvar *Cvar::find(const char *name) +Cvar *Cvar::find(const char* name) { std::string s(name); return(find(s)); diff --git a/src/core/cvar.h b/src/core/cvar.h index 8861f2a..4c3d942 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -13,12 +13,16 @@ namespace core { -/// a variable encapsulation class +/** + * @brief a client variable encapsulation class + * values f client variables can be set through the command console interface + */ class Cvar { public: - /// Cvar flags /** + * @brief Cvar flags + * * 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 @@ -27,86 +31,90 @@ public: enum Flags {Archive=1, ReadOnly=2, Game=4, Info=8}; /// create a new variable - Cvar(const char *name, const unsigned int flags = 0); + Cvar(const char* name, const unsigned int flags = 0); /*----- inspectors ------------------------------------------------ */ /// returns the name of the variable - inline std::string const &name() { return cvar_name; } + inline const std::string& name() const { return cvar_name; } /// returns the info of the variable - inline std::string const &info() { return cvar_info; } + inline const std::string& info() const { return cvar_info; } /// returns the flags of the variable - inline unsigned int flags() const { return cvar_flags; } + inline const unsigned int flags() const { return cvar_flags; } /// returns the float value of the variable - inline float value() const { return cvar_value; } + inline const float value() const { return cvar_value; } /// returns the string value of the variable - inline const std::string &str() const { return cvar_str; } + inline const std::string& str() const { return cvar_str; } /*----- mutators -------------------------------------------------- */ /// set the info string - void set_info(const char *); + void set_info(const char* info); /// char * assignment operator - Cvar &operator=(const char *other); + Cvar &operator=(const char* other); /// std::string assignment operator - Cvar &operator=(const std::string &other); + Cvar &operator=(const std::string& other); /// float assignment operator - Cvar &operator=(float other); + Cvar &operator=(const float other); /* ---- Static functions for the Cvar registry -------------------- */ /// type definition for the Cvar registry typedef std::map<std::string, Cvar*> Registry; - /// get a cvar value from the registry - /** If the a cvar with the given name already exists in the registry, - * its value will not be changed. If the cvar does not exist, - * it will be created - */ - static Cvar *get(const char *name, const char *value, const unsigned int flags=0); - - /// get a cvar value from the registry - /** If the a cvar with the given name already exists in the registry, - * its value will not be changed. If the cvar does not exist, - * it will be created - */ - static Cvar *get(const char *name, float value, const unsigned int flags=0); - - /// set a cvar value - /** If the a cvar with the given name already exists in the registry, - * its value will be replaced - */ - static Cvar *set(const char *name, const char *value, const unsigned int flags=0); - - /// set a cvar value - /** If the a cvar with the given name already exists in the registry, - * its value will be replaced - */ - static Cvar *set(const char *name, float value, const unsigned int flags=0); + /** + * @brief get a cvar value from the registry + * If the a cvar with the given name already exists in the registry, + * its value will not be changed. If the cvar does not exist, + * it will be created + */ + static Cvar* get(const char* name, const char* value, const unsigned int flags=0); - /// delete a cvar from the registry - static void unset(const char *name); + /** + * @brief get a cvar value from the registry + * If the a cvar with the given name already exists in the registry, + * its value will not be changed. If the cvar does not exist, + * it will be created + */ + static Cvar* get(const char* name, const float value, const unsigned int flags=0); - /// delete a cvar from the registry - static void unset(std::string const &name); + /** + * @brief set a cvar value + * If the a cvar with the given name already exists in the registry, + * its value will be replaced + */ + static Cvar* set(const char* name, const char* value, const unsigned int flags=0); + + /** + * @brief set a cvar value + * If the a cvar with the given name already exists in the registry, + * its value will be replaced + */ + static Cvar* set(const char* name, float value, const unsigned int flags=0); /// search for a named cvar, returns 0 if not found - static Cvar *find(std::string const &name); + static Cvar* find(const std::string& name); /// search for a named cvar, returns 0 if not found - static Cvar *find(const char *name); + static Cvar* find(const char* name); + + /// delete a cvar from the registry + static void unset(const char* name); + + /// delete a cvar from the registry + static void unset(const std::string& name); /// list the cvar registry static void list(); - /// the Cvar registry + /// the cvar registry static inline Registry & registry() { return cvar_registry; } static Cvar *sv_dedicated; // dedicated server diff --git a/src/core/entity.cc b/src/core/entity.cc index 2b3c482..0ead5f4 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -87,7 +87,7 @@ void Entity::list() /* ---- class Entity ----------------------------------------------- */ -Entity::Entity(unsigned int flags) : +Entity::Entity(const unsigned int flags) : entity_location(0.0f, 0.0f, 0.0f), entity_color(1.0f, 1.0f, 1.0f, 1.0f), entity_color_second(1.0f, 1.0f, 1.0f, 1.0f) @@ -186,7 +186,7 @@ void Entity::set_zone(Zone *zone) entity_zone->add(this); } -void Entity::set_label(char const *label) +void Entity::set_label(const char *label) { entity_label.assign(label); aux::to_label(entity_label); @@ -198,7 +198,7 @@ void Entity::set_label(const std::string &label) aux::to_label(entity_label); } -void Entity::set_name(char const *name) +void Entity::set_name(const char *name) { entity_name.assign(name); aux::strip_quotes(entity_name); @@ -210,34 +210,6 @@ void Entity::set_name(const std::string &name) aux::strip_quotes(entity_name); } -void Entity::set_visible(bool visible) -{ - if (visible) - show(); - else - hide(); -} - -void Entity::show() -{ - entity_visible = false; -} - -void Entity::hide() -{ - entity_visible = false; -} - -void Entity::set_flag(Flags flag) -{ - entity_flags |= flag; -} - -void Entity::unset_flag(Flags flag) -{ - entity_flags &= ~flag; -} - void Entity::set_model(model::Model *model) { entity_model = model; @@ -408,9 +380,9 @@ EntityDynamic::~EntityDynamic() void EntityDynamic::set_state(int state) { - if (entity_state != state) { + if (this->state() != state) { entity_state = state; - entity_dirty = true; + set_dirty(); } } @@ -422,9 +394,9 @@ void EntityDynamic::frame(float seconds) if (entity_speed == 0) return; - entity_location += entity_axis.forward() * entity_speed * seconds; + get_location() += axis().forward() * entity_speed * seconds; - entity_dirty = true; + set_dirty(); } void EntityDynamic::serialize_server_create(std::ostream & os) const @@ -465,9 +437,9 @@ void EntityDynamic::serialize_server_update(std::ostream & os) const os << (visible() ? 1 : 0 ) << " "; if (visible()) { os << std::setprecision(8) - << entity_location << " " - << entity_axis.forward() << " " - << entity_axis.left() << " " + << location() << " " + << axis().forward() << " " + << axis().left() << " " << roundf(entity_speed * 100.0f) << " " << entity_state << " "; @@ -482,12 +454,12 @@ void EntityDynamic::receive_server_update(std::istream &is) unsigned int o = 0; is >> o; // visibility if (o) { - entity_visible = true; - is >> entity_location; + set_visible(); + is >> get_location(); // axis up vector is the crossproduct of forward and left - is >> entity_axis[0]; - is >> entity_axis[1]; - entity_axis[2] = math::crossproduct(entity_axis.forward(), entity_axis.left()); + is >> get_axis()[0]; + is >> get_axis()[1]; + get_axis()[2] = math::crossproduct(axis().forward(), axis().left()); is >> entity_speed; entity_speed /= 100.0f; is >> entity_state; @@ -498,7 +470,7 @@ void EntityDynamic::receive_server_update(std::istream &is) entity_timer = 0; } } else { - entity_visible = false; + set_visible(false); } } @@ -632,7 +604,7 @@ void EntityControlable::set_thrust(float thrust) if (thrust != target_thrust) { target_thrust = thrust; - entity_dirty = true; + set_dirty(); } } @@ -643,7 +615,7 @@ void EntityControlable::set_direction(float direction) if (target_direction != direction) { target_direction = direction; - entity_dirty = true; + set_dirty(); } } @@ -654,7 +626,7 @@ void EntityControlable::set_pitch(float pitch) if (target_pitch != pitch) { target_pitch = pitch; - entity_dirty = true; + set_dirty(); } } @@ -665,7 +637,7 @@ void EntityControlable::set_roll(float roll) if (target_roll != roll) { target_roll = roll; - entity_dirty = true; + set_dirty(); } } @@ -676,7 +648,7 @@ void EntityControlable::set_strafe(float strafe) if (target_strafe != strafe) { target_strafe = strafe; - entity_dirty = true; + set_dirty(); } } @@ -687,7 +659,7 @@ void EntityControlable::set_afterburner(float afterburner) if (target_afterburner != afterburner) { target_afterburner = afterburner; - entity_dirty = true; + set_dirty(); } } diff --git a/src/core/entity.h b/src/core/entity.h index 41c56b4..3002219 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -54,7 +54,7 @@ public: typedef std::list<MenuDescription *> Menus; /// create a new entity and add it to the registry - Entity(unsigned int flags = 0); + Entity(const unsigned int flags = 0); /// create an entity from stream data Entity(std::istream & is); @@ -65,25 +65,25 @@ public: /*----- inspectors ------------------------------------------------ */ /// entity id - inline unsigned int id() const { return entity_id; } + inline const unsigned int id() const { return entity_id; } /// module type id - inline unsigned int moduletype() const { return entity_moduletypeid; } + inline const unsigned int moduletype() const { return entity_moduletypeid; } /// core type id virtual inline const unsigned int type() const { return Default; } /// entity flags - inline unsigned int flags() const { return entity_flags; } + inline const unsigned int flags() const { return entity_flags; } /// returns true of a flag is set - inline bool flag_is_set(const Flags flag) const { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); } + inline const bool flag_is_set(const Flags flag) const { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); } /// entity label (can not contain double quotes ") - inline std::string const & label() { return entity_label; } + inline const std::string& label() const { return entity_label; } /// entity name (can not contain double qoutes ") - inline std::string const & name() { return entity_name; } + inline const std::string & name() const { return entity_name; } /// pointer to the model, is used client-side inline model::Model * model() { return entity_model; } @@ -134,7 +134,10 @@ public: inline Extension *extension(size_t type) const { return entity_extension[type]; } /// find a menu - MenuDescription *find_menu(std::string const &label); + MenuDescription *find_menu(const std::string &label); + + + /* ---- mutators -------------------------------------------------- */ /// assign entity color inline void set_color(const math::Color &color) { entity_color.assign(color); } @@ -142,27 +145,8 @@ public: /// assign entity secondary color inline void set_color_second(const math::Color &color) { entity_color_second.assign(color); } -/*----- serializers ----------------------------------------------- */ - - /// serialize the entity to a stream - virtual void serialize_server_create(std::ostream & os) const; - - /// serialize a client-to-server update on a stream - virtual void serialize_client_update(std::ostream & os) const; - - /// serialize a server-to-client update on a stream - virtual void serialize_server_update(std::ostream & os) const; - -/*----- mutators -------------------------------------------------- */ - - /// receive a client-to-server update from a stream - virtual void receive_client_update(std::istream &is); - - /// receive a server-to-client create from a stream - virtual void receive_server_create(std::istream &is); - - /// receive a server-to-client update from a stream - virtual void receive_server_update(std::istream &is); + /// set dirty flag + inline void set_dirty(const bool dirty = true) { entity_dirty = dirty; } /// mark the entity as destroyed virtual void die(); @@ -173,33 +157,31 @@ public: */ virtual void frame(float seconds); - /// called when the entity received a docking request - virtual void dock(core::Entity *entity); - - /// set dirty flag - inline void set_dirty() { entity_dirty = true; } - - /// set the zone the entity is currently in /** + * @brief set the zone the entity is currently in + * * this fuction removes the entity from its previous zone * and removes it to the new one, if it is not 0 */ virtual void set_zone(Zone *zone); /// set the label - void set_label(char const *label); + void set_label(const char *label); /// set the label void set_label(const std::string &label); /// set the name - void set_name(char const *name); + void set_name(const char *name); /// set the name void set_name(const std::string &name); /// set visibility - void set_visible(bool visible = true); + inline void set_visible(const bool visible = true) { entity_visible = visible; } + + /// set as server-side entity + inline void set_serverside(const bool serverside = true) { entity_serverside = serverside; } /// set the model name and load the model void set_modelname(const std:: string &model); @@ -207,17 +189,19 @@ public: /// set the model void set_model(model::Model *model); - /// show the entity, make it visible - virtual void show(); + /// set entity radius + inline void set_radius(const float radius) { entity_radius = radius; } - /// hide the entity, make it invisible - virtual void hide(); + /* ---- actors ---------------------------------------------------- */ - /// set a flag - void set_flag(Flags flag); + /// called when the entity received a docking request + virtual void dock(core::Entity *entity); + + /// set flags + inline void set_flag(Flags flag) { entity_flags |= flag; } - /// unset a flag - void unset_flag(Flags flag); + /// unset flags + inline void unset_flag(Flags flag) { entity_flags &= ~flag; } /// add an entity menu void add_menu(MenuDescription *menu); @@ -228,8 +212,6 @@ public: /// clear all update flags virtual void clear_updates(); -/*----- actors ---------------------------------------------------- */ - /** * @brief mutable reference to the location */ @@ -251,7 +233,30 @@ public: inline math::Color& get_color_second() { return entity_color_second; } -/*----- static ---------------------------------------------------- */ + /* ---- deserializers -------------------------------------- */ + + /// receive a client-to-server update from a stream + virtual void receive_client_update(std::istream &is); + + /// receive a server-to-client create from a stream + virtual void receive_server_create(std::istream &is); + + /// receive a server-to-client update from a stream + virtual void receive_server_update(std::istream &is); + + /* ---- serializers ---------------------------------------- */ + + /// serialize the entity to a stream + virtual void serialize_server_create(std::ostream & os) const; + + /// serialize a client-to-server update on a stream + virtual void serialize_client_update(std::ostream & os) const; + + /// serialize a server-to-client update on a stream + virtual void serialize_server_update(std::ostream & os) const; + + + /* ---- static --------------------------------------------- */ /// type definition for the entity registry typedef std::map<unsigned int, Entity*> Registry; @@ -275,41 +280,43 @@ public: /// speed of the entity float entity_speed; - float entity_radius; Shape entity_shape; unsigned int entity_moduletypeid; - bool entity_dirty; bool entity_created; bool entity_destroyed; /// timestamp when entity data was received from the server float entity_servertimestamp; -protected: - // the zone the entity belongs to - Zone *entity_zone; - // the previous zone the entity belonged too - Zone *entity_oldzone; +private: + + unsigned int entity_id; + unsigned int entity_flags; + bool entity_dirty; bool entity_visible; bool entity_serverside; math::Vector3f entity_location; math::Axis entity_axis; + + float entity_radius; + math::Color entity_color; math::Color entity_color_second; -private: - unsigned int entity_id; - unsigned int entity_flags; - std::string entity_name; std::string entity_label; - - model::Model *entity_model; std::string entity_modelname; + model::Model* entity_model; + + // the zone the entity belongs to + Zone* entity_zone; + // the previous zone the entity belonged too + Zone* entity_oldzone; + Menus entity_menus; Extension* entity_extension[4]; @@ -326,7 +333,7 @@ class EntityDynamic : public Entity { public: /// create a dynamic entity - EntityDynamic(unsigned int flags = 0); + EntityDynamic(const unsigned int flags = 0); /// create a dynamic entity from stream data EntityDynamic(std::istream & is); @@ -387,7 +394,7 @@ class EntityControlable : public EntityDynamic friend class Player; public: /// create a controlable entity - EntityControlable(Player *owner, unsigned int flags = 0); + EntityControlable(Player *owner, const unsigned int flags = 0); /// create a controlable entity from stream data EntityControlable(std::istream & is); @@ -490,7 +497,7 @@ private: class EntityGlobe : public Entity { public: - EntityGlobe(unsigned int flags = 0); + EntityGlobe(const unsigned int flags = 0); EntityGlobe(std::istream & is); virtual ~EntityGlobe(); diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index 3384418..65126e3 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -178,7 +178,7 @@ void GameConnection::frame(unsigned long timestamp) if(localcontrol() && localcontrol()->dirty()) { connection_network->send_clientupdate(localcontrol()); - localcontrol()->entity_dirty = false; + localcontrol()->set_dirty(false); } diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 7416d9f..83bbd6e 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -736,7 +736,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me return; } - entitycontrolable->entity_dirty = true; + entitycontrolable->set_dirty(true); entitycontrolable->receive_client_update(msgstream); } return; diff --git a/src/core/parser.cc b/src/core/parser.cc index fcca2e1..84590a2 100644 --- a/src/core/parser.cc +++ b/src/core/parser.cc @@ -78,7 +78,7 @@ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity) return true; } else if (inifile.got_key_angle("radius", f)) { - entity->entity_radius = f; + entity->set_radius(f); return true; } else if (inifile.got_key_vector3f("location", v)) { |