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/model/mapfile.cc | 68 ++++++++++------------- src/model/model.cc | 26 +++------ src/model/model.h | 33 ++++-------- src/model/tags.cc | 52 +++++++----------- src/model/tags.h | 148 ++++++++++++++++++--------------------------------- 5 files changed, 116 insertions(+), 211 deletions(-) (limited to 'src/model') diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 49122d5..3a8aa40 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -1429,13 +1429,12 @@ Model * MapFile::load(std::string const &name) Model *model = new Model(name); mapfile.clear_bbox(); - Dock *tag_dock = 0; + Slot *tag_slot = 0; Particles *tag_particles = 0; Flare *tag_flare = 0; Light *tag_light = 0; SubModel *tag_submodel = 0; Sound *tag_sound = 0; - Weapon *tag_weapon = 0; std::string modelname; math::Vector3f location; @@ -1820,25 +1819,25 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_classname("location_dock")) { // new docking location - tag_dock = new Dock(); - model->add_dock(tag_dock); + tag_slot = new Slot(Slot::Dock); + model->add_slot(tag_slot); } else if (mapfile.classname().compare("location_dock") == 0) { // dock attributes - if (mapfile.got_key_axis(tag_dock->get_axis())) { + if (mapfile.got_key_axis(tag_slot->get_axis())) { continue; } else if (mapfile.got_key_vector3f("origin", location)) { - tag_dock->get_location().assign(location * SCALE); + tag_slot->get_location().assign(location * SCALE); continue; } else if (mapfile.got_key_float("radius", r)) { - tag_dock->set_radius(r * SCALE); + tag_slot->set_radius(r * SCALE); continue; } else if (mapfile.got_key_string("info", str)) { - tag_dock->set_info(str); + tag_slot->set_info(str); } else if (mapfile.got_key()) { mapfile.unknown_key(); @@ -1848,26 +1847,26 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_classname("location_cannon")) { // new cannon slot - tag_weapon = new Weapon(Weapon::Cannon); - model->add_weapon(tag_weapon); + tag_slot = new Slot(Slot::Cannon); + model->add_slot(tag_slot); continue; } else if (mapfile.classname().compare("location_cannon") == 0) { // cannon options - if (mapfile.got_key_axis(tag_weapon->get_axis())) { + if (mapfile.got_key_axis(tag_slot->get_axis())) { continue; } else if (mapfile.got_key_vector3f("origin", location)) { - tag_weapon->get_location().assign(location * SCALE); + tag_slot->get_location().assign(location * SCALE); continue; } else if (mapfile.got_key_float("cone", r)) { - tag_weapon->set_cone(r); + tag_slot->set_cone(r); continue; } else if (mapfile.got_key_string("info", str)) { - tag_weapon->set_info(str); + tag_slot->set_info(str); } else if (mapfile.got_key()) { mapfile.unknown_key(); @@ -1878,26 +1877,26 @@ Model * MapFile::load(std::string const &name) } else if (mapfile.got_classname("location_turret")) { // new turret slot - tag_weapon = new Weapon(Weapon::Turret); - model->add_weapon(tag_weapon); + tag_slot = new Slot(Slot::Turret); + model->add_slot(tag_slot); continue; } else if (mapfile.classname().compare("location_turret") == 0) { // turret options - if (mapfile.got_key_axis(tag_weapon->get_axis())) { + if (mapfile.got_key_axis(tag_slot->get_axis())) { continue; } else if (mapfile.got_key_vector3f("origin", location)) { - tag_weapon->get_location().assign(location * SCALE); + tag_slot->get_location().assign(location * SCALE); continue; } else if (mapfile.got_key_float("cone", r)) { - tag_weapon->set_cone(r); + tag_slot->set_cone(r); continue; } else if (mapfile.got_key_string("info", str)) { - tag_weapon->set_info(str); + tag_slot->set_info(str); } else if (mapfile.got_key()) { mapfile.unknown_key(); @@ -2048,21 +2047,12 @@ Model * MapFile::load(std::string const &name) model->add_sound(tag_sound); } - // copy dock tags - for (Model::Docks::const_iterator dit = submodel_model->docks().begin(); dit != submodel_model->docks().end(); ++dit) { - tag_dock = new Dock(*(*dit)); - tag_dock->get_location().assign(tag_submodel->location() + tag_submodel->axis() * (tag_dock->location() - submodel_model->origin()) * tag_submodel->scale()); - model->add_dock(tag_dock); + // copy slot tags + for (Model::Slots::const_iterator slit = submodel_model->slots().begin(); slit != submodel_model->slots().end(); ++slit) { + tag_slot = new Slot(*(*slit)); + tag_slot->get_location().assign(tag_submodel->location() + tag_submodel->axis() * (tag_slot->location() - submodel_model->origin()) * tag_submodel->scale()); + model->add_slot(tag_slot); } - - // copy weapon tags - for (Model::Weapons::const_iterator wit = submodel_model->weapons().begin(); wit != submodel_model->weapons().end(); ++wit) { - tag_weapon = new Weapon(*(*wit)); - tag_weapon->get_location().assign(tag_submodel->location() + tag_submodel->axis() * (tag_weapon->location() - submodel_model->origin()) * tag_submodel->scale()); - model->add_weapon(tag_weapon); - } - - } delete tag_submodel; @@ -2124,14 +2114,10 @@ Model * MapFile::load(std::string const &name) (*sit)->get_location() -= map_center; } - for (Model::Docks::iterator dit = model->docks().begin(); dit != model->docks().end(); ++dit) { - (*dit)->get_location() -= map_center; + for (Model::Slots::iterator slit = model->slots().begin(); slit != model->slots().end(); ++slit) { + (*slit)->get_location() -= map_center; } - - for (Model::Weapons::iterator wit = model->weapons().begin(); wit != model->weapons().end(); ++wit) { - (*wit)->get_location() -= map_center; - } - + if (mapfile.warning_q2brush) con_warn << mapfile.name() << " quake2 style brushes detected" << std::endl; diff --git a/src/model/model.cc b/src/model/model.cc index fdff22e..e98a251 100644 --- a/src/model/model.cc +++ b/src/model/model.cc @@ -43,11 +43,11 @@ Model::~Model() } model_groups.clear(); - // delete all docks - for (Docks::iterator dit = model_docks.begin(); dit != model_docks.end(); ++dit) { - delete(*dit); + // delete all slots + for (Slots::iterator slit = model_slots.begin(); slit != model_slots.end(); ++slit) { + delete(*slit); } - model_docks.clear(); + model_slots.clear(); // delete all particle systems for (Model::ParticleSystems::iterator pit = model_particles.begin(); pit != model_particles.end(); ++pit) { @@ -72,12 +72,6 @@ Model::~Model() delete (*sit); } model_sounds.clear(); - - // delete all weapon tags - for (Weapons::iterator wit = model_weapons.begin(); wit != model_weapons.end(); ++wit) { - delete (*wit); - } - model_weapons.clear(); } void Model::set_collisionmodel(CollisionModel *collisionmodel) @@ -120,14 +114,9 @@ void Model::add_sound(Sound *sound) model_sounds.push_back(sound); } -void Model::add_dock(Dock *dock) -{ - model_docks.push_back(dock); -} - -void Model::add_weapon(Weapon *weapon) +void Model::add_slot(Slot *slot) { - model_weapons.push_back(weapon); + model_slots.push_back(slot); } void Model::print() const @@ -193,8 +182,7 @@ bool compare_tag_location_front(const Tag *first, const Tag *second) } void Model::sort() { - model_weapons.sort(compare_tag_location); - model_docks.sort(compare_tag_location_front); + model_slots.sort(compare_tag_location_front); model_particles.sort(compare_tag_location); model_lights.sort(compare_tag_location); diff --git a/src/model/model.h b/src/model/model.h index 4d72793..3e6bd2d 100644 --- a/src/model/model.h +++ b/src/model/model.h @@ -43,8 +43,8 @@ public: /// type definition for a list of model flare tags typedef std::list Flares; - /// type definition for a list of model dock tags - typedef std::list Docks; + /// type definition for a list of model slot tags + typedef std::list Slots; /// type definition for a list of model particle system tags typedef std::list ParticleSystems; @@ -52,9 +52,6 @@ public: /// type definition for a list of model sound tags typedef std::list Sounds; - /// type definition for a list of model weapon tags - typedef std::list Weapons; - /// type definition for a list of FragmentGroups typedef std::list Groups; @@ -92,9 +89,9 @@ public: return model_lights; } - /// list of model dock tags - inline Docks & docks() { - return model_docks; + /// list of model slot tags + inline Slots & slots() { + return model_slots; } /// list of model flare tags @@ -107,11 +104,6 @@ public: return model_sounds; } - /// list of model weapon tags - inline Weapons & weapons() { - return model_weapons; - } - /// list of model particle system tags inline ParticleSystems & particles() { return model_particles; @@ -150,12 +142,9 @@ public: /// add a flare tag to the model void add_flare(Flare *flare); - /// add a docking location tag to the model - void add_dock(Dock *dock); + /// add a slot tag to the model + void add_slot(Slot *slot); - /// add a weapon slot tag to the model - void add_weapon(Weapon *weapon); - /// add a sound tag to the model void add_sound(Sound *sound); @@ -220,16 +209,16 @@ private: void sort(); std::string model_name; - Docks model_docks; + Slots model_slots; Flares model_flares; Sounds model_sounds; Lights model_lights; ParticleSystems model_particles; - Weapons model_weapons; Groups model_groups; - float model_radius; - static Registry model_registry; + float model_radius; CollisionModel *model_collisionmodel; + + static Registry model_registry; }; } diff --git a/src/model/tags.cc b/src/model/tags.cc index 7e5a393..f755373 100644 --- a/src/model/tags.cc +++ b/src/model/tags.cc @@ -121,23 +121,6 @@ Particles::~Particles() { } -/* ---- class Dock ------------------------------------------------- */ - -Dock::Dock() : Tag() -{ - dock_radius = 0.01f; -} - -Dock::Dock(const Dock& other) : Tag(other) -{ - dock_radius = other.radius(); - dock_axis.assign(other.axis()); -} - -Dock::~Dock() -{ -} - /* ---- class Sound ------------------------------------------------- */ Sound::Sound() : Tag() @@ -153,36 +136,41 @@ Sound::~Sound() { } -/* ---- class Dock ------------------------------------------------- */ +/* ---- class Slot ------------------------------------------------- */ -Weapon::Weapon(const Type type) : Tag() -{ +Slot::Slot(const Type type) : Tag() +{ + slot_radius = 0.0f; set_type(type); + } -Weapon::Weapon(const Weapon& other) : Tag(other) +Slot::Slot(const Slot& other) : Tag(other) { - weapon_type = other.type(); - weapon_cone = other.cone(); - weapon_axis.assign(other.axis()); + slot_type = other.type(); + slot_axis.assign(other.axis()); + slot_radius = other.radius(); + slot_cone = other.cone(); + } -Weapon::~Weapon() +Slot::~Slot() { } -void Weapon::set_type(const Type type) +void Slot::set_type(const Type type) { - weapon_type = type; - switch (weapon_type) { - case Unmountable: - weapon_cone = 0.0f; + slot_type = type; + switch (slot_type) { + case None: + case Dock: + slot_cone = 0.0f; break; case Cannon: - weapon_cone = 60.0f; // 60 degrees + slot_cone = 60.0f; // 60 degrees break; case Turret: - weapon_cone = 180.0f; // 180 degrees + slot_cone = 180.0f; // 180 degrees break; } } diff --git a/src/model/tags.h b/src/model/tags.h index 5be7576..775dc73 100644 --- a/src/model/tags.h +++ b/src/model/tags.h @@ -546,74 +546,6 @@ private: std::string particles_script; }; -/* ---- class Dock ------------------------------------------------- */ - -/// a docking location tag -class Dock : public Tag -{ -public: - /** - * @brief default constructor - * */ - Dock(); - - /** - * @brief copy constructor - * */ - Dock(const Dock& other); - - /** - * @brief destructor - * */ - ~Dock(); - - /* ---- inspectors ----------------------------------------- */ - - /** - * @brief dock radius, default is 0.01f - * */ - inline float radius() const - { - return dock_radius; - } - - inline const math::Axis &axis() const - { - return dock_axis; - } - - /* ---- mutators ------------------------------------------- */ - - /** - * @brief set dock radius - * */ - inline void set_radius(const float radius) - { - dock_radius = radius; - } - - /** - * @brief set dock axis - * */ - inline void set_axis(const math::Axis& axis) - { - dock_axis.assign(axis); - } - - /* ---- actors --------------------------------------------- */ - - /** - * @brief mutable reference to the axis - * */ - inline math::Axis& get_axis() { - return dock_axis; - } - -private: - float dock_radius; - math::Axis dock_axis; -}; - /* ---- class Sound ------------------------------------------------ */ /** @@ -711,89 +643,111 @@ private: math::Axis submodel_axis; }; -/* ---- class Weapon ----------------------------------------------- */ +/* ---- class Slot ------------------------------------------------- */ /** - * @brief a weapon slot tag + * @brief a slot tag + * A slot tag can be a cannon, turret or a dock. + * Unlike visual effects like lights and flares. slots get copied into entity space. * */ -class Weapon : public Tag +class Slot : public Tag { public: - enum Type {Unmountable = 0, Cannon = 1, Turret = 2 }; + enum Type {None = 0, Cannon = 1, Turret = 2, Dock = 3}; /** * @brief default constructor * */ - Weapon(const Type type = Cannon); + Slot(const Type type = None); /** * @brief copy constructor * */ - Weapon(const Weapon& other); + Slot(const Slot& other); /** * @brief destructor * */ - ~Weapon(); + ~Slot(); /* ---- inspectors ----------------------------------------- */ - inline const math::Axis &axis() const { - return weapon_axis; + /** + * @brief slot type + * */ + inline const Type type() const + { + return slot_type; } /** - * @brief weapon fire cone, in degrees + * @brief slot orientation within the parent model * */ - inline float cone() const - { - return weapon_cone; + inline const math::Axis &axis() const { + return slot_axis; } /** - * @brief weapon slot type + * @brief slot radius, used by Dock slots * */ - inline const Type type() const + inline float radius() const { - return weapon_type; + return slot_radius; } + /** + * @brief slot fire cone, in degrees, used by Turret and Cannon slots. + * */ + inline float cone() const + { + return slot_cone; + } + /* ---- mutators ------------------------------------------- */ /** - * @brief set weapon fire cone, in degrees + * @brief set slot type * */ - inline void set_cone(const float cone) - { - weapon_cone = cone; - } + void set_type(const Type type); /** - * @brief set weapon slot axis + * @brief set slot axis * */ inline void set_axis(const math::Axis& axis) { - weapon_axis.assign(axis); + slot_axis.assign(axis); } /** - * @brief set weapon slot type + * @brief set slot radius * */ -; void set_type(const Type type); + inline void set_radius(const float radius) + { + slot_radius = radius; + } + /** + * @brief set slot fire cone, in degrees + * */ + inline void set_cone(const float cone) + { + slot_cone = cone; + } + /* ---- actors --------------------------------------------- */ /** * @brief mutable reference to the axis * */ inline math::Axis& get_axis() { - return weapon_axis; + return slot_axis; } private: - Type weapon_type; - math::Axis weapon_axis; - float weapon_cone; + Type slot_type; + math::Axis slot_axis; + float slot_radius; + float slot_cone; }; -- cgit v1.2.3