projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix frame out of range error for -O2 release build (may or may not fix on other syste...
[supertux.git]
/
src
/
sprite
/
sprite.cpp
diff --git
a/src/sprite/sprite.cpp
b/src/sprite/sprite.cpp
index
abf3c93
..
16e1ada
100644
(file)
--- a/
src/sprite/sprite.cpp
+++ b/
src/sprite/sprite.cpp
@@
-87,12
+87,12
@@
Sprite::set_action_continued(const std::string& name)
}
action = newaction;
}
action = newaction;
- if(frame >= get_frames()) {
- frame = fmodf(frame, get_frames());
-
- if (animation_loops > 0) animation_loops--;
+ while(frame >= get_frames()) {
+ frame -= get_frames();
+ animation_loops--;
if(animation_done())
frame = get_frames()-1;
if(animation_done())
frame = get_frames()-1;
+ break;
}
}
}
}
@@
-105,20
+105,22
@@
Sprite::animation_done()
void
Sprite::update()
{
void
Sprite::update()
{
- if(animation_done())
+ if(animation_done()) {
+ frame = get_frames()-1;
return;
return;
+ }
float frame_inc = action->fps * (game_time - last_ticks);
last_ticks = game_time;
frame += frame_inc;
float frame_inc = action->fps * (game_time - last_ticks);
last_ticks = game_time;
frame += frame_inc;
- if(frame >= get_frames()) {
- frame = fmodf(frame, get_frames());
-
+ while(frame >= get_frames()) {
+ frame -= get_frames();
animation_loops--;
if(animation_done())
frame = get_frames()-1;
animation_loops--;
if(animation_done())
frame = get_frames()-1;
+ break;
}
}
}
}
@@
-130,7
+132,7
@@
Sprite::draw(DrawingContext& context, const Vector& pos, int layer,
update();
if((int)frame >= get_frames() || (int)frame < 0)
update();
if((int)frame >= get_frames() || (int)frame < 0)
- log_warning << "frame out of range: " <<
(int)
frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+ log_warning << "frame out of range: " << frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
else {
context.set_drawing_effect(effect);
context.draw_surface(action->surfaces[(int)frame],
else {
context.set_drawing_effect(effect);
context.draw_surface(action->surfaces[(int)frame],
@@
-167,7
+169,7
@@
Sprite::get_width() const
{
if((int)frame >= get_frames() || (int)frame < 0)
{
{
if((int)frame >= get_frames() || (int)frame < 0)
{
- log_warning << "frame out of range: " <<
(int)
frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+ log_warning << "frame out of range: " << frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
return 0;
}
else
return 0;
}
else
@@
-181,7
+183,7
@@
Sprite::get_height() const
{
if((int)frame >= get_frames() || (int)frame < 0)
{
{
if((int)frame >= get_frames() || (int)frame < 0)
{
- log_warning << "frame out of range: " <<
(int)
frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+ log_warning << "frame out of range: " << frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
return 0;
}
else
return 0;
}
else