Ignore:
Timestamp:
06/20/15 00:05:17 (10 years ago)
Author:
epyon
Message:
  • code compiles cleanly on maximum warning level
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/formats/md3_loader.cc

    r399 r406  
    267267nv::md3_loader::~md3_loader()
    268268{
    269         if (m_md3 != nullptr)
    270         {
    271                 free_md3( (md3_t*)(m_md3) );
    272                 delete (md3_t*)m_md3;
     269        md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
     270        if ( md3 != nullptr )
     271        {
     272                free_md3( md3 );
     273                delete md3;
    273274        }
    274275}
     
    276277bool nv::md3_loader::load( stream& source )
    277278{
    278         m_md3 = (void*)(new md3_t);
    279         if ( !read_md3( (md3_t*)m_md3, source ) )
     279        md3_t* md3 = new md3_t;
     280        m_md3 = md3;
     281        if ( !read_md3( md3, source ) )
    280282        {
    281283                return false;
     
    286288nv::key_raw_channel* nv::md3_loader::load_tags( const string_view& tag )
    287289{
    288         md3_t* md3 = (md3_t*)m_md3;
    289         key_raw_channel* result = key_raw_channel::create<md3_key>( (uint32)md3->header.num_frames );
     290        md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
     291        key_raw_channel* result = key_raw_channel::create<md3_key>( uint32( md3->header.num_frames ) );
    290292        // TODO: is this brain damaged in efficiency (loop nest order) or what?
    291293        for ( sint32 f = 0; f < md3->header.num_frames; ++f )
     
    294296                {
    295297                        const md3_tag_t& rtag = md3->tags[i + md3->header.num_tags * f];
    296                         string_view rname((char*)(rtag.name));
     298                        string_view rname( reinterpret_cast< const char* >(rtag.name) );
    297299                        if (rname == tag)
    298300                        {
     
    301303                                vec3 axisy  ( md3_vec3( rtag.axis[2] ) );
    302304                                vec3 origin ( md3_vec3( rtag.origin )  );
    303                                 ((md3_key*)(result->data))[f].tform = transform( origin, quat( mat3( axisx, axisy, axisz ) ) );
     305                                reinterpret_cast< md3_key*>(result->data)[f].tform = transform( origin, quat( mat3( axisx, axisy, axisz ) ) );
    304306                        }
    305307                }
     
    323325{
    324326        mesh_data* data = new mesh_data;
    325         release_mesh_frame( data, -1, (sint32)index );
     327        release_mesh_frame( data, -1, static_cast< sint32 >( index ) );
    326328        return data;
    327329}
     
    329331void nv::md3_loader::release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface )
    330332{
    331         md3_t* md3 = (md3_t*)m_md3;
    332         uint32 num_surfaces  = (uint32)md3->header.num_surfaces;
    333         uint32 num_verts     = 0;
    334         uint32 current_frame = ( frame == -1 ? 0 : (uint32)frame );
    335         uint32 frame_count   = ( frame == -1 ? (uint32)md3->header.num_frames : 1 );
    336         uint32 current_surf  = ( surface == -1 ? 0 : (uint32)surface );
    337         uint32 surf_count    = ( surface == -1 ? (uint32)md3->header.num_surfaces : 1 );
    338         uint32 index_count   = 0;
     333        md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
     334        sint32 num_surfaces  = md3->header.num_surfaces;
     335        sint32 num_verts     = 0;
     336        sint32 current_frame = ( frame == -1 ? 0 : frame );
     337        sint32 frame_count   = ( frame == -1 ? md3->header.num_frames : 1 );
     338        sint32 current_surf  = ( surface == -1 ? 0 : surface );
     339        sint32 surf_count    = ( surface == -1 ? md3->header.num_surfaces : 1 );
     340        sint32 index_count   = 0;
    339341
    340342        if ( surface >= 0 )
    341343        {
    342                 index_count = (uint32)md3->surfaces[(uint32)surface].header.num_triangles * 3;
    343                 num_verts   = (uint32)md3->surfaces[(uint32)surface].header.num_verts;
     344                index_count = md3->surfaces[surface].header.num_triangles * 3;
     345                num_verts   = md3->surfaces[surface].header.num_verts;
    344346        }
    345347        else
    346                 for ( uint32 i = 0; i < num_surfaces; ++i )
    347                 {
    348                         index_count += (uint32)md3->surfaces[i].header.num_triangles * 3;
    349                         num_verts   += (uint32)md3->surfaces[i].header.num_verts;
    350                 }
    351 
    352         mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( num_verts * frame_count );
    353         mesh_raw_channel* mc_t  = mesh_raw_channel::create< vtx_md3_t >( num_verts );
    354         mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( index_count );
    355         vtx_md3_pn* vtx_pn = (vtx_md3_pn*)mc_pn->data;
    356         vtx_md3_t*  vtx_t  = (vtx_md3_t*) mc_t->data;
    357         uint16*     icp    = (uint16*)ic->data;
     348                for ( sint32 i = 0; i < num_surfaces; ++i )
     349                {
     350                        index_count += md3->surfaces[i].header.num_triangles * 3;
     351                        num_verts   += md3->surfaces[i].header.num_verts;
     352                }
     353
     354        mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( uint32( num_verts * frame_count ) );
     355        mesh_raw_channel* mc_t  = mesh_raw_channel::create< vtx_md3_t >( uint32( num_verts ) );
     356        mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( uint32( index_count ) );
     357        vtx_md3_pn* vtx_pn = reinterpret_cast< vtx_md3_pn* >( mc_pn->data );
     358        vtx_md3_t*  vtx_t  = reinterpret_cast< vtx_md3_t* >( mc_t->data );
     359        uint16*     icp    = reinterpret_cast< uint16* >( ic->data );
    358360
    359361        uint32 index  = 0;
     
    387389        while ( frame_count > 0 )
    388390        {
    389                 current_surf  = ( surface == -1 ? 0 : (uint32)surface );
    390                 surf_count    = ( surface == -1 ? (uint32)md3->header.num_surfaces : 1 );
     391                current_surf  = ( surface == -1 ? 0 : surface );
     392                surf_count    = ( surface == -1 ? md3->header.num_surfaces : 1 );
    391393
    392394                while ( surf_count > 0 )
    393395                {
    394396                        md3_surface_t& sface  = md3->surfaces[current_surf];
    395                         uint32         vcount = (uint32)sface.header.num_verts;
    396                         uint32        offset = vcount * current_frame;
    397                         uint32        limit  = vcount + offset;
    398                         for (uint32 j = offset; j < limit; ++j )
     397                        sint32 vcount = sface.header.num_verts;
     398                        sint32 offset = vcount * current_frame;
     399                        sint32 limit  = vcount + offset;
     400                        for ( sint32 j = offset; j < limit; ++j )
    399401                        {
    400402                                md3_vertex_t& v = sface.vertices[j];
     
    410412        }
    411413
    412         data->set_name( (char*)md3->header.name );
     414        data->set_name( reinterpret_cast< char* >( md3->header.name ) );
    413415        data->add_channel( mc_pn );
    414416        data->add_channel( mc_t );
     
    418420mesh_nodes_data* nv::md3_loader::release_mesh_nodes_data( nv::size_t )
    419421{
    420         md3_t* md3 = (md3_t*)m_md3;
    421         uint32 node_count = (uint32)md3->header.num_tags;
     422        md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
     423        uint32 node_count = uint32( md3->header.num_tags );
    422424        if ( node_count == 0 ) return nullptr;
    423425        mesh_node_data* nodes = new mesh_node_data[ node_count ];
     
    425427        {
    426428                const md3_tag_t& rtag = md3->tags[i];
    427                 string_view name( (char*)(rtag.name) );
     429                string_view name( reinterpret_cast< const char* >(rtag.name) );
    428430
    429431                nodes[i].transform = mat4();
     
    441443mesh_data_pack* nv::md3_loader::release_mesh_data_pack()
    442444{
    443         md3_t* md3 = (md3_t*)m_md3;
    444         uint32 count = 1;
     445        md3_t* md3 = reinterpret_cast<md3_t*>( m_md3 );
     446        int count = 1;
    445447        mesh_data* data = nullptr;
    446448        if ( m_merge_all )
     
    448450                data = new mesh_data[1];
    449451                release_mesh_frame( &data[0], -1, -1 );
    450                 data[0].set_name( (char*)md3->header.name );
     452                data[0].set_name( reinterpret_cast< char* >( md3->header.name ) );
    451453        }
    452454        else
    453455        {
    454                 count = (uint32)md3->header.num_surfaces;
     456                count = md3->header.num_surfaces;
    455457                data = new mesh_data[ count ];
    456                 for ( uint32 i = 0; i < count; ++i )
    457                 {
    458                         release_mesh_frame( &data[i], -1, (sint32)i );
    459                         data[i].set_name( (char*)md3->surfaces[i].header.name );
    460                 }
    461         }
    462         return new mesh_data_pack( count, data, release_mesh_nodes_data() );
     458                for ( int i = 0; i < count; ++i )
     459                {
     460                        release_mesh_frame( &data[i], -1, i );
     461                        data[i].set_name( reinterpret_cast< char* >( md3->surfaces[i].header.name ) );
     462                }
     463        }
     464        return new mesh_data_pack( uint32( count ), data, release_mesh_nodes_data() );
    463465}
    464466
    465467nv::size_t md3_loader::get_max_frames() const
    466468{
    467         return static_cast< size_t >( ((md3_t*)m_md3)->header.num_frames );
    468 }
     469        return static_cast<size_t>( reinterpret_cast<md3_t*>( m_md3 )->header.num_frames );
     470}
Note: See TracChangeset for help on using the changeset viewer.