Changeset 501

Show
Ignore:
Timestamp:
02/12/08 16:10:15 (11 months ago)
Author:
phill
Message:

o Loader for X42_VER_V6.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/morph-targets/libx42/anim-morph.c

    r500 r501  
    2929 
    3030        register float wt = morph->weight; 
    31         const x42morphTarget_t * morphTarget = x42->morhpTargets + morph->targetIndex; 
     31        const x42morphTarget_t * morphTarget = x42->morphTargets + morph->targetIndex; 
    3232 
    3333        const x42index_t * RESTRICT idxs = x42->morphIndices + morphTarget->firstDelta; 
     
    5252         
    5353        register float wt = morph->weight; 
    54         const x42morphTarget_t * morphTarget = x42->morhpTargets + morph->targetIndex; 
     54        const x42morphTarget_t * morphTarget = x42->morphTargets + morph->targetIndex; 
    5555 
    5656        const x42index_t * RESTRICT idxs = x42->morphIndices + morphTarget->firstDelta; 
     
    7474         
    7575        register float wt = morph->weight; 
    76         const x42morphTarget_t * morphTarget = x42->morhpTargets + morph->targetIndex; 
     76        const x42morphTarget_t * morphTarget = x42->morphTargets + morph->targetIndex; 
    7777 
    7878        const x42index_t * RESTRICT idxs = x42->morphIndices + morphTarget->firstDelta; 
  • branches/morph-targets/libx42/anim.c

    r500 r501  
    118118                { 
    119119                        demand_rf( morphs[i].targetIndex < x42->header.numMorphTargets, X42_ERR_BADPARAMS, "invalid morph target index" ); 
    120                         demand_rf( x42->morhpTargets[morphs[i].targetIndex].targetGroup == groupNum, X42_ERR_BADPARAMS, "morph target does not match group" ); 
     120                        demand_rf( x42->morphTargets[morphs[i].targetIndex].targetGroup == groupNum, X42_ERR_BADPARAMS, "morph target does not match group" ); 
    121121                } 
    122122 
  • branches/morph-targets/libx42/include/x42.h

    r500 r501  
    7373        u32                                     numVerts; 
    7474        u32                                     numIndices; 
     75        u32                                     numMorphDeltas; 
    7576 
    7677        aabb_t                          boundingBox; 
     
    149150                Morph target data. 
    150151        */ 
    151         x42morphTarget_t        *morhpTargets; 
     152        x42morphTarget_t        *morphTargets; 
    152153        x42index_t                      *morphIndices; 
    153154        vec4_t                          *morphPos; 
  • branches/morph-targets/libx42/include/x42data.h

    r498 r501  
    158158        u32                     numVerts;                       //may be zero iff numGroups is zero 
    159159        u32                     numIndices;                     //may be zero 
     160 
     161        u32                     numMorphDeltas;         //may be zero iff numMorphTargets is zero 
    160162 
    161163        aabb_t          boundingBox; 
  • branches/morph-targets/libx42/load.c

    r499 r501  
    4444        { 
    4545        case X42_VER_V5: 
    46                 break; 
     46        case X42_VER_V6: 
     47                break;      
    4748 
    4849        default: 
     
    377378                        ret->numLods = in.numLods; 
    378379                        ret->numGroups = in.numGroups; 
     380                        ret->numMorphTargets = 0; 
    379381 
    380382                        ret->numVerts = in.numVerts; 
    381383                        ret->numIndices = in.numIndices; 
     384                        ret->numMorphDeltas = 0; 
    382385 
    383386                        ret->boundingSphere = in.boundingSphere; 
     
    386389                break; 
    387390 
     391                case X42_VER_V6: 
     392                { 
     393                        x42Header_v6_t in; 
     394                        checked_read( &in, sizeof( in ) ); 
     395 
     396                        ret->modelFlags = in.modelFlags; 
     397                         
     398                        ret->baseFrame = in.baseFrame; 
     399                        ret->numFrames = in.numFrames; 
     400                         
     401                        ret->nameBlobLen = in.nameBlobLen; 
     402 
     403                        ret->numBones = in.numBones; 
     404                        ret->numAnimGroups = in.numAnimGroups; 
     405 
     406                        ret->numPosValues = in.numPosValues; 
     407                        ret->numScaleValues = in.numScaleValues; 
     408                        ret->numRotValues = in.numRotValues; 
     409 
     410                        ret->keyStreamLength = in.keyStreamLength; 
     411                        ret->numAnims = in.numAnims; 
     412 
     413                        ret->numTags = in.numTags; 
     414                        ret->numInfluences = in.numInfluences; 
     415 
     416                        ret->numLods = in.numLods; 
     417                        ret->numGroups = in.numGroups; 
     418                        ret->numMorphTargets = in.numMorphTargets; 
     419 
     420                        ret->numVerts = in.numVerts; 
     421                        ret->numIndices = in.numIndices; 
     422                        ret->numMorphDeltas = in.numMorphDeltas; 
     423 
     424                        ret->boundingSphere = in.boundingSphere; 
     425                        ret->boundingBox = in.boundingBox; 
     426                } 
     427                break; 
     428 
    388429        NO_DEFAULT; 
    389430        } 
     
    413454                ret->numLods = swap_u16( ret->numLods ); 
    414455                ret->numGroups = swap_u16( ret->numGroups ); 
     456                ret->numMorphTargets = swap_u16( ret->numMorphTargets ); 
    415457 
    416458                ret->numVerts = swap_u32( ret->numVerts ); 
    417459                ret->numIndices = swap_u32( ret->numIndices ); 
     460                ret->numMorphDeltas = swap_u32( ret->numMorphDeltas ); 
    418461 
    419462                ret->boundingBox.mins[0] = swap_f32( ret->boundingBox.mins[0] ); 
     
    498541        ret += sizeof( float[4] ); 
    499542 
    500         ret = align( ret, sizeof( void* ) )                     + sizeof( x42keyStreamEntry_t ) * h->keyStreamLength; 
    501         ret = align( ret, sizeof( void* ) )                     + sizeof( x42animation_t ) * h->numAnims; 
    502          
    503         ret = align( ret, sizeof( float ) )                     + sizeof( vec3_t ) * h->numPosValues; 
    504         ret = align( ret, sizeof( float ) )                     + sizeof( vec3_t ) * h->numScaleValues; 
    505         ret = align( ret, sizeof( float ) )                     + sizeof( quat_t ) * h->numRotValues; 
    506          
    507         ret = align( ret, sizeof( void* ) )                     + sizeof( x42animGroup_t ) * h->numAnimGroups; 
    508         ret = align( ret, sizeof( void* ) )                     + sizeof( x42bone_t ) * h->numBones; 
    509         ret = align( ret, sizeof( void* ) )                     + sizeof( u8 ) * h->numBones; 
    510          
    511         ret = align( ret, sizeof( void* ) )                     + sizeof( x42influence_t ) * h->numInfluences; 
    512         ret = align( ret, sizeof( void* ) )                     + sizeof( x42tag_t ) * h->numTags; 
    513          
    514         ret = align( ret, sizeof( void* ) )                     + sizeof( x42lodRange_t ) * h->numLods; 
    515         ret = align( ret, sizeof( void* ) )                     + sizeof( x42group_t ) * h->numGroups; 
    516          
    517         ret = align( ret, sizeof( float[4] ) )          + sizeof( x42vertAnim_t ) * h->numVerts; 
     543        ret = align( ret, sizeof( void* ) )                     + sizeof( x42keyStreamEntry_t )         * h->keyStreamLength; 
     544        ret = align( ret, sizeof( void* ) )                     + sizeof( x42animation_t )                      * h->numAnims; 
     545         
     546        ret = align( ret, sizeof( float ) )                     + sizeof( vec3_t )                                      * h->numPosValues; 
     547        ret = align( ret, sizeof( float ) )                     + sizeof( vec3_t )                                      * h->numScaleValues; 
     548        ret = align( ret, sizeof( float ) )                     + sizeof( quat_t )                                      * h->numRotValues; 
     549         
     550        ret = align( ret, sizeof( void* ) )                     + sizeof( x42animGroup_t )                      * h->numAnimGroups; 
     551        ret = align( ret, sizeof( void* ) )                     + sizeof( x42bone_t )                           * h->numBones; 
     552        ret = align( ret, sizeof( void* ) )                     + sizeof( u8 )                                          * h->numBones; 
     553         
     554        ret = align( ret, sizeof( void* ) )                     + sizeof( x42influence_t )                      * h->numInfluences; 
     555        ret = align( ret, sizeof( void* ) )                     + sizeof( x42tag_t )                            * h->numTags; 
     556         
     557        ret = align( ret, sizeof( void* ) )                     + sizeof( x42lodRange_t )                       * h->numLods; 
     558        ret = align( ret, sizeof( void* ) )                     + sizeof( x42group_t )                          * h->numGroups; 
     559        ret = align( ret, sizeof( void* ) )                     + sizeof( x42morphTarget_t )            * h->numMorphTargets; 
     560         
     561        ret = align( ret, sizeof( float[4] ) )          + sizeof( x42vertAnim_t )                       * h->numVerts; 
    518562        if( persist_flags & X42_PERSIST_NORMALS ) 
    519                 ret = align( ret, sizeof( float[4] ) )  + sizeof( x42vertNormal_t ) * h->numVerts; 
     563                ret = align( ret, sizeof( float[4] ) )  + sizeof( x42vertNormal_t )                    * h->numVerts; 
    520564        if( persist_flags & X42_PERSIST_TANGENT_BASIS ) 
    521                 ret = align( ret, sizeof( float[4] ) )  + sizeof( x42vertTangent_t ) * h->numVerts; 
     565                ret = align( ret, sizeof( float[4] ) )  + sizeof( x42vertTangent_t )           * h->numVerts; 
    522566        if( persist_flags & X42_PERSIST_TEXTURE_COORDINATES ) 
    523                 ret = align( ret, sizeof( float ) )             + sizeof( vec2_t ) * h->numVerts; 
     567                ret = align( ret, sizeof( float ) )             + sizeof( vec2_t )                                     * h->numVerts; 
    524568        if( persist_flags & X42_PERSIST_COLORS ) 
    525                 ret = align( ret, sizeof( rgba_t ) )    + sizeof( rgba_t ) * h->numVerts; 
    526  
    527         ret = align( ret, sizeof( x42index_t ) )        + sizeof( x42index_t ) * h->numIndices; 
    528          
     569                ret = align( ret, sizeof( rgba_t ) )    + sizeof( rgba_t )                                      * h->numVerts; 
     570 
     571        ret = align( ret, sizeof( x42index_t ) )        + sizeof( x42index_t )                          * h->numIndices; 
     572         
     573        ret = align( ret, sizeof( x42index_t ) )        + sizeof( x42index_t )                          * h->numMorphDeltas; 
     574        ret = align( ret, sizeof( float[4] ) )          + sizeof( vec4_t )                                      * h->numMorphDeltas; 
     575        if( persist_flags & X42_PERSIST_NORMALS ) 
     576                ret = align( ret, sizeof( float[4] ) )  + sizeof( x42morphNormal_t )            * h->numMorphDeltas; 
     577        if( persist_flags & X42_PERSIST_TANGENT_BASIS ) 
     578                ret = align( ret, sizeof( float[4] ) )  + sizeof( x42morphTangent_t )           * h->numMorphDeltas; 
     579 
    529580        ret += sizeof( char ) * h->nameBlobLen; 
    530581 
     
    581632        ret->lods                       = (x42lodRange_t*)              advance_out( sizeof( void* ),   sizeof( x42lodRange_t )         * h->numLods ); 
    582633        ret->groups                     = (x42group_t*)                 advance_out( sizeof( void* ),   sizeof( x42group_t )            * h->numGroups ); 
    583          
     634        ret->morphTargets       = (x42morphTarget_t*)   advance_out( sizeof( void* ),   sizeof( x42morphTarget_t )      * h->numMorphTargets ); 
     635 
    584636        ret->vertPos            = (x42vertAnim_t*)              advance_out( sizeof( float[4] ),sizeof( x42vertAnim_t )         * h->numVerts ); 
    585637 
     
    605657 
    606658        ret->indices = (x42index_t*)                            advance_out( sizeof( x42index_t ),      sizeof( x42index_t )            * h->numIndices ); 
     659 
     660        ret->morphIndices       = (x42index_t*)                 advance_out( sizeof( x42index_t ),      sizeof( x42index_t )            * h->numMorphDeltas ); 
     661        ret->morphPos           = (vec4_t*)                             advance_out( sizeof( float[4] ),        sizeof( vec4_t )                        * h->numMorphDeltas ); 
     662 
     663        if( persist_flags & X42_PERSIST_NORMALS ) 
     664                ret->morphNorm  = (x42morphNormal_t*)   advance_out( sizeof( float[4] ),        sizeof( x42morphNormal_t )      * h->numMorphDeltas ); 
     665        else 
     666                ret->morphNorm = NULL; 
     667 
     668        if( persist_flags & X42_PERSIST_TANGENT_BASIS ) 
     669                ret->morphTan   = (x42morphTangent_t*)  advance_out( sizeof( float[4] ),        sizeof( x42morphTangent_t )     * h->numMorphDeltas ); 
     670        else 
     671                ret->morphTan = NULL; 
    607672 
    608673        ret->strings = (char*)                                          advance_out( sizeof( char ),            sizeof( char )                          * h->nameBlobLen ); 
     
    662727        memcpy( ret->lods,                      src->lods,                      sizeof( x42lodRange_t )                 * h->numLods ); 
    663728        memcpy( ret->groups,            src->groups,            sizeof( x42group_t )                    * h->numGroups ); 
     729        memcpy( ret->morphTargets,      src->morphTargets,      sizeof( x42morphTarget_t )              * h->numMorphTargets ); 
    664730 
    665731        memcpy( ret->vertPos,           src->vertPos,           sizeof( x42vertAnim_t )                 * h->numVerts ); 
     
    679745        memcpy( ret->indices,           src->indices,           sizeof( x42index_t )                    * h->numIndices ); 
    680746 
    681         memcpy( CONST_CAST( char, ret->strings ), src->strings,         sizeof( char )                                  * h->nameBlobLen ); 
     747        memcpy( ret->morphIndices,      src->morphIndices,      sizeof( x42index_t )                    * h->numMorphDeltas ); 
     748        memcpy( ret->morphPos,          src->morphPos,          sizeof( vec4_t )                                * h->numMorphDeltas ); 
     749 
     750        if( src->morphNorm ) 
     751                memcpy( ret->morphNorm, src->morphNorm,         sizeof( x42morphNormal_t )              * h->numMorphDeltas ); 
     752 
     753        if( src->morphTan ) 
     754                memcpy( ret->morphTan,  src->morphTan,          sizeof( x42morphTangent_t )             * h->numMorphDeltas ); 
     755 
     756        memcpy( CONST_CAST( char, ret->strings ), src->strings,         sizeof( char )          * h->nameBlobLen ); 
    682757 
    683758        return ret; 
     
    690765 
    691766        bool stat; 
    692         x42PackHeader_v5_t pack; 
     767        x42PackHeader_v6_t pack; 
    693768 
    694769        /* 
     
    699774 
    700775#define checked_read( buf, type, count )                                                                        \ 
    701         if( !const_cond_false )                                                                                                       \ 
     776        if( const_cond_true )                                                                                                 \ 
    702777        {                                                                                                                                               \ 
    703778                size_t cb = sizeof( type ) * count;                                                                     \ 
     
    711786 
    712787#define checked_align( a )                                                                                                      \ 
    713         if( !const_cond_false )                                                                                                       \ 
     788        if( const_cond_true )                                                                                                 \ 
    714789        {                                                                                                                                               \ 
    715790                stat = align_stream( file_stream, &inPos, a );                                          \ 
     
    720795 
    721796#define checked_read_a( buf, type, count, a )                                                           \ 
    722         if( !const_cond_false )                                                                                                       \ 
     797        if( const_cond_true )                                                                                                 \ 
    723798        {                                                                                                                                               \ 
    724799                checked_align( a );                                                                                                     \ 
     
    729804 
    730805#define checked_read_packed_floats( buf, pack, comps, count, stride )           \ 
    731         if( !const_cond_false )                                                                                                       \ 
     806        if( const_cond_true )                                                                                                 \ 
    732807        {                                                                                                                                               \ 
    733808                checked_align( 2 );                                                                                                     \ 
     
    740815 
    741816#define checked_read_packed_floats_s16n( buf, comps, count, stride )            \ 
    742         if( !const_cond_false )                                                                                                       \ 
     817        if( const_cond_true )                                                                                                 \ 
    743818        {                                                                                                                                               \ 
    744819                checked_align( 2 );                                                                                                     \ 
     
    751826 
    752827#define checked_read_packed_floats_s8n( buf, comps, count, stride )                     \ 
    753         if( !const_cond_false )                                                                                                       \ 
     828        if( const_cond_true )                                                                                                 \ 
    754829        {                                                                                                                                               \ 
    755830                checked_align( 1 );                                                                                                     \ 
     
    762837 
    763838#define checked_skip( size, a )                                                                                         \ 
    764         if( !const_cond_false )                                                                                                       \ 
     839        if( const_cond_true )                                                                                                 \ 
    765840        {                                                                                                                                               \ 
    766841                size_t cb = (size);                                                                                                     \ 
     
    779854        */ 
    780855 
    781         checked_read( &pack, x42PackHeader_v5_t, 1 ); 
     856        if( h->ident.version < X42_VER_V6 ) 
     857        { 
     858                memset( &pack, 0, sizeof( pack ) ); 
     859                checked_read( (x42PackHeader_v5_t*)&pack, x42PackHeader_v5_t, 1 ); //x42PackHeader_v6_t's first fields are identical to those of x42PackHeader_v5_t 
     860        } 
     861        else 
     862        { 
     863                checked_read( &pack, x42PackHeader_v6_t, 1 ); 
     864        } 
    782865 
    783866        checked_read_a( ret->bones, x42Bone_v5_t, h->numBones, 8 ); 
     
    821904        checked_read_a( ret->lods, x42LodRange_v5_t, h->numLods, 8 ); 
    822905        checked_read_a( ret->groups, x42Group_v5_t, h->numGroups, 8 ); 
     906 
     907        if( h->ident.version >= X42_VER_V6 ) 
     908                checked_read_a( ret->morphTargets, x42MorphTarget_v6_t, h->numMorphTargets, 8 ); 
    823909 
    824910        checked_read_packed_floats( &ret->vertPos[0].pos, pack.vertPosPack, 3, h->numVerts, sizeof( x42vertAnim_t ) ); 
     
    912998        checked_read_a( ret->indices, x42Index_t, h->numIndices, 4 ); 
    913999 
     1000        if( h->ident.version >= X42_VER_V6 ) 
     1001        { 
     1002                checked_read_a( ret->morphIndices, x42Index_t, h->numMorphDeltas, 4 ); 
     1003                checked_read_packed_floats( ret->morphPos, pack.morphPosPack, 3, h->numMorphDeltas, sizeof( vec4_t ) ); 
     1004 
     1005                if( ret->morphNorm ) 
     1006                { 
     1007                        checked_read_packed_floats_s8n( &ret->morphNorm[0].norm, 3, h->numMorphDeltas, sizeof( x42morphNormal_t ) ); 
     1008                } 
     1009                else if( h->modelFlags & X42_MF_HAS_NORMALS ) 
     1010                        checked_skip( sizeof( s8[3] ) * h->numMorphDeltas, 0 ); 
     1011 
     1012                if( ret->morphTan ) 
     1013                { 
     1014                        checked_read_packed_floats_s8n( &ret->morphTan[0].tan, 7, h->numMorphDeltas, sizeof( x42morphTangent_t ) ); 
     1015                } 
     1016                else if( h->modelFlags & X42_MF_HAS_TANGENT_BASIS ) 
     1017                        checked_skip( sizeof( s8[7] ) * h->numMorphDeltas, 0 ); 
     1018        } 
     1019 
    9141020        checked_read( (char*)ret->strings, u8, h->nameBlobLen ); 
    9151021 
     
    9561062} 
    9571063 
     1064static void swap_x42PackHeader_v6_t( x42PackHeader_v6_t *pack ) 
     1065{ 
     1066        pack->animPosPack[0][0] = swap_f32( pack->animPosPack[0][0] ); 
     1067        pack->animPosPack[0][1] = swap_f32( pack->animPosPack[0][1] ); 
     1068        pack->animPosPack[1][0] = swap_f32( pack->animPosPack[1][0] ); 
     1069        pack->animPosPack[1][1] = swap_f32( pack->animPosPack[1][1] ); 
     1070        pack->animPosPack[2][0] = swap_f32( pack->animPosPack[2][0] ); 
     1071        pack->animPosPack[2][1] = swap_f32( pack->animPosPack[2][1] ); 
     1072 
     1073        pack->animScalePack[0] = swap_f32( pack->animScalePack[0] ); 
     1074        pack->animScalePack[1] = swap_f32( pack->animScalePack[1] ); 
     1075 
     1076        pack->vertPosPack[0][0] = swap_f32( pack->vertPosPack[0][0] ); 
     1077        pack->vertPosPack[0][1] = swap_f32( pack->vertPosPack[0][1] ); 
     1078        pack->vertPosPack[1][0] = swap_f32( pack->vertPosPack[1][0] ); 
     1079        pack->vertPosPack[1][1] = swap_f32( pack->vertPosPack[1][1] ); 
     1080        pack->vertPosPack[2][0] = swap_f32( pack->vertPosPack[2][0] ); 
     1081        pack->vertPosPack[2][1] = swap_f32( pack->vertPosPack[2][1] ); 
     1082 
     1083        pack->vertTcPack[0][0] = swap_f32( pack->vertTcPack[0][0] ); 
     1084        pack->vertTcPack[0][1] = swap_f32( pack->vertTcPack[0][1] ); 
     1085        pack->vertTcPack[1][0] = swap_f32( pack->vertTcPack[1][0] ); 
     1086        pack->vertTcPack[1][1] = swap_f32( pack->vertTcPack[1][1] ); 
     1087 
     1088        pack->morphPosPack[0][0] = swap_f32( pack->morphPosPack[0][0] ); 
     1089        pack->morphPosPack[0][1] = swap_f32( pack->morphPosPack[0][1] ); 
     1090        pack->morphPosPack[1][0] = swap_f32( pack->morphPosPack[1][0] ); 
     1091        pack->morphPosPack[1][1] = swap_f32( pack->morphPosPack[1][1] ); 
     1092        pack->morphPosPack[2][0] = swap_f32( pack->morphPosPack[2][0] ); 
     1093        pack->morphPosPack[2][1] = swap_f32( pack->morphPosPack[2][1] ); 
     1094} 
     1095 
    9581096static void swap_x42KeyStreamEntry_v5_t( x42KeyStreamEntry_v5_t *ks ) 
    9591097{ 
     
    10491187} 
    10501188 
     1189static void swap_x42MorphTarget_v6_t( x42MorphTarget_v6_t *morph ) 
     1190{ 
     1191        morph->targetName = swap_u16( morph->targetName ); 
     1192        morph->targetGroup = swap_u16( morph->targetGroup ); 
     1193        morph->firstDelta = swap_u32( morph->firstDelta ); 
     1194        morph->numDeltas = swap_u32( morph->numDeltas ); 
     1195} 
     1196 
    10511197static bool load_swapped( x42data_t *ret, const x42header_t *h, 
    10521198        x42inStream_t *file_stream, size_t inPos ) 
     
    10551201 
    10561202        bool stat; 
    1057         x42PackHeader_v5_t pack; 
     1203        x42PackHeader_v6_t pack; 
    10581204 
    10591205        /* 
     
    10641210 
    10651211#define checked_read( buf, type, count )                                                                        \ 
    1066         if( !const_cond_false )                                                                                                       \ 
     1212        if( const_cond_true )                                                                                                 \ 
    10671213        {                                                                                                                                               \ 
    10681214                uint _i;                                                                                                                        \ 
     
    10801226 
    10811227#define checked_align( a )                                                                                                      \ 
    1082         if( !const_cond_false )                                                                                                       \ 
     1228        if( const_cond_true )                                                                                                 \ 
    10831229        {                                                                                                                                               \ 
    10841230                stat = align_stream( file_stream, &inPos, a );                                          \ 
     
    10891235 
    10901236#define checked_read_a( buf, type, count, a )                                                           \ 
    1091         if( !const_cond_false )                                                                                                       \ 
     1237        if( const_cond_true )                                                                                                 \ 
    10921238        {                                                                                                                                               \ 
    10931239                checked_align( a );                                                                                                     \ 
     
    10981244 
    10991245#define checked_read_packed_floats( buf, pack, comps, count, stride )           \ 
    1100         if( !const_cond_false )                                                                                                       \ 
     1246        if( const_cond_true )                                                                                                 \ 
    11011247        {                                                                                                                                               \ 
    11021248                checked_align( 2 );                                                                                                     \ 
     
    11091255 
    11101256#define checked_read_packed_floats_s16n( buf, comps, count, stride )            \ 
    1111         if( !const_cond_false )                                                                                                       \ 
     1257        if( const_cond_true )                                                                                                 \ 
    11121258        {                                                                                                                                               \ 
    11131259                checked_align( 2 );                                                                                                     \ 
     
    11201266 
    11211267#define checked_read_packed_floats_s8n( buf, comps, count, stride )                     \ 
    1122         if( !const_cond_false )                                                                                                       \ 
     1268        if( const_cond_true )                                                                                                 \ 
    11231269        {                                                                                                                                               \ 
    11241270                checked_align( 1 );                                                                                                     \ 
     
    11311277 
    11321278#define checked_skip( size, a )                                                                                         \ 
    1133         if( !const_cond_false )                                                                                                       \ 
     1279        if( const_cond_true )                                                                                                 \ 
    11341280        {                                                                                                                                               \ 
    11351281                size_t cb = (size);                                                                                                     \ 
     
    11481294        */ 
    11491295 
    1150         checked_read( &pack, x42PackHeader_v5_t, 1 ); 
     1296        if( h->ident.version < X42_VER_V6 ) 
     1297        { 
     1298                memset( &pack, 0, sizeof( pack ) ); 
     1299                checked_read( (x42PackHeader_v5_t*)&pack, x42PackHeader_v5_t, 1 ); //x42PackHeader_v6_t's first fields are identical to those of x42PackHeader_v5_t 
     1300        } 
     1301        else 
     1302        { 
     1303                checked_read( &pack, x42PackHeader_v6_t, 1 ); 
     1304        } 
    11511305 
    11521306        checked_read_a( ret->bones, x42Bone_v5_t, h->numBones, 8 ); 
     
    11901344        checked_read_a( ret->lods, x42LodRange_v5_t, h->numLods, 8 ); 
    11911345        checked_read_a( ret->groups, x42Group_v5_t, h->numGroups, 8 ); 
     1346 
     1347        if( h->ident.version >= X42_VER_V6 ) 
     1348                checked_read_a( ret->morphTargets, x42MorphTarget_v6_t, h->numMorphTargets, 8 ); 
    11921349 
    11931350        checked_read_packed_floats( &ret->vertPos[0].pos, pack.vertPosPack, 3, h->numVerts, sizeof( x42vertAnim_t ) ); 
     
    12811438        checked_read_a( ret->indices, x42Index_t, h->numIndices, 4 ); 
    12821439 
     1440        if( h->ident.version >= X42_VER_V6 ) 
     1441        { 
     1442                checked_read_a( ret->morphIndices, x42Index_t, h->numMorphDeltas, 4 ); 
     1443                checked_read_packed_floats( ret->morphPos, pack.morphPosPack, 3, h->numMorphDeltas, sizeof( vec4_t ) ); 
     1444 
     1445                if( ret->morphNorm ) 
     1446                { 
     1447                        checked_read_packed_floats_s8n( &ret->morphNorm[0].norm, 3, h->numMorphDeltas, sizeof( x42morphNormal_t ) ); 
     1448                } 
     1449                else if( h->modelFlags & X42_MF_HAS_NORMALS ) 
     1450                        checked_skip( sizeof( s8[3] ) * h->numMorphDeltas, 0 ); 
     1451 
     1452                if( ret->morphTan ) 
     1453                { 
     1454                        checked_read_packed_floats_s8n( &ret->morphTan[0].tan, 7, h->numMorphDeltas, sizeof( x42morphTangent_t ) ); 
     1455                } 
     1456                else if( h->modelFlags & X42_MF_HAS_TANGENT_BASIS ) 
     1457                        checked_skip( sizeof( s8[7] ) * h->numMorphDeltas, 0 ); 
     1458        } 
     1459 
    12831460        checked_read( (char*)ret->strings, u8, h->nameBlobLen ); 
    12841461 
  • branches/morph-targets/libx42/local.h

    r500 r501  
    121121        size_t elemSize, uint numElems, x42opts_t *opts ); 
    122122 
    123 #define fail_r( code, msg ) if( const_cond_true ) { LIBX42_ERROR_EVENT( code, msg ); return; } else return 
    124 #define fail_rn( code, msg ) if( const_cond_true ) { LIBX42_ERROR_EVENT( code, msg ); return NULL; } return NULL 
    125 #define fail_rz( code, msg ) if( const_cond_true ) { LIBX42_ERROR_EVENT( code, msg ); return 0; } else return 0 
    126 #define fail_rf( code, msg ) if( const_cond_true ) { LIBX42_ERROR_EVENT( code, msg ); return false; } else return false 
    127 #define fail_rv( code, msg, v ) if( const_cond_true ) { LIBX42_ERROR_EVENT( code, msg ); return (v); } else return (v) 
    128 #define fail_go( code, mst, label ) if( const_cond_true ) { LIBX42_ERROR_EVENT( code, msg ); goto label; } else goto label 
     123/* error handling macro goodness */ 
     124#define fail_r( code, msg )                                     if( const_cond_true )   { LIBX42_ERROR_EVENT( code, msg ); return; }                    else return 
     125#define fail_rn( code, msg )                            if( const_cond_true )   { LIBX42_ERROR_EVENT( code, msg ); return NULL; }               return NULL 
     126#define fail_rz( code, msg )                            if( const_cond_true )   { LIBX42_ERROR_EVENT( code, msg ); return 0; }                  else return 0 
     127#define fail_rf( code, msg )                            if( const_cond_true )   { LIBX42_ERROR_EVENT( code, msg ); return false; }              else return false 
     128#define fail_rv( code, msg, v )                         if( const_cond_true )   { LIBX42_ERROR_EVENT( code, msg ); return (v); }                else return (v) 
     129#define fail_go( code, mst, label )                     if( const_cond_true )   { LIBX42_ERROR_EVENT( code, msg ); goto label; }                else goto label 
    129130 
    130 #define demand_r( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return; } else (void)0 
    131 #define demand_rn( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return NULL; } else (void)0 
    132 #define demand_rz( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return 0; } else (void)0 
    133 #define demand_rf( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return false; } else (void)0 
    134 #define demand_rv( cond, code, msg, v ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); return (v); } else (void)0 
    135 #define demand_go( cond, code, msg, label ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); goto label; } else (void)0 
     131#define demand_r( cond, code, msg )                    if( !(cond) )                   { LIBX42_ERROR_EVENT( code, msg ); return; }                    else (void)0 
     132#define demand_rn( cond, code, msg )           if( !(cond) )                   { LIBX42_ERROR_EVENT( code, msg ); return NULL; }               else (void)0 
     133#define demand_rz( cond, code, msg )           if( !(cond) )                   { LIBX42_ERROR_EVENT( code, msg ); return 0; }                  else (void)0 
     134#define demand_rf( cond, code, msg )           if( !(cond) )                   { LIBX42_ERROR_EVENT( code, msg ); return false; }              else (void)0 
     135#define demand_rv( cond, code, msg, v )                if( !(cond) )                   { LIBX42_ERROR_EVENT( code, msg ); return (v); }                else (void)0 
     136#define demand_go( cond, code, msg, label )    if( !(cond) )                   { LIBX42_ERROR_EVENT( code, msg ); goto label; }                else (void)0 
    136137 
    137138#ifdef DEBUG 
     
    142143#endif 
    143144 
    144 #define assert( cond, code, msg ) if( !(cond) ) { LIBX42_ERROR_EVENT( code, msg ); debugger_break(); } else (void)0 
     145#define assert( cond, code, msg )                      if( !(cond) )                   { LIBX42_ERROR_EVENT( code, msg ); debugger_break(); }  else (void)0 
    145146#else 
    146 #define assert( cond, code, msg ) if( !const_cond_false ) { (void)sizeof( cond ); } else (void)0 
     147#define assert( cond, code, msg )                      if( const_cond_true )   { (void)sizeof( cond ); }                                                               else (void)0 
    147148#endif 
    148149 
  • branches/morph-targets/libx42/write.c

    r471 r501  
    436436 
    437437#define checked_write( buf, size )                                                                                      \ 
    438         if( !const_cond_false )                                                                                                       \ 
     438        if( const_cond_true )                                                                                                 \ 
    439439        {                                                                                                                                               \ 
    440440                size_t cb = (size);                                                                                                     \ 
     
    448448 
    449449#define checked_align( a )                                                                                                      \ 
    450         if( !const_cond_false )                                                                                                       \ 
     450        if( const_cond_true )                                                                                                 \ 
    451451        {                                                                                                                                               \ 
    452452                stat = align_stream( file_stream, &outPos, a );                                         \ 
     
    457457 
    458458#define checked_write_a( buf, size, a )                                                                         \ 
    459         if( !const_cond_false )                                                                                                       \ 
     459        if( const_cond_true )                                                                                                 \ 
    460