void Spaceship::Update(float delta)
{
	int rotSpeed = 100;
	//Rotate
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::A))
	{
		rotate(delta * -rotSpeed);
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::D))
	{
		rotate(delta * rotSpeed);
	}

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
	{
		ApplyForwardForce();
		tPart->SetActive(true);
	}
	else
	{
		tPart->SetActive(false);
	}
	ApplyVelocity(delta);
	tPart->Update(delta);
	
}
ACTIVITY_RETURN_TYPE CyclicPulsingCoordinate :: Activity(ACTIVITY_INPUT)
{
	#if 0
	textprint("CyclicPulsingCoordinate :: Activity(%i)\n", FixP_Time);
	#endif

	int Int_CurrentCoord_Old = Int_CurrentCoord_Val;
	
	ApplyVelocity( FixP_Time );
	
	int FixP_Displacement =
	(
		( fGoingForSecondCoord ? FixP_Target1_Val : FixP_Target0_Val ) - FixP_Position_Val
	);

	#if 0
	textprint
	(
		"FixP_Velocity_Val = %i FixP_Displacement = %i\n",
		FixP_Velocity_Val,
		FixP_Displacement
	);
	#endif

	if 
	(
		DAVEMCRO_NONZERO_AND_OPPOSITESIGN
		(
			FixP_Velocity_Val,
			FixP_Displacement
		)
	)
	{
		{
			SetCoord_FixP
			(
				( fGoingForSecondCoord ? FixP_Target1_Val : FixP_Target0_Val )
				+
				FixP_Displacement
			);

			fGoingForSecondCoord = !fGoingForSecondCoord;

			SetVelocity_FixP
			(
				-FixP_Velocity_Val
			);
		}
	}

	ACTIVITY_RVAL_BOOL(Int_CurrentCoord_Old != Int_CurrentCoord_Val)
}
void UCrowdManager::Tick(float DeltaTime)
{
	SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_Tick);
	INC_DWORD_STAT_BY(STAT_AI_Crowd_NumAgents, ActiveAgents.Num());

#if WITH_RECAST
	if (DetourCrowd)
	{
		int32 NumActive = DetourCrowd->cacheActiveAgents();
		if (NumActive)
		{
			MyNavData->BeginBatchQuery();

			for (auto It = ActiveAgents.CreateIterator(); It; ++It)
			{
				// collect position and velocity
				FCrowdAgentData& AgentData = It.Value();
				if (AgentData.IsValid())
				{
					PrepareAgentStep(It.Key(), AgentData, DeltaTime);
				}
			}

			// corridor update from previous step
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepCorridorTime);
				DetourCrowd->updateStepCorridor(DeltaTime, DetourAgentDebug);
			}

			// regular steps
			if (bAllowPathReplan)
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepPathsTime);
				DetourCrowd->updateStepPaths(DeltaTime, DetourAgentDebug);
			}
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepProximityTime);
				DetourCrowd->updateStepProximityData(DeltaTime, DetourAgentDebug);
				PostProximityUpdate();
			}
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepNextPointTime);
				DetourCrowd->updateStepNextMovePoint(DeltaTime, DetourAgentDebug);
				PostMovePointUpdate();
			}
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepSteeringTime);
				DetourCrowd->updateStepSteering(DeltaTime, DetourAgentDebug);
			}
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepAvoidanceTime);
				DetourCrowd->updateStepAvoidance(DeltaTime, DetourAgentDebug);
			}
			if (bResolveCollisions)
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepCollisionsTime);
				DetourCrowd->updateStepMove(DeltaTime, DetourAgentDebug);
			}
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepComponentsTime);
				UpdateAgentPaths();
			}
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepNavLinkTime);
				DetourCrowd->updateStepOffMeshVelocity(DeltaTime, DetourAgentDebug);
			}

			// velocity updates
			{
				SCOPE_CYCLE_COUNTER(STAT_AI_Crowd_StepMovementTime);
				for (auto It = ActiveAgents.CreateIterator(); It; ++It)
				{
					const FCrowdAgentData& AgentData = It.Value();
					if (AgentData.bIsSimulated && AgentData.IsValid())
					{
						UCrowdFollowingComponent* CrowdComponent = Cast<UCrowdFollowingComponent>(It.Key());
						if (CrowdComponent && CrowdComponent->IsCrowdSimulationEnabled())
						{
							ApplyVelocity(CrowdComponent, AgentData.AgentIndex);
						}
					}
				}
			}

			MyNavData->FinishBatchQuery();

#if WITH_EDITOR
			// normalize samples only for debug drawing purposes
			DetourAvoidanceDebug->normalizeSamples();
#endif
		}
	}
#endif // WITH_RECAST
}
ACTIVITY_RETURN_TYPE AcyclicFixedSpeedHoming :: Activity(ACTIVITY_INPUT)
{
	int Int_CurrentCoord_Old = Int_CurrentCoord_Val;

	#if 0
	textprint("acyclic homing coord for time %i\n",FixP_Time);
	#endif
	
	int FixP_Delta_Homing = (FixP_TargetCoord_Val - FixP_Position_Val);

	#if 0
	textprint
	(
		"current = %6i fixp = %6i\n",
		(int)Int_CurrentCoord_Val,
		(int)FixP_Position_Val
	);

	textprint
	(
		"target = %6i fixp = %6i\n",
		(int)Int_TargetCoord_Val,
		(int)FixP_TargetCoord_Val
	);
	#endif

	#if 0
	SetVelocity_FixP( FixP_IdealVelocity_Val );
	#endif

	int FixP_Delta_Position = MUL_FIXED(FixP_Time, FixP_Velocity_Val);
	
	#if 0
	textprint
	(
		"FixP delta Homing= %6i PosN=%6i\n",
		(int)FixP_Delta_Homing,
		(int)FixP_Delta_Position		
	);
	#endif

		
	//if target is within this frame's velocity...
	if
	(
		abs(FixP_Delta_Homing)
		<=
		abs(FixP_Delta_Position)
	)
	{
		#if 0
		textprint("within range\n");
		#endif
		
		SetCoord_FixP
		(
			FixP_TargetCoord_Val
		);
		SetVelocity_FixP( 0 );
		Stop();
	}
	else
	{
		#if 0
		textprint("not within range\n");
		#endif
		
		ApplyVelocity(FixP_Time);
		
		
	}

	ACTIVITY_RVAL_BOOL(Int_CurrentCoord_Old != Int_CurrentCoord_Val)
}