From 2c98d3eef488233b99a76ca44d69c1c9d53404af Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 7 Dec 2014 16:12:49 +0000 Subject: 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. --- src/core/slot.cc | 39 ++++++++++++++++++++++++--------------- src/core/slot.h | 49 ++++++++++++++++++++++++++++++++++++++----------- src/core/slots.cc | 23 ++++++++++++++++++----- src/core/slots.h | 2 +- 4 files changed, 81 insertions(+), 32 deletions(-) (limited to 'src/core') 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 @@ -12,17 +12,36 @@ 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,19 +23,29 @@ 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 * */ @@ -85,10 +95,18 @@ public: return slot_last_fired; } + /** + * @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; } @@ -160,10 +178,18 @@ public: slot_cone = cone; } + /** + * @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 -- cgit v1.2.3