Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-08-16 16:32:38 +0000
committerStijn Buys <ingar@osirion.org>2009-08-16 16:32:38 +0000
commit95cc140404c6524ea16e193e1421e826b239114f (patch)
tree3b4b2bf3ab9f4ee948192c1b37f265fe9127c21b
parent6f00effd8f95ad8698d077e6c21426b00d1d02b1 (diff)
more constness, initial patchDef2 support in MapFile, reverse engine disables impulse drive, r_axis support
-rw-r--r--src/core/cvar.cc37
-rw-r--r--src/core/cvar.h96
-rw-r--r--src/core/entity.cc72
-rw-r--r--src/core/entity.h139
-rw-r--r--src/core/gameconnection.cc2
-rw-r--r--src/core/netserver.cc2
-rw-r--r--src/core/parser.cc2
-rw-r--r--src/game/base/jumppoint.cc10
-rw-r--r--src/game/base/navpoint.cc6
-rw-r--r--src/game/base/planet.cc4
-rw-r--r--src/game/base/racetrack.cc6
-rw-r--r--src/game/base/ship.cc182
-rw-r--r--src/game/base/star.cc6
-rw-r--r--src/game/example/example.cc10
-rw-r--r--src/game/example/spectator.cc18
-rw-r--r--src/game/intro/convoy.cc6
-rw-r--r--src/model/asefile.cc2
-rw-r--r--src/model/mapfile.cc80
-rw-r--r--src/model/mapfile.h4
-rw-r--r--src/model/triangle.cc24
-rw-r--r--src/model/triangle.h172
-rw-r--r--src/render/camera.cc4
-rw-r--r--src/render/draw.cc41
-rw-r--r--src/render/render.cc9
-rw-r--r--src/render/render.h2
25 files changed, 523 insertions, 413 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)) {
diff --git a/src/game/base/jumppoint.cc b/src/game/base/jumppoint.cc
index e489055..9017f1c 100644
--- a/src/game/base/jumppoint.cc
+++ b/src/game/base/jumppoint.cc
@@ -15,13 +15,13 @@ namespace game
JumpPoint::JumpPoint() : core::EntityDynamic(core::Entity::Bright)
{
entity_shape = core::Entity::Diamond;
- entity_color.assign(0.0f, 0.8f, 0.8f, 1.0f);
- entity_color_second.assign(0.6f, 1.0f);
- entity_radius = 0.25f;
+ get_color().assign(0.0f, 0.8f, 0.8f, 1.0f);
+ get_color_second().assign(0.6f, 1.0f);
+ set_radius(0.25f);
entity_moduletypeid = jumppoint_enttype;
jumppoint_target = 0;
- entity_serverside = false;
+ set_serverside(false);
}
JumpPoint::~JumpPoint()
@@ -78,8 +78,8 @@ JumpGate::JumpGate() : JumpPoint()
{
unset_flag(core::Entity::Bright);
set_flag(core::Entity::ShowOnMap);
+ set_radius(1.0f);
- entity_radius = 1.0f;
entity_moduletypeid = jumpgate_enttype;
entity_state = core::Entity::NoPower;
}
diff --git a/src/game/base/navpoint.cc b/src/game/base/navpoint.cc
index 5dc35b2..7b48ee7 100644
--- a/src/game/base/navpoint.cc
+++ b/src/game/base/navpoint.cc
@@ -14,9 +14,9 @@ NavPoint::NavPoint() : core::Entity(core::Entity::Static | core::Entity::Bright)
{
//set_flag(core::Entity::ShowOnMap);
entity_shape = core::Entity::Diamond;
- entity_color.assign(1.0f, 1.0f);
- entity_color_second.assign(0.6f, 1.0f);
- entity_radius = 0.25f;
+ get_color().assign(1.0f, 1.0f);
+ get_color_second().assign(0.6f, 1.0f);
+ set_radius(0.25f);
entity_moduletypeid = navpoint_enttype;
}
diff --git a/src/game/base/planet.cc b/src/game/base/planet.cc
index 60885b1..b1ac976 100644
--- a/src/game/base/planet.cc
+++ b/src/game/base/planet.cc
@@ -14,8 +14,8 @@ Planet::Planet() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid)
{
set_flag(core::Entity::ShowOnMap);
- entity_color = math::Color(1,1,1,1); // white
- entity_radius = 64; // 64 game units
+ get_color().assign(1.0f, 1.0f); // white
+ set_radius(64.0f); // 64 game units
entity_moduletypeid = planet_enttype;
diff --git a/src/game/base/racetrack.cc b/src/game/base/racetrack.cc
index f54a24b..3d1cb69 100644
--- a/src/game/base/racetrack.cc
+++ b/src/game/base/racetrack.cc
@@ -20,8 +20,8 @@ CheckPoint::CheckPoint(RaceTrack *parent)
set_state(core::Entity::NoPower);
parent_track = parent;
if (parent) {
- entity_color = parent->color();
- entity_color_second = parent->color_second();
+ get_color().assign(parent->color());
+ get_color_second().assign(parent->color_second());
set_zone(parent->zone());
parent->add_checkpoint(this);
} else {
@@ -142,7 +142,7 @@ void RaceTrack::frame(float seconds)
if (track_racestart + 1.0f <= core::server()->time()) {
entity_timer -= 1.0f;
- entity_dirty = true;
+ set_dirty();
if (entity_timer > 0) {
std::stringstream msgstr;
diff --git a/src/game/base/ship.cc b/src/game/base/ship.cc
index 03fe3de..8bc7799 100644
--- a/src/game/base/ship.cc
+++ b/src/game/base/ship.cc
@@ -36,8 +36,8 @@ Ship::Ship(core::Player *owner, ShipModel *shipmodel) :
entity_moduletypeid = ship_enttype;
- entity_color = owner->color();
- entity_color_second = owner->color_second();
+ get_color().assign(owner->color());
+ get_color_second().assign(owner->color_second());
ship_shipmodel = shipmodel;
ship_jumpdrive = shipmodel->shipmodel_jumpdrive;
@@ -88,10 +88,9 @@ void Ship::func_impulse()
entity_timer = 3;
}
ship_impulsedrive_timer = core::server()->time();
- entity_dirty = true;
}
- entity_dirty = true;
+ set_dirty();
}
void Ship::initiate_jump(JumpPoint *depart)
@@ -114,7 +113,7 @@ void Ship::initiate_jump(JumpPoint *depart)
}
ship_jumpdrive_timer = core::server()->time();
- entity_dirty = true;
+ set_dirty();
}
void Ship::func_jump(std::string const &args)
@@ -149,8 +148,8 @@ void Ship::func_jump(std::string const &args)
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_state = core::Entity::Jump;
- entity_dirty = true;
+ set_state(core::Entity::Jump);
+ set_dirty();
return;
} else {
@@ -244,11 +243,16 @@ void Ship::frame(float seconds)
float actual_thrust = 0;
#ifndef HAVE_BULLET
- const float direction_change_speed = 2;
+ const float direction_reaction = 2.0f; // direction controls reaction time factor
+ const float thrust_reaction = 0.5f; // thrust control reaction time factor
+ const float strafe_reaction = 1.5f;
+ const float afterburner_reaction = 1.0f; // a fterburner control reaction time
+
+
float cosangle; // cosine of an angle
float angle; // angle in radians
math::Vector3f n; // normal of a plane
- math::Axis target_axis(entity_axis); // target axis
+ math::Axis target_axis(axis()); // target axis
#endif
entity_movement = 0;
@@ -256,7 +260,7 @@ void Ship::frame(float seconds)
// speed might be set to 0 on this update
if (entity_speed != 0.0f)
- entity_dirty = true;
+ set_dirty();
if (entity_state == core::Entity::Docked) {
@@ -280,11 +284,11 @@ void Ship::frame(float seconds)
set_state(core::Entity::Jump);
entity_speed = Game::g_impulsespeed->value();
if (ship_jumpdepart->moduletype() == jumpgate_enttype) {
- entity_axis.assign(ship_jumpdepart->target()->axis());
- entity_location.assign(ship_jumpdepart->target()->location());
+ get_axis().assign(ship_jumpdepart->target()->axis());
+ get_location().assign(ship_jumpdepart->target()->location());
//entity_location += entity_axis.forward() * radius();
} else {
- entity_location.assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
+ get_location().assign(ship_jumpdepart->target()->location() + location() - ship_jumpdepart->location());
}
set_zone(ship_jumpdepart->target()->zone());
owner()->send("^BJumping to the " + ship_jumpdepart->target()->zone()->name());
@@ -294,11 +298,11 @@ void Ship::frame(float seconds)
ship_jumpdrive_timer = 0;
entity_timer = 0;
- entity_dirty = true;
+ set_dirty();
return;
} else {
ship_jumpdrive_timer = core::server()->time();
- entity_dirty = true;
+ set_dirty();
}
}
@@ -323,7 +327,7 @@ void Ship::frame(float seconds)
// FIXME 5 second cooldown
entity_state = core::Entity::Normal;
- entity_dirty = true;
+ set_dirty();
if (owner() && owner()->view() && owner()->control() == (EntityControlable*) this)
owner()->set_view(0);
@@ -332,30 +336,38 @@ void Ship::frame(float seconds)
} else if (entity_state == core::Entity::ImpulseInitiate) {
- if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
- entity_timer -= 1.0f;
+ // cancel impulse drive if afterburner goes reverse
+ if (target_afterburner < 0.0f) {
+ set_state(core::Entity::Normal);
+ set_dirty();
+ entity_timer = 0;
+ } else {
- if (entity_timer <= 0) {
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
- entity_state = core::Entity::Impulse;
- entity_timer = 0;
- entity_dirty = true;
- } else {
- ship_impulsedrive_timer = core::server()->time();
- entity_dirty = true;
+ if (ship_impulsedrive_timer + 1.0f <= core::server()->time()) {
+ entity_timer -= 1.0f;
+
+ if (entity_timer <= 0) {
+ actual_maxspeed = Game::g_impulsespeed->value();
+ actual_acceleration = Game::g_impulseacceleration->value();
+ entity_state = core::Entity::Impulse;
+ entity_timer = 0;
+ set_dirty();
+ } else {
+ ship_impulsedrive_timer = core::server()->time();
+ set_dirty();
+ }
}
+
+ // clamp input values
+ target_thrust = 0.0f;
+ math::clamp(target_pitch, -1.0f, 1.0f);
+ math::clamp(target_roll, -1.0f, 1.0f);
+ math::clamp(target_direction, -1.0f, 1.0f);
+ math::clamp(target_afterburner, -1.0f, 1.0f);
+
+ actual_turnspeed *= 0.5;
}
- // clamp input values
- target_thrust = 0.0f;
- math::clamp(target_pitch, -1.0f, 1.0f);
- math::clamp(target_roll, -1.0f, 1.0f);
- math::clamp(target_direction, -1.0f, 1.0f);
- math::clamp(target_afterburner, -1.0f, 1.0f);
-
- actual_turnspeed *= 0.5;
-
} else if (entity_state == core::Entity::Impulse) {
// clamp input values
@@ -365,9 +377,18 @@ void Ship::frame(float seconds)
math::clamp(target_direction, -1.0f, 1.0f);
target_afterburner = 0.0f;
- actual_maxspeed = Game::g_impulsespeed->value();
- actual_acceleration = Game::g_impulseacceleration->value();
- actual_turnspeed *= 0.5;
+ // cancel impulse drive if afterburner goes reverse
+ if (target_afterburner < 0.0f) {
+ set_state(core::Entity::Normal);
+ set_dirty();
+ entity_timer = 0;
+ target_thrust = 1.0f;
+ target_thrust = 1.0f;
+ } else {
+ actual_maxspeed = Game::g_impulsespeed->value();
+ actual_acceleration = Game::g_impulseacceleration->value();
+ actual_turnspeed *= 0.5;
+ }
} else if (entity_state == core::Entity::Normal) {
@@ -395,28 +416,30 @@ void Ship::frame(float seconds)
entity_thrust = 0;
}
- // update afterburner
+ // update afterburner control target
if (current_target_afterburner < target_afterburner) {
- current_target_afterburner += 2.0f * seconds;
+ current_target_afterburner += afterburner_reaction * seconds;
if (current_target_afterburner > target_afterburner)
current_target_afterburner = target_afterburner;
+
} else if (current_target_afterburner > target_afterburner) {
- current_target_afterburner -= 2.0f * seconds;
+ current_target_afterburner -= afterburner_reaction * seconds;
if (current_target_afterburner < target_afterburner)
current_target_afterburner = target_afterburner;
}
- // update thrust
+ // update thrust control target
if (current_target_afterburner < 0.0f) {
target_thrust = 0;
}
if (entity_thrust < target_thrust) {
- entity_thrust += seconds * 0.5f;
+ entity_thrust += thrust_reaction * seconds;
if (entity_thrust > target_thrust)
entity_thrust = target_thrust;
+
} else if (entity_thrust > target_thrust) {
- entity_thrust -= seconds * 0.5f;
+ entity_thrust -= thrust_reaction * seconds;
if (entity_thrust < target_thrust)
entity_thrust = target_thrust;
}
@@ -426,17 +449,28 @@ void Ship::frame(float seconds)
actual_thrust = 1.0f;
}
+
+ // update strafe control target
+ if (current_target_strafe < target_strafe) {
+ current_target_strafe += strafe_reaction * seconds;
+ if (current_target_strafe > target_strafe)
+ current_target_strafe = target_strafe;
+ } else if (current_target_strafe > target_strafe) {
+ current_target_strafe -= strafe_reaction * seconds;
+ if (current_target_strafe < target_strafe)
+ current_target_strafe = target_strafe;
+ }
#ifndef HAVE_BULLET
/* -- original frame --------------------------------------- */
- // update roll
+ // update roll control target
if (current_target_roll < target_roll) {
- current_target_roll += direction_change_speed * seconds;
+ current_target_roll += direction_reaction * seconds;
if (current_target_roll > target_roll)
current_target_roll = target_roll;
} else if (current_target_roll > target_roll) {
- current_target_roll -= direction_change_speed * seconds;
+ current_target_roll -= direction_reaction * seconds;
if (current_target_roll < target_roll)
current_target_roll = target_roll;
}
@@ -444,19 +478,19 @@ void Ship::frame(float seconds)
if (fabs(current_target_roll) > MIN_DELTA) {
float roll_offset = seconds * current_target_roll;
- entity_axis.change_roll(actual_turnspeed * roll_offset);
+ get_axis().change_roll(actual_turnspeed * roll_offset);
} else {
current_target_roll = 0.0f;
}
- // update target_axis direction
+ // update direction control target
if (current_target_direction < target_direction) {
- current_target_direction += direction_change_speed * seconds;
+ current_target_direction += direction_reaction * seconds;
if (current_target_direction > target_direction) {
current_target_direction = target_direction;
}
} else if (current_target_direction > target_direction) {
- current_target_direction -= direction_change_speed * seconds;
+ current_target_direction -= direction_reaction * seconds;
if (current_target_direction < target_direction) {
current_target_direction = target_direction;
}
@@ -469,12 +503,13 @@ void Ship::frame(float seconds)
current_target_direction = 0.0f;
}
+ // update pitch control target
if (current_target_pitch < target_pitch) {
- current_target_pitch += direction_change_speed * seconds;
+ current_target_pitch += direction_reaction * seconds;
if (current_target_pitch > target_pitch)
current_target_pitch = target_pitch;
} else if (current_target_pitch > target_pitch) {
- current_target_pitch -= direction_change_speed * seconds;
+ current_target_pitch -= direction_reaction * seconds;
if (current_target_pitch < target_pitch)
current_target_pitch = target_pitch;
}
@@ -486,45 +521,36 @@ void Ship::frame(float seconds)
current_target_pitch = 0.0f;
}
- n.assign(math::crossproduct(entity_axis.forward(), target_axis.forward()));
+ // update axis
+ n.assign(math::crossproduct(axis().forward(), target_axis.forward()));
if (!(n.length() < MIN_DELTA)) {
n.normalize();
- cosangle = math::dotproduct(entity_axis.forward(), target_axis.forward());
+ cosangle = math::dotproduct(axis().forward(), target_axis.forward());
angle = acos(cosangle) * seconds; // * 180.0f / M_PI;
if (angle > MIN_DELTA)
- entity_axis.rotate(n, -angle);
+ get_axis().rotate(n, -angle);
}
// update speed
- if (entity_speed < actual_thrust * actual_maxspeed) {
+ const float max = actual_thrust * actual_maxspeed;
+ if (entity_speed < max) {
entity_speed += actual_acceleration * seconds;
- if (entity_speed > actual_thrust * actual_maxspeed) {
- entity_speed = actual_thrust * actual_maxspeed;
+ if (entity_speed > max) {
+ entity_speed = max;
}
- } else if(entity_speed > actual_thrust * actual_maxspeed) {
+ } else if(entity_speed > max) {
entity_speed -= actual_acceleration * seconds;
- if (entity_speed < actual_thrust * actual_maxspeed) {
- entity_speed = actual_thrust * actual_maxspeed;
+ if (entity_speed < max) {
+ entity_speed = max;
}
}
- // update strafe
- if (current_target_strafe < target_strafe) {
- current_target_strafe += 2.0f * seconds;
- if (current_target_strafe > target_strafe)
- current_target_strafe = target_strafe;
- } else if (current_target_strafe > target_strafe) {
- current_target_strafe -= 2.0f * seconds;
- if (current_target_strafe < target_strafe)
- current_target_strafe = target_strafe;
- }
-
if (fabs(current_target_strafe) > MIN_DELTA) {
- entity_location += entity_axis.left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds;
+ get_location() += axis().left() * (current_target_strafe * 0.15f * actual_maxspeed) * seconds;
}
- if (entity_speed) {
- entity_location += entity_axis.forward() * entity_speed * seconds;
+ if (fabs(speed()) > MIN_DELTA) {
+ get_location() += axis().forward() * speed() * seconds;
}
#else /* #ifndef HAVE_BULLET */
@@ -559,7 +585,7 @@ void Ship::frame(float seconds)
entity_movement = math::max(entity_movement, fabs(current_target_strafe));
if ((entity_movement > 0)|| (entity_speed > 0)) {
- entity_dirty = true;
+ set_dirty();
}
}
diff --git a/src/game/base/star.cc b/src/game/base/star.cc
index fa5dc32..ba3ccba 100644
--- a/src/game/base/star.cc
+++ b/src/game/base/star.cc
@@ -14,9 +14,9 @@ Star::Star() : core::EntityGlobe(core::Entity::Static | core::Entity::Solid | co
{
set_flag(core::Entity::ShowOnMap);
- entity_color.assign(1,1,1,1);
- entity_color_second.assign(1,1,1,1);
- entity_radius = 96; // 96 game units
+ get_color().assign(1.0f, 1.0f);
+ get_color_second().assign(1.0f, 1.0f);
+ set_radius(96.0f);
entity_moduletypeid = star_enttype;
}
diff --git a/src/game/example/example.cc b/src/game/example/example.cc
index 9d4c1ed..f368556 100644
--- a/src/game/example/example.cc
+++ b/src/game/example/example.cc
@@ -43,9 +43,9 @@ Example::Example() : core::Module("The Osirion Project Example", true)
cube->set_label("cube");
cube->set_name("The Red Cube");
cube->entity_shape = core::Entity::Cube; // set the shape to cube
- cube->get_location().assign(16, -8, 0); // set location
+ cube->get_location().assign(16, -8, 0); // set location
cube->get_color().assign(1, 0, 0); // set RGB color red
- cube->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
cube->set_zone(zone); // add the entity to the zone
core::Entity *sphere = new core::Entity(); // a new entity
@@ -54,7 +54,7 @@ Example::Example() : core::Module("The Osirion Project Example", true)
sphere->entity_shape = core::Entity::Sphere; // set the shape to sphere
sphere->get_location().assign(16, 0, 0); // set location
sphere->get_color().assign(0, 1, 0); // set RGB color green
- sphere->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
sphere->set_zone(zone); // add the entity to the zone
core::Entity *diamond = new core::Entity(); // a new entity
@@ -63,7 +63,7 @@ Example::Example() : core::Module("The Osirion Project Example", true)
diamond->entity_shape = core::Entity::Diamond; // set the shape to cube
diamond->get_location().assign(16, 8, 0); // set location
diamond->get_color().assign(0, 0, 1); // set RGB color blue
- diamond->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
diamond->set_zone(zone); // add the entity to the zone
core::Entity *axis = new core::Entity(); // a new entity
@@ -73,7 +73,7 @@ Example::Example() : core::Module("The Osirion Project Example", true)
axis->get_location().assign(0, 0, 0); // set location
axis->get_color().assign(1); // set greyscale color white
axis->get_color_second().assign(0.5f, 0.0f, 0.5f); // set RGB secondary color
- axis->entity_radius = 0.25f; // set radius, in game units
+ cube->set_radius(0.25f); // set radius, in game units
axis->set_zone(zone); // add the entity to the zone
}
diff --git a/src/game/example/spectator.cc b/src/game/example/spectator.cc
index a2c4353..5fad0f1 100644
--- a/src/game/example/spectator.cc
+++ b/src/game/example/spectator.cc
@@ -15,11 +15,11 @@ Spectator::Spectator(core::Player *owner) : core::EntityControlable(owner)
{
// default properties
entity_shape = core::Entity::Diamond;
- entity_radius = 0.25f;
+ set_radius(0.25f);
// the spectator gets player color
- entity_color.assign(owner->color());
- entity_color_second.assign(owner->color_second());
+ get_color().assign(owner->color());
+ get_color_second().assign(owner->color_second());
// set dirty flag
set_dirty();
@@ -40,9 +40,9 @@ void Spectator::frame(float elapsed)
// rotate according to input
float rotation = g_spectatorrotation->value() * elapsed;
- entity_axis.change_direction(target_direction * rotation);
- entity_axis.change_pitch(target_pitch * rotation);
- entity_axis.change_roll(target_roll * rotation);
+ get_axis().change_direction(target_direction * rotation);
+ get_axis().change_pitch(target_pitch * rotation);
+ get_axis().change_roll(target_roll * rotation);
// assign speed from thruster
float maxspeed = g_spectatorspeed->value();
@@ -50,13 +50,13 @@ void Spectator::frame(float elapsed)
// assign new location
if (entity_speed)
- entity_location += entity_axis.forward() * entity_speed * elapsed;
+ get_location() += axis().forward() * entity_speed * elapsed;
if (target_afterburner)
- entity_location += entity_axis.forward() * maxspeed * target_afterburner * elapsed;
+ get_location() += axis().forward() * maxspeed * target_afterburner * elapsed;
if (target_strafe)
- entity_location += entity_axis.left() * maxspeed * target_strafe * elapsed;
+ get_location() += axis().left() * maxspeed * target_strafe * elapsed;
// set dirty flag
set_dirty();
diff --git a/src/game/intro/convoy.cc b/src/game/intro/convoy.cc
index 9e13ae5..a0cc27c 100644
--- a/src/game/intro/convoy.cc
+++ b/src/game/intro/convoy.cc
@@ -27,7 +27,7 @@ Member::~Member()
void Member::frame(float seconds)
{
- entity_location += axis().forward() * speed() * thrust() * seconds;
+ get_location() += axis().forward() * speed() * thrust() * seconds;
}
/* ---- class Convoy ----------------------------------------------- */
@@ -38,8 +38,8 @@ Convoy::Convoy(core::Zone *zone) : core::EntityDynamic()
set_label("convoy");
set_name("Convoy");
- entity_speed = 1;
- entity_serverside = true;
+ entity_speed = 1.0f;
+ set_serverside();
}
Convoy::~Convoy()
diff --git a/src/model/asefile.cc b/src/model/asefile.cc
index a9e57d4..664a3f7 100644
--- a/src/model/asefile.cc
+++ b/src/model/asefile.cc
@@ -467,7 +467,7 @@ Model * ASEFile::load(const std::string &name)
model->add_group(group);
con_debug << " " << asefile.name() << " " << asefile.ase_vertexlist.size() << " vertices " <<
- model->model_tris_count << "/" << model->model_tris_detail_count << " faces/detail" << std::endl;
+ model->model_tris_count << "/" << model->model_tris_detail_count << " tris/detail" << std::endl;
return model;
}
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index c4f0b7b..54f6d78 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -142,13 +142,14 @@ inline bool spawnflag_isset(unsigned int spawnflags, unsigned int flag)
return ((spawnflags & flag) == flag);
}
-MapFile::MapFile() : map_center(0,0,0)
+MapFile::MapFile() : map_center(0.0f, 0.0f, 0.0f)
{
mapfile_name.clear();
map_brushes = 0;
map_faces = 0;
map_faces_detail = 0;
+ in_patchdef = false;
warning_q2brush = false;
}
@@ -205,6 +206,49 @@ bool MapFile::got_classend(const char * classnamelabel) const
return (last_read_was_classend && (classname_current.compare(classnamelabel) == 0));
}
+bool MapFile::read_patchdef()
+{
+ char data[1024];
+ memset(data, 0, sizeof(data));
+ size_t count = 0;
+
+ // first line: texture name
+ if (!mapfile_ifs.getline(data, 1023))
+ return false;
+ else
+ line_number++;
+
+ // second line: "( a b c d e )"
+ if (!mapfile_ifs.getline(data, 1023))
+ return false;
+ else
+ line_number++;
+
+ // third line: "("
+ if (!mapfile_ifs.getline(data, 1023))
+ return false;
+ else
+ line_number++;
+
+ while (mapfile_ifs.getline(data, 1023)) {
+ line_number++;
+
+ std::istringstream linestream(data);
+ std::string firstword;
+
+ if (linestream >> firstword) {
+ if (firstword.compare(")") == 0) {
+ //con_debug << " patchDef2 with " << count << " lines" << std::endl;
+ return true;
+ } else {
+ count ++;
+ }
+ }
+ }
+
+ return false;
+}
+
bool MapFile::getline()
{
using math::Vector3f;
@@ -236,9 +280,20 @@ bool MapFile::getline()
} else if (firstword == "{") {
parse_level++;
+
+ if ((parse_level == 3) && (in_patchdef)) {
+ if (!read_patchdef()) {
+ con_warn << name() << " error reading patchDef2 at line " << line_number << std::endl;
+ }
+ }
} else if (firstword == "}") {
- if ((parse_level == 2) && (planes.size())) {
+
+ if ((parse_level == 3) && (in_patchdef)) {
+ // end-of-patchdef
+ in_patchdef = false;
+
+ } else if ((parse_level == 2) && (planes.size())) {
// end-of-brush
// for every face
@@ -265,7 +320,7 @@ bool MapFile::getline()
} else if (parse_level == 1) {
- if (firstword == "\"classname\"") {
+ if (firstword.compare("\"classname\"") == 0) {
classname_current.clear();
if (linestream >> classname_current) {
@@ -295,7 +350,7 @@ bool MapFile::getline()
} else if (parse_level == 2) {
- if (firstword == "(") {
+ if (firstword.compare("(") == 0) {
// brush plane
Vector3f p1, p2, p3;
@@ -352,6 +407,9 @@ bool MapFile::getline()
planes.push_back(face);
value_current.clear();
+
+ } else if (firstword.compare("patchDef2") == 0) {
+ in_patchdef = true;
}
}
}
@@ -635,7 +693,7 @@ void MapFile::make_brushface(Face *face)
vl.pop_back();
}
} else {
- con_debug << "Unresolved face!\n";
+ con_warn << name() << " unresolved face at line " << line() << std::endl;
}
// clean up the vertex list
@@ -845,7 +903,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
if (primitives->quads().size()) {
Fragment *fragment = new Fragment(Fragment::Quads, primitives->material());
- // add structural triangles to the fragment
+ // add structural quads to the fragment
for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) {
Quad *quad = (*quad_it);
if (!quad->detail()) {
@@ -859,7 +917,7 @@ void MapFile::load_fragmentgroup(Model *model, const FragmentGroup::Type class_t
}
}
- // add detail triangles to the fragment
+ // add detail quads to the fragment
for (Primitives::Quads::iterator quad_it = primitives->quads().begin(); quad_it != primitives->quads().end(); quad_it++) {
Quad *quad = (*quad_it);
if (quad->detail()) {
@@ -943,7 +1001,8 @@ Model * MapFile::load(std::string const &name)
// worldspawn attributes
if (mapfile.got_key("name")) {
- con_debug << " model name '" << name << "'" << std::endl;
+ //con_debug << " model name '" << name << "'" << std::endl;
+ continue;
} else if (mapfile.got_key_int("enginesound", u)) {
model->model_enginesound = u;
@@ -1403,7 +1462,10 @@ Model * MapFile::load(std::string const &name)
}
con_debug << " " << mapfile.name() << " " << mapfile.map_brushes << " brushes " <<
- mapfile.map_faces << "/" << mapfile.map_faces_detail << " faces/detail " << std::endl;
+ model->model_tris_count << "/" << model->model_tris_detail_count << " tris/detail " <<
+ model->model_quad_count << "/" << model->model_quad_detail_count << " quads/detail" <<
+ std::endl;
+
if (mapfile.warning_q2brush)
con_warn << " quake2 style brushes detected" << std::endl;
diff --git a/src/model/mapfile.h b/src/model/mapfile.h
index fd6bf48..0cf66a5 100644
--- a/src/model/mapfile.h
+++ b/src/model/mapfile.h
@@ -45,6 +45,8 @@ private:
/// parse one line, returns false on end-of-file
bool getline();
+
+ bool read_patchdef();
/// current classname
inline std::string classname() const
@@ -182,6 +184,8 @@ private:
Materials map_materials;
bool warning_q2brush;
+
+ bool in_patchdef;
};
}
diff --git a/src/model/triangle.cc b/src/model/triangle.cc
index 90d52b7..40c34a3 100644
--- a/src/model/triangle.cc
+++ b/src/model/triangle.cc
@@ -10,23 +10,23 @@ namespace model
{
Triangle::Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2) :
- triangle_v0(v0),
- triangle_v1(v1),
- triangle_v2(v2)
+ triangle_v0(v0),
+ triangle_v1(v1),
+ triangle_v2(v2)
{
- triangle_detail = false;
+ triangle_detail = false;
}
Triangle::Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail) :
- triangle_v0(v0),
- triangle_n0(normal),
- triangle_v1(v1),
- triangle_n1(normal),
- triangle_v2(v2),
- triangle_n2(normal),
- triangle_normal(normal)
+ triangle_v0(v0),
+ triangle_n0(normal),
+ triangle_v1(v1),
+ triangle_n1(normal),
+ triangle_v2(v2),
+ triangle_n2(normal),
+ triangle_normal(normal)
{
- triangle_detail = detail;
+ triangle_detail = detail;
}
Triangle::~Triangle()
diff --git a/src/model/triangle.h b/src/model/triangle.h
index f2a741a..8e8d1e2 100644
--- a/src/model/triangle.h
+++ b/src/model/triangle.h
@@ -17,102 +17,92 @@ namespace model
class Triangle
{
public:
- /**
- * @brief a new triangle with 3 vertices
- * this constructor is used by the ASE reader sets the detail flag to false
- */
- Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2);
-
- /**
- * @brief a new triangle with 3 vertices
- * this constructor is used by the MAP reader and assigns the face normal to every vertex normal
- */
- Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false);
-
- /// delete triangle
- ~Triangle();
-
- /// triangle vertex 0
- inline math::Vector3f & v0()
- {
- return triangle_v0;
- }
-
- /// triangle vertex 0 normal
- inline math::Vector3f & n0()
- {
- return triangle_n0;
- }
-
- /// triangle vertex 0 texture coordinates
- inline math::Vector2f & t0()
- {
- return triangle_t0;
- }
-
- /// triangle vertex 1
- inline math::Vector3f & v1()
- {
- return triangle_v1;
- }
-
- /// triangle vertex 1 normal
- inline math::Vector3f & n1()
- {
- return triangle_n1;
- }
-
- /// triangle vertex 1 texture coordinates
- inline math::Vector2f & t1()
- {
- return triangle_t1;
- }
-
- /// triangle vertex 2
- inline math::Vector3f & v2()
- {
- return triangle_v2;
- }
-
- /// triangle vertex 2 normal
- inline math::Vector3f & n2()
- {
- return triangle_n2;
- }
-
- /// triangle vertex 2 texture coordinates
- inline math::Vector2f & t2()
- {
- return triangle_t2;
- }
-
- /// indidcates if this triangle was generated from a detail brush
- inline bool detail() const
- {
- return triangle_detail;
- }
-
- /// face normal
- inline math::Vector3f &normal() {
- return triangle_normal;
- }
+ /**
+ * @brief a new triangle with 3 vertices
+ * this constructor is used by the ASE reader sets the detail flag to false
+ */
+ Triangle(const math::Vector3f &v0, const math::Vector3f &v1, const math::Vector3f &v2);
+
+ /**
+ * @brief a new triangle with 3 vertices
+ * this constructor is used by the MAP reader and assigns the face normal to every vertex normal
+ */
+ Triangle(const math::Vector3f &v0,const math::Vector3f &v1, const math::Vector3f &v2, const math::Vector3f &normal, const bool detail = false);
+
+ /// delete triangle
+ ~Triangle();
+
+ /// triangle vertex 0
+ inline math::Vector3f & v0() {
+ return triangle_v0;
+ }
+
+ /// triangle vertex 0 normal
+ inline math::Vector3f & n0() {
+ return triangle_n0;
+ }
+
+ /// triangle vertex 0 texture coordinates
+ inline math::Vector2f & t0() {
+ return triangle_t0;
+ }
+
+ /// triangle vertex 1
+ inline math::Vector3f & v1() {
+ return triangle_v1;
+ }
+
+ /// triangle vertex 1 normal
+ inline math::Vector3f & n1() {
+ return triangle_n1;
+ }
+
+ /// triangle vertex 1 texture coordinates
+ inline math::Vector2f & t1() {
+ return triangle_t1;
+ }
+
+ /// triangle vertex 2
+ inline math::Vector3f & v2() {
+ return triangle_v2;
+ }
+
+ /// triangle vertex 2 normal
+ inline math::Vector3f & n2() {
+ return triangle_n2;
+ }
+
+ /// triangle vertex 2 texture coordinates
+ inline math::Vector2f & t2() {
+ return triangle_t2;
+ }
+
+ /// indidcates if this triangle was generated from a detail brush
+ inline bool detail() const {
+ return triangle_detail;
+ }
+
+ /// face normal
+ inline math::Vector3f &normal() {
+ return triangle_normal;
+ }
private:
- math::Vector3f triangle_v0;
- math::Vector3f triangle_n0;
- math::Vector2f triangle_t0;
+ math::Vector3f triangle_v0;
+ math::Vector3f triangle_n0;
+ math::Vector2f triangle_t0;
- math::Vector3f triangle_v1;
- math::Vector3f triangle_n1;
- math::Vector2f triangle_t1;
+ math::Vector3f triangle_v1;
+ math::Vector3f triangle_n1;
+ math::Vector2f triangle_t1;
- math::Vector3f triangle_v2;
- math::Vector3f triangle_n2;
- math::Vector2f triangle_t2;
-
- math::Vector3f triangle_normal;
- bool triangle_detail;
+ math::Vector3f triangle_v2;
+ math::Vector3f triangle_n2;
+ math::Vector2f triangle_t2;
+
+ math::Vector3f triangle_normal;
+ bool triangle_detail;
};
}
diff --git a/src/render/camera.cc b/src/render/camera.cc
index ba82ea6..54c4547 100644
--- a/src/render/camera.cc
+++ b/src/render/camera.cc
@@ -59,7 +59,7 @@ void Camera::init()
target_direction = 0.0f;
distance = 0.4f;
- camera_zoom = 1.0f;
+ camera_zoom = 2.0f;
camera_mode = Overview;
camera_previous_mode = Track;
@@ -290,7 +290,7 @@ void Camera::frame(float seconds)
if (core::localcontrol()->model()) {
camera_target -= camera_axis.forward() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().x);
- camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().z);
+ camera_target += camera_axis.up() * math::max(FRUSTUMFRONT / WORLDSCALE, core::localcontrol()->model()->maxbbox().z * 2.0f);
} else {
camera_target -= camera_axis.forward() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
camera_target += camera_axis.up() * math::max (FRUSTUMFRONT / WORLDSCALE, FRUSTUMFRONT / WORLDSCALE + core::localcontrol()->radius());
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 1884125..e9123cd 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -837,6 +837,7 @@ void draw_model_bbox(model::Model *model)
gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_minbbox.z);
gl::end();
+ // body
gl::begin(gl::Lines);
gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_maxbbox.z);
gl::vertex(model->model_maxbbox.x, model->model_maxbbox.y, model->model_minbbox.z);
@@ -846,6 +847,43 @@ void draw_model_bbox(model::Model *model)
gl::vertex(model->model_minbbox.x, model->model_minbbox.y, model->model_minbbox.z);
gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_maxbbox.z);
gl::vertex(model->model_maxbbox.x, model->model_minbbox.y, model->model_minbbox.z);
+
+ gl::end();
+}
+
+
+// draw entity axis
+void draw_model_axis(const core::Entity *entity)
+{
+ // axis
+ const float r = entity->radius() * 1.5f;
+
+ gl::begin(gl::Lines);
+
+ gl::color(entity->color());
+
+ gl::vertex(-r, 0.0f, 0.0f);
+ gl::vertex(r, 0.0f, 0.0f);
+
+ gl::vertex(0.0f, -r, 0.0f);
+ gl::vertex(0.0f, r, 0.0f);
+
+ gl::vertex(0.0f, 0.0f, -r);
+ gl::vertex(0.0f, 0.0f, r);
+
+ const math::Axis worldaxis(entity->axis().transpose());
+
+ gl::color(1.0f, 0.0f, 0.0f);
+
+ gl::vertex(worldaxis.forward() * -1 * r);
+ gl::vertex(worldaxis.forward() * r);
+
+ gl::vertex(worldaxis.left() * -1 * r);
+ gl::vertex(worldaxis.left() * r);
+
+ gl::vertex(worldaxis.up() * -1 * r);
+ gl::vertex(worldaxis.up() * r);
+
gl::end();
}
@@ -866,6 +904,9 @@ void draw_pass_model_fragments()
draw_model_bbox(entity->model());
}
+ if (r_axis->value()) {
+ draw_model_axis(entity);
+ }
gl::pop();
}
}
diff --git a/src/render/render.cc b/src/render/render.cc
index 27204f6..4ad2d84 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -26,6 +26,7 @@
namespace render {
+core::Cvar *r_axis = 0;
core::Cvar *r_bbox = 0;
core::Cvar *r_grid = 0;
core::Cvar *r_particles = 0;
@@ -74,11 +75,14 @@ void init(int width, int height)
r_normals->set_info("[bool] render face normals");
r_normalize = core::Cvar::get("r_normalize", "0", core::Cvar::Archive);
- r_normalize->set_info("[bool] use GL_NORMALIZE instead of GL_RESCALE_NORMAL");
+ r_normalize->set_info("[bool] use GL_NORMALIZE instead of GL_RESCALE_NORMAL (recommended off)");
r_grid = core::Cvar::get("r_grid", "0", core::Cvar::Archive);
r_grid->set_info("[bool] render the space grid");
+ r_axis = core::Cvar::get("r_axis", "0", core::Cvar::Archive);
+ r_axis->set_info("[bool] render entity axis");
+
r_bbox = core::Cvar::get("r_bbox", "0", core::Cvar::Archive);
r_bbox->set_info("[bool] render model bounding box");
@@ -99,9 +103,10 @@ void init(int width, int height)
// hardware generate mipmaps
r_mipmap = core::Cvar::get("r_mipmap", "1", core::Cvar::Archive);
- r_mipmap->set_info("[bool] use hardware generated mipmaps");
+ r_mipmap->set_info("[bool] use hardware generated mipmaps (recommended on)");
if (!State::has_generate_mipmaps()) {
con_print << " no hardware generated mipmap support" << std::endl;
+ (*r_mipmap) = 0.0f;
}
Camera::init();
diff --git a/src/render/render.h b/src/render/render.h
index c397c78..765e0f9 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -36,6 +36,8 @@ namespace render {
/// resize viewport
void resize(int width, int height);
+ /// render entity axis
+ extern core::Cvar *r_axis;
/// render model bounding boxes
extern core::Cvar *r_bbox;
/// render the spacegrid