mail[Wesnoth-commits] r20162 - in /trunk/src: unit.cpp unit_types.cpp unit_types.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on September 07, 2007 - 08:46:
Author: alink
Date: Fri Sep  7 08:46:25 2007
New Revision: 20162

URL: http://svn.gna.org/viewcvs/wesnoth?rev=20162&view=rev
Log:
Quick fix to a design flaw in attack_type code impacting performance:
This make the help opens ~5 times faster and speed up some AI operations.
(the creation of the "little" attack_type object also generated a lot of 
animations data, which are useless for non-display functions (AI, help...)
And these attack_type are not cached in unit_type, like we do for unit)

Modified:
    trunk/src/unit.cpp
    trunk/src/unit_types.cpp
    trunk/src/unit_types.hpp

Modified: trunk/src/unit.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit.cpp?rev=20162&r1=20161&r2=20162&view=diff
==============================================================================
--- trunk/src/unit.cpp (original)
+++ trunk/src/unit.cpp Fri Sep  7 08:46:25 2007
@@ -494,7 +494,7 @@
        max_hit_points_ = t->hitpoints();
        max_movement_ = t->movement();
        emit_zoc_ = t->level();
-       attacks_ = t->attacks();
+       attacks_ = t->attacks(true);
        unit_value_ = t->cost();
        flying_ = t->movement_type().is_flying();
 

Modified: trunk/src/unit_types.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.cpp?rev=20162&r1=20161&r2=20162&view=diff
==============================================================================
--- trunk/src/unit_types.cpp (original)
+++ trunk/src/unit_types.cpp Fri Sep  7 08:46:25 2007
@@ -53,7 +53,7 @@
        return id;
 }
 
-attack_type::attack_type(const config& cfg,const std::string& id, const 
std::string& image_fighting)
+attack_type::attack_type(const config& cfg,const std::string& id, const 
std::string& image_fighting, bool with_animations)
 {
        cfg_ = cfg;
        if(cfg["range"] == "long" || cfg["range"] == "ranged") {
@@ -61,23 +61,25 @@
        } else {
                range_type_ = SHORT_RANGE;
        }
-       const config expanded_cfg = 
unit_animation::prepare_animation(cfg,"animation");
-       const config::child_list& animations = 
expanded_cfg.get_children("animation");
-       for(config::child_list::const_iterator d = animations.begin(); d != 
animations.end(); ++d) {
-               animation_.push_back(attack_animation(**d));
-       }
-
-       if(cfg.child("frame") || cfg.child("missile_frame") || 
cfg.child("sound")) {
-               LOG_STREAM(err, config) << "the animation for " << 
cfg["name"] << "in unit " << id
-                                                               << " is 
directly in the attack, please use [animation]\n" ;
-       }
-       if(animation_.empty()) {
-               animation_.push_back(attack_animation(cfg));
-       }
-       if(animation_.empty()) {
-               
animation_.push_back(attack_animation(-200,unit_frame(image_fighting,300)));
-       }
-       assert(!animation_.empty());
+       if (with_animations) {
+               const config expanded_cfg = 
unit_animation::prepare_animation(cfg,"animation");
+               const config::child_list& animations = 
expanded_cfg.get_children("animation");
+               for(config::child_list::const_iterator d = 
animations.begin(); d != animations.end(); ++d) {
+                       animation_.push_back(attack_animation(**d));
+               }
+
+               if(cfg.child("frame") || cfg.child("missile_frame") || 
cfg.child("sound")) {
+                       LOG_STREAM(err, config) << "the animation for " << 
cfg["name"] << "in unit " << id
+                                                                       << " 
is directly in the attack, please use [animation]\n" ;
+               }
+               if(animation_.empty()) {
+                       animation_.push_back(attack_animation(cfg));
+               }
+               if(animation_.empty()) {
+                       
animation_.push_back(attack_animation(-200,unit_frame(image_fighting,300)));
+               }
+               assert(!animation_.empty());
+       }
 
        id_ = unit_id_test(cfg["name"]);
        description_ = cfg["description"];
@@ -921,12 +923,12 @@
 }
 
 
-std::vector<attack_type> unit_type::attacks() const
+std::vector<attack_type> unit_type::attacks(bool with_animations) const
 {
        std::vector<attack_type> res;
        for(config::const_child_itors range = cfg_.child_range("attack");
            range.first != range.second; ++range.first) {
-               
res.push_back(attack_type(**range.first,id(),image_fighting((**range.first)["range"]
 == "ranged" ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE)));
+               
res.push_back(attack_type(**range.first,id(),image_fighting((**range.first)["range"]
 == "ranged" ? attack_type::LONG_RANGE : attack_type::SHORT_RANGE), 
with_animations));
        }
 
        return res;

Modified: trunk/src/unit_types.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/unit_types.hpp?rev=20162&r1=20161&r2=20162&view=diff
==============================================================================
--- trunk/src/unit_types.hpp (original)
+++ trunk/src/unit_types.hpp Fri Sep  7 08:46:25 2007
@@ -40,7 +40,7 @@
 public:
        enum RANGE { SHORT_RANGE, LONG_RANGE };
 
-       attack_type(const config& cfg, const std::string& id, const 
std::string& image_fighting);
+       attack_type(const config& cfg, const std::string& id, const 
std::string& image_fighting, bool with_animations=true);
        const t_string& name() const { return description_; }
        const std::string& id() const { return id_; }
        const std::string& type() const { return type_; }
@@ -187,7 +187,7 @@
     const std::string& flag_rgb() const { return flag_rgb_; }
 
        int hitpoints() const { return atoi(cfg_["hitpoints"].c_str()); }
-       std::vector<attack_type> attacks() const;
+       std::vector<attack_type> attacks(bool with_animations = false) const;
        const unit_movement_type& movement_type() const { return 
movementType_; }
 
        int experience_needed(bool with_acceleration=true) const;




Related Messages


Powered by MHonArc, Updated Fri Sep 07 09:00:28 2007