- Timestamp:
- 08/14/14 19:00:26 (11 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/flags.hh
r197 r310 16 16 #include <nv/common.hh> 17 17 #include <nv/type_traits.hh> 18 #include < bitset>18 #include <nv/array.hh> 19 19 20 20 namespace nv 21 21 { 22 template< typename T, typename IS_ENUM >23 struct base_underlying_type_helper24 {25 typedef T type;26 };27 28 template< typename T >29 struct base_underlying_type_helper< T, std::true_type >30 {31 typedef typename nv::underlying_type<T>::type type;32 };33 34 35 template< typename T >36 struct base_underlying_type37 {38 typedef typename base_underlying_type_helper< T, typename std::is_enum<T>::type >::type type;39 };40 41 22 template < uint32 SIZE, typename T = uint32 > 42 23 class flags 43 24 { 44 25 public: 45 46 26 class reference 47 27 { … … 67 47 68 48 private: 69 reference() : m_flags( nullptr ), m_index( 0) {}49 reference() : m_flags( nullptr ), m_index( index_type(0) ) {} 70 50 71 51 reference( flags<SIZE,T>* a_flags, index_type a_index ) … … 79 59 }; 80 60 81 typedef uint8 data_type; 82 typedef bool value_type; 83 typedef T index_type; 61 class enumerator 62 { 63 friend class flags<SIZE,T>; 64 public: 65 typedef T index_type; 66 typedef T value_type; 67 typedef T* iterator; 68 typedef const T* const_iterator; 69 typedef T& reference; 70 typedef const T& const_reference; 71 typedef std::size_t size_type; 72 typedef std::ptrdiff_t difference_type; 73 74 T operator* () const { return m_index; } 75 T const* operator-> () const { return &m_index; } 76 bool operator== ( const enumerator& rhs ) const 77 { 78 return ( m_index == rhs.m_index ) && ( m_flags == rhs.m_flags ); 79 } 80 bool operator!= ( const enumerator& rhs ) const 81 { 82 return !( *this == rhs ); 83 } 84 85 enumerator& operator++ () 86 { 87 next(); 88 return *this; 89 } 90 enumerator operator++ (int) 91 { 92 auto result = *this; 93 ++*this; 94 return result; 95 } 96 protected: 97 enumerator() : m_flags( nullptr ), m_index( index_type(0) ) {} 98 99 enumerator( const flags<SIZE,T>* a_flags, index_type a_index ) 100 : m_flags( a_flags ), m_index( a_index ) 101 { 102 if ( a_flags && !a_flags->test( a_index ) ) next(); 103 } 104 105 void next() 106 { 107 if ( m_flags ) 108 do 109 { 110 if ( raw_index_type(m_index) >= SIZE ) { m_flags = nullptr; m_index = index_type(0); return; } 111 m_index = index_type((raw_index_type)m_index + 1); 112 } while ( !m_flags->test( m_index ) ); 113 } 114 115 const flags<SIZE,T>* m_flags; 116 index_type m_index; 117 }; 118 119 typedef uint8 data_type; 120 typedef T index_type; 84 121 typedef uint32 size_type; 85 122 typedef typename base_underlying_type<T>::type raw_index_type; … … 89 126 static const size_type data_size = (SIZE+data_type_size-1) / data_type_size; 90 127 128 enumerator begin() const { return enumerator( this, index_type(0) ); } 129 enumerator cbegin() const { return enumerator( this, index_type(0) ); } 130 131 enumerator end() const { return enumerator(); } 132 enumerator cend() const { return enumerator(); } 133 91 134 flags() 92 135 { … … 123 166 } 124 167 125 void set( index_type i, value_typevalue )168 void set( index_type i, bool value ) 126 169 { 127 170 raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size; -
trunk/nv/lib/wx.hh
r295 r310 32 32 explicit gl_canvas( wxWindow *parent ); 33 33 virtual void OnUpdate() = 0; 34 virtual void Stop() { m_update_timer->Stop(); } 35 virtual void Start() { m_update_timer->Start(10); } 34 // virtual void Stop() { m_update_timer->Stop(); } 35 // virtual void Start() { m_update_timer->Start(20); } 36 virtual void Stop() 37 { 38 Disconnect( wxEVT_IDLE, wxIdleEventHandler(gl_canvas::OnIdle) ); 39 //m_update_timer->Stop(); 40 } 41 virtual void Start() 42 { 43 Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler(gl_canvas::OnIdle) ); 44 //m_update_timer->Start(20); 45 } 46 void OnIdle(wxIdleEvent& evt) 47 { 48 if(m_render) 49 { 50 OnUpdate(); 51 evt.RequestMore(); // render continuously, not only once on idle 52 } 53 } 36 54 ~gl_canvas(); 37 55 protected: … … 42 60 nv::window* m_window; 43 61 wxTimer* m_update_timer; 62 bool m_render; 44 63 wxDECLARE_EVENT_TABLE(); 45 64 }; … … 68 87 m_window = m_device->adopt_window( GetHWND(), dc.GetHDC() ); 69 88 m_context = m_window->get_context(); 70 m_update_timer = new gl_update_timer( this );71 89 } 72 90 73 91 inline gl_canvas::~gl_canvas() 74 92 { 75 delete m_update_timer;76 93 delete m_window; 77 94 delete m_device; -
trunk/nv/range.hh
r255 r310 89 89 }; 90 90 91 template < typename T > 92 class bits_iterator_base : public forward_iterator_base< T > 93 { 94 public: 95 typedef typename base_underlying_type<T>::type base_type; 96 static const T invalid = T( 0 ); 97 98 bits_iterator_base( T value, T current ) : forward_iterator_base( current ), m_full( value ) 99 { 100 if( !( (base_type)value & (base_type)current ) ) 101 next(); 102 } 103 bits_iterator_base& operator++ () 104 { 105 next(); 106 return *this; 107 } 108 bits_iterator_base operator++ (int) 109 { 110 auto result = *this; 111 ++*this; 112 return result; 113 } 114 private: 115 void next() 116 { 117 do 118 { 119 if ( m_value == invalid || m_full <= m_value ) { m_value = invalid; m_full = invalid; break; } 120 m_value = T((base_type)m_value << 1); 121 } while ( !( (base_type)m_full & (base_type)m_value ) ); 122 } 123 124 T m_full; 125 }; 126 127 91 128 } // namespace detail 92 129 … … 134 171 135 172 template < typename T > 173 class bits_iterator_provider 174 { 175 public: 176 typedef typename base_underlying_type<T>::type base_type; 177 typedef detail::bits_iterator_base<T> iterator; 178 static const T invalid = T( 0 ); 179 180 bits_iterator_provider( T value ) : m_value( value ) {} 181 iterator begin() { return iterator( m_value, T(1) ); } 182 iterator end() { return iterator( m_value, invalid ); } 183 184 protected: 185 T m_value; 186 }; 187 188 template < typename T > 136 189 range_iterator_provider<T> range( T begin, T end ) 137 190 { … … 163 216 } 164 217 218 template < typename T > 219 bits_iterator_provider<T> bits( T value ) 220 { 221 return bits_iterator_provider<T>( value ); 222 } 223 224 165 225 } 166 226 -
trunk/nv/type_traits.hh
r253 r310 207 207 ((TYPE*)object)->TYPE::~TYPE(); 208 208 } 209 210 template< typename T, typename IS_ENUM > 211 struct base_underlying_type_helper 212 { 213 typedef T type; 214 }; 215 216 template< typename T > 217 struct base_underlying_type_helper< T, std::true_type > 218 { 219 typedef typename nv::underlying_type<T>::type type; 220 }; 221 222 223 template< typename T > 224 struct base_underlying_type 225 { 226 typedef typename base_underlying_type_helper< T, typename std::is_enum<T>::type >::type type; 227 }; 228 229 209 230 } 210 231 -
trunk/src/gl/gl_window.cc
r304 r310 350 350 #if NV_PLATFORM == NV_WINDOWS 351 351 #if NV_SDL_VERSION == NV_SDL_20 352 nv::load_gl_no_context();353 352 m_context = new native_gl_context( m_device, dc ); 354 353 SDL_Window* window = SDL_CreateWindowFrom( handle );
Note: See TracChangeset
for help on using the changeset viewer.