Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Naur supertux-0.1.3/src.bak/badguy.cpp supertux-0.1.3/src/badguy.cpp
- --- supertux-0.1.3/src.bak/badguy.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/badguy.cpp 2014-12-07 13:03:28.000000000 -0500
- @@ -33,6 +33,7 @@
- #include "tile.h"
- #include "resources.h"
- #include "sprite_manager.h"
- +#include "fpmath.h"
- Sprite* img_mriceblock_flat_left;
- Sprite* img_mriceblock_flat_right;
- @@ -65,8 +66,6 @@
- Sprite* img_snowball_squished_left;
- Sprite* img_snowball_squished_right;
- -#define BADGUY_WALK_SPEED .8f
- -
- BadGuyKind badguykind_from_string(const std::string& str)
- {
- if (str == "money" || str == "jumpy") // was money in old maps
- @@ -135,7 +134,7 @@
- }
- }
- -BadGuy::BadGuy(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
- +BadGuy::BadGuy(fp x, fp y, BadGuyKind kind_, bool stay_on_platform_)
- : removable(false), squishcount(0)
- {
- base.x = x;
- @@ -158,10 +157,10 @@
- timer.init(true);
- if(kind == BAD_MRBOMB) {
- - physic.set_velocity(-BADGUY_WALK_SPEED, 0);
- + physic.set_velocity(-FP_BADGUY_WALK_SPEED, 0);
- set_sprite(img_mrbomb_left, img_mrbomb_right);
- } else if (kind == BAD_MRICEBLOCK) {
- - physic.set_velocity(-BADGUY_WALK_SPEED, 0);
- + physic.set_velocity(-FP_BADGUY_WALK_SPEED, 0);
- set_sprite(img_mriceblock_left, img_mriceblock_right);
- } else if(kind == BAD_JUMPY) {
- set_sprite(img_jumpy_left_up, img_jumpy_left_up);
- @@ -174,7 +173,7 @@
- physic.enable_gravity(false);
- set_sprite(img_flame, img_flame);
- } else if(kind == BAD_BOUNCINGSNOWBALL) {
- - physic.set_velocity(-1.3, 0);
- + physic.set_velocity(-FP_BOUNCINGSNOWBALL_SPEED, 0);
- set_sprite(img_bouncingsnowball_left, img_bouncingsnowball_right);
- } else if(kind == BAD_STALACTITE) {
- physic.enable_gravity(false);
- @@ -186,10 +185,10 @@
- set_sprite(img_flyingsnowball, img_flyingsnowball);
- physic.enable_gravity(false);
- } else if(kind == BAD_SPIKY) {
- - physic.set_velocity(-BADGUY_WALK_SPEED, 0);
- + physic.set_velocity(-FP_BADGUY_WALK_SPEED, 0);
- set_sprite(img_spiky_left, img_spiky_right);
- } else if(kind == BAD_SNOWBALL) {
- - physic.set_velocity(-BADGUY_WALK_SPEED, 0);
- + physic.set_velocity(-FP_BADGUY_WALK_SPEED, 0);
- set_sprite(img_snowball_left, img_snowball_right);
- }
- @@ -197,14 +196,17 @@
- if(kind != BAD_FLAME && kind != BAD_FISH && collision_object_map(base))
- {
- std::cout << "Warning: badguy started in wall: kind: " << badguykind_to_string(kind)
- - << " pos: (" << base.x << ", " << base.y << ")" << std::endl;
- - while(collision_object_map(base))
- - --base.y;
- + << " pos: (" << fp2float(base.x) << ", " << fp2float(base.y) << ")" << std::endl;
- + while(collision_object_map(base)) {
- + //FIXME: check use of --
- + //--base.y;
- + base.y -= int2fp(1);
- + }
- }
- }
- void
- -BadGuy::action_mriceblock(double frame_ratio)
- +BadGuy::action_mriceblock(fp frame_ratio)
- {
- Player& tux = *World::current()->get_tux();
- @@ -225,32 +227,32 @@
- dir = tux.dir;
- if(dir==RIGHT)
- {
- - base.x = tux.base.x + 16;
- - base.y = tux.base.y + tux.base.height/1.5 - base.height;
- + base.x = tux.base.x + int2fp(16);
- + base.y = tux.base.y + tux.base.height*2/3 - base.height;
- }
- else /* facing left */
- {
- - base.x = tux.base.x - 16;
- - base.y = tux.base.y + tux.base.height/1.5 - base.height;
- + base.x = tux.base.x - int2fp(16);
- + base.y = tux.base.y + tux.base.height*2/3 - base.height;
- }
- if(collision_object_map(base))
- {
- base.x = tux.base.x;
- - base.y = tux.base.y + tux.base.height/1.5 - base.height;
- + base.y = tux.base.y + tux.base.height*2/3 - base.height;
- }
- if(tux.input.fire != DOWN) /* SHOOT! */
- {
- if(dir == LEFT)
- - base.x -= 24;
- + base.x -= int2fp(24);
- else
- - base.x += 24;
- + base.x += int2fp(24);
- old_base = base;
- mode=KICK;
- tux.kick_timer.start(KICKING_TIME);
- set_sprite(img_mriceblock_flat_left, img_mriceblock_flat_right);
- - physic.set_velocity_x((dir == LEFT) ? -3.5 : 3.5);
- + physic.set_velocity_x((dir == LEFT) ? -FP_MRICEBLOCK_SPEED : FP_MRICEBLOCK_SPEED);
- #ifndef GP2X
- play_sound(sounds[SND_KICK],SOUND_CENTER_SPEAKER);
- #else
- @@ -267,9 +269,9 @@
- {
- #ifndef GP2X
- /* handle stereo sound (number 10 should be tweaked...)*/
- - if (base.x < scroll_x + screen->w/2 - 10)
- + if (base.x < scroll_x + int2fp(screen->w/2 - 10))
- play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
- - else if (base.x > scroll_x + screen->w/2 + 10)
- + else if (base.x > scroll_x + int2fp(screen->w/2 + 10))
- play_sound(sounds[SND_RICOCHET], SOUND_RIGHT_SPEAKER);
- else
- play_sound(sounds[SND_RICOCHET], SOUND_CENTER_SPEAKER);
- @@ -286,7 +288,7 @@
- {
- mode = NORMAL;
- set_sprite(img_mriceblock_left, img_mriceblock_right);
- - physic.set_velocity( (dir == LEFT) ? -.8 : .8, 0);
- + physic.set_velocity( (dir == LEFT) ? -FP_BADGUY_WALK_SPEED : FP_BADGUY_WALK_SPEED, 0);
- }
- }
- }
- @@ -294,8 +296,8 @@
- void
- BadGuy::check_horizontal_bump(bool checkcliff)
- {
- - float halfheight = base.height / 2;
- - if (dir == LEFT && issolid( base.x, (int) base.y + halfheight))
- + fp halfheight = base.height / 2;
- + if (dir == LEFT && issolid(fp2int(base.x), fp2int(base.y + halfheight)))
- {
- if (kind == BAD_MRICEBLOCK && mode == KICK)
- World::current()->trybreakbrick(base.x, base.y + halfheight, false, dir);
- @@ -304,10 +306,10 @@
- physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
- return;
- }
- - if (dir == RIGHT && issolid( base.x + base.width, (int)base.y + halfheight))
- + if (dir == RIGHT && issolid(fp2int(base.x + base.width), fp2int(base.y + halfheight)))
- {
- if (kind == BAD_MRICEBLOCK && mode == KICK)
- - World::current()->trybreakbrick(base.x + base.width, (int) base.y + halfheight, false, dir);
- + World::current()->trybreakbrick(base.x + base.width, base.y + halfheight, false, dir);
- dir = LEFT;
- physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
- @@ -317,17 +319,17 @@
- // don't check for cliffs when we're falling
- if(!checkcliff)
- return;
- - if(!issolid(base.x + base.width/2, base.y + base.height))
- + if(!issolid(fp2int(base.x + base.width/2), fp2int(base.y + base.height)))
- return;
- - if(dir == LEFT && !issolid(base.x, (int) base.y + base.height + halfheight))
- + if(dir == LEFT && !issolid(fp2int(base.x), fp2int(base.y + base.height + halfheight)))
- {
- dir = RIGHT;
- physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
- return;
- }
- - if(dir == RIGHT && !issolid(base.x + base.width,
- - (int) base.y + base.height + halfheight))
- + if(dir == RIGHT && !issolid(fp2int(base.x + base.width),
- + fp2int(base.y + base.height + halfheight)))
- {
- dir = LEFT;
- physic.set_velocity(-physic.get_velocity_x(), physic.get_velocity_y());
- @@ -341,7 +343,7 @@
- /* Fall if we get off the ground: */
- if (dying != DYING_FALLING)
- {
- - if (!issolid(base.x+base.width/2, base.y + base.height))
- + if (!issolid(fp2int(base.x+base.width/2), fp2int(base.y + base.height)))
- {
- // not solid below us? enable gravity
- physic.enable_gravity(true);
- @@ -349,9 +351,12 @@
- else
- {
- /* Land: */
- + /* Always pull badguys out of the ground, otherwise they still
- + * get stuck on slow systems. */
- + base.y = int2fp((fp2int(base.y) / 32) * 32);
- if (physic.get_velocity_y() < 0)
- {
- - base.y = int((base.y + base.height)/32) * 32 - base.height;
- + //base.y = int2fp(fp2int(base.y + base.height)/32) * 32 - base.height;
- physic.set_velocity_y(0);
- }
- // no gravity anymore please
- @@ -359,18 +364,18 @@
- if (stay_on_platform && mode == NORMAL)
- {
- - if (!issolid(base.x + ((dir == LEFT) ? 0 : base.width),
- - base.y + base.height))
- + if (!issolid(fp2int(base.x + ((dir == LEFT) ? 0 : base.width)),
- + fp2int(base.y + base.height)))
- {
- if (dir == LEFT)
- {
- dir = RIGHT;
- - physic.set_velocity_x(fabsf(physic.get_velocity_x()));
- + physic.set_velocity_x(abs(physic.get_velocity_x()));
- }
- else
- {
- dir = LEFT;
- - physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
- + physic.set_velocity_x(-abs(physic.get_velocity_x()));
- }
- }
- }
- @@ -389,27 +394,25 @@
- }
- void
- -BadGuy::action_jumpy(double frame_ratio)
- +BadGuy::action_jumpy(fp frame_ratio)
- {
- - const float vy = physic.get_velocity_y();
- + const fp vy = physic.get_velocity_y();
- // XXX: These tests *should* use location from ground, not velocity
- - if (fabsf(vy) > 5.6f)
- + if (abs(vy) > FP_JUMP_SPEED_START)
- set_sprite(img_jumpy_left_down, img_jumpy_left_down);
- - else if (fabsf(vy) > 5.3f)
- + else if (abs(vy) > FP_JUMP_SPEED_MIDDLE)
- set_sprite(img_jumpy_left_middle, img_jumpy_left_middle);
- else
- set_sprite(img_jumpy_left_up, img_jumpy_left_up);
- Player& tux = *World::current()->get_tux();
- - static const float JUMPV = 6;
- -
- fall();
- // jump when on ground
- - if(dying == DYING_NOT && issolid(base.x, base.y+32))
- + if(dying == DYING_NOT && issolid(fp2int(base.x), fp2int(base.y)+32))
- {
- - physic.set_velocity_y(JUMPV);
- + physic.set_velocity_y(FP_JUMP_SPEED);
- physic.enable_gravity(true);
- mode = JUMPY_JUMP;
- @@ -432,7 +435,7 @@
- }
- void
- -BadGuy::action_mrbomb(double frame_ratio)
- +BadGuy::action_mrbomb(fp frame_ratio)
- {
- if (dying == DYING_NOT)
- check_horizontal_bump(true);
- @@ -445,7 +448,7 @@
- }
- void
- -BadGuy::action_bomb(double frame_ratio)
- +BadGuy::action_bomb(fp frame_ratio)
- {
- static const int TICKINGTIME = 1000;
- static const int EXPLODETIME = 1000;
- @@ -463,10 +466,10 @@
- timer.start(EXPLODETIME);
- /* play explosion sound */ // FIXME: is the stereo all right? maybe we should use player cordinates...
- - if (base.x < scroll_x + screen->w/2 - 10)
- + if (base.x < scroll_x + int2fp(screen->w/2 - 10))
- #ifndef GP2X
- play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
- - else if (base.x > scroll_x + screen->w/2 + 10)
- + else if (base.x > scroll_x + int2fp(screen->w/2 + 10))
- play_sound(sounds[SND_EXPLODE], SOUND_RIGHT_SPEAKER);
- else
- play_sound(sounds[SND_EXPLODE], SOUND_CENTER_SPEAKER);
- @@ -481,12 +484,12 @@
- }
- // move
- - physic.apply(frame_ratio, base.x, base.y);
- + physic.apply(frame_ratio, base.x, base.y);
- collision_swept_object_map(&old_base,&base);
- }
- void
- -BadGuy::action_stalactite(double frame_ratio)
- +BadGuy::action_stalactite(fp frame_ratio)
- {
- Player& tux = *World::current()->get_tux();
- @@ -496,20 +499,20 @@
- if(mode == NORMAL) {
- // start shaking when tux is below the stalactite and at least 40 pixels
- // near
- - if(tux.base.x + 32 > base.x - RANGE && tux.base.x < base.x + 32 + RANGE
- + if(tux.base.x + int2fp(32) > base.x - int2fp(RANGE) && tux.base.x < base.x + int2fp(32) + int2fp(RANGE)
- && tux.base.y + tux.base.height > base.y) {
- timer.start(SHAKETIME);
- mode = STALACTITE_SHAKING;
- }
- } if(mode == STALACTITE_SHAKING) {
- - base.x = old_base.x + (rand() % 6) - 3; // TODO this could be done nicer...
- + base.x = old_base.x + int2fp((rand() % 6) - 3); // TODO this could be done nicer...
- if(!timer.check()) {
- mode = STALACTITE_FALL;
- }
- } else if(mode == STALACTITE_FALL) {
- fall();
- /* Destroy if we collides with land */
- - if(issolid(base.x+base.width/2, base.y+base.height))
- + if(issolid(fp2int(base.x+base.width/2), fp2int(base.y+base.height)))
- {
- timer.start(2000);
- dying = DYING_SQUISHED;
- @@ -528,24 +531,21 @@
- }
- void
- -BadGuy::action_flame(double frame_ratio)
- +BadGuy::action_flame(fp frame_ratio)
- {
- - static const float radius = 100;
- - static const float speed = 0.02;
- - base.x = old_base.x + cos(base.ym) * radius;
- - base.y = old_base.y + sin(base.ym) * radius;
- + base.x = old_base.x + fpcos(base.ym * 256 / (2*FP_PI)) * FLAME_RADIUS;
- + base.y = old_base.y + fpsin(base.ym * 256 / (2*FP_PI)) * FLAME_RADIUS;
- - base.ym = fmodf(base.ym + frame_ratio * speed, 2*M_PI);
- + base.ym = (base.ym + fpmul(frame_ratio, FP_FLAME_SPEED)) % (2*FP_PI);
- }
- void
- -BadGuy::action_fish(double frame_ratio)
- +BadGuy::action_fish(fp frame_ratio)
- {
- - static const float JUMPV = 6;
- static const int WAITTIME = 1000;
- // go in wait mode when back in water
- - if(dying == DYING_NOT && gettile(base.x, base.y+ base.height)->water
- + if(dying == DYING_NOT && gettile(fp2int(base.x), fp2int(base.y+ base.height))->water
- && physic.get_velocity_y() <= 0 && mode == NORMAL)
- {
- mode = FISH_WAIT;
- @@ -559,7 +559,7 @@
- // jump again
- set_sprite(img_fish, img_fish);
- mode = NORMAL;
- - physic.set_velocity(0, JUMPV);
- + physic.set_velocity(0, FP_JUMP_SPEED);
- physic.enable_gravity(true);
- }
- @@ -572,16 +572,14 @@
- }
- void
- -BadGuy::action_bouncingsnowball(double frame_ratio)
- +BadGuy::action_bouncingsnowball(fp frame_ratio)
- {
- - static const float JUMPV = 4.5;
- -
- fall();
- // jump when on ground
- - if(dying == DYING_NOT && issolid(base.x, base.y+32))
- + if(dying == DYING_NOT && issolid(fp2int(base.x), fp2int(base.y)+32))
- {
- - physic.set_velocity_y(JUMPV);
- + physic.set_velocity_y(FP_SNOWBALL_JUMP_SPEED);
- physic.enable_gravity(true);
- }
- else
- @@ -606,25 +604,24 @@
- }
- void
- -BadGuy::action_flyingsnowball(double frame_ratio)
- +BadGuy::action_flyingsnowball(fp frame_ratio)
- {
- - static const float FLYINGSPEED = 1;
- static const int DIRCHANGETIME = 1000;
- // go into flyup mode if none specified yet
- if(dying == DYING_NOT && mode == NORMAL) {
- mode = FLY_UP;
- - physic.set_velocity_y(FLYINGSPEED);
- + physic.set_velocity_y(FP_FLYING_SPEED);
- timer.start(DIRCHANGETIME/2);
- }
- if(dying == DYING_NOT && !timer.check()) {
- if(mode == FLY_UP) {
- mode = FLY_DOWN;
- - physic.set_velocity_y(-FLYINGSPEED);
- + physic.set_velocity_y(-FP_FLYING_SPEED);
- } else if(mode == FLY_DOWN) {
- mode = FLY_UP;
- - physic.set_velocity_y(FLYINGSPEED);
- + physic.set_velocity_y(FP_FLYING_SPEED);
- }
- timer.start(DIRCHANGETIME);
- }
- @@ -646,7 +643,7 @@
- }
- void
- -BadGuy::action_spiky(double frame_ratio)
- +BadGuy::action_spiky(fp frame_ratio)
- {
- if (dying == DYING_NOT)
- check_horizontal_bump();
- @@ -655,9 +652,9 @@
- #if 0
- // jump when we're about to fall
- if (physic.get_velocity_y() == 0 &&
- - !issolid(base.x+base.width/2, base.y + base.height)) {
- + !issolid(fp2int(base.x+base.width/2), fp2int(base.y + base.height))) {
- physic.enable_gravity(true);
- - physic.set_velocity_y(2);
- + physic.set_velocity_y(FP_SPIKY_JUMP_SPEED);
- }
- #endif
- @@ -667,7 +664,7 @@
- }
- void
- -BadGuy::action_snowball(double frame_ratio)
- +BadGuy::action_snowball(fp frame_ratio)
- {
- if (dying == DYING_NOT)
- check_horizontal_bump();
- @@ -680,10 +677,10 @@
- }
- void
- -BadGuy::action(double frame_ratio)
- +BadGuy::action(fp frame_ratio)
- {
- // Remove if it's far off the screen:
- - if (base.x < scroll_x - OFFSCREEN_DISTANCE)
- + if (base.x < scroll_x - int2fp(OFFSCREEN_DISTANCE))
- {
- remove_me();
- return;
- @@ -691,9 +688,9 @@
- // BadGuy fall below the ground
- #ifndef RES320X240
- - if (base.y > screen->h) {
- + if (base.y > int2fp(screen->h)) {
- #else
- - if (base.y > 640) {
- + if (base.y > int2fp(640)) {
- #endif
- remove_me();
- return;
- @@ -701,9 +698,9 @@
- // Once it's on screen, it's activated!
- #ifndef RES320X240
- - if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
- + if (base.x <= scroll_x + int2fp(screen->w + OFFSCREEN_DISTANCE))
- #else
- - if (base.x <= scroll_x + 640 + OFFSCREEN_DISTANCE)
- + if (base.x <= scroll_x + int2fp(640 + OFFSCREEN_DISTANCE))
- #endif
- seen = true;
- @@ -765,9 +762,9 @@
- {
- // Don't try to draw stuff that is outside of the screen
- #ifndef RES320X240
- - if(base.x <= scroll_x - base.width || base.x >= scroll_x + screen->w)
- + if(base.x <= scroll_x - base.width || base.x >= scroll_x + int2fp(screen->w))
- #else
- - if(base.x <= scroll_x - base.width || base.x >= scroll_x + 640)
- + if(base.x <= scroll_x - base.width || base.x >= scroll_x + int2fp(640))
- #endif
- return;
- @@ -777,10 +774,10 @@
- }
- Sprite* sprite = (dir == LEFT) ? sprite_left : sprite_right;
- - sprite->draw(base.x - scroll_x, base.y);
- + sprite->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- if (debug_mode)
- - fillrect(base.x - scroll_x, base.y, base.width, base.height, 75,0,75, 150);
- + fillrect(fp2int(base.x - scroll_x), fp2int(base.y), fp2int(base.width), fp2int(base.height), 75,0,75, 150);
- }
- void
- @@ -788,8 +785,8 @@
- {
- if (1)
- {
- - base.width = 32;
- - base.height = 32;
- + base.width = int2fp(32);
- + base.height = int2fp(32);
- }
- else
- {
- @@ -798,13 +795,13 @@
- // representation
- if(left != 0) {
- if(base.width == 0 && base.height == 0) {
- - base.width = left->get_width();
- - base.height = left->get_height();
- - } else if(base.width != left->get_width() || base.height != left->get_height()) {
- - base.x -= (left->get_width() - base.width) / 2;
- - base.y -= left->get_height() - base.height;
- - base.width = left->get_width();
- - base.height = left->get_height();
- + base.width = int2fp(left->get_width());
- + base.height = int2fp(left->get_height());
- + } else if(base.width != int2fp(left->get_width()) || base.height != int2fp(left->get_height())) {
- + base.x -= (int2fp(left->get_width()) - base.width) / 2;
- + base.y -= int2fp(left->get_height()) - base.height;
- + base.width = int2fp(left->get_width());
- + base.height = int2fp(left->get_height());
- old_base = base;
- }
- } else {
- @@ -825,7 +822,7 @@
- || kind == BAD_FLYINGSNOWBALL)
- return;
- - physic.set_velocity_y(3);
- + physic.set_velocity_y(FP_BUMP_SPEED);
- kill_me(25);
- }
- @@ -891,10 +888,10 @@
- #endif
- if (player->base.x < base.x + (base.width/2)) {
- - physic.set_velocity_x(5);
- + physic.set_velocity_x(FP_MRICEBLOCK_SPEED_2);
- dir = RIGHT;
- } else {
- - physic.set_velocity_x(-5);
- + physic.set_velocity_x(-FP_MRICEBLOCK_SPEED_2);
- dir = LEFT;
- }
- @@ -1060,12 +1057,12 @@
- if (pbad_c->dir == LEFT)
- {
- dir = RIGHT;
- - physic.set_velocity(fabsf(physic.get_velocity_x()), 2);
- + physic.set_velocity(abs(physic.get_velocity_x()), FP_BOUNCE_SPEED);
- }
- else if (pbad_c->dir == RIGHT)
- {
- dir = LEFT;
- - physic.set_velocity(-fabsf(physic.get_velocity_x()), 2);
- + physic.set_velocity(-abs(physic.get_velocity_x()), FP_BOUNCE_SPEED);
- }
- @@ -1080,12 +1077,12 @@
- if (dir == LEFT)
- {
- dir = RIGHT;
- - physic.set_velocity_x(fabsf(physic.get_velocity_x()));
- + physic.set_velocity_x(abs(physic.get_velocity_x()));
- }
- else if (dir == RIGHT)
- {
- dir = LEFT;
- - physic.set_velocity_x(-fabsf(physic.get_velocity_x()));
- + physic.set_velocity_x(-abs(physic.get_velocity_x()));
- }
- }
- @@ -1106,12 +1103,12 @@
- // Hit from left side
- if (player->base.x < base.x) {
- - physic.set_velocity_x(5);
- + physic.set_velocity_x(FP_MRICEBLOCK_SPEED_2);
- dir = RIGHT;
- }
- // Hit from right side
- else {
- - physic.set_velocity_x(-5);
- + physic.set_velocity_x(-FP_MRICEBLOCK_SPEED_2);
- dir = LEFT;
- }
- diff -Naur supertux-0.1.3/src.bak/badguy.h supertux-0.1.3/src/badguy.h
- --- supertux-0.1.3/src.bak/badguy.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/badguy.h 2014-12-06 18:03:09.000000000 -0500
- @@ -105,9 +105,9 @@
- int animation_offset;
- public:
- - BadGuy(float x, float y, BadGuyKind kind, bool stay_on_platform);
- + BadGuy(fp x, fp y, BadGuyKind kind, bool stay_on_platform);
- - void action(double frame_ratio);
- + void action(fp frame_ratio);
- void draw();
- std::string type() { return "BadGuy"; };
- @@ -129,17 +129,17 @@
- bool is_removable() const { return removable; }
- private:
- - void action_mriceblock(double frame_ratio);
- - void action_jumpy(double frame_ratio);
- - void action_bomb(double frame_ratio);
- - void action_mrbomb(double frame_ratio);
- - void action_stalactite(double frame_ratio);
- - void action_flame(double frame_ratio);
- - void action_fish(double frame_ratio);
- - void action_bouncingsnowball(double frame_ratio);
- - void action_flyingsnowball(double frame_ratio);
- - void action_spiky(double frame_ratio);
- - void action_snowball(double frame_ratio);
- + void action_mriceblock(fp frame_ratio);
- + void action_jumpy(fp frame_ratio);
- + void action_bomb(fp frame_ratio);
- + void action_mrbomb(fp frame_ratio);
- + void action_stalactite(fp frame_ratio);
- + void action_flame(fp frame_ratio);
- + void action_fish(fp frame_ratio);
- + void action_bouncingsnowball(fp frame_ratio);
- + void action_flyingsnowball(fp frame_ratio);
- + void action_spiky(fp frame_ratio);
- + void action_snowball(fp frame_ratio);
- /** handles falling down. disables gravity calculation when we're back on
- * ground */
- @@ -169,7 +169,7 @@
- int y;
- bool stay_on_platform;
- - BadGuyData(BadGuy* pbadguy) : kind(pbadguy->kind), x((int)pbadguy->base.x), y((int)pbadguy->base.y), stay_on_platform(pbadguy->stay_on_platform) {};
- + BadGuyData(BadGuy* pbadguy) : kind(pbadguy->kind), x(fp2int(pbadguy->base.x)), y(fp2int(pbadguy->base.y)), stay_on_platform(pbadguy->stay_on_platform) {};
- BadGuyData(BadGuyKind kind_, int x_, int y_, bool stay_on_platform_)
- : kind(kind_), x(x_), y(y_), stay_on_platform(stay_on_platform_) {}
- diff -Naur supertux-0.1.3/src.bak/collision.cpp supertux-0.1.3/src/collision.cpp
- --- supertux-0.1.3/src.bak/collision.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/collision.cpp 2014-12-06 18:03:09.000000000 -0500
- @@ -25,21 +25,22 @@
- #include "world.h"
- #include "level.h"
- #include "tile.h"
- +#include "fpmath.h"
- bool rectcollision(const base_type& one, const base_type& two)
- {
- - return (one.x >= two.x - one.width + 1 &&
- - one.x <= two.x + two.width - 1 &&
- - one.y >= two.y - one.height + 1 &&
- - one.y <= two.y + two.height - 1);
- + return (one.x >= two.x - one.width + int2fp(1) &&
- + one.x <= two.x + two.width - int2fp(1) &&
- + one.y >= two.y - one.height + int2fp(1) &&
- + one.y <= two.y + two.height - int2fp(1));
- }
- -bool rectcollision_offset(const base_type& one, const base_type& two, float off_x, float off_y)
- -{
- - return (one.x >= two.x - one.width + off_x + 1 &&
- - one.x <= two.x + two.width + off_x - 1 &&
- - one.y >= two.y - one.height + off_y + 1 &&
- - one.y <= two.y + two.height + off_y - 1);
- +bool rectcollision_offset(const base_type& one, const base_type& two, fp off_x, fp off_y)
- +{
- + return (one.x >= two.x - one.width + off_x + int2fp(1) &&
- + one.x <= two.x + two.width + off_x - int2fp(1) &&
- + one.y >= two.y - one.height + off_y + int2fp(1) &&
- + one.y <= two.y + two.height + off_y - int2fp(1));
- }
- bool collision_object_map(const base_type& base)
- @@ -51,10 +52,10 @@
- TileManager& tilemanager = *TileManager::instance();
- // we make the collision rectangle 1 pixel smaller
- - int starttilex = int(base.x+1) / 32;
- - int starttiley = int(base.y+1) / 32;
- - int max_x = int(base.x + base.width);
- - int max_y = int(base.y + base.height);
- + int starttilex = (fp2int(base.x)+1) / 32;
- + int starttiley = (fp2int(base.y)+1) / 32;
- + int max_x = fp2int(base.x + base.width);
- + int max_y = fp2int(base.y + base.height);
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
- @@ -72,10 +73,10 @@
- const Level& level = *World::current()->get_level();
- TileManager& tilemanager = *TileManager::instance();
- - int starttilex = int(base.x) / 32;
- - int starttiley = int(base.y) / 32;
- - int max_x = int(base.x + base.width);
- - int max_y = int(base.y + base.height);
- + int starttilex = fp2int(base.x) / 32;
- + int starttiley = fp2int(base.y) / 32;
- + int max_x = fp2int(base.x + base.width);
- + int max_y = fp2int(base.y + base.height);
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
- @@ -105,9 +106,9 @@
- {
- int steps; /* Used to speed up the collision tests, by stepping every 16pixels in the path. */
- int h;
- - float lpath; /* Holds the longest path, which is either in X or Y direction. */
- - float xd,yd; /* Hold the smallest steps in X and Y directions. */
- - float temp, xt, yt; /* Temporary variable. */
- + fp lpath; /* Holds the longest path, which is either in X or Y direction. */
- + fp xd,yd; /* Hold the smallest steps in X and Y directions. */
- + fp temp, xt, yt; /* Temporary variable. */
- lpath = 0;
- xd = 0;
- @@ -122,12 +123,12 @@
- lpath = current->y - old->y;
- if(lpath < 0)
- {
- - yd = -1;
- + yd = int2fp(-1);
- lpath = -lpath;
- }
- else
- {
- - yd = 1;
- + yd = int2fp(1);
- }
- h = 1;
- @@ -138,12 +139,12 @@
- lpath = current->x - old->x;
- if(lpath < 0)
- {
- - xd = -1;
- + xd = int2fp(-1);
- lpath = -lpath;
- }
- else
- {
- - xd = 1;
- + xd = int2fp(1);
- }
- h = 2;
- yd = 0;
- @@ -158,23 +159,23 @@
- if(lpath < 0)
- lpath = -lpath;
- h = 3;
- - xd = (current->x - old->x) / lpath;
- - yd = (current->y - old->y) / lpath;
- + xd = fpdiv((current->x - old->x), lpath);
- + yd = fpdiv((current->y - old->y), lpath);
- }
- - steps = (int)(lpath / (float)16);
- + steps = fp2int(lpath / 16);
- - float orig_x = old->x;
- - float orig_y = old->y;
- + fp orig_x = old->x;
- + fp orig_y = old->y;
- old->x += xd;
- old->y += yd;
- - for(float i = 0; i <= lpath; old->x += xd, old->y += yd, ++i)
- + for(fp i = 0; i <= lpath; old->x += xd, old->y += yd, i += int2fp(1))
- {
- if(steps > 0)
- {
- - old->y += yd*16.;
- - old->x += xd*16.;
- + old->y += yd*16;
- + old->x += xd*16;
- steps--;
- }
- @@ -240,36 +241,36 @@
- *old = *current;
- }
- -Tile* gettile(float x, float y)
- +Tile* gettile(int x, int y)
- {
- return TileManager::instance()->get(World::current()->get_level()->gettileid(x, y));
- }
- -bool issolid(float x, float y)
- +bool issolid(int x, int y)
- {
- Tile* tile = gettile(x,y);
- return tile && tile->solid;
- }
- -bool isbrick(float x, float y)
- +bool isbrick(int x, int y)
- {
- Tile* tile = gettile(x,y);
- return tile && tile->brick;
- }
- -bool isice(float x, float y)
- +bool isice(int x, int y)
- {
- Tile* tile = gettile(x,y);
- return tile && tile->ice;
- }
- -bool isfullbox(float x, float y)
- +bool isfullbox(int x, int y)
- {
- Tile* tile = gettile(x,y);
- return tile && tile->fullbox;
- }
- -bool isdistro(float x, float y)
- +bool isdistro(int x, int y)
- {
- Tile* tile = gettile(x,y);
- return tile && tile->distro;
- diff -Naur supertux-0.1.3/src.bak/collision.h supertux-0.1.3/src/collision.h
- --- supertux-0.1.3/src.bak/collision.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/collision.h 2014-12-06 18:03:09.000000000 -0500
- @@ -41,19 +41,19 @@
- };
- bool rectcollision(const base_type& one, const base_type& two);
- -bool rectcollision_offset(const base_type& one, const base_type& two, float off_x, float off_y);
- +bool rectcollision_offset(const base_type& one, const base_type& two, fp off_x, fp off_y);
- void collision_swept_object_map(base_type* old, base_type* current);
- bool collision_object_map(const base_type& object);
- /** Return a pointer to the tile at the given x/y coordinates */
- -Tile* gettile(float x, float y);
- +Tile* gettile(int x, int y);
- // Some little helper function to check for tile properties
- -bool issolid(float x, float y);
- -bool isbrick(float x, float y);
- -bool isice(float x, float y);
- -bool isfullbox(float x, float y);
- +bool issolid(int x, int y);
- +bool isbrick(int x, int y);
- +bool isice(int x, int y);
- +bool isfullbox(int x, int y);
- typedef void* (*tiletestfunction)(Tile* tile);
- /** invokes the function for each tile the baserectangle collides with. The
- diff -Naur supertux-0.1.3/src.bak/configfile.cpp supertux-0.1.3/src/configfile.cpp
- --- supertux-0.1.3/src.bak/configfile.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/configfile.cpp 2014-12-06 18:06:14.000000000 -0500
- @@ -37,7 +37,7 @@
- debug_mode = false;
- audio_device = true;
- - use_fullscreen = true;
- + use_fullscreen = false;
- show_fps = false;
- use_gl = false;
- diff -Naur supertux-0.1.3/src.bak/defines.h supertux-0.1.3/src/defines.h
- --- supertux-0.1.3/src.bak/defines.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/defines.h 2014-12-07 10:59:26.000000000 -0500
- @@ -55,30 +55,76 @@
- /* Speed constraints: */
- -#define MAX_WALK_XM 2.3
- -#define MAX_RUN_XM 3.2
- -#define MAX_YM 20.0
- +#define FP_MAX_WALK_XM 37683 /* 2.3 */
- +#define FP_MAX_RUN_XM 52428 /* 3.2 */
- +//#define MAX_YM 20.0
- #define MAX_JUMP_TIME 375
- #define MAX_LIVES 99
- -#define WALK_SPEED 1.0
- -#define RUN_SPEED 1.5
- -#define JUMP_SPEED 1.2
- +#define WALK_SPEED 1
- +#define FP_WALK_SPEED 16384 /* 1.0 */
- +//#define RUN_SPEED 1.5
- +//#define JUMP_SPEED 1.2
- +
- +#define FP_BADGUY_WALK_SPEED 13107 /* 0.8 */
- +#define FP_BOUNCINGSNOWBALL_SPEED 21299 /* 1.3 */
- +#define FP_MRICEBLOCK_SPEED 57344 /* 3.5 */
- +#define FP_MRICEBLOCK_SPEED_2 81920 /* 5.0 */
- +
- +#define FP_WALK_JUMP_SPEED 85196 /* 5.2 */
- +#define FP_RUN_JUMP_SPEED 95027 /* 5.8 */
- +#define FP_KILL_SPEED 114688 /* 7.0 */
- +
- +#define FP_JUMP_SPEED 98304 /* 6.0 */
- +#define FP_JUMP_SPEED_START 91750 /* 5.6 */
- +#define FP_JUMP_SPEED_MIDDLE 86835 /* 5.3 */
- +#define FP_BOUNCE_SPEED 32768 /* 2.0 */
- +
- +#define FP_SNOWBALL_JUMP_SPEED 73728 /* 4.5 */
- +#define FP_FLYING_SPEED 16384 /* 1.0 */
- +#define FP_SPIKY_JUMP_SPEED 32768 /* 2.0 */
- +#define FP_BUMP_SPEED 49152 /* 3.0 */
- +
- +#define FP_UPGRADE_SPEED_X 16384 /* 1.0 */
- +#define FP_UPGRADE_SPEED_Y 65536 /* 4.0 */
- +#define FP_GROWUP_SPEED 16384 /* 1.0 */
- +
- +#define FP_BOUNCY_BRICK_MAX_OFFSET 131072 /* 8.0 */
- +#define FP_BOUNCY_BRICK_SPEED 14745 /* 0.9 */
- +
- +#define FP_BULLET_STARTING_YM 0 /* 0.0 */
- +#define FP_BULLET_XM 98304 /* 6.0 */
- +
- +#define FP_RISE_RATIO 11468 /* 0.7 */
- +
- +#define FLAME_RADIUS 100
- +#define FP_FLAME_SPEED 327 /* 0.02 */
- +
- +#define FP_MIN_PARTICLE_SPEED 163 /* 0.01 */
- +
- +#define FP_BROKEN_PIECE_SPEED 24576 /* 1.5 */
- /* gameplay related defines */
- +#define FP_PI 51471 /* 3.14159265 */
- +
- #define START_LIVES 4
- #define MAX_BULLETS 2
- -#define YM_FOR_JUMP 6.0
- -#define WALK_ACCELERATION_X 0.03
- -#define RUN_ACCELERATION_X 0.04
- -#define KILL_BOUNCE_YM 8.0
- +//#define YM_FOR_JUMP 6.0
- +#define FP_WALK_ACCELERATION_X 491 /* 0.03 */
- +#define FP_RUN_ACCELERATION_X 655 /* 0.04 */
- +//#define KILL_BOUNCE_YM 8.0
- -#define SKID_XM 2.0
- +#define FP_SKID_XM 32768 /* 2.0 */
- #define SKID_TIME 200
- +#define FP_FRAME_RATIO_LIMIT 24576 /* 1.5 */
- +#define FP_FRAME_RATIO_CORR 13926 /* 0.85 */
- +
- +#define FP_MENU_RATIO 8192 /* 0.5 */
- +
- /* Size constraints: */
- #define OFFSCREEN_DISTANCE 256
- @@ -92,11 +138,12 @@
- /* Scrolling text speed */
- #ifndef RES320X240
- -#define SCROLL_SPEED_CREDITS 1.2
- +#define FP_SCROLL_SPEED_CREDITS 19660 /* 1.2 */
- #else
- -#define SCROLL_SPEED_CREDITS 2.4
- +#define FP_SCROLL_SPEED_CREDITS 39321 /* 2.4 */
- #endif
- -#define SCROLL_SPEED_MESSAGE 1.0
- +#define FP_SCROLL_SPEED_MESSAGE 16384 /* 1.0 */
- +#define FP_SPEED_INC 163 /* 0.01 */
- /* Debugging */
- diff -Naur supertux-0.1.3/src.bak/fpmath.cpp supertux-0.1.3/src/fpmath.cpp
- --- supertux-0.1.3/src.bak/fpmath.cpp 1969-12-31 19:00:00.000000000 -0500
- +++ supertux-0.1.3/src/fpmath.cpp 2014-12-06 18:04:18.000000000 -0500
- @@ -0,0 +1,87 @@
- +// $Id: fpmath.cpp,v Exp $
- +//
- +// SuperTux - A Jump'n Run
- +// Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
- +//
- +// This program is free software; you can redistribute it and/or
- +// modify it under the terms of the GNU General Public License
- +// as published by the Free Software Foundation; either version 2
- +// of the License, or (at your option) any later version.
- +//
- +// This program is distributed in the hope that it will be useful,
- +// but WITHOUT ANY WARRANTY; without even the implied warranty of
- +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +// GNU General Public License for more details.
- +//
- +// You should have received a copy of the GNU General Public License
- +// along with this program; if not, write to the Free Software
- +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- +
- +#include "fpmath.h"
- +
- +// Fixed point sine and cosine tables, based
- +// on 256 'degrees' in a circle.
- +
- +fp sine[] = {
- +0, 402, 804, 1205, 1606, 2006, 2404, 2801, 3196,
- +3590, 3981, 4370, 4756, 5139, 5520, 5897, 6270, 6639,
- +7005, 7366, 7723, 8076, 8423, 8765, 9102, 9434, 9760,
- +10080, 10394, 10702, 11003, 11297, 11585, 11866, 12140, 12406,
- +12665, 12916, 13160, 13395, 13623, 13842, 14053, 14256, 14449,
- +14635, 14811, 14978, 15137, 15286, 15426, 15557, 15679, 15791,
- +15893, 15986, 16069, 16143, 16207, 16261, 16305, 16340, 16364,
- +16379, 16384, 16379, 16364, 16340, 16305, 16261, 16207, 16143,
- +16069, 15986, 15893, 15791, 15679, 15557, 15426, 15286, 15137,
- +14978, 14811, 14635, 14449, 14256, 14053, 13842, 13623, 13395,
- +13160, 12916, 12665, 12406, 12140, 11866, 11585, 11297, 11003,
- +10702, 10394, 10080, 9760, 9434, 9102, 8765, 8423, 8076,
- +7723, 7366, 7005, 6639, 6270, 5897, 5520, 5139, 4756,
- +4370, 3981, 3590, 3196, 2801, 2404, 2006, 1606, 1205,
- +804, 402, 0, -402, -804, -1205, -1606, -2006, -2404,
- +-2801, -3196, -3590, -3981, -4370, -4756, -5139, -5520, -5897,
- +-6270, -6639, -7005, -7366, -7723, -8076, -8423, -8765, -9102,
- +-9434, -9760, -10080, -10394, -10702, -11003, -11297, -11585, -11866,
- +-12140, -12406, -12665, -12916, -13160, -13395, -13623, -13842, -14053,
- +-14256, -14449, -14635, -14811, -14978, -15137, -15286, -15426, -15557,
- +-15679, -15791, -15893, -15986, -16069, -16143, -16207, -16261, -16305,
- +-16340, -16364, -16379, -16384, -16379, -16364, -16340, -16305, -16261,
- +-16207, -16143, -16069, -15986, -15893, -15791, -15679, -15557, -15426,
- +-15286, -15137, -14978, -14811, -14635, -14449, -14256, -14053, -13842,
- +-13623, -13395, -13160, -12916, -12665, -12406, -12140, -11866, -11585,
- +-11297, -11003, -10702, -10394, -10080, -9760, -9434, -9102, -8765,
- +-8423, -8076, -7723, -7366, -7005, -6639, -6270, -5897, -5520,
- +-5139, -4756, -4370, -3981, -3590, -3196, -2801, -2404, -2006,
- +-1606, -1205, -804, -402
- +};
- +
- +fp cosine[] = {
- +16384, 16379, 16364, 16340, 16305, 16261, 16207, 16143, 16069,
- +15986, 15893, 15791, 15679, 15557, 15426, 15286, 15137, 14978,
- +14811, 14635, 14449, 14256, 14053, 13842, 13623, 13395, 13160,
- +12916, 12665, 12406, 12140, 11866, 11585, 11297, 11003, 10702,
- +10394, 10080, 9760, 9434, 9102, 8765, 8423, 8076, 7723,
- +7366, 7005, 6639, 6270, 5897, 5520, 5139, 4756, 4370,
- +3981, 3590, 3196, 2801, 2404, 2006, 1606, 1205, 804,
- +402, 0, -402, -804, -1205, -1606, -2006, -2404, -2801,
- +-3196, -3590, -3981, -4370, -4756, -5139, -5520, -5897, -6270,
- +-6639, -7005, -7366, -7723, -8076, -8423, -8765, -9102, -9434,
- +-9760, -10080, -10394, -10702, -11003, -11297, -11585, -11866, -12140,
- +-12406, -12665, -12916, -13160, -13395, -13623, -13842, -14053, -14256,
- +-14449, -14635, -14811, -14978, -15137, -15286, -15426, -15557, -15679,
- +-15791, -15893, -15986, -16069, -16143, -16207, -16261, -16305, -16340,
- +-16364, -16379, -16384, -16379, -16364, -16340, -16305, -16261, -16207,
- +-16143, -16069, -15986, -15893, -15791, -15679, -15557, -15426, -15286,
- +-15137, -14978, -14811, -14635, -14449, -14256, -14053, -13842, -13623,
- +-13395, -13160, -12916, -12665, -12406, -12140, -11866, -11585, -11297,
- +-11003, -10702, -10394, -10080, -9760, -9434, -9102, -8765, -8423,
- +-8076, -7723, -7366, -7005, -6639, -6270, -5897, -5520, -5139,
- +-4756, -4370, -3981, -3590, -3196, -2801, -2404, -2006, -1606,
- +-1205, -804, -402, 0, 402, 804, 1205, 1606, 2006,
- +2404, 2801, 3196, 3590, 3981, 4370, 4756, 5139, 5520,
- +5897, 6270, 6639, 7005, 7366, 7723, 8076, 8423, 8765,
- +9102, 9434, 9760, 10080, 10394, 10702, 11003, 11297, 11585,
- +11866, 12140, 12406, 12665, 12916, 13160, 13395, 13623, 13842,
- +14053, 14256, 14449, 14635, 14811, 14978, 15137, 15286, 15426,
- +15557, 15679, 15791, 15893, 15986, 16069, 16143, 16207, 16261,
- +16305, 16340, 16364, 16379
- +};
- diff -Naur supertux-0.1.3/src.bak/fpmath.h supertux-0.1.3/src/fpmath.h
- --- supertux-0.1.3/src.bak/fpmath.h 1969-12-31 19:00:00.000000000 -0500
- +++ supertux-0.1.3/src/fpmath.h 2014-12-06 18:04:18.000000000 -0500
- @@ -0,0 +1,73 @@
- +// $Id: fpmath.h,v Exp $
- +//
- +// SuperTux - A Jump'n Run
- +// Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
- +//
- +// This program is free software; you can redistribute it and/or
- +// modify it under the terms of the GNU General Public License
- +// as published by the Free Software Foundation; either version 2
- +// of the License, or (at your option) any later version.
- +//
- +// This program is distributed in the hope that it will be useful,
- +// but WITHOUT ANY WARRANTY; without even the implied warranty of
- +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- +// GNU General Public License for more details.
- +//
- +// You should have received a copy of the GNU General Public License
- +// along with this program; if not, write to the Free Software
- +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- +
- +#ifndef FPMATH_H
- +#define FPMATH_H
- +
- +typedef long fp;
- +
- +// Number of bits behind the comma
- +#define FP 14
- +#define FPH 7
- +#define FP_FULL 0x4000
- +#define FP_HALF 0x80
- +
- +#define int2fp(exp) ((exp) << 14)
- +#define fp2int(exp) ((exp) >> 14)
- +
- +// Fractional part of the fixed point number
- +#define fpfract(exp) ((exp) & 0x3FFF)
- +
- +#define fp2float(exp) (((double)(exp)) / (1 << 14))
- +#define float2fp(exp) ((fp) ((exp) * (1 << 14)))
- +
- +// Inline functions
- +static inline fp fpmul(fp a, fp b) {
- +//ifndef HAVE_LONG_LONG
- +// int aa = a & (FP_HALF-1);
- +// a = a >> FPH;
- +// int bb = b & (FP_HALF-1);
- +// b = b >> FPH;
- +// return a*b + ((aa*b + a*bb) >> FPH);
- +//else
- + long long r = (long long)a * (long long)b;
- + return (fp)(r >> FP);
- +//endif
- +}
- +
- +static inline fp fpdiv(fp a, fp b) {
- +//ifndef HAVE_LONG_LONG
- +// if (b < FP_FULL)
- +// return fpmul(a, FP_FULL/b);
- +// else
- +// return a / fp2int(b);
- +//else
- + long long la = (long long)a << FP;
- + return (fp)(la / (long long)b);
- +//endif
- +}
- +
- +// Lookup table based functions
- +extern fp sine[];
- +extern fp cosine[];
- +
- +#define fpsin(exp) (sine[(exp) & 0xFF])
- +#define fpcos(exp) (cosine[(exp) & 0xFF])
- +
- +#endif
- diff -Naur supertux-0.1.3/src.bak/gameloop.cpp supertux-0.1.3/src/gameloop.cpp
- --- supertux-0.1.3/src.bak/gameloop.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/gameloop.cpp 2014-12-06 19:01:42.000000000 -0500
- @@ -54,6 +54,7 @@
- #include "particlesystem.h"
- #include "resources.h"
- #include "music_manager.h"
- +#include "fpmath.h"
- GameSession* GameSession::current_ = 0;
- @@ -82,7 +83,7 @@
- fps_timer.init(true);
- frame_timer.init(true);
- - float old_x_pos = -1;
- + fp old_x_pos = int2fp(-1);
- if (world)
- { // Tux has lost a life, so we try to respawn him at the nearest reset point
- @@ -105,20 +106,20 @@
- }
- // Set Tux to the nearest reset point
- - if (old_x_pos != -1)
- + if (old_x_pos != int2fp(-1))
- {
- ResetPoint best_reset_point = { -1, -1 };
- for(std::vector<ResetPoint>::iterator i = get_level()->reset_points.begin();
- i != get_level()->reset_points.end(); ++i)
- {
- - if (i->x - screen->w/2 < old_x_pos && best_reset_point.x < i->x)
- + if (int2fp(i->x) - screen->w/2 < old_x_pos && best_reset_point.x < i->x)
- best_reset_point = *i;
- }
- if (best_reset_point.x != -1)
- {
- - world->get_tux()->base.x = best_reset_point.x;
- - world->get_tux()->base.y = best_reset_point.y;
- + world->get_tux()->base.x = int2fp(best_reset_point.x);
- + world->get_tux()->base.y = int2fp(best_reset_point.y);
- world->get_tux()->old_base = world->get_tux()->base;
- world->get_tux()->previous_base = world->get_tux()->base;
- @@ -126,7 +127,7 @@
- std::cout << "Warning: reset point inside a wall.\n";
- }
- - scroll_x = best_reset_point.x - screen->w/2;
- + scroll_x = int2fp(best_reset_point.x - screen->w/2);
- }
- }
- @@ -212,7 +213,7 @@
- tux.input.right = DOWN;
- tux.input.down = UP;
- - if (int(last_x_pos) == int(tux.base.x))
- + if (fp2int(last_x_pos) == fp2int(tux.base.x))
- tux.input.up = DOWN;
- else
- tux.input.up = UP;
- @@ -340,10 +341,10 @@
- tux.size = !tux.size;
- if(tux.size == BIG)
- {
- - tux.base.height = 64;
- + tux.base.height = int2fp(64);
- }
- else
- - tux.base.height = 32;
- + tux.base.height = int2fp(32);
- }
- break;
- case SDLK_END:
- @@ -507,33 +508,48 @@
- Tile* endtile = collision_goal(tux->base);
- // fallback in case the other endpositions don't trigger
- - if (!end_sequence && tux->base.x >= endpos)
- + if (!end_sequence && tux->base.x >= int2fp(endpos))
- {
- + if (debug_mode) {
- + printf("\nEnd sequence WAITING triggered\n");
- + }
- end_sequence = ENDSEQUENCE_WAITING;
- - last_x_pos = -1;
- + last_x_pos = int2fp(-1);
- music_manager->play_music(level_end_song, 0);
- endsequence_timer.start(7000);
- tux->invincible_timer.start(7000); //FIXME: Implement a winning timer for the end sequence (with special winning animation etc.)
- }
- else if(end_sequence && !endsequence_timer.check())
- {
- + if (debug_mode) {
- + printf("End sequence finished\n");
- + }
- exit_status = ES_LEVEL_FINISHED;
- return;
- }
- else if(end_sequence == ENDSEQUENCE_RUNNING && endtile && endtile->data >= 1)
- {
- + if (debug_mode) {
- + printf("End sequence switched from RUNNING to WAITING\n");
- + }
- end_sequence = ENDSEQUENCE_WAITING;
- }
- else if(!end_sequence && endtile && endtile->data == 0)
- {
- + if (debug_mode) {
- + printf("\nEnd sequence RUNNING triggered\n");
- + }
- end_sequence = ENDSEQUENCE_RUNNING;
- - last_x_pos = -1;
- + last_x_pos = int2fp(-1);
- music_manager->play_music(level_end_song, 0);
- endsequence_timer.start(7000); // 5 seconds until we finish the map
- tux->invincible_timer.start(7000); //FIXME: Implement a winning timer for the end sequence (with special winning animation etc.)
- }
- else if (!end_sequence && tux->is_dead())
- {
- + if (debug_mode) {
- + printf("\nEnd sequence death triggered\n");
- + }
- player_status.bonus = PlayerStatus::NO_BONUS;
- if (player_status.lives < 0)
- @@ -553,7 +569,7 @@
- }
- void
- -GameSession::action(double frame_ratio)
- +GameSession::action(fp frame_ratio)
- {
- if (exit_status == ES_NONE)
- {
- @@ -640,7 +656,7 @@
- {
- SDL_Delay(10);
- /* Calculate the movement-factor */
- - double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
- + fp frame_ratio = (int2fp(update_time-last_update_time))/(FRAME_RATE);
- if(!frame_timer.check())
- {
- @@ -718,7 +734,7 @@
- if(show_fps)
- {
- ++fps_cnt;
- - fps_fps = (1000.0 / (float)fps_timer.get_gone()) * (float)fps_cnt;
- + fps_fps = int2fp(fps_cnt) * 1000 / fps_timer.get_gone();
- if(!fps_timer.check())
- {
- @@ -733,10 +749,10 @@
- }
- /* Bounce a brick: */
- -void bumpbrick(float x, float y)
- +void bumpbrick(fp x, fp y)
- {
- - World::current()->add_bouncy_brick(((int)(x + 1) / (32)) * (32),
- - (int)(y / (32)) * (32));
- + World::current()->add_bouncy_brick(int2fp(((fp2int(x) + 1) / 32) * 32),
- + int2fp((fp2int(y) / 32) * 32));
- #ifndef GP2X
- play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER);
- @@ -799,7 +815,7 @@
- if(show_fps)
- {
- - sprintf(str, "%2.1f", fps_fps);
- + sprintf(str, "%2.1f", fp2float(fps_fps));
- white_text->draw("FPS", screen->h, 40, 1);
- gold_text->draw(str, screen->h + 60, 40, 1);
- }
- diff -Naur supertux-0.1.3/src.bak/gameloop.h supertux-0.1.3/src/gameloop.h
- --- supertux-0.1.3/src.bak/gameloop.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/gameloop.h 2014-12-06 18:04:18.000000000 -0500
- @@ -26,6 +26,7 @@
- #include "type.h"
- #include "level.h"
- #include "world.h"
- +#include "fpmath.h"
- /* GameLoop modes */
- @@ -51,7 +52,7 @@
- World* world;
- int st_gl_mode;
- int levelnb;
- - float fps_fps;
- + fp fps_fps;
- unsigned int last_update_time;
- unsigned int update_time;
- int pause_menu_frame;
- @@ -65,7 +66,7 @@
- ENDSEQUENCE_WAITING // waiting for the end of the music
- };
- EndSequenceState end_sequence;
- - float last_x_pos;
- + fp last_x_pos;
- bool game_pause;
- @@ -87,7 +88,7 @@
- ExitStatus run();
- void draw();
- - void action(double frame_ratio);
- + void action(fp frame_ratio);
- Level* get_level() { return world->get_level(); }
- World* get_world() { return world; }
- @@ -115,7 +116,7 @@
- std::string slotinfo(int slot);
- bool rectcollision(base_type* one, base_type* two);
- -void bumpbrick(float x, float y);
- +void bumpbrick(fp x, fp y);
- #endif /*SUPERTUX_GAMELOOP_H*/
- diff -Naur supertux-0.1.3/src.bak/gameobjs.cpp supertux-0.1.3/src/gameobjs.cpp
- --- supertux-0.1.3/src.bak/gameobjs.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/gameobjs.cpp 2014-12-06 19:09:42.000000000 -0500
- @@ -24,21 +24,22 @@
- #include "tile.h"
- #include "gameloop.h"
- #include "gameobjs.h"
- +#include "fpmath.h"
- void
- -BouncyDistro::init(float x, float y)
- +BouncyDistro::init(fp x, fp y)
- {
- base.x = x;
- base.y = y;
- - base.ym = -2;
- + base.ym = int2fp(-2);
- }
- void
- -BouncyDistro::action(double frame_ratio)
- +BouncyDistro::action(fp frame_ratio)
- {
- - base.y = base.y + base.ym * frame_ratio;
- + base.y = base.y + fpmul(base.ym, frame_ratio);
- - base.ym += 0.1 * frame_ratio;
- + base.ym += frame_ratio / 10;
- if (base.ym >= 0)
- {
- @@ -54,13 +55,13 @@
- void
- BouncyDistro::draw()
- {
- - img_distro[0]->draw(base.x - scroll_x,
- - base.y);
- + img_distro[0]->draw(fp2int(base.x - scroll_x),
- + fp2int(base.y));
- }
- void
- -BrokenBrick::init(Tile* tile_, float x, float y, float xm, float ym)
- +BrokenBrick::init(Tile* tile_, fp x, fp y, fp xm, fp ym)
- {
- tile = tile_;
- base.x = x;
- @@ -73,10 +74,10 @@
- }
- void
- -BrokenBrick::action(double frame_ratio)
- +BrokenBrick::action(fp frame_ratio)
- {
- - base.x = base.x + base.xm * frame_ratio;
- - base.y = base.y + base.ym * frame_ratio;
- + base.x = base.x + fpmul(base.xm, frame_ratio);
- + base.y = base.y + fpmul(base.ym, frame_ratio);
- if (!timer.check())
- {
- @@ -98,11 +99,11 @@
- src.w = 16;
- src.h = 16;
- - dest.x = (int)(base.x - scroll_x);
- + dest.x = fp2int(base.x - scroll_x);
- #ifdef RES320X240
- dest.x=dest.x/2;
- #endif
- - dest.y = (int)base.y;
- + dest.y = fp2int(base.y);
- dest.w = 16;
- dest.h = 16;
- @@ -111,23 +112,23 @@
- }
- void
- -BouncyBrick::init(float x, float y)
- +BouncyBrick::init(fp x, fp y)
- {
- base.x = x;
- base.y = y;
- offset = 0;
- - offset_m = -BOUNCY_BRICK_SPEED;
- - shape = World::current()->get_level()->gettileid(x, y);
- + offset_m = -FP_BOUNCY_BRICK_SPEED;
- + shape = World::current()->get_level()->gettileid(fp2int(x), fp2int(y));
- }
- void
- -BouncyBrick::action(double frame_ratio)
- +BouncyBrick::action(fp frame_ratio)
- {
- - offset = (offset + offset_m * frame_ratio);
- + offset = (offset + fpmul(offset_m, frame_ratio));
- /* Go back down? */
- - if (offset < -BOUNCY_BRICK_MAX_OFFSET)
- - offset_m = BOUNCY_BRICK_SPEED;
- + if (offset < -FP_BOUNCY_BRICK_MAX_OFFSET)
- + offset_m = FP_BOUNCY_BRICK_SPEED;
- /* Stop bouncing? */
- @@ -148,15 +149,15 @@
- SDL_Rect dest;
- #ifndef RES320X240
- - if (base.x >= scroll_x - 32 &&
- - base.x <= scroll_x + screen->w)
- + if (base.x >= scroll_x - int2fp(32) &&
- + base.x <= scroll_x + int2fp(screen->w))
- #else
- if (base.x >= scroll_x - 32 &&
- base.x <= scroll_x + 640)
- #endif
- {
- - dest.x = (int)(base.x - scroll_x);
- - dest.y = (int)base.y;
- + dest.x = fp2int(base.x - scroll_x);
- + dest.y = fp2int(base.y);
- dest.w = 32;
- dest.h = 32;
- @@ -166,14 +167,14 @@
- // paint it later at on offseted position
- if(plevel->bkgd_image[0] == '\0')
- {
- - fillrect(base.x - scroll_x, base.y,
- + fillrect(fp2int(base.x - scroll_x), fp2int(base.y),
- 32,32,
- plevel->bkgd_top.red, plevel->bkgd_top.green, plevel->bkgd_top.blue, 0);
- // FIXME: doesn't respect the gradient, futhermore is this necessary at all??
- }
- else
- {
- - int s = ((int)scroll_x / 2)%640;
- + int s = (fp2int(scroll_x) / 2)%640;
- #ifdef RES320X240
- plevel->img_bkgd->draw_part(dest.x/2 + s/2, dest.y/2,
- @@ -184,14 +185,14 @@
- #endif
- }
- - Tile::draw(base.x - scroll_x,
- - base.y + offset,
- + Tile::draw(fp2int(base.x - scroll_x),
- + fp2int(base.y + offset),
- shape);
- }
- }
- void
- -FloatingScore::init(float x, float y, int s)
- +FloatingScore::init(fp x, fp y, int s)
- {
- base.x = x;
- base.y = y - 16;
- @@ -201,7 +202,7 @@
- }
- void
- -FloatingScore::action(double frame_ratio)
- +FloatingScore::action(fp frame_ratio)
- {
- base.y = base.y - 2 * frame_ratio;
- @@ -221,7 +222,7 @@
- {
- char str[10];
- sprintf(str, "%d", value);
- - gold_text->draw(str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1);
- + gold_text->draw(str, fp2int(base.x) + 16 - strlen(str) * 8, fp2int(base.y), 1);
- }
- /* EOF */
- diff -Naur supertux-0.1.3/src.bak/gameobjs.h supertux-0.1.3/src/gameobjs.h
- --- supertux-0.1.3/src.bak/gameobjs.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/gameobjs.h 2014-12-06 18:04:19.000000000 -0500
- @@ -26,6 +26,7 @@
- #include "texture.h"
- #include "timer.h"
- #include "scene.h"
- +#include "fpmath.h"
- /* Bounciness of distros: */
- #define NO_BOUNCE 0
- @@ -35,17 +36,14 @@
- {
- public:
- - void init(float x, float y);
- - void action(double frame_ratio);
- + void init(fp x, fp y);
- + void action(fp frame_ratio);
- void draw();
- std::string type() { return "BouncyDistro"; };
- };
- extern Surface* img_distro[4];
- -#define BOUNCY_BRICK_MAX_OFFSET 8
- -#define BOUNCY_BRICK_SPEED 0.9
- -
- class Tile;
- class BrokenBrick : public GameObject
- @@ -54,8 +52,8 @@
- Timer timer;
- Tile* tile;
- - void init(Tile* tile, float x, float y, float xm, float ym);
- - void action(double frame_ratio);
- + void init(Tile* tile, fp x, fp y, fp xm, fp ym);
- + void action(fp frame_ratio);
- void draw();
- std::string type() { return "BrokenBrick"; };
- };
- @@ -63,12 +61,12 @@
- class BouncyBrick : public GameObject
- {
- public:
- - float offset;
- - float offset_m;
- + fp offset;
- + fp offset_m;
- int shape;
- - void init(float x, float y);
- - void action(double frame_ratio);
- + void init(fp x, fp y);
- + void action(fp frame_ratio);
- void draw();
- std::string type() { return "BouncyBrick"; };
- };
- @@ -79,8 +77,8 @@
- int value;
- Timer timer;
- - void init(float x, float y, int s);
- - void action(double frame_ratio);
- + void init(fp x, fp y, int s);
- + void action(fp frame_ratio);
- void draw();
- std::string type() { return "FloatingScore"; };
- };
- diff -Naur supertux-0.1.3/src.bak/globals.cpp supertux-0.1.3/src/globals.cpp
- --- supertux-0.1.3/src.bak/globals.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/globals.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -68,7 +68,7 @@
- bool use_fullscreen;
- bool debug_mode;
- bool show_fps;
- -float game_speed = 1.0f;
- +//float game_speed = 1.0f;
- int joystick_num = 0;
- char* level_startup_file = 0;
- diff -Naur supertux-0.1.3/src.bak/globals.h supertux-0.1.3/src/globals.h
- --- supertux-0.1.3/src.bak/globals.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/globals.h 2014-12-06 18:04:19.000000000 -0500
- @@ -111,7 +111,7 @@
- extern char* st_dir;
- extern char* st_save_dir;
- -extern float game_speed;
- +//extern float game_speed;
- extern SDL_Joystick * js;
- int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false);
- diff -Naur supertux-0.1.3/src.bak/intro.cpp supertux-0.1.3/src/intro.cpp
- --- supertux-0.1.3/src.bak/intro.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/intro.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -37,6 +37,6 @@
- {
- if(debug_mode)
- fade("/images/background/arctis2.jpg", 30, false);
- -display_text_file("intro.txt", "/images/background/arctis2.jpg", SCROLL_SPEED_MESSAGE);
- +display_text_file("intro.txt", "/images/background/arctis2.jpg", FP_SCROLL_SPEED_MESSAGE);
- }
- diff -Naur supertux-0.1.3/src.bak/level.cpp supertux-0.1.3/src/level.cpp
- --- supertux-0.1.3/src.bak/level.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/level.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -23,6 +23,7 @@
- #include <stdio.h>
- #include <string.h>
- #include <iostream>
- +#include <zlib.h>
- #include "globals.h"
- #include "setup.h"
- #include "screen.h"
- @@ -33,6 +34,7 @@
- #include "lispreader.h"
- #include "resources.h"
- #include "music_manager.h"
- +#include "fpmath.h"
- using namespace std;
- @@ -92,7 +94,8 @@
- void LevelSubset::load(char *subset)
- {
- - FILE* fi;
- + //FILE* fi;
- + gzFile fi;
- char filename[1024];
- char str[1024];
- int i;
- @@ -105,13 +108,14 @@
- snprintf(filename, 1024, "%s/levels/%s/info", datadir.c_str(), subset);
- if(faccessible(filename))
- {
- - fi = fopen(filename, "r");
- + fi = gzopen(filename, "r");
- if (fi == NULL)
- {
- perror(filename);
- }
- +
- lisp_stream_t stream;
- - lisp_stream_init_file (&stream, fi);
- + lisp_stream_init_gzfile (&stream, fi);
- root_obj = lisp_read (&stream);
- if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
- @@ -133,7 +137,7 @@
- }
- lisp_free(root_obj);
- - fclose(fi);
- + gzclose(fi);
- snprintf(str, 1024, "%s.png", filename);
- if(faccessible(str))
- @@ -153,19 +157,30 @@
- {
- /* Get the number of levels in this subset */
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset,i);
- - if(!faccessible(filename))
- - {
- - snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset,i);
- - if(!faccessible(filename))
- - break;
- - }
- + if(faccessible(filename))
- + continue;
- +
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl.gz", st_dir, subset,i);
- + if(faccessible(filename))
- + continue;
- +
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset,i);
- + if(faccessible(filename))
- + continue;
- +
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl.gz", datadir.c_str(), subset,i);
- + if(faccessible(filename))
- + continue;
- +
- + break;
- }
- levels = --i;
- }
- void LevelSubset::save()
- {
- - FILE* fi;
- + //FILE* fi;
- + gzFile fi;
- string filename;
- /* Save data file: */
- @@ -177,24 +192,24 @@
- filename = datadir + "/levels/" + name + "/info";
- if(fwriteable(filename.c_str()))
- {
- - fi = fopen(filename.c_str(), "w");
- + fi = gzopen(filename.c_str(), "w");
- if (fi == NULL)
- {
- perror(filename.c_str());
- }
- /* Write header: */
- - fprintf(fi,";SuperTux-Level-Subset\n");
- - fprintf(fi,"(supertux-level-subset\n");
- + gzprintf(fi,";SuperTux-Level-Subset\n");
- + gzprintf(fi,"(supertux-level-subset\n");
- /* Save title info: */
- - fprintf(fi," (title \"%s\")\n", title.c_str());
- + gzprintf(fi," (title \"%s\")\n", title.c_str());
- /* Save the description: */
- - fprintf(fi," (description \"%s\")\n", description.c_str());
- + gzprintf(fi," (description \"%s\")\n", description.c_str());
- - fprintf( fi,")");
- - fclose(fi);
- + gzprintf( fi,")");
- + gzclose(fi);
- }
- }
- @@ -235,7 +250,7 @@
- start_pos_x = 100;
- start_pos_y = 170;
- time_left = 100;
- - gravity = 10.;
- + gravity = int2fp(10);
- back_scrolling = false;
- hor_autoscroll_speed = 0;
- bkgd_speed = 50;
- @@ -274,7 +289,11 @@
- // Load data file:
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level);
- if(!faccessible(filename))
- - snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset.c_str(), level);
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl.gz", datadir.c_str(), subset.c_str(), level);
- + if(!faccessible(filename))
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level);
- + if(!faccessible(filename))
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl.gz", datadir.c_str(), subset.c_str(), level);
- return load(filename);
- }
- @@ -317,8 +336,9 @@
- back_scrolling = false;
- reader.read_bool("back_scrolling", &back_scrolling);
- - hor_autoscroll_speed = 0;
- - reader.read_float("hor_autoscroll_speed", &hor_autoscroll_speed);
- + float hor_autoscroll_speed_f = 0;
- + reader.read_float("hor_autoscroll_speed", &hor_autoscroll_speed_f);
- + hor_autoscroll_speed = float2fp(hor_autoscroll_speed_f);
- bkgd_speed = 50;
- reader.read_int("bkgd_speed", &bkgd_speed);
- @@ -334,8 +354,10 @@
- reader.read_int("bkgd_green_bottom", &bkgd_bottom.green);
- reader.read_int("bkgd_blue_bottom", &bkgd_bottom.blue);
- - gravity = 10;
- - reader.read_float("gravity", &gravity);
- + float gravity_f = 10;
- + reader.read_float("gravity", &gravity_f);
- + gravity = float2fp(gravity_f);
- +
- name = "Noname";
- reader.read_string("name", &name);
- author = "unknown author";
- @@ -549,11 +571,18 @@
- fcreatedir(str);
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(),
- level);
- - if(!fwriteable(filename))
- + if(!faccessible(filename)) // write to .gz if no file exists
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl.gz", st_dir, subset.c_str(),
- + level);
- + if(!fwriteable(filename)) {
- snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(),
- subset.c_str(), level);
- + if(!faccessible(filename)) // write to .gz if no file exists
- + snprintf(filename, 1024, "%s/levels/%s/level%d.stl.gz", datadir.c_str(),
- + subset.c_str(), level);
- + }
- - FILE * fi = fopen(filename, "w");
- + gzFile fi = gzopen(filename, "w");
- if (fi == NULL)
- {
- perror(filename);
- @@ -563,78 +592,78 @@
- /* Write header: */
- - fprintf(fi,";SuperTux-Level\n");
- - fprintf(fi,"(supertux-level\n");
- + gzprintf(fi,";SuperTux-Level\n");
- + gzprintf(fi,"(supertux-level\n");
- - fprintf(fi," (version %d)\n", 1);
- - fprintf(fi," (name \"%s\")\n", name.c_str());
- - fprintf(fi," (author \"%s\")\n", author.c_str());
- - fprintf(fi," (music \"%s\")\n", song_title.c_str());
- - fprintf(fi," (background \"%s\")\n", bkgd_image.c_str());
- - fprintf(fi," (particle_system \"%s\")\n", particle_system.c_str());
- - fprintf(fi," (bkgd_speed %d)\n", bkgd_speed);
- - fprintf(fi," (bkgd_red_top %d)\n", bkgd_top.red);
- - fprintf(fi," (bkgd_green_top %d)\n", bkgd_top.green);
- - fprintf(fi," (bkgd_blue_top %d)\n", bkgd_top.blue);
- - fprintf(fi," (bkgd_red_bottom %d)\n", bkgd_bottom.red);
- - fprintf(fi," (bkgd_green_bottom %d)\n", bkgd_bottom.green);
- - fprintf(fi," (bkgd_blue_bottom %d)\n", bkgd_bottom.blue);
- - fprintf(fi," (time %d)\n", time_left);
- - fprintf(fi," (width %d)\n", width);
- + gzprintf(fi," (version %d)\n", 1);
- + gzprintf(fi," (name \"%s\")\n", name.c_str());
- + gzprintf(fi," (author \"%s\")\n", author.c_str());
- + gzprintf(fi," (music \"%s\")\n", song_title.c_str());
- + gzprintf(fi," (background \"%s\")\n", bkgd_image.c_str());
- + gzprintf(fi," (particle_system \"%s\")\n", particle_system.c_str());
- + gzprintf(fi," (bkgd_speed %d)\n", bkgd_speed);
- + gzprintf(fi," (bkgd_red_top %d)\n", bkgd_top.red);
- + gzprintf(fi," (bkgd_green_top %d)\n", bkgd_top.green);
- + gzprintf(fi," (bkgd_blue_top %d)\n", bkgd_top.blue);
- + gzprintf(fi," (bkgd_red_bottom %d)\n", bkgd_bottom.red);
- + gzprintf(fi," (bkgd_green_bottom %d)\n", bkgd_bottom.green);
- + gzprintf(fi," (bkgd_blue_bottom %d)\n", bkgd_bottom.blue);
- + gzprintf(fi," (time %d)\n", time_left);
- + gzprintf(fi," (width %d)\n", width);
- if(back_scrolling)
- - fprintf(fi," (back_scrolling #t)\n");
- + gzprintf(fi," (back_scrolling #t)\n");
- else
- - fprintf(fi," (back_scrolling #f)\n");
- - fprintf(fi," (hor_autoscroll_speed %2.1f)\n", hor_autoscroll_speed);
- - fprintf(fi," (gravity %2.1f)\n", gravity);
- - fprintf(fi," (background-tm ");
- + gzprintf(fi," (back_scrolling #f)\n");
- + gzprintf(fi," (hor_autoscroll_speed %2.1f)\n", fp2float(hor_autoscroll_speed));
- + gzprintf(fi," (gravity %2.1f)\n", fp2float(gravity));
- + gzprintf(fi," (background-tm ");
- for(int y = 0; y < 15; ++y)
- {
- for(int i = 0; i < width; ++i)
- - fprintf(fi," %d ", bg_tiles[y][i]);
- + gzprintf(fi," %d ", bg_tiles[y][i]);
- }
- - fprintf( fi,")\n");
- - fprintf(fi," (interactive-tm ");
- + gzprintf( fi,")\n");
- + gzprintf(fi," (interactive-tm ");
- for(int y = 0; y < 15; ++y)
- {
- for(int i = 0; i < width; ++i)
- - fprintf(fi," %d ", ia_tiles[y][i]);
- + gzprintf(fi," %d ", ia_tiles[y][i]);
- }
- - fprintf( fi,")\n");
- - fprintf(fi," (foreground-tm ");
- + gzprintf( fi,")\n");
- + gzprintf(fi," (foreground-tm ");
- for(int y = 0; y < 15; ++y)
- {
- for(int i = 0; i < width; ++i)
- - fprintf(fi," %d ", fg_tiles[y][i]);
- + gzprintf(fi," %d ", fg_tiles[y][i]);
- }
- - fprintf( fi,")\n");
- + gzprintf( fi,")\n");
- - fprintf( fi,"(reset-points\n");
- + gzprintf( fi,"(reset-points\n");
- for(std::vector<ResetPoint>::iterator i = reset_points.begin();
- i != reset_points.end(); ++i)
- - fprintf( fi,"(point (x %d) (y %d))\n",i->x, i->y);
- - fprintf( fi,")\n");
- + gzprintf( fi,"(point (x %d) (y %d))\n",i->x, i->y);
- + gzprintf( fi,")\n");
- - fprintf( fi,"(objects\n");
- + gzprintf( fi,"(objects\n");
- for(std::vector<BadGuyData>::iterator it = badguy_data.begin();
- it != badguy_data.end();
- ++it)
- - fprintf( fi,"(%s (x %d) (y %d) (stay-on-platform %s))\n",
- + gzprintf( fi,"(%s (x %d) (y %d) (stay-on-platform %s))\n",
- badguykind_to_string((*it).kind).c_str(),(*it).x,(*it).y,
- it->stay_on_platform ? "#t" : "#f");
- - fprintf( fi,")\n");
- + gzprintf( fi,")\n");
- - fprintf( fi,")\n");
- + gzprintf( fi,")\n");
- - fclose(fi);
- + gzclose(fi);
- }
- @@ -708,10 +737,10 @@
- }
- void
- -Level::change(float x, float y, int tm, unsigned int c)
- +Level::change(int x, int y, int tm, unsigned int c)
- {
- - int yy = ((int)y / 32);
- - int xx = ((int)x / 32);
- + int yy = (y / 32);
- + int xx = (x / 32);
- if (yy >= 0 && yy < 15 && xx >= 0 && xx <= width)
- {
- @@ -766,13 +795,13 @@
- }
- unsigned int
- -Level::gettileid(float x, float y) const
- +Level::gettileid(int x, int y) const
- {
- int xx, yy;
- unsigned int c;
- - yy = ((int)y / 32);
- - xx = ((int)x / 32);
- + yy = (y / 32);
- + xx = (x / 32);
- if (yy >= 0 && yy < 15 && xx >= 0 && xx <= width)
- c = ia_tiles[yy][xx];
- diff -Naur supertux-0.1.3/src.bak/leveleditor.cpp supertux-0.1.3/src/leveleditor.cpp
- --- supertux-0.1.3/src.bak/leveleditor.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/leveleditor.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -42,6 +42,7 @@
- #include "tile.h"
- #include "resources.h"
- #include "music_manager.h"
- +#include "fpmath.h"
- /* definitions to aid development */
- @@ -70,7 +71,7 @@
- void le_drawlevel();
- void le_drawinterface();
- void le_checkevents();
- -void le_change(float x, float y, int tm, unsigned int c);
- +void le_change(fp x, fp y, int tm, unsigned int c);
- void le_testlevel();
- void le_showhelp();
- void le_set_defaults(void);
- @@ -192,19 +193,19 @@
- if(select_tilegroup_menu_effect.check())
- {
- select_tilegroup_menu->set_pos(screen->w - 64 + select_tilegroup_menu_effect.get_left(),
- - 66,-0.5,0.5);
- + 66,-FP_MENU_RATIO,FP_MENU_RATIO);
- }
- else
- - select_tilegroup_menu->set_pos(screen->w - 64,66,-0.5,0.5);
- + select_tilegroup_menu->set_pos(screen->w - 64,66,-FP_MENU_RATIO,FP_MENU_RATIO);
- }
- else if(Menu::current() == select_objects_menu)
- {
- if(select_objects_menu_effect.check())
- {
- - select_objects_menu->set_pos(screen->w - 64 + select_objects_menu_effect.get_left(),82,-0.5,0.5);
- + select_objects_menu->set_pos(screen->w - 64 + select_objects_menu_effect.get_left(),82,-FP_MENU_RATIO,FP_MENU_RATIO);
- }
- else
- - select_objects_menu->set_pos(screen->w - 64,82,-0.5,0.5);
- + select_objects_menu->set_pos(screen->w - 64,82,-FP_MENU_RATIO,FP_MENU_RATIO);
- }
- if(le_world != NULL)
- @@ -518,6 +519,8 @@
- level_subsets = dsubdirs("/levels", "level1.stl");
- + if (level_subsets.num_items == 0)
- + level_subsets = dsubdirs("/levels", "level1.stl.gz");
- le_level_subset = new LevelSubset;
- le_world = NULL;
- @@ -611,7 +614,7 @@
- level_settings_menu->get_item_by_id(MNID_LENGTH).change_input(str);
- sprintf(str,"%d",le_world->get_level()->time_left);
- level_settings_menu->get_item_by_id(MNID_TIME).change_input(str);
- - sprintf(str,"%2.0f",le_world->get_level()->gravity);
- + sprintf(str,"%2.0f",fp2float(le_world->get_level()->gravity));
- level_settings_menu->get_item_by_id(MNID_GRAVITY).change_input(str);
- sprintf(str,"%d",le_world->get_level()->bkgd_speed);
- level_settings_menu->get_item_by_id(MNID_BGSPEED).change_input(str);
- @@ -663,7 +666,7 @@
- le_world->get_level()->change_size(atoi(level_settings_menu->get_item_by_id(MNID_LENGTH).input));
- le_world->get_level()->time_left = atoi(level_settings_menu->get_item_by_id(MNID_TIME).input);
- - le_world->get_level()->gravity = atof(level_settings_menu->get_item_by_id(MNID_GRAVITY).input);
- + le_world->get_level()->gravity = float2fp(atof(level_settings_menu->get_item_by_id(MNID_GRAVITY).input));
- le_world->get_level()->bkgd_speed = atoi(level_settings_menu->get_item_by_id(MNID_BGSPEED).input);
- le_world->get_level()->bkgd_top.red = atoi(level_settings_menu->get_item_by_id(MNID_TopRed).input);
- le_world->get_level()->bkgd_top.green = atoi(level_settings_menu->get_item_by_id(MNID_TopGreen).input);
- @@ -846,10 +849,10 @@
- if(mouse_select_object && selected_game_object != NULL)
- {
- - fillrect(selected_game_object->base.x-pos_x,selected_game_object->base.y,selected_game_object->base.width,3,255,0,0,255);
- - fillrect(selected_game_object->base.x-pos_x,selected_game_object->base.y,3,selected_game_object->base.height,255,0,0,255);
- - fillrect(selected_game_object->base.x-pos_x,selected_game_object->base.y+selected_game_object->base.height,selected_game_object->base.width,3,255,0,0,255);
- - fillrect(selected_game_object->base.x-pos_x+selected_game_object->base.width,selected_game_object->base.y,3,selected_game_object->base.height,255,0,0,255);
- + fillrect(fp2int(selected_game_object->base.x)-pos_x,fp2int(selected_game_object->base.y),fp2int(selected_game_object->base.width),3,255,0,0,255);
- + fillrect(fp2int(selected_game_object->base.x)-pos_x,fp2int(selected_game_object->base.y),3,fp2int(selected_game_object->base.height),255,0,0,255);
- + fillrect(fp2int(selected_game_object->base.x)-pos_x,fp2int(selected_game_object->base.y+selected_game_object->base.height),fp2int(selected_game_object->base.width),3,255,0,0,255);
- + fillrect(fp2int(selected_game_object->base.x)-pos_x+fp2int(selected_game_object->base.width),fp2int(selected_game_object->base.y),3,fp2int(selected_game_object->base.height),255,0,0,255);
- }
- if(le_world != NULL)
- @@ -911,7 +914,7 @@
- /* Draw the real background */
- if(le_world->get_level()->bkgd_image[0] != '\0')
- {
- - s = (int)((float)pos_x * ((float)le_world->get_level()->bkgd_speed/100.0f)) % screen->w;
- + s = (pos_x * le_world->get_level()->bkgd_speed / 100) % screen->w;
- le_world->get_level()->img_bkgd->draw_part(s,0,0,0,
- le_world->get_level()->img_bkgd->w - s - 32, le_world->get_level()->img_bkgd->h);
- le_world->get_level()->img_bkgd->draw_part(0,0,screen->w - s - 32 ,0,s,
- @@ -944,21 +947,21 @@
- else
- a = 128;
- - Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_world->get_level()->bg_tiles[y][x + (int)(pos_x / 32)],a);
- + Tile::draw(32*x - (pos_x % 32), y * 32, le_world->get_level()->bg_tiles[y][x + (int)(pos_x / 32)],a);
- if(active_tm == TM_IA)
- a = 255;
- else
- a = 128;
- - Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_world->get_level()->ia_tiles[y][x + (int)(pos_x / 32)],a);
- + Tile::draw(32*x - (pos_x % 32), y * 32, le_world->get_level()->ia_tiles[y][x + (int)(pos_x / 32)],a);
- if(active_tm == TM_FG)
- a = 255;
- else
- a = 128;
- - Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_world->get_level()->fg_tiles[y][x + (int)(pos_x / 32)],a);
- + Tile::draw(32*x - (pos_x % 32), y * 32, le_world->get_level()->fg_tiles[y][x + (int)(pos_x / 32)],a);
- /* draw whats inside stuff when cursor is selecting those */
- /* (draw them all the time - is this the right behaviour?) */
- @@ -973,7 +976,7 @@
- {
- /* to support frames: img_bsod_left[(frame / 5) % 4] */
- - scroll_x = pos_x;
- + scroll_x = int2fp(pos_x);
- (*it)->draw();
- }
- @@ -1040,7 +1043,7 @@
- le_world->get_level()->badguy_data[i].kind = pbad->kind;
- le_world->get_level()->badguy_data[i].stay_on_platform = pbad->stay_on_platform;
- delete (*it);
- - (*it) = new BadGuy(le_world->get_level()->badguy_data[i].x,le_world->get_level()->badguy_data[i].y,le_world->get_level()->badguy_data[i].kind,le_world->get_level()->badguy_data[i].stay_on_platform);
- + (*it) = new BadGuy(int2fp(le_world->get_level()->badguy_data[i].x),int2fp(le_world->get_level()->badguy_data[i].y),le_world->get_level()->badguy_data[i].kind,le_world->get_level()->badguy_data[i].stay_on_platform);
- }
- loop = false;
- break;
- @@ -1324,7 +1327,7 @@
- case BUTTON_CLICKED:
- Menu::set_current(select_tilegroup_menu);
- select_tilegroup_menu_effect.start(200);
- - select_tilegroup_menu->set_pos(screen->w - 64,100,-0.5,0.5);
- + select_tilegroup_menu->set_pos(screen->w - 64,100,-FP_MENU_RATIO,FP_MENU_RATIO);
- break;
- case BUTTON_WHEELUP:
- if(cur_tilegroup.empty())
- @@ -1371,7 +1374,7 @@
- case BUTTON_CLICKED:
- Menu::set_current(select_objects_menu);
- select_objects_menu_effect.start(200);
- - select_objects_menu->set_pos(screen->w - 64,100,-0.5,0.5);
- + select_objects_menu->set_pos(screen->w - 64,100,-FP_MENU_RATIO,FP_MENU_RATIO);
- break;
- case BUTTON_WHEELUP:
- it = objects_map.find(cur_objects);
- @@ -1482,16 +1485,16 @@
- base_type cursor_base;
- if(le_current.IsTile())
- {
- - cursor_base.x = cursor_x;
- - cursor_base.y = cursor_y;
- + cursor_base.x = int2fp(cursor_x);
- + cursor_base.y = int2fp(cursor_y);
- }
- else if(le_current.IsObject())
- {
- - cursor_base.x = cursor_x + pos_x;
- - cursor_base.y = cursor_y + pos_x;
- + cursor_base.x = int2fp(cursor_x + pos_x);
- + cursor_base.y = int2fp(cursor_y + pos_x);
- }
- - cursor_base.width = 32;
- - cursor_base.height = 32;
- + cursor_base.width = int2fp(32);
- + cursor_base.height = int2fp(32);
- for(std::list<BadGuy*>::iterator it = le_world->bad_guys.begin(); it != le_world->bad_guys.end(); ++it, ++i)
- if(rectcollision(cursor_base,(*it)->base))
- @@ -1522,7 +1525,7 @@
- {
- BadGuy* pbadguy = dynamic_cast<BadGuy*>(le_current.obj);
- - le_world->bad_guys.push_back(new BadGuy(cursor_x+scroll_x, cursor_y,pbadguy->kind,false));
- + le_world->bad_guys.push_back(new BadGuy(int2fp(cursor_x)+scroll_x, int2fp(cursor_y),pbadguy->kind,false));
- le_world->get_level()->badguy_data.push_back(le_world->bad_guys.back());
- }
- }
- @@ -1613,7 +1616,7 @@
- fillrect(x1*32-pos_x, y1*32,32* (x2 - x1 + 1),32 * (y2 - y1 + 1),173,234,177,103);
- }
- -void le_change(float x, float y, int tm, unsigned int c)
- +void le_change(fp x, fp y, int tm, unsigned int c)
- {
- if(le_world != NULL)
- {
- @@ -1626,13 +1629,13 @@
- switch(le_selection_mode)
- {
- case SM_CURSOR:
- - le_world->get_level()->change(x,y,tm,c);
- + le_world->get_level()->change(fp2int(x),fp2int(y),tm,c);
- base_type cursor_base;
- cursor_base.x = x;
- cursor_base.y = y;
- - cursor_base.width = 32;
- - cursor_base.height = 32;
- + cursor_base.width = int2fp(32);
- + cursor_base.height = int2fp(32);
- /* if there is a bad guy over there, remove it */
- for(std::list<BadGuy*>::iterator it = le_world->bad_guys.begin(); it != le_world->bad_guys.end(); ++it, ++i)
- @@ -1676,8 +1679,8 @@
- for(std::list<BadGuy*>::iterator it = le_world->bad_guys.begin();
- it != le_world->bad_guys.end(); /* will be at end of loop */)
- {
- - if((*it)->base.x/32 >= x1 && (*it)->base.x/32 <= x2
- - && (*it)->base.y/32 >= y1 && (*it)->base.y/32 <= y2)
- + if((*it)->base.x/32 >= int2fp(x1) && (*it)->base.x/32 <= int2fp(x2)
- + && (*it)->base.y/32 >= int2fp(y1) && (*it)->base.y/32 <= int2fp(y2))
- {
- delete (*it);
- it = le_world->bad_guys.erase(it);
- diff -Naur supertux-0.1.3/src.bak/level.h supertux-0.1.3/src/level.h
- --- supertux-0.1.3/src.bak/level.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/level.h 2014-12-06 18:04:19.000000000 -0500
- @@ -26,6 +26,7 @@
- #include "badguy.h"
- #include "lispreader.h"
- #include "musicref.h"
- +#include "fpmath.h"
- class Tile;
- @@ -88,9 +89,9 @@
- int bkgd_speed;
- int start_pos_x;
- int start_pos_y;
- - float gravity;
- + fp gravity;
- bool back_scrolling;
- - float hor_autoscroll_speed;
- + fp hor_autoscroll_speed;
- std::vector<BadGuyData> badguy_data;
- @@ -126,13 +127,13 @@
- void save(const std::string& subset, int level);
- /** Edit a piece of the map! */
- - void change(float x, float y, int tm, unsigned int c);
- + void change(int x, int y, int tm, unsigned int c);
- /** Resize the level to a new width */
- void change_size (int new_width);
- /** Return the id of the tile at position x/y */
- - unsigned int gettileid(float x, float y) const;
- + unsigned int gettileid(int x, int y) const;
- /** returns the id of the tile at position x,y
- * (these are logical and not pixel coordinates)
- */
- diff -Naur supertux-0.1.3/src.bak/lispreader.cpp supertux-0.1.3/src/lispreader.cpp
- --- supertux-0.1.3/src.bak/lispreader.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/lispreader.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -92,6 +92,9 @@
- case LISP_STREAM_ANY:
- return stream->v.any.next_char(stream->v.any.data);
- +
- + case LISP_STREAM_GZFILE :
- + return gzgetc(stream->v.gzfile);
- }
- assert(0);
- return EOF;
- @@ -114,6 +117,10 @@
- stream->v.any.unget_char(c, stream->v.any.data);
- break;
- + case LISP_STREAM_GZFILE :
- + gzungetc(c, stream->v.gzfile);
- + break;
- +
- default :
- assert(0);
- }
- @@ -315,6 +322,15 @@
- return stream;
- }
- +lisp_stream_t* lisp_stream_init_gzfile (lisp_stream_t *stream, gzFile file)
- +{
- + //return lisp_stream_init_any (stream, file, gzgetc, mygzungetc);
- + stream->type = LISP_STREAM_GZFILE;
- + stream->v.gzfile = file;
- +
- + return stream;
- +}
- +
- lisp_object_t*
- lisp_make_integer (int value)
- {
- @@ -1297,12 +1313,6 @@
- gzungetc(c, file);
- }
- -lisp_stream_t* lisp_stream_init_gzfile (lisp_stream_t *stream, gzFile file)
- -{
- - return lisp_stream_init_any (stream, file, gzgetc, mygzungetc);
- -}
- -#endif
- -
- lisp_object_t* lisp_read_from_gzfile(const char* filename)
- {
- bool done = false;
- @@ -1346,6 +1356,7 @@
- return root_obj;
- }
- +#endif
- bool has_suffix(const char* data, const char* suffix)
- {
- @@ -1367,25 +1378,31 @@
- lisp_object_t* lisp_read_from_file(const std::string& filename)
- {
- lisp_stream_t stream;
- + char fname[1024];
- +
- + strcpy(fname, filename.c_str());
- + if(!faccessible(fname)) {
- + strcat(fname, ".gz");
- + }
- - if (has_suffix(filename.c_str(), ".gz"))
- +/* if (has_suffix(filename.c_str(), ".gz"))
- {
- return lisp_read_from_gzfile(filename.c_str());
- }
- else
- - {
- + { */
- lisp_object_t* obj = 0;
- - FILE* in = fopen(filename.c_str(), "r");
- + gzFile in = gzopen(fname, "r");
- if (in)
- {
- - lisp_stream_init_file(&stream, in);
- + lisp_stream_init_gzfile(&stream, in);
- obj = lisp_read(&stream);
- - fclose(in);
- + gzclose(in);
- }
- return obj;
- - }
- +/* } */
- }
- // EOF //
- diff -Naur supertux-0.1.3/src.bak/lispreader.h supertux-0.1.3/src/lispreader.h
- --- supertux-0.1.3/src.bak/lispreader.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/lispreader.h 2014-12-06 18:04:19.000000000 -0500
- @@ -32,6 +32,7 @@
- #define LISP_STREAM_FILE 1
- #define LISP_STREAM_STRING 2
- #define LISP_STREAM_ANY 3
- +#define LISP_STREAM_GZFILE 4
- #define LISP_TYPE_INTERNAL -3
- #define LISP_TYPE_PARSE_ERROR -2
- @@ -62,6 +63,7 @@
- union
- {
- FILE *file;
- + gzFile gzfile;
- struct
- {
- char *buf;
- diff -Naur supertux-0.1.3/src.bak/Makefile supertux-0.1.3/src/Makefile
- --- supertux-0.1.3/src.bak/Makefile 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/Makefile 2014-12-07 11:39:50.000000000 -0500
- @@ -46,6 +46,7 @@
- AWK = gawk
- CC = gcc
- CCDEPMODE = depmode=gcc3
- +#CFLAGS = -g -O2 -I/usr/local/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
- CFLAGS = -g -O2 -I/usr/local/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT -pthread
- CPP = gcc -E
- CPPFLAGS =
- @@ -217,7 +218,9 @@
- music_manager.cpp \
- music_manager.h \
- musicref.cpp \
- -musicref.h
- +musicref.h \
- +fpmath.h \
- +fpmath.cpp
- subdir = src
- ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
- @@ -238,7 +241,7 @@
- type.$(OBJEXT) world.$(OBJEXT) worldmap.$(OBJEXT) \
- tile.$(OBJEXT) mousecursor.$(OBJEXT) resources.$(OBJEXT) \
- gameobjs.$(OBJEXT) sprite.$(OBJEXT) sprite_manager.$(OBJEXT) \
- - music_manager.$(OBJEXT) musicref.$(OBJEXT)
- + music_manager.$(OBJEXT) musicref.$(OBJEXT) fpmath.$(OBJEXT)
- supertux_OBJECTS = $(am_supertux_OBJECTS)
- supertux_LDADD = $(LDADD)
- supertux_DEPENDENCIES =
- @@ -249,10 +252,11 @@
- am__depfiles_maybe = depfiles
- DEP_FILES = ./$(DEPDIR)/badguy.Po ./$(DEPDIR)/bitmask.Po \
- ./$(DEPDIR)/button.Po ./$(DEPDIR)/collision.Po \
- - ./$(DEPDIR)/configfile.Po ./$(DEPDIR)/gameloop.Po \
- - ./$(DEPDIR)/gameobjs.Po ./$(DEPDIR)/globals.Po \
- - ./$(DEPDIR)/high_scores.Po ./$(DEPDIR)/intro.Po \
- - ./$(DEPDIR)/level.Po ./$(DEPDIR)/leveleditor.Po \
- + ./$(DEPDIR)/configfile.Po ./$(DEPDIR)/fpmath.Po \
- + ./$(DEPDIR)/gameloop.Po ./$(DEPDIR)/gameobjs.Po \
- + ./$(DEPDIR)/globals.Po ./$(DEPDIR)/high_scores.Po \
- + ./$(DEPDIR)/intro.Po ./$(DEPDIR)/level.Po \
- + ./$(DEPDIR)/leveleditor.Po \
- ./$(DEPDIR)/lispreader.Po ./$(DEPDIR)/menu.Po \
- ./$(DEPDIR)/mousecursor.Po \
- ./$(DEPDIR)/music_manager.Po \
- @@ -329,6 +333,7 @@
- include ./$(DEPDIR)/button.Po
- include ./$(DEPDIR)/collision.Po
- include ./$(DEPDIR)/configfile.Po
- +include ./$(DEPDIR)/fpmath.Po
- include ./$(DEPDIR)/gameloop.Po
- include ./$(DEPDIR)/gameobjs.Po
- include ./$(DEPDIR)/globals.Po
- diff -Naur supertux-0.1.3/src.bak/Makefile.am supertux-0.1.3/src/Makefile.am
- --- supertux-0.1.3/src.bak/Makefile.am 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/Makefile.am 2014-12-06 18:04:19.000000000 -0500
- @@ -74,7 +74,9 @@
- music_manager.cpp \
- music_manager.h \
- musicref.cpp \
- -musicref.h
- +musicref.h \
- +fpmath.h \
- +fpmath.cpp
- # EOF #
- diff -Naur supertux-0.1.3/src.bak/Makefile.in supertux-0.1.3/src/Makefile.in
- --- supertux-0.1.3/src.bak/Makefile.in 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/Makefile.in 2014-12-07 10:52:16.000000000 -0500
- @@ -215,7 +215,9 @@
- music_manager.cpp \
- music_manager.h \
- musicref.cpp \
- -musicref.h
- +musicref.h \
- +fpmath.h \
- +fpmath.cpp
- subdir = src
- ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
- @@ -236,7 +238,7 @@
- type.$(OBJEXT) world.$(OBJEXT) worldmap.$(OBJEXT) \
- tile.$(OBJEXT) mousecursor.$(OBJEXT) resources.$(OBJEXT) \
- gameobjs.$(OBJEXT) sprite.$(OBJEXT) sprite_manager.$(OBJEXT) \
- - music_manager.$(OBJEXT) musicref.$(OBJEXT)
- + music_manager.$(OBJEXT) musicref.$(OBJEXT) fpmath.$(OBJEXT)
- supertux_OBJECTS = $(am_supertux_OBJECTS)
- supertux_LDADD = $(LDADD)
- supertux_DEPENDENCIES =
- @@ -247,10 +249,11 @@
- am__depfiles_maybe = depfiles
- @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/badguy.Po ./$(DEPDIR)/bitmask.Po \
- @AMDEP_TRUE@ ./$(DEPDIR)/button.Po ./$(DEPDIR)/collision.Po \
- -@AMDEP_TRUE@ ./$(DEPDIR)/configfile.Po ./$(DEPDIR)/gameloop.Po \
- -@AMDEP_TRUE@ ./$(DEPDIR)/gameobjs.Po ./$(DEPDIR)/globals.Po \
- -@AMDEP_TRUE@ ./$(DEPDIR)/high_scores.Po ./$(DEPDIR)/intro.Po \
- -@AMDEP_TRUE@ ./$(DEPDIR)/level.Po ./$(DEPDIR)/leveleditor.Po \
- +@AMDEP_TRUE@ ./$(DEPDIR)/configfile.Po ./$(DEPDIR)/fpmath.Po \
- +@AMDEP_TRUE@ ./$(DEPDIR)/gameloop.Po ./$(DEPDIR)/gameobjs.Po \
- +@AMDEP_TRUE@ ./$(DEPDIR)/globals.Po ./$(DEPDIR)/high_scores.Po \
- +@AMDEP_TRUE@ ./$(DEPDIR)/intro.Po ./$(DEPDIR)/level.Po \
- +@AMDEP_TRUE@ ./$(DEPDIR)/leveleditor.Po \
- @AMDEP_TRUE@ ./$(DEPDIR)/lispreader.Po ./$(DEPDIR)/menu.Po \
- @AMDEP_TRUE@ ./$(DEPDIR)/mousecursor.Po \
- @AMDEP_TRUE@ ./$(DEPDIR)/music_manager.Po \
- @@ -327,6 +330,7 @@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/button.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collision.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/configfile.Po@am__quote@
- +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fpmath.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gameloop.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gameobjs.Po@am__quote@
- @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/globals.Po@am__quote@
- diff -Naur supertux-0.1.3/src.bak/menu.cpp supertux-0.1.3/src/menu.cpp
- --- supertux-0.1.3/src.bak/menu.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/menu.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -38,6 +38,7 @@
- #include "leveleditor.h"
- #include "timer.h"
- #include "high_scores.h"
- +#include "fpmath.h"
- #define FLICK_CURSOR_TIME 500
- @@ -328,10 +329,10 @@
- effect.init(false);
- }
- -void Menu::set_pos(int x, int y, float rw, float rh)
- +void Menu::set_pos(int x, int y, fp rw, fp rh)
- {
- - pos_x = x + (int)((float)get_width() * rw);
- - pos_y = y + (int)((float)get_height() * rh);
- + pos_x = x + fp2int(get_width() * rw);
- + pos_y = y + fp2int(get_height() * rh);
- }
- void
- diff -Naur supertux-0.1.3/src.bak/menu.h supertux-0.1.3/src/menu.h
- --- supertux-0.1.3/src.bak/menu.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/menu.h 2014-12-06 18:04:19.000000000 -0500
- @@ -26,6 +26,7 @@
- #include "timer.h"
- #include "type.h"
- #include "mousecursor.h"
- +#include "fpmath.h"
- /* IDs for menus */
- @@ -211,7 +212,7 @@
- void draw ();
- void draw_item(int index, int menu_width, int menu_height);
- - void set_pos(int x, int y, float rw = 0, float rh = 0);
- + void set_pos(int x, int y, fp rw = 0, fp rh = 0);
- /** translate a SDL_Event into a menu_action */
- void event(SDL_Event& event);
- diff -Naur supertux-0.1.3/src.bak/particlesystem.cpp supertux-0.1.3/src/particlesystem.cpp
- --- supertux-0.1.3/src.bak/particlesystem.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/particlesystem.cpp 2014-12-07 11:00:44.000000000 -0500
- @@ -26,12 +26,13 @@
- #include "world.h"
- #include "level.h"
- #include "scene.h"
- +#include "fpmath.h"
- ParticleSystem::ParticleSystem()
- {
- #ifndef RES320X240
- - virtual_width = screen->w;
- - virtual_height = screen->h;
- + virtual_width = int2fp(screen->w);
- + virtual_height = int2fp(screen->h);
- #else
- virtual_width = 640;
- virtual_height = 480;
- @@ -46,8 +47,11 @@
- }
- }
- -void ParticleSystem::draw(float scrollx, float scrolly, int layer)
- +void ParticleSystem::draw(fp scrollx, fp scrolly, int layer)
- {
- + int v_width = fp2int(virtual_width);
- + int v_height = fp2int(virtual_height);
- +
- std::vector<Particle*>::iterator i;
- for(i = particles.begin(); i != particles.end(); ++i) {
- Particle* particle = *i;
- @@ -55,12 +59,12 @@
- continue;
- // remap x,y coordinates onto screencoordinates
- - float x = fmodf(particle->x - scrollx, virtual_width);
- - if(x < 0) x += virtual_width;
- - float y = fmodf(particle->y - scrolly, virtual_height);
- - if(y < 0) y += virtual_height;
- - float xmax = fmodf(x + particle->texture->w, virtual_width);
- - float ymax = fmodf(y + particle->texture->h, virtual_height);
- + int x = fp2int((particle->x - scrollx) % (virtual_width));
- + if(x < 0) x += v_width;
- + int y = fp2int((particle->y - scrolly) % (virtual_height));
- + if(y < 0) y += v_height;
- + int xmax = (x + particle->texture->w) % (v_width);
- + int ymax = (y + particle->texture->h) % (v_height);
- // particle on screen
- #ifndef RES320X240
- @@ -69,16 +73,16 @@
- if(y >= screen->h && ymax >= screen->h)
- continue;
- - if(x > screen->w) x -= virtual_width;
- - if(y > screen->h) y -= virtual_height;
- + if(x > screen->w) x -= v_width;
- + if(y > screen->h) y -= v_height;
- #else
- if(x >= 640 && xmax >= 640)
- continue;
- if(y >= 480 && ymax >= 480)
- continue;
- - if(x > 640) x -= virtual_width;
- - if(y > 480) y -= virtual_height;
- + if(x > 640) x -= v_width;
- + if(y > 480) y -= v_height;
- #endif
- particle->texture->draw(x, y);
- @@ -92,27 +96,27 @@
- snowimages[2] = new Surface(datadir+"/images/shared/snow2.png", USE_ALPHA);
- #ifndef RES320X240
- - virtual_width = screen->w * 2;
- + virtual_width = int2fp(screen->w * 2);
- #else
- - virtual_width = 640 * 2;
- + virtual_width = int2fp(640 * 2);
- #endif
- // create some random snowflakes
- - size_t snowflakecount = size_t(virtual_width/10.0);
- + size_t snowflakecount = size_t(fp2int(virtual_width/10));
- for(size_t i=0; i<snowflakecount; ++i) {
- SnowParticle* particle = new SnowParticle;
- - particle->x = rand() % int(virtual_width);
- + particle->x = int2fp(rand() % fp2int(virtual_width));
- #ifndef RES320X240
- - particle->y = rand() % screen->h;
- + particle->y = int2fp(rand() % screen->h);
- #else
- - particle->y = rand() % 480;
- + particle->y = int2fp(rand() % 480);
- #endif
- particle->layer = i % 2;
- int snowsize = rand() % 3;
- particle->texture = snowimages[snowsize];
- do {
- - particle->speed = snowsize/60.0 + (float(rand()%10)/300.0);
- - } while(particle->speed < 0.01);
- - particle->speed *= World::current()->get_level()->gravity;
- + particle->speed = int2fp(snowsize)/60 + int2fp(rand()%10) / 300;
- + } while(particle->speed < FP_MIN_PARTICLE_SPEED);
- + particle->speed = fpmul(particle->speed, World::current()->get_level()->gravity);
- particles.push_back(particle);
- }
- @@ -124,19 +128,19 @@
- delete snowimages[i];
- }
- -void SnowParticleSystem::simulate(float elapsed_time)
- +void SnowParticleSystem::simulate(fp elapsed_time)
- {
- std::vector<Particle*>::iterator i;
- for(i = particles.begin(); i != particles.end(); ++i) {
- SnowParticle* particle = (SnowParticle*) *i;
- - particle->y += particle->speed * elapsed_time;
- + particle->y += fpmul(particle->speed, elapsed_time);
- #ifndef RES320X240
- - if(particle->y > screen->h) {
- + if(particle->y > virtual_height) {
- #else
- if(particle->y > 480) {
- #endif
- - particle->y = fmodf(particle->y , virtual_height);
- - particle->x = rand() % int(virtual_width);
- + particle->y = particle->y % virtual_height;
- + particle->x = rand() % virtual_width;
- }
- }
- }
- @@ -145,16 +149,16 @@
- {
- cloudimage = new Surface(datadir + "/images/shared/cloud.png", USE_ALPHA);
- - virtual_width = 2000.0;
- + virtual_width = int2fp(2000);
- // create some random clouds
- for(size_t i=0; i<15; ++i) {
- CloudParticle* particle = new CloudParticle;
- - particle->x = rand() % int(virtual_width);
- - particle->y = rand() % int(virtual_height);
- + particle->x = rand() % virtual_width;
- + particle->y = rand() % virtual_height;
- particle->layer = 0;
- particle->texture = cloudimage;
- - particle->speed = -float(250 + rand() % 200) / 1000.0;
- + particle->speed = -int2fp(250 + rand() % 200) / 1000;
- particles.push_back(particle);
- }
- @@ -165,11 +169,11 @@
- delete cloudimage;
- }
- -void CloudParticleSystem::simulate(float elapsed_time)
- +void CloudParticleSystem::simulate(fp elapsed_time)
- {
- std::vector<Particle*>::iterator i;
- for(i = particles.begin(); i != particles.end(); ++i) {
- CloudParticle* particle = (CloudParticle*) *i;
- - particle->x += particle->speed * elapsed_time;
- + particle->x += fpmul(particle->speed, elapsed_time);
- }
- }
- diff -Naur supertux-0.1.3/src.bak/particlesystem.h supertux-0.1.3/src/particlesystem.h
- --- supertux-0.1.3/src.bak/particlesystem.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/particlesystem.h 2014-12-06 18:04:19.000000000 -0500
- @@ -22,6 +22,7 @@
- #include <vector>
- #include "texture.h"
- +#include "fpmath.h"
- /**
- * This is the base class for particle systems. It is responsible for storing a
- @@ -44,9 +45,9 @@
- ParticleSystem();
- virtual ~ParticleSystem();
- - void draw(float scrollx, float scrolly, int layer);
- + void draw(fp scrollx, fp scrolly, int layer);
- - virtual void simulate(float elapsed_time) = 0;
- + virtual void simulate(fp elapsed_time) = 0;
- protected:
- class Particle
- @@ -55,13 +56,13 @@
- virtual ~Particle()
- { }
- - float x, y;
- + fp x, y;
- int layer;
- Surface* texture;
- };
- std::vector<Particle*> particles;
- - float virtual_width, virtual_height;
- + fp virtual_width, virtual_height;
- };
- class SnowParticleSystem : public ParticleSystem
- @@ -70,13 +71,13 @@
- SnowParticleSystem();
- virtual ~SnowParticleSystem();
- - virtual void simulate(float elapsed_time);
- + virtual void simulate(fp elapsed_time);
- private:
- class SnowParticle : public Particle
- {
- public:
- - float speed;
- + fp speed;
- };
- Surface* snowimages[3];
- @@ -88,13 +89,13 @@
- CloudParticleSystem();
- virtual ~CloudParticleSystem();
- - virtual void simulate(float elapsed_time);
- + virtual void simulate(fp elapsed_time);
- private:
- class CloudParticle : public Particle
- {
- public:
- - float speed;
- + fp speed;
- };
- Surface* cloudimage;
- diff -Naur supertux-0.1.3/src.bak/physic.cpp supertux-0.1.3/src/physic.cpp
- --- supertux-0.1.3/src.bak/physic.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/physic.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -26,6 +26,7 @@
- #include "timer.h"
- #include "world.h"
- #include "level.h"
- +#include "fpmath.h"
- Physic::Physic()
- : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true)
- @@ -44,19 +45,19 @@
- }
- void
- -Physic::set_velocity_x(float nvx)
- +Physic::set_velocity_x(fp nvx)
- {
- vx = nvx;
- }
- void
- -Physic::set_velocity_y(float nvy)
- +Physic::set_velocity_y(fp nvy)
- {
- vy = -nvy;
- }
- void
- -Physic::set_velocity(float nvx, float nvy)
- +Physic::set_velocity(fp nvx, fp nvy)
- {
- vx = nvx;
- vy = -nvy;
- @@ -72,44 +73,44 @@
- vy = -vy;
- }
- -float
- +fp
- Physic::get_velocity_x()
- {
- return vx;
- }
- -float
- +fp
- Physic::get_velocity_y()
- {
- return -vy;
- }
- void
- -Physic::set_acceleration_x(float nax)
- +Physic::set_acceleration_x(fp nax)
- {
- ax = nax;
- }
- void
- -Physic::set_acceleration_y(float nay)
- +Physic::set_acceleration_y(fp nay)
- {
- ay = -nay;
- }
- void
- -Physic::set_acceleration(float nax, float nay)
- +Physic::set_acceleration(fp nax, fp nay)
- {
- ax = nax;
- ay = -nay;
- }
- -float
- +fp
- Physic::get_acceleration_x()
- {
- return ax;
- }
- -float
- +fp
- Physic::get_acceleration_y()
- {
- return -ay;
- @@ -122,17 +123,19 @@
- }
- void
- -Physic::apply(float frame_ratio, float &x, float &y)
- +Physic::apply(fp frame_ratio, fp &x, fp &y)
- {
- - float gravity = World::current()->get_level()->gravity;
- - float grav;
- + fp gravity = World::current()->get_level()->gravity;
- + fp grav;
- if(gravity_enabled)
- - grav = gravity / 100.0;
- + grav = gravity / 100;
- else
- grav = 0;
- - x += vx * frame_ratio + ax * frame_ratio * frame_ratio;
- - y += vy * frame_ratio + (ay + grav) * frame_ratio * frame_ratio;
- - vx += ax * frame_ratio;
- - vy += (ay + grav) * frame_ratio;
- + fp frame_ratio_2 = fpmul(frame_ratio, frame_ratio);
- +
- + x += fpmul(vx, frame_ratio) + fpmul(ax, frame_ratio_2);
- + y += fpmul(vy, frame_ratio) + fpmul((ay + grav), frame_ratio_2);
- + vx += fpmul(ax, frame_ratio);
- + vy += fpmul((ay + grav), frame_ratio);
- }
- diff -Naur supertux-0.1.3/src.bak/physic.h supertux-0.1.3/src/physic.h
- --- supertux-0.1.3/src.bak/physic.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/physic.h 2014-12-06 18:04:19.000000000 -0500
- @@ -21,6 +21,8 @@
- #ifndef SUPERTUX_PHYSIC_H
- #define SUPERTUX_PHYSIC_H
- +#include "fpmath.h"
- +
- /** This is a very simplistic physics engine handling accelerated and constant
- * movement along with gravity.
- */
- @@ -34,40 +36,40 @@
- void reset();
- /** sets velocity to a fixed value */
- - void set_velocity(float vx, float vy);
- + void set_velocity(fp vx, fp vy);
- - void set_velocity_x(float vx);
- - void set_velocity_y(float vy);
- + void set_velocity_x(fp vx);
- + void set_velocity_y(fp vy);
- /** velocities invertion */
- void inverse_velocity_x();
- void inverse_velocity_y();
- - float get_velocity_x();
- - float get_velocity_y();
- + fp get_velocity_x();
- + fp get_velocity_y();
- /** sets acceleration applied to the object. (Note that gravity is
- * eventually added to the vertical acceleration)
- */
- - void set_acceleration(float ax, float ay);
- + void set_acceleration(fp ax, fp ay);
- - void set_acceleration_x(float ax);
- - void set_acceleration_y(float ay);
- + void set_acceleration_x(fp ax);
- + void set_acceleration_y(fp ay);
- - float get_acceleration_x();
- - float get_acceleration_y();
- + fp get_acceleration_x();
- + fp get_acceleration_y();
- /** enables or disables handling of gravity */
- void enable_gravity(bool gravity_enabled);
- /** applies the physical simulation to given x and y coordinates */
- - void apply(float frame_ratio, float &x, float &y);
- + void apply(fp frame_ratio, fp &x, fp &y);
- private:
- /// horizontal and vertical acceleration
- - float ax, ay;
- + fp ax, ay;
- /// horizontal and vertical velocity
- - float vx, vy;
- + fp vx, vy;
- /// should we respect gravity in out calculations?
- bool gravity_enabled;
- };
- diff -Naur supertux-0.1.3/src.bak/player.cpp supertux-0.1.3/src/player.cpp
- --- supertux-0.1.3/src.bak/player.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/player.cpp 2014-12-07 09:37:41.000000000 -0500
- @@ -26,6 +26,7 @@
- #include "tile.h"
- #include "sprite.h"
- #include "screen.h"
- +#include "fpmath.h"
- #define AUTOSCROLL_DEAD_INTERVAL 300
- @@ -68,14 +69,14 @@
- holding_something = false;
- - base.width = 32;
- - base.height = 32;
- + base.width = int2fp(32);
- + base.height = int2fp(32);
- size = SMALL;
- got_coffee = false;
- - base.x = plevel->start_pos_x;
- - base.y = plevel->start_pos_y;
- + base.x = int2fp(plevel->start_pos_x);
- + base.y = int2fp(plevel->start_pos_y);
- base.xm = 0;
- base.ym = 0;
- previous_base = old_base = base;
- @@ -138,8 +139,8 @@
- void
- Player::level_begin()
- {
- - base.x = 100;
- - base.y = 170;
- + base.x = int2fp(100);
- + base.y = int2fp(170);
- base.xm = 0;
- base.ym = 0;
- previous_base = old_base = base;
- @@ -158,7 +159,7 @@
- }
- void
- -Player::action(double frame_ratio)
- +Player::action(fp frame_ratio)
- {
- bool jumped_in_solid = false;
- @@ -211,7 +212,7 @@
- /* Land: */
- if (physic.get_velocity_y() < 0)
- {
- - base.y = (int)(((int)base.y / 32) * 32);
- + base.y = int2fp((fp2int(base.y) / 32) * 32);
- physic.set_velocity_y(0);
- }
- @@ -222,11 +223,11 @@
- if(jumped_in_solid)
- {
- - if (isbrick(base.x, base.y) ||
- - isfullbox(base.x, base.y))
- + if (isbrick(fp2int(base.x), fp2int(base.y)) ||
- + isfullbox(fp2int(base.x), fp2int(base.y)))
- {
- - World::current()->trygrabdistro(base.x, base.y - 32,BOUNCE);
- - World::current()->trybumpbadguy(base.x, base.y - 64);
- + World::current()->trygrabdistro(base.x, base.y - int2fp(32),BOUNCE);
- + World::current()->trybumpbadguy(base.x, base.y - int2fp(64));
- World::current()->trybreakbrick(base.x, base.y, size == SMALL, RIGHT);
- @@ -234,17 +235,17 @@
- World::current()->tryemptybox(base.x, base.y, RIGHT);
- }
- - if (isbrick(base.x+ 31, base.y) ||
- - isfullbox(base.x+ 31, base.y))
- + if (isbrick(fp2int(base.x)+ 31, fp2int(base.y)) ||
- + isfullbox(fp2int(base.x)+ 31, fp2int(base.y)))
- {
- - World::current()->trygrabdistro(base.x+ 31, base.y - 32,BOUNCE);
- - World::current()->trybumpbadguy(base.x+ 31, base.y - 64);
- + World::current()->trygrabdistro(base.x+ int2fp(31), base.y - int2fp(32),BOUNCE);
- + World::current()->trybumpbadguy(base.x+ int2fp(31), base.y - int2fp(64));
- if(size == BIG)
- - World::current()->trybreakbrick(base.x+ 31, base.y, size == SMALL, LEFT);
- + World::current()->trybreakbrick(base.x+ int2fp(31), base.y, size == SMALL, LEFT);
- - bumpbrick(base.x+ 31, base.y);
- - World::current()->tryemptybox(base.x+ 31, base.y, LEFT);
- + bumpbrick(base.x+ int2fp(31), base.y);
- + World::current()->tryemptybox(base.x+ int2fp(31), base.y, LEFT);
- }
- }
- @@ -252,8 +253,11 @@
- if (jumped_in_solid)
- {
- - ++base.y;
- - ++old_base.y;
- + //FIXME: check use of ++
- + //++base.y;
- + //++old_base.y;
- + base.y += int2fp(1);
- + old_base.y += int2fp(1);
- if(on_ground())
- {
- /* Make sure jumping is off. */
- @@ -275,75 +279,76 @@
- bool
- Player::on_ground()
- {
- - return ( issolid(base.x + base.width / 2, base.y + base.height) ||
- - issolid(base.x + 1, base.y + base.height) ||
- - issolid(base.x + base.width - 1, base.y + base.height) );
- + return ( issolid(fp2int(base.x + base.width / 2), fp2int(base.y + base.height)) ||
- + issolid(fp2int(base.x) + 1, fp2int(base.y + base.height)) ||
- + issolid(fp2int(base.x + base.width) - 1, fp2int(base.y + base.height)) );
- }
- bool
- Player::under_solid()
- {
- - return ( issolid(base.x + base.width / 2, base.y) ||
- - issolid(base.x + 1, base.y) ||
- - issolid(base.x + base.width - 1, base.y) );
- + return ( issolid(fp2int(base.x + base.width / 2), fp2int(base.y)) ||
- + issolid(fp2int(base.x) + 1, fp2int(base.y)) ||
- + issolid(fp2int(base.x + base.width) - 1, fp2int(base.y)) );
- }
- void
- Player::handle_horizontal_input()
- {
- - float vx = physic.get_velocity_x();
- - float vy = physic.get_velocity_y();
- - float ax = physic.get_acceleration_x();
- - float ay = physic.get_acceleration_y();
- + fp vx = physic.get_velocity_x();
- + fp vy = physic.get_velocity_y();
- + fp ax = physic.get_acceleration_x();
- + fp ay = physic.get_acceleration_y();
- - float dirsign = 0;
- - if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) {
- + int dirsign = 0;
- + if(input.left == DOWN && input.right == UP && (!duck || vy != 0)) {
- old_dir = dir;
- dir = LEFT;
- dirsign = -1;
- - } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) {
- + } else if(input.left == UP && input.right == DOWN && (!duck || vy != 0)) {
- old_dir = dir;
- dir = RIGHT;
- dirsign = 1;
- }
- if (input.fire == UP) {
- - ax = dirsign * WALK_ACCELERATION_X;
- + ax = dirsign * FP_WALK_ACCELERATION_X;
- // limit speed
- - if(vx >= MAX_WALK_XM && dirsign > 0) {
- - vx = MAX_WALK_XM;
- + if(vx >= FP_MAX_WALK_XM && dirsign > 0) {
- + vx = FP_MAX_WALK_XM;
- ax = 0;
- - } else if(vx <= -MAX_WALK_XM && dirsign < 0) {
- - vx = -MAX_WALK_XM;
- + } else if(vx <= -FP_MAX_WALK_XM && dirsign < 0) {
- + vx = -FP_MAX_WALK_XM;
- ax = 0;
- }
- } else {
- - ax = dirsign * RUN_ACCELERATION_X;
- + ax = dirsign * FP_RUN_ACCELERATION_X;
- // limit speed
- - if(vx >= MAX_RUN_XM && dirsign > 0) {
- - vx = MAX_RUN_XM;
- + if(vx >= FP_MAX_RUN_XM && dirsign > 0) {
- + vx = FP_MAX_RUN_XM;
- ax = 0;
- - } else if(vx <= -MAX_RUN_XM && dirsign < 0) {
- - vx = -MAX_RUN_XM;
- + } else if(vx <= -FP_MAX_RUN_XM && dirsign < 0) {
- + vx = -FP_MAX_RUN_XM;
- ax = 0;
- }
- }
- // we can reach WALK_SPEED without any acceleration
- - if(dirsign != 0 && fabs(vx) < WALK_SPEED) {
- - vx = dirsign * WALK_SPEED;
- + if(dirsign != 0 && fabs(vx) < FP_WALK_SPEED) {
- + vx = dirsign * FP_WALK_SPEED;
- }
- // changing directions?
- if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
- - if(fabs(vx)>SKID_XM && !skidding_timer.check()) {
- + if(fabs(vx)>FP_SKID_XM && !skidding_timer.check()) {
- skidding_timer.start(SKID_TIME);
- #ifndef GP2X
- play_sound(sounds[SND_SKID], SOUND_CENTER_SPEAKER);
- #else
- play_chunk(SND_SKID);
- #endif
- - ax *= 2.5;
- + //ax *= 2.5;
- + ax = ax*2 + ax/2;
- } else {
- ax *= 2;
- }
- @@ -351,18 +356,20 @@
- // we get slower when not pressing any keys
- if(dirsign == 0) {
- - if(fabs(vx) < WALK_SPEED) {
- + if(abs(vx) < FP_WALK_SPEED) {
- vx = 0;
- ax = 0;
- } else if(vx < 0) {
- - ax = WALK_ACCELERATION_X * 1.5;
- + //ax = WALK_ACCELERATION_X * 1.5;
- + ax = FP_WALK_ACCELERATION_X + FP_WALK_ACCELERATION_X/2;
- } else {
- - ax = WALK_ACCELERATION_X * -1.5;
- + //ax = WALK_ACCELERATION_X * -1.5;
- + ax = -FP_WALK_ACCELERATION_X - FP_WALK_ACCELERATION_X/2;
- }
- }
- // if we're on ice slow down acceleration or deceleration
- - if (isice(base.x, base.y + base.height))
- + if (isice(fp2int(base.x), fp2int(base.y + base.height)))
- {
- /* the acceleration/deceleration rate on ice is inversely proportional to
- * the current velocity.
- @@ -371,7 +378,7 @@
- // increasing 1 will increase acceleration/deceleration rate
- // decreasing 1 will decrease acceleration/deceleration rate
- // must stay above zero, though
- - if (ax != 0) ax *= 1 / fabs(vx);
- + if (ax != 0) ax = fpmul(ax, fpdiv(int2fp(1), abs(vx)));
- }
- physic.set_velocity(vx, vy);
- @@ -387,12 +394,14 @@
- if (on_ground())
- {
- // jump higher if we are running
- - if (fabs(physic.get_velocity_x()) > MAX_WALK_XM)
- - physic.set_velocity_y(5.8);
- + if (abs(physic.get_velocity_x()) > FP_MAX_WALK_XM)
- + physic.set_velocity_y(FP_RUN_JUMP_SPEED);
- else
- - physic.set_velocity_y(5.2);
- + physic.set_velocity_y(FP_WALK_JUMP_SPEED);
- - --base.y;
- + //FIXME: check use of --
- + //--base.y;
- + base.y -= int2fp(1);
- jumping = true;
- can_jump = false;
- if (size == SMALL)
- @@ -418,9 +427,9 @@
- }
- }
- - if ( (issolid(base.x + base.width / 2, base.y + base.height + 64) ||
- - issolid(base.x + 1, base.y + base.height + 64) ||
- - issolid(base.x + base.width - 1, base.y + base.height + 64))
- + if ( (issolid(fp2int(base.x + base.width / 2), fp2int(base.y + base.height) + 64) ||
- + issolid(fp2int(base.x) + 1, fp2int(base.y + base.height) + 64) ||
- + issolid(fp2int(base.x + base.width) - 1, fp2int(base.y + base.height) + 64))
- && jumping == false
- && can_jump == false
- && input.up == DOWN
- @@ -481,16 +490,16 @@
- if (input.down == DOWN && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground())
- {
- duck = true;
- - base.height = 32;
- - base.y += 32;
- + base.height = int2fp(32);
- + base.y += int2fp(32);
- // changing base size confuses collision otherwise
- old_base = previous_base = base;
- }
- else if(input.down == UP && size == BIG && duck && physic.get_velocity_y() == 0 && on_ground())
- {
- duck = false;
- - base.y -= 32;
- - base.height = 64;
- + base.y -= int2fp(32);
- + base.height = int2fp(64);
- // changing base size confuses collision otherwise
- old_base = previous_base = base;
- }
- @@ -503,8 +512,8 @@
- return;
- size = BIG;
- - base.height = 64;
- - base.y -= 32;
- + base.height = int2fp(64);
- + base.y -= int2fp(32);
- old_base = previous_base = base;
- }
- @@ -526,15 +535,15 @@
- if (!dying)
- {
- World::current()->trygrabdistro(base.x, base.y, NO_BOUNCE);
- - World::current()->trygrabdistro(base.x+ 31, base.y, NO_BOUNCE);
- + World::current()->trygrabdistro(base.x+ int2fp(31), base.y, NO_BOUNCE);
- World::current()->trygrabdistro(base.x, base.y + base.height, NO_BOUNCE);
- - World::current()->trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE);
- + World::current()->trygrabdistro(base.x+ int2fp(31), base.y + base.height, NO_BOUNCE);
- if(size == BIG)
- {
- World::current()->trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE);
- - World::current()->trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE);
- + World::current()->trygrabdistro(base.x+ int2fp(31), base.y + base.height / 2, NO_BOUNCE);
- }
- }
- @@ -561,7 +570,7 @@
- {
- if (dying == DYING_SQUISHED)
- {
- - smalltux_gameover->draw(base.x - scroll_x, base.y);
- + smalltux_gameover->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else
- {
- @@ -577,46 +586,46 @@
- if (duck && size != SMALL)
- {
- if (dir == RIGHT)
- - sprite->duck_right->draw(base.x - scroll_x, base.y);
- + sprite->duck_right->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - sprite->duck_left->draw(base.x - scroll_x, base.y);
- + sprite->duck_left->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else if (skidding_timer.started())
- {
- if (dir == RIGHT)
- - sprite->skid_right->draw(base.x - scroll_x, base.y);
- + sprite->skid_right->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - sprite->skid_left->draw(base.x - scroll_x, base.y);
- + sprite->skid_left->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else if (kick_timer.started())
- {
- if (dir == RIGHT)
- - sprite->kick_right->draw(base.x - scroll_x, base.y);
- + sprite->kick_right->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - sprite->kick_left->draw(base.x - scroll_x, base.y);
- + sprite->kick_left->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else if (physic.get_velocity_y() != 0)
- {
- if (dir == RIGHT)
- - sprite->jump_right->draw(base.x - scroll_x, base.y);
- + sprite->jump_right->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - sprite->jump_left->draw(base.x - scroll_x, base.y);
- + sprite->jump_left->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else
- {
- - if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
- + if (abs(physic.get_velocity_x()) < int2fp(1)) // standing
- {
- if (dir == RIGHT)
- - sprite->stand_right->draw( base.x - scroll_x, base.y);
- + sprite->stand_right->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - sprite->stand_left->draw( base.x - scroll_x, base.y);
- + sprite->stand_left->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else // moving
- {
- if (dir == RIGHT)
- - sprite->walk_right->draw(base.x - scroll_x, base.y);
- + sprite->walk_right->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - sprite->walk_left->draw(base.x - scroll_x, base.y);
- + sprite->walk_left->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- }
- @@ -624,9 +633,9 @@
- if (holding_something && physic.get_velocity_y() == 0 && !duck)
- {
- if (dir == RIGHT)
- - sprite->grab_right->draw(base.x - scroll_x, base.y);
- + sprite->grab_right->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - sprite->grab_left->draw(base.x - scroll_x, base.y);
- + sprite->grab_left->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- // Draw blinking star overlay
- @@ -634,16 +643,26 @@
- (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3))
- {
- if (size == SMALL || duck)
- - smalltux_star->draw(base.x - scroll_x, base.y);
- + smalltux_star->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- else
- - largetux_star->draw(base.x - scroll_x, base.y);
- + largetux_star->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- }
- }
- - if (debug_mode)
- - fillrect(base.x - scroll_x, base.y,
- - base.width, base.height, 75,75,75, 150);
- + if (debug_mode) {
- + fillrect(fp2int(base.x - scroll_x), fp2int(base.y),
- + fp2int(base.width), fp2int(base.height), 75,75,75, 150);
- + printf("scroll_x = %4.2f, player (%3.1f,%3.1f) v (%2.2f,%2.2f) a (%1.3f,%1.3f) \r",
- + fp2float(scroll_x),
- + fp2float(base.x),
- + fp2float(base.y),
- + fp2float(physic.get_velocity_x()),
- + fp2float(physic.get_velocity_y()),
- + fp2float(physic.get_acceleration_x()),
- + fp2float(physic.get_acceleration_y()));
- + }
- +
- }
- void
- @@ -666,7 +685,7 @@
- {
- holding_something = true;
- pbad_c->mode = BadGuy::HELD;
- - pbad_c->base.y-=8;
- + pbad_c->base.y -= int2fp(8);
- }
- else if (pbad_c->mode == BadGuy::FLAT)
- {
- @@ -735,7 +754,7 @@
- else
- {
- size = SMALL;
- - base.height = 32;
- + base.height = int2fp(32);
- duck = false;
- }
- safe_timer.start(TUX_SAFE_TIME);
- @@ -744,9 +763,9 @@
- {
- physic.enable_gravity(true);
- physic.set_acceleration(0, 0);
- - physic.set_velocity(0, 7);
- + physic.set_velocity(0, FP_RUN_JUMP_SPEED);
- if(dying != DYING_SQUISHED)
- - --player_status.lives;
- + --player_status.lives;
- dying = DYING_SQUISHED;
- }
- }
- @@ -761,9 +780,9 @@
- bool Player::is_dead()
- {
- #ifndef RES320X240
- - if(base.y > screen->h || base.x < scroll_x - AUTOSCROLL_DEAD_INTERVAL) // last condition can happen in auto-scrolling
- + if(base.y > int2fp(screen->h) || base.x < scroll_x - int2fp(AUTOSCROLL_DEAD_INTERVAL)) // last condition can happen in auto-scrolling
- #else
- - if(base.y > 640 || base.x < scroll_x - AUTOSCROLL_DEAD_INTERVAL) // last condition can happen in auto-scrolling
- + if(base.y > int2fp(640) || base.x < scroll_x - int2fp(AUTOSCROLL_DEAD_INTERVAL)) // last condition can happen in auto-scrolling
- #endif
- return true;
- else
- @@ -776,7 +795,7 @@
- {
- got_coffee = false;
- size = SMALL;
- - base.height = 32;
- + base.height = int2fp(32);
- }
- void
- @@ -791,9 +810,9 @@
- /* Keep in-bounds, vertically: */
- #ifndef RES320X240
- - if (base.y > screen->h)
- + if (base.y > int2fp(screen->h))
- #else
- - if (base.y > 640)
- + if (base.y > int2fp(640))
- #endif
- {
- kill(KILL);
- @@ -812,11 +831,11 @@
- if(hor_autoscroll)
- {
- if(base.x == scroll_x)
- - if((issolid(base.x+32, base.y) || (size != SMALL && !duck && issolid(base.x+32, base.y+32))) && (dying == DYING_NOT))
- + if((issolid(fp2int(base.x)+32, fp2int(base.y)) || (size != SMALL && !duck && issolid(fp2int(base.x)+32, fp2int(base.y)+32))) && (dying == DYING_NOT))
- kill(KILL);
- - if(base.x + base.width > scroll_x + screen->w)
- - base.x = scroll_x + screen->w - base.width;
- + if(base.x + base.width > scroll_x + int2fp(screen->w))
- + base.x = scroll_x + int2fp(screen->w) - base.width;
- }
- }
- diff -Naur supertux-0.1.3/src.bak/player.h supertux-0.1.3/src/player.h
- --- supertux-0.1.3/src.bak/player.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/player.h 2014-12-06 18:04:19.000000000 -0500
- @@ -28,6 +28,7 @@
- #include "collision.h"
- #include "sound.h"
- #include "physic.h"
- +#include "fpmath.h"
- /* Times: */
- @@ -137,7 +138,7 @@
- void init();
- int key_event(SDLKey key, int state);
- void level_begin();
- - void action(double frame_ratio);
- + void action(fp frame_ratio);
- void handle_input();
- void grabdistros();
- void draw();
- diff -Naur supertux-0.1.3/src.bak/scene.cpp supertux-0.1.3/src/scene.cpp
- --- supertux-0.1.3/src.bak/scene.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/scene.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -69,7 +69,7 @@
- }
- // FIXME: Move this into a view class
- -float scroll_x;
- +fp scroll_x;
- unsigned int global_frame_counter;
- diff -Naur supertux-0.1.3/src.bak/scene.h supertux-0.1.3/src/scene.h
- --- supertux-0.1.3/src.bak/scene.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/scene.h 2014-12-06 18:04:19.000000000 -0500
- @@ -22,6 +22,7 @@
- #include "texture.h"
- #include "timer.h"
- +#include "fpmath.h"
- #define FRAME_RATE 10 // 100 Frames per second (10ms)
- @@ -46,7 +47,7 @@
- extern PlayerStatus player_status;
- -extern float scroll_x;
- +extern fp scroll_x;
- extern unsigned int global_frame_counter;
- #endif /*SUPERTUX_SCENE_H*/
- diff -Naur supertux-0.1.3/src.bak/screen.cpp supertux-0.1.3/src/screen.cpp
- --- supertux-0.1.3/src.bak/screen.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/screen.cpp 2014-12-07 09:41:33.000000000 -0500
- @@ -71,21 +71,26 @@
- {
- glBegin(GL_QUADS);
- glColor3ub(top_clr.red, top_clr.green, top_clr.blue);
- - glVertex2f(0, 0);
- - glVertex2f(640, 0);
- + glVertex2i(0, 0);
- + glVertex2i(640, 0);
- glColor3ub(bot_clr.red, bot_clr.green, bot_clr.blue);
- - glVertex2f(640, 480);
- - glVertex2f(0, 480);
- + glVertex2i(640, 480);
- + glVertex2i(0, 480);
- glEnd();
- }
- else
- {
- #endif
- - for(float y = 0; y < 480; y += 2)
- - fillrect(0, (int)y, 640, 2,
- - (int)(((float)(top_clr.red-bot_clr.red)/(0-480)) * y + top_clr.red),
- - (int)(((float)(top_clr.green-bot_clr.green)/(0-480)) * y + top_clr.green),
- - (int)(((float)(top_clr.blue-bot_clr.blue)/(0-480)) * y + top_clr.blue), 255);
- +// for(float y = 0; y < 480; y += 2)
- +// fillrect(0, (int)y, 640, 2,
- +// (int)(((float)(top_clr.red-bot_clr.red)/(0-480)) * y + top_clr.red),
- +// (int)(((float)(top_clr.green-bot_clr.green)/(0-480)) * y + top_clr.green),
- +// (int)(((float)(top_clr.blue-bot_clr.blue)/(0-480)) * y + top_clr.blue), 255);
- + for(int y = 0; y < 480; y += 2)
- + fillrect(0, y, 640, 2,
- + (top_clr.red - bot_clr.red) * y / (0-480) + top_clr.red,
- + (top_clr.green - bot_clr.green) * y / (0-480) + top_clr.green,
- + (top_clr.blue - bot_clr.blue) * y / (0-480) + top_clr.blue, 255);
- /* calculates the color for each line, based in the generic equation for functions: y = mx + b */
- #ifndef NOOPENGL
- @@ -110,25 +115,25 @@
- void fade(Surface *surface, int seconds, bool fade_out)
- {
- -float alpha;
- +fp alpha;
- if (fade_out)
- alpha = 0;
- else
- - alpha = 255;
- + alpha = int2fp(255);
- int cur_time, old_time;
- cur_time = SDL_GetTicks();
- - while(alpha >= 0 && alpha < 256)
- + while(alpha >= 0 && alpha < int2fp(256))
- {
- - surface->draw(0,0,(int)alpha);
- + surface->draw(0,0,fp2int(alpha));
- flipscreen();
- old_time = cur_time;
- cur_time = SDL_GetTicks();
- /* Calculate the next alpha value */
- - float calc = (float) ((cur_time - old_time) / seconds);
- + fp calc = (int2fp(cur_time - old_time) / seconds);
- if(fade_out)
- alpha += 255 * calc;
- else
- @@ -279,7 +284,7 @@
- /* --- FILL A RECT --- */
- -void fillrect(float x, float y, float w, float h, int r, int g, int b, int a)
- +void fillrect(int x, int y, int w, int h, int r, int g, int b, int a)
- {
- if(w < 0)
- {
- @@ -307,10 +312,10 @@
- glColor4ub(r, g, b,a);
- glBegin(GL_POLYGON);
- - glVertex2f(x, y);
- - glVertex2f(x+w, y);
- - glVertex2f(x+w, y+h);
- - glVertex2f(x, y+h);
- + glVertex2i(x, y);
- + glVertex2i(x+w, y);
- + glVertex2i(x+w, y+h);
- + glVertex2i(x, y+h);
- glEnd();
- glDisable(GL_BLEND);
- }
- @@ -320,10 +325,10 @@
- SDL_Rect src, rect;
- SDL_Surface *temp = NULL;
- - rect.x = (int)x;
- - rect.y = (int)y;
- - rect.w = (int)w;
- - rect.h = (int)h;
- + rect.x = x;
- + rect.y = y;
- + rect.w = w;
- + rect.h = h;
- if(a != 255)
- {
- diff -Naur supertux-0.1.3/src.bak/screen.h supertux-0.1.3/src/screen.h
- --- supertux-0.1.3/src.bak/screen.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/screen.h 2014-12-06 18:04:19.000000000 -0500
- @@ -47,7 +47,7 @@
- void drawline(int x1, int y1, int x2, int y2, int r, int g, int b, int a);
- void clearscreen(int r, int g, int b);
- void drawgradient(Color top_clr, Color bot_clr);
- -void fillrect(float x, float y, float w, float h, int r, int g, int b, int a);
- +void fillrect(int x, int y, int w, int h, int r, int g, int b, int a);
- //void black_fade(Surface* surface, int seconds, bool fade_out);
- void fade(const std::string& surface, int seconds, bool fade_out);
- void updatescreen(void);
- diff -Naur supertux-0.1.3/src.bak/setup.cpp supertux-0.1.3/src/setup.cpp
- --- supertux-0.1.3/src.bak/setup.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/setup.cpp 2014-12-07 09:45:48.000000000 -0500
- @@ -423,7 +423,11 @@
- #else
- options_menu->additem(MN_DEACTIVE,"OpenGL (not supported)",use_gl, 0, MNID_OPENGL);
- #endif
- +#ifndef NOWINDOWED
- options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0, MNID_FULLSCREEN);
- +#else
- + options_menu->additem(MN_DEACTIVE,"Fullscreen (always on)",use_fullscreen, 0, MNID_FULLSCREEN);
- +#endif
- #endif
- if(audio_device)
- {
- @@ -777,6 +781,10 @@
- exit(1);
- }
- }
- + if ((screen != NULL) && (debug_mode))
- + {
- + printf("Screen bpp = %d\n", screen->format->BitsPerPixel);
- + }
- }
- void st_video_setup_gl(void)
- diff -Naur supertux-0.1.3/src.bak/special.cpp supertux-0.1.3/src/special.cpp
- --- supertux-0.1.3/src.bak/special.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/special.cpp 2014-12-07 11:34:37.000000000 -0500
- @@ -30,6 +30,7 @@
- #include "player.h"
- #include "sprite_manager.h"
- #include "resources.h"
- +#include "fpmath.h"
- Sprite* img_bullet;
- Sprite* img_star;
- @@ -37,31 +38,26 @@
- Sprite* img_iceflower;
- Sprite* img_1up;
- -#define GROWUP_SPEED 1.0f
- -
- -#define BULLET_STARTING_YM 0
- -#define BULLET_XM 6
- -
- void
- -Bullet::init(float x, float y, float xm, Direction dir)
- +Bullet::init(fp x, fp y, fp xm, Direction dir)
- {
- life_count = 3;
- - base.width = 4;
- - base.height = 4;
- + base.width = int2fp(4);
- + base.height = int2fp(4);
- if (dir == RIGHT)
- {
- - base.x = x + 32;
- - base.xm = BULLET_XM + xm;
- + base.x = x + int2fp(32);
- + base.xm = FP_BULLET_XM + xm;
- }
- else
- {
- base.x = x;
- - base.xm = -BULLET_XM + xm;
- + base.xm = -FP_BULLET_XM + xm;
- }
- base.y = y;
- - base.ym = BULLET_STARTING_YM;
- + base.ym = FP_BULLET_STARTING_YM;
- old_base = base;
- }
- @@ -81,43 +77,48 @@
- }
- void
- -Bullet::action(double frame_ratio)
- +Bullet::action(fp frame_ratio)
- {
- - frame_ratio *= 0.5f;
- + frame_ratio /= 2;
- - float old_y = base.y;
- + fp old_y = base.y;
- - base.x = base.x + base.xm * frame_ratio;
- - base.y = base.y + base.ym * frame_ratio;
- + base.x = base.x + fpmul(base.xm, frame_ratio);
- + base.y = base.y + fpmul(base.ym, frame_ratio);
- collision_swept_object_map(&old_base,&base);
- - if (issolid(base.x, base.y + 4) || issolid(base.x, base.y))
- + int base_x = fp2int(base.x);
- + int base_y = fp2int(base.y);
- + if (issolid(base_x, base_y + 4) || issolid(base_x, base_y))
- {
- base.y = old_y;
- base.ym = -base.ym;
- - if (base.ym > 9)
- - base.ym = 9;
- - else if (base.ym < -9)
- - base.ym = -9;
- + if (base.ym > int2fp(9))
- + base.ym = int2fp(9);
- + else if (base.ym < int2fp(-9))
- + base.ym = int2fp(-9);
- life_count -= 1;
- }
- - base.ym = base.ym + 0.5 * frame_ratio;
- + base.ym = base.ym + frame_ratio/2;
- +
- + base_x = fp2int(base.x);
- + base_y = fp2int(base.y);
- #ifndef RES320X240
- if (base.x < scroll_x ||
- - base.x > scroll_x + screen->w ||
- - base.y > screen->h ||
- - issolid(base.x + 4, base.y + 2) ||
- - issolid(base.x, base.y + 2) ||
- + base.x > scroll_x + int2fp(screen->w) ||
- + base.y > int2fp(screen->h) ||
- + issolid(base_x + 4, base_y + 2) ||
- + issolid(base_x, base_y + 2) ||
- life_count <= 0)
- #else
- if (base.x < scroll_x ||
- - base.x > scroll_x + 640 ||
- - base.y > 480 ||
- - issolid(base.x + 4, base.y + 2) ||
- - issolid(base.x, base.y + 2) ||
- + base.x > scroll_x + int2fp(640) ||
- + base.y > int2fp(480) ||
- + issolid(base_x + 4, base_y + 2) ||
- + issolid(base_x, base_y + 2) ||
- life_count <= 0)
- #endif
- {
- @@ -131,13 +132,13 @@
- {
- #ifndef RES320X240
- if (base.x >= scroll_x - base.width &&
- - base.x <= scroll_x + screen->w)
- + base.x <= scroll_x + int2fp(screen->w))
- #else
- if (base.x >= scroll_x - base.width &&
- - base.x <= scroll_x + 640)
- + base.x <= scroll_x + int2fp(640))
- #endif
- {
- - img_bullet->draw(base.x - scroll_x, base.y);
- + img_bullet->draw(fp2int(base.x - scroll_x), fp2int(base.y));
- }
- }
- @@ -150,12 +151,12 @@
- }
- void
- -Upgrade::init(float x_, float y_, Direction dir_, UpgradeKind kind_)
- +Upgrade::init(fp x_, fp y_, Direction dir_, UpgradeKind kind_)
- {
- kind = kind_;
- dir = dir_;
- - base.width = 32;
- + base.width = int2fp(32);
- base.height = 0;
- base.x = x_;
- base.y = y_;
- @@ -165,15 +166,15 @@
- physic.enable_gravity(false);
- if(kind == UPGRADE_1UP || kind == UPGRADE_HERRING) {
- - physic.set_velocity(dir == LEFT ? -1 : 1, 4);
- + physic.set_velocity(dir == LEFT ? -FP_UPGRADE_SPEED_X : FP_UPGRADE_SPEED_X, FP_UPGRADE_SPEED_Y);
- physic.enable_gravity(true);
- - base.height = 32;
- + base.height = int2fp(32);
- } else if (kind == UPGRADE_ICEFLOWER) {
- // nothing
- } else if (kind == UPGRADE_GROWUP) {
- - physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
- + physic.set_velocity(dir == LEFT ? -FP_GROWUP_SPEED : FP_GROWUP_SPEED, 0);
- } else {
- - physic.set_velocity(dir == LEFT ? -2 : 2, 0);
- + physic.set_velocity(dir == LEFT ? -FP_BOUNCE_SPEED : FP_BOUNCE_SPEED, 0);
- }
- }
- @@ -193,28 +194,28 @@
- }
- void
- -Upgrade::action(double frame_ratio)
- +Upgrade::action(fp frame_ratio)
- {
- if (kind == UPGRADE_ICEFLOWER || kind == UPGRADE_GROWUP) {
- - if (base.height < 32) {
- + if (base.height < int2fp(32)) {
- /* Rise up! */
- - base.height = base.height + 0.7 * frame_ratio;
- - if(base.height > 32)
- - base.height = 32;
- + base.height = base.height + fpmul(FP_RISE_RATIO, frame_ratio);
- + if(base.height > int2fp(32))
- + base.height = int2fp(32);
- return;
- }
- }
- /* Away from the screen? Kill it! */
- - if(base.x < scroll_x - OFFSCREEN_DISTANCE) {
- + if(base.x < scroll_x - int2fp(OFFSCREEN_DISTANCE)) {
- remove_me();
- return;
- }
- #ifndef RES320X240
- - if(base.y > screen->h) {
- + if(base.y > int2fp(screen->h)) {
- #else
- - if(base.y > 640) {
- + if(base.y > int2fp(640)) {
- #endif
- remove_me();
- return;
- @@ -230,21 +231,21 @@
- if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
- // falling?
- if(physic.get_velocity_y() != 0) {
- - if(issolid(base.x, base.y + base.height)) {
- - base.y = int(base.y / 32) * 32;
- - old_base = base;
- + if(issolid(fp2int(base.x), fp2int(base.y + base.height))) {
- + base.y = int2fp((fp2int(base.y) / 32) * 32);
- + old_base = base;
- if(kind == UPGRADE_GROWUP) {
- physic.enable_gravity(false);
- - physic.set_velocity(dir == LEFT ? -GROWUP_SPEED : GROWUP_SPEED, 0);
- + physic.set_velocity(dir == LEFT ? -FP_GROWUP_SPEED : FP_GROWUP_SPEED, 0);
- } else if(kind == UPGRADE_HERRING) {
- - physic.set_velocity(dir == LEFT ? -2 : 2, 3);
- + physic.set_velocity(dir == LEFT ? -FP_BOUNCE_SPEED : FP_BOUNCE_SPEED, FP_BOUNCE_SPEED);
- }
- }
- } else {
- if((physic.get_velocity_x() < 0
- - && !issolid(base.x+base.width, base.y + base.height))
- + && !issolid(fp2int(base.x+base.width), fp2int(base.y + base.height)))
- || (physic.get_velocity_x() > 0
- - && !issolid(base.x, base.y + base.height))) {
- + && !issolid(fp2int(base.x), fp2int(base.y + base.height)))) {
- physic.enable_gravity(true);
- }
- }
- @@ -253,9 +254,9 @@
- // horizontal bounce?
- if(kind == UPGRADE_GROWUP || kind == UPGRADE_HERRING) {
- if ( (physic.get_velocity_x() < 0
- - && issolid(base.x, (int) base.y + base.height/2))
- + && issolid(fp2int(base.x), fp2int(base.y + base.height/2)))
- || (physic.get_velocity_x() > 0
- - && issolid(base.x + base.width, (int) base.y + base.height/2))) {
- + && issolid(fp2int(base.x + base.width), fp2int(base.y + base.height/2)))) {
- physic.set_velocity(-physic.get_velocity_x(),physic.get_velocity_y());
- dir = dir == LEFT ? RIGHT : LEFT;
- }
- @@ -272,13 +273,13 @@
- #ifndef RES320X240
- - dest.x = (int)(base.x - scroll_x);
- + dest.x = fp2int(base.x - scroll_x);
- #else
- - dest.x = (int)(base.x - scroll_x)/2;
- + dest.x = fp2int(base.x - scroll_x)/2;
- #endif
- - dest.y = (int)(base.y + 32 - base.height);
- + dest.y = fp2int(base.y - base.height) + 32;
- dest.w = 32;
- - dest.h = (int)base.height;
- + dest.h = fp2int(base.height);
- if (kind == UPGRADE_GROWUP)
- img_growup->draw_part(0,0,dest.x,dest.y,dest.w,dest.h);
- @@ -294,21 +295,22 @@
- if (kind == UPGRADE_GROWUP)
- {
- img_growup->draw(
- - base.x - scroll_x, base.y);
- + fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else if (kind == UPGRADE_ICEFLOWER)
- {
- img_iceflower->draw(
- - base.x - scroll_x, base.y);
- + fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else if (kind == UPGRADE_HERRING)
- {
- img_star->draw(
- - base.x - scroll_x, base.y);
- + fp2int(base.x - scroll_x), fp2int(base.y));
- }
- else if (kind == UPGRADE_1UP)
- {
- - img_1up->draw( base.x - scroll_x, base.y);
- + img_1up->draw(
- + fp2int(base.x - scroll_x), fp2int(base.y));
- }
- }
- }
- @@ -327,7 +329,7 @@
- #endif
- // do a little jump and change direction
- - physic.set_velocity(-physic.get_velocity_x(), 3);
- + physic.set_velocity(-physic.get_velocity_x(), FP_BUMP_SPEED);
- dir = dir == LEFT ? RIGHT : LEFT;
- physic.enable_gravity(true);
- }
- diff -Naur supertux-0.1.3/src.bak/special.h supertux-0.1.3/src/special.h
- --- supertux-0.1.3/src.bak/special.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/special.h 2014-12-06 18:04:19.000000000 -0500
- @@ -27,6 +27,7 @@
- #include "collision.h"
- #include "player.h"
- #include "physic.h"
- +#include "fpmath.h"
- /* Upgrade types: */
- @@ -47,8 +48,8 @@
- Direction dir;
- Physic physic;
- - void init(float x, float y, Direction dir, UpgradeKind kind);
- - void action(double frame_ratio);
- + void init(fp x, fp y, Direction dir, UpgradeKind kind);
- + void action(fp frame_ratio);
- void draw();
- void collision(void* p_c_object, int c_object, CollisionType type);
- std::string type() { return "Upgrade"; };
- @@ -72,8 +73,8 @@
- base_type base;
- base_type old_base;
- - void init(float x, float y, float xm, Direction dir);
- - void action(double frame_ratio);
- + void init(fp x, fp y, fp xm, Direction dir);
- + void action(fp frame_ratio);
- void draw();
- void collision(int c_object);
- std::string type() { return "Bullet"; };
- diff -Naur supertux-0.1.3/src.bak/sprite.cpp supertux-0.1.3/src/sprite.cpp
- --- supertux-0.1.3/src.bak/sprite.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/sprite.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -73,7 +73,7 @@
- }
- void
- -Sprite::draw(float x, float y)
- +Sprite::draw(int x, int y)
- {
- time = SDL_GetTicks();
- unsigned int frame = get_current_frame();
- @@ -83,7 +83,7 @@
- }
- void
- -Sprite::draw_part(float sx, float sy, float x, float y, float w, float h)
- +Sprite::draw_part(int sx, int sy, int x, int y, int w, int h)
- {
- time = SDL_GetTicks();
- unsigned int frame = get_current_frame();
- diff -Naur supertux-0.1.3/src.bak/sprite.h supertux-0.1.3/src/sprite.h
- --- supertux-0.1.3/src.bak/sprite.h 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/sprite.h 2014-12-06 18:04:19.000000000 -0500
- @@ -55,8 +55,8 @@
- /** Update the sprite and process to the next frame */
- void update(float delta);
- - void draw(float x, float y);
- - void draw_part(float sx, float sy, float x, float y, float w, float h);
- + void draw(int x, int y);
- + void draw_part(int sx, int sy, int x, int y, int w, int h);
- int get_current_frame() const;
- std::string get_name() const { return name; }
- diff -Naur supertux-0.1.3/src.bak/supertux.cpp supertux-0.1.3/src/supertux.cpp
- --- supertux-0.1.3/src.bak/supertux.cpp 2014-12-06 18:00:56.000000000 -0500
- +++ supertux-0.1.3/src/supertux.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -33,12 +33,18 @@
- #include "resources.h"
- #include "texture.h"
- #include "tile.h"
- +#include "fpmath.h"
- int main(int argc, char * argv[])
- {
- st_directory_setup();
- parseargs(argc, argv);
- + if (debug_mode) {
- + printf("fpmath test: 3.5 * 8.6 = %2.2f\n", fp2float(fpmul(float2fp(3.5), float2fp(8.6))));
- + printf("fpmath test: 3.5 / 8.6 = %2.2f\n", fp2float(fpdiv(float2fp(3.5), float2fp(8.6))));
- + }
- +
- st_audio_setup();
- st_video_setup();
- st_joystick_setup();
- diff -Naur supertux-0.1.3/src.bak/text.cpp supertux-0.1.3/src/text.cpp
- --- supertux-0.1.3/src.bak/text.cpp 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/text.cpp 2014-12-07 10:12:49.000000000 -0500
- @@ -24,6 +24,7 @@
- #include "defines.h"
- #include "screen.h"
- #include "text.h"
- +#include "fpmath.h"
- #include "sound.h"
- Text::Text(const std::string& file, int kind_, int w_, int h_)
- @@ -234,22 +235,21 @@
- /* --- SCROLL TEXT FUNCTION --- */
- #define MAX_VEL 10
- -#define SPEED_INC 0.01
- #define SCROLL 60
- #define ITEMS_SPACE 4
- -void display_text_file(const std::string& file, const std::string& surface, float scroll_speed)
- +void display_text_file(const std::string& file, const std::string& surface, fp scroll_speed)
- {
- Surface* sur = new Surface(datadir + surface, IGNORE_ALPHA);
- display_text_file(file, sur, scroll_speed);
- delete sur;
- }
- -void display_text_file(const std::string& file, Surface* surface, float scroll_speed)
- +void display_text_file(const std::string& file, Surface* surface, fp scroll_speed)
- {
- int done;
- - float scroll;
- - float speed;
- + fp scroll;
- + fp speed;
- int y;
- int length;
- FILE* fi;
- @@ -297,15 +297,15 @@
- switch(event.key.keysym.sym)
- {
- case SDLK_UP:
- - speed -= SPEED_INC;
- + speed -= FP_SPEED_INC;
- break;
- case SDLK_DOWN:
- - speed += SPEED_INC;
- + speed += FP_SPEED_INC;
- break;
- case SDLK_SPACE:
- case SDLK_RETURN:
- if(speed >= 0)
- - scroll += SCROLL;
- + scroll += int2fp(SCROLL);
- break;
- case SDLK_ESCAPE:
- done = 1;
- @@ -339,10 +339,10 @@
- break;
- }
- - if(speed > MAX_VEL)
- - speed = MAX_VEL;
- - else if(speed < -MAX_VEL)
- - speed = -MAX_VEL;
- + if(speed > int2fp(MAX_VEL))
- + speed = int2fp(MAX_VEL);
- + else if(speed < int2fp(-MAX_VEL))
- + speed = int2fp(-MAX_VEL);
- /* draw the credits */
- surface->draw_bg();
- @@ -353,7 +353,7 @@
- switch(names.item[i][0])
- {
- case ' ':
- - white_small_text->drawf(names.item[i]+1, 0, screen->h+y-int(scroll),
- + white_small_text->drawf(names.item[i]+1, 0, screen->h+y-fp2int(scroll),
- A_HMIDDLE, A_TOP, 1);
- y += white_small_text->h+ITEMS_SPACE;
- #ifdef RES320X240
- @@ -361,7 +361,7 @@
- #endif
- break;
- case ' ':
- - white_text->drawf(names.item[i]+1, 0, screen->h+y-int(scroll),
- + white_text->drawf(names.item[i]+1, 0, screen->h+y-fp2int(scroll),
- A_HMIDDLE, A_TOP, 1);
- y += white_text->h+ITEMS_SPACE;
- #ifdef RES320X240
- @@ -370,9 +370,9 @@
- break;
- case '-':
- #ifdef RES320X240
- - white_text->drawf(names.item[i]+1, 0, screen->h+y-int(scroll), A_HMIDDLE, A_TOP, 3);
- + white_text->drawf(names.item[i]+1, 0, screen->h+y-fp2int(scroll), A_HMIDDLE, A_TOP, 3);
- #else
- - white_big_text->drawf(names.item[i]+1, 0, screen->h+y-int(scroll), A_HMIDDLE, A_TOP, 3);
- + white_big_text->drawf(names.item[i]+1, 0, screen->h+y-fp2int(scroll), A_HMIDDLE, A_TOP, 3);
- #endif
- y += white_big_text->h+ITEMS_SPACE;
- #ifdef RES320X240
- @@ -380,7 +380,7 @@
- #endif
- break;
- default:
- - blue_text->drawf(names.item[i], 0, screen->h+y-int(scroll),
- + blue_text->drawf(names.item[i], 0, screen->h+y-fp2int(scroll),
- A_HMIDDLE, A_TOP, 1);
- y += blue_text->h+ITEMS_SPACE;
- #ifdef RES320X240
- @@ -392,7 +392,7 @@
- flipscreen();
- - if(screen->h+y-scroll < 0 && 20+screen->h+y-scroll < 0)
- + if(int2fp(screen->h+y)-scroll < 0 && int2fp(20+screen->h+y)-scroll < 0)
- done = 1;
- Uint32 ticks = SDL_GetTicks();
- diff -Naur supertux-0.1.3/src.bak/text.h supertux-0.1.3/src/text.h
- --- supertux-0.1.3/src.bak/text.h 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/text.h 2014-12-06 18:04:19.000000000 -0500
- @@ -23,9 +23,10 @@
- #include <string>
- #include "texture.h"
- +#include "fpmath.h"
- -void display_text_file(const std::string& file, const std::string& surface, float scroll_speed);
- -void display_text_file(const std::string& file, Surface* surface, float scroll_speed);
- +void display_text_file(const std::string& file, const std::string& surface, fp scroll_speed);
- +void display_text_file(const std::string& file, Surface* surface, fp scroll_speed);
- /* Kinds of texts. */
- enum {
- diff -Naur supertux-0.1.3/src.bak/texture.cpp supertux-0.1.3/src/texture.cpp
- --- supertux-0.1.3/src.bak/texture.cpp 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/texture.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -207,7 +207,7 @@
- }
- void
- -Surface::draw(float x, float y, Uint8 alpha, bool update)
- +Surface::draw(int x, int y, Uint8 alpha, bool update)
- {
- if (impl)
- {
- @@ -228,7 +228,7 @@
- }
- void
- -Surface::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update)
- +Surface::draw_part(int sx, int sy, int x, int y, int w, int h, Uint8 alpha, bool update)
- {
- if (impl)
- {
- @@ -239,7 +239,7 @@
- }
- void
- -Surface::draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update)
- +Surface::draw_stretched(int x, int y, int w, int h, Uint8 alpha, bool update)
- {
- if (impl)
- {
- @@ -538,10 +538,12 @@
- }
- int
- -SurfaceOpenGL::draw(float x, float y, Uint8 alpha, bool update)
- +SurfaceOpenGL::draw(int x, int y, Uint8 alpha, bool update)
- {
- float pw = power_of_two(w);
- float ph = power_of_two(h);
- + float xf = (float) x;
- + float yf = (float) y;
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- @@ -553,12 +555,12 @@
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- - glVertex2f(x, y);
- + glVertex2f(xf, yf);
- glTexCoord2f((float)w / pw, 0);
- - glVertex2f((float)w+x, y);
- - glTexCoord2f((float)w / pw, (float)h / ph); glVertex2f((float)w+x, (float)h+y);
- + glVertex2f((float)w+xf, yf);
- + glTexCoord2f((float)w / pw, (float)h / ph); glVertex2f((float)w+xf, (float)h+yf);
- glTexCoord2f(0, (float)h / ph);
- - glVertex2f(x, (float)h+y);
- + glVertex2f(xf, (float)h+yf);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- @@ -599,10 +601,16 @@
- }
- int
- -SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update)
- +SurfaceOpenGL::draw_part(int sx, int sy, int x, int y, int w, int h, Uint8 alpha, bool update)
- {
- float pw = power_of_two(int(this->w));
- float ph = power_of_two(int(this->h));
- + float sxf = (float) sx;
- + float syf = (float) sy;
- + float xf = (float) x;
- + float yf = (float) y;
- + float wf = (float) w;
- + float hf = (float) h;
- glBindTexture(GL_TEXTURE_2D, gl_texture);
- @@ -615,14 +623,14 @@
- glBegin(GL_QUADS);
- - glTexCoord2f(sx / pw, sy / ph);
- - glVertex2f(x, y);
- - glTexCoord2f((float)(sx + w) / pw, sy / ph);
- - glVertex2f(w+x, y);
- - glTexCoord2f((sx+w) / pw, (sy+h) / ph);
- - glVertex2f(w +x, h+y);
- - glTexCoord2f(sx / pw, (float)(sy+h) / ph);
- - glVertex2f(x, h+y);
- + glTexCoord2f(sxf / pw, syf / ph);
- + glVertex2f(xf, yf);
- + glTexCoord2f((float)(sxf + wf) / pw, syf / ph);
- + glVertex2f(wf+xf, yf);
- + glTexCoord2f((sxf+wf) / pw, (syf+hf) / ph);
- + glVertex2f(wf+xf, hf+yf);
- + glTexCoord2f(sxf / pw, (float)(syf+hf) / ph);
- + glVertex2f(xf, hf+yf);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- @@ -633,10 +641,14 @@
- }
- int
- -SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, bool update)
- +SurfaceOpenGL::draw_stretched(int x, int y, int sw, int sh, Uint8 alpha, bool update)
- {
- float pw = power_of_two(int(this->w));
- float ph = power_of_two(int(this->h));
- + float xf = (float) x;
- + float yf = (float) y;
- + float swf = (float) sw;
- + float shf = (float) sh;
- glBindTexture(GL_TEXTURE_2D, gl_texture);
- @@ -650,13 +662,14 @@
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- - glVertex2f(x, y);
- + glVertex2f(xf, yf);
- glTexCoord2f((float)w / pw, 0);
- - glVertex2f(sw+x, y);
- - glTexCoord2f((float)w / pw, (float)h / ph); glVertex2f((float)sw+x, (float)sh+y);
- - glVertex2f(sw +x, sh+y);
- + glVertex2f(swf+xf, yf);
- + glTexCoord2f((float)w / pw, (float)h / ph);
- + glVertex2f(swf+xf, shf+yf);
- + glVertex2f(swf+xf, shf+yf);
- glTexCoord2f(0, (float)h / ph);
- - glVertex2f(x, sh+y);
- + glVertex2f(xf, shf+yf);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- @@ -690,12 +703,12 @@
- }
- int
- -SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update)
- +SurfaceSDL::draw(int x, int y, Uint8 alpha, bool update)
- {
- SDL_Rect dest;
- - dest.x = (int)x;
- - dest.y = (int)y;
- + dest.x = x;
- + dest.y = y;
- dest.w = w;
- dest.h = h;
- @@ -784,19 +797,19 @@
- }
- int
- -SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update)
- +SurfaceSDL::draw_part(int sx, int sy, int x, int y, int w, int h, Uint8 alpha, bool update)
- {
- SDL_Rect src, dest;
- - src.x = (int)sx;
- - src.y = (int)sy;
- - src.w = (int)w;
- - src.h = (int)h;
- -
- - dest.x = (int)x;
- - dest.y = (int)y;
- - dest.w = (int)w;
- - dest.h = (int)h;
- + src.x = sx;
- + src.y = sy;
- + src.w = w;
- + src.h = h;
- +
- + dest.x = x;
- + dest.y = y;
- + dest.w = w;
- + dest.h = h;
- if(alpha != 255)
- {
- @@ -836,14 +849,14 @@
- }
- int
- -SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, bool update)
- +SurfaceSDL::draw_stretched(int x, int y, int sw, int sh, Uint8 alpha, bool update)
- {
- SDL_Rect dest;
- - dest.x = (int)x;
- - dest.y = (int)y;
- - dest.w = (int)sw;
- - dest.h = (int)sh;
- + dest.x = x;
- + dest.y = y;
- + dest.w = sw;
- + dest.h = sh;
- if(alpha != 255)
- SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);
- diff -Naur supertux-0.1.3/src.bak/texture.h supertux-0.1.3/src/texture.h
- --- supertux-0.1.3/src.bak/texture.h 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/texture.h 2014-12-06 18:04:19.000000000 -0500
- @@ -87,10 +87,10 @@
- /** Reload the surface, which is necesarry in case of a mode swich */
- void reload();
- - void draw(float x, float y, Uint8 alpha = 255, bool update = false);
- + void draw(int x, int y, Uint8 alpha = 255, bool update = false);
- void draw_bg(Uint8 alpha = 255, bool update = false);
- - void draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha = 255, bool update = false);
- - void draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update = false);
- + void draw_part(int sx, int sy, int x, int y, int w, int h, Uint8 alpha = 255, bool update = false);
- + void draw_stretched(int x, int y, int w, int h, Uint8 alpha, bool update = false);
- void resize(int w_, int h_);
- };
- @@ -110,10 +110,10 @@
- virtual ~SurfaceImpl();
- /** Return 0 on success, -2 if surface needs to be reloaded */
- - virtual int draw(float x, float y, Uint8 alpha, bool update) = 0;
- + virtual int draw(int x, int y, Uint8 alpha, bool update) = 0;
- virtual int draw_bg(Uint8 alpha, bool update) = 0;
- - virtual int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update) = 0;
- - virtual int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update) = 0;
- + virtual int draw_part(int sx, int sy, int x, int y, int w, int h, Uint8 alpha, bool update) = 0;
- + virtual int draw_stretched(int x, int y, int w, int h, Uint8 alpha, bool update) = 0;
- int resize(int w_, int h_);
- SDL_Surface* get_sdl_surface() const; // @evil@ try to avoid this function
- @@ -127,10 +127,10 @@
- SurfaceSDL(const std::string& file, int x, int y, int w, int h, int use_alpha);
- virtual ~SurfaceSDL();
- - int draw(float x, float y, Uint8 alpha, bool update);
- + int draw(int x, int y, Uint8 alpha, bool update);
- int draw_bg(Uint8 alpha, bool update);
- - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
- - int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
- + int draw_part(int sx, int sy, int x, int y, int w, int h, Uint8 alpha, bool update);
- + int draw_stretched(int x, int y, int w, int h, Uint8 alpha, bool update);
- };
- #ifndef NOOPENGL
- @@ -145,10 +145,10 @@
- SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha);
- virtual ~SurfaceOpenGL();
- - int draw(float x, float y, Uint8 alpha, bool update);
- + int draw(int x, int y, Uint8 alpha, bool update);
- int draw_bg(Uint8 alpha, bool update);
- - int draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, bool update);
- - int draw_stretched(float x, float y, int w, int h, Uint8 alpha, bool update);
- + int draw_part(int sx, int sy, int x, int y, int w, int h, Uint8 alpha, bool update);
- + int draw_stretched(int x, int y, int w, int h, Uint8 alpha, bool update);
- private:
- void create_gl(SDL_Surface * surf, GLuint * tex);
- diff -Naur supertux-0.1.3/src.bak/tile.cpp supertux-0.1.3/src/tile.cpp
- --- supertux-0.1.3/src.bak/tile.cpp 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/tile.cpp 2014-12-06 18:04:19.000000000 -0500
- @@ -184,7 +184,7 @@
- }
- void
- -Tile::draw(float x, float y, unsigned int c, Uint8 alpha)
- +Tile::draw(int x, int y, unsigned int c, Uint8 alpha)
- {
- if (c != 0)
- {
- @@ -208,7 +208,7 @@
- }
- void
- -Tile::draw_stretched(float x, float y, int w, int h, unsigned int c, Uint8 alpha)
- +Tile::draw_stretched(int x, int y, int w, int h, unsigned int c, Uint8 alpha)
- {
- if (c != 0)
- {
- diff -Naur supertux-0.1.3/src.bak/tile.h supertux-0.1.3/src/tile.h
- --- supertux-0.1.3/src.bak/tile.h 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/tile.h 2014-12-06 18:04:19.000000000 -0500
- @@ -80,8 +80,8 @@
- int anim_speed;
- /** Draw a tile on the screen: */
- - static void draw(float x, float y, unsigned int c, Uint8 alpha = 255);
- - static void draw_stretched(float x, float y, int w, int h, unsigned int c, Uint8 alpha = 255);
- + static void draw(int x, int y, unsigned int c, Uint8 alpha = 255);
- + static void draw_stretched(int x, int y, int w, int h, unsigned int c, Uint8 alpha = 255);
- };
- struct TileGroup
- diff -Naur supertux-0.1.3/src.bak/title.cpp supertux-0.1.3/src/title.cpp
- --- supertux-0.1.3/src.bak/title.cpp 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/title.cpp 2014-12-07 10:36:25.000000000 -0500
- @@ -51,6 +51,7 @@
- #include "tile.h"
- #include "resources.h"
- #include "worldmap.h"
- +#include "fpmath.h"
- #include "sound.h"
- static Surface* bkg_title;
- @@ -187,7 +188,7 @@
- bkg_title->draw_bg();
- }
- -void draw_demo(GameSession* session, double frame_ratio)
- +void draw_demo(GameSession* session, fp frame_ratio)
- {
- World* world = session->get_world();
- World::set_current(world);
- @@ -213,14 +214,14 @@
- }
- // Wrap around at the end of the level back to the beginnig
- - if((plevel->width * 32) - 320 < tux->base.x)
- + if(int2fp(plevel->width * 32 - 320) < tux->base.x)
- {
- tux->level_begin();
- scroll_x = 0;
- }
- tux->can_jump = true;
- - float last_tux_x_pos = tux->base.x;
- + fp last_tux_x_pos = tux->base.x;
- world->action(frame_ratio);
- @@ -282,9 +283,9 @@
- update_time = last_update_time = st_get_ticks();
- // Calculate the movement-factor
- - double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
- - if(frame_ratio > 1.5) /* Quick hack to correct the unprecise CPU clocks a little bit. */
- - frame_ratio = 1.5 + (frame_ratio - 1.5) * 0.85;
- + fp frame_ratio = (int2fp(update_time-last_update_time))/(FRAME_RATE);
- + if(frame_ratio > FP_FRAME_RATIO_LIMIT) /* Quick hack to correct the unprecise CPU clocks a little bit. */
- + frame_ratio = FP_FRAME_RATIO_LIMIT + fpmul((frame_ratio - FP_FRAME_RATIO_LIMIT), FP_FRAME_RATIO_CORR);
- /* Lower the frame_ratio that Tux doesn't jump to hectically throught the demo. */
- frame_ratio /= 2;
- @@ -357,7 +358,7 @@
- menu_song = music_manager->load_music(datadir + "/music/credits.mod");
- music_manager->halt_music();
- music_manager->play_music(menu_song,0);
- - display_text_file("CREDITS", bkg_title, SCROLL_SPEED_CREDITS);
- + display_text_file("CREDITS", bkg_title, FP_SCROLL_SPEED_CREDITS);
- music_manager->halt_music();
- menu_song = music_manager->load_music(datadir + "/music/theme.mod");
- music_manager->play_music(menu_song);
- diff -Naur supertux-0.1.3/src.bak/type.h supertux-0.1.3/src/type.h
- --- supertux-0.1.3/src.bak/type.h 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/type.h 2014-12-06 18:04:19.000000000 -0500
- @@ -24,17 +24,18 @@
- #include <string>
- #include "SDL.h"
- #include "scene.h"
- +#include "fpmath.h"
- /* 'Base' type for game objects */
- struct base_type
- {
- - float x;
- - float y;
- - float xm;
- - float ym;
- - float width;
- - float height;
- + fp x;
- + fp y;
- + fp xm;
- + fp ym;
- + fp width;
- + fp height;
- };
- @@ -45,27 +46,28 @@
- public:
- GameObject() {};
- virtual ~GameObject() {};
- - virtual void action(double frame_ratio) = 0;
- + virtual void action(fp frame_ratio) = 0;
- virtual void draw() = 0;
- virtual std::string type() = 0;
- /* Draw ignoring the scroll_x value. FIXME: Hack? Should be discussed. @tobgle*/
- - void draw_on_screen(float x = -1, float y = -1)
- + void draw_on_screen(fp x = int2fp(-1), fp y = int2fp(-1))
- {
- base_type btmp = base;
- - if(x != -1 || y != -1)
- + if(x != int2fp(-1) || y != int2fp(-1))
- {
- btmp = base;
- - if(x != -1)
- + if(x != int2fp(-1))
- base.x = x;
- - if(y != -1)
- + if(y != int2fp(-1))
- base.y = y;
- }
- - float tmp = scroll_x;
- - scroll_x = 0; draw();
- + fp tmp = scroll_x;
- + scroll_x = 0;
- + draw();
- scroll_x = tmp;
- base = btmp;
- };
- -void move_to(float x, float y) { base.x = x; base.y = y; };
- +void move_to(fp x, fp y) { base.x = x; base.y = y; };
- base_type base;
- base_type old_base;
- diff -Naur supertux-0.1.3/src.bak/world.cpp supertux-0.1.3/src/world.cpp
- --- supertux-0.1.3/src.bak/world.cpp 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/world.cpp 2014-12-07 10:46:53.000000000 -0500
- @@ -32,6 +32,7 @@
- #include "level.h"
- #include "tile.h"
- #include "resources.h"
- +#include "fpmath.h"
- Surface* img_distro[4];
- @@ -95,8 +96,8 @@
- case PlayerStatus::GROWUP_BONUS:
- // FIXME: Move this to Player class
- tux.size = BIG;
- - tux.base.height = 64;
- - tux.base.y -= 32;
- + tux.base.height = int2fp(64);
- + tux.base.y -= int2fp(32);
- break;
- }
- }
- @@ -151,7 +152,7 @@
- i != level->badguy_data.end();
- ++i)
- {
- - add_bad_guy(i->x, i->y, i->kind, i->stay_on_platform);
- + add_bad_guy(int2fp(i->x), int2fp(i->y), i->kind, i->stay_on_platform);
- }
- }
- @@ -176,11 +177,14 @@
- World::draw()
- {
- int y,x;
- + int scroll_xi = fp2int(scroll_x);
- /* Draw the real background */
- if(level->img_bkgd)
- {
- - int s = (int)((float)scroll_x * ((float)level->bkgd_speed/100.0f)) % screen->w;
- + // overflow occurs if real fp calculation is done, so truncate to int first:
- + //int s = fp2int(scroll_x * level->bkgd_speed / 100) % screen->w;
- + int s = (scroll_xi * level->bkgd_speed / 100) % screen->w;
- level->img_bkgd->draw_part(s, 0,0,0,level->img_bkgd->w - s, level->img_bkgd->h);
- level->img_bkgd->draw_part(0, 0,screen->w - s ,0,s,level->img_bkgd->h);
- }
- @@ -201,8 +205,8 @@
- {
- for (x = 0; x < 21; ++x)
- {
- - Tile::draw(32*x - fmodf(scroll_x, 32), y * 32,
- - level->bg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
- + Tile::draw(32*x - (scroll_xi % 32), y * 32,
- + level->bg_tiles[y][x + (scroll_xi / 32)]);
- }
- }
- @@ -212,8 +216,8 @@
- {
- for (x = 0; x < 21; ++x)
- {
- - Tile::draw(32*x - fmodf(scroll_x, 32), y * 32,
- - level->ia_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
- + Tile::draw(32*x - (scroll_xi % 32), y * 32,
- + level->ia_tiles[y][x + (scroll_xi / 32)]);
- }
- }
- @@ -246,8 +250,8 @@
- {
- for (x = 0; x < 21; ++x)
- {
- - Tile::draw(32*x - fmodf(scroll_x, 32), y * 32,
- - level->fg_tiles[(int)y][(int)x + (int)(scroll_x / 32)]);
- + Tile::draw(32*x - (scroll_xi % 32), y * 32,
- + level->fg_tiles[y][x + (scroll_xi / 32)]);
- }
- }
- @@ -261,7 +265,7 @@
- }
- void
- -World::action(double frame_ratio)
- +World::action(fp frame_ratio)
- {
- tux.action(frame_ratio);
- tux.check_bounds(level->back_scrolling, (bool)level->hor_autoscroll_speed);
- @@ -325,15 +329,15 @@
- #define CHANGE_DIR_SCROLL_SPEED 2000
- /* This functions takes cares of the scrolling */
- -void World::scrolling(double frame_ratio)
- +void World::scrolling(fp frame_ratio)
- {
- if(level->hor_autoscroll_speed)
- {
- - scroll_x += level->hor_autoscroll_speed * frame_ratio;
- + scroll_x += fpmul(level->hor_autoscroll_speed, frame_ratio);
- return;
- }
- - int tux_pos_x = (int)(tux.base.x + (tux.base.width/2));
- + int tux_pos_x = fp2int(tux.base.x + (tux.base.width/2));
- if (level->back_scrolling || debug_mode)
- {
- @@ -342,53 +346,54 @@
- if(scrolling_timer.check())
- {
- - float final_scroll_x;
- + fp final_scroll_x;
- if (tux.physic.get_velocity_x() > 0)
- - final_scroll_x = tux_pos_x - (screen->w - X_SPACE);
- + final_scroll_x = int2fp(tux_pos_x - (screen->w - X_SPACE));
- else if (tux.physic.get_velocity_x() < 0)
- - final_scroll_x = tux_pos_x - X_SPACE;
- + final_scroll_x = int2fp(tux_pos_x - X_SPACE);
- else
- {
- if (tux.dir == RIGHT)
- - final_scroll_x = tux_pos_x - (screen->w - X_SPACE);
- + final_scroll_x = int2fp(tux_pos_x - (screen->w - X_SPACE));
- else if (tux.dir == LEFT && level->back_scrolling)
- - final_scroll_x = tux_pos_x - X_SPACE;
- + final_scroll_x = int2fp(tux_pos_x - X_SPACE);
- }
- - scroll_x += (final_scroll_x - scroll_x)
- - / (frame_ratio * (CHANGE_DIR_SCROLL_SPEED / 100))
- - + (tux.physic.get_velocity_x() * frame_ratio + tux.physic.get_acceleration_x() * frame_ratio * frame_ratio);
- + scroll_x += fpdiv( (final_scroll_x - scroll_x),
- + (frame_ratio * (CHANGE_DIR_SCROLL_SPEED / 100)) )
- + + (fpmul(tux.physic.get_velocity_x(), frame_ratio) +
- + fpmul(tux.physic.get_acceleration_x(), fpmul(frame_ratio, frame_ratio)));
- // std::cerr << tux_pos_x << " " << final_scroll_x << " " << scroll_x << std::endl;
- }
- else
- {
- - if (tux.physic.get_velocity_x() > 0 && scroll_x < tux_pos_x - (screen->w - X_SPACE))
- - scroll_x = tux_pos_x - (screen->w - X_SPACE);
- - else if (tux.physic.get_velocity_x() < 0 && scroll_x > tux_pos_x - X_SPACE && level->back_scrolling)
- - scroll_x = tux_pos_x - X_SPACE;
- + if (tux.physic.get_velocity_x() > 0 && scroll_x < int2fp(tux_pos_x - (screen->w - X_SPACE)))
- + scroll_x = int2fp(tux_pos_x - (screen->w - X_SPACE));
- + else if (tux.physic.get_velocity_x() < 0 && scroll_x > int2fp(tux_pos_x - X_SPACE) && level->back_scrolling)
- + scroll_x = int2fp(tux_pos_x - X_SPACE);
- else
- {
- - if (tux.dir == RIGHT && scroll_x < tux_pos_x - (screen->w - X_SPACE))
- - scroll_x = tux_pos_x - (screen->w - X_SPACE);
- - else if (tux.dir == LEFT && scroll_x > tux_pos_x - X_SPACE && level->back_scrolling)
- - scroll_x = tux_pos_x - X_SPACE;
- + if (tux.dir == RIGHT && scroll_x < int2fp(tux_pos_x - (screen->w - X_SPACE)))
- + scroll_x = int2fp(tux_pos_x - (screen->w - X_SPACE));
- + else if (tux.dir == LEFT && scroll_x > int2fp(tux_pos_x - X_SPACE) && level->back_scrolling)
- + scroll_x = int2fp(tux_pos_x - X_SPACE);
- }
- }
- }
- else /*no debug*/
- {
- - if (tux.physic.get_velocity_x() > 0 && scroll_x < tux_pos_x - (screen->w - X_SPACE))
- - scroll_x = tux_pos_x - (screen->w - X_SPACE);
- - else if (tux.physic.get_velocity_x() < 0 && scroll_x > tux_pos_x - X_SPACE && level->back_scrolling)
- - scroll_x = tux_pos_x - X_SPACE;
- + if (tux.physic.get_velocity_x() > 0 && scroll_x < int2fp(tux_pos_x - (screen->w - X_SPACE)))
- + scroll_x = int2fp(tux_pos_x - (screen->w - X_SPACE));
- + else if (tux.physic.get_velocity_x() < 0 && scroll_x > int2fp(tux_pos_x - X_SPACE) && level->back_scrolling)
- + scroll_x = int2fp(tux_pos_x - X_SPACE);
- else
- {
- - if (tux.dir == RIGHT && scroll_x < tux_pos_x - (screen->w - X_SPACE))
- - scroll_x = tux_pos_x - (screen->w - X_SPACE);
- - else if (tux.dir == LEFT && scroll_x > tux_pos_x - X_SPACE && level->back_scrolling)
- - scroll_x = tux_pos_x - X_SPACE;
- + if (tux.dir == RIGHT && scroll_x < int2fp(tux_pos_x - (screen->w - X_SPACE)))
- + scroll_x = int2fp(tux_pos_x - (screen->w - X_SPACE));
- + else if (tux.dir == LEFT && scroll_x > int2fp(tux_pos_x - X_SPACE) && level->back_scrolling)
- + scroll_x = int2fp(tux_pos_x - X_SPACE);
- }
- }
- @@ -397,11 +402,13 @@
- if(scroll_x < 0)
- scroll_x = 0;
- #ifndef RES320X240
- + if(scroll_x > int2fp(level->width * 32 - screen->w))
- + scroll_x = int2fp(level->width * 32 - screen->w);
- if(scroll_x > level->width * 32 - screen->w)
- scroll_x = level->width * 32 - screen->w;
- #else
- - if(scroll_x > level->width * 32 - 640)
- - scroll_x = level->width * 32 - 640;
- + if(scroll_x > int2fp(level->width * 32 - 640))
- + scroll_x = int2fp(level->width * 32 - 640);
- #endif
- }
- @@ -492,7 +499,7 @@
- }
- void
- -World::add_score(float x, float y, int s)
- +World::add_score(fp x, fp y, int s)
- {
- #ifdef RES320X240
- x=x/2;
- @@ -506,7 +513,7 @@
- }
- void
- -World::add_bouncy_distro(float x, float y)
- +World::add_bouncy_distro(fp x, fp y)
- {
- BouncyDistro* new_bouncy_distro = new BouncyDistro();
- new_bouncy_distro->init(x,y);
- @@ -514,17 +521,17 @@
- }
- void
- -World::add_broken_brick(Tile* tile, float x, float y)
- +World::add_broken_brick(Tile* tile, fp x, fp y)
- {
- - add_broken_brick_piece(tile, x, y, -1, -4);
- - add_broken_brick_piece(tile, x, y + 16, -1.5, -3);
- + add_broken_brick_piece(tile, x, y, int2fp(-1), int2fp(-4));
- + add_broken_brick_piece(tile, x, y + int2fp(16), -FP_BROKEN_PIECE_SPEED, int2fp(-3));
- - add_broken_brick_piece(tile, x + 16, y, 1, -4);
- - add_broken_brick_piece(tile, x + 16, y + 16, 1.5, -3);
- + add_broken_brick_piece(tile, x + int2fp(16), y, int2fp(1), int2fp(-4));
- + add_broken_brick_piece(tile, x + int2fp(16), y + int2fp(16), FP_BROKEN_PIECE_SPEED, int2fp(-3));
- }
- void
- -World::add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym)
- +World::add_broken_brick_piece(Tile* tile, fp x, fp y, fp xm, fp ym)
- {
- BrokenBrick* new_broken_brick = new BrokenBrick();
- new_broken_brick->init(tile, x, y, xm, ym);
- @@ -532,7 +539,7 @@
- }
- void
- -World::add_bouncy_brick(float x, float y)
- +World::add_bouncy_brick(fp x, fp y)
- {
- BouncyBrick* new_bouncy_brick = new BouncyBrick();
- new_bouncy_brick->init(x,y);
- @@ -540,7 +547,7 @@
- }
- BadGuy*
- -World::add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform)
- +World::add_bad_guy(fp x, fp y, BadGuyKind kind, bool stay_on_platform)
- {
- BadGuy* badguy = new BadGuy(x,y,kind, stay_on_platform);
- bad_guys.push_back(badguy);
- @@ -548,7 +555,7 @@
- }
- void
- -World::add_upgrade(float x, float y, Direction dir, UpgradeKind kind)
- +World::add_upgrade(fp x, fp y, Direction dir, UpgradeKind kind)
- {
- Upgrade new_upgrade;
- new_upgrade.init(x,y,dir,kind);
- @@ -556,7 +563,7 @@
- }
- void
- -World::add_bullet(float x, float y, float xm, Direction dir)
- +World::add_bullet(fp x, fp y, fp xm, Direction dir)
- {
- if(bullets.size() > MAX_BULLETS-1)
- return;
- @@ -599,18 +606,20 @@
- /* Break a brick: */
- void
- -World::trybreakbrick(float x, float y, bool small, Direction col_side)
- +World::trybreakbrick(fp x, fp y, bool small, Direction col_side)
- {
- Level* plevel = get_level();
- + int xx = fp2int(x);
- + int yy = fp2int(y);
- - Tile* tile = gettile(x, y);
- + Tile* tile = gettile(xx, yy);
- if (tile->brick)
- {
- if (tile->data > 0)
- {
- /* Get a distro from it: */
- - add_bouncy_distro(((int)(x + 1) / 32) * 32,
- - (int)(y / 32) * 32);
- + add_bouncy_distro( int2fp(((xx + 1) / 32) * 32),
- + int2fp((yy / 32) * 32));
- // TODO: don't handle this in a global way but per-tile...
- if (!counting_distros)
- @@ -626,7 +635,7 @@
- if (distro_counter <= 0)
- {
- counting_distros = false;
- - plevel->change(x, y, TM_IA, tile->next_tile);
- + plevel->change(xx, yy, TM_IA, tile->next_tile);
- }
- #ifndef GP2X
- play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
- @@ -639,12 +648,12 @@
- else if (!small)
- {
- /* Get rid of it: */
- - plevel->change(x, y, TM_IA, tile->next_tile);
- + plevel->change(xx, yy, TM_IA, tile->next_tile);
- /* Replace it with broken bits: */
- add_broken_brick(tile,
- - ((int)(x + 1) / 32) * 32,
- - (int)(y / 32) * 32);
- + int2fp(((xx + 1) / 32) * 32),
- + int2fp((yy / 32) * 32));
- /* Get some score: */
- #ifndef GP2X
- @@ -661,9 +670,12 @@
- /* Empty a box: */
- void
- -World::tryemptybox(float x, float y, Direction col_side)
- +World::tryemptybox(fp x, fp y, Direction col_side)
- {
- - Tile* tile = gettile(x,y);
- + int xx = fp2int(x);
- + int yy = fp2int(y);
- +
- + Tile* tile = gettile(xx,yy);
- if (!tile->fullbox)
- return;
- @@ -673,12 +685,12 @@
- else
- col_side = LEFT;
- - int posx = ((int)(x+1) / 32) * 32;
- - int posy = (int)(y/32) * 32 - 32;
- + int posx = ((xx+1) / 32) * 32;
- + int posy = (yy/32) * 32 - 32;
- switch(tile->data)
- {
- case 1: // Box with a distro!
- - add_bouncy_distro(posx, posy);
- + add_bouncy_distro(int2fp(posx), int2fp(posy));
- #ifndef GP2X
- play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
- #else
- @@ -690,9 +702,9 @@
- case 2: // Add an upgrade!
- if (tux.size == SMALL) /* Tux is small, add mints! */
- - add_upgrade(posx, posy, col_side, UPGRADE_GROWUP);
- + add_upgrade(int2fp(posx), int2fp(posy), col_side, UPGRADE_GROWUP);
- else /* Tux is big, add an iceflower: */
- - add_upgrade(posx, posy, col_side, UPGRADE_ICEFLOWER);
- + add_upgrade(int2fp(posx), int2fp(posy), col_side, UPGRADE_ICEFLOWER);
- #ifndef GP2X
- play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
- #else
- @@ -701,28 +713,31 @@
- break;
- case 3: // Add a golden herring
- - add_upgrade(posx, posy, col_side, UPGRADE_HERRING);
- + add_upgrade(int2fp(posx), int2fp(posy), col_side, UPGRADE_HERRING);
- break;
- case 4: // Add a 1up extra
- - add_upgrade(posx, posy, col_side, UPGRADE_1UP);
- + add_upgrade(int2fp(posx), int2fp(posy), col_side, UPGRADE_1UP);
- break;
- default:
- break;
- }
- /* Empty the box: */
- - level->change(x, y, TM_IA, tile->next_tile);
- + level->change(xx, yy, TM_IA, tile->next_tile);
- }
- /* Try to grab a distro: */
- void
- -World::trygrabdistro(float x, float y, int bounciness)
- +World::trygrabdistro(fp x, fp y, int bounciness)
- {
- - Tile* tile = gettile(x, y);
- + int xx = fp2int(x);
- + int yy = fp2int(y);
- +
- + Tile* tile = gettile(xx, yy);
- if (tile && tile->distro)
- {
- - level->change(x, y, TM_IA, tile->next_tile);
- + level->change(xx, yy, TM_IA, tile->next_tile);
- #ifndef GP2X
- play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER);
- #else
- @@ -731,8 +746,8 @@
- if (bounciness == BOUNCE)
- {
- - add_bouncy_distro(((int)(x + 1) / 32) * 32,
- - (int)(y / 32) * 32);
- + add_bouncy_distro(int2fp(((xx + 1) / 32) * 32),
- + int2fp((yy / 32) * 32));
- }
- player_status.score = player_status.score + SCORE_DISTRO;
- @@ -742,13 +757,13 @@
- /* Try to bump a bad guy from below: */
- void
- -World::trybumpbadguy(float x, float y)
- +World::trybumpbadguy(fp x, fp y)
- {
- // Bad guys:
- for (BadGuys::iterator i = bad_guys.begin(); i != bad_guys.end(); ++i)
- {
- - if ((*i)->base.x >= x - 32 && (*i)->base.x <= x + 32 &&
- - (*i)->base.y >= y - 16 && (*i)->base.y <= y + 16)
- + if ((*i)->base.x >= x - int2fp(32) && (*i)->base.x <= x + int2fp(32) &&
- + (*i)->base.y >= y - int2fp(16) && (*i)->base.y <= y + int2fp(16))
- {
- (*i)->collision(&tux, CO_PLAYER, COLLISION_BUMP);
- }
- @@ -757,9 +772,9 @@
- // Upgrades:
- for (unsigned int i = 0; i < upgrades.size(); i++)
- {
- - if (upgrades[i].base.height == 32 &&
- - upgrades[i].base.x >= x - 32 && upgrades[i].base.x <= x + 32 &&
- - upgrades[i].base.y >= y - 16 && upgrades[i].base.y <= y + 16)
- + if (upgrades[i].base.height == int2fp(32) &&
- + upgrades[i].base.x >= x - int2fp(32) && upgrades[i].base.x <= x + int2fp(32) &&
- + upgrades[i].base.y >= y - int2fp(16) && upgrades[i].base.y <= y + int2fp(16))
- {
- upgrades[i].collision(&tux, CO_PLAYER, COLLISION_BUMP);
- }
- diff -Naur supertux-0.1.3/src.bak/world.h supertux-0.1.3/src/world.h
- --- supertux-0.1.3/src.bak/world.h 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/world.h 2014-12-06 18:04:19.000000000 -0500
- @@ -30,6 +30,7 @@
- #include "badguy.h"
- #include "particlesystem.h"
- #include "gameobjs.h"
- +#include "fpmath.h"
- class Level;
- @@ -77,8 +78,8 @@
- void set_defaults();
- void draw();
- - void action(double frame_ratio);
- - void scrolling(double frame_ratio); // camera scrolling
- + void action(fp frame_ratio);
- + void scrolling(fp frame_ratio); // camera scrolling
- void play_music(int musictype);
- int get_music_type();
- @@ -92,29 +93,29 @@
- void activate_particle_systems();
- void activate_bad_guys();
- - void add_score(float x, float y, int s);
- - void add_bouncy_distro(float x, float y);
- - void add_broken_brick(Tile* tile, float x, float y);
- - void add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym);
- - void add_bouncy_brick(float x, float y);
- + void add_score(fp x, fp y, int s);
- + void add_bouncy_distro(fp x, fp y);
- + void add_broken_brick(Tile* tile, fp x, fp y);
- + void add_broken_brick_piece(Tile* tile, fp x, fp y, fp xm, fp ym);
- + void add_bouncy_brick(fp x, fp y);
- - BadGuy* add_bad_guy(float x, float y, BadGuyKind kind, bool stay_on_platform = false);
- + BadGuy* add_bad_guy(fp x, fp y, BadGuyKind kind, bool stay_on_platform = false);
- - void add_upgrade(float x, float y, Direction dir, UpgradeKind kind);
- - void add_bullet(float x, float y, float xm, Direction dir);
- + void add_upgrade(fp x, fp y, Direction dir, UpgradeKind kind);
- + void add_bullet(fp x, fp y, fp xm, Direction dir);
- /** Try to grab the coin at the given coordinates */
- - void trygrabdistro(float x, float y, int bounciness);
- + void trygrabdistro(fp x, fp y, int bounciness);
- /** Try to break the brick at the given coordinates */
- - void trybreakbrick(float x, float y, bool small, Direction col_side);
- + void trybreakbrick(fp x, fp y, bool small, Direction col_side);
- /** Try to get the content out of a bonus box, thus emptying it */
- - void tryemptybox(float x, float y, Direction col_side);
- + void tryemptybox(fp x, fp y, Direction col_side);
- /** Try to bumb a badguy that might we walking above Tux, thus shaking
- the tile which the badguy is walking on an killing him this way */
- - void trybumpbadguy(float x, float y);
- + void trybumpbadguy(fp x, fp y);
- /** Apply bonuses active in the player status, used to reactivate
- bonuses from former levels */
- diff -Naur supertux-0.1.3/src.bak/worldmap.cpp supertux-0.1.3/src/worldmap.cpp
- --- supertux-0.1.3/src.bak/worldmap.cpp 2014-12-06 18:00:57.000000000 -0500
- +++ supertux-0.1.3/src/worldmap.cpp 2014-12-07 10:49:12.000000000 -0500
- @@ -516,9 +516,17 @@
- /** get level's title */
- level->title = "<no title>";
- - FILE * fi;
- + char fname[1024];
- +
- + strcpy(fname, (datadir + "/levels/" + level->name).c_str());
- + if(!faccessible(fname)) {
- + strcat(fname, ".gz");
- + }
- +
- + //FILE * fi;
- + gzFile fi;
- lisp_object_t* root_obj = 0;
- - fi = fopen((datadir + "/levels/" + level->name).c_str(), "r");
- + fi = gzopen(fname, "r");
- if (fi == NULL)
- {
- perror((datadir + "/levels/" + level->name).c_str());
- @@ -526,7 +534,7 @@
- }
- lisp_stream_t stream;
- - lisp_stream_init_file (&stream, fi);
- + lisp_stream_init_gzfile (&stream, fi);
- root_obj = lisp_read (&stream);
- if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
- @@ -542,7 +550,7 @@
- lisp_free(root_obj);
- - fclose(fi);
- + gzclose(fi);
- }
- void
- @@ -791,10 +799,10 @@
- music_manager->play_music(theme);
- // Display final credits and go back to the main menu
- display_text_file(level->extro_filename,
- - "/images/background/extro.jpg", SCROLL_SPEED_MESSAGE);
- + "/images/background/extro.jpg", FP_SCROLL_SPEED_MESSAGE);
- music_manager->play_music(credits,0);
- display_text_file("CREDITS",
- - "/images/background/oiltux.jpg", SCROLL_SPEED_CREDITS);
- + "/images/background/oiltux.jpg", FP_SCROLL_SPEED_CREDITS);
- music_manager->play_music(theme);
- quit = true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement