netpanzer-cvs
[Top][All Lists]
Advanced

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

[netPanzer-CVS] netpanzer/src Lib/ArrayUtil/BoundBox.cpp Lib/Ar...


From: Matthias Braun
Subject: [netPanzer-CVS] netpanzer/src Lib/ArrayUtil/BoundBox.cpp Lib/Ar...
Date: Mon, 24 Nov 2003 05:18:45 -0500

CVSROOT:        /cvsroot/netpanzer
Module name:    netpanzer
Branch:         
Changes by:     Matthias Braun <address@hidden> 03/11/24 05:18:44

Modified files:
        src/Lib/ArrayUtil: BoundBox.cpp BoundBox.hpp 
        src/NetPanzer/Classes: SelectionList.cpp SelectionList.hpp 
                               UnitID.hpp UnitIDList.hpp UnitState.hpp 
                               WorldInputCmdProcessor.cpp 
        src/NetPanzer/Classes/Network: PowerUpNetMessage.hpp 
        src/NetPanzer/IRCLobby: IRCLobby.cpp 
        src/NetPanzer/Interfaces: PowerUpInterface.cpp UnitInterface.cpp 
                                  UnitInterface.hpp 

Log message:
        -converted the SelectionList to std::vector, also removed limit of 
maximum
        select units while doing this.

Patches:
Index: netpanzer/src/Lib/ArrayUtil/BoundBox.cpp
diff -u netpanzer/src/Lib/ArrayUtil/BoundBox.cpp:1.1 
netpanzer/src/Lib/ArrayUtil/BoundBox.cpp:1.2
--- netpanzer/src/Lib/ArrayUtil/BoundBox.cpp:1.1        Sat Nov 22 10:43:15 2003
+++ netpanzer/src/Lib/ArrayUtil/BoundBox.cpp    Mon Nov 24 05:18:42 2003
@@ -19,7 +19,7 @@
 #include <config.h>
 #include "BoundBox.hpp"
 
-bool BoundBox::bounds( iXY &center, iXY &test )
+bool BoundBox::bounds(const iXY& center, const iXY& test ) const
 {
     iXY new_max( center + max );
     iXY new_min( center + min );
Index: netpanzer/src/Lib/ArrayUtil/BoundBox.hpp
diff -u netpanzer/src/Lib/ArrayUtil/BoundBox.hpp:1.1 
netpanzer/src/Lib/ArrayUtil/BoundBox.hpp:1.2
--- netpanzer/src/Lib/ArrayUtil/BoundBox.hpp:1.1        Sat Nov 22 10:43:15 2003
+++ netpanzer/src/Lib/ArrayUtil/BoundBox.hpp    Mon Nov 24 05:18:43 2003
@@ -25,8 +25,7 @@
 class BoundBox : public iRect
 {
 public:
-
-    BoundBox( void )
+    BoundBox()
     {}
 
     BoundBox(int x1, int y1, int x2, int y2)
@@ -41,17 +40,17 @@
         assert( min.x <= 0 && min.y <= 0 && max.x >= 0 && max.y >= 0 );
     }
 
-    BoundBox(iXY &nMin, iXY &nMax)
+    BoundBox(const iXY& nMin, const iXY& nMax)
             : iRect( nMin, nMax )
     {
         assert( min.x <= 0 && min.y <= 0 && max.x >= 0 && max.y >= 0 );
     }
 
-    bool bounds( iXY &center, iXY &test );
+    bool bounds(const iXY &center, const iXY &test ) const;
 
     void setBounds(const iXY &nMin, const iXY &nMax );
 
-    inline iRect getAbsRect( iXY &center )
+    inline iRect getAbsRect(const iXY& center) const
     {
         return( iRect( center + min, center + max ) );
     }
Index: netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp
diff -u netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp:1.3 
netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp:1.4
--- netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp:1.3   Tue Sep 
16 16:16:11 2003
+++ netpanzer/src/NetPanzer/Classes/Network/PowerUpNetMessage.hpp       Mon Nov 
24 05:18:43 2003
@@ -27,12 +27,16 @@
        _net_message_id_powerup_hit
      };
 
+#ifdef MSVC
+#pragma pack(1)
+#endif
+
 class PowerUpCreateMesg : public NetMessage
 {
 public:
-    iXY map_loc;
-    int      ID;
-    int      type;
+    iXY     map_loc;
+    int32_t ID;
+    int32_t type;
 
     void set( iXY map_loc, int ID, int type )
     {
@@ -47,15 +51,16 @@
         message_id = _net_message_id_powerup_create;
     }
 
-};
+}
+__attribute__((packed));
 
 class PowerUpHitMesg : public NetMessage
 {
 public:
-    int      ID;
+    int32_t  ID;
     UnitID   unit_id;
     PlayerID player_id;
-    int unit_powerup_type;
+    int32_t  unit_powerup_type;
 
     void set( int ID, UnitID unit_id, PlayerID player_id )
     {
@@ -70,7 +75,11 @@
         message_id = _net_message_id_powerup_hit;
     }
 
-};
+}
+__attribute__((packed));
 
+#ifdef MSVC
+#pragma pack()
+#endif
 
 #endif // ** _POWERUP_NET_MESSAGE_HPP
Index: netpanzer/src/NetPanzer/Classes/SelectionList.cpp
diff -u netpanzer/src/NetPanzer/Classes/SelectionList.cpp:1.7 
netpanzer/src/NetPanzer/Classes/SelectionList.cpp:1.8
--- netpanzer/src/NetPanzer/Classes/SelectionList.cpp:1.7       Sat Nov 22 
10:43:24 2003
+++ netpanzer/src/NetPanzer/Classes/SelectionList.cpp   Mon Nov 24 05:18:43 2003
@@ -21,57 +21,20 @@
 #include "PlayerInterface.hpp"
 #include "Util/Log.hpp"
 
-int selectKey( void *key, UnitState *comp )
-{
-    iXY *point;
-
-    point = (iXY *) key;
-
-    if ( comp->bounds( *point ) == true )
-        return( 0 );
-
-    return( -1 );
-}
-
-int boundKey( void *key, UnitState *comp )
-{
-    iRect *bound;
-
-    bound = (iRect *) key;
-
-    if ( bound->contains( comp->location ) == true )
-        return( 0 );
-
-    return( 1 );
-}
-
-void SelectionList::initialize( unsigned long size,
-                                unsigned long growIncrement,
-                                unsigned long growLimit )
-{
-    unit_list.initialize( size, growIncrement, growLimit );
-}
-
-
 bool SelectionList::selectUnit( iXY point )
 {
     PlayerID player_id;
 
     deselect();
-    unit_list.removeAll();
+    unit_list.clear();
 
-    player_id = PlayerInterface::getLocalPlayerID( );
+    player_id = PlayerInterface::getLocalPlayerID();
 
-    UnitInterface::quearyUnitsKeySearch( &unit_list,
-                                         selectKey,
-                                         (void *) &point,
-                                         player_id,
-                                         _search_player,
-                                         false
-                                       );
+    UnitInterface::queryUnitsAt(unit_list, point, player_id, _search_player,
+            false);
 
     select();
-    if ( unit_list.containsItems() > 0 ) {
+    if (unit_list.size() > 0) {
         resetUnitCycling();
         return ( true );
     }
@@ -87,16 +50,11 @@
 
     player_id = PlayerInterface::getLocalPlayerID( );
 
-    UnitInterface::quearyUnitsKeySearch( &unit_list,
-                                         selectKey,
-                                         (void *) &point,
-                                         player_id,
-                                         _search_player,
-                                         false
-                                       );
+    UnitInterface::queryUnitsAt(unit_list, point, player_id,
+            _search_player, false);
 
     select();
-    if ( unit_list.containsItems() > 0 ) {
+    if ( unit_list.size() > 0 ) {
         resetUnitCycling();
         return ( true );
     }
@@ -110,19 +68,14 @@
     PlayerID player_id;
 
     deselect();
-    unit_list.removeAll();
+    unit_list.clear();
 
     player_id = PlayerInterface::getLocalPlayerID( );
 
-    UnitInterface::quearyUnitsKeySearch( &unit_list,
-                                         selectKey,
-                                         (void *) &point,
-                                         player_id,
-                                         _search_exclude_player,
-                                         false
-                                       );
+    UnitInterface::queryUnitsAt(unit_list, point, player_id,
+            _search_exclude_player, false);
 
-    if ( unit_list.containsItems() > 0 ) {
+    if ( unit_list.size() > 0 ) {
         resetUnitCycling();
         return ( true );
     }
@@ -139,29 +92,20 @@
 
     player_id = PlayerInterface::getLocalPlayerID( );
 
-    found_units = UnitInterface::quearyUnitsKeySearch( &unit_list,
-                  boundKey,
-                  (void *) &bounds,
-                  player_id,
-                  _search_player,
-                  true
-                                                     );
+    found_units = UnitInterface::queryUnitsAt(unit_list, bounds,
+            player_id, _search_player, true);
+
     if ( found_units == false )
         return( false );
 
     deselect();
-    unit_list.removeAll();
+    unit_list.clear();
 
-    UnitInterface::quearyUnitsKeySearch( &unit_list,
-                                         boundKey,
-                                         (void *) &bounds,
-                                         player_id,
-                                         _search_player,
-                                         false
-                                       );
+    UnitInterface::queryUnitsAt(unit_list, bounds,
+            player_id, _search_player, false);
 
     select();
-    if ( unit_list.containsItems() > 0 ) {
+    if ( unit_list.size() > 0 ) {
         resetUnitCycling();
         return ( true );
     }
@@ -176,7 +120,7 @@
     unsigned long id_list_size;
     UnitBase *unit;
 
-    id_list_size = unit_list.containsItems();
+    id_list_size = unit_list.size();
 
     for( id_list_index = 0; id_list_index < id_list_size; id_list_index++ ) {
         unit = UnitInterface::getUnit( unit_list[ id_list_index ] );
@@ -194,7 +138,7 @@
     unsigned long id_list_size;
     UnitBase *unit;
 
-    id_list_size = unit_list.containsItems();
+    id_list_size = unit_list.size();
 
     for( id_list_index = 0; id_list_index < id_list_size; id_list_index++ ) {
         unit = UnitInterface::getUnit( unit_list[ id_list_index ] );
@@ -211,7 +155,7 @@
 
     start_index = unit_cycle_index;
 
-    if ( unit_list.contains == 0 )
+    if ( unit_list.size() == 0 )
         return;
 
     deselect();
@@ -222,7 +166,7 @@
             unit->unit_state.select = true;
         }
 
-        unit_cycle_index = (unit_cycle_index + 1) % unit_list.contains;
+        unit_cycle_index = (unit_cycle_index + 1) % unit_list.size();
 
     } while( (unit == 0) && (unit_cycle_index != start_index) );
 
@@ -242,10 +186,10 @@
     unsigned long list_index;
     unsigned long list_size;
 
-    list_size=source_list.unit_list.contains;
+    list_size=source_list.unit_list.size();
 
     for ( list_index = 0; list_index < list_size; list_index++ ) {
-        unit_list.add( source_list.unit_list[ list_index ], unit_list.contains 
);
+        unit_list.push_back(source_list.unit_list[ list_index ]);
     }
 
     unit_cycle_index = source_list.unit_cycle_index;
@@ -259,7 +203,7 @@
 {
     UnitBase *unit;
 
-    if ( unit_list.containsItems() > 0 ) {
+    if ( unit_list.size() > 0 ) {
         unit = UnitInterface::getUnit( unit_list[ 0 ] );
         if( unit != 0 ) {
             return( unit->unit_state.unit_type );
@@ -277,7 +221,7 @@
     unsigned long id_list_size;
     UnitBase *unit;
 
-    id_list_size = unit_list.containsItems();
+    id_list_size = unit_list.size();
 
     if( id_list_size == 0) {
         return;
@@ -290,5 +234,5 @@
         }
     }
 
-    unit_list.removeAll();
+    unit_list.clear();
 }
Index: netpanzer/src/NetPanzer/Classes/SelectionList.hpp
diff -u netpanzer/src/NetPanzer/Classes/SelectionList.hpp:1.6 
netpanzer/src/NetPanzer/Classes/SelectionList.hpp:1.7
--- netpanzer/src/NetPanzer/Classes/SelectionList.hpp:1.6       Wed Nov 12 
03:28:31 2003
+++ netpanzer/src/NetPanzer/Classes/SelectionList.hpp   Mon Nov 24 05:18:43 2003
@@ -18,7 +18,6 @@
 #ifndef _SELECTIONLIST_HPP
 #define _SELECTIONLIST_HPP
 
-#include "UnitList.hpp"
 #include "UnitState.hpp"
 #include "UnitInterface.hpp"
 #include "UnitIDList.hpp"
@@ -29,14 +28,12 @@
     unsigned long unit_cycle_index;
 
 public:
-    UnitIDList unit_list;
+    std::vector<UnitID> unit_list;
 
     SelectionList( )
+        : unit_cycle_index(0)
     { }
 
-    void initialize( unsigned long size, unsigned long growIncrement,
-                     unsigned long growLimit );
-
     bool selectUnit( iXY point );
 
     bool addUnit( iXY point );
@@ -45,37 +42,34 @@
 
     bool selectBounded( iRect bounds );
 
-    inline bool isSelected( void )
+    bool isSelected()
     {
-        if ( unit_list.containsItems() > 0 )
-            return( true );
-
-        return( false );
+        return unit_list.size() > 0;
     }
 
-    void select( void );
+    void select();
 
-    void deselect( void );
+    void deselect();
 
-    inline void unGroup( void )
+    void unGroup()
     {
         deselect( );
-        unit_list.removeAll();
+        unit_list.clear();
     }
 
-    unsigned short getHeadUnitType( void );
+    unsigned short getHeadUnitType();
 
-    inline void resetUnitCycling( void )
+    inline void resetUnitCycling()
     {
         unit_cycle_index = 0;
     }
 
-    void cycleNextUnit( void );
+    void cycleNextUnit();
 
     void copyList( SelectionList &source_list );
     void addList( SelectionList &source_list );
 
-    void validateList( void );
+    void validateList();
 
 };
 
Index: netpanzer/src/NetPanzer/Classes/UnitID.hpp
diff -u netpanzer/src/NetPanzer/Classes/UnitID.hpp:1.6 
netpanzer/src/NetPanzer/Classes/UnitID.hpp:1.7
--- netpanzer/src/NetPanzer/Classes/UnitID.hpp:1.6      Thu Nov 20 19:19:24 2003
+++ netpanzer/src/NetPanzer/Classes/UnitID.hpp  Mon Nov 24 05:18:43 2003
@@ -18,41 +18,43 @@
 #ifndef _UNITID_HPP
 #define _UNITID_HPP
 
+#include <stdint.h>
+
 class UnitID
 {
 public:
-    unsigned char player;
-    unsigned short index;
-    unsigned short unique;
+    uint8_t player;
+    uint16_t index;
+    uint16_t unique;
 
     UnitID()
         : player(0xff), index(0xffff), unique(0xffff)
     { }
 
-    inline void set(unsigned char player, unsigned short index, unsigned short 
unique )
+    void set(uint8_t player, uint16_t index, uint16_t unique )
     {
         UnitID::player = player;
         UnitID::index = index;
         UnitID::unique = unique;
     }
 
-    inline void set( unsigned char player, unsigned short index )
+    void set( uint8_t player, uint16_t index )
     {
         UnitID::player = player;
         UnitID::index = index;
     }
 
-    inline unsigned char getPlayer() const
+    uint8_t getPlayer() const
     {
-        return( player );
+        return player;
     }
 
-    inline unsigned short getIndex() const
+    uint16_t getIndex() const
     {
-        return( index );
+        return index;
     }
 
-    inline bool operator==( const UnitID& Uid ) const
+    bool operator==( const UnitID& Uid ) const
     {
         if ( (player == Uid.player) && (index == Uid.index)
                 && (unique == Uid.unique)
@@ -62,7 +64,7 @@
         return false;
     }
 
-    inline bool operator!=( const UnitID& Uid ) const
+    bool operator!=( const UnitID& Uid ) const
     {
         if ( (player != Uid.player) || (index != Uid.index)
                 || (unique != Uid.unique)
@@ -72,7 +74,7 @@
         return false;
     }
 
-    inline bool operator<( const UnitID& Uid ) const
+    bool operator<( const UnitID& Uid ) const
     {
         return (player < Uid.player
                 || (player == Uid.player && index < Uid.index)
@@ -80,7 +82,7 @@
                     && unique < Uid.unique));
     }
 
-    inline bool playerEqual( const UnitID& Uid ) const
+    bool playerEqual( const UnitID& Uid ) const
     {
         if ( (player == Uid.player) )
             return true;
@@ -88,7 +90,7 @@
         return false;
     }
 
-    inline void operator=( const UnitID& Uid )
+    void operator=( const UnitID& Uid )
     {
         player = Uid.player;
         index  = Uid.index;
Index: netpanzer/src/NetPanzer/Classes/UnitIDList.hpp
diff -u netpanzer/src/NetPanzer/Classes/UnitIDList.hpp:1.3 
netpanzer/src/NetPanzer/Classes/UnitIDList.hpp:1.4
--- netpanzer/src/NetPanzer/Classes/UnitIDList.hpp:1.3  Sat Nov 22 10:43:25 2003
+++ netpanzer/src/NetPanzer/Classes/UnitIDList.hpp      Mon Nov 24 05:18:43 2003
@@ -18,42 +18,14 @@
 #ifndef _UNITIDLIST_HPP
 #define _UNITIDLIST_HPP
 
-#include "UnitID.hpp"
-#include "ArrayUtil/ArrayGrowableTemplate.hpp"
+#include <vector>
 
-typedef ArrayGrowableTemplate< UnitID > UnitIDListTemplate;
+#include "UnitID.hpp"
+#include "Util/NoCopy.hpp"
 
-class UnitIDList : public UnitIDListTemplate
+class UnitIDList : public std::vector<UnitID>, public NoCopy
 {
 public:
-    unsigned long contains;
-
-    UnitIDList() : UnitIDListTemplate()
-    {
-        contains = 0;
-    }
-
-    void initialize( unsigned long size, unsigned long growIncrement, unsigned 
long growLimit )
-    {
-        UnitIDListTemplate::initialize( size, growIncrement, growLimit );
-    }
-
-    inline void add( UnitID object, unsigned long index )
-    {
-        UnitIDListTemplate::add( object, index );
-        if ( contains < size )
-            contains++;
-    }
-
-    inline void removeAll( void )
-    {
-        contains = 0;
-    }
-
-    inline unsigned long containsItems( void )
-    {
-        return( contains );
-    }
 };
 
 #endif // ** _UNITIDLIST_HPP
Index: netpanzer/src/NetPanzer/Classes/UnitState.hpp
diff -u netpanzer/src/NetPanzer/Classes/UnitState.hpp:1.7 
netpanzer/src/NetPanzer/Classes/UnitState.hpp:1.8
--- netpanzer/src/NetPanzer/Classes/UnitState.hpp:1.7   Sat Nov 22 10:43:25 2003
+++ netpanzer/src/NetPanzer/Classes/UnitState.hpp       Mon Nov 24 05:18:43 2003
@@ -62,20 +62,14 @@
 
     UnitState( );
 
-    inline bool bounds( iXY &loc )
+    bool bounds(const iXY& loc) const
     {
         return( bbox.bounds( location, loc ) );
     }
 
-    inline void operator=( UnitState &unit_state )
-    {
-        memmove( this, &unit_state, sizeof( UnitState ) );
-    }
-
-    int percentDamageInt( void );
-    float percentDamageFloat( void );
-
+    int percentDamageInt();
+    float percentDamageFloat();
 };
 
-
 #endif
+
Index: netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp
diff -u netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp:1.31 
netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp:1.32
--- netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp:1.31     Sun Nov 
23 19:09:48 2003
+++ netpanzer/src/NetPanzer/Classes/WorldInputCmdProcessor.cpp  Mon Nov 24 
05:18:43 2003
@@ -86,16 +86,9 @@
     right_mouse_scroll = false;
 }
 
-void WorldInputCmdProcessor::initializeSelectionLists( void )
+void WorldInputCmdProcessor::initializeSelectionLists()
 {
-    unsigned long list_index;
-
-    for( list_index = 0; list_index < 10; list_index++ ) {
-        selection_group_lists[ list_index ].initialize( 20, 10, 40 );
-    } // ** for
-
-    target_list.initialize( 20, 10, 40 );
-    working_list.initialize( 20, 10, 40 );
+    /* empty */
 }
 
 void WorldInputCmdProcessor::switchSelectionList( unsigned long new_list_index 
)
@@ -761,7 +754,7 @@
 
                     current_selection_list_bits=0;
                     current_selection_list_index = 0xFFFF;
-                    if ( working_list.unit_list.containsItems() > 0 ) {
+                    if (working_list.unit_list.size() > 0) {
                         UnitBase *unit = 
UnitInterface::getUnit(working_list.unit_list[0]);
                         unit->soundSelected();
                     }
@@ -847,14 +840,14 @@
     PlacementMatrix matrix;
 
     unsigned long id_list_index;
-    unsigned long id_list_size;
+    size_t id_list_size;
     UnitBase *unit_ptr;
 
     TerminalUnitCmdRequest comm_mesg;
     MultiMessage *encode_message;
 
 
-    id_list_size = working_list.unit_list.containsItems();
+    id_list_size = working_list.unit_list.size();
 
     if ( id_list_size == 0 )
         return;
@@ -865,7 +858,7 @@
     PUBLIC_MESSAGE_ENCODER.resetEncoder();
 
     for( id_list_index = 0; id_list_index < id_list_size; id_list_index++ ) {
-        unit_ptr = UnitInterface::getUnit( working_list.unit_list[ 
id_list_index ] );
+        unit_ptr = UnitInterface::getUnit(working_list.unit_list[ 
id_list_index ]);
         if ( unit_ptr != 0 ) {
             if ( unit_ptr->unit_state.select == true ) {
                 matrix.getNextEmptyLoc( &map_pos );
@@ -899,8 +892,8 @@
 
     UnitBase *target_ptr;
 
-    unsigned long id_list_index;
-    unsigned long id_list_size;
+    size_t id_list_index;
+    size_t id_list_size;
     UnitBase *unit_ptr;
 
     if ( working_list.isSelected() == true ) {
@@ -908,7 +901,7 @@
 
         target_ptr = UnitInterface::getUnit( target_list.unit_list[0] );
 
-        id_list_size = working_list.unit_list.containsItems();
+        id_list_size = working_list.unit_list.size();
 
         if ( id_list_size == 0 )
             return;
@@ -946,12 +939,12 @@
         bool start_stop )
 {
     TerminalUnitCmdRequest comm_mesg;
-    unsigned long id_list_index;
-    unsigned long id_list_size;
+    size_t id_list_index;
+    size_t id_list_size;
     UnitBase *unit_ptr;
 
-    if ( working_list.unit_list.containsItems() > 0 ) {
-        id_list_size = working_list.unit_list.containsItems();
+    if ( working_list.unit_list.size() > 0 ) {
+        id_list_size = working_list.unit_list.size();
 
         PUBLIC_MESSAGE_ENCODER.resetEncoder();
 
@@ -985,12 +978,12 @@
     TerminalUnitCmdRequest comm_mesg;
     MultiMessage *encode_message;
 
-    unsigned long id_list_index;
-    unsigned long id_list_size;
+    size_t id_list_index;
+    size_t id_list_size;
     UnitBase *unit_ptr;
 
-    if ( working_list.unit_list.containsItems() > 0 ) {
-        id_list_size = working_list.unit_list.containsItems();
+    if ( working_list.unit_list.size() > 0 ) {
+        id_list_size = working_list.unit_list.size();
 
         PUBLIC_MESSAGE_ENCODER.resetEncoder();
 
@@ -1157,13 +1150,9 @@
 }
 
 
-bool WorldInputCmdProcessor::isUnitSelected( void )
+bool WorldInputCmdProcessor::isUnitSelected()
 {
-    if( working_list.unit_list.containsItems() > 0 ) {
-        return( true );
-    } else {
-        return( false );
-    }
+    return working_list.unit_list.size() > 0;
 }
 
 bool WorldInputCmdProcessor::selectUnits( iRect bound_box )
Index: netpanzer/src/NetPanzer/IRCLobby/IRCLobby.cpp
diff -u netpanzer/src/NetPanzer/IRCLobby/IRCLobby.cpp:1.4 
netpanzer/src/NetPanzer/IRCLobby/IRCLobby.cpp:1.5
--- netpanzer/src/NetPanzer/IRCLobby/IRCLobby.cpp:1.4   Sun Nov 23 19:53:25 2003
+++ netpanzer/src/NetPanzer/IRCLobby/IRCLobby.cpp       Mon Nov 24 05:18:44 2003
@@ -619,14 +619,10 @@
     *buf_upto=0;
 }
 
-
-
 void IRCLobby::sendServerRunningMess(const std::string& dest,const 
std::string& str)
 {
         std::stringstream buffer;
         buffer << "-" << server_running_mess << " " << str;
         return sendIRCMessageLine(buffer.str(), dest);
 }
-
-
 
Index: netpanzer/src/NetPanzer/Interfaces/PowerUpInterface.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/PowerUpInterface.cpp:1.13 
netpanzer/src/NetPanzer/Interfaces/PowerUpInterface.cpp:1.14
--- netpanzer/src/NetPanzer/Interfaces/PowerUpInterface.cpp:1.13        Sat Nov 
22 10:43:38 2003
+++ netpanzer/src/NetPanzer/Interfaces/PowerUpInterface.cpp     Mon Nov 24 
05:18:44 2003
@@ -211,18 +211,17 @@
     }
 
     for (PowerUpList::iterator i = powerup_list.begin();
-            i != powerup_list.end(); i++)
+            i != powerup_list.end(); /* empty */)
     {
-        PowerUpList::iterator cur = i;
-        PowerUp* powerup = *cur;
+        PowerUp* powerup = *i;
 
         if(powerup->powerup_state.life_cycle_state ==
                 _power_up_lifecycle_state_inactive) {
             delete powerup;
-            --i;
-            powerup_list.erase(cur);
+            i = powerup_list.erase(i);
         } else {
             powerup->updateState();
+            i++;
         }
     }
  }
Index: netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp
diff -u netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp:1.12 
netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp:1.13
--- netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp:1.12   Sat Nov 22 
10:43:38 2003
+++ netpanzer/src/NetPanzer/Interfaces/UnitInterface.cpp        Mon Nov 24 
05:18:44 2003
@@ -34,6 +34,7 @@
 #include "M109.hpp"
 #include "Archer.hpp"
 
+#include "Types/iXY.hpp"
 #include "ArrayUtil/Timer.hpp"
 #include "Server.hpp"
 #include "NetworkState.hpp"
@@ -518,19 +519,13 @@
 
 // ******************************************************************
 
-bool UnitInterface::
-quearyUnitsKeySearch( UnitIDList *working_list,
-                      int (* key_func )( void *key, UnitState *comp ),
-                      void *key, PlayerID player_id,
-                      unsigned char search_flags,
-                      bool find_first  )
+bool UnitInterface::queryUnitsAt(std::vector<UnitID>& working_list,
+                      const iXY& point, PlayerID player_id,
+                      unsigned char search_flags, bool find_first  )
 {
     UnitPointer *unit_ptr;
     UnitPointer *iterator;
-    unsigned long list_index;
-    unsigned long work_index;
-
-    work_index = working_list->containsItems();
+    size_t list_index;
 
     for( list_index = 0; list_index < max_players; list_index++) {
         if (   ( (search_flags == _search_exclude_player) && 
(player_id.getIndex() != list_index) )
@@ -541,14 +536,13 @@
 
             unit_ptr = unit_lists[ list_index ].incIteratorPtr( &iterator );
             while( unit_ptr != 0 ) {
-                if ( key_func( key, &(unit_ptr->unit->unit_state) ) == 0 ) {
-                    if ( find_first == true )
-                        return( true );
-
-                    working_list->add( unit_ptr->unit->unit_id, work_index );
-                    work_index++;
-                } // ** if key_func
+                if(unit_ptr->unit->unit_state.bounds(point)) {
+                    if(find_first)
+                        return true;
 
+                    working_list.push_back(unit_ptr->unit->unit_id);
+                }
+                
                 unit_ptr = unit_lists[ list_index ].incIteratorPtr( &iterator 
);
             } // ** while
 
@@ -556,13 +550,52 @@
 
     } // ** for
 
-    if( (find_first == false) && (work_index > 0) )
-        return( true );
+    if( (find_first == false) && (working_list.size() > 0) )
+        return true;
 
-    return( false );
+    return false;
 } // ** quearyUnitsKeySearch
 
 // ******************************************************************
+
+bool UnitInterface::queryUnitsAt(std::vector<UnitID>& working_list,
+                      const iRect& rect, PlayerID player_id,
+                      unsigned char search_flags, bool find_first  )
+{
+    UnitPointer *unit_ptr;
+    UnitPointer *iterator;
+    size_t list_index;
+
+    for( list_index = 0; list_index < max_players; list_index++) {
+        if (   ( (search_flags == _search_exclude_player) && 
(player_id.getIndex() != list_index) )
+                || ( (search_flags == _search_player) && (player_id.getIndex() 
== list_index ) )
+           ) {
+
+            unit_lists[ list_index ].resetIterator( &iterator );
+
+            unit_ptr = unit_lists[ list_index ].incIteratorPtr( &iterator );
+            while( unit_ptr != 0 ) {
+                if(rect.contains(unit_ptr->unit->unit_state.location)) {
+                    if(find_first)
+                        return true;
+
+                    working_list.push_back(unit_ptr->unit->unit_id);
+                }
+                
+                unit_ptr = unit_lists[ list_index ].incIteratorPtr( &iterator 
);
+            } // ** while
+
+        } // ** if search flags
+
+    } // ** for
+
+    if( (find_first == false) && (working_list.size() > 0) )
+        return true;
+
+    return false;
+} // ** quearyUnitsKeySearch
+
+/****************************************************************************/
 
 bool UnitInterface::quearyClosestUnit( UnitBase **closest_unit_ptr,
                                        iXY &loc,
Index: netpanzer/src/NetPanzer/Interfaces/UnitInterface.hpp
diff -u netpanzer/src/NetPanzer/Interfaces/UnitInterface.hpp:1.7 
netpanzer/src/NetPanzer/Interfaces/UnitInterface.hpp:1.8
--- netpanzer/src/NetPanzer/Interfaces/UnitInterface.hpp:1.7    Sat Nov 22 
10:43:38 2003
+++ netpanzer/src/NetPanzer/Interfaces/UnitInterface.hpp        Mon Nov 24 
05:18:44 2003
@@ -47,7 +47,7 @@
 
     static unsigned short unique_generator;
     static bool isUniqueIndex( unsigned short new_index );
-    static unsigned short uniqueIndex( void );
+    static unsigned short uniqueIndex();
 
 
     static UnitBase * newUnit( unsigned short unit_type,
@@ -59,41 +59,41 @@
     static void deleteUnit( UnitID unit_id );
     static void deleteUnit( UnitBase *unit );
 
-    static void sortBucketArray( void );
+    static void sortBucketArray();
 
 public:
 
     static void initialize( unsigned long max_units );
-    static void cleanUp( void );
-    static void reset( void );
+    static void cleanUp();
+    static void reset();
 
-    static inline UnitList * getUnitList( unsigned long player )
+    static UnitList * getUnitList( unsigned long player )
     {
         assert( (player < max_players) );
         return ( &unit_lists[ player ] );
     }
 
-    static inline UnitList * getUnitList( const UnitID &unit_id )
+    static UnitList * getUnitList( const UnitID &unit_id )
     {
         assert( (unit_id.getPlayer() < max_players) );
         return ( &unit_lists[ unit_id.getPlayer() ] );
     }
 
-    static inline unsigned long getUnitCount( unsigned short player_index )
+    static unsigned long getUnitCount( unsigned short player_index )
     {
         assert( (player_index < max_players) );
         return( unit_lists[ player_index ].containsItems() );
     }
 
-    static unsigned long getTotalUnitCount( void );
+    static unsigned long getTotalUnitCount();
 
-    static inline UnitPointer * getUnitPointer( const UnitID &unit_id )
+    static UnitPointer * getUnitPointer( const UnitID &unit_id )
     {
         assert( (unit_id.getPlayer() < max_players) );
         return( unit_lists[ unit_id.getPlayer() ][ unit_id.getIndex() ] );
     }
 
-    static inline UnitBase * getUnit( const UnitID &unit_id )
+    static UnitBase * getUnit( const UnitID &unit_id )
     {
         UnitPointer *unit_pointer;
         assert ( (unit_id.getPlayer() < max_players) );
@@ -107,7 +107,7 @@
         return( 0 );
     }
 
-    static inline UnitBase * getUnit( unsigned char  player_index,
+    static UnitBase * getUnit( unsigned char  player_index,
                                       unsigned short unit_index    )
     {
         UnitPointer *unit_pointer;
@@ -122,7 +122,7 @@
         return( 0 );
     }
 
-    static inline bool isValid( const UnitID &unit_id )
+    static bool isValid( const UnitID &unit_id )
     {
         assert( unit_id.getPlayer() < max_players );
         return( unit_lists[ unit_id.getPlayer() ].isValid( unit_id ) );
@@ -130,7 +130,7 @@
 
     static void sendMessage( UnitMessage *message );
 
-    static void updateUnitStatus( void );
+    static void updateUnitStatus();
 
     static void offloadGraphics( SpriteSorter &sorter );
 
@@ -142,11 +142,13 @@
                                   const PlayerID &player,
                                   const PlayerUnitConfig &unit_config );
 
-    static bool quearyUnitsKeySearch( UnitIDList *working_list,
-                                      int (* key_func )( void *key, UnitState 
*comp ),
-                                      void *key, PlayerID player_id,
-                                      unsigned char search_flags,
-                                      bool find_first );
+    static bool queryUnitsAt(std::vector<UnitID>& working_list,
+                             const iXY& point, PlayerID player_id,
+                             unsigned char search_flags, bool find_first);
+
+    static bool queryUnitsAt(std::vector<UnitID>& working_list,
+                            const iRect& rect, PlayerID player_id,
+                            unsigned char search_flags, bool find_first);
 
     static bool quearyClosestUnit( UnitBase **closest_unit_ptr,
                                    iXY &loc,
@@ -175,7 +177,7 @@
     static unsigned long  unit_cycle_iterator;
 public:
     // Unit positions, almost exclusivly for mini map
-    static void startUnitPositionEnumeration( void );
+    static void startUnitPositionEnumeration();
     static bool unitPositionEnumeration( unsigned char *unit_disposition, 
UnitState **state );
 
     static void resetUnitCycleIterator( unsigned long *iterator );
@@ -194,12 +196,12 @@
     static UnitOpcodeEncoder no_guarantee_opcode_encoder;
 
     // Network Message Handler Methods
-    static inline void sendOpcode( UnitOpcode *opcode )
+    static void sendOpcode( UnitOpcode *opcode )
     {
         opcode_encoder.encodeOpcode( opcode );
     }
 
-    static inline void sendOpcodeNG( UnitOpcode *opcode )
+    static void sendOpcodeNG( UnitOpcode *opcode )
     {
         no_guarantee_opcode_encoder.encodeOpcode( opcode );
     }
@@ -227,7 +229,6 @@
 public:
     static void processNetMessage( NetMessage *net_message );
     static void destroyPlayerUnits( PlayerID &player_id );
-
-
 };
+
 #endif // ** _UNITINTERFACE_HPP




reply via email to

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