Пример #1
0
void ObjectManager::Update( float dt, const Camera &cam ) {
  int tLx, tLy, bRx, bRy;
  GetCamCoords( cam, 1, 1, tLx, tLy, bRx, bRy );

  m_objGrid->SetRange( tLx, tLy, bRx, bRy );
  std::set<intrObj_type, CreationCmp> set;
  FillSet( set );

  // Need to separate collision from logic
  for ( SetItr obj = set.begin(); obj != set.end(); ++obj ) {
    UpdateCollisions( *obj, cam );
  }

  for ( SetItr obj = set.begin(); obj != set.end(); ++obj ) {
    const intrObj_type &object = *obj;
    ObjectAttorney::UpdateAI( object, dt );

    const IntRect &lastTiles =
      ObjectAttorney::GetLastTileRange( object );
    const IntRect &currTiles =
      ObjectAttorney::GetTileRange( object );
    m_objGrid->MoveElem( object, lastTiles, currTiles );
  }

  // Delete all objects ready to be destroyed
  for ( unsigned int i = 0; i < m_toBeDestroyed.size(); ++i ) {
    const intrObj_type &delObj = m_toBeDestroyed[i];
    
    const IntRect &tiles =
      ObjectAttorney::GetTileRange( delObj );
    m_objGrid->RemoveElem( delObj, tiles );
        
    std::string type = ObjectAttorney::GetType( delObj ); 
    std::pair<nameMap_type::iterator, nameMap_type::iterator> objects =
      m_objTypes.equal_range( type );

    for ( nameMap_type::iterator obj = objects.first; 
          obj != objects.second; ) {
      if ((*obj).second == delObj ) {
        m_objTypes.erase( obj++ );
      } else {
        ++obj;
      }
    }
  }

  m_toBeDestroyed.clear();
}
Пример #2
0
/*! Given the current state of the simulation (Voxel positions and velocities) and information about the current environment, advances the simulation by the maximum stable timestep. 
The integration scheme denoted by the CurIntegrator member variable is used.
Calculates some relevant system statistics such as maximum displacements and velocities and total force.
Returns true if the time step was successful, false otherwise.
@param[out] pRetMessage Pointer to an initialized string. Messages generated in this function will be appended to the string.
*/
bool CVX_Sim::TimeStep(std::string* pRetMessage)
{
	if(SelfColEnabled) UpdateCollisions(); //update self intersection lists if necessary
	else if (!SelfColEnabled && ColEnableChanged){ColEnableChanged=false; DeleteTmpBonds();}

	UpdateMatTemps(); //updates the temperatures

	//update information to calculate
	switch (GetStopConditionType()){ //may need to calculate certain items depending on stop condition
	case SC_CONST_MAXENERGY: StatToCalc |= CALCSTAT_KINE; StatToCalc |= CALCSTAT_STRAINE; break;
	case SC_MIN_KE: StatToCalc |= CALCSTAT_KINE; break;
	case SC_MIN_MAXMOVE: StatToCalc |= CALCSTAT_VEL; break;
	}
	if (IsEquilibriumEnabled()) StatToCalc |= CALCSTAT_KINE;

	if (!Integrate(CurIntegrator)){
		if (pRetMessage) *pRetMessage = "Simulation Diverged. Please reduce forces or accelerations.\n";	
		return false;
	}
	
	if (IsEquilibriumEnabled() && KineticEDecreasing()) ZeroAllMotion();
	UpdateStats(pRetMessage);
	return true;
}
Пример #3
0
//=============================================================================================================
void Game::Draw()
{
	float syncalpha = GameVariables::GetAlpha();

	if( state != TransitionOut && state != Inactive && state != TransitionHalf && state != FlyOff )
		UpdateCollisions(syncalpha);

	if( invert > 0 )
	{
		if( rendertarget != NULL && rendersurface != NULL )
		{
			if( invert == 3 )
			{
				avatarbubble.Alignment = DT_RIGHT|DT_BOTTOM;
				avatarbubble.Position.x = GameVariables::ScreenWidth - (avatar.Position.value.x + avatar.Image->Size.x * 1.05f);
				avatarbubble.Position.y = GameVariables::ScreenHeight - (avatar.Position.value.y - avatar.Image->Size.y * 0.3f);
			}
			else if( invert == 2 )
			{
				avatarbubble.Alignment = DT_LEFT|DT_BOTTOM;
				avatarbubble.Position.x = avatar.Position.value.x + avatar.Image->Size.x * 1.05f;
				avatarbubble.Position.y = GameVariables::ScreenHeight - (avatar.Position.value.y - avatar.Image->Size.y * 0.3f);
			}
			else
			{
				avatarbubble.Alignment = DT_RIGHT|DT_TOP;
				avatarbubble.Position.x = GameVariables::ScreenWidth - (avatar.Position.value.x + avatar.Image->Size.x * 1.05f);
				avatarbubble.Position.y = avatar.Position.value.y - avatar.Image->Size.y * 0.3f;
			}
        
			if( GameVariables::EnableShaders )
				DrawWithShadersInverted(syncalpha);
			else
				DrawWithoutShadersInverted(syncalpha);
		}
		else
		{
			avatarbubble.Alignment = DT_LEFT|DT_TOP;
			avatarbubble.Position.x = avatar.Position.value.x + avatar.Image->Size.x * 1.05f;
			avatarbubble.Position.y = avatar.Position.value.y - avatar.Image->Size.y * 0.3f;

			DrawWithoutShaders(syncalpha);
		}
	}
	else
	{
		avatarbubble.Alignment = DT_LEFT|DT_TOP;
		avatarbubble.Position.x = avatar.Position.value.x + avatar.Image->Size.x * 1.05f;
		avatarbubble.Position.y = avatar.Position.value.y - avatar.Image->Size.y * 0.3f;

		DrawWithoutShaders(syncalpha);
	}

	CForm::Draw();
	spritefont->Draw(GroupID);

	// animáció csíkok
	if( state == TransitionIn || state == TransitionOut ||
		state == Inactive || state == TransitionHalf )
	{
		if( state != Inactive )
			alpha.smooth((float)game->Sync.Alpha());

		D3DXCOLOR color(1, 1, 1, 1.0f - alpha.value);

		D3DXMATRIX transform(
			GameVariables::ScreenWidth, 0, 0, 0,
			0, GameVariables::ScreenHeight, 0, 0,
			0, 0, 1, 0,
			0, 0, 0, 1);

		game->StateManager->SetTexture(0, atlastex1);
		game->DrawImage(transform, hud.Panel->Texcoords, (DWORD)color);
	}
}
Пример #4
0
bool QVX_Sim::TimeStepMT(std::string* pRetMessage)
{
	if(SelfColEnabled) UpdateCollisions(); //update self intersection lists if necessary
	IntegrateMT(CurIntegrator);
	return UpdateStats(pRetMessage);
}