/* ============ idScriptObject::SetType Allocates an object and initializes memory. ============ */ bool idScriptObject::SetType( const char *typeName ) { size_t size; idTypeDef *newtype; // lookup the type newtype = gameLocal.program.FindType( typeName ); // only allocate memory if the object type changes if ( newtype != type ) { Free(); if ( !newtype ) { gameLocal.Warning( "idScriptObject::SetType: Unknown type '%s'", typeName ); return false; } if ( !newtype->Inherits( &type_object ) ) { gameLocal.Warning( "idScriptObject::SetType: Can't create object of type '%s'. Must be an object type.", newtype->Name() ); return false; } // set the type type = newtype; // allocate the memory size = type->Size(); data = ( byte * )Mem_Alloc( size ); } // init object memory ClearObject(); return true; }
bool MUnixSocketUDPBroadcast::Destroy(void) { mSocket.Destroy(); mSockAddress.Destroy(); ClearObject(); return true; }
bool MUnixSocketSelect::Destroy(void) { if(mReadHandles!=NULL) { delete mReadHandles; mReadHandles=NULL; } if(mWriteHandles!=NULL) { delete mWriteHandles; mWriteHandles=NULL; } if(mErrorHandles!=NULL) { delete mErrorHandles; mErrorHandles=NULL; } if(mSocketSet!=NULL) { delete mSocketSet; mSocketSet=NULL; } ClearObject(); return true; }
bool MUnixSocketServer::Destroy(void) { BreakServiceLoop(); MUnixSocket::Destroy(); // Close Socket ClearObject(); return true; }
bool ObjectDetector::SetLink( ObjectDetectorLink* pLink ) { // Make sure this link is registered with this detector if( pLink->m_pDetector != this ) { return false; } // Make sure we don't already have an object ClearObject(); // Keep track of this one! m_pTrackedLink = pLink; // Get the spatial data for this link GetObjectSpatialData( m_pTrackedLink, m_vTrackedSpatialPosition, m_vTrackedSpatialDimensions ); // Turn on the user flag if we have one we're managing if( m_pTrackedLink && m_nUserFlagVerification ) { g_pLTClient->Common()->SetObjectFlags( m_pTrackedLink->m_hObject, OFT_User, m_nUserFlagVerification, m_nUserFlagVerification ); } return true; }
MWinAccessControlList::MWinAccessControlList(int maxacecount) { ClearObject(); if(Create(maxacecount)==false) { return; } }
MSQLite::MSQLite(const char *filename) { ClearObject(); if(Create(filename)==false) { return; } }
MUnixSocketIP::MUnixSocketIP(const char *ipaddress) { ClearObject(); if(Create(ipaddress)==false) { return; } }
MUnixSocketIP::MUnixSocketIP(unsigned long ipaddress) { ClearObject(); if(Create(ipaddress)==false) { return; } }
MBuffer::MBuffer(int size) { ClearObject(); if(Create(size)==false) { return; } }
MUnixSocket::MUnixSocket(int tsocket) { ClearObject(); if(Create(tsocket)==false) { return; } }
MUnixSocket::MUnixSocket(int sockfamily,int socktype,int protocol) { ClearObject(); if(Create(sockfamily,socktype,protocol)==false) { return; } }
MBuffer::MBuffer(const MBuffer &ref) { ClearObject(); if(Create(ref)==false) { return; } }
MUnixSocketClient::MUnixSocketClient(const char *host,int port,int family ,int type,int protocol) { ClearObject(); if(Create(host,port,family,type,protocol)==false) { return; } }
bool MWinNamedPipeClient::Destroy(void) { if(mhPipe!=INVALID_HANDLE_VALUE) { CloseHandle(mhPipe); mhPipe=INVALID_HANDLE_VALUE; } ClearObject(); return true; }
bool MBuffer::Destroy(void) { mSize=0; if(mBuffer!=0) { delete[] mBuffer; mBuffer=0; } ClearObject(); return true; }
bool MUnixSocketIP::Create(const char *addr) { ClearObject(); if(addr==NULL) { return false; } if(Create(inet_addr(addr) )==false) { return false; } return true; }
void CRuleVector::SetVectorSize(void* pData, uint32 nNewSize) const { CRuleVectorData* pVec = (CRuleVectorData*)pData; if(nNewSize != pVec->nCount) { uint8* pData2 = NULL; if(nNewSize) { uint32 nBaseType = m_pBaseType->TypeCode(); uint32 i, nSize = m_pBaseType->GetSize(); if(nBaseType == ARF_STRUCT) nSize = sizeof(void*); uint8* pLeftMem = pData2; pData2 = new uint8[nSize*nNewSize]; for(i=0; i<nNewSize; ++i) { if(nBaseType == ARF_STRUCT) *(uint32**)pLeftMem = NULL; else m_pBaseType->InitObject(pLeftMem); pLeftMem += nSize; } uint32 nCount = nNewSize; if(nCount > pVec->nCount) nCount = pVec->nCount; pLeftMem = pData2; uint8* pRightMem = pVec->pData; for(i=0; i<nCount; ++i) { if(nBaseType != ARF_STRUCT) m_pBaseType->AssignObject(pLeftMem, pRightMem); else { uint32* pCounter = *(uint32**)pRightMem; if(pCounter) { *(uint32**)pLeftMem = pCounter; pCounter[0]++; } } pLeftMem += nSize; pRightMem += nSize; } } ClearObject(pData); pVec->nCount = nNewSize; pVec->pData = pData2; } }
bool MWinNamedPipeServer::Destroy(void) { if(mhPipe!=INVALID_HANDLE_VALUE) { if(mClientConnected==true) { DisconnectNamedPipe(mhPipe); mClientConnected=false; } CloseHandle(mhPipe); mhPipe=INVALID_HANDLE_VALUE; } ClearObject(); return true; }
bool MUnixSocket::Destroy(void) { if(mSocket!=-1) { ///////////////////////////////////////////// #if ( defined(MSTDLIB_OS_WINDOWS) || defined(MSTDLIB_OS_WINDOWSOLD) || defined(MSTDLIB_OS_MINGW) ) closesocket(mSocket); ///////////////////////////////////////////// #elif (defined(MSTDLIB_OS_LINUX) || defined(MSTDLIB_OS_OTHER) ) close(mSocket); ///////////////////////////////////////////// #endif } ClearObject(); return true; }
bool ObjectDetector::SetObject( HOBJECT hObject ) { ObjectDetectorLink* pLink = m_iRootLink.m_pNext; ClearObject(); // Find this object in the registered list while( pLink ) { if( pLink->m_hObject == hObject ) { SetLink( pLink ); break; } pLink = pLink->m_pNext; } return ( m_pTrackedLink != NULL ); }
HOBJECT ObjectDetector::AcquireObject( bool bFromPrevious ) { // Make sure the object to the currently tracked link is still valid if( m_pTrackedLink && !m_pTrackedLink->m_hObject.GetData() ) { ReleaseLink( *m_pTrackedLink ); ClearObject(); } // If we don't have any acquire flags set... then don't do anything if( !( m_nBehaviorFlags & ODBF_ACQUIREMASK ) ) { return NULL; } // Keep track of the links that fit the previous, best, and current requirements ObjectDetectorLink* pPrevTracked = ( bFromPrevious ? m_pTrackedLink : NULL ); ObjectDetectorLink* pCurrTracked = NULL; ObjectDetectorLink* pBestTracked = NULL; // Requirement ranges and other data tracking variables float fPrevRR = 0.0f; float fCurrRR = 1000000.0f; float fBestRR = 1000000.0f; float fTempRR, fActiveRR; uint32 nAttemptedTests, nPassedTests; bool bContinue; // Get the previously tracked link data... add up the RR values even if the // tests don't pass. This way we get a relative value to compare to regardless // of whether it can be acquired again during this attempt. if( pPrevTracked ) { LTVector vPos, vDims; GetObjectSpatialData( pPrevTracked, vPos, vDims ); if( m_nBehaviorFlags & ODBF_ACQUIREFORWARD ) { TestParamsForward( pPrevTracked, vPos, vDims, fTempRR ); fPrevRR += fTempRR; } if( m_nBehaviorFlags & ODBF_ACQUIREDIRECTION ) { TestParamsDirection( pPrevTracked, vPos, vDims, fTempRR ); fPrevRR += fTempRR; } if( m_nBehaviorFlags & ODBF_ACQUIREFOV ) { TestParamsFOV( pPrevTracked, vPos, vDims, fTempRR ); fPrevRR += fTempRR; } if( m_nBehaviorFlags & ODBF_ACQUIRESPHERE ) { TestParamsSphere( pPrevTracked, vPos, vDims, fTempRR ); fPrevRR += fTempRR; } if( m_nBehaviorFlags & ODBF_ACQUIRECYLINDER ) { TestParamsCylinder( pPrevTracked, vPos, vDims, fTempRR ); fPrevRR += fTempRR; } if( m_nBehaviorFlags & ODBF_ACQUIRECUSTOM ) { TestParamsCustom( pPrevTracked, fTempRR ); fPrevRR += fTempRR; } } // Go through each registered object ObjectDetectorLink* pLink = m_iRootLink.m_pNext; while( pLink ) { LTVector vPos, vDims; GetObjectSpatialData( pLink, vPos, vDims ); // Ignore the previous tracked link if( pLink == pPrevTracked ) { pLink = pLink->m_pNext; continue; } // If this link has invalid object data... release it if( !pLink->m_hObject.GetData() ) { ObjectDetectorLink* pRemove = pLink; pLink = pLink->m_pNext; ReleaseLink( *pRemove ); continue; } // Check our user flag verification if( m_nUserFlagVerification ) { uint32 nUserFlags; g_pLTClient->Common()->GetObjectFlags( pLink->m_hObject, OFT_User, nUserFlags ); if( ( nUserFlags & m_nUserFlagVerification ) != m_nUserFlagVerification ) { continue; } } // Zero out our temporary requirement range fActiveRR = 0.0f; nAttemptedTests = 0; nPassedTests = 0; // Check all the necessary params if( m_nBehaviorFlags & ODBF_ACQUIREFORWARD ) { ++nAttemptedTests; if( TestParamsForward( pLink, vPos, vDims, fTempRR ) ) { fActiveRR += fTempRR; ++nPassedTests; } } if( m_nBehaviorFlags & ODBF_ACQUIREDIRECTION ) { ++nAttemptedTests; if( TestParamsDirection( pLink, vPos, vDims, fTempRR ) ) { fActiveRR += fTempRR; ++nPassedTests; } } if( m_nBehaviorFlags & ODBF_ACQUIREFOV ) { ++nAttemptedTests; if( TestParamsFOV( pLink, vPos, vDims, fTempRR ) ) { fActiveRR += fTempRR; ++nPassedTests; } } if( m_nBehaviorFlags & ODBF_ACQUIRESPHERE ) { ++nAttemptedTests; if( TestParamsSphere( pLink, vPos, vDims, fTempRR ) ) { fActiveRR += fTempRR; ++nPassedTests; } } if( m_nBehaviorFlags & ODBF_ACQUIRECYLINDER ) { ++nAttemptedTests; if( TestParamsCylinder( pLink, vPos, vDims, fTempRR ) ) { fActiveRR += fTempRR; ++nPassedTests; } } if( m_nBehaviorFlags & ODBF_ACQUIRECUSTOM ) { ++nAttemptedTests; if( TestParamsCustom( pLink, fTempRR ) ) { fActiveRR += fTempRR; ++nPassedTests; } } // Make sure we passed the required tests... if( m_nBehaviorFlags & ODBF_INCLUSIVEACQUIRE ) { bContinue = ( nPassedTests == nAttemptedTests ); } else { bContinue = ( nPassedTests > 0 ); } if( bContinue ) { // Make sure we have a line of site to this object if( m_nBehaviorFlags & ODBF_ACQUIRELINEOFSITE ) { bContinue = TestLineOfSite( pLink ); } // If we passed the line of site test... if( bContinue ) { // If the active test is better than our best... track it! if( fActiveRR < fBestRR ) { fBestRR = fActiveRR; pBestTracked = pLink; } // If the active test is after our previous, but better than the current... track it too! if( ( fActiveRR > fPrevRR ) && ( fActiveRR < fCurrRR ) ) { fCurrRR = fActiveRR; pCurrTracked = pLink; } } } // Move on to the next object pLink = pLink->m_pNext; } // Reset our verification timers memcpy( m_fActiveVerifyFailureDelays, m_fVerifyFailureDelays, sizeof( float ) * ODBF_TESTSAVAILABLE ); // Set our tracked link to the proper one if( pCurrTracked ) { SetLink( pCurrTracked ); } else if( pBestTracked ) { SetLink( pBestTracked ); } else if( !pPrevTracked ) { ClearObject(); } return GetObject(); }
MBuffer::MBuffer(void) { ClearObject(); }
bool MSQLiteReader::Destroy(void) { ClearList(); ClearObject(); return true; }
MSQLiteReader::MSQLiteReader(void) { ClearObject(); }
bool MSQLite::Destroy(void) { if(mDatabase!=NULL){ sqlite3_close(mDatabase); } ClearObject(); return true; }
MSQLite::MSQLite(void) { ClearObject(); }
bool MWinAccessControlList::Destroy(void) { mMemoryBlock.Destroy(); ClearObject(); return true; }
MWinAccessControlList::MWinAccessControlList(void) { ClearObject(); }
void ObjectDetector::Update( float fFrameTime ) { // If we don't have a tracked link... there's nothing to update! if( !m_pTrackedLink ) { return; } // Make sure the link is still valid if( !m_pTrackedLink->m_hObject.GetData() ) { ReleaseLink( *m_pTrackedLink ); ClearObject(); return; } // If we don't have any verify flags set... then don't do anything if( !( m_nBehaviorFlags & ODBF_VERIFYMASK ) ) { return; } // Requirement ranges and other data tracking variables float fTempRR; uint32 nAttemptedTests = 0; uint32 nPassedTests = 0; UpdateObjectSpatialData(); // Handle each verification type if( m_nBehaviorFlags & ODBF_VERIFYLINEOFSITE ) { ++nAttemptedTests; if( TestLineOfSite( m_pTrackedLink ) ) { m_fActiveVerifyFailureDelays[ 0 ] = m_fVerifyFailureDelays[ 0 ]; ++nPassedTests; } else { if( m_fActiveVerifyFailureDelays[ 0 ] > 0.0f ) { m_fActiveVerifyFailureDelays[ 0 ] -= fFrameTime; ++nPassedTests; } } } if( m_nBehaviorFlags & ODBF_VERIFYFORWARD ) { ++nAttemptedTests; if( TestParamsForward( m_pTrackedLink, m_vTrackedSpatialPosition, m_vTrackedSpatialDimensions, fTempRR ) ) { m_fActiveVerifyFailureDelays[ 1 ] = m_fVerifyFailureDelays[ 1 ]; ++nPassedTests; } else { if( m_fActiveVerifyFailureDelays[ 1 ] > 0.0f ) { m_fActiveVerifyFailureDelays[ 1 ] -= fFrameTime; ++nPassedTests; } } } if( m_nBehaviorFlags & ODBF_VERIFYDIRECTION ) { ++nAttemptedTests; if( TestParamsDirection( m_pTrackedLink, m_vTrackedSpatialPosition, m_vTrackedSpatialDimensions, fTempRR ) ) { m_fActiveVerifyFailureDelays[ 2 ] = m_fVerifyFailureDelays[ 2 ]; ++nPassedTests; } else { if( m_fActiveVerifyFailureDelays[ 2 ] > 0.0f ) { m_fActiveVerifyFailureDelays[ 2 ] -= fFrameTime; ++nPassedTests; } } } if( m_nBehaviorFlags & ODBF_VERIFYFOV ) { ++nAttemptedTests; if( TestParamsFOV( m_pTrackedLink, m_vTrackedSpatialPosition, m_vTrackedSpatialDimensions, fTempRR ) ) { m_fActiveVerifyFailureDelays[ 3 ] = m_fVerifyFailureDelays[ 3 ]; ++nPassedTests; } else { if( m_fActiveVerifyFailureDelays[ 3 ] > 0.0f ) { m_fActiveVerifyFailureDelays[ 3 ] -= fFrameTime; ++nPassedTests; } } } if( m_nBehaviorFlags & ODBF_VERIFYSPHERE ) { ++nAttemptedTests; if( TestParamsSphere( m_pTrackedLink, m_vTrackedSpatialPosition, m_vTrackedSpatialDimensions, fTempRR ) ) { m_fActiveVerifyFailureDelays[ 4 ] = m_fVerifyFailureDelays[ 4 ]; ++nPassedTests; } else { if( m_fActiveVerifyFailureDelays[ 4 ] > 0.0f ) { m_fActiveVerifyFailureDelays[ 4 ] -= fFrameTime; ++nPassedTests; } } } if( m_nBehaviorFlags & ODBF_VERIFYCYLINDER ) { ++nAttemptedTests; if( TestParamsCylinder( m_pTrackedLink, m_vTrackedSpatialPosition, m_vTrackedSpatialDimensions, fTempRR ) ) { m_fActiveVerifyFailureDelays[ 5 ] = m_fVerifyFailureDelays[ 5 ]; ++nPassedTests; } else { if( m_fActiveVerifyFailureDelays[ 5 ] > 0.0f ) { m_fActiveVerifyFailureDelays[ 5 ] -= fFrameTime; ++nPassedTests; } } } if( m_nBehaviorFlags & ODBF_VERIFYCUSTOM ) { ++nAttemptedTests; if( TestParamsCustom( m_pTrackedLink, fTempRR ) ) { m_fActiveVerifyFailureDelays[ 6 ] = m_fVerifyFailureDelays[ 6 ]; ++nPassedTests; } else { if( m_fActiveVerifyFailureDelays[ 6 ] > 0.0f ) { m_fActiveVerifyFailureDelays[ 6 ] -= fFrameTime; ++nPassedTests; } } } // Make sure we passed the required tests... if( ( nPassedTests == 0 ) || ( ( m_nBehaviorFlags & ODBF_INCLUSIVEVERIFY ) && ( nPassedTests != nAttemptedTests ) ) ) { ClearObject(); } // Otherwise, see if we're in a delay for clearing the object... and apply that instead if( m_fActiveClearDelay != OD_INVALID_CLEAR_DELAY ) { m_fActiveClearDelay -= fFrameTime; if( m_fActiveClearDelay <= 0.0f ) { ClearObject(); } } }