Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2014-12-07 16:12:49 +0000
committerStijn Buys <ingar@osirion.org>2014-12-07 16:12:49 +0000
commit2c98d3eef488233b99a76ca44d69c1c9d53404af (patch)
tree9259bad9533d1de7381b291eee19fd319b8366eb /src/core
parentacb236d0df275394095ab43e8519aebc4811865d (diff)
Cleanup of the slots code, unified model weapon and dock tags into a single slots list,
load dock tags into entity slots, represent entity slot locations in entity coordinate space, have r_slots render fixed-size slot indicators regardless of model scale.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/slot.cc39
-rw-r--r--src/core/slot.h49
-rw-r--r--src/core/slots.cc23
-rw-r--r--src/core/slots.h2
4 files changed, 81 insertions, 32 deletions
diff --git a/src/core/slot.cc b/src/core/slot.cc
index 58bb51c..8907097 100644
--- a/src/core/slot.cc
+++ b/src/core/slot.cc
@@ -13,16 +13,35 @@ namespace core
Slot::Slot()
{
+ clear();
+}
+
+Slot::~Slot()
+{
+}
+
+void Slot::load(const model::Slot *slot_tag, const float modelscale)
+{
+ if (slot_tag) {
+ set_type(slot_tag->type());
+ set_location(slot_tag->location() * modelscale);
+ set_axis(slot_tag->axis());
+ set_radius(slot_tag->radius());
+ set_cone(slot_tag->cone() * M_PI / 180.0f);
+ } else {
+ Slot();
+ }
+}
+
+void Slot::clear()
+{
slot_item = 0;
slot_flags = 0;
slot_timestamp = 0;
slot_last_fired = 0;
slot_cone = 0;
- slot_type = model::Weapon::Cannon;
-}
-
-Slot::~Slot()
-{
+ slot_radius = 1.0f;
+ slot_type = model::Slot::None;
}
void Slot::set_flag(const Flags flag)
@@ -43,14 +62,4 @@ void Slot::set_item(Item *item)
set_timestamp(game() ? game()->timestamp() : 1);
}
-void Slot::load(const model::Weapon * weapon_tag)
-{
- if (weapon_tag) {
- set_type(weapon_tag->type());
- set_cone(weapon_tag->cone() * M_PI / 180.0f);
- set_location(weapon_tag->location());
- set_axis(weapon_tag->axis());
- }
-}
-
} // namespace core
diff --git a/src/core/slot.h b/src/core/slot.h
index 5466de8..99353ee 100644
--- a/src/core/slot.h
+++ b/src/core/slot.h
@@ -23,20 +23,30 @@ namespace core
* */
class Slot {
public:
- enum Flags {Mounted = 1, Active = 2};
+ enum Flags {None = 0, Mounted = 1, Active = 2};
/**
* @brief default constructor
* Creates an empty slot
* */
Slot();
-
+
/**
* @brief default destructor
* */
~Slot();
/**
+ * @brief load slot configuration from a model slot
+ * */
+ void load(const model::Slot *slot_tag, const float modelscale);
+
+ /**
+ * @brief clear slot values
+ * */
+ void clear();
+
+ /**
* @brief location of the slot within the parent model
* */
inline const math::Vector3f & location() const
@@ -86,9 +96,17 @@ public:
}
/**
+ * @brief slot radius
+ * */
+ inline const float radius() const
+ {
+ return slot_radius;
+ }
+
+ /**
* @brief slot fire cone, in degrees
* */
- inline float cone() const
+ inline const float cone() const
{
return slot_cone;
}
@@ -96,7 +114,7 @@ public:
/**
* @brief weapon slot type
* */
- inline const model::Weapon::Type type() const
+ inline const model::Slot::Type type() const
{
return slot_type;
}
@@ -161,9 +179,17 @@ public:
}
/**
+ * @brief set slot slot_radius
+ * */
+ void set_radius(const float radius)
+ {
+ slot_radius = radius;
+ }
+
+ /**
* @brief set slot type
* */
- void set_type(const model::Weapon::Type type)
+ void set_type(const model::Slot::Type type)
{
slot_type = type;
}
@@ -171,13 +197,19 @@ public:
/**
* @brief load slot parameters from a model weapon tag
* */
- void load(const model::Weapon *weapon_tag);
+ void load(const model::Slot *slot_tag);
private:
+ model::Slot::Type slot_type;
+
math::Vector3f slot_location;
math::Axis slot_axis;
+
+ float slot_radius;
+
+ float slot_cone;
// slot flags
unsigned int slot_flags;
@@ -188,13 +220,8 @@ private:
// timestamp indicating when the slot last generated a projectile, server-side
unsigned long slot_last_fired;
-
// item mounted in this slot
Item *slot_item;
-
- model::Weapon::Type slot_type;
-
- float slot_cone;
};
} // namespace core
diff --git a/src/core/slots.cc b/src/core/slots.cc
index 6d6096a..23fb7e1 100644
--- a/src/core/slots.cc
+++ b/src/core/slots.cc
@@ -19,12 +19,25 @@ Slots::~Slots()
clear();
}
-void Slots::load(model::Model *model)
+void Slots::load(model::Model *model, const float modelscale)
{
- for (model::Model::Weapons::iterator it = model->weapons().begin(); it != model->weapons().end(); ++it) {
- Slot *slot = new Slot();
- slot->load((*it));
- slots_container.push_back(slot);
+ for (model::Model::Slots::const_iterator slit = model->slots().begin(); slit != model->slots().end(); ++slit) {
+
+ const model::Slot *tag_slot = (*slit);
+ Slot *slot = 0;
+
+ switch (tag_slot->type()) {
+ case model::Slot::Cannon:
+ case model::Slot::Turret:
+ case model::Slot::Dock:
+ slot = new Slot();
+ slot->load(tag_slot, modelscale);
+ slots_container.push_back(slot);
+ break;
+
+ case model::Slot::None:
+ break;
+ }
}
//con_debug << " loaded " << slots_container.size() << " entity slots" << std::endl;
}
diff --git a/src/core/slots.h b/src/core/slots.h
index 2452ccb..b7b0673 100644
--- a/src/core/slots.h
+++ b/src/core/slots.h
@@ -32,7 +32,7 @@ public:
/**
* @brief initialize slots collection from model properties
* */
- void load(model::Model *model);
+ void load(model::Model *model, const float modelscale);
/**
* @brief remove all slots