bool CRegionBase::RealizeRegion() { ADDTOCALLSTACK("CRegionBase::RealizeRegion"); // Link the region to the world. RETURN: false = not valid. if ( IsRegionEmpty() ) return false; if ( !m_pt.IsValidPoint() ) m_pt = GetRegionCorner( DIR_QTY ); // center // Attach to all sectors that i overlap. ASSERT( m_iLinkedSectors == 0 ); for ( long l = 0; l < g_MapList.GetSectorQty(m_pt.m_map); l++ ) { CSector *pSector = g_World.GetSector(m_pt.m_map, l); if ( pSector && IsOverlapped(pSector->GetRect()) ) { // Yes, this sector overlapped, so add it to the sector list if ( !pSector->LinkRegion(this) ) { g_Log.EventError("Linking sector #%ld for map %d for region %s failed (fatal for this region).\n", l, m_pt.m_map, GetName()); return false; } m_iLinkedSectors++; } } return true; }
bool CGRegion::IsOverlapped( const CGRegion * pRegionTest ) const { ADDTOCALLSTACK("CGRegion::IsOverlapped"); // Does the region overlap this rectangle. if ( ! m_rectUnion.IsOverlapped( pRegionTest->m_rectUnion )) return( false ); size_t iQty = m_Rects.GetCount(); size_t iQtyTest = pRegionTest->m_Rects.GetCount(); if ( iQty == 0 ) { if ( iQtyTest == 0 ) return( true ); return( pRegionTest->IsOverlapped(m_rectUnion)); } if ( iQtyTest == 0 ) { return( IsOverlapped(pRegionTest->m_rectUnion)); } for ( size_t j = 0; j < iQty; j++ ) { for ( size_t i = 0; i < iQtyTest; i++ ) { if ( m_Rects[j].IsOverlapped( pRegionTest->m_Rects[i] )) return( true ); } } return( false ); }
void CRegionBase::UnRealizeRegion() { ADDTOCALLSTACK("CRegionBase::UnRealizeRegion"); // remove myself from the world. // used in the case of a ship where the region will move. for ( int i=0; ; i++ ) { CSector * pSector = GetSector(i); if ( pSector == NULL ) break; // Does the rect overlap ? if ( ! IsOverlapped( pSector->GetRect())) continue; if ( pSector->UnLinkRegion( this )) m_iLinkedSectors--; } }
bool CRegionBase::SendSectorsVerb( LPCTSTR pszVerb, LPCTSTR pszArgs, CTextConsole * pSrc ) { ADDTOCALLSTACK("CRegionBase::SendSectorsVerb"); // Send a command to all the CSectors in this region. bool fRet = false; for ( int i=0; ; i++ ) { CSector * pSector = GetSector(i); if ( pSector == NULL ) break; // Does the rect overlap ? if ( IsOverlapped( pSector->GetRect() ) ) { CScript script( pszVerb, pszArgs ); fRet |= pSector->r_Verb( script, pSrc ); } } return( fRet ); }
void neTreeNode::GetCandidateNodes(neSimpleArray<neTreeNode*> & nodes, const neV3 & minBound, const neV3 & maxBound, s32 level) { if (!IsOverlapped(minBound, maxBound)) return; /* if (level >= 3) { DrawBounds(); //DrawTriangles(); } */ if (this->triangleIndices.GetUsedCount() > 0) { neTreeNode ** n = nodes.Alloc(); ASSERT(n); *n = this; /* if (level >= 4) { DrawBounds(); DrawTriangles(); } */ return; } s32 i; for (i = 0; i < 4; i++) { if (children[i] != -1) { neTreeNode * c = &tree->nodes[children[i]]; c->GetCandidateNodes(nodes, minBound, maxBound, level + 1); } } }
static bool IsQuadrangle(cv::Point2f p1, cv::Point2f p2, cv::Point2f p3, cv::Point2f p4) { cv::Point2d pi1((int)p1.x, (int)p1.y); cv::Point2d pi2((int)p2.x, (int)p2.y); cv::Point2d pi3((int)p3.x, (int)p3.y); cv::Point2d pi4((int)p4.x, (int)p4.y); return !(IsOverlapped(pi1, pi2) || IsOverlapped(pi1, pi3) || IsOverlapped(pi1, pi4) || IsOverlapped(pi2, pi3) || IsOverlapped(pi2, pi4) || IsOverlapped(pi3, pi4) || IsLine(pi1, pi2, pi3) || IsLine(pi1, pi2, pi4) || IsLine(pi2, pi3, pi4)); }
/** The capsule block descriptors may be fragmented and spread all over memory. To simplify the coalescing of capsule blocks, first coalesce all the capsule block descriptors low in memory. The descriptors passed in can be fragmented throughout memory. Here they are relocated into memory to turn them into a contiguous (null terminated) array. @param PeiServices pointer to PEI services table @param BlockList pointer to the capsule block descriptors @param NumDescriptors number of capsule data block descriptors, whose Length is non-zero. @param MemBase base of system memory in which we can work @param MemSize size of the system memory pointed to by MemBase @retval NULL could not relocate the descriptors @retval Pointer to the base of the successfully-relocated block descriptors. **/ EFI_CAPSULE_BLOCK_DESCRIPTOR * RelocateBlockDescriptors ( IN EFI_PEI_SERVICES **PeiServices, IN EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockList, IN UINTN NumDescriptors, IN UINT8 *MemBase, IN UINTN MemSize ) { EFI_CAPSULE_BLOCK_DESCRIPTOR *NewBlockList; EFI_CAPSULE_BLOCK_DESCRIPTOR *CurrBlockDescHead; EFI_CAPSULE_BLOCK_DESCRIPTOR *TempBlockDesc; EFI_CAPSULE_BLOCK_DESCRIPTOR *PrevBlockDescTail; UINTN BufferSize; UINT8 *RelocBuffer; UINTN BlockListSize; // // Get the info on the blocks and descriptors. Since we're going to move // the descriptors low in memory, adjust the base/size values accordingly here. // NumDescriptors is the number of legit data descriptors, so add one for // a terminator. (Already done by caller, no check is needed.) // BufferSize = NumDescriptors * sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR); NewBlockList = (EFI_CAPSULE_BLOCK_DESCRIPTOR *) MemBase; if (MemSize < BufferSize) { return NULL; } MemSize -= BufferSize; MemBase += BufferSize; // // Go through all the blocks and make sure none are in the way // TempBlockDesc = BlockList; while (TempBlockDesc->Union.ContinuationPointer != (EFI_PHYSICAL_ADDRESS) (UINTN) NULL) { if (TempBlockDesc->Length == 0) { // // Next block of descriptors // TempBlockDesc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *) (UINTN) TempBlockDesc->Union.ContinuationPointer; } else { // // If the capsule data pointed to by this descriptor is in the way, // move it. // if (IsOverlapped ( (UINT8 *) NewBlockList, BufferSize, (UINT8 *) (UINTN) TempBlockDesc->Union.DataBlock, (UINTN) TempBlockDesc->Length )) { // // Relocate the block // RelocBuffer = FindFreeMem (BlockList, MemBase, MemSize, (UINTN) TempBlockDesc->Length); if (RelocBuffer == NULL) { return NULL; } CopyMem ((VOID *) RelocBuffer, (VOID *) (UINTN) TempBlockDesc->Union.DataBlock, (UINTN) TempBlockDesc->Length); DEBUG ((EFI_D_INFO, "Capsule relocate descriptors from/to/size 0x%lX 0x%lX 0x%lX\n", TempBlockDesc->Union.DataBlock, (UINT64)(UINTN)RelocBuffer, TempBlockDesc->Length)); TempBlockDesc->Union.DataBlock = (EFI_PHYSICAL_ADDRESS) (UINTN) RelocBuffer; } TempBlockDesc++; } } // // Now go through all the block descriptors to make sure that they're not // in the memory region we want to copy them to. // CurrBlockDescHead = BlockList; PrevBlockDescTail = NULL; while ((CurrBlockDescHead != NULL) && (CurrBlockDescHead->Union.ContinuationPointer != (EFI_PHYSICAL_ADDRESS) (UINTN) NULL)) { // // Get the size of this list then see if it overlaps our low region // TempBlockDesc = CurrBlockDescHead; BlockListSize = sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR); while (TempBlockDesc->Length != 0) { BlockListSize += sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR); TempBlockDesc++; } if (IsOverlapped ( (UINT8 *) NewBlockList, BufferSize, (UINT8 *) CurrBlockDescHead, BlockListSize )) { // // Overlaps, so move it out of the way // RelocBuffer = FindFreeMem (BlockList, MemBase, MemSize, BlockListSize); if (RelocBuffer == NULL) { return NULL; } CopyMem ((VOID *) RelocBuffer, (VOID *) CurrBlockDescHead, BlockListSize); DEBUG ((EFI_D_INFO, "Capsule reloc descriptor block #2\n")); // // Point the previous block's next point to this copied version. If // the tail pointer is null, then this is the first descriptor block. // if (PrevBlockDescTail == NULL) { BlockList = (EFI_CAPSULE_BLOCK_DESCRIPTOR *) RelocBuffer; } else { PrevBlockDescTail->Union.DataBlock = (EFI_PHYSICAL_ADDRESS) (UINTN) RelocBuffer; } } // // Save our new tail and jump to the next block list // PrevBlockDescTail = TempBlockDesc; CurrBlockDescHead = (EFI_CAPSULE_BLOCK_DESCRIPTOR *) (UINTN) TempBlockDesc->Union.ContinuationPointer; } // // Cleared out low memory. Now copy the descriptors down there. // TempBlockDesc = BlockList; CurrBlockDescHead = NewBlockList; while ((TempBlockDesc != NULL) && (TempBlockDesc->Union.ContinuationPointer != (EFI_PHYSICAL_ADDRESS) (UINTN) NULL)) { if (TempBlockDesc->Length != 0) { CurrBlockDescHead->Union.DataBlock = TempBlockDesc->Union.DataBlock; CurrBlockDescHead->Length = TempBlockDesc->Length; CurrBlockDescHead++; TempBlockDesc++; } else { TempBlockDesc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *) (UINTN) TempBlockDesc->Union.ContinuationPointer; } } // // Null terminate // CurrBlockDescHead->Union.ContinuationPointer = (EFI_PHYSICAL_ADDRESS) (UINTN) NULL; CurrBlockDescHead->Length = 0; return NewBlockList; }
/** Given a pointer to the capsule block list, info on the available system memory, and the size of a buffer, find a free block of memory where a buffer of the given size can be copied to safely. @param BlockList Pointer to head of capsule block descriptors @param MemBase Pointer to the base of memory in which we want to find free space @param MemSize The size of the block of memory pointed to by MemBase @param DataSize How big a free block we want to find @return A pointer to a memory block of at least DataSize that lies somewhere between MemBase and (MemBase + MemSize). The memory pointed to does not contain any of the capsule block descriptors or capsule blocks pointed to by the BlockList. **/ UINT8 * FindFreeMem ( EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockList, UINT8 *MemBase, UINTN MemSize, UINTN DataSize ) { UINTN Size; EFI_CAPSULE_BLOCK_DESCRIPTOR *CurrDesc; EFI_CAPSULE_BLOCK_DESCRIPTOR *TempDesc; UINT8 *MemEnd; BOOLEAN Failed; // // Need at least enough to copy the data to at the end of the buffer, so // say the end is less the data size for easy comparisons here. // MemEnd = MemBase + MemSize - DataSize; CurrDesc = BlockList; // // Go through all the descriptor blocks and see if any obstruct the range // while (CurrDesc != NULL) { // // Get the size of this block list and see if it's in the way // Failed = FALSE; TempDesc = CurrDesc; Size = sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR); while (TempDesc->Length != 0) { Size += sizeof (EFI_CAPSULE_BLOCK_DESCRIPTOR); TempDesc++; } if (IsOverlapped (MemBase, DataSize, (UINT8 *) CurrDesc, Size)) { // // Set our new base to the end of this block list and start all over // MemBase = (UINT8 *) CurrDesc + Size; CurrDesc = BlockList; if (MemBase > MemEnd) { return NULL; } Failed = TRUE; } // // Now go through all the blocks and make sure none are in the way // while ((CurrDesc->Length != 0) && (!Failed)) { if (IsOverlapped (MemBase, DataSize, (UINT8 *) (UINTN) CurrDesc->Union.DataBlock, (UINTN) CurrDesc->Length)) { // // Set our new base to the end of this block and start all over // Failed = TRUE; MemBase = (UINT8 *) ((UINTN) CurrDesc->Union.DataBlock) + CurrDesc->Length; CurrDesc = BlockList; if (MemBase > MemEnd) { return NULL; } } CurrDesc++; } // // Normal continuation -- jump to next block descriptor list // if (!Failed) { CurrDesc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *) (UINTN) CurrDesc->Union.ContinuationPointer; } } return MemBase; }
void CLinkMap::ModifyView( CCtrl* pCtrl ) { int nCenter, nOldCenter; int nMaxWidth, nUnit, nPos, nMaxPos, nVisibilityRange; int i, j; BOOL* pfMask; int nMaskPos; CObj** apObj; // CObj* pObj; CUser *pUser, *pUsertmp; CCtrl* pCtrltmp; D3DXVECTOR3 vPos = pCtrl->GetLinkPos(); // is player if( pCtrl->GetType() == OT_MOVER && ( (CMover*)pCtrl )->IsPlayer() ) { pUser = (CUser*)pCtrl; for( int nLinkLevel = 0; nLinkLevel < MAX_LINKLEVEL; nLinkLevel++ ) { // player link apObj = GetObj( CObj::linkPlayer, nLinkLevel ); nMaxWidth = GetLinkWidth( CObj::linkPlayer, nLinkLevel) * m_nLandWidth; nMaxPos = nMaxWidth * nMaxWidth; nUnit = (MAP_SIZE * m_nLandWidth) / nMaxWidth; nCenter = (int)( vPos.z / m_iMPU / nUnit ) * nMaxWidth + (int)( vPos.x / m_iMPU / nUnit ); nOldCenter = pUser->m_nOldCenter[nLinkLevel]; if( nCenter == nOldCenter ) { if( nLinkLevel == 0 ) return; continue; } nVisibilityRange = m_nVisibilityRange[nLinkLevel]; pfMask = m_apfMask[nLinkLevel]; for( i = -nVisibilityRange; i <= nVisibilityRange; i++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; if( ( nMaskPos = IsOverlapped( nOldCenter, nPos, nVisibilityRange, nMaxWidth ) ) < 0 ) { pUsertmp = (CUser*)apObj[nPos]; while( pUsertmp ) { if( !pUsertmp->IsDelete() && pUsertmp != pUser ) { pUser->PCSetAt( pUsertmp->GetId(), (CCtrl*)pUsertmp ); pUser->AddAddObj( (CCtrl*)pUsertmp ); pUsertmp->PCSetAt( pUser->GetId(), (CCtrl*)pUser ); pUsertmp->AddAddObj( (CCtrl*)pUser ); } pUsertmp = (CUser*)pUsertmp->GetNextNode(); } } else // old pos { pfMask[nMaskPos] = TRUE; } } } for( i = -nVisibilityRange; i <= nVisibilityRange; i ++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nOldCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; nMaskPos = ( i + nVisibilityRange ) * ( 2 * nVisibilityRange + 1 ) + ( j + nVisibilityRange ) ; if( pfMask[nMaskPos] == FALSE ) { pUsertmp = (CUser*)apObj[nPos]; while( pUsertmp ) { if( !pUsertmp->IsDelete() ) { pUser->PCRemoveKey( pUsertmp->GetId() ); pUser->AddRemoveObj( pUsertmp->GetId() ); pUsertmp->PCRemoveKey( pUser->GetId() ); pUsertmp->AddRemoveObj( pUser->GetId() ); } pUsertmp = (CUser*)pUsertmp->GetNextNode(); } } else { pfMask[nMaskPos] = FALSE; } } } // dynamic link apObj = GetObj( CObj::linkDynamic, nLinkLevel ); for( i = -nVisibilityRange; i <= nVisibilityRange; i++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; if( ( nMaskPos = IsOverlapped( nOldCenter, nPos, nVisibilityRange, nMaxWidth ) ) < 0 ) { pCtrltmp = (CCtrl*)apObj[nPos]; while( pCtrltmp ) { if( !pCtrltmp->IsDelete() ) { pUser->NPCSetAt( pCtrltmp->GetId(), pCtrltmp ); pUser->AddAddObj( pCtrltmp ); pCtrltmp->PCSetAt( pUser->GetId(), (CCtrl*)pUser ); } pCtrltmp = (CCtrl*)pCtrltmp->GetNextNode(); } } else // old pos { pfMask[nMaskPos] = TRUE; } } } for( i = -nVisibilityRange; i <= nVisibilityRange; i ++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nOldCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; nMaskPos = ( i + nVisibilityRange ) * ( 2 * nVisibilityRange + 1 ) + ( j + nVisibilityRange ) ; if( pfMask[nMaskPos] == FALSE ) { pCtrltmp = (CCtrl*)apObj[nPos]; while( pCtrltmp ) { if( !pCtrltmp->IsDelete() ) { pUser->NPCRemoveKey( pCtrltmp->GetId() ); pUser->AddRemoveObj( pCtrltmp->GetId() ); pCtrltmp->PCRemoveKey( pUser->GetId() ); } pCtrltmp = (CCtrl*)pCtrltmp->GetNextNode(); } } else { pfMask[nMaskPos] = FALSE; } } } // airship link apObj = GetObj( CObj::linkAirShip, nLinkLevel ); for( i = -nVisibilityRange; i <= nVisibilityRange; i++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; if( ( nMaskPos = IsOverlapped( nOldCenter, nPos, nVisibilityRange, nMaxWidth ) ) < 0 ) { pCtrltmp = (CCtrl*)apObj[nPos]; while( pCtrltmp ) { if( !pCtrltmp->IsDelete() ) { pUser->NPCSetAt( pCtrltmp->GetId(), pCtrltmp ); pUser->AddAddObj( pCtrltmp ); pCtrltmp->PCSetAt( pUser->GetId(), (CCtrl*)pUser ); } pCtrltmp = (CCtrl*)pCtrltmp->GetNextNode(); } } else // old pos { pfMask[nMaskPos] = TRUE; } } } for( i = -nVisibilityRange; i <= nVisibilityRange; i ++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nOldCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; nMaskPos = ( i + nVisibilityRange ) * ( 2 * nVisibilityRange + 1 ) + ( j + nVisibilityRange ) ; if( pfMask[nMaskPos] == FALSE ) { pCtrltmp = (CCtrl*)apObj[nPos]; while( pCtrltmp ) { if( !pCtrltmp->IsDelete() ) { pUser->NPCRemoveKey( pCtrltmp->GetId() ); pUser->AddRemoveObj( pCtrltmp->GetId() ); pCtrltmp->PCRemoveKey( pUser->GetId() ); } pCtrltmp = (CCtrl*)pCtrltmp->GetNextNode(); } } else { pfMask[nMaskPos] = FALSE; } } } pUser->m_nOldCenter[nLinkLevel] = nCenter; } } // is not player else { const int nMaxLevel = 1; for( int nLinkLevel = 0; nLinkLevel < nMaxLevel; nLinkLevel++ ) { apObj = GetObj( CObj::linkPlayer, nLinkLevel ); nMaxWidth = GetLinkWidth( CObj::linkPlayer, nLinkLevel) * m_nLandWidth; nMaxPos = nMaxWidth * nMaxWidth; nUnit = (MAP_SIZE * m_nLandWidth) / nMaxWidth; nCenter = (int)( vPos.z / m_iMPU / nUnit ) * nMaxWidth + (int)( vPos.x / m_iMPU / nUnit ); nOldCenter = pCtrl->m_nOldCenter[nLinkLevel]; if( nCenter == nOldCenter ) { if( nLinkLevel == 0 ) return; continue; } nVisibilityRange = m_nVisibilityRange[nLinkLevel]; pfMask = m_apfMask[nLinkLevel]; for( i = -nVisibilityRange; i <= nVisibilityRange; i++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; if( ( nMaskPos = IsOverlapped( nOldCenter, nPos, nVisibilityRange, nMaxWidth ) ) < 0 ) { pUsertmp = (CUser*)apObj[nPos]; while( pUsertmp ) { if( !pUsertmp->IsDelete() ) { pCtrl->PCSetAt( pUsertmp->GetId(), (CCtrl*)pUsertmp ); pUsertmp->NPCSetAt( pCtrl->GetId(), pCtrl ); pUsertmp->AddAddObj( pCtrl ); } pUsertmp = (CUser*)pUsertmp->GetNextNode(); } } else // old pos { pfMask[nMaskPos] = TRUE; } } } for( i = -nVisibilityRange; i <= nVisibilityRange; i ++ ) { for( j = -nVisibilityRange; j <= nVisibilityRange; j++ ) { nPos = nOldCenter + i * nMaxWidth + j; if( nPos < 0 || nPos >= nMaxPos ) continue; nMaskPos = ( i + nVisibilityRange ) * ( 2 * nVisibilityRange + 1 ) + ( j + nVisibilityRange ) ; if( pfMask[nMaskPos] == FALSE ) { pUsertmp = (CUser*)apObj[nPos]; while( pUsertmp ) { if( !pUsertmp->IsDelete() ) { pCtrl->PCRemoveKey( pUsertmp->GetId() ); pUsertmp->NPCRemoveKey( pCtrl->GetId() ); pUsertmp->AddRemoveObj( pCtrl->GetId() ); } pUsertmp = (CUser*)pUsertmp->GetNextNode(); } } else { pfMask[nMaskPos] = FALSE; } } } pCtrl->m_nOldCenter[nLinkLevel] = nCenter; } } }