netpanzer-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[netPanzer-CVS] netpanzer/src Editor/MapView.cpp Lib/Types/Angl...


From: Matthias Braun
Subject: [netPanzer-CVS] netpanzer/src Editor/MapView.cpp Lib/Types/Angl...
Date: Mon, 01 Dec 2003 15:58:01 -0500

CVSROOT:        /cvsroot/netpanzer
Module name:    netpanzer
Branch:         
Changes by:     Matthias Braun <address@hidden> 03/12/01 15:58:00

Modified files:
        src/Editor     : MapView.cpp 
        src/Lib/Types  : Angle.hpp 
        src/NetPanzer/Classes: UnitOpcodeEncoder.cpp UnitOpcodes.hpp 
                               UnitState.cpp UnitState.hpp 
        src/NetPanzer/Classes/AI: Astar.cpp 
        src/NetPanzer/Classes/Network: PowerUpNetMessage.hpp 
                                       UnitNetMessage.hpp 
        src/NetPanzer/Core: NetworkGlobals.hpp 
        src/NetPanzer/Interfaces: UnitInterface.cpp 
        src/NetPanzer/Views/MainMenu: MainMenuView.cpp 

Log message:
        fixed some more valgrind warnings

Patches:
Index: netpanzer/src/Editor/MapView.cpp
diff -u netpanzer/src/Editor/MapView.cpp:1.1 
netpanzer/src/Editor/MapView.cpp:1.2
--- netpanzer/src/Editor/MapView.cpp:1.1        Wed Nov 26 17:42:24 2003
+++ netpanzer/src/Editor/MapView.cpp    Mon Dec  1 15:57:58 2003
@@ -26,6 +26,7 @@
 
 void MapView::redraw()
 {
-    maprenderer->render(getSurface(), 0, mapxpos, mapypos);
+    if(maprenderer)
+        maprenderer->render(getSurface(), 0, mapxpos, mapypos);
 }
 
Index: netpanzer/src/Lib/Types/Angle.hpp
diff -u netpanzer/src/Lib/Types/Angle.hpp:1.1 
netpanzer/src/Lib/Types/Angle.hpp:1.2
--- netpanzer/src/Lib/Types/Angle.hpp:1.1       Sat Nov 22 10:48:44 2003
+++ netpanzer/src/Lib/Types/Angle.hpp   Mon Dec  1 15:57:59 2003
@@ -19,6 +19,8 @@
 #define _ANGLE_HPP
 
 #include <math.h>
+#include <stdint.h>
+
 #include "Types/iXY.hpp"
 
 class Angle
@@ -95,7 +97,29 @@
     }
 };
 
-class AngleInt : public Angle
+#ifdef MSVC
+#pragma pack(1)
+#endif
+
+struct NetworkAngleInt
+{
+public:
+    NetworkAngleInt()
+    { }
+    
+private:
+    int32_t angle_int;
+    uint32_t grain;
+    int32_t angle_limit;
+
+    friend class AngleInt;
+} __attribute__((packed));
+
+#ifdef MSVC
+#pragma pack()
+#endif
+
+class AngleInt
 {
 public:
     long angle_int;
@@ -103,7 +127,6 @@
     long angle_limit;
 
     AngleInt( long nAngle = 0, unsigned long granularity = 360 )
-            : Angle( (double) nAngle )
     {
         angle_int = nAngle;
         grain = granularity;
@@ -111,15 +134,13 @@
     }
 
     AngleInt( long x, long y)
-            : Angle( x, y )
     {
-        angle_int = DegreesInt();
+        angle_int = Angle(x,y).DegreesInt();
     }
 
     AngleInt( iXY &vec )
-            : Angle( vec )
     {
-        angle_int = DegreesInt();
+        angle_int = Angle(vec).DegreesInt();
     }
 
     inline void set( long nAngle, unsigned long granularity )
@@ -148,6 +169,24 @@
     inline long Degrees() const
     {
         return( angle_int * grain );
+    }
+
+    NetworkAngleInt getNetworkAngleInt() const
+    {
+        NetworkAngleInt netangle;
+
+        netangle.angle_int = angle_int;
+        netangle.grain = grain;
+        netangle.angle_limit = angle_limit;
+
+        return netangle;
+    }
+
+    void setFromNetworkAngleInt(const NetworkAngleInt& netangle)
+    {
+        angle_int = netangle.angle_int;
+        grain = netangle.grain;
+        angle_limit = netangle.angle_limit;
     }
 };
 
Index: netpanzer/src/NetPanzer/Classes/AI/Astar.cpp
diff -u netpanzer/src/NetPanzer/Classes/AI/Astar.cpp:1.12 
netpanzer/src/NetPanzer/Classes/AI/Astar.cpp:1.13
--- netpanzer/src/NetPanzer/Classes/AI/Astar.cpp:1.12   Sun Nov 30 18:00:28 2003
+++ netpanzer/src/NetPanzer/Classes/AI/Astar.cpp        Mon Dec  1 15:57:59 2003
@@ -188,7 +188,12 @@
     delta_x = labs( pointA.x - pointB.x );
     delta_y = labs( pointA.y - pointB.y );
 
-    return( heuristic_weight * (delta_x + delta_y) );
+#if 0
+    // we can move diagonal...
+    return heuristic_weight * std::max(delta_x, delta_y);
+#else
+    return heuristic_weight * (delta_x + delta_y);
+#endif
 }
 
 
Index: netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp
diff -u netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp:1.5 
netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp:1.6
--- netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp:1.5   Sun Nov 
30 18:58:09 2003
+++ netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp       Mon Dec 
 1 15:57:59 2003
@@ -67,6 +67,7 @@
         PowerUpHitMesg::ID = ID;
         PowerUpHitMesg::unit_id = unit_id;
         PowerUpHitMesg::player_id = player_id.getIndex();
+        unit_powerup_type = 0;
     }
 
     PowerUpHitMesg()
Index: netpanzer/src/NetPanzer/Classes/Network/UnitNetMessage.hpp
diff -u netpanzer/src/NetPanzer/Classes/Network/UnitNetMessage.hpp:1.5 
netpanzer/src/NetPanzer/Classes/Network/UnitNetMessage.hpp:1.6
--- netpanzer/src/NetPanzer/Classes/Network/UnitNetMessage.hpp:1.5      Sun Nov 
30 18:23:13 2003
+++ netpanzer/src/NetPanzer/Classes/Network/UnitNetMessage.hpp  Mon Dec  1 
15:57:59 2003
@@ -62,7 +62,7 @@
     UnitID unit_id;
     uint32_t location_x;
     uint32_t location_y;
-    UnitState unit_state;
+    NetworkUnitState unit_state;
 
     UnitIniSyncMessage()
     {
Index: netpanzer/src/NetPanzer/Classes/UnitOpcodeEncoder.cpp
diff -u netpanzer/src/NetPanzer/Classes/UnitOpcodeEncoder.cpp:1.5 
netpanzer/src/NetPanzer/Classes/UnitOpcodeEncoder.cpp:1.6
--- netpanzer/src/NetPanzer/Classes/UnitOpcodeEncoder.cpp:1.5   Sun Oct  5 
09:50:12 2003
+++ netpanzer/src/NetPanzer/Classes/UnitOpcodeEncoder.cpp       Mon Dec  1 
15:57:59 2003
@@ -90,7 +90,6 @@
 
 void UnitOpcodeEncoder::sendOpcodeMessage( void )
 {
-
     if ( opcode_message.opcode_count > 0 ) {
         if( send_method == _opcode_encoder_send_method_guarantee ) {
             SERVER->sendMessage( &opcode_message, opcode_message.realSize(), 0 
);
Index: netpanzer/src/NetPanzer/Classes/UnitOpcodes.hpp
diff -u netpanzer/src/NetPanzer/Classes/UnitOpcodes.hpp:1.6 
netpanzer/src/NetPanzer/Classes/UnitOpcodes.hpp:1.7
--- netpanzer/src/NetPanzer/Classes/UnitOpcodes.hpp:1.6 Tue Nov 11 08:42:04 2003
+++ netpanzer/src/NetPanzer/Classes/UnitOpcodes.hpp     Mon Dec  1 15:57:59 2003
@@ -18,24 +18,33 @@
 #ifndef _UNITOPCODES_HPP
 #define _UNITOPCODES_HPP
 
+#include <stdint.h>
 #include <queue>
 
 enum { _unit_opcode_flag_sync = 0x01 };
 
+/** The following is a tricky macro to ensure a struct has a specific size. THe
+ * check is done at compiletime. The trick is that C doesn't allow duplicate
+ * case labels...
+ */
+#define ASSERT_SIZE(mystruct, size)                                     \
+    namespace TRICKYTESTS { static inline void mystruct##_test() {      \
+        int i=0; switch(i) { case 0: ; case (sizeof(mystruct) == (size)): ; } \
+    } }
+
 #ifdef MSVC
 #pragma pack(1)
 #endif
 
 struct UnitOpcodeStruct
 {
-    unsigned char  opcode;
-    unsigned char  player_index;
-    unsigned short unit_index;
-    unsigned char  flags;
-
-    unsigned char op_data[7];
-}
-__attribute__((packed));
+    uint8_t opcode;
+    uint8_t player_index;
+    uint16_t unit_index;
+    uint8_t flags;
+
+    uint8_t op_data[7];
+} __attribute__((packed));
 
 
 typedef std::queue< UnitOpcodeStruct > UnitOpcodeQueue;
@@ -43,22 +52,21 @@
 class UnitOpcode
 {
 public:
-    unsigned char  opcode;
-    unsigned char  player_index;
-    unsigned short unit_index;
-    unsigned char  flags;
-}
-__attribute__((packed));
+    uint8_t opcode;
+    uint8_t player_index;
+    uint16_t unit_index;
+    uint8_t flags;
+} __attribute__((packed));
 
 #define _UNIT_OPCODE_MOVE 1
 
 class MoveOpcode : public UnitOpcode
 {
 public:
-    unsigned long square;
-    signed char   loc_x_offset;
-    signed char   loc_y_offset;
-    unsigned char pad[1];
+    uint32_t square;
+    int8_t loc_x_offset;
+    int8_t loc_y_offset;
+    uint8_t pad[1];
 
     MoveOpcode( )
     {
@@ -70,18 +78,19 @@
         loc_y_offset = 0;
         pad[0] = 0;
     }
-}
-__attribute__((packed));
+} __attribute__((packed));
+
+ASSERT_SIZE(MoveOpcode, 7 + sizeof(UnitOpcode))
 
 #define _UNIT_OPCODE_TURRET_TRACK_POINT 2
 
 class TurretTrackPointOpcode : public UnitOpcode
 {
 public:
-    unsigned short x;
-    unsigned short y;
-    bool  activate;
-    unsigned char pad[2];
+    uint16_t x;
+    uint16_t y;
+    uint8_t  activate;
+    uint8_t pad[2];
 
     TurretTrackPointOpcode( )
     {
@@ -93,19 +102,19 @@
         pad[0] = pad[1] = 0;
     }
 
-}
-__attribute__((packed));
+} __attribute__((packed));
+
+ASSERT_SIZE(TurretTrackPointOpcode, 7 + sizeof(UnitOpcode))
 
 #define _UNIT_OPCODE_TURRET_TRACK_TARGET 3
 
 class TurretTrackTargetOpcode : public UnitOpcode
 {
 public:
-    unsigned char target_player_index;
-    unsigned short target_unit_index;
-    bool activate;
-    unsigned char pad[3];
-
+    uint8_t target_player_index;
+    uint16_t target_unit_index;
+    uint8_t activate;
+    uint8_t pad[3];
 
     TurretTrackTargetOpcode( )
     {
@@ -117,18 +126,18 @@
         activate = false;
         pad[0] = pad[1] = pad[2] = 0;
     }
+} __attribute__((packed));
 
-}
-__attribute__((packed));
+ASSERT_SIZE(TurretTrackTargetOpcode, 7 + sizeof(UnitOpcode))
 
 #define _UNIT_OPCODE_FIRE_WEAPON 4
 
 class FireWeaponOpcode : public UnitOpcode
 {
 public:
-    unsigned short x;
-    unsigned short y;
-    unsigned char pad[3];
+    uint16_t x;
+    uint16_t y;
+    uint8_t pad[3];
 
     FireWeaponOpcode( )
     {
@@ -138,15 +147,16 @@
         x = y = 0;
         pad[0] = pad[1] = pad[2] = 0;
     }
-}
-__attribute__((packed));
+} __attribute__((packed));
+
+ASSERT_SIZE(FireWeaponOpcode, 7 + sizeof(UnitOpcode))
 
 #define _UNIT_OPCODE_SYNC_UNIT 5
 
 class SyncUnitOpcode : public UnitOpcode
 {
 public:
-    unsigned char pad[7];
+    uint8_t pad[7];
 
     SyncUnitOpcode( )
     {
@@ -157,24 +167,26 @@
             pad[i] = 0;
     }
 
-}
-__attribute__((packed));
+} __attribute__((packed));
+
+ASSERT_SIZE(SyncUnitOpcode, 7 + sizeof(UnitOpcode))
 
 #define _UNIT_OPCODE_UPDATE_STATE 6
 
 class UpdateStateUnitOpcode : public UnitOpcode
 {
 public:
-    short hit_points;
-    unsigned char pad[5];
+    int16_t hit_points;
+    uint8_t pad[5];
 
     UpdateStateUnitOpcode( )
     {
         flags = 0;
         opcode = _UNIT_OPCODE_UPDATE_STATE;
     }
-}
-__attribute__((packed));
+} __attribute__((packed));
+
+ASSERT_SIZE(UpdateStateUnitOpcode, 7 + sizeof(UnitOpcode))
 
 #define _UNIT_OPCODE_DESTRUCT 7
 
@@ -188,9 +200,9 @@
         flags = 0;
         opcode = _UNIT_OPCODE_DESTRUCT;
     }
+} __attribute__((packed));
 
-}
-__attribute__((packed));
+ASSERT_SIZE(DestructUnitOpcode, 7 + sizeof(UnitOpcode))
 
 #ifdef MSVC
 #pragma pack()
Index: netpanzer/src/NetPanzer/Classes/UnitState.cpp
diff -u netpanzer/src/NetPanzer/Classes/UnitState.cpp:1.5 
netpanzer/src/NetPanzer/Classes/UnitState.cpp:1.6
--- netpanzer/src/NetPanzer/Classes/UnitState.cpp:1.5   Tue Sep 16 16:16:11 2003
+++ netpanzer/src/NetPanzer/Classes/UnitState.cpp       Mon Dec  1 15:57:59 2003
@@ -58,3 +58,65 @@
 
     return( damage_percentage );
 }
+
+NetworkUnitState UnitState::getNetworkUnitState() const
+{
+    NetworkUnitState state;
+
+    state.unit_type = unit_type;
+    state.location_x = location.x;
+    state.location_y = location.y;
+    state.bbox_min_x = bbox.min.x;
+    state.bbox_min_y = bbox.min.y;
+    state.bbox_max_x = bbox.max.x;
+    state.bbox_max_y = bbox.max.y;
+
+    state.body_angle = body_angle.getNetworkAngleInt();
+    state.turret_angle = turret_angle.getNetworkAngleInt();
+    state.orientation = orientation;
+    state.speed_rate = speed_rate;
+    state.speed_factor = speed_factor;
+    
+    state.reload_time = reload_time;
+    state.max_hit_points = max_hit_points;
+    state.hit_points = hit_points;
+    state.damage_factor = damage_factor;
+    state.weapon_range = weapon_range;
+    state.defend_range = defend_range;
+    
+    state.threat_level = threat_level;
+    state.lifecycle_state = lifecycle_state;
+
+    return state;
+}
+
+void UnitState::setFromNetworkUnitState(const NetworkUnitState& state)
+{
+    select = false;
+
+    unit_type = state.unit_type;
+    location.x = state.location_x;
+    location.y = state.location_y;
+    bbox.min.x = state.bbox_min_x;
+    bbox.min.y = state.bbox_min_y;
+    bbox.max.x = state.bbox_max_x;
+    bbox.max.y = state.bbox_max_y;
+
+    body_angle.setFromNetworkAngleInt(state.body_angle);
+    turret_angle.setFromNetworkAngleInt(state.turret_angle);
+
+    orientation = state.orientation;
+    speed_rate = state.speed_rate;
+    speed_factor = state.speed_factor;
+    
+    reload_time = state.reload_time;
+    max_hit_points = state.max_hit_points;
+    hit_points = state.hit_points;
+    damage_factor = state.damage_factor;
+    weapon_range = state.weapon_range;
+    defend_range = state.defend_range;
+
+    threat_level = state.threat_level;
+    lifecycle_state = state.lifecycle_state;
+}
+
Index: netpanzer/src/NetPanzer/Classes/UnitState.hpp
diff -u netpanzer/src/NetPanzer/Classes/UnitState.hpp:1.9 
netpanzer/src/NetPanzer/Classes/UnitState.hpp:1.10
--- netpanzer/src/NetPanzer/Classes/UnitState.hpp:1.9   Sun Nov 30 18:58:08 2003
+++ netpanzer/src/NetPanzer/Classes/UnitState.hpp       Mon Dec  1 15:57:59 2003
@@ -19,6 +19,8 @@
 #define _UNITSTATE_HPP
 
 #include <string.h>
+#include <stdint.h>
+
 #include "ArrayUtil/BoundBox.hpp"
 #include "Types/Angle.hpp"
 
@@ -29,14 +31,58 @@
        _threat_level_defending
      };
 
-class UnitState
+#ifdef MSVC
+#pragma pack(1)
+#endif
+
+class NetworkUnitState
 {
 public:
-    unsigned long var_flags;
+    NetworkUnitState()
+    { }
+
+private:
+    uint8_t     unit_type;
+
+    int32_t     location_x;
+    int32_t     location_y;
+    int32_t     bbox_min_x;
+    int32_t     bbox_min_y;
+    int32_t     bbox_max_x;
+    int32_t     bbox_max_y;
+    
+    NetworkAngleInt body_angle;
+    NetworkAngleInt turret_angle;
+
+    uint16_t    orientation;
+    uint16_t    speed_rate;
+    uint16_t    speed_factor;
+
+    uint16_t    reload_time;
+    int16_t     max_hit_points;
+    int16_t     hit_points;
+    uint16_t    damage_factor;
+    uint32_t    weapon_range;
+    uint32_t    defend_range;
+
+    uint8_t threat_level;
+    uint8_t lifecycle_state;
+
+    friend class UnitState;
+} __attribute__((packed));
+
+#ifdef MSVC
+#pragma pack()
+#endif
 
+class UnitState
+{
+public:
     unsigned char  unit_type;
 
+    /// true if the unit is currently selected
     bool           select;
+    /// position of the unit
     iXY            location;
     BoundBox       bbox;
 
@@ -66,6 +112,9 @@
 
     int percentDamageInt();
     float percentDamageFloat();
+
+    NetworkUnitState getNetworkUnitState() const;
+    void setFromNetworkUnitState(const NetworkUnitState& state);
 };
 
 #endif
Index: netpanzer/src/NetPanzer/Core/NetworkGlobals.hpp
diff -u netpanzer/src/NetPanzer/Core/NetworkGlobals.hpp:1.7 
netpanzer/src/NetPanzer/Core/NetworkGlobals.hpp:1.8
--- netpanzer/src/NetPanzer/Core/NetworkGlobals.hpp:1.7 Sun Nov 30 18:23:13 2003
+++ netpanzer/src/NetPanzer/Core/NetworkGlobals.hpp     Mon Dec  1 15:57:59 2003
@@ -21,6 +21,6 @@
 #define _NETPANZER_DEFAULT_PORT_TCP            3030
 
 #define _NETPANZER_CODEWORD          "netPanzerTest02"
-#define _NETPANZER_PROTOCOL_VERSION  1014
+#define _NETPANZER_PROTOCOL_VERSION  1015
 
 #endif // ** _NETWORK_GLOBALS_HPP
Index: netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp:1.14 
netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp:1.15
--- netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp:1.14   Sun Nov 30 
18:23:13 2003
+++ netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp        Mon Dec  1 
15:58:00 2003
@@ -951,8 +951,7 @@
     unit_lists[ player_index ].add( (UnitBase *) unit, sync_message->unit_id );
     unit_bucket_array.addUnit( unit );
 
-    unit->unit_state = sync_message->unit_state;
-    unit->unit_state.select = false;
+    unit->unit_state.setFromNetworkUnitState(sync_message->unit_state);
 }
 
 // ******************************************************************
@@ -1111,7 +1110,7 @@
         sync_message.unit_id    = unit->unit_id;
         sync_message.location_x = unit_map_loc.x;
         sync_message.location_y = unit_map_loc.y;
-        sync_message.unit_state = unit->unit_state;
+        sync_message.unit_state = unit->unit_state.getNetworkUnitState();
 
         send_ret_val = SERVER->sendMessage( sync_units_remote_player,
                                             &sync_message, sizeof( 
UnitIniSyncMessage ), 0 );
Index: netpanzer/src/NetPanzer/Views/MainMenu/MainMenuView.cpp
diff -u netpanzer/src/NetPanzer/Views/MainMenu/MainMenuView.cpp:1.11 
netpanzer/src/NetPanzer/Views/MainMenu/MainMenuView.cpp:1.12
--- netpanzer/src/NetPanzer/Views/MainMenu/MainMenuView.cpp:1.11        Mon Oct 
13 10:30:20 2003
+++ netpanzer/src/NetPanzer/Views/MainMenu/MainMenuView.cpp     Mon Dec  1 
15:58:00 2003
@@ -49,8 +49,8 @@
         "Gnu General Public license (GPL). See the COPYING file for details."
         "\n"
         "NetPanzer only supports TCP/IP multiplayer games over "
-        "LAN systems and over the Internet. A Skirmish mode might "
-        "be added later. We're still searching for talented coders "
+        "LAN systems and over the Internet. "
+        "We're still searching for talented coders "
         "and artists. Look at http://www.nongnu.org/netpanzer for details. ";
 
     viewArea.bltStringInBox(bodyTextRect, text, Color::white, 12);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]