//----------------------------------------------- // Build // //----------------------------------------------- bool CSheetId::buildSheetId(const std::string& sheetName) { nlassert(_Initialised); // When no sheet_id.bin is loaded, use dynamically assigned IDs. if (_DontHaveSheetKnowledge) { std::string sheetNameLc = toLower(sheetName); std::map<std::string, uint32>::iterator it = _DevSheetNameToId.find(sheetNameLc); if (it == _DevSheetNameToId.end()) { // Create a new dynamic sheet ID. // nldebug("SHEETID: Creating a dynamic sheet id for '%s'", sheetName.c_str()); std::string sheetType = CFile::getExtension(sheetNameLc); std::string sheetName = CFile::getFilenameWithoutExtension(sheetNameLc); std::map<std::string, uint32>::iterator tit = _DevTypeNameToId.find(sheetType); uint32 typeId; if (tit == _DevTypeNameToId.end()) { _FileExtensions.push_back(sheetType); _DevSheetIdToName.push_back(std::vector<std::string>()); typeId = (uint32)_FileExtensions.size() - 1; _DevTypeNameToId[sheetType] = typeId; std::string unknownNewType = std::string("unknown." + sheetType); _DevSheetIdToName[typeId].push_back(unknownNewType); _Id.IdInfos.Type = typeId; _Id.IdInfos.Id = _DevSheetIdToName[typeId].size() - 1; _DevSheetNameToId[unknownNewType] = _Id.Id; if (sheetName == "unknown") return true; // Return with the unknown sheet id of this type } else { typeId = tit->second; _Id.IdInfos.Type = typeId; } // Add a new sheet name to the type _DevSheetIdToName[typeId].push_back(sheetNameLc); _Id.IdInfos.Id = _DevSheetIdToName[typeId].size() - 1; // nldebug("SHEETID: Type %i, id %i, sheetid %i", _Id.IdInfos.Type, _Id.IdInfos.Id, _Id.Id); _DevSheetNameToId[sheetNameLc] = _Id.Id; return true; } _Id.Id = it->second; return true; } // try looking up the sheet name in _SheetNameToId CStaticMap<CChar,uint32,CCharComp>::const_iterator itId; CChar c; c.Ptr = new char [sheetName.size()+1]; strcpy(c.Ptr, sheetName.c_str()); toLower(c.Ptr); itId = _SheetNameToId.find (c); delete [] c.Ptr; if( itId != _SheetNameToId.end() ) { _Id.Id = itId->second; #ifdef NL_DEBUG_SHEET_ID // store debug info _DebugSheetName = itId->first.Ptr; #endif return true; } // we failed to find the sheet name in the sheetname map so see if the string is numeric if (sheetName.size()>1 && sheetName[0]=='#') { uint32 numericId; NLMISC::fromString((const char*)(sheetName.c_str()+1), numericId); if (NLMISC::toString("#%u",numericId)==sheetName) { _Id.Id= numericId; return true; } } #ifdef NL_TEMP_YUBO_NO_SOUND_SHEET_ID if (a_NoSoundSheetId && sheetName.find(".sound") != std::string::npos) { std::string sheetNameLc = toLower(sheetName); std::map<std::string, uint32>::iterator it = _DevSheetNameToId.find(sheetNameLc); if (it == _DevSheetNameToId.end()) { // nldebug("SHEETID: Creating a temporary sheet id for '%s'", sheetName.c_str()); _DevSheetIdToName[0].push_back(sheetName); _Id.IdInfos.Type = a_NoSoundSheetType; _Id.IdInfos.Id = _DevSheetIdToName[0].size() - 1; _DevSheetNameToId[sheetNameLc] = _Id.Id; return true; } _Id.Id = it->second; return true; } #endif return false; }
// *************************************************************************** void CVegetableBlendLayerModel::render(IDriver *driver) { H_AUTO( NL3D_Vegetable_Render ); nlassert(VegetableManager); if(SortBlocks.size()==0) return; // Setup VegetableManager renderState (like pre-setuped material) //================== VegetableManager->setupRenderStateForBlendLayerModel(driver); // Render SortBlocks of this layer //================== uint rdrPass= NL3D_VEGETABLE_RDRPASS_UNLIT_2SIDED_ZSORT; // first time, activate the hard VB. bool precVBHardMode= true; CVegetableVBAllocator *vbAllocator= &VegetableManager->getVBAllocatorForRdrPassAndVBHardMode(rdrPass, 1); vbAllocator->activate(); // profile CPrimitiveProfile ppIn, ppOut; driver->profileRenderedPrimitives(ppIn, ppOut); uint precNTriRdr= ppOut.NTriangles; // render from back to front the list setuped in CVegetableManager::render() for(uint i=0; i<SortBlocks.size();i++) { CVegetableSortBlock *ptrSortBlock= SortBlocks[i]; // change of VertexBuffer (soft / hard) if needed. if(ptrSortBlock->ZSortHardMode != precVBHardMode) { // setup new VB for hardMode. CVegetableVBAllocator *vbAllocator= &VegetableManager->getVBAllocatorForRdrPassAndVBHardMode(rdrPass, ptrSortBlock->ZSortHardMode); vbAllocator->activate(); // prec. precVBHardMode= ptrSortBlock->ZSortHardMode; } // render him. we are sure that size > 0, because tested before. driver->activeIndexBuffer(ptrSortBlock->_SortedTriangleArray); #ifdef NL_DEBUG if (ptrSortBlock->ZSortHardMode) { nlassert(ptrSortBlock->_SortedTriangleArray.getFormat() == CIndexBuffer::Indices16); } else { nlassert(ptrSortBlock->_SortedTriangleArray.getFormat() == CIndexBuffer::Indices32); } #endif driver->renderSimpleTriangles( ptrSortBlock->_SortedTriangleIndices[ptrSortBlock->_QuadrantId], ptrSortBlock->_NTriangles); } // add number of triangles rendered with vegetable manager. driver->profileRenderedPrimitives(ppIn, ppOut); VegetableManager->_NumVegetableFaceRendered+= ppOut.NTriangles-precNTriRdr; // refresh list now! // We must do it here, because if CVegetableManager::render() is no more called (eg: disabled), // then the blend layers models must do nothing. SortBlocks.clear(); // Reset RenderState. //================== VegetableManager->exitRenderStateForBlendLayerModel(driver); }
void IProgressCallback::pushCropedValues (float min, float max) { nlassert (_CropedValues.size ()>0); //const CCropedValues &values = _CropedValues.back (); _CropedValues.push_back (CCropedValues (getCropedValue (min), getCropedValue (max))); }
void IProgressCallback::popCropedValues () { nlassert (_CropedValues.size ()>1); _CropedValues.pop_back (); }
//********************************************************************************************************* void CInstanceMapDeco::onUpdate(CGroupMap &groupMap) { //H_AUTO(R2_CInstanceMapDeco_onUpdate) if (!_Active) return; nlassert(_Instance); _GlowStarActive = false; if (!_Main || !_Over || !_OverInvalid) return; sint32 x; sint32 y; CVector2f worldPos = getWorldPos(); // if not in current map then don't disply anything CIslandCollision &col = getEditor().getIslandCollision(); R2::CScenarioEntryPoints::CCompleteIsland *currIsland = col.getCurrIslandDesc(); if (currIsland) { if (!currIsland->isIn(worldPos)) { setActive(false); return; } } groupMap.worldToWindowSnapped(x, y, getWorldPos()); _Main->setX(x); _Main->setY(y); CDisplayerVisual *vd = _Instance->getDisplayerVisual(); if (!vd) { _Over->setActive(false); _OverInvalid->setActive(false); return; } // bool closeView = _CloseTexture.empty() ? false : groupMap.getMeterPerPixel() < CV_MapEntityCloseDist.get(); // bool selected = vd->getDisplayFlag(CDisplayerVisual::FlagSelected); bool hasFocus = vd->getDisplayFlag(CDisplayerVisual::FlagHasFocus); // setTextureAndFit(closeView ? _CloseTexture : CV_MapEntitySmallTexture.get()); _Main->setColor((selected && ! closeView) ? CV_MapEntitySelectColor.get() : vd->getDisplayModeColorInMap()); // if small icon, then change the icon color directly, because no over will be displayed // if (selected || hasFocus) { // if the selection is out of the window, then draw an arrow to locate it const CVector2f &wmin = groupMap.getVisibleWorldMin(); const CVector2f &wmax = groupMap.getVisibleWorldMax(); if (worldPos.x < wmin.x || worldPos.x > wmax.x || worldPos.y < wmin.y || worldPos.y > wmax.y) { // OUT OF VISIBLE REGION CASE _Over->setActive(true); _Over->setColorRGBA(selected ? CV_MapEntitySelectColor.get() : CV_MapEntityHighlightColor.get()); // out of the visible portion, so draw an arrow instead _Over->setTexture(CV_MapEntityFarTexture.get()); // snap position to inner visible world rect CVector2f m = 0.5f * (wmin + wmax); CVector2f dir = worldPos - m; CVector2f inter; float d0; float d1; if (dir.x > 0.f) { d0 = (wmax.x - m.x) / dir.x; if (dir.y > 0.f) { d1 = (wmax.y - m.y) / dir.y; inter = m + std::min(d0, d1) * dir; } else if (dir.y < 0.f) { d1 = (wmin.y - m.y) / dir.y; inter = m + std::min(d0, d1) * dir; } else { inter.set(wmax.x, m.y); } } else if (dir.x < 0.f) { d0 = (wmin.x - m.x) / dir.x; if (dir.y > 0.f) { d1 = (wmax.y - m.y) / dir.y; inter = m + std::min(d0, d1) * dir; } else if (dir.y < 0.f) { d1 = (wmin.y - m.y) / dir.y; inter = m + std::min(d0, d1) * dir; } else { inter.set(wmin.x, m.y); } } else { if (dir.y > 0.f) { inter.set(m.x, wmax.y); } else if (dir.y < 0.f) { inter.set(m.x, wmin.y); } else { inter = m; } } float size = CV_MapEntityFarArrowSize.get(); // TMP TMP size = size; float bias = 1.f; dir.normalize(); CVector2f winInter; groupMap.worldToWindow(winInter, inter); _Over->setRenderLayer(3); _Over->setQuad(winInter - (size + bias) * dir, winInter - bias * dir, 0.5f * size); // if (_GlowStar[0]) { sint32 screenInterX, screenInterY; groupMap.windowToScreen(screenInterX, screenInterY, (sint32) winInter.x, (sint32) winInter.y); sint32 refCornerX, refCornerY; _GlowStar[0]->getParent()->getCorner(refCornerX, refCornerY, Hotspot_BL); _GlowStarPos.set((float) (screenInterX - refCornerX), (float) (screenInterY - refCornerY), 0.f); _GlowStarActive = true; } } else { // VISIBLE CASE _GlowStar[0]->setActive(false); _GlowStar[1]->setActive(false); if (closeView || hasFocus) { _Over->setActive(true); if (!closeView) { _Over->setColorRGBA(CV_MapEntitySelectColor.get()); } else { _Over->setColorRGBA(selected ? CV_MapEntitySelectColor.get() : CV_MapEntityHighlightColor.get()); } const std::string &tex = closeView ? CV_MapEntitySelectTexture.get() : CV_MapEntitySmallHighlightTexture.get(); _Over->setTexture(tex); _Over->setRenderLayer(2); _Over->setQuad(tex, CVector((float) x, (float) y, 0.f)); } else { _Over->setActive(false); } } } else { // no focus _Over->setActive(false); _GlowStar[0]->setActive(false); _GlowStar[1]->setActive(false); } // update 'quad that signal invalid pos' if (_OverInvalid->getActive()) { const std::string &tex = closeView ? CV_MapEntityInvalidTexture.get() : CV_MapEntityInvalidTextureSmall.get(); _OverInvalid->setTexture(tex); _OverInvalid->setQuad(tex, CVector((float) x, (float) y, 0.f)); } }
float IProgressCallback::getCropedValue (float value) const { nlassert (_CropedValues.size ()>0); const CCropedValues &values = _CropedValues.back (); return value*(values.Max-values.Min)+values.Min; }
CTransformShape *CScene::createInstance(const string &shapeName) { // We must attach a bank to the scene (a ShapeBank handle the shape caches and // the creation/deletion of the instances) nlassert( _ShapeBank != NULL ); // If the shape is not present in the bank if (_ShapeBank->getPresentState( shapeName ) != CShapeBank::Present) { // Load it from file _ShapeBank->load( shapeName ); if (_ShapeBank->getPresentState( shapeName ) != CShapeBank::Present) { return NULL; } } // Then create a reference to the shape CTransformShape *pTShp = _ShapeBank->addRef( shapeName )->createInstance(*this); if (pTShp) pTShp->setDistMax(pTShp->Shape->getDistMax()); // Look if this instance get lightmap information #if defined(__GNUC__) && __GNUC__ < 3 CMeshBase *pMB = (CMeshBase*)((IShape*)(pTShp->Shape)); #else // not GNUC CMeshBase *pMB = dynamic_cast<CMeshBase*>((IShape*)(pTShp->Shape)); #endif // not GNUC CMeshBaseInstance *pMBI = dynamic_cast<CMeshBaseInstance*>( pTShp ); if( ( pMB != NULL ) && ( pMBI != NULL ) ) { // Init lightmap information pMBI->initAnimatedLightIndex (*this); // Auto animations //========================== if (_AutomaticAnimationSet) { if (pMB->getAutoAnim()) { std::string animName = toLower(CFile::getFilenameWithoutExtension(shapeName)); uint animID = _AutomaticAnimationSet->getAnimationIdByName(animName); if (animID != CAnimationSet::NotFound) { CChannelMixer *chanMix = new CChannelMixer; chanMix->setAnimationSet((CAnimationSet *) _AutomaticAnimationSet); chanMix->setSlotAnimation(0, animID); pMBI->registerToChannelMixer(chanMix, ""); // Gives this object ownership of the channel mixer so we don't need to keep track of it pMBI->setChannelMixerOwnerShip(true); } } } } CLandscapeModel *pLM = dynamic_cast<CLandscapeModel*>( pTShp ); if( pLM != NULL ) { // Init lightmap information pLM->Landscape.initAnimatedLightIndex (*this); } return pTShp; }
// ********************************************************************************************************* void CDisplayerVisualActivitySequence::update() { //H_AUTO(R2_CDisplayerVisualActivitySequence_update) if (!_Active) return; if (!_Touched) return; _Touched = false; CObjectTable *activities = getProps().toTable("Components"); if (!activities) { clear(); return; } // get first world object parent to get start position nlassert(getDisplayedInstance()); CInstance *prevZone = NULL; CDisplayerVisual *prevDV = getParentDV(); if (!prevDV) { clear(); return; } // clear(false); // for(uint k = 0; k < activities->getSize(); ++k) { // search next zone of activity CObjectTable *activity = activities->getValue(k)->toTable(); if (!activity) continue; std::string activityStr = getString(activity, "Activity"); if (activityStr == "Stand Still" || activityStr == "Inactive") continue; // CInstance *nextZone = NULL; std::string zoneId = getString(activity, "ActivityZoneId"); // if (!zoneId.empty()) { _ObserverHandles.push_back(getEditor().addInstanceObserver(zoneId, this)); nextZone = getEditor().getInstanceFromId(zoneId); } if (!nextZone) break; CDisplayerVisual *nextDV = nextZone->getDisplayerVisual(); if (!nextDV) break; _TraversedPrimInfos.push_back(CTraversedPrimInfo()); _TraversedPrimInfos.back().PrimDisplay = nextDV; _TraversedPrimInfos.back().Visible = nextDV->getActualDisplayMode() != DisplayModeHidden; CWorldPosCache wpc; wpc.DV = nextDV; wpc.WorldPos2f = nextDV->getWorldPos2f(); _WPCache.push_back(wpc); if (nextDV->getActualDisplayMode() != DisplayModeHidden && prevDV->getActualDisplayMode() != DisplayModeHidden) { // special case for regions if (nextZone->isKindOf("Region")) { // first case : previous zone is not a region if (!prevZone || !prevZone->isKindOf("Region")) { // search shortest distance bewteen last pos and the region CVector entryPos; if (nextDV->evalEnterPoint(prevDV->evalExitPoint(), entryPos)) { addFootSteps(CLine(prevDV->evalExitPoint(), entryPos)); } else { addWanderSteps(prevDV->evalExitPoint()); } } else { // region-region footsteps // just use the couple of vertices for which the distance is the smallest static std::vector<CVector2f> r0; static std::vector<CVector2f> r1; prevDV->getSonsWorldPos2f(r0); nextDV->getSonsWorldPos2f(r1); if (!r0.empty() && !r1.empty()) { CVector2f p0(0.f, 0.f), p1(0.f, 0.f); float bestDist = FLT_MAX; for(uint k = 0; k < r0.size(); ++k) { for(uint l = 0; l < r0.size(); ++l) { float dist = (r0[k] - r1[l]).norm(); if (dist <bestDist) { bestDist = dist; p0 = r0[k]; p1 = r1[l]; } } } nlassert(bestDist != FLT_MAX); addFootSteps(CLine(p0.asVector(), p1.asVector())); } } } else { // special case if prev zone is a region if (prevZone && prevZone->isKindOf("Region")) { // search shortest distance bewteen last pos and the region CVector entryPos; if (prevDV->evalEnterPoint(nextDV->evalLinkPoint(), entryPos)) { addFootSteps(CLine(entryPos, nextDV->evalLinkPoint())); } else { addWanderSteps(nextDV->evalLinkPoint()); } } else { // simple footsteps between last & new pos addFootSteps(CLine(prevDV->evalExitPoint(), nextDV->evalLinkPoint())); } } } prevDV = nextDV; prevZone = nextZone; } // CGroupMap *gm = CTool::getWorldMap(); if (!_AddedToWorldMap && gm) { gm->addDeco(this); } if (_AddedToWorldMap) { setWorldMapNumEdges((uint)_FootSteps.size()); nlassert(gm); onUpdate(*gm); } }
// *************************************************************************** void CScene::endPartRender(bool keepTrav) { nlassert(_IsRendering); _IsRendering = false; if (!keepTrav) { // Delete model deleted during the rendering uint i; for (i=0; i<_ToDelete.size(); i++) deleteModel (_ToDelete[i]); _ToDelete.clear (); // Special for SkeletonSpawnScript animation. create models spawned now flushSSSModelRequests(); // Particle system handling (remove the resources of those which are too far, as their clusters may not have been parsed). // Note that only a few of them are tested at each call _ParticleSystemManager.refreshModels(ClipTrav.WorldFrustumPyramid, ClipTrav.CamPos); // Waiting Instance handling double deltaT = _DeltaSystemTimeBetweenRender; clamp (deltaT, 0.01, 0.1); updateWaitingInstances(deltaT); } // Reset profiling _NextRenderProfile= false; IDriver *drv = getDriver(); drv->activeVertexProgram(NULL); drv->activePixelProgram(NULL); drv->activeGeometryProgram(NULL); // Ensure nothing animates on subsequent renders _EllapsedTime = 0.f; /* uint64 total = PSStatsRegisterPSModelObserver + PSStatsRemovePSModelObserver + PSStatsUpdateOpacityInfos + PSStatsUpdateLightingInfos + PSStatsGetAABBox + PSStatsReallocRsc + PSStatsReleasePSPointer + PSStatsRefreshRscDeletion + PSStatsReleaseRsc + PSStatsReleaseRscAndInvalidate + PSStatsGetNumTriangles + PSStatsCheckAgainstPyramid + PSStatsTraverseAnimDetail + PSStatsDoAnimate + PSStatsTraverseRender + PSStatsTraverseClip + PSStatsCheckDestroyCondition + PSStatsForceInstanciate + PSStatsDoAnimatePart1 + PSStatsDoAnimatePart2 + PSStatsDoAnimatePart3 + PSStatsTraverseAnimDetailPart1 + PSStatsTraverseAnimDetailPart2 + PSStatsTraverseAnimDetailPart3 + PSStatsTraverseAnimDetailPart4 + PSAnim1 + PSAnim2+ PSAnim3+ PSAnim4+ PSAnim5+ PSAnim6+ PSAnim7+ PSAnim8+ PSAnim9+ PSAnim10+ PSAnim11; if (((double) total / (double) NLMISC::CSystemInfo::getProcessorFrequency()) > 0.01) { nlinfo("***** PS STATS ****"); #define PS_STATS(var) \ nlinfo("time for " #var " = %.2f", (float) (1000 * ((double) var / (double) CSystemInfo::getProcessorFrequency()))); PS_STATS(PSStatsRegisterPSModelObserver) PS_STATS(PSStatsRemovePSModelObserver) PS_STATS(PSStatsUpdateOpacityInfos) PS_STATS(PSStatsUpdateLightingInfos) PS_STATS(PSStatsGetAABBox) PS_STATS(PSStatsReallocRsc) PS_STATS(PSStatsReleasePSPointer) PS_STATS(PSStatsRefreshRscDeletion) PS_STATS(PSStatsReleaseRsc) PS_STATS(PSStatsReleaseRscAndInvalidate) PS_STATS(PSStatsGetNumTriangles) PS_STATS(PSStatsCheckAgainstPyramid) PS_STATS(PSStatsTraverseAnimDetail) PS_STATS(PSStatsDoAnimate) PS_STATS(PSStatsTraverseRender) PS_STATS(PSStatsTraverseClip) PS_STATS(PSStatsClipSystemInstanciated); PS_STATS(PSStatsClipSystemNotInstanciated); PS_STATS(PSStatsClipSystemCheckAgainstPyramid); PS_STATS(PSStatsInsertInVisibleList); PS_STATS(PSStatsCheckDestroyCondition) PS_STATS(PSStatsForceInstanciate) PS_STATS(PSStatsDoAnimatePart1) PS_STATS(PSStatsDoAnimatePart2) PS_STATS(PSStatsDoAnimatePart3) PS_STATS(PSStatsTraverseAnimDetailPart1) PS_STATS(PSStatsTraverseAnimDetailPart2) PS_STATS(PSStatsTraverseAnimDetailPart3) PS_STATS(PSStatsTraverseAnimDetailPart4) PS_STATS(PSAnim1) PS_STATS(PSAnim2) PS_STATS(PSAnim3) PS_STATS(PSAnim4) PS_STATS(PSAnim5) PS_STATS(PSAnim6) PS_STATS(PSAnim7) PS_STATS(PSAnim8) PS_STATS(PSAnim9) PS_STATS(PSAnim10) PS_STATS(PSAnim11) PS_STATS(PSStatsZonePlane) PS_STATS(PSStatsZoneSphere) PS_STATS(PSStatsZoneDisc) PS_STATS(PSStatsZoneRectangle) PS_STATS(PSStatsZoneCylinder) PS_STATS(PSMotion1) PS_STATS(PSMotion2) PS_STATS(PSMotion3) PS_STATS(PSMotion4) PS_STATS(PSStatCollision) PS_STATS(PSStatEmit) PS_STATS(PSStatRender) nlinfo("num do animate = %d", (int) PSStatsNumDoAnimateCalls); nlinfo("Max et = %.2f", PSMaxET); nlinfo("Max ps nb pass = %d", (int) PSMaxNBPass); PS_STATS(total) } PSStatsRegisterPSModelObserver = 0; PSStatsRemovePSModelObserver = 0; PSStatsUpdateOpacityInfos = 0; PSStatsUpdateLightingInfos = 0; PSStatsGetAABBox = 0; PSStatsReallocRsc = 0; PSStatsReleasePSPointer = 0; PSStatsRefreshRscDeletion = 0; PSStatsReleaseRsc = 0; PSStatsReleaseRscAndInvalidate = 0; PSStatsGetNumTriangles = 0; PSStatsCheckAgainstPyramid = 0; PSStatsTraverseAnimDetail = 0; PSStatsDoAnimate = 0; PSStatsTraverseRender = 0; PSStatsTraverseClip = 0; PSStatsCheckDestroyCondition = 0; PSStatsForceInstanciate = 0; PSStatsClipSystemInstanciated = 0; PSStatsClipSystemNotInstanciated = 0; PSStatsClipSystemCheckAgainstPyramid = 0; PSStatsInsertInVisibleList = 0; PSStatsDoAnimatePart1 = 0; PSStatsDoAnimatePart2 = 0; PSStatsDoAnimatePart3 = 0; PSStatsTraverseAnimDetailPart1 = 0; PSStatsTraverseAnimDetailPart2 = 0; PSStatsTraverseAnimDetailPart3 = 0; PSStatsTraverseAnimDetailPart4 = 0; PSStatsNumDoAnimateCalls = 0; PSAnim1 = 0; PSAnim2 = 0; PSAnim3 = 0; PSAnim4 = 0; PSAnim5 = 0; PSAnim6 = 0; PSAnim7 = 0; PSAnim8 = 0; PSAnim9 = 0; PSAnim10 = 0; PSAnim11 = 0; PSMaxET = 0.f; PSMaxNBPass = 0; PSStatsZonePlane = 0; PSStatsZoneSphere = 0; PSStatsZoneDisc = 0; PSStatsZoneRectangle = 0; PSStatsZoneCylinder = 0; PSMotion1 = 0; PSMotion2 = 0; PSMotion3 = 0; PSMotion4 = 0; PSStatCollision = 0; PSStatEmit = 0; PSStatRender = 0; */ }
// *************************************************************************** void CScene::renderPart(UScene::TRenderPart rp, bool doHrcPass, bool doTrav, bool keepTrav) { nlassert(_IsRendering); // if nothing (????), abort if(rp==UScene::RenderNothing) return; // If part asked already rendered, abort nlassert((rp & _RenderedPart) == 0); // cannot render the same part twice during a render // if first part to be rendered, do the start stuff if (_RenderedPart == UScene::RenderNothing) { RenderTrav.clearWaterModelList(); if (doTrav) { // update water envmap //updateWaterEnvmap(); _FirstFlare = NULL; double fNewGlobalSystemTime = NLMISC::CTime::ticksToSecond(NLMISC::CTime::getPerformanceTime()); if(_GlobalSystemTime==0) _DeltaSystemTimeBetweenRender= 0.020; else _DeltaSystemTimeBetweenRender= fNewGlobalSystemTime - _GlobalSystemTime; _GlobalSystemTime = fNewGlobalSystemTime; } // ++ _NumRender; // nlassert(CurrentCamera); // update models. updateModels(); // Use the camera to setup Clip / Render pass. float left, right, bottom, top, znear, zfar; CurrentCamera->getFrustum(left, right, bottom, top, znear, zfar); // setup basic camera. ClipTrav.setFrustum(left, right, bottom, top, znear, zfar, CurrentCamera->isPerspective()); RenderTrav.setFrustum (left, right, bottom, top, znear, zfar, CurrentCamera->isPerspective()); RenderTrav.setViewport (_Viewport); LoadBalancingTrav.setFrustum (left, right, bottom, top, znear, zfar, CurrentCamera->isPerspective()); // Set Infos for cliptrav. ClipTrav.Camera = CurrentCamera; ClipTrav.setQuadGridClipManager (_QuadGridClipManager); // **** For all render traversals, traverse them (except the Hrc one), in ascending order. if( doHrcPass ) HrcTrav.traverse(); else HrcTrav._MovingObjects.clear(); // Set Cam World Matrix for all trav that need it ClipTrav.setCamMatrix(CurrentCamera->getWorldMatrix()); RenderTrav.setCamMatrix (CurrentCamera->getWorldMatrix()); LoadBalancingTrav.setCamMatrix (CurrentCamera->getWorldMatrix()); // clip ClipTrav.traverse(); // animDetail AnimDetailTrav.traverse(); // loadBalance LoadBalancingTrav.traverse(); if (doTrav) { // if (_RequestParticlesAnimate) { _ParticleSystemManager.processAnimate(_EllapsedTime); // deals with permanently animated particle systems _RequestParticlesAnimate = false; } } // Light LightTrav.traverse(); } // render RenderTrav.traverse(rp, (_RenderedPart == UScene::RenderNothing), doTrav); if (!keepTrav) { // Always must clear shadow caster (if render did not work because of IDriver::isLost()) RenderTrav.getShadowMapManager().clearAllShadowCasters(); } // render flare if (rp & UScene::RenderFlare) { if (doTrav) { if (_FirstFlare) { IDriver *drv = getDriver(); CFlareModel::updateOcclusionQueryBegin(drv); CFlareModel *currFlare = _FirstFlare; do { currFlare->updateOcclusionQuery(drv); currFlare = currFlare->Next; } while(currFlare); CFlareModel::updateOcclusionQueryEnd(drv); } } else { _FirstFlare = NULL; } } _RenderedPart = (UScene::TRenderPart) (_RenderedPart | rp); }
// *************************************************************************** void CScene::unregisterShadowCasterToList(CTransform *sc) { nlassert(sc); _ShadowCasterList.erase(sc->_ItShadowCasterInScene); }
// *************************************************************************** void CScene::registerShadowCasterToList(CTransform *sc) { nlassert(sc); _ShadowCasterList.push_front(sc); sc->_ItShadowCasterInScene= _ShadowCasterList.begin(); }
// *************************************************************************** void CScene::addInstanceGroupForLightAnimation(CInstanceGroup *ig) { nlassert( ig ); nlassert( _AnimatedIgSet.find(ig) == _AnimatedIgSet.end() ); _AnimatedIgSet.insert(ig); }
/// Play void CSimpleSource::play() { // nldebug("CSimpleSource %p : play", this); CAudioMixerUser *mixer = CAudioMixerUser::instance(); // -- Some test to check if we can play the source // Check if sample buffer is available and if the sound source is not too far if (_SimpleSound->getBuffer() == 0 || !_SimpleSound->getBuffer()->isBufferLoaded() //|| (mixer->getListenPosVector() - _Position).sqrnorm() > _SimpleSound->getMaxDistance() * _SimpleSound->getMaxDistance()) || (_RelativeMode ? getPos().sqrnorm() : (mixer->getListenPosVector() - getPos()).sqrnorm()) > _SimpleSound->getMaxDistance() * _SimpleSound->getMaxDistance()) { // The sample buffer is not available, don't play (we don't know the length) _WaitingForPlay = false; if (_Spawn) { if (_SpawnEndCb != 0) _SpawnEndCb(this, _CbUserParam); delete this; } // nldebug("CSimpleSource %p : play FAILED !", (CAudioMixerUser::IMixerEvent*)this); return; } // -- Here we can play the source, either in a real track or as a muted source. // Try to obtain a track if (!hasPhysicalSource()) initPhysicalSource(); if (hasPhysicalSource()) { ISource *pSource = getPhysicalSource(); nlassert(pSource != NULL); // ok, we have a track to realy play, fill the data into the track pSource->setStaticBuffer(_SimpleSound->getBuffer()); // pSource->setPos( _Position, false); pSource->setPos(getVirtualPos(), false); if (!_SimpleSound->getBuffer()->isStereo()) { pSource->setMinMaxDistances(_SimpleSound->getMinDistance(), _SimpleSound->getMaxDistance(), false); setDirection(_Direction); // because there is a workaround inside pSource->setVelocity(_Velocity); } pSource->setGain(getFinalGain()); pSource->setSourceRelativeMode(_RelativeMode); pSource->setLooping(_Looping); pSource->setPitch(_Pitch); pSource->setAlpha(_Alpha); // and play the sound bool play = pSource->play(); #ifdef NL_DEBUG nlassert(play); #else if (!play) nlwarning("Failed to play physical sound source. This is a serious error"); #endif // nldebug("CSimpleSource %p : REAL play done", (CAudioMixerUser::IMixerEvent*)this); } else { if (_Priority == HighestPri) { // This sound is not discardable, add it in waiting playlist mixer->addSourceWaitingForPlay(this); _WaitingForPlay = true; return; } // there is no available track, just do a 'muted' play mixer->addEvent(this, CTime::getLocalTime() + _SimpleSound->getDuration()); _PlayMuted = true; mixer->incPlayingSourceMuted(); // nldebug("CSimpleSource %p : MUTED play done", (CAudioMixerUser::IMixerEvent*)this); } CSourceCommon::play(); _WaitingForPlay = false; }
//********************************************************************************************************* void CInstanceMapDeco::onPreRender(CGroupMap &groupMap) { //H_AUTO(R2_CInstanceMapDeco_onPreRender) if (!_Active) return; nlassert(_Instance); if (_GlowStarActive) { if (_GlowStar[0]) { // draw glowing stars on the edge to signal position well for(uint k = 0; k < 2; ++k) { _GlowStar[k]->setActive(true); _GlowStar[k]->setQuad(_GlowStarPos, CV_MapGlowStarSize.get(), (float) (CV_MapGlowStarSpeed[k].get() * 0.001 * (double) T1)); _GlowStar[k]->updateCoords(); } } } // if (_Orient) { bool closeView = groupMap.getMeterPerPixel() < CV_MapEntityCloseDist.get(); CDisplayerVisual *vd = _Instance->getDisplayerVisual(); if (vd) { if (_LastCloseView!= closeView) { _OrientBlendFactor = closeView ? 0.5f : 0.f; } if (vd->getRotateInProgress()) { _OrientBlendFactor = 1.f; } else { // fade to default alpha NLMISC::incrementalBlend(_OrientBlendFactor, closeView ? 0.5f : 0.f, DT * 1000.f / favoid0(CV_MapEntityOrientBlendTimeInMs.get())); } } else { _OrientBlendFactor = 0.f; } if (_OrientBlendFactor == 0.f) { _Orient->setActive(false); } else { _Orient->setActive(true); _Orient->setColorRGBA(CRGBA(255, 255, 255, (uint8) (255 * _OrientBlendFactor))); CVector2f worldPos = getWorldPos(); sint32 x; sint32 y; groupMap.worldToWindowSnapped(x, y, getWorldPos()); _Orient->setQuad(CV_MapEntityOrientTexture.get(), CVector((float) x, (float) y, 0.f), vd->getAngle(), closeView ? CV_MapEntityOrientOriginDist.get() : CV_MapEntityOrientOriginDistSmall.get()); _Orient->updateCoords(); } _LastCloseView = closeView; } if (_OverInvalid->getActive()) { _OverInvalid->setColorRGBA(CTool::getInvalidPosColor()); } }
// **************************************************************************** bool CStaticStringMapper::isAdded(const std::string &str) const { nlassert(!_MemoryCompressed); return _TempStringTable.count(str) != 0; }
// ********************************************************************************************************* void CDisplayerVisualActivitySequence::onPostRender() { //H_AUTO(R2_CDisplayerVisualActivitySequence_onPostRender) CDisplayerVisual *entityDV = getParentDV(); CDisplayerVisual *groupDV = getPossibleGroupDV(entityDV); if (!isVisible(groupDV, entityDV)) { removeFromWorldMap(); return; } // TSequenceState state = Hidden; // if this activity sequence is not the selected one in its parent then it is hidden updateState(state, groupDV); // if current selection is a son of the group... static std::vector<CDisplayerVisual *> groupSons; groupDV->getSons(groupSons); for(uint k = 0; k < groupSons.size(); ++k) { nlassert(groupSons[k]); updateState(state, groupSons[k]); } // if one of the route is selected or highlighted CObjectTable *activities = getProps().toTable("Components"); if (!activities) { removeFromWorldMap(); return; } // get first world object parent to get start position for(uint k = 0; k < activities->getSize(); ++k) { // search next zone of activity CObjectTable *activity = activities->getValue(k)->toTable(); if (!activity) continue; std::string zoneId = getString(activity, "ActivityZoneId"); if (zoneId.empty()) continue; std::string activityStr = getString(activity, "Activity"); if (activityStr == "Stand Still" || activityStr == "Inactive") continue; CInstance *zone = getEditor().getInstanceFromId(zoneId); if (!zone) continue; CDisplayerVisual *dv = zone->getDisplayerVisual(); if (!dv) continue; updateState(state, dv); static std::vector<CDisplayerVisual *> vertices; dv->getSons(vertices); for (uint l = 0; l < vertices.size(); ++l) { nlassert(vertices[l]); updateState(state, vertices[l]); } } // if (state != Hidden && entityDV) { // see if this sequence is the selected one sint index = entityDV->getDisplayedInstance()->getSelectedSequence(); CObject *sequences = getProps().getParent(); // see what is my index in the sequences list of my parent if (sequences) { clamp(index, (sint) 0, (sint) sequences->getSize() - 1); if (index != sequences->findIndex(&getProps())) { state = Hidden; // not the current selected sequence } } } // _DecalColor = CV_FootStepDecalSelectedColor.get(); CRGBA mapColor = CV_FootStepMapSelectedColor.get(); switch(state) { case Hidden: _DecalColor = CV_FootStepDecalHiddenColor.get(); mapColor = CV_FootStepMapHiddenColor.get(); break; case HasFocus: _DecalColor = CV_FootStepDecalFocusedColor.get(); mapColor = CV_FootStepMapFocusedColor.get(); break; default: break; } for(uint k = 0; k < _WPCache.size(); ++k) { if (_WPCache[k].DV) { if (_WPCache[k].DV->getWorldPos2f() != _WPCache[k].WorldPos2f) { touch(); break; } } } update(); if (_AddedToWorldMap) { setWorldMapColor(mapColor); } }