Esempio n. 1
0
void psWorld::BuildWarpCache()
{
    int sectorCount = engine->GetSectors()->GetCount();
    Debug2(LOG_STARTUP,0,"Building warp cache for %d sectors...",sectorCount);

    /// Clear existing entries
    transarray.Empty();

    transarray.SetSize(sectorCount);

    for(int i=0; i<sectorCount; i++)
    {
        const csSet<csPtrKey<iMeshWrapper> > &portals = engine->GetSectors()->Get(i)->GetPortalMeshes();
        Debug3(LOG_STARTUP,0," %zu portal meshes for %s",portals.GetSize(),
               engine->GetSectors()->Get(i)->QueryObject()->GetName());

        csSet<csPtrKey<iMeshWrapper> >::GlobalIterator it = portals.GetIterator();
        while(it.HasNext())
        {
            iMeshWrapper* portal_mesh = it.Next();
            iPortalContainer* pc = portal_mesh->GetPortalContainer();
            for(int j = 0 ; j < pc->GetPortalCount() ; j++)
            {
                iPortal* portal = pc->GetPortal(j);
                if(portal->CompleteSector(0))
                {
                    if(engine->GetSectors()->Find(portal->GetSector()) != -1)
                    {
                        const csReversibleTransform warp = portal->GetWarp();

                        // Check the values and issue warning for strange values.
                        csVector3 v_o2t = warp.GetO2TTranslation();
                        if(fabs(v_o2t.x) > 1.0e+10 || fabs(v_o2t.y) > 1.0e+10 || fabs(v_o2t.z) > 1.0e+10)
                        {
                            Error3("Warpspace with very large o2t translation:  %s: %s",
                                   portal->GetName(),warp.Description().GetData());
                        }

                        // Apply the warp to the chache
                        transarray[i].Set(portal->GetSector(), warp);
                    }
                }
            }
        }
    }
}