cbspbrush_t * CompileCBspbrushClass( hobj_t *brush, hmanager_t *planehm, hmanager_t *texdefhm ) { int i; cbspbrush_t *bb; hobj_search_iterator_t surfiter; hobj_t *surface; hobj_t *plane; hobj_t *texdef; hpair_t *pair; InitClassSearchIterator( &surfiter, brush, "surface" ); for ( i = 0; ( surface = SearchGetNextClass( &surfiter ) ); i++ ) { } bb = NewBrush( i ); bb->surfacenum = i; pair = FindHPair( brush, "content" ); if ( !pair ) Error( "missing 'contents' in brush '%s'.\n", brush->name ); HPairCastToInt_safe( &bb->contents, pair ); InitClassSearchIterator( &surfiter, brush, "surface" ); for ( i = 0; ( surface = SearchGetNextClass( &surfiter ) ); i++ ) { // contents pair = FindHPair( surface, "content" ); if ( !pair ) Error( "missing 'content' in surface '%s'.\n", surface->name ); HPairCastToInt( &bb->surfaces[i].contents, pair ); // clsref plane pair = FindHPair( surface, "plane" ); if ( !pair ) Error( "missing 'plane' in surface '%s'.\n", surface->name ); plane = HManagerSearchClassName( planehm, pair->value ); bb->surfaces[i].pl = GetClassExtra( plane ); // clsref texdef pair = FindHPair( surface, "texdef" ); if ( !texdefhm || !pair ) { bb->surfaces[i].td = NULL; } else { texdef = HManagerSearchClassName( texdefhm, pair->value ); bb->surfaces[i].td = GetClassExtra( texdef ); } bb->original = brush; SetClassExtra( brush, bb ); } return bb; }
void BuildNodeClassRecursive( hobj_t *node, hmanager_t *planecls ) { cnode_t *n; hobj_t *child; hobj_t *plane; hpair_t *pair; // first remove data of an older portalization RemoveAndDestroyAllHPairsOfKey( node, "portal" ); RemoveAndDestroyAllHPairsOfKey( node, "portalized_leaf" ); n = NewNode(); SetClassExtra( node, n ); n->self = node; pair = FindHPair( node, "plane" ); if ( !pair ) { // leaf pair = FindHPair( node, "contents" ); if ( !pair ) Error( "missing 'contents' in node '%s'.\n", node->name ); HPairCastToInt( &n->contents, pair ); n->type = NodeType_leaf; } else { // node n->type = NodeType_node; plane = HManagerSearchClassName( planecls, pair->value ); if ( !plane ) Error( "node '%s' can't find plane '%s'.\n", node->name, pair->value ); n->pl = GetClassExtra( plane ); child = FindClassType( node, "bspnode_front" ); if ( !child ) Error( "missing 'bspnode_front' in node class.\n" ); BuildNodeClassRecursive( child, planecls ); n->child[0] = GetClassExtra( child ); child = FindClassType( node, "bspnode_back" ); if ( !child ) Error( "missing 'bspnode_back' in node class.\n" ); BuildNodeClassRecursive( child, planecls ); n->child[1] = GetClassExtra( child ); } }
ATOM Window::Register(HINSTANCE hinst) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)Window::s_WinProc; wcex.cbClsExtra = GetClassExtra(); wcex.cbWndExtra = GetWinExtra(); wcex.hInstance = hinst; wcex.hIcon = GetIcon(); wcex.hCursor = GetCursor(); wcex.hbrBackground = GetBrush(); wcex.lpszMenuName = GetMenu(); wcex.lpszClassName = ClassName(); wcex.hIconSm = GetSmallIcon(); return RegisterClassEx(&wcex); }
int main( int argc, char *argv[] ) { int i; char *in_node_name; char *out_portal_name; char *out_node_name; char *in_plane_name; hmanager_t *planecls; hmanager_t *nodecls; void *topnode; int stop_depth; printf( "===== portal - build portals for a bsp tree =====\n" ); SetCmdArgs( argc, argv ); // SetEpsilon( 0.000001, -0.000001 ); in_node_name = GetCmdOpt2( "-i" ); out_node_name = GetCmdOpt2( "-o" ); out_portal_name = GetCmdOpt2( "-p" ); in_plane_name = GetCmdOpt2( "-pl" ); // out_node_portal_name = GetCmdOpt2( "-n" ); if ( GetCmdOpt2( "--stop-depth" ) ) { stop_depth = atoi( GetCmdOpt2( "--stop-depth" ) ); printf ( "Switch: set portalization max depth to %d\n", stop_depth ); } else { stop_depth = 0; printf ( "default portalization max depth id %d\n", stop_depth ); } if ( !in_node_name ) { Error( "no input node file.\n" ); } else { printf( " input bspnode class: %s\n", in_node_name ); } if ( !out_node_name ) { out_node_name = "_portalout_bspnode.hobj"; printf( " default output bspnode class: %s\n", out_node_name ); } else { printf( " output bspnode class: %s\n", out_node_name ); } if ( !out_portal_name ) { out_portal_name = "_portalout_portal.hobj"; printf( " default output portal class: %s\n", out_portal_name ); } else { printf( " output portal class: %s\n", out_portal_name ); } if ( !in_plane_name ) { in_plane_name = "_plane.hobj"; printf( " default input plane class: %s\n", in_plane_name ); } else { printf( " input plane class: %s\n", in_plane_name ); } planecls = ReadPlaneClass( in_plane_name ); nodecls = ReadNodeClass( in_node_name, planecls ); topnode = GetClassExtra( HManagerGetRootClass( nodecls ) ); printf( " topnode %p\n", topnode ); // getchar(); printf( "portalize tree ...\n" ); #if 0 // setup special nodes for ( i = 0; i < p_nodenum; i++ ) { p_nodes[i].plane = p_bspnodes[i].plane; p_nodes[i].index = i; p_nodes[i].portalnum = 0; if ( p_nodes[i].plane < 0 ) { p_nodes[i].child[0] = NULL; p_nodes[i].child[1] = NULL; } else { p_nodes[i].child[0] = &p_nodes[p_bspnodes[i].child[0]]; p_nodes[i].child[1] = &p_nodes[p_bspnodes[i].child[1]]; } p_nodes[i].portals = NULL; } #endif failed_file = fopen( "portalize_fail", "w" ); if ( !failed_file ) Error( "can't open portalize_fail file.\n" ); Portal_MakeHeadNode( topnode ); Portal_MakeNodesRecursive( topnode, stop_depth ); fprintf( failed_file, "end" ); fclose ( failed_file ); printf( " build %d portals\n", p_portalnum ); printf( " %d portalized leafs\n", portalized_num ); printf( "build portal class and update bspnode class ...\n" ); WritePortalClass( out_portal_name, out_node_name, topnode ); // Write_NodePortals( out_node_portal_name, "portal" ); HManagerSaveID(); exit(0); }
/* ==================== ReadPlaneClass ==================== */ hmanager_t * ReadPlaneClass( char *name ) { tokenstream_t *ts; hobj_t *planecls; hmanager_t *hm; hobj_search_iterator_t iter; hobj_t *plane; hobj_t *flipplane; cplane_t *pl; int num; hpair_t *pair; ts = BeginTokenStream( name ); planecls = ReadClass( ts ); EndTokenStream( ts ); hm = NewHManager(); HManagerSetRootClass( hm, planecls ); HManagerRebuildHash( hm ); // // create compiled planes // fprintf( stderr, "load plane class and compile ...\n" ); InitClassSearchIterator( &iter, planecls, "plane" ); for ( num = 0; ( plane = SearchGetNextClass( &iter ) ); num++ ) { pl = NewCPlane(); pl->count = 0; // plane norm pair = FindHPair( plane, "norm" ); if ( !pair ) Error( "missing plane normal.\n" ); HPairCastToVec3d_safe( pl->norm, pair ); // plane dist pair = FindHPair( plane, "dist" ); if ( !pair ) Error( "missing plane distance.\n" ); HPairCastToFloat_safe( &pl->dist, pair ); // plane type pair = FindHPair( plane, "type" ); if ( !pair ) Error( "missing plane type.\n" ); HPairCastToInt_safe( &pl->type, pair ); pl->self = plane; SetClassExtra( plane, pl ); } // // resolve clsref_flipplane // InitClassSearchIterator( &iter, planecls, "plane" ); for ( num = 0; ( plane = SearchGetNextClass( &iter ) ); num++ ) { // plane flipplane clsref pair = FindHPair( plane, "flipplane" ); if ( !pair ) Error( "missinig clsref flipplane" ); flipplane = HManagerSearchClassName( hm, pair->value ); if ( !flipplane ) Error( "can't resolve clsref flipplane.\n" ); pl = GetClassExtra( plane ); pl->flipplane = GetClassExtra( flipplane ); } printf( " %d planes\n", num ); return hm; }
int main( int argc, char *argv[] ) { char *in_brush_name; char *in_plane_name; char *out_field_name; hmanager_t *planehm; hmanager_t *brushhm; map3_t *map; FILE *h; printf( "===== field2 - build field clusters =====\n" ); SetCmdArgs( argc, argv ); in_brush_name = GetCmdOpt2( "-b" ); in_plane_name = GetCmdOpt2( "-pl" ); out_field_name = GetCmdOpt2( "-o" ); if ( !in_brush_name ) { in_brush_name = "_gather1_bspbrush.hobj"; printf( " default input brush class: %s\n", in_brush_name ); } else { printf( " input brush class: %s\n", in_brush_name ); } if ( !in_plane_name ) { in_plane_name = "_plane.hobj"; printf( " default input plane class: %s\n", in_plane_name ); } else { printf( " input plane class: %s\n", in_plane_name ); } if ( !out_field_name ) { out_field_name = "_fieldmap.bin"; printf( " default output field binary: %s\n", out_field_name ); } else { printf( " output field binary: %s\n", out_field_name ); } printf( "loading plane class ...\n" ); planehm = ReadPlaneClass( in_plane_name ); printf( "loading brush class ...\n" ); if ( !(brushhm = NewHManagerLoadClass( in_brush_name ) ) ) Error( "failed\n" ); map = NewMap3Hash(); { hobj_search_iterator_t brushiter; hobj_search_iterator_t surfiter; hobj_search_iterator_t polyiter; hobj_t *brush; hobj_t *surface; hobj_t *plane; hobj_t *texdef; hobj_t *poly; hpair_t *pair; cplane_t *pl; polygon_t *p; int i, num; char tt[256]; InitClassSearchIterator( &brushiter, HManagerGetRootClass( brushhm ), "bspbrush" ); for ( ; ( brush = SearchGetNextClass( &brushiter ) ); ) { InitClassSearchIterator( &surfiter, brush, "surface" ); for ( ; ( surface = SearchGetNextClass( &surfiter ) ); ) { pair = FindHPair( surface, "plane" ); if ( !pair ) Error( "missing 'plane' in surface '%s'.\n", surface->name ); plane = HManagerSearchClassName( planehm, pair->value ); if ( !plane ) Error( "surface '%s' can't find plane '%s'.\n", surface->name, pair->value ); pl = GetClassExtra( plane ); InitClassSearchIterator( &polyiter, surface, "polygon" ); for ( ; ( poly = SearchGetNextClass( &polyiter ) ); ) { pair = FindHPair( poly, "num" ); if ( !pair ) Error( "missing pointnum 'num' of polygon '%s'.\n", poly->name ); HPairCastToInt_safe( &num, pair ); p = NewPolygon( num ); p->pointnum = num; for ( i = 0; i < num; i++ ) { sprintf( tt, "%d", i ); pair = FindHPair( poly, tt ); if ( !pair ) Error( "missing point '%s' of polygon '%s'.\n", tt, poly->name ); HPairCastToVec3d( p->p[i], pair ); } DistributePolygon( map, p, pl ); } } } } Map3Normalize( map ); printf( " %d field patches\n", fieldpatchnum ); printf( " %d field cells\n", fieldcellnum ); h = fopen( out_field_name, "w" ); if ( !h ) Error( "can't open output file.\n" ); WriteMap3( map, h ); fclose( h ); }
hobj_t * BuildVisleaf( hobj_t *leaf, hmanager_t *portalhm, hmanager_t *nodehm, hmanager_t *planehm ) { hpair_search_iterator_t iter; bool_t flip; cplane_t *pl; hobj_t *portal; hobj_t *otherleaf; hobj_t *vportal; hobj_t *plane; hobj_t *visleaf; hpair_t *pair; char tt[256]; vec3d_t center, pc, min, max; int num; Vec3dInit( center, 0, 0, 0 ); Vec3dInitBB( min, max, 999999.9 ); sprintf( tt, "#%u", HManagerGetFreeID() ); visleaf = NewClass( "visleaf", tt ); InitHPairSearchIterator( &iter, leaf, "portal" ); for ( num = 0; ( pair = SearchGetNextHPair( &iter ) ); num++ ) { portal = HManagerSearchClassName( portalhm, pair->value ); if ( !portal ) Error( "leaf '%s' can't find portal '%s'.\n", leaf->name, pair->value ); CalcPortalCenter( portal, pc, min, max ); Vec3dAdd( center, center, pc ); // get otherleaf pair = FindHPair( portal, "frontnode" ); if ( !pair ) Error( "missing 'frontnode' in portal '%s'.\n", portal->name ); if ( !strcmp( pair->value, leaf->name ) ) { // I'm the frontnode of the portal, let's go to the backnode pair = FindHPair( portal, "backnode" ); if ( !pair ) Error( "missing 'backnode' in portal '%s'.\n", portal->name ); otherleaf = HManagerSearchClassName( nodehm, pair->value ); if ( !otherleaf ) Error( "portal '%s' can't find leaf '%s'.\n", portal->name, pair->value ); flip = true; } else { otherleaf = HManagerSearchClassName( nodehm, pair->value ); if ( !otherleaf ) Error( "portal '%s' can't find leaf '%s'.\n", portal->name, pair->value ); flip = false; } pair = FindHPair( portal, "plane" ); if ( !pair ) Error( "missing 'plane' of portal '%s'.\n", portal->name ); plane = HManagerSearchClassName( planehm, pair->value ); if ( !plane ) Error( "portal '%s' can't find plane '%s'.\n", portal->name, pair->value ); pl = GetClassExtra( plane ); if ( flip ) pl = pl->flipplane; sprintf( tt, "#%u", HManagerGetFreeID() ); vportal = NewClass( "portal", tt ); pair = NewHPair2( "ref", "plane", pl->self->name ); InsertHPair( vportal, pair ); CopyPortalPolygonToPortal( vportal, portal, flip ); pair = FindHPair( portal, "state" ); if ( !pair ) Error( "missing 'state' of portal '%s'.\n", portal->name ); if ( !strcmp( pair->value, "open" ) ) { // open portal goes to othernode pair = NewHPair2( "ref", "otherleaf", otherleaf->name ); InsertHPair( vportal, pair ); } else { // closed portals pair = NewHPair2( "ref", "touchleaf", otherleaf->name ); InsertHPair( visleaf, pair ); // hack: also insert touchleaf into the closed portal pair = NewHPair2( pair->type, pair->key, pair->value ); InsertHPair( vportal, pair ); } InsertClass( visleaf, vportal ); } // leaf center Vec3dScale( center, 1.0/num, center ); pair = NewHPair2( "vec3d", "center", "x" ); HPairCastFromVec3d( center, pair ); InsertHPair( visleaf, pair ); // leaf bounds min pair = NewHPair2( "vec3d", "min", "x" ); HPairCastFromVec3d( min, pair ); InsertHPair( visleaf, pair ); // leaf bounds max pair = NewHPair2( "vec3d", "max", "X" ); HPairCastFromVec3d( max, pair ); InsertHPair( visleaf, pair ); return visleaf; }