netpanzer-cvs
[Top][All Lists]
Advanced

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

[netPanzer-CVS] netpanzer/src Lib/ArrayUtil/ArrayGrowableTempla...


From: Matthias Braun
Subject: [netPanzer-CVS] netpanzer/src Lib/ArrayUtil/ArrayGrowableTempla...
Date: Mon, 01 Dec 2003 19:22:10 -0500

CVSROOT:        /cvsroot/netpanzer
Module name:    netpanzer
Branch:         
Changes by:     Matthias Braun <address@hidden> 03/12/01 19:22:10

Modified files:
        src/Lib/ArrayUtil: ArrayGrowableTemplate.hpp ArrayTemplate.hpp 
                           BitArray.hpp QueueTemplate.hpp 
        src/Lib/System/SDL: SDLSound.cpp 
        src/NetPanzer/Views/Game: HelpScrollView.cpp 

Log message:
        did some robustness fixes on the array classes

Patches:
Index: netpanzer/src/Lib/ArrayUtil/ArrayGrowableTemplate.hpp
diff -u netpanzer/src/Lib/ArrayUtil/ArrayGrowableTemplate.hpp:1.1 
netpanzer/src/Lib/ArrayUtil/ArrayGrowableTemplate.hpp:1.2
--- netpanzer/src/Lib/ArrayUtil/ArrayGrowableTemplate.hpp:1.1   Sat Nov 22 
10:43:14 2003
+++ netpanzer/src/Lib/ArrayUtil/ArrayGrowableTemplate.hpp       Mon Dec  1 
19:22:10 2003
@@ -26,26 +26,16 @@
 class ArrayGrowableTemplate : public NoCopy
 {
 protected:
-    unsigned long size;
-    unsigned long grow_increment;
-    unsigned long grow_limit;
-    TYPE *array;
+    std::vector<TYPE> elems;
 
 public:
-
     ArrayGrowableTemplate();
 
-    ArrayGrowableTemplate( unsigned long size, unsigned long growIncrement,
-                           unsigned long growLimit );
-
-    ArrayGrowableTemplate( unsigned long size, unsigned long growIncrement );
-
     ArrayGrowableTemplate( unsigned long size );
 
     ~ArrayGrowableTemplate( void );
 
-    void initialize( unsigned long size, unsigned long growIncrement,
-                     unsigned long growLimit );
+    void initialize( unsigned long size );
 
     TYPE & operator[]( unsigned long index);
 
@@ -53,16 +43,12 @@
 
     void resize( unsigned long size );
 
-    void setGrowLimit( unsigned long limit );
-
-    void setGrowIncrement( unsigned long growIncrement );
-
-    inline unsigned long getSize( void ) const
+    unsigned long getSize( void ) const
     {
         return( size );
     }
 
-    inline void deallocate( void )
+    void deallocate( void )
     {
         if ( array != 0 ) {
             free( array );
@@ -77,122 +63,51 @@
 template< class TYPE >
 ArrayGrowableTemplate< TYPE >::ArrayGrowableTemplate()
 {
-    array = 0;
-    size = 0;
-    grow_increment = 1;
-    grow_limit = 0xFFFFFFFF;
 }
 
 template< class TYPE >
 ArrayGrowableTemplate< TYPE >::
-ArrayGrowableTemplate( unsigned long size, unsigned long growIncrement,
-                       unsigned long growLimit )
-        : array(0)
-{
-    initialize( size , growIncrement, growLimit );
-}
-
-
-template< class TYPE >
-ArrayGrowableTemplate< TYPE >::
-ArrayGrowableTemplate( unsigned long size, unsigned long growIncrement )
-        : array(0)
-{
-    initialize( size , growIncrement, 0xFFFFFFFF );
-}
-
-
-template< class TYPE >
-ArrayGrowableTemplate< TYPE >::
-ArrayGrowableTemplate( unsigned long size )
-        : array(0)
+ArrayGrowableTemplate(unsigned long size)
 {
-    initialize( size , 1, 0xFFFFFFFF );
+    elems.resize(size);
 }
 
 template< class TYPE >
 void ArrayGrowableTemplate< TYPE >::
-initialize( unsigned long size, unsigned long growIncrement,
-            unsigned long growLimit )
+initialize(unsigned long size)
 {
-    ArrayGrowableTemplate< TYPE >::size = size;
-
-    grow_increment = growIncrement;
-
-    grow_limit = growLimit;
-
-    assert( (size > 0) && (growIncrement > 0) );
-
-    if ( array != 0 ) {
-        free( array );
-        array = 0;
-    }
-
-    array = (TYPE *) malloc( sizeof(TYPE) * size );
-
-    assert( array != 0 );
+    elems.resize(size);
 }
 
 template< class TYPE >
-ArrayGrowableTemplate< TYPE >::~ArrayGrowableTemplate( void )
+ArrayGrowableTemplate< TYPE >::~ArrayGrowableTemplate()
 {
-    free( array );
 }
 
 template< class TYPE >
 TYPE & ArrayGrowableTemplate< TYPE >::operator[]( unsigned long index)
 {
-    if ( index >= size ) {
-        unsigned long new_size;
-        new_size = (index + 1 + grow_increment);
-        if ( new_size <= grow_limit ) {
-            array = (TYPE *) realloc( array, sizeof(TYPE) * new_size );
-            memset( &array[ size ], 0, sizeof(TYPE) * (new_size - size) );
-            size = new_size;
-            assert( array != 0 );
-        } else
-            assert( 0 );
+    if(index >= elems.size()) {
+        elems.resize(index);
     }
-
-    return( array[index] );
+    
+    return elems.at(index);
 }
 
 template< class TYPE >
 void ArrayGrowableTemplate< TYPE >::add( TYPE object, unsigned long index )
 {
-    if ( index >= size ) {
-        unsigned long new_size;
-        new_size = (index + 1 + grow_increment);
-        if ( new_size <= grow_limit ) {
-            array = (TYPE *) realloc( array, sizeof(TYPE) * new_size );
-            memset( &array[ size ], 0, sizeof(TYPE) * (new_size - size) );
-            size = new_size;
-            assert( array != 0 );
-        } else
-            return;
+    if(index >= elems.size()) {
+        elems.resize(index);
     }
 
-    memmove( (void *) &array[index], (void *) &object , sizeof( TYPE ) );
+    elems[index] = object;
 }
 
 template< class TYPE >
-void ArrayGrowableTemplate< TYPE >::resize( unsigned long size )
+void ArrayGrowableTemplate< TYPE >::resize(unsigned long size)
 {
-    array = (TYPE *) realloc( array, sizeof(TYPE) * size );
-    assert( array != 0 );
+    elems.resize(size);
 }
-
-template< class TYPE >
-void ArrayGrowableTemplate< TYPE >::setGrowLimit( unsigned long limit )
-{
-    grow_limit = limit;
-}
-
-template< class TYPE >
-void ArrayGrowableTemplate< TYPE >::setGrowIncrement( unsigned long 
growIncrement )
-{
-    grow_increment = growIncrement;
-}
-
 
 #endif // ** _ARRAYGROWABLETEMPLATE_HPP
Index: netpanzer/src/Lib/ArrayUtil/ArrayTemplate.hpp
diff -u netpanzer/src/Lib/ArrayUtil/ArrayTemplate.hpp:1.1 
netpanzer/src/Lib/ArrayUtil/ArrayTemplate.hpp:1.2
--- netpanzer/src/Lib/ArrayUtil/ArrayTemplate.hpp:1.1   Sat Nov 22 10:43:15 2003
+++ netpanzer/src/Lib/ArrayUtil/ArrayTemplate.hpp       Mon Dec  1 19:22:10 2003
@@ -27,73 +27,55 @@
 class ArrayTemplate : public NoCopy
 {
 protected:
-    unsigned long size;
+    size_t size;
     TYPE *array;
 
 public:
-
     ArrayTemplate()
     {
         size = 0;
         array = 0;
     }
+    ArrayTemplate(size_t newsize)
+        : size(newsize)
+    {
+        array = new TYPE[size];
+    }
+    ~ArrayTemplate()
+    {
+        delete[] array;
+    }
 
-    ArrayTemplate( unsigned long size );
-    ~ArrayTemplate( void );
-
-    void initialize( unsigned long size );
+    void initialize(size_t newsize)
+    {
+        deallocate();
+        array = new TYPE[newsize];
+        size = newsize;
+    }
 
-    inline TYPE &operator[]( unsigned long index)
+    TYPE &operator[](size_t index)
     {
         assert( index < size );
-        return( array[index] );
+        return array[index];
     }
 
-    inline void add( TYPE object, unsigned long index )
+    void add(const TYPE& object, size_t index)
     {
         assert( index < size );
-        memmove( (void *) &array[index], (void *) &object, sizeof( TYPE ) );
+        array[index] = object;
     }
 
-    inline unsigned long getSize( void ) const
+    size_t getSize() const
     {
-        return( size );
+        return size;
     }
 
-    inline void deallocate( void )
+    void deallocate()
     {
-        if ( array != 0 ) {
-            delete[] array;
-            array = 0;
-        }
-
+        delete[] array;
+        array = 0;
         size = 0;
     }
 };
-
-
-
-template< class TYPE >
-ArrayTemplate< TYPE >::ArrayTemplate( unsigned long size )
-{
-    ArrayTemplate< TYPE >::size = size;
-    array = new TYPE [ size ];
-}
-
-template< class TYPE >
-ArrayTemplate< TYPE >::~ArrayTemplate( void )
-{
-    delete[] array;
-}
-
-template< class TYPE >
-void ArrayTemplate< TYPE >::initialize( unsigned long size )
-{
-    ArrayTemplate< TYPE >::size = size;
-
-    delete[] array ;
-    array = new TYPE [ size ];
-}
-
 
 #endif // ** _ARRAYTEMPLATE_HPP
Index: netpanzer/src/Lib/ArrayUtil/BitArray.hpp
diff -u netpanzer/src/Lib/ArrayUtil/BitArray.hpp:1.1 
netpanzer/src/Lib/ArrayUtil/BitArray.hpp:1.2
--- netpanzer/src/Lib/ArrayUtil/BitArray.hpp:1.1        Sat Nov 22 10:43:15 2003
+++ netpanzer/src/Lib/ArrayUtil/BitArray.hpp    Mon Dec  1 19:22:10 2003
@@ -20,7 +20,9 @@
 
 #include <stdlib.h>
 
-class BitArray
+#include "Util/NoCopy.hpp"
+
+class BitArray : public NoCopy
 {
 private:
     unsigned char *array;
Index: netpanzer/src/Lib/ArrayUtil/QueueTemplate.hpp
diff -u netpanzer/src/Lib/ArrayUtil/QueueTemplate.hpp:1.1 
netpanzer/src/Lib/ArrayUtil/QueueTemplate.hpp:1.2
--- netpanzer/src/Lib/ArrayUtil/QueueTemplate.hpp:1.1   Sat Nov 22 10:43:15 2003
+++ netpanzer/src/Lib/ArrayUtil/QueueTemplate.hpp       Mon Dec  1 19:22:10 2003
@@ -34,13 +34,13 @@
 
     void initialize( unsigned long size );
 
-    inline void reset( void )
+    void reset( void )
     {
         front = 0;
         rear = 0;
     }
 
-    inline bool enqueue( TYPE & object )
+    bool enqueue(const TYPE& object )
     {
         add( object, (rear + 1) % size );
         rear = (rear + 1) % size;
@@ -51,7 +51,7 @@
         return( true );
     }
 
-    inline TYPE dequeue( void )
+    TYPE dequeue( void )
     {
         assert( front != rear );
 
@@ -59,21 +59,21 @@
         return( array[ front ] );
     }
 
-    inline void pop( void )
+    void pop( void )
     {
         assert( front != rear );
 
         front = ( front + 1 ) % size;
     }
 
-    inline TYPE getFirst( void )
+    TYPE getFirst( void )
     {
         assert( front != rear );
 
         return( array[ (( front + 1 ) % size) ] );
     }
 
-    inline TYPE * getFirstPtr( void )
+    TYPE * getFirstPtr( void )
     {
         assert( front != rear );
 
@@ -81,22 +81,22 @@
     }
 
 
-    inline bool isEmpty( void ) const
+    bool isEmpty( void ) const
     {
         return front == rear;
     }
 
-    inline bool isFull ( void ) const
+    bool isFull ( void ) const
     {
         return front == (rear + 1) % size;
     }
 
-    inline bool isReady( void ) const
+    bool isReady( void ) const
     {
         return front != rear;
     }
 
-    inline unsigned long itemCount( void ) const
+    unsigned long itemCount( void ) const
     {
         if ( front > rear )
             return ( (rear+1) + ( (size-1) - front ) );
Index: netpanzer/src/Lib/System/SDL/SDLSound.cpp
diff -u netpanzer/src/Lib/System/SDL/SDLSound.cpp:1.1 
netpanzer/src/Lib/System/SDL/SDLSound.cpp:1.2
--- netpanzer/src/Lib/System/SDL/SDLSound.cpp:1.1       Sat Nov 22 10:43:19 2003
+++ netpanzer/src/Lib/System/SDL/SDLSound.cpp   Mon Dec  1 19:22:10 2003
@@ -106,7 +106,9 @@
     if (chunk) {
         int oldVolume = Mix_VolumeChunk(chunk, getSoundVolume(distance));
         if (Mix_PlayChannel(-1, chunk, 0) == -1) {
+            LOG(("allocating more sound channels..."));
             Mix_AllocateChannels(8 + Mix_AllocateChannels(-1));
+            LOG(("ok: %d", Mix_AllocateChannels(-1)));
             if (Mix_PlayChannel(-1, chunk, 0) == -1) {
                 LOG (("Couldn't play sound '%s': %s", name, Mix_GetError()));
             }
Index: netpanzer/src/NetPanzer/Views/Game/HelpScrollView.cpp
diff -u netpanzer/src/NetPanzer/Views/Game/HelpScrollView.cpp:1.14 
netpanzer/src/NetPanzer/Views/Game/HelpScrollView.cpp:1.15
--- netpanzer/src/NetPanzer/Views/Game/HelpScrollView.cpp:1.14  Mon Nov 24 
07:03:34 2003
+++ netpanzer/src/NetPanzer/Views/Game/HelpScrollView.cpp       Mon Dec  1 
19:22:10 2003
@@ -76,8 +76,9 @@
     insert("Outpost Related");
     insert("");
     insert("  'O'                              Cycle through your outposts");
-    insert("  Ctrl + RMC on captured outpost   Displays the outpost view");
-    insert("  Double RMC on captured outpost   Displays the outpost view");
+    insert("  LMC on captured outpost          Displays the outpost view");
+    insert("  mouse drag on captured outpost   Select unit spawn point");
+    //insert("  Double RMC on captured outpost   Displays the outpost view");
     //insert("  Alt + RMC on captured outpost........Sets selected outpost's 
delivery location");
     insert("");
     insert("");
@@ -104,10 +105,11 @@
     insert("  RMH + [1 - 7]                    Sets the blending level of the 
minimap");
     insert("  RMH + [+ or -]                   Scales the size of the 
minimap");
     //insert("  RMH + 'O'                        Toggles outposts");
-    //insert(" ");
-    //insert(" ");
-    //insert("System Related");
-    //insert("");
+    insert(" ");
+    insert(" ");
+    insert("System Related");
+    insert("");
+    insert("  ALT + Enter                      Toggle Fullscreen/Windowed 
mode");
     //insert("  F9                               BMP screen shot");
     //insert("  Alt + '-'                        Decrease brightness");
     //insert("  Alt + '='                        Increase brightness");




reply via email to

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