int32 StreamingRingBuffer::Read(void *buffer, size_t length, bool onlyBlockOnNoData) { BAutolock readerLock(fReaderLocker); if (!readerLock.IsLocked()) return B_ERROR; BAutolock dataLock(fDataLocker); if (!dataLock.IsLocked()) return B_ERROR; int32 readSize = 0; while (length > 0) { size_t copyLength = min_c(length, fBufferSize - fReadPosition); copyLength = min_c(copyLength, fReadable); if (copyLength == 0) { if (onlyBlockOnNoData && readSize > 0) return readSize; fReaderWaiting = true; dataLock.Unlock(); status_t result; do { TRACE("waiting in reader\n"); result = acquire_sem(fReaderNotifier); TRACE("done waiting in reader with status: 0x%08lx\n", result); } while (result == B_INTERRUPTED); if (result != B_OK) return result; if (!dataLock.Lock()) return B_ERROR; continue; } // support discarding input if (buffer != NULL) { memcpy(buffer, fBuffer + fReadPosition, copyLength); buffer = (uint8 *)buffer + copyLength; } fReadPosition = (fReadPosition + copyLength) % fBufferSize; fReadable -= copyLength; readSize += copyLength; length -= copyLength; if (fWriterWaiting) { release_sem_etc(fWriterNotifier, 1, B_DO_NOT_RESCHEDULE); fWriterWaiting = false; } } return readSize; }
bool GridMovement::checkCollision(int x, int y) { std::shared_lock<std::shared_timed_mutex> readerLock(gridMutex); char buffer[64]; sprintf(buffer, "%i,%i",x,y); std::string index = buffer; auto positr = posMap->find(index); if(positr == posMap->end()) { return false; }else return true; }
pList GridMovement::checkPosition(int x, int y) { std::shared_lock<std::shared_timed_mutex> readerLock(gridMutex); char buffer[64]; sprintf(buffer,"%i,%i",x,y); std::string index = buffer; pList tmp; auto positr = posMap->find(index); if (positr != posMap->end()) { //Output::Inst()->kprintf("returning a list"); return posMap->find(index)->second; } //Output::Inst()->kprintf("returning an empty list"); //pList somelist = posMap.find(index)->second; return tmp; }
SdfLayerRefPtr& UsdKatanaCache::_FindOrCreateSessionLayer( FnAttribute::GroupAttribute sessionAttr, std::string rootLocation) { // Grab a reader lock for reading the _sessionKeyCache boost::upgrade_lock<boost::upgrade_mutex> readerLock(UsdKatanaGetSessionCacheLock()); std::string cacheKey = FnAttribute::GroupAttribute("s", sessionAttr, "r", FnAttribute::StringAttribute(rootLocation), true).getHash().str(); // Open the usd stage SdfLayerRefPtr sessionLayer; if (_sessionKeyCache.find(cacheKey) == _sessionKeyCache.end()) { boost::upgrade_to_unique_lock<boost::upgrade_mutex> writerLock(readerLock); sessionLayer = SdfLayer::CreateAnonymous(); _sessionKeyCache[cacheKey] = sessionLayer; std::string rootLocationPlusSlash = rootLocation + "/"; FnAttribute::GroupAttribute variantsAttr = sessionAttr.getChildByName("variants"); for (int64_t i = 0, e = variantsAttr.getNumberOfChildren(); i != e; ++i) { std::string entryName = FnAttribute::DelimiterDecode( variantsAttr.getChildName(i)); FnAttribute::GroupAttribute entryVariantSets = variantsAttr.getChildByIndex(i); if (entryVariantSets.getNumberOfChildren() == 0) { continue; } if (!pystring::startswith(entryName, rootLocationPlusSlash)) { continue; } std::string primPath = pystring::slice(entryName, rootLocation.size()); for (int64_t i = 0, e = entryVariantSets.getNumberOfChildren(); i != e; ++i) { std::string variantSetName = entryVariantSets.getChildName(i); FnAttribute::StringAttribute variantValueAttr = entryVariantSets.getChildByIndex(i); if (!variantValueAttr.isValid()) { continue; } std::string variantSetSelection = variantValueAttr.getValue("", false); SdfPath varSelPath(primPath); SdfPrimSpecHandle spec = SdfCreatePrimInLayer( sessionLayer, varSelPath.GetPrimPath()); if (spec) { std::pair<std::string, std::string> sel = varSelPath.GetVariantSelection(); spec->SetVariantSelection(variantSetName, variantSetSelection); } } } FnAttribute::GroupAttribute activationsAttr = sessionAttr.getChildByName("activations"); for (int64_t i = 0, e = activationsAttr.getNumberOfChildren(); i != e; ++i) { std::string entryName = FnAttribute::DelimiterDecode( activationsAttr.getChildName(i)); FnAttribute::IntAttribute stateAttr = activationsAttr.getChildByIndex(i); if (stateAttr.getNumberOfValues() != 1) { continue; } if (!pystring::startswith(entryName, rootLocationPlusSlash)) { continue; } std::string primPath = pystring::slice(entryName, rootLocation.size()); SdfPath varSelPath(primPath); SdfPrimSpecHandle spec = SdfCreatePrimInLayer( sessionLayer, varSelPath.GetPrimPath()); spec->SetActive(stateAttr.getValue()); } } return _sessionKeyCache[cacheKey]; }
void printNumber(const std::string& na){ std::shared_lock<std::shared_timed_mutex> readerLock(teleBookMutex); std::cout << na << ": " << teleBook[na]; }
void USDVMP::setup(FnKat::ViewerModifierInput& input) { TF_DEBUG(KATANA_DEBUG_VMP_USD).Msg("%s @ %p : %s\n", TF_FUNC_NAME().c_str(), this, input.getFullName().c_str()); // The multi-threaded Usd Op may be loading or unloading models on the stage // we need, so we grab the global lock in reader mode. boost::shared_lock<boost::upgrade_mutex> readerLock(UsdKatanaGetStageLock()); // Open stage if necessary. if (not _stage) { // Get usd file, node path, and current time, // needed to call TidSceneRenderer FnKat::StringAttribute usdFileAttr = input.getAttribute("fileName"); FnKat::StringAttribute usdRootLocationAttr = input.getAttribute("rootLocation"); FnKat::StringAttribute usdReferencePathAttr = input.getAttribute("referencePath"); FnKat::StringAttribute variantStringAttr = input.getAttribute("variants"); FnKat::StringAttribute ignoreLayerAttr= input.getAttribute("ignoreLayerRegex"); FnKat::FloatAttribute forcePopulateAttr = input.getAttribute("forcePopulateUsdStage"); std::string usdFile = usdFileAttr.getValue("", false); std::string usdRootLocation = usdRootLocationAttr.getValue("", false); std::string usdReferencePath = usdReferencePathAttr.getValue("",false); std::string variantString = variantStringAttr.getValue("",false); std::string ignoreLayerRegex = ignoreLayerAttr.getValue("$^", false); bool forcePopulate = forcePopulateAttr.getValue((float)true,false); if (usdFile.empty()) return; _stage = UsdKatanaCache::GetInstance().GetStage(usdFile, variantString, ignoreLayerRegex, forcePopulate); if (not _stage) { TF_DEBUG(KATANA_DEBUG_VMP_USD).Msg( "Cannot resolve path %s", usdFile.c_str()); return; } if (usdReferencePath == "") _prim = _stage->GetPseudoRoot(); else _prim = _stage->GetPrimAtPath(SdfPath(usdReferencePath)); if (not _prim) FnLogWarn(std::string("Cannot compose ") + _prim.GetPath().GetString()); _params.cullStyle = UsdImagingEngine::CULL_STYLE_BACK_UNLESS_DOUBLE_SIDED; _renderer = UsdKatanaCache::GetInstance() .GetRenderer(_stage, _prim, variantString); } // always update frame time FnKat::DoubleAttribute currentTimeAttr = input.getAttribute("currentTime"); double currentTime = currentTimeAttr.getValue(0.0, false); _params.frame = currentTime; }
void USDVMP::draw(FnKat::ViewerModifierInput& input) { TF_DEBUG(KATANA_DEBUG_VMP_USD).Msg("%s @ %p : %s\n", TF_FUNC_NAME().c_str(), this, _prim.GetPath().GetString().c_str()); // Render if (_stage) { // Get draw options needed for styling. bool isSelected = input.getDrawOption("selected"); bool drawPoints = input.getDrawOption("fillPoints"); bool drawWireframe = input.getDrawOption("fillWireframe"); bool drawSmooth = input.getDrawOption("shadingSmooth"); bool isPicking = input.getDrawOption("isPicking"); // Clear out override color _params.overrideColor[3] = 0.0f; // Determine the approrpiate draw mode based on the styling options. if ( drawSmooth ) { if (_GetProxyOverlayMode() == _tokens->wireframe) { _params.drawMode = UsdImagingGL::DRAW_WIREFRAME_ON_SURFACE; } else { _params.drawMode = UsdImagingGL::DRAW_SHADED_SMOOTH; } } if ( drawWireframe ) { _params.drawMode = UsdImagingGL::DRAW_WIREFRAME; } if ( drawPoints ) { // TODO: support draw points _params.drawMode = UsdImagingGL::DRAW_POINTS; } // If this gprim is selected setup drawmode and selection color. if ( isSelected ) { _params.drawMode = UsdImagingGL::DRAW_GEOM_SMOOTH; _params.overrideColor = GfVec4f(0.0f, 1.0f, 1.0f, 1.0f); glColor4fv(_params.overrideColor.GetArray()); } if (isPicking) { if(input.getDrawOption("hasPickColor") == 1) { GfVec4f pickColor(0, 0, 0, 1); pickColor[0] = input.getDrawOptionFloat("pickColorR"); pickColor[1] = input.getDrawOptionFloat("pickColorG"); pickColor[2] = input.getDrawOptionFloat("pickColorB"); _params.overrideColor = pickColor; } else { // Most horrible hack in the world :( // Katana does it's picking by setting a shader // that takes a pick id and renders geometry with // the color representation of that id. // Unfortunately if we are using Hydra, we need to // use our own shaders. To get around this, we are // using specific knowledge of the katana pick shader // to extract the pick id and set our own override color // based on this id. This is basically emulating what the // katana shader is doing. GLint program = -1; glGetIntegerv(GL_CURRENT_PROGRAM, &program); TF_VERIFY(program != -1); GLint kat_PickIdLoc = glGetUniformLocation(program, "kat_PickId"); if (TF_VERIFY(kat_PickIdLoc != -1)) { GLint kat_PickId; glGetUniformiv(program, kat_PickIdLoc, &kat_PickId); // Simulate pick id with color _params.overrideColor = GfVec4f( ((float)((kat_PickId >> 0 ) & 0xff)) / 255.0f, ((float)((kat_PickId >> 8 ) & 0xff)) / 255.0f, ((float)((kat_PickId >> 16 ) & 0xff)) / 255.0f, 1.0f); } } // Using DRAW_GEOM_ONLY will disable lighting and make // sure we are rendering a solid color _params.drawMode = UsdImagingGL::DRAW_GEOM_ONLY; } // Save and restore shader settings around render call // because hydra does not restore shader state. GLint oldProgram = -1; glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgram); if (TF_VERIFY(_renderer)) { _renderer->SetCameraStateFromOpenGL(); glPushAttrib(GL_LIGHTING_BIT | GL_ENABLE_BIT); if (_GetProxyOverlayMode() == _tokens->ghosted) { glEnable(GL_LIGHT0); float f = 0.1; float params[4] = { f, 0.0, f, 1.0 }; glLightfv(GL_LIGHT0, GL_AMBIENT, params); } _renderer->SetLightingStateFromOpenGL(); glPopAttrib(); // The multi-threaded Usd Op may be loading or unloading models on // the stage we need, so we grab the global lock in reader mode // before rendering. boost::shared_lock<boost::upgrade_mutex> readerLock(UsdKatanaGetStageLock()); _renderer->Render(_prim, _params); } // Restore old shader glUseProgram(oldProgram); }
static void cook(FnKat::GeolibCookInterface &interface) { boost::shared_lock<boost::upgrade_mutex> readerLock(UsdKatanaGetStageLock()); UsdPrim prim; PxrUsdKatanaUsdInArgsRefPtr usdInArgs; PxrUsdKatanaUsdInPrivateData* privateData = static_cast<PxrUsdKatanaUsdInPrivateData*>(interface.getPrivateData()); FnKat::GroupAttribute opArgs = interface.getOpArg(); if (privateData) { usdInArgs = privateData->GetUsdInArgs(); } else { FnKat::GroupAttribute additionalOpArgs; usdInArgs = InitUsdInArgs(interface, additionalOpArgs); opArgs = FnKat::GroupBuilder() .update(opArgs) .deepUpdate(additionalOpArgs) .build(); } if (not usdInArgs) { ERROR("Could not initialize PxrUsdIn usdInArgs."); return; } if (interface.atRoot()) { interface.stopChildTraversal(); prim = usdInArgs->GetRootPrim(); // XXX This info currently gets used to determine whether // to correctively rotate cameras. The camera's zUp needs to be // recorded until we have no more USD z-Up assets and the katana // assets have no more prerotate camera nodes. interface.setAttr("info.usd.stageIsZup", FnKat::IntAttribute(UsdUtilsGetCamerasAreZup(usdInArgs->GetStage()))); // Construct the global camera list at the USD scene root. // FnKat::StringBuilder cameraListBuilder; SdfPathVector cameraPaths = PxrUsdKatanaUtils::FindCameraPaths(prim.GetStage()); TF_FOR_ALL(cameraPathIt, cameraPaths) { const std::string path = (*cameraPathIt).GetString(); // only add cameras to the camera list that are beneath the isolate prim path if (path.find(usdInArgs->GetIsolatePath()) != std::string::npos) { cameraListBuilder.push_back( TfNormPath(usdInArgs->GetRootLocationPath()+"/"+ path.substr(usdInArgs->GetIsolatePath().size()))); } } FnKat::StringAttribute cameraListAttr = cameraListBuilder.build(); if (cameraListAttr.getNumberOfValues() > 0) { interface.setAttr("cameraList", cameraListAttr); } interface.setAttr("info.usdOpArgs", opArgs); FnKat::GroupAttribute masterMapping = opArgs.getChildByName("masterMapping"); if (masterMapping.isValid() && masterMapping.getNumberOfChildren()) { FnGeolibServices::StaticSceneCreateOpArgsBuilder sscb(false); for (size_t i = 0, e = masterMapping.getNumberOfChildren(); i != e; ++i) { std::string masterName = FnKat::DelimiterDecode( masterMapping.getChildName(i)); std::string katanaPath = FnKat::StringAttribute( masterMapping.getChildByIndex(i) ).getValue("", false); if (katanaPath.empty()) { continue; } sscb.createEmptyLocation(katanaPath, "instance source"); sscb.setAttrAtLocation(katanaPath, "tabs.scenegraph.stopExpand", FnKat::IntAttribute(1)); sscb.setAttrAtLocation(katanaPath, "childPrimPath", FnKat::StringAttribute(masterName)); } interface.createChild( "Masters", "PxrUsdIn.MasterIntermediate", FnKat::GroupBuilder() .update(opArgs) .set("staticScene", sscb.build()) .build(), FnKat::GeolibCookInterface::ResetRootFalse, new PxrUsdKatanaUsdInPrivateData( usdInArgs->GetRootPrim(), usdInArgs, privateData), PxrUsdKatanaUsdInPrivateData::Delete); } }