diff --git a/cppcheck-result b/cppcheck-result new file mode 100644 index 0000000..b9b6eeb --- /dev/null +++ b/cppcheck-result @@ -0,0 +1,176 @@ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:264:0: style: The function 'getNumFrames' is never used. [unusedFunction] +int AnimatedSprite::getNumFrames() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:270:0: style: The function 'setCurrentFrame' is never used. [unusedFunction] +void AnimatedSprite::setCurrentFrame(int num) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:287:0: style: The function 'setAnimationCounter' is never used. [unusedFunction] +void AnimatedSprite::setAnimationCounter(std::string name, int num) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:293:0: style: The function 'setAnimationSpeed' is never used. [unusedFunction] +void AnimatedSprite::setAnimationSpeed(std::string name, int speed) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:305:0: style: The function 'setAnimationLoop' is never used. [unusedFunction] +void AnimatedSprite::setAnimationLoop(std::string name, int loop) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:317:0: style: The function 'setAnimationCompleted' is never used. [unusedFunction] +void AnimatedSprite::setAnimationCompleted(std::string name, bool value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:335:0: style: The function 'getAnimationClip' is never used. [unusedFunction] +SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:529:0: style: The function 'setAnimationFrames' is never used. [unusedFunction] +void AnimatedSprite::setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.cpp:239:0: style: The function 'setSrcRect' is never used. [unusedFunction] +void Background::setSrcRect(SDL_Rect value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.cpp:245:0: style: The function 'setDstRect' is never used. [unusedFunction] +void Background::setDstRect(SDL_Rect value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:681:0: style: The function 'setBlink' is never used. [unusedFunction] +void Balloon::setBlink(bool value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:687:0: style: The function 'isBlinking' is never used. [unusedFunction] +bool Balloon::isBlinking() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:699:0: style: The function 'isVisible' is never used. [unusedFunction] +bool Balloon::isVisible() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:735:0: style: The function 'getStoppedTimer' is never used. [unusedFunction] +Uint16 Balloon::getStoppedTimer() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1000:0: style: The function 'decBalloonSpeed' is never used. [unusedFunction] +void Game::decBalloonSpeed() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1169:0: style: The function 'popAllBalloons' is never used. [unusedFunction] +void Game::popAllBalloons() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:1226:0: style: The function 'countBalloons' is never used. [unusedFunction] +int Game::countBalloons() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:319:0: style: The function 'checkAnyInput' is never used. [unusedFunction] +bool Input::checkAnyInput(int device, int controller_index) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:498:0: style: The function 'printBindings' is never used. [unusedFunction] +void Input::printBindings(int device, int controller_index) const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:531:0: style: The function 'getIndexByName' is never used. [unusedFunction] +int Input::getIndexByName(std::string name) const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:575:0: style: The function 'to_inputs_e' is never used. [unusedFunction] +InputType Input::to_inputs_e(std::string name) const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:114:0: style: The function 'getZoomW' is never used. [unusedFunction] +float MovingSprite::getZoomW() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:120:0: style: The function 'getZoomH' is never used. [unusedFunction] +float MovingSprite::getZoomH() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:126:0: style: The function 'getAngle' is never used. [unusedFunction] +double MovingSprite::getAngle() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:196:0: style: The function 'setAngle' is never used. [unusedFunction] +void MovingSprite::setAngle(double value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:208:0: style: The function 'decAngle' is never used. [unusedFunction] +void MovingSprite::decAngle(double value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:214:0: style: The function 'getRotate' is never used. [unusedFunction] +bool MovingSprite::getRotate() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:220:0: style: The function 'getRotateSpeed' is never used. [unusedFunction] +Uint16 MovingSprite::getRotateSpeed() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:256:0: style: The function 'disableRotate' is never used. [unusedFunction] +void MovingSprite::disableRotate() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:286:0: style: The function 'flip' is never used. [unusedFunction] +void MovingSprite::flip() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:292:0: style: The function 'getFlip' is never used. [unusedFunction] +SDL_RendererFlip MovingSprite::getFlip() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:414:0: style: The function 'hasDied' is never used. [unusedFunction] +bool Player::hasDied() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:523:0: style: The function 'getStatusPlaying' is never used. [unusedFunction] +PlayerStatus Player::getStatusPlaying() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:535:0: style: The function 'setScoreMultiplier' is never used. [unusedFunction] +void Player::setScoreMultiplier(float value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:568:0: style: The function 'getInvulnerableCounter' is never used. [unusedFunction] +int Player::getInvulnerableCounter() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:574:0: style: The function 'setInvulnerableCounter' is never used. [unusedFunction] +void Player::setInvulnerableCounter(int value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:611:0: style: The function 'getPowerUpCounter' is never used. [unusedFunction] +int Player::getPowerUpCounter() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:617:0: style: The function 'setPowerUpCounter' is never used. [unusedFunction] +void Player::setPowerUpCounter(int value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:666:0: style: The function 'enableInput' is never used. [unusedFunction] +void Player::enableInput() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:672:0: style: The function 'disableInput' is never used. [unusedFunction] +void Player::disableInput() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:697:0: style: The function 'setPlayerTextures' is never used. [unusedFunction] +void Player::setPlayerTextures(std::vector> texture) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:248:0: style: The function 'setWindowSize' is never used. [unusedFunction] +void Screen::setWindowSize(int size) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:271:0: style: The function 'setBorderColor' is never used. [unusedFunction] +void Screen::setBorderColor(Color color) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:55:0: style: The function 'getDestX' is never used. [unusedFunction] +int SmartSprite::getDestX() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:61:0: style: The function 'getDestY' is never used. [unusedFunction] +int SmartSprite::getDestY() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:148:0: style: The function 'isOnDestination' is never used. [unusedFunction] +bool SmartSprite::isOnDestination() const +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.cpp:159:0: style: The function 'incPosY' is never used. [unusedFunction] +void Sprite::incPosY(int value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:264:0: style: The function 'setFixedWidth' is never used. [unusedFunction] +void Text::setFixedWidth(bool value) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:236:0: style: The function 'getSDLTexture' is never used. [unusedFunction] +SDL_Texture *Texture::getSDLTexture() +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:242:0: style: The function 'newSurface' is never used. [unusedFunction] +Surface Texture::newSurface(int w, int h) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:184:0: style: The function 'toLower' is never used. [unusedFunction] +std::string toLower(std::string str) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:200:0: style: The function 'getSound' is never used. [unusedFunction] +JA_Sound_t *getSound(std::vector sounds, std::string name) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:228:0: style: The function 'sortHiScoreTable' is never used. [unusedFunction] +HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:239:0: style: The function 'DrawCircle' is never used. [unusedFunction] +void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:278:0: style: The function 'lightenColor' is never used. [unusedFunction] +Color lightenColor(Color color, int amount) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:288:0: style: The function 'DarkenColor' is never used. [unusedFunction] +Color DarkenColor(Color color, int amount) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:316:0: style: The function 'easeOutQuint' is never used. [unusedFunction] +double easeOutQuint(double t) +^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.cpp:101:0: style: The function 'IsEnabled' is never used. [unusedFunction] +bool Writer::IsEnabled() const +^ +nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs] + diff --git a/cppcheck-result-warning-style-performance b/cppcheck-result-warning-style-performance new file mode 100644 index 0000000..48590d1 --- /dev/null +++ b/cppcheck-result-warning-style-performance @@ -0,0 +1,770 @@ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:14:11: warning: The class 'MovingSprite' defines member variable with name 'x_' also defined in its parent class 'Sprite'. [duplInheritedMember] + float x_; // Posición en el eje X + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:11:9: note: Parent variable 'Sprite::x_' + int x_; // Posición en el eje X donde dibujar el sprite + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:14:11: note: Derived variable 'MovingSprite::x_' + float x_; // Posición en el eje X + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:15:11: warning: The class 'MovingSprite' defines member variable with name 'y_' also defined in its parent class 'Sprite'. [duplInheritedMember] + float y_; // Posición en el eje Y + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:12:9: note: Parent variable 'Sprite::y_' + int y_; // Posición en el eje Y donde dibujar el sprite + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:15:11: note: Derived variable 'MovingSprite::y_' + float y_; // Posición en el eje Y + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:51:10: warning: The class 'MovingSprite' defines member function with name 'render' also defined in its parent class 'Sprite'. [duplInheritedMember] + void render(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:30:10: note: Parent function 'Sprite::render' + void render(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:51:10: note: Derived function 'MovingSprite::render' + void render(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:54:11: warning: The class 'MovingSprite' defines member function with name 'getPosX' also defined in its parent class 'Sprite'. [duplInheritedMember] + float getPosX() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:33:9: note: Parent function 'Sprite::getPosX' + int getPosX() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:54:11: note: Derived function 'MovingSprite::getPosX' + float getPosX() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:55:11: warning: The class 'MovingSprite' defines member function with name 'getPosY' also defined in its parent class 'Sprite'. [duplInheritedMember] + float getPosY() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:34:9: note: Parent function 'Sprite::getPosY' + int getPosY() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:55:11: note: Derived function 'MovingSprite::getPosY' + float getPosY() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:122:14: warning: The class 'MovingSprite' defines member function with name 'getRect' also defined in its parent class 'Sprite'. [duplInheritedMember] + SDL_Rect getRect(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:44:14: note: Parent function 'Sprite::getRect' + SDL_Rect getRect() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:122:14: note: Derived function 'MovingSprite::getRect' + SDL_Rect getRect(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:519:22: warning: The class 'AnimatedSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember] +void AnimatedSprite::update() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:519:22: note: Derived function 'AnimatedSprite::update' +void AnimatedSprite::update() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.h:52:5: style: Class 'Texture' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Texture(SDL_Renderer *renderer, std::string path = ""); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:23:5: style: Class 'Sprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr texture = nullptr); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:24:5: style: Class 'Sprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Sprite(SDL_Rect rect, std::shared_ptr texture = nullptr); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:36:5: style: Class 'MovingSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, std::shared_ptr texture = nullptr); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:40:5: style: Class 'AnimatedSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + AnimatedSprite(std::shared_ptr texture = nullptr, std::string file = "", std::vector *buffer = nullptr); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:41:5: style: Class 'AnimatedSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + AnimatedSprite(AnimatedFile *animation); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:159:78: performance: Function parameter 'file' should be passed by const reference. [passedByValue] +AnimatedSprite::AnimatedSprite(std::shared_ptr texture, std::string file, std::vector *buffer) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:208:42: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +int AnimatedSprite::getIndex(std::string name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:212:12: performance: Range variable 'a' should be declared as const reference. [iterateByValue] + for (auto a : animations_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:287:54: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +void AnimatedSprite::setAnimationCounter(std::string name, int num) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:293:52: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +void AnimatedSprite::setAnimationSpeed(std::string name, int speed) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:305:51: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +void AnimatedSprite::setAnimationLoop(std::string name, int loop) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:317:56: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +void AnimatedSprite::setAnimationCompleted(std::string name, bool value) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:335:55: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +SDL_Rect AnimatedSprite::getAnimationClip(std::string name, Uint8 index) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:493:54: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +void AnimatedSprite::setCurrentAnimation(std::string name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:186:46: style: Parameter 'animation' can be declared as pointer to const [constParameterPointer] +AnimatedSprite::AnimatedSprite(AnimatedFile *animation) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:172:16: style: Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm] + animations_.push_back(animation); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:197:15: style: Consider using std::copy algorithm instead of a raw loop. [useStlAlgorithm] + animations_.push_back(a); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.cpp:18:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:31:5: performance: Variable 'executable_path_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + executable_path_ = executable_path.substr(0, executable_path.find_last_of("\\/")); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.h:48:2: style: Class 'Asset' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Asset(std::string path); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:11:30: performance: Function parameter 'executable_path' should be passed by const reference. [passedByValue] +void Asset::init(std::string executable_path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:29:26: performance: Function parameter 'executable_path' should be passed by const reference. [passedByValue] +Asset::Asset(std::string executable_path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:36:29: performance: Function parameter 'file' should be passed by const reference. [passedByValue] +void Asset::add(std::string file, AssetType type, bool required, bool absolute) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:49:36: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +std::string Asset::get(std::string text) const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:51:15: performance: Range variable 'f' should be declared as const reference. [iterateByValue] + for (auto f : file_list_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:86:19: performance: Range variable 'f' should be declared as const reference. [iterateByValue] + for (auto f : file_list_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:101:23: performance: Range variable 'f' should be declared as const reference. [iterateByValue] + for (auto f : file_list_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:120:35: performance: Function parameter 'path' should be passed by const reference. [passedByValue] +bool Asset::checkFile(std::string path) const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:123:24: style: Variable 'result' is assigned a value that is never used. [unreadVariable] + std::string result = "ERROR"; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:126:33: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = path.substr(path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/asset.cpp:131:16: style: Variable 'result' is assigned a value that is never used. [unreadVariable] + result = "OK"; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.cpp:14:5: performance: Variable 'buildings_texture_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + buildings_texture_ = std::make_shared(renderer, Asset::get()->get("game_buildings.png")); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/background.h:110:3: style: Class 'Background' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Background(SDL_Renderer *renderer); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/balloon.cpp:13:2: performance: Variable 'sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + sprite_ = std::make_unique(texture, "", animation); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:88:10: warning: The class 'AnimatedSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember] + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:88:10: note: Derived function 'AnimatedSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/bullet.cpp:23:5: performance: Variable 'sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + sprite_ = std::make_unique(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/define_buttons.h:49:5: style: Class 'DefineButtons' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + DefineButtons(std::unique_ptr text); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:35:7: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'AnimatedSprite'. [duplInheritedMember] + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:88:10: note: Parent function 'AnimatedSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:35:7: note: Derived function 'SmartSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:35:7: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember] + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:35:7: note: Derived function 'SmartSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/fade.h:57:2: style: Class 'Fade' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Fade(SDL_Renderer *renderer); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.h:26:2: style: Class 'SmartSprite' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + SmartSprite(std::shared_ptr texture); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/hiscore_table.h:73:2: style: Class 'HiScoreTable' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + HiScoreTable(JA_Music_t *music); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/instructions.h:83:2: style: Class 'Instructions' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Instructions(JA_Music_t *music); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.h:30:2: style: Class 'Writer' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Writer(std::shared_ptr text); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/intro.h:55:2: style: Class 'Intro' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Intro(JA_Music_t *music); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.h:27:5: style: Class 'ManageHiScoreTable' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + ManageHiScoreTable(std::vector *table); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.h:98:2: style: Class 'Title' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Title(JA_Music_t *music); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:301:19: style: Operator '|' with one operand equal to zero is redundant. [badBitmaskCheck] + flags = flags | SDL_RENDERER_PRESENTVSYNC; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:481:39: performance: Function parameter 'filepath' should be passed by const reference. [passedByValue] +void Director::loadParams(std::string filepath) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:506:47: performance: Function parameter 'folder' should be passed by const reference. [passedByValue] +void Director::createSystemFolder(std::string folder) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:572:12: performance: Range variable 'l' should be declared as const reference. [iterateByValue] + for (auto l : list) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:590:12: performance: Range variable 'l' should be declared as const reference. [iterateByValue] + for (auto l : list) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/director.cpp:487:54: style: Parameter 'argv' can be declared as const array [constParameter] +void Director::checkProgramArguments(int argc, char *argv[]) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/enemy_formations.cpp:455:7: style: Variable 'incX' is assigned a value that is never used. [unreadVariable] + incX = BALLOON_WIDTH_1 + 1; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.h:275:7: style: Unused private function: 'Game::decBalloonSpeed' [unusedPrivateFunction] + void decBalloonSpeed(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.h:287:7: style: Unused private function: 'Game::popAllBalloons' [unusedPrivateFunction] + void popAllBalloons(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.h:299:6: style: Unused private function: 'Game::countBalloons' [unusedPrivateFunction] + int countBalloons(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2421:13: style: Condition 'igetMenace(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2354:10: style: Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm] + power += balloon->getPower(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:2735:3: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] + { + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:604:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:673:37: performance: Function parameter 'file_path' should be passed by const reference. [passedByValue] +bool Game::saveDemoFile(std::string file_path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game.cpp:676:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/game_logo.cpp:19:5: performance: Variable 'dust_texture_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + dust_texture_ = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png")); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.h:94:2: style: Class 'Input' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Input(std::string game_controller_db_path); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:12:30: performance: Function parameter 'game_controller_db_path' should be passed by const reference. [passedByValue] +void Input::init(std::string game_controller_db_path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:30:26: performance: Function parameter 'game_controller_db_path' should be passed by const reference. [passedByValue] +Input::Input(std::string game_controller_db_path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:531:39: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +int Input::getIndexByName(std::string name) const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:575:42: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +InputType Input::to_inputs_e(std::string name) const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/input.cpp:441:32: style: Variable 'separator' is assigned a value that is never used. [unreadVariable] + const std::string separator(" #"); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/intro.cpp:416:13: style: Variable 'text' can be declared as reference to const [constVariableReference] + for (auto &text : texts_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/item.cpp:11:2: performance: Variable 'sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + sprite_ = std::make_unique(texture, "", animation); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/item.cpp:14:2: performance: Variable 'time_to_live_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + time_to_live_ = 600; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:89:26: style: C-style pointer casting [cstyleCast] + char *name = (char *)malloc(nameSize + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:53:38: performance: Function parameter 'a' should be passed by const reference. [passedByValue] + bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; } + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:53:54: performance: Function parameter 'b' should be passed by const reference. [passedByValue] + bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; } + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:60:51: performance: Function parameter 'file_path' should be passed by const reference. [passedByValue] +bool ManageHiScoreTable::loadFromFile(std::string file_path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:116:49: performance: Function parameter 'file_path' should be passed by const reference. [passedByValue] +bool ManageHiScoreTable::saveToFile(std::string file_path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:65:32: style: Variable 'filename' is assigned a value that is never used. [unreadVariable] + const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/manage_hiscore_table.cpp:119:32: style: Variable 'fileName' is assigned a value that is never used. [unreadVariable] + const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:30:2: performance: Variable 'currentFlip_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + currentFlip_ = SDL_FLIP_NONE; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:69:20: warning: The class 'MovingSprite' defines member function with name 'render' also defined in its parent class 'Sprite'. [duplInheritedMember] +void MovingSprite::render() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:30:10: note: Parent function 'Sprite::render' + void render(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:69:20: note: Derived function 'MovingSprite::render' +void MovingSprite::render() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:78:21: warning: The class 'MovingSprite' defines member function with name 'getPosX' also defined in its parent class 'Sprite'. [duplInheritedMember] +float MovingSprite::getPosX() const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:33:9: note: Parent function 'Sprite::getPosX' + int getPosX() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:78:21: note: Derived function 'MovingSprite::getPosX' +float MovingSprite::getPosX() const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:84:21: warning: The class 'MovingSprite' defines member function with name 'getPosY' also defined in its parent class 'Sprite'. [duplInheritedMember] +float MovingSprite::getPosY() const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:34:9: note: Parent function 'Sprite::getPosY' + int getPosY() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:84:21: note: Derived function 'MovingSprite::getPosY' +float MovingSprite::getPosY() const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:298:24: warning: The class 'MovingSprite' defines member function with name 'getRect' also defined in its parent class 'Sprite'. [duplInheritedMember] +SDL_Rect MovingSprite::getRect() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.h:44:14: note: Parent function 'Sprite::getRect' + SDL_Rect getRect() const; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.cpp:298:24: note: Derived function 'MovingSprite::getRect' +SDL_Rect MovingSprite::getRect() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/notify.cpp:17:5: performance: Variable 'bgColor' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + bgColor = param.notification.color; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/notify.cpp:13:120: performance: Function parameter 'soundFile' should be passed by const reference. [passedByValue] +Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:243:29: performance: Function parameter 'var' should be passed by const reference. [passedByValue] +bool setOptions(std::string var, std::string value) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:243:46: performance: Function parameter 'value' should be passed by const reference. [passedByValue] +bool setOptions(std::string var, std::string value) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:89:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/options.cpp:153:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:155:28: performance: Function parameter 'var' should be passed by const reference. [passedByValue] +bool setParams(std::string var, std::string value) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:155:45: performance: Function parameter 'value' should be passed by const reference. [passedByValue] +bool setParams(std::string var, std::string value) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:101:48: warning: Either the condition 'pos<=(int)line.size()' is redundant or 'pos' can have the value line.size(). Expression 'line[pos]' cause access out of bounds. [containerOutOfBounds] + while (pos <= (int)line.size() && (int)line[pos] > 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:101:16: note: Assuming that condition 'pos<=(int)line.size()' is not redundant + while (pos <= (int)line.size() && (int)line[pos] > 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:101:48: note: Access out of bounds + while (pos <= (int)line.size() && (int)line[pos] > 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:117:49: warning: Either the condition 'pos<=(int)line.size()' is redundant or 'pos' can have the value line.size(). Expression 'line[pos]' cause access out of bounds. [containerOutOfBounds] + while (pos <= (int)line.size() && (int)line[pos] <= 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:117:17: note: Assuming that condition 'pos<=(int)line.size()' is not redundant + while (pos <= (int)line.size() && (int)line[pos] <= 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:117:49: note: Access out of bounds + while (pos <= (int)line.size() && (int)line[pos] <= 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:130:50: warning: Either the condition 'pos<=(int)line.size()' is redundant or 'pos' can have the value line.size(). Expression 'line[pos]' cause access out of bounds. [containerOutOfBounds] + while (pos <= (int)line.size() && (int)line[pos] > 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:130:18: note: Assuming that condition 'pos<=(int)line.size()' is not redundant + while (pos <= (int)line.size() && (int)line[pos] > 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:130:50: note: Access out of bounds + while (pos <= (int)line.size() && (int)line[pos] > 32) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/param.cpp:84:11: performance: Ineffective call of function 'substr' because a prefix of the string is assigned to itself. Use resize() or pop_back() instead. [uselessCallsSubstr] + line = line.substr(0, line.find("#")); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:14:9: warning: Member variable 'Player::controller_index_' is not initialized in the constructor. [uninitMemberVar] +Player::Player(int id, float x, int y, bool demo, SDL_Rect *play_area, std::vector> texture, std::vector *> animations) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:17:2: performance: Variable 'player_sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + player_sprite_ = std::make_unique(texture[0], "", animations[0]); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:18:2: performance: Variable 'power_sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + power_sprite_ = std::make_unique(texture[1], "", animations[1]); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:241:22: style: The statement 'if (status_walking_!=status) status_walking_=status' is logically equivalent to 'status_walking_=status'. [duplicateConditionalAssign] + if (status_walking_ != status) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:243:19: note: Assignment 'status_walking_=status' + status_walking_ = status; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:241:22: note: Condition 'status_walking_!=status' is redundant + if (status_walking_ != status) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:251:21: style: The statement 'if (status_firing_!=status) status_firing_=status' is logically equivalent to 'status_firing_=status'. [duplicateConditionalAssign] + if (status_firing_ != status) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:253:18: note: Assignment 'status_firing_=status' + status_firing_ = status; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:251:21: note: Condition 'status_firing_!=status' is redundant + if (status_firing_ != status) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:697:70: performance: Function parameter 'texture' should be passed by const reference. [passedByValue] +void Player::setPlayerTextures(std::vector> texture) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:747:34: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +void Player::setName(std::string name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/player.cpp:753:40: performance: Function parameter 'record_name' should be passed by const reference. [passedByValue] +void Player::setRecordName(std::string record_name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:40:2: performance: Variable 'game_power_meter_texture_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + game_power_meter_texture_ = nullptr; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:41:2: performance: Variable 'power_meter_sprite_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + power_meter_sprite_ = nullptr; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:42:2: performance: Variable 'text_scoreboard_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + text_scoreboard_ = nullptr; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.h:106:2: style: Class 'Scoreboard' has a constructor with 1 argument that is not explicit. [noExplicitConstructor] + Scoreboard(SDL_Renderer *renderer); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:326:13: style: Local variable 'rect_' shadows outer variable [shadowVariable] + SDL_Rect rect_ = {enter_name_pos_.x, enter_name_pos_.y, 5, 7}; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.h:71:11: note: Shadowed declaration + SDL_Rect rect_; // Posición y dimensiones del marcador + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:326:13: note: Shadow variable + SDL_Rect rect_ = {enter_name_pos_.x, enter_name_pos_.y, 5, 7}; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:133:50: performance: Function parameter 'name_' should be passed by const reference. [passedByValue] +void Scoreboard::setName(int panel_, std::string name_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:139:56: performance: Function parameter 'record_name_' should be passed by const reference. [passedByValue] +void Scoreboard::setRecordName(int panel_, std::string record_name_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/scoreboard.cpp:187:45: performance: Function parameter 'name_' should be passed by const reference. [passedByValue] +void Scoreboard::setHiScoreName(std::string name_) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:50:5: performance: Variable 'src_rect_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + src_rect_ = {0, 0, param.game.width, param.game.height}; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:51:5: performance: Variable 'dst_rect_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + dst_rect_ = {0, 0, param.game.width, param.game.height}; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:52:5: performance: Variable 'border_color_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + border_color_ = {0, 0, 0}; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:66:5: performance: Variable 'fps_ticks_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + fps_ticks_ = 0; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:458:43: performance: Function parameter 'text1' should be passed by const reference. [passedByValue] +void Screen::showNotification(std::string text1, std::string text2, int icon) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:458:62: performance: Function parameter 'text2' should be passed by const reference. [passedByValue] +void Screen::showNotification(std::string text1, std::string text2, int icon) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:188:24: style: Variable 'options.video.mode' is reassigned a value before the old one has been used. [redundantAssignment] + options.video.mode = ScreenVideoMode::WINDOW; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:186:24: note: options.video.mode is assigned + options.video.mode = videoMode; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/screen.cpp:188:24: note: options.video.mode is overwritten + options.video.mode = ScreenVideoMode::WINDOW; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:26:19: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'AnimatedSprite'. [duplInheritedMember] +void SmartSprite::update() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/animated_sprite.h:88:10: note: Parent function 'AnimatedSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:26:19: note: Derived function 'SmartSprite::update' +void SmartSprite::update() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:26:19: warning: The class 'SmartSprite' defines member function with name 'update' also defined in its parent class 'MovingSprite'. [duplInheritedMember] +void SmartSprite::update() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/moving_sprite.h:45:10: note: Parent function 'MovingSprite::update' + void update(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/smart_sprite.cpp:26:19: note: Derived function 'SmartSprite::update' +void SmartSprite::update() + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/sprite.cpp:8:2: performance: Variable 'spriteClip_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + spriteClip_ = {0, 0, w, h}; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:82:49: performance: Function parameter 'text_file' should be passed by const reference. [passedByValue] +Text::Text(std::string bitmap_file, std::string text_file, SDL_Renderer *renderer) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:106:24: performance: Function parameter 'text_file' should be passed by const reference. [passedByValue] +Text::Text(std::string text_file, std::shared_ptr texture) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:149:44: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +void Text::write(int x, int y, std::string text, int kerning, int lenght) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:172:51: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:180:52: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadow_distance, int kerning, int lenght) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:189:52: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:196:59: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadow_distance, Color shadow_color, int lenght) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:238:30: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +int Text::lenght(std::string text, int kerning) const + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:270:35: performance: Function parameter 'path' should be passed by const reference. [passedByValue] +void Text::addPalette(std::string path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/text.cpp:24:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1).c_str(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.h:36:13: style: Unused private function: 'Texture::newSurface' [unusedPrivateFunction] + Surface newSurface(int w, int h); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:79:17: style: Condition 'req_format==STBI_rgb' is always false [knownConditionTrueFalse] + if (req_format == STBI_rgb) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:60:19: note: Assignment 'req_format=STBI_rgb_alpha', assigned value is 4 + int req_format = STBI_rgb_alpha; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:79:17: note: Condition 'req_format==STBI_rgb' is always false + if (req_format == STBI_rgb) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:99:66: style: C-style pointer casting [cstyleCast] + SDL_Surface *loadedSurface = SDL_CreateRGBSurfaceWithFormatFrom((void *)data, width, height, depth, pitch, pixel_format); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:244:18: style: C-style pointer casting [cstyleCast] + Surface surf = (Surface)malloc(sizeof(surface_s)); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:247:15: style: C-style pointer casting [cstyleCast] + surf->data = (Uint8 *)malloc(w * h); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:279:18: style: C-style pointer casting [cstyleCast] + Uint8 *buffer = (Uint8 *)malloc(size); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:290:21: style: C-style pointer casting [cstyleCast] + Surface surface = (Surface)malloc(sizeof(surface_s)); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:315:37: style: C-style pointer casting [cstyleCast] + SDL_LockTexture(texture_, nullptr, (void **)&pixels, &pitch); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:343:18: style: C-style pointer casting [cstyleCast] + Uint8 *buffer = (Uint8 *)malloc(size); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:14:54: performance: Function parameter 'path' should be passed by const reference. [passedByValue] +Texture::Texture(SDL_Renderer *renderer, std::string path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:57:40: performance: Function parameter 'path' should be passed by const reference. [passedByValue] +bool Texture::loadFromFile(std::string path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:364:38: performance: Function parameter 'path' should be passed by const reference. [passedByValue] +void Texture::addPalette(std::string path) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:41:4: performance: Passing the result of c_str() to a function that takes std::string as argument no. 1 is slow and redundant. [stlcstrParam] + addPalette(path_.c_str()); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/texture.cpp:59:30: style: Variable 'file_name' is assigned a value that is never used. [unreadVariable] + const std::string file_name = path.substr(path.find_last_of("\\/") + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.cpp:318:12: style: Local variable 'num_controllers_' shadows outer variable [shadowVariable] + const int num_controllers_ = input_->getNumControllers(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.h:70:6: note: Shadowed declaration + int num_controllers_; // Número de mandos conectados + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/title.cpp:318:12: note: Shadow variable + const int num_controllers_ = input_->getNumControllers(); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:187:19: style: C-style pointer casting [cstyleCast] + char *lower = (char *)malloc(str.size() + 1); + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:166:31: performance: Function parameter 'str' should be passed by const reference. [passedByValue] +bool stringToBool(std::string str) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:184:33: performance: Function parameter 'str' should be passed by const reference. [passedByValue] +std::string toLower(std::string str) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:200:45: performance: Function parameter 'sounds' should be passed by const reference. [passedByValue] +JA_Sound_t *getSound(std::vector sounds, std::string name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:200:65: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +JA_Sound_t *getSound(std::vector sounds, std::string name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:202:15: performance: Range variable 's' should be declared as const reference. [iterateByValue] + for (auto s : sounds) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:214:45: performance: Function parameter 'music' should be passed by const reference. [passedByValue] +JA_Music_t *getMusic(std::vector music, std::string name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:214:64: performance: Function parameter 'name' should be passed by const reference. [passedByValue] +JA_Music_t *getMusic(std::vector music, std::string name) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:216:15: performance: Range variable 'm' should be declared as const reference. [iterateByValue] + for (auto m : music) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:228:44: performance: Function parameter 'entry1' should be passed by const reference. [passedByValue] +HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:228:65: performance: Function parameter 'entry2' should be passed by const reference. [passedByValue] +HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:32:29: style: Parameter 'a' can be declared as reference to const [constParameterReference] +bool checkCollision(Circle &a, Circle &b) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:32:40: style: Parameter 'b' can be declared as reference to const [constParameterReference] +bool checkCollision(Circle &a, Circle &b) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:50:29: style: Parameter 'a' can be declared as reference to const [constParameterReference] +bool checkCollision(Circle &a, SDL_Rect &b) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:50:42: style: Parameter 'b' can be declared as reference to const [constParameterReference] +bool checkCollision(Circle &a, SDL_Rect &b) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:95:31: style: Parameter 'a' can be declared as reference to const [constParameterReference] +bool checkCollision(SDL_Rect &a, SDL_Rect &b) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:95:44: style: Parameter 'b' can be declared as reference to const [constParameterReference] +bool checkCollision(SDL_Rect &a, SDL_Rect &b) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:135:32: style: Parameter 'p' can be declared as reference to const [constParameterReference] +bool checkCollision(SDL_Point &p, SDL_Rect &r) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:135:45: style: Parameter 'r' can be declared as reference to const [constParameterReference] +bool checkCollision(SDL_Point &p, SDL_Rect &r) + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:205:9: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] + { + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/utils.cpp:219:9: style: Consider using std::find_if algorithm instead of a raw loop. [useStlAlgorithm] + { + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.cpp:11:2: performance: Variable 'caption_' is assigned in constructor body. Consider performing initialization in initialization list. [useInitializationList] + caption_ = ""; + ^ +/home/sergio/gitea/coffee_crisis_arcade_edition/source/writer.cpp:81:37: performance: Function parameter 'text' should be passed by const reference. [passedByValue] +void Writer::setCaption(std::string text) + ^ +nofile:0:0: information: Too many #ifdef configurations - cppcheck only checks 12 configurations. Use --force to check all configurations. For more details, use --enable=information. [toomanyconfigs] + diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index b087a00..1a0f50b 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -15,7 +15,9 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr texture, std::string auto frame_height = 0; auto max_tiles = 0; +#ifdef VERBOSE const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); +#endif std::ifstream file(file_path); std::string line; @@ -156,21 +158,20 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr texture, std::string } // Constructor -AnimatedSprite::AnimatedSprite(std::shared_ptr texture, std::string file, std::vector *buffer) +AnimatedSprite::AnimatedSprite(std::shared_ptr texture, const std::string &file, std::vector *buffer) + : MovingSprite(texture) { - // Copia los punteros - setTexture(texture); - // Carga las animaciones if (file != "") { AnimatedFile as = loadAnimationFromFile(texture, file); // Copia los datos de las animaciones - for (auto animation : as.animations) + /*for (auto animation : as.animations) { animations_.push_back(animation); - } + }*/ + std::copy(as.animations.begin(), as.animations.end(), std::back_inserter(animations_)); } else if (buffer) @@ -183,19 +184,14 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr texture, std::string fil } // Constructor -AnimatedSprite::AnimatedSprite(AnimatedFile *animation) +AnimatedSprite::AnimatedSprite(const AnimatedFile *animation) + : MovingSprite(animation->texture) { - // Copia los punteros - setTexture(animation->texture); - // Inicializa variables current_animation_ = 0; // Copia los datos de las animaciones - for (auto a : animation->animations) - { - animations_.push_back(a); - } + std::copy(animation->animations.begin(), animation->animations.end(), std::back_inserter(animations_)); } // Destructor @@ -205,11 +201,11 @@ 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) { auto index = -1; - for (auto a : animations_) + for (const auto &a : animations_) { index++; if (a.name == name) @@ -226,7 +222,7 @@ int AnimatedSprite::getIndex(std::string name) // Calcula el frame correspondiente a la animación void AnimatedSprite::animate() { - if (!enabled_ || animations_[current_animation_].speed == 0) + if (animations_[current_animation_].speed == 0) { return; } @@ -284,13 +280,13 @@ 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) { animations_[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) { animations_[getIndex(name)].counter = speed; } @@ -302,7 +298,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) { animations_[getIndex(name)].loop = loop; } @@ -314,7 +310,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) { animations_[getIndex(name)].completed = value; } @@ -332,7 +328,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 animations_[getIndex(name)].frames[index]; } @@ -484,13 +480,13 @@ bool AnimatedSprite::loadFromVector(std::vector *source) } // Pone un valor por defecto - setRect({0, 0, frame_width, frame_height}); + setPos((SDL_Rect){0, 0, frame_width, frame_height}); return success; } // Establece la animacion actual -void AnimatedSprite::setCurrentAnimation(std::string name) +void AnimatedSprite::setCurrentAnimation(const std::string &name) { const auto new_animation = getIndex(name); if (current_animation_ != new_animation) @@ -518,11 +514,8 @@ void AnimatedSprite::setCurrentAnimation(int index) // Actualiza las variables del objeto void AnimatedSprite::update() { - if (enabled_) - { - animate(); - MovingSprite::update(); - } + animate(); + MovingSprite::update(); } // Establece el rectangulo para un frame de una animación diff --git a/source/animated_sprite.h b/source/animated_sprite.h index 7f03ca3..8c98d7d 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -30,15 +30,15 @@ AnimatedFile loadAnimationFromFile(std::shared_ptr texture, std::string class AnimatedSprite : public MovingSprite { -private: +protected: // Variables std::vector animations_; // Vector con las diferentes animaciones int current_animation_; // Animacion activa public: // Constructor - AnimatedSprite(std::shared_ptr texture = nullptr, std::string file = "", std::vector *buffer = nullptr); - AnimatedSprite(AnimatedFile *animation); + explicit AnimatedSprite(std::shared_ptr texture = nullptr, const std::string &file = "", std::vector *buffer = nullptr); + explicit AnimatedSprite(const AnimatedFile *animation); // Destructor ~AnimatedSprite(); @@ -53,39 +53,39 @@ public: void setCurrentFrame(int num); // Establece el valor del contador - void setAnimationCounter(std::string name, int num); + void setAnimationCounter(const std::string &name, int num); // Establece la velocidad de una animación - void setAnimationSpeed(std::string name, int speed); + void setAnimationSpeed(const std::string &name, int speed); void setAnimationSpeed(int index, int speed); // Establece el frame al que vuelve la animación al finalizar - void setAnimationLoop(std::string name, int loop); + void setAnimationLoop(const std::string &name, int loop); void setAnimationLoop(int index, int loop); // Establece el valor de la variable - void setAnimationCompleted(std::string name, bool value); + void setAnimationCompleted(const std::string &name, bool value); void setAnimationCompleted(int index, bool value); // Comprueba si ha terminado la animación bool animationIsCompleted(); // Devuelve el rectangulo de una animación y frame concreto - SDL_Rect getAnimationClip(std::string name = "default", Uint8 index = 0); + SDL_Rect getAnimationClip(const std::string &name = "default", Uint8 index = 0); SDL_Rect getAnimationClip(int indexA = 0, Uint8 indexF = 0); // Obtiene el indice de la animación a partir del nombre - int getIndex(std::string name); + int getIndex(const std::string &name); // Carga la animación desde un vector bool loadFromVector(std::vector *source); // Establece la animacion actual - void setCurrentAnimation(std::string name = "default"); + void setCurrentAnimation(const std::string &name = "default"); void setCurrentAnimation(int index = 0); // Actualiza las variables del objeto - void update(); + void update() override; // OLD - Establece el rectangulo para un frame de una animación void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h); diff --git a/source/asset.cpp b/source/asset.cpp index 3c05fe9..470d8af 100644 --- a/source/asset.cpp +++ b/source/asset.cpp @@ -5,35 +5,35 @@ #include // for basic_ostream, operator<<, cout, endl // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado -Asset *Asset::asset = nullptr; +Asset *Asset::asset_ = nullptr; // [SINGLETON] Crearemos el objeto asset con esta función estática -void Asset::init(std::string executable_path) +void Asset::init(const std::string &executable_path) { - Asset::asset = new Asset(executable_path); + Asset::asset_ = new Asset(executable_path); } // [SINGLETON] Destruiremos el objeto asset con esta función estática void Asset::destroy() { - delete Asset::asset; + delete Asset::asset_; } // [SINGLETON] Con este método obtenemos el objeto asset y podemos trabajar con él Asset *Asset::get() { - return Asset::asset; + return Asset::asset_; } // Constructor -Asset::Asset(std::string executable_path) +Asset::Asset(const std::string &executable_path) { executable_path_ = executable_path.substr(0, executable_path.find_last_of("\\/")); longest_name_ = 0; } // Añade un elemento a la lista -void Asset::add(std::string file, AssetType type, bool required, bool absolute) +void Asset::add(const std::string &file, AssetType type, bool required, bool absolute) { AssetItem ai; ai.file = absolute ? file : executable_path_ + file; @@ -46,9 +46,9 @@ void Asset::add(std::string file, AssetType type, bool required, bool absolute) } // Devuelve el fichero de un elemento de la lista a partir de una cadena -std::string Asset::get(std::string text) const +std::string Asset::get(const std::string &text) const { - for (auto f : file_list_) + for (const auto &f : file_list_) { const size_t last_index = f.file.find_last_of("/") + 1; const std::string file = f.file.substr(last_index, std::string::npos); @@ -83,7 +83,7 @@ bool Asset::check() const // Comprueba si hay ficheros de ese tipo bool any = false; - for (auto f : file_list_) + for (const auto &f : file_list_) { if (f.required && f.type == static_cast(type)) { @@ -98,7 +98,7 @@ bool Asset::check() const std::cout << "\n>> " << getTypeName(static_cast(type)).c_str() << " FILES" << std::endl; #endif - for (auto f : file_list_) + for (const auto &f : file_list_) { if (f.required && f.type == static_cast(type)) { @@ -117,29 +117,27 @@ bool Asset::check() const } // Comprueba que existe un fichero -bool Asset::checkFile(std::string path) const +bool Asset::checkFile(const std::string &path) const { - bool success = false; - std::string result = "ERROR"; + auto success = false; // Comprueba si existe el fichero - const std::string file_name = path.substr(path.find_last_of("\\/") + 1); - SDL_RWops *file = SDL_RWFromFile(path.c_str(), "rb"); + auto file = SDL_RWFromFile(path.c_str(), "rb"); - if (file != nullptr) + if (file) { - result = "OK"; success = true; SDL_RWclose(file); } #ifdef VERBOSE + const std::string file_name = path.substr(path.find_last_of("\\/") + 1); std::cout.setf(std::ios::left, std::ios::adjustfield); std::cout << "Checking file: "; std::cout.width(longest_name_ + 2); std::cout.fill('.'); - std::cout << file_name + " "; - std::cout << " [" + result + "]" << std::endl; + std::cout << file_name; + std::cout << (success ? " [OK]" : " [ERROR]") << std::endl; #endif return success; diff --git a/source/asset.h b/source/asset.h index d1f6c7f..fa1eb11 100644 --- a/source/asset.h +++ b/source/asset.h @@ -1,7 +1,7 @@ #pragma once -#include // for string, basic_string -#include // for vector +#include // for string, basic_string +#include // for vector enum class AssetType : int { @@ -22,7 +22,7 @@ class Asset { private: // [SINGLETON] Objeto asset privado para Don Melitón - static Asset *asset; + static Asset *asset_; // Estructura para definir un item struct AssetItem @@ -34,25 +34,25 @@ private: }; // Variables - int longest_name_; // Contiene la longitud del nombre de fichero mas largo + int longest_name_; // Contiene la longitud del nombre de fichero mas largo std::vector file_list_; // Listado con todas las rutas a los ficheros - std::string executable_path_; // Ruta al ejecutable + std::string executable_path_; // Ruta al ejecutable // Comprueba que existe un fichero - bool checkFile(std::string executable_path) const; + bool checkFile(const std::string &path) const; // Devuelve el nombre del tipo de recurso std::string getTypeName(AssetType type) const; // Constructor - Asset(std::string path); + explicit Asset(const std::string &executable_path); // Destructor ~Asset() = default; public: // [SINGLETON] Crearemos el objeto screen con esta función estática - static void init(std::string path); + static void init(const std::string &executable_path); // [SINGLETON] Destruiremos el objeto screen con esta función estática static void destroy(); @@ -61,10 +61,10 @@ public: static Asset *get(); // Añade un elemento a la lista - void add(std::string file, AssetType type, bool required = true, bool absolute = false); + void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); // Devuelve un elemento de la lista a partir de una cadena - std::string get(std::string text) const; + std::string get(const std::string &text) const; // Comprueba que existen todos los elementos bool check() const; diff --git a/source/background.cpp b/source/background.cpp index 90ba5bd..073a226 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -8,15 +8,14 @@ // Constructor Background::Background(SDL_Renderer *renderer) - : renderer_(renderer) -{ - // Carga las texturas - buildings_texture_ = std::make_shared(renderer, Asset::get()->get("game_buildings.png")); - top_clouds_texture_ = std::make_shared(renderer, Asset::get()->get("game_clouds1.png")); - bottom_clouds_texture_ = std::make_shared(renderer, Asset::get()->get("game_clouds2.png")); - grass_texture_ = std::make_shared(renderer, Asset::get()->get("game_grass.png")); - gradients_texture_ = std::make_shared(renderer, Asset::get()->get("game_sky_colors.png")); + : renderer_(renderer), + buildings_texture_(std::make_shared(renderer, Asset::get()->get("game_buildings.png"))), + top_clouds_texture_(std::make_shared(renderer, Asset::get()->get("game_clouds1.png"))), + bottom_clouds_texture_(std::make_shared(renderer, Asset::get()->get("game_clouds2.png"))), + grass_texture_(std::make_shared(renderer, Asset::get()->get("game_grass.png"))), + gradients_texture_(std::make_shared(renderer, Asset::get()->get("game_sky_colors.png"))) +{ // Inicializa variables gradient_number_ = 0; alpha_ = 0; diff --git a/source/background.h b/source/background.h index 2658dbd..1c943de 100644 --- a/source/background.h +++ b/source/background.h @@ -107,7 +107,7 @@ private: public: // Constructor - Background(SDL_Renderer *renderer); + explicit Background(SDL_Renderer *renderer); // Destructor ~Background(); diff --git a/source/balloon.cpp b/source/balloon.cpp index e914d26..d05e4a6 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -323,7 +323,7 @@ void Balloon::render() if (kind_ == POWER_BALL && !isBeingCreated()) { - auto sp = std::make_unique(sprite_->getRect(), sprite_->getTexture()); + auto sp = std::make_unique(sprite_->getPos(), sprite_->getTexture()); sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4); sp->render(); } diff --git a/source/logo.cpp b/source/logo.cpp index 2c1c52e..2c11575 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -32,7 +32,6 @@ Logo::Logo() dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2; since_sprite_->setPosY(dest_.y + jail_texture_->getHeight() + 5); since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight()); - since_sprite_->setEnabled(false); since_texture_->setColor(0x00, 0x00, 0x00); // Esto en linux no hace nada ?? // Crea los sprites de cada linea @@ -192,12 +191,6 @@ void Logo::update() { section::name = section::Name::INTRO; } - - // Comprueba si se ha de mostrar el sprite - else if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK) - { - since_sprite_->setEnabled(true); - } } } @@ -215,7 +208,11 @@ void Logo::render() { sprite->render(); } - since_sprite_->render(); + + if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK) + { + since_sprite_->render(); + } // Vuelca el contenido del renderizador en pantalla Screen::get()->blit(); diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index 44ce667..8715e9b 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -3,31 +3,39 @@ // Constructor MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, float ax, float ay, std::shared_ptr texture) - : Sprite((int)x, (int)y, w, h, texture), x_(x), y_(y), vx_(vx), vy_(vy), ax_(ax), ay_(ay) + : Sprite((int)x, (int)y, w, h, texture), + x_(x), + y_(y), + vx_(vx), + vy_(vy), + ax_(ax), + ay_(ay) { // Establece el zoom W,H del sprite - zoomW_ = 1; - zoomH_ = 1; - - // Establece el angulo con el que se dibujará - angle_ = (double)0; + zoom_w_ = 1; + zoom_h_ = 1; // Establece los valores de rotacion - rotateEnabled_ = false; - rotateSpeed_ = 0; - rotateAmount_ = (double)0; + rotate_.enabled = false; + rotate_.speed = 0; + rotate_.angle = 0.0f; + rotate_.amount = 0.0f; + rotate_.center = nullptr; // Contador interno counter_ = 0; // Establece el rectangulo de donde coger la imagen - spriteClip_ = {0, 0, w_, h_}; - - // Establece el centro de rotación - center_ = nullptr; + sprite_clip_ = (SDL_Rect){0, 0, w, h}; // Establece el tipo de volteado - currentFlip_ = SDL_FLIP_NONE; + flip_ = SDL_FLIP_NONE; +}; + +MovingSprite::MovingSprite(std::shared_ptr texture) + : Sprite(texture) +{ + clear(); }; // Reinicia todas las variables @@ -42,17 +50,21 @@ void MovingSprite::clear() ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad - zoomW_ = 1.0f; // Zoom aplicado a la anchura - zoomH_ = 1.0f; // Zoom aplicado a la altura + zoom_w_ = 1.0f; // Zoom aplicado a la anchura + zoom_h_ = 1.0f; // Zoom aplicado a la altura - angle_ = 0.0; // Angulo para dibujarlo - rotateEnabled_ = false; // Indica si ha de rotar - center_ = nullptr; // Centro de rotación - rotateSpeed_ = 0; // Velocidad de giro - rotateAmount_ = 0.0; // Cantidad de grados a girar en cada iteración - counter_ = 0; // Contador interno + rotate_.enabled = false; // Indica si ha de rotar + rotate_.speed = 0; // Velocidad de giro + rotate_.angle = 0.0f; // Angulo para dibujarlo + rotate_.amount = 0.0f; // Cantidad de grados a girar en cada iteración + rotate_.center = nullptr; // Centro de rotación - currentFlip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite + counter_ = 0; // Contador interno + + flip_ = SDL_FLIP_NONE; // Establece como se ha de voltear el sprite + + setPos((SDL_Rect){0, 0, 0, 0}); + setSpriteClip((SDL_Rect){0, 0, 0, 0}); } // Mueve el sprite @@ -68,10 +80,7 @@ void MovingSprite::move() // Muestra el sprite por pantalla void MovingSprite::render() { - if (enabled_) - { - texture_->render((int)x_, (int)y_, &spriteClip_, zoomW_, zoomH_, angle_, center_, currentFlip_); - } + texture_->render((int)x_, (int)y_, &sprite_clip_, zoom_w_, zoom_h_, (double)rotate_.angle, rotate_.center, flip_); } // Obtiene el valor de la variable @@ -113,28 +122,28 @@ float MovingSprite::getAccelY() const // Obtiene el valor de la variable float MovingSprite::getZoomW() const { - return zoomW_; + return zoom_w_; } // Obtiene el valor de la variable float MovingSprite::getZoomH() const { - return zoomH_; + return zoom_h_; } // Obtiene el valor de la variable -double MovingSprite::getAngle() const +float MovingSprite::getAngle() const { - return angle_; + return rotate_.angle; } // Establece la posición y_ el tamaño del objeto -void MovingSprite::setRect(SDL_Rect rect) +void MovingSprite::setPos(SDL_Rect rect) { x_ = (float)rect.x; y_ = (float)rect.y; - w_ = rect.w; - h_ = rect.h; + + pos_ = rect; } // Establece el valor de las variables @@ -142,18 +151,23 @@ void MovingSprite::setPos(float x, float y) { x_ = x; y_ = y; + + pos_.x = (int)x; + pos_.y = (int)y; } // Establece el valor de la variable void MovingSprite::setPosX(float value) { x_ = value; + pos_.x = (int)x_; } // Establece el valor de la variable void MovingSprite::setPosY(float value) { y_ = value; + pos_.y = (int)y_; } // Establece el valor de la variable @@ -183,53 +197,53 @@ void MovingSprite::setAccelY(float value) // Establece el valor de la variable void MovingSprite::setZoomW(float value) { - zoomW_ = value; + zoom_w_ = value; } // Establece el valor de la variable void MovingSprite::setZoomH(float value) { - zoomH_ = value; + zoom_h_ = value; } // Establece el valor de la variable void MovingSprite::setAngle(double value) { - angle_ = value; + rotate_.angle = value; } // Incrementa el valor de la variable void MovingSprite::incAngle(double value) { - angle_ += value; + rotate_.angle += value; } // Decrementa el valor de la variable void MovingSprite::decAngle(double value) { - angle_ -= value; + rotate_.angle -= value; } // Obtiene el valor de la variable bool MovingSprite::getRotate() const { - return rotateEnabled_; + return rotate_.enabled; } // Obtiene el valor de la variable Uint16 MovingSprite::getRotateSpeed() const { - return rotateSpeed_; + return rotate_.speed; } // Establece la rotacion void MovingSprite::rotate() { - if (rotateEnabled_) + if (rotate_.enabled) { - if (counter_ % rotateSpeed_ == 0) + if (counter_ % rotate_.speed == 0) { - incAngle(rotateAmount_); + incAngle(rotate_.amount); } } } @@ -237,65 +251,62 @@ void MovingSprite::rotate() // Establece el valor de la variable void MovingSprite::setRotate(bool value) { - rotateEnabled_ = value; + rotate_.enabled = value; } // Establece el valor de la variable void MovingSprite::setRotateSpeed(int value) { - rotateSpeed_ = (value < 1) ? 1 : value; + rotate_.speed = (value < 1) ? 1 : value; } // Establece el valor de la variable void MovingSprite::setRotateAmount(double value) { - rotateAmount_ = value; + rotate_.amount = value; } // Establece el valor de la variable void MovingSprite::disableRotate() { - rotateEnabled_ = false; - angle_ = (double)0; + rotate_.enabled = false; + rotate_.angle = 0.0f; } // Actualiza las variables internas del objeto void MovingSprite::update() { - if (enabled_) - { - move(); - rotate(); - ++counter_ %= 60000; - } + move(); + rotate(); + ++counter_ %= 60000; } // Cambia el sentido de la rotación void MovingSprite::switchRotate() { - rotateAmount_ *= -1; + rotate_.amount *= -1; } // Establece el valor de la variable void MovingSprite::setFlip(SDL_RendererFlip flip) { - currentFlip_ = flip; + flip_ = flip; } // Gira el sprite horizontalmente void MovingSprite::flip() { - currentFlip_ = (currentFlip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; + flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; } // Obtiene el valor de la variable SDL_RendererFlip MovingSprite::getFlip() { - return currentFlip_; + return flip_; } // Devuelve el rectangulo donde está el sprite -SDL_Rect MovingSprite::getRect() +SDL_Rect MovingSprite::getPos() const { - return (SDL_Rect){(int)x_, (int)y_, w_, h_}; + return (SDL_Rect){(int)x_, (int)y_, pos_.w, pos_.h}; } \ No newline at end of file diff --git a/source/moving_sprite.h b/source/moving_sprite.h index e4e5cfd..d77d25f 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -1,16 +1,25 @@ #pragma once -#include // for SDL_Rect, SDL_Point -#include // for SDL_RendererFlip -#include // for Uint16 +#include // for SDL_Rect, SDL_Point +#include // for SDL_RendererFlip +#include // for Uint16 #include -#include "sprite.h" // for Sprite +#include "sprite.h" // for Sprite #include "texture.h" // Clase MovingSprite. Añade posicion y velocidad en punto flotante class MovingSprite : public Sprite { protected: + struct Rotate + { + bool enabled; // Indica si ha de rotar + int speed; // Velocidad de giro + float angle; // Angulo para dibujarlo + float amount; // Cantidad de grados a girar en cada iteración + SDL_Point *center; // Centro de rotación + }; + float x_; // Posición en el eje X float y_; // Posición en el eje Y @@ -20,20 +29,17 @@ protected: float ax_; // Aceleración en el eje X. Variación de la velocidad float ay_; // Aceleración en el eje Y. Variación de la velocidad - float zoomW_; // Zoom aplicado a la anchura - float zoomH_; // Zoom aplicado a la altura + float zoom_w_; // Zoom aplicado a la anchura + float zoom_h_; // Zoom aplicado a la altura - double angle_; // Angulo para dibujarlo - bool rotateEnabled_; // Indica si ha de rotar - int rotateSpeed_; // Velocidad de giro - double rotateAmount_; // Cantidad de grados a girar en cada iteración - int counter_; // Contador interno - SDL_Point *center_; // Centro de rotación - SDL_RendererFlip currentFlip_; // Indica como se voltea el sprite + int counter_; // Contador interno + Rotate rotate_; // Variables usada para controlar la rotación del sprite + SDL_RendererFlip flip_; // Indica como se voltea el sprite public: // Constructor - MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, std::shared_ptr texture = nullptr); + explicit MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, std::shared_ptr texture = nullptr); + explicit MovingSprite(std::shared_ptr texture = nullptr); // Mueve el sprite void move(); @@ -42,13 +48,13 @@ public: void rotate(); // Actualiza las variables internas del objeto - void update(); + virtual void update(); // Reinicia todas las variables void clear(); // Muestra el sprite por pantalla - void render(); + void render() override; // Obten el valor de la variable float getPosX() const; @@ -67,16 +73,17 @@ public: float getZoomH() const; // Obten el valor de la variable - double getAngle() const; + float getAngle() const; bool getRotate() const; Uint16 getRotateSpeed() const; - // Establece la posición y el tamaño del objeto - void setRect(SDL_Rect rect); - - // Establece el valor de las variables + // Establece la posición del objeto + void setPos(SDL_Rect rect) override; void setPos(float x, float y); + // Devuelve el rectangulo donde está el sprite + SDL_Rect getPos() const override; + // Establece el valor de la variable void setPosX(float value); void setPosY(float value); @@ -118,6 +125,5 @@ public: // Obtiene el valor de la variable SDL_RendererFlip getFlip(); - // Devuelve el rectangulo donde está el sprite - SDL_Rect getRect(); + }; \ No newline at end of file diff --git a/source/smart_sprite.cpp b/source/smart_sprite.cpp index bbfa0e1..11ea74e 100644 --- a/source/smart_sprite.cpp +++ b/source/smart_sprite.cpp @@ -4,20 +4,18 @@ class Texture; // Constructor SmartSprite::SmartSprite(std::shared_ptr texture) + : AnimatedSprite(texture) { - // Copia punteros - setTexture(texture); - init(); } // Inicializa el objeto void SmartSprite::init() { - finishedCounter_ = 0; - onDestination_ = false; - destX_ = 0; - destY_ = 0; + finished_counter_ = 0; + on_destination_ = false; + dest_x_ = 0; + dest_y_ = 0; finished_ = false; enabled_ = false; } @@ -36,31 +34,31 @@ void SmartSprite::update() // Establece el valor de la variable void SmartSprite::setFinishedCounter(int value) { - finishedCounter_ = value; + finished_counter_ = value; } // Establece el valor de la variable void SmartSprite::setDestX(int x) { - destX_ = x; + dest_x_ = x; } // Establece el valor de la variable void SmartSprite::setDestY(int y) { - destY_ = y; + dest_y_ = y; } // Obtiene el valor de la variable int SmartSprite::getDestX() const { - return destX_; + return dest_x_; } // Obtiene el valor de la variable int SmartSprite::getDestY() const { - return destY_; + return dest_y_; } // Comprueba el movimiento @@ -70,10 +68,10 @@ void SmartSprite::checkMove() if (getAccelX() > 0 || getVelX() > 0) { // Comprueba si ha llegado al destino - if (getPosX() > destX_) + if (getPosX() > dest_x_) { // Lo coloca en posición - setPosX(destX_); + setPosX(dest_x_); // Lo detiene setVelX(0.0f); @@ -84,10 +82,10 @@ void SmartSprite::checkMove() else if (getAccelX() < 0 || getVelX() < 0) { // Comprueba si ha llegado al destino - if (getPosX() < destX_) + if (getPosX() < dest_x_) { // Lo coloca en posición - setPosX(destX_); + setPosX(dest_x_); // Lo detiene setVelX(0.0f); @@ -99,10 +97,10 @@ void SmartSprite::checkMove() if (getAccelY() > 0 || getVelY() > 0) { // Comprueba si ha llegado al destino - if (getPosY() > destY_) + if (getPosY() > dest_y_) { // Lo coloca en posición - setPosY(destY_); + setPosY(dest_y_); // Lo detiene setVelY(0.0f); @@ -113,10 +111,10 @@ void SmartSprite::checkMove() else if (getAccelY() < 0 || getVelY() < 0) { // Comprueba si ha llegado al destino - if (getPosY() < destY_) + if (getPosY() < dest_y_) { // Lo coloca en posición - setPosY(destY_); + setPosY(dest_y_); // Lo detiene setVelY(0.0f); @@ -129,17 +127,17 @@ void SmartSprite::checkMove() void SmartSprite::checkFinished() { // Comprueba si ha llegado a su destino - onDestination_ = (getPosX() == destX_ && getPosY() == destY_) ? true : false; + on_destination_ = (getPosX() == dest_x_ && getPosY() == dest_y_) ? true : false; - if (onDestination_) + if (on_destination_) { - if (finishedCounter_ == 0) + if (finished_counter_ == 0) { finished_ = true; } else { - --finishedCounter_; + --finished_counter_; } } } @@ -147,11 +145,16 @@ void SmartSprite::checkFinished() // Obtiene el valor de la variable bool SmartSprite::isOnDestination() const { - return onDestination_; + return on_destination_; } // Obtiene el valor de la variable bool SmartSprite::hasFinished() const { return finished_; +} + +void SmartSprite::setEnabled(bool value) +{ + enabled_ = value; } \ No newline at end of file diff --git a/source/smart_sprite.h b/source/smart_sprite.h index 16d4ece..07b3ea4 100644 --- a/source/smart_sprite.h +++ b/source/smart_sprite.h @@ -9,11 +9,12 @@ class SmartSprite : public AnimatedSprite { private: // Variables - bool onDestination_; // Indica si está en el destino - int destX_; // Posicion de destino en el eje X - int destY_; // Posicion de destino en el eje Y - int finishedCounter_; // Contador para deshabilitarlo - bool finished_; // Indica si ya ha terminado + bool on_destination_; // Indica si está en el destino + int dest_x_; // Posicion de destino en el eje X + int dest_y_; // Posicion de destino en el eje Y + int finished_counter_; // Contador para deshabilitarlo + bool finished_; // Indica si ya ha terminado + bool enabled_; // Indica si el objeto está habilitado // Comprueba el movimiento void checkMove(); @@ -23,7 +24,7 @@ private: public: // Constructor - SmartSprite(std::shared_ptr texture); + explicit SmartSprite(std::shared_ptr texture); // Destructor ~SmartSprite() = default; @@ -32,7 +33,7 @@ public: void init(); // Actualiza la posición y comprueba si ha llegado a su destino - void update(); + void update() override; // Establece el valor de la variable void setFinishedCounter(int value); @@ -54,4 +55,6 @@ public: // Obtiene el valor de la variable bool hasFinished() const; + + void setEnabled(bool value); }; \ No newline at end of file diff --git a/source/sprite.cpp b/source/sprite.cpp index 3e7c6b8..60b26d7 100644 --- a/source/sprite.cpp +++ b/source/sprite.cpp @@ -2,121 +2,108 @@ // Constructor Sprite::Sprite(int x, int y, int w, int h, std::shared_ptr texture) - : x_(x), y_(y), w_(w), h_(h), texture_(texture) -{ - // Establece el rectangulo de donde coger la imagen - spriteClip_ = {0, 0, w, h}; - - // Inicializa variables - enabled_ = true; -} + : texture_(texture), + pos_((SDL_Rect){x, y, w, h}), + sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {} Sprite::Sprite(SDL_Rect rect, std::shared_ptr texture) - : x_(rect.x), y_(rect.y), w_(rect.w), h_(rect.h), texture_(texture) -{ - // Establece el rectangulo de donde coger la imagen - spriteClip_ = {0, 0, w_, h_}; + : texture_(texture), + pos_(rect), + sprite_clip_((SDL_Rect){0, 0, pos_.w, pos_.h}) {} - // Inicializa variables - enabled_ = true; -} +Sprite::Sprite(std::shared_ptr texture) + : texture_(texture) {} // Muestra el sprite por pantalla void Sprite::render() { - if (enabled_) - { - texture_->render(x_, y_, &spriteClip_); - } + texture_->render(pos_.x, pos_.y, &sprite_clip_); } // Obten el valor de la variable int Sprite::getPosX() const { - return x_; + return pos_.x; } // Obten el valor de la variable int Sprite::getPosY() const { - return y_; + return pos_.y; } // Obten el valor de la variable int Sprite::getWidth() const { - return w_; + return pos_.w; } // Obten el valor de la variable int Sprite::getHeight() const { - return h_; + return pos_.h; } // Establece la posición del objeto void Sprite::setPos(int x, int y) { - x_ = x; - y_ = y; + pos_.x = x; + pos_.y = y; } // Establece la posición del objeto void Sprite::setPos(SDL_Point p) { - x_ = p.x; - y_ = p.y; + pos_.x = p.x; + pos_.y = p.y; } // Establece la posición del objeto void Sprite::setPos(SDL_Rect r) { - x_ = r.x; - y_ = r.y; - w_ = r.w; - h_ = r.h; + pos_ = r; } // Establece el valor de la variable void Sprite::setPosX(int x) { - x_ = x; + pos_.x = x; } // Establece el valor de la variable void Sprite::setPosY(int y) { - y_ = y; + pos_.y = y; } // Establece el valor de la variable void Sprite::setWidth(int w) { - w_ = w; + pos_.w = w; } // Establece el valor de la variable void Sprite::setHeight(int h) { - h_ = h; + pos_.h = h; } // Obten el valor de la variable SDL_Rect Sprite::getSpriteClip() const { - return spriteClip_; + return sprite_clip_; } // Establece el valor de la variable void Sprite::setSpriteClip(SDL_Rect rect) { - spriteClip_ = rect; + sprite_clip_ = rect; } // Establece el valor de la variable void Sprite::setSpriteClip(int x, int y, int w, int h) { - spriteClip_ = (SDL_Rect){x, y, w, h}; + sprite_clip_ = (SDL_Rect){x, y, w, h}; } // Obten el valor de la variable @@ -131,32 +118,20 @@ void Sprite::setTexture(std::shared_ptr texture) texture_ = texture; } -// Establece el valor de la variable -void Sprite::setEnabled(bool value) -{ - enabled_ = value; -} - -// Comprueba si el objeto está habilitado -bool Sprite::isEnabled() const -{ - return enabled_; -} - // Devuelve el rectangulo donde está el sprite -SDL_Rect Sprite::getRect() const +SDL_Rect Sprite::getPos() const { - return (SDL_Rect){x_, y_, w_, h_}; + return pos_; } // Incrementa el valor de la variable void Sprite::incPosX(int value) { - x_ += value; + pos_.x += value; } // Incrementa el valor de la variable void Sprite::incPosY(int value) { - y_ += value; + pos_.y += value; } \ No newline at end of file diff --git a/source/sprite.h b/source/sprite.h index 336bd72..cc2fffd 100644 --- a/source/sprite.h +++ b/source/sprite.h @@ -8,26 +8,22 @@ class Sprite { protected: - int x_; // Posición en el eje X donde dibujar el sprite - int y_; // Posición en el eje Y donde dibujar el sprite - int w_; // Ancho del sprite - int h_; // Alto del sprite - + // Variables std::shared_ptr texture_; // Textura donde estan todos los dibujos del sprite - SDL_Rect spriteClip_; // Rectangulo de origen de la textura que se dibujará en pantalla - - bool enabled_; // Indica si el sprite esta habilitado + SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite + SDL_Rect sprite_clip_; // Rectangulo de origen de la textura que se dibujará en pantalla public: // Constructor - Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr texture = nullptr); - Sprite(SDL_Rect rect, std::shared_ptr texture = nullptr); + explicit Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr texture = nullptr); + explicit Sprite(SDL_Rect rect, std::shared_ptr texture = nullptr); + explicit Sprite(std::shared_ptr texture = nullptr); // Destructor ~Sprite() = default; // Muestra el sprite por pantalla - void render(); + virtual void render(); // Obten el valor de la variable int getPosX() const; @@ -35,20 +31,20 @@ public: int getWidth() const; int getHeight() const; - // Establece la posición del objeto - void setPos(int x, int y); - void setPos(SDL_Point p); - void setPos(SDL_Rect r); - // Devuelve el rectangulo donde está el sprite - SDL_Rect getRect() const; - + virtual SDL_Rect getPos() const; + // Establece el valor de la variable void setPosX(int x); void setPosY(int y); void setWidth(int w); void setHeight(int h); + // Establece la posición del objeto + void setPos(int x, int y); + void setPos(SDL_Point p); + virtual void setPos(SDL_Rect r); + // Incrementa el valor de la variable void incPosX(int value); void incPosY(int value); @@ -65,11 +61,4 @@ public: // Establece el valor de la variable void setTexture(std::shared_ptr texture); - - // Establece el valor de la variable - void setEnabled(bool value); - - // Comprueba si el objeto está habilitado - bool isEnabled() const; - }; \ No newline at end of file diff --git a/source/texture.h b/source/texture.h index 309a5a7..23446db 100644 --- a/source/texture.h +++ b/source/texture.h @@ -49,7 +49,7 @@ private: public: // Constructor - Texture(SDL_Renderer *renderer, std::string path = ""); + explicit Texture(SDL_Renderer *renderer, std::string path = ""); // Destructor ~Texture();