revised filtering & api
[csRadar.git] / csrDraw.h
index b162b0fc556199fd7ab20edb8108bc547f514600..b6e17caf8d2f1377469056c5064f695f16eaab82 100644 (file)
--- a/csrDraw.h
+++ b/csrDraw.h
@@ -1,5 +1,6 @@
 typedef struct csr_frag csr_frag;
 typedef struct csr_target csr_target;
 typedef struct csr_frag csr_frag;
 typedef struct csr_target csr_target;
+typedef struct csr_filter csr_filter;
 
 struct csr_frag
 {
 
 struct csr_frag
 {
@@ -17,6 +18,25 @@ struct csr_target
        v4f bounds;
 };
 
        v4f bounds;
 };
 
+struct csr_filter
+{
+       const char *visgroup;           // Limit to this visgroup only
+       const char *classname;          // Limit to this exact classname. will not draw world
+};
+
+void csr_create_target( csr_target *rt, u32 x, u32 y, v4f bounds )
+{
+       rt->x = x;
+       rt->y = y;
+       rt->fragments = (csr_frag *)csr_malloc( x*y*sizeof(csr_frag) );
+       v4_copy( bounds, rt->bounds );
+}
+
+void csr_rt_free( csr_target *rt )
+{
+       free( rt->fragments );
+}
+
 void csr_rt_clear( csr_target *rt )
 {
        for( u32 i = 0; i < rt->x*rt->y; i ++ )
 void csr_rt_clear( csr_target *rt )
 {
        for( u32 i = 0; i < rt->x*rt->y; i ++ )
@@ -97,58 +117,64 @@ void csr_draw( csr_target *rt, vmf_vert *triangles, u32 triangle_count, m4x3f tr
        }
 }
 
        }
 }
 
-void draw_vmf_group( csr_target *rt, vmf_map *map, vdf_node *root, const char *group, m4x3f prev, m4x3f inst )
+void draw_vmf_group( csr_target *rt, vmf_map *map, vdf_node *root, csr_filter *filter, m4x3f prev, m4x3f inst )
 {
        m4x3f transform = M4X3_IDENTITY;
        vmf_solid solid;
        vmf_vert tri[3];
 {
        m4x3f transform = M4X3_IDENTITY;
        vmf_solid solid;
        vmf_vert tri[3];
+       vdf_node *ent_solid;
 
        u32 group_id = 0;
 
        u32 group_id = 0;
+       int filter_visgroups = 0, filter_classname = 0;
        
        
-       if( group )
+       if( filter )
        {
        {
-               group_id = vmf_visgroup_id( root, group );
+               if( filter->visgroup )
+               {
+                       filter_visgroups = 1;
+                       group_id = vmf_visgroup_id( root, filter->visgroup );
+               }
+               
+               if( filter->classname )
+               {
+                       filter_classname = 1;
+               }
        }
        }
-
+       
        // Multiply previous transform with instance transform to create basis
        if( prev )
        {
                m4x3_mul( prev, inst, transform );
        }
 
        // Multiply previous transform with instance transform to create basis
        if( prev )
        {
                m4x3_mul( prev, inst, transform );
        }
 
-       // Draw brushes
+       // Gather world brushes
        solidgen_ctx_init( &solid );
        solidgen_ctx_init( &solid );
-       vdf_node *world = vdf_next( root, "world", NULL );
        
        
-       vdf_foreach( world, "solid", brush )
-       {
-               if( group && !vmf_visgroup_match( brush, group_id ) )
-                       continue;
-               
-               solidgen_push( &solid, brush );
-       }
-
-       for( int i = 0; i < csr_sb_count( solid.indices )/3; i ++ )
+       if( !filter_classname )
        {
        {
-               u32 * base = solid.indices + i*3;
-               
-               tri[0] = solid.verts[ base[0] ];
-               tri[1] = solid.verts[ base[1] ];
-               tri[2] = solid.verts[ base[2] ];
+               vdf_node *world = vdf_next( root, "world", NULL );
                
                
-               csr_draw( rt, tri, 1, transform );
+               vdf_foreach( world, "solid", brush )
+               {
+                       if( filter_visgroups && !vmf_visgroup_match( brush, group_id ) )
+                               continue;
+                       
+                       solidgen_push( &solid, brush );
+               }
        }
        }
-       
-       solidgen_ctx_reset( &solid );
                
        // Actual entity loop
        m4x3f model;
        
        vdf_foreach( root, "entity", ent )
        {
                
        // Actual entity loop
        m4x3f model;
        
        vdf_foreach( root, "entity", ent )
        {
-               if( group && !vmf_visgroup_match( ent, group_id ) )
+               if( filter_visgroups && !vmf_visgroup_match( ent, group_id ) )
                        continue;
        
                        continue;
        
+               if( filter_classname )
+                       if( strcmp( kv_get( ent, "classname", "" ), filter->classname ) )
+                               continue;
+       
                if( ent->user & VMF_FLAG_IS_PROP )
                {
                        // Create model transform
                if( ent->user & VMF_FLAG_IS_PROP )
                {
                        // Create model transform
@@ -177,13 +203,30 @@ void draw_vmf_group( csr_target *rt, vmf_map *map, vdf_node *root, const char *g
                        m4x3_identity( model );
                        vmf_entity_transform( ent, model );
                        
                        m4x3_identity( model );
                        vmf_entity_transform( ent, model );
                        
-                       draw_vmf_group( rt, map, map->cache[ ent->user1 ].root, group, transform, model );
+                       draw_vmf_group( rt, map, map->cache[ ent->user1 ].root, filter, transform, model );
                }
                }
-               else if( ent->user & VMF_FLAG_BRUSH_ENT )
+               else
                {
                {
-                       // ...
+                       // Brush entity
+                       if( (ent_solid = vdf_next( ent, "solid", NULL )) )
+                       {
+                               solidgen_push( &solid, ent_solid );
+                       }
                }
        }
        
                }
        }
        
+       // Draw brushes
+       for( int i = 0; i < csr_sb_count( solid.indices )/3; i ++ )
+       {
+               u32 * base = solid.indices + i*3;
+               
+               tri[0] = solid.verts[ base[0] ];
+               tri[1] = solid.verts[ base[1] ];
+               tri[2] = solid.verts[ base[2] ];
+               
+               csr_draw( rt, tri, 1, transform );
+       }
+       
+       solidgen_ctx_reset( &solid );
        solidgen_ctx_free( &solid );
 }
        solidgen_ctx_free( &solid );
 }