cppcheck
This commit is contained in:
@@ -22,6 +22,8 @@ static animatedSprite_t parseAnimationStream(std::istream &file, Texture *textur
|
||||
while (std::getline(file, line)) {
|
||||
if (line == "[animation]") {
|
||||
animation_t buffer;
|
||||
buffer.speed = 0;
|
||||
buffer.loop = -1;
|
||||
buffer.counter = 0;
|
||||
buffer.currentFrame = 0;
|
||||
buffer.completed = false;
|
||||
@@ -82,7 +84,7 @@ static animatedSprite_t parseAnimationStream(std::istream &file, Texture *textur
|
||||
}
|
||||
|
||||
// Carga la animación desde un fichero
|
||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose) {
|
||||
animatedSprite_t loadAnimationFromFile(Texture *texture, const std::string &filePath, bool verbose) {
|
||||
const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1);
|
||||
std::ifstream file(filePath);
|
||||
if (!file.good()) {
|
||||
@@ -109,42 +111,34 @@ animatedSprite_t loadAnimationFromMemory(Texture *texture, const std::vector<uin
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, std::string file, std::vector<std::string> *buffer) {
|
||||
AnimatedSprite::AnimatedSprite(Texture *texture, SDL_Renderer *renderer, const std::string &file, std::vector<std::string> *buffer)
|
||||
: currentAnimation(0) {
|
||||
// Copia los punteros
|
||||
setTexture(texture);
|
||||
setRenderer(renderer);
|
||||
|
||||
// Carga las animaciones
|
||||
if (file != "") {
|
||||
if (!file.empty()) {
|
||||
animatedSprite_t as = loadAnimationFromFile(texture, file);
|
||||
|
||||
// Copia los datos de las animaciones
|
||||
for (auto animation : as.animations) {
|
||||
this->animation.push_back(animation);
|
||||
}
|
||||
animation.insert(animation.end(), as.animations.begin(), as.animations.end());
|
||||
}
|
||||
|
||||
else if (buffer) {
|
||||
loadFromVector(buffer);
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
currentAnimation = 0;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation) {
|
||||
AnimatedSprite::AnimatedSprite(SDL_Renderer *renderer, animatedSprite_t *animation)
|
||||
: currentAnimation(0) {
|
||||
// Copia los punteros
|
||||
setTexture(animation->texture);
|
||||
setRenderer(renderer);
|
||||
|
||||
// Inicializa variables
|
||||
currentAnimation = 0;
|
||||
|
||||
// Copia los datos de las animaciones
|
||||
for (auto a : animation->animations) {
|
||||
this->animation.push_back(a);
|
||||
}
|
||||
this->animation.insert(this->animation.end(), animation->animations.begin(), animation->animations.end());
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -156,10 +150,10 @@ AnimatedSprite::~AnimatedSprite() {
|
||||
}
|
||||
|
||||
// Obtiene el indice de la animación a partir del nombre
|
||||
int AnimatedSprite::getIndex(std::string name) {
|
||||
int AnimatedSprite::getIndex(const std::string &name) {
|
||||
int index = -1;
|
||||
|
||||
for (auto a : animation) {
|
||||
for (const auto &a : animation) {
|
||||
index++;
|
||||
if (a.name == name) {
|
||||
return index;
|
||||
@@ -222,12 +216,12 @@ void AnimatedSprite::setCurrentFrame(int num) {
|
||||
}
|
||||
|
||||
// Establece el valor del contador
|
||||
void AnimatedSprite::setAnimationCounter(std::string name, int num) {
|
||||
void AnimatedSprite::setAnimationCounter(const std::string &name, int num) {
|
||||
animation[getIndex(name)].counter = num;
|
||||
}
|
||||
|
||||
// Establece la velocidad de una animación
|
||||
void AnimatedSprite::setAnimationSpeed(std::string name, int speed) {
|
||||
void AnimatedSprite::setAnimationSpeed(const std::string &name, int speed) {
|
||||
animation[getIndex(name)].counter = speed;
|
||||
}
|
||||
|
||||
@@ -237,7 +231,7 @@ void AnimatedSprite::setAnimationSpeed(int index, int speed) {
|
||||
}
|
||||
|
||||
// Establece si la animación se reproduce en bucle
|
||||
void AnimatedSprite::setAnimationLoop(std::string name, int loop) {
|
||||
void AnimatedSprite::setAnimationLoop(const std::string &name, int loop) {
|
||||
animation[getIndex(name)].loop = loop;
|
||||
}
|
||||
|
||||
@@ -247,7 +241,7 @@ void AnimatedSprite::setAnimationLoop(int index, int loop) {
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void AnimatedSprite::setAnimationCompleted(std::string name, bool value) {
|
||||
void AnimatedSprite::setAnimationCompleted(const std::string &name, bool value) {
|
||||
animation[getIndex(name)].completed = value;
|
||||
}
|
||||
|
||||
@@ -262,7 +256,7 @@ bool AnimatedSprite::animationIsCompleted() {
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo de una animación y frame concreto
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index) {
|
||||
SDL_Rect AnimatedSprite::getAnimationClip(const std::string &name, Uint8 index) {
|
||||
return animation[getIndex(name)].frames[index];
|
||||
}
|
||||
|
||||
@@ -292,6 +286,8 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source) {
|
||||
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
|
||||
if (line == "[animation]") {
|
||||
animation_t buffer;
|
||||
buffer.speed = 0;
|
||||
buffer.loop = -1;
|
||||
buffer.counter = 0;
|
||||
buffer.currentFrame = 0;
|
||||
buffer.completed = false;
|
||||
@@ -391,7 +387,7 @@ bool AnimatedSprite::loadFromVector(std::vector<std::string> *source) {
|
||||
}
|
||||
|
||||
// Establece la animacion actual
|
||||
void AnimatedSprite::setCurrentAnimation(std::string name) {
|
||||
void AnimatedSprite::setCurrentAnimation(const std::string &name) {
|
||||
const int newAnimation = getIndex(name);
|
||||
if (currentAnimation != newAnimation) {
|
||||
currentAnimation = newAnimation;
|
||||
|
||||
Reference in New Issue
Block a user