Changeset 402 for trunk/src/core
- Timestamp:
- 06/13/15 21:51:27 (10 years ago)
- Location:
- trunk/src/core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/core/library.cc
r399 r402 11 11 # include <windows.h> 12 12 # define NV_LIB_EXT ".dll" 13 # define NV_LIB_HANDLE HMODULE 14 # define NV_LIB_OPEN( name ) LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) 15 # define NV_LIB_GET( handle, name ) GetProcAddress( handle, name ) 16 # define NV_LIB_CLOSE( name ) !FreeLibrary( name ) 13 # define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) ) 14 # define NV_LIB_GET( handle, name ) reinterpret_cast<void*>( GetProcAddress( static_cast<HMODULE>( handle ), name ) ) 15 # define NV_LIB_CLOSE( handle ) ( FreeLibrary( static_cast<HMODULE>( handle ) ) != 0 ) 17 16 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 18 17 # include <dlfcn.h> 19 18 # define NV_LIB_EXT ".so" 20 # define NV_LIB_HANDLE void*21 19 # define NV_LIB_OPEN( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL) 22 # define NV_LIB_GET( handle, name ) dlsym( handle, name )23 # define NV_LIB_CLOSE( name ) dlclose( name)20 # define NV_LIB_GET( handle, name ) dlsym( static_cast<void*>( handle ), name ) 21 # define NV_LIB_CLOSE( handle ) ( dlclose( static_cast<void*>( handle ) ) == 0 ) 24 22 #elif NV_PLATFORM == NV_APPLE 25 23 # include "macUtils.h" 26 24 # include <dlfcn.h> 27 25 # define NV_LIB_EXT ".dylib" 28 # define NV_LIB_HANDLE CFBundleRef29 26 # define NV_LIB_OPEN( name ) mac_loadExeBundle( name ) 30 27 # define NV_LIB_GET( handle, name ) mac_getBundleSym( handle, name ) 31 # define NV_LIB_CLOSE( name ) mac_unloadExeBundle( name)28 # define NV_LIB_CLOSE( handle ) ( mac_unloadExeBundle( handle ) == 0 ) 32 29 #endif 33 30 … … 83 80 } 84 81 85 m_handle = (void*)NV_LIB_OPEN( name.c_str() );82 m_handle = NV_LIB_OPEN( name.c_str() ); 86 83 87 84 if ( m_handle == NULL ) … … 96 93 void* library::get( string_view symbol ) 97 94 { 98 void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE)m_handle, symbol.data() );95 void* result = NV_LIB_GET( m_handle, symbol.data() ); 99 96 if ( !result ) 100 97 { … … 106 103 void* nv::library::try_get( string_view symbol ) 107 104 { 108 return (void*) NV_LIB_GET( (NV_LIB_HANDLE)m_handle, symbol.data() );105 return NV_LIB_GET( m_handle, symbol.data() ); 109 106 } 110 107 … … 116 113 void library::close() 117 114 { 118 if ( NV_LIB_CLOSE( (NV_LIB_HANDLE)m_handle ) )115 if ( ! NV_LIB_CLOSE( m_handle ) ) 119 116 { 120 117 NV_LOG_ERROR( "library : can't close library '", m_name, "'!" ); 121 118 } 122 m_handle = NULL;119 m_handle = nullptr; 123 120 } 124 121 125 122 library::~library() 126 123 { 127 if ( m_handle != NULL)124 if ( m_handle != nullptr ) 128 125 { 129 126 close(); … … 135 132 #if NV_PLATFORM == NV_WINDOWS 136 133 // We do hate WinAPI for code like this, don't we? 137 LPTSTR buffer = NULL;134 LPTSTR buffer = nullptr; 138 135 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 139 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );140 std::string msg( (char*)buffer);136 NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPTSTR>( &buffer ), 0, NULL ); 137 std::string msg( reinterpret_cast<char*>( buffer ) ); 141 138 LocalFree( buffer ); 142 139 return msg; 143 140 #elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE 144 return st ring(dlerror());141 return std::string( dlerror() ); 145 142 #else 146 return st ring("");143 return std::string(""); 147 144 #endif 148 145 } -
trunk/src/core/logger.cc
r399 r402 89 89 for ( auto& sink_info : m_log_sinks ) 90 90 { 91 if ( sink_info.sink && (sink_info.level >= (uint32)level) )91 if ( sink_info.sink && (sink_info.level >= static_cast<uint32>( level ) ) ) 92 92 { 93 93 // log and iterate … … 106 106 { 107 107 sink_info.sink = sink; 108 sink_info.level = (uint32)level;108 sink_info.level = static_cast<uint32>( level ); 109 109 return; 110 110 } … … 194 194 //if ( m_flush ) FlushFileBuffers( m_handle ); 195 195 #else 196 fwrite( stamp, ssize, 1, (FILE*)m_handle ); 197 fwrite( " [", 2, 1, (FILE*)m_handle ); 198 fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, (FILE*)m_handle ); 199 fwrite( "] ", 2, 1, (FILE*)m_handle ); 200 fwrite( message.data(), message.size(), 1, (FILE*)m_handle ); 201 fwrite( "\n", 1, 1, (FILE*)m_handle ); 202 if ( m_flush ) fflush( (FILE*)m_handle ); 196 FILE* file = static_cast<FILE*>( m_handle ); 197 fwrite( stamp, ssize, 1, file ); 198 fwrite( " [", 2, 1, file ); 199 fwrite( NV_LOG_LEVEL_NAME_PAD( level ), 8, 1, file ); 200 fwrite( "] ", 2, 1, file ); 201 fwrite( message.data(), message.size(), 1, file ); 202 fwrite( "\n", 1, 1, file ); 203 if ( m_flush ) fflush( file ); 203 204 #endif 204 205 } … … 226 227 CloseHandle( m_handle ); 227 228 #else 228 fclose( (FILE*) m_handle);229 fclose( static_cast<FILE*>( m_handle ) ); 229 230 #endif 230 231 } … … 244 245 { 245 246 uint32 ms = get_system_ms(); 246 unsigned int secs = (unsigned int)(ms / 1000);247 unsigned int mm = (unsigned int)( ms * 100 / 1000 ) % 100;248 unsigned int h = (unsigned int)(secs / (60*60));249 unsigned int m = (unsigned int)(secs / 60) % 60;247 unsigned int secs = static_cast<unsigned int>( ms / 1000 ); 248 unsigned int mm = static_cast<unsigned int>( ms * 100 / 1000 ) % 100; 249 unsigned int h = static_cast<unsigned int>( secs / (60*60) ); 250 unsigned int m = static_cast<unsigned int>( secs / 60 ) % 60; 250 251 unsigned int s = secs % 60; 251 252 #if NV_COMPILER == NV_MSVC -
trunk/src/core/profiler.cc
r399 r402 124 124 if ( c->m_calls > 0 ) 125 125 { 126 f64 pparent = ( (f64)c->m_total_time_us / (f64)c->m_parent->m_total_time_us ) * 100.f; 126 f64 ftotal_time_us = static_cast<f64>( c->m_total_time_us ); 127 f64 pparent = ( ftotal_time_us / static_cast<f64>( c->m_parent->m_total_time_us ) ) * 100.f; 127 128 uint32 calls = c->m_calls; 128 f64 total_ms = c->m_total_time_us / 1000.f;129 f64 avg_ms = ( (f64)c->m_total_time_us / (f64)c->m_calls) / 1000.f;129 f64 total_ms = ftotal_time_us / 1000.f; 130 f64 avg_ms = ( ftotal_time_us / static_cast<f64>( c->m_calls ) ) / 1000.f; 130 131 if ( indent > 0 ) nvmemset( buffer, '-', indent ); 131 132 snprintf( buffer + indent, 128 - indent, "%*.*s %6.2f %6d %9.2f %6.2f", indent - 23, 23 - indent, -
trunk/src/core/random.cc
r395 r402 19 19 random::seed_type random::randomize() 20 20 { 21 std::mt19937& rng = *( ( std::mt19937* )m_data);21 std::mt19937& rng = *( reinterpret_cast< std::mt19937* >( m_data ) ); 22 22 seed_type seed = randomized_seed(); 23 23 rng.seed( seed ); … … 27 27 void random::set_seed( random::seed_type seed /*= 0 */ ) 28 28 { 29 std::mt19937& rng = *( ( std::mt19937* )m_data);29 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 30 30 rng.seed( seed == 0 ? randomized_seed() : seed ); 31 31 } … … 39 39 random::result_type random::rand() 40 40 { 41 std::mt19937& rng = *( ( std::mt19937* )m_data);41 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 42 42 return rng(); 43 43 } … … 45 45 sint32 random::srand( sint32 val ) 46 46 { 47 std::mt19937& rng = *( ( std::mt19937* )m_data);47 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 48 48 std::uniform_int_distribution<sint32> dist( 0, val - 1 ); 49 49 return dist( rng ); … … 52 52 uint32 random::urand( uint32 val ) 53 53 { 54 std::mt19937& rng = *( ( std::mt19937* )m_data);54 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 55 55 std::uniform_int_distribution<uint32> dist( 0, val - 1 ); 56 56 return dist( rng ); … … 59 59 f32 random::frand( f32 val ) 60 60 { 61 std::mt19937& rng = *( ( std::mt19937* )m_data);61 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 62 62 std::uniform_real_distribution<f32> dist( 0, val ); 63 63 return dist( rng ); … … 66 66 sint32 random::srange( sint32 min, sint32 max ) 67 67 { 68 std::mt19937& rng = *( ( std::mt19937* )m_data);68 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 69 69 std::uniform_int_distribution<sint32> dist( min, max ); 70 70 return dist( rng ); … … 73 73 uint32 random::urange( uint32 min, uint32 max ) 74 74 { 75 std::mt19937& rng = *( ( std::mt19937* )m_data);75 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 76 76 std::uniform_int_distribution<uint32> dist( min, max ); 77 77 return dist( rng ); … … 80 80 f32 random::frange( f32 min, f32 max ) 81 81 { 82 std::mt19937& rng = *( ( std::mt19937* )m_data);82 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 83 83 std::uniform_real_distribution<f32> dist( min, max ); 84 84 return dist( rng ); … … 87 87 uint32 random::dice( uint32 count, uint32 sides ) 88 88 { 89 std::mt19937& rng = *( ( std::mt19937* )m_data);89 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 90 90 std::uniform_int_distribution<uint32> dist( 1, sides ); 91 91 uint32 result = 0; … … 106 106 nv::vec2 nv::random::precise_unit_vec2() 107 107 { 108 std::mt19937& rng = *( ( std::mt19937* )m_data);108 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 109 109 std::uniform_real_distribution<f32> dist( 0, glm::pi<float>() * 2.f ); 110 110 float angle = dist( rng ); … … 114 114 nv::vec3 nv::random::precise_unit_vec3() 115 115 { 116 std::mt19937& rng = *( ( std::mt19937* )m_data);116 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 117 117 std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f ); 118 118 std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() ); … … 129 129 nv::vec2 nv::random::fast_disk_point() 130 130 { 131 std::mt19937& rng = *( ( std::mt19937* )m_data);131 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 132 132 std::uniform_real_distribution<f32> dist( 0.0f, 1.0f ); 133 133 float r1 = dist( rng ); … … 140 140 nv::vec2 nv::random::precise_disk_point() 141 141 { 142 std::mt19937& rng = *( ( std::mt19937* )m_data);142 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 143 143 std::uniform_real_distribution<f32> unit( 0.0f, 1.0f ); 144 144 std::uniform_real_distribution<f32> angle( 0.0f, glm::pi<float>() ); … … 150 150 nv::vec3 nv::random::fast_sphere_point() 151 151 { 152 std::mt19937& rng = *( ( std::mt19937* )m_data);152 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 153 153 std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f ); 154 154 std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f ); … … 168 168 nv::vec3 nv::random::precise_sphere_point() 169 169 { 170 std::mt19937& rng = *( ( std::mt19937* )m_data);170 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 171 171 std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f ); 172 172 std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f ); … … 185 185 nv::vec2 nv::random::precise_ellipse_point( const vec2& radii ) 186 186 { 187 std::mt19937& rng = *( ( std::mt19937* )m_data);187 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 188 188 std::uniform_real_distribution<f32> distx( -radii.x, radii.x ); 189 189 std::uniform_real_distribution<f32> disty( -radii.y, radii.y ); … … 204 204 nv::vec3 nv::random::precise_ellipsoid_point( const vec3& radii ) 205 205 { 206 std::mt19937& rng = *( ( std::mt19937* )m_data);206 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 207 207 std::uniform_real_distribution<f32> distx( -radii.x, radii.x ); 208 208 std::uniform_real_distribution<f32> disty( -radii.y, radii.y ); … … 225 225 nv::vec2 nv::random::fast_hollow_disk_point( float iradius, float oradius ) 226 226 { 227 std::mt19937& rng = *( ( std::mt19937* )m_data);227 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 228 228 float idist2 = iradius * iradius; 229 229 float odist2 = oradius * oradius; … … 239 239 nv::vec3 nv::random::fast_hollow_sphere_point( float iradius, float oradius ) 240 240 { 241 std::mt19937& rng = *( ( std::mt19937* )m_data);241 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 242 242 float idist3 = iradius * iradius * iradius; 243 243 float odist3 = oradius * oradius * oradius; … … 254 254 nv::vec2 nv::random::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii ) 255 255 { 256 std::mt19937& rng = *( ( std::mt19937* )m_data);256 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 257 257 vec2 iradii2 = iradii * iradii; 258 258 vec2 opoint = ellipse_edge( oradii ); … … 275 275 nv::vec3 nv::random::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii ) 276 276 { 277 std::mt19937& rng = *( ( std::mt19937* )m_data);277 std::mt19937& rng = *( reinterpret_cast<std::mt19937*>( m_data ) ); 278 278 vec3 iradii2 = iradii * iradii; 279 279 vec3 opoint = ellipsoid_edge( oradii ); -
trunk/src/core/time.cc
r401 r402 85 85 nv::uint32 nv::get_cpu_ms() 86 86 { 87 return (uint32)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000.0) ) ;87 return static_cast<uint32>( static_cast<f32>( clock() - zero_timer.clock_zero ) / ( static_cast<f32>(CLOCKS_PER_SEC) / 1000.0f ) ) ; 88 88 } 89 89 90 90 nv::uint64 nv::get_cpu_us() 91 91 { 92 return (uint64)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000000.0) ) ;92 return static_cast<uint64>( static_cast<f32>( clock() - zero_timer.clock_zero ) / ( static_cast<f32>(CLOCKS_PER_SEC) / 1000000.0f ) ) ; 93 93 } 94 94 … … 99 99 QueryPerformanceCounter(&now); 100 100 LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart; 101 return (uint32) (1000.0 * result / (double) zero_timer.frequency.QuadPart);101 return static_cast<uint32>(1000.0 * result / static_cast<f64>( zero_timer.frequency.QuadPart ) ); 102 102 #else 103 103 struct timeval now; 104 104 gettimeofday(&now, NULL); 105 return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000+(now.tv_usec-zero_timer.timeval_zero.tv_usec)/1000 );105 return static_cast<uint32>( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000+(now.tv_usec-zero_timer.timeval_zero.tv_usec)/1000 ); 106 106 #endif 107 107 } … … 113 113 QueryPerformanceCounter(&now); 114 114 LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart; 115 return (uint64) (1000000.0 * result / (double) zero_timer.frequency.QuadPart);115 return static_cast<uint64>(1000000.0 * result / static_cast<f64>( zero_timer.frequency.QuadPart ) ); 116 116 #else 117 117 struct timeval now; 118 118 gettimeofday(&now, NULL); 119 return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000000+(now.tv_usec - zero_timer.timeval_zero.tv_usec) );119 return static_cast<uint64>( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000000+(now.tv_usec - zero_timer.timeval_zero.tv_usec) ); 120 120 #endif 121 121 }
Note: See TracChangeset
for help on using the changeset viewer.