Added to enable optional compilation of CarSim plugin.

This commit is contained in:
Axel 2020-12-04 16:09:46 +01:00 committed by bernat
parent 009663e57d
commit b068dd81d5
7 changed files with 91 additions and 28 deletions

View File

@ -6,6 +6,7 @@ using UnrealBuildTool;
public class Carla : ModuleRules
{
bool UsingCarSim = false;
private bool IsWindows(ReadOnlyTargetRules Target)
{
return (Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32);
@ -20,6 +21,21 @@ public class Carla : ModuleRules
bEnableExceptions = true;
}
// Read config about carsim
string CarlaPluginPath = Path.GetFullPath( ModuleDirectory );
string ConfigDir = Path.GetFullPath(Path.Combine(CarlaPluginPath, "../../../../Config/"));
string CarSimConfigFile = Path.Combine(ConfigDir, "CarSimConfig.ini");
string[] text = System.IO.File.ReadAllLines(CarSimConfigFile);
foreach (string line in text)
{
Console.WriteLine(line);
if (line == "CarSim ON")
{
UsingCarSim = true;
PublicDefinitions.Add("WITH_CARSIM");
}
}
PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
@ -42,13 +58,10 @@ public class Carla : ModuleRules
// ... add other public dependencies that you statically link with here ...
}
);
PublicDependencyModuleNames.AddRange(
new string[]
{
"CarSim"
// ... add other public dependencies that you statically link with here ...
}
);
if (UsingCarSim)
{
PublicDependencyModuleNames.AddRange(new string[] { "CarSim" });
}
if (Target.Type == TargetType.Editor)
{
@ -75,14 +88,12 @@ public class Carla : ModuleRules
// ... add private dependencies that you statically link with here ...
}
);
PrivateDependencyModuleNames.AddRange(
new string[]
{
"CarSim"
// ... add private dependencies that you statically link with here ...
}
);
PrivateIncludePathModuleNames.AddRange(new string[] { "CarSim" });
if (UsingCarSim)
{
PrivateDependencyModuleNames.AddRange(new string[] { "CarSim" });
PrivateIncludePathModuleNames.AddRange(new string[] { "CarSim" });
}
DynamicallyLoadedModuleNames.AddRange(
new string[]

View File

@ -942,7 +942,9 @@ void FCarlaServer::FPimpl::BindActions()
if(Vehicle)
{
Vehicle->SetActorEnableCollision(true);
#ifdef WITH_CARSIM
if(!Vehicle->IsCarSimEnabled())
#endif
{
RootComponent->SetSimulatePhysics(bEnabled);
RootComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
@ -1098,6 +1100,7 @@ void FCarlaServer::FPimpl::BindActions()
bool bEnabled,
std::string SimfilePath) -> R<void>
{
#ifdef WITH_CARSIM
REQUIRE_CARLA_EPISODE();
auto ActorView = Episode->FindActor(ActorId);
if (!ActorView.IsValid())
@ -1111,12 +1114,16 @@ void FCarlaServer::FPimpl::BindActions()
}
Vehicle->SetCarSimEnabled(bEnabled, carla::rpc::ToFString(SimfilePath));
return R<void>::Success();
#else
RESPOND_ERROR("CarSim plugin is not enabled");
#endif
};
BIND_SYNC(use_carsim_road) << [this](
cr::ActorId ActorId,
bool bEnabled) -> R<void>
{
#ifdef WITH_CARSIM
REQUIRE_CARLA_EPISODE();
auto ActorView = Episode->FindActor(ActorId);
if (!ActorView.IsValid())
@ -1130,6 +1137,9 @@ void FCarlaServer::FPimpl::BindActions()
}
Vehicle->UseCarSimRoad(bEnabled);
return R<void>::Success();
#else
RESPOND_ERROR("CarSim plugin is not enabled");
#endif
};
//-----CARSIM--------------------------------
// ~~ Traffic lights ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -33,8 +33,11 @@ ACarlaWheeledVehicle::ACarlaWheeledVehicle(const FObjectInitializer& ObjectIniti
VelocityControl = CreateDefaultSubobject<UVehicleVelocityControl>(TEXT("VelocityControl"));
VelocityControl->Deactivate();
CarSimMovementComponent = CreateDefaultSubobject<UCarSimMovementComponent>(TEXT("CarSimMovement"));
#ifdef WITH_CARSIM
ExternalMovementComponent = CreateDefaultSubobject<UCarSimMovementComponent>(TEXT("CarSimMovement"));
CarSimMovementComponent = Cast<UCarSimMovementComponent>(ExternalMovementComponent);
CarSimMovementComponent->DisableVehicle = true;
#endif
GetVehicleMovementComponent()->bReverseAsBrake = false;
}
@ -114,7 +117,9 @@ void ACarlaWheeledVehicle::BeginPlay()
Vehicle4W->WheelSetups = NewWheelSetups;
#ifdef WITH_CARSIM
SetCarSimEnabled(false);
#endif
}
void ACarlaWheeledVehicle::AdjustVehicleBounds()
@ -144,14 +149,13 @@ void ACarlaWheeledVehicle::AdjustVehicleBounds()
float ACarlaWheeledVehicle::GetVehicleForwardSpeed() const
{
#ifdef WITH_CARSIM
if (bCarSimEnabled)
{
return CarSimMovementComponent->GetForwardSpeed();
}
else
{
return GetVehicleMovementComponent()->GetForwardSpeed();
}
#endif
return GetVehicleMovementComponent()->GetForwardSpeed();
}
FVector ACarlaWheeledVehicle::GetVehicleOrientation() const
@ -161,14 +165,13 @@ FVector ACarlaWheeledVehicle::GetVehicleOrientation() const
int32 ACarlaWheeledVehicle::GetVehicleCurrentGear() const
{
#ifdef WITH_CARSIM
if (bCarSimEnabled)
{
return CarSimMovementComponent->GetCurrentGear();
}
else
{
return GetVehicleMovementComponent()->GetCurrentGear();
}
#endif
return GetVehicleMovementComponent()->GetCurrentGear();
}
FTransform ACarlaWheeledVehicle::GetVehicleBoundingBoxTransform() const
@ -196,6 +199,7 @@ float ACarlaWheeledVehicle::GetMaximumSteerAngle() const
void ACarlaWheeledVehicle::FlushVehicleControl()
{
#ifdef WITH_CARSIM
if (bCarSimEnabled)
{
//-----CARSIM--------------------------------
@ -224,6 +228,7 @@ void ACarlaWheeledVehicle::FlushVehicleControl()
//-----------------------------------------
}
else
#endif
{
auto *MovementComponent = GetVehicleMovementComponent();
MovementComponent->SetThrottleInput(InputControl.Control.Throttle);
@ -539,12 +544,15 @@ void ACarlaWheeledVehicle::SwitchToUE4Physics()
void ACarlaWheeledVehicle::RevertToCarSimPhysics()
{
#ifdef WITH_CARSIM
SetCarSimEnabled(true, CarSimMovementComponent->VsConfigFile);
carla::log_warning("Collision: giving control to carsim");
#endif
}
void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath)
{
#ifdef WITH_CARSIM
if (bEnabled == bCarSimEnabled)
{
return;
@ -605,16 +613,20 @@ void ACarlaWheeledVehicle::SetCarSimEnabled(bool bEnabled, FString SimfilePath)
GetMesh()->SetCollisionProfileName("Vehicle");
}
bCarSimEnabled = bEnabled;
#endif
}
void ACarlaWheeledVehicle::UseCarSimRoad(bool bEnabled)
{
#ifdef WITH_CARSIM
carla::log_warning("Enabling CarSim Road", bEnabled);
CarSimMovementComponent->UseVehicleSimRoad = bEnabled;
CarSimMovementComponent->ResetVsVehicle(false);
CarSimMovementComponent->SyncVsVehicleLocOri();
#endif
}
#ifdef WITH_CARSIM
FVector ACarlaWheeledVehicle::GetVelocity() const
{
if (bCarSimEnabled)
@ -626,6 +638,7 @@ FVector ACarlaWheeledVehicle::GetVelocity() const
return Super::GetVelocity();
}
}
#endif
bool ACarlaWheeledVehicle::IsCarSimEnabled() const
{

View File

@ -19,7 +19,9 @@
#include "CoreMinimal.h"
//-----CARSIM--------------------------------
#ifdef WITH_CARSIM
#include "CarSimMovementComponent.h"
#endif
//-------------------------------------------
#include "CarlaWheeledVehicle.generated.h"
@ -241,7 +243,7 @@ private:
FVehicleControl LastAppliedControl;
//-----CARSIM--------------------------------
//-----CARSIM--------------------------------
public:
UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintCallable)
@ -250,7 +252,9 @@ public:
UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintCallable)
void UseCarSimRoad(bool bEnabled);
#ifdef WITH_CARSIM
virtual FVector GetVelocity() const override;
#endif
UFUNCTION(Category="CARLA Wheeled Vehicle", BlueprintPure)
bool IsCarSimEnabled() const;
@ -281,6 +285,11 @@ private:
bool bCarSimEnabled = false;
UPROPERTY(Category="CARLA Wheeled Vehicle", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
UMovementComponent * ExternalMovementComponent;
#ifdef WITH_CARSIM
// Casted version of ExternalMovementComponent
UCarSimMovementComponent * CarSimMovementComponent;
#endif
//-------------------------------------------
};

View File

@ -24,11 +24,12 @@ REMOVE_INTERMEDIATE=false
HARD_CLEAN=false
BUILD_CARLAUE4=false
LAUNCH_UE4_EDITOR=false
USE_CARSIM=false
GDB=
RHI="-vulkan"
OPTS=`getopt -o h --long help,build,rebuild,launch,clean,hard-clean,gdb,opengl -n 'parse-options' -- "$@"`
OPTS=`getopt -o h --long help,build,rebuild,launch,clean,hard-clean,gdb,opengl,carsim -n 'parse-options' -- "$@"`
eval set -- "$OPTS"
@ -57,6 +58,9 @@ while [[ $# -gt 0 ]]; do
--opengl )
RHI="-opengl";
shift ;;
--carsim )
USE_CARSIM=true;
shift ;;
-h | --help )
echo "$DOC_STRING"
echo "$USAGE_STRING"
@ -123,6 +127,12 @@ if ${BUILD_CARLAUE4} ; then
fi
if ${USE_CARSIM} ; then
echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini
else
echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini
fi
log "Build CarlaUE4 project."
make CarlaUE4Editor

View File

@ -17,7 +17,7 @@ REMOVE_INTERMEDIATE=false
BUILD_RSS_VARIANT=false
BUILD_PYTHONAPI=true
OPTS=`getopt -o h --long help,config:,rebuild,clean,rss,python-version:,packages:,clean-intermediate,all,xml, -n 'parse-options' -- "$@"`
OPTS=`getopt -o h --long help,config:,rebuild,clean,rss,carsim,python-version:,packages:,clean-intermediate,all,xml, -n 'parse-options' -- "$@"`
eval set -- "$OPTS"

View File

@ -15,8 +15,9 @@ DO_TARBALL=true
DO_CLEAN_INTERMEDIATE=false
PROPS_MAP_NAME=PropsMap
PACKAGE_CONFIG=Shipping
USE_CARSIM=false
OPTS=`getopt -o h --long help,config:,no-zip,clean-intermediate,packages:,python-version: -n 'parse-options' -- "$@"`
OPTS=`getopt -o h --long help,config:,no-zip,clean-intermediate,carsim,packages:,python-version: -n 'parse-options' -- "$@"`
eval set -- "$OPTS"
@ -34,6 +35,9 @@ while [[ $# -gt 0 ]]; do
--packages )
PACKAGES="$2"
shift 2 ;;
--carsim )
USE_CARSIM=true;
shift ;;
-h | --help )
echo "$DOC_STRING"
echo "$USAGE_STRING"
@ -87,6 +91,12 @@ if ${DO_CARLA_RELEASE} ; then
pushd "${CARLAUE4_ROOT_FOLDER}" >/dev/null
if [ ${USE_CARSIM} ]; then
echo "CarSim ON" > ${PWD}/Config/CarSimConfig.ini
else
echo "CarSim OFF" > ${PWD}/Config/CarSimConfig.ini
fi
log "Cooking CARLA project."
rm -Rf ${RELEASE_BUILD_FOLDER}