compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
authorterom
Mon, 08 Dec 2008 12:02:20 +0000
changeset 282 e0e4dfc3e528
parent 281 3f2de9d1d909
child 283 7540b0859579
compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
build/mkcmake.sh
src/GameState.cc
src/Graphics.cc
src/Input.cc
src/Network/Client.cc
src/Network/Server.cc
src/PhysicsObject.cc
src/PhysicsObject.hh
src/PhysicsWorld.cc
src/Player.cc
src/Projectile.cc
src/Rope.cc
src/Terrain.cc
src/Timer.cc
src/Weapon.cc
--- a/build/mkcmake.sh	Mon Dec 08 11:10:04 2008 +0000
+++ b/build/mkcmake.sh	Mon Dec 08 12:02:20 2008 +0000
@@ -3,5 +3,5 @@
 cmake ../                                       \
     -DCMAKE_BUILD_TYPE=Debug                    \
     -DCMAKE_INSTALL_PREFIX=~/opt                \
-    -DCMAKE_CXX_FLAGS=-Wall                     
+    -DCMAKE_CXX_FLAGS="-Wall -Wextra -Wconversion"
 
--- a/src/GameState.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/GameState.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -4,7 +4,7 @@
 #include "Config.hh"
 
 GameState::GameState (void) : 
-    local_player(NULL), world(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)) 
+    world(Vector(0, MAP_GRAVITY), Vector(MAP_WIDTH, MAP_HEIGHT)), local_player(NULL)
 { 
 
 }
--- a/src/Graphics.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Graphics.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -5,9 +5,9 @@
 
 Graphics::Graphics (Engine &engine, GameState &state) :
     CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
-    resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
     engine(engine), 
     state(state), 
+    resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT),
     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
     input(get_ic()->get_keyboard()),
     simple_font("Font2", engine.getResourceManager()) 
--- a/src/Input.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Input.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -15,20 +15,20 @@
     {   INPUT_MOVE_RIGHT,   -CL_KEY_ENTER,      CL_KEY_RIGHT    },
     {   INPUT_JUMP,         -CL_KEY_ENTER,      CL_KEY_RSHIFT   },
     {   INPUT_DIG,          CL_KEY_LEFT,        CL_KEY_RIGHT    },
-    {   INPUT_SHOOT,        CL_KEY_RCONTROL                     },
+    {   INPUT_SHOOT,        CL_KEY_RCONTROL,    0               },
     {   INPUT_CHANGE_PREV,  CL_KEY_ENTER,       CL_KEY_LEFT     },
     {   INPUT_CHANGE_NEXT,  CL_KEY_ENTER,       CL_KEY_RIGHT    },
     {   INPUT_ROPE,         CL_KEY_ENTER,       CL_KEY_RSHIFT   },
     {   INPUT_UNROPE,       -CL_KEY_ENTER,      CL_KEY_RSHIFT   },
     {   INPUT_ROPE_UP,      CL_KEY_ENTER,       CL_KEY_UP       },
     {   INPUT_ROPE_DOWN,    CL_KEY_ENTER,       CL_KEY_DOWN     },
-    {   INPUT_NONE,                                             }
+    {   INPUT_NONE,         0,                  0               }
 };
 
 InputKeymapEntry<GuiInputBit> INPUT_GUI_KEYMAP[] = {
-    {   GUI_INPUT_QUIT,             CL_KEY_ESCAPE               },
-    {   GUI_INPUT_DISPLAY_WEAPON,   CL_KEY_ENTER                },
-    {   GUI_INPUT_DEBUG_PLAYER,     CL_KEY_I                    },
+    {   GUI_INPUT_QUIT,             CL_KEY_ESCAPE,          0   },
+    {   GUI_INPUT_DISPLAY_WEAPON,   CL_KEY_ENTER,           0   },
+    {   GUI_INPUT_DEBUG_PLAYER,     CL_KEY_I,               0   },
 };
 
 Input::Input (CL_InputDevice &keyboard) :
--- a/src/Network/Client.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Network/Client.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -24,12 +24,13 @@
     Terrain &terrain = state.world;
 
     // read map width/height
-    uint32_t map_w = pkt.read_uint32();
-    uint32_t map_h = pkt.read_uint32();
+    // XXX: over 2**31?
+    PixelDimension map_w = pkt.read_uint32();
+    PixelDimension map_h = pkt.read_uint32();
 
     // read map data
-    for (int x = 0; x < map_w; x++) {
-        for (int y = 0; y < map_h; y++) {
+    for (PixelDimension x = 0; x < map_w; x++) {
+        for (PixelDimension y = 0; y < map_h; y++) {
             terrain.terrain[x][y] = (TerrainType) pkt.read_uint8();
         }
     }
@@ -57,6 +58,9 @@
 }
 
 void NetworkClientController::handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node) {
+    // XXX: should be server
+    (void) node;
+
     switch (msg_id) {
         case NETMSG_SERVER_HELLO:
             on_server_hello(obj_id, pkt);
@@ -150,7 +154,8 @@
  * NetworkClientPlayerBase
  */
 NetworkClientPlayerBase::NetworkClientPlayerBase (NetworkClient &client, NetworkObjectID obj_id, Vector position) :
-    NetworkClientObject(client, obj_id), Player(client.state, position, true) 
+    Player(client.state, position, true),
+    NetworkClientObject(client, obj_id)
 {
     slots.connect(sig_message(NETMSG_PLAYER_POSITION),         this,   &NetworkClientPlayerBase::on_position         );
     slots.connect(sig_message(NETMSG_PLAYER_DIG),              this,   &NetworkClientPlayerBase::on_dig              );
@@ -215,6 +220,8 @@
 }
 
 void NetworkClientPlayerBase::on_rope_released (NetworkPacketInput &pkt) {
+    (void) pkt;
+
     Engine::log(INFO, "client_player.on_rope_released") << this;
     
     // use rope.getPosition() instead of e.g. Vector(0, 0) because it will collide there...
@@ -282,6 +289,9 @@
 }
 
 void NetworkClientProjectile::onDestroy (Vector position, bool removeGround) {
+    (void) position;
+    (void) removeGround;
+
     // ignore :>
 }
 
--- a/src/Network/Server.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Network/Server.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -197,9 +197,10 @@
         
 void NetworkServerPlayer::send_terrain_data (void) {
     Terrain &terrain = server.state.world;
-
-    uint32_t map_w = terrain.terrain.size();
-    uint32_t map_h = terrain.terrain[0].size();
+    
+    // XXX: over 2**31?
+    PixelDimension map_w = terrain.terrain.size();
+    PixelDimension map_h = terrain.terrain[0].size();
 
     // allocate our packet...
     BigNetworkPacket pkt (NETWORK_SESSION_HEADER_SIZE + 2 * sizeof(uint32_t) + map_w * map_h);
@@ -212,8 +213,8 @@
     pkt.write_uint32(map_h);
 
     // write out terrain data
-    for (int x = 0; x < map_w; x++) {
-        for (int y = 0; y < map_h; y++) {
+    for (PixelDimension x = 0; x < map_w; x++) {
+        for (PixelDimension y = 0; y < map_h; y++) {
             pkt.write_uint8((uint8_t) terrain.terrain[x][y]);
         }
     }
--- a/src/PhysicsObject.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/PhysicsObject.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -7,8 +7,18 @@
 
 PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity, ObjectType type, 
             float collision_elasticity, bool enabled) :
-    world(world), position(position), velocity(velocity), mass(mass), inAir(true), aim(0), facing(FACING_RIGHT), 
-    alive(false), shouldDelete(false), type(type), pivot(NULL), collision_elasticity(collision_elasticity)
+    world(world), 
+    position(position), 
+    velocity(velocity), 
+    mass(mass), 
+    inAir(true), 
+    collision_elasticity(collision_elasticity),
+    aim(0), 
+    facing(FACING_RIGHT), 
+    alive(false),
+    shouldDelete(false), 
+    type(type), 
+    pivot(NULL)
 {  
     if (enabled)
         enable();  
@@ -152,7 +162,7 @@
         // If, however, there's a force caused by a bomb, e.g., set it in air.
         // Still, we have to be able to separate forces caused by walking attempts
         // and bombs etc (+0.1 because float comparison can be dangerous)
-        if (total.y < 0.01 || abs(total.x) > PLAYER_MOVE_FORCE + 0.1)
+        if (total.y < 0.01 || fabs(total.x) > PLAYER_MOVE_FORCE + 0.1)
             this->inAir = true;
     }
 
@@ -270,8 +280,8 @@
     velAfterTick = velocity;
     Derivative tmpd;
     Derivative k1 = evaluate(force, 0, tmpd, posAfterTick, velAfterTick);
-    Derivative k2 = evaluate(force, 0.5f*dt, k1, posAfterTick, velAfterTick);
-    Derivative k3 = evaluate(force, 0.5f*dt, k2, posAfterTick, velAfterTick);
+    Derivative k2 = evaluate(force, dt / 2, k1, posAfterTick, velAfterTick);
+    Derivative k3 = evaluate(force, dt / 2, k2, posAfterTick, velAfterTick);
     Derivative k4 = evaluate(force, dt, k3, posAfterTick, velAfterTick);
     
 
@@ -404,6 +414,8 @@
 }
 
 float PhysicsObject::getPivotForce (PhysicsObject *bob) { 
+    (void) bob;
+
     return 0.0; 
 }
 
@@ -426,6 +438,11 @@
     }
     return true;
 }
+    
+void  PhysicsObject::onCollision (Vector collisionPoint, PhysicsObject *other) {
+    (void) collisionPoint;
+    (void) other;
+}
 
 int8_t crossProduct (const Vector &p1, const Vector &p2, const Vector &p3) {
     float p = (p2.x - p1.x)*(p3.y - p1.y) - (p2.y - p1.y)*(p3.x - p1.x);
--- a/src/PhysicsObject.hh	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/PhysicsObject.hh	Mon Dec 08 12:02:20 2008 +0000
@@ -27,6 +27,9 @@
  * PhysicObject class. A basic PhysicsObject class.
  */
 class PhysicsObject {
+public:
+    PhysicsWorld &world;
+
 protected:
     Vector position;
     Vector velocity;
@@ -154,12 +157,12 @@
 
     /**
      * Define object behaviour on collisions.
+     *
+     * XXX: make this pure-virtual
      */
-    virtual void onCollision (Vector collisionPoint, PhysicsObject *other) {}
+    virtual void onCollision (Vector collisionPoint, PhysicsObject *other);
 
 public:
-    PhysicsWorld &world;
-
     /**
      * Checks if it is possible for the object to be in the given
      * location.
--- a/src/PhysicsWorld.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/PhysicsWorld.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -5,7 +5,11 @@
 #include <functional>
 
 PhysicsWorld::PhysicsWorld (Vector gravity, Vector dimensions) :
-    Terrain(dimensions.x, dimensions.y, 1337), tick_timer(PHYSICS_TICK_MS), dimensions(dimensions), gravity(gravity)
+    // XXX: assume Vector == PixelCoordinate
+    Terrain((unsigned int) dimensions.x, (unsigned int) dimensions.y, 1337), 
+    dimensions(dimensions), 
+    gravity(gravity),
+    tick_timer(PHYSICS_TICK_MS)
 {
     slots.connect(tick_timer.sig_tick(), this, &PhysicsWorld::tick);
     tick_timer.start();
--- a/src/Player.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Player.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -20,8 +20,13 @@
 const int img_width = 17;
 
 Player::Player(GameState &state, Vector position, bool visible) : 
-    PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0), PLAYER, PLAYER_COLLISION_ELASTICITY), state(state), 
-    visible(visible), weapons(buildWeaponsList()), selectedWeapon(0), animation_step(0), rope(*this) 
+    PhysicsObject(state.world, PLAYER_MASS, position, Vector(0, 0), PLAYER, PLAYER_COLLISION_ELASTICITY), 
+    state(state), 
+    visible(visible), 
+    weapons(buildWeaponsList()), 
+    selectedWeapon(0), 
+    rope(*this),
+    animation_step(0)
 {
     // XXX: populate weapons from somewhere else
 
@@ -86,11 +91,11 @@
 }
         
 void Player::handleRopeState (RopeState state) {
-    
+    (void) state;
 }
 
 void Player::handleRopeLength (float length) {
-
+    (void) length;
 }
 
 void LocalPlayer::fireWeapon (Weapon *weapon) {
--- a/src/Projectile.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Projectile.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -5,7 +5,10 @@
    
 Projectile::Projectile (Player *player, Vector position, Vector velocity, Weapon *weapon, bool visible) :
     PhysicsObject(player->state.world, PROJECTILE_MASS, position, velocity, PROJECTILE, weapon->getBounce()),
-    player(player), visible(visible), explosionRadius(weapon->getExplosionRadius()), radius(weapon->getRadius()),
+    player(player), 
+    visible(visible), 
+    radius(weapon->getRadius()),
+    explosionRadius(weapon->getExplosionRadius()), 
     expire(weapon->getExpire())
 {
     // set birth tick
@@ -37,6 +40,8 @@
 }
 
 void Projectile::onCollision (Vector collisionPoint, PhysicsObject *other) {
+    (void) other;
+
     if (collision_elasticity == 0)
         onDestroy(collisionPoint, true);
 }
@@ -56,6 +61,7 @@
 
     if (visible) {
         PixelCoordinate pos = getCoordinate() - camera;
+        PixelDimension radius = (unsigned int) this->radius;
 
         CL_Quad projectile(
                 pos.x,          pos.y - radius,
--- a/src/Rope.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Rope.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -38,6 +38,8 @@
 }
 
 void Rope::onCollision (Vector collisionPoint, PhysicsObject *other) {
+    (void) other;
+
     // attached to something!
     state = ROPE_FIXED;
         
@@ -114,7 +116,7 @@
 }
 
 float Rope::getPivotForce (PhysicsObject *bob) {
-    if ((position - player.getPosition()).length() >= length)
+    if ((position - bob->getPosition()).length() >= length)
         return ROPE_FORCE;
     else
         return 0;
--- a/src/Terrain.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Terrain.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -13,7 +13,9 @@
 }
 
 Terrain::Terrain (PixelDimension map_width, PixelDimension map_height, int seed) :
-    map_width(map_width), map_height(map_height), terrain(map_width, std::vector<TerrainType>(map_height, TERRAIN_DIRT))
+    terrain(map_width, std::vector<TerrainType>(map_height, TERRAIN_DIRT)),
+    map_width(map_width), 
+    map_height(map_height)
 {
     generateTerrain(seed);
 }
@@ -176,7 +178,8 @@
 }
 
 PixelCoordinate Terrain::getPixelCoordinate (Vector point) const {
-    return PixelCoordinate(point.x, point.y);
+    // XXX: assume 1:1
+    return PixelCoordinate((unsigned int) point.x, (unsigned int) point.y);
 }
 
 PixelCoordinate Terrain::getDimensions (void) const {
@@ -267,7 +270,7 @@
     // though the current impelementation doesn't seem too bad either.
 
     PixelCoordinate mid = getPixelCoordinate(pos);
-    PixelDimension r = radius;
+    PixelDimension r = (unsigned int) radius; // XXX: scale
 
     for (PixelDimension i = mid.x - r; i < mid.x + r; i++) {
         for (PixelDimension j = mid.y-r; j < mid.y+r; j++) {
--- a/src/Timer.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Timer.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -2,7 +2,10 @@
 #include "Timer.hh"
 
 Timer::Timer (TimeMS interval) :
-    interval(interval), ticks(0), last_tick(0), enabled(false)
+    interval(interval), 
+    ticks(0), 
+    enabled(false),
+    last_tick(0)
 {
 
 }
--- a/src/Weapon.cc	Mon Dec 08 11:10:04 2008 +0000
+++ b/src/Weapon.cc	Mon Dec 08 12:02:20 2008 +0000
@@ -2,8 +2,16 @@
 
 Weapon::Weapon(WeaponID id, TickCount expire, float velocity, float recoil, float explosionRadius, float radius,
         TimeMS reloadTime, std::string name, float bounce) : 
-    id(id), expire(expire), velocity(velocity), recoil(recoil), explosionRadius(explosionRadius), radius(radius),
-    reloadTime(reloadTime), name(name), reloadTimer(0), bounce(bounce)
+    id(id), 
+    name(name), 
+    velocity(velocity), 
+    explosionRadius(explosionRadius), 
+    radius(radius),
+    reloadTime(reloadTime), 
+    recoil(recoil), 
+    expire(expire), 
+    reloadTimer(0), 
+    bounce(bounce)
 {
 
 }