virtual bool EatKey(const plKey& key) { uint32_t count = plCommonObjLib::GetNumLibs(); for (uint32_t i = 0; i < count; i++) { plCommonObjLib* lib = plCommonObjLib::GetLib(i); if (lib->IsInteresting(key)) { // Lib wants this guy, so load the object and add it // Note: we want to switch to passive mode here, so any keys read in // will NOT force a load on whichever page those keys belong to. Otherwise, // we'd have to load that entire page and ref all the objects all over // again and I just really don't want to do that... plResMgrSettings::Get().SetPassiveKeyRead(true); hsKeyedObject* object = key->VerifyLoaded(); plResMgrSettings::Get().SetPassiveKeyRead(false); lib->AddObject(object); break; } } return true; }
bool plPluginResManager::NukeKeyAndObject(plKey& objectKey) { class plPublicRefKey : public plKeyImp { public: uint16_t GetRefCount() const { return fRefCount; } }; plKeyImp* keyData = (plKeyImp*)objectKey; // Check the ref count on the object. Nobody should have a ref to it // except the key hsKeyedObject* object = objectKey->ObjectIsLoaded(); if (object != nil) { if (keyData->GetActiveRefs()) // Somebody still has a ref to this object, so we can't nuke it return false; } // Nobody has a ref to the object, so we're clear to nuke keyData->SetObjectPtr(nil); // Check the key. The refcount should be 1 at this point, for the copy // we're holding in this function. Nobody else should be holding the key // now that the object is gone. if (((plPublicRefKey*)keyData)->GetRefCount() > 1) return false; // Nuke out the key as well objectKey = nil; // All done! return true; }
void plSimulationMgr::UpdateDetectorsInScene(plKey world, plKey avatar, hsPoint3& pos, bool entering) { // search thru the actors in a scene looking for convex hull detectors and see if the avatar is inside it // ... and then send appropiate collision message if needed NxScene* scene = GetScene(world); plSceneObject* avObj = plSceneObject::ConvertNoRef(avatar->ObjectIsLoaded()); const plCoordinateInterface* ci = avObj->GetCoordinateInterface(); hsPoint3 soPos = ci->GetWorldPos(); if (scene) { uint32_t numActors = scene->getNbActors(); NxActor** actors = scene->getActors(); for (int i = 0; i < numActors; i++) { plPXPhysical* physical = (plPXPhysical*)actors[i]->userData; if (physical && physical->DoDetectorHullWorkaround()) { if ( physical->IsObjectInsideHull(pos) ) { physical->SetInsideConvexHull(entering); // we are entering this world... say we entered this detector ISendCollisionMsg(physical->GetObjectKey(), avatar, entering); } } } } }
// check to make sure that the avatar and the exclude region are in the same subworld bool plExcludeRegionModifier::ICheckSubworlds(plKey avatar) { plSceneObject* avObj = plSceneObject::ConvertNoRef(avatar->GetObjectPtr()); if (avObj) { // get the avatar modifier const plArmatureMod *avMod = (plArmatureMod*)avObj->GetModifierByType(plArmatureMod::Index()); if (avMod) { // get the avatar controller plPhysicalControllerCore* avController = avMod->GetController(); if (avController) { // get physical of the detector region plPhysical* phys = GetPhysical(GetTarget()); if (phys) { // are they in the same subworld? if ( phys->GetWorldKey() == avController->GetSubworld() ) return true; else return false; } } } } return false; }
int plExcludeRegionModifier::IFindClosestSafePoint(plKey avatar) { float closestDist = 0.f; int closestIdx = -1; plSceneObject* avObj = plSceneObject::ConvertNoRef(avatar->GetObjectPtr()); if (!avObj) return -1; hsVector3 avPos; avObj->GetCoordinateInterface()->GetLocalToWorld().GetTranslate(&avPos); for (int i = 0; i < fSafePoints.size(); i++) { plSceneObject* safeObj = plSceneObject::ConvertNoRef(fSafePoints[i]->GetObjectPtr()); hsVector3 safePos; safeObj->GetCoordinateInterface()->GetLocalToWorld().GetTranslate(&safePos); float dist = (safePos - avPos).Magnitude(); if (dist < closestDist || closestIdx == -1) { closestDist = dist; closestIdx = i; } } return closestIdx; }
// // write to net msg and send to server // void plSDLModifier::ISendNetMsg(plStateDataRecord*& state, plKey senderKey, uint32_t sendFlags) { hsAssert(senderKey, "nil senderKey?"); plSynchedObject* sobj = plSynchedObject::ConvertNoRef(senderKey->ObjectIsLoaded()); if (sobj && (sobj->IsInSDLVolatileList(GetSDLName()))) state->SetFlags(state->GetFlags() | plStateDataRecord::kVolatile); bool dirtyOnly = (sendFlags & plSynchedObject::kForceFullSend) == 0; bool broadcast = (sendFlags & plSynchedObject::kBCastToClients) != 0; int writeOptions=0; // if (dirtyOnly) writeOptions |= plSDL::kDirtyOnly; if (broadcast) writeOptions |= plSDL::kBroadcast; writeOptions |= plSDL::kTimeStampOnRead; // send to server plNetMsgSDLState* msg = state->PrepNetMsg(0, writeOptions); msg->SetNetProtocol(kNetProtocolCli2Game); msg->ObjectInfo()->SetUoid(senderKey->GetUoid()); if (sendFlags & plSynchedObject::kNewState) msg->SetBit(plNetMessage::kNewSDLState); if (sendFlags & plSynchedObject::kUseRelevanceRegions) msg->SetBit(plNetMessage::kUseRelevanceRegions); if (sendFlags & plSynchedObject::kDontPersistOnServer) msg->SetPersistOnServer(false); if (sendFlags & plSynchedObject::kIsAvatarState) msg->SetIsAvatarState(true); if (broadcast && plNetClientApp::GetInstance()) { msg->SetPlayerID(plNetClientApp::GetInstance()->GetPlayerID()); } plNetClientApp::GetInstance()->SendMsg(msg); msg->UnRef(); fSentOrRecvdState = true; }
// // a remote ccr is turning [in]visible // void plNetClientMgr::MakeCCRInvisible(plKey avKey, int level) { if (!avKey) { ErrorMsg("Failed to make remote CCR Invisible, nil avatar key"); return; } if (level<0) { ErrorMsg("Failed to make remote CCR Invisible, negative level"); return; } if (!avKey->ObjectIsLoaded() || !avKey->ObjectIsLoaded()->IsFinal()) { hsAssert(false, "avatar not loaded or final"); return; } plAvatarStealthModeMsg *msg = new plAvatarStealthModeMsg(); msg->SetSender(avKey); msg->fLevel = level; if (GetCCRLevel()<level) // I'm a lower level than him, so he's invisible to me msg->fMode = plAvatarStealthModeMsg::kStealthCloaked; else { // he's visible to me if (AmCCR() && level > 0) msg->fMode = plAvatarStealthModeMsg::kStealthCloakedButSeen; // draw as semi-invis else msg->fMode = plAvatarStealthModeMsg::kStealthVisible; } DebugMsg("Handled MakeCCRInvisible - sending stealth msg");; // This fxn is called when avatar SDL state is received from the server, // so this msg will inherit the 'non-local' status of the parent sdl msg. // That means that the avatar linkSound won't receive it, since the linkSound // is set as localOnly. // So, terminate the remote cascade and start a new (local) cascade. msg->SetBCastFlag(plMessage::kNetStartCascade); msg->Send(); }
//============================================================================ void plNCAgeJoiner::IResMgrProgressBarCallback (plKey key) { #ifndef PLASMA_EXTERNAL_RELEASE if (s_instance) s_instance->progressBar->SetStatusText(key->GetName()); #endif if (s_instance) s_instance->progressBar->Increment(1); }
void plPluginResManager::AddLooseEnd(plKey key) { if( key ) { key->RefObject(); fLooseEnds.Append(key); } }
virtual bool IsInteresting( const plKey &objectKey ) { if( objectKey->GetUoid().GetClassType() == plCubicEnvironmap::Index() || objectKey->GetUoid().GetClassType() == plMipmap::Index() ) { return true; } return false; }
plPhysicsSoundMgr::CollidePair::CollidePair(const plKey& firstPhys, const plKey& secondPhys, const hsPoint3& point, const hsVector3& normal) { // To simplify searching and sorting, all pairs are set up with the pointer value of the // first element greater than the pointer value of the second. if (firstPhys->GetObjectPtr() < secondPhys->GetObjectPtr()) { this->firstPhysKey = secondPhys; this->secondPhysKey = firstPhys; } else { this->firstPhysKey = firstPhys; this->secondPhysKey = secondPhys; } this->point = point; this->normalForce = normal; }
// // save or load a key. return the key. // const plKey plSynchedValueBase::ISaveOrLoad(const plKey key, bool32 save, hsStream* stream, hsResMgr* mgr) { if (save) { if (key) { stream->WriteByte(1); // I need to write a key to MY stream... #if 0 // DEBUG plStringBuffer<char> buf = key->GetName()->ToIso8859_1(); stream->WriteLE32(buf.GetSize()); stream->Write(buf.GetSize(), buf.GetData()); #endif key->GetUoid().Write(stream); } else { stream->WriteByte(0); } return key; } else { int32_t has=stream->ReadByte(); if (has) { // read a key from MY stream #if 0 // DEBUG int32_t len = stream->ReadLE32(); char tmp[256]; hsAssert(len<256, "key name overflow"); stream->Read(len, tmp); #endif plUoid uoid; uoid.Read(stream); return mgr->FindKey(uoid); } else return (nil); } return nil; }
pfKIListPlayerItem( plKey key, bool inRange = false ) : pfGUIListText(), fPlayerKey( key ) { static char str[ 256 ]; if( key == nil ) SetText( "<Everyone>" ); else { const char *name = plNetClientMgr::GetInstance()->GetPlayerName( key ); if( inRange ) { sprintf( str, ">%s<", name != nil ? name : key->GetName() ); SetText( str ); } else SetText( name != nil ? name : key->GetName() ); } ISetJustify( true ); }
void plAvTaskSeek::SetTarget(plKey target) { hsAssert(target, "Bad key to seek task"); if(target) { fSeekObject = plSceneObject::ConvertNoRef(target->ObjectIsLoaded()); } else { fSeekObject = nil; } }
void plPageOptimizer::KeyedObjectProc(plKey key) { plString keyName = key->GetName(); const char* className = plFactory::GetNameOfClass(key->GetUoid().GetClassType()); // For now, ignore any key that isn't in the location we're looking at. That means stuff like textures. if (fInstance->fLoc != key->GetUoid().GetLocation()) return; KeySet& loadedKeys = fInstance->fLoadedKeys; KeyVec& loadOrder = fInstance->fKeyLoadOrder; KeySet::iterator it = loadedKeys.lower_bound(key); if (it != loadedKeys.end() && *it == key) { printf("Keyed object %s(%s) loaded more than once\n", keyName.c_str(), className); } else { loadedKeys.insert(it, key); loadOrder.push_back(key); } }
void plKeyCollector::del(plKey key) { std::vector<plKey>& keyList = keys[key->getLocation()][key->getType()]; std::vector<plKey>::iterator it = keyList.begin(); size_t sub = 0; while (it != keyList.end()) { if ((*it) == key) { it = keyList.erase(it); sub++; } else { (*it)->setID((*it)->getID() - sub); it++; } } if (keyList.empty()) keys[key->getLocation()].erase(key->getType()); if (keys[key->getLocation()].empty()) keys.erase(key->getLocation()); if (key.Exists() && key.isLoaded()) { delete key->getObj(); key->setObj(NULL); } }
bool plCommonObjLib::RemoveObjectAndKey( plKey &key ) { if (!key) { hsAssert( false, "Received RemoveObjectAndKey() call for a key that is invalid. Nillifying key anyway." ); key = nil; return true; } hsKeyedObject *object = hsKeyedObject::ConvertNoRef( key->ObjectIsLoaded() ); if( object == nil ) { hsAssert( false, "Received RemoveObjectAndKey() call for a key that isn't loaded. Nillifying key anyway." ); key = nil; return true; } int idx = fObjects.Find( object ); if( idx == fObjects.kMissingIndex ) { hsAssert( false, "Trying to RemoveObjectAndKey() for a common object not in the lib." ); key = nil; return true; } // Unref and remove from our list fObjects[ idx ]->GetKey()->UnRefObject(); fObjects.Remove( idx ); // Nuke out the key and its object if( !plPluginResManager::ResMgr()->NukeKeyAndObject( key ) ) { hsAssert( false, "Trouble nuking out the key for this texture. Problems abound...." ); return false; } // All done! return true; }
// plCaptureRender::Capture bool plCaptureRender::Capture(const plKey& ack, uint16_t width, uint16_t height) { // Create our render target const uint16_t flags = plRenderTarget::kIsOffscreen; const uint8_t bitDepth(32); const uint8_t zDepth(-1); const uint8_t stencilDepth(-1); plRenderTarget* rt = new plRenderTarget(flags, width, height, bitDepth, zDepth, stencilDepth); static int idx=0; ST::string buff = ST::format("tRT{}", idx++); hsgResMgr::ResMgr()->NewKey(buff, rt, ack->GetUoid().GetLocation()); // Create a render request and render request message plCaptureRenderRequest* req = new plCaptureRenderRequest; const float pri(-100.f); req->SetPriority(pri); req->SetRenderTarget(rt); const uint32_t renderState = plPipeline::kRenderNormal | plPipeline::kRenderClearColor | plPipeline::kRenderClearDepth; req->SetRenderState(renderState); // Set the Ack to be our requestor req->RequestAck(ack); // Submit plRenderRequestMsg* msg = new plRenderRequestMsg(ack, req); hsRefCnt_SafeUnRef(req); msg->Send(); return true; }
void plWinAudible::SetSceneObject(plKey obj) { plKey oldKey = nil; // remove old SDL mod if (fSDLMod && fSceneObj && fSceneObj != obj) { oldKey = fSceneObj; plSceneObject* so=plSceneObject::ConvertNoRef(fSceneObj->ObjectIsLoaded()); if (so) so->RemoveModifier(fSDLMod); delete fSDLMod; fSDLMod=nil; } fSceneObj = obj; plSceneObject* so=plSceneObject::ConvertNoRef(obj ? obj->ObjectIsLoaded() : nil); if (so) { so->RemoveModifier(fSDLMod); delete fSDLMod; fSDLMod=new plSoundSDLModifier; so->AddModifier(fSDLMod); } for( int i = 0; i < fSoundObjs.Count(); i++ ) { if( fSoundObjs[ i ] != nil && fSoundObjs[ i ]->GetKey() != nil ) { if( obj != nil ) { plGenRefMsg *replaceMsg = new plGenRefMsg( fSoundObjs[ i ]->GetKey(), plRefMsg::kOnReplace, 0, plSound::kRefParentSceneObject ); hsgResMgr::ResMgr()->AddViaNotify( obj, replaceMsg, plRefFlags::kPassiveRef ); } else if( oldKey != nil ) fSoundObjs[ i ]->GetKey()->Release( oldKey ); } } }
void plKeyCollector::MoveKey(plKey key, const plLocation& to) { std::vector<plKey>& keyList = keys[key->getLocation()][key->getType()]; std::vector<plKey>::iterator it = keyList.begin(); size_t sub = 0; while (it != keyList.end()) { if ((*it) == key) { it = keyList.erase(it); sub++; } else { (*it)->setID((*it)->getID() - sub); it++; } } if (keyList.empty()) keys[key->getLocation()].erase(key->getType()); if (keys[key->getLocation()].empty()) keys.erase(key->getLocation()); key->setLocation(to); add(key); }
void plNetMsgRoomsList::AddRoom(plKey rmKey) { fRooms.push_back(rmKey->GetUoid().GetLocation()); fRoomNames.push_back(rmKey->GetName()); }
void plKeyCollector::add(plKey key) { keys[key->getLocation()][key->getType()].push_back(key); if (key->getID() == 0) key->setID(keys[key->getLocation()][key->getType()].size()); }
void QGUIRadioGroupCtrl::controlAdded(plKey ctrl) { fDefaultValue->addItem(pqGetTypeIcon(ctrl->getType()), ~ctrl->getName()); }
void plPageOptimizer::IRewritePage() { hsUNIXStream newPage; if (newPage.Open(fTempPagePath, "wb")) { hsUNIXStream oldPage; oldPage.Open(fPagePath); const plPageInfo& pageInfo = fPageNode->GetPageInfo(); uint32_t dataStart = pageInfo.GetDataStart(); fBuf.resize(dataStart); oldPage.Read(dataStart, &fBuf[0]); newPage.Write(dataStart, &fBuf[0]); int size = (int)fKeyLoadOrder.size(); for (int i = 0; i < size; i++) IWriteKeyData(&oldPage, &newPage, fKeyLoadOrder[i]); // If there are any objects that we didn't write (because they didn't load for // some reason), put them at the end for (int i = 0; i < fAllKeys.size(); i++) { bool found = (fLoadedKeys.find(fAllKeys[i]) != fLoadedKeys.end()); if (!found) IWriteKeyData(&oldPage, &newPage, fAllKeys[i]); } uint32_t newKeyStart = newPage.GetPosition(); uint32_t oldKeyStart = pageInfo.GetIndexStart(); oldPage.SetPosition(oldKeyStart); uint32_t numTypes = oldPage.ReadLE32(); newPage.WriteLE32(numTypes); for (uint32_t i = 0; i < numTypes; i++) { uint16_t classType = oldPage.ReadLE16(); uint32_t len = oldPage.ReadLE32(); uint8_t flags = oldPage.ReadByte(); uint32_t numKeys = oldPage.ReadLE32(); newPage.WriteLE16(classType); newPage.WriteLE32(len); newPage.WriteByte(flags); newPage.WriteLE32(numKeys); for (uint32_t j = 0; j < numKeys; j++) { plUoid uoid; uoid.Read(&oldPage); uint32_t startPos = oldPage.ReadLE32(); uint32_t dataLen = oldPage.ReadLE32(); // Get the new start pos plKeyImp* key = (plKeyImp*)fResMgr->FindKey(uoid); startPos = key->GetStartPos(); uoid.Write(&newPage); newPage.WriteLE32(startPos); newPage.WriteLE32(dataLen); } } newPage.Close(); oldPage.Close(); } }
bool plKey::operator<(const plKey& other) const { return fKeyData->getUoid() < other->getUoid(); }