int main() { // This has to be done before anything else. This initializes // all of the registry information for the schema you are using. // The SchemaInit() function is generated by exp2cxx... see // extern statement above. Registry * registry = new Registry( SchemaInit ); // The nifty thing about the Registry is that it basically keeps a list // of everything in your schema. What this means is that we can go // through the Registry and instantiate, say, one of everything, without // knowing at coding-time what entities there are to instantiate. So, // this test could be linked with other class libraries produced from // other schema, rather than the example, and run happily. InstMgr instance_list; // Here's what's going to happen below: we're going to figure out // how many different entities there are, instantiate one of each and // keep an array of pointers to each. We'll stick some random data in // them as we go. When we're done, we'll print out everything by walking // the array, and then write out the STEPfile information to the screen. // Figure outhow many entities there are, then allocate an array // to store a pointer to one of each. int num_ents = registry->GetEntityCnt(); STEPentity ** SEarray = new STEPentity*[num_ents]; // "Reset" the Schema and Entity hash tables... this sets things up // so we can walk through the table using registry->NextEntity() registry->ResetSchemas(); registry->ResetEntities(); // Print out what schema we're running through. const SchemaDescriptor * schema = registry->NextSchema(); cout << "Entities in schema " << schema->Name() << ":\n"; // "Loop" through the schema, building one of each entity type. const EntityDescriptor * ent; // needs to be declared const... for ( int i = 0; i < num_ents; i++ ) { ent = registry->NextEntity(); // Build object, using its name, through the registry SEarray[i] = registry->ObjCreate( ent->Name() ); // Add each realized entity to the instance list instance_list.Append( SEarray[i], completeSE ); // Put some data into each instance PrintEntity( SEarray[i] ); } // Print out all entities SEarrIterator SEitr( ( const STEPentity ** ) SEarray, num_ents ); exit( 0 ); }
/* =============== ProcessEntity =============== */ void ProcessEntity (int entnum) { entity_t *ent; char mod[80]; surface_t *surfs; node_t *nodes; brushset_t *bs; ent = &entities[entnum]; if (!ent->brushes) return; // non-bmodel entity if (entnum > 0) { worldmodel = false; if (entnum == 1) qprintf ("--- Internal Entities ---\n"); sprintf (mod, "*%i", nummodels); if (verbose) PrintEntity (ent); if (hullnum == 0) printf ("MODEL: %s\n", mod); SetKeyValue (ent, "model", mod); } else worldmodel = true; // // take the brush_ts and clip off all overlapping and contained faces, // leaving a perfect skin of the model with no hidden faces // bs = Brush_LoadEntity (ent, hullnum); if (!bs->brushes) { PrintEntity (ent); Error ("Entity with no valid brushes"); } brushset = bs; surfs = CSGFaces (bs); if (hullnum != 0) { nodes = SolidBSP (surfs, true); if (entnum == 0 && !nofill) // assume non-world bmodels are simple { PortalizeWorld (nodes); if (FillOutside (nodes)) { surfs = GatherNodeFaces (nodes); nodes = SolidBSP (surfs, false); // make a really good tree with proper heuristic splitting plane selection } FreeAllPortals (nodes); } WriteNodePlanes (nodes); WriteClipNodes (nodes); BumpModel (hullnum); } else { // // SolidBSP generates a node tree // // if not the world, make a good tree first // the world is just going to make a bad tree // because the outside filling will force a regeneration later nodes = SolidBSP (surfs, entnum == 0); // // build all the portals in the bsp tree // some portals are solid polygons, and some are paths to other leafs // if (entnum == 0 && !nofill) // assume non-world bmodels are simple { PortalizeWorld (nodes); if (FillOutside (nodes)) { FreeAllPortals (nodes); // get the remaining faces together into surfaces again surfs = GatherNodeFaces (nodes); // merge polygons MergeAll (surfs); // make a really good tree nodes = SolidBSP (surfs, false); // make the real portals for vis tracing PortalizeWorld (nodes); // save portal file for vis tracing WritePortalfile (nodes); // fix tjunctions tjunc (nodes); } FreeAllPortals (nodes); } WriteNodePlanes (nodes); MakeFaceEdges (nodes); WriteDrawNodes (nodes); } }