Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8770 in orxonox.OLD


Ignore:
Timestamp:
Jun 24, 2006, 12:38:43 PM (18 years ago)
Author:
ponder
Message:

Added some checks and assertions.

Location:
branches/terrain/src/lib/graphics/importer/terrain
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/terrain/src/lib/graphics/importer/terrain/terrain.cc

    r8748 r8770  
    1212#endif
    1313
     14bool validateSize( int _s ) {
     15        _s-=1;
     16        int s = 16;
     17        while ( s <= _s ) {
     18                if (s == _s )
     19                        return true;
     20                s*=2;
     21        }
     22        return false;
     23}
    1424void Terrain::build()
    1525{
     
    2131                return;
    2232        }               
    23        
     33        if ( !validateSize( tmpData->h ) || !validateSize( tmpData->w ) ) {
     34                PRINTF(0)( "The size of the elevation map must be 2^n+1x2^m+1. and at least 17x17" );
     35                return;
     36        }
     37        if ( tmpData->format->BytesPerPixel != 1 ) {
     38                PRINTF(0)( "The elevetation map must be an 8bit image!" );
     39                return;
     40        }
    2441        heightfield.height = tmpData->h;
    2542        heightfield.width = tmpData->w;
     
    2946        memcpy( heightfield.data, tmpData->pixels, sizeof(Uint8)*dataSize );
    3047        SDL_FreeSurface( tmpData );
    31         //TODO: Perform some checks... size, bits and so on
    3248        pagesX = (heightfield.width/(pageSize-1) );
    3349        pagesZ = (heightfield.height/(pageSize-1) );
     
    334350                break;
    335351    case 3:
    336         if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
     352        if( SDL_BYTEORDER == SDL_BIG_ENDIAN )
    337353            pixel = p[0] << 16 | p[1] << 8 | p[2];
    338354        else
     
    343359                break;
    344360    default:
    345         return 0;       /* shouldn't happen, but avoids warnings */
     361        return 255;       /* shouldn't happen, but avoids warnings */
    346362    }
    347363        Uint8 r,g,b,a;
  • branches/terrain/src/lib/graphics/importer/terrain/terrain.h

    r8748 r8770  
    8080                {
    8181                        pageSize = 17;
     82                        pagesX = pagesZ = 0;
     83                        lightmap = NULL;
     84                        heightmapSource = "";
     85                        root = NULL;
     86                        current = 0;
     87                        activePages = NULL;
    8288                        scale  = Triple( 1.0f, 3.0f, 1.0f );
    8389                        frustum = new Frustum();
     
    207213inline float Terrain::getAltitude( int _x, int _z ) const
    208214{
     215        assert( heightfield.data );
    209216        if ( _x < 0 || _x >= heightfield.width || _z < 0 || _z >= heightfield.height ) {
    210217                return 0.0f;
  • branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc

    r8748 r8770  
    3434        errors = new LODError[TerrainPage::MAX_LODS];
    3535        vertices = NULL; indices = NULL;
    36         position = Triple( scale.x*_xOffset, 0.0f, scale.z*_zOffset );
     36        left = top = bottom = right = NULL;
     37        for ( int i = 0; i < 8; ++i )
     38                layerVisibility[i] = LV_NO;     
     39               
     40        position = Triple( scale.x*_xOffset,
     41                0.0f, scale.z*_zOffset );
    3742        isVisible = false;
    3843        next = NULL;
    3944        active = false;
    40         previous = NULL;
    41         currentLOD = -1;
     45        previous = NULL; 
     46        currentLOD = -1; wantedLOD = -1;
    4247        hasfull = false;
    4348        forceTesselation = true;
  • branches/terrain/src/lib/graphics/importer/terrain/terrain_page.h

    r8745 r8770  
    8383               
    8484                /**
    85                  * @brief Sets the visibility to _flag. If the visibility changed, the vertex and index
    86                  * arrays are allocated or freed, respectively.
     85                 * @brief Sets the visibility to _flag. If the visibility changed, the vertex and
     86                 * index arrays are allocated or freed, respectively.
    8787                 */
    8888                inline void setVisibility( bool _flag );
     
    109109               
    110110                /**
    111                  * @return The curren tween factor. This is a floating point value  between 0.0f and 1.0f
     111                 * @return The curren tween factor. This is a floating point value  between 0.0f
     112                 * and 1.0f
    112113                 */
    113114                float getTween() { return 0.0f; }
     
    271272                int                                                     currentLOD,
    272273                                                                        wantedLOD;
    273                 float                                           tween;
    274274                pTerrainPage                            left,
    275275                                                                        right,
  • branches/terrain/src/lib/graphics/importer/terrain/types.h

    r8745 r8770  
    144144        int                             pitch;
    145145        UByte                   *data;
     146        Heightfield() { data = NULL; width=0;height=0;pitch=0;}
    146147};
    147148
Note: See TracChangeset for help on using the changeset viewer.