#include "vmdl.h"
#include "vmf.h"
-
// CSR main
#include "csrDraw.h"
#include "csr32f.h"
vmf_map *map = vmf_init( argv[1], 1 );
- // TODO: Make init/free codes
- csr_target target =
+ csr_target target;
+
+ csr_create_target( &target, 1024, 1024, (v4f){ -1000.f, -1000.f, 1000.f, 1000.f } );
+ csr_rt_clear( &target );
+
+ csr_filter filter_layout =
{
- .x = 1024, .y = 1024,
- .fragments = (csr_frag *)csr_malloc( 1024*1024*sizeof(csr_frag) ),
- .bounds = { -1000.f, -1000.f, 1000.f, 1000.f }
+ .classname = NULL,
+ .visgroup = "tar_layout"
};
- csr_rt_clear( &target );
- draw_vmf_group( &target, map, map->root, "tar_layout", NULL, NULL );
+ csr_filter filter_buyzone =
+ {
+ .classname = "func_buyzone",
+ .visgroup = NULL
+ };
+
+ draw_vmf_group( &target, map, map->root, &filter_buyzone, NULL, NULL );
float *rgba_test = (float *)csr_malloc( 1024*1024*sizeof(float)*3 );
csr_32f_write( "hello.pfm", 1024, 1024, rgba_test );
- free( target.fragments );
+ csr_rt_free( &target );
+
free( rgba_test );
vmf_free( map );
fs_exit();
typedef struct csr_frag csr_frag;
typedef struct csr_target csr_target;
+typedef struct csr_filter csr_filter;
struct csr_frag
{
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 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];
+ vdf_node *ent_solid;
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 );
}
- // Draw brushes
+ // Gather world brushes
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 )
{
- if( group && !vmf_visgroup_match( ent, group_id ) )
+ if( filter_visgroups && !vmf_visgroup_match( ent, group_id ) )
continue;
+ if( filter_classname )
+ if( strcmp( kv_get( ent, "classname", "" ), filter->classname ) )
+ continue;
+
if( ent->user & VMF_FLAG_IS_PROP )
{
// Create model transform
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 );
}