Index: trunk/src/formats/md3_loader.cc
===================================================================
--- trunk/src/formats/md3_loader.cc	(revision 399)
+++ trunk/src/formats/md3_loader.cc	(revision 406)
@@ -267,8 +267,9 @@
 nv::md3_loader::~md3_loader()
 {
-	if (m_md3 != nullptr)
-	{
-		free_md3( (md3_t*)(m_md3) );
-		delete (md3_t*)m_md3;
+	md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
+	if ( md3 != nullptr )
+	{
+		free_md3( md3 );
+		delete md3;
 	}
 }
@@ -276,6 +277,7 @@
 bool nv::md3_loader::load( stream& source )
 {
-	m_md3 = (void*)(new md3_t);
-	if ( !read_md3( (md3_t*)m_md3, source ) )
+	md3_t* md3 = new md3_t;
+	m_md3 = md3;
+	if ( !read_md3( md3, source ) )
 	{
 		return false;
@@ -286,6 +288,6 @@
 nv::key_raw_channel* nv::md3_loader::load_tags( const string_view& tag )
 {
-	md3_t* md3 = (md3_t*)m_md3;
-	key_raw_channel* result = key_raw_channel::create<md3_key>( (uint32)md3->header.num_frames );
+	md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
+	key_raw_channel* result = key_raw_channel::create<md3_key>( uint32( md3->header.num_frames ) );
 	// TODO: is this brain damaged in efficiency (loop nest order) or what?
 	for ( sint32 f = 0; f < md3->header.num_frames; ++f )
@@ -294,5 +296,5 @@
 		{
 			const md3_tag_t& rtag = md3->tags[i + md3->header.num_tags * f];
-			string_view rname((char*)(rtag.name));
+			string_view rname( reinterpret_cast< const char* >(rtag.name) );
 			if (rname == tag)
 			{
@@ -301,5 +303,5 @@
 				vec3 axisy  ( md3_vec3( rtag.axis[2] ) );
 				vec3 origin ( md3_vec3( rtag.origin )  );
-				((md3_key*)(result->data))[f].tform = transform( origin, quat( mat3( axisx, axisy, axisz ) ) );
+				reinterpret_cast< md3_key*>(result->data)[f].tform = transform( origin, quat( mat3( axisx, axisy, axisz ) ) );
 			}
 		}
@@ -323,5 +325,5 @@
 {
 	mesh_data* data = new mesh_data;
-	release_mesh_frame( data, -1, (sint32)index );
+	release_mesh_frame( data, -1, static_cast< sint32 >( index ) );
 	return data;
 }
@@ -329,31 +331,31 @@
 void nv::md3_loader::release_mesh_frame( mesh_data* data, sint32 frame, sint32 surface )
 {
-	md3_t* md3 = (md3_t*)m_md3;
-	uint32 num_surfaces  = (uint32)md3->header.num_surfaces;
-	uint32 num_verts     = 0;
-	uint32 current_frame = ( frame == -1 ? 0 : (uint32)frame );
-	uint32 frame_count   = ( frame == -1 ? (uint32)md3->header.num_frames : 1 );
-	uint32 current_surf  = ( surface == -1 ? 0 : (uint32)surface );
-	uint32 surf_count    = ( surface == -1 ? (uint32)md3->header.num_surfaces : 1 );
-	uint32 index_count   = 0;
+	md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
+	sint32 num_surfaces  = md3->header.num_surfaces;
+	sint32 num_verts     = 0;
+	sint32 current_frame = ( frame == -1 ? 0 : frame );
+	sint32 frame_count   = ( frame == -1 ? md3->header.num_frames : 1 );
+	sint32 current_surf  = ( surface == -1 ? 0 : surface );
+	sint32 surf_count    = ( surface == -1 ? md3->header.num_surfaces : 1 );
+	sint32 index_count   = 0;
 
 	if ( surface >= 0 )
 	{
-		index_count = (uint32)md3->surfaces[(uint32)surface].header.num_triangles * 3;
-		num_verts   = (uint32)md3->surfaces[(uint32)surface].header.num_verts;
+		index_count = md3->surfaces[surface].header.num_triangles * 3;
+		num_verts   = md3->surfaces[surface].header.num_verts;
 	}
 	else
-		for ( uint32 i = 0; i < num_surfaces; ++i )
-		{
-			index_count += (uint32)md3->surfaces[i].header.num_triangles * 3;
-			num_verts   += (uint32)md3->surfaces[i].header.num_verts;
-		}
-
-	mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( num_verts * frame_count );
-	mesh_raw_channel* mc_t  = mesh_raw_channel::create< vtx_md3_t >( num_verts );
-	mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( index_count );
-	vtx_md3_pn* vtx_pn = (vtx_md3_pn*)mc_pn->data;
-	vtx_md3_t*  vtx_t  = (vtx_md3_t*) mc_t->data;
-	uint16*     icp    = (uint16*)ic->data;
+		for ( sint32 i = 0; i < num_surfaces; ++i )
+		{
+			index_count += md3->surfaces[i].header.num_triangles * 3;
+			num_verts   += md3->surfaces[i].header.num_verts;
+		}
+
+	mesh_raw_channel* mc_pn = mesh_raw_channel::create< vtx_md3_pn >( uint32( num_verts * frame_count ) );
+	mesh_raw_channel* mc_t  = mesh_raw_channel::create< vtx_md3_t >( uint32( num_verts ) );
+	mesh_raw_channel* ic = mesh_raw_channel::create_index< uint16 >( uint32( index_count ) );
+	vtx_md3_pn* vtx_pn = reinterpret_cast< vtx_md3_pn* >( mc_pn->data );
+	vtx_md3_t*  vtx_t  = reinterpret_cast< vtx_md3_t* >( mc_t->data );
+	uint16*     icp    = reinterpret_cast< uint16* >( ic->data );
 
 	uint32 index  = 0;
@@ -387,14 +389,14 @@
 	while ( frame_count > 0 )
 	{
-		current_surf  = ( surface == -1 ? 0 : (uint32)surface );
-		surf_count    = ( surface == -1 ? (uint32)md3->header.num_surfaces : 1 );
+		current_surf  = ( surface == -1 ? 0 : surface );
+		surf_count    = ( surface == -1 ? md3->header.num_surfaces : 1 );
 
 		while ( surf_count > 0 )
 		{
 			md3_surface_t& sface  = md3->surfaces[current_surf];
-			uint32         vcount = (uint32)sface.header.num_verts;
-			uint32         offset = vcount * current_frame;
-			uint32         limit  = vcount + offset;
-			for (uint32 j = offset; j < limit; ++j )
+			sint32 vcount = sface.header.num_verts;
+			sint32 offset = vcount * current_frame;
+			sint32 limit  = vcount + offset;
+			for ( sint32 j = offset; j < limit; ++j )
 			{
 				md3_vertex_t& v = sface.vertices[j];
@@ -410,5 +412,5 @@
 	}
 
-	data->set_name( (char*)md3->header.name );
+	data->set_name( reinterpret_cast< char* >( md3->header.name ) );
 	data->add_channel( mc_pn );
 	data->add_channel( mc_t );
@@ -418,6 +420,6 @@
 mesh_nodes_data* nv::md3_loader::release_mesh_nodes_data( nv::size_t )
 {
-	md3_t* md3 = (md3_t*)m_md3;
-	uint32 node_count = (uint32)md3->header.num_tags;
+	md3_t* md3 = reinterpret_cast< md3_t* >( m_md3 );
+	uint32 node_count = uint32( md3->header.num_tags );
 	if ( node_count == 0 ) return nullptr;
 	mesh_node_data* nodes = new mesh_node_data[ node_count ];
@@ -425,5 +427,5 @@
 	{
 		const md3_tag_t& rtag = md3->tags[i];
-		string_view name( (char*)(rtag.name) );
+		string_view name( reinterpret_cast< const char* >(rtag.name) );
 
 		nodes[i].transform = mat4();
@@ -441,6 +443,6 @@
 mesh_data_pack* nv::md3_loader::release_mesh_data_pack()
 {
-	md3_t* md3 = (md3_t*)m_md3;
-	uint32 count = 1;
+	md3_t* md3 = reinterpret_cast<md3_t*>( m_md3 );
+	int count = 1;
 	mesh_data* data = nullptr;
 	if ( m_merge_all )
@@ -448,21 +450,21 @@
 		data = new mesh_data[1];
 		release_mesh_frame( &data[0], -1, -1 );
-		data[0].set_name( (char*)md3->header.name );
+		data[0].set_name( reinterpret_cast< char* >( md3->header.name ) );
 	}
 	else
 	{
-		count = (uint32)md3->header.num_surfaces;
+		count = md3->header.num_surfaces;
 		data = new mesh_data[ count ];
-		for ( uint32 i = 0; i < count; ++i )
-		{
-			release_mesh_frame( &data[i], -1, (sint32)i );
-			data[i].set_name( (char*)md3->surfaces[i].header.name );
-		}
-	}
-	return new mesh_data_pack( count, data, release_mesh_nodes_data() );
+		for ( int i = 0; i < count; ++i )
+		{
+			release_mesh_frame( &data[i], -1, i );
+			data[i].set_name( reinterpret_cast< char* >( md3->surfaces[i].header.name ) );
+		}
+	}
+	return new mesh_data_pack( uint32( count ), data, release_mesh_nodes_data() );
 }
 
 nv::size_t md3_loader::get_max_frames() const
 {
-	return static_cast< size_t >( ((md3_t*)m_md3)->header.num_frames );
-}
+	return static_cast<size_t>( reinterpret_cast<md3_t*>( m_md3 )->header.num_frames );
+}
