Unit/Animation: emplace_back (mostly) ahoy

Three cases could not use emplace_back since the ctor they use is private... :(
Which sucks since unit_animation looks like it'd be a bit expensive to copy.
This commit is contained in:
Charles Dang 2018-04-24 14:56:54 +11:00
parent b6f412fba1
commit 0cdcfac5d3

View file

@ -183,7 +183,7 @@ static void prepare_single_animation(const config& anim_cfg, animation_branches&
* etc. individually (so 2 instances of 'frame' would be stored as 2 children).
*/
std::list<animation_cursor> anim_cursors;
anim_cursors.push_back(animation_cursor(anim_cfg));
anim_cursors.emplace_back(anim_cfg);
while(!anim_cursors.empty()) {
animation_cursor& ac = anim_cursors.back();
@ -212,7 +212,7 @@ static void prepare_single_animation(const config& anim_cfg, animation_branches&
do {
// Copies the current branches to each cursor created for the conditional clauses.
// Merge attributes of the clause into them.
anim_cursors.push_back(animation_cursor(ac.itors.front().cfg, &ac));
anim_cursors.emplace_back(ac.itors.front().cfg, &ac);
ac.itors.pop_front();
++count;
} while (!ac.itors.empty() && ac.itors.front().key == "else");
@ -555,14 +555,12 @@ void unit_animation::fill_initial_animations(std::vector<unit_animation>& animat
animations.push_back(base);
animations.back().event_ = { "attack" };
animations.back().unit_anim_.override(-150, 300, particle::NO_CYCLE, "", "", {0,0,0}, "0~0.6:150,0.6~0:150", std::to_string(drawing_queue::LAYER_UNIT_MOVE_DEFAULT-drawing_queue::LAYER_UNIT_FIRST));
animations.back().primary_attack_filter_.push_back(config());
animations.back().primary_attack_filter_.back()["range"] = "melee";
animations.back().primary_attack_filter_.emplace_back("range", "melee");
animations.push_back(base);
animations.back().event_ = { "attack" };
animations.back().unit_anim_.override(-150, 150, particle::NO_CYCLE);
animations.back().primary_attack_filter_.push_back(config());
animations.back().primary_attack_filter_.back()["range"] = "ranged";
animations.back().primary_attack_filter_.emplace_back("range", "ranged");
animations.push_back(base);
animations.back().event_ = { "death" };
@ -618,14 +616,14 @@ static void add_simple_anim(std::vector<unit_animation>& animations,
config::attribute_value& v = anim["layer"];
if(v.empty()) v = layer - drawing_queue::LAYER_UNIT_FIRST;
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
}
}
void unit_animation::add_anims( std::vector<unit_animation> & animations, const config & cfg)
{
for(const animation_branch& ab : prepare_animation(cfg, "animation")) {
animations.push_back(unit_animation(ab.merge()));
animations.emplace_back(ab.merge());
}
const int default_layer = drawing_queue::LAYER_UNIT_DEFAULT - drawing_queue::LAYER_UNIT_FIRST;
@ -662,7 +660,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["offscreen"] = false;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
}
// Standing animations are also used as default animations
@ -687,7 +685,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["offscreen"] = false;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
}
for(const animation_branch& ab : prepare_animation(cfg, "healing_anim")) {
@ -699,7 +697,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["layer"] = default_layer;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
}
for(const animation_branch& ab : prepare_animation(cfg, "healed_anim")) {
@ -711,7 +709,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["layer"] = default_layer;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
animations.back().sub_anims_["_healed_sound"] = particle();
const std::string healed_sound = get_heal_sound(cfg);
@ -727,7 +725,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["layer"] = default_layer;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
animations.back().sub_anims_["_poison_sound"] = particle();
animations.back().sub_anims_["_poison_sound"].add_frame(1,frame_builder().sound(game_config::sounds::status::poisoned),true);
}
@ -746,7 +744,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["layer"] = move_layer;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
}
add_simple_anim(animations, cfg, "post_movement_anim", "post_movement", drawing_queue::LAYER_UNIT_MOVE_DEFAULT);
@ -765,11 +763,11 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
if(anim["hits"].empty()) {
anim["hits"] = false;
animations.push_back(unit_animation(anim));
animations.back().base_score_--; //so default doesn't interefere with 'if' block
animations.emplace_back(anim);
animations.back().base_score_--; //so default doesn't interfere with 'if' block
anim["hits"] = true;
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
animations.back().base_score_--;
image::locator image_loc = animations.back().get_last_frame().end_parameters().image;
@ -782,7 +780,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
config tmp = anim;
tmp["hits"] = hit_type;
animations.push_back(unit_animation(tmp));
animations.emplace_back(tmp);
image::locator image_loc = animations.back().get_last_frame().end_parameters().image;
if(hit_type == "yes" || hit_type == "hit" || hit_type=="kill") {
@ -827,7 +825,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim.add_child_at("missile_frame", tmp, 0);
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
}
for(const animation_branch& ab : prepare_animation(cfg, "death")) {
@ -838,7 +836,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["layer"] = default_layer;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
image::locator image_loc = animations.back().get_last_frame().end_parameters().image;
animations.back().add_frame(600, frame_builder()
@ -862,7 +860,7 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
anim["layer"] = default_layer;
}
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
}
for(const animation_branch& ab : prepare_animation(cfg, "teleport_anim")) {
@ -872,11 +870,11 @@ void unit_animation::add_anims( std::vector<unit_animation> & animations, const
}
anim["apply_to"] = "pre_teleport";
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
animations.back().unit_anim_.set_end_time(0);
anim["apply_to"] ="post_teleport";
animations.push_back(unit_animation(anim));
animations.emplace_back(anim);
animations.back().unit_anim_.remove_frames_until(0);
}
}
@ -1325,7 +1323,7 @@ void unit_animator::replace_anim_if_invalid(const unit* animated_unit
tmp.with_bars= with_bars;
tmp.animation = nullptr;
animated_units_.push_back(tmp);
animated_units_.push_back(std::move(tmp));
} else {
add_animation(animated_unit,event,src,dst,value,with_bars,text,text_color,hit_type,attack,second_attack,value2);
}