Changeset 479 for trunk


Ignore:
Timestamp:
10/30/15 15:02:06 (10 years ago)
Author:
epyon
Message:
  • resource system cleanups
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/resource.hh

    r478 r479  
    6363                template < typename T >
    6464                friend class resource_lock;
    65                 //              friend class resource_manager;
     65//              friend class resource_manager;
    6666        };
    6767
     
    7272        public:
    7373                resource() : m_id(0), m_handler( nullptr ) {}
    74                 bool is_valid() const { return m_id.valid() && m_handler != nullptr;  }
    7574                resource_id id() const { return m_id; }
     75                constexpr bool is_valid() const { return m_id && m_handler; }
     76                constexpr explicit operator bool() const { return is_valid(); }
    7677                ~resource()
    7778                {
     
    184185//              }
    185186//
    186 //              virtual const void* create( resource_id id, resource_type_id type_hash )
    187 //              {
    188 //                      auto handler = m_handlers.find( type_hash );
    189 //                      NV_ASSERT( handler != m_handlers.end(), "Handler not registered!" );
    190 //                      return handler->second->create( id, type_hash );
    191 //              }
     187// //           virtual const void* create( resource_id id, resource_type_id type_hash )
     188// //           {
     189// //                   auto handler = m_handlers.find( type_hash );
     190// //                   NV_ASSERT( handler != m_handlers.end(), "Handler not registered!" );
     191// //                   return handler->second->create( id, type_hash );
     192// //           }
    192193//
    193194//              virtual void unlock( resource_id id, resource_type_id type_hash )
  • trunk/nv/engine/resource_system.hh

    r477 r479  
    115115                }
    116116
    117 
    118117                virtual void clear()
    119118                {
     
    124123                        }
    125124                        m_store.clear();
     125                }
     126
     127                resource_type add( shash64 id, stored_type resource )
     128                {
     129                        m_store[id] = resource;
     130                        return create< T >( id );
    126131                }
    127132
     
    139144                virtual void release( stored_type ) {}
    140145
    141                 void add( stored_type resource, shash64 id )
    142                 {
    143                         m_store[id] = resource;
    144                 }
    145 
    146146                hash_store< shash64, stored_type > m_store;
    147147        };
  • trunk/nv/gfx/skeleton_instance.hh

    r477 r479  
    5959
    6060                dynamic_array< mat4 > m_transform;
    61 };
     61        };
    6262
    6363
  • trunk/nv/stl/functional/hash.hh

    r472 r479  
    176176                constexpr hash_value( const hash_value& ) = default;
    177177
    178                 constexpr bool valid() const { return m_value != 0; }
     178                constexpr bool is_valid() const { return m_value != 0; }
     179                constexpr explicit operator bool() const { return is_valid(); }
    179180
    180181                template < typename H2, typename Tag2 >
  • trunk/nv/stl/handle.hh

    r451 r479  
    3030                typedef T value_type;
    3131                typedef TAG tag_type;
    32                 static const int INDEX_BITS   = IBITS;
    33                 static const int COUNTER_BITS = IBITS;
    34                 static const T MAX_INDEX   = (1 << IBITS) - 1;
    35                 static const T MAX_COUNTER = (1 << CBITS) - 1;
    36 
    37                 handle() : m_index(0), m_counter(0) {}
    38 
    39                 inline bool operator==(const handle& rhs) const {return m_index == rhs.m_index && m_counter == rhs.m_counter; }
    40                 inline bool operator!=(const handle& rhs) const {return !(*this == rhs);}
    41 
    42                 bool is_nil() const { return m_index == 0 && m_counter == 0; }
    43                 bool is_valid() const { return !is_nil(); }
    44                 T index() const { return m_index; }
     32                static constexpr int INDEX_BITS   = IBITS;
     33                static constexpr int COUNTER_BITS = IBITS;
     34                static constexpr T MAX_INDEX   = (1 << IBITS) - 1;
     35                static constexpr T MAX_COUNTER = (1 << CBITS) - 1;
     36
     37                constexpr handle() : m_index(0), m_counter(0) {}
     38
     39                constexpr inline bool operator==(const handle& rhs) const {return m_index == rhs.m_index && m_counter == rhs.m_counter; }
     40                constexpr inline bool operator!=(const handle& rhs) const {return !(*this == rhs);}
     41
     42                constexpr bool is_nil() const { return m_index == 0 && m_counter == 0; }
     43                constexpr bool is_valid() const { return !is_nil(); }
     44                constexpr operator bool() const { return is_valid(); }
     45
     46                constexpr T index() const { return m_index; }
    4547                //size_t hash() const { return hash<T>()( T( m_counter << IBITS | m_index ) ); }
    46                 size_t hash() const { NV_ASSERT( false, "UNIMPLEMENTED!" ); return 0; }
     48                constexpr size_t hash() const { NV_ASSERT( false, "UNIMPLEMENTED!" ); return 0; }
    4749        protected:
    4850                T m_index   : IBITS;
    4951                T m_counter : CBITS;
    5052
    51                 handle( T a_index, T a_counter ) : m_index( a_index ), m_counter( a_counter ) {}
     53                constexpr handle( T a_index, T a_counter ) : m_index( a_index ), m_counter( a_counter ) {}
    5254                template < typename H >
    5355                friend class handle_operator;
  • trunk/src/engine/particle_engine.cc

    r471 r479  
    303303{
    304304        shash64 id = table.get_string_hash_64( "id" );
    305         if ( !id.valid() )
     305        if ( !id )
    306306        {
    307307                NV_LOG_ERROR( "Bad table passed to particle_engine!" )
  • trunk/src/engine/program_manager.cc

    r477 r479  
    3636        }
    3737
    38         add( m_context->get_device()->create_program( vsource, fsource ), id );
     38        add( id, m_context->get_device()->create_program( vsource, fsource ) );
    3939        return true;
    4040}
  • trunk/src/gfx/skeletal_mesh.cc

    r477 r479  
    1515void nv::skeletal_animation_entry::update_skeleton( skeleton_instance& data, uint32 a_ms_time ) const
    1616{
    17         float  fframe   = ( a_ms_time * 0.001f ) * m_fps;
    18         uint32 frame    = uint32( math::floor( fframe ) );
    19         float  reminder = fframe - static_cast<float>( frame );
     17        float  fframe = ( a_ms_time * 0.001f ) * m_fps;
     18        float  nframe = nv::floor( fframe );
    2019        uint32 duration = get_frame_count();
    2120        if ( duration == 0 )
    2221        {
    23                 frame  = get_start_frame();
    24                 fframe = static_cast<float>( frame );
     22                fframe = static_cast<float>( get_start_frame() );
    2523        }
    26         else if ( frame >= duration )
     24        else if ( nframe >= duration )
    2725        {
    2826                if ( is_looping() )
    29                 {
    30                         frame  = frame % duration;
    31                         fframe = static_cast<float>( frame ) + reminder;
    32                 }
     27                        fframe = nv::fmodf( fframe, nv::f32( duration ) );
    3328                else
    34                 {
    35                         frame  = get_end_frame();
    36                         fframe = static_cast<float>( frame );
    37                 }
     29                        fframe = static_cast<float>( get_end_frame() );
    3830        }
    3931
Note: See TracChangeset for help on using the changeset viewer.