void CEmbeddedObject::ValidateInitialised(char* szMethod)
{
	if (!IsInitialised())
	{
		LogExpectedToBeInitialised(szMethod);
	}
}
void UTankAimingComponent::Fire()
{
	UWorld* const World = GetWorld();

	if (!ensure(World)) { return; }
	if (!ensure(ProjectileBlueprint)) { return; }

	if (IsInitialised())
	{
		// Spawn Projectile into the world
		if (FiringState == EFiringState::Locked)
		{
			AProjectile* Projectile = World->SpawnActor<AProjectile>
			(
				ProjectileBlueprint,
				Barrel->GetSocketLocation(FName("Projectile")),
				Barrel->GetSocketRotation(FName("Projectile"))
			);

			if (Projectile)
			{
				Projectile->LaunchProjectile(LaunchSpeed);
				LastFireTime = FPlatformTime::Seconds();

				ReduceRounds();
			}
		}
	}
}
void UTankAimingComponent::AimAt(const FVector& HitLocation)
{
	AActor* const Owner = GetOwner();
	if (IsInitialised())
	{
		FVector OutLaunchVelocity;
		FVector StartLocation = Barrel->GetSocketLocation(FName(TEXT("Projectile"))); 

		// Only for DebugTrace purpose - if not ignore them
		FCollisionResponseParams DummyParams; TArray<AActor*> DummyIgnores;
		
		// Calculate the OutLaunchVelocity
		bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
		(
			this,
			OutLaunchVelocity,
			StartLocation,
			HitLocation,
			LaunchSpeed,
			false, 
			10.f, 
			0.f, 
			ESuggestProjVelocityTraceOption::DoNotTrace
			//, DummyParams, DummyIgnores, true			// comment line to remove Debug DrawLine
		);

		if (bHaveAimSolution)
		{
			AimForwardDirection = OutLaunchVelocity.GetSafeNormal();
		
			MoveBarrelTowards(AimForwardDirection);
		}
	}
}
void UTankMovementComponent::IntendTurnRight(float Throw)
{
	if (IsInitialised())
	{
		LeftTrack->SetThrottle( Throw );
		RightTrack->SetThrottle( -Throw );
	}
}
// called to finish the capture cycle (a new one is allowed now)
void wxLongExpoPort::EndExposure()
{
   if ( ! IsInitialised()) return; // cannot use the port

    m_expoCycle = false;
    if (!m_lxMode) return;

    LXmodeOn(); // usually already there
}
// leave LX mode i.e. set all from init
void wxLongExpoPort::LXmodeOff()
{
   if ( ! IsInitialised()) return; // cannot use the port

   unsigned short wrd = m_LX_init;
   wrd = (m_invertedLogic) ? ~wrd: wrd;
   wxF()->portManager()->PPut(m_ioPortHandle, wrd);

   m_lxMode = false;
}
// called to enable framereadout
// NOTE:  best to sync this with image capture cycle
bool wxLongExpoPort::ReadExposure()
{
   if ( ! IsInitialised()) return false; // cannot use the port

   if (!m_expoCycle)
      return false;

   unsigned short wrd = m_LX_ampOn | m_LX_readout;
   wrd = (m_invertedLogic) ? ~wrd: wrd;
   wxF()->portManager()->PPut(m_ioPortHandle, wrd);

   return true;
}
// called when the amp should be switched on (if set)
bool wxLongExpoPort::TriggerExposure()
{
   if ( ! IsInitialised()) return false; // cannot use the port

   if (!m_expoCycle)
      return false;

   if (!m_ampMode)
      return true;  // nothing to do if not in AmpMode

   unsigned short wrd = m_LX_ampOn;
   wrd = (m_invertedLogic) ? ~wrd: wrd;
   wxF()->portManager()->PPut(m_ioPortHandle, wrd);

   return true;
}
void UTankAimingComponent::MoveBarrelTowards(const FVector& AimDirection)
{
	if (IsInitialised())
	{
		const FRotator AimAsRotator = AimDirection.Rotation();

		const FRotator BarrelRotator = Barrel->GetForwardVector().Rotation();
		const FRotator BarrelDeltaRotator = AimAsRotator - BarrelRotator;
		float BarrelDeltaElevate = FMath::UnwindDegrees(BarrelDeltaRotator.Pitch);	
		
		const FRotator TurretRotator = Turret->GetForwardVector().Rotation();
		const FRotator TurretDeltaRotator = AimAsRotator - TurretRotator;
		float TurretDeltaRotate = FMath::UnwindDegrees(TurretDeltaRotator.Yaw);

		Barrel->Elevate(BarrelDeltaElevate);
		Turret->Rotate(TurretDeltaRotate);
	}
}
// start of a LE cycle
// set shutter cycle if enabled
bool wxLongExpoPort::PreStartExposure()
{
   if ( ! IsInitialised()) return false; // cannot use the port

   if (m_expoCycle) return false;
   if (!m_lxMode) return false;

   m_expoCycle=true;

   if (m_shutterMode && m_LX_shutOn) {
        // this is only supported for parallel ports
      unsigned short wrd = m_LX_ampOn | m_LX_readout | m_LX_shutOn;
      wrd = (m_invertedLogic) ? ~wrd: wrd;
      wxF()->portManager()->PPut(m_ioPortHandle, wrd);
      // wait 300ms now via Timer
   }
   return true;
}
Exemple #11
0
	void PrintChar(uint8_t c)
	{
		if(c == 0)
			return;

		if(SERIALMIRROR){ HardwareAbstraction::Devices::SerialPort::WriteChar(c); }

		if(!IsInitialised())
		{
			Kernel::HardwareAbstraction::VideoOutput::Console80x25::PrintChar(c);
			return;
		}

		AutoMutex lk = AutoMutex(Mutexes::ConsoleOutput);

		if(c == '\r')
		{
			VT_CursorX = 0;
			return;
		}
		if(c == '\b')
		{
			if(VT_CursorX > 0)
			{
				VT_CursorX--;
				DrawChar(' ', (VT_CursorX * CharWidth) + OffsetLeft, (VT_CursorY * 16), VT_Colour);
			}
			else if(VT_CursorY > 0)
			{
				VT_CursorX = CharsPerLine - 1;
				VT_CursorY--;

				DrawChar(' ', (VT_CursorX * CharWidth) + OffsetLeft, (VT_CursorY * 16), VT_Colour);
			}

			return;
		}

		if(VT_CursorY == CharsPerColumn && VT_CursorX == CharsPerLine)
		{
			// Reached end of line and no more space below
			VT_CursorX = 0;
			ScrollDown(1);



			if(c == '\n' || c == '\t')
			{
				ScrollDown(1);
				VT_CursorX = 0;

				return;
			}
			DrawChar(c, (VT_CursorX * CharWidth) + OffsetLeft, (VT_CursorY * 16), VT_Colour);
			VT_CursorX++;

		}
		else if((VT_CursorX * 8) >= ((GetResX()) - 10))
		{
			// Reached end of line
			VT_CursorX = 0;
			VT_CursorY++;

			DrawChar(c, (VT_CursorX * CharWidth) + OffsetLeft, (VT_CursorY * 16), VT_Colour);
			VT_CursorX = 1;
		}
		else
		{
			if(c == '\n')
			{
				if(VT_CursorY < CharsPerColumn)
				{
					VT_CursorX = 0;
					VT_CursorY++;
				}
				else
				{
					VT_CursorX = 0;
					ScrollDown(1);
				}

				return;
			}
			else if(c == '\t')
			{
				if(((VT_CursorX + 4) & ~(4 - 1)) < CharsPerLine)
				{
					VT_CursorX = (VT_CursorX + 4) & ~(4 - 1);
				}
				else
				{
					VT_CursorX = 0;
					if(VT_CursorY < CharsPerColumn)
						VT_CursorY++;

					else
						ScrollDown(1);
				}

				return;
			}

			// Normal printing
			DrawChar(c, (VT_CursorX * CharWidth) + OffsetLeft, (VT_CursorY * 16), VT_Colour);
			VT_CursorX++;
		}

		return;
	}
bool wxLongExpoPort::CommitConfiguration()
{
   if ( ! IsInitialised()) return false; // cannot use the port

   return wxF()->portManager()->PSetMask(m_ioPortHandle, m_LX_mask); // set the bits used for LE
}