Remove deprecated code from Carla plugin

This commit is contained in:
nsubiron 2019-04-08 14:41:24 +02:00
parent 294f95926e
commit fce4d1a9f8
62 changed files with 41 additions and 6368 deletions

View File

@ -1,421 +0,0 @@
[Default]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=50
SunDirectionalLightIntensity=15.092
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=16.296
HorizontFalloff=3
ZenithColor=(R=0.034046,G=0.109247,B=0.295000,A=1.000000)
HorizonColor=(R=0.659853,G=0.862215,B=1.000000,A=1.000000)
CloudColor=(R=0.855778,G=0.919005,B=1.000000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=5.505
SkyLightColor=(R=0.149650,G=0.161819,B=0.205000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=40
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[ClearNoon]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=50
SunDirectionalLightIntensity=15.092
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=16.296
HorizontFalloff=3
ZenithColor=(R=0.034046,G=0.109247,B=0.295000,A=1.000000)
HorizonColor=(R=0.659853,G=0.862215,B=1.000000,A=1.000000)
CloudColor=(R=0.855778,G=0.919005,B=1.000000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=5.505
SkyLightColor=(R=0.179300,G=0.188248,B=0.220000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=40
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[CloudyNoon]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=0
SunDirectionalLightIntensity=1.835
SunDirectionalLightColor=(R=1.000000,G=0.862295,B=0.475000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.143627,G=0.159235,B=0.190000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=36
SkyLightColor=(R=0.166985,G=0.176777,B=0.240000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetNoon]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=3.67
SunDirectionalLightIntensity=20.184
SunDirectionalLightColor=(R=1.000000,G=0.862295,B=0.475000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=17.431
HorizontFalloff=5.752
ZenithColor=(R=0.000000,G=0.085618,B=0.715000,A=1.000000)
HorizonColor=(R=0.532350,G=0.590445,B=0.630000,A=1.000000)
CloudColor=(R=0.143627,G=0.159235,B=0.190000,A=1.000000)
OverallSkyColor=(R=0.660000,G=0.630413,B=0.518100,A=1.000000)
SkyLightIntensity=14.679
SkyLightColor=(R=0.135000,G=0.120150,B=0.075600,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=54.128
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetCloudyNoon]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=0
SunDirectionalLightIntensity=1.835
SunDirectionalLightColor=(R=1.000000,G=0.862295,B=0.475000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
HorizonColor=(R=0.000000,G=0.000000,B=0.000000,A=1.000000)
CloudColor=(R=0.230559,G=0.255614,B=0.305000,A=1.000000)
OverallSkyColor=(R=0.660000,G=0.630413,B=0.518100,A=1.000000)
SkyLightIntensity=60
SkyLightColor=(R=0.230000,G=0.204700,B=0.128800,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=47.706
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[MidRainyNoon]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=0
SunDirectionalLightIntensity=1.33
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=14.761
HorizontFalloff=3
ZenithColor=(R=0.370000,G=0.370000,B=0.370000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.042789,G=0.045950,B=0.050000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=70
SkyLightColor=(R=0.119882,G=0.121557,B=0.170000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=40
PrecipitationAccumulation=50
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[HardRainNoon]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=0
SunDirectionalLightIntensity=1.33
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=0.580000,G=0.580000,B=0.580000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.089857,G=0.096495,B=0.105000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=37.66
SkyLightColor=(R=0.190125,G=0.191290,B=0.225000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=70.826
PrecipitationAccumulation=87.248
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[SoftRainNoon]
SunPolarAngle=44.586
SunAzimuthAngle=-179
SunBrightness=0
SunDirectionalLightIntensity=1.33
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.440725,G=0.473285,B=0.515000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=3
SkyLightColor=(R=0.525365,G=0.532706,B=0.745000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=10.55
PrecipitationAccumulation=61.927
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[ClearSunset]
SunPolarAngle=86
SunAzimuthAngle=-179
SunBrightness=1.835
SunDirectionalLightIntensity=50
SunDirectionalLightColor=(R=0.810000,G=0.347470,B=0.170100,A=1.000000)
SunIndirectLightIntensity=73.394
CloudOpacity=13.344
HorizontFalloff=0.917
ZenithColor=(R=0.046375,G=0.044100,B=0.105000,A=1.000000)
HorizonColor=(R=0.745000,G=0.219006,B=0.046649,A=1.000000)
CloudColor=(R=1.000000,G=0.561587,B=0.189305,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=14
SkyLightColor=(R=0.181188,G=0.177630,B=0.260000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[CloudySunset]
SunPolarAngle=86
SunAzimuthAngle=-179
SunBrightness=67.89
SunDirectionalLightIntensity=6.422
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=35.78
HorizontFalloff=1.835
ZenithColor=(R=0.192397,G=0.130043,B=0.245000,A=1.000000)
HorizonColor=(R=1.000000,G=0.007579,B=0.000000,A=1.000000)
CloudColor=(R=1.000000,G=0.518982,B=0.175000,A=1.000000)
OverallSkyColor=(R=0.288600,G=0.306730,B=0.370000,A=1.000000)
SkyLightIntensity=46.331
SkyLightColor=(R=0.193050,G=0.195113,B=0.270000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetSunset]
SunPolarAngle=86
SunAzimuthAngle=-179
SunBrightness=0
SunDirectionalLightIntensity=25.688
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=17.596
HorizontFalloff=1.165
ZenithColor=(R=0.046375,G=0.044100,B=0.105000,A=1.000000)
HorizonColor=(R=0.695000,G=0.379445,B=0.150922,A=1.000000)
CloudColor=(R=1.000000,G=0.561587,B=0.189305,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=82.568
SkyLightColor=(R=0.269874,G=0.264000,B=0.400000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=65.046
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetCloudySunset]
SunPolarAngle=86
SunAzimuthAngle=-179
SunBrightness=67.89
SunDirectionalLightIntensity=25.688
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=31.514
HorizontFalloff=1.165
ZenithColor=(R=0.046375,G=0.044100,B=0.105000,A=1.000000)
HorizonColor=(R=0.695000,G=0.379445,B=0.150922,A=1.000000)
CloudColor=(R=1.000000,G=0.561587,B=0.189305,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=50
SkyLightColor=(R=0.083625,G=0.081983,B=0.120000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=50
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
bWind=False
WindIntensity=20
WindAngle=0
[MidRainSunset]
SunPolarAngle=86
SunAzimuthAngle=-179
SunBrightness=13.761
SunDirectionalLightIntensity=12.587
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=44.037
HorizontFalloff=1.835
ZenithColor=(R=0.154038,G=0.101968,B=0.295000,A=1.000000)
HorizonColor=(R=1.000000,G=0.655600,B=0.160000,A=1.000000)
CloudColor=(R=0.555000,G=0.314891,B=0.111000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=40
SkyLightColor=(R=0.203500,G=0.211373,B=0.275000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=37.156
PrecipitationAccumulation=88.073
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[HardRainSunset]
SunPolarAngle=86
SunAzimuthAngle=-179
SunBrightness=13.761
SunDirectionalLightIntensity=12.587
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=44.037
HorizontFalloff=1.835
ZenithColor=(R=0.360000,G=0.000000,B=0.025421,A=1.000000)
HorizonColor=(R=1.000000,G=0.590000,B=0.000000,A=1.000000)
CloudColor=(R=0.555000,G=0.290880,B=0.066600,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=40
SkyLightColor=(R=0.255300,G=0.265177,B=0.345000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=84.862
PrecipitationAccumulation=100
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[SoftRainSunset]
SunPolarAngle=86
SunAzimuthAngle=-179
SunBrightness=13.761
SunDirectionalLightIntensity=12.587
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=24.771
HorizontFalloff=1.835
ZenithColor=(R=1.000000,G=0.627121,B=0.480000,A=1.000000)
HorizonColor=(R=0.980000,G=0.807226,B=0.558600,A=1.000000)
CloudColor=(R=1.000000,G=0.561963,B=0.190000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=14.679
SkyLightColor=(R=0.255300,G=0.265177,B=0.345000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=30
PrecipitationAccumulation=53.211
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5

View File

@ -1,418 +0,0 @@
[Default]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=50
SunDirectionalLightIntensity=15.092
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=16.296
HorizontFalloff=3
ZenithColor=(R=0.034046,G=0.109247,B=0.295000,A=1.000000)
HorizonColor=(R=0.659853,G=0.862215,B=1.000000,A=1.000000)
CloudColor=(R=0.855778,G=0.919005,B=1.000000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=5.505
SkyLightColor=(R=0.149650,G=0.161819,B=0.205000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[ClearNoon]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=50
SunDirectionalLightIntensity=34.286
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=16.296
HorizontFalloff=3
ZenithColor=(R=0.034046,G=0.109247,B=0.295000,A=1.000000)
HorizonColor=(R=0.659853,G=0.862215,B=1.000000,A=1.000000)
CloudColor=(R=0.855778,G=0.919005,B=1.000000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=10
SkyLightColor=(R=0.195000,G=0.193979,B=0.152151,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[CloudyNoon]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=0
SunDirectionalLightIntensity=1.835
SunDirectionalLightColor=(R=1.000000,G=0.862295,B=0.475000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.143627,G=0.159235,B=0.190000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=16.514
SkyLightColor=(R=0.100887,G=0.106803,B=0.145000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetNoon]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=3.67
SunDirectionalLightIntensity=20.184
SunDirectionalLightColor=(R=1.000000,G=0.862295,B=0.475000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=17.431
HorizontFalloff=5.752
ZenithColor=(R=0.000000,G=0.085618,B=0.715000,A=1.000000)
HorizonColor=(R=0.532350,G=0.590445,B=0.630000,A=1.000000)
CloudColor=(R=0.143627,G=0.159235,B=0.190000,A=1.000000)
OverallSkyColor=(R=0.660000,G=0.630413,B=0.518100,A=1.000000)
SkyLightIntensity=14.679
SkyLightColor=(R=0.135000,G=0.120150,B=0.075600,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=54.128
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetCloudyNoon]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=0
SunDirectionalLightIntensity=1.835
SunDirectionalLightColor=(R=1.000000,G=0.862295,B=0.475000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
HorizonColor=(R=0.000000,G=0.000000,B=0.000000,A=1.000000)
CloudColor=(R=0.230559,G=0.255614,B=0.305000,A=1.000000)
OverallSkyColor=(R=0.660000,G=0.630413,B=0.518100,A=1.000000)
SkyLightIntensity=25.688
SkyLightColor=(R=0.135000,G=0.120150,B=0.075600,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=47.706
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[MidRainyNoon]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=0
SunDirectionalLightIntensity=1.33
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=0.370000,G=0.370000,B=0.370000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.042789,G=0.045950,B=0.050000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=21.147
SkyLightColor=(R=0.119882,G=0.121557,B=0.170000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=40
PrecipitationAccumulation=50
bWind=False
WindIntensity=40
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[HardRainNoon]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=0
SunDirectionalLightIntensity=1.33
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=0.580000,G=0.580000,B=0.580000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.089857,G=0.096495,B=0.105000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=37.66
SkyLightColor=(R=0.126934,G=0.128707,B=0.180000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=80
PrecipitationAccumulation=87.248
bWind=False
WindIntensity=40
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[SoftRainNoon]
SunPolarAngle=44.586
SunAzimuthAngle=174
SunBrightness=0
SunDirectionalLightIntensity=1.33
SunDirectionalLightColor=(R=255.000000,G=239.000000,B=194.000000,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=18.431
HorizontFalloff=3
ZenithColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
HorizonColor=(R=0.169000,G=0.187443,B=0.200000,A=1.000000)
CloudColor=(R=0.440725,G=0.473285,B=0.515000,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=3
SkyLightColor=(R=0.525365,G=0.532706,B=0.745000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=10.55
PrecipitationAccumulation=61.927
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[ClearSunset]
SunPolarAngle=86
SunAzimuthAngle=174
SunBrightness=1.835
SunDirectionalLightIntensity=50
SunDirectionalLightColor=(R=0.810000,G=0.347470,B=0.170100,A=1.000000)
SunIndirectLightIntensity=73.394
CloudOpacity=27.63
HorizontFalloff=0.917
ZenithColor=(R=0.046375,G=0.044100,B=0.105000,A=1.000000)
HorizonColor=(R=0.745000,G=0.219006,B=0.046649,A=1.000000)
CloudColor=(R=1.000000,G=0.561587,B=0.189305,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=14
SkyLightColor=(R=0.076220,G=0.074724,B=0.109375,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[CloudySunset]
SunPolarAngle=86
SunAzimuthAngle=174
SunBrightness=67.89
SunDirectionalLightIntensity=6.422
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=28.869
HorizontFalloff=1.165
ZenithColor=(R=0.046375,G=0.044100,B=0.105000,A=1.000000)
HorizonColor=(R=1.000000,G=0.007579,B=0.000000,A=1.000000)
CloudColor=(R=1.000000,G=0.518982,B=0.175000,A=1.000000)
OverallSkyColor=(R=0.410000,G=0.410000,B=0.410000,A=1.000000)
SkyLightIntensity=36.239
SkyLightColor=(R=0.193050,G=0.195113,B=0.270000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetSunset]
SunPolarAngle=86
SunAzimuthAngle=174
SunBrightness=0
SunDirectionalLightIntensity=25.688
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=17.596
HorizontFalloff=1.165
ZenithColor=(R=0.046375,G=0.044100,B=0.105000,A=1.000000)
HorizonColor=(R=0.695000,G=0.379445,B=0.150922,A=1.000000)
CloudColor=(R=1.000000,G=0.561587,B=0.189305,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=66.972
SkyLightColor=(R=0.113887,G=0.110000,B=0.200000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=65.046
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[WetCloudySunset]
SunPolarAngle=86
SunAzimuthAngle=174
SunBrightness=67.89
SunDirectionalLightIntensity=25.688
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=15
HorizontFalloff=1.165
ZenithColor=(R=0.046375,G=0.044100,B=0.105000,A=1.000000)
HorizonColor=(R=0.695000,G=0.379445,B=0.150922,A=1.000000)
CloudColor=(R=1.000000,G=0.561587,B=0.189305,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=50
SkyLightColor=(R=0.083625,G=0.081983,B=0.120000,A=0.000000)
bPrecipitation=False
PrecipitationType=Rain
PrecipitationAmount=0
PrecipitationAccumulation=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[MidRainSunset]
SunPolarAngle=86
SunAzimuthAngle=174
SunBrightness=12.381
SunDirectionalLightIntensity=5.714
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=17.143
HorizontFalloff=1.835
ZenithColor=(R=0.317708,G=0.208096,B=0.260868,A=1.000000)
HorizonColor=(R=1.000000,G=0.590000,B=0.000000,A=1.000000)
CloudColor=(R=0.555000,G=0.290880,B=0.066600,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=6.667
SkyLightColor=(R=0.214844,G=0.273773,B=0.750000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=37.156
PrecipitationAccumulation=88.073
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[HardRainSunset]
SunPolarAngle=86
SunAzimuthAngle=174
SunBrightness=0.952
SunDirectionalLightIntensity=3.063
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=17.37
HorizontFalloff=1.835
ZenithColor=(R=0.307292,G=0.161669,B=0.123237,A=1.000000)
HorizonColor=(R=0.453125,G=0.297809,B=0.228923,A=1.000000)
CloudColor=(R=0.416667,G=0.288257,B=0.189558,A=1.000000)
OverallSkyColor=(R=1.000000,G=0.736403,B=0.487039,A=1.000000)
SkyLightIntensity=5.81
SkyLightColor=(R=0.500000,G=0.383356,B=0.250000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=84.862
PrecipitationAccumulation=100
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5
[SoftRainSunset]
SunPolarAngle=86
SunAzimuthAngle=174
SunBrightness=13.761
SunDirectionalLightIntensity=12.587
SunDirectionalLightColor=(R=0.810000,G=0.347162,B=0.083003,A=1.000000)
SunIndirectLightIntensity=6
CloudOpacity=34.513
HorizontFalloff=1.835
ZenithColor=(R=0.360000,G=0.125625,B=0.142175,A=1.000000)
HorizonColor=(R=1.000000,G=0.590000,B=0.000000,A=1.000000)
CloudColor=(R=0.296875,G=0.169776,B=0.061849,A=1.000000)
OverallSkyColor=(R=1.000000,G=1.000000,B=1.000000,A=1.000000)
SkyLightIntensity=7.339
SkyLightColor=(R=0.458070,G=0.394209,B=0.750000,A=0.000000)
bPrecipitation=True
PrecipitationType=Rain
PrecipitationAmount=8.716
PrecipitationAccumulation=53.211
bWind=False
WindIntensity=20
WindAngle=0
bOverrideCameraPostProcessParameters=True
CameraPostProcessParameters.AutoExposureMethod=Histogram
CameraPostProcessParameters.AutoExposureMinBrightness=0.27
CameraPostProcessParameters.AutoExposureMaxBrightness=5
CameraPostProcessParameters.AutoExposureBias=-3.5

View File

@ -1,92 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Carla.h"
#include "AgentComponent.h"
#include "Engine/World.h"
#include "Game/CarlaGameModeBase.h"
#include "Game/DataRouter.h"
#include "Engine/Engine.h"
#include "Kismet/GameplayStatics.h"
static FDataRouter *GetDataRouter(UWorld *World)
{
check(World != nullptr);
ACarlaGameModeBase *GameMode = Cast<ACarlaGameModeBase>(World->GetAuthGameMode());
return GameMode != nullptr ? &GameMode->GetDataRouter() : nullptr;
}
UAgentComponent::UAgentComponent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bVisible = false;
bHiddenInGame = true;
SetShouldUpdatePhysicsVolume(false);
PrimaryComponentTick.bCanEverTick = false;
}
void UAgentComponent::AcceptVisitor(IAgentComponentVisitor &Visitor) const
{
unimplemented();
}
void UAgentComponent::BeginPlay()
{
Super::BeginPlay();
if (bRegisterAgentComponent)
{
/**
* This only returns true if the current game mode is not null
* because you can only access a game mode if you are the host
* @param oftheworld UWorld is needed to access the game mode
* @return true if there is a game mode and it is not null
*/
if(UGameplayStatics::GetGameMode(GetWorld())!=nullptr)
{
auto *DataRouter = GetDataRouter(GetWorld());
if (DataRouter != nullptr)
{
DataRouter->RegisterAgent(this);
}
} else
{
UCarlaGameInstance* GameInstance = Cast<UCarlaGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
if(GameInstance) GameInstance->GetDataRouter().RegisterAgent(this);
}
bAgentComponentIsRegistered = true;
}
}
void UAgentComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
if (bAgentComponentIsRegistered)
{
FDataRouter *DataRouter = nullptr;
if(UGameplayStatics::GetGameMode(GetWorld())!=nullptr)
{
DataRouter = GetDataRouter(GetWorld());
}
else
{
UCarlaGameInstance *GameInstance = Cast<UCarlaGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
if(GameInstance)
{
DataRouter = &GameInstance->GetDataRouter();
}
}
if (DataRouter != nullptr)
{
DataRouter->DeregisterAgent(this);
}
bAgentComponentIsRegistered = false;
}
Super::EndPlay(EndPlayReason);
}

View File

@ -1,51 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Agent/AgentComponentVisitor.h"
#include "Components/SceneComponent.h"
#include "Templates/SharedPointer.h"
#include "AgentComponent.generated.h"
/// Actors with an UAgentComponent are registered as agents in the scene and
/// their status is sent to the client each frame (if requested by the client).
UCLASS(Abstract)
class CARLA_API UAgentComponent : public USceneComponent
{
GENERATED_BODY()
public:
UAgentComponent(const FObjectInitializer& ObjectInitializer);
uint32 GetId() const
{
return GetTypeHash(this);
}
virtual void AcceptVisitor(IAgentComponentVisitor &Visitor) const;
protected:
virtual void BeginPlay() override;
virtual void EndPlay(EEndPlayReason::Type EndPlayReason) override;
protected:
/** If true, this component will be registered at BeginPlay. */
UPROPERTY(Category = "Agent Component", EditAnywhere)
bool bRegisterAgentComponent = true;
private:
/** Whether this component has been registered. */
UPROPERTY(Category = "Agent Component", VisibleAnywhere, AdvancedDisplay)
bool bAgentComponentIsRegistered = false;
};

View File

@ -1,23 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
class UAgentComponent;
class UTrafficSignAgentComponent;
class UVehicleAgentComponent;
class UWalkerAgentComponent;
class IAgentComponentVisitor
{
public:
virtual void Visit(const UTrafficSignAgentComponent &) = 0;
virtual void Visit(const UVehicleAgentComponent &) = 0;
virtual void Visit(const UWalkerAgentComponent &) = 0;
};

View File

@ -1,23 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Carla.h"
#include "TrafficSignAgentComponent.h"
#include "Traffic/TrafficSignBase.h"
UTrafficSignAgentComponent::UTrafficSignAgentComponent(const FObjectInitializer &ObjectInitializer)
: Super(ObjectInitializer) {}
void UTrafficSignAgentComponent::BeginPlay()
{
TrafficSign = Cast<ATrafficSignBase>(GetOwner());
checkf(TrafficSign != nullptr, TEXT("UTrafficSignAgentComponent can only be attached to ATrafficSignBase"));
Super::BeginPlay();
}

View File

@ -1,43 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Agent/AgentComponent.h"
#include "TrafficSignAgentComponent.generated.h"
class ATrafficSignBase;
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class CARLA_API UTrafficSignAgentComponent : public UAgentComponent
{
GENERATED_BODY()
public:
UTrafficSignAgentComponent(const FObjectInitializer &ObjectInitializer);
const ATrafficSignBase &GetTrafficSign() const
{
check(TrafficSign != nullptr);
return *TrafficSign;
}
protected:
virtual void BeginPlay() override;
virtual void AcceptVisitor(IAgentComponentVisitor &Visitor) const final
{
Visitor.Visit(*this);
}
private:
UPROPERTY()
ATrafficSignBase *TrafficSign = nullptr;
};

View File

@ -1,30 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Carla.h"
#include "VehicleAgentComponent.h"
static bool IsPlayer(const ACarlaWheeledVehicle &InVehicle)
{
auto *Controller = Cast<AWheeledVehicleAIController>(InVehicle.GetController());
return (Controller != nullptr) && Controller->IsPossessingThePlayer();
}
UVehicleAgentComponent::UVehicleAgentComponent(const FObjectInitializer &ObjectInitializer)
: Super(ObjectInitializer) {}
void UVehicleAgentComponent::BeginPlay()
{
Vehicle = Cast<ACarlaWheeledVehicle>(GetOwner());
checkf(Vehicle != nullptr, TEXT("UVehicleAgentComponent can only be attached to ACarlaWheeledVehicle"));
// We only want to register non-player agents.
bRegisterAgentComponent = !IsPlayer(*Vehicle);
Super::BeginPlay();
}

View File

@ -1,58 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Agent/AgentComponent.h"
#include "Vehicle/CarlaWheeledVehicle.h"
#include "VehicleAgentComponent.generated.h"
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class CARLA_API UVehicleAgentComponent : public UAgentComponent
{
GENERATED_BODY()
public:
UVehicleAgentComponent(const FObjectInitializer &ObjectInitializer);
/// Return forward speed in cm/s.
float GetForwardSpeed() const
{
return Vehicle->GetVehicleForwardSpeed();
}
FTransform GetTransform() const
{
return Vehicle->GetVehicleTransform();
}
FTransform GetBoundingBoxTransform() const
{
return Vehicle->GetVehicleBoundingBoxTransform();
}
FVector GetBoundingBoxExtent() const
{
return Vehicle->GetVehicleBoundingBoxExtent();
}
protected:
virtual void BeginPlay() override;
virtual void AcceptVisitor(IAgentComponentVisitor &Visitor) const final
{
Visitor.Visit(*this);
}
private:
UPROPERTY()
ACarlaWheeledVehicle *Vehicle = nullptr;
};

View File

@ -1,21 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Carla.h"
#include "WalkerAgentComponent.h"
UWalkerAgentComponent::UWalkerAgentComponent(const FObjectInitializer &ObjectInitializer)
: Super(ObjectInitializer) {}
void UWalkerAgentComponent::BeginPlay()
{
Walker = Cast<ACharacter>(GetOwner());
checkf(Walker != nullptr, TEXT("UWalkerAgentComponent can only be attached to ACharacter"));
Super::BeginPlay();
}

View File

@ -1,61 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Agent/AgentComponent.h"
#include "GameFramework/Character.h"
#include "WalkerAgentComponent.generated.h"
/// This component can be added to any ACharacter to be added as agent.
/// See UAgentComponent.
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class CARLA_API UWalkerAgentComponent : public UAgentComponent
{
GENERATED_BODY()
public:
UWalkerAgentComponent(const FObjectInitializer &ObjectInitializer);
/// Return forward speed in cm/s.
float GetForwardSpeed() const
{
return FVector::DotProduct(Walker->GetVelocity(), Walker->GetActorRotation().Vector());
}
FTransform GetTransform() const
{
return Walker->GetActorTransform();
}
FTransform GetBoundingBoxTransform() const
{
return FTransform();
}
FVector GetBoundingBoxExtent() const
{
/// @todo Perhaps the box it is not the same for every walker...
return {45.0f, 35.0f, 100.0f};
}
protected:
virtual void BeginPlay() override;
virtual void AcceptVisitor(IAgentComponentVisitor &Visitor) const final
{
Visitor.Visit(*this);
}
private:
UPROPERTY()
ACharacter *Walker = nullptr;
};

View File

@ -1,217 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "DynamicWeather.h"
#include "Util/IniFile.h"
#include "Components/ArrowComponent.h"
static FString GetIniFileName(const FString &MapName = TEXT(""))
{
const FString BaseName = TEXT("CarlaWeather");
constexpr auto Sep = TEXT(".");
constexpr auto Ext = TEXT(".ini");
return (MapName.IsEmpty() ? (BaseName + Ext) : (BaseName + Sep + MapName + Ext));
}
static bool GetWeatherIniFilePath(const FString &FileName, FString &FilePath)
{
FilePath = FPaths::Combine(FPaths::ProjectConfigDir(), FileName);
const bool bFileExists = FPaths::FileExists(FilePath);
if (!bFileExists) {
UE_LOG(LogCarla, Warning, TEXT("\"%s\" not found"), *FilePath);
}
return bFileExists;
}
static bool CheckWeatherValidity(const FWeatherDescription &Weather)
{
if (Weather.Name.IsEmpty()) {
UE_LOG(LogCarla, Error, TEXT("Weather doesn't have a name, please provide one"));
return false;
}
return true;
}
void ADynamicWeather::LoadWeatherDescriptionsFromFile(
const FString &MapName,
TArray<FWeatherDescription> &Descriptions)
{
// Try to load config file.
FString DefaultFilePath;
if (GetWeatherIniFilePath(GetIniFileName(), DefaultFilePath)) {
UE_LOG(LogCarla, Log, TEXT("Loading weather description from %s"), *DefaultFilePath);
FIniFile ConfigFile(DefaultFilePath);
{ // Override map specific presets.
FString MapOverridesFilePath;
if (GetWeatherIniFilePath(GetIniFileName(MapName), MapOverridesFilePath)) {
UE_LOG(LogCarla, Log, TEXT("Loading weather description from %s"), *MapOverridesFilePath);
ConfigFile.Combine(MapOverridesFilePath);
}
}
// For every section in the config file add a weather description.
for (auto &Item : ConfigFile.GetFConfigFile()) {
Descriptions.AddDefaulted(1u);
Descriptions.Last().ReadFromConfigFile(ConfigFile, Item.Key);
}
}
// If no description was found, append a defaulted one.
if (Descriptions.Num() == 0) {
UE_LOG(LogCarla, Warning, TEXT("No weather description found"));
Descriptions.AddDefaulted(1u);
Descriptions.Last().Name = TEXT("Default");
}
}
ADynamicWeather::ADynamicWeather(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
#if WITH_EDITORONLY_DATA
, FileName(GetIniFileName())
#endif // WITH_EDITORONLY_DATA
{
PrimaryActorTick.bCanEverTick = false;
RootComponent = ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComponent0"));
#if WITH_EDITORONLY_DATA
ArrowComponent = CreateEditorOnlyDefaultSubobject<UArrowComponent>(TEXT("ArrowComponent0"));
if (ArrowComponent) {
ArrowComponent->ArrowColor = FColor(150, 200, 255);
ArrowComponent->bTreatAsASprite = true;
ArrowComponent->SpriteInfo.Category = TEXT("Lighting");
ArrowComponent->SpriteInfo.DisplayName = NSLOCTEXT( "SpriteCategory", "Lighting", "Lighting" );
ArrowComponent->SetupAttachment(RootComponent);
ArrowComponent->bLightAttachment = true;
ArrowComponent->bIsScreenSizeScaled = true;
}
#endif // WITH_EDITORONLY_DATA
}
void ADynamicWeather::OnConstruction(const FTransform &Transform)
{
Super::OnConstruction(Transform);
#if WITH_EDITOR
Update();
#endif // WITH_EDITOR
}
void ADynamicWeather::BeginPlay()
{
Super::BeginPlay();
#if WITH_EDITOR
Update();
#endif // WITH_EDITOR
}
#if WITH_EDITOR
void ADynamicWeather::PostEditChangeProperty(FPropertyChangedEvent &Event)
{
Super::PostEditChangeProperty(Event);
const FName PropertyName = (Event.Property != NULL ? Event.Property->GetFName() : NAME_None);
if (PropertyName == GET_MEMBER_NAME_CHECKED(ADynamicWeather, Weather)) {
Update();
} else if ((PropertyName == GET_MEMBER_NAME_CHECKED(ADynamicWeather, bSaveToConfigFile)) ||
(PropertyName == GET_MEMBER_NAME_CHECKED(ADynamicWeather, bLoadFromConfigFile))) {
// Do nothing.
} else {
AdjustSunPositionBasedOnActorRotation();
}
if (bSaveToConfigFile) {
bSaveToConfigFile = false;
if (SaveToConfigFile()) {
UE_LOG(LogCarla, Log, TEXT("Weather \"%s\" saved to config file"), *Weather.Name);
} else {
UE_LOG(LogCarla, Error, TEXT("Error saving weather to config file"));
}
}
if (bLoadFromConfigFile) {
bLoadFromConfigFile = false;
if (LoadFromConfigFile()) {
UE_LOG(LogCarla, Log, TEXT("Weather \"%s\" loaded from config file"), *Weather.Name);
Update();
} else {
UE_LOG(LogCarla, Error, TEXT("Error loading weather from config file"));
}
}
}
void ADynamicWeather::EditorApplyRotation(
const FRotator &DeltaRotation,
bool bAltDown,
bool bShiftDown,
bool bCtrlDown)
{
Super::EditorApplyRotation(DeltaRotation, bAltDown, bShiftDown, bCtrlDown);
AdjustSunPositionBasedOnActorRotation();
}
#endif // WITH_EDITOR
FVector ADynamicWeather::GetSunDirection() const
{
const FVector2D SphericalCoords(
FMath::DegreesToRadians(Weather.SunPolarAngle),
FMath::DegreesToRadians(Weather.SunAzimuthAngle));
return - SphericalCoords.SphericalToUnitCartesian();
}
void ADynamicWeather::AdjustSunPositionBasedOnActorRotation()
{
const FVector Direction = - GetActorQuat().GetForwardVector();
const FVector2D SphericalCoords = Direction.UnitCartesianToSpherical();
Weather.SunPolarAngle = FMath::RadiansToDegrees(SphericalCoords.X);
Weather.SunAzimuthAngle = FMath::RadiansToDegrees(SphericalCoords.Y);
}
#if WITH_EDITOR
void ADynamicWeather::Update()
{
// Modify this actor's rotation according to Sun position.
if (!SetActorRotation(FQuat(GetSunDirection().Rotation()), ETeleportType::None)) {
UE_LOG(LogCarla, Warning, TEXT("Unable to rotate actor"));
}
if (bRefreshAutomatically) {
RefreshWeather();
}
}
bool ADynamicWeather::LoadFromConfigFile()
{
FString FilePath;
if (GetWeatherIniFilePath(FileName, FilePath) && CheckWeatherValidity(Weather)) {
FIniFile ConfigFile(FilePath);
if (!ConfigFile.HasSection(Weather.Name)) {
UE_LOG(LogCarla, Error, TEXT("Weather \"%s\" is not present in config file"), *Weather.Name);
return false;
}
Weather.ReadFromConfigFile(ConfigFile, Weather.Name);
return true;
} else {
return false;
}
}
bool ADynamicWeather::SaveToConfigFile() const
{
FString FilePath;
if (GetWeatherIniFilePath(FileName, FilePath) && CheckWeatherValidity(Weather)) {
FIniFile ConfigFile(FilePath);
Weather.WriteToConfigFile(ConfigFile);
return ConfigFile.Write(FilePath);
} else {
return false;
}
}
#endif // WITH_EDITOR

View File

@ -1,116 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "GameFramework/Actor.h"
#include "Settings/WeatherDescription.h"
#include "DynamicWeather.generated.h"
class UArrowComponent;
UCLASS(Abstract)
class CARLA_API ADynamicWeather : public AActor
{
GENERATED_BODY()
public:
/// Load weather descriptions from config file.
///
/// Settings are loaded in order from the following file list, with values
/// later in the list overriding earlier values
///
/// * Config/CarlaWeather.ini
/// * Config/<MapName>.CarlaWeather.ini
///
/// If no description is found, the default one is added.
static void LoadWeatherDescriptionsFromFile(
const FString &MapName,
TArray<FWeatherDescription> &Descriptions);
ADynamicWeather(const FObjectInitializer& ObjectInitializer);
virtual void OnConstruction(const FTransform &Transform) override;
virtual void BeginPlay() override;
#if WITH_EDITOR
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
virtual void EditorApplyRotation(const FRotator & DeltaRotation, bool bAltDown, bool bShiftDown, bool bCtrlDown) override;
#endif // WITH_EDITOR
void SetWeatherDescription(const FWeatherDescription &WeatherDescription)
{
Weather = WeatherDescription;
}
UFUNCTION(BlueprintCallable)
const FWeatherDescription &GetWeatherDescription() const
{
return Weather;
}
UFUNCTION(BlueprintCallable)
void ActivateWeatherDescription(const FWeatherDescription &WeatherDescription)
{
SetWeatherDescription(WeatherDescription);
RefreshWeather();
}
UFUNCTION(BlueprintImplementableEvent)
void RefreshWeather();
UFUNCTION(BlueprintCallable)
FVector GetSunDirection() const;
private:
void AdjustSunPositionBasedOnActorRotation();
#if WITH_EDITOR
void Update();
bool LoadFromConfigFile();
bool SaveToConfigFile() const;
#endif // WITH_EDITOR
#if WITH_EDITORONLY_DATA
UPROPERTY()
UArrowComponent *ArrowComponent;
/** If true, the weather is refreshed on construction and at begin play.
* Useful for editing the weather (Editor only).
*/
UPROPERTY(Category = "Weather Description", EditAnywhere)
bool bRefreshAutomatically = false;
/** Load the section with the currently set name. */
UPROPERTY(Category = "Weather Description", EditAnywhere)
bool bLoadFromConfigFile = false;
/** Save current settings to disk. */
UPROPERTY(Category = "Weather Description", EditAnywhere)
bool bSaveToConfigFile = false;
/** Name of the file to load and save. File must exist in Config folder. */
UPROPERTY(Category = "Weather Description", EditAnywhere)
FString FileName;
#endif // WITH_EDITORONLY_DATA
UPROPERTY(Category = "Weather Description", EditAnywhere)
FWeatherDescription Weather;
};

View File

@ -33,8 +33,8 @@ void FCarlaEngine::NotifyInitGame(const UCarlaSettings &Settings)
{
if (!bIsRunning)
{
const auto StreamingPort = Settings.StreamingPort.Get(Settings.WorldPort + 1u);
auto BroadcastStream = Server.Start(Settings.WorldPort, StreamingPort);
const auto StreamingPort = Settings.StreamingPort.Get(Settings.RPCPort + 1u);
auto BroadcastStream = Server.Start(Settings.RPCPort, StreamingPort);
Server.AsyncRun(GetNumberOfThreadsForRPCServer());
WorldObserver.SetStream(BroadcastStream);

View File

@ -1,38 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Containers/Array.h"
class AController;
class APlayerStart;
class FDataRouter;
class UCarlaSettings;
/// Base class for a CARLA game controller.
class ICarlaGameControllerBase
{
public:
ICarlaGameControllerBase(FDataRouter &DataRouter) : DataRouter(DataRouter) {}
virtual ~ICarlaGameControllerBase() {}
virtual void Initialize(UCarlaSettings &CarlaSettings) = 0;
virtual APlayerStart *ChoosePlayerStart(const TArray<APlayerStart *> &AvailableStartSpots) = 0;
virtual void RegisterPlayer(AController &NewPlayer) = 0;
virtual void BeginPlay() = 0;
virtual void Tick(float DeltaSeconds) = 0;
protected:
FDataRouter &DataRouter;
};

View File

@ -5,11 +5,9 @@
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "CarlaGameInstance.h"
#include "Carla/Game/CarlaGameInstance.h"
#include "Game/MockGameController.h"
#include "Server/ServerGameController.h"
#include "Settings/CarlaSettings.h"
#include "Carla/Settings/CarlaSettings.h"
UCarlaGameInstance::UCarlaGameInstance() {
CarlaSettings = CreateDefaultSubobject<UCarlaSettings>(TEXT("CarlaSettings"));
@ -19,16 +17,3 @@ UCarlaGameInstance::UCarlaGameInstance() {
}
UCarlaGameInstance::~UCarlaGameInstance() = default;
void UCarlaGameInstance::InitializeGameControllerIfNotPresent(
const FMockGameControllerSettings &MockControllerSettings)
{
if (GameController == nullptr) {
if (CarlaSettings->bUseNetworking) {
GameController = MakeUnique<FServerGameController>(DataRouter);
} else {
GameController = MakeUnique<MockGameController>(DataRouter, MockControllerSettings);
UE_LOG(LogCarla, Log, TEXT("Using mock CARLA controller"));
}
}
}

View File

@ -9,14 +9,11 @@
#include "Engine/GameInstance.h"
#include "Carla/Game/CarlaEngine.h"
#include "Carla/Game/CarlaGameControllerBase.h"
#include "Carla/Game/DataRouter.h"
#include "Carla/Server/TheNewCarlaServer.h"
#include "CarlaGameInstance.generated.h"
class UCarlaSettings;
struct FMockGameControllerSettings;
/// The game instance contains elements that must be kept alive in between
/// levels. It is instantiate once per game.
@ -31,15 +28,6 @@ public:
~UCarlaGameInstance();
void InitializeGameControllerIfNotPresent(
const FMockGameControllerSettings &MockControllerSettings);
ICarlaGameControllerBase &GetGameController()
{
check(GameController != nullptr);
return *GameController;
}
UCarlaSettings &GetCarlaSettings()
{
check(CarlaSettings != nullptr);
@ -65,11 +53,6 @@ public:
return CarlaEngine.GetCurrentEpisode();
}
FDataRouter &GetDataRouter()
{
return DataRouter;
}
void NotifyInitGame()
{
CarlaEngine.NotifyInitGame(GetCarlaSettings());
@ -95,9 +78,5 @@ private:
UPROPERTY(Category = "CARLA Settings", EditAnywhere)
UCarlaSettings *CarlaSettings = nullptr;
FDataRouter DataRouter;
TUniquePtr<ICarlaGameControllerBase> GameController;
FCarlaEngine CarlaEngine;
};

View File

@ -1,336 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "Carla/Game/CarlaGameModeBase.h"
#include "Carla/Game/CarlaGameInstance.h"
#include "Carla/Game/CarlaHUD.h"
#include "Carla/Game/CarlaPlayerState.h"
#include "Carla/Game/Tagger.h"
#include "Carla/Game/TaggerDelegate.h"
#include "Carla/Settings/CarlaSettings.h"
#include "Carla/Settings/CarlaSettingsDelegate.h"
#include "Carla/Util/RandomEngine.h"
#include "Carla/Vehicle/CarlaVehicleController.h"
#include "ConstructorHelpers.h"
#include "Engine/PlayerStartPIE.h"
#include "EngineUtils.h"
#include "GameFramework/PlayerStart.h"
#include "SceneViewport.h"
ACarlaGameModeBase::ACarlaGameModeBase(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer),
GameController(nullptr),
PlayerController(nullptr)
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.TickGroup = TG_PrePhysics;
bAllowTickBeforeBeginPlay = false;
PlayerControllerClass = ACarlaVehicleController::StaticClass();
PlayerStateClass = ACarlaPlayerState::StaticClass();
HUDClass = ACarlaHUD::StaticClass();
TaggerDelegate = CreateDefaultSubobject<UTaggerDelegate>(TEXT("TaggerDelegate"));
CarlaSettingsDelegate = CreateDefaultSubobject<UCarlaSettingsDelegate>(TEXT("CarlaSettingsDelegate"));
}
void ACarlaGameModeBase::InitGame(
const FString &MapName,
const FString &Options,
FString &ErrorMessage)
{
Super::InitGame(MapName, Options, ErrorMessage);
GameInstance = Cast<UCarlaGameInstance>(GetGameInstance());
checkf(
GameInstance != nullptr,
TEXT("GameInstance is not a UCarlaGameInstance, did you forget to set it in the project settings?"));
GameInstance->InitializeGameControllerIfNotPresent(MockGameControllerSettings);
GameController = &GameInstance->GetGameController();
auto &CarlaSettings = GameInstance->GetCarlaSettings();
UWorld *world = GetWorld();
{ // Load weather descriptions and initialize game controller.
#if WITH_EDITOR
{
// Hack to be able to test level-specific weather descriptions in editor.
// When playing in editor the map name gets an extra prefix, here we
// remove it.
FString CorrectedMapName = MapName;
constexpr auto PIEPrefix = TEXT("UEDPIE_0_");
CorrectedMapName.RemoveFromStart(PIEPrefix);
UE_LOG(LogCarla, Log, TEXT("Corrected map name from %s to %s"), *MapName, *CorrectedMapName);
CarlaSettings.MapName = CorrectedMapName;
CarlaSettings.LoadWeatherDescriptions();
}
#else
CarlaSettings.MapName = MapName;
CarlaSettings.LoadWeatherDescriptions();
#endif // WITH_EDITOR
GameController->Initialize(CarlaSettings);
CarlaSettings.ValidateWeatherId();
CarlaSettings.LogSettings();
}
// Set default pawn class.
if (!CarlaSettings.PlayerVehicle.IsEmpty())
{
auto Class = FindObject<UClass>(ANY_PACKAGE, *CarlaSettings.PlayerVehicle);
if (Class)
{
DefaultPawnClass = Class;
}
else
{
UE_LOG(LogCarla, Error, TEXT("Failed to load player pawn class \"%s\""), *CarlaSettings.PlayerVehicle)
}
}
if (TaggerDelegate != nullptr)
{
TaggerDelegate->RegisterSpawnHandler(world);
}
else
{
UE_LOG(LogCarla, Error, TEXT("Missing TaggerDelegate!"));
}
if(CarlaSettingsDelegate!=nullptr)
{
//apply quality settings
CarlaSettingsDelegate->ApplyQualityLevelPostRestart();
//assign settings delegate for every new actor from now on
CarlaSettingsDelegate->RegisterSpawnHandler(world);
}
else
{
UE_LOG(LogCarla, Error, TEXT("Missing CarlaSettingsDelegate!"));
}
if (DynamicWeatherClass != nullptr)
{
DynamicWeather = world->SpawnActor<ADynamicWeather>(DynamicWeatherClass);
}
if (VehicleSpawnerClass != nullptr)
{
VehicleSpawner = world->SpawnActor<AVehicleSpawnerBase>(VehicleSpawnerClass);
}
if (WalkerSpawnerClass != nullptr)
{
WalkerSpawner = world->SpawnActor<AWalkerSpawnerBase>(WalkerSpawnerClass);
}
}
void ACarlaGameModeBase::RestartPlayer(AController* NewPlayer)
{
check(NewPlayer != nullptr);
TArray<APlayerStart *> UnOccupiedStartPoints;
APlayerStart *PlayFromHere = FindUnOccupiedStartPoints(NewPlayer, UnOccupiedStartPoints);
bool bStartSpotFound = false;
if (PlayFromHere != nullptr)
{
RestartPlayerAtPlayerStart(NewPlayer, PlayFromHere);
RegisterPlayer(*NewPlayer);
bStartSpotFound = true;
}
else if (UnOccupiedStartPoints.Num() > 0u)
{
check(GameController != nullptr);
APlayerStart *StartSpot = GameController->ChoosePlayerStart(UnOccupiedStartPoints);
if (StartSpot != nullptr)
{
RestartPlayerAtPlayerStart(NewPlayer, StartSpot);
RegisterPlayer(*NewPlayer);
bStartSpotFound = true;
}
}
if(!bStartSpotFound)
{
UE_LOG(LogCarla, Error, TEXT("No start spot found!"));
}
if(CarlaSettingsDelegate != nullptr)
{
CarlaSettingsDelegate->ApplyQualityLevelPreRestart();
}
}
void ACarlaGameModeBase::BeginPlay()
{
Super::BeginPlay();
const auto &CarlaSettings = GameInstance->GetCarlaSettings();
// Setup semantic segmentation if necessary.
if (CarlaSettings.bSemanticSegmentationEnabled)
{
TagActorsForSemanticSegmentation();
TaggerDelegate->SetSemanticSegmentationEnabled();
}
// Change weather.
if (DynamicWeather != nullptr)
{
const auto *Weather = CarlaSettings.GetActiveWeatherDescription();
if (Weather != nullptr)
{
UE_LOG(LogCarla, Log, TEXT("Changing weather settings to \"%s\""), *Weather->Name);
DynamicWeather->SetWeatherDescription(*Weather);
DynamicWeather->RefreshWeather();
}
}
else
{
UE_LOG(LogCarla, Error, TEXT("Missing dynamic weather actor!"));
}
// Find road map.
TActorIterator<ACityMapGenerator> It(GetWorld());
URoadMap *RoadMap = (It ? It->GetRoadMap() : nullptr);
if (PlayerController != nullptr)
{
PlayerController->SetRoadMap(RoadMap);
}
else
{
UE_LOG(LogCarla, Error, TEXT("Player controller is not a AWheeledVehicleAIController!"));
}
// Setup other vehicles.
if (VehicleSpawner != nullptr)
{
VehicleSpawner->SetNumberOfVehicles(CarlaSettings.NumberOfVehicles);
VehicleSpawner->SetSeed(CarlaSettings.SeedVehicles);
VehicleSpawner->SetRoadMap(RoadMap);
if (PlayerController != nullptr)
{
PlayerController->GetRandomEngine()->Seed(
VehicleSpawner->GetRandomEngine()->GenerateSeed());
}
}
else
{
UE_LOG(LogCarla, Error, TEXT("Missing vehicle spawner actor!"));
}
// Setup walkers.
if (WalkerSpawner != nullptr)
{
WalkerSpawner->SetNumberOfWalkers(CarlaSettings.NumberOfPedestrians);
WalkerSpawner->SetSeed(CarlaSettings.SeedPedestrians);
}
else
{
UE_LOG(LogCarla, Error, TEXT("Missing walker spawner actor!"));
}
GameController->BeginPlay();
}
void ACarlaGameModeBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
if (CarlaSettingsDelegate != nullptr && EndPlayReason!=EEndPlayReason::EndPlayInEditor)
{
CarlaSettingsDelegate->Reset();
}
}
void ACarlaGameModeBase::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
GameController->Tick(DeltaSeconds);
}
void ACarlaGameModeBase::RegisterPlayer(AController &NewPlayer)
{
check(GameController != nullptr);
AddTickPrerequisiteActor(&NewPlayer);
PlayerController = Cast<ACarlaVehicleController>(&NewPlayer);
if (PlayerController != nullptr)
{
GetDataRouter().RegisterPlayer(*PlayerController);
GameController->RegisterPlayer(*PlayerController);
AttachSensorsToPlayer();
}
else
{
UE_LOG(LogCarla, Error, TEXT("ACarlaGameModeBase: Player is not a ACarlaVehicleController"));
}
}
void ACarlaGameModeBase::AttachSensorsToPlayer()
{
check(PlayerController != nullptr);
UE_LOG(LogCarla, Error, TEXT("Sensors are no longer available in this game mode."));
// const auto &Settings = GameInstance->GetCarlaSettings();
// const auto *Weather = Settings.GetActiveWeatherDescription();
// for (auto &Item : Settings.SensorDescriptions)
// {
// check(Item.Value != nullptr);
// auto &SensorDescription = *Item.Value;
// if (Weather != nullptr)
// {
// SensorDescription.AdjustToWeather(*Weather);
// }
// auto *Sensor = FSensorFactory::Make(SensorDescription, *GetWorld());
// check(Sensor != nullptr);
// Sensor->AttachToActor(PlayerController->GetPawn());
// GetDataRouter().RegisterSensor(*Sensor);
// }
}
void ACarlaGameModeBase::TagActorsForSemanticSegmentation()
{
check(GetWorld() != nullptr);
ATagger::TagActorsInLevel(*GetWorld(), true);
}
APlayerStart *ACarlaGameModeBase::FindUnOccupiedStartPoints(
AController *Player,
TArray<APlayerStart *> &UnOccupiedStartPoints)
{
APlayerStart* FoundPlayerStart = nullptr;
UClass* PawnClass = GetDefaultPawnClassForController(Player);
APawn* PawnToFit = PawnClass ? PawnClass->GetDefaultObject<APawn>() : nullptr;
for (TActorIterator<APlayerStart> It(GetWorld()); It; ++It)
{
APlayerStart* PlayerStart = *It;
if (PlayerStart->IsA<APlayerStartPIE>())
{
FoundPlayerStart = PlayerStart;
break;
}
else
{
FVector ActorLocation = PlayerStart->GetActorLocation();
const FRotator ActorRotation = PlayerStart->GetActorRotation();
if (!GetWorld()->EncroachingBlockingGeometry(PawnToFit, ActorLocation, ActorRotation))
{
UnOccupiedStartPoints.Add(PlayerStart);
}
#if WITH_EDITOR
else if (GetWorld()->FindTeleportSpot(PawnToFit, ActorLocation, ActorRotation))
{
UE_LOG(
LogCarla,
Warning,
TEXT("Player start cannot be used, occupied location: %s"),
*PlayerStart->GetActorLocation().ToString());
}
#endif // WITH_EDITOR
}
}
return FoundPlayerStart;
}

View File

@ -1,113 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "GameFramework/GameModeBase.h"
#include "DynamicWeather.h"
#include "Game/CarlaGameControllerBase.h"
#include "Game/CarlaGameInstance.h"
#include "Game/MockGameControllerSettings.h"
#include "Vehicle/VehicleSpawnerBase.h"
#include "Walker/WalkerSpawnerBase.h"
#include "CarlaGameModeBase.generated.h"
class ACarlaVehicleController;
class APlayerStart;
class ASceneCaptureCamera;
class UCarlaGameInstance;
class UTaggerDelegate;
class UCarlaSettingsDelegate;
UCLASS(HideCategories=(ActorTick))
class CARLA_API ACarlaGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
ACarlaGameModeBase(const FObjectInitializer& ObjectInitializer);
virtual void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override;
virtual void RestartPlayer(AController *NewPlayer) override;
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
virtual void Tick(float DeltaSeconds) override;
FDataRouter &GetDataRouter()
{
check(GameInstance != nullptr);
return GameInstance->GetDataRouter();
}
UFUNCTION(BlueprintPure, Category="CARLA Settings")
UCarlaSettingsDelegate *GetCARLASettingsDelegate()
{
return CarlaSettingsDelegate;
}
protected:
/** Used only when networking is disabled. */
UPROPERTY(Category = "Mock CARLA Controller", EditAnywhere, BlueprintReadOnly, meta = (ExposeFunctionCategories = "Mock CARLA Controller"))
FMockGameControllerSettings MockGameControllerSettings;
/** The class of DynamicWeather to spawn. */
UPROPERTY(Category = "CARLA Classes", EditAnywhere, BlueprintReadOnly)
TSubclassOf<ADynamicWeather> DynamicWeatherClass;
/** The class of VehicleSpawner to spawn. */
UPROPERTY(Category = "CARLA Classes", EditAnywhere, BlueprintReadOnly)
TSubclassOf<AVehicleSpawnerBase> VehicleSpawnerClass;
/** The class of WalkerSpawner to spawn. */
UPROPERTY(Category = "CARLA Classes", EditAnywhere, BlueprintReadOnly)
TSubclassOf<AWalkerSpawnerBase> WalkerSpawnerClass;
private:
void RegisterPlayer(AController &NewPlayer);
void AttachSensorsToPlayer();
void TagActorsForSemanticSegmentation();
/// Iterate all the APlayerStart present in the world and add the ones with
/// unoccupied locations to @a UnOccupiedStartPoints.
///
/// @return APlayerStart if "Play from Here" was used while in PIE mode.
APlayerStart *FindUnOccupiedStartPoints(
AController *Player,
TArray<APlayerStart *> &UnOccupiedStartPoints);
ICarlaGameControllerBase *GameController;
UPROPERTY()
UCarlaGameInstance *GameInstance;
UPROPERTY()
ACarlaVehicleController *PlayerController;
UPROPERTY()
UTaggerDelegate *TaggerDelegate;
UPROPERTY()
UCarlaSettingsDelegate* CarlaSettingsDelegate;
UPROPERTY()
ADynamicWeather *DynamicWeather;
UPROPERTY()
AVehicleSpawnerBase *VehicleSpawner;
UPROPERTY()
AWalkerSpawnerBase *WalkerSpawner;
};

View File

@ -1,146 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "CarlaHUD.h"
#include "Vehicle/CarlaVehicleController.h"
#include "CommandLine.h"
#include "ConstructorHelpers.h"
#include "Engine/Canvas.h"
#include "Engine/Font.h"
#define LOCTEXT_NAMESPACE "CarlaHUD"
static bool GetDefaultHUDVisibility() {
return !FParse::Param(FCommandLine::Get(), TEXT("carla-no-hud"));
}
static FText RoundedFloatAsText(float Value)
{
return FText::AsNumber(FMath::RoundHalfFromZero(Value));
}
static FText GetVectorAsText(const FVector &Vector)
{
return FText::Format(
LOCTEXT("FVectorFormat", "({0}, {1}, {2})"),
RoundedFloatAsText(Vector.X),
RoundedFloatAsText(Vector.Y),
RoundedFloatAsText(Vector.Z));
}
static FText GetVectorAsText(const FVector &Vector, const FNumberFormattingOptions &FormatOpt)
{
return FText::Format(
LOCTEXT("FVectorFormat", "({0}, {1}, {2})"),
FText::AsNumber(Vector.X, &FormatOpt),
FText::AsNumber(Vector.Y, &FormatOpt),
FText::AsNumber(Vector.Z, &FormatOpt));
}
static FText GetGearAsText(int32 Gear)
{
if (Gear < 0) {
return FText(LOCTEXT("ReverseGear", "R"));
} else {
return (Gear == 0 ? LOCTEXT("NeutralGear", "N") : FText::AsNumber(Gear));
}
}
static FText GetTrafficLightAsText(ETrafficLightState State)
{
switch (State) {
case ETrafficLightState::Green: return FText(LOCTEXT("GreenTrafficLight", "Green"));
case ETrafficLightState::Yellow: return FText(LOCTEXT("YellowTrafficLight", "Yellow"));
case ETrafficLightState::Red: return FText(LOCTEXT("RedTrafficLight", "Red"));
default: return FText(LOCTEXT("InvalidTrafficLight", "INVALID"));
}
}
static FText GetHUDText(const ACarlaPlayerState &Vehicle)
{
// Set number precision.
FNumberFormattingOptions HighPrecision;
HighPrecision.MinimumFractionalDigits = 2u;
HighPrecision.MaximumFractionalDigits = 2u;
constexpr float TO_MILLISECONDS = 1e3;
constexpr float TO_METERS = 1e-2;
constexpr float TO_KMPH = 0.036f;
FFormatNamedArguments Args;
Args.Add("SimStep", RoundedFloatAsText(Vehicle.GetSimulationStepInSeconds() * TO_MILLISECONDS));
Args.Add("Location", GetVectorAsText(Vehicle.GetLocation() * TO_METERS));
Args.Add("Acceleration", GetVectorAsText(Vehicle.GetAcceleration() * TO_METERS, HighPrecision));
Args.Add("Orientation", GetVectorAsText(Vehicle.GetOrientation(), HighPrecision));
Args.Add("Speed", RoundedFloatAsText(Vehicle.GetForwardSpeed() * TO_KMPH));
Args.Add("Gear", GetGearAsText(Vehicle.GetCurrentGear()));
Args.Add("SpeedLimit", RoundedFloatAsText(Vehicle.GetSpeedLimit()));
Args.Add("TrafficLightState", GetTrafficLightAsText(Vehicle.GetTrafficLightState()));
Args.Add("CollisionCars", RoundedFloatAsText(Vehicle.GetCollisionIntensityCars() * TO_METERS));
Args.Add("CollisionPedestrians", RoundedFloatAsText(Vehicle.GetCollisionIntensityPedestrians() * TO_METERS));
Args.Add("CollisionOther", RoundedFloatAsText(Vehicle.GetCollisionIntensityOther() * TO_METERS));
Args.Add("IntersectionOtherLane", RoundedFloatAsText(100.0f * Vehicle.GetOtherLaneIntersectionFactor()));
Args.Add("IntersectionOffRoad", RoundedFloatAsText(100.0f * Vehicle.GetOffRoadIntersectionFactor()));
return FText::Format(
LOCTEXT("HUDTextFormat",
"Simulation Step: {SimStep} ms\n"
"\n"
"Speed: {Speed} km/h\n"
"Gear: {Gear}\n"
"\n"
"Speed Limit: {SpeedLimit} km/h\n"
"Traffic Light: {TrafficLightState}\n"
"\n"
"Location: {Location}\n"
"Orientation: {Orientation}\n"
"Acceleration: {Acceleration}\n"
"\n"
"Collision (Cars): {CollisionCars}\n"
"Collision (Pedestrian): {CollisionPedestrians}\n"
"Collision (Other): {CollisionOther}\n"
"\n"
"Intersection (Lane): {IntersectionOtherLane}%\n"
"Intersection (OffRoad): {IntersectionOffRoad}%")
,
Args);
}
ACarlaHUD::ACarlaHUD() :
bIsVisible(GetDefaultHUDVisibility())
{
static ConstructorHelpers::FObjectFinder<UFont> Font(TEXT("/Engine/EngineFonts/DroidSansMono"));
HUDFont = Font.Object;
}
void ACarlaHUD::DrawHUD()
{
Super::DrawHUD();
if (!bIsVisible)
return;
// Calculate ratio from 720p
const float HUDXRatio = Canvas->SizeX / 1280.f;
const float HUDYRatio = Canvas->SizeY / 720.f;
ACarlaVehicleController *Vehicle = Cast<ACarlaVehicleController>(
GetOwningPawn() == nullptr ? nullptr : GetOwningPawn()->GetController());
if (Vehicle != nullptr)
{
FVector2D ScaleVec(HUDYRatio * 1.4f, HUDYRatio * 1.4f);
auto Text = GetHUDText(Vehicle->GetPlayerState());
FCanvasTextItem HUDTextItem(FVector2D(HUDXRatio * 50.0f, HUDYRatio * 330.0f), Text, HUDFont, FLinearColor::White);
HUDTextItem.Scale = ScaleVec;
Canvas->DrawItem(HUDTextItem);
}
}
#undef LOCTEXT_NAMESPACE

View File

@ -1,49 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "GameFramework/HUD.h"
#include "CarlaHUD.generated.h"
class FTexture;
UCLASS()
class CARLA_API ACarlaHUD : public AHUD
{
GENERATED_BODY()
public:
ACarlaHUD();
UPROPERTY(EditAnywhere)
UFont* HUDFont;
virtual void DrawHUD() override;
UFUNCTION(BlueprintCallable)
bool IsVisible() const
{
return bIsVisible;
}
UFUNCTION(BlueprintCallable)
void SetVisible(bool bInIsVisible)
{
bIsVisible = bInIsVisible;
}
UFUNCTION(BlueprintCallable)
void ToggleHUDView()
{
SetVisible(!bIsVisible);
}
private:
bool bIsVisible;
};

View File

@ -1,84 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "CarlaPlayerState.h"
#include "CoreGlobals.h"
void ACarlaPlayerState::Reset()
{
Super::Reset();
// Reset incremental values.
GameTimeStamp = 0.0f;
CollisionIntensityCars = 0.0f;
CollisionIntensityPedestrians = 0.0f;
CollisionIntensityOther = 0.0f;
}
void ACarlaPlayerState::CopyProperties(APlayerState *PlayerState)
{
Super::CopyProperties(PlayerState);
if ((PlayerState != nullptr) && (this != PlayerState))
{
ACarlaPlayerState *Other = Cast<ACarlaPlayerState>(PlayerState);
if (Other != nullptr)
{
FrameNumber = Other->FrameNumber;
SimulationStepInSeconds = Other->SimulationStepInSeconds;
PlatformTimeStamp = Other->PlatformTimeStamp;
GameTimeStamp = Other->GameTimeStamp;
Transform = Other->Transform;
ForwardSpeed = Other->ForwardSpeed;
Acceleration = Other->Acceleration;
Throttle = Other->Throttle;
Steer = Other->Steer;
Brake = Other->Brake;
bHandBrake = Other->bHandBrake;
CurrentGear = Other->CurrentGear;
SpeedLimit = Other->SpeedLimit;
TrafficLightState = Other->TrafficLightState;
CollisionIntensityCars = Other->CollisionIntensityCars;
CollisionIntensityPedestrians = Other->CollisionIntensityPedestrians;
CollisionIntensityOther = Other->CollisionIntensityOther;
OtherLaneIntersectionFactor = Other->OtherLaneIntersectionFactor;
OffRoadIntersectionFactor = Other->OffRoadIntersectionFactor;
UE_LOG(LogCarla, Log, TEXT("Copied properties of ACarlaPlayerState"));
}
}
}
void ACarlaPlayerState::RegisterCollision(
AActor * /*Actor*/,
AActor * /*OtherActor*/,
const FVector &NormalImpulse,
const FHitResult &Hit)
{
switch (ATagger::GetTagOfTaggedComponent(*Hit.Component)) {
case ECityObjectLabel::Vehicles:
CollisionIntensityCars += NormalImpulse.Size();
break;
case ECityObjectLabel::Pedestrians:
CollisionIntensityPedestrians += NormalImpulse.Size();
break;
default:
CollisionIntensityOther += NormalImpulse.Size();
break;
}
}
static int32 RoundToMilliseconds(float Seconds)
{
return FMath::RoundHalfToZero(1000.0 * Seconds);
}
void ACarlaPlayerState::UpdateTimeStamp(float DeltaSeconds)
{
FrameNumber = GFrameCounter;
SimulationStepInSeconds = DeltaSeconds;
PlatformTimeStamp = RoundToMilliseconds(FPlatformTime::Seconds());
GameTimeStamp += RoundToMilliseconds(DeltaSeconds);
}

View File

@ -1,290 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "GameFramework/PlayerState.h"
#include "Traffic/TrafficLightState.h"
#include "CarlaPlayerState.generated.h"
/// Current state of the player, updated every frame by ACarlaVehicleController.
///
/// This class matches the reward that it is sent to the client over the
/// network.
UCLASS()
class CARLA_API ACarlaPlayerState : public APlayerState
{
GENERATED_BODY()
// ===========================================================================
// -- APlayerState -----------------------------------------------------------
// ===========================================================================
public:
virtual void Reset() override;
virtual void CopyProperties(APlayerState *PlayerState) override;
// ===========================================================================
// -- Getters ----------------------------------------------------------------
// ===========================================================================
public:
// ===========================================================================
/// @name Timing
// ===========================================================================
/// @{
uint64 GetFrameNumber() const
{
return FrameNumber;
}
UFUNCTION(BlueprintCallable)
float GetSimulationStepInSeconds() const
{
return SimulationStepInSeconds;
}
UFUNCTION(BlueprintCallable)
int32 GetPlatformTimeStamp() const
{
return PlatformTimeStamp;
}
UFUNCTION(BlueprintCallable)
int32 GetGameTimeStamp() const
{
return GameTimeStamp;
}
/// @}
// ===========================================================================
/// @name Transform and dynamics
// ===========================================================================
/// @{
UFUNCTION(BlueprintCallable)
const FTransform &GetPlayerTransform() const
{
return Transform;
}
UFUNCTION(BlueprintCallable)
FVector GetLocation() const
{
return Transform.GetLocation();
}
UFUNCTION(BlueprintCallable)
FVector GetOrientation() const
{
return Transform.GetRotation().GetForwardVector();
}
UFUNCTION(BlueprintCallable)
FTransform GetBoundingBoxTransform() const
{
return BoundingBoxTransform;
}
UFUNCTION(BlueprintCallable)
FVector GetBoundingBoxExtent() const
{
return BoundingBoxExtent;
}
UFUNCTION(BlueprintCallable)
float GetForwardSpeed() const
{
return ForwardSpeed;
}
UFUNCTION(BlueprintCallable)
const FVector &GetAcceleration() const
{
return Acceleration;
}
/// @}
// ===========================================================================
/// @name Vehicle control
// ===========================================================================
/// @{
UFUNCTION(BlueprintCallable)
float GetThrottle() const
{
return Throttle;
}
UFUNCTION(BlueprintCallable)
float GetSteer() const
{
return Steer;
}
UFUNCTION(BlueprintCallable)
float GetBrake() const
{
return Brake;
}
UFUNCTION(BlueprintCallable)
bool GetHandBrake() const
{
return bHandBrake;
}
UFUNCTION(BlueprintCallable)
int32 GetCurrentGear() const
{
return CurrentGear;
}
UFUNCTION(BlueprintCallable)
float GetSpeedLimit() const
{
return SpeedLimit;
}
UFUNCTION(BlueprintCallable)
ETrafficLightState GetTrafficLightState() const
{
return TrafficLightState;
}
/// @}
// ===========================================================================
/// @name Collision
// ===========================================================================
/// @{
UFUNCTION(BlueprintCallable)
float GetCollisionIntensityCars() const
{
return CollisionIntensityCars;
}
UFUNCTION(BlueprintCallable)
float GetCollisionIntensityPedestrians() const
{
return CollisionIntensityPedestrians;
}
UFUNCTION(BlueprintCallable)
float GetCollisionIntensityOther() const
{
return CollisionIntensityOther;
}
/// @}
// ===========================================================================
/// @name Road intersection
// ===========================================================================
/// @{
UFUNCTION(BlueprintCallable)
float GetOtherLaneIntersectionFactor() const
{
return OtherLaneIntersectionFactor;
}
UFUNCTION(BlueprintCallable)
float GetOffRoadIntersectionFactor() const
{
return OffRoadIntersectionFactor;
}
/// @}
// ===========================================================================
// -- Modifiers --------------------------------------------------------------
// ===========================================================================
private:
void RegisterCollision(
AActor *Actor,
AActor *OtherActor,
const FVector &NormalImpulse,
const FHitResult &Hit);
void UpdateTimeStamp(float DeltaSeconds);
// ===========================================================================
// -- Private members --------------------------------------------------------
// ===========================================================================
private:
friend class ACarlaVehicleController;
// If you add another variable here, don't forget to copy it inside
// CopyProperties if necessary.
UPROPERTY(VisibleAnywhere)
uint64 FrameNumber;
UPROPERTY(VisibleAnywhere)
float SimulationStepInSeconds;
UPROPERTY(VisibleAnywhere)
int32 PlatformTimeStamp;
UPROPERTY(VisibleAnywhere)
int32 GameTimeStamp = 0.0f;
UPROPERTY(VisibleAnywhere)
FTransform Transform;
UPROPERTY(VisibleAnywhere)
FTransform BoundingBoxTransform;
UPROPERTY(VisibleAnywhere)
FVector BoundingBoxExtent;
UPROPERTY(VisibleAnywhere)
float ForwardSpeed = 0.0f;
UPROPERTY(VisibleAnywhere)
FVector Acceleration;
UPROPERTY(VisibleAnywhere)
float Throttle = 0.0f;
UPROPERTY(VisibleAnywhere)
float Steer = 0.0f;
UPROPERTY(VisibleAnywhere)
float Brake = 0.0f;
UPROPERTY(VisibleAnywhere)
bool bHandBrake = false;
UPROPERTY(VisibleAnywhere)
int32 CurrentGear;
UPROPERTY(VisibleAnywhere)
float SpeedLimit = -1.0f;
UPROPERTY(VisibleAnywhere)
ETrafficLightState TrafficLightState = ETrafficLightState::Green;
UPROPERTY(VisibleAnywhere)
float CollisionIntensityCars = 0.0f;
UPROPERTY(VisibleAnywhere)
float CollisionIntensityPedestrians = 0.0f;
UPROPERTY(VisibleAnywhere)
float CollisionIntensityOther = 0.0f;
UPROPERTY(VisibleAnywhere)
float OtherLaneIntersectionFactor = 0.0f;
UPROPERTY(VisibleAnywhere)
float OffRoadIntersectionFactor = 0.0f;
};

View File

@ -1,21 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "Carla/Game/DataRouter.h"
void FDataRouter::RestartLevel()
{
if (Player != nullptr) {
Player->RestartLevel();
Player = nullptr;
} else {
UE_LOG(
LogCarla,
Error,
TEXT("FDataRouter: Trying to restart level but I don't have any player registered"));
}
}

View File

@ -1,62 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Carla/Util/NonCopyable.h"
#include "Carla/Vehicle/CarlaVehicleController.h"
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
class ACarlaPlayerState;
class UAgentComponent;
struct FVehicleControl;
class FDataRouter : private NonCopyable
{
public:
void RegisterPlayer(ACarlaVehicleController &InPlayer)
{
Player = &InPlayer;
}
void RegisterAgent(const UAgentComponent *Agent)
{
check(Agent != nullptr);
Agents.Emplace(Agent);
}
void DeregisterAgent(const UAgentComponent *Agent)
{
check(Agent != nullptr);
Agents.RemoveSwap(Agent);
}
const ACarlaPlayerState &GetPlayerState() const
{
check(Player != nullptr);
return Player->GetPlayerState();
}
const TArray<const UAgentComponent *> &GetAgents() const
{
return Agents;
}
void ApplyVehicleControl(const FVehicleControl &VehicleControl, EVehicleInputPriority Priority)
{
check((Player != nullptr) && (Player->IsPossessingAVehicle()));
Player->GetPossessedVehicle()->ApplyVehicleControl(VehicleControl, Priority);
}
void RestartLevel();
private:
TArray<const UAgentComponent *> Agents;
ACarlaVehicleController *Player = nullptr;
};

View File

@ -1,65 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "MockGameController.h"
#include "Game/DataRouter.h"
MockGameController::MockGameController(
FDataRouter &InDataRouter,
const FMockGameControllerSettings &InSettings)
: ICarlaGameControllerBase(InDataRouter),
Settings(InSettings) {}
void MockGameController::Initialize(UCarlaSettings &CarlaSettings)
{
#if WITH_EDITOR
if (Settings.bOverrideCarlaSettings) {
CarlaSettings.NumberOfVehicles = Settings.NumberOfVehicles;
CarlaSettings.NumberOfPedestrians = Settings.NumberOfPedestrians;
CarlaSettings.WeatherId = Settings.WeatherId;
}
#endif // WITH_EDITOR
if (Settings.bChangeWeatherOnBeginPlay && (CarlaSettings.WeatherDescriptions.Num() > 0)) {
static uint32 StaticIndex = 0u;
CarlaSettings.WeatherId = StaticIndex % CarlaSettings.WeatherDescriptions.Num();
++StaticIndex;
}
}
APlayerStart *MockGameController::ChoosePlayerStart(
const TArray<APlayerStart *> &AvailableStartSpots)
{
check(AvailableStartSpots.Num() > 0);
const uint32 Index =
(Settings.bRandomPlayerStart ?
FMath::RandRange(0, AvailableStartSpots.Num() - 1) :
Settings.PlayerStartIndex % AvailableStartSpots.Num());
UE_LOG(LogCarla, Log, TEXT("Spawning player at player start %d/%d"), Index, AvailableStartSpots.Num());
return AvailableStartSpots[Index];
}
void MockGameController::RegisterPlayer(AController &NewPlayer)
{
ACarlaVehicleController *VehicleController = Cast<ACarlaVehicleController>(&NewPlayer);
if (VehicleController != nullptr) {
VehicleController->EnableUserInput(true);
} else {
UE_LOG(LogCarla, Warning, TEXT("Player is not a ACarlaVehicleController"));
}
}
void MockGameController::BeginPlay()
{
}
void MockGameController::Tick(float /*DeltaSeconds*/)
{
}

View File

@ -1,33 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Game/CarlaGameControllerBase.h"
#include "Game/MockGameControllerSettings.h"
/// Mocks the CARLA game controller class for testing purposes.
class MockGameController : public ICarlaGameControllerBase
{
public:
explicit MockGameController(FDataRouter &DataRouter, const FMockGameControllerSettings &Settings);
virtual void Initialize(UCarlaSettings &CarlaSettings) final;
virtual APlayerStart *ChoosePlayerStart(const TArray<APlayerStart *> &AvailableStartSpots) final;
virtual void RegisterPlayer(AController &NewPlayer) final;
virtual void BeginPlay() final;
virtual void Tick(float DeltaSeconds) final;
private:
FMockGameControllerSettings Settings;
};

View File

@ -1,50 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "MockGameControllerSettings.generated.h"
USTRUCT(BlueprintType)
struct CARLA_API FMockGameControllerSettings
{
GENERATED_USTRUCT_BODY()
/** If true, weather will be changed every time we start the level.
*
* Has precedence over options in "Override CARLA Settings".
*/
UPROPERTY(EditAnywhere, Category = "Mock CARLA Controller")
bool bChangeWeatherOnBeginPlay = false;
/** If true, a random player start position will be chosen every time we start the level. */
UPROPERTY(EditAnywhere, Category = "Mock CARLA Controller")
bool bRandomPlayerStart = false;
/** Index of the player start position. */
UPROPERTY(EditAnywhere, Category = "Mock CARLA Controller", meta = (EditCondition = "!bRandomPlayerStart", ClampMin = 0))
int32 PlayerStartIndex = 0;
#if WITH_EDITORONLY_DATA
/** Override available settings in CARLA Settings (Editor only). */
UPROPERTY(EditAnywhere, Category = "Mock CARLA Controller", meta = (DisplayName = "Override CARLA Settings"))
bool bOverrideCarlaSettings = false;
/** Number of NPC vehicles to be spawned into the level. */
UPROPERTY(EditAnywhere, Category = "Mock CARLA Controller", meta = (EditCondition = "bOverrideCarlaSettings", ClampMin = 0))
int32 NumberOfVehicles = 5;
/** Number of NPC pedestrians to be spawned into the level. */
UPROPERTY(EditAnywhere, Category = "Mock CARLA Controller", meta = (EditCondition = "bOverrideCarlaSettings", ClampMin = 0))
int32 NumberOfPedestrians = 15;
/** Index of the weather setting to use. If negative, weather won't be changed. */
UPROPERTY(EditAnywhere, Category = "Mock CARLA Controller", meta = (EditCondition = "bOverrideCarlaSettings"))
int32 WeatherId = -1;
#endif // WITH_EDITORONLY_DATA
};

View File

@ -6,7 +6,8 @@
#pragma once
#include "CityMapDefinitions.h"
#include "Carla/MapGen/CityMapDefinitions.h"
#include "Carla/Util/NonCopyable.h"
#include <vector>

View File

@ -4,11 +4,14 @@
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "Carla/Recorder/CarlaReplayerHelper.h"
#include "Carla/Actor/ActorDescription.h"
#include "Carla/Actor/ActorView.h"
#include "Carla/Vehicle/WheeledVehicleAIController.h"
#include "Carla/Walker/WalkerControl.h"
#include "Carla/Walker/WalkerController.h"
#include "CarlaReplayerHelper.h"
// create or reuse an actor for replaying
std::pair<int, FActorView>CarlaReplayerHelper::TryToCreateReplayerActor(

View File

@ -1,65 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "RoadIntersection.h"
ARoadIntersection::ARoadIntersection(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = false;
RootComponent =
ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("RootComponent"));
RootComponent->SetMobility(EComponentMobility::Static);
#define CARLA_CREATE_STATIC_MESH_COMPONENT(Mesh) \
{ \
auto Component = CreateDefaultSubobject<UStaticMeshComponent>(TEXT(#Mesh) TEXT("Component")); \
Component->SetMobility(EComponentMobility::Static); \
Component->SetupAttachment(RootComponent); \
StaticMeshComponents.Add(Component); \
StaticMeshes.Add(ERoadIntersectionItem:: Mesh, nullptr); \
}
CARLA_CREATE_STATIC_MESH_COMPONENT(Lane0)
CARLA_CREATE_STATIC_MESH_COMPONENT(Lane1)
CARLA_CREATE_STATIC_MESH_COMPONENT(Lane2)
CARLA_CREATE_STATIC_MESH_COMPONENT(Lane3)
CARLA_CREATE_STATIC_MESH_COMPONENT(Sidewalk0)
CARLA_CREATE_STATIC_MESH_COMPONENT(Sidewalk1)
CARLA_CREATE_STATIC_MESH_COMPONENT(Sidewalk2)
CARLA_CREATE_STATIC_MESH_COMPONENT(Sidewalk3)
CARLA_CREATE_STATIC_MESH_COMPONENT(LaneMarking)
#undef CARLA_CREATE_STATIC_MESH_COMPONENT
}
#if WITH_EDITOR
void ARoadIntersection::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (PropertyChangedEvent.Property) {
UpdateMeshes();
}
}
#endif // WITH_EDITOR
void ARoadIntersection::SetStaticMesh(ERoadIntersectionItem Item, UStaticMesh *StaticMesh)
{
if (static_cast<uint8>(Item) < StaticMeshes.Num()) {
StaticMeshes[Item] = StaticMesh;
}
}
void ARoadIntersection::UpdateMeshes()
{
check(StaticMeshes.Num() == StaticMeshComponents.Num());
int32 i = 0;
for (auto Item : StaticMeshes) {
check(StaticMeshComponents[i] != nullptr);
StaticMeshComponents[i]->SetStaticMesh(Item.Value);
++i;
}
}

View File

@ -1,53 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "RoadIntersection.generated.h"
UENUM(BlueprintType)
enum class ERoadIntersectionItem : uint8
{
Lane0 UMETA(DisplayName = "Lane 1"),
Lane1 UMETA(DisplayName = "Lane 2"),
Lane2 UMETA(DisplayName = "Lane 3"),
Lane3 UMETA(DisplayName = "Lane 4"),
Sidewalk0 UMETA(DisplayName = "Sidewalk 1"),
Sidewalk1 UMETA(DisplayName = "Sidewalk 2"),
Sidewalk2 UMETA(DisplayName = "Sidewalk 3"),
Sidewalk3 UMETA(DisplayName = "Sidewalk 4"),
LaneMarking UMETA(DisplayName = "LaneMarking"),
};
/// A road intersection.
UCLASS()
class CARLA_API ARoadIntersection : public AActor
{
GENERATED_BODY()
public:
ARoadIntersection(const FObjectInitializer& ObjectInitializer);
#if WITH_EDITOR
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif // WITH_EDITOR
UFUNCTION(BlueprintCallable)
void SetStaticMesh(ERoadIntersectionItem Item, UStaticMesh *StaticMesh);
private:
void UpdateMeshes();
UPROPERTY()
TArray<UStaticMeshComponent *> StaticMeshComponents;
UPROPERTY(Category = "Meshes", EditAnywhere)
TMap<ERoadIntersectionItem, UStaticMesh *> StaticMeshes;
};

View File

@ -1,88 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "RoadSegment.h"
#include "Engine/StaticMesh.h"
enum RoadSegmentItems {
ELaneLeft,
ELaneRight,
ESidewalkLeft,
ESidewalkRight,
ELaneMarkingSolid,
ELaneMarkingBroken,
NUMBER_OF_ITEMS
};
ARoadSegment::ARoadSegment(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = false;
}
void ARoadSegment::OnConstruction(const FTransform &Transform)
{
Super::OnConstruction(Transform);
UpdateMeshes();
}
#if WITH_EDITOR
void ARoadSegment::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (PropertyChangedEvent.Property) {
GenerateRoad();
}
}
#endif // WITH_EDITOR
void ARoadSegment::GenerateRoad()
{
UpdateMeshes();
UpdateRoad();
}
void ARoadSegment::UpdateMeshes()
{
if (GetNumberOfInstantiators() != NUMBER_OF_ITEMS) {
ClearInstantiators();
for (auto i = 0u; i < NUMBER_OF_ITEMS; ++i) {
PushBackInstantiator(nullptr);
}
}
SetStaticMesh(ELaneLeft, LaneLeft);
SetStaticMesh(ELaneRight, LaneRight);
SetStaticMesh(ESidewalkLeft, SidewalkLeft);
SetStaticMesh(ESidewalkRight, SidewalkRight);
SetStaticMesh(ELaneMarkingSolid, LaneMarkingSolid);
SetStaticMesh(ELaneMarkingBroken, LaneMarkingBroken);
}
void ARoadSegment::UpdateRoad()
{
ClearInstances();
Scale = (LaneLeft != nullptr ? LaneLeft->GetBoundingBox().GetSize().X : 1.0f);
FVector Translation(0.0f, 0.0f, 0.0f);
for (auto &Item : RoadDescription) {
FTransform Transform{Translation};
AddInstance(ELaneLeft, Transform);
AddInstance(ELaneRight, Transform);
if (Item.bHasRightSidewalk) {
AddInstance(ESidewalkRight, Transform);
}
if (Item.bHasLeftSidewalk) {
AddInstance(ESidewalkLeft, Transform);
}
if (Item.LaneMarking == ELaneMarkingType::Solid) {
AddInstance(ELaneMarkingSolid, Transform);
} else if (Item.LaneMarking == ELaneMarkingType::Broken) {
AddInstance(ELaneMarkingBroken, Transform);
}
Translation.X += Scale;
}
}

View File

@ -1,140 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "MapGen/StaticMeshCollection.h"
#include "RoadSegment.generated.h"
UENUM(BlueprintType)
enum class ELaneMarkingType : uint8
{
None UMETA(DisplayName = "None"),
Solid UMETA(DisplayName = "Solid Lane Marking"),
Broken UMETA(DisplayName = "Broken Lane Marking")
};
/// Description of a road segment piece.
USTRUCT(BlueprintType)
struct CARLA_API FRoadSegmentPiece
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bHasLeftSidewalk = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool bHasRightSidewalk = true;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
ELaneMarkingType LaneMarking = ELaneMarkingType::Solid;
};
/// A straight segment of road.
///
/// Please call GenerateRoad after modifying it.
UCLASS()
class CARLA_API ARoadSegment : public AStaticMeshCollection
{
GENERATED_BODY()
public:
ARoadSegment(const FObjectInitializer& ObjectInitializer);
virtual void OnConstruction(const FTransform &Transform) override;
#if WITH_EDITOR
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif // WITH_EDITOR
UFUNCTION(BlueprintCallable, Category="Road Description")
void GenerateRoad();
UFUNCTION(BlueprintCallable, Category="Road Description")
int32 GetNumberOfPieces() const
{
return RoadDescription.Num();
}
UFUNCTION(BlueprintCallable, Category="Road Description")
void AppendPiece(const FRoadSegmentPiece &RoadSegmentPiece)
{
RoadDescription.Add(RoadSegmentPiece);
}
UFUNCTION(BlueprintCallable, Category="Road Description")
void RemoveAllPieces()
{
RoadDescription.Empty();
}
UFUNCTION(BlueprintCallable, Category="Set Static Mesh")
void SetStaticMesh_LaneLeft(UStaticMesh *StaticMesh)
{
LaneLeft = StaticMesh;
}
UFUNCTION(BlueprintCallable, Category="Set Static Mesh")
void SetStaticMesh_LaneRight(UStaticMesh *StaticMesh)
{
LaneRight = StaticMesh;
}
UFUNCTION(BlueprintCallable, Category="Set Static Mesh")
void SetStaticMesh_SidewalkLeft(UStaticMesh *StaticMesh)
{
SidewalkLeft = StaticMesh;
}
UFUNCTION(BlueprintCallable, Category="Set Static Mesh")
void SetStaticMesh_SidewalkRight(UStaticMesh *StaticMesh)
{
SidewalkRight = StaticMesh;
}
UFUNCTION(BlueprintCallable, Category="Set Static Mesh")
void SetStaticMesh_LaneMarkingSolid(UStaticMesh *StaticMesh)
{
LaneMarkingSolid = StaticMesh;
}
UFUNCTION(BlueprintCallable, Category="Set Static Mesh")
void SetStaticMesh_LaneMarkingBroken(UStaticMesh *StaticMesh)
{
LaneMarkingBroken = StaticMesh;
}
private:
void UpdateMeshes();
void UpdateRoad();
UPROPERTY(Category = "Road Description", EditAnywhere)
TArray<FRoadSegmentPiece> RoadDescription;
UPROPERTY(Category = "Road Description", AdvancedDisplay, EditAnywhere)
float Scale = 1.0f;
UPROPERTY(Category = "Meshes", EditAnywhere)
UStaticMesh *LaneLeft;
UPROPERTY(Category = "Meshes", EditAnywhere)
UStaticMesh *LaneRight;
UPROPERTY(Category = "Meshes", EditAnywhere)
UStaticMesh *SidewalkLeft;
UPROPERTY(Category = "Meshes", EditAnywhere)
UStaticMesh *SidewalkRight;
UPROPERTY(Category = "Meshes", EditAnywhere)
UStaticMesh *LaneMarkingSolid;
UPROPERTY(Category = "Meshes", EditAnywhere)
UStaticMesh *LaneMarkingBroken;
};

View File

@ -1,210 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
#include "Carla.h"
#include "CarlaEncoder.h"
#include "Agent/TrafficSignAgentComponent.h"
#include "Agent/VehicleAgentComponent.h"
#include "Agent/WalkerAgentComponent.h"
#include "Game/CarlaPlayerState.h"
#include "Settings/SensorDescription.h"
#include "GameFramework/PlayerStart.h"
#include <cstring>
// Conversion from centimeters to meters.
static constexpr float TO_METERS = 1e-2;
// =============================================================================
// -- Static local methods -----------------------------------------------------
// =============================================================================
static void Encode(const FVector &Vector, carla_vector3d &Data)
{
Data = {Vector.X, Vector.Y, Vector.Z};
}
static void Encode(const FRotator &Rotator, carla_rotation3d &Data)
{
Data.pitch = Rotator.Pitch;
Data.roll = Rotator.Roll;
Data.yaw = Rotator.Yaw;
}
static void Encode(const FTransform &Transform, carla_transform &Data)
{
Encode(Transform.GetLocation() * TO_METERS, Data.location);
Encode(Transform.GetRotation().GetForwardVector(), Data.orientation);
Encode(Transform.Rotator(), Data.rotation);
}
// =============================================================================
// -- FCarlaEncoder static methods ---------------------------------------------
// =============================================================================
TUniquePtr<const char[]> FCarlaEncoder::Encode(const FString &String)
{
const char *Ptr = TCHAR_TO_UTF8(*String);
auto Buffer = MakeUnique<char[]>(std::strlen(Ptr) + 1u); // + null terminator.
#if defined(_WIN32)
strcpy_s(Buffer.Get(),String.Len()+1, Ptr);
#else
std::strcpy(Buffer.Get(), Ptr);
#endif
return TUniquePtr<const char[]>(Buffer.Release());
}
void FCarlaEncoder::Encode(
const TArray<APlayerStart *> &AvailableStartSpots,
TArray<carla_transform> &Data)
{
const int32 NumberOfStartSpots = AvailableStartSpots.Num();
Data.AddUninitialized(NumberOfStartSpots);
for (auto i = 0; i < NumberOfStartSpots; ++i) {
check(AvailableStartSpots[i] != nullptr);
::Encode(AvailableStartSpots[i]->GetActorTransform(), Data[i]);
}
}
void FCarlaEncoder::Encode(
const TArray<USensorDescription *> &SensorDescriptions,
TArray<carla_sensor_definition> &Data,
TArray<TUniquePtr<const char[]>> &SensorNames)
{
const int32 NumberOfSensors = SensorDescriptions.Num();
Data.AddUninitialized(NumberOfSensors);
SensorNames.Reserve(NumberOfSensors);
for (auto i = 0; i < NumberOfSensors; ++i) {
check(SensorDescriptions[i] != nullptr);
SensorNames.Emplace(::Encode(*SensorDescriptions[i], Data[i]));
}
}
void FCarlaEncoder::Encode(
const ACarlaPlayerState &PlayerState,
carla_measurements &Data)
{
Data.frame_number = PlayerState.GetFrameNumber();
Data.platform_timestamp = PlayerState.GetPlatformTimeStamp();
Data.game_timestamp = PlayerState.GetGameTimeStamp();
auto &Player = Data.player_measurements;
::Encode(PlayerState.GetPlayerTransform(), Player.transform);
::Encode(PlayerState.GetBoundingBoxTransform(), Player.bounding_box.transform);
::Encode(PlayerState.GetBoundingBoxExtent() * TO_METERS, Player.bounding_box.extent);
::Encode(PlayerState.GetAcceleration() * TO_METERS, Player.acceleration);
Player.forward_speed = PlayerState.GetForwardSpeed() * TO_METERS;
Player.collision_vehicles = PlayerState.GetCollisionIntensityCars() * TO_METERS;
Player.collision_pedestrians = PlayerState.GetCollisionIntensityPedestrians() * TO_METERS;
Player.collision_other = PlayerState.GetCollisionIntensityOther() * TO_METERS;
Player.intersection_otherlane = PlayerState.GetOtherLaneIntersectionFactor();
Player.intersection_offroad = PlayerState.GetOffRoadIntersectionFactor();
Player.autopilot_control.steer = PlayerState.GetSteer();
Player.autopilot_control.throttle = PlayerState.GetThrottle();
Player.autopilot_control.brake = PlayerState.GetBrake();
Player.autopilot_control.hand_brake = PlayerState.GetHandBrake();
Player.autopilot_control.reverse = PlayerState.GetCurrentGear() < 0;
}
void FCarlaEncoder::Encode(
const TArray<const UAgentComponent *> &Agents,
TArray<carla_agent> &Data)
{
const int32 NumberOfAgents = Agents.Num();
Data.AddUninitialized(NumberOfAgents);
for (auto i = 0; i < NumberOfAgents; ++i) {
check(Agents[i] != nullptr);
Encode(*Agents[i], Data[i]);
}
}
void FCarlaEncoder::Encode(const UAgentComponent &AgentComponent, carla_agent &AgentData)
{
AgentData.id = AgentComponent.GetId();
FCarlaEncoder Encoder(AgentData);
AgentComponent.AcceptVisitor(Encoder);
}
// =============================================================================
// -- FCarlaEncoder ------------------------------------------------------------
// =============================================================================
FCarlaEncoder::FCarlaEncoder(carla_agent &InData) : Data(InData) {}
void FCarlaEncoder::Visit(const UTrafficSignAgentComponent &Agent)
{
constexpr float TO_METERS_PER_SECOND = 1.0f / 3.6f;
::Encode(Agent.GetComponentTransform(), Data.transform);
auto &TrafficSign = Agent.GetTrafficSign();
switch (TrafficSign.GetTrafficSignState()) {
case ETrafficSignState::TrafficLightRed:
Data.type = CARLA_SERVER_AGENT_TRAFFICLIGHT_RED;
break;
case ETrafficSignState::TrafficLightYellow:
Data.type = CARLA_SERVER_AGENT_TRAFFICLIGHT_YELLOW;
break;
case ETrafficSignState::TrafficLightGreen:
Data.type = CARLA_SERVER_AGENT_TRAFFICLIGHT_GREEN;
break;
case ETrafficSignState::SpeedLimit_30:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 30.0f * TO_METERS_PER_SECOND;
break;
case ETrafficSignState::SpeedLimit_40:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 40.0f * TO_METERS_PER_SECOND;
break;
case ETrafficSignState::SpeedLimit_50:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 50.0f * TO_METERS_PER_SECOND;
break;
case ETrafficSignState::SpeedLimit_60:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 60.0f * TO_METERS_PER_SECOND;
break;
case ETrafficSignState::SpeedLimit_90:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 90.0f * TO_METERS_PER_SECOND;
break;
case ETrafficSignState::SpeedLimit_100:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 100.0f * TO_METERS_PER_SECOND;
break;
case ETrafficSignState::SpeedLimit_120:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 120.0f * TO_METERS_PER_SECOND;
break;
case ETrafficSignState::SpeedLimit_130:
Data.type = CARLA_SERVER_AGENT_SPEEDLIMITSIGN;
Data.forward_speed = 130.0f * TO_METERS_PER_SECOND;
break;
default:
UE_LOG(LogCarla, Error, TEXT("Unknown traffic sign!"));
}
}
void FCarlaEncoder::Visit(const UVehicleAgentComponent &Agent)
{
::Encode(Agent.GetTransform(), Data.transform);
Data.type = CARLA_SERVER_AGENT_VEHICLE;
Data.forward_speed = Agent.GetForwardSpeed() * TO_METERS;
::Encode(Agent.GetBoundingBoxTransform(), Data.bounding_box.transform);
::Encode(Agent.GetBoundingBoxExtent() * TO_METERS, Data.bounding_box.extent);
}
void FCarlaEncoder::Visit(const UWalkerAgentComponent &Agent)
{
::Encode(Agent.GetTransform(), Data.transform);
Data.type = CARLA_SERVER_AGENT_PEDESTRIAN;
Data.forward_speed = Agent.GetForwardSpeed() * TO_METERS;
::Encode(Agent.GetBoundingBoxTransform(), Data.bounding_box.transform);
::Encode(Agent.GetBoundingBoxExtent() * TO_METERS, Data.bounding_box.extent);
}
#endif // CARLA_COMPILE_CARLASERVER_LEGACY

View File

@ -1,75 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
#include "Agent/AgentComponentVisitor.h"
#include "Sensor/SensorDataView.h"
#include "Vehicle/VehicleControl.h"
#include <carla/carla_server.h>
/// Encodes Unreal classes to CarlaServer API. To be used by FCarlaServer only.
class FCarlaEncoder : private IAgentComponentVisitor
{
public:
static TUniquePtr<const char[]> Encode(const FString &String);
static void Encode(
const TArray<APlayerStart *> &AvailableStartSpots,
TArray<carla_transform> &Data);
static void Encode(
const ACarlaPlayerState &PlayerState,
carla_measurements &Data);
static void Encode(
const TArray<const UAgentComponent *> &Agents,
TArray<carla_agent> &Data);
static void Encode(const FSensorDataView &SensorData, carla_sensor_data &Data)
{
Data.id = SensorData.GetSensorId();
Data.header = SensorData.GetHeader().GetData();
Data.header_size = SensorData.GetHeader().GetSize();
Data.data = SensorData.GetData().GetData();
Data.data_size = SensorData.GetData().GetSize();
}
static void Decode(const carla_request_new_episode &Data, FString &IniFile)
{
IniFile = FString(Data.ini_file_length, ANSI_TO_TCHAR(Data.ini_file));
}
static void Decode(const carla_control &Data, FVehicleControl &Control)
{
Control.Steer = Data.steer;
Control.Throttle = Data.throttle;
Control.Brake = Data.brake;
Control.bHandBrake = Data.hand_brake;
Control.bReverse = Data.reverse;
}
private:
static void Encode(const UAgentComponent &AgentComponent, carla_agent &Data);
FCarlaEncoder(carla_agent &Data);
virtual void Visit(const UTrafficSignAgentComponent &) override;
virtual void Visit(const UVehicleAgentComponent &) override;
virtual void Visit(const UWalkerAgentComponent &) override;
carla_agent &Data;
};
#endif // CARLA_COMPILE_CARLASERVER_LEGACY

View File

@ -1,213 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "CarlaServer.h"
#include "Server/CarlaEncoder.h"
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
# include <carla/carla_server.h>
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
// =============================================================================
// -- Static local methods -----------------------------------------------------
// =============================================================================
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
static FCarlaServer::ErrorCode ParseErrorCode(const uint32 ErrorCode)
{
if (ErrorCode == CARLA_SERVER_SUCCESS) {
return FCarlaServer::Success;
} else if (ErrorCode == CARLA_SERVER_TRY_AGAIN) {
return FCarlaServer::TryAgain;
} else {
return FCarlaServer::Error;
}
}
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
static int32 GetTimeOut(uint32 TimeOut, const bool bBlocking)
{
return (bBlocking ? TimeOut : 0u);
}
// =============================================================================
// -- CarlaServer --------------------------------------------------------------
// =============================================================================
FCarlaServer::FCarlaServer(const uint32 InWorldPort, const uint32 InTimeOut) :
WorldPort(InWorldPort),
TimeOut(InTimeOut),
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
Server(carla_make_server())
#else
Server(nullptr)
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
{
check(Server != nullptr);
}
FCarlaServer::~FCarlaServer()
{
#ifdef CARLA_SERVER_EXTRA_LOG
UE_LOG(LogCarlaServer, Warning, TEXT("Destroying CarlaServer"));
#endif // CARLA_SERVER_EXTRA_LOG
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
carla_free_server(Server);
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}
FCarlaServer::ErrorCode FCarlaServer::Connect()
{
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
UE_LOG(LogCarlaServer, Log, TEXT("Waiting for the client to connect..."));
return ParseErrorCode(carla_server_connect(Server, WorldPort, TimeOut));
#else
UE_LOG(LogCarlaServer, Error, TEXT("CarlaServer no longer supported!!"));
return ErrorCode::Error;
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}
FCarlaServer::ErrorCode FCarlaServer::ReadNewEpisode(FString &IniFile, const bool bBlocking)
{
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
carla_request_new_episode values;
auto ec = ParseErrorCode(carla_read_request_new_episode(Server, values, GetTimeOut(TimeOut, bBlocking)));
if (Success == ec) {
FCarlaEncoder::Decode(values, IniFile);
UE_LOG(LogCarlaServer, Log, TEXT("Received new episode"));
#ifdef CARLA_SERVER_EXTRA_LOG
UE_LOG(LogCarlaServer, Log, TEXT("Received CarlaSettings.ini:\n%s"), *IniFile);
#endif // CARLA_SERVER_EXTRA_LOG
}
return ec;
#else
return ErrorCode::Error;
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}
FCarlaServer::ErrorCode FCarlaServer::SendSceneDescription(
const FString &MapName,
const TArray<APlayerStart *> &AvailableStartSpots,
const bool bBlocking)
{
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
carla_scene_description scene;
// Encode map name.
const auto MapNameBuffer = FCarlaEncoder::Encode(MapName);
scene.map_name = MapNameBuffer.Get();
// Encode start spots.
TArray<carla_transform> Transforms;
FCarlaEncoder::Encode(AvailableStartSpots, Transforms);
scene.player_start_spots = (Transforms.Num() > 0 ? Transforms.GetData() : nullptr);;
scene.number_of_player_start_spots = Transforms.Num();
// Encode sensors.
TArray<TUniquePtr<const char[]>> SensorNames; // This holds the memory while we send it.
TArray<carla_sensor_definition> Sensors;
FCarlaEncoder::Encode(SensorDescriptions, Sensors, SensorNames);
scene.sensors = (Sensors.Num() > 0 ? Sensors.GetData() : nullptr);;
scene.number_of_sensors = Sensors.Num();
// Send scene description.
UE_LOG(LogCarlaServer, Log, TEXT("Sending %d available start positions"), scene.number_of_player_start_spots);
UE_LOG(LogCarlaServer, Log, TEXT("Sending %d sensor descriptions"), scene.number_of_sensors);
return ParseErrorCode(carla_write_scene_description(Server, scene, GetTimeOut(TimeOut, bBlocking)));
#else
return ErrorCode::Error;
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}
FCarlaServer::ErrorCode FCarlaServer::ReadEpisodeStart(uint32 &StartPositionIndex, const bool bBlocking)
{
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
carla_episode_start values;
auto ec = ParseErrorCode(carla_read_episode_start(Server, values, GetTimeOut(TimeOut, bBlocking)));
if (Success == ec) {
StartPositionIndex = values.player_start_spot_index;
UE_LOG(LogCarlaServer, Log, TEXT("Episode start received: { StartIndex = %d }"), StartPositionIndex);
}
return ec;
#else
return ErrorCode::Error;
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}
FCarlaServer::ErrorCode FCarlaServer::SendEpisodeReady(const bool bBlocking)
{
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
UE_LOG(LogCarlaServer, Log, TEXT("Ready to play, notifying client"));
const carla_episode_ready values = {true};
return ParseErrorCode(carla_write_episode_ready(Server, values, GetTimeOut(TimeOut, bBlocking)));
#else
return ErrorCode::Error;
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}
FCarlaServer::ErrorCode FCarlaServer::ReadControl(FVehicleControl &Control, const bool bBlocking)
{
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
carla_control values;
auto ec = ParseErrorCode(carla_read_control(Server, values, GetTimeOut(TimeOut, bBlocking)));
if (Success == ec) {
#ifdef CARLA_SERVER_EXTRA_LOG
UE_LOG(
LogCarlaServer,
Log,
TEXT("Read control (%s): { Steer = %f, Throttle = %f, Brake = %f, Handbrake = %s, Reverse = %s }"),
(bBlocking ? TEXT("Sync") : TEXT("Async")),
values.steer,
values.throttle,
values.brake,
(values.hand_brake ? TEXT("True") : TEXT("False")),
(values.reverse ? TEXT("True") : TEXT("False")));
#endif // CARLA_SERVER_EXTRA_LOG
FCarlaEncoder::Decode(values, Control);
} else if ((!bBlocking) && (TryAgain == ec)) {
UE_LOG(LogCarlaServer, Warning, TEXT("No control received from the client this frame!"));
}
return ec;
#else
return ErrorCode::Error;
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}
FCarlaServer::ErrorCode FCarlaServer::SendMeasurements(
const ACarlaPlayerState &PlayerState,
const TArray<const UAgentComponent *> &Agents,
const bool bSendNonPlayerAgentsInfo)
{
#ifdef CARLA_COMPILE_CARLASERVER_LEGACY
// Encode measurements.
carla_measurements values;
FCarlaEncoder::Encode(PlayerState, values);
// Encode agents.
TArray<carla_agent> AgentsData;
if (bSendNonPlayerAgentsInfo) {
FCarlaEncoder::Encode(Agents, AgentsData);
}
values.non_player_agents = (AgentsData.Num() > 0 ? AgentsData.GetData() : nullptr);;
values.number_of_non_player_agents = AgentsData.Num();
// Send measurements.
#ifdef CARLA_SERVER_EXTRA_LOG
UE_LOG(LogCarlaServer, Log, TEXT("Sending data of %d agents"), values.number_of_non_player_agents);
#endif // CARLA_SERVER_EXTRA_LOG
return ParseErrorCode(carla_write_measurements(Server, values));
#else
return ErrorCode::Error;
#endif // CARLA_COMPILE_CARLASERVER_LEGACY
}

View File

@ -1,60 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Containers/Array.h"
class ACarlaPlayerState;
class APlayerStart;
class FString;
struct FVehicleControl;
/// Wrapper around carla_server API.
class FCarlaServer
{
public:
enum ErrorCode {
Success,
TryAgain,
Error
};
explicit FCarlaServer(uint32 WorldPort, uint32 TimeOutInMilliseconds);
~FCarlaServer();
/// Connect with the client, block until the client connects or the time-out
/// is met.
ErrorCode Connect();
ErrorCode ReadNewEpisode(FString &IniFile, bool bBlocking);
ErrorCode SendSceneDescription(
const FString &MapName,
const TArray<APlayerStart *> &AvailableStartSpots,
bool bBlocking);
ErrorCode ReadEpisodeStart(uint32 &StartPositionIndex, bool bBlocking);
ErrorCode SendEpisodeReady(bool bBlocking);
ErrorCode ReadControl(FVehicleControl &Control, bool bBlocking);
ErrorCode SendMeasurements(
const ACarlaPlayerState &PlayerState,
const TArray<const UAgentComponent *> &Agents,
bool bSendNonPlayerAgentsInfo);
private:
const uint32 WorldPort;
const uint32 TimeOut;
void* const Server;
};

View File

@ -1,149 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "ServerGameController.h"
#include "Game/DataRouter.h"
#include "Server/CarlaServer.h"
#include "Settings/CarlaSettings.h"
#include "Private/RenderTargetTemp.h"
using Errc = FCarlaServer::ErrorCode;
static constexpr bool BLOCKING = true;
static constexpr bool NON_BLOCKING = false;
FServerGameController::FServerGameController(FDataRouter &InDataRouter)
: ICarlaGameControllerBase(InDataRouter),
Server(nullptr) {}
FServerGameController::~FServerGameController() {}
void FServerGameController::Initialize(UCarlaSettings &InCarlaSettings)
{
CarlaSettings = &InCarlaSettings;
// Initialize server if missing.
if (!Server.IsValid()) {
Server = MakeShared<FCarlaServer>(CarlaSettings->WorldPort, CarlaSettings->ServerTimeOut);
FString IniFile;
if ((Errc::Success == Server->Connect()) &&
(Errc::Success == Server->ReadNewEpisode(IniFile, BLOCKING))) {
CarlaSettings->LoadSettingsFromString(IniFile);
} else {
UE_LOG(LogCarlaServer, Warning, TEXT("Failed to initialize, server needs restart"));
Server = nullptr;
}
}
}
APlayerStart *FServerGameController::ChoosePlayerStart(
const TArray<APlayerStart *> &AvailableStartSpots)
{
check(AvailableStartSpots.Num() > 0);
// Send scene description.
if (Server.IsValid()) {
const auto &MapName = CarlaSettings->MapName;
if (Errc::Success != Server->SendSceneDescription(MapName, AvailableStartSpots, BLOCKING)) {
UE_LOG(LogCarlaServer, Warning, TEXT("Failed to send scene description, server needs restart"));
Server = nullptr;
}
}
// Read episode start.
uint32 StartIndex = 0u; // default.
if (Server.IsValid()) {
if (Errc::Success != Server->ReadEpisodeStart(StartIndex, BLOCKING)) {
UE_LOG(LogCarlaServer, Warning, TEXT("Failed to read episode start, server needs restart"));
Server = nullptr;
}
}
if (static_cast<int64>(StartIndex) >= AvailableStartSpots.Num()) {
UE_LOG(LogCarlaServer, Warning, TEXT("Client requested an invalid player start, using default one instead."));
StartIndex = 0u;
}
return AvailableStartSpots[StartIndex];
}
void FServerGameController::RegisterPlayer(AController &NewPlayer)
{
}
void FServerGameController::BeginPlay()
{
if (Server.IsValid()) {
if (Errc::Success != Server->SendEpisodeReady(BLOCKING)) {
UE_LOG(LogCarlaServer, Warning, TEXT("Failed to read episode start, server needs restart"));
Server = nullptr;
}
}
}
void FServerGameController::Tick(float DeltaSeconds)
{
check(CarlaSettings != nullptr);
if (!Server.IsValid()) {
UE_LOG(LogCarlaServer, Warning, TEXT("Client disconnected, server needs restart"));
RestartLevel();
return;
}
// Check if the client requested a new episode.
{
FString IniFile;
auto ec = Server->ReadNewEpisode(IniFile, NON_BLOCKING);
switch (ec) {
case Errc::Success:
CarlaSettings->LoadSettingsFromString(IniFile);
RestartLevel();
return;
case Errc::Error:
Server = nullptr;
return;
default:
break; // fallthrough...
}
}
// Send measurements.
{
if (CarlaSettings->bSynchronousMode)
{
FlushRenderingCommands();
}
if (Errc::Error == Server->SendMeasurements(
DataRouter.GetPlayerState(),
DataRouter.GetAgents(),
CarlaSettings->bSendNonPlayerAgentsInfo))
{
// The error here must be ignored, otherwise we can create a race
// condition between the different ports.
return;
}
}
// Read control, block if the settings say so.
{
const bool bShouldBlock = CarlaSettings->bSynchronousMode;
FVehicleControl Control;
if (Errc::Error != Server->ReadControl(Control, bShouldBlock))
{
DataRouter.ApplyVehicleControl(Control, EVehicleInputPriority::Client);
} // Here we ignore the error too.
}
}
void FServerGameController::RestartLevel()
{
UE_LOG(LogCarlaServer, Log, TEXT("Restarting the level..."));
DataRouter.RestartLevel();
}

View File

@ -1,39 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Game/CarlaGameControllerBase.h"
class FCarlaServer;
/// Implements remote control of game and player.
class FServerGameController : public ICarlaGameControllerBase
{
public:
FServerGameController(FDataRouter &DataRouter);
~FServerGameController();
virtual void Initialize(UCarlaSettings &CarlaSettings) final;
virtual APlayerStart *ChoosePlayerStart(const TArray<APlayerStart *> &AvailableStartSpots) final;
virtual void RegisterPlayer(AController &NewPlayer) final;
virtual void BeginPlay() final;
virtual void Tick(float DeltaSeconds) final;
private:
void RestartLevel();
TSharedPtr<FCarlaServer> Server;
UCarlaSettings *CarlaSettings = nullptr;
};

View File

@ -1,52 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Engine/Scene.h"
#include "CameraPostProcessParameters.generated.h"
/**
* Some post-process parameters that can be overriden per camera depending on
* the weather and lighting conditions.
*/
USTRUCT(BlueprintType)
struct CARLA_API FCameraPostProcessParameters
{
GENERATED_USTRUCT_BODY()
/** Luminance computation method */
UPROPERTY(Category = "Camera Parameters", EditAnywhere, BlueprintReadWrite)
TEnumAsByte<enum EAutoExposureMethod> AutoExposureMethod = AEM_Histogram;
/**
* A good value should be positive near 0. This is the minimum brightness the auto exposure can adapt to.
* It should be tweaked in a dark lighting situation (too small: image appears too bright, too large: image appears too dark).
* Note: Tweaking emissive materials and lights or tweaking auto exposure can look the same. Tweaking auto exposure has global
* effect and defined the HDR range - you don't want to change that late in the project development.
* Eye Adaptation is disabled if MinBrightness = MaxBrightness
*/
UPROPERTY(Category = "Camera Parameters", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", UIMax = "10.0"))
float AutoExposureMinBrightness = 0.03f;
/**
* A good value should be positive (2 is a good value). This is the maximum brightness the auto exposure can adapt to.
* It should be tweaked in a bright lighting situation (too small: image appears too bright, too large: image appears too dark).
* Note: Tweaking emissive materials and lights or tweaking auto exposure can look the same. Tweaking auto exposure has global
* effect and defined the HDR range - you don't want to change that late in the project development.
* Eye Adaptation is disabled if MinBrightness = MaxBrightness
*/
UPROPERTY(Category = "Camera Parameters", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", UIMax = "10.0"))
float AutoExposureMaxBrightness = 2.0f;
/**
* Logarithmic adjustment for the exposure. Only used if a tonemapper is specified.
* 0: no adjustment, -1:2x darker, -2:4x darker, 1:2x brighter, 2:4x brighter, ...
*/
UPROPERTY(Category = "Camera Parameters", EditAnywhere, BlueprintReadWrite, meta = (UIMin = "-8.0", UIMax = "8.0"))
float AutoExposureBias = 0.0f;
};

View File

@ -5,24 +5,23 @@
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "CarlaSettings.h"
#include "DynamicWeather.h"
#include "Util/IniFile.h"
#include "Package.h"
#include "Carla/Settings/CarlaSettings.h"
#include "Carla/Util/IniFile.h"
#include "CommandLine.h"
#include "UnrealMathUtility.h"
#include "Engine/Engine.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/DirectionalLight.h"
#include "Engine/Engine.h"
#include "Engine/PointLight.h"
#include "Engine/StaticMesh.h"
#include "Engine/PostProcessVolume.h"
#include "Engine/StaticMesh.h"
#include "Kismet/GameplayStatics.h"
#include "Materials/MaterialInstance.h"
#include "Package.h"
#include "UnrealMathUtility.h"
// INI file sections.
#define S_CARLA_SERVER TEXT("CARLA/Server")
#define S_CARLA_LEVELSETTINGS TEXT("CARLA/LevelSettings")
#define S_CARLA_SENSOR TEXT("CARLA/Sensor")
#define S_CARLA_QUALITYSETTINGS TEXT("CARLA/QualitySettings")
// =============================================================================
@ -36,33 +35,6 @@ const FName UCarlaSettings::CARLA_SKY_TAG = FName("CARLA_SKY");
// -- Static methods -----------------------------------------------------------
// =============================================================================
template <typename T>
static void ForEachSectionInName(const FString &SensorName, T &&Callback)
{
TArray<FString> SubSections;
SensorName.ParseIntoArray(SubSections, TEXT("/"), true);
check(SubSections.Num() > 0);
FString Section = S_CARLA_SENSOR;
Callback(Section);
for (FString &SubSection : SubSections)
{
Section += TEXT("/");
Section += SubSection;
Callback(Section);
}
}
static FString GetSensorType(
const FIniFile &ConfigFile,
const FString &SensorName)
{
FString SensorType;
ForEachSectionInName(SensorName, [&](const auto &Section) {
ConfigFile.GetString(*Section, TEXT("SensorType"), SensorType);
});
return SensorType;
}
static EQualityLevel QualityLevelFromString(
const FString &SQualitySettingsLevel,
const EQualityLevel Default = EQualityLevel::INVALID)
@ -96,24 +68,12 @@ static void LoadSettingsFromConfig(
// CarlaServer.
if (bLoadCarlaServerSection)
{
ConfigFile.GetBool(S_CARLA_SERVER, TEXT("UseNetworking"), Settings.bUseNetworking);
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WorldPort"), Settings.WorldPort);
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("WorldPort"), Settings.RPCPort);
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("RPCPort"), Settings.RPCPort);
ConfigFile.GetInt(S_CARLA_SERVER, TEXT("ServerTimeOut"), Settings.ServerTimeOut);
}
ConfigFile.GetBool(S_CARLA_SERVER, TEXT("SynchronousMode"), Settings.bSynchronousMode);
ConfigFile.GetBool(S_CARLA_SERVER, TEXT("SendNonPlayerAgentsInfo"), Settings.bSendNonPlayerAgentsInfo);
ConfigFile.GetBool(S_CARLA_SERVER, TEXT("DisableRendering"), Settings.bDisableRendering);
// LevelSettings.
ConfigFile.GetString(S_CARLA_LEVELSETTINGS, TEXT("PlayerVehicle"), Settings.PlayerVehicle);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfVehicles"), Settings.NumberOfVehicles);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("NumberOfPedestrians"), Settings.NumberOfPedestrians);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("WeatherId"), Settings.WeatherId);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("SeedVehicles"), Settings.SeedVehicles);
ConfigFile.GetInt(S_CARLA_LEVELSETTINGS, TEXT("SeedPedestrians"), Settings.SeedPedestrians);
ConfigFile.GetBool(S_CARLA_LEVELSETTINGS,
TEXT("DisableTwoWheeledVehicles"),
Settings.bDisableTwoWheeledVehicles);
// QualitySettings.
FString sQualityLevel;
ConfigFile.GetString(S_CARLA_QUALITYSETTINGS, TEXT("QualityLevel"), sQualityLevel);
@ -152,27 +112,18 @@ void UCarlaSettings::LoadSettings()
}
// Override settings from command-line.
{
if (FParse::Param(FCommandLine::Get(), TEXT("carla-server")))
{
bUseNetworking = true;
}
uint32 Value;
if (FParse::Value(FCommandLine::Get(), TEXT("-world-port="), Value) ||
FParse::Value(FCommandLine::Get(), TEXT("-carla-port="), Value) ||
FParse::Value(FCommandLine::Get(), TEXT("-carla-rpc-port="), Value) ||
FParse::Value(FCommandLine::Get(), TEXT("-carla-world-port="), Value))
{
WorldPort = Value;
bUseNetworking = true;
RPCPort = Value;
}
if (FParse::Value(FCommandLine::Get(), TEXT("-carla-streaming-port="), Value))
{
StreamingPort = Value;
}
if (FParse::Param(FCommandLine::Get(), TEXT("carla-no-networking")))
{
bUseNetworking = false;
}
FString StringQualityLevel;
if (FParse::Value(FCommandLine::Get(), TEXT("-quality-level="), StringQualityLevel))
{
@ -199,22 +150,6 @@ void UCarlaSettings::LoadSettingsFromString(const FString &INIFileContents)
CurrentFileName = TEXT("<string-provided-by-client>");
}
void UCarlaSettings::LoadWeatherDescriptions()
{
WeatherDescriptions.Empty();
ADynamicWeather::LoadWeatherDescriptionsFromFile(MapName, WeatherDescriptions);
check(WeatherDescriptions.Num() > 0);
}
void UCarlaSettings::ValidateWeatherId()
{
if (WeatherId >= WeatherDescriptions.Num())
{
UE_LOG(LogCarla, Error, TEXT("Provided weather id %d cannot be found"), WeatherId);
WeatherId = -1;
}
}
void UCarlaSettings::LogSettings() const
{
auto EnabledDisabled = [](bool bValue) { return (bValue ? TEXT("Enabled") : TEXT("Disabled")); };
@ -222,61 +157,19 @@ void UCarlaSettings::LogSettings() const
TEXT("== CARLA Settings =============================================================="));
UE_LOG(LogCarla, Log, TEXT("Last settings file loaded: %s"), *CurrentFileName);
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SERVER);
UE_LOG(LogCarla, Log, TEXT("Networking = %s"), EnabledDisabled(bUseNetworking));
UE_LOG(LogCarla, Log, TEXT("World Port = %d"), WorldPort);
UE_LOG(LogCarla, Log, TEXT("RPC Port = %d"), RPCPort);
UE_LOG(LogCarla, Log, TEXT("Streaming Port = %d"), StreamingPort.Get(RPCPort + 1u));
UE_LOG(LogCarla, Log, TEXT("Server Time-out = %d ms"), ServerTimeOut);
UE_LOG(LogCarla, Log, TEXT("Synchronous Mode = %s"), EnabledDisabled(bSynchronousMode));
UE_LOG(LogCarla, Log, TEXT("Send Non-Player Agents Info = %s"), EnabledDisabled(bSendNonPlayerAgentsInfo));
UE_LOG(LogCarla, Log, TEXT("Rendering = %s"), EnabledDisabled(!bDisableRendering));
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_LEVELSETTINGS);
UE_LOG(LogCarla, Log, TEXT("Player Vehicle = %s"),
(PlayerVehicle.IsEmpty() ? TEXT("Default") : *PlayerVehicle));
UE_LOG(LogCarla, Log, TEXT("Number Of Vehicles = %d"), NumberOfVehicles);
UE_LOG(LogCarla, Log, TEXT("Number Of Pedestrians = %d"), NumberOfPedestrians);
UE_LOG(LogCarla, Log, TEXT("Weather Id = %d"), WeatherId);
UE_LOG(LogCarla, Log, TEXT("Seed Vehicle Spawner = %d"), SeedVehicles);
UE_LOG(LogCarla, Log, TEXT("Seed Pedestrian Spawner = %d"), SeedPedestrians);
UE_LOG(LogCarla, Log, TEXT("Two-Wheeled Vehicles = %s"), EnabledDisabled(!bDisableTwoWheeledVehicles));
UE_LOG(LogCarla, Log, TEXT("Found %d available weather settings."), WeatherDescriptions.Num());
for (auto i = 0; i < WeatherDescriptions.Num(); ++i)
{
UE_LOG(LogCarla, Log, TEXT(" * %d - %s"), i, *WeatherDescriptions[i].Name);
}
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_QUALITYSETTINGS);
UE_LOG(LogCarla, Log, TEXT("Quality Level = %s"), *QualityLevelToString(QualityLevel));
UE_LOG(LogCarla, Log, TEXT("[%s]"), S_CARLA_SENSOR);
UE_LOG(LogCarla, Log, TEXT("Semantic Segmentation = %s"), EnabledDisabled(bSemanticSegmentationEnabled));
UE_LOG(LogCarla, Log,
TEXT("================================================================================"));
}
#undef S_CARLA_QUALITYSETTINGS
#undef S_CARLA_SERVER
#undef S_CARLA_LEVELSETTINGS
#undef S_CARLA_SENSOR
void UCarlaSettings::GetActiveWeatherDescription(
bool &bWeatherWasChanged,
FWeatherDescription &WeatherDescription) const
{
auto WeatherPtr = GetActiveWeatherDescription();
if (WeatherPtr != nullptr)
{
WeatherDescription = *WeatherPtr;
bWeatherWasChanged = true;
}
else
{
bWeatherWasChanged = false;
}
}
const FWeatherDescription &UCarlaSettings::GetWeatherDescriptionByIndex(int32 Index)
{
check(WeatherDescriptions.Num() > 0);
FMath::Clamp(Index, 0, WeatherDescriptions.Num());
return WeatherDescriptions[Index];
}
void UCarlaSettings::LoadSettingsFromFile(const FString &FilePath, const bool bLogOnFailure)
{

View File

@ -9,7 +9,6 @@
#include "Engine/StaticMesh.h"
#include "Carla/Settings/QualityLevelUE.h"
#include "Carla/Settings/WeatherDescription.h"
#include "CarlaSettings.generated.h"
@ -52,36 +51,9 @@ public:
/// section is ignored.
void LoadSettingsFromString(const FString &INIFileContents);
/// Load weather description from config files. (There may be overrides for
/// each map).
void LoadWeatherDescriptions();
/// Check if requested weather id is present in WeatherDescriptions.
void ValidateWeatherId();
/// Log settings values.
void LogSettings() const;
const FWeatherDescription *GetActiveWeatherDescription() const
{
if ((WeatherId >= 0) && (WeatherId < WeatherDescriptions.Num()))
{
return &WeatherDescriptions[WeatherId];
}
return nullptr;
}
// Special overload for blueprints.
UFUNCTION(BlueprintCallable, Category = "CARLA Settings")
void GetActiveWeatherDescription(
bool &bWeatherWasChanged,
FWeatherDescription &WeatherDescription) const;
UFUNCTION(BlueprintCallable)
const FWeatherDescription &GetWeatherDescriptionByIndex(int32 Index);
/// ----------- constants ------------------
public:
/// CARLA_ROAD name to tag road mesh actors.
@ -106,13 +78,9 @@ private:
public:
/// If active, wait for the client to connect and control the pawn.
UPROPERTY(Category = "CARLA Server", VisibleAnywhere)
bool bUseNetworking = false;
/// World port to listen for client connections.
UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking))
uint32 WorldPort = 2000u;
uint32 RPCPort = 2000u;
/// Optional setting for the secondary port.
TOptional<uint32> StreamingPort;
@ -126,62 +94,11 @@ public:
UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking))
bool bSynchronousMode = false;
/// Send info about every non-player agent in the scene every frame.
UPROPERTY(Category = "CARLA Server", VisibleAnywhere, meta = (EditCondition = bUseNetworking))
bool bSendNonPlayerAgentsInfo = false;
/// Enable or disable the viewport rendering of the world. Disabled by
/// default.
UPROPERTY(Category = "CARLA Server", VisibleAnywhere)
bool bDisableRendering = false;
/// @}
// ===========================================================================
/// @name Level Settings
// ===========================================================================
/// @{
public:
/// Display name of the current map.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
FString MapName;
/// Path to the pawn class of the player.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
FString PlayerVehicle;
/// Number of NPC vehicles to be spawned into the level.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
uint32 NumberOfVehicles = 5u;
/// Number of NPC pedestrians to be spawned into the level.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
uint32 NumberOfPedestrians = 15u;
/// Index of the weather setting to use. If negative, weather won't be
/// changed.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
int32 WeatherId = -1;
/// Available weather settings.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
TArray<FWeatherDescription> WeatherDescriptions;
/// Random seed for the pedestrian spawner.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
int32 SeedPedestrians = 123456789;
/// Random seed for the vehicle spawner.
UPROPERTY(Category = "Level Settings", VisibleAnywhere)
int32 SeedVehicles = 123456789;
/// Disable bikes and motorbikes.
UPROPERTY(Category = "Level Settings", BlueprintReadOnly, VisibleAnywhere)
bool bDisableTwoWheeledVehicles = false;
/// @}
// ===========================================================================
/// @name Quality Settings
// ===========================================================================
@ -233,19 +150,4 @@ public:
TArray<FStaticMaterial> EpicRoadMaterials;
/// @}
// ===========================================================================
/// @name Sensors
// ===========================================================================
/// @{
public:
/// Whether semantic segmentation should be activated. The mechanisms for
/// semantic segmentation impose some performance penalties even if it is not
/// used, we only enable it if necessary.
UPROPERTY(Category = "Sensors", BlueprintReadOnly, VisibleAnywhere)
bool bSemanticSegmentationEnabled = true;
/// @}
};

View File

@ -1,19 +1,19 @@
#include "Carla.h"
#include "Carla/Settings/CarlaSettingsDelegate.h"
#include "Carla/Settings/CarlaSettings.h"
#include "Game/CarlaGameModeBase.h"
#include "Settings/CarlaSettings.h"
#include "CarlaSettingsDelegate.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/Engine.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/DirectionalLight.h"
#include "Engine/StaticMesh.h"
#include "Engine/PostProcessVolume.h"
#include "Async.h"
#include "Landscape.h"
#include "InstancedFoliageActor.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/DirectionalLight.h"
#include "Engine/Engine.h"
#include "Engine/LocalPlayer.h"
#include "Engine/PostProcessVolume.h"
#include "Engine/StaticMesh.h"
#include "GameFramework/HUD.h"
#include "InstancedFoliageActor.h"
#include "Kismet/GameplayStatics.h"
#include "Landscape.h"
static constexpr float CARLA_SETTINGS_MAX_SCALE_SIZE = 50.0f;

View File

@ -1,146 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "WeatherDescription.h"
#include "Util/IniFile.h"
static FString PrecipitationTypeToString(EPrecipitationType PrecipitationType)
{
const UEnum* ptr = FindObject<UEnum>(ANY_PACKAGE, TEXT("EPrecipitationType"), true);
if(!ptr)
return FString("Rain");
return ptr->GetNameStringByIndex(static_cast<int32>(PrecipitationType));
}
static void LoadPrecipitationType(
const FIniFile &ConfigFile,
const TCHAR* Section,
const TCHAR* Key,
EPrecipitationType &Target)
{
FString ValueString;
if (ConfigFile.GetFConfigFile().GetString(Section, Key, ValueString)) {
if (ValueString == "Rain") {
Target = EPrecipitationType::Rain;
} else {
UE_LOG(LogCarla, Error, TEXT("Invalid precipitation type \"%s\" in INI file"), *ValueString);
Target = EPrecipitationType::Rain;
}
}
}
static FString AutoExposureMethodToString(EAutoExposureMethod AutoExposureMethod)
{
switch (AutoExposureMethod) {
case AEM_Histogram: return "Histogram";
case AEM_Basic: return "Basic";
default: return "INVALID";
};
}
static void LoadAutoExposureMethod(
const FIniFile &ConfigFile,
const TCHAR* Section,
const TCHAR* Key,
EAutoExposureMethod &Target)
{
FString ValueString;
if (ConfigFile.GetFConfigFile().GetString(Section, Key, ValueString)) {
if (ValueString == "Basic") {
Target = AEM_Basic;
} else {
Target = AEM_Histogram;
}
}
}
void FWeatherDescription::ReadFromConfigFile(const FIniFile &ConfigFile, const FString &Section)
{
Name = Section;
#define CARLA_LOAD_FROM_INI(Type, Key) ConfigFile.Get ## Type(*Section, TEXT(#Key), Key);
// Sun.
CARLA_LOAD_FROM_INI(Float, SunPolarAngle)
CARLA_LOAD_FROM_INI(Float, SunAzimuthAngle)
CARLA_LOAD_FROM_INI(Float, SunBrightness)
CARLA_LOAD_FROM_INI(Float, SunDirectionalLightIntensity)
CARLA_LOAD_FROM_INI(LinearColor, SunDirectionalLightColor)
CARLA_LOAD_FROM_INI(Float, SunIndirectLightIntensity)
// Sky.
CARLA_LOAD_FROM_INI(Float, CloudOpacity)
CARLA_LOAD_FROM_INI(Float, HorizontFalloff)
CARLA_LOAD_FROM_INI(LinearColor, ZenithColor)
CARLA_LOAD_FROM_INI(LinearColor, HorizonColor)
CARLA_LOAD_FROM_INI(LinearColor, CloudColor)
CARLA_LOAD_FROM_INI(LinearColor, OverallSkyColor)
CARLA_LOAD_FROM_INI(Float, SkyLightIntensity)
CARLA_LOAD_FROM_INI(LinearColor, SkyLightColor)
// Precipitation.
CARLA_LOAD_FROM_INI(Bool, bPrecipitation)
LoadPrecipitationType(ConfigFile, *Section, TEXT("PrecipitationType"), PrecipitationType);
CARLA_LOAD_FROM_INI(Float, PrecipitationAmount)
CARLA_LOAD_FROM_INI(Float, PrecipitationAccumulation)
// Wind.
CARLA_LOAD_FROM_INI(Bool, bWind)
CARLA_LOAD_FROM_INI(Float, WindIntensity)
CARLA_LOAD_FROM_INI(Float, WindAngle)
// Camera Post-Process Parameters.
CARLA_LOAD_FROM_INI(Bool, bOverrideCameraPostProcessParameters)
EAutoExposureMethod AutoExposureMethod;
LoadAutoExposureMethod(
ConfigFile,
*Section,
TEXT("CameraPostProcessParameters.AutoExposureMethod"),
AutoExposureMethod);
CameraPostProcessParameters.AutoExposureMethod = AutoExposureMethod;
CARLA_LOAD_FROM_INI(Float, CameraPostProcessParameters.AutoExposureMinBrightness)
CARLA_LOAD_FROM_INI(Float, CameraPostProcessParameters.AutoExposureMaxBrightness)
CARLA_LOAD_FROM_INI(Float, CameraPostProcessParameters.AutoExposureBias)
#undef CARLA_LOAD_FROM_INI
}
void FWeatherDescription::WriteToConfigFile(FIniFile &ConfigFile) const
{
const FString &Section = Name;
ConfigFile.AddSectionIfMissing(Section);
#define CARLA_WRITE_TO_INI(Type, Key) ConfigFile.Set ## Type(*Section, TEXT(#Key), Key);
// Sun.
CARLA_WRITE_TO_INI(Float, SunPolarAngle)
CARLA_WRITE_TO_INI(Float, SunAzimuthAngle)
CARLA_WRITE_TO_INI(Float, SunBrightness)
CARLA_WRITE_TO_INI(Float, SunDirectionalLightIntensity)
CARLA_WRITE_TO_INI(LinearColor, SunDirectionalLightColor)
CARLA_WRITE_TO_INI(Float, SunIndirectLightIntensity)
// Sky.
CARLA_WRITE_TO_INI(Float, CloudOpacity)
CARLA_WRITE_TO_INI(Float, HorizontFalloff)
CARLA_WRITE_TO_INI(LinearColor, ZenithColor)
CARLA_WRITE_TO_INI(LinearColor, HorizonColor)
CARLA_WRITE_TO_INI(LinearColor, CloudColor)
CARLA_WRITE_TO_INI(LinearColor, OverallSkyColor)
CARLA_WRITE_TO_INI(Float, SkyLightIntensity)
CARLA_WRITE_TO_INI(LinearColor, SkyLightColor)
// Precipitation.
CARLA_WRITE_TO_INI(Bool, bPrecipitation)
ConfigFile.SetString(*Section, TEXT("PrecipitationType"), PrecipitationTypeToString(PrecipitationType));
CARLA_WRITE_TO_INI(Float, PrecipitationAmount)
CARLA_WRITE_TO_INI(Float, PrecipitationAccumulation)
// Wind.
CARLA_WRITE_TO_INI(Bool, bWind)
CARLA_WRITE_TO_INI(Float, WindIntensity)
CARLA_WRITE_TO_INI(Float, WindAngle)
// Camera Post-Process Parameters.
CARLA_WRITE_TO_INI(Bool, bOverrideCameraPostProcessParameters)
ConfigFile.SetString(
*Section,
TEXT("CameraPostProcessParameters.AutoExposureMethod"),
AutoExposureMethodToString(CameraPostProcessParameters.AutoExposureMethod.GetValue()));
CARLA_WRITE_TO_INI(Float, CameraPostProcessParameters.AutoExposureMinBrightness)
CARLA_WRITE_TO_INI(Float, CameraPostProcessParameters.AutoExposureMaxBrightness)
CARLA_WRITE_TO_INI(Float, CameraPostProcessParameters.AutoExposureBias)
#undef CARLA_WRITE_TO_INI
}

View File

@ -1,162 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Settings/CameraPostProcessParameters.h"
#include "WeatherDescription.generated.h"
class FIniFile;
UENUM(BlueprintType)
enum class EPrecipitationType : uint8
{
Rain UMETA(DisplayName = "Rain")
};
USTRUCT(BlueprintType)
struct CARLA_API FWeatherDescription
{
GENERATED_USTRUCT_BODY()
void ReadFromConfigFile(const FIniFile &ConfigFile, const FString &Section);
void WriteToConfigFile(FIniFile &ConfigFile) const;
// ===========================================================================
/// @name Weather
// ===========================================================================
/// @{
/** Display name of the current weather. */
UPROPERTY(Category = "Weather", EditAnywhere, BlueprintReadWrite)
FString Name;
/// @}
// ===========================================================================
/// @name Weather - Sun
// ===========================================================================
/// @{
/** Polar angle of the Sun in degrees, with 0.0 at zenith, 90.0 at equator. */
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "0.0", ClampMax = "180.0"))
float SunPolarAngle = 45.0f;
/** Azimuth angle of the Sun in degrees. */
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta = (ClampMin = "-180.0", ClampMax = "180.0"))
float SunAzimuthAngle = 0.0f;
/** */
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
float SunBrightness = 50.0f;
/** */
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
float SunDirectionalLightIntensity = 5.0f;
/** */
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite)
FLinearColor SunDirectionalLightColor = FLinearColor(255.0f, 240.0f, 195.0f);
/** */
UPROPERTY(Category = "Weather|Sun", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
float SunIndirectLightIntensity = 6.0f;
/// @}
// ===========================================================================
/// @name Weather - Sky
// ===========================================================================
/// @{
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
float CloudOpacity = 10.0f;
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
float HorizontFalloff = 3.0f;
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
FLinearColor ZenithColor = FLinearColor(0.0340f, 0.1092f, 0.2950f);
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
FLinearColor HorizonColor = FLinearColor(0.6599f, 0.8622f, 1.0f);
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
FLinearColor CloudColor = FLinearColor(0.8558f, 0.9190f, 1.0f);
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
FLinearColor OverallSkyColor = FLinearColor(1.0f, 1.0f, 1.0f);
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite, meta=(ClampMin = "0.0", ClampMax = "100.0"))
float SkyLightIntensity = 4.0f;
/** */
UPROPERTY(Category = "Weather|Sky", EditAnywhere, BlueprintReadWrite)
FLinearColor SkyLightColor = FLinearColor(0.1950f, 0.1851f, 0.1413f, 0.0f);
/// @}
// ===========================================================================
/// @name Weather - Precipitation
// ===========================================================================
/// @{
/** */
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite)
bool bPrecipitation = false;
/** */
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation"))
EPrecipitationType PrecipitationType = EPrecipitationType::Rain;
/** */
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation", ClampMin = "0.0", ClampMax = "100.0"))
float PrecipitationAmount = 50.0f;
/** */
UPROPERTY(Category = "Weather|Precipitation", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bPrecipitation", ClampMin = "0.0", ClampMax = "100.0"))
float PrecipitationAccumulation = 50.0f;
/// @}
// ===========================================================================
/// @name Weather - Wind
// ===========================================================================
/// @{
/** */
UPROPERTY(Category = "Weather|Wind", EditAnywhere, BlueprintReadWrite)
bool bWind = false;
/** */
UPROPERTY(Category = "Weather|Wind", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bWind", ClampMin = "0.0", ClampMax = "100.0"))
float WindIntensity = 20.0f;
/** */
UPROPERTY(Category = "Weather|Wind", EditAnywhere, BlueprintReadWrite, meta=(EditCondition="bWind", ClampMin = "-180.0", ClampMax = "180.0"))
float WindAngle = 0.0f;
/// @}
// ===========================================================================
/// @name Weather - Camera Post-Process Parameters
// ===========================================================================
/// @{
/** If disabled the camera default values will be used instead. */
UPROPERTY(Category = "Weather|Camera Post-Process Parameters", EditAnywhere, BlueprintReadWrite)
bool bOverrideCameraPostProcessParameters = false;
/** Camera post-process parameters to be overriden. */
UPROPERTY(Category = "Weather|Camera Post-Process Parameters", EditAnywhere, BlueprintReadWrite, meta=(EditCondition = "bOverrideCameraPostProcessParameters"))
FCameraPostProcessParameters CameraPostProcessParameters;
/// @}
};

View File

@ -14,9 +14,4 @@ ATrafficSignBase::ATrafficSignBase(const FObjectInitializer &ObjectInitializer)
RootComponent =
ObjectInitializer.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneRootComponent"));
RootComponent->SetMobility(EComponentMobility::Static);
TrafficSignAgentComponent =
CreateDefaultSubobject<UTrafficSignAgentComponent>(TEXT("TrafficSignAgentComponent"));
TrafficSignAgentComponent->SetupAttachment(RootComponent);
TrafficSignAgentComponent->SetMobility(EComponentMobility::Static);
}

View File

@ -8,8 +8,6 @@
#include "GameFramework/Actor.h"
#include "Carla/Agent/TrafficSignAgentComponent.h"
#include "TrafficSignBase.generated.h"
class UBoxComponent;
@ -60,7 +58,4 @@ private:
UPROPERTY(Category = "Traffic Sign", EditAnywhere)
ETrafficSignState TrafficSignState = ETrafficSignState::UNKNOWN;
UPROPERTY(Category = "Traffic Sign", VisibleAnywhere)
UTrafficSignAgentComponent *TrafficSignAgentComponent;
};

View File

@ -1,125 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "CarlaVehicleController.h"
#include "Components/BoxComponent.h"
#include "EngineUtils.h"
#include "GameFramework/Pawn.h"
#include "WheeledVehicle.h"
#include "WheeledVehicleMovementComponent.h"
// =============================================================================
// -- Constructor and destructor -----------------------------------------------
// =============================================================================
ACarlaVehicleController::ACarlaVehicleController(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
}
ACarlaVehicleController::~ACarlaVehicleController() {}
// =============================================================================
// -- APlayerController --------------------------------------------------------
// =============================================================================
void ACarlaVehicleController::Possess(APawn *aPawn)
{
Super::Possess(aPawn);
if (IsPossessingAVehicle()) {
// Bind hit events.
aPawn->OnActorHit.AddDynamic(this, &ACarlaVehicleController::OnCollisionEvent);
// Get custom player state.
CarlaPlayerState = Cast<ACarlaPlayerState>(PlayerState);
check(CarlaPlayerState != nullptr);
// We can set the bounding box already as it's not going to change.
CarlaPlayerState->BoundingBoxTransform = GetPossessedVehicle()->GetVehicleBoundingBoxTransform();
CarlaPlayerState->BoundingBoxExtent = GetPossessedVehicle()->GetVehicleBoundingBoxExtent();
// Set HUD input.
CarlaHUD = Cast<ACarlaHUD>(GetHUD());
if (CarlaHUD != nullptr) {
InputComponent->BindAction("ToggleHUD", IE_Pressed, CarlaHUD, &ACarlaHUD::ToggleHUDView);
CarlaHUD->bShowHUD = !(Cast<UCarlaGameInstance>(GetWorld()->GetGameInstance())->GetCarlaSettings().bDisableRendering);
CarlaHUD->SetVisible(CarlaHUD->bShowHUD);
} else {
UE_LOG(LogCarla, Warning, TEXT("Current HUD is not a ACarlaHUD"));
}
}
}
// =============================================================================
// -- AActor -------------------------------------------------------------------
// =============================================================================
void ACarlaVehicleController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (IsPossessingAVehicle()) {
auto CurrentVehicle = GetPossessedVehicle();
CarlaPlayerState->UpdateTimeStamp(DeltaTime);
const FVector PreviousSpeed = CarlaPlayerState->ForwardSpeed * CarlaPlayerState->GetOrientation();
CarlaPlayerState->Transform = CurrentVehicle->GetVehicleTransform();
CarlaPlayerState->ForwardSpeed = CurrentVehicle->GetVehicleForwardSpeed();
const FVector CurrentSpeed = CarlaPlayerState->ForwardSpeed * CarlaPlayerState->GetOrientation();
CarlaPlayerState->Acceleration = (CurrentSpeed - PreviousSpeed) / DeltaTime;
const auto &AutopilotCtrl = GetAutopilotControl();
CarlaPlayerState->Steer = AutopilotCtrl.Steer;
CarlaPlayerState->Throttle = AutopilotCtrl.Throttle;
CarlaPlayerState->Brake = AutopilotCtrl.Brake;
CarlaPlayerState->bHandBrake = AutopilotCtrl.bHandBrake;
CarlaPlayerState->CurrentGear = CurrentVehicle->GetVehicleCurrentGear();
CarlaPlayerState->SpeedLimit = GetSpeedLimit();
CarlaPlayerState->TrafficLightState = GetTrafficLightState();
IntersectPlayerWithRoadMap();
}
}
// =============================================================================
// -- Events -------------------------------------------------------------------
// =============================================================================
void ACarlaVehicleController::OnCollisionEvent(
AActor* Actor,
AActor* OtherActor,
FVector NormalImpulse,
const FHitResult& Hit)
{
// Register collision only if we are moving faster than 1 km/h.
check(IsPossessingAVehicle());
if (FMath::Abs(GetPossessedVehicle()->GetVehicleForwardSpeed() * 0.036f) > 1.0f) {
CarlaPlayerState->RegisterCollision(Actor, OtherActor, NormalImpulse, Hit);
}
}
// =============================================================================
// -- Other --------------------------------------------------------------------
// =============================================================================
void ACarlaVehicleController::IntersectPlayerWithRoadMap()
{
auto CurrentRoadMap = GetRoadMap();
if (CurrentRoadMap == nullptr) {
return;
}
check(IsPossessingAVehicle());
auto CurrentVehicle = GetPossessedVehicle();
constexpr float ChecksPerCentimeter = 0.1f;
const auto *BoundingBox = CurrentVehicle->GetVehicleBoundingBox();
check(BoundingBox != nullptr);
auto Result = CurrentRoadMap->Intersect(
BoundingBox->GetComponentTransform(),
BoundingBox->GetUnscaledBoxExtent(),
ChecksPerCentimeter);
CarlaPlayerState->OffRoadIntersectionFactor = Result.OffRoad;
CarlaPlayerState->OtherLaneIntersectionFactor = Result.OppositeLane;
}

View File

@ -1,116 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Vehicle/WheeledVehicleController.h"
#include "CarlaVehicleController.generated.h"
struct FCameraPostProcessParameters;
class ACarlaHUD;
class ACarlaPlayerState;
class ALidar;
class ASceneCaptureCamera;
class UCameraDescription;
class ULidarDescription;
struct FCameraPostProcessParameters;
/// The CARLA player controller.
UCLASS()
class CARLA_API ACarlaVehicleController : public AWheeledVehicleController
{
GENERATED_BODY()
// ===========================================================================
/// @name Constructor and destructor
// ===========================================================================
/// @{
public:
ACarlaVehicleController(const FObjectInitializer& ObjectInitializer);
~ACarlaVehicleController();
/// @}
// ===========================================================================
/// @name APlayerController overrides
// ===========================================================================
/// @{
public:
virtual void Possess(APawn *aPawn) override;
/// @}
// ===========================================================================
/// @name AActor overrides
// ===========================================================================
/// @{
public:
virtual void Tick(float DeltaTime) override;
/// @}
// ===========================================================================
/// @name AWheeledVehicleAIController overrides
// ===========================================================================
/// @{
public:
virtual bool IsPossessingThePlayer() const final
{
return true;
}
/// @}
// ===========================================================================
/// @name Player state
// ===========================================================================
/// @{
public:
const ACarlaPlayerState &GetPlayerState() const
{
return *CarlaPlayerState;
}
/// @}
// ===========================================================================
/// @name Events
// ===========================================================================
/// @{
private:
UFUNCTION()
void OnCollisionEvent(
AActor* Actor,
AActor* OtherActor,
FVector NormalImpulse,
const FHitResult& Hit);
/// @}
// ===========================================================================
/// @name Private methods
// ===========================================================================
/// @{
private:
void IntersectPlayerWithRoadMap();
/// @}
// ===========================================================================
// -- Member variables -------------------------------------------------------
// ===========================================================================
private:
// Cast for quick access to the custom player state.
UPROPERTY()
ACarlaPlayerState *CarlaPlayerState;
// Cast for quick access to the custom HUD.
UPROPERTY()
ACarlaHUD *CarlaHUD;
};

View File

@ -5,14 +5,13 @@
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "TireConfig.h"
#include "CarlaWheeledVehicle.h"
#include "VehicleWheel.h"
#include "Agent/VehicleAgentComponent.h"
#include "Carla/Vehicle/CarlaWheeledVehicle.h"
#include "Components/BoxComponent.h"
#include "Engine/CollisionProfile.h"
#include "TireConfig.h"
#include "VehicleWheel.h"
// =============================================================================
// -- Constructor and destructor -----------------------------------------------
// =============================================================================
@ -25,9 +24,6 @@ ACarlaWheeledVehicle::ACarlaWheeledVehicle(const FObjectInitializer& ObjectIniti
VehicleBounds->SetHiddenInGame(true);
VehicleBounds->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
VehicleAgentComponent = CreateDefaultSubobject<UVehicleAgentComponent>(TEXT("VehicleAgentComponent"));
VehicleAgentComponent->SetupAttachment(RootComponent);
GetVehicleMovementComponent()->bReverseAsBrake = false;
}

View File

@ -19,7 +19,6 @@
#include "CarlaWheeledVehicle.generated.h"
class UBoxComponent;
class UVehicleAgentComponent;
/// Base class for CARLA wheeled vehicles.
UCLASS()
@ -182,9 +181,6 @@ private:
UPROPERTY(Category = "CARLA Wheeled Vehicle", EditAnywhere)
UBoxComponent *VehicleBounds;
UPROPERTY(Category = "CARLA Wheeled Vehicle", VisibleAnywhere)
UVehicleAgentComponent *VehicleAgentComponent;
struct
{
EVehicleInputPriority Priority = EVehicleInputPriority::INVALID;

View File

@ -1,212 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "VehicleSpawnerBase.h"
#include "Util/RandomEngine.h"
#include "Vehicle/CarlaWheeledVehicle.h"
#include "Vehicle/WheeledVehicleAIController.h"
#include "EngineUtils.h"
#include "GameFramework/Character.h"
#include "GameFramework/PlayerStart.h"
#include "TimerManager.h"
#include "Kismet/GameplayStatics.h"
// =============================================================================
// -- Static local methods -----------------------------------------------------
// =============================================================================
static bool VehicleIsValid(const ACarlaWheeledVehicle *Vehicle)
{
return ((Vehicle != nullptr) && !Vehicle->IsPendingKill());
}
static AWheeledVehicleAIController *GetController(ACarlaWheeledVehicle *Vehicle)
{
return (VehicleIsValid(Vehicle) ? Cast<AWheeledVehicleAIController>(Vehicle->GetController()) : nullptr);
}
// =============================================================================
// -- AVehicleSpawnerBase ------------------------------------------------------
// =============================================================================
// Sets default values
AVehicleSpawnerBase::AVehicleSpawnerBase(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = false;
}
void AVehicleSpawnerBase::BeginPlay()
{
Super::BeginPlay();
NumberOfVehicles = FMath::Max(0, NumberOfVehicles);
// Allocate space for walkers.
Vehicles.Reserve(NumberOfVehicles);
// Find spawn points present in level.
for (TActorIterator<APlayerStart> It(GetWorld()); It; ++It) {
SpawnPoints.Add(*It);
}
UE_LOG(LogCarla, Log, TEXT("Found %d PlayerStart positions for spawning vehicles"), SpawnPoints.Num());
if (SpawnPoints.Num() < NumberOfVehicles && SpawnPoints.Num()>0)
{
UE_LOG(LogCarla, Warning, TEXT("We don't have enough spawn points (PlayerStart) for vehicles!"));
if(SpawnPoints.Num()==0)
{
UE_LOG(LogCarla, Error, TEXT("At least one spawn point (PlayerStart) is needed to spawn vehicles!"));
} else
{
UE_LOG(LogCarla, Log,
TEXT("To cover the %d vehicles to spawn after beginplay, it will spawn one new vehicle each %f seconds"),
NumberOfVehicles - SpawnPoints.Num(),
TimeBetweenSpawnAttemptsAfterBegin
)
;
}
}
if(NumberOfVehicles==0||SpawnPoints.Num()==0) bSpawnVehicles = false;
if (bSpawnVehicles)
{
GetRandomEngine()->Shuffle(SpawnPoints); //to get a random spawn point from the map
const int32 MaximumNumberOfAttempts = SpawnPoints.Num();
int32 NumberOfAttempts = 0;
int32 SpawnIndexCount = 0;
while ((NumberOfVehicles > Vehicles.Num()) && (NumberOfAttempts < MaximumNumberOfAttempts))
{
if(SpawnPoints.IsValidIndex(SpawnIndexCount))
{
if(SpawnVehicleAtSpawnPoint(*SpawnPoints[SpawnIndexCount])){
SpawnIndexCount++;
}
}
NumberOfAttempts++;
}
bool bAllSpawned = false;
if (NumberOfVehicles > SpawnIndexCount)
{
UE_LOG(LogCarla, Warning, TEXT("Requested %d vehicles, but we were only able to spawn %d"), NumberOfVehicles, SpawnIndexCount);
} else
{
if(SpawnIndexCount == NumberOfVehicles)
{
bAllSpawned = true;
}
}
if(!bAllSpawned)
{
UE_LOG(LogCarla, Log,
TEXT("Starting the timer to spawn the other %d vehicles, one per %f seconds"),
NumberOfVehicles - SpawnIndexCount,
TimeBetweenSpawnAttemptsAfterBegin
);
GetWorld()->GetTimerManager().SetTimer(AttemptTimerHandle,this, &AVehicleSpawnerBase::SpawnVehicleAttempt, TimeBetweenSpawnAttemptsAfterBegin,false,-1);
} else
{
UE_LOG(LogCarla, Log, TEXT("Spawned all %d requested vehicles"), NumberOfVehicles);
}
}
}
void AVehicleSpawnerBase::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
GetWorld()->GetTimerManager().ClearAllTimersForObject(this);
}
void AVehicleSpawnerBase::SetNumberOfVehicles(const int32 Count)
{
if (Count > 0)
{
bSpawnVehicles = true;
NumberOfVehicles = Count;
} else {
bSpawnVehicles = false;
}
}
void AVehicleSpawnerBase::TryToSpawnRandomVehicle()
{
auto SpawnPoint = GetRandomSpawnPoint();
if (SpawnPoint != nullptr)
{
SpawnVehicleAtSpawnPoint(*SpawnPoint);
} else {
UE_LOG(LogCarla, Error, TEXT("Unable to find spawn point"));
}
}
ACarlaWheeledVehicle* AVehicleSpawnerBase::SpawnVehicleAtSpawnPoint(
const APlayerStart &SpawnPoint)
{
ACarlaWheeledVehicle *Vehicle;
SpawnVehicle(SpawnPoint.GetActorTransform(), Vehicle);
if ((Vehicle != nullptr) && !Vehicle->IsPendingKill())
{
Vehicle->AIControllerClass = AWheeledVehicleAIController::StaticClass();
Vehicle->SpawnDefaultController();
auto Controller = GetController(Vehicle);
if (Controller != nullptr)
{ // Sometimes fails...
Controller->GetRandomEngine()->Seed(GetRandomEngine()->GenerateSeed());
Controller->SetRoadMap(GetRoadMap());
Controller->SetAutopilot(true);
Vehicles.Add(Vehicle);
} else {
UE_LOG(LogCarla, Error, TEXT("Something went wrong creating the controller for the new vehicle"));
Vehicle->Destroy();
}
}
return Vehicle;
}
void AVehicleSpawnerBase::SpawnVehicleAttempt()
{
if(Vehicles.Num()>=NumberOfVehicles)
{
UE_LOG(LogCarla, Log, TEXT("All vehicles spawned correctly"));
return;
}
APlayerStart* spawnpoint = GetRandomSpawnPoint();
APawn* playerpawn = UGameplayStatics::GetPlayerPawn(GetWorld(),0);
const float DistanceToPlayer = playerpawn&&spawnpoint? FVector::Distance(playerpawn->GetActorLocation(),spawnpoint->GetActorLocation()):0.0f;
float NextTime = TimeBetweenSpawnAttemptsAfterBegin;
if(DistanceToPlayer>DistanceToPlayerBetweenSpawnAttemptsAfterBegin)
{
if(SpawnVehicleAtSpawnPoint(*spawnpoint)!=nullptr)
{
UE_LOG(LogCarla, Log, TEXT("Vehicle %d/%d late spawned"), Vehicles.Num(), NumberOfVehicles);
}
} else
{
NextTime /= 2.0f;
}
if(Vehicles.Num()<NumberOfVehicles)
{
auto &timemanager = GetWorld()->GetTimerManager();
if(AttemptTimerHandle.IsValid()) timemanager.ClearTimer(AttemptTimerHandle);
timemanager.SetTimer(AttemptTimerHandle,this, &AVehicleSpawnerBase::SpawnVehicleAttempt,NextTime,false,-1);
} else
{
UE_LOG(LogCarla, Log, TEXT("All vehicles spawned correctly"));
}
}
APlayerStart *AVehicleSpawnerBase::GetRandomSpawnPoint()
{
return (SpawnPoints.Num() > 0 ? GetRandomEngine()->PickOne(SpawnPoints) : nullptr);
}

View File

@ -1,102 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Util/ActorWithRandomEngine.h"
#include "VehicleSpawnerBase.generated.h"
class ACarlaWheeledVehicle;
class APlayerStart;
UCLASS(Abstract)
class CARLA_API AVehicleSpawnerBase : public AActorWithRandomEngine
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AVehicleSpawnerBase(const FObjectInitializer& ObjectInitializer);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called when the actor is removed from the level
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
UFUNCTION(BlueprintImplementableEvent)
void SpawnVehicle(const FTransform &SpawnTransform, ACarlaWheeledVehicle *&SpawnedCharacter);
//UFUNCTION(BlueprintImplementableEvent)
void TryToSpawnRandomVehicle();
public:
void SetNumberOfVehicles(int32 Count);
int32 GetNumberOfSpawnedVehicles() const
{
return Vehicles.Num();
}
const TArray<ACarlaWheeledVehicle *> &GetVehicles() const {
return Vehicles;
}
void SetRoadMap(URoadMap *InRoadMap)
{
RoadMap = InRoadMap;
}
UFUNCTION(Category = "Road Map", BlueprintCallable)
URoadMap *GetRoadMap()
{
return RoadMap;
}
/** Function called to spawn another vehicle when there is not enough spawn points in the beginplay */
UFUNCTION(Category = "Vehicle Spawner", BlueprintCallable)
void SpawnVehicleAttempt();
protected:
APlayerStart* GetRandomSpawnPoint();
ACarlaWheeledVehicle* SpawnVehicleAtSpawnPoint(const APlayerStart &SpawnPoint);
UPROPERTY()
URoadMap *RoadMap = nullptr;
/** If false, no walker will be spawned. */
UPROPERTY(Category = "Vehicle Spawner", EditAnywhere)
bool bSpawnVehicles = true;
/** Number of walkers to be present within the volume. */
UPROPERTY(Category = "Vehicle Spawner", EditAnywhere, meta = (EditCondition = bSpawnVehicles, ClampMin = "1"))
int32 NumberOfVehicles = 10;
UPROPERTY(Category = "Vehicle Spawner", VisibleAnywhere, AdvancedDisplay)
TArray<APlayerStart *> SpawnPoints;
UPROPERTY(Category = "Vehicle Spawner", BlueprintReadOnly, VisibleAnywhere, AdvancedDisplay)
TArray<ACarlaWheeledVehicle *> Vehicles;
/** Time to spawn new vehicles after begin play if there was not enough spawn points at the moment */
UPROPERTY(Category = "Vehicle Spawner", BlueprintReadWrite, EditAnywhere, meta = (ClampMin = "0.1", ClampMax = "1000.0", UIMin = "0.1", UIMax = "1000.0"))
float TimeBetweenSpawnAttemptsAfterBegin = 3.0f;
/** Min Distance to the player vehicle to validate a spawn point location for the next vehicle spawn attempt */
UPROPERTY(Category = "Vehicle Spawner", BlueprintReadWrite, EditAnywhere, meta = (ClampMin = "10", ClampMax = "10000", UIMin = "10", UIMax = "10000"))
float DistanceToPlayerBetweenSpawnAttemptsAfterBegin = 5000;
private:
/** Time handler to spawn more vehicles in the case we could not do it in the beginplay */
FTimerHandle AttemptTimerHandle;
};

View File

@ -1,203 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "WheeledVehicleController.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/Pawn.h"
#include "GameFramework/SpringArmComponent.h"
// =============================================================================
// -- Constructor and destructor -----------------------------------------------
// =============================================================================
AWheeledVehicleController::AWheeledVehicleController(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
bAutoManageActiveCameraTarget = false;
// Create the spring arm component.
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm0"));
SpringArm->TargetOffset = FVector(0.f, 0.f, 200.f);
SpringArm->SetRelativeRotation(FRotator(-15.f, 0.f, 0.f));
SpringArm->SetupAttachment(RootComponent);
SpringArm->TargetArmLength = 650.0f;
SpringArm->bEnableCameraRotationLag = true;
SpringArm->CameraRotationLagSpeed = 7.f;
SpringArm->bInheritPitch = false;
SpringArm->bInheritRoll = false;
SpringArm->bInheritYaw = true;
// Do not collide, may clip into level.
SpringArm->bDoCollisionTest = false;
// Create the camera component.
PlayerCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera0"));
PlayerCamera->SetupAttachment(SpringArm, USpringArmComponent::SocketName);
PlayerCamera->bUsePawnControlRotation = false;
PlayerCamera->FieldOfView = 90.f;
// Create the on-board camera component.
OnBoardCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("OnBoardCamera0"));
OnBoardCamera->SetRelativeLocation(FVector(140.f, 0.f, 140.f));
OnBoardCamera->SetRelativeRotation(FRotator(-10.f, 0.f, 0.f));
OnBoardCamera->SetupAttachment(RootComponent);
OnBoardCamera->bUsePawnControlRotation = false;
OnBoardCamera->FieldOfView = 100.f;
}
AWheeledVehicleController::~AWheeledVehicleController() {}
// =============================================================================
// -- AActor -------------------------------------------------------------------
// =============================================================================
void AWheeledVehicleController::BeginPlay()
{
Super::BeginPlay();
EnableOnBoardCamera(bOnBoardCameraIsActive, true);
}
// =============================================================================
// -- APlayerController --------------------------------------------------------
// =============================================================================
void AWheeledVehicleController::SetupInputComponent()
{
Super::SetupInputComponent();
if (InputComponent != nullptr) {
// Camera movement.
InputComponent->BindAxis("CameraZoom", this, &AWheeledVehicleController::ChangeCameraZoom);
InputComponent->BindAxis("CameraUp", this, &AWheeledVehicleController::ChangeCameraUp);
InputComponent->BindAxis("CameraRight", this, &AWheeledVehicleController::ChangeCameraRight);
InputComponent->BindAction("ToggleCamera", IE_Pressed, this, &AWheeledVehicleController::ToggleCamera);
InputComponent->BindAction("RestartLevel", IE_Pressed, this, &AWheeledVehicleController::RestartLevel);
// Vehicle movement.
InputComponent->BindAction("ToggleAutopilot", IE_Pressed, this, &AWheeledVehicleAIController::ToggleAutopilot);
InputComponent->BindAxis("MoveForward", this, &AWheeledVehicleController::SetThrottleInput);
InputComponent->BindAxis("MoveRight", this, &AWheeledVehicleController::SetSteeringInput);
InputComponent->BindAxis("Brake", this, &AWheeledVehicleController::SetBrakeInput);
InputComponent->BindAction("ToggleReverse", IE_Pressed, this, &AWheeledVehicleController::ToggleReverse);
InputComponent->BindAction("Handbrake", IE_Pressed, this, &AWheeledVehicleController::HoldHandbrake);
InputComponent->BindAction("Handbrake", IE_Released, this, &AWheeledVehicleController::ReleaseHandbrake);
}
}
void AWheeledVehicleController::Possess(APawn *aPawn)
{
Super::Possess(aPawn);
SpringArm->AttachToComponent(
aPawn->GetRootComponent(),
FAttachmentTransformRules::KeepRelativeTransform);
OnBoardCamera->AttachToComponent(
aPawn->GetRootComponent(),
FAttachmentTransformRules::KeepRelativeTransform);
}
void AWheeledVehicleController::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
{
if (bOnBoardCameraIsActive) {
OnBoardCamera->GetCameraView(DeltaTime, OutResult);
} else {
PlayerCamera->GetCameraView(DeltaTime, OutResult);
}
}
// =============================================================================
// -- User input ---------------------------------------------------------------
// =============================================================================
void AWheeledVehicleController::EnableUserInput(const bool On)
{
bAllowUserInput = On;
if (bAllowUserInput) {
Super::SetAutopilot(false);
}
}
// =============================================================================
// -- Camera movement methods --------------------------------------------------
// =============================================================================
void AWheeledVehicleController::AWheeledVehicleController::ChangeCameraZoom(float Value)
{
SpringArm->TargetArmLength = FMath::Clamp(SpringArm->TargetArmLength + Value, 150.0f, 2e4f);
}
void AWheeledVehicleController::ChangeCameraUp(float Value)
{
auto Rotation = SpringArm->GetRelativeTransform().Rotator();
Rotation.Pitch = FMath::Clamp(Rotation.Pitch - Value, -85.0f, 0.0f);
SpringArm->SetRelativeRotation(Rotation);
}
void AWheeledVehicleController::ChangeCameraRight(float Value)
{
auto Rotation = SpringArm->GetRelativeTransform().Rotator();
Rotation.Yaw -= Value;
SpringArm->SetRelativeRotation(Rotation);
}
void AWheeledVehicleController::EnableOnBoardCamera(const bool bEnable, const bool bForce)
{
if (bForce || (bOnBoardCameraIsActive != bEnable)) {
bOnBoardCameraIsActive = bEnable;
if (bEnable) {
PlayerCamera->Deactivate();
OnBoardCamera->Activate();
} else {
OnBoardCamera->Deactivate();
PlayerCamera->Activate();
}
}
}
// =============================================================================
// -- Vehicle movement methods -------------------------------------------------
// =============================================================================
void AWheeledVehicleController::SetThrottleInput(const float Value)
{
if (bAllowUserInput && !IsAutopilotEnabled()) {
GetPossessedVehicle()->SetThrottleInput(Value);
}
}
void AWheeledVehicleController::SetSteeringInput(const float Value)
{
if (bAllowUserInput && !IsAutopilotEnabled()) {
GetPossessedVehicle()->SetSteeringInput(Value);
}
}
void AWheeledVehicleController::SetBrakeInput(const float Value)
{
if (bAllowUserInput && !IsAutopilotEnabled()) {
GetPossessedVehicle()->SetBrakeInput(Value);
}
}
void AWheeledVehicleController::ToggleReverse()
{
if (bAllowUserInput && !IsAutopilotEnabled()) {
GetPossessedVehicle()->ToggleReverse();
}
}
void AWheeledVehicleController::HoldHandbrake()
{
if (bAllowUserInput && !IsAutopilotEnabled()) {
GetPossessedVehicle()->HoldHandbrake();
}
}
void AWheeledVehicleController::ReleaseHandbrake()
{
if (bAllowUserInput && !IsAutopilotEnabled()) {
GetPossessedVehicle()->ReleaseHandbrake();
}
}

View File

@ -1,126 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Vehicle/WheeledVehicleAIController.h"
#include "CoreMinimal.h"
#include "WheeledVehicleController.generated.h"
class UCameraComponent;
class USpringArmComponent;
/// Wheeled vehicle controller with cameras and optional user input.
UCLASS()
class CARLA_API AWheeledVehicleController : public AWheeledVehicleAIController
{
GENERATED_BODY()
// ===========================================================================
/// @name Constructor
// ===========================================================================
/// @{
public:
AWheeledVehicleController(const FObjectInitializer& ObjectInitializer);
~AWheeledVehicleController();
/// @}
// ===========================================================================
/// @name AActor overrides
// ===========================================================================
/// @{
public:
virtual void BeginPlay() override;
/// @}
// ===========================================================================
/// @name APlayerController overrides
// ===========================================================================
/// @{
public:
virtual void SetupInputComponent() override;
virtual void Possess(APawn *aPawn) override;
virtual void CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult) override;
/// @}
// ===========================================================================
/// @name User input
// ===========================================================================
/// @{
public:
/// Enable keyboard control.
UFUNCTION(Category = "Vehicle User Input", BlueprintCallable)
void EnableUserInput(bool Enable);
/// @}
// ===========================================================================
/// @name Camera movement
// ===========================================================================
/// @{
private:
void ChangeCameraZoom(float Value);
void ChangeCameraUp(float Value);
void ChangeCameraRight(float Value);
void EnableOnBoardCamera(bool bEnable = true, bool bForce = false);
void ToggleCamera()
{
EnableOnBoardCamera(!bOnBoardCameraIsActive);
}
/// @}
// ===========================================================================
/// @name Vehicle movement
// ===========================================================================
/// @{
private:
void SetThrottleInput(float Value);
void SetSteeringInput(float Value);
void SetBrakeInput(float Value);
void ToggleReverse();
void HoldHandbrake();
void ReleaseHandbrake();
/// @}
// ===========================================================================
// -- Member variables -------------------------------------------------------
// ===========================================================================
private:
UPROPERTY(EditAnywhere)
USpringArmComponent *SpringArm;
UPROPERTY(EditAnywhere)
UCameraComponent *PlayerCamera;
UPROPERTY(EditAnywhere)
UCameraComponent *OnBoardCamera;
UPROPERTY()
bool bOnBoardCameraIsActive = false;
UPROPERTY(Category = "Vehicle User Input", VisibleAnywhere)
bool bAllowUserInput = false;
};

View File

@ -1,300 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "WalkerAIController.h"
#include "Navigation/CrowdFollowingComponent.h"
#include "Perception/AIPerceptionComponent.h"
#include "Perception/AISenseConfig_Sight.h"
#include "WheeledVehicle.h"
#include "WheeledVehicleMovementComponent.h"
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
# include <DrawDebugHelpers.h>
# define LOG_AI_WALKER(Verbosity, Text) UE_LOG(LogCarla, Verbosity, TEXT("Walker %s " Text), *GetPawn()->GetName());
# define EXTRA_LOG_ONLY(predicate) predicate
#else
# define LOG_AI_WALKER(Verbosity, Text)
# define EXTRA_LOG_ONLY(predicate)
#endif // CARLA_AI_WALKERS_EXTRA_LOG
static constexpr float UPDATE_TIME_IN_SECONDS = 0.6f;
static constexpr float PREVISION_TIME_IN_SECONDS = 5.0f;
static constexpr float WALKER_SIGHT_RADIUS = 500.0f;
static constexpr float WALKER_SPEED_DAMPING = 4.0f;
static constexpr float WALKER_PERIPHERAL_VISION_ANGLE_IN_DEGREES = 130.0f;
static constexpr float WALKER_MAX_TIME_PAUSED = 5.0f;
static constexpr float VEHICLE_SAFETY_RADIUS = 600.0f;
// =============================================================================
// -- PawnPath -----------------------------------------------------------------
// =============================================================================
class PawnPath {
private:
static FVector GetLocation(const AActor &Actor)
{
const FVector &Location = Actor.GetActorLocation();
return {Location.X, Location.Y, 0.0f};
}
static FVector GetForwardVector(const AActor &Actor)
{
return Actor.GetTransform().GetRotation().GetForwardVector();
}
static float GetForwardSpeed(const AWheeledVehicle &Vehicle)
{
const auto *MovementComponent = Vehicle.GetVehicleMovementComponent();
check(nullptr != MovementComponent);
return MovementComponent->GetForwardSpeed();
}
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
static FVector GetPointForDrawing(const FVector &Location)
{
return {Location.X, Location.Y, 50.0f};
}
#endif // CARLA_AI_WALKERS_EXTRA_LOG
/// Helper constructor for vehicles.
explicit PawnPath(const FVector &Location, const FVector &ForwardDirection, const float Speed) :
Start(Location - ForwardDirection * VEHICLE_SAFETY_RADIUS),
End(Location + ForwardDirection * (VEHICLE_SAFETY_RADIUS + Speed * PREVISION_TIME_IN_SECONDS)) {}
private:
explicit PawnPath(const APawn &Walker) :
Start(GetLocation(Walker)),
End(GetLocation(Walker) + GetForwardVector(Walker) * WALKER_SPEED_DAMPING * WALKER_SIGHT_RADIUS) {}
explicit PawnPath(const AWheeledVehicle &Vehicle) :
PawnPath(GetLocation(Vehicle), GetForwardVector(Vehicle), GetForwardSpeed(Vehicle)) {}
static bool Intersect(const PawnPath &Lhs, const PawnPath &Rhs, UWorld* EXTRA_LOG_ONLY(World))
{
EXTRA_LOG_ONLY(Lhs.DrawDebugArrow(World));
EXTRA_LOG_ONLY(Rhs.DrawDebugArrow(World));
FVector IntersectionPoint;
const bool bIntersect = FMath::SegmentIntersection2D(
Lhs.Start, Lhs.End,
Rhs.Start, Rhs.End,
IntersectionPoint);
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
if (bIntersect) {
DrawDebugPoint(World, GetPointForDrawing(IntersectionPoint), 10.0f, FColor::Red, false, 2.0f);
}
#endif // CARLA_AI_WALKERS_EXTRA_LOG
return bIntersect;
}
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
void DrawDebugArrow(UWorld *World) const
{
DrawDebugDirectionalArrow(World, GetPointForDrawing(Start), GetPointForDrawing(End), 60.0f, FColor::Red, false, 1.0f);
}
#endif // CARLA_AI_WALKERS_EXTRA_LOG
public:
/// Check if the paths of @a Walker and @a Vehicle intersect.
///
/// It checks if within the update time the vehicle will cross the straight
/// line of @a Walker sight radius on its forward direction.
static bool Intersect(const APawn &Walker, const AWheeledVehicle &Vehicle)
{
return Intersect(PawnPath(Walker), PawnPath(Vehicle), Walker.GetWorld());
}
private:
FVector Start;
FVector End;
};
// =============================================================================
// -- Other static functions ---------------------------------------------------
// =============================================================================
static bool IntersectsWithVehicle(const APawn &Self, const TArray<AActor *> &Actors)
{
for (auto *Actor : Actors) {
const auto *Vehicle = Cast<AWheeledVehicle>(Actor);
if ((Vehicle != nullptr) && PawnPath::Intersect(Self, *Vehicle)) {
return true;
}
}
return false;
}
// =============================================================================
// -- AWalkerAIController ------------------------------------------------------
// =============================================================================
AWalkerAIController::AWalkerAIController(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent")))
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.TickInterval = UPDATE_TIME_IN_SECONDS;
auto Perception = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("AIPerception Component"));
check(Perception != nullptr);
SightConfiguration = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("SightConfiguration"));
SightConfiguration->SightRadius = WALKER_SIGHT_RADIUS;
SightConfiguration->LoseSightRadius = (WALKER_SIGHT_RADIUS + 100.0f);
SightConfiguration->PeripheralVisionAngleDegrees = WALKER_PERIPHERAL_VISION_ANGLE_IN_DEGREES;
SightConfiguration->DetectionByAffiliation.bDetectEnemies = true;
SightConfiguration->DetectionByAffiliation.bDetectNeutrals = true;
SightConfiguration->DetectionByAffiliation.bDetectFriendlies = true;
Perception->ConfigureSense(*SightConfiguration);
Perception->SetDominantSense(SightConfiguration->GetSenseImplementation());
Perception->OnPerceptionUpdated.AddDynamic(this, &AWalkerAIController::SenseActors);
SetPerceptionComponent(*Perception);
TimeInState=0.0f;
}
void AWalkerAIController::Possess(APawn *aPawn)
{
Super::Possess(aPawn);
check(aPawn != nullptr);
aPawn->OnTakeAnyDamage.AddDynamic(this, &AWalkerAIController::OnPawnTookDamage);
}
void AWalkerAIController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
TimeInState+=DeltaSeconds;
if (Status != EWalkerStatus::RunOver)
{
switch (GetMoveStatus())
{
default: break;
case EPathFollowingStatus::Idle:
//case EPathFollowingStatus::Waiting: //<-- incomplete path
LOG_AI_WALKER(Warning, "is stuck!");
ChangeStatus(EWalkerStatus::Stuck);
break;
case EPathFollowingStatus::Paused:
if(TimeInState>WALKER_MAX_TIME_PAUSED){
LOG_AI_WALKER(Log, "is paused, trying resume movement");
TryResumeMovement();
}
break;
};
}
}
FPathFollowingRequestResult AWalkerAIController::MoveTo(
const FAIMoveRequest& MoveRequest,
FNavPathSharedPtr* OutPath)
{
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("Walker %s requested move from (%s) to (%s)"),
*GetPawn()->GetName(),
*GetPawn()->GetActorLocation().ToString(),
*MoveRequest.GetGoalLocation().ToString())
;
#endif // CARLA_AI_WALKERS_EXTRA_LOG
ChangeStatus(EWalkerStatus::Moving);
return Super::MoveTo(MoveRequest, OutPath);
}
void AWalkerAIController::OnMoveCompleted(
const FAIRequestID RequestID,
const FPathFollowingResult &Result)
{
Super::OnMoveCompleted(RequestID, Result);
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("Walker %s completed move at (%s)"),
*GetPawn()->GetName(),
*GetPawn()->GetActorLocation().ToString());
#endif // CARLA_AI_WALKERS_EXTRA_LOG
ChangeStatus(EWalkerStatus::MoveCompleted);
}
void AWalkerAIController::SenseActors(const TArray<AActor *> &Actors)
{
const auto *aPawn = GetPawn();
if ((Status == EWalkerStatus::Moving) &&
(aPawn != nullptr) &&
IntersectsWithVehicle(*aPawn, Actors)) {
TryPauseMovement();
}
}
void AWalkerAIController::TrySetMovement(bool paused)
{
if(paused) TryPauseMovement(false);
else TryResumeMovement();
}
void AWalkerAIController::ChangeStatus(EWalkerStatus status)
{
if(status==Status) return;
//switch (status) { }
TimeInState = 0.0f;
Status = status;
}
void AWalkerAIController::TryResumeMovement()
{
if (Status != EWalkerStatus::Moving) {
auto MoveRequestID = GetCurrentMoveRequestID();
if (MoveRequestID == FAIRequestID()) { // equals invalid request.
LOG_AI_WALKER(Error, "has invalid move ID");
} else {
if (!ResumeMove(MoveRequestID)) {
LOG_AI_WALKER(Error, "is unable to resume movement");
} else {
LOG_AI_WALKER(Log, "resuming movement");
ChangeStatus(EWalkerStatus::Moving);
}
}
}
}
void AWalkerAIController::TryPauseMovement(const bool bItWasRunOver)
{
if ((Status != EWalkerStatus::Paused) && (Status != EWalkerStatus::RunOver)) {
auto MoveRequestID = GetCurrentMoveRequestID();
if (MoveRequestID == FAIRequestID()) { // equals invalid request.
LOG_AI_WALKER(Error, "has invalid move ID");
} else {
if (!PauseMove(MoveRequestID)) {
LOG_AI_WALKER(Error, "is unable to pause movement");
} else {
LOG_AI_WALKER(Log, "paused");
ChangeStatus(bItWasRunOver ? EWalkerStatus::RunOver : EWalkerStatus::Paused);
}
}
}
}
void AWalkerAIController::OnPawnTookDamage(
AActor *DamagedActor,
float Damage,
const UDamageType *DamageType,
AController *InstigatedBy,
AActor *DamageCauser)
{
LOG_AI_WALKER(Warning, "has been run over");
constexpr bool bItWasRunOver = true;
TryPauseMovement(bItWasRunOver);
ChangeStatus(EWalkerStatus::RunOver);
}
#undef EXTRA_LOG_ONLY
#undef LOG_AI_WALKER

View File

@ -1,85 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "AIController.h"
#include "WalkerAIController.generated.h"
class UAISenseConfig_Sight;
UENUM(BlueprintType)
enum class EWalkerStatus : uint8 {
Moving UMETA(DisplayName = "Walker Is Moving"),
Paused UMETA(DisplayName = "Walker Movement Is Paused"),
MoveCompleted UMETA(DisplayName = "Walker Completed Move"),
Stuck UMETA(DisplayName = "Walker Is Stuck"),
RunOver UMETA(DisplayName = "Walker Has Been Run Over"),
Invalid UMETA(DisplayName = "Walker Is Invalid"),
Unknown UMETA(DisplayName = "Unknown"),
};
UCLASS()
class CARLA_API AWalkerAIController : public AAIController
{
GENERATED_BODY()
public:
AWalkerAIController(const FObjectInitializer& ObjectInitializer);
virtual void Possess(APawn *aPawn) override;
virtual void Tick(float DeltaSeconds) override;
virtual FPathFollowingRequestResult MoveTo(
const FAIMoveRequest& MoveRequest,
FNavPathSharedPtr* OutPath = nullptr) override;
virtual void OnMoveCompleted(
FAIRequestID RequestID,
const FPathFollowingResult &Result) override;
UFUNCTION(BlueprintCallable)
void SenseActors(const TArray<AActor *> &Actors);
EWalkerStatus GetWalkerStatus() const
{
return Status;
}
UFUNCTION(BlueprintCallable)
void TrySetMovement(bool paused);
UFUNCTION(BlueprintCallable)
float GetTimeInState() const { return TimeInState; }
private:
void ChangeStatus(EWalkerStatus status);
void TryResumeMovement();
void TryPauseMovement(bool bItWasRunOver = false);
UFUNCTION()
void OnPawnTookDamage(
AActor *DamagedActor,
float Damage,
const UDamageType *DamageType,
AController *InstigatedBy,
AActor *DamageCauser);
UPROPERTY(Category = "Walker AI Controller", VisibleAnywhere)
UAISenseConfig_Sight *SightConfiguration;
UPROPERTY(VisibleAnywhere)
EWalkerStatus Status = EWalkerStatus::Unknown;
/** Continous time in the same EWalkerStatus */
float TimeInState=0.0f;
};

View File

@ -1,339 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#include "Carla.h"
#include "WalkerSpawnerBase.h"
#include "Util/RandomEngine.h"
#include "Walker/WalkerAIController.h"
#include "Walker/WalkerSpawnPoint.h"
#include "Components/BoxComponent.h"
#include "EngineUtils.h"
#include "GameFramework/Character.h"
#include "Kismet/KismetSystemLibrary.h"
// =============================================================================
// -- Static local methods -----------------------------------------------------
// =============================================================================
static bool WalkerIsValid(const ACharacter *Walker)
{
return ((Walker != nullptr) && !Walker->IsPendingKill());
}
static AWalkerAIController *GetController(ACharacter *Walker)
{
return (WalkerIsValid(Walker) ? Cast<AWalkerAIController>(Walker->GetController()) : nullptr);
}
static float GetDistance(const FVector &Location0, const FVector &Location1)
{
return FMath::Abs((Location0 - Location1).Size());
}
static float GetDistance(const AActor &Actor0, const AActor &Actor1)
{
return GetDistance(Actor0.GetActorLocation(), Actor1.GetActorLocation());
}
static EWalkerStatus GetWalkerStatus(ACharacter *Walker)
{
const auto *Controller = GetController(Walker);
return (Controller == nullptr ? EWalkerStatus::Invalid : Controller->GetWalkerStatus());
}
// =============================================================================
// -- Constructor and destructor -----------------------------------------------
// =============================================================================
AWalkerSpawnerBase::AWalkerSpawnerBase(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.TickGroup = TG_PrePhysics;
}
// =============================================================================
// -- Overriden from AActor ----------------------------------------------------
// =============================================================================
void AWalkerSpawnerBase::BeginPlay()
{
Super::BeginPlay();
NumberOfWalkers = FMath::Max(0, NumberOfWalkers);
// Allocate space for walkers.
Walkers.Reserve(NumberOfWalkers);
// Find spawn points present in level.
TArray<AWalkerSpawnPointBase *> BeginSpawnPoints;
for (TActorIterator<AWalkerSpawnPointBase> It(GetWorld()); It; ++It) {
BeginSpawnPoints.Add(*It);
AWalkerSpawnPoint *SpawnPoint = Cast<AWalkerSpawnPoint>(*It);
if (SpawnPoint != nullptr) {
SpawnPoints.Add(SpawnPoint);
}
}
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("Found %d positions for spawning walkers at begin play."), BeginSpawnPoints.Num());
UE_LOG(LogCarla, Log, TEXT("Found %d positions for spawning walkers during game play."), SpawnPoints.Num());
#endif
if (SpawnPoints.Num() < 2) {
bSpawnWalkers = false;
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Error, TEXT("We don't have enough spawn points for walkers!"));
#endif
} else if (BeginSpawnPoints.Num() < NumberOfWalkers) {
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Warning, TEXT("Requested %d walkers, but we only have %d spawn points. Some will fail to spawn."), NumberOfWalkers, BeginSpawnPoints.Num());
#endif
}
GetRandomEngine()->Shuffle(BeginSpawnPoints);
if (bSpawnWalkers && bSpawnWalkersAtBeginPlay) {
uint32 Count = 0u;
for (auto i = 0; i < NumberOfWalkers; ++i) {
if (TryToSpawnWalkerAt(*BeginSpawnPoints[i % BeginSpawnPoints.Num()])) {
++Count;
}
}
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("Spawned %d walkers at begin play."), Count);
#endif
}
}
void AWalkerSpawnerBase::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (bSpawnWalkers && (NumberOfWalkers > GetCurrentNumberOfWalkers())) {
// Try to spawn one walker.
TryToSpawnWalkerAt(GetRandomSpawnPoint());
}
if (WalkersBlackList.Num() > 0)
{
CurrentBlackWalkerIndexToCheck = ++CurrentBlackWalkerIndexToCheck % WalkersBlackList.Num();
ACharacter* BlackListedWalker = WalkersBlackList[CurrentBlackWalkerIndexToCheck];
AWalkerAIController* controller = BlackListedWalker!=nullptr?Cast<AWalkerAIController>(BlackListedWalker->GetController()):nullptr;
if(BlackListedWalker != nullptr && controller!=nullptr && IsValid(BlackListedWalker))
{
const auto Status = GetWalkerStatus(BlackListedWalker);
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("Watching walker %s with state %d"), *UKismetSystemLibrary::GetDisplayName(BlackListedWalker), (int)Status);
#endif
switch(Status)
{
case EWalkerStatus::RunOver:{
//remove from list and wait for auto-destroy
WalkersBlackList.RemoveAtSwap(CurrentBlackWalkerIndexToCheck);
break;
}
case EWalkerStatus::MoveCompleted:
{
BlackListedWalker->Destroy();
break;
}
default: {
switch(controller->GetMoveStatus())
{
case EPathFollowingStatus::Idle:
if(!TrySetDestination(*BlackListedWalker))
{
if(!SetRandomWalkerDestination(BlackListedWalker))
{
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla,Error,TEXT("Could not set a random destination to walker %s"),*UKismetSystemLibrary::GetDisplayName(BlackListedWalker));
#endif
}
}
break;
case EPathFollowingStatus::Waiting:
//incomplete path
break;
case EPathFollowingStatus::Paused:
//waiting for blueprint code
break;
case EPathFollowingStatus::Moving:
if(BlackListedWalker->GetVelocity().Size()>1.0f)
{
WalkersBlackList.RemoveAtSwap(CurrentBlackWalkerIndexToCheck);
Walkers.Add(BlackListedWalker);
}
break;
default: break;
}
break;
}
}
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("New state for walker %s : %d"), *UKismetSystemLibrary::GetDisplayName(BlackListedWalker), (int)GetWalkerStatus(BlackListedWalker));
#endif
}
}
if (Walkers.Num() > 0)
{
// Check one walker, if fails black-list it or kill it.
CurrentWalkerIndexToCheck = ++CurrentWalkerIndexToCheck % Walkers.Num();
auto Walker = Walkers[CurrentWalkerIndexToCheck];
if(Walker == nullptr || !IsValid(Walker))
{
Walkers.RemoveAtSwap(CurrentWalkerIndexToCheck);
} else {
const auto Status = GetWalkerStatus(Walker);
switch (Status)
{
default:
case EWalkerStatus::Paused:
case EWalkerStatus::Unknown:
break;
case EWalkerStatus::RunOver: {
Walkers.RemoveAtSwap(CurrentWalkerIndexToCheck);
break;
}
case EWalkerStatus::MoveCompleted:
Walker->Destroy();
break;
case EWalkerStatus::Invalid:
case EWalkerStatus::Stuck:
{
SetRandomWalkerDestination(Walker);
// Black-list it and wait for this walker to move
WalkersBlackList.Add(Walker);
Walkers.RemoveAtSwap(CurrentWalkerIndexToCheck);
break;
}
}
}
}
}
bool AWalkerSpawnerBase::SetRandomWalkerDestination(ACharacter *Walker)
{
const auto &DestinationPoint = GetRandomSpawnPoint();
auto Controller = GetController(Walker);
if(!Controller) {
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Warning, TEXT("AWalkerSpawnerBase::SetRandomWalkerDestination: Walker %s has no controller"),
*UKismetSystemLibrary::GetDisplayName(Walker)
);
#endif
return false;
}
const EPathFollowingRequestResult::Type request_result = Controller->MoveToLocation(DestinationPoint.GetActorLocation(),-1.0f,false,true,true,true,nullptr,true);
switch(request_result)
{
case EPathFollowingRequestResult::Type::Failed:
{
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Warning, TEXT("AWalkerSpawnerBase::SetRandomWalkerDestination: Bad destination point %s"),
*UKismetSystemLibrary::GetDisplayName(&DestinationPoint)
);
#endif
return false;
}
case EPathFollowingRequestResult::Type::AlreadyAtGoal:{
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(LogCarla, Log, TEXT("AWalkerSpawnerBase::SetRandomWalkerDestination already in destination, generating new location"));
#endif
return SetRandomWalkerDestination(Walker);
}
default: case EPathFollowingRequestResult::Type::RequestSuccessful: return true;
}
}
// =============================================================================
// -- Other member functions ---------------------------------------------------
// =============================================================================
void AWalkerSpawnerBase::SetNumberOfWalkers(const int32 Count)
{
if (Count > 0) {
bSpawnWalkers = true;
NumberOfWalkers = Count;
} else {
bSpawnWalkers = false;
}
}
const AWalkerSpawnPointBase &AWalkerSpawnerBase::GetRandomSpawnPoint()
{
check(SpawnPoints.Num() > 0);
const auto *SpawnPoint = GetRandomEngine()->PickOne(SpawnPoints);
check(SpawnPoint != nullptr);
return *SpawnPoint;
}
bool AWalkerSpawnerBase::TryGetValidDestination(const FVector &Origin, FVector &Destination)
{
const auto &DestinationPoint = GetRandomSpawnPoint();
Destination = DestinationPoint.GetActorLocation();
return (GetDistance(Origin, Destination) >= MinimumWalkDistance);
}
bool AWalkerSpawnerBase::TryToSpawnWalkerAt(const AWalkerSpawnPointBase &SpawnPoint)
{
// Try find destination.
FVector Destination;
if (!TryGetValidDestination(SpawnPoint.GetActorLocation(), Destination)) {
return false;
}
// Spawn walker.
ACharacter *Walker;
SpawnWalker(SpawnPoint.GetActorTransform(), Walker);
if (!WalkerIsValid(Walker)) {
return false;
}
// Assign controller.
Walker->AIControllerClass = AWalkerAIController::StaticClass();
Walker->SpawnDefaultController();
auto Controller = GetController(Walker);
if (Controller == nullptr) { // Sometimes fails...
UE_LOG(LogCarla, Error, TEXT("Something went wrong creating the controller for the new walker"));
Walker->Destroy();
return false;
}
// Add walker and set destination.
Walkers.Add(Walker);
if (Controller->MoveToLocation(Destination,-1.0f,false,true,true,true,nullptr,true)!=EPathFollowingRequestResult::Type::RequestSuccessful)
{
SetRandomWalkerDestination(Walker);
}
return true;
}
bool AWalkerSpawnerBase::TrySetDestination(ACharacter &Walker)
{
// Try to retrieve controller.
auto Controller = GetController(&Walker);
if (Controller == nullptr) {
UE_LOG(LogCarla, Warning, TEXT("Could not get valid controller for walker: %s"), *Walker.GetName());
return false;
}
// Try find destination.
FVector Destination;
if (!TryGetValidDestination(Walker.GetActorLocation(), Destination)) {
#ifdef CARLA_AI_WALKERS_EXTRA_LOG
UE_LOG(
LogCarla, Warning,
TEXT("Could not get a new destiny: %s for walker: %s"),
*Destination.ToString(), *Walker.GetName()
);
#endif
return false;
}
return Controller->MoveToLocation(Destination,-1.0f,false,true,true,true,nullptr,true)==EPathFollowingRequestResult::RequestSuccessful;
}

View File

@ -1,124 +0,0 @@
// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
// de Barcelona (UAB).
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
#pragma once
#include "Util/ActorWithRandomEngine.h"
#include "WalkerSpawnerBase.generated.h"
class AWalkerSpawnPoint;
class AWalkerSpawnPointBase;
class UBoxComponent;
/// Base class for spawning walkers. Implement SpawnWalker in derived
/// blueprints.
///
/// Walkers are spawned at a random AWalkerSpawnPoint present in the level, and
/// walk until its destination is reached at another random AWalkerSpawnPoint.
UCLASS(Abstract)
class CARLA_API AWalkerSpawnerBase : public AActorWithRandomEngine
{
GENERATED_BODY()
// ===========================================================================
/// @name Constructor and destructor
// ===========================================================================
/// @{
public:
AWalkerSpawnerBase(const FObjectInitializer& ObjectInitializer);
/// @}
// ===========================================================================
/// @name Overriden from AActor
// ===========================================================================
/// @{
protected:
virtual void BeginPlay() override;
public:
virtual void Tick(float DeltaTime) override;
/// @}
// ===========================================================================
/// @name Blueprintable functions
// ===========================================================================
/// @{
protected:
UFUNCTION(BlueprintImplementableEvent)
void SpawnWalker(const FTransform &SpawnTransform, ACharacter *&SpawnedCharacter);
/// @}
// ===========================================================================
/// @name Other member functions
// ===========================================================================
/// @{
public:
void SetNumberOfWalkers(int32 Count);
int32 GetCurrentNumberOfWalkers() const
{
return Walkers.Num() + WalkersBlackList.Num();
}
const TArray<ACharacter *> &GetWalkersWhiteList() const {
return Walkers;
}
const TArray<ACharacter *> &GetWalkersBlackList() const {
return WalkersBlackList;
}
private:
const AWalkerSpawnPointBase &GetRandomSpawnPoint();
bool TryGetValidDestination(const FVector &Origin, FVector &Destination);
bool TryToSpawnWalkerAt(const AWalkerSpawnPointBase &SpawnPoint);
bool TrySetDestination(ACharacter &Walker);
bool SetRandomWalkerDestination(ACharacter * Walker);
/// @}
private:
/** If false, no walker will be spawned at all. */
UPROPERTY(Category = "Walker Spawner", EditAnywhere)
bool bSpawnWalkers = true;
/** If false, no walker will be spawned at begin play. */
UPROPERTY(Category = "Walker Spawner", EditAnywhere, meta = (EditCondition = bSpawnWalkers))
bool bSpawnWalkersAtBeginPlay = true;
/** Number of walkers to be present within the volume. */
UPROPERTY(Category = "Walker Spawner", EditAnywhere, meta = (EditCondition = bSpawnWalkers, ClampMin = "1"))
int32 NumberOfWalkers = 10;
/** Minimum walk distance in centimeters. */
UPROPERTY(Category = "Walker Spawner", EditAnywhere, meta = (EditCondition = bSpawnWalkers))
float MinimumWalkDistance = 1500.0f;
UPROPERTY(Category = "Walker Spawner", VisibleAnywhere, AdvancedDisplay)
TArray<AWalkerSpawnPoint *> SpawnPoints;
UPROPERTY(Category = "Walker Spawner", VisibleAnywhere, AdvancedDisplay)
TArray<ACharacter *> Walkers;
UPROPERTY(Category = "Walker Spawner", VisibleAnywhere, AdvancedDisplay)
TArray<ACharacter *> WalkersBlackList;
uint32 CurrentWalkerIndexToCheck = 0u;
uint32 CurrentBlackWalkerIndexToCheck = 0u;
};

View File

@ -1,8 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "CarlaUE4.h"
#include "CarlaUE4GameModeBase.h"

View File

@ -1,19 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/GameModeBase.h"
#include "CarlaUE4GameModeBase.generated.h"
/**
*
*/
UCLASS()
class CARLAUE4_API ACarlaUE4GameModeBase : public AGameModeBase
{
GENERATED_BODY()
};