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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.