Changeset 520


Ignore:
Timestamp:
10/03/16 17:45:46 (9 years ago)
Author:
epyon
Message:
  • ecs updates
  • animation updates
  • ragdoll manager
  • lua has own random engine
  • several minor fixes
  • particle engine/particle group
  • shitload of other stuff
  • bullet world
Location:
trunk
Files:
16 added
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/ecs/ecs.hh

    r499 r520  
    1717#include <nv/stl/string.hh>
    1818#include <nv/stl/handle.hh>
     19#include <nv/core/types.hh>
    1920
    2021namespace nv
     
    122123
    123124
    124                 template < typename HANDLE = handle<> >
     125                template < typename Handle = handle<>, typename Time = f32 >
    125126                class ecs
    126127                {
    127128                public:
    128                         typedef HANDLE handle_type;
     129                        typedef Time   time_type;
     130                        typedef Handle handle_type;
    129131
    130132                        typedef uint32 message_type;
     
    134136                                message_type type;
    135137                                handle_type  entity;
    136                                 uint8        payload[128 - sizeof( uint32 ) - sizeof( handle_type )];
     138                                time_type    time;
     139                                uint8        payload[128 - sizeof( uint32 ) - sizeof( handle_type ) - sizeof( time_type )];
    137140                        };
    138141
    139                         class component_interface
     142                        struct message_compare_type
     143                        {
     144                                bool operator()( const message& l, const message& r )
     145                                {
     146                                        return l.time > r.time;
     147                                }
     148                        };
     149
     150                        class receiver_interface
    140151                        {
    141152                        public:
     153                                virtual void update( time_type dtime ) = 0;
    142154                                virtual bool handle_message( const message& ) = 0;
    143155                                virtual void clear() = 0;
     156                        };
     157
     158                        class component_interface : public receiver_interface
     159                        {
     160                        public:
    144161                                virtual void remove( handle_type h ) = 0;
     162                                virtual void* get_raw( handle_type h ) = 0;
     163                                virtual const void* get_raw( handle_type h ) const = 0;
    145164                        };
    146165
     
    153172                        }
    154173
    155                         template < typename COMPONENT >
    156                         void register_component( string_view /*name*/, component_interface* c )
     174                        void register_receiver( string_view /*name*/, receiver_interface* c )
     175                        {
     176                                m_receivers.push_back( c );
     177                        }
     178
     179                        template < typename Component >
     180                        void register_component( string_view name, component_interface* c )
    157181                        {
    158182                                m_components.push_back( c );
     183                                register_receiver( name, c );
     184                                m_component_map[thash64::create<Component>()] = c;
    159185                        }
    160186
    161187                        bool dispatch( const message& m )
    162188                        {
    163                                 for ( auto c : m_components )
     189                                for ( auto c : m_receivers )
    164190                                        c->handle_message( m );
    165191                                return true;
     
    169195                        bool dispatch( handle_type h, Args&&... args )
    170196                        {
    171                                 message m{ Payload::message_id, h };
     197                                message m{ Payload::message_id, h, time_type(0) };
    172198                                new( &m.payload ) Payload{ nv::forward<Args>( args )... };
    173199                                return dispatch( m );
    174200                        }
    175201
     202                        bool queue( const message& m )
     203                        {
     204                                push_event( m );
     205                                return true;
     206                        }
     207
     208                        template < typename Payload, typename ...Args >
     209                        bool queue( handle_type h, time_type delay, Args&&... args )
     210                        {
     211                                message m{ Payload::message_id, h, m_time + delay };
     212                                new( &m.payload ) Payload{ nv::forward<Args>( args )... };
     213                                return queue( m );
     214                        }
     215
     216
    176217                        handle_type create()
    177218                        {
     
    179220                        }
    180221
     222                        void update( time_type dtime )
     223                        {
     224                                if ( dtime == time_type(0) ) return;
     225                                m_time += dtime;
     226                                while ( !m_queue.empty() && m_queue.front().time <= m_time )
     227                                {
     228                                        message msg = m_queue.front();
     229                                        pop_event();
     230                                        dispatch( msg );
     231                                }
     232
     233                                for ( auto c : m_receivers )
     234                                        c->update( dtime );
     235                        }
     236
     237                        time_type update_step()
     238                        {
     239                                time_type before = m_time;
     240                                if ( !m_queue.empty() )
     241                                {
     242                                        message msg = m_queue.front();
     243                                        m_time = msg.time;
     244                                        pop_event();
     245                                        dispatch( msg );
     246                                        if ( before != m_time )
     247                                                for ( auto c : m_receivers )
     248                                                        c->update( m_time - before );
     249                                }
     250                                return m_time;
     251                        }
     252
     253                        time_type get_time() const { return m_time; }
     254
     255                        bool events_pending() const
     256                        {
     257                                return !m_queue.empty();
     258                        }
     259
     260                        const message& top_event() const
     261                        {
     262                                return m_queue.front();
     263                        }
     264
     265                        void reset_events()
     266                        {
     267                                m_queue.clear();
     268                                m_time = time_type(0);
     269                        }
     270
    181271                        void clear()
    182272                        {
    183                                 for ( auto c : m_components )
     273                                reset_events();
     274                                for ( auto c : m_receivers )
    184275                                        c->clear();
    185276                                m_handles.clear();
     
    198289                        }
    199290
     291                        template < typename Component >
     292                        Component* get( handle_type h )
     293                        {
     294                                return static_cast< Component* >( m_component_map[thash64::create< Component >()]->get_raw( h ) );
     295                        }
     296
     297                        template < typename Component >
     298                        const Component* get( handle_type h ) const
     299                        {
     300                                return static_cast<const Component*>( m_component_map[thash64::create< Component >()]->get_raw( h ) );
     301                        }
     302
    200303                protected:
    201                         handle_manager< handle_type > m_handles;
    202                         vector< component_interface* > m_components;
     304                        void push_event( const message& msg )
     305                        {
     306                                m_queue.push_back( msg );
     307                                push_heap( m_queue.begin(), m_queue.end(), m_compare );
     308                        }
     309
     310                        void pop_event()
     311                        {
     312                                pop_heap( m_queue.begin(), m_queue.end(), m_compare );
     313                                m_queue.pop_back();
     314                        }
     315
     316                        handle_manager< handle_type >               m_handles;
     317                        vector< component_interface* >              m_components;
     318                        vector< receiver_interface* >               m_receivers;
     319                        hash_store< thash64, component_interface* > m_component_map;
     320                        time_type                                   m_time = time_type(0);
     321                        vector< message >                           m_queue;
     322                        message_compare_type                        m_compare;
    203323                };
    204324
     
    210330                        typedef typename ecs_type::message             message_type;
    211331                        typedef typename ecs_type::handle_type         handle_type;
     332                        typedef typename ecs_type::time_type           time_type;
    212333                        typedef index_table< handle_type >             index_table_type;
    213334                        typedef COMPONENT                              value_type;
     
    252373                        }
    253374
     375                        virtual void update( time_type /*dtime*/ )
     376                        {
     377                                // no-op
     378                        }
     379
    254380                        virtual void clear()
    255381                        {
     382                                for ( uint32 i = 0; i < m_index.size(); ++i )
     383                                        destroy( &m_data[i] );
    256384                                m_index.clear();
    257385                                m_data.clear();
     
    270398                        }
    271399
     400                        void* get_raw( handle_type h )
     401                        {
     402                                index_type i = m_index.get( h );
     403                                return i >= 0 ? &( m_data[unsigned( i )] ) : nullptr;
     404                        }
     405
     406                        const void* get_raw( handle_type h ) const
     407                        {
     408                                index_type i = m_index.get( h );
     409                                return i >= 0 ? &( m_data[unsigned( i )] ) : nullptr;
     410                        }
     411
     412
    272413                        virtual void remove( handle_type h )
    273414                        {
     415                                value_type* v = get( h );
     416                                if ( v == nullptr ) return;
     417                                destroy( v );
    274418                                index_type dead_eindex = m_index.remove_swap( h );
    275419                                if ( dead_eindex == -1 ) return;
     
    281425                        }
    282426
    283                         virtual void remove( index_type i )
    284                         {
    285                                 index_type dead_eindex = m_index.remove_swap( i );
    286                                 if ( dead_eindex == -1 ) return;
    287                                 if ( dead_eindex != static_cast<index_type>( m_data.size() - 1 ) )
    288                                 {
    289                                         m_data[unsigned( dead_eindex )] = move( m_data.back() );
    290                                 }
    291                                 m_data.pop_back();
     427                        virtual void destroy( value_type* )
     428                        {
     429                                // cleanup
    292430                        }
    293431
     
    295433                        {
    296434                                return true;
     435                        }
     436
     437                        ~component()
     438                        {
     439                                clear();
    297440                        }
    298441
     
    318461                };
    319462
    320                 template < typename COMPONENTS >
    321                 class system
     463                template < typename ECS >
     464                class receiver : public ECS::receiver_interface
    322465                {
    323 
     466                public:
     467                        typedef ECS                                    ecs_type;
     468                        typedef typename ecs_type::message             message_type;
     469                        typedef typename ecs_type::handle_type         handle_type;
     470                        typedef typename ecs_type::time_type           time_type;
     471
     472                        receiver( ecs_type& a_ecs, string_view a_name ) : m_ecs( a_ecs )
     473                        {
     474                                m_ecs.register_receiver( a_name, this );
     475                        }
     476                        virtual void update( time_type /*dtime*/ )
     477                        {
     478                                // no-op
     479                        }
     480
     481                        virtual void clear()
     482                        {
     483                                // no-op
     484                        }
     485                        virtual bool handle_message( const message_type& )
     486                        {
     487                                return false;
     488                        }
     489                protected:
     490                        ecs_type&        m_ecs;
    324491                };
    325 
    326492        }
    327493
  • trunk/nv/engine/animation.hh

    r509 r520  
    109109                        return m_current_state;
    110110                }
    111                 void add_transition( const animator_transition_data& data, uint32 source )
    112                 {
     111                float add_transition( const animator_transition_data& data, uint32 source )
     112                {
     113                        float duration = 0.0f;
    113114                        if ( m_transitions.size() > 0 )
    114115                        {
     116                                for ( const auto& t : m_transitions )
     117                                        duration += t.duration - t.time;
    115118                                auto& last = m_transitions.back();
    116119                                if ( last.target == source && data.target == last.source )
     
    118121                                        nv::swap( last.target, last.source );
    119122                                        last.time = last.duration - last.time;
    120                                         return;
     123                                        /* this duration might be inaccurate? */
     124                                        return duration;
    121125                                }
    122126                        }
    123127                        m_transitions.push_back( animator_transition_instance( data, source ) );
     128                        return duration + m_transitions.back().duration;
    124129                }
    125130                void reset()
     
    198203                }
    199204               
    200                 void queue_event( const animator_data* data, shash64 name )
    201                 {
     205                float queue_event( const animator_data* data, shash64 name )
     206                {
     207                        float duration = 0.0f;
    202208                        for ( uint32 i = 0; i < m_layers.size(); ++i )
    203209                                // what about activating nonactive layers?
     
    209215                                        if ( it != state.transitions.end() )
    210216                                        {
    211                                                 m_layers[i].add_transition( it->second, uint32( last_state ) );
     217                                                float d = m_layers[i].add_transition( it->second, uint32( last_state ) );
     218                                                duration = nv::max( d, duration );
    212219                                        }
    213220                                }
    214                 }
    215 
    216                 void update( const animator_data* data, float dtime )
     221                        return duration;
     222                }
     223
     224                void update( const animator_data* data, float dtime, bool do_delocalize = true )
    217225                {
    218226                        for ( uint32 i = 0; i < m_layers.size(); ++i )
     
    235243                                }
    236244
     245                        if ( do_delocalize )
     246                                m_transforms.delocalize( data->poses->get_tree() );
     247                }
     248                void delocalize( const animator_data* data )
     249                {
    237250                        m_transforms.delocalize( data->poses->get_tree() );
    238251                }
     
    275288                }
    276289
    277         protected:
     290                const skeleton_transforms& stored()
     291                {
     292                        return m_stored;
     293                }
     294
     295                void store()
     296                {
     297                        m_stored.assign( m_transforms );
     298                }
     299
     300
     301//      protected:
    278302
    279303                void animate_layer( const animator_layer_data& layer, const animator_transition_instance& transition, pose_data_set* pose_data, float t )
     
    349373                }
    350374
     375
    351376                vector< animator_layer_instance > m_layers;
    352377                skeleton_transforms               m_transforms;
    353 
    354 
     378                skeleton_transforms               m_stored;
    355379        };
    356380
  • trunk/nv/engine/default_resource_manager.hh

    r518 r520  
    2626#include <nv/engine/model_manager.hh>
    2727#include <nv/engine/particle_manager.hh>
     28#include <nv/engine/ragdoll_manager.hh>
    2829
    2930namespace nv
     
    5859                const type_database* get_type_db() { return m_lua->get_type_data()->get_type_database(); }
    5960
    60                 virtual void initialize( lua::state* lua );
     61                virtual void initialize( lua::state* lua, physics_world* world );
    6162                virtual void reload_data();
    6263        protected:
     
    7374                model_manager*         m_models;
    7475                particle_manager*      m_particles;
     76                ragdoll_manager*       m_ragdolls;
    7577        };
    7678
  • trunk/nv/engine/light.hh

    r508 r520  
    3333        {
    3434                vec3 position;
    35                 vec3 color;
     35                vec4 color;
    3636                vec4 direction;
    3737                float angle;
     
    4343                light_data() : color( 1.0 ), direction( 0.0f, -1.0f, 0.0f, 1.0f ), angle( 0.6f ), umbra_angle( 0.2f ), range( 4.0 ), smooth( 0 ), shadow( shadow_type::ACTIVE ) {}
    4444                light_data( const vec3& a_position, const vec3& a_color, shadow_type type )
    45                         : position( a_position ), color( a_color )
     45                        : position( a_position ), color( a_color, 1.0f )
    4646                        , direction( 0.0f, -1.0f, 0.0f, 1.0f ), angle( 0.6f ), umbra_angle( 0.2f ), range( 4.0 ), smooth( 0 ), shadow( type ) {}
    4747                light_data( const light_data& ) = default;
    4848        };
     49       
     50        NV_RTTI_DECLARE( nv::light_data )
    4951
    5052        struct light_data_distance_compare
     
    8991
    9092                                m_blocks[i].position  = vec4( lights[i]->position, 1.0f );
    91                                 m_blocks[i].color     = vec4( lights[i]->color, 1.0f );
     93                                m_blocks[i].color     = vec4( vec3( lights[i]->color ) * lights[i]->color.w, 1.0f );
    9294                                m_blocks[i].direction = lights[i]->direction;
    9395                                m_blocks[i].params    = vec4( lights[i]->angle, lights[i]->umbra_angle, lights[i]->range, 1.0f );
  • trunk/nv/engine/particle_engine.hh

    r519 r520  
    1 // Copyright (C) 2014-2015 ChaosForge Ltd
     1// Copyright (C) 2014-2016 ChaosForge Ltd
    22// http://chaosforge.org/
    33//
     
    1616#include <nv/gfx/texture_atlas.hh>
    1717#include <nv/core/resource.hh>
     18#include <nv/core/random.hh>
    1819#include <nv/interface/scene_node.hh>
    1920#include <nv/interface/context.hh>
     21#include <nv/engine/particle_group.hh>
    2022
    2123namespace nv
     
    2729        struct particle_emitter_data;
    2830        struct particle_affector_data;
    29         struct particle;
    3031
    31         typedef void( *particle_emitter_func )( const particle_emitter_data*, particle*, uint32 count );
     32        typedef void( *particle_emitter_func )( random_base* r, const particle_emitter_data*, particle*, uint32 count );
    3233        typedef void( *particle_affector_func )( const particle_affector_data*, particle*, float factor, uint32 count );
    3334        typedef bool( *particle_affector_init_func )( lua::table_guard* table, particle_affector_data* data );
     
    3738                particle_affector_func      process;
    3839                particle_affector_init_func init;
    39         };
    40 
    41         enum class particle_orientation
    42         {
    43                 POINT,
    44                 ORIENTED,
    45                 ORIENTED_COMMON,
    46                 PERPENDICULAR,
    47                 PERPENDICULAR_COMMON,
    48         };
    49         enum class particle_origin
    50         {
    51                 CENTER,
    52                 TOP_LEFT,
    53                 TOP_CENTER,
    54                 TOP_RIGHT,
    55                 CENTER_LEFT,
    56                 CENTER_RIGHT,
    57                 BOTTOM_LEFT,
    58                 BOTTOM_CENTER,
    59                 BOTTOM_RIGHT,
    60         };
    61 
    62         struct particle_vtx
    63         {
    64                 vec3 position;
    65                 vec2 texcoord;
    66                 vec4 color;
    67         };
    68 
    69         struct particle_quad
    70         {
    71                 particle_vtx data[6];
    72         };
    73 
    74         struct particle
    75         {
    76                 vec3   position;
    77                 vec4   color;
    78                 vec3   velocity;
    79                 vec2   size;
    80                 vec2   tcoord_a;
    81                 vec2   tcoord_b;
    82                 float  rotation;
    83                 float  lifetime;
    84                 float  death;
    8540        };
    8641
     
    12782        };
    12883
    129         struct particle_system_data
     84        struct particle_system_data : particle_group_settings
    13085        {
    13186                uint32 quota;
    132                 vec3   common_up;
    133                 vec3   common_dir;
    134                 bool   accurate_facing;
    135                 particle_orientation   orientation;
    136                 particle_origin        origin;
    13787                uint32                 emitter_count;
    13888                particle_emitter_data  emitters[MAX_PARTICLE_EMITTERS];
     
    14191        };
    14292
    143         struct particle_system_group_tag {};
    144         typedef handle< uint32, 16, 16, particle_system_group_tag > particle_system_group;
    14593        struct particle_system_tag {};
    14694        typedef handle< uint32, 16, 16, particle_system_tag > particle_system;
     
    15199                particle_emitter_info emitters[MAX_PARTICLE_EMITTERS];
    152100
    153                 uint32                count;
    154                 vec2                  texcoords[2];
    155                 particle_system_group group;
     101                uint32         count;
     102                vec2           texcoords[2];
     103                particle_group group;
    156104
    157105                const particle_system_data*    data;
    158         };
    159 
    160         struct particle_system_group_info
    161         {
    162                 uint32                count;
    163                 uint32                quota;
    164                 vertex_array          vtx_array;
    165                 buffer                vtx_buffer;
    166                 bool                  local;
    167                 particle_quad*        quads;
    168                 uint32                ref_counter;
    169         };
    170 
    171         struct particle_render_data
    172         {
    173                 uint32                count;
    174                 vertex_array          vtx_array;
    175106        };
    176107
     
    178109
    179110NV_RTTI_DECLARE_NAME( nv::particle_system_data, "particle_system_data" )
    180 NV_RTTI_DECLARE_NAME( nv::particle_orientation, "particle_orientation" )
    181 NV_RTTI_DECLARE_NAME( nv::particle_origin,      "particle_origin" )
    182111
    183 namespace nv {
     112namespace nv
     113{
    184114
    185115        class particle_engine
    186116        {
    187117        public:
    188                 particle_engine( context* a_context, bool debug_data = false );
     118                particle_engine( context* a_context, random_base* rng, particle_group_manager* groups, bool debug_data = false );
    189119                void reset();
    190                 void prepare( particle_system_group group );
    191                 particle_system_group create_group( uint32 max_particles );
    192                 particle_system create_system( resource< particle_system_data > rdata, particle_system_group group );
    193                 particle_system create_system( const particle_system_data* data, particle_system_group group );
    194                 void release( particle_system_group group );
     120                void prepare( particle_group group );
     121                particle_group create_group( uint32 max_particles );
     122                particle_system create_system( resource< particle_system_data > rdata, particle_group group );
     123                particle_system create_system( const particle_system_data* data, particle_group group );
     124                void release( particle_group group );
    195125                void release( particle_system system );
    196126                void update( particle_system system, transform model, float dtime );
     
    205135                static const vector< particle_emitter_func >* get_debug_emitter_list() { return m_debug_emitter_list; }
    206136                static const vector< particle_affector_func >* get_debug_affector_list() { return m_debug_affector_list; }
    207                 static const type_entry* get_debug_type( particle_affector_init_func f );
    208                 static void register_types( type_database* db );
    209                 particle_render_data get_render_data( particle_system_group group );
     137                static const type_entry* get_debug_type( particle_affector_func f );
     138                static void register_types( type_database* db, bool debug_data = false );
     139                particle_render_data get_render_data( particle_group group );
     140                particle_group_manager* get_particle_manager() { return m_pgm; }
    210141                ~particle_engine();
    211142        private:
     
    213144                void register_standard_emitters();
    214145                void register_standard_affectors();
    215                 void generate_data( particle_system_info* info, const scene_state& s );
    216146                void destroy_particles( particle_system_info* info, float dtime );
    217147                void create_particles( particle_system_info* info, transform tr, float dtime );
     
    219149                void update_emitters( particle_system_info* info, float dtime );
    220150
     151                particle_group_manager* m_pgm;
    221152                context* m_context;
     153                random_base* m_rng;
    222154
    223155                handle_store< particle_system_info, particle_system >             m_systems;
    224                 handle_store< particle_system_group_info, particle_system_group > m_groups;
    225156
    226157                static hash_store< shash64, particle_emitter_func >          m_emitters;
  • trunk/nv/gfx/debug_draw.hh

    r509 r520  
    3737                void push_aabox( const vec3& a, const vec3& b, const vec3& color );
    3838                void push_gizmo( const nv::transform& tr, float length );
     39                void push_wire_capsule( const transform& tr, float radius, float height );
    3940                ~debug_data();
    4041        private:
  • trunk/nv/gfx/mesh_creator.hh

    r503 r520  
    1010#include <nv/common.hh>
    1111#include <nv/stl/math.hh>
     12#include <nv/core/aabb.hh>
    1213#include <nv/interface/mesh_data.hh>
    1314
     
    2223                        initialize();
    2324                }
     25
     26                aabb calculate_aabb();
    2427
    2528                // assumes that position and normal is vec3, tangent is vec4
  • trunk/nv/gfx/skeleton_instance.hh

    r491 r520  
    1010#include <nv/common.hh>
    1111#include <nv/stl/array.hh>
     12#include <nv/core/logging.hh>
    1213#include <nv/interface/context.hh>
    1314#include <nv/interface/mesh_data.hh>
     
    126127                }
    127128
     129                void delocalize( const data_node_tree& node_data, const array_view< bool >& mask )
     130                {
     131                        for ( uint32 n = 0; n < node_data.size(); ++n )
     132                                if ( node_data[n].parent_id == -1 )
     133                                        delocalize_rec( node_data, n, transform(), mask );
     134                }
     135
    128136                void delocalize_rec( const data_node_tree& node_data, uint32 id, const transform& parent );
     137                void delocalize_rec( const data_node_tree& node_data, uint32 id, const transform& parent, const array_view< bool >& mask );
    129138
    130139//      protected:
     
    194203
    195204
    196         protected:
     205//      protected:
    197206
    198207                dynamic_array< mat4 >      m_matrix;
  • trunk/nv/gl/gl_context.hh

    r503 r520  
    4141                virtual void release( vertex_array va );
    4242                virtual void release( framebuffer f );
     43                virtual image_data* dump_image( image_format f, image_data* reuse );
    4344                virtual const framebuffer_info* get_framebuffer_info( framebuffer f ) const;
    4445
  • trunk/nv/image/miniz.hh

    r484 r520  
    1717
    1818        void *miniz_decompress( const void *source_buf, size_t source_buf_len, size_t *out_len, bool parse_header );
    19 
     19        int miniz_compress( unsigned char *pDest, unsigned long *pDest_len, const unsigned char *pSource, unsigned long source_len, int level );
     20        unsigned long miniz_bound( unsigned long source_len );
    2021
    2122}
  • trunk/nv/interface/context.hh

    r506 r520  
    159159                virtual void release( texture t ) { m_device->release( t ); }
    160160                virtual void release( buffer b ) { m_device->release( b ); }
     161
     162                virtual image_data* dump_image( image_format f, image_data* reuse ) = 0;
    161163
    162164                virtual texture create_texture( texture_type type, ivec2 size, image_format aformat, sampler asampler, const void* data = nullptr ) = 0;
  • trunk/nv/lua/lua_aux.hh

    r503 r520  
    99
    1010#include <nv/lua/lua_state.hh>
     11#include <nv/core/random.hh>
    1112
    1213namespace nv
     
    1415        namespace lua
    1516        {
     17                random& rng();
    1618                void register_aux( lua::state* state );
    1719        }
  • trunk/nv/stl/container/random_access.hh

    r435 r520  
    9999                inline void fill( const value_type& value )
    100100                {
    101                         fill_n( iterator( Super::data() ), iterator( Super::data() + this->size() ), value );
     101                        ::nv::fill( iterator( Super::data() ), iterator( Super::data() + this->size() ), value );
    102102                }
    103103
  • trunk/nv_wx.lua

    r466 r520  
    11assert( NV_RUNTIME == "dcrt" )
     2
     3project "*"
     4        includedirs {
     5                "D:/Libraries/wxwidgets/include/msvc/",
     6                "D:/Libraries/wxwidgets/include/",
     7        }
     8        libdirs { "D:/Libraries/wxwidgets/lib/vc140_dll" }
     9        defines { "__WXMSW__", "_UNICODE", "WXUSINGDLL", "wxMSVC_VERSION_AUTO" }
    210
    311project "nv-wx"
     
    1119        links { "nv-core", "nv-gl", "nv-formats", "nv-lua", "nv-lib", "nv-io", "nv-gfx", "nv-sdl" }
    1220
    13 solution "*"
    14         includedirs {
    15                 "D:/Libraries/wxwidgets/include/msvc/",
    16                 "D:/Libraries/wxwidgets/include/",
    17         }
    18         libdirs { "D:/Libraries/wxwidgets/lib/vc140_dll" }
    19         defines { "__WXMSW__", "_UNICODE", "WXUSINGDLL", "wxMSVC_VERSION_AUTO" }
  • trunk/src/core/library.cc

    r438 r520  
    1111#   include <windows.h>
    1212#   define NV_LIB_EXT ".dll"
    13 #   define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryEx( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) )
     13#   define NV_LIB_OPEN( name ) static_cast<void*>( LoadLibraryExA( name, NULL, LOAD_WITH_ALTERED_SEARCH_PATH ) )
    1414#   define NV_LIB_GET( handle, name ) reinterpret_cast<void*>( GetProcAddress( static_cast<HMODULE>( handle ), name ) )
    1515#   define NV_LIB_CLOSE( handle ) ( FreeLibrary( static_cast<HMODULE>( handle ) ) != 0 )
  • trunk/src/curses/curses_terminal.cc

    r514 r520  
    131131        }
    132132
     133        // if result is a typable char from the 0..9 range
     134        if ( result >= 0x108 && result <= 0x108 + 12 )
     135        {
     136                kevent.key.code = static_cast<nv::key_code>( nv::KEY_F1 + result - 0x108 - 1 );
     137        }
     138
    133139        // other recognized codes
    134140        switch ( result )
  • trunk/src/engine/default_resource_manager.cc

    r519 r520  
    1111default_resource_manager::default_resource_manager( context* context, bool clear_material_paths )
    1212{
    13         m_images        = register_resource_handler< image_data >( new image_manager );
    14         m_meshes        = register_resource_handler< data_channel_set >( new mesh_manager );
    15         m_binds         = register_resource_handler< animator_bind_data >( new animator_bind_manager );
    16         m_animators     = register_resource_handler< animator_data >( new animator_manager );
    17         m_materials     = register_resource_handler< material >( new material_manager( clear_material_paths ) );
    18         m_programs      = register_resource_handler< program >( new program_manager( context ) );
    19         m_gpu_meshes    = register_resource_handler< gpu_mesh >( new gpu_mesh_manager( context, m_meshes ) );
    20         m_mesh_datas    = register_resource_handler< mesh_data >( new mesh_data_manager( m_meshes ) );
     13        m_images = register_resource_handler< image_data >( new image_manager );
     14        m_meshes = register_resource_handler< data_channel_set >( new mesh_manager );
     15        m_binds = register_resource_handler< animator_bind_data >( new animator_bind_manager );
     16        m_animators = register_resource_handler< animator_data >( new animator_manager );
     17        m_materials = register_resource_handler< material >( new material_manager( clear_material_paths ) );
     18        m_programs = register_resource_handler< program >( new program_manager( context ) );
     19        m_gpu_meshes = register_resource_handler< gpu_mesh >( new gpu_mesh_manager( context, m_meshes ) );
     20        m_mesh_datas = register_resource_handler< mesh_data >( new mesh_data_manager( m_meshes ) );
    2121        m_gpu_materials = register_resource_handler< gpu_material >( new gpu_material_manager( context, m_materials, m_images ) );
    22         m_models        = register_resource_handler< model >( new model_manager( this, m_binds, m_mesh_datas ) );
    23         m_particles     = register_resource_handler< particle_system_data >( new particle_manager );
     22        m_models = register_resource_handler< model >( new model_manager( this, m_binds, m_mesh_datas ) );
     23        m_particles = register_resource_handler< particle_system_data >( new particle_manager );
     24        m_ragdolls = register_resource_handler< ragdoll_data >( new ragdoll_manager( m_models ) );
    2425}
    2526
    26 void default_resource_manager::initialize( lua::state* lua )
     27void default_resource_manager::initialize( lua::state* lua, physics_world* world )
    2728{
    2829        m_lua = lua;
     
    7273        m_models->initialize( lua );
    7374        m_particles->initialize( lua );
     75        m_ragdolls->initialize( lua );
     76        m_ragdolls->initialize( world );
    7477}
    7578
  • trunk/src/engine/particle_engine.cc

    r519 r520  
    1 // Copyright (C) 2014-2015 ChaosForge Ltd
     1// Copyright (C) 2014-2016 ChaosForge Ltd
    22// http://chaosforge.org/
    33//
     
    2626using namespace nv;
    2727
    28 static void nv_particle_emitter_point( const particle_emitter_data*, particle* p, uint32 count )
     28static void nv_particle_emitter_point( random_base*, const particle_emitter_data*, particle* p, uint32 count )
    2929{
    3030        for ( uint32 i = 0; i < count; ++i )
     
    3434}
    3535
    36 static void nv_particle_emitter_box( const particle_emitter_data* pe, particle* p, uint32 count )
    37 {
    38         random& r = random::get();
    39         for ( uint32 i = 0; i < count; ++i )
    40         {
    41                 p[i].position =
    42                         r.frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir +
    43                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
    44                         r.frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir;
    45         }
    46 }
    47 
    48 static void nv_particle_emitter_cylinder( const particle_emitter_data* pe, particle* p, uint32 count )
    49 {
    50         random& r = random::get();
    51         for ( uint32 i = 0; i < count; ++i )
    52         {
    53                 vec2 rellipse( r.disk_point( pe->precise ) * pe->extents[0] );
     36static void nv_particle_emitter_box( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     37{
     38        for ( uint32 i = 0; i < count; ++i )
     39        {
     40                p[i].position =
     41                        r->frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir +
     42                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
     43                        r->frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir;
     44        }
     45}
     46
     47static void nv_particle_emitter_cylinder( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     48{
     49        for ( uint32 i = 0; i < count; ++i )
     50        {
     51                vec2 rellipse( r->disk_point( pe->precise ) * pe->extents[0] );
    5452                p[i].position =
    5553                        rellipse.x * pe->cdir +
    56                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     54                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    5755                        rellipse.y * pe->odir;
    5856        }
    5957}
    6058
    61 static void nv_particle_emitter_sphere( const particle_emitter_data* pe, particle* p, uint32 count )
    62 {
    63         random& r = random::get();
    64         for ( uint32 i = 0; i < count; ++i )
    65         {
    66                 vec3 rsphere = r.sphere_point( pe->precise ) * pe->extents[0];
     59static void nv_particle_emitter_sphere( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     60{
     61        for ( uint32 i = 0; i < count; ++i )
     62        {
     63                vec3 rsphere = r->sphere_point( pe->precise ) * pe->extents[0];
    6764                p[i].position =
    6865                        rsphere.x * pe->cdir +
     
    7269}
    7370
    74 static void nv_particle_emitter_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count )
    75 {
    76         random& r = random::get();
    77         for ( uint32 i = 0; i < count; ++i )
    78         {
    79                 vec2 rellipse = r.ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise );
     71static void nv_particle_emitter_cylindroid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     72{
     73        for ( uint32 i = 0; i < count; ++i )
     74        {
     75                vec2 rellipse = r->ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise );
    8076                p[i].position =
    8177                        rellipse.x * pe->cdir +
    82                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     78                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    8379                        rellipse.y * pe->odir;
    8480        }
    8581}
    8682
    87 static void nv_particle_emitter_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count )
    88 {
    89         random& r = random::get();
    90         for ( uint32 i = 0; i < count; ++i )
    91         {
    92                 vec3 rsphere = r.ellipsoid_point( pe->hextents, pe->precise );
     83static void nv_particle_emitter_ellipsoid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     84{
     85        for ( uint32 i = 0; i < count; ++i )
     86        {
     87                vec3 rsphere = r->ellipsoid_point( pe->hextents, pe->precise );
    9388                p[i].position =
    9489                        rsphere.x * pe->cdir +
     
    9893}
    9994
    100 static void nv_particle_emitter_hollow_cylinder( const particle_emitter_data* pe, particle* p, uint32 count )
    101 {
    102         random& r = random::get();
    103         for ( uint32 i = 0; i < count; ++i )
    104         {
    105                 vec2 rellipse = r.hollow_disk_point(
     95static void nv_particle_emitter_hollow_cylinder( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     96{
     97        for ( uint32 i = 0; i < count; ++i )
     98        {
     99                vec2 rellipse = r->hollow_disk_point(
    106100                        pe->ihextents[0],
    107101                        pe->hextents[0],
     
    109103                p[i].position =
    110104                        rellipse.x * pe->cdir +
    111                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     105                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    112106                        rellipse.y * pe->odir;
    113107        }
    114108}
    115109
    116 static void nv_particle_emitter_hollow_sphere( const particle_emitter_data* pe, particle* p, uint32 count )
    117 {
    118         random& r = random::get();
    119         for ( uint32 i = 0; i < count; ++i )
    120         {
    121                 vec3 rellipse = r.hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise );
     110static void nv_particle_emitter_hollow_sphere( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     111{
     112        for ( uint32 i = 0; i < count; ++i )
     113        {
     114                vec3 rellipse = r->hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise );
    122115                p[i].position =
    123116                        rellipse.x * pe->cdir +
     
    127120}
    128121
    129 static void nv_particle_emitter_hollow_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count )
    130 {
    131         random& r = random::get();
    132         for ( uint32 i = 0; i < count; ++i )
    133         {
    134                 vec2 rellipse = r.hollow_ellipse_point(
     122static void nv_particle_emitter_hollow_cylindroid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     123{
     124        for ( uint32 i = 0; i < count; ++i )
     125        {
     126                vec2 rellipse = r->hollow_ellipse_point(
    135127                        vec2( pe->ihextents[0], pe->ihextents[2] ),
    136128                        vec2( pe->hextents[0], pe->hextents[2] ),
     
    138130                p[i].position =
    139131                        rellipse.x * pe->cdir +
    140                         r.frange( 0.0f, pe->extents[1] ) * pe->dir +
     132                        r->frange( 0.0f, pe->extents[1] ) * pe->dir +
    141133                        rellipse.y * pe->odir;
    142134        }
    143135}
    144136
    145 static void nv_particle_emitter_hollow_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count )
    146 {
    147         random& r = random::get();
    148         for ( uint32 i = 0; i < count; ++i )
    149         {
    150                 vec3 rellipse = r.hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise );
     137static void nv_particle_emitter_hollow_ellipsoid( random_base* r, const particle_emitter_data* pe, particle* p, uint32 count )
     138{
     139        for ( uint32 i = 0; i < count; ++i )
     140        {
     141                vec3 rellipse = r->hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise );
    151142                p[i].position =
    152143                        rellipse.x * pe->cdir +
     
    278269}
    279270
    280 nv::particle_engine::particle_engine( context* a_context, bool debug_data )
    281 {
    282         m_context       = a_context;
     271nv::particle_engine::particle_engine( context* a_context, random_base* rng, particle_group_manager* groups, bool debug_data )
     272{
     273        m_context = a_context;
     274        m_pgm     = groups;
     275        m_rng     = rng;
     276        if ( m_rng == nullptr )
     277                m_rng = &random::get();
     278
    283279        if ( debug_data )
    284280        {
    285281                m_debug_emitter_names  = new nv::hash_map< nv::particle_emitter_func,  nv::const_string >;
    286282                m_debug_affector_names = new nv::hash_map< nv::particle_affector_func, nv::const_string >;
    287                 m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >;
    288283                m_debug_emitter_list   = new nv::vector< nv::particle_emitter_func >;
    289284                m_debug_affector_list  = new nv::vector< nv::particle_affector_func >;
     
    294289}
    295290
    296 nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_system_group group )
    297 {
    298         particle_system_group_info* ginfo = m_groups.get( group );
    299         if ( !ginfo ) return nv::particle_system();
    300 
     291nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_group group )
     292{
     293        if ( !m_pgm->ref( group ) )
     294                return nv::particle_system();
     295       
    301296        particle_system result = m_systems.create();
    302297        particle_system_info* info = m_systems.get( result );
     
    310305                        info->emitters[i].pause = 0;
    311306                else
    312                         info->emitters[i].pause = random::get().frange( data->emitters[i].duration_min, data->emitters[i].duration_max );
     307                        info->emitters[i].pause = m_rng->frange( data->emitters[i].duration_min, data->emitters[i].duration_max );
    313308
    314309        }
     
    316311        info->count = 0;
    317312        info->particles = new particle[data->quota];
    318         ginfo->ref_counter++;
    319313
    320314        return result;
    321315}
    322316
    323 nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_system_group group )
     317nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_group group )
    324318{
    325319        if ( auto data = rdata.lock() )
     
    328322}
    329323
    330 void nv::particle_engine::prepare( particle_system_group group )
    331 {
    332         particle_system_group_info* info = m_groups.get( group );
    333         if ( info )
    334         {
    335                 info->count = 0;
    336         }
    337 }
    338 
    339 nv::particle_system_group nv::particle_engine::create_group( uint32 max_particles )
    340 {
    341         particle_system_group result     = m_groups.create();
    342         particle_system_group_info* info = m_groups.get( result );
    343         info->local = false;
    344         info->count = 0;
    345         info->quota = max_particles;
    346         info->vtx_buffer = m_context->create_buffer( VERTEX_BUFFER, STREAM_DRAW, info->quota * sizeof( particle_quad )/*, info->quads_[0].data*/ );
    347         vertex_array_desc desc;
    348         desc.add_vertex_buffers< particle_vtx >( info->vtx_buffer, true );
    349         info->vtx_array = m_context->create_vertex_array( desc );
    350         info->quads     = new particle_quad[info->quota];
    351         info->ref_counter = 0;
    352         return result;
     324void nv::particle_engine::prepare( particle_group group )
     325{
     326        m_pgm->prepare( group );
     327}
     328
     329nv::particle_group nv::particle_engine::create_group( uint32 max_particles )
     330{
     331        return m_pgm->create_group( max_particles );
    353332}
    354333
     
    369348        while ( m_systems.size() > 0 )
    370349                release( m_systems.get_handle( 0 ) );
    371         while ( m_groups.size() > 0 )
    372                 release( m_groups.get_handle( 0 ) );
     350        if ( m_pgm )
     351                m_pgm->reset();
    373352        m_emitters.clear();
    374353        m_affectors.clear();
     
    381360        if ( info )
    382361        {
    383                 particle_system_group_info* ginfo = m_groups.get( info->group );
    384                 if ( ginfo ) ginfo->ref_counter--;
    385                                 delete[] info->particles;
     362                m_pgm->unref( info->group );
     363                delete[] info->particles;
    386364                m_systems.destroy( system );
    387365        }
    388366}
    389367
    390 void nv::particle_engine::release( particle_system_group group )
    391 {
    392         particle_system_group_info* info = m_groups.get( group );
    393         if ( info )
    394         {
    395                 delete[] info->quads;
    396                 m_context->release( info->vtx_array );
    397                 m_groups.destroy( group );
    398         }
     368void nv::particle_engine::release( particle_group group )
     369{
     370        m_pgm->release( group );
    399371}
    400372
     
    403375        particle_system_info* info = m_systems.get( system );
    404376        if ( info )
    405         {
    406                 generate_data( info, s );
    407         }
     377                m_pgm->generate_data( array_view< particle >( info->particles, info->count ), info->data, info->group, s );
    408378}
    409379
     
    440410                info->texcoords[1] = b;
    441411        }
    442 }
    443 
    444 void nv::particle_engine::generate_data( particle_system_info* info, const scene_state& s )
    445 {
    446 //      void* rawptr = m_context->map_buffer( info->vtx_buffer, nv::WRITE_UNSYNCHRONIZED, offset, info->count*sizeof( particle_quad ) );
    447 //      particle_quad* quads = reinterpret_cast<particle_quad*>( rawptr );
    448 
    449         particle_system_group_info* group = m_groups.get( info->group );
    450         if ( !info )
    451         {
    452                 return;
    453         }
    454 
    455         vec2 lb     = vec2( -0.5f, -0.5f );
    456         vec2 rt     = vec2( 0.5f, 0.5f );
    457 
    458         switch ( info->data->origin )
    459         {
    460         case particle_origin::CENTER        : break;
    461         case particle_origin::TOP_LEFT      : lb = vec2(0.f,-1.f); rt = vec2(1.f,0.f);  break;
    462         case particle_origin::TOP_CENTER    : lb.y = -1.f; rt.y = 0.f; break;
    463         case particle_origin::TOP_RIGHT     : lb = vec2(-1.f,-1.f); rt = vec2(); break;
    464         case particle_origin::CENTER_LEFT   : lb.x = 0.f; rt.x = 1.f; break;
    465         case particle_origin::CENTER_RIGHT  : lb.x = -1.f; rt.x = 0.f; break;
    466         case particle_origin::BOTTOM_LEFT   : lb = vec2(); rt = vec2(1.f,1.f); break;
    467         case particle_origin::BOTTOM_CENTER : lb.y = 0.f; rt.y = 1.f; break;
    468         case particle_origin::BOTTOM_RIGHT  : lb = vec2(-1.f,0.f); rt = vec2(.0f,1.f); break;
    469         }
    470 
    471         const vec3 sm[4] =
    472         {
    473                 vec3( lb.x, lb.y, 0.0f ),
    474                 vec3( rt.x, lb.y, 0.0f ),
    475                 vec3( lb.x, rt.y, 0.0f ),
    476                 vec3( rt.x, rt.y, 0.0f ),
    477         };
    478         vec3 z( 0.0f, 0.0f ,1.0f );
    479 
    480         particle_orientation orientation = info->data->orientation;
    481         vec3 common_up ( info->data->common_up );
    482         vec3 common_dir( info->data->common_dir );
    483         bool accurate_facing = info->data->accurate_facing;
    484         mat3 rot_mat;
    485         vec3 right;
    486         vec3 pdir( 0.0f, 1.0f, 0.0f );
    487 
    488         vec3 camera_pos   = s.get_camera().get_position();
    489         vec3 inv_view_dir = math::normalize( -s.get_camera().get_direction() );
    490 
    491         for ( uint32 i = 0; i < info->count; ++i )
    492         {
    493                 const particle& pdata = info->particles[i];
    494 //              particle_quad& rdata  = quads[i];
    495                 particle_quad& rdata  = group->quads[i + group->count];
    496 
    497                 vec3 view_dir( inv_view_dir );
    498                 if ( accurate_facing ) view_dir = math::normalize( camera_pos - pdata.position );
    499 
    500                 switch ( orientation )
    501                 {
    502                 case particle_orientation::POINT :
    503                         right   = math::normalize( math::cross( view_dir, vec3( 0, 1, 0 ) ) );
    504                         right   = math::rotate( right, pdata.rotation, view_dir );
    505                         rot_mat = mat3( right, math::cross( right, -view_dir ), -view_dir );
    506                         break;
    507                 case particle_orientation::ORIENTED :
    508                         pdir    = normalize_safe( pdata.velocity, pdir );
    509                         right   = math::normalize( math::cross( pdir, view_dir ) );
    510                         rot_mat = mat3( right, pdir, math::cross( pdir, right ) );
    511                         break;
    512                 case particle_orientation::ORIENTED_COMMON :
    513                         right   = math::normalize( math::cross( common_dir, view_dir ) );
    514                         rot_mat = mat3( right, common_dir, math::cross( common_dir, right ) );
    515                         break;
    516                 case particle_orientation::PERPENDICULAR :
    517                         pdir    = normalize_safe( pdata.velocity, pdir );
    518                         right   = math::normalize( math::cross( common_up, pdir ) );
    519                         rot_mat = mat3( right, common_up, math::cross( common_up, right ) );
    520                         break;
    521                 case particle_orientation::PERPENDICULAR_COMMON :
    522                         right   = math::normalize( math::cross( common_up, common_dir ) );
    523                         rot_mat = mat3( right, common_up, math::cross( common_up, right ) );
    524                         break;
    525                 }
    526 
    527                 vec2 texcoords[4] =
    528                 {
    529                         pdata.tcoord_a,
    530                         vec2( pdata.tcoord_b.x, pdata.tcoord_a.y ),
    531                         vec2( pdata.tcoord_a.x, pdata.tcoord_b.y ),
    532                         pdata.tcoord_b
    533                 };
    534 
    535                 vec3 size( pdata.size.x, pdata.size.y, 0.0f );
    536                 vec3 s0 = rot_mat * ( ( size * sm[0] ) );
    537                 vec3 s1 = rot_mat * ( ( size * sm[1] ) );
    538                 vec3 s2 = rot_mat * ( ( size * sm[2] ) );
    539                 vec3 s3 = rot_mat * ( ( size * sm[3] ) );
    540 
    541                 rdata.data[0].position = pdata.position + s0;
    542                 rdata.data[0].color    = pdata.color;
    543                 rdata.data[0].texcoord = texcoords[0];
    544 
    545                 rdata.data[1].position = pdata.position + s1;
    546                 rdata.data[1].color    = pdata.color;
    547                 rdata.data[1].texcoord = texcoords[1];
    548 
    549                 rdata.data[2].position = pdata.position + s2;
    550                 rdata.data[2].color    = pdata.color;
    551                 rdata.data[2].texcoord = texcoords[2];
    552 
    553                 rdata.data[3].position = pdata.position + s3;
    554                 rdata.data[3].color    = pdata.color;
    555                 rdata.data[3].texcoord = texcoords[3];
    556 
    557                 rdata.data[4] = rdata.data[2];
    558                 rdata.data[5] = rdata.data[1];
    559         }
    560 //      m_context->unmap_buffer( info->vtx_buffer );
    561 
    562         m_context->update( group->vtx_buffer, group->quads, group->count*sizeof(particle_quad), info->count*sizeof( particle_quad ) );
    563         group->count += info->count;
    564412}
    565413
     
    584432        if ( ecount == 0 ) return;
    585433
    586         random& r = random::get();
    587434        bool local = model.is_identity();
    588435//      if ( !local )
     
    605452                                {
    606453                                        particle& pinfo = info->particles[info->count];
    607                                         edata.emitter_func( &(info->data->emitters[i]), &pinfo, 1 );
     454                                        edata.emitter_func( m_rng, &(info->data->emitters[i]), &pinfo, 1 );
    608455                                        pinfo.position = vec3();
    609456                                        pinfo.position+= edata.position;
     
    611458                                                pinfo.position = pinfo.position * model;
    612459                                        pinfo.color    = edata.color_min == edata.color_max ?
    613                                                 edata.color_min : r.range( edata.color_min, edata.color_max );
     460                                                edata.color_min : m_rng->range( edata.color_min, edata.color_max );
    614461                                        pinfo.size     = edata.size_min == edata.size_max ?
    615                                                 edata.size_min : r.range( edata.size_min, edata.size_max );
     462                                                edata.size_min : m_rng->range( edata.size_min, edata.size_max );
    616463                                        if ( edata.square ) pinfo.size.y = pinfo.size.x;
    617464                                        float velocity = edata.velocity_min == edata.velocity_max ?
    618                                                 edata.velocity_min : r.frange( edata.velocity_min, edata.velocity_max );
     465                                                edata.velocity_min : m_rng->frange( edata.velocity_min, edata.velocity_max );
    619466                                        pinfo.lifetime = dtime + einfo.next;
    620467                                        pinfo.death = ( edata.lifetime_min == edata.lifetime_max ?
    621                                                 edata.lifetime_min : r.frange( edata.lifetime_min, edata.lifetime_max ) );
    622                                         pinfo.rotation = r.frand( 2* math::pi<float>() );
     468                                                edata.lifetime_min : m_rng->frange( edata.lifetime_min, edata.lifetime_max ) );
     469                                        pinfo.rotation = m_rng->frand( 2* math::pi<float>() );
    623470                                        pinfo.tcoord_a = info->texcoords[0];
    624471                                        pinfo.tcoord_b = info->texcoords[1];
     
    628475                                        {
    629476                                                float emission_angle = math::radians( edata.angle );
    630                                                 float cos_theta = r.frange( cos( emission_angle ), 1.0f );
     477                                                float cos_theta = m_rng->frange( cos( emission_angle ), 1.0f );
    631478                                                float sin_theta = sqrt(1.0f - cos_theta * cos_theta );
    632                                                 float phi       = r.frange( 0.0f, 2* math::pi<float>() );
     479                                                float phi       = m_rng->frange( 0.0f, 2* math::pi<float>() );
    633480                                                pinfo.velocity  = model.get_orientation() *
    634481                                                        ( edata.odir * ( cos(phi) * sin_theta ) +
     
    672519        uint32 ecount = info->data->emitter_count;
    673520        if ( ecount == 0 ) return;
    674         random& r = random::get();
    675521
    676522        for ( uint32 i = 0; i < ecount; ++i )
     
    691537                                einfo.active = false;
    692538                                if ( edata.repeat_min > 0.0f )
    693                                         einfo.pause += r.frange( edata.repeat_min, edata.repeat_max );
     539                                        einfo.pause += m_rng->frange( edata.repeat_min, edata.repeat_max );
    694540                                else
    695541                                        einfo.pause = 0.0f;
     
    698544                        {
    699545                                einfo.active = true;
    700                                 einfo.pause += r.frange( edata.duration_min, edata.duration_max );
     546                                einfo.pause += m_rng->frange( edata.duration_min, edata.duration_max );
    701547                        }
    702548                }
     
    776622}
    777623
    778 nv::particle_render_data nv::particle_engine::get_render_data( particle_system_group group )
    779 {
    780         const particle_system_group_info* info = m_groups.get( group );
    781         if ( info )
    782         {
    783                 return{ info->count, info->vtx_array };
    784         }
    785         return { 0, nv::vertex_array() };
     624nv::particle_render_data nv::particle_engine::get_render_data( particle_group group )
     625{
     626        return m_pgm->get_render_data( group );
    786627}
    787628
     
    794635}
    795636
    796 void nv::particle_engine::register_types( type_database* db )
     637const nv::type_entry* nv::particle_engine::get_debug_type( particle_affector_func f )
     638{
     639        if ( m_debug_affector_types )
     640        {
     641                auto it = m_debug_affector_types->find( f );
     642                if ( it != m_debug_affector_types->end() )
     643                        return it->second;
     644        }
     645        return nullptr;
     646}
     647
     648void nv::particle_engine::register_types( type_database* db, bool debug_data )
    797649{
    798650        db->create_type<particle_orientation>()
     
    816668                ;
    817669
    818         if ( m_debug_affector_types )
    819         {
     670        if ( debug_data )
     671        {
     672                if ( !m_debug_affector_types )
     673                        m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >;
     674
    820675                int you_could_get_rid_of_the_init_function_using_these; int error;
    821676                int universal_vm_based_affector;
     
    849704        }
    850705}
     706
  • trunk/src/engine/particle_manager.cc

    r518 r520  
    6161        data->emitter_count   = 0;
    6262        data->affector_count  = 0;
    63 
    64         const_string orientation = table.get_string( "orientation", "point" );
    65         if ( orientation == "point" )                     { data->orientation = particle_orientation::POINT; }
    66         else if ( orientation == "oriented" )             { data->orientation = particle_orientation::ORIENTED; }
    67         else if ( orientation == "oriented_common" )      { data->orientation = particle_orientation::ORIENTED_COMMON; }
    68         else if ( orientation == "perpendicular" )        { data->orientation = particle_orientation::PERPENDICULAR; }
    69         else if ( orientation == "perpendicular_common" ) { data->orientation = particle_orientation::PERPENDICULAR_COMMON; }
    70         else
    71         {
    72                 NV_LOG_ERROR( "Unknown orientation type! (", orientation, ")!" );
    73                 data->orientation = particle_orientation::POINT;
    74         }
    75 
    76         const_string origin = table.get_string( "origin", "center" );
    77         if      ( origin == "center" )        { data->origin = particle_origin::CENTER; }
    78         else if ( origin == "top_left" )      { data->origin = particle_origin::TOP_LEFT; }
    79         else if ( origin == "top_center" )    { data->origin = particle_origin::TOP_CENTER; }
    80         else if ( origin == "top_right" )     { data->origin = particle_origin::TOP_RIGHT; }
    81         else if ( origin == "center_left" )   { data->origin = particle_origin::CENTER_LEFT; }
    82         else if ( origin == "center_right" )  { data->origin = particle_origin::CENTER_RIGHT; }
    83         else if ( origin == "bottom_left" )   { data->origin = particle_origin::BOTTOM_LEFT; }
    84         else if ( origin == "bottom_center" ) { data->origin = particle_origin::BOTTOM_CENTER; }
    85         else if ( origin == "bottom_right" )  { data->origin = particle_origin::BOTTOM_RIGHT; }
    86         else
    87         {
    88                 NV_LOG_ERROR( "Unknown particle origin! (", origin, ")!" );
    89                 data->origin = particle_origin::CENTER;
    90         }
     63        data->orientation     = particle_orientation( table.get_unsigned("orientation", 0) );
     64        data->origin          = particle_origin( table.get_unsigned( "origin",0  ) );
    9165
    9266        data->common_up  = math::normalize( table.get<vec3>("common_up",  vec3(1,0,0) ) );
  • trunk/src/gfx/debug_draw.cc

    r509 r520  
    101101}
    102102
     103void nv::debug_data::push_wire_capsule( const transform& tr, float radius, float height )
     104{
     105        vec3 p = tr.get_position();
     106        quat o = tr.get_orientation();
     107        vec3 dir   = o * vec3( 0, 1, 0 );
     108        vec3 ldir  = o * vec3( 1, 0, 0 );
     109        vec3 h1dir = o * normalize( vec3( 1, -1, 0 ) );
     110        vec3 h2dir = o * normalize( vec3( 1, 1, 0 ) );
     111        vec3 sp1[12];
     112        vec3 sp2[12];
     113        vec3 hsp1[12];
     114        vec3 hsp2[12];
     115        for ( uint32 i = 0; i < 12; ++i )
     116        {
     117                sp1[i]  = nv::math::rotate( ldir * radius, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir );
     118                hsp1[i] = nv::math::rotate( h1dir * radius, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir );
     119        }
     120        for ( uint32 i = 0; i < 12; ++i )
     121        {
     122                sp2[i]  = nv::math::rotate( ldir * radius + height * dir, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir );
     123                hsp2[i] = nv::math::rotate( h2dir * radius + height * dir, ( float( i ) / 12.0f ) * math::two_pi<float>(), dir );
     124        }
     125
     126        for ( uint32 i = 0; i < 12; ++i )
     127        {
     128                push_line( p + sp1[i], p + sp1[( i + 1 ) % 12], vec3( 1.0f, 0.0f, 0.0f ) );
     129                push_line( p + sp2[i], p + sp2[( i + 1 ) % 12], vec3( 0.0f, 1.0f, 0.0f ) );
     130                push_line( p + sp1[i], p + sp2[i], vec3( 0.0f, 0.0f, 1.0f ) );
     131
     132                push_line( p + hsp1[i], p + sp1[i], vec3( 0.0f, 0.0f, 1.0f ) );
     133                push_line( p + hsp1[i], p + hsp1[( i + 1 ) % 12], vec3( 1.0f, 0.0f, 0.0f ) );
     134                push_line( p + hsp2[i], p + sp2[i], vec3( 0.0f, 0.0f, 1.0f ) );
     135                push_line( p + hsp2[i], p + hsp2[( i + 1 ) % 12], vec3( 0.0f, 1.0f, 0.0f ) );
     136
     137                push_line( p + hsp1[i], p - radius * dir, vec3( 0.0f, 0.0f, 1.0f ) );
     138                push_line( p + hsp2[i], p + ( height + radius ) * dir, vec3( 0.0f, 0.0f, 1.0f ) );
     139
     140        }
     141
     142               
     143}
     144
     145
    103146nv::debug_data::~debug_data()
    104147{
  • trunk/src/gfx/gfx_terminal.cc

    r514 r520  
    8484                fgcolor = fg.get_argb32();
    8585                bgcolor = bg.get_argb32();
    86                 gylph   = uint32( ch );
    87                 NV_LOG_INFO( uint32(
    88                         ( fgcolor & uint32( 0x00FF0000 ) ) >> 16 ), "-", uint32( ( fgcolor & uint32( 0x0000FF00 ) ) >> 8 ),"-" , uint32( fgcolor & uint32( 0x000000FF ) ) );
     86                gylph   = uint32( uint8(ch) );
    8987        }
    9088};
     
    139137        m_dc.p = m_context->create_program( nv_gfx_terminal_vs, nv_gfx_terminal_fs );
    140138
    141         m_data->buffer = m_context->create_buffer( nv::UNIFORM_BUFFER, nv::DYNAMIC_DRAW, tsize.x * tsize.y * sizeof( gfx_terminal_uniform_block ), m_data->data );
     139        m_data->buffer = m_context->create_buffer( nv::UNIFORM_BUFFER, nv::STREAM_DRAW, tsize.x * tsize.y * sizeof( gfx_terminal_uniform_block ), m_data->data );
    142140        m_context->bind( m_data->buffer, 7 );
    143141        m_context->get_device()->set_opt_uniform( m_dc.p, "term_size", vec2( tsize ) );
     
    151149void gfx_terminal::update()
    152150{
    153         m_context->bind( m_data->buffer, 7 );
    154         m_context->update( m_data->buffer, m_data->data, 0, m_data->size.x * m_data->size.y * sizeof( gfx_terminal_uniform_block ) );
    155         m_update_needed = false;
     151        if ( m_update_needed )
     152        {
     153                m_context->bind( m_data->buffer, 7 );
     154                m_context->update( m_data->buffer, m_data->data, 0, m_data->size.x * m_data->size.y * sizeof( gfx_terminal_uniform_block ) );
     155                m_update_needed = false;
     156        }
    156157}
    157158
  • trunk/src/gfx/mesh_creator.cc

    r503 r520  
    8787}
    8888
     89
     90nv::aabb nv::mesh_data_creator::calculate_aabb()
     91{
     92        NV_ASSERT_ALWAYS( m_pos_channel, "No position channel found!" );
     93        vec3 minv;
     94        vec3 maxv;
     95
     96        if ( m_pos_channel->size() > 0 )
     97        {
     98                minv = *reinterpret_cast<const vec3*>( m_pos_channel->raw_data() + m_pos_offset );
     99                maxv = minv;
     100        }
     101
     102        for ( uint32 c = 0; c < m_pos_channel->size(); ++c )
     103        {
     104                vec3 v = *reinterpret_cast<const vec3*>( m_pos_channel->raw_data() + c*m_pos_channel->element_size() + m_pos_offset );
     105                minv = nv::math::min( minv, v );
     106                maxv = nv::math::max( maxv, v );
     107        }
     108        vec3 extents  = maxv - minv;
     109        vec3 hextents = extents * 0.5f;
     110        vec3 halfv    = minv + hextents;
     111        return aabb( nv::transform( halfv ), hextents );
     112}
    89113
    90114void nv::mesh_data_creator::transform( const vec3& pos, const mat3& r33, float scale /*= 1.0f */ )
  • trunk/src/gfx/skeleton_instance.cc

    r486 r520  
    182182}
    183183
     184void nv::skeleton_transforms::delocalize_rec( const data_node_tree& node_data, uint32 id, const transform& parent, const array_view< bool >& mask )
     185{
     186        transform global_mat = parent;
     187        bool b = mask[id];
     188        if ( !b )
     189                global_mat = m_transforms[id];
     190        else
     191        {
     192                global_mat *= m_transforms[id];
     193                m_transforms[id] = global_mat;
     194        }
     195        for ( auto child : node_data.children( id ) )
     196        {
     197                delocalize_rec( node_data, child, global_mat, mask );
     198        }
     199}
     200
  • trunk/src/gl/gl_context.cc

    r515 r520  
    125125        }
    126126}
     127
     128nv::image_data* nv::gl_context::dump_image( image_format f, image_data* reuse )
     129{
     130        NV_ASSERT_ALWAYS( f.type   == nv::UBYTE, "Bad format passed to dump" );
     131        NV_ASSERT_ALWAYS( f.format == nv::RGB || f.format == nv::RGBA, "Bad format passed to dump" );
     132        glPixelStorei( GL_PACK_ALIGNMENT, 1 );
     133        image_data* result = reuse;
     134        if ( !result ) result = new image_data( f, ivec2( m_viewport.z, m_viewport.w ) );
     135        glReadPixels( 0, 0, m_viewport.z, m_viewport.w, f.format == nv::RGB ? GL_RGB : GL_RGBA, datatype_to_gl_enum( f.type ), const_cast< uint8* >( result->get_data() ) );
     136        return result;
     137}
     138
    127139
    128140const framebuffer_info* nv::gl_context::get_framebuffer_info( framebuffer f ) const
  • trunk/src/gui/gui_ascii_renderer.cc

    r514 r520  
    9898                m_terminal->print( abs.ll(), er->border_color, term_color(), er->border_chars[6] );
    9999                m_terminal->print( abs.lr,   er->border_color, term_color(), er->border_chars[7] );
    100                 m_terminal->update();
     100                //m_terminal->update();
    101101        }
    102102        if ( !e->m_text.empty() )
  • trunk/src/gui/gui_environment.cc

    r492 r520  
    183183                        handle h = get_element( position( ev.mbutton.x, ev.mbutton.y ) );
    184184                        element* e = m_elements.get( h );
     185                        if (e)
    185186                        if ( e->m_on_click ) e->m_on_click();
    186187
  • trunk/src/image/miniz.cc

    r487 r520  
    26682668        return tinfl_decompress_mem_to_heap( source_buf, source_buf_len, out_len, parse_header ? TINFL_FLAG_PARSE_ZLIB_HEADER : 0 );
    26692669}
     2670
     2671int nv::miniz_compress( unsigned char *pDest, unsigned long *pDest_len, const unsigned char *pSource, unsigned long source_len, int level )
     2672{
     2673        NV_PROFILE( "compress" );
     2674        return mz_compress2( pDest, pDest_len, pSource, source_len, level );
     2675}
     2676
     2677unsigned long nv::miniz_bound( unsigned long source_len )
     2678{
     2679        return mz_compressBound( source_len );
     2680}
  • trunk/src/lib/gl.cc

    r501 r520  
    189189
    190190
    191         HWND hWndFake = CreateWindow(TEXT("Dummy67789"), "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN,
     191        HWND hWndFake = CreateWindowA("Dummy67789", "FAKE", WS_OVERLAPPEDWINDOW | WS_MAXIMIZE | WS_CLIPCHILDREN,
    192192                0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
    193193                NULL, GetModuleHandle(nullptr), NULL);
     
    213213        wgl_makecurrent(hDC, hRCFake);
    214214
    215         LoadLibrary( "gdi32.dll" );
     215        LoadLibraryA( "gdi32.dll" );
    216216        bool gl_loaded = nv::load_gl_library( path );
    217217        bool wgl_loaded = nv::load_wgl_library( path );
  • trunk/src/lua/lua_area.cc

    r503 r520  
    88
    99#include "nv/lua/lua_raw.hh"
    10 #include "nv/core/random.hh"
     10#include "nv/lua/lua_aux.hh"
    1111
    1212using nv::lua::detail::is_coord;
     
    333333        nv::sint32 xs = ( b.x - a.x ) + 1;
    334334        nv::sint32 ys = ( b.y - a.y ) - 1;
    335         nv::sint32 roll = nv::random::get().srand( 2 * xs + 2 * ys );
     335        nv::sint32 roll = nv::lua::rng().srand( 2 * xs + 2 * ys );
    336336        nv::ivec2 result;
    337337
     
    356356        nv::sint32 xs = ( b.x - a.x ) - 1;
    357357        nv::sint32 ys = ( b.y - a.y ) - 1;
    358         nv::sint32 roll = nv::random::get().srand( 2 * xs + 2 * ys );
     358        nv::sint32 roll = nv::lua::rng().srand( 2 * xs + 2 * ys );
    359359        nv::ivec2 result;
    360360
     
    375375{
    376376        nv::rectangle area = to_area( L, 1 );
    377         push_coord( L, nv::random::get().range( area.ul, area.lr ) );
     377        push_coord( L, nv::lua::rng().range( area.ul, area.lr ) );
    378378        return 1;
    379379}
     
    383383        nv::rectangle area  = to_area( L, 1 );
    384384        nv::ivec2     dim   = to_coord( L, 2 );
    385         nv::ivec2     start = nv::random::get().range( area.ul, area.lr - dim );
     385        nv::ivec2     start = nv::lua::rng().range( area.ul, area.lr - dim );
    386386        push_area( L, nv::rectangle( start, start + dim ) );
    387387        return 1;
  • trunk/src/lua/lua_aux.cc

    r503 r520  
    99#include "nv/lua/lua_raw.hh"
    1010#include "nv/core/random.hh"
     11
     12static nv::random lua_rng;
    1113
    1214static int nluaaux_table_copy( lua_State* L )
     
    9496        if ( dice < 1 )  luaL_argerror( L, 1, "die count lower than 1!" );
    9597        if ( sides < 1 ) luaL_argerror( L, 2, "side count lower than 1!" );
    96         lua_pushnumber( L, nv::random::get().dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) );
     98        lua_pushnumber( L, lua_rng.dice( static_cast< nv::uint32 >( dice ), static_cast< nv::uint32 >( sides ) ) );
    9799        return 1;
    98100}
     
    102104        if ( lua_gettop( L ) == 0 )
    103105        {
    104                 lua_pushnumber( L, nv::random::get().frand(1.0f) );
     106                lua_pushnumber( L, lua_rng.frand(1.0f) );
    105107        }
    106108        else
     
    110112                        lua_Integer arg1 = luaL_checkinteger( L, 1 );
    111113                        if ( arg1 < 1 ) arg1 = 1;
    112                         nlua_pushunsigned( L, nv::random::get().urange( 1, static_cast<nv::uint32>( arg1 ) ) );
     114                        nlua_pushunsigned( L, lua_rng.urange( 1, static_cast<nv::uint32>( arg1 ) ) );
    113115                }
    114116                else
     
    116118                        int arg1 = static_cast< int >( luaL_checkinteger( L, 1 ) );
    117119                        int arg2 = static_cast< int >( luaL_checkinteger( L, 2 ) );
    118                         int result = ( arg2 >= arg1 ? nv::random::get().srange( arg1, arg2 ) : nv::random::get().srange( arg2, arg1 ) );
     120                        int result = ( arg2 >= arg1 ? lua_rng.srange( arg1, arg2 ) : lua_rng.srange( arg2, arg1 ) );
    119121                        lua_pushinteger( L, result );
    120122                }
     
    125127static int nluaaux_math_randomseed( lua_State* L )
    126128{
    127         nv::random::get().set_seed( nlua_tounsigned( L, 1 ) );
     129        lua_rng.set_seed( nlua_tounsigned( L, 1 ) );
    128130        return 0;
    129131}
     
    137139};
    138140
     141nv::random & nv::lua::rng()
     142{
     143        return lua_rng;
     144}
     145
    139146void nv::lua::register_aux( lua::state* state )
    140147{
  • trunk/src/lua/lua_map_tile.cc

    r503 r520  
    1111#include "nv/stl/numeric.hh"
    1212#include "nv/stl/algorithm.hh"
    13 #include "nv/core/random.hh"
     13#include "nv/lua/lua_aux.hh"
    1414#include "nv/lua/lua_area.hh"
    1515#include "nv/lua/lua_math.hh"
     
    207207static int nlua_map_tile_flip_random( lua_State* L )
    208208{
    209         switch ( nv::random::get().urand( 4 ) )
     209        switch ( nv::lua::rng().urand( 4 ) )
    210210        {
    211211        case 1 : nlua_map_tile_flip_x( L ); break;
  • trunk/src/lua/lua_math.cc

    r512 r520  
    88
    99#include "nv/lua/lua_raw.hh"
    10 #include "nv/core/random.hh"
     10#include "nv/lua/lua_aux.hh"
    1111#include "nv/stl/type_traits/common.hh"
    1212
     
    126126int nlua_vec_random( lua_State* L )
    127127{
    128         push_vec<T>( L, nv::random::get().range( to_vec<T>( L, 1 ), to_vec<T>( L, 2 ) ) );
     128        push_vec<T>( L, nv::lua::rng().range( to_vec<T>( L, 1 ), to_vec<T>( L, 2 ) ) );
    129129        return 1;
    130130}
Note: See TracChangeset for help on using the changeset viewer.