// delete a portal instance by pointer void PCZSceneManager::destroyPortal(Portal * p) { // remove the portal from it's target portal Portal * targetPortal = p->getTargetPortal(); if (targetPortal) { targetPortal->setTargetPortal(0); // the targetPortal will still have targetZone value, but targetPortal will be invalid } // remove the Portal from it's home zone PCZone * homeZone = p->getCurrentHomeZone(); if (homeZone) { // inform zone of portal change. Do here since PCZone is abstract homeZone->setPortalsUpdated(true); homeZone->_removePortal(p); } // remove the portal from the master portal list PortalList::iterator it = std::find( mPortals.begin(), mPortals.end(), p ); if (it != mPortals.end()) { mPortals.erase(it); } // delete the portal instance OGRE_DELETE p; }
/* Attempt to automatically connect unconnected portals to proper target zones * by looking for matching portals in other zones which are at the same location */ void PCZSceneManager::connectPortalsToTargetZonesByLocation(void) { // go through every zone to find portals ZoneMap::iterator i, iend; PCZone* zone; iend = mZones.end(); bool foundMatch; for (i = mZones.begin(); i != iend; i++) { zone = i->second; // go through all the portals in the zone Portal* portal; PortalList::iterator pi, piend; piend = zone->mPortals.end(); for (pi = zone->mPortals.begin(); pi != piend; pi++) { portal = *pi; //portal->updateDerivedValues(); if (portal->getTargetZone() == 0) { // this is a portal without a connected zone - look for // a matching portal in another zone PCZone* zone2; ZoneMap::iterator j= mZones.begin(); foundMatch = false; while (!foundMatch && j != mZones.end()) { zone2 = j->second; if (zone2 != zone) // make sure we don't look in the same zone { Portal * portal2 = zone2->findMatchingPortal(portal); if (portal2) { // found a match! Ogre::LogManager::getSingletonPtr()->logMessage("Connecting portal "+portal->getName()+" to portal "+portal2->getName()); foundMatch = true; portal->setTargetZone(zone2); portal->setTargetPortal(portal2); portal2->setTargetZone(zone); portal2->setTargetPortal(portal); } } j++; } if (foundMatch == false) { // error, didn't find a matching portal! OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Could not find matching portal for portal " + portal->getName(), "PCZSceneManager::connectPortalsToTargetZonesByLocation"); } } } } }
// delete a portal instance by pointer void PCZSceneManager::destroyPortal(const String & portalName) { // find the portal from the master portal list Portal * p; Portal * thePortal = 0; PortalList::iterator it = mPortals.begin(); while (it != mPortals.end()) { p = *it; if (p->getName() == portalName) { thePortal = p; // erase entry in the master list mPortals.erase(it); break; } it++; } if (thePortal) { // remove the portal from it's target portal Portal * targetPortal = thePortal->getTargetPortal(); if (targetPortal) { targetPortal->setTargetPortal(0); // the targetPortal will still have targetZone value, but targetPortal will be invalid } // remove the Portal from it's home zone PCZone * homeZone = thePortal->getCurrentHomeZone(); if (homeZone) { // inform zone of portal change homeZone->setPortalsUpdated(true); homeZone->_removePortal(thePortal); } // delete the portal instance OGRE_DELETE thePortal; } }