/* ================================================== G_MapTryClassLoad ================================================== */ hmanager_t * G_MapTryClassLoad( const char *path, const char *name ) { hmanager_t *hm; tokenstream_t *ts; hobj_t *root; char tt[256]; // printf( "path: \"%s\"\n", path ); sprintf( tt, "%s/%s", path, name ); // printf( "loading: %s", name ); GC_GiveBackTime(); ts = BeginTokenStream( tt ); if ( !ts ) return NULL; root = ReadClass( ts ); if ( !root ) return NULL; EndTokenStream( ts ); hm = NewHManagerFromClass( root ); if ( !hm ) return NULL; return hm; }
/*-----------------------------------------------------------------------------* | ReadClass: function ricorsiva per la lettura di una classe | | | | | | Data creazione: 16/12/2008 Autore: Arcadio Ciro | *-----------------------------------------------------------------------------*/ int ReadClass ( FILE *lc, //file da leggere STACK **Stack//stack degli elementi caricati dal file ) { int Tag,Error;//tag numerici e stato d'errore char *ReadBuffer;//buffer di lettura TREE *Leaf;//foglie dell'alero da caricare nello stack //allocazione del buffer di lettura ReadBuffer=(char*)calloc(BUFFSIZE,sizeof(char)); Leaf=NULL; //2 --> NESSUN ERRORE Error=2; do { //scansione del file carattere per carattere PopChar(lc,&ReadBuffer); //verifica eventuali TAG Tag=IsTag(ReadBuffer); } while(!Tag && !feof(lc)); switch(Tag) //switch del TAG trovato { case CLASS : NewLeaf(&Leaf); //CLASSE trovata LoadLeaf(lc,&Leaf); //acquisizione delle informazioni Push_STACK(Leaf,Stack); ReadClass(lc,Stack); break; case END : Error=0; break; //fine del FILE } free(ReadBuffer);//liberazione memoria del buffer di lettura return Error;//ritorno dello stato d'errore }
/* ============================== ReadPolygonList ============================== */ u_list_t * ReadPolygonList( char *name ) { u_list_t *poly_list; hobj_t *poly_root; hobj_search_iterator_t iter; hobj_t *polygon; tokenstream_t *ts; poly_list = NEWTYPE( u_list_t ); ts = BeginTokenStream( name ); if ( !ts ) Error( "can't open raw polygon class '%s'\n", name ); poly_root = ReadClass( ts ); EndTokenStream( ts ); U_InitList( poly_list ); InitClassSearchIterator( &iter, poly_root, "polygon" ); for ( ; ( polygon = SearchGetNextClass( &iter ) ) ; ) { polygon_t *p; p = CreatePolygonFromClass( polygon ); if ( !p ) Error( "CreatePolygonFromClass failed\n" ); U_ListInsertAtHead( poly_list, p ); } return poly_list; }
u_list_t * BuildVertexListFromClass( char *name ) { tokenstream_t *ts; hobj_t *root; u_list_t *list; hobj_search_iterator_t iter; hobj_t *vertex; ts = BeginTokenStream( name ); if ( !ts ) Error( "can't open vertex class\n" ); root = ReadClass( ts ); EndTokenStream( ts ); list = U_NewList(); InitClassSearchIterator( &iter, root, "vertex" ); for ( ; ( vertex = SearchGetNextClass( &iter ) ) ; ) { vertex_t *tmp; tmp = NEWTYPE( vertex_t ); U_ListInsertAtHead( list, tmp ); EasyFindVec3d( tmp->vec, vertex, "vec" ); } return list; }
void* Stream::ReadObject() { uint32 id; Read(&id, 4); if (id == 0) { return NULL; } map<uint32, void*>::iterator it = m_objectmapLoad.find(id); if (it != m_objectmapLoad.end()) { return (*it).second; } else { // We don't call any constructors.. hmm. char classname[256] = {0}; Read(classname, 256); ClassType* pType = (ClassType*)pD->LookupNamedType(classname); ASSERT(pType); uint8* object = new /*(pHeap)*/ uint8[pType->get_sizeof()]; ReadClass(object, pType); return object; } return NULL; }
void SHM_StartUp() { tokenstream_t *ts; ts = BeginTokenStream( "menu/menu.hobj" ); __chkptr( ts ); menu = ReadClass( ts ); __chkptr( menu ); EndTokenStream( ts ); strcpy( curpage, "none" ); powerless = 0; snd_enter = G_ResourceSearch( g_rs, "menu.sound.enter" ); __chkptr( snd_enter ); snd_escape = G_ResourceSearch( g_rs, "menu.sound.escape" ); __chkptr( snd_escape ); snd_scroll = G_ResourceSearch( g_rs, "menu.sound.scroll" ); __chkptr( snd_scroll ); }
u_list_t * BuildPolygonListFromClass( char *name ) { tokenstream_t *ts; hobj_t *root; hobj_t *polygon; hobj_search_iterator_t iter; u_list_t *list; ts = BeginTokenStream( name ); if ( !ts ) Error( "can't open polygon class\n" ); root = ReadClass( ts ); EndTokenStream( ts ); list = U_NewList(); InitClassSearchIterator( &iter, root, "polygon" ); for ( ; ( polygon = SearchGetNextClass( &iter ) ) ; ) { polygon_t *p; p = CreatePolygonFromClass( polygon ); U_ListInsertAtHead( list, p ); } return list; }
void Stream::ReadClass(uint8* object, ClassType* pType) { for (unsigned int i = 0; i < pType->m_bases.size(); i++) { ReadClass(object + pType->m_bases[i]->m_offset, pType->m_bases[i]->m_pClass->GetClass()); } ReadMembers(object, pType); }
void BuildTreeFromClass( char *name ) { tokenstream_t *ts; hobj_search_iterator_t iter; hobj_t *root; hobj_t *node; hpair_t *pair; ts = BeginTokenStream( name ); if ( !ts ) Error( "can't open node class\n" ); root = ReadClass( ts ); EndTokenStream( ts ); g_num_node = 0; InitClassSearchIterator( &iter, root, "bspnode" ); for ( ; ( node = SearchGetNextClass( &iter ) ) ; ) { int index; EasyFindInt( &index, node, "index" ); if ( index >= MAX_NUM_NODES ) Error( "reached MAX_NUM_NODES\n" ); pair = FindHPair( node, "type" ); if ( !pair ) Error( "missing key 'type' in bspnode\n" ); if ( !strcmp( pair->value, "node" ) ) { // node EasyFindVec3d( g_nodes[index].norm, node, "norm" ); EasyFindFloat( &g_nodes[index].dist, node, "dist" ); // printf( "dist: %f, norm: ", g_nodes[index].dist ); Vec3dPrint( g_nodes[index].norm ); EasyFindInt( &g_nodes[index].child[0], node, "child_front" ); EasyFindInt( &g_nodes[index].child[1], node, "child_back" ); g_num_node++; } else { // leaf g_nodes[index].child[0] = -1; g_nodes[index].child[1] = -1; g_num_leaf++; } } }
hmanager_t * ReadBspbrushClass( char *name, face_t **list ) { tokenstream_t *ts; hobj_t *bspbrushcls; hobj_t *bspbrush; hobj_t *surface; hmanager_t *hm; hobj_search_iterator_t iter; hobj_search_iterator_t surfiter; hobj_search_iterator_t polyiter; hpair_t *pair; face_t *f; int num, i, j; hobj_t *poly; fprintf( stderr, "load bspbrush class ...\n" ); *list = NULL; ts = BeginTokenStream( name ); bspbrushcls = ReadClass( ts ); EndTokenStream( ts ); hm = NewHManager(); HManagerSetRootClass( hm, bspbrushcls ); HManagerRebuildHash( hm ); printf( "#%u\n", HManagerGetFreeID() ); InitClassSearchIterator( &iter, bspbrushcls, "bspbrush" ); for ( num = 0; ( bspbrush = SearchGetNextClass( &iter ) ); num++ ) { InitClassSearchIterator( &surfiter, bspbrush, "surface" ); for ( i = 0; ( surface = SearchGetNextClass( &surfiter ) ); i++ ) { InitClassSearchIterator( &polyiter, surface, "polygon" ); for ( j = 0; ( poly = SearchGetNextClass( &polyiter ) ); j++ ) { polygon_num++; f = NewFaceFromPolygonClass( poly ); f->surface = surface; f->self = poly; f->next = *list; *list = f; } } } return hm; }
/*-----------------------------------------------------------------------------* | LcOpen : legge un file caricandolo in un albero binario. | | | | | | Data creazione: 16/12/2008 Autore: Arcadio Ciro | *-----------------------------------------------------------------------------*/ int LcOpen ( TREE** Tree //albero di OutPut ) { int Error; //stato d'errore int TotLeafs;//totale foglie FILE *lc; //file da leggere char *ReadBuffer;//buffer di lettura STACK *Stk; //stack temporaneo TotLeafs=0; //allocazione del buffer ReadBuffer=(char*)calloc(BUFFSIZE,sizeof(char)); Error=0; //Path del file lc=fopen("maps/cities.lc","r"); //se l'apertura è andata a buon fine if(lc!=NULL) { do PopChar(lc,&ReadBuffer); //i caratteri restituiti da PopChar vengono salvati nel Buffer while(IsTag(ReadBuffer)!=BEGIN && !feof(lc)); //Init dello STACK Init_STACK(&Stk); //Chiamata a ReadClass ReadClass(lc,&Stk); //chiusura del FILE fclose(lc); } else Error=202; //stato d'errore //conversione dello stack in albero tramite visita in ampiezza *Tree=StackToTree(&Stk,&TotLeafs); //viene liberata la memoria usata dallo stack Free_STACK(&Stk); //liberazione del buffer di lettura free(ReadBuffer); //ritorno dello stato d'errore return Error; }
hmanager_t * ReadNodeClass( char *name, hmanager_t *planecls ) { tokenstream_t *ts; hobj_t *nodecls; hmanager_t *hm; printf( "load and compile bspnode class ...\n" ); ts = BeginTokenStream( name ); nodecls = ReadClass( ts ); EndTokenStream( ts ); hm = NewHManager(); HManagerSetRootClass( hm, nodecls ); HManagerRebuildHash( hm ); BuildNodeClassRecursive( nodecls, planecls ); printf( " %d nodes\n", p_nodenum ); return hm; }
/* ============================== G_InitMap ============================== */ void G_InitMap( g_map_t *map ) { // g_map_t *map; char lightmap_bin[256]; char lightmap_class[256]; char lightsource_class[256]; char tt[256]; char path[256]; tokenstream_t *ts; sh_var_t *tmp; INITTYPE( map, g_map_t ); map->state = gMapState_try_init; SHV_Printf( "\n" ); SHV_Printf( " --- Init Map ---\n" ); tmp = SHP_GetVar( "gc_map" ); SHV_Printf( "gc_map is '%s'\n", tmp->string ); sprintf( path, "world/%s.d/fake", tmp->string ); SHV_Printf( "path: '%s'\n", path ); // SHV_Printf( "create new game map\n" ); // map = NEWTYPE( g_map_t ); // // load multilayer defs // SHV_Printf( "load multilayer definition class\n" ); { hobj_t *root; ts = BeginTokenStream( "shape_config/multilayer.hobj" ); if ( !ts ) __error( "can't open shape_config/multilayer.hobj" ); root = ReadClass( ts ); EndTokenStream( ts ); map->multilayerhm = NewFlatHManagerFromClass( root ); } // // bsp classes // printf( "load map classes\n" ); G_SpawnMap( map, path ); printf( "setup map data\n" ); R_InitData( map ); // // load lightmap database // printf( "setup lightmap database\n" ); #if 0 map->lightmap_db = NEWTYPE( db_lightmap_t ); LightmapDB_Init( map->lightmap_db ); sprintf( lightmap_bin, "%s/%s", path, MAP_BIN_NAME_LIGHTMAP ); sprintf( lightmap_class, "%s/%s", path, MAP_CLASS_NAME_LIGHTMAP ); sprintf( lightsource_class, "%s/%s", path, "_light_source.class" ); LightmapDB_Load( map->lightmap_db, lightmap_bin, lightmap_class, lightsource_class ); #else sprintf( lightmap_bin, "%s/%s", path, MAP_BIN_NAME_LIGHTMAP ); sprintf( lightmap_class, "%s/%s", path, MAP_CLASS_NAME_LIGHTMAP ); sprintf( lightsource_class, "%s/%s", path, "_light_source.hobj" ); map->lightmap_db = new lightmap_db_cpp(lightmap_bin, lightmap_class, lightsource_class); //LightmapDB_Load( map->lightmap_db, lightmap_bin, lightmap_class, lightsource_class ); // map->lightmap_db->load( lightmap_bin, lightmap_class, lightsource_class ); #endif // // init shape database // printf( "setup shape database\n" ); map->shape_db = NEWTYPE( db_shape_t ); ShapeDB_Init( map->shape_db ); // // load glmesh binary // { int filesize; ib_file_t *h; sprintf( tt, "%s/%s", path, MAP_BIN_NAME_GLMESH ); h = IB_Open( tt ); if ( !h ) __error( "can't open glmesh binary\n" ); filesize = IB_GetSize( h ); map->glmesh = (unsigned char *)NEWBYTES( filesize ); IB_Read( map->glmesh, filesize, 1, h ); IB_Close( h ); } // // render stuff // printf( "setup subimage cache\n" ); map->imgcache = IC_NewMgr( 128, 128, 64+32 ); printf( "setup shader manager\n" ); map->shader_mgr = Shader_NewMgr(); printf( "setup shapes\n" ); R_SetupShapes( map ); R_InitGLResources(); SHV_Printf( "\n" ); SHV_Printf( "setup tesselation ...\n" ); // sort the shapes into the bsp tree R_SetupShapeRefs(); // render3.c SHV_Printf( "\n" ); G_InitData( map ); R_AllShapesLoadLightmaps(); SHV_Printf( "\n" ); SHV_Printf( " --- Init Map done ---\n" ); map->state = gMapState_is_init; // return map; }
/* ==================== 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_node_name; char *in_portal_name; char *in_plane_name; char *out_node_name; char *out_visleaf_name; hmanager_t *nodehm; hmanager_t *portalhm; hmanager_t *planehm; hobj_t *visleafcls; tokenstream_t *ts; FILE *h; printf( "===== visleaf - build a initial visleaf class for pvs generation =====\n" ); SetCmdArgs( argc, argv ); in_portal_name = GetCmdOpt2( "-p" ); in_node_name = GetCmdOpt2( "-n" ); in_plane_name = GetCmdOpt2( "-pl" ); out_node_name = GetCmdOpt2( "-o" ); out_visleaf_name = GetCmdOpt2( "-v" ); if ( !in_portal_name ) { in_portal_name = "_mkpcout_portal.hobj"; printf( " default input portal class: %s\n", in_portal_name ); } else { printf( " input portal class: %s\n", in_portal_name ); } if ( !in_node_name ) { in_node_name = "_leafflood_bspnode.hobj"; printf( " default input bspnode class: %s\n", in_node_name ); } else { printf( " input bspnode class: %s\n", in_node_name ); } if ( !out_node_name ) { out_node_name = "_visleaf_bspnode.hobj"; printf( " default output bspnode class: %s\n", out_node_name ); } else { printf( " output bspnode class: %s\n", out_node_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_visleaf_name ) { out_visleaf_name = "_visleaf_visleaf.hobj"; printf( " default output visleaf class: %s\n", out_visleaf_name ); } else { printf( " output visleaf class: %s\n", out_visleaf_name ); } printf( "load portal class ...\n" ); ts = BeginTokenStream( in_portal_name ); if ( !ts ) Error( "can't open portal class.\n" ); portalhm = NewHManager(); HManagerSetRootClass( portalhm, ReadClass( ts ) ); EndTokenStream( ts ); HManagerRebuildHash( portalhm ); printf( "load bspnode class ...\n" ); ts = BeginTokenStream( in_node_name ); if ( !ts ) Error( "can't open bspnode class.\n" ); nodehm = NewHManager(); HManagerSetRootClass( nodehm, ReadClass( ts ) ); EndTokenStream( ts ); HManagerRebuildHash( nodehm ); planehm = ReadPlaneClass( in_plane_name ); printf( "build visleafs ...\n" ); visleafcls = NewClass( "visleafs", "visleafs0" ); BuildVisleafsRecursive( HManagerGetRootClass( nodehm ), portalhm, nodehm, planehm, visleafcls ); printf( "fix otherleaf clsref ...\n" ); printf( " %d visleafs total\n", FixOtherleafs( visleafcls, nodehm ) ); h = fopen( out_visleaf_name, "w" ); if ( !h ) Error( "can't open file.\n" ); WriteClass( visleafcls, h ); fclose( h ); h = fopen( out_node_name, "w" ); if ( !h ) Error( "can't open file.\n" ); WriteClass( HManagerGetRootClass( nodehm ), h ); fclose( h ); HManagerSaveID(); }
int main( int argc, char *argv[] ) { char *in_name; char *out_name_prefix; char *in_plane_name; tokenstream_t *ts; hobj_t *sbrushcls; hmanager_t *hm; fp_t pump_brush_dist; unsigned int pump_brush_contents; printf( "===== w2p2 - preprocess wired sbrush class =====\n" ); SetCmdArgs( argc, argv ); if ( argc == 2 ) { if ( !strcmp( argv[1], "-h" ) || !strcmp( argv[1], "--help" ) ) { PrintHelp(); exit(-1); } } in_name = GetCmdOpt2( "-i" ); if ( !in_name ) { in_name = "sbrush.hobj"; printf( " default input brush class: %s\n", in_name ); } else { printf( " input brush class: %s\n", in_name ); } printf( "in_name: %s\n", in_name ); ts = BeginTokenStream( in_name ); sbrushcls = ReadClass( ts ); EndTokenStream( ts ); // DeepDumpClass( sbrushcls ); hm = NewHManager(); HManagerSetRootClass( hm, sbrushcls ); HManagerRebuildHash( hm ); if ( ! HManagerCheckClassConsistancy( hm ) ) { Error( "please fix class !\n" ); } // DumpHManager( hm, false ); fprintf( stderr, "building _bspbrush.hobj ..." ); ConvertSBrushes( hm, "_bspbrush.hobj" ); printf( "add BIG_BOX planes ...\n" ); MakeBigBox( BIG_BOX ); // shared/defs.h in_plane_name = GetCmdOpt2( "-ipl" ); if ( in_plane_name ) { hmanager_t *inplanehm; FILE *h; if ( ! (inplanehm = NewHManagerLoadClass( in_plane_name ) ) ) Error( "inplane load failed\n" ); printf( "do additional planes ...\n" ); AddPlaneClasses( inplanehm ); h = fopen( in_plane_name, "w" ); if ( !h ) Error( "can't write inplane\n" ); WriteClass( HManagerGetRootClass( inplanehm ), h ); fclose( h ); } #if 0 printf( " write files ...\n" ); printf( " planes.asc\n" ); Write_Planes( p_planes, p_planenum, "planes.asc", "w2p" ); printf( " textures.asc\n" ); Write_WTextures( p_wtextures, p_wtexturenum, "textures.asc", "w2p" ); printf( " texdefs.asc\n" ); Write_WTexdefs( "texdefs.asc" ); printf( " wsurfaces.asc\n" ); Write_WSurfaces( "wsurfaces.asc" ); printf( " wbrushes.asc\n" ); Write_WBrushes( "wbrushes.asc" ); printf( " initbspbrushes.asc\n" ); Write_InitialBspbrushes( "initbspbrushes.asc" ); printf( " - WBrush Statistic -\n" ); printf( " %d solid, ", stat_wbrush_solidnum ); printf( "%d liquid, ", stat_wbrush_liquidnum ); printf( "%d deco, ", stat_wbrush_deconum ); printf( "%d hint\n", stat_wbrush_hintnum ); #endif printf( " planes: %d, %d are axial\n", p_planenum, stat_axialplanes ); printf( " textures: %d\n", p_wtexturenum ); printf( " texdefs: %d\n", p_wtexdefnum ); printf( " %d surfaces are set to 'bsp_dont_split'\n", stat_cpoly_hack ); printf( "_plane.hobj\n" ); WritePlaneClass( "_plane.hobj" ); printf( "_texdef.hobj\n" ); WriteTexdefClass( "_texdef.hobj" ); printf( "_texture.hobj\n" ); WriteTextureClass( "_texture.hobj" ); HManagerSaveID(); #if 0 printf( " - WArcheType Statistic -\n" ); printf( " archetypes: %d\n", stat_warche_num ); printf( " pairs: %d\n", stat_wkvpair_num ); #endif }