void CElement::CallEventNoParent ( const char* szName, const CLuaArguments& Arguments, CElement* pSource, CPlayer* pCaller ) { // Call it on us if this isn't the same class it was raised on if ( pSource != this && m_pEventManager->HasEvents () ) { m_pEventManager->Call ( szName, Arguments, pSource, this, pCaller ); } // Call it on all our children CElementListSnapshot* pList = GetChildrenListSnapshot(); pList->AddRef(); // Keep list alive during use for ( CElementListSnapshot::const_iterator iter = pList->begin() ; iter != pList->end() ; iter++ ) { CElement* pElement = *iter; if ( !pElement->IsBeingDeleted() ) { if ( !pElement->m_pEventManager || pElement->m_pEventManager->HasEvents () || !pElement->m_Children.empty () ) { pElement->CallEventNoParent ( szName, Arguments, pSource, pCaller ); if ( m_bIsBeingDeleted ) break; } } } pList->Release(); }
void CPerPlayerEntity::RemovePlayersBelow(CElement* pElement, std::set<CPlayer*>& Removed) { assert(pElement); // Is this a player? if (IS_PLAYER(pElement)) { // Remove the reference CPlayer* pPlayer = static_cast<CPlayer*>(pElement); RemovePlayerReference(pPlayer); // Did we just loose the last reference to that player? Add him to the list over removed players. if (!IsVisibleToPlayer(*pPlayer)) { MapInsert(Removed, pPlayer); } } // Call ourself on all our children CChildListType ::const_iterator iterChildren = pElement->IterBegin(); for (; iterChildren != pElement->IterEnd(); iterChildren++) { CElement* pElement = *iterChildren; if (pElement->CountChildren() || IS_PLAYER(pElement)) // This check reduces cpu usage when unloading large maps (due to recursion) RemovePlayersBelow(pElement, Removed); } }
void CPerPlayerEntity::AddPlayersBelow(CElement* pElement, std::set<CPlayer*>& Added) { assert(pElement); // Is this a player? if (IS_PLAYER(pElement)) { // Are we not already visible to that player? Add it to the list CPlayer* pPlayer = static_cast<CPlayer*>(pElement); if (!IsVisibleToPlayer(*pPlayer)) { MapInsert(Added, pPlayer); } // Add it to our reference list AddPlayerReference(pPlayer); } // Call ourself on all its children elements CChildListType ::const_iterator iterChildren = pElement->IterBegin(); for (; iterChildren != pElement->IterEnd(); iterChildren++) { CElement* pElement = *iterChildren; if (pElement->CountChildren() || IS_PLAYER(pElement)) // This check reduces cpu usage when loading large maps (due to recursion) AddPlayersBelow(pElement, Added); } }
ATTR_METHOD_IMPL(CElementParser, OnMaxOccurs) { TRACE_PARSE_ENTRY(); if (cchValue==sizeof("unbounded")-1 && !wcsncmp(wszValue, L"unbounded", cchValue)) { CElement * pCurr = GetElement(); if (pCurr != NULL) { pCurr->SetMaxOccurs(MAXOCCURS_UNBOUNDED); return S_OK; } return E_FAIL; } int nMaxOccurs = 0; nMaxOccurs = _wtoi(wszValue); if (nMaxOccurs >= 0) { // // maxOccurs must be >= 0 // CElement * pCurr = GetElement(); if (pCurr != NULL) { pCurr->SetMaxOccurs(nMaxOccurs); return S_OK; } } EmitInvalidValue("maxOccurs", wszValue); return E_FAIL; }
bool CComponentLibrary::fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) { CXmlElement childElement; CXmlElement::CChildIterator it(xmlElement); // XML populate all component libraries while (it.next(childElement)) { // Filter component library/type set elements if (childElement.getType() == "ComponentLibrary" || childElement.getType() == "ComponentTypeSet") { if (!fromXml(childElement, serializingContext)) { return false; } } else { // Regular child creation and populating CElement *pChild = createChild(childElement, serializingContext); if (!pChild || !pChild->fromXml(childElement, serializingContext)) { return false; } } } return true; }
void CFreeCameraComponent::Reset() { CElement *owner = GetOwner(); m_camController->SetPosition( owner->GetPosition() ); }
/***************************************************************** * * method :void DrawCurrentPage(CDC *inDC) * * parameters : inCDC a device context * * returns : nothing * * description: Draw the current page * * ****************************************************************/ void CEasyReport::DrawCurrentPage(CDC *inDC) { int i,aStart, aMax; CElement *aElem; if( m_CurPage != 0 ) aStart = m_PageItems[m_CurPage-1]; else aStart = 0; aMax = m_PageItems[m_CurPage]; for( i =aStart;i< aMax;i++) { aElem = (CElement *)m_ReportItems[i]; aElem->Draw(inDC); } /* CRect aRect(m_LeftMargin, -m_TopMargin, m_PageWidth - m_RightMargin, -(m_PageHeight-m_BottomMargin)); inDC->MoveTo(aRect.left, aRect.top); inDC->LineTo(aRect.right,aRect.top); inDC->LineTo(aRect.right, aRect.bottom); inDC->LineTo(aRect.left, aRect.bottom); inDC->LineTo(aRect.left, aRect.top); */ }
void CFreeCameraComponent::Update(double elapsedTime) { if ( m_Destroyed ) return; CElement *owner = GetOwner(); m_camController->SetPosition( owner->GetPosition() ); }
void CElement::_GetEntitiesFromRoot ( unsigned int uiTypeHash, std::map < CElement*, int >& mapResults ) { t_mapEntitiesFromRoot::iterator find = ms_mapEntitiesFromRoot.find ( uiTypeHash ); if ( find != ms_mapEntitiesFromRoot.end () ) { CChildListType& listEntities = find->second; CElement* pEntity; unsigned int uiIndex = 0; for ( CChildListType::const_reverse_iterator i = listEntities.rbegin (); i != listEntities.rend (); ++i ) { pEntity = *i; assert ( pEntity ); ElementID ID = pEntity->GetID (); assert ( ID != INVALID_ELEMENT_ID ); assert ( pEntity == CElementIDs::GetElement ( ID ) ); if ( pEntity->IsBeingDeleted () ) OutputDebugString ( SString ( "Server: 0x%08x %s is flagged as IsBeingDeleted() but is still in GetEntitiesFromRoot\n", pEntity, pEntity->GetTypeName ().c_str () ) ); assert ( mapResults.find ( pEntity ) == mapResults.end () ); mapResults [ pEntity ] = 1; } } }
void CPickup::Callback_OnLeave ( CColShape& Shape, CElement& Element ) { if ( IS_PLAYER ( &Element ) ) { CPlayer& Player = static_cast < CPlayer& > ( Element ); // Matching interior if ( GetInterior () == Element.GetInterior () ) { // Matching dimension if ( GetDimension () == Element.GetDimension () ) { // Is he alive? if ( !Player.IsDead () ) { // Call the onPickupHit event CLuaArguments Arguments; Arguments.PushElement ( &Player ); CallEvent ( "onPickupLeave", Arguments ); CLuaArguments Arguments2; Arguments2.PushElement ( this ); // pickup Element.CallEvent ( "onPlayerPickupLeave", Arguments2 ); } } } } }
bool CPlayer::IsPlayerIgnoringElement( CElement* pElement ) { // For each ignored element for ( list < CElement* > ::const_iterator iter = m_lstIgnoredList.begin () ; iter != m_lstIgnoredList.end () ; ++iter ) { CElement* pIgnoredElement = *iter; if ( IS_TEAM ( pIgnoredElement ) ) { // Check team CTeam* pTeam = static_cast < CTeam* > ( pIgnoredElement ); // If the broadcast-to player is in the ignored team list < CPlayer* > ::const_iterator iter = pTeam->PlayersBegin (); for ( ; iter != pTeam->PlayersEnd (); iter++ ) { if ( *iter == pElement ) return true; } } else if ( IS_PLAYER( pIgnoredElement ) ) { // Check player if ( pIgnoredElement == pElement ) return true; } else { // Check element decendants if ( pIgnoredElement->IsMyChild ( pElement , true ) ) return true; } } return false; }
TAG_METHOD_IMPL(CElementParser, OnComplexType) { TRACE_PARSE_ENTRY(); CElement * pCurr = GetElement(); if (pCurr != NULL) { CComplexType * pElem = pCurr->AddComplexType(); if (pElem != NULL) { SetXSDElementInfo(pElem, pCurr, GetLocator()); CAutoPtr<CComplexTypeParser> p( new CComplexTypeParser(GetReader(), this, GetLevel(), pElem) ); if (p != NULL) { if (g_ParserList.AddHead(p) != NULL) { return p.Detach()->GetAttributes(pAttributes); } } } } EmitErrorHr(E_OUTOFMEMORY); return E_FAIL; }
CElement* CElement::SetParentObject ( CElement* pParent, bool bUpdatePerPlayerEntities ) { // Different parent? if ( pParent != m_pParent ) { // Already got a parent? if ( m_pParent ) { // Call the on children remove on our current parent m_pParent->OnSubtreeRemove ( this ); // Eventually unreference us from the previous parent entity m_pParent->m_Children.remove ( this ); } // Get into/out-of FromRoot info bool bOldFromRoot = CElement::IsFromRoot ( m_pParent ); bool bNewFromRoot = CElement::IsFromRoot ( pParent ); // Moving out of FromRoot? if ( bOldFromRoot && !bNewFromRoot ) CElement::RemoveEntityFromRoot ( m_uiTypeHash, this ); // Grab the root element now CElement* pRoot; if ( pParent ) { pRoot = pParent->GetRootElement (); } else { assert ( m_pParent ); pRoot = m_pParent->GetRootElement (); } // Set the new parent m_pParent = pParent; // New parent? if ( pParent ) { // Add us to the new parent's child list pParent->m_Children.push_back ( this ); // Moving into FromRoot? if ( !bOldFromRoot && bNewFromRoot ) CElement::AddEntityFromRoot ( m_uiTypeHash, this ); // Call the on children add event on the new parent pParent->OnSubtreeAdd ( this ); } // Update all per-player references from the root and down if ( bUpdatePerPlayerEntities ) pRoot->UpdatePerPlayerEntities (); } return pParent; }
void CFreeCameraComponent::Init() { CElement *owner = GetOwner(); m_camController->SetPosition( owner->GetPosition() ); CEngine::GetSingleton().getCameraManager()->add(getName(), m_camController); }
void CCell::Draw(CDC *pDC) { POSITION pos; CElement *pElement; for(pos=m_Elements.GetHeadPosition();pos!=NULL;){ pElement=(CElement *)(m_Elements.GetNext(pos)); pElement->Draw(pDC); } }
void CCell::MoveInCell(POINT potTracker) { POSITION pos; CElement *pElement; for(pos=m_Elements.GetHeadPosition();pos!=NULL;){ pElement=(CElement *)(m_Elements.GetNext(pos)); pElement->MoveInCell(potTracker); } }
void CCell::UpdateView() { POSITION pos; CElement *pElement; for(pos=m_Elements.GetHeadPosition();pos!=NULL;){ pElement=(CElement *)(m_Elements.GetNext(pos)); pElement->UpdateView(); } }
/////////////////////////////////////////////////////////////// // // CSpatialDatabaseImpl::FlushUpdateQueue // // Process all entities that have changed since the last call // /////////////////////////////////////////////////////////////// void CSpatialDatabaseImpl::FlushUpdateQueue ( void ) { int iTotalUpdated = 0; for ( std::map < CElement*, int >::iterator it = m_UpdateQueue.begin (); it != m_UpdateQueue.end (); ++it ) { CElement* pEntity = it->first; // Get the new bounding box SEntityInfo newInfo; CSphere sphere = pEntity->GetWorldBoundingSphere (); newInfo.box = CBox ( sphere.vecPosition, fabsf ( sphere.fRadius ) ); // Make everything 2D for now newInfo.box.vecMin.fZ = SPATIAL_2D_Z; newInfo.box.vecMax.fZ = SPATIAL_2D_Z; // Get previous info if ( SEntityInfo* pOldInfo = MapFind ( m_InfoMap, pEntity ) ) { // Don't update if bounding box is the same if ( pOldInfo->box == newInfo.box ) continue; // Remove old bounding box from tree m_Tree.Remove ( &pOldInfo->box.vecMin.fX, &pOldInfo->box.vecMax.fX, pEntity ); } if ( !IsValidSphere ( sphere ) ) continue; // Add new bounding box m_Tree.Insert( &newInfo.box.vecMin.fX, &newInfo.box.vecMax.fX, pEntity ); // Update info map MapSet ( m_InfoMap, pEntity, newInfo ); iTotalUpdated++; #ifdef SPATIAL_DATABASE_DEBUG_OUTPUTA OutputDebugLine ( SString ( "SpatialDatabase::UpdateEntity %08x %2.0f,%2.0f,%2.0f %2.0f,%2.0f,%2.0f" ,pEntity ,info.box.vecMin.fX ,info.box.vecMin.fY ,info.box.vecMin.fZ ,info.box.vecMax.fX ,info.box.vecMax.fY ,info.box.vecMax.fZ ) ); #endif } m_UpdateQueue.clear (); #ifdef SPATIAL_DATABASE_DEBUG_OUTPUTB int iTotalToUpdate = m_UpdateQueue.size (); if ( iTotalToUpdate ) OutputDebugLine ( SString ( "SpatialDatabase::FlushUpdateQueue TotalToUpdate: %d TotalUpdated: %d m_InfoMap: %d tree: %d ", iTotalToUpdate, iTotalUpdated, m_InfoMap.size (), m_Tree.Count () ) ); #endif }
vector < char * > * CLuaArguments::WriteToCharVector ( vector < char * > * values ) { vector < CLuaArgument* > ::const_iterator iter = m_Arguments.begin (); for ( ; iter != m_Arguments.end () ; iter++ ) { switch ( (*iter)->GetType() ) { case LUA_TNUMBER: { char * szValue = new char [ 20 ]; itoa ( ( int ) (*iter)->GetNumber(), szValue, 10 ); values->push_back ( szValue ); break; } case LUA_TSTRING: { const char * szString = (*iter)->GetString().c_str (); char * szValue = new char [ strlen ( szString ) + 1 ]; strcpy ( szValue, szString ); values->push_back ( szValue ); break; } case LUA_TBOOLEAN: { char * szValue = new char [ 6 ]; if ( (*iter)->GetBoolean() ) values->push_back ( strcpy ( szValue, "true" ) ); else values->push_back ( strcpy ( szValue, "false" ) ); break; } case LUA_TLIGHTUSERDATA: { char * szValue = new char [10]; memset(szValue,0,10); CElement* pElement = (*iter)->GetElement (); if ( VERIFY_ELEMENT(pElement) ) { _snprintf ( szValue, 9, "E#%d", (int)pElement->GetID() ); } else { g_pGame->GetScriptDebugging()->LogError ( NULL, "Couldn't serialize argument list, invalid element specified. Passing empty string instead." ); } values->push_back ( szValue ); } default: { char * szEmpty = new char [ 1 ]; szEmpty[0] = '\0'; values->push_back ( szEmpty ); } } } return values; }
void CElement::GetDescendantsByTypeSlow ( std::vector < CElement* >& outResult, uint uiTypeHash ) { for ( CChildListType::const_iterator iter = m_Children.begin () ; iter != m_Children.end () ; ++iter ) { CElement* pChild = *iter; if ( pChild->GetTypeHash () == uiTypeHash ) outResult.push_back ( pChild ); if ( !pChild->m_Children.empty () ) pChild->GetDescendantsByTypeSlow ( outResult, uiTypeHash ); } }
int CLuaFunctionDefs::SetWeaponAmmo ( lua_State* luaVM ) { // bool setWeaponAmmo ( player thePlayer, int weapon, int totalAmmo, [int ammoInClip = 0] ) CElement* pElement; eWeaponType weaponType; ushort usAmmo; ushort usAmmoInClip; CCustomWeapon * pWeapon = NULL; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pElement ); if ( !argStream.HasErrors () ) { if ( pElement->GetType () != CElement::WEAPON ) { argStream.ReadEnumStringOrNumber ( weaponType ); argStream.ReadNumber ( usAmmo ); argStream.ReadNumber ( usAmmoInClip, 0 ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponAmmo ( pElement, weaponType, usAmmo, usAmmoInClip ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } else { pWeapon = static_cast <CCustomWeapon *> ( pElement ); argStream.ReadNumber ( usAmmo ); if ( !argStream.HasErrors () ) { if ( CStaticFunctionDefinitions::SetWeaponAmmo ( pWeapon, usAmmo ) ) { lua_pushboolean ( luaVM, true ); return 1; } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage () ); lua_pushboolean ( luaVM, false ); return 1; }
ATTR_METHOD_IMPL(CElementParser, OnArrayType) { TRACE_PARSE_ENTRY(); CElement *pCurr = GetElement(); if (pCurr != NULL) { return pCurr->SetArrayType(wszValue, cchValue); } return E_FAIL; }
long CCell::Bottom() { long lTemp=0; POSITION pos; CElement *pElement; for(pos=m_Elements.GetHeadPosition();pos!=NULL;){ pElement=(CElement *)(m_Elements.GetNext(pos)); if(lTemp<pElement->Bottom()) lTemp=pElement->Bottom(); } return lTemp; }
int CSchemaMapManager::getNumberOfComponents() const { int nCount = 0; HashIterator iter(*(m_pElementPtrsMap.get())); ForEach(iter) { CElement *pElement = *(m_pElementPtrsMap->mapToValue(&iter.query())); if (pElement->isTopLevelElement() == true) nCount++; } return nCount; }
// Lua push/pop macros for our datatypes CElement* lua_toelement ( lua_State* luaVM, int iArgument ) { if ( lua_type ( luaVM, iArgument ) == LUA_TLIGHTUSERDATA ) { ElementID ID = TO_ELEMENTID ( lua_touserdata ( luaVM, iArgument ) ); CElement* pElement = CElementIDs::GetElement ( ID ); if ( !pElement || pElement->IsBeingDeleted () ) return NULL; return pElement; } return NULL; }
ATTR_METHOD_IMPL(CElementParser, OnSizeIs) { TRACE_PARSE_ENTRY(); CElement *pCurr = GetElement(); if (pCurr != NULL) { return pCurr->SetSizeIs(wszValue, cchValue); } EmitError(IDS_SDL_INTERNAL); return E_FAIL; }
HRESULT __stdcall CElementParser::startPrefixMapping( const wchar_t *wszPrefix, int cchPrefix, const wchar_t *wszUri, int cchUri) { CElement * pCurr = GetElement(); if (pCurr != NULL) { return pCurr->SetNamespaceUri(wszPrefix, cchPrefix, wszUri, cchUri); } return E_FAIL; }
long CCell::Top() { long lTemp=0x7fffffff; POSITION pos; CElement *pElement; for(pos=m_Elements.GetHeadPosition();pos!=NULL;){ pElement=(CElement *)(m_Elements.GetNext(pos)); if(lTemp>pElement->Top()) lTemp=pElement->Top(); } return lTemp; }
// // Handle the changing state of collision between one colshape and any entity // void CColManager::DoHitDetectionForColShape ( CColShape* pShape ) { // Ensure colshape is enabled and not being deleted if ( pShape->IsBeingDeleted () || !pShape->IsEnabled () ) return; std::map < CElement*, int > entityList; // Get all entities within the sphere CSphere querySphere = pShape->GetWorldBoundingSphere (); CElementResult result; GetSpatialDatabase()->SphereQuery ( result, querySphere ); // Extract relevant types for ( CElementResult::const_iterator it = result.begin () ; it != result.end (); ++it ) { CElement* pEntity = *it; switch ( pEntity->GetType () ) { case CElement::COLSHAPE: case CElement::SCRIPTFILE: case CElement::RADAR_AREA: case CElement::CONSOLE: case CElement::TEAM: case CElement::BLIP: case CElement::DUMMY: break; default: if ( pEntity->GetParentEntity () ) entityList[ pEntity ] = 1; } } // Add existing colliders, so they can be disconnected if required for ( list < CElement* > ::const_iterator it = pShape->CollidersBegin () ; it != pShape->CollidersEnd (); ++it ) { entityList[ *it ] = 1; } // Test each entity against the colshape for ( std::map < CElement*, int > ::const_iterator it = entityList.begin () ; it != entityList.end (); ++it ) { CElement* pEntity = it->first; CVector vecPosition = pEntity->GetPosition (); // Collided? bool bHit = pShape->DoHitDetection ( vecPosition ); HandleHitDetectionResult ( bHit, pShape, pEntity ); } }
void CSkViewView::OnDraw(CDC* pDC) { CSkViewDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; POSITION aPos = pDoc->GetListHeadPosition(); CElement* pElement = 0; while(aPos) { pElement = pDoc->GetNext(aPos); if(pDC->RectVisible(pElement->GetBoundRect())) pElement->Draw(pDC); } }