fix worst compilation errors when using the debian lenny gcc/libc...
authorTero Marttila <terom@fixme.fi>
Thu, 22 Jan 2009 03:53:17 +0200
changeset 423 947ab54de4b7
parent 422 5e4c8631779e
child 424 f337a86d144e
fix worst compilation errors when using the debian lenny gcc/libc...
src/Config.hh
src/Engine.cc
src/GameState.cc
src/Graphics/Color.hh
src/Graphics/Display.hh
src/Graphics/Drawable.hh
src/Graphics/Graphics.hh
src/Network/Address.hh
src/Network/Error.cc
src/Network/Packet.hh
src/Network/Platform.hh
src/PhysicsObject.hh
src/PhysicsWorld.cc
src/PhysicsWorld.hh
src/Player.cc
src/Terrain.cc
src/Terrain.hh
src/Timer.cc
src/Vector.hh
src/Weapon.hh
--- a/src/Config.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Config.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -13,8 +13,9 @@
 // custom types
 #include "Types.hh"
 
-// for CL_Color
-#include <ClanLib/display.h>
+// for Color
+#include "Graphics/Color.hh"
+using graphics::Color;
 
 /**
  * @name General
@@ -35,13 +36,13 @@
 const PixelDimensions TERRAIN_DIMENSIONS (1000, 800);
 
 /** Base color of empty space (i.e. background color) */
-const CL_Color COLOR_EMPTY(86, 41, 0);
+const Color COLOR_EMPTY(86, 41, 0);
 
 /** Base color of dirt */
-const CL_Color COLOR_DIRT(144, 82, 23);
+const Color COLOR_DIRT(144, 82, 23);
 
 /** Base color of rock */
-const CL_Color COLOR_ROCK(132, 136, 135);
+const Color COLOR_ROCK(132, 136, 135);
 
 
 // @}
@@ -65,7 +66,7 @@
  */
 
 /** The value of pi used in physics/graphics calculations */
-const float KG_PI = 3.14159265;
+const float KG_PI = 3.14159265f;
 
 /** Physics tick interval */
 const TimeMS PHYSICS_TICK_MS = 10;
@@ -84,13 +85,13 @@
 const float PLAYER_MOVE_FORCE = 1100.0;
 const float PLAYER_MIN_SPEED = 10.0;
 const float PLAYER_JUMP_MIN_DISTANCE = 5.0;
-const float PLAYER_AIM_MIN = -3*KG_PI/8; 
-const float PLAYER_AIM_MAX = KG_PI/2;
+const float PLAYER_AIM_MIN = -3 * KG_PI / 8; 
+const float PLAYER_AIM_MAX = KG_PI / 2;
 const float PLAYER_INITIAL_X = 400.0;
 const float PLAYER_INITIAL_Y = 300.0;
 const float PLAYER_CROSSHAIR_DISTANCE = 20.0;
 const float PLAYER_CROSSHAIR_WIDTH = 4;
-const float CROSSHAIR_ANGLE_SPEED = PI/2000;
+const float CROSSHAIR_ANGLE_SPEED = KG_PI / 2000;
 const float PLAYER_MAX_SPEED = 43;
 const float PLAYER_WALK_SPEED = 33;
 const float PLAYER_COLLISION_ELASTICITY = 0.25;
@@ -143,8 +144,8 @@
 /**
  * Rope colors, it should alternate between these two
  */
-const CL_Color ROPE_COLOR_LIGHT = CL_Color(198, 100, 2);
-const CL_Color ROPE_COLOR_DARK = CL_Color(159, 79, 1);
+const Color ROPE_COLOR_LIGHT(198, 100, 2);
+const Color ROPE_COLOR_DARK(159, 79, 1);
 
 // @}
 
--- a/src/Engine.cc	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Engine.cc	Thu Jan 22 03:53:17 2009 +0200
@@ -14,6 +14,7 @@
 
 #if GRAPHICS_ENABLED
     #include "Graphics/Graphics.hh"
+    #include "Graphics/GameView.hh"
 #endif
 
 #include <iostream>
@@ -107,6 +108,10 @@
 void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) {
 
 #if NETWORK_ENABLED 
+    // client operation requires graphics
+    if (!GRAPHICS_ENABLED)
+        throw Error("Network client mode requires graphics support");
+
     // connect_to
     NetworkEndpoint connect_addr(connect_host, connect_port);
 
@@ -137,8 +142,10 @@
         startGameView(lp);
 }
         
+GameState& Engine::onNetworkClientConnected (Terrain *terrain) {
+    // sanity-check
+    assert(!terrain && !game_state && graphics);
 
-GameState& Engine::onNetworkClientConnected (Terrain *terrain) {
     // setup the game
     setupGame(terrain);
 
@@ -148,12 +155,22 @@
     // return GameState
     return *game_state;
 }
-        
+
 void Engine::onNetworkClientPlayer (LocalPlayer *player) {
+
+#if GRAPHICS_ENABLED
     assert(game_view);
 
     // set the GameView's player
     game_view->setPlayer(player);
+
+#else
+    (void) player;
+
+    assert(graphics);
+
+#endif
+
 }
 
 void Engine::stop (void) {
--- a/src/GameState.cc	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/GameState.cc	Thu Jan 22 03:53:17 2009 +0200
@@ -5,7 +5,7 @@
 #include "Error.hh"
 
 GameState::GameState (Terrain &terrain) : 
-    world(Vector(0, MAP_GRAVITY), Vector(terrain.getWidth(), terrain.getHeight()), terrain), 
+    world(Vector(0, MAP_GRAVITY), Vector((float) terrain.getWidth(), (float) terrain.getHeight()), terrain), 
     terrain(terrain),
     local_player(NULL), event_handler(NULL)
 { 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Graphics/Color.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -0,0 +1,37 @@
+#ifndef GRAPHICS_COLOR_HH
+#define GRAPHICS_COLOR_HH
+
+#if GRAPHICS_ENABLED
+
+#include <ClanLib/Display/color.h>
+
+namespace graphics
+{
+
+// alias
+typedef CL_Color Color;
+
+}
+
+# else /* GRAPHICS_ENABLED */
+
+namespace graphics
+{
+
+/**
+ * XXX: define dummy color type for use when graphics are disabled
+ */
+class Color {
+public:
+    Color (unsigned red, unsigned green, unsigned blue) 
+    { 
+        (void) red;
+        (void) green;
+        (void) blue;
+    }
+};
+
+}
+#endif /* GRAPHICS_ENABLED */
+
+#endif /* GRAPHICS_COLOR_HH */
--- a/src/Graphics/Display.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Graphics/Display.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -11,6 +11,9 @@
 
 }
 
+// XXX: ugly hack
+#if GRAPHICS_ENABLED
+
 #include "View.hh"
 #include "../Timer.hh"
 #include "../Configuration.hh"
@@ -99,4 +102,6 @@
 
 }
 
-#endif
+#endif /* GRAPHICS_ENABLED */
+
+#endif /* GRAPHICS_ENABLED */
--- a/src/Graphics/Drawable.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Graphics/Drawable.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -1,4 +1,6 @@
-#ifndef GRAPHICS_DRAWABLE_HH
+
+// XXX: because this is included from ..
+#if GRAPHICS_ENABLED && !(defined GRAPHICS_DRAWABLE_HH)
 #define GRAPHICS_DRAWABLE_HH
 
 namespace graphics
--- a/src/Graphics/Graphics.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Graphics/Graphics.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -1,4 +1,5 @@
-#ifndef GRAPHICS_GRAPHICS_HH
+// XXX: ugly hack
+#if GRAPHICS_ENABLED && !(defined GRAPHICS_GRAPHICS_HH)
 #define GRAPHICS_GRAPHICS_HH
 
 namespace graphics
--- a/src/Network/Address.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Network/Address.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -10,6 +10,8 @@
 #include "Platform.hh"
 #include "Endpoint.hh"
 
+#include <cstring>
+
 /**
  * A NetworkAddress represents a single network address in the form of a `struct sockaddr`, as used by the OS's socket
  * API. A NetworkAddress's value may only be constructed/manipulated in sockaddr form, and the class then emulates the
--- a/src/Network/Error.cc	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Network/Error.cc	Thu Jan 22 03:53:17 2009 +0200
@@ -1,7 +1,7 @@
 
 #include "Error.hh"
+#include "Platform.hh"
 
-#include <cerrno>
 #include <sstream>
 
 std::string NetworkErrno::build_str (std::string op, int err) {
--- a/src/Network/Packet.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Network/Packet.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -7,8 +7,8 @@
  * Provides the NetworkPackets that are used to communicate over a NetworkTCP/NetworkUDP sockets.
  */
 
+#include "../Types.hh"
 #include "../Config.hh"
-#include "../Types.hh"
 #include "../Error.hh"
 
 /**
--- a/src/Network/Platform.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Network/Platform.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -30,6 +30,10 @@
     #include <arpa/inet.h>
     #include <sys/time.h>
     #include <unistd.h> 
+
+    // NetworkErrno
+    #include <string.h>
+    #include <errno.h>
 #else
     // misc, here because ClanLib included these...
     #include <winsock2.h>
--- a/src/PhysicsObject.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/PhysicsObject.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -1,8 +1,6 @@
 #ifndef PHYSICS_OBJECT_HH
 #define PHYSICS_OBJECT_HH
 
-#include <ClanLib/display.h>
-#include <utility>
 
 // Forward declares
 class PhysicsObject;
@@ -13,6 +11,9 @@
 #include "Timer.hh"
 #include "Config.hh"
 
+#include <utility>
+#include <queue>
+
 // Type definitions
 typedef Vector Force;
 
--- a/src/PhysicsWorld.cc	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/PhysicsWorld.cc	Thu Jan 22 03:53:17 2009 +0200
@@ -2,7 +2,9 @@
 #include "PhysicsWorld.hh"
 #include "Engine.hh"
 
+#include <algorithm>
 #include <functional>
+#include <cmath>
 
 PhysicsWorld::PhysicsWorld (Vector gravity, Vector dimensions, Terrain &terrain) :
     terrain(terrain),
--- a/src/PhysicsWorld.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/PhysicsWorld.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -1,13 +1,6 @@
 #ifndef PHYSICS_WORLD_HH
 #define PHYSICS_WORLD_HH
 
-#include <ClanLib/display.h>
-#include <ClanLib/core.h>
-
-#include <algorithm>
-#include <functional>
-#include <cmath>
-
 #include "Terrain.hh"          
 
 class PhysicsWorld;
@@ -17,6 +10,8 @@
 #include "Timer.hh"
 #include "Config.hh"
 
+#include <ClanLib/core.h>
+
 /**
 * PhysicsWorld class. PhysicsWorld contains a number of PhysicsObjects that are simulated forward in time using
 * the physics tick rate
--- a/src/Player.cc	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Player.cc	Thu Jan 22 03:53:17 2009 +0200
@@ -3,15 +3,16 @@
 #include "Weapons.hh"
 #include "Engine.hh"
 
-#include "Graphics/Graphics.hh"
-
 #include <cstdlib>
-#include <ClanLib/display.h>
 #include <algorithm>
 #include <string>
 #include <cassert>
 
 #if GRAPHICS_ENABLED
+
+#include <ClanLib/display.h>
+#include "Graphics/Graphics.hh"
+
 /*
  * Static draw-related state
  */
--- a/src/Terrain.cc	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Terrain.cc	Thu Jan 22 03:53:17 2009 +0200
@@ -3,10 +3,18 @@
 #include "Engine.hh"
 
 #include <cmath>
+#include <cstring>
 #include <cassert>
 #include <algorithm>
+
+#if GRAPHICS_ENABLED
+
+#include "Graphics/Drawable.hh"
+
 #include <ClanLib/display.h>
 
+#endif
+
 const Vector DIRECTIONS[] = {
     Vector(0,-1),
     Vector(1,-1),
@@ -124,6 +132,8 @@
 
 }
 
+// XXX: disable textures as well
+#if GRAPHICS_ENABLED
 /*
  * Texture generation utility functions
  */
@@ -219,8 +229,8 @@
         return val;
 }
 
-CL_Color Terrain::getTexturePixel (PixelDimension x, PixelDimension y) {
-    CL_Color color;
+Color Terrain::getTexturePixel (PixelDimension x, PixelDimension y) {
+    Color color;
     int texture_fade = 8;
     
     // determine fade constant
@@ -255,12 +265,13 @@
     blue += (texture[tx][ty] - 128) / texture_fade;
     
     // normalize colors to within range and return new color    
-    return CL_Color(
+    return Color(
             normalizeRange(0, red, 255),
             normalizeRange(0, green, 255),
             normalizeRange(0, blue, 255)
     );
 }
+#endif /* GRAPHICS_ENABLED */
 
 const TerrainPixel* Terrain::getTerrainBuffer (void) const {
     return terrain_buf;
--- a/src/Terrain.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Terrain.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -6,8 +6,6 @@
 #include "Config.hh"
 #include "Configuration.hh"
 
-#include "Graphics/Drawable.hh"
-
 #include <vector>
 
 /**
@@ -117,7 +115,7 @@
      * Applies noise generated using generateTexture to generate a slightly varying color for the terrain pixel
      * at \a pc.
      */
-    CL_Color getTexturePixel (PixelDimension x, PixelDimension y);
+    Color getTexturePixel (PixelDimension x, PixelDimension y);
 
     /**
      * Scale parameter to "pixels"
--- a/src/Timer.cc	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Timer.cc	Thu Jan 22 03:53:17 2009 +0200
@@ -50,7 +50,9 @@
         
         // update state
         last_tick = now;
-        ticks += tick_length / interval;
+
+        // XXX: handle overflow
+        ticks += (TickCount) tick_length / interval;
 
         // if it was single-shot, disable
         if (single_shot)
--- a/src/Vector.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Vector.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -208,8 +208,8 @@
  * Float/int absolute value
  */
 template<typename T> static T absType (T value);
-template<> static float absType<float> (float value) { return fabs(value); }
-template<> static long absType<long> (long value) { return labs(value); }
+template<> float absType<float> (float value) { return (float) fabs(value); }
+template<> long absType<long> (long value) { return labs(value); }
 
 /**
  * Direction-normalize the given coordinate against the tangent coordinate.
--- a/src/Weapon.hh	Thu Jan 22 03:19:25 2009 +0200
+++ b/src/Weapon.hh	Thu Jan 22 03:53:17 2009 +0200
@@ -68,9 +68,9 @@
     TickCount expire;
 
     /**
-     * current reload state
+     * Remaining reload time
      */
-    int reloadTimer;
+    TimeMS reloadTimer;
 
     /**
      * If nonzero, projectiles bounce off walls (it's the elasticity factor), else they explode on contact
@@ -106,14 +106,17 @@
     float getSpeed (void) const { return velocity; }
     float getRecoil (void) const { return recoil; }
     float getExplosionRadius (void) const { return explosionRadius; }
-    int getDamage (void) const { return damage; }
+    
+    // XXX: int -> Health
+    Health getDamage (void) const { return (Health) damage; }
     float getRadius (void) const { return radius; }
     TickCount getExpire (void) const { return expire; }
     float getBounce (void) const { return bounce; }
     float getMass (void) const { return mass; }
-
-    int getReloadTimer(void) const { return reloadTimer; }
-    int getReloadTime(void) const { return reloadTime; }
+    
+    // XXX: remove one of these
+    TimeMS getReloadTimer(void) const { return reloadTimer; }
+    TimeMS getReloadTime(void) const { return reloadTime; }
     
     /**
      * Start reloading