Skip to content

Commit

Permalink
Animation: pass std::string by copy and move, pass fge::anim::Animati…
Browse files Browse the repository at this point in the history
…onDataPtr by copy and move
  • Loading branch information
JonathSpirit committed Dec 28, 2023
1 parent ac2e1d5 commit 823b381
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions includes/FastEngine/C_animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class FGE_API Animation
* \param name The name of the animation
* \param frame The beginning frame of the animation
*/
Animation(std::string const& name, std::size_t frame = 0); ///TODO: use string_view ?
Animation(std::string name, std::size_t frame = 0); ///TODO: use string_view ?
/**
* \brief Constructor that takes the name of the animation and the group name
*
Expand All @@ -61,12 +61,12 @@ class FGE_API Animation
* \param group The name of the group
* \param frame The beginning frame of the animation
*/
Animation(std::string const& name, std::string const& group, std::size_t frame = 0);
Animation(std::string name, std::string const& group, std::size_t frame = 0);
Animation(char const* name, std::size_t frame = 0);
Animation(char const* name, char const* group, std::size_t frame = 0);
Animation(fge::anim::AnimationDataPtr const& data, std::size_t frame = 0);
Animation(fge::anim::AnimationDataPtr const& data, std::string const& group, std::size_t frame = 0);
Animation(fge::anim::AnimationDataPtr const& data, char const* group, std::size_t frame = 0);
Animation(fge::anim::AnimationDataPtr data, std::size_t frame = 0);
Animation(fge::anim::AnimationDataPtr data, std::string const& group, std::size_t frame = 0);
Animation(fge::anim::AnimationDataPtr data, char const* group, std::size_t frame = 0);

/**
* \brief Clear the animation
Expand Down Expand Up @@ -221,9 +221,9 @@ class FGE_API Animation
*/
[[nodiscard]] fge::anim::AnimationDataPtr const& getData() const;

fge::Animation& operator=(std::string const& name);
fge::Animation& operator=(std::string name);
fge::Animation& operator=(char const* name);
fge::Animation& operator=(fge::anim::AnimationDataPtr const& data);
fge::Animation& operator=(fge::anim::AnimationDataPtr data);

/**
* \brief Retrieve the texture of the actual frame
Expand Down
34 changes: 17 additions & 17 deletions sources/C_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ Animation::Animation() :
g_loop(false),
g_reverse(false)
{}
Animation::Animation(std::string const& name, std::size_t frame) :
Animation::Animation(std::string name, std::size_t frame) :
g_data(fge::anim::GetAnimation(name)),
g_name(name),
g_name(std::move(name)),

g_groupIndex(0),
g_frameIndex(frame),

g_loop(false),
g_reverse(false)
{}
Animation::Animation(std::string const& name, std::string const& group, std::size_t frame) :
Animation::Animation(std::string name, std::string const& group, std::size_t frame) :
g_data(fge::anim::GetAnimation(name)),
g_name(name),
g_name(std::move(name)),

g_groupIndex(0),
g_frameIndex(frame),
Expand Down Expand Up @@ -73,10 +73,10 @@ Animation::Animation(char const* name, char const* group, std::size_t frame) :
g_loop(false),
g_reverse(false)
{
this->setGroup(std::string(group));
this->setGroup(std::string{group});
}
Animation::Animation(fge::anim::AnimationDataPtr const& data, std::size_t frame) :
g_data(data),
Animation::Animation(fge::anim::AnimationDataPtr data, std::size_t frame) :
g_data(std::move(data)),
g_name(FGE_ANIM_BAD),

g_groupIndex(0),
Expand All @@ -85,8 +85,8 @@ Animation::Animation(fge::anim::AnimationDataPtr const& data, std::size_t frame)
g_loop(false),
g_reverse(false)
{}
Animation::Animation(fge::anim::AnimationDataPtr const& data, std::string const& group, std::size_t frame) :
g_data(data),
Animation::Animation(fge::anim::AnimationDataPtr data, std::string const& group, std::size_t frame) :
g_data(std::move(data)),
g_name(FGE_ANIM_BAD),

g_groupIndex(0),
Expand All @@ -97,8 +97,8 @@ Animation::Animation(fge::anim::AnimationDataPtr const& data, std::string const&
{
this->setGroup(group);
}
Animation::Animation(fge::anim::AnimationDataPtr const& data, char const* group, std::size_t frame) :
g_data(data),
Animation::Animation(fge::anim::AnimationDataPtr data, char const* group, std::size_t frame) :
g_data(std::move(data)),
g_name(FGE_ANIM_BAD),

g_groupIndex(0),
Expand All @@ -107,7 +107,7 @@ Animation::Animation(fge::anim::AnimationDataPtr const& data, char const* group,
g_loop(false),
g_reverse(false)
{
this->setGroup(std::string(group));
this->setGroup(std::string{group});
}

void Animation::clear()
Expand Down Expand Up @@ -357,22 +357,22 @@ fge::anim::AnimationDataPtr const& Animation::getData() const
return this->g_data;
}

fge::Animation& Animation::operator=(std::string const& name)
fge::Animation& Animation::operator=(std::string name)
{
this->g_name = name;
this->g_name = std::move(name);
this->g_data = fge::anim::GetAnimation(name);
return *this;
}
fge::Animation& Animation::operator=(char const* name)
{
this->g_name = std::string(name);
this->g_name = std::string{name};
this->g_data = fge::anim::GetAnimation(this->g_name);
return *this;
}
fge::Animation& Animation::operator=(fge::anim::AnimationDataPtr const& data)
fge::Animation& Animation::operator=(fge::anim::AnimationDataPtr data)
{
this->g_name = FGE_ANIM_BAD;
this->g_data = data;
this->g_data = std::move(data);
return *this;
}

Expand Down

0 comments on commit 823b381

Please sign in to comment.