Index: unk/nv/any.hh
===================================================================
--- /trunk/nv/any.hh	(revision 318)
+++ 	(revision )
@@ -1,154 +1,0 @@
-// Copyright (C) 2014 ChaosForge Ltd
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file any.hh
- * @author Kornel Kisielewicz
- * @brief any type
- *
- * based on http://www.two-sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf
- */
-
-#ifndef NV_ANY_HH
-#define NV_ANY_HH
-
-#include <nv/common.hh>
-#include <nv/type_traits.hh>
-
-namespace nv
-{
-	
-	class any
-	{
-	public:
-		any() : m_content( nullptr ) {}
-		
-		any( const any& other )
-			: m_content( other.m_content ? other.m_content->clone() : nullptr )
-		{}
-
-		template< typename T >
-		any( const T& value )
-			: m_content( new holder<T>( value ) )
-		{}
-
-		any( any&& other ) 
-			: m_content( other.m_content )
-		{}
-
-		template< typename T >
-		any( T&& value )
-			: m_content( new holder<T>( std::forward<T>(value) ) )
-		{}
-
-		~any() 
-		{ 
-			delete m_content; 
-		}
-
-		any& swap( any& rhs )
-		{
-			std::swap( m_content, rhs.m_content );
-			return *this;
-		}
-
-		any& operator=( const any& rhs )
-		{
-			return swap( any( rhs ) );
-		}
-
-		any& operator=( any&& rhs )
-		{
-			swap( rhs );
-			any().swap( rhs );
-			return *this;
-		}
-
-		template < typename T >
-		any& operator= ( T&& rhs )
-		{
-			any( std::forward<T>(rhs) ).swap(*this);
-			return *this;
-		}
-
-		operator const void* () const
-		{
-			return m_content;
-		}
-
-		template< typename T >
-		bool copy_to( T& value ) const
-		{
-			const T* copyable = to_ptr<T>();
-			if ( copyable ) value = *copyable;
-			return copyable;
-		}
-		template< typename T >
-		const T* to_ptr() const
-		{
-			return type_info() == typeid(T) ? &static_cast< holder<T> *>(m_content)->held				: nullptr;
-		}
-
-		bool empty() const
-		{
-			return !m_content;
-		}
-
-		void clear()
-		{
-			any().swap(*this);
-		}
-
-		const std::type_info &type_info() const
-		{
-			return m_content ? m_content->type_info() : typeid(void);
-		}
-	private:
-		class placeholder
-		{
-		public:
-			virtual const std::type_info& type_info() const = 0;
-			virtual placeholder *clone() const = 0;
-			virtual ~placeholder() {}
-		};
-
-		template< typename T >
-		class holder : public placeholder
-		{
-		public:
-			holder( const T& value ) : held(value)
-			{
-			}
-			holder( T&& value ) : held(std::forward<T>(value))
-			{
-			}
-			virtual const std::type_info &type_info() const
-			{
-				return typeid(T);
-			}
-			virtual placeholder *clone() const
-			{
-				return new holder(held);
-			}
-			const T held;
-		};
-		placeholder *m_content;
-	};
-
-	inline void swap( any& lhs, any& rhs )
-	{
-		lhs.swap(rhs);
-	}
-
-	template< typename T >
-	T any_cast( const any& operand )
-	{
-		const T* result = operand.to_ptr<T>();
-		return result ? *result : throw std::bad_cast();
-	}
-}
-
-#endif // NV_ANY_HH
Index: unk/nv/array.hh
===================================================================
--- /trunk/nv/array.hh	(revision 318)
+++ 	(revision )
@@ -1,193 +1,0 @@
-// Copyright (C) 2014 ChaosForge Ltd
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file array.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief exception free array classes
- */
-
-#ifndef NV_ARRAY_HH
-#define NV_ARRAY_HH
-
-#include <nv/common.hh>
-#include <vector>
-#include <array>
-
-namespace nv
-{
-	namespace detail
-	{
-		template < typename T >
-		class array_base
-		{
-		public:
-			typedef T              value_type;
-			typedef T*             iterator;
-			typedef const T*       const_iterator;
-			typedef T&             reference;
-			typedef const T&       const_reference;
-			typedef std::size_t    size_type;
-			typedef std::ptrdiff_t difference_type;
-
-			typedef std::reverse_iterator<iterator>       reverse_iterator;
-			typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-		};
-	}
-
-	using std::vector;
-	using std::array;
-
-	template< class T, std::size_t N >
-	class static_array : public detail::array_base<T>
-	{
-	public:
-		iterator        begin()        { return m_data; }
-		const_iterator  begin()  const { return m_data; }
-		const_iterator  cbegin() const { return m_data; }
-
-		iterator        end()        { return m_data+N; }
-		const_iterator  end()  const { return m_data+N; }
-		const_iterator  cend() const { return m_data+N; }
-
-		reverse_iterator rbegin()              { return reverse_iterator( end() ); }
-		const_reverse_iterator rbegin() const  { return const_reverse_iterator( end() ); }
-		const_reverse_iterator crbegin() const { return const_reverse_iterator( end() ); }
-
-		reverse_iterator rend()                { return reverse_iterator( begin() ); }
-		const_reverse_iterator rend() const    { return const_reverse_iterator( begin() ); }
-		const_reverse_iterator crend() const   { return const_reverse_iterator( begin() ); }
-
-		reference operator[]( size_type i ) 
-		{ 
-			NV_ASSERT( i < N, "Out of range" ); 
-			return m_data[i];
-		}
-
-		const_reference operator[]( size_type i ) const 
-		{     
-			NV_ASSERT( i < N, "Out of range" ); 
-			return m_data[i]; 
-		}
-
-		reference       front()       { return m_data[0]; }
-		const_reference front() const { return m_data[0]; }
-		reference       back()        { return m_data[N-1]; }
-		const_reference back() const  { return m_data[N-1]; }
-
-		static size_type size()     { return N; }
-		static bool      empty()    { return false; }
-		static size_type max_size() { return N; }
-
-		const value_type* data() const { return m_data; }
-		value_type*       data()       { return m_data; }
-
-		size_type   raw_size() const { return N * ELEMENT_SIZE; }
-		const char* raw_data() const { return (const char*)m_data; }
-		char*       raw_data()       { return (char*)m_data; }
-
-		void assign( const value_type& value ) { std::fill_n( begin(), size(), value ); }
-
-		static const size_type SIZE = N;
-		static const size_type ELEMENT_SIZE = sizeof(T);
-	public:
-		value_type m_data[N];
-	};
-
-	template< class T >
-	class dynamic_array : public detail::array_base<T>
-	{
-	public:
-		dynamic_array() 
-			: m_data( nullptr ), m_size(0) {}
-		explicit dynamic_array( size_type new_size )
-			: m_data( new value_type[ new_size ] ), m_size( new_size ) {}
-		dynamic_array( const value_type& value, size_type size )
-			: m_data( nullptr ), m_size(0) { assign( value, size ); }
-		dynamic_array( const_iterator values, size_type size )
-			: m_data( nullptr ), m_size(0) { assign( values, size ); }
-
-		void resize( size_type new_size )
-		{
-			if ( new_size != m_size ) 
-			{
-				value_type* old_data = m_data;
-				m_data = new_size > 0 ? new value_type[ new_size ] : nullptr;
-				if ( old_data && m_data )
-				{
-					std::copy_n( old_data, new_size > m_size ? m_size : new_size, m_data );
-				}
-				delete[] old_data;
-				m_size = new_size;
-			}
-		}
-
-		iterator        begin()        { return m_data; }
-		const_iterator  begin()  const { return m_data; }
-		const_iterator  cbegin() const { return m_data; }
-
-		iterator        end()        { return m_data+m_size; }
-		const_iterator  end()  const { return m_data+m_size; }
-		const_iterator  cend() const { return m_data+m_size; }
-
-		reverse_iterator rbegin()              { return reverse_iterator( end() ); }
-		const_reverse_iterator rbegin() const  { return const_reverse_iterator( end() ); }
-		const_reverse_iterator crbegin() const { return const_reverse_iterator( end() ); }
-
-		reverse_iterator rend()                { return reverse_iterator( begin() ); }
-		const_reverse_iterator rend() const    { return const_reverse_iterator( begin() ); }
-		const_reverse_iterator crend() const   { return const_reverse_iterator( begin() ); }
-
-		reference operator[]( size_type i ) 
-		{ 
-			NV_ASSERT( i < m_size, "Out of range" ); 
-			return m_data[i];
-		}
-
-		const_reference operator[]( size_type i ) const 
-		{     
-			NV_ASSERT( i < m_size, "Out of range" ); 
-			return m_data[i]; 
-		}
-
-		reference       front()       { return m_data[0]; }
-		const_reference front() const { return m_data[0]; }
-		reference       back()        { return m_data[m_size-1]; }
-		const_reference back() const  { return m_data[m_size-1]; }
-
-		size_type        size() const     { return m_size; }
-		bool             empty() const    { return m_size == 0; }
-		static size_type max_size()       { return std::numeric_limits< size_type >::max(); }
-		const value_type* data() const { return m_data; }
-		value_type*       data()       { return m_data; }
-
-		size_type   raw_size() const { return m_size * ELEMENT_SIZE; }
-		const char* raw_data() const { return (const char*)m_data; }
-		char*       raw_data()       { return (char*)m_data; }
-
-		void assign( const value_type& value ) { std::fill_n( begin(), size(), value ); }
-		void assign( const value_type& value, size_type new_size ) 
-		{
-			resize( new_size );
-			std::fill_n( begin(), size(), value );
-		}
-		void assign( const_iterator values, size_type new_size )
-		{
-			resize( new_size );
-			std::copy_n( values, size(), m_data );
-		}
-
-		~dynamic_array() { delete[] m_data; }
-
-		static const size_type ELEMENT_SIZE = sizeof(T);
-	public:
-		value_type* m_data;
-		size_type   m_size;
-	};
-
-}
-
-#endif // NV_ARRAY_HH
Index: unk/nv/array2d.hh
===================================================================
--- /trunk/nv/array2d.hh	(revision 318)
+++ 	(revision )
@@ -1,362 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file array2d.hh
- * @author Kornel Kisielewicz
- * @brief 2D array
- */
-
-// TODO: make it work with the stl allocator
-
-#ifndef NV_ARRAY2D_HH
-#define NV_ARRAY2D_HH
-
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/range.hh>
-
-namespace nv
-{
-	typedef ivec2 coord2d;
-
-	template < typename T >
-	class array2d
-	{
-	public:
-		typedef T                 value_type;
-		typedef value_type&       reference;
-		typedef const value_type& const_reference;
-		typedef value_type*       pointer;
-		typedef const value_type* const_pointer;
-		typedef pointer           iterator;
-		typedef const_pointer     const_iterator;
-
-		/**
-		 * Creates a new 2D array.
-		 */
-		array2d() : m_data( nullptr ), m_size() {}
-
-		/**
-		 * Creates a new 2D array.
-		 *
-		 * @param asize The dimensions of the new array.
-		 */
-		array2d( const ivec2& asize ) : m_data( nullptr ), m_size() { resize( asize ); }
-
-		/**
-		 * Creates a new 2D array.
-		 *
-		 * @param asize_x The width of the new array.
-		 * @param asize_y The height of the new array.
-		 */
-		array2d( const sint32 asize_x, const sint32 asize_y ) : m_data( nullptr ), m_size() { resize( new ivec2( asize_x, asize_y ) ); }
-		
-		/**
-		 * Gets the dimensions of the array.
-		 *
-		 * @returns The size of the array.
-		 */
-		const ivec2& size() const { return m_size; }
-
-		/**
-		 * Gets a pointer to the data in the array.
-		 *
-		 * @returns A pointer to the data in the array.
-		 */
-		pointer data() { return m_data; }
-
-		/**
-		 * Gets a constant pointer to the data in the array.
-		 *
-		 * @returns A constant pointer to the data in the array.
-		 */
-		const_pointer data() const { return m_data; }
-
-		/**
-		 * Changes the dimensions of the array.
-		 *
-		 * @param new_size The new dimensions of the array.
-		 * @param preserve True to keep as much of the existing data as will fit in the new array, False to discard the existing data.
-		 */
-		void resize( const ivec2& new_size, bool preserve = false ) 
-		{
-			if (new_size == m_size) return; // Don't do anything if the sizes are the same.
-
-			pointer new_data = new value_type[ new_size.x * new_size.y ];
-			if ( m_data != nullptr )
-			{
-				if (!preserve)
-				{
-					// Just delete the data.
-					delete[] m_data;
-				}
-				else
-				{
-					// Copy the data.  Truncates the bottom or right side of the data if destination is smaller.
-					for ( sint32 i = 0; i < min(new_size.y, m_size.y); i++ )
-					{
-						std::copy( m_data + m_size.x * i, m_data + m_size.x * i + min( new_size.x, m_size.x ), new_data + m_size.x * i );
-					}
-					// ...then delete the original data.
-					delete[] m_data;
-				}
-			}
-			m_data = new_data;
-			m_size = new_size;
-		}
-
-		/**
-		 * Gets a pointer to the start of the array.
-		 *
-		 * @returns A pointer to the first position in the array.
-		 */
-		iterator       begin()       { return m_data; }
-
-		/**
-		 * Gets a constant pointer to the start of the array.
-		 *
-		 * @returns A constant pointer to the first position in the array.
-		 */
-		const_iterator begin() const { return m_data; }
-
-		/**
-		 * Gets a pointer to the end of the array.
-		 *
-		 * @returns A pointer to the end of the array.
-		 */
-		iterator       end()         { return m_data + ( m_size.x * m_size.y ); }
-
-		/**
-		 * Gets a constant pointer to the end of the array.
-		 *
-		 * @returns A constant pointer to the end of the array.
-		 */
-		const_iterator end() const   { return m_data + ( m_size.x * m_size.y ); }
-
-
-		/**
-		 * Looks up a position by X and Y value.
-		 *
-		 * @param x The X position of the array to look up.
-		 * @param y The Y position of the array to look up.
-		 * @returns A reference to the data at the indicated position.
-		 */
-		inline const_reference operator() ( sint32 x, sint32 y ) const
-		{
-			NV_ASSERT( x >= 0 && y >= 0 && x < m_size.x && y < m_size.y, "Bad parameters passed to array2d()" );
-			return m_data[ y * m_size.x + x ];
-		}
-
-		/**
-		 * Looks up a position by X and Y value.
-		 *
-		 * @param x The X position of the array to look up.
-		 * @param y The Y position of the array to look up.
-		 * @returns A reference to the data at the indicated position.
-		 */
-		inline reference operator() ( sint32 x, sint32 y )
-		{
-			NV_ASSERT( x >= 0 && y >= 0 && x < m_size.x && y < m_size.y, "Bad parameters passed to array2d()" );
-			return m_data[ y * m_size.x + x ];
-		}
-
-		/**
-		 * Looks up the given position in the array.
-		 *
-		 * @param c The position to look up.
-		 * @returns A reference to the data at the indicated position.
-		 */
-		inline const_reference operator[] ( const ivec2& c ) const 
-		{
-			NV_ASSERT( c.x >= 0 && c.y >= 0 && c.x < m_size.x && c.y < m_size.y, "Bad parameters passed to array2d[]" );
-			return m_data[ c.y * m_size.x + c.x ];
-		}
-
-		/**
-		 * Looks up the given position in the array.
-		 *
-		 * @param c The position to look up.
-		 * @returns A reference to the data at the indicated position.
-		 */
-		inline reference operator[] ( const ivec2& c )
-		{
-			NV_ASSERT( c.x >= 0 && c.y >= 0 && c.x < m_size.x && c.y < m_size.y, "Bad parameters passed to array2d[]" );
-			return m_data[ c.y * m_size.x + c.x ];
-		}
-
-		/**
-		 * Returns a copy of this array in a new instance.
-		 *
-		 * @returns An independent copy of this array.
-		 */
-		array2d<T> clone()
-		{
-			array2d<T> temp = new array2d<T>(m_size);
-			for ( sint32 i = 0; i < m_size.y; i++ )
-			{
-				std::copy( m_data + m_size.x * i, m_data + m_size.x * i + m_size.x, m_size.x * i );
-			}
-			return temp;
-		}
-
-		/**
-		 * Returns an array that represents a subset of the data in this array.
-		 *
-		 * @param start The upper and left bounds of data to retrieve.
-		 * @param size The width and height of the data to retrieve.
-		 * @returns A new 2D array containing the subset of data within the bounds specified.
-		 */
-		array2d<T> get_sub_array( const ivec2& start, const ivec2& size ) {	return get_sub_array( start.x, start.y, size.x, size.y ); }
-
-		/**
-		 * Returns an array that represents a subset of the data in this array.
-		 *
-		 * @param start_x The left bound of the data to retrieve.
-		 * @param start_y The upper bound of the data to retrieve.
-		 * @param size_x The width of the data to retrieve.
-		 * @param size_y The height of the data to retrieve.
-		 * @returns A new 2D array containing the subset of data within the bounds specified.
-		 */
-		array2d<T> get_sub_array( const sint32 start_x, const sint32 start_y, const sint32 size_x, const sint32 size_y)
-		{
-			// Make sure the parameters are correct and in bounds.
-			NV_ASSERT( start_x >= 0 && start_x < m_size.x && start_y >= 0 && start_y < m_size.y, "get_sub_array: start is out of bounds." );
-			NV_ASSERT( size_x >= 1 && size_x + start_x <= m_size.x && size_y >= 1 && size_y + start_y <= m_size.y, "get_sub_array: size is invalid." );
-			// Empty holder for the sub array of the correct size.
-			array2d<T> temp = new array2d<T>( size_x, size_y );
-			for ( sint32 i = start_y; i < start_y + size_y; i++ )
-			{
-				// Copy starts at start_x.
-				// Copy end is the end position.
-				// Destination is the start of the destination row.
-				//         Start                              End                                         Destination
-				std::copy( m_data + m_size().x * i + start_x, m_data + m_size().x * i + start_x + size_x, temp.m_data + temp.m_size().x * ( i - start_y ) );
-			}
-			return temp;
-		}
-
-		/**
-		 * Fills this array with another array.
-		 *
-		 * @param source The array to fill with.  If it does not fit in the destination it will be truncated.
-		 * @param dest_start The upper and left bounds of the data to fill.
-		 */
-		void set_sub_array( const array2d<T> source, const ivec2& dest_start )
-		{
-			return set_sub_array( source, dest_start.x, dest_start.y, 0, 0, source.m_size.x, source.m_size.y );
-		}
-
-		/**
-		 * Fills this array with a subset of another array.
-		 *
-		 * @param source The arrya to fill with.  If it does not fit in the destination it will be truncated.
-		 * @param dest_start The upper and left bounds of the data to fill.
-		 * @param size The size of the area to copy over.
-		 */
-		void set_sub_array( const array2d<T> source, const ivec2& dest_start, const ivec2& size )
-		{
-			return set_sub_array( source, dest_start.x, dest_start.y, 0, 0, size.x, size.y );
-		}
-
-
-		/**
-		 * Fills this array with a subset of another array.
-		 *
-		 * @param source The array to fill with.  If it does not fit in the destination it will be truncated.
-		 * @param dest_start The upper and left bounds of the data to fill.
-		 * @param source_start The upper and left bounds of the source to fill with.
-		 * @param size The size of the area to copy over.
-		 */
-		void set_sub_array( const array2d<T> source, const ivec2& dest_start, const ivec2& source_start, const ivec2& size )
-		{
-			return set_sub_array( source, dest_start.x, dest_start.y, source_start.x, source_start.y, size.x, size.y );
-		}
-
-		/**
-		 * Fills this array with another array.
-		 *
-		 * @param source The array to fill with.  If it does not fit in the area to fill, it will be truncated.
-		 * @param dest_start_x The left bound of the data to fill.
-		 * @param dest_start_y The upper bound of the data to fill.
-		 */
-		void set_sub_array( const array2d<T> source, const sint32 dest_start_x, const sint32 dest_start_y )
-		{
-			return set_sub_array( source, dest_start_x, dest_start_y, 0, 0, source.m_size.x, source.m_size.y );
-		}
-
-		/**
-		 * Fills this array with another array.
-		 *
-		 * @param source The array to fill with.  If it does not fit in the area to fill, it will be truncated.
-		 * @param dest_start_x The left bound of the data to fill.
-		 * @param dest_start_y The upper bound of the data to fill.
-		 * @param size_x The width of the area to copy over.
-		 * @param size_y The height of the area to copy over.
-		 */
-		void set_sub_array( const array2d<T> source, const sint32 dest_start_x, const sint32 dest_start_y, const sint32 size_x, const sint32 size_y )
-		{
-			return set_sub_array( source, dest_start_x, dest_start_y, 0, 0, size_x, size_y );
-		}
-
-		/**
-		 * Fills this array with a subset of another array.
-		 *
-		 * @param source The array to fill with.  If it does not fit in the area to fill, it will be truncated.
-		 * @param dest_start_x The left bound of the data to fill.
-		 * @param dest_start_y The upper bound of the data to fill.
-		 * @param source_start_x The left bound of the source to fill with.
-		 * @param source_start_y The upper bound of the source to fill with.
-		 * @param size_x The width of the area to copy over.
-		 * @param size_y The height of the area to copy over.
-		 */
-		void set_sub_array( const array2d<T> source, const sint32 dest_start_x, const sint32 dest_start_y, const sint32 source_start_x, const sint32 source_start_y, const sint32 size_x, const sint32 size_y )
-		{
-			// Start by checking the parameters.  Make sure nothing is out of bounds.
-			NV_ASSERT( source != nullptr, "set_sub_array: no source defined." );
-			NV_ASSERT( dest_start_x >= 0 && dest_start_x < m_size.x && dest_start_y >= 0 && dest_start_y < m_size.y, "set_sub_array: destination start is out of bounds." );
-			NV_ASSERT( source_start_x >= 0 && source_start_x < source.m_size.x && source_start_y >= 0 && source_start_y < source.m_size.y, "set_sub_array: source start is out of bounds." );
-			NV_ASSERT( size_x >= 1 && size_y >= 1, "set_sub_array: invalid size specified." ); // If size is 0, nothing would be copied in the first place.
-		
-			// Warn when copied data is truncated.
-			// If the end of the copied area is beyond the bounds of the destination array, data will be truncated.
-			if ( dest_start_x + min(size_x, source.m_size.x - source_start_x) > m_size.x || dest_start_y + min(size_y, source.m_size.y - source_start_y) > m_size.y )
-			{
-				NV_LOG( LOG_WARNING, "set_sub_array: Source area does not fit in the destination area.  Data will be truncated." );
-			}
-		
-			// Copy into THIS array from source the following.
-			// Highest row is either the size limit or the end of either array, whichever is smaller.
-			for ( uint32 i = 0; i < min( size_y , min ( m_size.y - dest_start_y, source.m_size.y - source_start_y ) ); i++ )
-			{
-				// Copy the indicated row.
-				// The start position is the beginning of the current row (which is source_start_y + i), offset by source_start_x.
-				// The end position is either the size limit or the end of either array, whichever is smaller.
-				// Destination start is the beginning of the current destination row (which is dest_start_y + i), offset by dest_start_x.
-				std:copy( source.m_data + ( source_start_y + i ) * source.m_size.x + source_start_x,  // Source Start
-						  source.m_data + ( source_start_y + i ) * source.m_size.x + min( source.m_size.x, min( source_start_x + size_x, source_start_x + m_size.x - dest_start_x ) ), // Source End
-						  m_data + (dest_start_y + i) * m_size.x + dest_start_x ); // Destination Start
-			}
-		}
-
-		/**
-		 * Destructor.
-		 */
-		~array2d()
-		{
-			if ( m_data != nullptr )
-			{
-				delete[] m_data;
-			}
-		}
-	protected:
-		pointer m_data; ///< Pointer to the data.
-		ivec2   m_size; ///< Allocated size of the data.
-	};
-
-}
-
-#endif // NV_ARRAY2D_HH
Index: unk/nv/common.hh
===================================================================
--- /trunk/nv/common.hh	(revision 318)
+++ 	(revision )
@@ -1,229 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_COMMON_HH
-#define NV_COMMON_HH
-
-// NV Library version
-#define NV_VERSION_MAJOR 0
-#define NV_VERSION_MINOR 1
-#define NV_VERSION_PATCH 0
-#define NV_VERSION    (NV_VERSION_MAJOR << 16) | (NV_VERSION_MINOR << 8) | NV_VERSION_PATCH)
-
-// Platform
-#define NV_WINDOWS        1
-#define NV_LINUX          2
-#define NV_APPLE          3
-
-// Compiler
-#define NV_MSVC           1
-#define NV_GNUC           2
-#define NV_CLANG          3
-
-// Endianess
-#define NV_LITTLEENDIAN   1
-#define NV_BIGENDIAN      2
-
-// Bits
-#define NV_32BIT          1
-#define NV_64BIT          2
-
-// Assumption
-#define NV_ENDIANESS NV_LITTLEENDIAN
-
-// Platform detection
-#if defined( __WIN32__ ) || defined( _WIN32 )
-#define NV_PLATFORM NV_WINDOWS
-#elif defined( __APPLE_CC__)
-#define NV_PLATFORM NV_APPLE
-#else
-#define NV_PLATFORM NV_LINUX
-#endif
-
-// Compiler detection
-#if defined( _MSC_VER )
-#define NV_COMPILER NV_MSVC
-#define NV_COMP_VER _MSC_VER
-#elif defined( __clang__ )
-#define NV_COMPILER NV_CLANG
-#define NV_COMP_VER (((__clang_major__)*100) + (__clang_minor__*10) + __clang_patchlevel__)
-#elif defined( __GNUC__ )
-#define NV_COMPILER NV_GNUC
-#define NV_COMP_VER (((__GNUC__)*100) + (__GNUC_MINOR__*10) + __GNUC_PATCHLEVEL__)
-#else
-#error "Unknown compiler!"
-#endif
-
-// Architecture detection
-#if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__)
-#define NV_ARCHITECTURE NV_64BIT
-#elif defined(__ia64__) || defined(__s390__) || defined(__s390x__)
-#define NV_ARCHITECTURE NV_64BIT
-#else
-#define NV_ARCHITECTURE NV_32BIT
-#endif
-
-// Platform specific settings.
-#if NV_PLATFORM == NV_WINDOWS
-#ifdef _DEBUG
-#define NV_DEBUG 1
-#else
-#define NV_DEBUG 0
-#endif
-#endif
-
-#if NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
-#ifdef DEBUG
-#define NV_DEBUG 1
-#else
-#define NV_DEBUG 0
-#endif
-#endif
-
-#if NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
-#define NV_POSIX
-#endif
-
-#if NV_COMPILER == NV_MSVC && NV_COMP_VER < 1600
-#error "MSVC 2012+ required!"
-#endif
-
-#if NV_COMPILER == NV_GNUC && NV_COMP_VER < 460
-#error "GCC 4.6+ required!"
-#endif
-
-#if NV_COMPILER == NV_CLANG && NV_COMP_VER < 320
-#error "clang 3.2+ required!"
-#endif
-
-#if NV_COMPILER == NV_MSVC 
-#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
-#pragma warning( disable : 4510 ) // default constructor could not be generated
-#pragma warning( disable : 4610 ) // object 'class' can never be instantiated - user-defined constructor required
-#undef _SCL_SECURE_NO_WARNINGS // to prevent redefining
-#define _SCL_SECURE_NO_WARNINGS
-#endif
-
-#include <typeinfo>
-#include <iterator>
-#include <cstddef>
-#include <cstdint>
-#include <cassert>
-#include <nv/logging.hh>
-
-#define NV_STRINGIZE_DETAIL(x) #x
-#define NV_STRINGIZE(x) NV_STRINGIZE_DETAIL(x)
-
-#if NV_COMPILER == NV_MSVC
-#define NV_DEPRECATED(func) __declspec(deprecated) func
-#elif NV_COMPILER == NV_GNUC || NV_COMPILER == NV_CLANG
-#define NV_DEPRECATED(func) func __attribute__ ((deprecated))
-#else 
-#define NV_DEPRECATED(func) func
-#endif 
-
-#define NV_UNUSED(x) (void)(x)
-#define NV_ASSERT(cond, msg) assert( (cond) && msg )
-#define NV_THROW(eobj, ...) { \
-	NV_LOG( nv::LOG_ERROR, __FILE__ " line " NV_STRINGIZE(__LINE__) " - exception thrown - " #eobj ); \
-	throw eobj( __VA_ARGS__ ); \
-} 
-
-// MSVC and GCC is too stupid to notice fully covered enums, clang 
-// is picky about it
-#if NV_COMPILER == NV_CLANG
-#define NV_RETURN_COVERED_DEFAULT( value ) 
-#else
-#define NV_RETURN_COVERED_DEFAULT( value ) default : return value
-#endif
-
-#define NV_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
-#define NV_SAFE_ARRAY( arr, idx, def ) ( index < NV_COUNT_OF(arr) ? (arr)[idx] : (def) )
-
-namespace nv
-{
-	namespace lua
-	{
-		class state;
-	}
-
-	// Typedefs for fixed size types.
-	typedef int8_t  sint8;
-	typedef int16_t sint16;
-	typedef int32_t sint32;
-	typedef int64_t sint64;
-
-	typedef uint8_t  uint8;
-	typedef uint16_t uint16;
-	typedef uint32_t uint32;
-	typedef uint64_t uint64;
-
-	typedef unsigned char  char8;
-	typedef unsigned short char16;
-	typedef unsigned long  char32;
-
-	typedef float  f32;
-	typedef double f64;
-
-	typedef uint64 uid;
-
-	struct empty_type {};
-
-	template < int a, int b, int c, int d >
-
-	struct four_cc
-	{
-		static const unsigned int value = (((((d << 8) | c) << 8) | b) << 8) | a;
-	};
-
-	class noncopyable
-	{
-	protected:
-// 		noncopyable() = default;
-// 		~noncopyable() = default;
-// 		noncopyable( const noncopyable& ) = delete;
-// 		noncopyable& operator=( const noncopyable& ) = delete;
-		noncopyable() {}
-		~noncopyable() {}
-	private:
-		noncopyable( const noncopyable& );
-		noncopyable& operator=( const noncopyable& );
-	};
-
-
-} // namespace nv
-
-template <typename OBJ, typename T> 
-inline size_t offset_of(T OBJ::*ptr)
-{
-	return ((size_t)&(((OBJ*)0)->*ptr));
-}
-
-template <typename T, typename U>
-inline T* down_cast(U* x)
-{
-#if NV_DEBUG
-	T* p = dynamic_cast<T*>(x);
-	if (p == 0)
-	{
-#ifdef NV_LOG
-		NV_THROW( std::bad_cast );
-#endif
-	}
-
-	return p;
-#else
-	return static_cast<T*>(x);
-#endif
-}
-
-template <typename T, typename U>
-T narrow_cast(const U& a)
-{
-	return static_cast<T>(a & T(-1) );
-}
-
-#endif // NV_COMMON_HH
Index: unk/nv/config.hh
===================================================================
--- /trunk/nv/config.hh	(revision 318)
+++ 	(revision )
@@ -1,12 +1,0 @@
-// Copyright (C) 2012 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_CONFIG_HH
-#define NV_CONFIG_HH
-
-#define NV_LIB_STATIC  1
-#define NV_LIB_SHARED  2
-#define NV_LIB_DYNAMIC 3
-
-#endif // NV_CONFIG_HH
Index: /trunk/nv/core/any.hh
===================================================================
--- /trunk/nv/core/any.hh	(revision 319)
+++ /trunk/nv/core/any.hh	(revision 319)
@@ -0,0 +1,154 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file any.hh
+ * @author Kornel Kisielewicz
+ * @brief any type
+ *
+ * based on http://www.two-sdg.demon.co.uk/curbralan/papers/ValuedConversions.pdf
+ */
+
+#ifndef NV_CORE_ANY_HH
+#define NV_CORE_ANY_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/type_traits.hh>
+
+namespace nv
+{
+	
+	class any
+	{
+	public:
+		any() : m_content( nullptr ) {}
+		
+		any( const any& other )
+			: m_content( other.m_content ? other.m_content->clone() : nullptr )
+		{}
+
+		template< typename T >
+		any( const T& value )
+			: m_content( new holder<T>( value ) )
+		{}
+
+		any( any&& other ) 
+			: m_content( other.m_content )
+		{}
+
+		template< typename T >
+		any( T&& value )
+			: m_content( new holder<T>( std::forward<T>(value) ) )
+		{}
+
+		~any() 
+		{ 
+			delete m_content; 
+		}
+
+		any& swap( any& rhs )
+		{
+			std::swap( m_content, rhs.m_content );
+			return *this;
+		}
+
+		any& operator=( const any& rhs )
+		{
+			return swap( any( rhs ) );
+		}
+
+		any& operator=( any&& rhs )
+		{
+			swap( rhs );
+			any().swap( rhs );
+			return *this;
+		}
+
+		template < typename T >
+		any& operator= ( T&& rhs )
+		{
+			any( std::forward<T>(rhs) ).swap(*this);
+			return *this;
+		}
+
+		operator const void* () const
+		{
+			return m_content;
+		}
+
+		template< typename T >
+		bool copy_to( T& value ) const
+		{
+			const T* copyable = to_ptr<T>();
+			if ( copyable ) value = *copyable;
+			return copyable;
+		}
+		template< typename T >
+		const T* to_ptr() const
+		{
+			return type_info() == typeid(T) ? &static_cast< holder<T> *>(m_content)->held				: nullptr;
+		}
+
+		bool empty() const
+		{
+			return !m_content;
+		}
+
+		void clear()
+		{
+			any().swap(*this);
+		}
+
+		const std::type_info &type_info() const
+		{
+			return m_content ? m_content->type_info() : typeid(void);
+		}
+	private:
+		class placeholder
+		{
+		public:
+			virtual const std::type_info& type_info() const = 0;
+			virtual placeholder *clone() const = 0;
+			virtual ~placeholder() {}
+		};
+
+		template< typename T >
+		class holder : public placeholder
+		{
+		public:
+			holder( const T& value ) : held(value)
+			{
+			}
+			holder( T&& value ) : held(std::forward<T>(value))
+			{
+			}
+			virtual const std::type_info &type_info() const
+			{
+				return typeid(T);
+			}
+			virtual placeholder *clone() const
+			{
+				return new holder(held);
+			}
+			const T held;
+		};
+		placeholder *m_content;
+	};
+
+	inline void swap( any& lhs, any& rhs )
+	{
+		lhs.swap(rhs);
+	}
+
+	template< typename T >
+	T any_cast( const any& operand )
+	{
+		const T* result = operand.to_ptr<T>();
+		return result ? *result : throw std::bad_cast();
+	}
+}
+
+#endif // NV_CORE_ANY_HH
Index: /trunk/nv/core/array.hh
===================================================================
--- /trunk/nv/core/array.hh	(revision 319)
+++ /trunk/nv/core/array.hh	(revision 319)
@@ -0,0 +1,193 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file array.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief exception free array classes
+ */
+
+#ifndef NV_CORE_ARRAY_HH
+#define NV_CORE_ARRAY_HH
+
+#include <nv/core/common.hh>
+#include <vector>
+#include <array>
+
+namespace nv
+{
+	namespace detail
+	{
+		template < typename T >
+		class array_base
+		{
+		public:
+			typedef T              value_type;
+			typedef T*             iterator;
+			typedef const T*       const_iterator;
+			typedef T&             reference;
+			typedef const T&       const_reference;
+			typedef std::size_t    size_type;
+			typedef std::ptrdiff_t difference_type;
+
+			typedef std::reverse_iterator<iterator>       reverse_iterator;
+			typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
+		};
+	}
+
+	using std::vector;
+	using std::array;
+
+	template< class T, std::size_t N >
+	class static_array : public detail::array_base<T>
+	{
+	public:
+		iterator        begin()        { return m_data; }
+		const_iterator  begin()  const { return m_data; }
+		const_iterator  cbegin() const { return m_data; }
+
+		iterator        end()        { return m_data+N; }
+		const_iterator  end()  const { return m_data+N; }
+		const_iterator  cend() const { return m_data+N; }
+
+		reverse_iterator rbegin()              { return reverse_iterator( end() ); }
+		const_reverse_iterator rbegin() const  { return const_reverse_iterator( end() ); }
+		const_reverse_iterator crbegin() const { return const_reverse_iterator( end() ); }
+
+		reverse_iterator rend()                { return reverse_iterator( begin() ); }
+		const_reverse_iterator rend() const    { return const_reverse_iterator( begin() ); }
+		const_reverse_iterator crend() const   { return const_reverse_iterator( begin() ); }
+
+		reference operator[]( size_type i ) 
+		{ 
+			NV_ASSERT( i < N, "Out of range" ); 
+			return m_data[i];
+		}
+
+		const_reference operator[]( size_type i ) const 
+		{     
+			NV_ASSERT( i < N, "Out of range" ); 
+			return m_data[i]; 
+		}
+
+		reference       front()       { return m_data[0]; }
+		const_reference front() const { return m_data[0]; }
+		reference       back()        { return m_data[N-1]; }
+		const_reference back() const  { return m_data[N-1]; }
+
+		static size_type size()     { return N; }
+		static bool      empty()    { return false; }
+		static size_type max_size() { return N; }
+
+		const value_type* data() const { return m_data; }
+		value_type*       data()       { return m_data; }
+
+		size_type   raw_size() const { return N * ELEMENT_SIZE; }
+		const char* raw_data() const { return (const char*)m_data; }
+		char*       raw_data()       { return (char*)m_data; }
+
+		void assign( const value_type& value ) { std::fill_n( begin(), size(), value ); }
+
+		static const size_type SIZE = N;
+		static const size_type ELEMENT_SIZE = sizeof(T);
+	public:
+		value_type m_data[N];
+	};
+
+	template< class T >
+	class dynamic_array : public detail::array_base<T>
+	{
+	public:
+		dynamic_array() 
+			: m_data( nullptr ), m_size(0) {}
+		explicit dynamic_array( size_type new_size )
+			: m_data( new value_type[ new_size ] ), m_size( new_size ) {}
+		dynamic_array( const value_type& value, size_type size )
+			: m_data( nullptr ), m_size(0) { assign( value, size ); }
+		dynamic_array( const_iterator values, size_type size )
+			: m_data( nullptr ), m_size(0) { assign( values, size ); }
+
+		void resize( size_type new_size )
+		{
+			if ( new_size != m_size ) 
+			{
+				value_type* old_data = m_data;
+				m_data = new_size > 0 ? new value_type[ new_size ] : nullptr;
+				if ( old_data && m_data )
+				{
+					std::copy_n( old_data, new_size > m_size ? m_size : new_size, m_data );
+				}
+				delete[] old_data;
+				m_size = new_size;
+			}
+		}
+
+		iterator        begin()        { return m_data; }
+		const_iterator  begin()  const { return m_data; }
+		const_iterator  cbegin() const { return m_data; }
+
+		iterator        end()        { return m_data+m_size; }
+		const_iterator  end()  const { return m_data+m_size; }
+		const_iterator  cend() const { return m_data+m_size; }
+
+		reverse_iterator rbegin()              { return reverse_iterator( end() ); }
+		const_reverse_iterator rbegin() const  { return const_reverse_iterator( end() ); }
+		const_reverse_iterator crbegin() const { return const_reverse_iterator( end() ); }
+
+		reverse_iterator rend()                { return reverse_iterator( begin() ); }
+		const_reverse_iterator rend() const    { return const_reverse_iterator( begin() ); }
+		const_reverse_iterator crend() const   { return const_reverse_iterator( begin() ); }
+
+		reference operator[]( size_type i ) 
+		{ 
+			NV_ASSERT( i < m_size, "Out of range" ); 
+			return m_data[i];
+		}
+
+		const_reference operator[]( size_type i ) const 
+		{     
+			NV_ASSERT( i < m_size, "Out of range" ); 
+			return m_data[i]; 
+		}
+
+		reference       front()       { return m_data[0]; }
+		const_reference front() const { return m_data[0]; }
+		reference       back()        { return m_data[m_size-1]; }
+		const_reference back() const  { return m_data[m_size-1]; }
+
+		size_type        size() const     { return m_size; }
+		bool             empty() const    { return m_size == 0; }
+		static size_type max_size()       { return std::numeric_limits< size_type >::max(); }
+		const value_type* data() const { return m_data; }
+		value_type*       data()       { return m_data; }
+
+		size_type   raw_size() const { return m_size * ELEMENT_SIZE; }
+		const char* raw_data() const { return (const char*)m_data; }
+		char*       raw_data()       { return (char*)m_data; }
+
+		void assign( const value_type& value ) { std::fill_n( begin(), size(), value ); }
+		void assign( const value_type& value, size_type new_size ) 
+		{
+			resize( new_size );
+			std::fill_n( begin(), size(), value );
+		}
+		void assign( const_iterator values, size_type new_size )
+		{
+			resize( new_size );
+			std::copy_n( values, size(), m_data );
+		}
+
+		~dynamic_array() { delete[] m_data; }
+
+		static const size_type ELEMENT_SIZE = sizeof(T);
+	public:
+		value_type* m_data;
+		size_type   m_size;
+	};
+
+}
+
+#endif // NV_CORE_ARRAY_HH
Index: /trunk/nv/core/array2d.hh
===================================================================
--- /trunk/nv/core/array2d.hh	(revision 319)
+++ /trunk/nv/core/array2d.hh	(revision 319)
@@ -0,0 +1,362 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file array2d.hh
+ * @author Kornel Kisielewicz
+ * @brief 2D array
+ */
+
+// TODO: make it work with the stl allocator
+
+#ifndef NV_CORE_ARRAY2D_HH
+#define NV_CORE_ARRAY2D_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+#include <nv/core/range.hh>
+
+namespace nv
+{
+	typedef ivec2 coord2d;
+
+	template < typename T >
+	class array2d
+	{
+	public:
+		typedef T                 value_type;
+		typedef value_type&       reference;
+		typedef const value_type& const_reference;
+		typedef value_type*       pointer;
+		typedef const value_type* const_pointer;
+		typedef pointer           iterator;
+		typedef const_pointer     const_iterator;
+
+		/**
+		 * Creates a new 2D array.
+		 */
+		array2d() : m_data( nullptr ), m_size() {}
+
+		/**
+		 * Creates a new 2D array.
+		 *
+		 * @param asize The dimensions of the new array.
+		 */
+		array2d( const ivec2& asize ) : m_data( nullptr ), m_size() { resize( asize ); }
+
+		/**
+		 * Creates a new 2D array.
+		 *
+		 * @param asize_x The width of the new array.
+		 * @param asize_y The height of the new array.
+		 */
+		array2d( const sint32 asize_x, const sint32 asize_y ) : m_data( nullptr ), m_size() { resize( new ivec2( asize_x, asize_y ) ); }
+		
+		/**
+		 * Gets the dimensions of the array.
+		 *
+		 * @returns The size of the array.
+		 */
+		const ivec2& size() const { return m_size; }
+
+		/**
+		 * Gets a pointer to the data in the array.
+		 *
+		 * @returns A pointer to the data in the array.
+		 */
+		pointer data() { return m_data; }
+
+		/**
+		 * Gets a constant pointer to the data in the array.
+		 *
+		 * @returns A constant pointer to the data in the array.
+		 */
+		const_pointer data() const { return m_data; }
+
+		/**
+		 * Changes the dimensions of the array.
+		 *
+		 * @param new_size The new dimensions of the array.
+		 * @param preserve True to keep as much of the existing data as will fit in the new array, False to discard the existing data.
+		 */
+		void resize( const ivec2& new_size, bool preserve = false ) 
+		{
+			if (new_size == m_size) return; // Don't do anything if the sizes are the same.
+
+			pointer new_data = new value_type[ new_size.x * new_size.y ];
+			if ( m_data != nullptr )
+			{
+				if (!preserve)
+				{
+					// Just delete the data.
+					delete[] m_data;
+				}
+				else
+				{
+					// Copy the data.  Truncates the bottom or right side of the data if destination is smaller.
+					for ( sint32 i = 0; i < min(new_size.y, m_size.y); i++ )
+					{
+						std::copy( m_data + m_size.x * i, m_data + m_size.x * i + min( new_size.x, m_size.x ), new_data + m_size.x * i );
+					}
+					// ...then delete the original data.
+					delete[] m_data;
+				}
+			}
+			m_data = new_data;
+			m_size = new_size;
+		}
+
+		/**
+		 * Gets a pointer to the start of the array.
+		 *
+		 * @returns A pointer to the first position in the array.
+		 */
+		iterator       begin()       { return m_data; }
+
+		/**
+		 * Gets a constant pointer to the start of the array.
+		 *
+		 * @returns A constant pointer to the first position in the array.
+		 */
+		const_iterator begin() const { return m_data; }
+
+		/**
+		 * Gets a pointer to the end of the array.
+		 *
+		 * @returns A pointer to the end of the array.
+		 */
+		iterator       end()         { return m_data + ( m_size.x * m_size.y ); }
+
+		/**
+		 * Gets a constant pointer to the end of the array.
+		 *
+		 * @returns A constant pointer to the end of the array.
+		 */
+		const_iterator end() const   { return m_data + ( m_size.x * m_size.y ); }
+
+
+		/**
+		 * Looks up a position by X and Y value.
+		 *
+		 * @param x The X position of the array to look up.
+		 * @param y The Y position of the array to look up.
+		 * @returns A reference to the data at the indicated position.
+		 */
+		inline const_reference operator() ( sint32 x, sint32 y ) const
+		{
+			NV_ASSERT( x >= 0 && y >= 0 && x < m_size.x && y < m_size.y, "Bad parameters passed to array2d()" );
+			return m_data[ y * m_size.x + x ];
+		}
+
+		/**
+		 * Looks up a position by X and Y value.
+		 *
+		 * @param x The X position of the array to look up.
+		 * @param y The Y position of the array to look up.
+		 * @returns A reference to the data at the indicated position.
+		 */
+		inline reference operator() ( sint32 x, sint32 y )
+		{
+			NV_ASSERT( x >= 0 && y >= 0 && x < m_size.x && y < m_size.y, "Bad parameters passed to array2d()" );
+			return m_data[ y * m_size.x + x ];
+		}
+
+		/**
+		 * Looks up the given position in the array.
+		 *
+		 * @param c The position to look up.
+		 * @returns A reference to the data at the indicated position.
+		 */
+		inline const_reference operator[] ( const ivec2& c ) const 
+		{
+			NV_ASSERT( c.x >= 0 && c.y >= 0 && c.x < m_size.x && c.y < m_size.y, "Bad parameters passed to array2d[]" );
+			return m_data[ c.y * m_size.x + c.x ];
+		}
+
+		/**
+		 * Looks up the given position in the array.
+		 *
+		 * @param c The position to look up.
+		 * @returns A reference to the data at the indicated position.
+		 */
+		inline reference operator[] ( const ivec2& c )
+		{
+			NV_ASSERT( c.x >= 0 && c.y >= 0 && c.x < m_size.x && c.y < m_size.y, "Bad parameters passed to array2d[]" );
+			return m_data[ c.y * m_size.x + c.x ];
+		}
+
+		/**
+		 * Returns a copy of this array in a new instance.
+		 *
+		 * @returns An independent copy of this array.
+		 */
+		array2d<T> clone()
+		{
+			array2d<T> temp = new array2d<T>(m_size);
+			for ( sint32 i = 0; i < m_size.y; i++ )
+			{
+				std::copy( m_data + m_size.x * i, m_data + m_size.x * i + m_size.x, m_size.x * i );
+			}
+			return temp;
+		}
+
+		/**
+		 * Returns an array that represents a subset of the data in this array.
+		 *
+		 * @param start The upper and left bounds of data to retrieve.
+		 * @param size The width and height of the data to retrieve.
+		 * @returns A new 2D array containing the subset of data within the bounds specified.
+		 */
+		array2d<T> get_sub_array( const ivec2& start, const ivec2& size ) {	return get_sub_array( start.x, start.y, size.x, size.y ); }
+
+		/**
+		 * Returns an array that represents a subset of the data in this array.
+		 *
+		 * @param start_x The left bound of the data to retrieve.
+		 * @param start_y The upper bound of the data to retrieve.
+		 * @param size_x The width of the data to retrieve.
+		 * @param size_y The height of the data to retrieve.
+		 * @returns A new 2D array containing the subset of data within the bounds specified.
+		 */
+		array2d<T> get_sub_array( const sint32 start_x, const sint32 start_y, const sint32 size_x, const sint32 size_y)
+		{
+			// Make sure the parameters are correct and in bounds.
+			NV_ASSERT( start_x >= 0 && start_x < m_size.x && start_y >= 0 && start_y < m_size.y, "get_sub_array: start is out of bounds." );
+			NV_ASSERT( size_x >= 1 && size_x + start_x <= m_size.x && size_y >= 1 && size_y + start_y <= m_size.y, "get_sub_array: size is invalid." );
+			// Empty holder for the sub array of the correct size.
+			array2d<T> temp = new array2d<T>( size_x, size_y );
+			for ( sint32 i = start_y; i < start_y + size_y; i++ )
+			{
+				// Copy starts at start_x.
+				// Copy end is the end position.
+				// Destination is the start of the destination row.
+				//         Start                              End                                         Destination
+				std::copy( m_data + m_size().x * i + start_x, m_data + m_size().x * i + start_x + size_x, temp.m_data + temp.m_size().x * ( i - start_y ) );
+			}
+			return temp;
+		}
+
+		/**
+		 * Fills this array with another array.
+		 *
+		 * @param source The array to fill with.  If it does not fit in the destination it will be truncated.
+		 * @param dest_start The upper and left bounds of the data to fill.
+		 */
+		void set_sub_array( const array2d<T> source, const ivec2& dest_start )
+		{
+			return set_sub_array( source, dest_start.x, dest_start.y, 0, 0, source.m_size.x, source.m_size.y );
+		}
+
+		/**
+		 * Fills this array with a subset of another array.
+		 *
+		 * @param source The arrya to fill with.  If it does not fit in the destination it will be truncated.
+		 * @param dest_start The upper and left bounds of the data to fill.
+		 * @param size The size of the area to copy over.
+		 */
+		void set_sub_array( const array2d<T> source, const ivec2& dest_start, const ivec2& size )
+		{
+			return set_sub_array( source, dest_start.x, dest_start.y, 0, 0, size.x, size.y );
+		}
+
+
+		/**
+		 * Fills this array with a subset of another array.
+		 *
+		 * @param source The array to fill with.  If it does not fit in the destination it will be truncated.
+		 * @param dest_start The upper and left bounds of the data to fill.
+		 * @param source_start The upper and left bounds of the source to fill with.
+		 * @param size The size of the area to copy over.
+		 */
+		void set_sub_array( const array2d<T> source, const ivec2& dest_start, const ivec2& source_start, const ivec2& size )
+		{
+			return set_sub_array( source, dest_start.x, dest_start.y, source_start.x, source_start.y, size.x, size.y );
+		}
+
+		/**
+		 * Fills this array with another array.
+		 *
+		 * @param source The array to fill with.  If it does not fit in the area to fill, it will be truncated.
+		 * @param dest_start_x The left bound of the data to fill.
+		 * @param dest_start_y The upper bound of the data to fill.
+		 */
+		void set_sub_array( const array2d<T> source, const sint32 dest_start_x, const sint32 dest_start_y )
+		{
+			return set_sub_array( source, dest_start_x, dest_start_y, 0, 0, source.m_size.x, source.m_size.y );
+		}
+
+		/**
+		 * Fills this array with another array.
+		 *
+		 * @param source The array to fill with.  If it does not fit in the area to fill, it will be truncated.
+		 * @param dest_start_x The left bound of the data to fill.
+		 * @param dest_start_y The upper bound of the data to fill.
+		 * @param size_x The width of the area to copy over.
+		 * @param size_y The height of the area to copy over.
+		 */
+		void set_sub_array( const array2d<T> source, const sint32 dest_start_x, const sint32 dest_start_y, const sint32 size_x, const sint32 size_y )
+		{
+			return set_sub_array( source, dest_start_x, dest_start_y, 0, 0, size_x, size_y );
+		}
+
+		/**
+		 * Fills this array with a subset of another array.
+		 *
+		 * @param source The array to fill with.  If it does not fit in the area to fill, it will be truncated.
+		 * @param dest_start_x The left bound of the data to fill.
+		 * @param dest_start_y The upper bound of the data to fill.
+		 * @param source_start_x The left bound of the source to fill with.
+		 * @param source_start_y The upper bound of the source to fill with.
+		 * @param size_x The width of the area to copy over.
+		 * @param size_y The height of the area to copy over.
+		 */
+		void set_sub_array( const array2d<T> source, const sint32 dest_start_x, const sint32 dest_start_y, const sint32 source_start_x, const sint32 source_start_y, const sint32 size_x, const sint32 size_y )
+		{
+			// Start by checking the parameters.  Make sure nothing is out of bounds.
+			NV_ASSERT( source != nullptr, "set_sub_array: no source defined." );
+			NV_ASSERT( dest_start_x >= 0 && dest_start_x < m_size.x && dest_start_y >= 0 && dest_start_y < m_size.y, "set_sub_array: destination start is out of bounds." );
+			NV_ASSERT( source_start_x >= 0 && source_start_x < source.m_size.x && source_start_y >= 0 && source_start_y < source.m_size.y, "set_sub_array: source start is out of bounds." );
+			NV_ASSERT( size_x >= 1 && size_y >= 1, "set_sub_array: invalid size specified." ); // If size is 0, nothing would be copied in the first place.
+		
+			// Warn when copied data is truncated.
+			// If the end of the copied area is beyond the bounds of the destination array, data will be truncated.
+			if ( dest_start_x + min(size_x, source.m_size.x - source_start_x) > m_size.x || dest_start_y + min(size_y, source.m_size.y - source_start_y) > m_size.y )
+			{
+				NV_LOG( LOG_WARNING, "set_sub_array: Source area does not fit in the destination area.  Data will be truncated." );
+			}
+		
+			// Copy into THIS array from source the following.
+			// Highest row is either the size limit or the end of either array, whichever is smaller.
+			for ( uint32 i = 0; i < min( size_y , min ( m_size.y - dest_start_y, source.m_size.y - source_start_y ) ); i++ )
+			{
+				// Copy the indicated row.
+				// The start position is the beginning of the current row (which is source_start_y + i), offset by source_start_x.
+				// The end position is either the size limit or the end of either array, whichever is smaller.
+				// Destination start is the beginning of the current destination row (which is dest_start_y + i), offset by dest_start_x.
+				std:copy( source.m_data + ( source_start_y + i ) * source.m_size.x + source_start_x,  // Source Start
+						  source.m_data + ( source_start_y + i ) * source.m_size.x + min( source.m_size.x, min( source_start_x + size_x, source_start_x + m_size.x - dest_start_x ) ), // Source End
+						  m_data + (dest_start_y + i) * m_size.x + dest_start_x ); // Destination Start
+			}
+		}
+
+		/**
+		 * Destructor.
+		 */
+		~array2d()
+		{
+			if ( m_data != nullptr )
+			{
+				delete[] m_data;
+			}
+		}
+	protected:
+		pointer m_data; ///< Pointer to the data.
+		ivec2   m_size; ///< Allocated size of the data.
+	};
+
+}
+
+#endif // NV_CORE_ARRAY2D_HH
Index: /trunk/nv/core/common.hh
===================================================================
--- /trunk/nv/core/common.hh	(revision 319)
+++ /trunk/nv/core/common.hh	(revision 319)
@@ -0,0 +1,229 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_CORE_COMMON_HH
+#define NV_CORE_COMMON_HH
+
+// NV Library version
+#define NV_VERSION_MAJOR 0
+#define NV_VERSION_MINOR 1
+#define NV_VERSION_PATCH 0
+#define NV_VERSION    (NV_VERSION_MAJOR << 16) | (NV_VERSION_MINOR << 8) | NV_VERSION_PATCH)
+
+// Platform
+#define NV_WINDOWS        1
+#define NV_LINUX          2
+#define NV_APPLE          3
+
+// Compiler
+#define NV_MSVC           1
+#define NV_GNUC           2
+#define NV_CLANG          3
+
+// Endianess
+#define NV_LITTLEENDIAN   1
+#define NV_BIGENDIAN      2
+
+// Bits
+#define NV_32BIT          1
+#define NV_64BIT          2
+
+// Assumption
+#define NV_ENDIANESS NV_LITTLEENDIAN
+
+// Platform detection
+#if defined( __WIN32__ ) || defined( _WIN32 )
+#define NV_PLATFORM NV_WINDOWS
+#elif defined( __APPLE_CC__)
+#define NV_PLATFORM NV_APPLE
+#else
+#define NV_PLATFORM NV_LINUX
+#endif
+
+// Compiler detection
+#if defined( _MSC_VER )
+#define NV_COMPILER NV_MSVC
+#define NV_COMP_VER _MSC_VER
+#elif defined( __clang__ )
+#define NV_COMPILER NV_CLANG
+#define NV_COMP_VER (((__clang_major__)*100) + (__clang_minor__*10) + __clang_patchlevel__)
+#elif defined( __GNUC__ )
+#define NV_COMPILER NV_GNUC
+#define NV_COMP_VER (((__GNUC__)*100) + (__GNUC_MINOR__*10) + __GNUC_PATCHLEVEL__)
+#else
+#error "Unknown compiler!"
+#endif
+
+// Architecture detection
+#if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__)
+#define NV_ARCHITECTURE NV_64BIT
+#elif defined(__ia64__) || defined(__s390__) || defined(__s390x__)
+#define NV_ARCHITECTURE NV_64BIT
+#else
+#define NV_ARCHITECTURE NV_32BIT
+#endif
+
+// Platform specific settings.
+#if NV_PLATFORM == NV_WINDOWS
+#ifdef _DEBUG
+#define NV_DEBUG 1
+#else
+#define NV_DEBUG 0
+#endif
+#endif
+
+#if NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
+#ifdef DEBUG
+#define NV_DEBUG 1
+#else
+#define NV_DEBUG 0
+#endif
+#endif
+
+#if NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
+#define NV_POSIX
+#endif
+
+#if NV_COMPILER == NV_MSVC && NV_COMP_VER < 1600
+#error "MSVC 2012+ required!"
+#endif
+
+#if NV_COMPILER == NV_GNUC && NV_COMP_VER < 460
+#error "GCC 4.6+ required!"
+#endif
+
+#if NV_COMPILER == NV_CLANG && NV_COMP_VER < 320
+#error "clang 3.2+ required!"
+#endif
+
+#if NV_COMPILER == NV_MSVC 
+#pragma warning( disable : 4201 ) // nonstandard extension used : nameless struct/union
+#pragma warning( disable : 4510 ) // default constructor could not be generated
+#pragma warning( disable : 4610 ) // object 'class' can never be instantiated - user-defined constructor required
+#undef _SCL_SECURE_NO_WARNINGS // to prevent redefining
+#define _SCL_SECURE_NO_WARNINGS
+#endif
+
+#include <typeinfo>
+#include <iterator>
+#include <cstddef>
+#include <cstdint>
+#include <cassert>
+#include <nv/core/logging.hh>
+
+#define NV_STRINGIZE_DETAIL(x) #x
+#define NV_STRINGIZE(x) NV_STRINGIZE_DETAIL(x)
+
+#if NV_COMPILER == NV_MSVC
+#define NV_DEPRECATED(func) __declspec(deprecated) func
+#elif NV_COMPILER == NV_GNUC || NV_COMPILER == NV_CLANG
+#define NV_DEPRECATED(func) func __attribute__ ((deprecated))
+#else 
+#define NV_DEPRECATED(func) func
+#endif 
+
+#define NV_UNUSED(x) (void)(x)
+#define NV_ASSERT(cond, msg) assert( (cond) && msg )
+#define NV_THROW(eobj, ...) { \
+	NV_LOG( nv::LOG_ERROR, __FILE__ " line " NV_STRINGIZE(__LINE__) " - exception thrown - " #eobj ); \
+	throw eobj( __VA_ARGS__ ); \
+} 
+
+// MSVC and GCC is too stupid to notice fully covered enums, clang 
+// is picky about it
+#if NV_COMPILER == NV_CLANG
+#define NV_RETURN_COVERED_DEFAULT( value ) 
+#else
+#define NV_RETURN_COVERED_DEFAULT( value ) default : return value
+#endif
+
+#define NV_COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
+#define NV_SAFE_ARRAY( arr, idx, def ) ( index < NV_COUNT_OF(arr) ? (arr)[idx] : (def) )
+
+namespace nv
+{
+	namespace lua
+	{
+		class state;
+	}
+
+	// Typedefs for fixed size types.
+	typedef int8_t  sint8;
+	typedef int16_t sint16;
+	typedef int32_t sint32;
+	typedef int64_t sint64;
+
+	typedef uint8_t  uint8;
+	typedef uint16_t uint16;
+	typedef uint32_t uint32;
+	typedef uint64_t uint64;
+
+	typedef unsigned char  char8;
+	typedef unsigned short char16;
+	typedef unsigned long  char32;
+
+	typedef float  f32;
+	typedef double f64;
+
+	typedef uint64 uid;
+
+	struct empty_type {};
+
+	template < int a, int b, int c, int d >
+
+	struct four_cc
+	{
+		static const unsigned int value = (((((d << 8) | c) << 8) | b) << 8) | a;
+	};
+
+	class noncopyable
+	{
+	protected:
+// 		noncopyable() = default;
+// 		~noncopyable() = default;
+// 		noncopyable( const noncopyable& ) = delete;
+// 		noncopyable& operator=( const noncopyable& ) = delete;
+		noncopyable() {}
+		~noncopyable() {}
+	private:
+		noncopyable( const noncopyable& );
+		noncopyable& operator=( const noncopyable& );
+	};
+
+
+} // namespace nv
+
+template <typename OBJ, typename T> 
+inline size_t offset_of(T OBJ::*ptr)
+{
+	return ((size_t)&(((OBJ*)0)->*ptr));
+}
+
+template <typename T, typename U>
+inline T* down_cast(U* x)
+{
+#if NV_DEBUG
+	T* p = dynamic_cast<T*>(x);
+	if (p == 0)
+	{
+#ifdef NV_LOG
+		NV_THROW( std::bad_cast );
+#endif
+	}
+
+	return p;
+#else
+	return static_cast<T*>(x);
+#endif
+}
+
+template <typename T, typename U>
+T narrow_cast(const U& a)
+{
+	return static_cast<T>(a & T(-1) );
+}
+
+#endif // NV_CORE_COMMON_HH
Index: /trunk/nv/core/config.hh
===================================================================
--- /trunk/nv/core/config.hh	(revision 319)
+++ /trunk/nv/core/config.hh	(revision 319)
@@ -0,0 +1,12 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_CORE_CONFIG_HH
+#define NV_CORE_CONFIG_HH
+
+#define NV_LIB_STATIC  1
+#define NV_LIB_SHARED  2
+#define NV_LIB_DYNAMIC 3
+
+#endif // NV_CORE_CONFIG_HH
Index: /trunk/nv/core/exception.hh
===================================================================
--- /trunk/nv/core/exception.hh	(revision 319)
+++ /trunk/nv/core/exception.hh	(revision 319)
@@ -0,0 +1,46 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file exception.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief nv exception bases
+ */
+
+#ifndef NV_CORE_EXCEPTION_HH
+#define NV_CORE_EXCEPTION_HH
+
+#include <nv/core/common.hh>
+#include <string>
+#include <exception>
+#include <stdexcept>
+
+namespace nv
+{
+	/**
+	 * NV logic_error.
+	 *
+	 * Inherits std::logic_error.
+	 */
+	class logic_error : public std::logic_error
+	{
+	public:
+		explicit logic_error( const std::string& msg ) : std::logic_error( msg ) {}
+	};
+
+	/**
+	 * NV runtime_error.
+	 *
+	 * Inherits std::runtime_error.
+	 */
+	class runtime_error : public std::runtime_error
+	{
+	public:
+		explicit runtime_error( const std::string& msg ) : std::runtime_error( msg ) {}
+	};
+}
+
+#endif // NV_CORE_EXCEPTION_HH
Index: /trunk/nv/core/flags.hh
===================================================================
--- /trunk/nv/core/flags.hh	(revision 319)
+++ /trunk/nv/core/flags.hh	(revision 319)
@@ -0,0 +1,221 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file flags.hh
+ * @author Kornel Kisielewicz
+ * @brief flags
+ */
+
+#ifndef NV_CORE_FLAGS_HH
+#define NV_CORE_FLAGS_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/type_traits.hh>
+#include <nv/core/array.hh>
+
+namespace nv
+{
+	template < uint32 SIZE, typename T = uint32 >
+	class flags
+	{
+	public:
+		class reference
+		{
+			friend class flags<SIZE,T>;
+		public:
+			typedef bool value_type;
+			typedef T    index_type;
+
+			reference& operator=( value_type a_value )
+			{
+				m_flags->set( m_index, a_value );
+				return (*this);
+			}
+			reference& operator=( const reference& a_value )
+			{
+				m_flags->set( m_index, bool( a_value ) );
+				return (*this);
+			}
+			operator bool() const 
+			{
+				return m_flags->test( m_index );
+			}
+
+		private:
+			reference() : m_flags( nullptr ), m_index( index_type(0) ) {}
+
+			reference( flags<SIZE,T>* a_flags, index_type a_index )
+				: m_flags( a_flags ), m_index( a_index )
+			{	
+			}
+
+		private:
+			flags<SIZE,T>* m_flags;
+			index_type     m_index;
+		};
+
+		class enumerator
+		{
+			friend class flags<SIZE,T>;
+		public:
+			typedef T              index_type;
+			typedef T              value_type;
+			typedef T*             iterator;
+			typedef const T*       const_iterator;
+			typedef T&             reference;
+			typedef const T&       const_reference;
+			typedef std::size_t    size_type;
+			typedef std::ptrdiff_t difference_type;
+
+			T operator* () const { return m_index; }
+			T const* operator-> () const { return &m_index; }
+			bool operator== ( const enumerator& rhs ) const
+			{
+				return ( m_index == rhs.m_index ) && ( m_flags == rhs.m_flags );
+			}
+			bool operator!= ( const enumerator& rhs ) const
+			{
+				return !( *this == rhs );
+			}
+			
+			enumerator& operator++ () 
+			{
+				next();
+				return *this; 
+			}
+			enumerator operator++ (int) 
+			{
+				auto result = *this; 
+				++*this; 
+				return result;
+			}
+		protected:
+			enumerator() : m_flags( nullptr ), m_index( index_type(0) ) {}
+
+			enumerator( const flags<SIZE,T>* a_flags, index_type a_index )
+				: m_flags( a_flags ), m_index( a_index )
+			{	
+				if ( a_flags && !a_flags->test( a_index ) ) next();
+			}
+
+			void next()
+			{
+				if ( m_flags )
+				do 
+				{
+					if ( raw_index_type(m_index) >= SIZE ) { m_flags = nullptr; m_index = index_type(0); return; }
+					m_index = index_type((raw_index_type)m_index + 1);
+				} while ( !m_flags->test( m_index ) );
+			}
+
+			const flags<SIZE,T>* m_flags;
+			index_type           m_index;
+		};
+
+		typedef uint8     data_type;
+		typedef T         index_type;
+		typedef uint32 size_type;
+		typedef typename base_underlying_type<T>::type raw_index_type;
+
+		static const size_type data_type_size = sizeof( data_type ) * 8;
+		static const size_type data_count     = SIZE;
+		static const size_type data_size      = (SIZE+data_type_size-1) / data_type_size;
+
+		enumerator begin()  const { return enumerator( this, index_type(0) ); }
+		enumerator cbegin() const { return enumerator( this, index_type(0) ); }
+
+		enumerator end()  const { return enumerator(); }
+		enumerator cend() const { return enumerator(); }
+
+		flags()
+		{
+			reset();
+		}
+
+		explicit flags( const data_type* a_data )
+		{
+			assign( a_data );
+		}
+
+		void assign( const data_type* a_data )
+		{
+			std::copy( a_data, a_data + data_size, m_data );
+		}
+
+		void reset()
+		{
+			std::fill( m_data, m_data + data_size, 0 );
+		}
+
+		void include( index_type i )
+		{
+			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
+			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
+			m_data[ idx ] |= 1 << static_cast< data_type >( pos );
+		}
+
+		void exclude( index_type i )
+		{
+			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
+			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
+			m_data[ idx ] &= ~(1 << static_cast< data_type >( pos ) );
+		}
+
+		void set( index_type i, bool value )
+		{
+			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
+			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
+			if ( value )
+				m_data[ idx ] |= 1 << static_cast< data_type >( pos );
+			else
+				m_data[ idx ] &= ~(1 << static_cast< data_type >( pos ) );
+		}
+
+		bool test( index_type i ) const
+		{
+			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
+			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
+			return ( m_data[ idx ] & ( 1 << static_cast< data_type >( pos ) ) ) != 0;
+		}
+
+		const data_type* data() const
+		{
+			return m_data;
+		}
+
+		data_type* data()
+		{
+			return m_data;
+		}
+
+		size_type size() const
+		{
+			return data_count;
+		}
+
+		size_type capacity() const
+		{
+			return data_size;
+		}
+
+		bool operator[]( index_type idx ) const
+		{
+			return test( idx );
+		}
+
+		reference operator[]( index_type idx )
+		{
+			return reference( this, idx );
+		}
+
+	private:
+		data_type m_data[ data_size ];
+	};
+
+} // namespace nv
+
+#endif // NV_CORE_FLAGS_HH
Index: /trunk/nv/core/handle.hh
===================================================================
--- /trunk/nv/core/handle.hh	(revision 319)
+++ /trunk/nv/core/handle.hh	(revision 319)
@@ -0,0 +1,314 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file handle.hh
+ * @author Kornel Kisielewicz
+ */
+
+#ifndef NV_CORE_HANDLE_HH
+#define NV_CORE_HANDLE_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/array.hh>
+
+namespace nv
+{
+
+	template < 
+		typename T = uint32, 
+		unsigned IBITS = 16,
+		unsigned CBITS = 16,
+		typename TAG = void 
+	>
+	class handle
+	{
+	public:
+		typedef T value_type;
+		static const int INDEX_BITS   = IBITS;
+		static const int COUNTER_BITS = IBITS;
+		static const T MAX_INDEX   = (1 << IBITS) - 1;
+		static const T MAX_COUNTER = (1 << CBITS) - 1;
+
+		handle() : m_index(0), m_counter(0) {}
+
+		inline bool operator==(const handle& rhs) const {return m_index == rhs.m_index && m_counter == rhs.m_counter; }
+		inline bool operator!=(const handle& rhs) const {return !(*this == rhs);}
+
+		bool is_nil() const { return m_index == 0 && m_counter == 0; }
+		bool is_valid() const { return !is_nil(); }
+		T index() const { return m_index; }
+		size_t hash() const { return std::hash<T>()( m_counter << IBITS | m_index ); }
+	protected:
+		T m_index   : IBITS;
+		T m_counter : CBITS;
+
+		handle( T a_index, T a_counter ) : m_index( a_index ), m_counter( a_counter ) {}
+		template < typename H, typename I >
+		friend class index_store;
+	};
+
+
+
+	template < typename HANDLE, typename TINDEX = sint32 >
+	class index_store
+	{
+	public:
+		typedef HANDLE handle;
+		typedef TINDEX index_type;
+		typedef typename HANDLE::value_type value_type;
+
+		index_store() : m_first_free(-1), m_last_free(-1) {}
+
+		handle create_handle( index_type index )
+		{
+			value_type i       = get_free_entry();
+			m_entries[i].index = index;
+			m_entries[i].counter++;
+			return handle( i, m_entries[i].counter );
+		}
+
+		void free_handle( handle h )
+		{
+			m_entries[ h.m_index ].index     = -1;
+			m_entries[ h.m_index ].next_free = -1;
+			if ( m_last_free == -1 )
+			{
+				m_first_free = m_last_free = h.m_index;
+				return;
+			}
+			m_entries[ m_last_free ].next_free = h.m_index;
+			m_last_free = h.m_index;
+		}
+
+		void swap_indices( handle h1, handle h2 )
+		{
+			std::swap( m_entries[ h1.m_index ].index, m_entries[ h2.m_index ].index );
+		}
+
+		sint32 get_index( handle h ) const
+		{
+			return m_entries[ h.m_index ].counter == h.m_counter ? m_entries[ h.m_index ].index : -1;
+		}
+	private:
+		struct index_entry
+		{
+			index_type index;
+			value_type counter;
+			index_type next_free;
+
+			index_entry() : index(0), counter(0), next_free(-1) {}
+		};
+
+		value_type get_free_entry()
+		{
+			if ( m_first_free != -1 )
+			{
+				value_type result = (value_type)m_first_free;
+				m_first_free = m_entries[result].next_free;
+				m_entries[result].next_free = -1;
+				if ( m_first_free == -1 ) m_last_free = -1;
+				return result;
+			}
+			m_entries.emplace_back();
+			return value_type( m_entries.size() - 1 );
+		}
+
+		index_type m_first_free;
+		index_type m_last_free;
+		std::vector< index_entry > m_entries;
+	};
+
+	template < typename T, typename HANDLE = handle<>, typename TINDEX = sint32 >
+	class packed_indexed_array
+	{
+	public:
+		typedef HANDLE                   handle;
+		typedef TINDEX                   index_type;
+		typedef std::vector< T >         storage;
+		typedef T                        value_type;
+		typedef typename storage::iterator        iterator;
+		typedef typename storage::const_iterator  const_iterator;
+		typedef typename storage::reference       reference;
+		typedef typename storage::const_reference const_reference;
+
+		packed_indexed_array() {}
+		packed_indexed_array( uint32 reserve )
+		{
+			m_data.reserve( reserve );
+			m_indexes.reserve( reserve );
+		}
+
+		T* insert( handle h )
+		{
+			resize_indexes_to( h.index() );
+			m_indexes[ h.index() ] = m_data.size();
+			m_handles.push_back( h );
+			m_data.emplace_back();
+			return &(m_data.back());
+		}
+
+		bool exists( handle h )
+		{
+			if ( h.is_nil() || h.index() >= m_indexes.size() ) return false;
+			return m_indexes[ h.index() ] >= 0;		
+		}
+
+		T* get( handle h )
+		{
+			if ( h.is_nil() || h.index() >= m_indexes.size() ) return nullptr;
+			index_type i = m_indexes[ h.index() ];
+			return i >= 0 ? &(m_data[ i ]) : nullptr;
+		}
+
+		void remove( handle h )
+		{
+			handle swap_handle    = m_handles.back();
+			sint32 dead_eindex    = m_indexes[ h.index() ];
+			if ( dead_eindex != (sint32)m_data.size()-1 )
+			{
+				m_data[ dead_eindex ]            = m_data.back();
+				m_handles[ dead_eindex ]         = swap_handle;
+				m_indexes[ swap_handle.index() ] = dead_eindex;
+			}
+			m_data.pop_back();
+			m_handles.pop_back();
+			m_indexes[ h.index() ] = -1;
+		}
+
+		void clear()
+		{
+			m_data.clear();
+			m_handles.clear();
+			m_indexes.clear();
+		}
+
+		const value_type& operator[] ( index_type i ) const { return m_data[i]; }
+		value_type& operator[] ( index_type i ) { return m_data[i]; }
+		size_t size() const { return m_data.size(); }
+
+		iterator        begin()        { return m_data.begin(); }
+		const_iterator  begin()  const { return m_data.cbegin(); }
+		const_iterator  cbegin() const { return m_data.cbegin(); }
+
+		iterator        end()        { return m_data.end(); }
+		const_iterator  end()  const { return m_data.cend(); }
+		const_iterator  cend() const { return m_data.cend(); }
+
+	private:
+		void resize_indexes_to( index_type i )
+		{
+			index_type size = (index_type)m_indexes.size();
+			if ( i >= size )
+			{
+				if ( size == 0 ) size = 1;
+				while ( i >= size ) size = size * 2;
+				m_indexes.resize( size, -1 );
+			}
+		}
+
+		std::vector< T >          m_data;
+		std::vector< handle >     m_handles;
+		std::vector< index_type > m_indexes;
+	};
+
+
+	template < typename T, typename HANDLE = handle<>, typename TINDEX = sint32 >
+	class entity_store
+	{
+	public:
+		typedef HANDLE                   handle;
+		typedef TINDEX                   index_type;
+		typedef std::vector< T >         storage;
+		typedef T                        value_type;
+		typedef typename storage::iterator        iterator;
+		typedef typename storage::const_iterator  const_iterator;
+		typedef typename storage::reference       reference;
+		typedef typename storage::const_reference const_reference;
+
+		entity_store() {}
+
+		explicit entity_store( uint32 reserve )
+		{
+			m_handles.reserve( reserve );
+			m_data.reserve( reserve );
+		}
+
+		handle create()
+		{
+			m_data.emplace_back();
+			m_handles.push_back( m_indexes.create_handle( sint32( m_data.size() - 1 ) ) );
+			return m_handles.back();
+		}
+
+		const value_type* get( handle h ) const
+		{
+			if ( h.is_nil() ) return nullptr;
+			sint32 eindex = m_indexes.get_index( h );
+			return eindex >= 0 ? &(m_data[ eindex ]) : nullptr;
+		}
+
+		value_type* get( handle h )
+		{
+			if ( h.is_nil() ) return nullptr;
+			sint32 eindex = m_indexes.get_index( h );
+			return eindex >= 0 ? &(m_data[ eindex ]) : nullptr;
+		}
+
+		void destroy( handle e )
+		{
+			handle swap_handle    = m_handles.back();
+			sint32 dead_eindex    = m_indexes.get_index( e );
+			if ( dead_eindex != (sint32)m_data.size()-1 )
+			{
+				m_data[ dead_eindex ]    = m_data.back();
+				m_handles[ dead_eindex ] = m_handles.back();
+			}
+			m_data.pop_back();
+			m_handles.pop_back();
+			m_indexes.swap_indices( e, swap_handle );
+			m_indexes.free_handle( e );
+		}
+
+		handle get_handle( index_type i ) const { return m_handles[i]; }
+		const value_type& operator[] ( index_type i ) const { return m_data[i]; }
+		value_type& operator[] ( index_type i ) { return m_data[i]; }
+		size_t size() const { return m_data.size(); }
+
+		iterator        begin()        { return m_data.begin(); }
+		const_iterator  begin()  const { return m_data.cbegin(); }
+		const_iterator  cbegin() const { return m_data.cbegin(); }
+
+		iterator        end()        { return m_data.end(); }
+		const_iterator  end()  const { return m_data.cend(); }
+		const_iterator  cend() const { return m_data.cend(); }
+
+	private:
+		std::vector< handle >         m_handles;
+		storage                       m_data;
+		index_store< handle, TINDEX > m_indexes;
+	};
+
+}
+
+namespace std
+{
+	template < 
+		typename T, 
+		unsigned IBITS,
+		unsigned CBITS,
+		typename TAG
+	>
+	struct hash<nv::handle<T,IBITS,CBITS,TAG>>
+	{
+		size_t operator()(const nv::handle<T,IBITS,CBITS,TAG>& h) const
+		{
+			return h.hash();
+		}
+	};
+}
+
+#endif // NV_CORE_HANDLE_HH
Index: /trunk/nv/core/io_event.hh
===================================================================
--- /trunk/nv/core/io_event.hh	(revision 319)
+++ /trunk/nv/core/io_event.hh	(revision 319)
@@ -0,0 +1,218 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file io_event.hh
+ * @author Kornel Kisielewicz
+ * @brief 
+ */
+
+#ifndef NV_CORE_IO_EVENT_HH
+#define NV_CORE_IO_EVENT_HH
+
+#include <nv/core/common.hh>
+
+namespace nv
+{
+
+	// Generate the key_code enum
+	enum key_code
+	{
+#	define NV_KEY( id, val ) id = val,
+#		include <nv/detail/key_list.inc>
+#	undef NV_KEY
+	};
+	
+	// Generate the mouse_code enum
+	enum mouse_code
+	{
+#	define NV_MOUSE( id, val ) id = val,
+#		include <nv/detail/mouse_list.inc>
+#	undef NV_MOUSE
+	};
+
+	// Generate the io_event_code enum
+	enum io_event_code
+	{
+#	define NV_IO_EVENT( id ) id,
+#		include <nv/detail/io_event_list.inc>
+#	undef NV_IO_EVENT
+	};
+
+	struct key_event
+	{
+		/// Input event ASCII code
+		char8 ascii;
+
+		/// Input event local code
+		key_code code;
+
+		/// True if shift key is present
+		bool shift;
+
+		/// True if control key is present
+		bool control;
+
+		/// True if alt key is present
+		bool alt;
+
+		/// True if pressed
+		bool pressed;
+	};
+
+	struct mouse_button_event
+	{
+		/// X position where mouse was clicked.
+		uint16 x;
+		/// Y position where mouse was clicked.
+		uint16 y;
+		/// Button that was clicked.
+		uint32 button;
+		/// True if pressed
+		bool pressed;
+		/// Mouse button code
+		mouse_code code;
+	};
+
+	struct mouse_wheel_event
+	{
+		/// amount scrolled horizontally positive to the right
+		sint32 x;
+		/// amount scrolled vertically 
+		sint32 y;
+	};
+
+	struct mouse_move_event
+	{
+		/// X Position the mouse moved to.
+		uint16 x;
+		/// Y Position the mouse moved to.
+		uint16 y;
+		/// Distance in x direction mouse was moved.
+		sint16 rx;
+		/// Distance in y direction mouse was moved.
+		sint16 ry;
+		/// True if pressed
+		bool pressed;
+		/// Mouse button code
+		mouse_code code;
+	};
+
+	struct joy_button_event
+	{
+		/// Joystick ID
+		sint32 id;
+		/// Button that is affected
+		uint8 button;
+		/// True if pressed
+		bool pressed;
+	};
+
+	struct joy_axis_event
+	{
+		/// Joystick ID
+		sint32 id;
+		/// Axis ID
+		uint8 axis;
+		/// Value
+		sint16 value;
+	};
+
+	struct joy_hat_event
+	{
+		/// Joystick ID
+		sint32 id;
+		/// Hat ID
+		uint8 hat;
+		/// Value
+		sint16 value;
+	};
+
+	struct joy_ball_event
+	{
+		/// Joystick ID
+		sint32 id;
+		/// Ball ID
+		uint8 ball;
+		/// Relative X
+		sint16 rx;
+		/// Relative Y
+		sint16 ry;
+	};
+
+	struct resize_event
+	{
+		/// New x size of the object.
+		sint32 x;
+		/// New y size of the object.
+		sint32 y;
+	};
+
+	struct active_event
+	{
+		/// Whether focus was gained or lost.
+		bool gain;
+	};
+
+	struct system_event
+	{
+		uint8  sys_type;
+		uint32 param1;
+		uint32 param2;
+	};
+
+	struct io_event
+	{
+		io_event_code type;
+		union
+		{
+			key_event          key;
+			mouse_button_event mbutton;
+			mouse_move_event   mmove;
+			mouse_wheel_event  mwheel;
+			joy_button_event   jbutton;
+			joy_axis_event     jaxis;
+			joy_hat_event      jhat;
+			joy_ball_event     jball;
+			resize_event       resize;
+			active_event       active;
+			system_event       system;
+		};
+	};
+
+	/**
+	 * Gets the name of the key given the code.
+	 *
+	 * @param key The code value of the key.
+	 * @returns The name of the key.
+	 */
+	const char* get_key_name( key_code key );
+
+	/**
+	 * Gets the name of the mouse button given the code.
+	 *
+	 * @param button The code value of the mouse button.
+	 * @returns The name of the button.
+	 */
+	const char* get_mouse_name( mouse_code button );
+
+	/**
+	 * Gets the name of the IO event given the code.
+	 *
+	 * @param event The code value of the IO event.
+	 * @returns The name of the event.
+	 */
+	const char* get_io_event_name( io_event_code event );
+
+	/**
+	 * Registers all events to the specified database.
+	 *
+	 * @param db The database to store all event data in.
+	 */
+	//void register_io_types( type_database* db );
+}
+
+#endif // NV_CORE_IO_EVENT_HH
Index: /trunk/nv/core/library.hh
===================================================================
--- /trunk/nv/core/library.hh	(revision 319)
+++ /trunk/nv/core/library.hh	(revision 319)
@@ -0,0 +1,144 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file library.hh
+ * @author Kornel Kisielewicz
+ * @brief Implements a dynamic library class
+ */
+
+#ifndef NV_CORE_LIBRARY_HH
+#define NV_CORE_LIBRARY_HH
+
+#include <nv/core/exception.hh>
+#include <nv/core/string.hh>
+
+namespace nv
+{
+	/**
+	 * library
+	 * @brief Class representing a dynamically loaded library
+	 */
+	class library 
+	{
+	public:
+
+		/**
+		 * Library constructor
+		 */
+		library();
+
+		/**
+		 * Opens the library
+		 *
+		 * Throws library_error on failure
+		 */
+		void open( const string& name );
+
+		/**
+		 * Tries to open the library
+		 *
+		 * returns true if succeeded, false otherwise
+		 */
+		bool try_open( const string& name );
+
+		/**
+		 * Returns true if the library is open, false otherwise
+		 */
+		bool is_open() const;
+
+		/**
+		 * Returns library name
+		 */
+		const string& get_name() const;
+
+		/**
+		 * Get symbol from library
+		 *
+		 * Throws on symbol not found
+		 */
+		void* get( const string& symbol );
+
+		/**
+		 * Get symbol from library
+		 *
+		 * Returns null if symbol not found
+		 */
+		void* try_get( const string& symbol );
+
+		/**
+		 * Destructor
+		 *
+		 * Closes the library if open.
+		 */
+		~library();
+
+		/**
+		 * Returns library loading error if present
+		 *
+		 * Exact implementation depends on platform/compiler.
+		 */
+		static string get_error();
+
+	protected:
+		/**
+		 * Opens the library
+		 *
+		 * Opens the library and prepares it for getting symbols.
+		 * Needs to be done before any get call.
+		 *
+		 * returns true on success, false otherwise
+		 */
+		bool open();
+
+		/**
+		 * @brief Closes the library
+		 *
+		 * Closes the library. Any further get calls or operations on
+		 * received symbols are invalid!
+		 */
+		void close();
+
+		/// Library handle
+		void* m_handle;
+
+		/// Library name
+		string m_name;
+
+	};  // class Library
+
+	class library_error : public runtime_error
+	{
+		/// Library name
+		string m_name;
+	public:
+		/**
+		 * Constructor
+		 */
+		library_error( const string& message, const string& name )
+			: runtime_error( "Library (" + name + ") : " + message + " [ " + library::get_error() + " ]"), m_name( name )
+		{
+		}
+
+		/**
+		 * Destructor.
+		 *
+		 * It must not throw any exceptions because of the inheritance
+		 */
+		~library_error() throw() {}
+
+		/**
+		 * Returns library name
+		 */
+		const string& get_name()
+		{
+			return m_name;
+		}
+	};
+
+} // namespace nv
+
+#endif // NV_CORE_LIBRARY_HH
Index: /trunk/nv/core/logger.hh
===================================================================
--- /trunk/nv/core/logger.hh	(revision 319)
+++ /trunk/nv/core/logger.hh	(revision 319)
@@ -0,0 +1,212 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file logger.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief logger implementation
+ */
+
+#ifndef NV_CORE_LOGGER_HH
+#define NV_CORE_LOGGER_HH
+
+#include <nv/core/string.hh>
+#include <nv/core/logging.hh>
+#include <iosfwd>
+#include <list>
+
+namespace nv
+{
+	/**
+	 * Class representing log output.
+	 *
+	 * Base class for all logging output targets.
+	 */
+	class log_sink
+	{
+	public:
+		/**
+		 * Logging function.
+		 *
+		 * @param level level on which to log.
+		 * @param message message to be logged.
+		 */
+		virtual void log( log_level level, const std::string& message ) = 0;
+		/**
+         * Optional timestamp string
+		 */
+		const char* timestamp() const;
+		/**
+         * Log level name (unpadded)
+		 */
+		const char* level_name( log_level level ) const;
+		/**
+         * Log level name (padded)
+		 */
+		const char* padded_level_name( log_level level ) const;
+		/**
+		 * Enforcement of virtual destructor.
+		 */
+		virtual ~log_sink() {}
+	};
+
+	/**
+	 * Logger class.
+	 *
+	 * Allows to catch all logging in ORE and in the application using ORE
+	 * logging macros. Initially does nothing, needs to have some log sinks
+	 * added.
+	 */
+	class logger : public logger_base
+	{
+	public:
+		/**
+		 * Constructor, taking the minimum level for logging.
+		 *
+		 * No matter what level sinks you add, the passed level is the
+		 * overriding cutoff.
+		 */
+		explicit logger( unsigned int llevel )
+		{
+			m_level = llevel;
+		}
+
+		/**
+		 * Logging function.
+		 *
+		 * Goes over all registered log sinks and prints to them depending
+		 * on the log level of the sink. Messages that are lower level than
+		 * the initial level passed to the constructor never even reach this
+		 * function.
+		 *
+		 * @param level level on which to log.
+		 * @param message message to be logged.
+		 */
+		virtual void log( log_level level, const std::string& message );
+
+		/** 
+		 * Log sink registering.
+		 * 
+		 * Registers a new log sink. Ownership is passed to logger - log sink
+		 * will be disposed at program shutdown.
+		 *
+		 * @param sink log sink to be registered.
+		 * @param level level on which the sink should log.
+		 */
+		virtual void add_sink( log_sink* sink, int level );
+
+		/** 
+		 * Log sink removal.
+		 * 
+		 * Removes a log sink. If log sink doesn't exist, nothing will 
+		 * happen.
+		 *
+		 * @param sink log sink to be removed.
+		 * @returns true if sink was found, false otherwise
+		 */
+		virtual bool remove_sink( log_sink* sink );
+
+		/**
+		 * Destructor.
+		 * 
+		 * Also destroys all file sinks.
+		 */
+		virtual ~logger();
+
+	protected:
+		/** Type for the log sink list. */
+		typedef std::list< std::pair< log_level, log_sink* > > log_sink_list;
+
+		/** Log sink list. */
+		log_sink_list m_log_sinks;
+	};
+
+	/**
+	 * Console logger sink.
+	 *
+	 * Logs to std::out -- be sure a console window is open, or std::out redirected!
+	 */
+	class log_console_sink : public log_sink
+	{
+	public:
+		/**
+		 * Log sink constructor
+		 */
+		log_console_sink( bool coloring = true );
+		/**
+		 * Logging function.
+		 */
+		virtual void log( log_level level, const std::string& message );
+
+	private:
+		void* m_handle;
+		bool  m_color;
+	};
+
+	/**
+	 * General stream sink.
+	 *
+	 * Logs to passed stream.
+	 */
+	class log_stream_sink : public log_sink
+	{
+	public:
+		/**
+		 * Constructor.
+		 *
+		 * Logs to the passed stream. The stream is NOT disposed at destruction.
+		 * Flushing can be controlled by optional flush parameter.
+		 *
+		 * @param stream stream to be logged to.
+		 * @param flush_always if set to false, wont flush after each line.
+		 */
+		log_stream_sink( std::ostream* stream, bool flush_always ) 
+			: m_stream(stream), m_flush(flush_always) {}
+
+		/**
+		 * Logging function.
+		 */
+		virtual void log( log_level level, const std::string& message );
+
+	protected:
+		/** Stored stream. */
+		std::ostream* m_stream;
+		/** Controls flushing. */
+		bool m_flush;
+	};
+
+	/**
+	 * File logger sink.
+	 *
+	 * Logs to std::out -- be sure a console window is open, or std::out redirected!
+	 */
+	class log_file_sink : public log_stream_sink
+	{
+	public:
+		/**
+		 * Constructor.
+		 *
+		 * Logs to the file passed. File is closed and disposed of after ending.
+		 * File is not appended, it's overwritten. If file is not creatable,
+		 * the constructor will throw!
+		 *
+		 * @param file_name file to be logged to.
+		 * @param flush_always if set to false, wont flush after each line.
+		 * @throws runtime_error if file_name cannot be opened.
+		 */
+		log_file_sink( const std::string file_name, bool flush_always = true );
+
+		/**
+		 * Destructor.
+		 *
+		 * Flushes, closes file and disposes of the stream.
+		 */
+		virtual ~log_file_sink();
+	};
+
+}
+
+#endif // NV_CORE_LOGGER_HH
Index: /trunk/nv/core/logging.hh
===================================================================
--- /trunk/nv/core/logging.hh	(revision 319)
+++ /trunk/nv/core/logging.hh	(revision 319)
@@ -0,0 +1,78 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file logging.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief logging interfaces
+ */
+
+#ifndef NV_CORE_LOGGING_HH
+#define NV_CORE_LOGGING_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/singleton.hh>
+#include <string>
+#include <sstream>
+
+namespace nv
+{
+
+	enum log_level
+	{
+		LOG_NONE     = 0,
+		LOG_FATAL    = 10,
+		LOG_CRITICAL = 20,
+		LOG_ERROR    = 30,
+		LOG_WARNING  = 40,
+		LOG_NOTICE   = 50,
+		LOG_INFO     = 60,
+		LOG_DEBUG    = 80,
+		LOG_TRACE    = 100
+	};
+
+	class logger_base : public singleton< logger_base >
+	{
+	public:
+		unsigned int get_level()
+		{
+			return m_level;
+		}
+		void set_level( unsigned int level )
+		{
+			m_level = level;
+		}
+		virtual void log( log_level level, const std::string& message ) = 0;
+		virtual ~logger_base() {}
+	protected:
+		unsigned int m_level;
+	};
+
+} // namespace nv
+
+#define NV_LOG(level, message_stream) \
+	if ( nv::logger_base::is_valid() && \
+		(unsigned int)nv::logger_base::reference().get_level() >= (unsigned int)level ) \
+	{       \
+		std::stringstream ss; \
+		ss << message_stream; \
+		nv::logger_base::reference().log( level, ss.str() ); \
+	}
+
+#if NV_DEBUG == 1
+#define NV_DEBUG_LOG(level, message_stream) \
+	if ( nv::logger_base::is_valid() && \
+		(unsigned int)nv::logger_base::reference().get_level() >= (unsigned int)level ) \
+	{       \
+		std::stringstream ss; \
+		ss << message_stream; \
+		nv::logger_base::reference().log( level, ss.str() ); \
+	}
+#else
+#define NV_DEBUG_LOG(level, message_stream)
+#endif
+
+#endif // NV_CORE_LOGGING_HH
Index: /trunk/nv/core/math.hh
===================================================================
--- /trunk/nv/core/math.hh	(revision 319)
+++ /trunk/nv/core/math.hh	(revision 319)
@@ -0,0 +1,251 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_CORE_MATH_HH
+#define NV_CORE_MATH_HH
+
+#include <nv/core/common.hh>
+
+#if NV_COMPILER == NV_GNUC
+#pragma GCC system_header
+#elif NV_COMPILER == NV_CLANG
+#pragma clang system_header
+#endif
+
+#include <glm/glm.hpp>
+#include <glm/gtc/matrix_transform.hpp>
+#include <glm/gtc/type_ptr.hpp>
+#include <glm/gtc/quaternion.hpp>
+
+namespace nv
+{
+
+	typedef glm::detail::tvec2<sint8> i8vec2;
+	typedef glm::detail::tvec3<sint8> i8vec3;
+	typedef glm::detail::tvec4<sint8> i8vec4;
+
+	typedef glm::detail::tvec2<sint16> i16vec2;
+	typedef glm::detail::tvec3<sint16> i16vec3;
+	typedef glm::detail::tvec4<sint16> i16vec4;
+
+	typedef glm::vec2 vec2;
+	typedef glm::vec3 vec3;
+	typedef glm::vec4 vec4;
+
+	typedef glm::ivec2 ivec2;
+	typedef glm::ivec3 ivec3;
+	typedef glm::ivec4 ivec4;
+
+	typedef glm::mat2 mat2;
+	typedef glm::mat3 mat3;
+	typedef glm::mat4 mat4;
+
+	typedef glm::quat quat;
+
+	template <typename T> 
+	struct datatype_traits 
+	{
+		typedef T type;
+		typedef T base_type;
+		static const size_t size = 1;
+	};
+
+	template <typename T> 
+	struct datatype_traits< glm::detail::tvec2<T> > 
+	{
+		typedef glm::detail::tvec2<T> type;
+		typedef typename type::value_type base_type;
+		static const size_t size = 2;
+	};
+
+	template <typename T> 
+	struct datatype_traits< glm::detail::tvec3<T> > 
+	{
+		typedef glm::detail::tvec3<T> type;
+		typedef typename type::value_type base_type;
+		static const size_t size = 3;
+	};
+
+	template <typename T> 
+	struct datatype_traits< glm::detail::tvec4<T> > 
+	{
+		typedef glm::detail::tvec4<T> type;
+		typedef typename type::value_type base_type;
+		static const size_t size = 4;
+	};
+
+	using glm::max;
+	using glm::min;
+
+	enum datatype
+	{
+		NONE,
+		INT,
+		BYTE,
+		SHORT,
+		UINT,
+		UBYTE,
+		USHORT,
+		FLOAT,
+		FLOAT_VECTOR_2,
+		FLOAT_VECTOR_3,
+		FLOAT_VECTOR_4,
+		FLOAT_MATRIX_2,
+		FLOAT_MATRIX_3,
+		FLOAT_MATRIX_4,
+		INT_VECTOR_2,
+		INT_VECTOR_3,
+		INT_VECTOR_4,
+		// unsupported gl conversion, remove?
+		BYTE_VECTOR_2, 
+		BYTE_VECTOR_3,
+		BYTE_VECTOR_4,
+		QUAT,
+		TRANSFORM,
+		DATATYPE_COUNT,
+	};
+
+	struct datatype_info
+	{
+		size_t   size;
+		datatype base;
+		size_t   elements;
+	};
+
+	inline const datatype_info& get_datatype_info( datatype dt )
+	{
+		static datatype_info info[ DATATYPE_COUNT ] = {
+			{ 0, NONE, 0 },   // NONE  
+			{ 4, INT, 1 },    // INT,
+			{ 1, BYTE, 1 },   // BYTE,
+			{ 2, SHORT, 1 },  // SHORT,
+			{ 4, UINT, 1 },   // UINT,
+			{ 1, UBYTE, 1 },  // UBYTE,
+			{ 2, USHORT, 1 }, // USHORT,
+			{ 4, FLOAT, 1 },  // FLOAT
+			{ 4 * 2,  FLOAT, 2 },  // FLOAT_VECTOR_2,
+			{ 4 * 3,  FLOAT, 3 },  // FLOAT_VECTOR_3,
+			{ 4 * 4,  FLOAT, 4 },  // FLOAT_VECTOR_4,
+			{ 4 * 4,  FLOAT, 4 },  // FLOAT_MATRIX_2,
+			{ 4 * 9,  FLOAT, 9 },  // FLOAT_MATRIX_3,
+			{ 4 * 16, FLOAT, 16 }, // FLOAT_MATRIX_4,
+			{ 4 * 2,  INT, 2 },  // INT_VECTOR_2,
+			{ 4 * 3,  INT, 3 },  // INT_VECTOR_3,
+			{ 4 * 4,  INT, 4 },  // INT_VECTOR_4,
+			// unsupported gl conversion, remove?
+			{ 1 * 2,  BYTE, 2 },  // BYTE_VECTOR_2,
+			{ 1 * 3,  BYTE, 3 },  // BYTE_VECTOR_3,
+			{ 1 * 4,  BYTE, 4 },  // BYTE_VECTOR_4,
+			{ 4 * 4,  FLOAT, 4 },      // QUAT,
+			{ 7 * 4,  FLOAT, 7 },      // TRANSFORM,
+		};
+		return info[dt];
+	}
+
+	template < datatype EnumType > struct enum_to_type {};
+
+	template <> struct enum_to_type< NONE >  { typedef void type; };
+	template <> struct enum_to_type< INT >   { typedef int type; };
+	template <> struct enum_to_type< UINT >  { typedef unsigned int type; };
+	template <> struct enum_to_type< SHORT > { typedef short type; };
+	template <> struct enum_to_type< USHORT >{ typedef unsigned short type; };
+	template <> struct enum_to_type< BYTE >  { typedef char type; };
+	template <> struct enum_to_type< UBYTE > { typedef unsigned char type; };
+	template <> struct enum_to_type< FLOAT > { typedef f32 type; };
+
+	template <> struct enum_to_type< FLOAT_VECTOR_2 > { typedef vec2 type; };
+	template <> struct enum_to_type< FLOAT_VECTOR_3 > { typedef vec3 type; };
+	template <> struct enum_to_type< FLOAT_VECTOR_4 > { typedef vec4 type; };
+
+	template <> struct enum_to_type< INT_VECTOR_2 > { typedef ivec2 type; };
+	template <> struct enum_to_type< INT_VECTOR_3 > { typedef ivec3 type; };
+	template <> struct enum_to_type< INT_VECTOR_4 > { typedef ivec4 type; };
+
+	template <> struct enum_to_type< BYTE_VECTOR_2 > { typedef i8vec2 type; };
+	template <> struct enum_to_type< BYTE_VECTOR_3 > { typedef i8vec3 type; };
+	template <> struct enum_to_type< BYTE_VECTOR_4 > { typedef i8vec4 type; };
+
+	template <> struct enum_to_type< FLOAT_MATRIX_2 > { typedef mat2 type; };
+	template <> struct enum_to_type< FLOAT_MATRIX_3 > { typedef mat3 type; };
+	template <> struct enum_to_type< FLOAT_MATRIX_4 > { typedef mat4 type; };
+
+	template <> struct enum_to_type< QUAT > { typedef quat type; };
+
+	template < typename TYPE > struct type_to_enum {};
+
+	template <> struct type_to_enum< long >          { static const datatype type = INT; };
+	template <> struct type_to_enum< unsigned long > { static const datatype type = UINT; };
+	template <> struct type_to_enum< int >           { static const datatype type = INT; };
+	template <> struct type_to_enum< unsigned int >  { static const datatype type = UINT; };
+	template <> struct type_to_enum< short >         { static const datatype type = SHORT; };
+	template <> struct type_to_enum< unsigned short >{ static const datatype type = USHORT; };
+	template <> struct type_to_enum< char >          { static const datatype type = BYTE; };
+	template <> struct type_to_enum< signed char >   { static const datatype type = BYTE; };
+	template <> struct type_to_enum< unsigned char > { static const datatype type = UBYTE; };
+	template <> struct type_to_enum< f32 > { static const datatype type = FLOAT; };
+
+	template <> struct type_to_enum< vec2 > { static const datatype type = FLOAT_VECTOR_2; };
+	template <> struct type_to_enum< vec3 > { static const datatype type = FLOAT_VECTOR_3; };
+	template <> struct type_to_enum< vec4 > { static const datatype type = FLOAT_VECTOR_4; };
+
+	template <> struct type_to_enum< ivec2 > { static const datatype type = INT_VECTOR_2; };
+	template <> struct type_to_enum< ivec3 > { static const datatype type = INT_VECTOR_3; };
+	template <> struct type_to_enum< ivec4 > { static const datatype type = INT_VECTOR_4; };
+
+	template <> struct type_to_enum< i8vec2 > { static const datatype type = BYTE_VECTOR_2; };
+	template <> struct type_to_enum< i8vec3 > { static const datatype type = BYTE_VECTOR_3; };
+	template <> struct type_to_enum< i8vec4 > { static const datatype type = BYTE_VECTOR_4; };
+
+	template <> struct type_to_enum< mat2 > { static const datatype type = FLOAT_MATRIX_2; };
+	template <> struct type_to_enum< mat3 > { static const datatype type = FLOAT_MATRIX_3; };
+	template <> struct type_to_enum< mat4 > { static const datatype type = FLOAT_MATRIX_4; };
+	template <> struct type_to_enum< quat > { static const datatype type = QUAT; };
+
+	template < typename T >
+	struct sizeof_type 
+	{
+		static const int result = sizeof( T );
+	};
+
+	template <>
+	struct sizeof_type< void >
+	{
+		static const int result = 0;
+	};
+
+	template < datatype T >
+	struct sizeof_enum_type 
+	{
+		static const int result = sizeof_type< typename enum_to_type<T>::type >::result;
+	};
+
+	template < typename T >
+	T interpolate( const T& lhs, const T& rhs, float f )
+	{
+		return glm::mix( lhs, rhs, f );
+	}
+
+	template <>
+	inline quat interpolate( const quat& lhs, const quat& rhs, float f )
+	{
+		return glm::slerp( lhs, rhs, f );
+	}
+
+	template <typename T>
+	glm::detail::tvec3<T> normalize_safe( 
+		const glm::detail::tvec3<T>& x, 
+		const glm::detail::tvec3<T>& def = vec3()
+	)
+	{
+		typename glm::detail::tvec3<T>::value_type sqr = x.x * x.x + x.y * x.y + x.z * x.z;
+		return ( sqr > 0 ? x * glm::inversesqrt(sqr) : def );
+	}
+
+
+
+} // namespace nv
+
+#endif // NV_CORE_MATH_HH
Index: /trunk/nv/core/position.hh
===================================================================
--- /trunk/nv/core/position.hh	(revision 319)
+++ /trunk/nv/core/position.hh	(revision 319)
@@ -0,0 +1,323 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file position.hh
+ * @author Kornel Kisielewicz
+ * @brief UI 2D positioning classes
+ */
+
+#ifndef NV_CORE_POSITION_HH
+#define NV_CORE_POSITION_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+#include <nv/core/range.hh>
+#include <utility>
+
+namespace nv
+{
+	typedef ivec2 position;
+	typedef ivec2 dimension;
+
+	struct rectangle
+	{
+		typedef position::value_type value_type;
+		typedef std::size_t size_type;
+		typedef rectangle type;
+		
+		position ul;
+		position lr;
+		/**
+		 * Creates a new rectangle assigned to {0, 0, 0, 0}.
+		 */
+		rectangle() : ul(), lr() {}
+		
+		/**
+		 * Creates a new rectangle given a position.
+		 *
+		 * @param p The position to assign the rectangle to.
+		 */
+		explicit rectangle( position p ) : ul(p), lr(p) {}
+		
+		/**
+		 * Creates a new rectangle given an upper-left and lower-right position.
+		 *
+		 * @param aul The position of the upper-left corner of the rectangle.
+		 * @param alr The position of the lower-right corner of the rectangle.
+		 */
+		rectangle( position aul, position alr ) : ul(aul), lr(alr) {}
+		
+		/**
+		 * Creates a new rectangle given an upper-left position, width, and height.
+		 *
+		 * @param aul The position of the upper-left corner of the rectangle.
+		 * @param width The width of the rectangle.
+		 * @param height The height of the rectangle.
+		 */
+		rectangle( position aul, value_type width, value_type height ) : ul(aul), lr(aul + position(width,height)) {}
+        
+        /**
+         * Explicit Copy constructor
+         */
+        rectangle( const rectangle& r ) : ul( r.ul ), lr( r.lr ) {}
+        
+        /**
+         * Explicit Copy assignment operator
+         */
+        rectangle& operator= (const rectangle& r) { ul = r.ul; lr = r.lr; return *this; }
+		
+		/**
+		 * Sets the dimensions of the rectangle without moving the upper-left of the rectangle.
+		 *
+		 * @param d The new dimensions of the rectangle.
+		 */
+		rectangle& dim( dimension d ) { lr = ul + d; return *this; }
+
+		/**
+		 * Moves the rectangle to a new position while maintaining its size.
+		 *
+		 * @param p The new position of the rectangle's upper-left corner.
+		 */
+		rectangle& pos( position p )  { lr = p + (lr - ul); lr = p; return *this; }
+
+		/**
+		 * Sets the dimensions of the rectangle without moving the upper-left of the rectangle.
+		 *
+		 * @param d The new dimensions of the rectangle.
+		 */
+		void set_dimension( dimension d ) { lr = ul + d; }
+		
+		/**
+		 * Moves the rectangle to a new position while maintaining its size.
+		 *
+		 * @param p The new position of the rectangle's upper-left corner.
+		 */
+		void set_position( position p ) { lr = p + (lr - ul); ul = p; }
+
+		position ur() const { return position( lr.x, ul.y ); }
+		position ll() const { return position( ul.x, lr.y ); }
+		/**
+		 * Gets the dimensions of the rectangle.  Synonym for get_size.
+		 *
+		 * @returns The dimensions of the rectangle.
+		 * @see get_size
+		 */
+		dimension get_dimension() const { return lr - ul; }
+
+		/**
+		 * Gets the position of the upper-left corner of the rectangle.
+		 *
+		 * @returns The position of the rectangle's upper-left corner.
+		 */
+		position  get_position() const { return ul; }
+
+		/**
+		 * Gets the dimensions of the rectangle.  Synonym for get_dimension.
+		 *
+		 * @returns The dimensions of the rectangle.
+		 * @see get_dimension
+		 */
+		dimension get_size() const { return lr - ul; }
+
+		/**
+		 * Gets the center of the rectangle.
+		 *
+		 * @returns The center of the rectangle.
+		 */
+		position get_center() const { return ( lr + ul ) / 2; }
+
+		/**
+		 * Gets the width of the rectangle.
+		 *
+		 * @returns The width of the rectangle.
+		 */
+		value_type get_width() const { return lr.x - ul.x; }
+
+		/**
+		 * Gets the height of the rectangle.
+		 *
+		 * @returns The height of the rectangle.
+		 */
+		value_type get_height() const { return lr.y - ul.y; }
+
+		/**
+		 * Gets the area of the rectangle.
+		 *
+		 * @returns The area of the rectangle.
+		 */
+		value_type get_area() const { return (lr.y - ul.y) * (lr.x - ul.x); }
+
+		/**
+		 * Gets the area of the rectangle.
+		 *
+		 * @returns The area of the rectangle, including the edge
+		 */
+		value_type get_enclosed_area() const { return (lr.y - ul.y + 1) * (lr.x - ul.x + 1); }
+
+		/**
+		 * Checks to see if the rectangle is backwards.
+		 *
+		 * @returns True if the rectangle's upper-left is above and left (or equal to) the rectangle's lower-right, false if it is not.
+		 */
+		bool is_valid() const {	return lr.x >= ul.x && lr.y >= ul.y; }
+
+		/**
+		 * Enlarges the rectangle by a given amount.  Each side is adjusted by the given amount, e.g. expanding by 1 increases the width and height by 2 each.
+		 *
+		 * @param value The amount to adjust each sides by.
+		 */
+		void expand( value_type value ) { position p(value,value); ul -= p; lr += p; }
+
+		/**
+		 * Reduces the rectangle by a given amount.  Each side is adjusted by the given amount, e.g. shrinking by 1 decreases the width and height by 2 each.
+		 *
+		 * @param value The amount to adjust each side by.
+		 */
+		void shrink( value_type value ) { position p(value,value); ul += p; lr -= p; }
+
+		/**
+		 * Gets a rectangle that is an expanded version of this rectangle.
+		 *
+		 * @param value The amount to adjust each side by.
+		 * @returns An expanded rectangle.
+		 * @see expand
+		 */
+		rectangle expanded( int value ) { position p(value,value); return rectangle(ul-p, lr+p); }
+
+		/**
+		 * Gets a rectangle that is a shrunk version of this rectangle.
+		 *
+		 * @param value The amount to adjust each side by.
+		 * @returns A shrunk rectangle.
+		 * @see shrink
+		 */
+		rectangle shrinked( int value ) { position p(value,value); return rectangle(ul+p, lr-p); }
+		
+		/**
+		 * Shifts the rectangle by a given amount.
+		 *
+		 * @param pos The amount to shift the rectangle by.
+		 */
+		rectangle& operator+=( const position& pos ) { ul += pos; lr += pos; return (*this); }
+
+		/**
+		 * Returns a rectangle shifted by a given amount.
+		 *
+		 * @param pos The amount to shift by. 
+		 * @returns The shifted rectangle.
+		 */
+		rectangle operator+( const position& pos ) const {	rectangle r(*this); return r += pos; }
+
+		/**
+		 * Shifts the rectangle by a given amount.
+		 *
+		 * @param pos The amount to shift the rectangle by.
+		 */
+		rectangle& operator-=( const position& pos ) { ul -= pos; lr -= pos; return (*this); }
+
+		/**
+		 * Returns a rectangle shifted by a given amount.
+		 *
+		 * @param pos The amount to shift by.
+		 * @returns The shifted rectangle.
+		 */
+		rectangle operator-( const position& pos ) const {	rectangle r(*this); return r -= pos; }
+
+		/**
+		 * Compares two rectangles to see if they are the same.
+		 *
+		 * @param r The rectangle to compare to.
+		 * @returns True if the rectangles have the same positions and dimensions, false otherwise.
+		 */
+		bool operator==( const rectangle& r ) const { return r.ul == ul && r.lr == lr; }
+
+		/**
+		 * Compares two rectangles to see if they are different.
+		 *
+		 * @param r The rectangle to compare to.
+		 * @returns True if the rectangles have different positions or dimensions, false otherwise.
+		 */
+		bool operator!=( const rectangle& r ) const { return r.ul != ul || r.lr != lr; }
+
+		/**
+		 * Checks if a position is within the bounds of this rectangle.
+		 *
+		 * @param r The position to check.
+		 * @returns True if the position is inside or on the edge of the rectangle, false otherwise.
+		 */
+		bool contains( const position& r ) const{ return lr.y >= r.y && ul.y <= r.y && lr.x >= r.x && ul.x <= r.x; }
+
+		/**
+		 * Checks if a rectangle is within the bounds of this rectangle.
+		 *
+		 * @param r The rectangle to check.
+		 * @returns True if the entire rectangle to check is inside or on the edge of this rectangle, false otherwise.
+		 */
+		bool contains( const rectangle& r ) const { return contains( r.ul ) && contains( r.lr ); }
+
+		/**
+		 * Checks if another rectangle overlaps this one.
+		 *
+		 * @param r The rectangle to check.
+		 * @returns True if any part of the rectangle to check overlaps this rectangle, false otherwise.
+		 */
+		bool collides( const rectangle& r ) const { return lr.y > r.ul.y && ul.y < r.lr.y && lr.x > r.ul.x && ul.x < r.lr.x; }
+
+		/**
+		 * Limits the region of the rectangle to the inidicated rectangle.
+		 *
+		 * @param r The rectangle that this rectangle is confined to.
+		 * @returns True if the rectangle was changed, false otherwise.
+		 */
+		bool clamp_to( const rectangle& r )
+		{
+			if (r.contains(*this)) return false;
+			ul = nv::max( ul, r.ul );
+			lr = nv::min( lr, r.lr );
+			ul = nv::min( ul, lr );
+			return true;
+		}
+
+		/**
+		 * Limits the size of the rectangle to the given rectangle's size.
+		 *
+		 * @param r The rectangle representing the maximum dimensions this rectangle can be.
+		 * @returns True if the rectangle needed to be resized, false otherwise.
+		 */
+		bool constrain_to( const rectangle& r )
+		{
+			if ( r.get_width() < get_width() || r.get_height() < get_height() ) return false;
+			(*this) += nv::min( r.ul - ul, position() );
+			(*this) -= nv::min( lr - r.lr, position() );
+			return true;
+		}
+
+		/**
+		 * Fixes an invalid rectangle.
+		 */
+		void repair() 
+		{
+			if (ul.x > lr.x) std::swap( ul.x, lr.x );
+			if (ul.y > lr.y) std::swap( ul.y, lr.y );
+		}
+
+		/**
+		 * Expands the rectangle to just include the given point.
+		 *
+		 * @param p The point to include in the rectangle.
+		 */
+		void include_point( position p )
+		{
+			lr = nv::max( lr, p );
+			ul = nv::min( ul, p );
+		}
+
+	};
+
+}
+
+#endif // NV_CORE_POSITION_HH
Index: /trunk/nv/core/profiler.hh
===================================================================
--- /trunk/nv/core/profiler.hh	(revision 319)
+++ /trunk/nv/core/profiler.hh	(revision 319)
@@ -0,0 +1,88 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file profiler.hh
+ * @author Kornel Kisielewicz
+ * @brief profiler
+ */
+
+#ifndef NV_CORE_PROFILER_HH
+#define NV_CORE_PROFILER_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/singleton.hh>
+#include <unordered_map>
+
+#define NV_PROFILE( tag ) nv::profiler_guard __profile( tag )
+
+namespace nv
+{
+	class profiler : public auto_singleton< profiler >
+	{
+	protected:
+		class node
+		{
+		public:
+			friend class profiler;
+			node* get_parent() { return m_parent; }
+			node* get_child( const std::string& tag )
+			{
+				auto it = m_children.find( tag );
+				return ( it != m_children.end() ) ? it->second : nullptr;
+			}
+		protected:
+			node( const char* tag, node* parent );
+			node* request_child( const char* tag );
+			void start();
+			bool stop();
+			~node();
+		protected:
+			typedef std::unordered_map< std::string, node* > map;
+
+			std::string m_tag;
+			map         m_children;
+			node*       m_parent;
+			uint32      m_recusion;
+
+			uint32      m_calls;
+			uint64      m_start_time_us;
+			uint64      m_total_time_us;
+		};
+
+	protected:
+		profiler();
+		~profiler();
+
+		void start_profile( const char* tag );
+		void stop_profile();
+	public:
+		friend class auto_singleton< profiler >;
+		friend class profiler_guard;
+		void log_report();
+	private:
+		void log_node_children( const std::string& ind, const node* n );
+		node* m_root;
+		node* m_current;
+	};
+
+	class profiler_guard
+	{
+	public:
+		profiler_guard( const char* tag )
+		{
+			profiler::pointer()->start_profile( tag );
+		}
+
+		~profiler_guard()
+		{
+			profiler::pointer()->stop_profile();
+		}
+	};
+
+} // namespace nv
+
+#endif // NV_CORE_PROFILER_HH
Index: /trunk/nv/core/random.hh
===================================================================
--- /trunk/nv/core/random.hh	(revision 319)
+++ /trunk/nv/core/random.hh	(revision 319)
@@ -0,0 +1,183 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_CORE_RANDOM_HH
+#define NV_CORE_RANDOM_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+#include <random>
+
+namespace nv
+{
+
+	class random
+	{
+	public:
+		typedef std::mt19937::result_type result_type;
+		typedef std::mt19937::result_type seed_type;
+
+		random( seed_type seed = 0 );
+		seed_type randomize();
+		void set_seed( seed_type seed = 0 );
+		static random& get();
+		result_type rand();
+		sint32 srand( sint32 val );
+		uint32 urand( uint32 val );
+		f32 frand( f32 val );
+		sint32 srange( sint32 min, sint32 max );
+		uint32 urange( uint32 min, uint32 max );
+		f32 frange( f32 min, f32 max );
+		uint32 dice( uint32 count, uint32 sides );
+
+		template < typename T >
+		glm::detail::tvec2<T> range( glm::detail::tvec2<T> min, glm::detail::tvec2<T> max )
+		{
+			return glm::detail::tvec2<T>( 
+				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
+				range_impl( min.y, max.y, std::is_floating_point<T>() )
+				);
+		}
+
+		template < typename T >
+		glm::detail::tvec3<T> range( glm::detail::tvec3<T> min, glm::detail::tvec3<T> max )
+		{
+			return glm::detail::tvec3<T>( 
+				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
+				range_impl( min.y, max.y, std::is_floating_point<T>() ),
+				range_impl( min.z, max.z, std::is_floating_point<T>() )
+				);
+		}
+
+		template < typename T >
+		glm::detail::tvec4<T> range( glm::detail::tvec4<T> min, glm::detail::tvec4<T> max )
+		{
+			return glm::detail::tvec4<T>( 
+				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
+				range_impl( min.y, max.y, std::is_floating_point<T>() ),
+				range_impl( min.z, max.z, std::is_floating_point<T>() ), 
+				range_impl( min.w, max.w, std::is_floating_point<T>() ) 
+				);
+		}
+
+		vec3 unit_vec3( bool = false )
+		{
+			return precise_unit_vec3();
+//			return precise ? precise_unit_vec3() : fast_unit_vec3();
+		}
+		vec2 unit_vec2( bool = false )
+		{
+			return precise_unit_vec2();
+//			return precise ? precise_unit_vec2() : fast_unit_vec2();
+		}
+
+		vec2 disk_point( bool precise = false )
+		{
+			return precise ? precise_disk_point() : fast_disk_point();
+		}
+
+		vec3 sphere_point( bool precise = false )
+		{
+			return precise ? precise_sphere_point() : fast_sphere_point();
+		}
+
+		vec2 ellipse_point( const vec2& radii, bool precise = false )
+		{
+			return precise ? precise_ellipse_point( radii ) : fast_ellipse_point( radii );
+		}
+
+		vec3 ellipsoid_point( const vec3& radii, bool precise = false )
+		{
+			return precise ? precise_ellipsoid_point( radii ) : fast_ellipsoid_point( radii );
+		}
+
+		vec2 ellipse_edge( const vec2& radii, bool = false )
+		{
+			return unit_vec2() * radii;
+		}
+
+		vec3 ellipsoid_edge( const vec3& radii, bool = false )
+		{
+			return unit_vec3() * radii;
+		}
+
+		vec2 hollow_disk_point( float iradius, float oradius, bool precise = false )
+		{
+			return precise ? precise_hollow_disk_point( iradius, oradius ) : fast_hollow_disk_point( iradius, oradius );
+		}
+
+		vec3 hollow_sphere_point( float iradius, float oradius, bool precise = false )
+		{
+			return precise ? precise_hollow_sphere_point( iradius, oradius ) : fast_hollow_sphere_point( iradius, oradius );
+		}
+
+		vec2 hollow_ellipse_point( const vec2& iradii, const vec2& oradii, bool precise = false )
+		{
+			return precise ? precise_hollow_ellipse_point( iradii, oradii ) : fast_hollow_ellipse_point( iradii, oradii );
+		}
+
+		vec3 hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii, bool precise = false )
+		{
+			return precise ? precise_hollow_ellipsoid_point( iradii, oradii ) : fast_hollow_ellipsoid_point( iradii, oradii );
+		}
+
+		//vec2 fast_unit_vec2();
+		vec2 precise_unit_vec2();
+		//vec3 fast_unit_vec3();
+		vec3 precise_unit_vec3();
+	
+		vec2 fast_disk_point();
+		vec2 precise_disk_point();
+		vec3 fast_sphere_point();
+		vec3 precise_sphere_point();
+
+		vec2 fast_ellipse_point( const vec2& radii )
+		{
+			return fast_disk_point() * radii;
+		}
+		vec2 precise_ellipse_point( const vec2& radii );
+
+		vec3 fast_ellipsoid_point( const vec3& radii )
+		{
+			return fast_sphere_point() * radii;
+		}
+
+		vec3 precise_ellipsoid_point( const vec3& radii );
+
+		vec2 fast_hollow_disk_point( float iradius, float oradius );
+		vec2 precise_hollow_disk_point( float iradius, float oradius );
+		vec3 fast_hollow_sphere_point( float iradius, float oradius );
+		vec3 precise_hollow_sphere_point( float iradius, float oradius );
+
+		vec2 fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii );
+		vec2 precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii );
+		vec3 fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii );
+		vec3 precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii );
+
+
+	private:
+		static seed_type randomized_seed();
+
+		template <typename T>
+		T range_impl( T min, T max, const std::true_type& )
+		{
+			std::uniform_real_distribution<T> dist( min, max );
+			return dist( rng );
+		}
+
+		template <typename T>
+		T range_impl( T min, T max, const std::false_type& )
+		{
+			std::uniform_int_distribution<T> dist( min, max );
+			return dist( rng );
+		}
+	private:
+		std::mt19937 rng;
+	};
+
+}
+
+#endif // NV_CORE_RANDOM_HH
Index: /trunk/nv/core/range.hh
===================================================================
--- /trunk/nv/core/range.hh	(revision 319)
+++ /trunk/nv/core/range.hh	(revision 319)
@@ -0,0 +1,227 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file range.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief range iterators
+ */
+
+#ifndef NV_CORE_RANGE_HH
+#define NV_CORE_RANGE_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+#include <nv/core/type_traits.hh>
+#include <iterator>
+
+namespace nv
+{
+
+	namespace detail
+	{
+
+		template < typename T >
+		class forward_iterator_base : public std::iterator< std::input_iterator_tag, T >
+		{
+		public:
+			forward_iterator_base( T value ) : m_value( value ) {}
+			T operator* () const { return m_value; }
+			T const* operator-> () const { return &m_value; }
+			bool operator== ( const forward_iterator_base& rhs ) const
+			{
+				return m_value == rhs.m_value;
+			}
+			bool operator!= ( const forward_iterator_base& rhs ) const
+			{
+				return !( *this == rhs );
+			}
+		protected:
+			T m_value;
+		};
+
+		template < typename T >
+		class range_iterator_base : public forward_iterator_base< T >
+		{
+		public:
+			range_iterator_base( T value ) : forward_iterator_base( value ) {}
+			range_iterator_base& operator++ () 
+			{
+				++m_value; 
+				return *this; 
+			}
+			range_iterator_base operator++ (int) 
+			{
+				auto result = *this; 
+				++*this; 
+				return result;
+			}
+		};
+
+		template < typename T >
+		class range2d_iterator_base 
+			: public forward_iterator_base< glm::detail::tvec2<T> >
+		{
+		public:
+			range2d_iterator_base( glm::detail::tvec2<T> value, T min, T max ) 
+				: forward_iterator_base( value ), m_min(min), m_max(max) {}
+			range2d_iterator_base& operator++ () 
+			{
+				++m_value.x;
+				if ( m_value.x > m_max ) 
+				{
+					++m_value.y;
+					m_value.x = m_min;
+				}
+				return *this; 
+			}
+			range2d_iterator_base operator++ (int) 
+			{
+				auto result = *this; 
+				++*this; 
+				return result;
+			}
+		protected:
+			T m_min;
+			T m_max;
+		};
+
+		template < typename T >
+		class bits_iterator_base : public forward_iterator_base< T >
+		{
+		public:
+			typedef typename base_underlying_type<T>::type base_type;
+			static const T invalid = T( 0 );
+
+			bits_iterator_base( T value, T current ) : forward_iterator_base( current ), m_full( value )
+			{
+				if( !( (base_type)value & (base_type)current ) )
+					next();
+			}
+			bits_iterator_base& operator++ () 
+			{
+				next();
+				return *this; 
+			}
+			bits_iterator_base operator++ (int) 
+			{
+				auto result = *this; 
+				++*this; 
+				return result;
+			}
+		private:
+			void next()
+			{
+				do
+				{
+					if ( m_value == invalid || m_full <= m_value ) { m_value = invalid; m_full = invalid; break; }
+					m_value = T((base_type)m_value << 1);
+				} while ( !( (base_type)m_full & (base_type)m_value ) );
+			}
+
+			T m_full;
+		};
+
+
+	} // namespace detail
+
+	template < typename T >
+	class range_iterator_provider
+	{
+	public:
+		class iterator : public detail::range_iterator_base<T>
+		{
+		public:
+			iterator( T value ) : detail::range_iterator_base<T>(value) {}
+		};
+
+		range_iterator_provider( T begin, T end ) : m_begin( begin ), m_end( end ) {}
+		iterator begin() { return m_begin; }
+		iterator end() { return m_end; }
+
+	protected:
+		iterator m_begin;
+		iterator m_end;
+	};
+
+	template < typename T >
+	class range2d_iterator_provider
+	{
+	public:
+		typedef T value_type;
+		typedef typename T::value_type element_type;
+
+		class iterator : public detail::range2d_iterator_base<element_type>
+		{
+		public:
+			iterator( value_type begin, element_type min, element_type max ) 
+				: detail::range2d_iterator_base<element_type>(begin, min, max) {}
+		};
+
+		range2d_iterator_provider( value_type begin, value_type end ) : m_begin( begin, begin.x, end.x ), m_end( T(begin.x, ++end.y ), begin.x, end.x ) {}
+		iterator begin() { return m_begin; }
+		iterator end() { return m_end; }
+
+	protected:
+		iterator m_begin;
+		iterator m_end;
+	};
+
+	template < typename T >
+	class bits_iterator_provider
+	{
+	public:
+		typedef typename base_underlying_type<T>::type base_type;
+		typedef detail::bits_iterator_base<T> iterator;
+		static const T invalid = T( 0 );
+
+		bits_iterator_provider( T value ) : m_value( value ) {}
+		iterator begin() { return iterator( m_value, T(1) ); }
+		iterator end() { return iterator( m_value, invalid ); }
+
+	protected:
+		T m_value;
+	};
+
+	template < typename T >
+	range_iterator_provider<T> range( T begin, T end )
+	{
+		return range_iterator_provider<T>( begin, end+1 );
+	}
+
+	template < typename T >
+	range2d_iterator_provider<T> range2d( T begin, T end )
+	{
+		return range2d_iterator_provider<T>( begin, end );
+	}
+
+	template < typename T >
+	range_iterator_provider<T> range( T end )
+	{
+		return range_iterator_provider<T>( 0, end );
+	}
+
+	template < typename T >
+	range2d_iterator_provider<T> range2d( T end )
+	{
+		return range2d_iterator_provider<T>( T(0,0), T( --end.x, --end.y ) );
+	}
+
+	template < typename C >
+	auto index( const C& c ) -> range_iterator_provider<decltype( c.size() )>
+	{
+		return range_iterator_provider( 0, c.size() );
+	}
+
+	template < typename T >
+	bits_iterator_provider<T> bits( T value )
+	{
+		return bits_iterator_provider<T>( value );
+	}
+
+
+}
+
+#endif // NV_CORE_RANGE_HH
Index: /trunk/nv/core/singleton.hh
===================================================================
--- /trunk/nv/core/singleton.hh	(revision 319)
+++ /trunk/nv/core/singleton.hh	(revision 319)
@@ -0,0 +1,120 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file singleton.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief singleton pattern
+ */
+
+#ifndef NV_CORE_SINGLETON_HH
+#define NV_CORE_SINGLETON_HH
+
+#include <cassert>
+
+namespace nv
+{
+	/**
+	 * singleton
+	 * @brief Represents an accessible static object that will only have one instance.
+	 */
+    template <class T>
+    class singleton
+    {
+    private:
+        static T *singleton_; ///< Pointer to the instance of this object type.
+
+    protected:
+
+		/**
+		 * Creates the single instance if one doesn't already exist.
+		 */
+        singleton()
+        {
+            assert(!singleton_);
+            singleton_ = static_cast<T*>(this);
+        }
+
+		/**
+		 * Destroys the instance.
+		 */
+        ~singleton()
+        {
+            assert(singleton_);
+            singleton_ = 0;
+        }
+
+    public:
+		/**
+		 * Checks to see if the instance exists.
+		 *
+		 * @returns True if this singleton has an instance assigned, false otherwise.
+		 */
+        static bool is_valid()
+        {
+            return singleton_ != 0;
+        }
+
+		/**
+		 * Returns the pointer to the instance.
+		 *
+		 * @returns The pointer to the instance.
+		 */
+        static T *pointer()
+        {
+            assert(singleton_);
+            return singleton_;
+        }
+		/**
+		 * Returns the object referenced by this singleton.
+		 */
+        static T &reference()
+        {
+            assert(singleton_);
+            return *singleton_;
+        }
+    };
+
+    template <class T>
+    T* singleton<T>::singleton_ = 0;
+
+
+	/**
+	 * auto_singleton
+	 * @brief Represents a singleton that automatically creates an instance if one doesn't already exist.
+	 */
+    template <class T>
+    class auto_singleton : public singleton<T>
+    {
+    public:
+		/**
+		 * Returns the pointer to the instance.  Makes an instance if one doesn't already exist.
+		 */
+        static T *pointer()
+        {
+            if ( !singleton<T>::is_valid() )
+            {
+                new T();
+            }
+            return singleton<T>::pointer();
+        }
+
+		/**
+		 * Returns the object referenced by this singleton.  Makes an instance if one doesn't already exist.
+		 */
+        static T &reference()
+        {
+            if ( !singleton<T>::is_valid() )
+            {
+                new T();
+            }
+            return singleton<T>::reference();
+        }
+    };
+
+} // namespace nv
+
+#endif // NV_CORE_SINGLETON_HH
Index: /trunk/nv/core/string.hh
===================================================================
--- /trunk/nv/core/string.hh	(revision 319)
+++ /trunk/nv/core/string.hh	(revision 319)
@@ -0,0 +1,251 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_CORE_STRING_HH
+#define NV_CORE_STRING_HH
+
+#include <string>
+#include <algorithm>
+#include <cstring>
+#include <sstream>
+#include <fstream>
+#include <nv/core/common.hh>
+#include <nv/core/exception.hh>
+
+namespace nv
+{
+	using std::string;
+
+	/**
+	* Utility function for converting any value to string.
+	*
+	* @param value value to be converted, needs to have << operator
+	*        to stream
+	* @throw runtime_error Throws runtime_error on conversion fail
+	* @return value converted to string
+	*/
+	template < class T >
+	string to_string( const T& value )
+	{
+		std::stringstream stream;
+		stream << value;
+
+		if ( stream.fail() )
+		{
+			NV_THROW( runtime_error, "bad cast" );
+		}
+
+		return stream.str();
+	}
+
+	/**
+	* Override function for special treatment of strings. Returns the
+	* value passed.
+	*/
+	inline string to_string( const string& value)
+	{
+		return value;
+	}
+
+	/**
+	* Utility function for converting a string to the given type
+	*
+	* @param vin the string representing the value
+	* @param vout the value to be read. Must be streamable with >>
+	* @throw runtime_error Throws runtime_error on conversion fail
+	*/
+	template < class T >
+	void from_string( const string& vin, T& vout )
+	{
+		std::istringstream value( vin );
+		value >> vout;
+
+		if ( value.fail() )
+		{
+			NV_THROW( runtime_error, "bad cast" );
+		}
+	}
+
+	/**
+	* Utility function for converting a string to the given type
+	*
+	* @param vin the string representing the value
+	* @throw runtime_error Throws runtime_error on conversion fail
+	*/
+	template < class T >
+	T string_cast( const string& vin )
+	{
+		T vout;
+		std::istringstream value( vin );
+		value >> vout;
+
+		if ( value.fail() )
+		{
+			NV_THROW( runtime_error, "bad cast" );
+		}
+		return vout;
+	}
+
+
+	/**
+	* Override function for special treatment of strings. Returns the
+	* value passed.
+	*/
+	inline void from_string( const string& vin, string& vout )
+	{
+		vout = vin;
+	}
+
+	/**
+	* Override function for special treatment of strings. Returns the
+	* value passed.
+	*/
+	template <>
+	inline std::string string_cast( const string& vin )
+	{
+		return vin;
+	}
+
+
+	/**
+	* Simple function for slurping a file into a string.
+	*/
+	inline std::string slurp( const std::string& filename )
+	{
+		std::ifstream input(filename);
+		if ( !input.is_open() ) NV_THROW( std::runtime_error, "File "+filename+" not found!");
+		std::stringstream sstr;
+		while(input >> sstr.rdbuf());
+		return sstr.str();
+	}
+
+	inline bool trim( std::string& str )
+	{
+		size_t endpos = str.find_last_not_of(" \r\n\t");
+		size_t startpos = str.find_first_not_of(" \r\n\t");
+
+		if ( string::npos != endpos || string::npos != startpos )
+		{
+			if ( string::npos == startpos ) startpos = 0;
+			if ( string::npos != endpos )   endpos = endpos+1-startpos;
+			str = str.substr( startpos, endpos );
+			return true;
+		}
+		return false;
+	}
+
+	inline bool rtrim( std::string& str )
+	{
+		size_t endpos = str.find_last_not_of(" \r\n\t");
+		if ( string::npos != endpos )
+		{
+			str = str.substr( 0, endpos+1 );
+			return true;
+		}
+		return false;
+	}
+
+	inline bool ltrim( std::string& str )
+	{
+		size_t startpos = str.find_first_not_of(" \r\n\t");
+		if( string::npos != startpos )
+		{
+			str = str.substr( startpos );
+			return true;
+		}
+		return false;
+	}
+
+	inline std::string trimmed( const std::string& str )
+	{
+		size_t endpos = str.find_last_not_of(" \r\n\t");
+		size_t startpos = str.find_first_not_of(" \r\n\t");
+
+		if ( string::npos != endpos || string::npos != startpos )
+		{
+			if ( string::npos == startpos ) startpos = 0;
+			if ( string::npos != endpos )   endpos = endpos+1-startpos;
+			return str.substr( startpos, endpos );
+		}
+		return str;
+	}
+
+	inline std::string rtrimmed( const std::string& str )
+	{
+		size_t endpos = str.find_last_not_of(" \r\n\t");
+		if ( string::npos != endpos )
+		{
+			return str.substr( 0, endpos+1 );
+		}
+		return str;
+	}
+
+	inline std::string ltrimmed( const std::string& str )
+	{
+		size_t startpos = str.find_first_not_of(" \r\n\t");
+		if( string::npos != startpos )
+		{
+			return str.substr( startpos );
+		}
+		return str;
+	}
+
+	inline bool ends_with( const std::string& s, const std::string & ending )
+	{
+		if ( s.length() >= ending.length() ) {
+			return ( 0 == s.compare (s.length() - ending.length(), ending.length(), ending) );
+		} else {
+			return false;
+		}
+	}
+
+	inline std::string& remove_chars( std::string& s, const std::string& chars ) 
+	{
+		s.erase(remove_if(s.begin(), s.end(), 
+			[&chars](const char& c) {
+				return chars.find(c) != std::string::npos;
+			}), s.end());
+		return s;
+	}
+
+	inline std::string remove_chars_copy( std::string s, const std::string& chars ) 
+	{
+		return remove_chars(s, chars);
+	}
+
+	template< typename T >
+	struct string_length
+	{
+		static size_t get( T ) { return 0; }
+	};
+	template< size_t S >
+	struct string_length< char[S] >
+	{
+		static size_t get( const char[S] ) { return S-1; }
+	};
+	template< size_t S >
+	struct string_length< const char[S] >
+	{
+		static size_t get( const char[S] ) { return S-1; }
+	};
+	template<>
+	struct string_length< char* >
+	{
+		static size_t get( const char* s ) { return std::strlen( s ); }
+	};
+	template<>
+	struct string_length< const char* >
+	{
+		static size_t get( const char* s ) { return std::strlen( s ); }
+	};
+	template<>
+	struct string_length< std::string >
+	{
+		static size_t get( const std::string& s ) { return s.length(); }
+	};
+
+
+}
+
+#endif // NV_CORE_STRING_HH
Index: /trunk/nv/core/time.hh
===================================================================
--- /trunk/nv/core/time.hh	(revision 319)
+++ /trunk/nv/core/time.hh	(revision 319)
@@ -0,0 +1,148 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file time.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief Time related functions
+ */
+
+#ifndef NV_CORE_TIME_HH
+#define NV_CORE_TIME_HH
+
+#include <nv/core/common.hh>
+
+namespace nv
+{
+	/**
+	 * Returns the amount of ticks of the processors high resolution 
+	 * timer. Currently only supported on GCC and MSVC. Probably only on
+	 * some architectures.
+	 *
+	 * @returns amount of ticks
+	 */
+	uint64 get_ticks();
+
+	/**
+	 * Performs an operating system sleep call.
+	 *
+	 * @param ms time in milliseconds to sleep
+	 */
+	void sleep( uint32 ms );
+
+	/**
+	 * Get millisecond count based on std::clock
+	 */
+	uint32 get_cpu_ms();
+
+	/**
+	 * Get microsecond count based on std::clock
+	 */
+	uint64 get_cpu_us();
+
+	/**
+	 * Get millisecond count based on system counter
+	 */
+	uint32 get_system_ms();
+
+	/**
+	 * Get microsecond count based on system counter
+	 */
+	uint64 get_system_us();
+
+	struct cpu_ms_timer 
+	{ 
+		typedef uint32 value_type;
+		static const value_type second = 1000;    
+		value_type operator()() { return get_cpu_ms(); } 
+	};
+
+	struct cpu_us_timer 
+	{ 
+		typedef uint64 value_type;
+		static const value_type second = 1000000; 
+		uint64 operator()() { return get_cpu_us(); } 
+	};
+
+	struct system_ms_timer 
+	{ 
+		typedef uint32 value_type;
+		static const value_type second = 1000;    
+		value_type operator()() { return get_system_ms(); } 
+	};
+
+	struct system_us_timer 
+	{ 
+		typedef uint64 value_type;
+		static const value_type second = 1000000; 
+		value_type operator()() { return get_system_us(); } 
+	};
+	
+	/**
+	 * Timer template class
+	 */
+	template < class Timer >
+	class timer_class
+	{
+	public:
+		typedef typename Timer::value_type value_type;
+
+		timer_class()	: last( Timer()() ) {}
+		void mark()	
+		{
+			value_type now = Timer()();
+			stored = now - last;
+			last = now;
+		}
+		value_type elapsed() const
+		{
+			return stored;
+		}
+	private:
+		value_type last;
+		value_type stored;
+	};
+
+	/**
+	 * FPS template class
+	 */
+	template < class Timer >
+	class fps_counter_class
+	{
+	public:
+		typedef typename Timer::value_type value_type;
+
+		fps_counter_class() : frames(1), last(0) {}
+		bool tick()
+		{
+			value_type now = Timer()();
+			if ( now - last >= Timer::second )
+			{
+				value = (static_cast<float>(frames) /
+					static_cast<float>(now - last))*Timer::second;
+				frames = 1;
+				last = now;
+				return true;
+			}
+			frames++;
+			return false;
+		}
+		f32 fps() const
+		{
+			return value;
+		}
+	private:
+		value_type last;
+		uint32     frames;
+		f32        value;
+	};
+
+	typedef timer_class< system_ms_timer > ms_timer;
+	typedef timer_class< system_us_timer > us_timer;
+	typedef fps_counter_class< system_ms_timer > fps_counter;
+
+} // namespace nv
+
+#endif // NV_CORE_TIME_HH
Index: /trunk/nv/core/transform.hh
===================================================================
--- /trunk/nv/core/transform.hh	(revision 319)
+++ /trunk/nv/core/transform.hh	(revision 319)
@@ -0,0 +1,107 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#ifndef NV_CORE_TRANSFORM_HH
+#define NV_CORE_TRANSFORM_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+
+namespace nv
+{
+
+	class transform
+	{
+	public:
+		transform() {}
+		explicit transform( const vec3& a_position ) : m_position( a_position ) {}
+		explicit transform( const quat& a_orientation ) : m_orientation( a_orientation ) {}
+		explicit transform( const mat4& a_matrix ) { set( a_matrix ); }
+		transform( const vec3& a_position, const quat& a_orientation ) : m_position( a_position ), m_orientation( a_orientation ) {}
+
+		void set_position( const vec3& a_position ) { m_position = a_position; }
+		void set_orientation( const quat& a_orientation ) { m_orientation = a_orientation; }
+		void set_orientation( const vec3& axis, float angle )
+		{
+			m_orientation = glm::angleAxis( angle, axis );
+		}
+
+		const vec3& get_position() const { return m_position; }
+		const quat& get_orientation() const { return m_orientation; }
+
+	public:
+		void move( const vec3& heading, float distance )
+		{
+			m_position += glm::normalize( heading ) * distance;
+		}
+		void translate( const vec3& absolute )
+		{
+			m_position += absolute;
+		}
+		void rotate( const vec3& axis, f32 angle )
+		{
+			quat temp( angle, axis );
+			m_orientation = temp * m_orientation;
+		}
+		void set( const mat4& from )
+		{
+			m_orientation = quat( from );
+			m_position    = vec3( from[3] );
+		}
+		mat4 extract() const
+		{
+			mat4 result = glm::mat4_cast( m_orientation );
+			result[3] = vec4( m_position, 1.0f );
+			return result;
+		}
+		transform inverse() const
+		{
+			quat new_orient( glm::inverse( m_orientation ) );
+			// TODO: simplify
+			return transform( -glm::mat3_cast(new_orient) * m_position, new_orient );
+		}
+
+		transform& operator*=(const transform& rhs)
+		{
+			m_position = m_position + m_orientation * rhs.m_position;
+			m_orientation = m_orientation * rhs.m_orientation;
+			return *this;
+		}
+
+		vec3 transformed( const vec3& v ) const
+		{
+			return m_orientation * v + m_position;
+		}
+	private:
+		vec3 m_position;
+		quat m_orientation;
+	};
+
+	inline transform operator*(transform lhs, const transform& rhs)
+	{
+		lhs *= rhs;
+		return lhs;
+	}
+
+	inline vec3 operator*(const vec3 lhs, const transform& rhs)
+	{
+		return rhs.transformed( lhs );
+	}
+
+	template <> struct enum_to_type< TRANSFORM > { typedef transform type; };
+	template <> struct type_to_enum< transform > { static const datatype type = TRANSFORM; };
+
+	template<>
+	inline transform interpolate( const transform& a, const transform& b, float value )
+	{
+		return transform( 
+			glm::mix  ( a.get_position(), b.get_position(), value ), 
+			glm::slerp( a.get_orientation(), b.get_orientation(), value ) 
+		);
+	}
+}
+
+#endif // NV_CORE_TRANSFORM_HH
Index: /trunk/nv/core/type_traits.hh
===================================================================
--- /trunk/nv/core/type_traits.hh	(revision 319)
+++ /trunk/nv/core/type_traits.hh	(revision 319)
@@ -0,0 +1,232 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+/**
+ * @file type_traits.hh
+ * @author Kornel Kisielewicz epyon@chaosforge.org
+ * @brief type traits
+ */
+// TODO: function_traits support only up to 4 parameters because:
+//    -- if you have more than 4 params, you're doing something wrong
+//    -- once the Variadic Templates cometh, for great justice we will win!
+
+#ifndef NV_CORE_TYPE_TRAITS_HH
+#define NV_CORE_TYPE_TRAITS_HH
+
+#include <nv/core/common.hh>
+#include <type_traits>
+
+namespace nv
+{
+
+	// These could be done much better
+	template <typename T>
+	struct is_cstring
+		: public std::integral_constant<bool,
+		std::is_same<       char *, typename std::decay< T >::type >::value ||
+		std::is_same< const char *, typename std::decay< T >::type >::value >
+		{};
+
+	template <typename T>
+	struct is_stdstring
+		: public std::integral_constant<bool,
+		std::is_same< std::string, typename std::decay< T >::type >::value 
+		>
+	{};
+
+	template < typename T > struct is_string : public std::integral_constant<bool, is_stdstring<T>::value || is_cstring<T>::value> {};
+
+	// Just for once, MSVC is the good guy, and everybody else sucks.
+	// Remove, once requiring standard-compliant CLANG/GCC versions.
+#if NV_COMPILER == NV_MSVC
+	using std::underlying_type;
+#elif NV_COMPILER == NV_CLANG
+	template < typename T >
+	struct underlying_type
+	{
+		typedef __underlying_type(T) type;
+	};
+#else
+	template< typename T >
+	struct underlying_type
+	{
+		typedef typename std::conditional<
+			T( -1 ) < T( 0 ),
+			typename std::make_signed< T >::type,
+			typename std::make_unsigned< T >::type
+			>::type type;
+	};
+#endif
+
+	namespace detail
+	{
+
+		template < typename F >
+		struct function_traits_impl
+		{
+
+		};
+
+		template < typename R >
+		struct function_traits_impl< R (*)(void) >
+		{
+			typedef R (*type)();
+			typedef R        return_type;
+			typedef void     class_type;
+			static const int arg_count = 0;
+		};
+
+		template < typename R, typename T1 >
+		struct function_traits_impl< R (*)( T1 ) >
+		{
+			typedef R (*type)();
+			typedef R        return_type;
+			typedef void     class_type;
+			static const int arg_count = 1;
+		};
+
+		template < typename R, typename T1, typename T2 >
+		struct function_traits_impl< R (*)( T1, T2 ) >
+		{
+			typedef R (*type)();
+			typedef R        return_type;
+			typedef void     class_type;
+			static const int arg_count = 2;
+		};
+
+		template < typename R, typename T1, typename T2, typename T3 >
+		struct function_traits_impl< R (*)( T1, T2, T3 ) >
+		{
+			typedef R (*type)();
+			typedef R        return_type;
+			typedef void     class_type;
+			static const int arg_count = 3;
+		};
+
+		template < typename R, typename T1, typename T2, typename T3, typename T4 >
+		struct function_traits_impl< R (*)( T1, T2, T3, T4 ) >
+		{
+			typedef R (*type)();
+			typedef R        return_type;
+			typedef void     class_type;
+			static const int arg_count = 4;
+		};
+
+		template < class C, typename R >
+		struct function_traits_impl< R (C::*)() >
+		{
+			typedef R (*type)();
+			typedef R       return_type;
+			typedef C       class_type;
+			static const int arg_count = 0;
+		};
+
+		template < class C, typename R, typename T1 >
+		struct function_traits_impl< R (C::*)( T1 ) >
+		{
+			typedef R (*type)();
+			typedef R       return_type;
+			typedef C       class_type;
+			static const int arg_count = 1;
+		};
+
+		template < class C, typename R, typename T1, typename T2 >
+		struct function_traits_impl< R (C::*)( T1, T2 ) >
+		{
+			typedef R (*type)();
+			typedef R       return_type;
+			typedef C       class_type;
+			static const int arg_count = 2;
+		};
+
+		template < class C, typename R, typename T1, typename T2, typename T3 >
+		struct function_traits_impl< R (C::*)( T1, T2, T3 ) >
+		{
+			typedef R (*type)();
+			typedef R       return_type;
+			typedef C       class_type;
+			static const int arg_count = 3;
+		};
+
+		template < class C, typename R, typename T1, typename T2, typename T3, typename T4 >
+		struct function_traits_impl< R (C::*)( T1, T2, T3, T4 ) >
+		{
+			typedef R (*type)();
+			typedef R       return_type;
+			typedef C       class_type;
+			static const int arg_count = 4;
+		};
+
+	}
+
+	template < typename F >
+	struct function_traits : public detail::function_traits_impl< F >
+	{
+
+	};
+
+	template < typename T >
+	struct return_type
+	{
+		typedef typename function_traits< T >::return_type type;
+	};
+
+	template < typename T >
+	struct memfn_class_type
+	{
+		typedef typename function_traits< T >::class_type type;
+	};
+
+	template<typename T>
+	struct is_container
+	{
+	private:
+		typedef char                      yes;
+		typedef struct { char array[2]; } no;
+		template<typename C> static yes test(typename C::iterator*);
+		template<typename C> static no  test(...);
+	public:
+		static const bool value = sizeof(test<T>(0)) == sizeof(yes);
+	};
+
+	template<>
+	struct is_container< std::string > {
+		static const bool value = false;
+	};
+
+	template <typename TYPE> 
+	void construct_object(void* object)
+	{
+		new (object) TYPE;
+	}
+	template <typename TYPE> 
+	void destroy_object(void* object)
+	{
+		((TYPE*)object)->TYPE::~TYPE();
+	}
+
+	template< typename T, typename IS_ENUM >
+	struct base_underlying_type_helper
+	{
+		typedef T type;
+	};
+
+	template< typename T >
+	struct base_underlying_type_helper< T, std::true_type >
+	{
+		typedef typename nv::underlying_type<T>::type type;
+	};
+
+
+	template< typename T >
+	struct base_underlying_type
+	{
+		typedef typename base_underlying_type_helper< T, typename std::is_enum<T>::type >::type type;
+	};
+
+
+}
+
+#endif // NV_CORE_TYPE_TRAITS_HH
Index: /trunk/nv/core/uid.hh
===================================================================
--- /trunk/nv/core/uid.hh	(revision 319)
+++ /trunk/nv/core/uid.hh	(revision 319)
@@ -0,0 +1,109 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+/**
+ * @file uid.hh
+ * @author Kornel Kisielewicz
+ * @brief Implements a unique identifier class manager
+ */
+
+#ifndef NV_CORE_UID_HH
+#define NV_CORE_UID_HH
+
+#include <nv/core/common.hh>
+#include <unordered_map>
+
+namespace nv
+{
+
+	class uid_store_raw
+	{
+	public:
+		
+		/**
+		 * Creates a new instance of the unique identifier store.
+		 */
+		uid_store_raw();
+
+		/**
+		 * Gets the object with the specified ID.
+		 *
+		 * @param auid The ID to fetch.
+		 * @returns The stored object for that ID.
+		 */
+		void* get( uid auid ) const;
+
+		/**
+		 * Removes the object with the specified ID.
+		 *
+		 * @param auid The ID to remove.
+		 * @returns True if the removal was successful, false if the ID didn't exist.
+		 */
+		bool remove( uid auid );
+
+		/**
+		 * Adds an object to the store assigned to the indicated ID.
+		 *
+		 * @param o The object to add to the store.
+		 * @param auid The ID to assign to the object.
+		 */
+		void insert( void* o, uid auid );
+
+		/**
+		 * Adds an object to the store and assigns it a new ID.
+		 *
+		 * @param o The object to add to the store.
+		 * @returns The ID the object was store under.
+		 */
+		uid insert( void* o );
+
+		/**
+		 * Gets the next available ID.
+		 *
+		 * @returns The next ID in the store.
+		 */
+		uid request_uid();
+
+		/**
+		 * Destroys the unique identifier store.
+		 */
+		~uid_store_raw();
+
+	protected:
+		typedef std::unordered_map< uid, void* > map;
+		map m_map; ///< The hash map everything is stored in.
+		uid m_current; ///< The last UID assigned.
+	};
+
+	template < typename T >
+	class uid_store
+	{
+	public:
+		T* get( uid auid ) const      { return static_cast<T*>( m_store.get( auid ) ); }
+		bool remove( uid auid )       { m_store.remove( auid ); }
+		void insert( T* o, uid auid ) { m_store.insert( o, auid ); }
+		uid insert( T* o )            { return m_store.insert( o ); }
+		uid request_uid()             { return m_store.request_uid(); }
+
+		/**
+		 * Retrieves an object and casts it to the specified type.
+		 *
+		 * @tparam T The type to cast to.
+		 * @param auid The ID the object is stored under.
+		 * @returns An object of the indicated type that was stored at the indicated ID.
+		 */
+		template< typename U >
+		U* get_as( uid auid ) const 
+		{
+			return dynamic_cast< U* >( get(auid) );
+		}
+	protected:
+		uid_store_raw m_store;
+	};
+	
+}
+
+#endif // NV_CORE_UID_HH
Index: /trunk/nv/curses/curses_terminal.hh
===================================================================
--- /trunk/nv/curses/curses_terminal.hh	(revision 318)
+++ /trunk/nv/curses/curses_terminal.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,7 +13,7 @@
 #define NV_CURSES_TERMINAL_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/terminal.hh>
-#include <nv/io_event.hh>
+#include <nv/core/io_event.hh>
 
 namespace nv
Index: /trunk/nv/engine/program_manager.hh
===================================================================
--- /trunk/nv/engine/program_manager.hh	(revision 318)
+++ /trunk/nv/engine/program_manager.hh	(revision 319)
@@ -14,5 +14,5 @@
 #define NV_ENGINE_PROGRAM_MANAGER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/engine/resource_system.hh>
 
Index: /trunk/nv/engine/resource_system.hh
===================================================================
--- /trunk/nv/engine/resource_system.hh	(revision 318)
+++ /trunk/nv/engine/resource_system.hh	(revision 319)
@@ -14,5 +14,5 @@
 #define NV_ENGINE_RESOURCE_MANAGER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/context.hh>
 #include <nv/lua/lua_state.hh>
Index: unk/nv/exception.hh
===================================================================
--- /trunk/nv/exception.hh	(revision 318)
+++ 	(revision )
@@ -1,46 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file exception.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief nv exception bases
- */
-
-#ifndef NV_EXCEPTION_HH
-#define NV_EXCEPTION_HH
-
-#include <nv/common.hh>
-#include <string>
-#include <exception>
-#include <stdexcept>
-
-namespace nv
-{
-	/**
-	 * NV logic_error.
-	 *
-	 * Inherits std::logic_error.
-	 */
-	class logic_error : public std::logic_error
-	{
-	public:
-		explicit logic_error( const std::string& msg ) : std::logic_error( msg ) {}
-	};
-
-	/**
-	 * NV runtime_error.
-	 *
-	 * Inherits std::runtime_error.
-	 */
-	class runtime_error : public std::runtime_error
-	{
-	public:
-		explicit runtime_error( const std::string& msg ) : std::runtime_error( msg ) {}
-	};
-}
-
-#endif // NV_EXCEPTION_HH
Index: unk/nv/flags.hh
===================================================================
--- /trunk/nv/flags.hh	(revision 318)
+++ 	(revision )
@@ -1,221 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file flags.hh
- * @author Kornel Kisielewicz
- * @brief flags
- */
-
-#ifndef NV_FLAGS_HH
-#define NV_FLAGS_HH
-
-#include <nv/common.hh>
-#include <nv/type_traits.hh>
-#include <nv/array.hh>
-
-namespace nv
-{
-	template < uint32 SIZE, typename T = uint32 >
-	class flags
-	{
-	public:
-		class reference
-		{
-			friend class flags<SIZE,T>;
-		public:
-			typedef bool value_type;
-			typedef T    index_type;
-
-			reference& operator=( value_type a_value )
-			{
-				m_flags->set( m_index, a_value );
-				return (*this);
-			}
-			reference& operator=( const reference& a_value )
-			{
-				m_flags->set( m_index, bool( a_value ) );
-				return (*this);
-			}
-			operator bool() const 
-			{
-				return m_flags->test( m_index );
-			}
-
-		private:
-			reference() : m_flags( nullptr ), m_index( index_type(0) ) {}
-
-			reference( flags<SIZE,T>* a_flags, index_type a_index )
-				: m_flags( a_flags ), m_index( a_index )
-			{	
-			}
-
-		private:
-			flags<SIZE,T>* m_flags;
-			index_type     m_index;
-		};
-
-		class enumerator
-		{
-			friend class flags<SIZE,T>;
-		public:
-			typedef T              index_type;
-			typedef T              value_type;
-			typedef T*             iterator;
-			typedef const T*       const_iterator;
-			typedef T&             reference;
-			typedef const T&       const_reference;
-			typedef std::size_t    size_type;
-			typedef std::ptrdiff_t difference_type;
-
-			T operator* () const { return m_index; }
-			T const* operator-> () const { return &m_index; }
-			bool operator== ( const enumerator& rhs ) const
-			{
-				return ( m_index == rhs.m_index ) && ( m_flags == rhs.m_flags );
-			}
-			bool operator!= ( const enumerator& rhs ) const
-			{
-				return !( *this == rhs );
-			}
-			
-			enumerator& operator++ () 
-			{
-				next();
-				return *this; 
-			}
-			enumerator operator++ (int) 
-			{
-				auto result = *this; 
-				++*this; 
-				return result;
-			}
-		protected:
-			enumerator() : m_flags( nullptr ), m_index( index_type(0) ) {}
-
-			enumerator( const flags<SIZE,T>* a_flags, index_type a_index )
-				: m_flags( a_flags ), m_index( a_index )
-			{	
-				if ( a_flags && !a_flags->test( a_index ) ) next();
-			}
-
-			void next()
-			{
-				if ( m_flags )
-				do 
-				{
-					if ( raw_index_type(m_index) >= SIZE ) { m_flags = nullptr; m_index = index_type(0); return; }
-					m_index = index_type((raw_index_type)m_index + 1);
-				} while ( !m_flags->test( m_index ) );
-			}
-
-			const flags<SIZE,T>* m_flags;
-			index_type           m_index;
-		};
-
-		typedef uint8     data_type;
-		typedef T         index_type;
-		typedef uint32 size_type;
-		typedef typename base_underlying_type<T>::type raw_index_type;
-
-		static const size_type data_type_size = sizeof( data_type ) * 8;
-		static const size_type data_count     = SIZE;
-		static const size_type data_size      = (SIZE+data_type_size-1) / data_type_size;
-
-		enumerator begin()  const { return enumerator( this, index_type(0) ); }
-		enumerator cbegin() const { return enumerator( this, index_type(0) ); }
-
-		enumerator end()  const { return enumerator(); }
-		enumerator cend() const { return enumerator(); }
-
-		flags()
-		{
-			reset();
-		}
-
-		explicit flags( const data_type* a_data )
-		{
-			assign( a_data );
-		}
-
-		void assign( const data_type* a_data )
-		{
-			std::copy( a_data, a_data + data_size, m_data );
-		}
-
-		void reset()
-		{
-			std::fill( m_data, m_data + data_size, 0 );
-		}
-
-		void include( index_type i )
-		{
-			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
-			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
-			m_data[ idx ] |= 1 << static_cast< data_type >( pos );
-		}
-
-		void exclude( index_type i )
-		{
-			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
-			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
-			m_data[ idx ] &= ~(1 << static_cast< data_type >( pos ) );
-		}
-
-		void set( index_type i, bool value )
-		{
-			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
-			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
-			if ( value )
-				m_data[ idx ] |= 1 << static_cast< data_type >( pos );
-			else
-				m_data[ idx ] &= ~(1 << static_cast< data_type >( pos ) );
-		}
-
-		bool test( index_type i ) const
-		{
-			raw_index_type idx = static_cast< raw_index_type >( i ) / data_type_size;
-			raw_index_type pos = static_cast< raw_index_type >( i ) % data_type_size;
-			return ( m_data[ idx ] & ( 1 << static_cast< data_type >( pos ) ) ) != 0;
-		}
-
-		const data_type* data() const
-		{
-			return m_data;
-		}
-
-		data_type* data()
-		{
-			return m_data;
-		}
-
-		size_type size() const
-		{
-			return data_count;
-		}
-
-		size_type capacity() const
-		{
-			return data_size;
-		}
-
-		bool operator[]( index_type idx ) const
-		{
-			return test( idx );
-		}
-
-		reference operator[]( index_type idx )
-		{
-			return reference( this, idx );
-		}
-
-	private:
-		data_type m_data[ data_size ];
-	};
-
-} // namespace nv
-
-#endif // NV_FLAGS_HH
Index: /trunk/nv/fmod/fmod_audio.hh
===================================================================
--- /trunk/nv/fmod/fmod_audio.hh	(revision 318)
+++ /trunk/nv/fmod/fmod_audio.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_FMOD_AUDIO_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/audio.hh>
 
Index: /trunk/nv/formats/assimp_loader.hh
===================================================================
--- /trunk/nv/formats/assimp_loader.hh	(revision 318)
+++ /trunk/nv/formats/assimp_loader.hh	(revision 319)
@@ -8,5 +8,5 @@
 #define NV_ASSIMP_LOADER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/io/string_table.hh>
 #include <nv/interface/mesh_loader.hh>
Index: /trunk/nv/formats/md2_loader.hh
===================================================================
--- /trunk/nv/formats/md2_loader.hh	(revision 318)
+++ /trunk/nv/formats/md2_loader.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,7 +14,7 @@
 #define NV_MD2_LOADER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <unordered_map>
-#include <vector>
+#include <nv/core/array.hh>
 #include <nv/interface/mesh_loader.hh>
 
Index: /trunk/nv/formats/md3_loader.hh
===================================================================
--- /trunk/nv/formats/md3_loader.hh	(revision 318)
+++ /trunk/nv/formats/md3_loader.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,8 +14,8 @@
 #define NV_MD3_LOADER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <unordered_map>
-#include <vector>
-#include <nv/transform.hh>
+#include <nv/core/array.hh>
+#include <nv/core/transform.hh>
 #include <nv/interface/mesh_data.hh>
 #include <nv/interface/mesh_loader.hh>
Index: /trunk/nv/formats/md5_loader.hh
===================================================================
--- /trunk/nv/formats/md5_loader.hh	(revision 318)
+++ /trunk/nv/formats/md5_loader.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,6 +14,6 @@
 #define NV_MD5_LOADER_HH
 
-#include <nv/common.hh>
-#include <nv/array.hh>
+#include <nv/core/common.hh>
+#include <nv/core/array.hh>
 #include <nv/interface/mesh_loader.hh>
 
Index: /trunk/nv/formats/nmd_loader.hh
===================================================================
--- /trunk/nv/formats/nmd_loader.hh	(revision 318)
+++ /trunk/nv/formats/nmd_loader.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_NMD_LOADER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/mesh_loader.hh>
 #include <nv/interface/mesh_data.hh>
Index: /trunk/nv/formats/obj_loader.hh
===================================================================
--- /trunk/nv/formats/obj_loader.hh	(revision 318)
+++ /trunk/nv/formats/obj_loader.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,5 +14,5 @@
 #define NV_OBJ_LOADER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/mesh_loader.hh>
 #include <nv/interface/mesh_data.hh>
Index: /trunk/nv/gfx/animation.hh
===================================================================
--- /trunk/nv/gfx/animation.hh	(revision 318)
+++ /trunk/nv/gfx/animation.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,12 +8,12 @@
 #define NV_ANIMATION_HH
 
-#include <nv/common.hh>
-#include <vector>
+#include <nv/core/common.hh>
+#include <nv/core/array.hh>
 #include <nv/interface/stream.hh>
-#include <nv/math.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/animation_key.hh>
 #include <nv/interface/interpolation_raw.hh>
 #include <nv/interface/interpolation_template.hh>
-#include <nv/transform.hh>
+#include <nv/core/transform.hh>
 #include <glm/gtc/matrix_transform.hpp>
 
Index: /trunk/nv/gfx/debug_draw.hh
===================================================================
--- /trunk/nv/gfx/debug_draw.hh	(revision 318)
+++ /trunk/nv/gfx/debug_draw.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 #define NV_DEBUG_DRAW_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/context.hh>
 
Index: /trunk/nv/gfx/image.hh
===================================================================
--- /trunk/nv/gfx/image.hh	(revision 318)
+++ /trunk/nv/gfx/image.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 #define NV_IMAGE_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/image_data.hh>
 
Index: /trunk/nv/gfx/keyframed_mesh.hh
===================================================================
--- /trunk/nv/gfx/keyframed_mesh.hh	(revision 318)
+++ /trunk/nv/gfx/keyframed_mesh.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_KEYFRAMED_MESH_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/context.hh>
 #include <nv/interface/animated_mesh.hh>
Index: /trunk/nv/gfx/mesh_creator.hh
===================================================================
--- /trunk/nv/gfx/mesh_creator.hh	(revision 318)
+++ /trunk/nv/gfx/mesh_creator.hh	(revision 319)
@@ -8,6 +8,6 @@
 #define NV_MESH_CREATOR_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/mesh_data.hh>
 
Index: /trunk/nv/gfx/particle_engine.hh
===================================================================
--- /trunk/nv/gfx/particle_engine.hh	(revision 318)
+++ /trunk/nv/gfx/particle_engine.hh	(revision 319)
@@ -1,9 +1,15 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
 #ifndef NV_GFX_PARTICLE_ENGINE
 #define NV_GFX_PARTICLE_ENGINE
 
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/array.hh>
-#include <nv/handle.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+#include <nv/core/array.hh>
+#include <nv/core/handle.hh>
 #include <nv/lua/lua_state.hh>
 #include <nv/gfx/texture_atlas.hh>
Index: /trunk/nv/gfx/skeletal_mesh.hh
===================================================================
--- /trunk/nv/gfx/skeletal_mesh.hh	(revision 318)
+++ /trunk/nv/gfx/skeletal_mesh.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_SKELETAL_MESH_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/context.hh>
 #include <nv/interface/animated_mesh.hh>
Index: /trunk/nv/gfx/sliced_buffer.hh
===================================================================
--- /trunk/nv/gfx/sliced_buffer.hh	(revision 318)
+++ /trunk/nv/gfx/sliced_buffer.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -11,7 +11,6 @@
 #define NV_SLICED_BUFFER_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/interface/vertex_buffer.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 
 namespace nv
@@ -271,7 +270,7 @@
 		static const int value_type_size = sizeof(T);
 
-		indexed_sliced_buffer( device* dev, buffer_hint hint, int initial_size, int initial_index_size )
-			: m_vertex_buffer( dev, VERTEX_BUFFER, hint, initial_size )
-			, m_index_buffer( dev, INDEX_BUFFER, hint, initial_index_size )
+		indexed_sliced_buffer( context* ctx, buffer_hint hint, int initial_size, int initial_index_size )
+			: m_vertex_buffer( ctx, VERTEX_BUFFER, hint, initial_size )
+			, m_index_buffer( ctx, INDEX_BUFFER, hint, initial_index_size )
 		{
 
@@ -295,5 +294,6 @@
 		int get_vertex_size()     const { return m_vertex_buffer.get_size(); }
 		int get_index_size()      const { return m_index_buffer.get_size(); }
-		buffer* get_buffer() { return m_vertex_buffer.get_buffer(); }
+		buffer get_vertex_buffer() { return m_vertex_buffer.get_buffer(); }
+		buffer get_index_buffer()  { return m_index_buffer.get_buffer(); }
 		sliced_vertex_buffer& get_vertex_cache() { return m_vertex_buffer; }
 		sliced_index_buffer&  get_index_cache()  { return m_index_buffer; }
Index: /trunk/nv/gfx/texture_atlas.hh
===================================================================
--- /trunk/nv/gfx/texture_atlas.hh	(revision 318)
+++ /trunk/nv/gfx/texture_atlas.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -10,6 +10,6 @@
 #define NV_TEXTURE_ATLAS_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <nv/gfx/image.hh>
 #include <vector>
Index: /trunk/nv/gfx/texture_font.hh
===================================================================
--- /trunk/nv/gfx/texture_font.hh	(revision 318)
+++ /trunk/nv/gfx/texture_font.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,8 +8,8 @@
 #define NV_TEXTURE_FONT_HH
 
-#include <nv/common.hh>
-#include <nv/string.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
 #include <unordered_map>
-#include <nv/math.hh>
+#include <nv/core/math.hh>
 #include <nv/gfx/texture_atlas.hh>
 
Index: /trunk/nv/gl/gl_context.hh
===================================================================
--- /trunk/nv/gl/gl_context.hh	(revision 318)
+++ /trunk/nv/gl/gl_context.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/nv/gl/gl_device.hh
===================================================================
--- /trunk/nv/gl/gl_device.hh	(revision 318)
+++ /trunk/nv/gl/gl_device.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/nv/gl/gl_enum.hh
===================================================================
--- /trunk/nv/gl/gl_enum.hh	(revision 318)
+++ /trunk/nv/gl/gl_enum.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,8 +13,7 @@
 #define NV_GL_ENUM_HH
 
-#include <nv/math.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/clear_state.hh>
 #include <nv/interface/render_state.hh>
-#include <nv/interface/vertex_buffer.hh>
 #include <nv/interface/image_data.hh>
 #include <nv/interface/context.hh>
Index: /trunk/nv/gl/gl_window.hh
===================================================================
--- /trunk/nv/gl/gl_window.hh	(revision 318)
+++ /trunk/nv/gl/gl_window.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/nv/gui/gui_common.hh
===================================================================
--- /trunk/nv/gui/gui_common.hh	(revision 318)
+++ /trunk/nv/gui/gui_common.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,6 +14,6 @@
 #define NV_GUI_COMMON_HH
 
-#include <nv/common.hh>
-#include <nv/handle.hh>
+#include <nv/core/common.hh>
+#include <nv/core/handle.hh>
 
 namespace nv
Index: /trunk/nv/gui/gui_element.hh
===================================================================
--- /trunk/nv/gui/gui_element.hh	(revision 318)
+++ /trunk/nv/gui/gui_element.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,8 +14,10 @@
 #define NV_GUI_ELEMENT_HH
 
-#include <nv/common.hh>
-#include <nv/position.hh>
-#include <nv/io_event.hh>
+#include <nv/core/common.hh>
+#include <nv/core/position.hh>
+#include <nv/core/io_event.hh>
+#include <nv/core/string.hh>
 #include <nv/gui/gui_common.hh>
+#include <list>
 
 namespace nv
Index: /trunk/nv/gui/gui_environment.hh
===================================================================
--- /trunk/nv/gui/gui_environment.hh	(revision 318)
+++ /trunk/nv/gui/gui_environment.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -17,7 +17,7 @@
 #include <nv/gui/gui_style.hh>
 #include <nv/lua/lua_state.hh>
-#include <nv/io_event.hh>
+#include <nv/core/io_event.hh>
 #include <nv/interface/window.hh>
-#include <nv/array.hh>
+#include <nv/core/array.hh>
 
 namespace nv
Index: /trunk/nv/gui/gui_renderer.hh
===================================================================
--- /trunk/nv/gui/gui_renderer.hh	(revision 318)
+++ /trunk/nv/gui/gui_renderer.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,7 +14,6 @@
 #define NV_GUI_RENDERER_HH
 
-#include <nv/object.hh>
-#include <nv/position.hh>
-#include <nv/math.hh>
+#include <nv/core/position.hh>
+#include <nv/core/math.hh>
 #include <nv/gui/gui_common.hh>
 #include <nv/gui/gui_style.hh>
Index: /trunk/nv/gui/gui_style.hh
===================================================================
--- /trunk/nv/gui/gui_style.hh	(revision 318)
+++ /trunk/nv/gui/gui_style.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: unk/nv/handle.hh
===================================================================
--- /trunk/nv/handle.hh	(revision 318)
+++ 	(revision )
@@ -1,314 +1,0 @@
-// Copyright (C) 2014 ChaosForge Ltd
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file handle.hh
- * @author Kornel Kisielewicz
- */
-
-#ifndef NV_HANDLE_HH
-#define NV_HANDLE_HH
-
-#include <nv/common.hh>
-#include <nv/array.hh>
-
-namespace nv
-{
-
-	template < 
-		typename T = uint32, 
-		unsigned IBITS = 16,
-		unsigned CBITS = 16,
-		typename TAG = void 
-	>
-	class handle
-	{
-	public:
-		typedef T value_type;
-		static const int INDEX_BITS   = IBITS;
-		static const int COUNTER_BITS = IBITS;
-		static const T MAX_INDEX   = (1 << IBITS) - 1;
-		static const T MAX_COUNTER = (1 << CBITS) - 1;
-
-		handle() : m_index(0), m_counter(0) {}
-
-		inline bool operator==(const handle& rhs) const {return m_index == rhs.m_index && m_counter == rhs.m_counter; }
-		inline bool operator!=(const handle& rhs) const {return !(*this == rhs);}
-
-		bool is_nil() const { return m_index == 0 && m_counter == 0; }
-		bool is_valid() const { return !is_nil(); }
-		T index() const { return m_index; }
-		size_t hash() const { return std::hash<T>()( m_counter << IBITS | m_index ); }
-	protected:
-		T m_index   : IBITS;
-		T m_counter : CBITS;
-
-		handle( T a_index, T a_counter ) : m_index( a_index ), m_counter( a_counter ) {}
-		template < typename H, typename I >
-		friend class index_store;
-	};
-
-
-
-	template < typename HANDLE, typename TINDEX = sint32 >
-	class index_store
-	{
-	public:
-		typedef HANDLE handle;
-		typedef TINDEX index_type;
-		typedef typename HANDLE::value_type value_type;
-
-		index_store() : m_first_free(-1), m_last_free(-1) {}
-
-		handle create_handle( index_type index )
-		{
-			value_type i       = get_free_entry();
-			m_entries[i].index = index;
-			m_entries[i].counter++;
-			return handle( i, m_entries[i].counter );
-		}
-
-		void free_handle( handle h )
-		{
-			m_entries[ h.m_index ].index     = -1;
-			m_entries[ h.m_index ].next_free = -1;
-			if ( m_last_free == -1 )
-			{
-				m_first_free = m_last_free = h.m_index;
-				return;
-			}
-			m_entries[ m_last_free ].next_free = h.m_index;
-			m_last_free = h.m_index;
-		}
-
-		void swap_indices( handle h1, handle h2 )
-		{
-			std::swap( m_entries[ h1.m_index ].index, m_entries[ h2.m_index ].index );
-		}
-
-		sint32 get_index( handle h ) const
-		{
-			return m_entries[ h.m_index ].counter == h.m_counter ? m_entries[ h.m_index ].index : -1;
-		}
-	private:
-		struct index_entry
-		{
-			index_type index;
-			value_type counter;
-			index_type next_free;
-
-			index_entry() : index(0), counter(0), next_free(-1) {}
-		};
-
-		value_type get_free_entry()
-		{
-			if ( m_first_free != -1 )
-			{
-				value_type result = (value_type)m_first_free;
-				m_first_free = m_entries[result].next_free;
-				m_entries[result].next_free = -1;
-				if ( m_first_free == -1 ) m_last_free = -1;
-				return result;
-			}
-			m_entries.emplace_back();
-			return value_type( m_entries.size() - 1 );
-		}
-
-		index_type m_first_free;
-		index_type m_last_free;
-		std::vector< index_entry > m_entries;
-	};
-
-	template < typename T, typename HANDLE = handle<>, typename TINDEX = sint32 >
-	class packed_indexed_array
-	{
-	public:
-		typedef HANDLE                   handle;
-		typedef TINDEX                   index_type;
-		typedef std::vector< T >         storage;
-		typedef T                        value_type;
-		typedef typename storage::iterator        iterator;
-		typedef typename storage::const_iterator  const_iterator;
-		typedef typename storage::reference       reference;
-		typedef typename storage::const_reference const_reference;
-
-		packed_indexed_array() {}
-		packed_indexed_array( uint32 reserve )
-		{
-			m_data.reserve( reserve );
-			m_indexes.reserve( reserve );
-		}
-
-		T* insert( handle h )
-		{
-			resize_indexes_to( h.index() );
-			m_indexes[ h.index() ] = m_data.size();
-			m_handles.push_back( h );
-			m_data.emplace_back();
-			return &(m_data.back());
-		}
-
-		bool exists( handle h )
-		{
-			if ( h.is_nil() || h.index() >= m_indexes.size() ) return false;
-			return m_indexes[ h.index() ] >= 0;		
-		}
-
-		T* get( handle h )
-		{
-			if ( h.is_nil() || h.index() >= m_indexes.size() ) return nullptr;
-			index_type i = m_indexes[ h.index() ];
-			return i >= 0 ? &(m_data[ i ]) : nullptr;
-		}
-
-		void remove( handle h )
-		{
-			handle swap_handle    = m_handles.back();
-			sint32 dead_eindex    = m_indexes[ h.index() ];
-			if ( dead_eindex != (sint32)m_data.size()-1 )
-			{
-				m_data[ dead_eindex ]            = m_data.back();
-				m_handles[ dead_eindex ]         = swap_handle;
-				m_indexes[ swap_handle.index() ] = dead_eindex;
-			}
-			m_data.pop_back();
-			m_handles.pop_back();
-			m_indexes[ h.index() ] = -1;
-		}
-
-		void clear()
-		{
-			m_data.clear();
-			m_handles.clear();
-			m_indexes.clear();
-		}
-
-		const value_type& operator[] ( index_type i ) const { return m_data[i]; }
-		value_type& operator[] ( index_type i ) { return m_data[i]; }
-		size_t size() const { return m_data.size(); }
-
-		iterator        begin()        { return m_data.begin(); }
-		const_iterator  begin()  const { return m_data.cbegin(); }
-		const_iterator  cbegin() const { return m_data.cbegin(); }
-
-		iterator        end()        { return m_data.end(); }
-		const_iterator  end()  const { return m_data.cend(); }
-		const_iterator  cend() const { return m_data.cend(); }
-
-	private:
-		void resize_indexes_to( index_type i )
-		{
-			index_type size = (index_type)m_indexes.size();
-			if ( i >= size )
-			{
-				if ( size == 0 ) size = 1;
-				while ( i >= size ) size = size * 2;
-				m_indexes.resize( size, -1 );
-			}
-		}
-
-		std::vector< T >          m_data;
-		std::vector< handle >     m_handles;
-		std::vector< index_type > m_indexes;
-	};
-
-
-	template < typename T, typename HANDLE = handle<>, typename TINDEX = sint32 >
-	class entity_store
-	{
-	public:
-		typedef HANDLE                   handle;
-		typedef TINDEX                   index_type;
-		typedef std::vector< T >         storage;
-		typedef T                        value_type;
-		typedef typename storage::iterator        iterator;
-		typedef typename storage::const_iterator  const_iterator;
-		typedef typename storage::reference       reference;
-		typedef typename storage::const_reference const_reference;
-
-		entity_store() {}
-
-		explicit entity_store( uint32 reserve )
-		{
-			m_handles.reserve( reserve );
-			m_data.reserve( reserve );
-		}
-
-		handle create()
-		{
-			m_data.emplace_back();
-			m_handles.push_back( m_indexes.create_handle( sint32( m_data.size() - 1 ) ) );
-			return m_handles.back();
-		}
-
-		const value_type* get( handle h ) const
-		{
-			if ( h.is_nil() ) return nullptr;
-			sint32 eindex = m_indexes.get_index( h );
-			return eindex >= 0 ? &(m_data[ eindex ]) : nullptr;
-		}
-
-		value_type* get( handle h )
-		{
-			if ( h.is_nil() ) return nullptr;
-			sint32 eindex = m_indexes.get_index( h );
-			return eindex >= 0 ? &(m_data[ eindex ]) : nullptr;
-		}
-
-		void destroy( handle e )
-		{
-			handle swap_handle    = m_handles.back();
-			sint32 dead_eindex    = m_indexes.get_index( e );
-			if ( dead_eindex != (sint32)m_data.size()-1 )
-			{
-				m_data[ dead_eindex ]    = m_data.back();
-				m_handles[ dead_eindex ] = m_handles.back();
-			}
-			m_data.pop_back();
-			m_handles.pop_back();
-			m_indexes.swap_indices( e, swap_handle );
-			m_indexes.free_handle( e );
-		}
-
-		handle get_handle( index_type i ) const { return m_handles[i]; }
-		const value_type& operator[] ( index_type i ) const { return m_data[i]; }
-		value_type& operator[] ( index_type i ) { return m_data[i]; }
-		size_t size() const { return m_data.size(); }
-
-		iterator        begin()        { return m_data.begin(); }
-		const_iterator  begin()  const { return m_data.cbegin(); }
-		const_iterator  cbegin() const { return m_data.cbegin(); }
-
-		iterator        end()        { return m_data.end(); }
-		const_iterator  end()  const { return m_data.cend(); }
-		const_iterator  cend() const { return m_data.cend(); }
-
-	private:
-		std::vector< handle >         m_handles;
-		storage                       m_data;
-		index_store< handle, TINDEX > m_indexes;
-	};
-
-}
-
-namespace std
-{
-	template < 
-		typename T, 
-		unsigned IBITS,
-		unsigned CBITS,
-		typename TAG
-	>
-	struct hash<nv::handle<T,IBITS,CBITS,TAG>>
-	{
-		size_t operator()(const nv::handle<T,IBITS,CBITS,TAG>& h) const
-		{
-			return h.hash();
-		}
-	};
-}
-
-#endif // NV_HANDLE_HH
Index: /trunk/nv/interface/animated_mesh.hh
===================================================================
--- /trunk/nv/interface/animated_mesh.hh	(revision 318)
+++ /trunk/nv/interface/animated_mesh.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,7 +14,7 @@
 #define NV_ANIMATED_MESH_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/transform.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+#include <nv/core/transform.hh>
 #include <nv/interface/context.hh>
 
Index: /trunk/nv/interface/animation_key.hh
===================================================================
--- /trunk/nv/interface/animation_key.hh	(revision 318)
+++ /trunk/nv/interface/animation_key.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -10,7 +10,7 @@
 #define NV_ANIMATION_KEY_HH
 
-#include <nv/common.hh>
-#include <nv/transform.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/transform.hh>
+#include <nv/core/math.hh>
 
 namespace nv
Index: /trunk/nv/interface/audio.hh
===================================================================
--- /trunk/nv/interface/audio.hh	(revision 318)
+++ /trunk/nv/interface/audio.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,6 +13,6 @@
 #define NV_AUDIO_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 
 namespace nv
Index: /trunk/nv/interface/camera.hh
===================================================================
--- /trunk/nv/interface/camera.hh	(revision 318)
+++ /trunk/nv/interface/camera.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,6 +13,6 @@
 #define NV_CAMERA_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 
 namespace nv
Index: /trunk/nv/interface/clear_state.hh
===================================================================
--- /trunk/nv/interface/clear_state.hh	(revision 318)
+++ /trunk/nv/interface/clear_state.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,6 +14,6 @@
 #define NV_CLEAR_STATE_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 
 namespace nv
Index: /trunk/nv/interface/context.hh
===================================================================
--- /trunk/nv/interface/context.hh	(revision 318)
+++ /trunk/nv/interface/context.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,8 +13,7 @@
 #define NV_CONTEXT_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/device.hh>
 #include <nv/interface/camera.hh>
-#include <nv/interface/vertex_buffer.hh>
 #include <nv/interface/clear_state.hh>
 #include <nv/interface/render_state.hh>
Index: /trunk/nv/interface/device.hh
===================================================================
--- /trunk/nv/interface/device.hh	(revision 318)
+++ /trunk/nv/interface/device.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,10 +13,9 @@
 #define NV_DEVICE_HH
 
-#include <nv/common.hh>
-#include <nv/string.hh>
-#include <nv/handle.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
+#include <nv/core/handle.hh>
 #include <nv/interface/uniform.hh>
 #include <nv/interface/mesh_data.hh>
-#include <nv/interface/vertex_buffer.hh>
 #include <nv/interface/image_data.hh>
 
Index: /trunk/nv/interface/file_system.hh
===================================================================
--- /trunk/nv/interface/file_system.hh	(revision 318)
+++ /trunk/nv/interface/file_system.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_FILE_SYSTEM_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/stream.hh>
 
Index: /trunk/nv/interface/font.hh
===================================================================
--- /trunk/nv/interface/font.hh	(revision 318)
+++ /trunk/nv/interface/font.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 #define NV_GL_FONT_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <unordered_map>
 
Index: /trunk/nv/interface/image_data.hh
===================================================================
--- /trunk/nv/interface/image_data.hh	(revision 318)
+++ /trunk/nv/interface/image_data.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,6 +14,6 @@
 #define NV_IMAGE_DATA_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <algorithm>
 
Index: /trunk/nv/interface/interpolation_raw.hh
===================================================================
--- /trunk/nv/interface/interpolation_raw.hh	(revision 318)
+++ /trunk/nv/interface/interpolation_raw.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -10,7 +10,7 @@
 #define NV_INTERPOLATION_RAW_HH
 
-#include <nv/common.hh>
-#include <nv/transform.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/transform.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/animation_key.hh>
 
Index: /trunk/nv/interface/interpolation_template.hh
===================================================================
--- /trunk/nv/interface/interpolation_template.hh	(revision 318)
+++ /trunk/nv/interface/interpolation_template.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -10,7 +10,7 @@
 #define NV_INTERPOLATION_TEMPLATE_HH
 
-#include <nv/common.hh>
-#include <nv/transform.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/transform.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/animation_key.hh>
 
Index: /trunk/nv/interface/map_area.hh
===================================================================
--- /trunk/nv/interface/map_area.hh	(revision 318)
+++ /trunk/nv/interface/map_area.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,8 +13,8 @@
 #define NV_MAP_AREA_HH
 
-#include <nv/common.hh>
-#include <nv/string.hh>
-#include <nv/array.hh>
-#include <nv/position.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
+#include <nv/core/array.hh>
+#include <nv/core/position.hh>
 
 namespace nv
Index: /trunk/nv/interface/mesh_data.hh
===================================================================
--- /trunk/nv/interface/mesh_data.hh	(revision 318)
+++ /trunk/nv/interface/mesh_data.hh	(revision 319)
@@ -8,8 +8,8 @@
 #define NV_MESH_DATA_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/string.hh>
-#include <nv/array.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
+#include <nv/core/string.hh>
+#include <nv/core/array.hh>
 #include <nv/gfx/animation.hh>
 #include <nv/interface/vertex.hh>
Index: /trunk/nv/interface/mesh_loader.hh
===================================================================
--- /trunk/nv/interface/mesh_loader.hh	(revision 318)
+++ /trunk/nv/interface/mesh_loader.hh	(revision 319)
@@ -14,9 +14,9 @@
 #define NV_MESH_LOADER_HH
 
-#include <nv/common.hh>
-#include <vector>
+#include <nv/core/common.hh>
+#include <nv/core/array.hh>
 #include <unordered_map>
-#include <nv/transform.hh>
-#include <nv/string.hh>
+#include <nv/core/transform.hh>
+#include <nv/core/string.hh>
 #include <nv/gfx/animation.hh>
 #include <nv/interface/mesh_data.hh>
Index: /trunk/nv/interface/render_state.hh
===================================================================
--- /trunk/nv/interface/render_state.hh	(revision 318)
+++ /trunk/nv/interface/render_state.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,8 +14,8 @@
 #define NV_RENDER_STATE_HH
 
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/clear_state.hh>
-#include <nv/string.hh>
+#include <nv/core/string.hh>
 
 namespace nv
Index: /trunk/nv/interface/scene_node.hh
===================================================================
--- /trunk/nv/interface/scene_node.hh	(revision 318)
+++ /trunk/nv/interface/scene_node.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,8 +13,8 @@
 #define NV_SCENE_NODE_HH
 
-#include <nv/common.hh>
-#include <vector>
-#include <nv/transform.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/array.hh>
+#include <nv/core/transform.hh>
+#include <nv/core/math.hh>
 #include <nv/interface/render_state.hh>
 
Index: /trunk/nv/interface/stream.hh
===================================================================
--- /trunk/nv/interface/stream.hh	(revision 318)
+++ /trunk/nv/interface/stream.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_STREAM_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 
 namespace nv
Index: /trunk/nv/interface/terminal.hh
===================================================================
--- /trunk/nv/interface/terminal.hh	(revision 318)
+++ /trunk/nv/interface/terminal.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2013-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,7 +13,7 @@
 #define NV_TERMINAL_HH
 
-#include <nv/common.hh>
-#include <nv/position.hh>
-#include <nv/io_event.hh>
+#include <nv/core/common.hh>
+#include <nv/core/position.hh>
+#include <nv/core/io_event.hh>
 
 namespace nv
Index: /trunk/nv/interface/uniform.hh
===================================================================
--- /trunk/nv/interface/uniform.hh	(revision 318)
+++ /trunk/nv/interface/uniform.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,8 +13,8 @@
 #define NV_UNIFORM_HH
 
+#include <nv/interface/camera.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
 #include <unordered_map>
-#include <nv/interface/camera.hh>
-#include <nv/common.hh>
-#include <nv/string.hh>
 
 namespace nv
Index: /trunk/nv/interface/vertex.hh
===================================================================
--- /trunk/nv/interface/vertex.hh	(revision 318)
+++ /trunk/nv/interface/vertex.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -10,7 +10,7 @@
 #define NV_VERTEX_HH
 
-#include <nv/common.hh>
-#include <nv/transform.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/transform.hh>
+#include <nv/core/math.hh>
 
 namespace nv
Index: unk/nv/interface/vertex_buffer.hh
===================================================================
--- /trunk/nv/interface/vertex_buffer.hh	(revision 318)
+++ 	(revision )
@@ -1,26 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-/**
- * @file vertex_buffer.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief Vertex buffer class
- */
-
-#ifndef NV_VERTEX_BUFFER_HH
-#define NV_VERTEX_BUFFER_HH
-
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/interface/vertex.hh>
-#include <nv/interface/mesh_data.hh>
-#include <unordered_map>
-
-namespace nv
-{
-
-} // namespace nv
-
-#endif // NV_VERTEX_BUFFER_HH
Index: /trunk/nv/interface/window.hh
===================================================================
--- /trunk/nv/interface/window.hh	(revision 318)
+++ /trunk/nv/interface/window.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -10,10 +10,10 @@
  */
 
-#ifndef NV_WINDOW_HH
-#define NV_WINDOW_HH
+#ifndef NV_GUI_WINDOW_HH
+#define NV_GUI_WINDOW_HH
 
-#include <nv/common.hh>
-#include <nv/string.hh>
-#include <nv/io_event.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
+#include <nv/core/io_event.hh>
 
 namespace nv
@@ -39,3 +39,3 @@
 
 
-#endif // NV_WINDOW_HH
+#endif // NV_GUI_WINDOW_HH
Index: /trunk/nv/io/c_file_system.hh
===================================================================
--- /trunk/nv/io/c_file_system.hh	(revision 318)
+++ /trunk/nv/io/c_file_system.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_C_FILE_SYSTEM_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/file_system.hh>
 
Index: /trunk/nv/io/c_stream.hh
===================================================================
--- /trunk/nv/io/c_stream.hh	(revision 318)
+++ /trunk/nv/io/c_stream.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_C_STREAM_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/stream.hh>
 
Index: /trunk/nv/io/std_stream.hh
===================================================================
--- /trunk/nv/io/std_stream.hh	(revision 318)
+++ /trunk/nv/io/std_stream.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_STD_STREAM_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/stream.hh>
 #include <streambuf>
Index: /trunk/nv/io/string_table.hh
===================================================================
--- /trunk/nv/io/string_table.hh	(revision 318)
+++ /trunk/nv/io/string_table.hh	(revision 319)
@@ -13,6 +13,6 @@
 #define NV_IO_STRING_TABLE_HH
 
-#include <nv/common.hh>
-#include <nv/array.hh>
+#include <nv/core/common.hh>
+#include <nv/core/array.hh>
 #include <unordered_map>
 #include <nv/interface/stream.hh>
Index: unk/nv/io_event.hh
===================================================================
--- /trunk/nv/io_event.hh	(revision 318)
+++ 	(revision )
@@ -1,219 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file io_event.hh
- * @author Kornel Kisielewicz
- * @brief 
- */
-
-#ifndef NV_IO_EVENT_HH
-#define NV_IO_EVENT_HH
-
-#include <nv/common.hh>
-#include <nv/types.hh>
-
-namespace nv
-{
-
-	// Generate the key_code enum
-	enum key_code
-	{
-#	define NV_KEY( id, val ) id = val,
-#		include <nv/detail/key_list.inc>
-#	undef NV_KEY
-	};
-	
-	// Generate the mouse_code enum
-	enum mouse_code
-	{
-#	define NV_MOUSE( id, val ) id = val,
-#		include <nv/detail/mouse_list.inc>
-#	undef NV_MOUSE
-	};
-
-	// Generate the io_event_code enum
-	enum io_event_code
-	{
-#	define NV_IO_EVENT( id ) id,
-#		include <nv/detail/io_event_list.inc>
-#	undef NV_IO_EVENT
-	};
-
-	struct key_event
-	{
-		/// Input event ASCII code
-		char8 ascii;
-
-		/// Input event local code
-		key_code code;
-
-		/// True if shift key is present
-		bool shift;
-
-		/// True if control key is present
-		bool control;
-
-		/// True if alt key is present
-		bool alt;
-
-		/// True if pressed
-		bool pressed;
-	};
-
-	struct mouse_button_event
-	{
-		/// X position where mouse was clicked.
-		uint16 x;
-		/// Y position where mouse was clicked.
-		uint16 y;
-		/// Button that was clicked.
-		uint32 button;
-		/// True if pressed
-		bool pressed;
-		/// Mouse button code
-		mouse_code code;
-	};
-
-	struct mouse_wheel_event
-	{
-		/// amount scrolled horizontally positive to the right
-		sint32 x;
-		/// amount scrolled vertically 
-		sint32 y;
-	};
-
-	struct mouse_move_event
-	{
-		/// X Position the mouse moved to.
-		uint16 x;
-		/// Y Position the mouse moved to.
-		uint16 y;
-		/// Distance in x direction mouse was moved.
-		sint16 rx;
-		/// Distance in y direction mouse was moved.
-		sint16 ry;
-		/// True if pressed
-		bool pressed;
-		/// Mouse button code
-		mouse_code code;
-	};
-
-	struct joy_button_event
-	{
-		/// Joystick ID
-		sint32 id;
-		/// Button that is affected
-		uint8 button;
-		/// True if pressed
-		bool pressed;
-	};
-
-	struct joy_axis_event
-	{
-		/// Joystick ID
-		sint32 id;
-		/// Axis ID
-		uint8 axis;
-		/// Value
-		sint16 value;
-	};
-
-	struct joy_hat_event
-	{
-		/// Joystick ID
-		sint32 id;
-		/// Hat ID
-		uint8 hat;
-		/// Value
-		sint16 value;
-	};
-
-	struct joy_ball_event
-	{
-		/// Joystick ID
-		sint32 id;
-		/// Ball ID
-		uint8 ball;
-		/// Relative X
-		sint16 rx;
-		/// Relative Y
-		sint16 ry;
-	};
-
-	struct resize_event
-	{
-		/// New x size of the object.
-		sint32 x;
-		/// New y size of the object.
-		sint32 y;
-	};
-
-	struct active_event
-	{
-		/// Whether focus was gained or lost.
-		bool gain;
-	};
-
-	struct system_event
-	{
-		uint8  sys_type;
-		uint32 param1;
-		uint32 param2;
-	};
-
-	struct io_event
-	{
-		io_event_code type;
-		union
-		{
-			key_event          key;
-			mouse_button_event mbutton;
-			mouse_move_event   mmove;
-			mouse_wheel_event  mwheel;
-			joy_button_event   jbutton;
-			joy_axis_event     jaxis;
-			joy_hat_event      jhat;
-			joy_ball_event     jball;
-			resize_event       resize;
-			active_event       active;
-			system_event       system;
-		};
-	};
-
-	/**
-	 * Gets the name of the key given the code.
-	 *
-	 * @param key The code value of the key.
-	 * @returns The name of the key.
-	 */
-	const char* get_key_name( key_code key );
-
-	/**
-	 * Gets the name of the mouse button given the code.
-	 *
-	 * @param button The code value of the mouse button.
-	 * @returns The name of the button.
-	 */
-	const char* get_mouse_name( mouse_code button );
-
-	/**
-	 * Gets the name of the IO event given the code.
-	 *
-	 * @param event The code value of the IO event.
-	 * @returns The name of the event.
-	 */
-	const char* get_io_event_name( io_event_code event );
-
-	/**
-	 * Registers all events to the specified database.
-	 *
-	 * @param db The database to store all event data in.
-	 */
-	void register_io_types( type_database* db );
-}
-
-#endif // NV_IO_EVENT_HH
Index: /trunk/nv/lib/assimp.hh
===================================================================
--- /trunk/nv/lib/assimp.hh	(revision 318)
+++ /trunk/nv/lib/assimp.hh	(revision 319)
@@ -8,8 +8,8 @@
 #define NV_LIB_ASSIMP_HH
 
-#include <nv/common.hh>
-#include <nv/logging.hh>
-#include <nv/string.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/logging.hh>
+#include <nv/core/string.hh>
+#include <nv/core/math.hh>
 
 #define NV_ASSIMP_DYNAMIC
Index: /trunk/nv/lib/curses.hh
===================================================================
--- /trunk/nv/lib/curses.hh	(revision 318)
+++ /trunk/nv/lib/curses.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_LIB_CURSES_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 
 #define NV_CURSES_DYNAMIC
Index: /trunk/nv/lib/fmod.hh
===================================================================
--- /trunk/nv/lib/fmod.hh	(revision 318)
+++ /trunk/nv/lib/fmod.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_LIB_FMOD_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 
 #define NV_FMOD_DYNAMIC
Index: /trunk/nv/lib/freetype2.hh
===================================================================
--- /trunk/nv/lib/freetype2.hh	(revision 318)
+++ /trunk/nv/lib/freetype2.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -12,5 +12,5 @@
 #include <stddef.h>
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 
 #define NV_FREETYPE_DYNAMIC
Index: /trunk/nv/lib/gl.hh
===================================================================
--- /trunk/nv/lib/gl.hh	(revision 318)
+++ /trunk/nv/lib/gl.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_LIB_GL_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 
 #if NV_PLATFORM == NV_WINDOWS
Index: /trunk/nv/lib/lua.hh
===================================================================
--- /trunk/nv/lib/lua.hh	(revision 318)
+++ /trunk/nv/lib/lua.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -33,5 +33,5 @@
 ******************************************************************************/
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 
 #define NV_LUA_DYNAMIC
Index: /trunk/nv/lib/sdl.hh
===================================================================
--- /trunk/nv/lib/sdl.hh	(revision 318)
+++ /trunk/nv/lib/sdl.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_LIB_SDL_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 
 #define NV_SDL_DYNAMIC
Index: /trunk/nv/lib/sdl_image.hh
===================================================================
--- /trunk/nv/lib/sdl_image.hh	(revision 318)
+++ /trunk/nv/lib/sdl_image.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_LIB_SDL_IMAGE_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/lib/sdl.hh>
 
Index: /trunk/nv/lib/sdl_mixer.hh
===================================================================
--- /trunk/nv/lib/sdl_mixer.hh	(revision 318)
+++ /trunk/nv/lib/sdl_mixer.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 #define NV_LIB_SDL_MIXER_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/lib/sdl.hh>
 
Index: /trunk/nv/lib/wx.hh
===================================================================
--- /trunk/nv/lib/wx.hh	(revision 318)
+++ /trunk/nv/lib/wx.hh	(revision 319)
@@ -19,5 +19,5 @@
 #undef near
 #undef far
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/lib/gl.hh>
 #include <nv/gl/gl_device.hh>
Index: unk/nv/library.hh
===================================================================
--- /trunk/nv/library.hh	(revision 318)
+++ 	(revision )
@@ -1,144 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file library.hh
- * @author Kornel Kisielewicz
- * @brief Implements a dynamic library class
- */
-
-#ifndef NV_LIBRARY_HH
-#define NV_LIBRARY_HH
-
-#include <nv/exception.hh>
-#include <nv/string.hh>
-
-namespace nv
-{
-	/**
-	 * library
-	 * @brief Class representing a dynamically loaded library
-	 */
-	class library 
-	{
-	public:
-
-		/**
-		 * Library constructor
-		 */
-		library();
-
-		/**
-		 * Opens the library
-		 *
-		 * Throws library_error on failure
-		 */
-		void open( const string& name );
-
-		/**
-		 * Tries to open the library
-		 *
-		 * returns true if succeeded, false otherwise
-		 */
-		bool try_open( const string& name );
-
-		/**
-		 * Returns true if the library is open, false otherwise
-		 */
-		bool is_open() const;
-
-		/**
-		 * Returns library name
-		 */
-		const string& get_name() const;
-
-		/**
-		 * Get symbol from library
-		 *
-		 * Throws on symbol not found
-		 */
-		void* get( const string& symbol );
-
-		/**
-		 * Get symbol from library
-		 *
-		 * Returns null if symbol not found
-		 */
-		void* try_get( const string& symbol );
-
-		/**
-		 * Destructor
-		 *
-		 * Closes the library if open.
-		 */
-		~library();
-
-		/**
-		 * Returns library loading error if present
-		 *
-		 * Exact implementation depends on platform/compiler.
-		 */
-		static string get_error();
-
-	protected:
-		/**
-		 * Opens the library
-		 *
-		 * Opens the library and prepares it for getting symbols.
-		 * Needs to be done before any get call.
-		 *
-		 * returns true on success, false otherwise
-		 */
-		bool open();
-
-		/**
-		 * @brief Closes the library
-		 *
-		 * Closes the library. Any further get calls or operations on
-		 * received symbols are invalid!
-		 */
-		void close();
-
-		/// Library handle
-		void* m_handle;
-
-		/// Library name
-		string m_name;
-
-	};  // class Library
-
-	class library_error : public runtime_error
-	{
-		/// Library name
-		string m_name;
-	public:
-		/**
-		 * Constructor
-		 */
-		library_error( const string& message, const string& name )
-			: runtime_error( "Library (" + name + ") : " + message + " [ " + library::get_error() + " ]"), m_name( name )
-		{
-		}
-
-		/**
-		 * Destructor.
-		 *
-		 * It must not throw any exceptions because of the inheritance
-		 */
-		~library_error() throw() {}
-
-		/**
-		 * Returns library name
-		 */
-		const string& get_name()
-		{
-			return m_name;
-		}
-	};
-
-} // namespace nv
-
-#endif // NV_LIBRARY_HH
Index: unk/nv/logger.hh
===================================================================
--- /trunk/nv/logger.hh	(revision 318)
+++ 	(revision )
@@ -1,212 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file logger.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief logger implementation
- */
-
-#ifndef NV_LOGGER_HH
-#define NV_LOGGER_HH
-
-#include <nv/string.hh>
-#include <nv/logging.hh>
-#include <iosfwd>
-#include <list>
-
-namespace nv
-{
-	/**
-	 * Class representing log output.
-	 *
-	 * Base class for all logging output targets.
-	 */
-	class log_sink
-	{
-	public:
-		/**
-		 * Logging function.
-		 *
-		 * @param level level on which to log.
-		 * @param message message to be logged.
-		 */
-		virtual void log( log_level level, const std::string& message ) = 0;
-		/**
-         * Optional timestamp string
-		 */
-		const char* timestamp() const;
-		/**
-         * Log level name (unpadded)
-		 */
-		const char* level_name( log_level level ) const;
-		/**
-         * Log level name (padded)
-		 */
-		const char* padded_level_name( log_level level ) const;
-		/**
-		 * Enforcement of virtual destructor.
-		 */
-		virtual ~log_sink() {}
-	};
-
-	/**
-	 * Logger class.
-	 *
-	 * Allows to catch all logging in ORE and in the application using ORE
-	 * logging macros. Initially does nothing, needs to have some log sinks
-	 * added.
-	 */
-	class logger : public logger_base
-	{
-	public:
-		/**
-		 * Constructor, taking the minimum level for logging.
-		 *
-		 * No matter what level sinks you add, the passed level is the
-		 * overriding cutoff.
-		 */
-		explicit logger( unsigned int llevel )
-		{
-			m_level = llevel;
-		}
-
-		/**
-		 * Logging function.
-		 *
-		 * Goes over all registered log sinks and prints to them depending
-		 * on the log level of the sink. Messages that are lower level than
-		 * the initial level passed to the constructor never even reach this
-		 * function.
-		 *
-		 * @param level level on which to log.
-		 * @param message message to be logged.
-		 */
-		virtual void log( log_level level, const std::string& message );
-
-		/** 
-		 * Log sink registering.
-		 * 
-		 * Registers a new log sink. Ownership is passed to logger - log sink
-		 * will be disposed at program shutdown.
-		 *
-		 * @param sink log sink to be registered.
-		 * @param level level on which the sink should log.
-		 */
-		virtual void add_sink( log_sink* sink, int level );
-
-		/** 
-		 * Log sink removal.
-		 * 
-		 * Removes a log sink. If log sink doesn't exist, nothing will 
-		 * happen.
-		 *
-		 * @param sink log sink to be removed.
-		 * @returns true if sink was found, false otherwise
-		 */
-		virtual bool remove_sink( log_sink* sink );
-
-		/**
-		 * Destructor.
-		 * 
-		 * Also destroys all file sinks.
-		 */
-		virtual ~logger();
-
-	protected:
-		/** Type for the log sink list. */
-		typedef std::list< std::pair< log_level, log_sink* > > log_sink_list;
-
-		/** Log sink list. */
-		log_sink_list m_log_sinks;
-	};
-
-	/**
-	 * Console logger sink.
-	 *
-	 * Logs to std::out -- be sure a console window is open, or std::out redirected!
-	 */
-	class log_console_sink : public log_sink
-	{
-	public:
-		/**
-		 * Log sink constructor
-		 */
-		log_console_sink( bool coloring = true );
-		/**
-		 * Logging function.
-		 */
-		virtual void log( log_level level, const std::string& message );
-
-	private:
-		void* m_handle;
-		bool  m_color;
-	};
-
-	/**
-	 * General stream sink.
-	 *
-	 * Logs to passed stream.
-	 */
-	class log_stream_sink : public log_sink
-	{
-	public:
-		/**
-		 * Constructor.
-		 *
-		 * Logs to the passed stream. The stream is NOT disposed at destruction.
-		 * Flushing can be controlled by optional flush parameter.
-		 *
-		 * @param stream stream to be logged to.
-		 * @param flush_always if set to false, wont flush after each line.
-		 */
-		log_stream_sink( std::ostream* stream, bool flush_always ) 
-			: m_stream(stream), m_flush(flush_always) {}
-
-		/**
-		 * Logging function.
-		 */
-		virtual void log( log_level level, const std::string& message );
-
-	protected:
-		/** Stored stream. */
-		std::ostream* m_stream;
-		/** Controls flushing. */
-		bool m_flush;
-	};
-
-	/**
-	 * File logger sink.
-	 *
-	 * Logs to std::out -- be sure a console window is open, or std::out redirected!
-	 */
-	class log_file_sink : public log_stream_sink
-	{
-	public:
-		/**
-		 * Constructor.
-		 *
-		 * Logs to the file passed. File is closed and disposed of after ending.
-		 * File is not appended, it's overwritten. If file is not creatable,
-		 * the constructor will throw!
-		 *
-		 * @param file_name file to be logged to.
-		 * @param flush_always if set to false, wont flush after each line.
-		 * @throws runtime_error if file_name cannot be opened.
-		 */
-		log_file_sink( const std::string file_name, bool flush_always = true );
-
-		/**
-		 * Destructor.
-		 *
-		 * Flushes, closes file and disposes of the stream.
-		 */
-		virtual ~log_file_sink();
-	};
-
-}
-
-#endif // NV_LOGGER_HH
Index: unk/nv/logging.hh
===================================================================
--- /trunk/nv/logging.hh	(revision 318)
+++ 	(revision )
@@ -1,78 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file logging.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief logging interfaces
- */
-
-#ifndef NV_LOGGING_HH
-#define NV_LOGGING_HH
-
-#include <nv/common.hh>
-#include <nv/singleton.hh>
-#include <string>
-#include <sstream>
-
-namespace nv
-{
-
-	enum log_level
-	{
-		LOG_NONE     = 0,
-		LOG_FATAL    = 10,
-		LOG_CRITICAL = 20,
-		LOG_ERROR    = 30,
-		LOG_WARNING  = 40,
-		LOG_NOTICE   = 50,
-		LOG_INFO     = 60,
-		LOG_DEBUG    = 80,
-		LOG_TRACE    = 100
-	};
-
-	class logger_base : public singleton< logger_base >
-	{
-	public:
-		unsigned int get_level()
-		{
-			return m_level;
-		}
-		void set_level( unsigned int level )
-		{
-			m_level = level;
-		}
-		virtual void log( log_level level, const std::string& message ) = 0;
-		virtual ~logger_base() {}
-	protected:
-		unsigned int m_level;
-	};
-
-} // namespace nv
-
-#define NV_LOG(level, message_stream) \
-	if ( nv::logger_base::is_valid() && \
-		(unsigned int)nv::logger_base::reference().get_level() >= (unsigned int)level ) \
-	{       \
-		std::stringstream ss; \
-		ss << message_stream; \
-		nv::logger_base::reference().log( level, ss.str() ); \
-	}
-
-#if NV_DEBUG == 1
-#define NV_DEBUG_LOG(level, message_stream) \
-	if ( nv::logger_base::is_valid() && \
-		(unsigned int)nv::logger_base::reference().get_level() >= (unsigned int)level ) \
-	{       \
-		std::stringstream ss; \
-		ss << message_stream; \
-		nv::logger_base::reference().log( level, ss.str() ); \
-	}
-#else
-#define NV_DEBUG_LOG(level, message_stream)
-#endif
-
-#endif // NV_LOGGING_HH
Index: /trunk/nv/lua/lua_area.hh
===================================================================
--- /trunk/nv/lua/lua_area.hh	(revision 318)
+++ /trunk/nv/lua/lua_area.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,6 +7,6 @@
 #define NV_LUA_AREA_HH
 
-#include <nv/common.hh>
-#include <nv/position.hh>
+#include <nv/core/common.hh>
+#include <nv/core/position.hh>
 #include <nv/lua/lua_glm.hh>
 #include <nv/lua/lua_state.hh>
Index: /trunk/nv/lua/lua_aux.hh
===================================================================
--- /trunk/nv/lua/lua_aux.hh	(revision 318)
+++ /trunk/nv/lua/lua_aux.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/nv/lua/lua_dispatch.hh
===================================================================
--- /trunk/nv/lua/lua_dispatch.hh	(revision 318)
+++ /trunk/nv/lua/lua_dispatch.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -14,6 +14,6 @@
 #define NV_LUA_DISPATCH_HH
 
-#include <nv/common.hh>
-#include <nv/string.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
 #include <nv/lua/lua_values.hh>
 #include <nv/lua/lua_path.hh>
Index: /trunk/nv/lua/lua_flags.hh
===================================================================
--- /trunk/nv/lua/lua_flags.hh	(revision 318)
+++ /trunk/nv/lua/lua_flags.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,6 +7,6 @@
 #define NV_LUA_FLAGS_HH
 
-#include <nv/common.hh>
-#include <nv/flags.hh>
+#include <nv/core/common.hh>
+#include <nv/core/flags.hh>
 #include <nv/lua/lua_state.hh>
 #include <nv/lua/lua_values.hh>
Index: /trunk/nv/lua/lua_function.hh
===================================================================
--- /trunk/nv/lua/lua_function.hh	(revision 318)
+++ /trunk/nv/lua/lua_function.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 #define NV_LUA_FUNCTION_HH
 
-#include <nv/common.hh>
-#include <nv/string.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
 #include <nv/lua/lua_values.hh>
 #include <nv/lua/lua_path.hh>
Index: /trunk/nv/lua/lua_glm.hh
===================================================================
--- /trunk/nv/lua/lua_glm.hh	(revision 318)
+++ /trunk/nv/lua/lua_glm.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 
 #include <new>
-#include <nv/common.hh>
-#include <nv/math.hh>
+#include <nv/core/common.hh>
+#include <nv/core/math.hh>
 #include <nv/lua/lua_values.hh>
 
Index: /trunk/nv/lua/lua_map_area.hh
===================================================================
--- /trunk/nv/lua/lua_map_area.hh	(revision 318)
+++ /trunk/nv/lua/lua_map_area.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/nv/lua/lua_map_tile.hh
===================================================================
--- /trunk/nv/lua/lua_map_tile.hh	(revision 318)
+++ /trunk/nv/lua/lua_map_tile.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_LUA_MAP_TILE_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/lua/lua_state.hh>
 
Index: /trunk/nv/lua/lua_nova.hh
===================================================================
--- /trunk/nv/lua/lua_nova.hh	(revision 318)
+++ /trunk/nv/lua/lua_nova.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/nv/lua/lua_path.hh
===================================================================
--- /trunk/nv/lua/lua_path.hh	(revision 318)
+++ /trunk/nv/lua/lua_path.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 #define NV_LUA_PATH_HH
 
-#include <nv/common.hh>
-#include <nv/string.hh>
+#include <nv/core/common.hh>
+#include <nv/core/string.hh>
 #include <cstring>
 
Index: /trunk/nv/lua/lua_raw.hh
===================================================================
--- /trunk/nv/lua/lua_raw.hh	(revision 318)
+++ /trunk/nv/lua/lua_raw.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,5 +7,5 @@
 #define NV_LUA_RAW_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/lib/lua.hh>
 #include <istream>
Index: /trunk/nv/lua/lua_state.hh
===================================================================
--- /trunk/nv/lua/lua_state.hh	(revision 318)
+++ /trunk/nv/lua/lua_state.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,11 +9,11 @@
 
 
-#ifndef NV_LUA_HH
-#define NV_LUA_HH
-
-#include <nv/common.hh>
+#ifndef NV_LUA_STATE_HH
+#define NV_LUA_STATE_HH
+
+#include <nv/core/common.hh>
+#include <nv/core/flags.hh>
 #include <istream>
 #include <map>
-#include <nv/flags.hh>
 
 #include <nv/lua/lua_path.hh>
@@ -273,3 +273,3 @@
 } // namespace nv
 
-#endif // NV_LUA_HH
+#endif // NV_LUA_STATE_HH
Index: /trunk/nv/lua/lua_values.hh
===================================================================
--- /trunk/nv/lua/lua_values.hh	(revision 318)
+++ /trunk/nv/lua/lua_values.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,7 +8,7 @@
 #define NV_LUA_VALUES_HH
 
-#include <nv/common.hh>
-#include <nv/type_traits.hh>
-#include <nv/string.hh>
+#include <nv/core/common.hh>
+#include <nv/core/type_traits.hh>
+#include <nv/core/string.hh>
 
 struct lua_State;
Index: unk/nv/math.hh
===================================================================
--- /trunk/nv/math.hh	(revision 318)
+++ 	(revision )
@@ -1,251 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_MATH_HH
-#define NV_MATH_HH
-
-#include <nv/common.hh>
-
-#if NV_COMPILER == NV_GNUC
-#pragma GCC system_header
-#elif NV_COMPILER == NV_CLANG
-#pragma clang system_header
-#endif
-
-#include <glm/glm.hpp>
-#include <glm/gtc/matrix_transform.hpp>
-#include <glm/gtc/type_ptr.hpp>
-#include <glm/gtc/quaternion.hpp>
-
-namespace nv
-{
-
-	typedef glm::detail::tvec2<sint8> i8vec2;
-	typedef glm::detail::tvec3<sint8> i8vec3;
-	typedef glm::detail::tvec4<sint8> i8vec4;
-
-	typedef glm::detail::tvec2<sint16> i16vec2;
-	typedef glm::detail::tvec3<sint16> i16vec3;
-	typedef glm::detail::tvec4<sint16> i16vec4;
-
-	typedef glm::vec2 vec2;
-	typedef glm::vec3 vec3;
-	typedef glm::vec4 vec4;
-
-	typedef glm::ivec2 ivec2;
-	typedef glm::ivec3 ivec3;
-	typedef glm::ivec4 ivec4;
-
-	typedef glm::mat2 mat2;
-	typedef glm::mat3 mat3;
-	typedef glm::mat4 mat4;
-
-	typedef glm::quat quat;
-
-	template <typename T> 
-	struct datatype_traits 
-	{
-		typedef T type;
-		typedef T base_type;
-		static const size_t size = 1;
-	};
-
-	template <typename T> 
-	struct datatype_traits< glm::detail::tvec2<T> > 
-	{
-		typedef glm::detail::tvec2<T> type;
-		typedef typename type::value_type base_type;
-		static const size_t size = 2;
-	};
-
-	template <typename T> 
-	struct datatype_traits< glm::detail::tvec3<T> > 
-	{
-		typedef glm::detail::tvec3<T> type;
-		typedef typename type::value_type base_type;
-		static const size_t size = 3;
-	};
-
-	template <typename T> 
-	struct datatype_traits< glm::detail::tvec4<T> > 
-	{
-		typedef glm::detail::tvec4<T> type;
-		typedef typename type::value_type base_type;
-		static const size_t size = 4;
-	};
-
-	using glm::max;
-	using glm::min;
-
-	enum datatype
-	{
-		NONE,
-		INT,
-		BYTE,
-		SHORT,
-		UINT,
-		UBYTE,
-		USHORT,
-		FLOAT,
-		FLOAT_VECTOR_2,
-		FLOAT_VECTOR_3,
-		FLOAT_VECTOR_4,
-		FLOAT_MATRIX_2,
-		FLOAT_MATRIX_3,
-		FLOAT_MATRIX_4,
-		INT_VECTOR_2,
-		INT_VECTOR_3,
-		INT_VECTOR_4,
-		// unsupported gl conversion, remove?
-		BYTE_VECTOR_2, 
-		BYTE_VECTOR_3,
-		BYTE_VECTOR_4,
-		QUAT,
-		TRANSFORM,
-		DATATYPE_COUNT,
-	};
-
-	struct datatype_info
-	{
-		size_t   size;
-		datatype base;
-		size_t   elements;
-	};
-
-	inline const datatype_info& get_datatype_info( datatype dt )
-	{
-		static datatype_info info[ DATATYPE_COUNT ] = {
-			{ 0, NONE, 0 },   // NONE  
-			{ 4, INT, 1 },    // INT,
-			{ 1, BYTE, 1 },   // BYTE,
-			{ 2, SHORT, 1 },  // SHORT,
-			{ 4, UINT, 1 },   // UINT,
-			{ 1, UBYTE, 1 },  // UBYTE,
-			{ 2, USHORT, 1 }, // USHORT,
-			{ 4, FLOAT, 1 },  // FLOAT
-			{ 4 * 2,  FLOAT, 2 },  // FLOAT_VECTOR_2,
-			{ 4 * 3,  FLOAT, 3 },  // FLOAT_VECTOR_3,
-			{ 4 * 4,  FLOAT, 4 },  // FLOAT_VECTOR_4,
-			{ 4 * 4,  FLOAT, 4 },  // FLOAT_MATRIX_2,
-			{ 4 * 9,  FLOAT, 9 },  // FLOAT_MATRIX_3,
-			{ 4 * 16, FLOAT, 16 }, // FLOAT_MATRIX_4,
-			{ 4 * 2,  INT, 2 },  // INT_VECTOR_2,
-			{ 4 * 3,  INT, 3 },  // INT_VECTOR_3,
-			{ 4 * 4,  INT, 4 },  // INT_VECTOR_4,
-			// unsupported gl conversion, remove?
-			{ 1 * 2,  BYTE, 2 },  // BYTE_VECTOR_2,
-			{ 1 * 3,  BYTE, 3 },  // BYTE_VECTOR_3,
-			{ 1 * 4,  BYTE, 4 },  // BYTE_VECTOR_4,
-			{ 4 * 4,  FLOAT, 4 },      // QUAT,
-			{ 7 * 4,  FLOAT, 7 },      // TRANSFORM,
-		};
-		return info[dt];
-	}
-
-	template < datatype EnumType > struct enum_to_type {};
-
-	template <> struct enum_to_type< NONE >  { typedef void type; };
-	template <> struct enum_to_type< INT >   { typedef int type; };
-	template <> struct enum_to_type< UINT >  { typedef unsigned int type; };
-	template <> struct enum_to_type< SHORT > { typedef short type; };
-	template <> struct enum_to_type< USHORT >{ typedef unsigned short type; };
-	template <> struct enum_to_type< BYTE >  { typedef char type; };
-	template <> struct enum_to_type< UBYTE > { typedef unsigned char type; };
-	template <> struct enum_to_type< FLOAT > { typedef f32 type; };
-
-	template <> struct enum_to_type< FLOAT_VECTOR_2 > { typedef vec2 type; };
-	template <> struct enum_to_type< FLOAT_VECTOR_3 > { typedef vec3 type; };
-	template <> struct enum_to_type< FLOAT_VECTOR_4 > { typedef vec4 type; };
-
-	template <> struct enum_to_type< INT_VECTOR_2 > { typedef ivec2 type; };
-	template <> struct enum_to_type< INT_VECTOR_3 > { typedef ivec3 type; };
-	template <> struct enum_to_type< INT_VECTOR_4 > { typedef ivec4 type; };
-
-	template <> struct enum_to_type< BYTE_VECTOR_2 > { typedef i8vec2 type; };
-	template <> struct enum_to_type< BYTE_VECTOR_3 > { typedef i8vec3 type; };
-	template <> struct enum_to_type< BYTE_VECTOR_4 > { typedef i8vec4 type; };
-
-	template <> struct enum_to_type< FLOAT_MATRIX_2 > { typedef mat2 type; };
-	template <> struct enum_to_type< FLOAT_MATRIX_3 > { typedef mat3 type; };
-	template <> struct enum_to_type< FLOAT_MATRIX_4 > { typedef mat4 type; };
-
-	template <> struct enum_to_type< QUAT > { typedef quat type; };
-
-	template < typename TYPE > struct type_to_enum {};
-
-	template <> struct type_to_enum< long >          { static const datatype type = INT; };
-	template <> struct type_to_enum< unsigned long > { static const datatype type = UINT; };
-	template <> struct type_to_enum< int >           { static const datatype type = INT; };
-	template <> struct type_to_enum< unsigned int >  { static const datatype type = UINT; };
-	template <> struct type_to_enum< short >         { static const datatype type = SHORT; };
-	template <> struct type_to_enum< unsigned short >{ static const datatype type = USHORT; };
-	template <> struct type_to_enum< char >          { static const datatype type = BYTE; };
-	template <> struct type_to_enum< signed char >   { static const datatype type = BYTE; };
-	template <> struct type_to_enum< unsigned char > { static const datatype type = UBYTE; };
-	template <> struct type_to_enum< f32 > { static const datatype type = FLOAT; };
-
-	template <> struct type_to_enum< vec2 > { static const datatype type = FLOAT_VECTOR_2; };
-	template <> struct type_to_enum< vec3 > { static const datatype type = FLOAT_VECTOR_3; };
-	template <> struct type_to_enum< vec4 > { static const datatype type = FLOAT_VECTOR_4; };
-
-	template <> struct type_to_enum< ivec2 > { static const datatype type = INT_VECTOR_2; };
-	template <> struct type_to_enum< ivec3 > { static const datatype type = INT_VECTOR_3; };
-	template <> struct type_to_enum< ivec4 > { static const datatype type = INT_VECTOR_4; };
-
-	template <> struct type_to_enum< i8vec2 > { static const datatype type = BYTE_VECTOR_2; };
-	template <> struct type_to_enum< i8vec3 > { static const datatype type = BYTE_VECTOR_3; };
-	template <> struct type_to_enum< i8vec4 > { static const datatype type = BYTE_VECTOR_4; };
-
-	template <> struct type_to_enum< mat2 > { static const datatype type = FLOAT_MATRIX_2; };
-	template <> struct type_to_enum< mat3 > { static const datatype type = FLOAT_MATRIX_3; };
-	template <> struct type_to_enum< mat4 > { static const datatype type = FLOAT_MATRIX_4; };
-	template <> struct type_to_enum< quat > { static const datatype type = QUAT; };
-
-	template < typename T >
-	struct sizeof_type 
-	{
-		static const int result = sizeof( T );
-	};
-
-	template <>
-	struct sizeof_type< void >
-	{
-		static const int result = 0;
-	};
-
-	template < datatype T >
-	struct sizeof_enum_type 
-	{
-		static const int result = sizeof_type< typename enum_to_type<T>::type >::result;
-	};
-
-	template < typename T >
-	T interpolate( const T& lhs, const T& rhs, float f )
-	{
-		return glm::mix( lhs, rhs, f );
-	}
-
-	template <>
-	inline quat interpolate( const quat& lhs, const quat& rhs, float f )
-	{
-		return glm::slerp( lhs, rhs, f );
-	}
-
-	template <typename T>
-	glm::detail::tvec3<T> normalize_safe( 
-		const glm::detail::tvec3<T>& x, 
-		const glm::detail::tvec3<T>& def = vec3()
-	)
-	{
-		typename glm::detail::tvec3<T>::value_type sqr = x.x * x.x + x.y * x.y + x.z * x.z;
-		return ( sqr > 0 ? x * glm::inversesqrt(sqr) : def );
-	}
-
-
-
-} // namespace nv
-
-#endif // NV_MATH_HH
Index: unk/nv/object.hh
===================================================================
--- /trunk/nv/object.hh	(revision 318)
+++ 	(revision )
@@ -1,153 +1,0 @@
-// Copyright (C) 2012 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_OBJECT_HH
-#define NV_OBJECT_HH
-
-#include <nv/common.hh>
-#include <nv/string.hh>
-#include <list>
-
-namespace nv
-{
-
-	/**
-	 * Implements a object tree-like structure.
-	 */
-	class object
-	{
-	public:
-		friend class root;
-
-		/// List type
-		typedef std::list<object*> list;
-
-		/**
-		 * Object constructor
-		 */
-		explicit object( const string& aid );
-
-		/**
-		 * Adds a child to this object. 
-		 *
-		 * The child is added to the end of the list. The child is
-		 * first detached from it's parent if present.
-		 *
-		 * @param child child to be added.
-		 */
-		virtual void add_child( object* child );
-
-
-		/**
-		 * Removes a child from this object.
-		 *
-		 * Does nothing if child not present, or is not child of
-		 * this object.
-		 *
-		 * @param child child to be removed.
-		 */
-		virtual void remove_child( object* child );
-
-		/**
-		 * Detaches object from parent.
-		 */
-		void detach(); 
-
-		/**
-		 * Moves the node to a new parent.
-		 *
-		 * Simply calls detach, and then add_child( new_parent ).
-		 *
-		 * @param new_parent the parent where we move
-		 */
-		virtual void change_parent( object* new_parent );
-
-		/**
-		 * Templated function to return parent.
-		 *
-		 * If parent doesn't exist, or is of other type nullptr will be returned.
-		 *
-		 * @tparam T requested parent type.
-		 * @returns parent as passed type, or nullptr if not present/invalid
-		 */
-		template< typename T >
-		//typename T* get_parent_as() const
-		T* get_parent_as() const
-		{
-			if ( !m_parent )
-			{
-				return nullptr;
-			}
-			return dynamic_cast<T>( m_parent );
-		}
-
-		/**
-		 * Searches for child by pointer.
-		 *
-		 * @param child child being searched
-		 * @param recursive whether to search recursively
-		 * @returns nullptr if not found, child otherwise
-		 */
-		object* find( object* child, bool recursive = false );
-
-		/**
-		 * Searches for child by uid.
-		 *
-		 * @param child uid being searched
-		 * @param recursive whether to search recursively
-		 * @returns nullptr if not found, child otherwise
-		 */
-		object* find( uid child, bool recursive = false );
-
-		/**
-		 * Searches for child by id.
-		 *
-		 * @param child id being searched
-		 * @param recursive whether to search recursively
-		 * @returns nullptr if not found, or *first* child otherwise (breadth first)
-		 */
-		object* find( string child, bool recursive = false );
-
-		/**
-		 * Returns the parent of this object.
-		 *
-		 * If no parent is present, nullptr will be returned.
-		 *
-		 * @returns parent object of current object
-		 */
-		virtual object* get_parent() const { return m_parent; }
-
-		/**
-		 * Returns object UID
-		 */
-		uid get_uid() const { return m_uid; }
-
-		/**
-		 * Returns object ID
-		 */
-		const std::string& get_id() const { return m_id; }
-
-		list::iterator begin() { return m_children.begin(); }
-		list::iterator end()   { return m_children.end(); }
-
-		/**
-		 * Destructor.
-		 *
-		 * Destroys all children, unregisters the object from the uid_store.
-		 */
-	protected:
-		virtual ~object();
-
-	protected:
-		string   m_id;              ///< id type of the object
-		string   m_name;            ///< name of the object
-		uid      m_uid;             ///< uid of the object
-		object*  m_parent;          ///< pointer to parent
-		list     m_children;        ///< children objects
-		size_t   m_child_count;     ///< number of children
-	};
-
-} // namespace nv
-
-#endif // NV_OBJECT_HH
Index: unk/nv/position.hh
===================================================================
--- /trunk/nv/position.hh	(revision 318)
+++ 	(revision )
@@ -1,323 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file gui_element.hh
- * @author Kornel Kisielewicz
- * @brief UI 2D positioning classes
- */
-
-#ifndef NV_POSITION_HH
-#define NV_POSITION_HH
-
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/range.hh>
-#include <utility>
-
-namespace nv
-{
-	typedef ivec2 position;
-	typedef ivec2 dimension;
-
-	struct rectangle
-	{
-		typedef position::value_type value_type;
-		typedef std::size_t size_type;
-		typedef rectangle type;
-		
-		position ul;
-		position lr;
-		/**
-		 * Creates a new rectangle assigned to {0, 0, 0, 0}.
-		 */
-		rectangle() : ul(), lr() {}
-		
-		/**
-		 * Creates a new rectangle given a position.
-		 *
-		 * @param p The position to assign the rectangle to.
-		 */
-		explicit rectangle( position p ) : ul(p), lr(p) {}
-		
-		/**
-		 * Creates a new rectangle given an upper-left and lower-right position.
-		 *
-		 * @param aul The position of the upper-left corner of the rectangle.
-		 * @param alr The position of the lower-right corner of the rectangle.
-		 */
-		rectangle( position aul, position alr ) : ul(aul), lr(alr) {}
-		
-		/**
-		 * Creates a new rectangle given an upper-left position, width, and height.
-		 *
-		 * @param aul The position of the upper-left corner of the rectangle.
-		 * @param width The width of the rectangle.
-		 * @param height The height of the rectangle.
-		 */
-		rectangle( position aul, value_type width, value_type height ) : ul(aul), lr(aul + position(width,height)) {}
-        
-        /**
-         * Explicit Copy constructor
-         */
-        rectangle( const rectangle& r ) : ul( r.ul ), lr( r.lr ) {}
-        
-        /**
-         * Explicit Copy assignment operator
-         */
-        rectangle& operator= (const rectangle& r) { ul = r.ul; lr = r.lr; return *this; }
-		
-		/**
-		 * Sets the dimensions of the rectangle without moving the upper-left of the rectangle.
-		 *
-		 * @param d The new dimensions of the rectangle.
-		 */
-		rectangle& dim( dimension d ) { lr = ul + d; return *this; }
-
-		/**
-		 * Moves the rectangle to a new position while maintaining its size.
-		 *
-		 * @param p The new position of the rectangle's upper-left corner.
-		 */
-		rectangle& pos( position p )  { lr = p + (lr - ul); lr = p; return *this; }
-
-		/**
-		 * Sets the dimensions of the rectangle without moving the upper-left of the rectangle.
-		 *
-		 * @param d The new dimensions of the rectangle.
-		 */
-		void set_dimension( dimension d ) { lr = ul + d; }
-		
-		/**
-		 * Moves the rectangle to a new position while maintaining its size.
-		 *
-		 * @param p The new position of the rectangle's upper-left corner.
-		 */
-		void set_position( position p ) { lr = p + (lr - ul); ul = p; }
-
-		position ur() const { return position( lr.x, ul.y ); }
-		position ll() const { return position( ul.x, lr.y ); }
-		/**
-		 * Gets the dimensions of the rectangle.  Synonym for get_size.
-		 *
-		 * @returns The dimensions of the rectangle.
-		 * @see get_size
-		 */
-		dimension get_dimension() const { return lr - ul; }
-
-		/**
-		 * Gets the position of the upper-left corner of the rectangle.
-		 *
-		 * @returns The position of the rectangle's upper-left corner.
-		 */
-		position  get_position() const { return ul; }
-
-		/**
-		 * Gets the dimensions of the rectangle.  Synonym for get_dimension.
-		 *
-		 * @returns The dimensions of the rectangle.
-		 * @see get_dimension
-		 */
-		dimension get_size() const { return lr - ul; }
-
-		/**
-		 * Gets the center of the rectangle.
-		 *
-		 * @returns The center of the rectangle.
-		 */
-		position get_center() const { return ( lr + ul ) / 2; }
-
-		/**
-		 * Gets the width of the rectangle.
-		 *
-		 * @returns The width of the rectangle.
-		 */
-		value_type get_width() const { return lr.x - ul.x; }
-
-		/**
-		 * Gets the height of the rectangle.
-		 *
-		 * @returns The height of the rectangle.
-		 */
-		value_type get_height() const { return lr.y - ul.y; }
-
-		/**
-		 * Gets the area of the rectangle.
-		 *
-		 * @returns The area of the rectangle.
-		 */
-		value_type get_area() const { return (lr.y - ul.y) * (lr.x - ul.x); }
-
-		/**
-		 * Gets the area of the rectangle.
-		 *
-		 * @returns The area of the rectangle, including the edge
-		 */
-		value_type get_enclosed_area() const { return (lr.y - ul.y + 1) * (lr.x - ul.x + 1); }
-
-		/**
-		 * Checks to see if the rectangle is backwards.
-		 *
-		 * @returns True if the rectangle's upper-left is above and left (or equal to) the rectangle's lower-right, false if it is not.
-		 */
-		bool is_valid() const {	return lr.x >= ul.x && lr.y >= ul.y; }
-
-		/**
-		 * Enlarges the rectangle by a given amount.  Each side is adjusted by the given amount, e.g. expanding by 1 increases the width and height by 2 each.
-		 *
-		 * @param value The amount to adjust each sides by.
-		 */
-		void expand( value_type value ) { position p(value,value); ul -= p; lr += p; }
-
-		/**
-		 * Reduces the rectangle by a given amount.  Each side is adjusted by the given amount, e.g. shrinking by 1 decreases the width and height by 2 each.
-		 *
-		 * @param value The amount to adjust each side by.
-		 */
-		void shrink( value_type value ) { position p(value,value); ul += p; lr -= p; }
-
-		/**
-		 * Gets a rectangle that is an expanded version of this rectangle.
-		 *
-		 * @param value The amount to adjust each side by.
-		 * @returns An expanded rectangle.
-		 * @see expand
-		 */
-		rectangle expanded( int value ) { position p(value,value); return rectangle(ul-p, lr+p); }
-
-		/**
-		 * Gets a rectangle that is a shrunk version of this rectangle.
-		 *
-		 * @param value The amount to adjust each side by.
-		 * @returns A shrunk rectangle.
-		 * @see shrink
-		 */
-		rectangle shrinked( int value ) { position p(value,value); return rectangle(ul+p, lr-p); }
-		
-		/**
-		 * Shifts the rectangle by a given amount.
-		 *
-		 * @param pos The amount to shift the rectangle by.
-		 */
-		rectangle& operator+=( const position& pos ) { ul += pos; lr += pos; return (*this); }
-
-		/**
-		 * Returns a rectangle shifted by a given amount.
-		 *
-		 * @param pos The amount to shift by. 
-		 * @returns The shifted rectangle.
-		 */
-		rectangle operator+( const position& pos ) const {	rectangle r(*this); return r += pos; }
-
-		/**
-		 * Shifts the rectangle by a given amount.
-		 *
-		 * @param pos The amount to shift the rectangle by.
-		 */
-		rectangle& operator-=( const position& pos ) { ul -= pos; lr -= pos; return (*this); }
-
-		/**
-		 * Returns a rectangle shifted by a given amount.
-		 *
-		 * @param pos The amount to shift by.
-		 * @returns The shifted rectangle.
-		 */
-		rectangle operator-( const position& pos ) const {	rectangle r(*this); return r -= pos; }
-
-		/**
-		 * Compares two rectangles to see if they are the same.
-		 *
-		 * @param r The rectangle to compare to.
-		 * @returns True if the rectangles have the same positions and dimensions, false otherwise.
-		 */
-		bool operator==( const rectangle& r ) const { return r.ul == ul && r.lr == lr; }
-
-		/**
-		 * Compares two rectangles to see if they are different.
-		 *
-		 * @param r The rectangle to compare to.
-		 * @returns True if the rectangles have different positions or dimensions, false otherwise.
-		 */
-		bool operator!=( const rectangle& r ) const { return r.ul != ul || r.lr != lr; }
-
-		/**
-		 * Checks if a position is within the bounds of this rectangle.
-		 *
-		 * @param r The position to check.
-		 * @returns True if the position is inside or on the edge of the rectangle, false otherwise.
-		 */
-		bool contains( const position& r ) const{ return lr.y >= r.y && ul.y <= r.y && lr.x >= r.x && ul.x <= r.x; }
-
-		/**
-		 * Checks if a rectangle is within the bounds of this rectangle.
-		 *
-		 * @param r The rectangle to check.
-		 * @returns True if the entire rectangle to check is inside or on the edge of this rectangle, false otherwise.
-		 */
-		bool contains( const rectangle& r ) const { return contains( r.ul ) && contains( r.lr ); }
-
-		/**
-		 * Checks if another rectangle overlaps this one.
-		 *
-		 * @param r The rectangle to check.
-		 * @returns True if any part of the rectangle to check overlaps this rectangle, false otherwise.
-		 */
-		bool collides( const rectangle& r ) const { return lr.y > r.ul.y && ul.y < r.lr.y && lr.x > r.ul.x && ul.x < r.lr.x; }
-
-		/**
-		 * Limits the region of the rectangle to the inidicated rectangle.
-		 *
-		 * @param r The rectangle that this rectangle is confined to.
-		 * @returns True if the rectangle was changed, false otherwise.
-		 */
-		bool clamp_to( const rectangle& r )
-		{
-			if (r.contains(*this)) return false;
-			ul = nv::max( ul, r.ul );
-			lr = nv::min( lr, r.lr );
-			ul = nv::min( ul, lr );
-			return true;
-		}
-
-		/**
-		 * Limits the size of the rectangle to the given rectangle's size.
-		 *
-		 * @param r The rectangle representing the maximum dimensions this rectangle can be.
-		 * @returns True if the rectangle needed to be resized, false otherwise.
-		 */
-		bool constrain_to( const rectangle& r )
-		{
-			if ( r.get_width() < get_width() || r.get_height() < get_height() ) return false;
-			(*this) += nv::min( r.ul - ul, position() );
-			(*this) -= nv::min( lr - r.lr, position() );
-			return true;
-		}
-
-		/**
-		 * Fixes an invalid rectangle.
-		 */
-		void repair() 
-		{
-			if (ul.x > lr.x) std::swap( ul.x, lr.x );
-			if (ul.y > lr.y) std::swap( ul.y, lr.y );
-		}
-
-		/**
-		 * Expands the rectangle to just include the given point.
-		 *
-		 * @param p The point to include in the rectangle.
-		 */
-		void include_point( position p )
-		{
-			lr = nv::max( lr, p );
-			ul = nv::min( ul, p );
-		}
-
-	};
-
-}
-
-#endif // NV_POSITION_HH
Index: unk/nv/profiler.hh
===================================================================
--- /trunk/nv/profiler.hh	(revision 318)
+++ 	(revision )
@@ -1,88 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file profiler.hh
- * @author Kornel Kisielewicz
- * @brief profiler
- */
-
-#ifndef NV_PROFILER_HH
-#define NV_PROFILER_HH
-
-#include <nv/common.hh>
-#include <nv/singleton.hh>
-#include <unordered_map>
-
-#define NV_PROFILE( tag ) nv::profiler_guard __profile( tag )
-
-namespace nv
-{
-	class profiler : public auto_singleton< profiler >
-	{
-	protected:
-		class node
-		{
-		public:
-			friend class profiler;
-			node* get_parent() { return m_parent; }
-			node* get_child( const std::string& tag )
-			{
-				auto it = m_children.find( tag );
-				return ( it != m_children.end() ) ? it->second : nullptr;
-			}
-		protected:
-			node( const char* tag, node* parent );
-			node* request_child( const char* tag );
-			void start();
-			bool stop();
-			~node();
-		protected:
-			typedef std::unordered_map< std::string, node* > map;
-
-			std::string m_tag;
-			map         m_children;
-			node*       m_parent;
-			uint32      m_recusion;
-
-			uint32      m_calls;
-			uint64      m_start_time_us;
-			uint64      m_total_time_us;
-		};
-
-	protected:
-		profiler();
-		~profiler();
-
-		void start_profile( const char* tag );
-		void stop_profile();
-	public:
-		friend class auto_singleton< profiler >;
-		friend class profiler_guard;
-		void log_report();
-	private:
-		void log_node_children( const std::string& ind, const node* n );
-		node* m_root;
-		node* m_current;
-	};
-
-	class profiler_guard
-	{
-	public:
-		profiler_guard( const char* tag )
-		{
-			profiler::pointer()->start_profile( tag );
-		}
-
-		~profiler_guard()
-		{
-			profiler::pointer()->stop_profile();
-		}
-	};
-
-} // namespace nv
-
-#endif // NV_PROFILER_HH
Index: unk/nv/random.hh
===================================================================
--- /trunk/nv/random.hh	(revision 318)
+++ 	(revision )
@@ -1,183 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_RANDOM_HH
-#define NV_RANDOM_HH
-
-#include <nv/common.hh>
-#include <random>
-#include <nv/math.hh>
-
-namespace nv
-{
-
-	class random
-	{
-	public:
-		typedef std::mt19937::result_type result_type;
-		typedef std::mt19937::result_type seed_type;
-
-		random( seed_type seed = 0 );
-		seed_type randomize();
-		void set_seed( seed_type seed = 0 );
-		static random& get();
-		result_type rand();
-		sint32 srand( sint32 val );
-		uint32 urand( uint32 val );
-		f32 frand( f32 val );
-		sint32 srange( sint32 min, sint32 max );
-		uint32 urange( uint32 min, uint32 max );
-		f32 frange( f32 min, f32 max );
-		uint32 dice( uint32 count, uint32 sides );
-
-		template < typename T >
-		glm::detail::tvec2<T> range( glm::detail::tvec2<T> min, glm::detail::tvec2<T> max )
-		{
-			return glm::detail::tvec2<T>( 
-				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
-				range_impl( min.y, max.y, std::is_floating_point<T>() )
-				);
-		}
-
-		template < typename T >
-		glm::detail::tvec3<T> range( glm::detail::tvec3<T> min, glm::detail::tvec3<T> max )
-		{
-			return glm::detail::tvec3<T>( 
-				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
-				range_impl( min.y, max.y, std::is_floating_point<T>() ),
-				range_impl( min.z, max.z, std::is_floating_point<T>() )
-				);
-		}
-
-		template < typename T >
-		glm::detail::tvec4<T> range( glm::detail::tvec4<T> min, glm::detail::tvec4<T> max )
-		{
-			return glm::detail::tvec4<T>( 
-				range_impl( min.x, max.x, std::is_floating_point<T>() ), 
-				range_impl( min.y, max.y, std::is_floating_point<T>() ),
-				range_impl( min.z, max.z, std::is_floating_point<T>() ), 
-				range_impl( min.w, max.w, std::is_floating_point<T>() ) 
-				);
-		}
-
-		vec3 unit_vec3( bool = false )
-		{
-			return precise_unit_vec3();
-//			return precise ? precise_unit_vec3() : fast_unit_vec3();
-		}
-		vec2 unit_vec2( bool = false )
-		{
-			return precise_unit_vec2();
-//			return precise ? precise_unit_vec2() : fast_unit_vec2();
-		}
-
-		vec2 disk_point( bool precise = false )
-		{
-			return precise ? precise_disk_point() : fast_disk_point();
-		}
-
-		vec3 sphere_point( bool precise = false )
-		{
-			return precise ? precise_sphere_point() : fast_sphere_point();
-		}
-
-		vec2 ellipse_point( const vec2& radii, bool precise = false )
-		{
-			return precise ? precise_ellipse_point( radii ) : fast_ellipse_point( radii );
-		}
-
-		vec3 ellipsoid_point( const vec3& radii, bool precise = false )
-		{
-			return precise ? precise_ellipsoid_point( radii ) : fast_ellipsoid_point( radii );
-		}
-
-		vec2 ellipse_edge( const vec2& radii, bool = false )
-		{
-			return unit_vec2() * radii;
-		}
-
-		vec3 ellipsoid_edge( const vec3& radii, bool = false )
-		{
-			return unit_vec3() * radii;
-		}
-
-		vec2 hollow_disk_point( float iradius, float oradius, bool precise = false )
-		{
-			return precise ? precise_hollow_disk_point( iradius, oradius ) : fast_hollow_disk_point( iradius, oradius );
-		}
-
-		vec3 hollow_sphere_point( float iradius, float oradius, bool precise = false )
-		{
-			return precise ? precise_hollow_sphere_point( iradius, oradius ) : fast_hollow_sphere_point( iradius, oradius );
-		}
-
-		vec2 hollow_ellipse_point( const vec2& iradii, const vec2& oradii, bool precise = false )
-		{
-			return precise ? precise_hollow_ellipse_point( iradii, oradii ) : fast_hollow_ellipse_point( iradii, oradii );
-		}
-
-		vec3 hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii, bool precise = false )
-		{
-			return precise ? precise_hollow_ellipsoid_point( iradii, oradii ) : fast_hollow_ellipsoid_point( iradii, oradii );
-		}
-
-		//vec2 fast_unit_vec2();
-		vec2 precise_unit_vec2();
-		//vec3 fast_unit_vec3();
-		vec3 precise_unit_vec3();
-	
-		vec2 fast_disk_point();
-		vec2 precise_disk_point();
-		vec3 fast_sphere_point();
-		vec3 precise_sphere_point();
-
-		vec2 fast_ellipse_point( const vec2& radii )
-		{
-			return fast_disk_point() * radii;
-		}
-		vec2 precise_ellipse_point( const vec2& radii );
-
-		vec3 fast_ellipsoid_point( const vec3& radii )
-		{
-			return fast_sphere_point() * radii;
-		}
-
-		vec3 precise_ellipsoid_point( const vec3& radii );
-
-		vec2 fast_hollow_disk_point( float iradius, float oradius );
-		vec2 precise_hollow_disk_point( float iradius, float oradius );
-		vec3 fast_hollow_sphere_point( float iradius, float oradius );
-		vec3 precise_hollow_sphere_point( float iradius, float oradius );
-
-		vec2 fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii );
-		vec2 precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii );
-		vec3 fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii );
-		vec3 precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii );
-
-
-	private:
-		static seed_type randomized_seed();
-
-		template <typename T>
-		T range_impl( T min, T max, const std::true_type& )
-		{
-			std::uniform_real_distribution<T> dist( min, max );
-			return dist( rng );
-		}
-
-		template <typename T>
-		T range_impl( T min, T max, const std::false_type& )
-		{
-			std::uniform_int_distribution<T> dist( min, max );
-			return dist( rng );
-		}
-	private:
-		std::mt19937 rng;
-	};
-
-}
-
-#endif // NV_RANDOM_HH
Index: unk/nv/range.hh
===================================================================
--- /trunk/nv/range.hh	(revision 318)
+++ 	(revision )
@@ -1,227 +1,0 @@
-// Copyright (C) 2014 ChaosForge Ltd
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-/**
- * @file range.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief range iterators
- */
-
-#ifndef NV_RANGE_HH
-#define NV_RANGE_HH
-
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/type_traits.hh>
-#include <iterator>
-
-namespace nv
-{
-
-	namespace detail
-	{
-
-		template < typename T >
-		class forward_iterator_base : public std::iterator< std::input_iterator_tag, T >
-		{
-		public:
-			forward_iterator_base( T value ) : m_value( value ) {}
-			T operator* () const { return m_value; }
-			T const* operator-> () const { return &m_value; }
-			bool operator== ( const forward_iterator_base& rhs ) const
-			{
-				return m_value == rhs.m_value;
-			}
-			bool operator!= ( const forward_iterator_base& rhs ) const
-			{
-				return !( *this == rhs );
-			}
-		protected:
-			T m_value;
-		};
-
-		template < typename T >
-		class range_iterator_base : public forward_iterator_base< T >
-		{
-		public:
-			range_iterator_base( T value ) : forward_iterator_base( value ) {}
-			range_iterator_base& operator++ () 
-			{
-				++m_value; 
-				return *this; 
-			}
-			range_iterator_base operator++ (int) 
-			{
-				auto result = *this; 
-				++*this; 
-				return result;
-			}
-		};
-
-		template < typename T >
-		class range2d_iterator_base 
-			: public forward_iterator_base< glm::detail::tvec2<T> >
-		{
-		public:
-			range2d_iterator_base( glm::detail::tvec2<T> value, T min, T max ) 
-				: forward_iterator_base( value ), m_min(min), m_max(max) {}
-			range2d_iterator_base& operator++ () 
-			{
-				++m_value.x;
-				if ( m_value.x > m_max ) 
-				{
-					++m_value.y;
-					m_value.x = m_min;
-				}
-				return *this; 
-			}
-			range2d_iterator_base operator++ (int) 
-			{
-				auto result = *this; 
-				++*this; 
-				return result;
-			}
-		protected:
-			T m_min;
-			T m_max;
-		};
-
-		template < typename T >
-		class bits_iterator_base : public forward_iterator_base< T >
-		{
-		public:
-			typedef typename base_underlying_type<T>::type base_type;
-			static const T invalid = T( 0 );
-
-			bits_iterator_base( T value, T current ) : forward_iterator_base( current ), m_full( value )
-			{
-				if( !( (base_type)value & (base_type)current ) )
-					next();
-			}
-			bits_iterator_base& operator++ () 
-			{
-				next();
-				return *this; 
-			}
-			bits_iterator_base operator++ (int) 
-			{
-				auto result = *this; 
-				++*this; 
-				return result;
-			}
-		private:
-			void next()
-			{
-				do
-				{
-					if ( m_value == invalid || m_full <= m_value ) { m_value = invalid; m_full = invalid; break; }
-					m_value = T((base_type)m_value << 1);
-				} while ( !( (base_type)m_full & (base_type)m_value ) );
-			}
-
-			T m_full;
-		};
-
-
-	} // namespace detail
-
-	template < typename T >
-	class range_iterator_provider
-	{
-	public:
-		class iterator : public detail::range_iterator_base<T>
-		{
-		public:
-			iterator( T value ) : detail::range_iterator_base<T>(value) {}
-		};
-
-		range_iterator_provider( T begin, T end ) : m_begin( begin ), m_end( end ) {}
-		iterator begin() { return m_begin; }
-		iterator end() { return m_end; }
-
-	protected:
-		iterator m_begin;
-		iterator m_end;
-	};
-
-	template < typename T >
-	class range2d_iterator_provider
-	{
-	public:
-		typedef T value_type;
-		typedef typename T::value_type element_type;
-
-		class iterator : public detail::range2d_iterator_base<element_type>
-		{
-		public:
-			iterator( value_type begin, element_type min, element_type max ) 
-				: detail::range2d_iterator_base<element_type>(begin, min, max) {}
-		};
-
-		range2d_iterator_provider( value_type begin, value_type end ) : m_begin( begin, begin.x, end.x ), m_end( T(begin.x, ++end.y ), begin.x, end.x ) {}
-		iterator begin() { return m_begin; }
-		iterator end() { return m_end; }
-
-	protected:
-		iterator m_begin;
-		iterator m_end;
-	};
-
-	template < typename T >
-	class bits_iterator_provider
-	{
-	public:
-		typedef typename base_underlying_type<T>::type base_type;
-		typedef detail::bits_iterator_base<T> iterator;
-		static const T invalid = T( 0 );
-
-		bits_iterator_provider( T value ) : m_value( value ) {}
-		iterator begin() { return iterator( m_value, T(1) ); }
-		iterator end() { return iterator( m_value, invalid ); }
-
-	protected:
-		T m_value;
-	};
-
-	template < typename T >
-	range_iterator_provider<T> range( T begin, T end )
-	{
-		return range_iterator_provider<T>( begin, end+1 );
-	}
-
-	template < typename T >
-	range2d_iterator_provider<T> range2d( T begin, T end )
-	{
-		return range2d_iterator_provider<T>( begin, end );
-	}
-
-	template < typename T >
-	range_iterator_provider<T> range( T end )
-	{
-		return range_iterator_provider<T>( 0, end );
-	}
-
-	template < typename T >
-	range2d_iterator_provider<T> range2d( T end )
-	{
-		return range2d_iterator_provider<T>( T(0,0), T( --end.x, --end.y ) );
-	}
-
-	template < typename C >
-	auto index( const C& c ) -> range_iterator_provider<decltype( c.size() )>
-	{
-		return range_iterator_provider( 0, c.size() );
-	}
-
-	template < typename T >
-	bits_iterator_provider<T> bits( T value )
-	{
-		return bits_iterator_provider<T>( value );
-	}
-
-
-}
-
-#endif // NV_RANGE_HH
Index: /trunk/nv/rogue/fov.hh
===================================================================
--- /trunk/nv/rogue/fov.hh	(revision 318)
+++ /trunk/nv/rogue/fov.hh	(revision 319)
@@ -10,6 +10,6 @@
 #define NV_ROGUE_FOV_HH
 
-#include <nv/common.hh>
-#include <nv/position.hh>
+#include <nv/core/common.hh>
+#include <nv/core/position.hh>
 #include <nv/interface/map_area.hh>
 
Index: /trunk/nv/rogue/fov_recursive_shadowcasting.hh
===================================================================
--- /trunk/nv/rogue/fov_recursive_shadowcasting.hh	(revision 318)
+++ /trunk/nv/rogue/fov_recursive_shadowcasting.hh	(revision 319)
@@ -8,6 +8,6 @@
 #define NV_ROGUE_FOV_RECURSIVE_SHADOWCASTING_HH
 
-#include <nv/common.hh>
-#include <nv/position.hh>
+#include <nv/core/common.hh>
+#include <nv/core/position.hh>
 #include <nv/rogue/fov.hh>
 
Index: unk/nv/root.hh
===================================================================
--- /trunk/nv/root.hh	(revision 318)
+++ 	(revision )
@@ -1,39 +1,0 @@
-// Copyright (C) 2012 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_ROOT_HH
-#define NV_ROOT_HH
-
-#include <nv/common.hh>
-#include <nv/object.hh>
-#include <nv/string.hh>
-#include <list>
-
-namespace nv
-{
-
-	/**
-	 * Implements the root of a object tree-like structure.
-	 */
-	class root 
-	{
-	public:
-		root() {}
-		template < typename T >
-		object* create_object( const std::string& id )
-		{
-			object* o = new T(id);
-			object_created(o);
-			return o;
-		}
-		void destroy_children( object* o );
-		virtual void destroy_object( object* o );
-		virtual ~root() {}
-	protected:
-		virtual void object_created( object* ) {}
-	};
-	
-} // namespace nv
-
-#endif // NV_ROOT_HH
Index: /trunk/nv/sdl/sdl_audio.hh
===================================================================
--- /trunk/nv/sdl/sdl_audio.hh	(revision 318)
+++ /trunk/nv/sdl/sdl_audio.hh	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -13,5 +13,5 @@
 #define NV_SDL_AUDIO_HH
 
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <nv/interface/audio.hh>
 
Index: unk/nv/singleton.hh
===================================================================
--- /trunk/nv/singleton.hh	(revision 318)
+++ 	(revision )
@@ -1,120 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file singleton.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief singleton pattern
- */
-
-#ifndef NV_SINGLETON_HH
-#define NV_SINGLETON_HH
-
-#include <cassert>
-
-namespace nv
-{
-	/**
-	 * singleton
-	 * @brief Represents an accessible static object that will only have one instance.
-	 */
-    template <class T>
-    class singleton
-    {
-    private:
-        static T *singleton_; ///< Pointer to the instance of this object type.
-
-    protected:
-
-		/**
-		 * Creates the single instance if one doesn't already exist.
-		 */
-        singleton()
-        {
-            assert(!singleton_);
-            singleton_ = static_cast<T*>(this);
-        }
-
-		/**
-		 * Destroys the instance.
-		 */
-        ~singleton()
-        {
-            assert(singleton_);
-            singleton_ = 0;
-        }
-
-    public:
-		/**
-		 * Checks to see if the instance exists.
-		 *
-		 * @returns True if this singleton has an instance assigned, false otherwise.
-		 */
-        static bool is_valid()
-        {
-            return singleton_ != 0;
-        }
-
-		/**
-		 * Returns the pointer to the instance.
-		 *
-		 * @returns The pointer to the instance.
-		 */
-        static T *pointer()
-        {
-            assert(singleton_);
-            return singleton_;
-        }
-		/**
-		 * Returns the object referenced by this singleton.
-		 */
-        static T &reference()
-        {
-            assert(singleton_);
-            return *singleton_;
-        }
-    };
-
-    template <class T>
-    T* singleton<T>::singleton_ = 0;
-
-
-	/**
-	 * auto_singleton
-	 * @brief Represents a singleton that automatically creates an instance if one doesn't already exist.
-	 */
-    template <class T>
-    class auto_singleton : public singleton<T>
-    {
-    public:
-		/**
-		 * Returns the pointer to the instance.  Makes an instance if one doesn't already exist.
-		 */
-        static T *pointer()
-        {
-            if ( !singleton<T>::is_valid() )
-            {
-                new T();
-            }
-            return singleton<T>::pointer();
-        }
-
-		/**
-		 * Returns the object referenced by this singleton.  Makes an instance if one doesn't already exist.
-		 */
-        static T &reference()
-        {
-            if ( !singleton<T>::is_valid() )
-            {
-                new T();
-            }
-            return singleton<T>::reference();
-        }
-    };
-
-} // namespace nv
-
-#endif // NV_SINGLETON_HH
Index: unk/nv/string.hh
===================================================================
--- /trunk/nv/string.hh	(revision 318)
+++ 	(revision )
@@ -1,251 +1,0 @@
-// Copyright (C) 2012 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_STRING_HH
-#define NV_STRING_HH
-
-#include <string>
-#include <algorithm>
-#include <cstring>
-#include <sstream>
-#include <fstream>
-#include <nv/common.hh>
-#include <nv/exception.hh>
-
-namespace nv
-{
-	using std::string;
-
-	/**
-	* Utility function for converting any value to string.
-	*
-	* @param value value to be converted, needs to have << operator
-	*        to stream
-	* @throw runtime_error Throws runtime_error on conversion fail
-	* @return value converted to string
-	*/
-	template < class T >
-	string to_string( const T& value )
-	{
-		std::stringstream stream;
-		stream << value;
-
-		if ( stream.fail() )
-		{
-			NV_THROW( runtime_error, "bad cast" );
-		}
-
-		return stream.str();
-	}
-
-	/**
-	* Override function for special treatment of strings. Returns the
-	* value passed.
-	*/
-	inline string to_string( const string& value)
-	{
-		return value;
-	}
-
-	/**
-	* Utility function for converting a string to the given type
-	*
-	* @param vin the string representing the value
-	* @param vout the value to be read. Must be streamable with >>
-	* @throw runtime_error Throws runtime_error on conversion fail
-	*/
-	template < class T >
-	void from_string( const string& vin, T& vout )
-	{
-		std::istringstream value( vin );
-		value >> vout;
-
-		if ( value.fail() )
-		{
-			NV_THROW( runtime_error, "bad cast" );
-		}
-	}
-
-	/**
-	* Utility function for converting a string to the given type
-	*
-	* @param vin the string representing the value
-	* @throw runtime_error Throws runtime_error on conversion fail
-	*/
-	template < class T >
-	T string_cast( const string& vin )
-	{
-		T vout;
-		std::istringstream value( vin );
-		value >> vout;
-
-		if ( value.fail() )
-		{
-			NV_THROW( runtime_error, "bad cast" );
-		}
-		return vout;
-	}
-
-
-	/**
-	* Override function for special treatment of strings. Returns the
-	* value passed.
-	*/
-	inline void from_string( const string& vin, string& vout )
-	{
-		vout = vin;
-	}
-
-	/**
-	* Override function for special treatment of strings. Returns the
-	* value passed.
-	*/
-	template <>
-	inline std::string string_cast( const string& vin )
-	{
-		return vin;
-	}
-
-
-	/**
-	* Simple function for slurping a file into a string.
-	*/
-	inline std::string slurp( const std::string& filename )
-	{
-		std::ifstream input(filename);
-		if ( !input.is_open() ) NV_THROW( std::runtime_error, "File "+filename+" not found!");
-		std::stringstream sstr;
-		while(input >> sstr.rdbuf());
-		return sstr.str();
-	}
-
-	inline bool trim( std::string& str )
-	{
-		size_t endpos = str.find_last_not_of(" \r\n\t");
-		size_t startpos = str.find_first_not_of(" \r\n\t");
-
-		if ( string::npos != endpos || string::npos != startpos )
-		{
-			if ( string::npos == startpos ) startpos = 0;
-			if ( string::npos != endpos )   endpos = endpos+1-startpos;
-			str = str.substr( startpos, endpos );
-			return true;
-		}
-		return false;
-	}
-
-	inline bool rtrim( std::string& str )
-	{
-		size_t endpos = str.find_last_not_of(" \r\n\t");
-		if ( string::npos != endpos )
-		{
-			str = str.substr( 0, endpos+1 );
-			return true;
-		}
-		return false;
-	}
-
-	inline bool ltrim( std::string& str )
-	{
-		size_t startpos = str.find_first_not_of(" \r\n\t");
-		if( string::npos != startpos )
-		{
-			str = str.substr( startpos );
-			return true;
-		}
-		return false;
-	}
-
-	inline std::string trimmed( const std::string& str )
-	{
-		size_t endpos = str.find_last_not_of(" \r\n\t");
-		size_t startpos = str.find_first_not_of(" \r\n\t");
-
-		if ( string::npos != endpos || string::npos != startpos )
-		{
-			if ( string::npos == startpos ) startpos = 0;
-			if ( string::npos != endpos )   endpos = endpos+1-startpos;
-			return str.substr( startpos, endpos );
-		}
-		return str;
-	}
-
-	inline std::string rtrimmed( const std::string& str )
-	{
-		size_t endpos = str.find_last_not_of(" \r\n\t");
-		if ( string::npos != endpos )
-		{
-			return str.substr( 0, endpos+1 );
-		}
-		return str;
-	}
-
-	inline std::string ltrimmed( const std::string& str )
-	{
-		size_t startpos = str.find_first_not_of(" \r\n\t");
-		if( string::npos != startpos )
-		{
-			return str.substr( startpos );
-		}
-		return str;
-	}
-
-	inline bool ends_with( const std::string& s, const std::string & ending )
-	{
-		if ( s.length() >= ending.length() ) {
-			return ( 0 == s.compare (s.length() - ending.length(), ending.length(), ending) );
-		} else {
-			return false;
-		}
-	}
-
-	inline std::string& remove_chars( std::string& s, const std::string& chars ) 
-	{
-		s.erase(remove_if(s.begin(), s.end(), 
-			[&chars](const char& c) {
-				return chars.find(c) != std::string::npos;
-			}), s.end());
-		return s;
-	}
-
-	inline std::string remove_chars_copy( std::string s, const std::string& chars ) 
-	{
-		return remove_chars(s, chars);
-	}
-
-	template< typename T >
-	struct string_length
-	{
-		static size_t get( T ) { return 0; }
-	};
-	template< size_t S >
-	struct string_length< char[S] >
-	{
-		static size_t get( const char[S] ) { return S-1; }
-	};
-	template< size_t S >
-	struct string_length< const char[S] >
-	{
-		static size_t get( const char[S] ) { return S-1; }
-	};
-	template<>
-	struct string_length< char* >
-	{
-		static size_t get( const char* s ) { return std::strlen( s ); }
-	};
-	template<>
-	struct string_length< const char* >
-	{
-		static size_t get( const char* s ) { return std::strlen( s ); }
-	};
-	template<>
-	struct string_length< std::string >
-	{
-		static size_t get( const std::string& s ) { return s.length(); }
-	};
-
-
-}
-
-#endif // NV_STRING_HH
Index: unk/nv/time.hh
===================================================================
--- /trunk/nv/time.hh	(revision 318)
+++ 	(revision )
@@ -1,148 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-/**
- * @file time.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief Time related functions
- */
-
-#ifndef NV_TIME_HH
-#define NV_TIME_HH
-
-#include <nv/common.hh>
-
-namespace nv
-{
-	/**
-	 * Returns the amount of ticks of the processors high resolution 
-	 * timer. Currently only supported on GCC and MSVC. Probably only on
-	 * some architectures.
-	 *
-	 * @returns amount of ticks
-	 */
-	uint64 get_ticks();
-
-	/**
-	 * Performs an operating system sleep call.
-	 *
-	 * @param ms time in milliseconds to sleep
-	 */
-	void sleep( uint32 ms );
-
-	/**
-	 * Get millisecond count based on std::clock
-	 */
-	uint32 get_cpu_ms();
-
-	/**
-	 * Get microsecond count based on std::clock
-	 */
-	uint64 get_cpu_us();
-
-	/**
-	 * Get millisecond count based on system counter
-	 */
-	uint32 get_system_ms();
-
-	/**
-	 * Get microsecond count based on system counter
-	 */
-	uint64 get_system_us();
-
-	struct cpu_ms_timer 
-	{ 
-		typedef uint32 value_type;
-		static const value_type second = 1000;    
-		value_type operator()() { return get_cpu_ms(); } 
-	};
-
-	struct cpu_us_timer 
-	{ 
-		typedef uint64 value_type;
-		static const value_type second = 1000000; 
-		uint64 operator()() { return get_cpu_us(); } 
-	};
-
-	struct system_ms_timer 
-	{ 
-		typedef uint32 value_type;
-		static const value_type second = 1000;    
-		value_type operator()() { return get_system_ms(); } 
-	};
-
-	struct system_us_timer 
-	{ 
-		typedef uint64 value_type;
-		static const value_type second = 1000000; 
-		value_type operator()() { return get_system_us(); } 
-	};
-	
-	/**
-	 * Timer template class
-	 */
-	template < class Timer >
-	class timer_class
-	{
-	public:
-		typedef typename Timer::value_type value_type;
-
-		timer_class()	: last( Timer()() ) {}
-		void mark()	
-		{
-			value_type now = Timer()();
-			stored = now - last;
-			last = now;
-		}
-		value_type elapsed() const
-		{
-			return stored;
-		}
-	private:
-		value_type last;
-		value_type stored;
-	};
-
-	/**
-	 * FPS template class
-	 */
-	template < class Timer >
-	class fps_counter_class
-	{
-	public:
-		typedef typename Timer::value_type value_type;
-
-		fps_counter_class() : frames(1), last(0) {}
-		bool tick()
-		{
-			value_type now = Timer()();
-			if ( now - last >= Timer::second )
-			{
-				value = (static_cast<float>(frames) /
-					static_cast<float>(now - last))*Timer::second;
-				frames = 1;
-				last = now;
-				return true;
-			}
-			frames++;
-			return false;
-		}
-		f32 fps() const
-		{
-			return value;
-		}
-	private:
-		value_type last;
-		uint32     frames;
-		f32        value;
-	};
-
-	typedef timer_class< system_ms_timer > ms_timer;
-	typedef timer_class< system_us_timer > us_timer;
-	typedef fps_counter_class< system_ms_timer > fps_counter;
-
-} // namespace nv
-
-#endif // NV_TIME_HH
Index: unk/nv/transform.hh
===================================================================
--- /trunk/nv/transform.hh	(revision 318)
+++ 	(revision )
@@ -1,107 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_TRANSFORM_HH
-#define NV_TRANSFORM_HH
-
-#include <nv/common.hh>
-#include <nv/math.hh>
-
-namespace nv
-{
-
-	class transform
-	{
-	public:
-		transform() {}
-		explicit transform( const vec3& a_position ) : m_position( a_position ) {}
-		explicit transform( const quat& a_orientation ) : m_orientation( a_orientation ) {}
-		explicit transform( const mat4& a_matrix ) { set( a_matrix ); }
-		transform( const vec3& a_position, const quat& a_orientation ) : m_position( a_position ), m_orientation( a_orientation ) {}
-
-		void set_position( const vec3& a_position ) { m_position = a_position; }
-		void set_orientation( const quat& a_orientation ) { m_orientation = a_orientation; }
-		void set_orientation( const vec3& axis, float angle )
-		{
-			m_orientation = glm::angleAxis( angle, axis );
-		}
-
-		const vec3& get_position() const { return m_position; }
-		const quat& get_orientation() const { return m_orientation; }
-
-	public:
-		void move( const vec3& heading, float distance )
-		{
-			m_position += glm::normalize( heading ) * distance;
-		}
-		void translate( const vec3& absolute )
-		{
-			m_position += absolute;
-		}
-		void rotate( const vec3& axis, f32 angle )
-		{
-			quat temp( angle, axis );
-			m_orientation = temp * m_orientation;
-		}
-		void set( const mat4& from )
-		{
-			m_orientation = quat( from );
-			m_position    = vec3( from[3] );
-		}
-		mat4 extract() const
-		{
-			mat4 result = glm::mat4_cast( m_orientation );
-			result[3] = vec4( m_position, 1.0f );
-			return result;
-		}
-		transform inverse() const
-		{
-			quat new_orient( glm::inverse( m_orientation ) );
-			// TODO: simplify
-			return transform( -glm::mat3_cast(new_orient) * m_position, new_orient );
-		}
-
-		transform& operator*=(const transform& rhs)
-		{
-			m_position = m_position + m_orientation * rhs.m_position;
-			m_orientation = m_orientation * rhs.m_orientation;
-			return *this;
-		}
-
-		vec3 transformed( const vec3& v ) const
-		{
-			return m_orientation * v + m_position;
-		}
-	private:
-		vec3 m_position;
-		quat m_orientation;
-	};
-
-	inline transform operator*(transform lhs, const transform& rhs)
-	{
-		lhs *= rhs;
-		return lhs;
-	}
-
-	inline vec3 operator*(const vec3 lhs, const transform& rhs)
-	{
-		return rhs.transformed( lhs );
-	}
-
-	template <> struct enum_to_type< TRANSFORM > { typedef transform type; };
-	template <> struct type_to_enum< transform > { static const datatype type = TRANSFORM; };
-
-	template<>
-	inline transform interpolate( const transform& a, const transform& b, float value )
-	{
-		return transform( 
-			glm::mix  ( a.get_position(), b.get_position(), value ), 
-			glm::slerp( a.get_orientation(), b.get_orientation(), value ) 
-		);
-	}
-}
-
-#endif // NV_TRANSFORM_HH
Index: unk/nv/type_traits.hh
===================================================================
--- /trunk/nv/type_traits.hh	(revision 318)
+++ 	(revision )
@@ -1,232 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-/**
- * @file type_traits.hh
- * @author Kornel Kisielewicz epyon@chaosforge.org
- * @brief type traits
- */
-// TODO: function_traits support only up to 4 parameters because:
-//    -- if you have more than 4 params, you're doing something wrong
-//    -- once the Variadic Templates cometh, for great justice we will win!
-
-#ifndef NV_TYPE_TRAITS_HH
-#define NV_TYPE_TRAITS_HH
-
-#include <nv/common.hh>
-#include <type_traits>
-
-namespace nv
-{
-
-	// These could be done much better
-	template <typename T>
-	struct is_cstring
-		: public std::integral_constant<bool,
-		std::is_same<       char *, typename std::decay< T >::type >::value ||
-		std::is_same< const char *, typename std::decay< T >::type >::value >
-		{};
-
-	template <typename T>
-	struct is_stdstring
-		: public std::integral_constant<bool,
-		std::is_same< std::string, typename std::decay< T >::type >::value 
-		>
-	{};
-
-	template < typename T > struct is_string : public std::integral_constant<bool, is_stdstring<T>::value || is_cstring<T>::value> {};
-
-	// Just for once, MSVC is the good guy, and everybody else sucks.
-	// Remove, once requiring standard-compliant CLANG/GCC versions.
-#if NV_COMPILER == NV_MSVC
-	using std::underlying_type;
-#elif NV_COMPILER == NV_CLANG
-	template < typename T >
-	struct underlying_type
-	{
-		typedef __underlying_type(T) type;
-	};
-#else
-	template< typename T >
-	struct underlying_type
-	{
-		typedef typename std::conditional<
-			T( -1 ) < T( 0 ),
-			typename std::make_signed< T >::type,
-			typename std::make_unsigned< T >::type
-			>::type type;
-	};
-#endif
-
-	namespace detail
-	{
-
-		template < typename F >
-		struct function_traits_impl
-		{
-
-		};
-
-		template < typename R >
-		struct function_traits_impl< R (*)(void) >
-		{
-			typedef R (*type)();
-			typedef R        return_type;
-			typedef void     class_type;
-			static const int arg_count = 0;
-		};
-
-		template < typename R, typename T1 >
-		struct function_traits_impl< R (*)( T1 ) >
-		{
-			typedef R (*type)();
-			typedef R        return_type;
-			typedef void     class_type;
-			static const int arg_count = 1;
-		};
-
-		template < typename R, typename T1, typename T2 >
-		struct function_traits_impl< R (*)( T1, T2 ) >
-		{
-			typedef R (*type)();
-			typedef R        return_type;
-			typedef void     class_type;
-			static const int arg_count = 2;
-		};
-
-		template < typename R, typename T1, typename T2, typename T3 >
-		struct function_traits_impl< R (*)( T1, T2, T3 ) >
-		{
-			typedef R (*type)();
-			typedef R        return_type;
-			typedef void     class_type;
-			static const int arg_count = 3;
-		};
-
-		template < typename R, typename T1, typename T2, typename T3, typename T4 >
-		struct function_traits_impl< R (*)( T1, T2, T3, T4 ) >
-		{
-			typedef R (*type)();
-			typedef R        return_type;
-			typedef void     class_type;
-			static const int arg_count = 4;
-		};
-
-		template < class C, typename R >
-		struct function_traits_impl< R (C::*)() >
-		{
-			typedef R (*type)();
-			typedef R       return_type;
-			typedef C       class_type;
-			static const int arg_count = 0;
-		};
-
-		template < class C, typename R, typename T1 >
-		struct function_traits_impl< R (C::*)( T1 ) >
-		{
-			typedef R (*type)();
-			typedef R       return_type;
-			typedef C       class_type;
-			static const int arg_count = 1;
-		};
-
-		template < class C, typename R, typename T1, typename T2 >
-		struct function_traits_impl< R (C::*)( T1, T2 ) >
-		{
-			typedef R (*type)();
-			typedef R       return_type;
-			typedef C       class_type;
-			static const int arg_count = 2;
-		};
-
-		template < class C, typename R, typename T1, typename T2, typename T3 >
-		struct function_traits_impl< R (C::*)( T1, T2, T3 ) >
-		{
-			typedef R (*type)();
-			typedef R       return_type;
-			typedef C       class_type;
-			static const int arg_count = 3;
-		};
-
-		template < class C, typename R, typename T1, typename T2, typename T3, typename T4 >
-		struct function_traits_impl< R (C::*)( T1, T2, T3, T4 ) >
-		{
-			typedef R (*type)();
-			typedef R       return_type;
-			typedef C       class_type;
-			static const int arg_count = 4;
-		};
-
-	}
-
-	template < typename F >
-	struct function_traits : public detail::function_traits_impl< F >
-	{
-
-	};
-
-	template < typename T >
-	struct return_type
-	{
-		typedef typename function_traits< T >::return_type type;
-	};
-
-	template < typename T >
-	struct memfn_class_type
-	{
-		typedef typename function_traits< T >::class_type type;
-	};
-
-	template<typename T>
-	struct is_container
-	{
-	private:
-		typedef char                      yes;
-		typedef struct { char array[2]; } no;
-		template<typename C> static yes test(typename C::iterator*);
-		template<typename C> static no  test(...);
-	public:
-		static const bool value = sizeof(test<T>(0)) == sizeof(yes);
-	};
-
-	template<>
-	struct is_container< std::string > {
-		static const bool value = false;
-	};
-
-	template <typename TYPE> 
-	void construct_object(void* object)
-	{
-		new (object) TYPE;
-	}
-	template <typename TYPE> 
-	void destroy_object(void* object)
-	{
-		((TYPE*)object)->TYPE::~TYPE();
-	}
-
-	template< typename T, typename IS_ENUM >
-	struct base_underlying_type_helper
-	{
-		typedef T type;
-	};
-
-	template< typename T >
-	struct base_underlying_type_helper< T, std::true_type >
-	{
-		typedef typename nv::underlying_type<T>::type type;
-	};
-
-
-	template< typename T >
-	struct base_underlying_type
-	{
-		typedef typename base_underlying_type_helper< T, typename std::is_enum<T>::type >::type type;
-	};
-
-
-}
-
-#endif // NV_TYPE_TRAITS_HH
Index: unk/nv/types.hh
===================================================================
--- /trunk/nv/types.hh	(revision 318)
+++ 	(revision )
@@ -1,215 +1,0 @@
-// Copyright (C) 2012 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#ifndef NV_TYPES_HH
-#define NV_TYPES_HH
-
-#include <nv/common.hh>
-#include <nv/math.hh>
-#include <nv/object.hh>
-#include <nv/type_traits.hh>
-#include <typeinfo>
-#include <typeindex>
-#include <utility>
-#include <unordered_map>
-#include <vector>
-#include <string>
-#include <cstddef>
-
-namespace nv
-{
-
-	struct type_entry;
-	class type_database;
-
-	enum type_flag
-	{
-		TF_POINTER      = 0x01, //!< field is a pointer
-		TF_NOSERIALIZE  = 0x02, //!< ignore during serialization
-		TF_INVISIBLE    = 0x04, //!< field invisible to API
-		TF_READONLY     = 0x08, //!< read only field
-		TF_SIMPLETYPE   = 0x10, //!< raw binary I/O possible
-		TF_OWNED        = 0x20,
-		TF_CONTAINER    = 0x40, //!< is a container
-	};
-
-	struct type_field
-	{
-		std::string      name;          //!< name of the field
-		std::string      type_name;     //!< name of the type of the field
-		const std::type_info* type_inf; //!< typeinfo for later retrieval of type
-		type_entry*      type;          //!< pointer to field type
-		unsigned int     flags;         //!< flags 
-		size_t           offset;
-
-		template< typename TOBJECT, typename TFIELD >
-		type_field( const char* aname, TFIELD TOBJECT::*field, typename std::enable_if< is_container<TFIELD>::value, void* >::type = nullptr )
-		: name(aname)
-			, type_name()
-			, type_inf( &typeid( typename std::remove_pointer<typename TFIELD::value_type>::type ) )
-			, type( nullptr )
-			, flags( 0 )
-			, offset( offset_of( field ) ) 
-		{
-			NV_LOG( LOG_INFO, aname << "-" << offset);
-			flags = TF_CONTAINER |
-				( std::is_pointer<typename TFIELD::value_type>::value ? TF_POINTER : 0 ) |
-				( std::is_pod<typename TFIELD::value_type>::value ? TF_SIMPLETYPE : 0 );
-		}
-
-		template< typename TOBJECT, typename TFIELD >
-		type_field( const char* aname, TFIELD TOBJECT::*field, typename std::enable_if< !is_container<TFIELD>::value, void* >::type = nullptr )
-		: name(aname)
-			, type_name()
-			, type_inf( &typeid( typename std::remove_pointer<TFIELD>::type ) )
-			, type( nullptr )
-			, flags( 0 )
-			, offset( offset_of( field ) )
-		{
-			NV_LOG( LOG_INFO, aname << "-" << offset);
-			flags = 
-				( std::is_pointer<TFIELD>::value ? TF_POINTER : 0 ) |
-				( std::is_pod<TFIELD>::value ? TF_SIMPLETYPE : 0 );
-		}
-
-		type_field& flag( unsigned int f )
-		{
-			flags |= f;
-			return *this;
-		}
-	};
-
-	struct type_enum
-	{
-		std::string name;
-		int         value;
-		type_enum( const char* aname, int avalue ) : name(aname), value(avalue) {}
-	};
-
-	struct type_entry
-	{
-		// Function types for the constructor and destructor of registered types
-		typedef void (*constructor_func)(void*);
-		typedef void (*destructor_func)(void*);
-
-		// Parent type database
-		type_database* type_db;
-
-		// Scoped C++ name of the type
-		std::string name;
-
-		// Pointers to the constructor and destructor functions
-		constructor_func constructor;
-		destructor_func  destructor;
-
-		// Result of sizeof(type) operation
-		size_t size;
-
-		// Base type
-		type_entry* base_type;
-
-		// Field list
-		std::vector<type_field> field_list;
-
-		// Enum list
-		std::vector<type_enum> enum_list;
-
-		template <typename TYPE>
-		type_entry& base();
-
-		template <int SIZE>
-		type_entry& fields( type_field (&init_fields)[SIZE] );
-
-		template <int SIZE>
-		type_entry& enums( type_enum (&init_enums)[SIZE] )
-		{
-			for (int i = 0; i < SIZE; i++)
-			{
-				enum_list.push_back( init_enums[i] );
-			}
-			return *this;
-		}
-	};
-
-	class type_database
-	{
-	public:
-		template< typename TYPE >
-		type_entry& create_type( const char* name )
-		{
-			type_entry* i_type = nullptr;
-			type_name_map::iterator it = m_name_types.find( name );
-			if ( it != m_name_types.end() ) 
-			{
-				return *(it->second);
-			}
-			i_type          = new type_entry;
-			i_type->type_db = this;
-			i_type->name    = name;
-			i_type->size    = sizeof(TYPE);
-
-			i_type->constructor = construct_object<TYPE>;
-			i_type->destructor  = destroy_object<TYPE>;
-
-			m_name_types[name]        = i_type;
-			m_idx_types[typeid(TYPE)] = i_type;
-			return *i_type;
-		}
-
-		type_entry* get_type( const std::string name )
-		{
-			type_name_map::iterator it = m_name_types.find( name );
-			if ( it != m_name_types.end() ) 
-			{
-				return it->second;
-			}
-			return nullptr;
-		}
-
-		type_entry* get_type( const std::type_info& t )
-		{
-			type_info_map::iterator it = m_idx_types.find( std::type_index(t) );
-			if ( it != m_idx_types.end() ) 
-			{
-				return it->second;
-			}
-			return nullptr;
-		}
-	private:
-		struct compare_type_info {
-			bool operator ()(const std::type_info* a, const std::type_info* b) const {
-				return a->before(*b);
-			}
-		};
-
-		typedef std::unordered_map<std::string, type_entry*>     type_name_map;
-		typedef std::unordered_map<std::type_index, type_entry*> type_info_map;
-		type_name_map m_name_types;
-		type_info_map m_idx_types;
-	};
-    
-    template < typename TYPE >
-    type_entry& type_entry::base()
-    {
-        base_type = type_db->get_type( typeid(TYPE) );
-		return *this;
-    }
-    
-    template <int SIZE>
-    type_entry& type_entry::fields( type_field (&init_fields)[SIZE] )
-    {
-        for (int i = 0; i < SIZE; i++)
-        {
-            type_field f = init_fields[i];
-            f.type = type_db->get_type(*(f.type_inf));
-            f.type_name = f.type->name;
-            field_list.push_back(f);
-        }
-        return *this;
-    }
-
-}
-
-#endif
-
Index: unk/nv/uid.hh
===================================================================
--- /trunk/nv/uid.hh	(revision 318)
+++ 	(revision )
@@ -1,109 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-/**
- * @file uid.hh
- * @author Kornel Kisielewicz
- * @brief Implements a unique identifier class manager
- */
-
-#ifndef NV_UID_HH
-#define NV_UID_HH
-
-#include <nv/common.hh>
-#include <unordered_map>
-
-namespace nv
-{
-
-	class uid_store_raw
-	{
-	public:
-		
-		/**
-		 * Creates a new instance of the unique identifier store.
-		 */
-		uid_store_raw();
-
-		/**
-		 * Gets the object with the specified ID.
-		 *
-		 * @param auid The ID to fetch.
-		 * @returns The stored object for that ID.
-		 */
-		void* get( uid auid ) const;
-
-		/**
-		 * Removes the object with the specified ID.
-		 *
-		 * @param auid The ID to remove.
-		 * @returns True if the removal was successful, false if the ID didn't exist.
-		 */
-		bool remove( uid auid );
-
-		/**
-		 * Adds an object to the store assigned to the indicated ID.
-		 *
-		 * @param o The object to add to the store.
-		 * @param auid The ID to assign to the object.
-		 */
-		void insert( void* o, uid auid );
-
-		/**
-		 * Adds an object to the store and assigns it a new ID.
-		 *
-		 * @param o The object to add to the store.
-		 * @returns The ID the object was store under.
-		 */
-		uid insert( void* o );
-
-		/**
-		 * Gets the next available ID.
-		 *
-		 * @returns The next ID in the store.
-		 */
-		uid request_uid();
-
-		/**
-		 * Destroys the unique identifier store.
-		 */
-		~uid_store_raw();
-
-	protected:
-		typedef std::unordered_map< uid, void* > map;
-		map m_map; ///< The hash map everything is stored in.
-		uid m_current; ///< The last UID assigned.
-	};
-
-	template < typename T >
-	class uid_store
-	{
-	public:
-		T* get( uid auid ) const      { return static_cast<T*>( m_store.get( auid ) ); }
-		bool remove( uid auid )       { m_store.remove( auid ); }
-		void insert( T* o, uid auid ) { m_store.insert( o, auid ); }
-		uid insert( T* o )            { return m_store.insert( o ); }
-		uid request_uid()             { return m_store.request_uid(); }
-
-		/**
-		 * Retrieves an object and casts it to the specified type.
-		 *
-		 * @tparam T The type to cast to.
-		 * @param auid The ID the object is stored under.
-		 * @returns An object of the indicated type that was stored at the indicated ID.
-		 */
-		template< typename U >
-		U* get_as( uid auid ) const 
-		{
-			return dynamic_cast< U* >( get(auid) );
-		}
-	protected:
-		uid_store_raw m_store;
-	};
-	
-}
-
-#endif // NV_UID_HH
Index: /trunk/src/core/io_event.cc
===================================================================
--- /trunk/src/core/io_event.cc	(revision 319)
+++ /trunk/src/core/io_event.cc	(revision 319)
@@ -0,0 +1,139 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/core/io_event.hh"
+
+using namespace nv;
+
+const char* nv::get_key_name( key_code key )
+{
+	switch ( key )
+	{
+#	define NV_KEY( id, val ) case id : return #id;
+#		include <nv/detail/key_list.inc>
+#	undef NV_KEY
+	NV_RETURN_COVERED_DEFAULT( "KEY_UNKNOWN" );
+	};
+}
+
+const char* nv::get_mouse_name( mouse_code button )
+{
+	switch ( button )
+	{
+#	define NV_MOUSE( id, val ) case id : return #id;
+#		include <nv/detail/mouse_list.inc>
+#	undef NV_MOUSE
+	NV_RETURN_COVERED_DEFAULT( "MOUSE_UNKNOWN" );
+	};
+}
+
+const char* nv::get_io_event_name( io_event_code event )
+{
+	switch ( event )
+	{
+#	define NV_IO_EVENT( id ) case id : return #id;
+#		include <nv/detail/io_event_list.inc>
+#	undef NV_IO_EVENT
+	NV_RETURN_COVERED_DEFAULT( "EV_UNKNOWN" );
+	};
+}
+
+/************************************************************************
+void nv::register_io_types( type_database* db )
+{
+	type_enum key_enums[] = {
+#	define NV_KEY( id, val ) type_enum( #id, id ),
+#		include <nv/detail/key_list.inc>
+#	undef NV_KEY
+	};
+	db->create_type<key_code>("key_code").enums( key_enums );
+
+	type_enum mouse_enums[] = {
+#	define NV_MOUSE( id, val ) type_enum( #id, id ),
+#		include <nv/detail/mouse_list.inc>
+#	undef NV_MOUSE
+	};
+	db->create_type<mouse_code>("mouse_code").enums( mouse_enums );
+
+	type_enum io_event_enums[] = {
+#	define NV_IO_EVENT( id ) type_enum( #id, id ),
+#		include <nv/detail/io_event_list.inc>
+#	undef NV_IO_EVENT
+	};
+	db->create_type<io_event_code>("event_code").enums( io_event_enums );
+
+	type_field key_fields[] = {
+		type_field( "ascii",   &key_event::ascii ),
+		type_field( "code",    &key_event::code ),
+		type_field( "shift",   &key_event::shift ),
+		type_field( "control", &key_event::control ),
+		type_field( "alt",     &key_event::alt ),
+		type_field( "pressed", &key_event::pressed ),
+	};
+	db->create_type<key_event>("key_event").fields( key_fields );
+
+	type_field mouse_button_fields[] = {
+		type_field( "x",       &mouse_button_event::x ),
+		type_field( "y",       &mouse_button_event::y ),
+		type_field( "button",  &mouse_button_event::button ),
+		type_field( "pressed", &mouse_button_event::pressed ),
+		type_field( "code",    &mouse_button_event::code ),
+	};
+	db->create_type<mouse_button_event>("mouse_button_event").fields( mouse_button_fields );
+
+	type_field mouse_move_fields[] = {
+		type_field( "x",       &mouse_move_event::x ),
+		type_field( "y",       &mouse_move_event::y ),
+		type_field( "rx",      &mouse_move_event::rx ),
+		type_field( "ry",      &mouse_move_event::ry ),
+		type_field( "pressed", &mouse_move_event::pressed ),
+		type_field( "code",    &mouse_move_event::code ),
+	};
+	db->create_type<mouse_move_event>("mouse_move_event").fields( mouse_move_fields );
+
+	type_field mouse_wheel_fields[] = {
+		type_field( "x",       &mouse_wheel_event::x ),
+		type_field( "y",       &mouse_wheel_event::y ),
+	};
+	db->create_type<mouse_wheel_event>("mouse_wheel_event").fields( mouse_wheel_fields );
+
+	type_field joy_button_fields[] = {
+		type_field( "id",      &joy_button_event::id ),
+		type_field( "button",  &joy_button_event::button ),
+		type_field( "pressed", &joy_button_event::pressed ),
+	};
+	db->create_type<joy_button_event>("joy_button_event").fields( joy_button_fields );
+
+	type_field joy_axis_fields[] = {
+		type_field( "id",      &joy_axis_event::id ),
+		type_field( "axis",    &joy_axis_event::axis ),
+		type_field( "value",   &joy_axis_event::value ),
+	};
+	db->create_type<joy_axis_event>("joy_axis_event").fields( joy_axis_fields );
+
+	type_field joy_hat_fields[] = {
+		type_field( "id",      &joy_hat_event::id ),
+		type_field( "hat",     &joy_hat_event::hat ),
+		type_field( "value",   &joy_hat_event::value ),
+	};
+	db->create_type<joy_hat_event>("joy_hat_event").fields( joy_hat_fields );
+
+	type_field joy_ball_fields[] = {
+		type_field( "id",      &joy_ball_event::id ),
+		type_field( "ball",    &joy_ball_event::ball ),
+		type_field( "rx",      &joy_ball_event::rx ),
+		type_field( "ry",      &joy_ball_event::ry ),
+	};
+	db->create_type<joy_ball_event>("joy_ball_event").fields( joy_ball_fields );
+
+	type_field system_fields[] = {
+		type_field( "sys_type", &system_event::sys_type ),
+		type_field( "param1",   &system_event::param1 ),
+		type_field( "param2",   &system_event::param2 ),
+	};
+	db->create_type<system_event>("system_event").fields( system_fields );
+}
+************************************************************************/
Index: /trunk/src/core/library.cc
===================================================================
--- /trunk/src/core/library.cc	(revision 319)
+++ /trunk/src/core/library.cc	(revision 319)
@@ -0,0 +1,147 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+#include "nv/core/common.hh"
+#include "nv/core/library.hh"
+
+#if NV_PLATFORM == NV_WINDOWS
+#   define WIN32_LEAN_AND_MEAN
+#   include <windows.h>
+#   define NV_LIB_EXT ".dll"
+#   define NV_LIB_HANDLE HMODULE
+#   define NV_LIB_OPEN( name ) LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
+#   define NV_LIB_GET( handle, name ) GetProcAddress( handle, name )
+#   define NV_LIB_CLOSE( name ) !FreeLibrary( name )
+#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
+#   include <dlfcn.h>
+#   define NV_LIB_EXT ".so"
+#   define NV_LIB_HANDLE void*
+#   define NV_LIB_OPEN( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL)
+#   define NV_LIB_GET( handle, name ) dlsym( handle, name )
+#   define NV_LIB_CLOSE( name ) dlclose( name )
+#elif NV_PLATFORM == NV_APPLE
+#   include "macUtils.h"
+#   include <dlfcn.h>
+#   define NV_LIB_EXT ".dylib"
+#   define NV_LIB_HANDLE CFBundleRef
+#   define NV_LIB_OPEN( name ) mac_loadExeBundle( name )
+#   define NV_LIB_GET( handle, name ) mac_getBundleSym( handle, name )
+#   define NV_LIB_CLOSE( name ) mac_unloadExeBundle( name )
+#endif
+
+#include "nv/core/logging.hh"
+
+using namespace nv;
+
+library::library() 
+    : m_handle( nullptr ), m_name()
+{
+}
+
+void library::open( const string& name )
+{
+	m_name = name;
+	if ( !open() )
+	{
+		m_handle = nullptr;
+		NV_THROW( library_error, "Can't load library!", name );
+	}
+}
+
+bool nv::library::try_open( const string& name )
+{
+	m_name = name;
+	if ( !open() )
+	{
+		m_handle = nullptr;
+		return false;
+	}
+	return true;
+}
+
+const string& library::get_name() const
+{
+    return m_name;
+}
+
+bool library::open( )
+{
+    if ( m_handle != NULL )
+    {
+        return true;
+    }
+    NV_LOG( LOG_NOTICE, "library : loading '" + m_name + "'..." );
+
+    string name = m_name;
+    string ext  = NV_LIB_EXT;
+    size_t ext_len   = ext.length();
+
+    if ( name.length() < ext_len || name.substr( name.length() - ext_len, ext_len ) != ext ) 
+    {
+        name += ext;
+    }
+
+    m_handle = (void*)NV_LIB_OPEN( name.c_str() );
+
+    if ( m_handle == NULL )
+    {
+		NV_LOG( LOG_NOTICE, "library : '" + name + "' failed to open." );
+		return false;
+    }
+    NV_LOG( LOG_NOTICE, "library : '" + name + "' loaded." );
+	return true;
+}
+
+void* library::get( const string& symbol )
+{
+	void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
+    if ( !result )
+    {
+        NV_THROW( library_error, "Can't find symbol " + symbol + "!", m_name );
+    }
+	return result;
+}
+
+void* nv::library::try_get( const string& symbol )
+{
+	return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
+}
+
+bool library::is_open() const
+{
+	return m_handle != nullptr;
+}
+
+void library::close()
+{
+    if ( NV_LIB_CLOSE( (NV_LIB_HANDLE)m_handle ) )
+    {
+        NV_LOG( LOG_ERROR, "library : can't close library '" + m_name + "'!" );
+    }
+    m_handle = NULL;
+}
+
+library::~library()
+{
+    if ( m_handle != NULL )
+    {
+        close();
+    }
+}
+
+string library::get_error()
+{
+#if NV_PLATFORM == NV_WINDOWS
+    // We do hate WinAPI for code like this, don't we?
+    LPTSTR buffer = NULL;
+    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+        NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );
+    string msg( (char*)buffer );
+    LocalFree( buffer );
+    return msg;
+#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
+    return string(dlerror());
+#else
+    return string("");
+#endif
+}
Index: /trunk/src/core/logger.cc
===================================================================
--- /trunk/src/core/logger.cc	(revision 319)
+++ /trunk/src/core/logger.cc	(revision 319)
@@ -0,0 +1,262 @@
+// Copyright (C) 2011-2014 ChaosForge Ltd
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/core/logger.hh"
+
+#include "nv/core/common.hh"
+#include <iostream>
+#include <utility>
+#include <algorithm>
+#include <fstream>
+#include <ctime>
+#include <cstdio>
+#include "nv/core/exception.hh"
+#if NV_PLATFORM == NV_WINDOWS
+#define WIN32_LEAN_AND_MEAN
+#include <Windows.h>
+#endif
+
+using namespace nv;
+
+// log level names
+static const char *log_level_names[] =
+{
+	"NONE",
+	"FATAL",
+	"CRITICAL",
+	"ERROR",
+	"WARNING",
+	"NOTICE",
+	"INFO",
+	"INFO",
+	"DEBUG",
+	"DEBUG2",
+	"TRACE"
+};
+
+// log level names
+static const char *log_level_names_pad[] =
+{
+	"NONE    ",
+	"FATAL   ",
+	"CRITICAL",
+	"ERROR   ",
+	"WARNING ",
+	"NOTICE  ",
+	"INFO    ",
+	"INFO    ",
+	"DEBUG   ",
+	"DEBUG2  ",
+	"TRACE   "
+};
+
+// helper macro to access log_level_names
+#define NV_LOG_LEVEL_NAME(level) (log_level_names[ (level) / 10 ])
+#define NV_LOG_LEVEL_NAME_PAD(level) (log_level_names_pad[ (level) / 10 ])
+
+#if NV_PLATFORM == NV_WINDOWS 
+static unsigned short log_color[] =
+{
+	FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
+	FOREGROUND_RED | FOREGROUND_INTENSITY,
+	FOREGROUND_RED | FOREGROUND_INTENSITY,
+	FOREGROUND_RED,
+	FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
+	FOREGROUND_GREEN | FOREGROUND_INTENSITY,
+	FOREGROUND_GREEN,
+	FOREGROUND_GREEN,
+	FOREGROUND_INTENSITY,
+	FOREGROUND_INTENSITY,
+	FOREGROUND_INTENSITY
+};
+#else
+static const char *log_color[] =
+{
+	"\33[37;1m",
+	"\33[31;1m",
+	"\33[31;1m",
+	"\33[31m",
+	"\33[33;1m",
+	"\33[32;1m",
+	"\33[32m",
+	"\33[32m",
+	"\33[30;1m",
+	"\33[30;1m",
+	"\33[30;1m"
+};
+#endif
+
+// log function
+void logger::log( log_level level, const std::string& message )
+{
+	// get the iterator to the beginning of the log_sink list
+	log_sink_list::reverse_iterator it = m_log_sinks.rbegin();
+
+	// iterate
+	while ( it != m_log_sinks.rend() )
+	{
+		// if we have a log sink with high enough level...
+		if ( it->first >= level )
+		{
+			// log and iterate
+			it->second->log( level, message );
+		}
+		else 
+		{
+			// otherwise return, the list is sorted by log level
+			return;
+		}
+		++it;
+	}
+}
+
+// add a new sink
+void logger::add_sink( log_sink* sink, int level )
+{
+	// add a sink
+	m_log_sinks.push_back( std::make_pair( log_level(level), sink ) );
+	// and sort the list (default sort of pairs is by first element)
+	m_log_sinks.sort();
+}
+
+// remove existing sink
+bool logger::remove_sink( log_sink* sink )
+{
+	// get the iterator to the beginning of the log_sink list
+	log_sink_list::iterator it = m_log_sinks.begin();
+
+	// iterate
+	while ( it != m_log_sinks.end() )
+	{
+		// found?
+		if ( it->second == sink ) 
+		{
+			// erase and return true to report success
+			m_log_sinks.erase(it);
+			return true;
+		}
+		++it;
+	}
+
+	// not found, return false
+	return false;
+}
+
+// destructor
+logger::~logger()
+{
+	// while we have sinks
+	while ( !m_log_sinks.empty() )
+	{
+		// delete the last one
+		delete m_log_sinks.back().second;
+		// and pop it
+		m_log_sinks.pop_back();
+	}
+}
+
+
+// console logging
+void log_console_sink::log( log_level level, const std::string& message )
+{
+	if (m_color) 
+	{
+#if NV_PLATFORM == NV_WINDOWS 
+		SetConsoleTextAttribute( m_handle, FOREGROUND_INTENSITY );
+		std::cout << timestamp() << " [";
+		SetConsoleTextAttribute( m_handle, log_color[ (level) / 10 ] );
+		std::cout << NV_LOG_LEVEL_NAME_PAD(level);
+		SetConsoleTextAttribute( m_handle, FOREGROUND_INTENSITY );
+		std::cout << "] ";
+		SetConsoleTextAttribute( m_handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
+		std::cout << message << std::endl;
+#else
+		std::cout << "\33[30;1m" << timestamp() << " [" << log_color[ (level) / 10 ] << NV_LOG_LEVEL_NAME_PAD(level) << "\33[30;1m] \33[37;1m" << message << std::endl;
+#endif
+	}
+	else
+	{
+	std::cout << timestamp() << " [" << NV_LOG_LEVEL_NAME_PAD(level) << "] " << message << std::endl;
+	}
+}
+
+// stream logging
+void log_stream_sink::log( log_level level, const std::string& message )
+{
+	// if flushing is enabled
+	if ( m_flush )
+	{
+		// write and flush using std::endl
+		*m_stream << timestamp() << " [" << NV_LOG_LEVEL_NAME(level) << "] " << message << std::endl;
+	}
+	else
+	{
+		// write and end with "\n" (no flush)
+		*m_stream << timestamp() << " [" << NV_LOG_LEVEL_NAME(level) << "] " << message << "\n";
+	}
+}
+
+// file logging
+log_file_sink::log_file_sink( const std::string file_name, bool flush_always /*= true */ )
+	: log_stream_sink( nullptr, flush_always )
+{
+	// create the stream manually
+	std::ofstream* fstream = new std::ofstream( file_name );
+
+	// check if it's open
+	if ( !fstream->is_open() )
+	{
+		// throw if not open
+		NV_THROW( runtime_error, "Could not open file \""+file_name+"\" for logging!" );
+	}
+
+	m_stream = fstream;
+}
+
+// file logger destructor
+log_file_sink::~log_file_sink()
+{
+	// close the file
+	dynamic_cast< std::ofstream* >(m_stream)->close();
+	// dispose of the stream
+	delete m_stream;
+}
+
+nv::log_console_sink::log_console_sink( bool coloring )
+	: m_color( coloring )
+{
+#if NV_PLATFORM == NV_WINDOWS 
+	m_handle = GetStdHandle( STD_OUTPUT_HANDLE );
+#else
+  NV_UNUSED( m_handle );
+#endif
+}
+
+const char* nv::log_sink::timestamp() const
+{
+	std::clock_t time = std::clock();
+	unsigned int secs = (unsigned int)(time / CLOCKS_PER_SEC);
+	unsigned int mm   = (unsigned int)(time*100 / CLOCKS_PER_SEC) % 100;
+	unsigned int h    = (unsigned int)(secs / (60*60));
+	unsigned int m    = (unsigned int)(secs / 60) % 60;
+	unsigned int s    = secs % 60;
+	static char buffer[128];
+#if NV_PLATFORM == NV_WINDOWS 
+	sprintf_s( buffer, 128, "%02d:%02d:%02d.%02d", h, m, s, mm );
+#else
+	sprintf( buffer, "%02d:%02d:%02d.%02d", h, m, s, mm );
+#endif
+	buffer[11] = '\0';
+	return buffer;
+}
+
+const char* nv::log_sink::level_name( log_level level ) const
+{
+	return NV_LOG_LEVEL_NAME( level );
+}
+
+const char* nv::log_sink::padded_level_name( log_level level ) const
+{
+	return NV_LOG_LEVEL_NAME_PAD( level );
+}
Index: /trunk/src/core/profiler.cc
===================================================================
--- /trunk/src/core/profiler.cc	(revision 319)
+++ /trunk/src/core/profiler.cc	(revision 319)
@@ -0,0 +1,133 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/core/profiler.hh"
+
+#include <iomanip>
+#include <ios>
+#include "nv/core/time.hh"
+
+using namespace nv;
+
+
+profiler::profiler()
+{
+	m_root = new node( "root", nullptr );
+	m_root->start();
+	m_current = m_root;
+}
+
+profiler::~profiler()
+{
+	delete m_root;
+}
+
+void profiler::start_profile( const char* tag )
+{
+	if ( tag != m_current->m_tag )
+	{
+		m_current = m_current->request_child( tag );
+	}
+	m_current->start();
+}
+
+void profiler::stop_profile()
+{
+	if ( m_current->stop() )
+	{
+		m_current = m_current->get_parent();
+	}
+}
+
+profiler::node::node( const char* tag, node* parent ) 
+	: m_tag( tag )
+	, m_parent( parent )
+	, m_recusion( 0 )
+	, m_calls( 0 )
+	, m_start_time_us( 0 )
+	, m_total_time_us( 0 )
+{
+
+}
+
+profiler::node* profiler::node::request_child( const char* tag )
+{
+	auto it = m_children.find( tag );
+	if ( it != m_children.end() ) 
+		return it->second;
+	else
+	{
+		node* result = new node( tag, this );
+		m_children[ tag ] = result;
+		return result;
+	}
+}
+
+void profiler::node::start()
+{
+	m_calls++;
+	m_recusion++;
+	if ( m_recusion == 1 )
+	{
+		m_start_time_us = get_system_us();
+	}
+}
+
+bool profiler::node::stop()
+{
+	m_recusion--;
+	if ( m_recusion == 0 )
+	{
+		uint64 stop_time_us = get_system_us();
+		uint64 elapsed_us   = stop_time_us - m_start_time_us;
+		m_total_time_us     += elapsed_us;
+		return true;
+	}
+	return false;
+}
+
+
+nv::profiler::node::~node()
+{
+	for ( const auto& pair : m_children )
+	{
+		delete pair.second;
+	}
+}
+
+
+void profiler::log_report()
+{
+	m_root->stop();
+	NV_LOG( LOG_INFO, "-- PROFILER REPORT -----------------------------------------" );
+	NV_LOG( LOG_INFO, std::left << std::setw(24) << "TAG" 
+		<< std::setw(7) << "%PARNT" 
+		<< std::setw(7) << "CALLS" 
+		<< std::setw(10) << "TOTAL(ms)" 
+		<< std::setw(10) << "AVG(ms)" );
+	log_node_children( "", m_root );
+	NV_LOG( LOG_INFO, "-- PROFILER REPORT END -------------------------------------" );
+	m_root->start();
+}
+
+void profiler::log_node_children( const std::string& ind, const node* n )
+{
+	for ( const auto& pair : n->m_children )
+	{
+		const node* c = pair.second;
+		if ( c->m_calls > 0 )
+		{
+			NV_LOG( LOG_INFO, std::left << std::setw(24) << ind + c->m_tag 
+				<< std::setw(7) << std::setprecision(2) << std::fixed << ( (double)c->m_total_time_us / (double)c->m_parent->m_total_time_us ) * 100.0
+				<< std::setw(7) << c->m_calls 
+				<< std::setw(10) << std::setprecision(2) << std::fixed << c->m_total_time_us / 1000.f
+				<< std::setw(10) << std::setprecision(2) << std::fixed << ( (double)c->m_total_time_us / (double)c->m_calls ) / 1000.f
+				);
+			if ( c->m_children.size() > 0 )
+			{
+				log_node_children( ind + "-", c );
+			}
+		}
+	}
+}
Index: /trunk/src/core/random.cc
===================================================================
--- /trunk/src/core/random.cc	(revision 319)
+++ /trunk/src/core/random.cc	(revision 319)
@@ -0,0 +1,276 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/core/random.hh"
+#include "nv/core/time.hh"
+
+using namespace nv;
+
+random::random( random::seed_type seed /*= 0 */ )
+	: rng( seed == 0 ? randomized_seed() : seed )
+{
+	
+}
+
+random::seed_type random::randomize()
+{
+	seed_type seed = randomized_seed();
+	rng.seed( seed );
+	return seed;
+}
+
+void random::set_seed( random::seed_type seed /*= 0 */ )
+{
+	rng.seed( seed == 0 ? randomized_seed() : seed );
+}
+
+nv::random& random::get()
+{
+	static random default_rng;
+	return default_rng;
+}
+
+random::result_type random::rand()
+{
+	return rng();
+}
+
+sint32 random::srand( sint32 val )
+{
+	std::uniform_int_distribution<sint32> dist( 0, val - 1 );
+	return dist( rng );
+}
+
+uint32 random::urand( uint32 val )
+{
+	std::uniform_int_distribution<uint32> dist( 0, val - 1 );
+	return dist( rng );
+}
+
+f32 random::frand( f32 val )
+{
+	std::uniform_real_distribution<f32> dist( 0, val );
+	return dist( rng );
+}
+
+sint32 random::srange( sint32 min, sint32 max )
+{
+	std::uniform_int_distribution<sint32> dist( min, max );
+	return dist( rng );
+}
+
+uint32 random::urange( uint32 min, uint32 max )
+{
+	std::uniform_int_distribution<uint32> dist( min, max );
+	return dist( rng );
+}
+
+f32 random::frange( f32 min, f32 max )
+{
+	std::uniform_real_distribution<f32> dist( min, max );
+	return dist( rng );
+}
+
+uint32 random::dice( uint32 count, uint32 sides )
+{
+	std::uniform_int_distribution<uint32> dist( 1, sides );
+	uint32 result = 0;
+	while (count-- > 0)
+	{
+		result += dist( rng );
+	};
+	return result;
+}
+
+random::seed_type random::randomized_seed()
+{
+	return narrow_cast< seed_type >( get_ticks() );
+}
+
+nv::vec2 nv::random::precise_unit_vec2()
+{
+	std::uniform_real_distribution<f32> dist( 0, glm::pi<float>() * 2.f );
+	float angle = dist( rng );
+	return vec2( glm::cos( angle ), glm::sin( angle ) );
+}
+
+nv::vec3 nv::random::precise_unit_vec3()
+{
+	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
+	std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() );
+	float cos_theta = dist11( rng );
+	float sin_theta = glm::sqrt( 1.0f - cos_theta * cos_theta );
+	float phi       = dist02pi( rng );
+	return vec3( 
+		sin_theta * glm::sin(phi),
+		sin_theta * glm::cos(phi),
+		cos_theta
+		);
+}
+
+nv::vec2 nv::random::fast_disk_point()
+{
+	std::uniform_real_distribution<f32> dist( 0.0f, 1.0f );
+	float r1 = dist( rng );
+	float r2 = dist( rng );
+	if ( r1 > r2 ) std::swap( r1, r2 );
+	float rf = 2*glm::pi<float>()*(r1/r2);
+	return vec2( r2*glm::cos( rf ), r2*glm::sin( rf ) );
+}
+
+nv::vec2 nv::random::precise_disk_point()
+{
+	std::uniform_real_distribution<f32> unit( 0.0f, 1.0f );
+	std::uniform_real_distribution<f32> angle( 0.0f, glm::pi<float>() );
+	float r = glm::sqrt( unit( rng ) );
+	float rangle = angle( rng );
+	return vec2( r*glm::cos( rangle ), r*glm::sin( rangle ) );
+}
+
+nv::vec3 nv::random::fast_sphere_point()
+{
+	std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f );
+	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
+	std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() );
+	float rad     = dist01( rng );
+	float pi      = glm::pi<float>();
+	float phi     = glm::asin( dist11( rng ) ) + pi*.5f;
+	float theta   = dist02pi( rng );
+	float sin_phi = glm::sin( phi );
+	return vec3( 
+		rad * glm::cos(theta) * sin_phi,
+		rad * glm::sin(theta) * sin_phi,
+		rad * glm::cos(phi)
+	);
+}
+
+nv::vec3 nv::random::precise_sphere_point()
+{
+	std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f );
+	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
+	std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() );
+	float radius = std::pow( dist01( rng ), 1.f/3.f );
+	float cos_theta = dist11( rng );
+	float sin_theta = glm::sqrt( 1.0f - cos_theta * cos_theta );
+	float phi       = dist02pi( rng );
+	return vec3( 
+		radius * sin_theta * glm::sin(phi),
+		radius * sin_theta * glm::cos(phi),
+		radius * cos_theta
+		);
+}
+
+nv::vec2 nv::random::precise_ellipse_point( const vec2& radii )
+{
+	std::uniform_real_distribution<f32> distx( -radii.x, radii.x );
+	std::uniform_real_distribution<f32> disty( -radii.y, radii.y );
+	vec2 inv_radii  = 1.f / radii;
+	vec2 inv_radii2 = inv_radii * inv_radii;
+	for ( uint32 i = 0; i < 12; ++i )
+	{
+		float x = distx( rng );
+		float y = disty( rng );
+		if ( x * x * inv_radii2.x + y * y * inv_radii2.y <= 1.f )
+		{
+			return vec2( x, y );
+		}
+	}
+	return fast_disk_point() * radii;
+}
+
+nv::vec3 nv::random::precise_ellipsoid_point( const vec3& radii )
+{
+	std::uniform_real_distribution<f32> distx( -radii.x, radii.x );
+	std::uniform_real_distribution<f32> disty( -radii.y, radii.y );
+	std::uniform_real_distribution<f32> distz( -radii.z, radii.z );
+	vec3 inv_radii  = 1.f / radii;
+	vec3 inv_radii2 = inv_radii * inv_radii;
+	for ( uint32 i = 0; i < 12; ++i )
+	{
+		float x = distx( rng );
+		float y = disty( rng );
+		float z = distz( rng );
+		if ( x * x * inv_radii2.x + y * y * inv_radii2.y + z * z * inv_radii2.z <= 1.f )
+		{
+			return vec3( x, y, z );
+		}
+	}
+	return fast_sphere_point() * radii;
+}
+
+nv::vec2 nv::random::fast_hollow_disk_point( float iradius, float oradius )
+{
+	float idist2 = iradius * iradius;
+	float odist2 = oradius * oradius;
+	float rdist  = glm::sqrt( std::uniform_real_distribution<f32>( idist2, odist2 )( rng ) );
+	return rdist * precise_unit_vec2();
+}
+
+nv::vec2 nv::random::precise_hollow_disk_point( float iradius, float oradius )
+{
+	return fast_hollow_disk_point( iradius, oradius );
+}
+
+nv::vec3 nv::random::fast_hollow_sphere_point( float iradius, float oradius )
+{
+	float idist3 = iradius * iradius * iradius;
+	float odist3 = oradius * oradius * oradius;
+	float rdist  = std::pow( std::uniform_real_distribution<f32>( idist3, odist3 )( rng ), 1.f/3.f );
+	return rdist * precise_unit_vec3();
+}
+
+nv::vec3 nv::random::precise_hollow_sphere_point( float iradius, float oradius )
+{
+	return fast_hollow_sphere_point( iradius, oradius );
+}
+
+
+nv::vec2 nv::random::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
+{
+	vec2 iradii2    = iradii * iradii;
+	vec2 opoint     = ellipse_edge( oradii );
+	vec2 opoint2    = opoint * opoint;
+	vec2 odir       = glm::normalize( opoint );
+	float odist2    = opoint2.x + opoint2.y;
+
+	float low    = iradii2.y * opoint2.x + iradii2.x * opoint2.y;
+	float idist2 = ((iradii2.x * iradii2.y) / low ) * odist2;
+
+	float rdist     = glm::sqrt( std::uniform_real_distribution<f32>( idist2, odist2 )( rng ) );
+	return odir * rdist;	
+}
+
+nv::vec2 nv::random::precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
+{
+	return fast_hollow_ellipse_point( iradii, oradii );
+}
+
+nv::vec3 nv::random::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
+{
+	vec3 iradii2    = iradii * iradii;
+	vec3 opoint     = ellipsoid_edge( oradii );
+	vec3 opoint2    = opoint * opoint;
+	vec3 odir       = glm::normalize( opoint );
+	float odist2    = opoint2.x + opoint2.y + opoint2.z;
+
+	float low    = 
+		iradii2.y * iradii2.z * opoint2.x + 
+		iradii2.x * iradii2.z * opoint2.y +
+		iradii2.x * iradii2.y * opoint2.z;
+	float idist2 = ((iradii2.x * iradii2.y * iradii2.z) / low ) * odist2;
+
+	float odist3 = odist2 * glm::sqrt( odist2 );
+	float idist3 = idist2 * glm::sqrt( idist2 );
+
+	float rdist     = std::pow( std::uniform_real_distribution<f32>( idist3, odist3 )( rng ), 1.f/3.f );
+	return odir * rdist;	
+}
+
+nv::vec3 nv::random::precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
+{
+	return fast_hollow_ellipsoid_point( iradii, oradii );
+}
+
Index: /trunk/src/core/time.cc
===================================================================
--- /trunk/src/core/time.cc	(revision 319)
+++ /trunk/src/core/time.cc	(revision 319)
@@ -0,0 +1,100 @@
+// Copyright (C) 2011-2014 ChaosForge Ltd
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/core/time.hh"
+
+#include "nv/core/logging.hh"
+
+#if NV_COMPILER == NV_MSVC
+#define WIN32_LEAN_AND_MEAN 
+#include <windows.h>
+#include <intrin.h>
+#pragma intrinsic(__rdtsc)
+#else
+#include <unistd.h>
+#include <sys/time.h>
+#endif
+
+#include <ctime>
+
+struct timer_impl
+{
+	timer_impl()
+	{
+		clock_zero = clock();
+#if NV_COMPILER == NV_MSVC
+		QueryPerformanceFrequency(&frequency);
+		QueryPerformanceCounter(&query_zero);
+#else
+		gettimeofday(&timeval_zero, NULL);
+#endif
+	}
+	clock_t clock_zero;
+#if NV_COMPILER == NV_MSVC
+	LARGE_INTEGER query_zero;
+	LARGE_INTEGER frequency;
+#else
+	struct timeval timeval_zero;
+#endif
+};
+
+static timer_impl zero_timer;
+
+nv::uint64 nv::get_ticks()
+{
+#if NV_COMPILER == NV_MSVC
+	return __rdtsc();
+#else
+	register long long ticks asm("eax") = 0;
+	asm volatile (".byte 15, 49" : : : "eax", "edx");
+	return static_cast<nv::uint64>( ticks );
+#endif
+}
+
+void nv::sleep( uint32 ms )
+{
+#if NV_COMPILER == NV_MSVC
+	Sleep( ms );
+#else
+	usleep( ms * 1000 );
+#endif
+}
+
+nv::uint32 nv::get_cpu_ms()
+{
+	return (uint32)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000.0 ) ) ;
+}
+
+nv::uint64 nv::get_cpu_us()
+{
+	return (uint64)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000000.0 ) ) ;
+}
+
+nv::uint32 nv::get_system_ms()
+{
+#if NV_COMPILER == NV_MSVC
+	LARGE_INTEGER now;
+	QueryPerformanceCounter(&now);
+	LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart;
+	return (uint32) (1000.0 * result / (double) zero_timer.frequency.QuadPart);
+#else
+	struct timeval now;
+	gettimeofday(&now, NULL);
+	return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000+(now.tv_usec-zero_timer.timeval_zero.tv_usec)/1000 );
+#endif
+}
+
+nv::uint64 nv::get_system_us()
+{
+#if NV_COMPILER == NV_MSVC
+	LARGE_INTEGER now;
+	QueryPerformanceCounter(&now);
+	LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart;
+	return (uint64) (1000000.0 * result / (double) zero_timer.frequency.QuadPart);
+#else
+	struct timeval now;
+	gettimeofday(&now, NULL);
+	return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000000+(now.tv_usec - zero_timer.timeval_zero.tv_usec) );
+#endif
+}
Index: /trunk/src/core/uid.cc
===================================================================
--- /trunk/src/core/uid.cc	(revision 319)
+++ /trunk/src/core/uid.cc	(revision 319)
@@ -0,0 +1,52 @@
+// Copyright (C) 2012-2014 ChaosForge Ltd
+// http://chaosforge.org/
+//
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
+#include "nv/core/uid.hh"
+
+using namespace nv;
+
+uid_store_raw::uid_store_raw()
+	: m_map(), m_current(0)
+{
+	
+}
+
+void* uid_store_raw::get( uid auid ) const
+{
+	map::const_iterator i = m_map.find( auid );
+	if ( i != m_map.end() )
+	{
+		return i->second;
+	}
+	return nullptr;
+}
+
+bool uid_store_raw::remove( uid auid )
+{
+	return m_map.erase( auid ) != 0;
+}
+
+void uid_store_raw::insert( void* o, uid auid )
+{
+	m_map[ auid ] = o;
+}
+
+uid uid_store_raw::insert( void* o )
+{
+	uid u = request_uid();
+	m_map[ u ] = o;
+	return u;
+}
+
+uid uid_store_raw::request_uid()
+{
+	return ++m_current;
+}
+
+uid_store_raw::~uid_store_raw()
+{
+	// no-op
+}
Index: /trunk/src/curses/curses_terminal.cc
===================================================================
--- /trunk/src/curses/curses_terminal.cc	(revision 318)
+++ /trunk/src/curses/curses_terminal.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2013-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,5 +7,5 @@
 #include "nv/curses/curses_terminal.hh"
 
-#include "nv/time.hh"
+#include "nv/core/time.hh"
 #include "nv/lib/curses.hh"
 
Index: /trunk/src/engine/program_manager.cc
===================================================================
--- /trunk/src/engine/program_manager.cc	(revision 318)
+++ /trunk/src/engine/program_manager.cc	(revision 319)
@@ -6,5 +6,5 @@
 
 #include "nv/engine/program_manager.hh"
-#include "nv/range.hh"
+#include "nv/core/range.hh"
 #include "nv/lua/lua_nova.hh"
 
Index: /trunk/src/engine/resource_system.cc
===================================================================
--- /trunk/src/engine/resource_system.cc	(revision 318)
+++ /trunk/src/engine/resource_system.cc	(revision 319)
@@ -6,5 +6,5 @@
 
 #include "nv/engine/resource_system.hh"
-#include "nv/range.hh"
+#include "nv/core/range.hh"
 #include "nv/lua/lua_nova.hh"
 
@@ -38,15 +38,15 @@
 }
 
-nv::resource_type_id nv::resource_system::register_resource_type( const string& name, resource_manager_base* manager )
+nv::resource_type_id nv::resource_system::register_resource_type( const string& /*name*/, resource_manager_base* /*manager*/ )
 {
 	return 0;
 }
 
-nv::resource_type_id nv::resource_system::get_resource_type_id( const string& name ) const
+nv::resource_type_id nv::resource_system::get_resource_type_id( const string& /*name*/ ) const
 {
 	return 0;
 }
 
-void nv::resource_system::initialize( lua::state* a_lua_state )
+void nv::resource_system::initialize( lua::state* /*a_lua_state*/ )
 {
 
Index: /trunk/src/fmod/fmod_audio.cc
===================================================================
--- /trunk/src/fmod/fmod_audio.cc	(revision 318)
+++ /trunk/src/fmod/fmod_audio.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 
 #include "nv/lib/fmod.hh"
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 
 using namespace nv;
Index: /trunk/src/formats/md2_loader.cc
===================================================================
--- /trunk/src/formats/md2_loader.cc	(revision 318)
+++ /trunk/src/formats/md2_loader.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 
 #include <glm/gtc/constants.hpp>
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 #include <cstring>
 
Index: /trunk/src/formats/md3_loader.cc
===================================================================
--- /trunk/src/formats/md3_loader.cc	(revision 318)
+++ /trunk/src/formats/md3_loader.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 
 #include <glm/gtc/constants.hpp>
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 #include <cstring>
 
Index: /trunk/src/formats/md5_loader.cc
===================================================================
--- /trunk/src/formats/md5_loader.cc	(revision 318)
+++ /trunk/src/formats/md5_loader.cc	(revision 319)
@@ -1,5 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
@@ -8,5 +6,5 @@
 
 #include <glm/gtc/constants.hpp>
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 #include "nv/io/std_stream.hh"
 #include <cstring>
Index: /trunk/src/formats/nmd_loader.cc
===================================================================
--- /trunk/src/formats/nmd_loader.cc	(revision 318)
+++ /trunk/src/formats/nmd_loader.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,5 +7,5 @@
 #include "nv/formats/nmd_loader.hh"
 #include "nv/io/std_stream.hh"
-#include "nv/string.hh"
+#include "nv/core/string.hh"
 
 using namespace nv;
Index: /trunk/src/formats/obj_loader.cc
===================================================================
--- /trunk/src/formats/obj_loader.cc	(revision 318)
+++ /trunk/src/formats/obj_loader.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/gfx/debug_draw.cc
===================================================================
--- /trunk/src/gfx/debug_draw.cc	(revision 318)
+++ /trunk/src/gfx/debug_draw.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2014 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/gfx/image.cc
===================================================================
--- /trunk/src/gfx/image.cc	(revision 318)
+++ /trunk/src/gfx/image.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2011 Kornel Kisielewicz
+// Copyright (C) 2011-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
Index: /trunk/src/gfx/keyframed_mesh.cc
===================================================================
--- /trunk/src/gfx/keyframed_mesh.cc	(revision 318)
+++ /trunk/src/gfx/keyframed_mesh.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2011 Kornel Kisielewicz
+// Copyright (C) 2011-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
@@ -11,5 +11,5 @@
 
 
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 
 using namespace nv;
Index: /trunk/src/gfx/particle_engine.cc
===================================================================
--- /trunk/src/gfx/particle_engine.cc	(revision 318)
+++ /trunk/src/gfx/particle_engine.cc	(revision 319)
@@ -1,8 +1,12 @@
+// Copyright (C) 2014 ChaosForge Ltd
+// This file is part of NV Libraries.
+// For conditions of distribution and use, see copyright notice in nv.hh
+
 #include "nv/gfx/particle_engine.hh"
 
 #include <nv/interface/device.hh>
-#include <nv/random.hh>
+#include <nv/core/random.hh>
 #include <nv/lua/lua_glm.hh>
-#include <nv/logging.hh>
+#include <nv/core/logging.hh>
 #include <cmath>
 
Index: /trunk/src/gfx/skeletal_mesh.cc
===================================================================
--- /trunk/src/gfx/skeletal_mesh.cc	(revision 318)
+++ /trunk/src/gfx/skeletal_mesh.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2011 Kornel Kisielewicz
+// Copyright (C) 2011-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
Index: /trunk/src/gfx/texture_atlas.cc
===================================================================
--- /trunk/src/gfx/texture_atlas.cc	(revision 318)
+++ /trunk/src/gfx/texture_atlas.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,5 +7,5 @@
 #include "nv/gfx/texture_atlas.hh"
 
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 #include <iostream>
 
Index: /trunk/src/gfx/texture_font.cc
===================================================================
--- /trunk/src/gfx/texture_font.cc	(revision 318)
+++ /trunk/src/gfx/texture_font.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/gl/gl_context.cc
===================================================================
--- /trunk/src/gl/gl_context.cc	(revision 318)
+++ /trunk/src/gl/gl_context.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
Index: /trunk/src/gl/gl_device.cc
===================================================================
--- /trunk/src/gl/gl_device.cc	(revision 318)
+++ /trunk/src/gl/gl_device.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
@@ -6,5 +6,5 @@
 
 #include "nv/gl/gl_window.hh"
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 #include "nv/lib/sdl.hh"
 #include "nv/lib/sdl_image.hh"
Index: /trunk/src/gl/gl_enum.cc
===================================================================
--- /trunk/src/gl/gl_enum.cc	(revision 318)
+++ /trunk/src/gl/gl_enum.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
Index: /trunk/src/gl/gl_window.cc
===================================================================
--- /trunk/src/gl/gl_window.cc	(revision 318)
+++ /trunk/src/gl/gl_window.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
@@ -5,5 +5,5 @@
 #include "nv/gl/gl_window.hh"
 
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 #include "nv/lib/gl.hh"
 #include "nv/lib/sdl.hh"
Index: /trunk/src/gui/gui_environment.cc
===================================================================
--- /trunk/src/gui/gui_environment.cc	(revision 318)
+++ /trunk/src/gui/gui_environment.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/gui/gui_renderer.cc
===================================================================
--- /trunk/src/gui/gui_renderer.cc	(revision 318)
+++ /trunk/src/gui/gui_renderer.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/gui/gui_style.cc
===================================================================
--- /trunk/src/gui/gui_style.cc	(revision 318)
+++ /trunk/src/gui/gui_style.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/io/c_file_system.cc
===================================================================
--- /trunk/src/io/c_file_system.cc	(revision 318)
+++ /trunk/src/io/c_file_system.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
Index: /trunk/src/io/c_stream.cc
===================================================================
--- /trunk/src/io/c_stream.cc	(revision 318)
+++ /trunk/src/io/c_stream.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // This file is part of NV Libraries.
 // For conditions of distribution and use, see copyright notice in nv.hh
Index: /trunk/src/io/std_stream.cc
===================================================================
--- /trunk/src/io/std_stream.cc	(revision 318)
+++ /trunk/src/io/std_stream.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: unk/src/io_event.cc
===================================================================
--- /trunk/src/io_event.cc	(revision 318)
+++ 	(revision )
@@ -1,139 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/io_event.hh"
-
-#include <nv/types.hh>
-
-using namespace nv;
-
-const char* nv::get_key_name( key_code key )
-{
-	switch ( key )
-	{
-#	define NV_KEY( id, val ) case id : return #id;
-#		include <nv/detail/key_list.inc>
-#	undef NV_KEY
-	NV_RETURN_COVERED_DEFAULT( "KEY_UNKNOWN" );
-	};
-}
-
-const char* nv::get_mouse_name( mouse_code button )
-{
-	switch ( button )
-	{
-#	define NV_MOUSE( id, val ) case id : return #id;
-#		include <nv/detail/mouse_list.inc>
-#	undef NV_MOUSE
-	NV_RETURN_COVERED_DEFAULT( "MOUSE_UNKNOWN" );
-	};
-}
-
-const char* nv::get_io_event_name( io_event_code event )
-{
-	switch ( event )
-	{
-#	define NV_IO_EVENT( id ) case id : return #id;
-#		include <nv/detail/io_event_list.inc>
-#	undef NV_IO_EVENT
-	NV_RETURN_COVERED_DEFAULT( "EV_UNKNOWN" );
-	};
-}
-
-void nv::register_io_types( type_database* db )
-{
-	type_enum key_enums[] = {
-#	define NV_KEY( id, val ) type_enum( #id, id ),
-#		include <nv/detail/key_list.inc>
-#	undef NV_KEY
-	};
-	db->create_type<key_code>("key_code").enums( key_enums );
-
-	type_enum mouse_enums[] = {
-#	define NV_MOUSE( id, val ) type_enum( #id, id ),
-#		include <nv/detail/mouse_list.inc>
-#	undef NV_MOUSE
-	};
-	db->create_type<mouse_code>("mouse_code").enums( mouse_enums );
-
-	type_enum io_event_enums[] = {
-#	define NV_IO_EVENT( id ) type_enum( #id, id ),
-#		include <nv/detail/io_event_list.inc>
-#	undef NV_IO_EVENT
-	};
-	db->create_type<io_event_code>("event_code").enums( io_event_enums );
-
-	type_field key_fields[] = {
-		type_field( "ascii",   &key_event::ascii ),
-		type_field( "code",    &key_event::code ),
-		type_field( "shift",   &key_event::shift ),
-		type_field( "control", &key_event::control ),
-		type_field( "alt",     &key_event::alt ),
-		type_field( "pressed", &key_event::pressed ),
-	};
-	db->create_type<key_event>("key_event").fields( key_fields );
-
-	type_field mouse_button_fields[] = {
-		type_field( "x",       &mouse_button_event::x ),
-		type_field( "y",       &mouse_button_event::y ),
-		type_field( "button",  &mouse_button_event::button ),
-		type_field( "pressed", &mouse_button_event::pressed ),
-		type_field( "code",    &mouse_button_event::code ),
-	};
-	db->create_type<mouse_button_event>("mouse_button_event").fields( mouse_button_fields );
-
-	type_field mouse_move_fields[] = {
-		type_field( "x",       &mouse_move_event::x ),
-		type_field( "y",       &mouse_move_event::y ),
-		type_field( "rx",      &mouse_move_event::rx ),
-		type_field( "ry",      &mouse_move_event::ry ),
-		type_field( "pressed", &mouse_move_event::pressed ),
-		type_field( "code",    &mouse_move_event::code ),
-	};
-	db->create_type<mouse_move_event>("mouse_move_event").fields( mouse_move_fields );
-
-	type_field mouse_wheel_fields[] = {
-		type_field( "x",       &mouse_wheel_event::x ),
-		type_field( "y",       &mouse_wheel_event::y ),
-	};
-	db->create_type<mouse_wheel_event>("mouse_wheel_event").fields( mouse_wheel_fields );
-
-	type_field joy_button_fields[] = {
-		type_field( "id",      &joy_button_event::id ),
-		type_field( "button",  &joy_button_event::button ),
-		type_field( "pressed", &joy_button_event::pressed ),
-	};
-	db->create_type<joy_button_event>("joy_button_event").fields( joy_button_fields );
-
-	type_field joy_axis_fields[] = {
-		type_field( "id",      &joy_axis_event::id ),
-		type_field( "axis",    &joy_axis_event::axis ),
-		type_field( "value",   &joy_axis_event::value ),
-	};
-	db->create_type<joy_axis_event>("joy_axis_event").fields( joy_axis_fields );
-
-	type_field joy_hat_fields[] = {
-		type_field( "id",      &joy_hat_event::id ),
-		type_field( "hat",     &joy_hat_event::hat ),
-		type_field( "value",   &joy_hat_event::value ),
-	};
-	db->create_type<joy_hat_event>("joy_hat_event").fields( joy_hat_fields );
-
-	type_field joy_ball_fields[] = {
-		type_field( "id",      &joy_ball_event::id ),
-		type_field( "ball",    &joy_ball_event::ball ),
-		type_field( "rx",      &joy_ball_event::rx ),
-		type_field( "ry",      &joy_ball_event::ry ),
-	};
-	db->create_type<joy_ball_event>("joy_ball_event").fields( joy_ball_fields );
-
-	type_field system_fields[] = {
-		type_field( "sys_type", &system_event::sys_type ),
-		type_field( "param1",   &system_event::param1 ),
-		type_field( "param2",   &system_event::param2 ),
-	};
-	db->create_type<system_event>("system_event").fields( system_fields );
-}
Index: /trunk/src/lib/assimp.cc
===================================================================
--- /trunk/src/lib/assimp.cc	(revision 318)
+++ /trunk/src/lib/assimp.cc	(revision 319)
@@ -23,5 +23,5 @@
 #if defined( NV_ASSIMP_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #define NV_ASSIMP_FUN( rtype, fname, fparams ) rtype (NV_ASSIMP_APIENTRY *fname) fparams = nullptr;
Index: /trunk/src/lib/curses.cc
===================================================================
--- /trunk/src/lib/curses.cc	(revision 318)
+++ /trunk/src/lib/curses.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2013-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #if defined( NV_CURSES_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #define NV_CURSES_FUN( rtype, fname, fparams ) rtype (*fname) fparams = nullptr;
Index: /trunk/src/lib/fmod.cc
===================================================================
--- /trunk/src/lib/fmod.cc	(revision 318)
+++ /trunk/src/lib/fmod.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #if defined( NV_FMOD_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #define NV_FMOD_FUN( rtype, fname, fparams ) rtype (NV_FMOD_APIENTRY *fname) fparams = nullptr;
Index: /trunk/src/lib/freetype2.cc
===================================================================
--- /trunk/src/lib/freetype2.cc	(revision 318)
+++ /trunk/src/lib/freetype2.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #if defined( NV_FREETYPE_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #define NV_FREETYPE_FUN( rtype, fname, fparams ) rtype (*fname) fparams = nullptr;
Index: /trunk/src/lib/gl.cc
===================================================================
--- /trunk/src/lib/gl.cc	(revision 318)
+++ /trunk/src/lib/gl.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -5,11 +5,11 @@
 // For conditions of distribution and use, see copyright notice in nv.hh
 
-#include "nv/common.hh"
-#include "nv/range.hh"
+#include "nv/core/common.hh"
+#include "nv/core/range.hh"
 #include "nv/lib/gl.hh"
 
 #if defined( NV_GL_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #if defined( NV_SDL_GL )
Index: /trunk/src/lib/lua.cc
===================================================================
--- /trunk/src/lib/lua.cc	(revision 318)
+++ /trunk/src/lib/lua.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #if defined( NV_LUA_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #if NV_LUA_VERSION == NV_LUA_52
Index: /trunk/src/lib/sdl.cc
===================================================================
--- /trunk/src/lib/sdl.cc	(revision 318)
+++ /trunk/src/lib/sdl.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #if defined( NV_SDL_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #define NV_SDL_FUN( rtype, fname, fparams ) rtype (NV_SDL_APIENTRY *fname) fparams = nullptr;
Index: /trunk/src/lib/sdl_image.cc
===================================================================
--- /trunk/src/lib/sdl_image.cc	(revision 318)
+++ /trunk/src/lib/sdl_image.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #if defined( NV_SDL_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #define NV_SDL_FUN( rtype, fname, fparams ) rtype (NV_SDL_APIENTRY *fname) fparams = nullptr;
Index: /trunk/src/lib/sdl_mixer.cc
===================================================================
--- /trunk/src/lib/sdl_mixer.cc	(revision 318)
+++ /trunk/src/lib/sdl_mixer.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #if defined( NV_SDL_DYNAMIC )
 
-#include "nv/library.hh"
+#include "nv/core/library.hh"
 
 #define NV_SDL_FUN( rtype, fname, fparams ) rtype (NV_SDL_APIENTRY *fname) fparams = nullptr;
Index: unk/src/library.cc
===================================================================
--- /trunk/src/library.cc	(revision 318)
+++ 	(revision )
@@ -1,147 +1,0 @@
-// Copyright (C) 2012 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-#include "nv/common.hh"
-#include "nv/library.hh"
-
-#if NV_PLATFORM == NV_WINDOWS
-#   define WIN32_LEAN_AND_MEAN
-#   include <windows.h>
-#   define NV_LIB_EXT ".dll"
-#   define NV_LIB_HANDLE HMODULE
-#   define NV_LIB_OPEN( name ) LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
-#   define NV_LIB_GET( handle, name ) GetProcAddress( handle, name )
-#   define NV_LIB_CLOSE( name ) !FreeLibrary( name )
-#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
-#   include <dlfcn.h>
-#   define NV_LIB_EXT ".so"
-#   define NV_LIB_HANDLE void*
-#   define NV_LIB_OPEN( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL)
-#   define NV_LIB_GET( handle, name ) dlsym( handle, name )
-#   define NV_LIB_CLOSE( name ) dlclose( name )
-#elif NV_PLATFORM == NV_APPLE
-#   include "macUtils.h"
-#   include <dlfcn.h>
-#   define NV_LIB_EXT ".dylib"
-#   define NV_LIB_HANDLE CFBundleRef
-#   define NV_LIB_OPEN( name ) mac_loadExeBundle( name )
-#   define NV_LIB_GET( handle, name ) mac_getBundleSym( handle, name )
-#   define NV_LIB_CLOSE( name ) mac_unloadExeBundle( name )
-#endif
-
-#include "nv/logging.hh"
-
-using namespace nv;
-
-library::library() 
-    : m_handle( nullptr ), m_name()
-{
-}
-
-void library::open( const string& name )
-{
-	m_name = name;
-	if ( !open() )
-	{
-		m_handle = nullptr;
-		NV_THROW( library_error, "Can't load library!", name );
-	}
-}
-
-bool nv::library::try_open( const string& name )
-{
-	m_name = name;
-	if ( !open() )
-	{
-		m_handle = nullptr;
-		return false;
-	}
-	return true;
-}
-
-const string& library::get_name() const
-{
-    return m_name;
-}
-
-bool library::open( )
-{
-    if ( m_handle != NULL )
-    {
-        return true;
-    }
-    NV_LOG( LOG_NOTICE, "library : loading '" + m_name + "'..." );
-
-    string name = m_name;
-    string ext  = NV_LIB_EXT;
-    size_t ext_len   = ext.length();
-
-    if ( name.length() < ext_len || name.substr( name.length() - ext_len, ext_len ) != ext ) 
-    {
-        name += ext;
-    }
-
-    m_handle = (void*)NV_LIB_OPEN( name.c_str() );
-
-    if ( m_handle == NULL )
-    {
-		NV_LOG( LOG_NOTICE, "library : '" + name + "' failed to open." );
-		return false;
-    }
-    NV_LOG( LOG_NOTICE, "library : '" + name + "' loaded." );
-	return true;
-}
-
-void* library::get( const string& symbol )
-{
-	void* result = (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
-    if ( !result )
-    {
-        NV_THROW( library_error, "Can't find symbol " + symbol + "!", m_name );
-    }
-	return result;
-}
-
-void* nv::library::try_get( const string& symbol )
-{
-	return (void*) NV_LIB_GET( (NV_LIB_HANDLE) m_handle, symbol.c_str() );
-}
-
-bool library::is_open() const
-{
-	return m_handle != nullptr;
-}
-
-void library::close()
-{
-    if ( NV_LIB_CLOSE( (NV_LIB_HANDLE)m_handle ) )
-    {
-        NV_LOG( LOG_ERROR, "library : can't close library '" + m_name + "'!" );
-    }
-    m_handle = NULL;
-}
-
-library::~library()
-{
-    if ( m_handle != NULL )
-    {
-        close();
-    }
-}
-
-string library::get_error()
-{
-#if NV_PLATFORM == NV_WINDOWS
-    // We do hate WinAPI for code like this, don't we?
-    LPTSTR buffer = NULL;
-    FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-        NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &buffer, 0, NULL );
-    string msg( (char*)buffer );
-    LocalFree( buffer );
-    return msg;
-#elif NV_PLATFORM == NV_LINUX || NV_PLATFORM == NV_APPLE
-    return string(dlerror());
-#else
-    return string("");
-#endif
-}
Index: unk/src/logger.cc
===================================================================
--- /trunk/src/logger.cc	(revision 318)
+++ 	(revision )
@@ -1,262 +1,0 @@
-// Copyright (C) 2011 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/logger.hh"
-
-#include "nv/common.hh"
-#include <iostream>
-#include <utility>
-#include <algorithm>
-#include <fstream>
-#include <ctime>
-#include <cstdio>
-#include <nv/exception.hh>
-#if NV_PLATFORM == NV_WINDOWS
-#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
-#endif
-
-using namespace nv;
-
-// log level names
-static const char *log_level_names[] =
-{
-	"NONE",
-	"FATAL",
-	"CRITICAL",
-	"ERROR",
-	"WARNING",
-	"NOTICE",
-	"INFO",
-	"INFO",
-	"DEBUG",
-	"DEBUG2",
-	"TRACE"
-};
-
-// log level names
-static const char *log_level_names_pad[] =
-{
-	"NONE    ",
-	"FATAL   ",
-	"CRITICAL",
-	"ERROR   ",
-	"WARNING ",
-	"NOTICE  ",
-	"INFO    ",
-	"INFO    ",
-	"DEBUG   ",
-	"DEBUG2  ",
-	"TRACE   "
-};
-
-// helper macro to access log_level_names
-#define NV_LOG_LEVEL_NAME(level) (log_level_names[ (level) / 10 ])
-#define NV_LOG_LEVEL_NAME_PAD(level) (log_level_names_pad[ (level) / 10 ])
-
-#if NV_PLATFORM == NV_WINDOWS 
-static unsigned short log_color[] =
-{
-	FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
-	FOREGROUND_RED | FOREGROUND_INTENSITY,
-	FOREGROUND_RED | FOREGROUND_INTENSITY,
-	FOREGROUND_RED,
-	FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,
-	FOREGROUND_GREEN | FOREGROUND_INTENSITY,
-	FOREGROUND_GREEN,
-	FOREGROUND_GREEN,
-	FOREGROUND_INTENSITY,
-	FOREGROUND_INTENSITY,
-	FOREGROUND_INTENSITY
-};
-#else
-static const char *log_color[] =
-{
-	"\33[37;1m",
-	"\33[31;1m",
-	"\33[31;1m",
-	"\33[31m",
-	"\33[33;1m",
-	"\33[32;1m",
-	"\33[32m",
-	"\33[32m",
-	"\33[30;1m",
-	"\33[30;1m",
-	"\33[30;1m"
-};
-#endif
-
-// log function
-void logger::log( log_level level, const std::string& message )
-{
-	// get the iterator to the beginning of the log_sink list
-	log_sink_list::reverse_iterator it = m_log_sinks.rbegin();
-
-	// iterate
-	while ( it != m_log_sinks.rend() )
-	{
-		// if we have a log sink with high enough level...
-		if ( it->first >= level )
-		{
-			// log and iterate
-			it->second->log( level, message );
-		}
-		else 
-		{
-			// otherwise return, the list is sorted by log level
-			return;
-		}
-		++it;
-	}
-}
-
-// add a new sink
-void logger::add_sink( log_sink* sink, int level )
-{
-	// add a sink
-	m_log_sinks.push_back( std::make_pair( log_level(level), sink ) );
-	// and sort the list (default sort of pairs is by first element)
-	m_log_sinks.sort();
-}
-
-// remove existing sink
-bool logger::remove_sink( log_sink* sink )
-{
-	// get the iterator to the beginning of the log_sink list
-	log_sink_list::iterator it = m_log_sinks.begin();
-
-	// iterate
-	while ( it != m_log_sinks.end() )
-	{
-		// found?
-		if ( it->second == sink ) 
-		{
-			// erase and return true to report success
-			m_log_sinks.erase(it);
-			return true;
-		}
-		++it;
-	}
-
-	// not found, return false
-	return false;
-}
-
-// destructor
-logger::~logger()
-{
-	// while we have sinks
-	while ( !m_log_sinks.empty() )
-	{
-		// delete the last one
-		delete m_log_sinks.back().second;
-		// and pop it
-		m_log_sinks.pop_back();
-	}
-}
-
-
-// console logging
-void log_console_sink::log( log_level level, const std::string& message )
-{
-	if (m_color) 
-	{
-#if NV_PLATFORM == NV_WINDOWS 
-		SetConsoleTextAttribute( m_handle, FOREGROUND_INTENSITY );
-		std::cout << timestamp() << " [";
-		SetConsoleTextAttribute( m_handle, log_color[ (level) / 10 ] );
-		std::cout << NV_LOG_LEVEL_NAME_PAD(level);
-		SetConsoleTextAttribute( m_handle, FOREGROUND_INTENSITY );
-		std::cout << "] ";
-		SetConsoleTextAttribute( m_handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
-		std::cout << message << std::endl;
-#else
-		std::cout << "\33[30;1m" << timestamp() << " [" << log_color[ (level) / 10 ] << NV_LOG_LEVEL_NAME_PAD(level) << "\33[30;1m] \33[37;1m" << message << std::endl;
-#endif
-	}
-	else
-	{
-	std::cout << timestamp() << " [" << NV_LOG_LEVEL_NAME_PAD(level) << "] " << message << std::endl;
-	}
-}
-
-// stream logging
-void log_stream_sink::log( log_level level, const std::string& message )
-{
-	// if flushing is enabled
-	if ( m_flush )
-	{
-		// write and flush using std::endl
-		*m_stream << timestamp() << " [" << NV_LOG_LEVEL_NAME(level) << "] " << message << std::endl;
-	}
-	else
-	{
-		// write and end with "\n" (no flush)
-		*m_stream << timestamp() << " [" << NV_LOG_LEVEL_NAME(level) << "] " << message << "\n";
-	}
-}
-
-// file logging
-log_file_sink::log_file_sink( const std::string file_name, bool flush_always /*= true */ )
-	: log_stream_sink( nullptr, flush_always )
-{
-	// create the stream manually
-	std::ofstream* fstream = new std::ofstream( file_name );
-
-	// check if it's open
-	if ( !fstream->is_open() )
-	{
-		// throw if not open
-		NV_THROW( runtime_error, "Could not open file \""+file_name+"\" for logging!" );
-	}
-
-	m_stream = fstream;
-}
-
-// file logger destructor
-log_file_sink::~log_file_sink()
-{
-	// close the file
-	dynamic_cast< std::ofstream* >(m_stream)->close();
-	// dispose of the stream
-	delete m_stream;
-}
-
-nv::log_console_sink::log_console_sink( bool coloring )
-	: m_color( coloring )
-{
-#if NV_PLATFORM == NV_WINDOWS 
-	m_handle = GetStdHandle( STD_OUTPUT_HANDLE );
-#else
-  NV_UNUSED( m_handle );
-#endif
-}
-
-const char* nv::log_sink::timestamp() const
-{
-	std::clock_t time = std::clock();
-	unsigned int secs = (unsigned int)(time / CLOCKS_PER_SEC);
-	unsigned int mm   = (unsigned int)(time*100 / CLOCKS_PER_SEC) % 100;
-	unsigned int h    = (unsigned int)(secs / (60*60));
-	unsigned int m    = (unsigned int)(secs / 60) % 60;
-	unsigned int s    = secs % 60;
-	static char buffer[128];
-#if NV_PLATFORM == NV_WINDOWS 
-	sprintf_s( buffer, 128, "%02d:%02d:%02d.%02d", h, m, s, mm );
-#else
-	sprintf( buffer, "%02d:%02d:%02d.%02d", h, m, s, mm );
-#endif
-	buffer[11] = '\0';
-	return buffer;
-}
-
-const char* nv::log_sink::level_name( log_level level ) const
-{
-	return NV_LOG_LEVEL_NAME( level );
-}
-
-const char* nv::log_sink::padded_level_name( log_level level ) const
-{
-	return NV_LOG_LEVEL_NAME_PAD( level );
-}
Index: /trunk/src/lua/lua_area.cc
===================================================================
--- /trunk/src/lua/lua_area.cc	(revision 318)
+++ /trunk/src/lua/lua_area.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 
 #include "nv/lua/lua_raw.hh"
-#include "nv/string.hh"
-#include "nv/random.hh"
+#include "nv/core/string.hh"
+#include "nv/core/random.hh"
 
 const char* nv::lua::detail::AREA_METATABLE = "area";
Index: /trunk/src/lua/lua_aux.cc
===================================================================
--- /trunk/src/lua/lua_aux.cc	(revision 318)
+++ /trunk/src/lua/lua_aux.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #include <utility>
 #include "nv/lua/lua_raw.hh"
-#include "nv/random.hh"
+#include "nv/core/random.hh"
 
 static int nluaaux_table_copy( lua_State* L )
Index: /trunk/src/lua/lua_flags.cc
===================================================================
--- /trunk/src/lua/lua_flags.cc	(revision 318)
+++ /trunk/src/lua/lua_flags.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,5 +8,5 @@
 
 #include "nv/lua/lua_raw.hh"
-#include "nv/string.hh"
+#include "nv/core/string.hh"
 
 
Index: /trunk/src/lua/lua_function.cc
===================================================================
--- /trunk/src/lua/lua_function.cc	(revision 318)
+++ /trunk/src/lua/lua_function.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/lua/lua_glm.cc
===================================================================
--- /trunk/src/lua/lua_glm.cc	(revision 318)
+++ /trunk/src/lua/lua_glm.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -8,6 +8,6 @@
 
 #include "nv/lua/lua_raw.hh"
-#include "nv/string.hh"
-#include "nv/random.hh"
+#include "nv/core/string.hh"
+#include "nv/core/random.hh"
 
 static size_t nlua_swizzel_lookup[256];
Index: /trunk/src/lua/lua_map_area.cc
===================================================================
--- /trunk/src/lua/lua_map_area.cc	(revision 318)
+++ /trunk/src/lua/lua_map_area.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -6,5 +6,5 @@
 
 #include "nv/lua/lua_map_area.hh"
-#include "nv/flags.hh"
+#include "nv/core/flags.hh"
 #include "nv/lua/lua_area.hh"
 #include "nv/lua/lua_glm.hh"
Index: /trunk/src/lua/lua_map_tile.cc
===================================================================
--- /trunk/src/lua/lua_map_tile.cc	(revision 318)
+++ /trunk/src/lua/lua_map_tile.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,6 +9,6 @@
 #include <numeric>
 #include "nv/lua/lua_map_area.hh"
-#include "nv/flags.hh"
-#include "nv/random.hh"
+#include "nv/core/flags.hh"
+#include "nv/core/random.hh"
 #include "nv/lua/lua_area.hh"
 #include "nv/lua/lua_glm.hh"
Index: /trunk/src/lua/lua_nova.cc
===================================================================
--- /trunk/src/lua/lua_nova.cc	(revision 318)
+++ /trunk/src/lua/lua_nova.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/lua/lua_path.cc
===================================================================
--- /trunk/src/lua/lua_path.cc	(revision 318)
+++ /trunk/src/lua/lua_path.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: /trunk/src/lua/lua_raw.cc
===================================================================
--- /trunk/src/lua/lua_raw.cc	(revision 318)
+++ /trunk/src/lua/lua_raw.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,5 +7,5 @@
 #include "nv/lua/lua_raw.hh"
 
-#include "nv/string.hh"
+#include "nv/core/string.hh"
 
 std::string nlua_typecontent( lua_State* L, int idx )
Index: /trunk/src/lua/lua_state.cc
===================================================================
--- /trunk/src/lua/lua_state.cc	(revision 318)
+++ /trunk/src/lua/lua_state.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,6 +9,6 @@
 #include "nv/lua/lua_raw.hh"
 #include "nv/lua/lua_nova.hh"
-#include "nv/logging.hh"
-#include "nv/string.hh"
+#include "nv/core/logging.hh"
+#include "nv/core/string.hh"
 
 using namespace nv;
Index: /trunk/src/lua/lua_values.cc
===================================================================
--- /trunk/src/lua/lua_values.cc	(revision 318)
+++ /trunk/src/lua/lua_values.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
Index: unk/src/object.cc
===================================================================
--- /trunk/src/object.cc	(revision 318)
+++ 	(revision )
@@ -1,133 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/object.hh"
-
-#include <algorithm>
-
-using namespace nv;
-
-object::object( const string& aid )
-	: m_id( aid )
-	, m_name()
-	, m_uid(0)
-	, m_parent( nullptr )
-	, m_children()
-	, m_child_count(0)
-{
-}
-
-void object::add_child( object* child )
-{
-	if (child)
-	{
-		if (child->m_parent)
-		{
-			child->detach();
-		}
-		child->m_parent = this;
-		m_children.push_back( child );
-		m_child_count++;
-	}
-}
-
-void object::remove_child( object* child )
-{
-	if ( child->m_parent != this )
-	{
-		return; // signal error?
-	}
-	list::iterator it = std::find( m_children.begin(), m_children.end(), child );
-	if ( it != m_children.end() )
-	{
-		(*it)->m_parent = nullptr;
-		m_children.erase(it);
-	}	
-}
-
-void object::detach()
-{
-	if (m_parent)
-	{
-		m_parent->remove_child( this );
-	}
-}
-
-void object::change_parent( object* new_parent )
-{
-	if (m_parent) detach();
-	if (new_parent) new_parent->add_child( this );
-}
-
-object::~object()
-{
-}
-
-object* object::find( object* child, bool recursive /*= false */ )
-{
-	list::iterator it = std::find( m_children.begin(), m_children.end(), child );
-	if ( it != m_children.end() )
-	{
-		return *it;
-	}
-	if ( recursive )
-	{
-		for ( object* i : m_children )
-		{
-			object* r = i->find( child, recursive );
-			if (r) return r;
-		}
-	}
-	return nullptr;
-}
-
-object* object::find( uid child, bool recursive /*= false */ )
-{
-	for ( object* i : m_children )
-	{
-		if (i->m_uid == child) return i;
-	}
-	if ( recursive )
-	{
-		for ( object* i : m_children )
-		{
-			object* r = i->find( child, recursive );
-			if (r) return r;
-		}
-	}
-	return nullptr;
-}
-
-object* object::find( string child, bool recursive /*= false */ )
-{
-	for ( object* i : m_children )
-	{
-		if (i->m_id == child) return i;
-	}
-	if ( recursive )
-	{
-		for ( object* i : m_children )
-		{
-			object* r = i->find( child, recursive );
-			if (r) return r;
-		}
-	}
-	return nullptr;
-}
-
-
-// void object::register_type( type_database* db )
-// {
-// 	type_field fields[] = {
-// 		type_field("id",          &object::m_id),
-// 		type_field("uid",         &object::m_uid).flag( TF_READONLY ), 
-// 		type_field("lua_index",   &object::m_lua_index).flag( TF_READONLY | TF_NOSERIALIZE ),
-// 		type_field("parent",      &object::m_parent).flag( TF_READONLY | TF_NOSERIALIZE ),
-// 		type_field("child_count", &object::m_child_count).flag( TF_READONLY ),
-// 		type_field("children"   , &object::m_children).flag( TF_READONLY ),
-// 	};
-// 	db->create_type<object>("object").fields(fields);
-// }
Index: unk/src/profiler.cc
===================================================================
--- /trunk/src/profiler.cc	(revision 318)
+++ 	(revision )
@@ -1,133 +1,0 @@
-// Copyright (C) 2012-2013 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/profiler.hh"
-
-#include <iomanip>
-#include <ios>
-#include "nv/time.hh"
-
-using namespace nv;
-
-
-profiler::profiler()
-{
-	m_root = new node( "root", nullptr );
-	m_root->start();
-	m_current = m_root;
-}
-
-profiler::~profiler()
-{
-	delete m_root;
-}
-
-void profiler::start_profile( const char* tag )
-{
-	if ( tag != m_current->m_tag )
-	{
-		m_current = m_current->request_child( tag );
-	}
-	m_current->start();
-}
-
-void profiler::stop_profile()
-{
-	if ( m_current->stop() )
-	{
-		m_current = m_current->get_parent();
-	}
-}
-
-profiler::node::node( const char* tag, node* parent ) 
-	: m_tag( tag )
-	, m_parent( parent )
-	, m_recusion( 0 )
-	, m_calls( 0 )
-	, m_start_time_us( 0 )
-	, m_total_time_us( 0 )
-{
-
-}
-
-profiler::node* profiler::node::request_child( const char* tag )
-{
-	auto it = m_children.find( tag );
-	if ( it != m_children.end() ) 
-		return it->second;
-	else
-	{
-		node* result = new node( tag, this );
-		m_children[ tag ] = result;
-		return result;
-	}
-}
-
-void profiler::node::start()
-{
-	m_calls++;
-	m_recusion++;
-	if ( m_recusion == 1 )
-	{
-		m_start_time_us = get_system_us();
-	}
-}
-
-bool profiler::node::stop()
-{
-	m_recusion--;
-	if ( m_recusion == 0 )
-	{
-		uint64 stop_time_us = get_system_us();
-		uint64 elapsed_us   = stop_time_us - m_start_time_us;
-		m_total_time_us     += elapsed_us;
-		return true;
-	}
-	return false;
-}
-
-
-nv::profiler::node::~node()
-{
-	for ( const auto& pair : m_children )
-	{
-		delete pair.second;
-	}
-}
-
-
-void profiler::log_report()
-{
-	m_root->stop();
-	NV_LOG( LOG_INFO, "-- PROFILER REPORT -----------------------------------------" );
-	NV_LOG( LOG_INFO, std::left << std::setw(24) << "TAG" 
-		<< std::setw(7) << "%PARNT" 
-		<< std::setw(7) << "CALLS" 
-		<< std::setw(10) << "TOTAL(ms)" 
-		<< std::setw(10) << "AVG(ms)" );
-	log_node_children( "", m_root );
-	NV_LOG( LOG_INFO, "-- PROFILER REPORT END -------------------------------------" );
-	m_root->start();
-}
-
-void profiler::log_node_children( const std::string& ind, const node* n )
-{
-	for ( const auto& pair : n->m_children )
-	{
-		const node* c = pair.second;
-		if ( c->m_calls > 0 )
-		{
-			NV_LOG( LOG_INFO, std::left << std::setw(24) << ind + c->m_tag 
-				<< std::setw(7) << std::setprecision(2) << std::fixed << ( (double)c->m_total_time_us / (double)c->m_parent->m_total_time_us ) * 100.0
-				<< std::setw(7) << c->m_calls 
-				<< std::setw(10) << std::setprecision(2) << std::fixed << c->m_total_time_us / 1000.f
-				<< std::setw(10) << std::setprecision(2) << std::fixed << ( (double)c->m_total_time_us / (double)c->m_calls ) / 1000.f
-				);
-			if ( c->m_children.size() > 0 )
-			{
-				log_node_children( ind + "-", c );
-			}
-		}
-	}
-}
Index: unk/src/random.cc
===================================================================
--- /trunk/src/random.cc	(revision 318)
+++ 	(revision )
@@ -1,276 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/random.hh"
-#include "nv/time.hh"
-
-using namespace nv;
-
-random::random( random::seed_type seed /*= 0 */ )
-	: rng( seed == 0 ? randomized_seed() : seed )
-{
-	
-}
-
-random::seed_type random::randomize()
-{
-	seed_type seed = randomized_seed();
-	rng.seed( seed );
-	return seed;
-}
-
-void random::set_seed( random::seed_type seed /*= 0 */ )
-{
-	rng.seed( seed == 0 ? randomized_seed() : seed );
-}
-
-nv::random& random::get()
-{
-	static random default_rng;
-	return default_rng;
-}
-
-random::result_type random::rand()
-{
-	return rng();
-}
-
-sint32 random::srand( sint32 val )
-{
-	std::uniform_int_distribution<sint32> dist( 0, val - 1 );
-	return dist( rng );
-}
-
-uint32 random::urand( uint32 val )
-{
-	std::uniform_int_distribution<uint32> dist( 0, val - 1 );
-	return dist( rng );
-}
-
-f32 random::frand( f32 val )
-{
-	std::uniform_real_distribution<f32> dist( 0, val );
-	return dist( rng );
-}
-
-sint32 random::srange( sint32 min, sint32 max )
-{
-	std::uniform_int_distribution<sint32> dist( min, max );
-	return dist( rng );
-}
-
-uint32 random::urange( uint32 min, uint32 max )
-{
-	std::uniform_int_distribution<uint32> dist( min, max );
-	return dist( rng );
-}
-
-f32 random::frange( f32 min, f32 max )
-{
-	std::uniform_real_distribution<f32> dist( min, max );
-	return dist( rng );
-}
-
-uint32 random::dice( uint32 count, uint32 sides )
-{
-	std::uniform_int_distribution<uint32> dist( 1, sides );
-	uint32 result = 0;
-	while (count-- > 0)
-	{
-		result += dist( rng );
-	};
-	return result;
-}
-
-random::seed_type random::randomized_seed()
-{
-	return narrow_cast< seed_type >( get_ticks() );
-}
-
-nv::vec2 nv::random::precise_unit_vec2()
-{
-	std::uniform_real_distribution<f32> dist( 0, glm::pi<float>() * 2.f );
-	float angle = dist( rng );
-	return vec2( glm::cos( angle ), glm::sin( angle ) );
-}
-
-nv::vec3 nv::random::precise_unit_vec3()
-{
-	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
-	std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() );
-	float cos_theta = dist11( rng );
-	float sin_theta = glm::sqrt( 1.0f - cos_theta * cos_theta );
-	float phi       = dist02pi( rng );
-	return vec3( 
-		sin_theta * glm::sin(phi),
-		sin_theta * glm::cos(phi),
-		cos_theta
-		);
-}
-
-nv::vec2 nv::random::fast_disk_point()
-{
-	std::uniform_real_distribution<f32> dist( 0.0f, 1.0f );
-	float r1 = dist( rng );
-	float r2 = dist( rng );
-	if ( r1 > r2 ) std::swap( r1, r2 );
-	float rf = 2*glm::pi<float>()*(r1/r2);
-	return vec2( r2*glm::cos( rf ), r2*glm::sin( rf ) );
-}
-
-nv::vec2 nv::random::precise_disk_point()
-{
-	std::uniform_real_distribution<f32> unit( 0.0f, 1.0f );
-	std::uniform_real_distribution<f32> angle( 0.0f, glm::pi<float>() );
-	float r = glm::sqrt( unit( rng ) );
-	float rangle = angle( rng );
-	return vec2( r*glm::cos( rangle ), r*glm::sin( rangle ) );
-}
-
-nv::vec3 nv::random::fast_sphere_point()
-{
-	std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f );
-	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
-	std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() );
-	float rad     = dist01( rng );
-	float pi      = glm::pi<float>();
-	float phi     = glm::asin( dist11( rng ) ) + pi*.5f;
-	float theta   = dist02pi( rng );
-	float sin_phi = glm::sin( phi );
-	return vec3( 
-		rad * glm::cos(theta) * sin_phi,
-		rad * glm::sin(theta) * sin_phi,
-		rad * glm::cos(phi)
-	);
-}
-
-nv::vec3 nv::random::precise_sphere_point()
-{
-	std::uniform_real_distribution<f32> dist01( 0.0f, 1.0f );
-	std::uniform_real_distribution<f32> dist11( -1.0f, 1.0f );
-	std::uniform_real_distribution<f32> dist02pi( 0.0f, 2*glm::pi<float>() );
-	float radius = std::pow( dist01( rng ), 1.f/3.f );
-	float cos_theta = dist11( rng );
-	float sin_theta = glm::sqrt( 1.0f - cos_theta * cos_theta );
-	float phi       = dist02pi( rng );
-	return vec3( 
-		radius * sin_theta * glm::sin(phi),
-		radius * sin_theta * glm::cos(phi),
-		radius * cos_theta
-		);
-}
-
-nv::vec2 nv::random::precise_ellipse_point( const vec2& radii )
-{
-	std::uniform_real_distribution<f32> distx( -radii.x, radii.x );
-	std::uniform_real_distribution<f32> disty( -radii.y, radii.y );
-	vec2 inv_radii  = 1.f / radii;
-	vec2 inv_radii2 = inv_radii * inv_radii;
-	for ( uint32 i = 0; i < 12; ++i )
-	{
-		float x = distx( rng );
-		float y = disty( rng );
-		if ( x * x * inv_radii2.x + y * y * inv_radii2.y <= 1.f )
-		{
-			return vec2( x, y );
-		}
-	}
-	return fast_disk_point() * radii;
-}
-
-nv::vec3 nv::random::precise_ellipsoid_point( const vec3& radii )
-{
-	std::uniform_real_distribution<f32> distx( -radii.x, radii.x );
-	std::uniform_real_distribution<f32> disty( -radii.y, radii.y );
-	std::uniform_real_distribution<f32> distz( -radii.z, radii.z );
-	vec3 inv_radii  = 1.f / radii;
-	vec3 inv_radii2 = inv_radii * inv_radii;
-	for ( uint32 i = 0; i < 12; ++i )
-	{
-		float x = distx( rng );
-		float y = disty( rng );
-		float z = distz( rng );
-		if ( x * x * inv_radii2.x + y * y * inv_radii2.y + z * z * inv_radii2.z <= 1.f )
-		{
-			return vec3( x, y, z );
-		}
-	}
-	return fast_sphere_point() * radii;
-}
-
-nv::vec2 nv::random::fast_hollow_disk_point( float iradius, float oradius )
-{
-	float idist2 = iradius * iradius;
-	float odist2 = oradius * oradius;
-	float rdist  = glm::sqrt( std::uniform_real_distribution<f32>( idist2, odist2 )( rng ) );
-	return rdist * precise_unit_vec2();
-}
-
-nv::vec2 nv::random::precise_hollow_disk_point( float iradius, float oradius )
-{
-	return fast_hollow_disk_point( iradius, oradius );
-}
-
-nv::vec3 nv::random::fast_hollow_sphere_point( float iradius, float oradius )
-{
-	float idist3 = iradius * iradius * iradius;
-	float odist3 = oradius * oradius * oradius;
-	float rdist  = std::pow( std::uniform_real_distribution<f32>( idist3, odist3 )( rng ), 1.f/3.f );
-	return rdist * precise_unit_vec3();
-}
-
-nv::vec3 nv::random::precise_hollow_sphere_point( float iradius, float oradius )
-{
-	return fast_hollow_sphere_point( iradius, oradius );
-}
-
-
-nv::vec2 nv::random::fast_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
-{
-	vec2 iradii2    = iradii * iradii;
-	vec2 opoint     = ellipse_edge( oradii );
-	vec2 opoint2    = opoint * opoint;
-	vec2 odir       = glm::normalize( opoint );
-	float odist2    = opoint2.x + opoint2.y;
-
-	float low    = iradii2.y * opoint2.x + iradii2.x * opoint2.y;
-	float idist2 = ((iradii2.x * iradii2.y) / low ) * odist2;
-
-	float rdist     = glm::sqrt( std::uniform_real_distribution<f32>( idist2, odist2 )( rng ) );
-	return odir * rdist;	
-}
-
-nv::vec2 nv::random::precise_hollow_ellipse_point( const vec2& iradii, const vec2& oradii )
-{
-	return fast_hollow_ellipse_point( iradii, oradii );
-}
-
-nv::vec3 nv::random::fast_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
-{
-	vec3 iradii2    = iradii * iradii;
-	vec3 opoint     = ellipsoid_edge( oradii );
-	vec3 opoint2    = opoint * opoint;
-	vec3 odir       = glm::normalize( opoint );
-	float odist2    = opoint2.x + opoint2.y + opoint2.z;
-
-	float low    = 
-		iradii2.y * iradii2.z * opoint2.x + 
-		iradii2.x * iradii2.z * opoint2.y +
-		iradii2.x * iradii2.y * opoint2.z;
-	float idist2 = ((iradii2.x * iradii2.y * iradii2.z) / low ) * odist2;
-
-	float odist3 = odist2 * glm::sqrt( odist2 );
-	float idist3 = idist2 * glm::sqrt( idist2 );
-
-	float rdist     = std::pow( std::uniform_real_distribution<f32>( idist3, odist3 )( rng ), 1.f/3.f );
-	return odir * rdist;	
-}
-
-nv::vec3 nv::random::precise_hollow_ellipsoid_point( const vec3& iradii, const vec3& oradii )
-{
-	return fast_hollow_ellipsoid_point( iradii, oradii );
-}
-
Index: /trunk/src/rogue/fov_recursive_shadowcasting.cc
===================================================================
--- /trunk/src/rogue/fov_recursive_shadowcasting.cc	(revision 318)
+++ /trunk/src/rogue/fov_recursive_shadowcasting.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -7,5 +7,5 @@
 #include "nv/rogue/fov_recursive_shadowcasting.hh"
 
-#include <nv/math.hh>
+#include "nv/core/math.hh"
 
 static int nv_rogue_rs_mult[4][8] = {
Index: unk/src/root.cc
===================================================================
--- /trunk/src/root.cc	(revision 318)
+++ 	(revision )
@@ -1,25 +1,0 @@
-// Copyright (C) 2012-2014 ChaosForge Ltd
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/root.hh"
-
-#include "nv/uid.hh"
-#include "nv/lua/lua_state.hh"
-
-void nv::root::destroy_object( object* o )
-{
-	destroy_children( o );
-	o->detach();
-	delete o;
-}
-
-void nv::root::destroy_children( object* o )
-{
-	while ( !o->m_children.empty() )
-	{
-		destroy_object( o->m_children.front() );
-	}
-}
Index: /trunk/src/sdl/sdl_audio.cc
===================================================================
--- /trunk/src/sdl/sdl_audio.cc	(revision 318)
+++ /trunk/src/sdl/sdl_audio.cc	(revision 319)
@@ -1,3 +1,3 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
+// Copyright (C) 2012-2014 ChaosForge Ltd
 // http://chaosforge.org/
 //
@@ -9,5 +9,5 @@
 #include "nv/lib/sdl.hh"
 #include "nv/lib/sdl_mixer.hh"
-#include "nv/logging.hh"
+#include "nv/core/logging.hh"
 
 using namespace nv;
Index: unk/src/time.cc
===================================================================
--- /trunk/src/time.cc	(revision 318)
+++ 	(revision )
@@ -1,100 +1,0 @@
-// Copyright (C) 2011 Kornel Kisielewicz
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/time.hh"
-
-#include "nv/logging.hh"
-
-#if NV_COMPILER == NV_MSVC
-#define WIN32_LEAN_AND_MEAN 
-#include <windows.h>
-#include <intrin.h>
-#pragma intrinsic(__rdtsc)
-#else
-#include <unistd.h>
-#include <sys/time.h>
-#endif
-
-#include <ctime>
-
-struct timer_impl
-{
-	timer_impl()
-	{
-		clock_zero = clock();
-#if NV_COMPILER == NV_MSVC
-		QueryPerformanceFrequency(&frequency);
-		QueryPerformanceCounter(&query_zero);
-#else
-		gettimeofday(&timeval_zero, NULL);
-#endif
-	}
-	clock_t clock_zero;
-#if NV_COMPILER == NV_MSVC
-	LARGE_INTEGER query_zero;
-	LARGE_INTEGER frequency;
-#else
-	struct timeval timeval_zero;
-#endif
-};
-
-static timer_impl zero_timer;
-
-nv::uint64 nv::get_ticks()
-{
-#if NV_COMPILER == NV_MSVC
-	return __rdtsc();
-#else
-	register long long ticks asm("eax") = 0;
-	asm volatile (".byte 15, 49" : : : "eax", "edx");
-	return static_cast<nv::uint64>( ticks );
-#endif
-}
-
-void nv::sleep( uint32 ms )
-{
-#if NV_COMPILER == NV_MSVC
-	Sleep( ms );
-#else
-	usleep( ms * 1000 );
-#endif
-}
-
-nv::uint32 nv::get_cpu_ms()
-{
-	return (uint32)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000.0 ) ) ;
-}
-
-nv::uint64 nv::get_cpu_us()
-{
-	return (uint64)( (f32)( clock() - zero_timer.clock_zero ) / ( (f32)CLOCKS_PER_SEC / 1000000.0 ) ) ;
-}
-
-nv::uint32 nv::get_system_ms()
-{
-#if NV_COMPILER == NV_MSVC
-	LARGE_INTEGER now;
-	QueryPerformanceCounter(&now);
-	LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart;
-	return (uint32) (1000.0 * result / (double) zero_timer.frequency.QuadPart);
-#else
-	struct timeval now;
-	gettimeofday(&now, NULL);
-	return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000+(now.tv_usec-zero_timer.timeval_zero.tv_usec)/1000 );
-#endif
-}
-
-nv::uint64 nv::get_system_us()
-{
-#if NV_COMPILER == NV_MSVC
-	LARGE_INTEGER now;
-	QueryPerformanceCounter(&now);
-	LONGLONG result = now.QuadPart - zero_timer.query_zero.QuadPart;
-	return (uint64) (1000000.0 * result / (double) zero_timer.frequency.QuadPart);
-#else
-	struct timeval now;
-	gettimeofday(&now, NULL);
-	return (uint32)( (now.tv_sec - zero_timer.timeval_zero.tv_sec)*1000000+(now.tv_usec - zero_timer.timeval_zero.tv_usec) );
-#endif
-}
Index: unk/src/uid.cc
===================================================================
--- /trunk/src/uid.cc	(revision 318)
+++ 	(revision )
@@ -1,52 +1,0 @@
-// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
-// http://chaosforge.org/
-//
-// This file is part of NV Libraries.
-// For conditions of distribution and use, see copyright notice in nv.hh
-
-#include "nv/uid.hh"
-
-using namespace nv;
-
-uid_store_raw::uid_store_raw()
-	: m_map(), m_current(0)
-{
-	
-}
-
-void* uid_store_raw::get( uid auid ) const
-{
-	map::const_iterator i = m_map.find( auid );
-	if ( i != m_map.end() )
-	{
-		return i->second;
-	}
-	return nullptr;
-}
-
-bool uid_store_raw::remove( uid auid )
-{
-	return m_map.erase( auid ) != 0;
-}
-
-void uid_store_raw::insert( void* o, uid auid )
-{
-	m_map[ auid ] = o;
-}
-
-uid uid_store_raw::insert( void* o )
-{
-	uid u = request_uid();
-	m_map[ u ] = o;
-	return u;
-}
-
-uid uid_store_raw::request_uid()
-{
-	return ++m_current;
-}
-
-uid_store_raw::~uid_store_raw()
-{
-	// no-op
-}
Index: /trunk/tests/cachebuf_test/nv_cachebuf_test.cc
===================================================================
--- /trunk/tests/cachebuf_test/nv_cachebuf_test.cc	(revision 318)
+++ /trunk/tests/cachebuf_test/nv_cachebuf_test.cc	(revision 319)
@@ -1,16 +1,12 @@
-#include <nv/interface/vertex_buffer.hh>
 #include <nv/gl/gl_device.hh>
 #include <nv/gfx/image.hh>
 #include <nv/interface/context.hh>
 #include <nv/interface/window.hh>
-#include <nv/interface/program.hh>
-#include <nv/interface/texture2d.hh>
-#include <nv/logging.hh>
-#include <nv/logger.hh>
+#include <nv/core/logging.hh>
+#include <nv/core/logger.hh>
 #include <glm/glm.hpp>
 #include <glm/gtc/matrix_transform.hpp>
 #include <glm/gtc/type_ptr.hpp>
-#include <nv/string.hh>
-#include <nv/interface/mesh.hh>
+#include <nv/core/string.hh>
 #include <cstdlib> // rand
 #include <ctime> // time
@@ -222,6 +218,7 @@
 	~application();
 protected:
-	nv::device* m_device;
-	nv::window* m_window;
+	nv::device*  m_device;
+	nv::context* m_context;
+	nv::window*  m_window;
 	nv::clear_state m_clear_state;
 	nv::render_state m_render_state;
@@ -230,6 +227,6 @@
 	std::vector<app_window>  m_windows;
 
-	nv::program* m_program;
-	nv::vertex_array* m_va;
+	nv::program       m_program;
+	nv::vertex_array  m_va;
 	unsigned int m_count;
 };
@@ -237,6 +234,7 @@
 application::application()
 {
-	m_device = new nv::gl_device();
-	m_window = m_device->create_window( 800, 600 );
+	m_device  = new nv::gl_device();
+	m_window  = m_device->create_window( 800, 600, false );
+	m_context = m_window->get_context();
 
 	m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
@@ -254,17 +252,17 @@
 	{ 
 		m_program   = m_device->create_program( nv::slurp( "cachebuf.vert" ), nv::slurp( "cachebuf.frag" ) );
-		m_va        = m_device->create_vertex_array();
-
-		#ifdef INDEXED_TEST
-		m_quad_cache = new gcache( m_device, nv::DYNAMIC_DRAW, 200, 200 );
-		m_va->set_index_buffer( m_quad_cache->get_index_buffer(), nv::USHORT, false );
-		nv::vertex_buffer* buffer = m_quad_cache->get_vertex_buffer();
-		#else
-		m_quad_cache = new gcache( m_device, nv::DYNAMIC_DRAW, 20, true );
-		nv::vertex_buffer* buffer = (nv::vertex_buffer*)m_quad_cache->get_buffer();
-		#endif
-
-		m_va->add_vertex_buffer( nv::slot::POSITION, buffer, nv::INT,   2, 0, sizeof( vertex ), false );
-		m_va->add_vertex_buffer( nv::slot::COLOR,    buffer, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
+		m_va        = m_context->create_vertex_array();
+
+		#ifdef INDEXED_TEST
+		m_quad_cache = new gcache( m_context, nv::DYNAMIC_DRAW, 200, 200 );
+		m_context->set_index_buffer( m_va, m_quad_cache->get_index_buffer(), nv::USHORT, false );
+		nv::buffer buffer = m_quad_cache->get_vertex_buffer();
+		#else
+		m_quad_cache = new gcache( m_context, nv::DYNAMIC_DRAW, 20, true );
+		nv::buffer buffer = m_quad_cache->get_buffer();
+		#endif
+
+		m_context->add_vertex_buffer( m_va, nv::slot::POSITION, buffer, nv::INT,   2, 0, sizeof( vertex ), false );
+		m_context->add_vertex_buffer( m_va, nv::slot::COLOR,    buffer, nv::FLOAT, 4, offset_of( &vertex::color ), sizeof( vertex ), false );
 	}
 	return true;
@@ -274,7 +272,6 @@
 {
 	int keypress = 0;
-	m_program->bind();
 	glm::mat4 projection = glm::ortho( 0.0f, 800.0f, 600.0f, 0.0f, -1.0f, 1.0f );
-	m_program->set_uniform( "nv_projection", glm::mat4(projection) );
+	m_device->set_uniform( m_program, "nv_projection", glm::mat4(projection) );
 
 	while(!keypress) 
@@ -287,15 +284,12 @@
 		{
 			#ifdef INDEXED_TEST
-			m_va->set_index_buffer( m_quad_cache->get_index_buffer() );
-			nv::vertex_buffer* buffer = m_quad_cache->get_vertex_buffer();
+			m_context->set_index_buffer( m_va, m_quad_cache->get_index_buffer(), nv::USHORT, false );
+			nv::buffer buffer = m_quad_cache->get_vertex_buffer();
 			#else
-			nv::vertex_buffer* buffer = (nv::vertex_buffer*)m_quad_cache->get_buffer();
+			nv::buffer buffer = m_quad_cache->get_buffer();
 			#endif
-			m_va->update_vertex_buffer( nv::slot::POSITION, buffer, false );
-			m_va->update_vertex_buffer( nv::slot::COLOR,    buffer, false );
 		}
 
 		m_window->get_context()->clear( m_clear_state );
-		m_program->bind();
 //		m_program->set_uniform( "tex", 0 );
 		#ifdef INDEXED_TEST
@@ -369,6 +363,6 @@
 	delete m_quad_cache;
 
-	delete m_program;
-	delete m_va;
+	m_device->release( m_program );
+	m_context->release( m_va );
 	delete m_window;
 	delete m_device;
Index: /trunk/tests/gui_test/nv_gui_test.cc
===================================================================
--- /trunk/tests/gui_test/nv_gui_test.cc	(revision 318)
+++ /trunk/tests/gui_test/nv_gui_test.cc	(revision 319)
@@ -2,6 +2,6 @@
 #include <nv/gui/gui_environment.hh>
 #include <nv/interface/context.hh>
-#include <nv/logging.hh>
-#include <nv/logger.hh>
+#include <nv/core/logging.hh>
+#include <nv/core/logger.hh>
 #include <cstdlib> // rand
 #include <ctime> // time
Index: /trunk/tests/md3_test/md3_test.cc
===================================================================
--- /trunk/tests/md3_test/md3_test.cc	(revision 318)
+++ /trunk/tests/md3_test/md3_test.cc	(revision 319)
@@ -1,6 +1,5 @@
-#include <nv/common.hh>
+#include <nv/core/common.hh>
 #include <iomanip>
 #include <nv/gfx/keyframed_mesh.hh>
-#include <nv/interface/vertex_buffer.hh>
 #include <nv/gl/gl_device.hh>
 #include <nv/gfx/image.hh>
@@ -10,10 +9,10 @@
 #include <nv/io/c_file_system.hh>
 #include <nv/formats/md3_loader.hh>
-#include <nv/profiler.hh>
-#include <nv/logging.hh>
-#include <nv/logger.hh>
-#include <nv/math.hh>
-#include <nv/time.hh>
-#include <nv/string.hh>
+#include <nv/core/profiler.hh>
+#include <nv/core/logging.hh>
+#include <nv/core/logger.hh>
+#include <nv/core/math.hh>
+#include <nv/core/time.hh>
+#include <nv/core/string.hh>
 #include <glm/gtx/rotate_vector.hpp>
 #include <glm/gtc/matrix_access.hpp>
@@ -68,5 +67,4 @@
 	void update( nv::uint32 ms, nv::program program )
 	{
-		m_mesh->update( ms );
 		m_mesh->update_animation( m_entry, ms );
 		m_mesh->update( program );
@@ -206,19 +204,19 @@
 
 			m_scene_state.set_model( model );
-			m_window->get_context()->draw( m_render_state, m_scene_state, m_program, m_legs->get_mesh() );
+			m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_program, m_legs->get_mesh()->get_vertex_array(), m_legs->get_mesh()->get_index_count() );
 
 			//model = m_legs->get_transform( "tag_torso", last_legs_frame, legs_frame, legs_interpolate );
 			model = m_legs->get_transform( 0 );
 			m_scene_state.set_model( model );
-			m_window->get_context()->draw( m_render_state, m_scene_state, m_program, m_torso->get_mesh() );
+			m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_program, m_torso->get_mesh()->get_vertex_array(), m_torso->get_mesh()->get_index_count() );
 
 			glm::mat4 head = model * m_torso->get_transform( 0 ); //, last_torso_frame, torso_frame, torso_interpolate );
 			m_scene_state.set_model( head );
-			m_window->get_context()->draw( m_render_state, m_scene_state, m_program, m_head->get_mesh() );
+			m_window->get_context()->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_program, m_head->get_mesh()->get_vertex_array(), m_head->get_mesh()->get_index_count() );
 
 			glm::mat4 weapon = model * m_torso->get_transform( 2 ); //, last_torso_frame, torso_frame, torso_interpolate );
 			m_scene_state.set_model( weapon );
 			m_context->bind( m_diffuse_weapon, nv::TEX_DIFFUSE );
-			m_context->draw( m_render_state, m_scene_state, m_program, m_weapon->get_mesh() );
+			m_context->draw( nv::TRIANGLES, m_render_state, m_scene_state, m_program, m_weapon->get_mesh()->get_vertex_array(), m_weapon->get_mesh()->get_index_count() );
 
 		}
