Skip to content

Commit

Permalink
[cppcheck] Part 1: Performance
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbi committed Nov 21, 2014
1 parent 1f813f3 commit eb9172b
Show file tree
Hide file tree
Showing 30 changed files with 48 additions and 67 deletions.
4 changes: 2 additions & 2 deletions src/audio/sound_manager.cpp
Expand Up @@ -225,7 +225,7 @@ SoundManager::remove_from_update(StreamSoundSource* sss)
if( *i == sss ){
i = update_list.erase(i);
} else {
i++;
++i;
}
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ SoundManager::update()
StreamSoundSources::iterator s = update_list.begin();
while( s != update_list.end() ){
(*s)->update();
s++;
++s;
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/badguy/ghosttree.cpp
Expand Up @@ -44,7 +44,7 @@ GhostTree::GhostTree(const Reader& lisp) :
willo_radius(200),
willo_speed(1.8f),
willo_color(0),
glow_sprite(),
glow_sprite(SpriteManager::current()->create("images/creatures/ghosttree/ghosttree-glow.sprite")),
colorchange_timer(),
suck_timer(),
root_timer(),
Expand All @@ -53,7 +53,6 @@ GhostTree::GhostTree(const Reader& lisp) :
suck_lantern(0),
willowisps()
{
glow_sprite = SpriteManager::current()->create("images/creatures/ghosttree/ghosttree-glow.sprite");
set_colgroup_active(COLGROUP_TOUCHABLE);
SoundManager::current()->preload("sounds/tree_howling.ogg");
SoundManager::current()->preload("sounds/tree_suck.ogg");
Expand Down
3 changes: 1 addition & 2 deletions src/badguy/root.cpp
Expand Up @@ -25,11 +25,10 @@ static const float HATCH_TIME = 0.75;
Root::Root(const Vector& pos) :
BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1),
mystate(STATE_APPEARING),
base_sprite(),
base_sprite(SpriteManager::current()->create("images/creatures/ghosttree/root-base.sprite")),
offset_y(0),
hatch_timer()
{
base_sprite = SpriteManager::current()->create("images/creatures/ghosttree/root-base.sprite");
base_sprite->set_action("appearing", 1);
base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action
physic.enable_gravity(false);
Expand Down
2 changes: 1 addition & 1 deletion src/badguy/totem.cpp
Expand Up @@ -86,7 +86,7 @@ Totem::active_update(float elapsed_time)
Sector* s = Sector::current();
if (s) {
// jump a bit if we find a suitable totem
for (std::vector<MovingObject*>::iterator i = s->moving_objects.begin(); i != s->moving_objects.end(); i++) {
for (std::vector<MovingObject*>::iterator i = s->moving_objects.begin(); i != s->moving_objects.end(); ++i) {
Totem* t = dynamic_cast<Totem*>(*i);
if (!t) continue;

Expand Down
9 changes: 3 additions & 6 deletions src/object/ambient_sound.cpp
Expand Up @@ -27,10 +27,10 @@
#include "util/reader.hpp"

AmbientSound::AmbientSound(const Reader& lisp) :
name(),
name(""),
position(),
dimension(),
sample(),
sample(""),
sound_source(),
latency(),
distance_factor(),
Expand All @@ -41,7 +41,6 @@ AmbientSound::AmbientSound(const Reader& lisp) :
currentvolume(),
volume_ptr()
{
name="";
position.x = 0;
position.y = 0;

Expand All @@ -51,7 +50,6 @@ AmbientSound::AmbientSound(const Reader& lisp) :
distance_factor = 0;
distance_bias = 0;
maximumvolume = 1;
sample = "";
currentvolume = 0;

if (!(lisp.get("x", position.x)&&lisp.get("y", position.y))) {
Expand Down Expand Up @@ -97,7 +95,7 @@ AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std:
name(),
position(),
dimension(),
sample(),
sample(file),
sound_source(),
latency(),
distance_factor(),
Expand All @@ -117,7 +115,6 @@ AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std:
distance_factor=factor*factor;
distance_bias=bias*bias;
maximumvolume=vol;
sample=file;

// set default silence_distance

Expand Down
4 changes: 1 addition & 3 deletions src/object/cloud_particle_system.cpp
Expand Up @@ -24,10 +24,8 @@

CloudParticleSystem::CloudParticleSystem() :
ParticleSystem(128),
cloudimage()
cloudimage(Surface::create("images/objects/particles/cloud.png"))
{
cloudimage = Surface::create("images/objects/particles/cloud.png");

virtual_width = 2000.0;

// create some random clouds
Expand Down
4 changes: 1 addition & 3 deletions src/object/coin_rain.cpp
Expand Up @@ -25,15 +25,13 @@
static const float DROP_TIME = .1f; // time duration between "drops" of coin rain

CoinRain::CoinRain(const Vector& pos, bool emerge) :
sprite(),
sprite(SpriteManager::current()->create("images/objects/coin/coin.sprite")),
position(pos),
emerge_distance(0),
timer(),
counter(0),
drop(0)
{
sprite = SpriteManager::current()->create("images/objects/coin/coin.sprite");

if(emerge) {
emerge_distance = sprite->get_height();
}
Expand Down
6 changes: 2 additions & 4 deletions src/object/falling_coin.cpp
Expand Up @@ -21,11 +21,9 @@

FallingCoin::FallingCoin(const Vector& start_position, const int vel_x) :
physic(),
pos(),
sprite()
pos(start_position),
sprite(SpriteManager::current()->create("images/objects/coin/coin.sprite"))
{
pos = start_position;
sprite = SpriteManager::current()->create("images/objects/coin/coin.sprite");
physic.set_velocity_y(-800);
physic.set_velocity_x(vel_x);
}
Expand Down
4 changes: 2 additions & 2 deletions src/object/infoblock.cpp
Expand Up @@ -53,7 +53,7 @@ InfoBlock::InfoBlock(const Reader& lisp) :

InfoBlock::~InfoBlock()
{
for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); i++) {
for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); ++i) {
delete *i;
}
}
Expand All @@ -73,7 +73,7 @@ InfoBlock::hit(Player& player)
// first hide all other InfoBlocks' messages in same sector
Sector* parent = Sector::current();
if (!parent) return;
for (Sector::GameObjects::iterator i = parent->gameobjects.begin(); i != parent->gameobjects.end(); i++) {
for (Sector::GameObjects::iterator i = parent->gameobjects.begin(); i != parent->gameobjects.end(); ++i) {
InfoBlock* block = dynamic_cast<InfoBlock*>(i->get());
if (!block) continue;
if (block != this) block->hide_message();
Expand Down
2 changes: 1 addition & 1 deletion src/object/ispy.cpp
Expand Up @@ -118,7 +118,7 @@ Ispy::free_line_of_sight(Vector line_start, Vector line_end, const MovingObject*
std::list<TileMap*> solid_tilemaps = Sector::current()->solid_tilemaps;
for (float test_x = lsx; test_x <= lex; test_x += 16) {
for (float test_y = lsy; test_y <= ley; test_y += 16) {
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); i++) {
for(std::list<TileMap*>::const_iterator i = solid_tilemaps.begin(); i != solid_tilemaps.end(); ++i) {
TileMap* solids = *i;
const Tile* tile = solids->get_tile_at(Vector(test_x, test_y));
if(!tile) continue;
Expand Down
3 changes: 1 addition & 2 deletions src/object/lantern.cpp
Expand Up @@ -42,9 +42,8 @@ Lantern::Lantern(const Reader& reader) :
Lantern::Lantern(const Vector& pos) :
Rock(pos, "images/objects/lantern/lantern.sprite"),
lightcolor(0.0f, 0.0f, 0.0f),
lightsprite()
lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light.sprite"))
{
lightsprite = SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light.sprite");
lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
updateColor();
SoundManager::current()->preload("sounds/willocatch.wav");
Expand Down
3 changes: 1 addition & 2 deletions src/object/moving_sprite.cpp
Expand Up @@ -79,10 +79,9 @@ MovingSprite::MovingSprite(const Reader& reader, int layer_, CollisionGroup coll
MovingSprite::MovingSprite(const MovingSprite& other) :
MovingObject(other),
sprite_name(),
sprite(),
sprite(other.sprite->clone()),
layer(other.layer)
{
sprite = other.sprite->clone();
}
/*
MovingSprite&
Expand Down
4 changes: 2 additions & 2 deletions src/object/particles.cpp
Expand Up @@ -65,7 +65,7 @@ Particles::~Particles()
{
// free particles
for(std::vector<Particle*>::iterator i = particles.begin();
i < particles.end(); i++)
i < particles.end(); ++i)
delete (*i);
}

Expand Down Expand Up @@ -101,7 +101,7 @@ Particles::draw(DrawingContext& context)
{
// draw particles
for(std::vector<Particle*>::iterator i = particles.begin();
i != particles.end(); i++) {
i != particles.end(); ++i) {
context.draw_filled_rect((*i)->pos, Vector(size,size), color,drawing_layer);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/object/particlesystem_interactive.cpp
Expand Up @@ -80,7 +80,7 @@ ParticleSystem_Interactive::collision(Particle* object, Vector movement)
dest.move(movement);
Constraints constraints;

for(std::list<TileMap*>::const_iterator i = Sector::current()->solid_tilemaps.begin(); i != Sector::current()->solid_tilemaps.end(); i++) {
for(std::list<TileMap*>::const_iterator i = Sector::current()->solid_tilemaps.begin(); i != Sector::current()->solid_tilemaps.end(); ++i) {
TileMap* solids = *i;
// FIXME Handle a nonzero tilemap offset
for(int x = starttilex; x*32 < max_x; ++x) {
Expand Down
4 changes: 2 additions & 2 deletions src/object/path.cpp
Expand Up @@ -99,7 +99,7 @@ Path::get_nearest_node_no(Vector reference_point) const
int nearest_node_id = -1;
float nearest_node_dist = 0;
int id = 0;
for (std::vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) {
for (std::vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); ++i, ++id) {
float dist = (i->position - reference_point).norm();
if ((nearest_node_id == -1) || (dist < nearest_node_dist)) {
nearest_node_id = id;
Expand All @@ -115,7 +115,7 @@ Path::get_farthest_node_no(Vector reference_point) const
int farthest_node_id = -1;
float farthest_node_dist = 0;
int id = 0;
for (std::vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); i++, id++) {
for (std::vector<Node>::const_iterator i = nodes.begin(); i != nodes.end(); ++i, ++id) {
float dist = (i->position - reference_point).norm();
if ((farthest_node_id == -1) || (dist > farthest_node_dist)) {
farthest_node_id = id;
Expand Down
6 changes: 2 additions & 4 deletions src/object/rainsplash.cpp
Expand Up @@ -18,11 +18,9 @@

RainSplash::RainSplash(Vector pos, bool vertical) :
sprite(),
position(),
frame()
position(pos),
frame(0)
{
frame = 0;
position = pos;
if (vertical) sprite = SpriteManager::current()->create("images/objects/particles/rainsplash-vertical.sprite");
else sprite = SpriteManager::current()->create("images/objects/particles/rainsplash.sprite");
}
Expand Down
2 changes: 1 addition & 1 deletion src/sprite/sprite_data.cpp
Expand Up @@ -143,7 +143,7 @@ SpriteData::parse_action(const Reader& lisp, const std::string& basedir)
}

const SpriteData::Action*
SpriteData::get_action(const std::string act)
SpriteData::get_action(const std::string& act)
{
Actions::iterator i = actions.find(act);
if(i == actions.end()) {
Expand Down
2 changes: 1 addition & 1 deletion src/sprite/sprite_data.hpp
Expand Up @@ -68,7 +68,7 @@ class SpriteData

void parse_action(const Reader& lispreader, const std::string& basedir);
/** Get an action */
const Action* get_action(const std::string act);
const Action* get_action(const std::string& act);

Actions actions;
std::string name;
Expand Down
6 changes: 3 additions & 3 deletions src/supertux/console.cpp
Expand Up @@ -257,11 +257,11 @@ void
Console::show_history(int offset_)
{
while ((offset_ > 0) && (m_history_position != m_history.end())) {
m_history_position++;
++m_history_position;
offset_--;
}
while ((offset_ < 0) && (m_history_position != m_history.begin())) {
m_history_position--;
--m_history_position;
offset_++;
}
if (m_history_position == m_history.end()) {
Expand Down Expand Up @@ -561,7 +561,7 @@ Console::draw(DrawingContext& context)
}

int skipLines = -m_offset;
for (std::list<std::string>::iterator i = m_buffer.m_lines.begin(); i != m_buffer.m_lines.end(); i++)
for (std::list<std::string>::iterator i = m_buffer.m_lines.begin(); i != m_buffer.m_lines.end(); ++i)
{
if (skipLines-- > 0) continue;
lineNo++;
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/flip_level_transformer.cpp
Expand Up @@ -87,7 +87,7 @@ FlipLevelTransformer::transform_drawing_effect(DrawingEffect effect)
void
FlipLevelTransformer::transform_path(float height, float obj_height, Path& path)
{
for (std::vector<Path::Node>::iterator i = path.nodes.begin(); i != path.nodes.end(); i++) {
for (std::vector<Path::Node>::iterator i = path.nodes.begin(); i != path.nodes.end(); ++i) {
Vector& pos = i->position;
pos.y = height - pos.y - obj_height;
}
Expand Down
8 changes: 3 additions & 5 deletions src/supertux/info_box.cpp
Expand Up @@ -24,14 +24,12 @@

InfoBox::InfoBox(const std::string& text) :
firstline(0),
lines(),
// Split text string lines into a vector
lines(InfoBoxLine::split(text, 400)),
images(),
arrow_scrollup(),
arrow_scrolldown()
{
// Split text string lines into a vector
lines = InfoBoxLine::split(text, 400);

try
{
// get the arrow sprites
Expand All @@ -49,7 +47,7 @@ InfoBox::InfoBox(const std::string& text) :
InfoBox::~InfoBox()
{
for(std::vector<InfoBoxLine*>::iterator i = lines.begin();
i != lines.end(); i++)
i != lines.end(); ++i)
delete *i;
}

Expand Down
3 changes: 1 addition & 2 deletions src/supertux/info_box_line.cpp
Expand Up @@ -89,12 +89,11 @@ InfoBoxLine::LineType get_linetype_by_format_char(char format_char) {

InfoBoxLine::InfoBoxLine(char format_char, const std::string& text_) :
lineType(NORMAL),
font(Resources::normal_font),
font(get_font_by_format_char(format_char)),
color(),
text(text_),
image()
{
font = get_font_by_format_char(format_char);
lineType = get_linetype_by_format_char(format_char);
color = get_color_by_format_char(format_char);
if (lineType == IMAGE)
Expand Down
3 changes: 1 addition & 2 deletions src/supertux/levelintro.cpp
Expand Up @@ -31,12 +31,11 @@
LevelIntro::LevelIntro(const Level* level_, const Statistics* best_level_statistics_) :
level(level_),
best_level_statistics(best_level_statistics_),
player_sprite(),
player_sprite(SpriteManager::current()->create("images/creatures/tux/tux.sprite")),
player_sprite_py(0),
player_sprite_vy(0),
player_sprite_jump_timer()
{
player_sprite = SpriteManager::current()->create("images/creatures/tux/tux.sprite");
player_sprite->set_action("small-walk-right");
player_sprite_jump_timer.start(graphicsRandom.randf(5,10));
}
Expand Down
4 changes: 2 additions & 2 deletions src/supertux/menu/language_menu.cpp
Expand Up @@ -40,7 +40,7 @@ LanguageMenu::LanguageMenu()

int mnid = MNID_LANGUAGE_NEXT;
std::set<tinygettext::Language> languages = g_dictionary_manager->get_languages();
for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++)
for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); ++i)
{
add_entry(mnid++, i->get_name());
}
Expand Down Expand Up @@ -76,7 +76,7 @@ LanguageMenu::menu_action(MenuItem* item)
int mnid = MNID_LANGUAGE_NEXT;
std::set<tinygettext::Language> languages = g_dictionary_manager->get_languages();

for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); i++)
for (std::set<tinygettext::Language>::iterator i = languages.begin(); i != languages.end(); ++i)
{
if (item->id == mnid++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/textscroller.cpp
Expand Up @@ -81,7 +81,7 @@ TextScroller::TextScroller(const std::string& filename) :

TextScroller::~TextScroller()
{
for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); i++) delete *i;
for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); ++i) delete *i;
}

void
Expand Down
2 changes: 1 addition & 1 deletion src/supertux/tile.cpp
Expand Up @@ -154,7 +154,7 @@ Tile::print_debug(int id) const
* in quotation marks because because the slope's gradient is taken.
* Also, this uses the movement relative to the tilemaps own movement
* (if any). --octo */
bool Tile::check_movement_unisolid (const Vector movement) const
bool Tile::check_movement_unisolid (const Vector& movement) const
{
int slope_info;
double mv_x;
Expand Down

0 comments on commit eb9172b

Please sign in to comment.