Example #1
0
void EntityManager::UpdateEntityAfterMoving( CCopyEntity *pEntity )
{
  {
	PROFILE_FUNCTION();

	if( pEntity->PrevPosition() != pEntity->GetWorldPosition() )
	{
		//'pEntity' has moved during this frame
		pEntity->sState |= CESTATE_MOVED_DURING_LAST_FRAME;
		pEntity->sState |= CESTATE_LIGHT_INFORMATION_INVALID;

		// update the link in the entity tree
		pEntity->Unlink();
		Link( pEntity );

		// update world aabb
		pEntity->world_aabb.TransformCoord( pEntity->local_aabb, pEntity->GetWorldPosition() );
	}
	else
		pEntity->sState &= ~CESTATE_MOVED_DURING_LAST_FRAME;

  }
	if( true /*pEntity->GetEntityFlags() & AUTOMATICALLY_UPDATE_CHILDREN*/ )
	{
		const int num_children = pEntity->GetNumChildren();
		for( int i=0; i<num_children; i++ )
		{
			if( IsValidEntity( pEntity->GetChild(i) ) )
				UpdateEntityAfterMoving( pEntity->GetChild(i) );
		}
	}
}
Example #2
0
/// Release all the copy entities in 'm_pEntityInUse'
void EntityManager::ReleaseAllEntities()
{
//	CCopyEntity *pEntity = this->m_pEntityInUse;
//	CCopyEntity *pNextEntity = NULL;
	shared_ptr<CCopyEntity> pEntity = this->m_pEntityInUse;
	shared_ptr<CCopyEntity> pNextEntity;

	// terminate all the remaining entities
	while( pEntity )
	{
		// save the pointer to the next entity since CStage::TerminateEntity()
		// takes the reference to an entity pointer and sets it to NULL
		pNextEntity = pEntity->m_pNext;

		if( IsValidEntity( pEntity.get() ) )
		{
			CCopyEntity *p = pEntity.get();
			m_pStage->TerminateEntity( p );
		}

		pEntity = pNextEntity;
	}

	ReleaseTerminatedEntities();
}
Example #3
0
    void UpdateEntityVelocity(int entityNum, const vec3_t velocity) {
        if (not initialized or not IsValidEntity(entityNum) or not IsValidVector(velocity)) {
            return;
        }

        UpdateRegisteredEntityVelocity(entityNum, velocity);
    }
Example #4
0
    void UpdateEntityPosition(int entityNum, const vec3_t position) {
        if (not initialized or not IsValidEntity(entityNum) or not IsValidVector(position)) {
            return;
        }

        UpdateRegisteredEntityPosition(entityNum, position);
    }
Example #5
0
    void StreamData(int streamNum, const void* data, int numSamples, int rate, int width, int channels, float volume, int entityNum) {
        if (not initialized or (streamNum < 0 or streamNum >= N_STREAMS)) {
            return;
        }

        if (not streams[streamNum]) {
            streams[streamNum] = std::make_shared<StreamingSound>();
            if (IsValidEntity(entityNum)) {
                AddSound(GetEmitterForEntity(entityNum), streams[streamNum], 1);
            } else {
                AddSound(GetLocalEmitter(), streams[streamNum], 1);
            }
        }

        streams[streamNum]->SetGain(volume);

	    AudioData audioData(rate, width, channels, (width * numSamples * channels),
	                        reinterpret_cast<const char*>(data));
	    AL::Buffer buffer;

	    int feedError = buffer.Feed(audioData);

        if (not feedError) {
            streams[streamNum]->AppendBuffer(std::move(buffer));
        }
    }
Example #6
0
    void UpdateListener(int entityNum, const vec3_t orientation[3]) {
        if (not initialized or
            not IsValidEntity(entityNum) or
            not orientation or
            not IsValidVector(orientation[0]) or
            not IsValidVector(orientation[1]) or
            not IsValidVector(orientation[2])) {
            return;
        }

        UpdateListenerEntity(entityNum, orientation);
    }
Example #7
0
/// Handles an entity entering the Trigger area.
void RPG_Trigger::ProcessEnter(VisBaseEntity_cl* entity)
{
  if(CanTrigger() &&
     IsValidEntity(entity))
  {
    m_lastEnteredTime = Vision::GetTimer()->GetTime();

    if(m_maxTriggerCount > 0)
    {
      ++m_curTriggerCount;
    }

    m_insideEntities.Add(entity);

    OnEnter(entity);
    if(m_onEnterSource)
      m_onEnterSource->TriggerAllTargets();
    TriggerScriptEvent("OnEnter", "*o", entity);
  }
}
Example #8
0
bool EntityManager::MakeEntityTree(BSPTree* pSrcBSPTree)
{
//	Reset();

	vector<EntityNode> entity_tree;

	// allocate some memory in advance
	// not doing this may cause error in Release build
	entity_tree.reserve( 10000 );

	// create the new entity tree on the temporary node buffer entity_tree
	// - Do not copy the tree to m_paEntityTree until all the entities are unlinked
	MakeEntityNode_r(0, pSrcBSPTree, &entity_tree);

	if(entity_tree.size() == 0)
		return false;	// entity tree costruction failed

	entity_tree[0].sParent = -1;	// the root node has no parent

	// unlink all the entities from the current entity tree
	if( m_pEntityInUse )
	{
		for( CCopyEntity* pEntity = m_pEntityInUse.get();
			 pEntity != NULL;
			 pEntity = pEntity->m_pNextRawPtr )
		{
			pEntity->Unlink();
		}
	}

	// Do this AFTER all the entities are unlinked from the entity nodes
	SafeDeleteArray( m_paEntityTree );

	// copy the new tree
	m_NumEntityNodes = (int)entity_tree.size();
	m_paEntityTree = new EntityNode [ m_NumEntityNodes ];
	for(int i=0; i<m_NumEntityNodes; i++)
		m_paEntityTree[i] = entity_tree[i];

	entity_tree.clear();

	// set stage and entity set
	for(int i=0; i<m_NumEntityNodes; i++)
	{
		m_paEntityTree[i].m_pStage     = m_pStage;
		m_paEntityTree[i].m_pEntitySet = this;
	}


	// update entity tree of the render manager
	m_pRenderManager->UpdateEntityTree( m_paEntityTree, m_NumEntityNodes );

	WriteEntityTreeToFile( "debug/entity_tree - recreated the tree.txt" );

	// re-link all the entities to the new tree nodes
	if( m_pEntityInUse )
	{
		for( CCopyEntity* pEntity = m_pEntityInUse.get();
			 pEntity != NULL;
			 pEntity = pEntity->m_pNextRawPtr )
		{
			// added: 11:34 PM 5/25/2008
			// Do not re-link an entity if it has already been marked as 'not in use'
			// - Failure to do this leads to an invalid link in the entity tree node
			//   - Caused infinite loops in EntityNode::CheckPosition_r()
			if( !IsValidEntity( pEntity ) )
				continue;

			Link( pEntity );
		}
	}

	WriteEntityTreeToFile( "debug/entity_tree - re-linked entities to the tree.txt" );

	// re-link all the light entities to the new tree nodes
//	m_pLightEntityManager->RelinkLightEntities();

	return true;
}