Expose spectator pawn
This commit is contained in:
parent
63d6f11d41
commit
4f5044a495
|
@ -17,6 +17,7 @@
|
|||
## `carla.World`
|
||||
|
||||
- `get_blueprint_library()`
|
||||
- `get_spectator()`
|
||||
- `spawn_actor(blueprint, transform, attach_to=None)`
|
||||
- `try_spawn_actor(blueprint, transform, attach_to=None)`
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "carla/client/Client.h"
|
||||
|
||||
#include "carla/client/Actor.h"
|
||||
#include "carla/client/BlueprintLibrary.h"
|
||||
#include "carla/client/Control.h"
|
||||
#include "carla/client/Sensor.h"
|
||||
#include "carla/client/Vehicle.h"
|
||||
|
@ -30,6 +31,16 @@ namespace client {
|
|||
return _active_world;
|
||||
}
|
||||
|
||||
SharedPtr<BlueprintLibrary> Client::GetBlueprintLibrary() {
|
||||
return MakeShared<BlueprintLibrary>(
|
||||
Call<std::vector<carla::rpc::ActorDefinition>>("get_actor_definitions"));
|
||||
}
|
||||
|
||||
SharedPtr<Actor> Client::GetSpectator() {
|
||||
auto spectator = Call<carla::rpc::Actor>("get_spectator");
|
||||
return SharedPtr<Actor>(new Actor{spectator, GetWorld()});
|
||||
}
|
||||
|
||||
SharedPtr<Actor> Client::SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const Transform &transform,
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "carla/NonCopyable.h"
|
||||
#include "carla/Version.h"
|
||||
#include "carla/client/BlueprintLibrary.h"
|
||||
#include "carla/client/Control.h"
|
||||
#include "carla/client/Memory.h"
|
||||
#include "carla/client/Transform.h"
|
||||
|
@ -22,6 +21,7 @@ namespace client {
|
|||
|
||||
class Actor;
|
||||
class ActorBlueprint;
|
||||
class BlueprintLibrary;
|
||||
class World;
|
||||
|
||||
class Client
|
||||
|
@ -68,10 +68,9 @@ namespace client {
|
|||
|
||||
SharedPtr<World> GetWorld();
|
||||
|
||||
SharedPtr<BlueprintLibrary> GetBlueprintLibrary() {
|
||||
return MakeShared<BlueprintLibrary>(
|
||||
Call<std::vector<carla::rpc::ActorDefinition>>("get_actor_definitions"));
|
||||
}
|
||||
SharedPtr<BlueprintLibrary> GetBlueprintLibrary();
|
||||
|
||||
SharedPtr<Actor> GetSpectator();
|
||||
|
||||
SharedPtr<Actor> SpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
|
|
|
@ -25,6 +25,10 @@ namespace client {
|
|||
return _parent->GetBlueprintLibrary();
|
||||
}
|
||||
|
||||
SharedPtr<Actor> GetSpectator() const {
|
||||
return _parent->GetSpectator();
|
||||
}
|
||||
|
||||
SharedPtr<Actor> TrySpawnActor(
|
||||
const ActorBlueprint &blueprint,
|
||||
const Transform &transform,
|
||||
|
|
|
@ -15,6 +15,7 @@ void export_world() {
|
|||
|
||||
class_<cc::World, boost::noncopyable, boost::shared_ptr<cc::World>>("World", no_init)
|
||||
.def("get_blueprint_library", &cc::World::GetBlueprintLibrary)
|
||||
.def("get_spectator", &cc::World::GetSpectator)
|
||||
.def("try_spawn_actor", &cc::World::TrySpawnActor,
|
||||
(arg("blueprint"), arg("transform"), arg("attach_to")=cc::SharedPtr<cc::Actor>()))
|
||||
.def("spawn_actor", &cc::World::SpawnActor,
|
||||
|
|
|
@ -13,7 +13,7 @@ AppliedDefaultGraphicsPerformance=Maximum
|
|||
EditorStartupMap=/Game/Carla/Maps/Town01.Town01
|
||||
GameDefaultMap=/Game/Carla/Maps/Town01.Town01
|
||||
ServerDefaultMap=/Game/Carla/Maps/Town01.Town01
|
||||
GlobalDefaultGameMode=/Game/Carla/Blueprints/Game/TheNewGameMode.TheNewGameMode_C
|
||||
GlobalDefaultGameMode=/Game/Carla/Blueprints/Game/TheNewCarlaGameMode.TheNewCarlaGameMode_C
|
||||
GameInstanceClass=/Script/Carla.CarlaGameInstance
|
||||
TransitionMap=/Game/Carla/Maps/Town01.Town01
|
||||
GlobalDefaultServerGameMode=/Game/Carla/Blueprints/Game/CarlaGameMode.CarlaGameMode_C
|
||||
|
|
|
@ -6,27 +6,6 @@
|
|||
-AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.25,Exponent=1.f,Sensitivity=1.f))
|
||||
-AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f))
|
||||
-AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.f,Exponent=1.f,Sensitivity=0.07f))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_RightY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MouseX",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MouseY",AxisProperties=(DeadZone=0.000000,Sensitivity=0.070000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MouseWheelAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_LeftTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_RightTriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Left_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Left_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Left_TriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Left_Grip1Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Left_Grip2Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Right_Thumbstick_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Right_Thumbstick_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Right_TriggerAxis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Right_Grip1Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="MotionController_Right_Grip2Axis",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_Special_Left_X",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
-AxisConfig=(AxisKeyName="Gamepad_Special_Left_Y",AxisProperties=(DeadZone=0.000000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
+AxisConfig=(AxisKeyName="Gamepad_LeftX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
+AxisConfig=(AxisKeyName="Gamepad_LeftY",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
+AxisConfig=(AxisKeyName="Gamepad_RightX",AxisProperties=(DeadZone=0.250000,Sensitivity=1.000000,Exponent=1.000000,bInvert=False))
|
||||
|
@ -59,16 +38,6 @@ bCaptureMouseOnLaunch=True
|
|||
DefaultViewportMouseCaptureMode=CapturePermanently_IncludingInitialMouseDown
|
||||
bDefaultViewportMouseLock=False
|
||||
DefaultViewportMouseLockMode=LockOnCapture
|
||||
-ActionMappings=(ActionName="RestartLevel",Key=R,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="Handbrake",Key=SpaceBar,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="ToggleManualMode",Key=M,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="ToggleHUD",Key=G,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="Jump",Key=Enter,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="ToggleReverse",Key=Q,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="UseTheForce",Key=F,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="ToggleCamera",Key=Tab,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="ChangeWeather",Key=C,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-ActionMappings=(ActionName="ToggleAutopilot",Key=None,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
+ActionMappings=(ActionName="RestartLevel",Key=R,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
+ActionMappings=(ActionName="Handbrake",Key=SpaceBar,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
+ActionMappings=(ActionName="ToggleManualMode",Key=M,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
|
@ -79,17 +48,6 @@ DefaultViewportMouseLockMode=LockOnCapture
|
|||
+ActionMappings=(ActionName="ToggleCamera",Key=Tab,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
+ActionMappings=(ActionName="ChangeWeather",Key=C,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
+ActionMappings=(ActionName="ToggleAutopilot",Key=P,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
|
||||
-AxisMappings=(AxisName="CameraZoom",Key=MouseWheelAxis,Scale=-20.000000)
|
||||
-AxisMappings=(AxisName="CameraZoom",Key=PageUp,Scale=-10.000000)
|
||||
-AxisMappings=(AxisName="CameraZoom",Key=PageDown,Scale=10.000000)
|
||||
-AxisMappings=(AxisName="CameraUp",Key=Up,Scale=1.000000)
|
||||
-AxisMappings=(AxisName="CameraUp",Key=Down,Scale=-1.000000)
|
||||
-AxisMappings=(AxisName="CameraRight",Key=Right,Scale=1.000000)
|
||||
-AxisMappings=(AxisName="CameraRight",Key=Left,Scale=-1.000000)
|
||||
-AxisMappings=(AxisName="MoveForward",Key=W,Scale=1.000000)
|
||||
-AxisMappings=(AxisName="MoveRight",Key=D,Scale=1.000000)
|
||||
-AxisMappings=(AxisName="MoveRight",Key=A,Scale=-1.000000)
|
||||
-AxisMappings=(AxisName="Brake",Key=S,Scale=1.000000)
|
||||
+AxisMappings=(AxisName="CameraZoom",Key=MouseWheelAxis,Scale=-20.000000)
|
||||
+AxisMappings=(AxisName="CameraZoom",Key=PageUp,Scale=-10.000000)
|
||||
+AxisMappings=(AxisName="CameraZoom",Key=PageDown,Scale=10.000000)
|
||||
|
@ -100,7 +58,10 @@ DefaultViewportMouseLockMode=LockOnCapture
|
|||
+AxisMappings=(AxisName="MoveForward",Key=W,Scale=1.000000)
|
||||
+AxisMappings=(AxisName="MoveRight",Key=D,Scale=1.000000)
|
||||
+AxisMappings=(AxisName="MoveRight",Key=A,Scale=-1.000000)
|
||||
+AxisMappings=(AxisName="Brake",Key=S,Scale=1.000000)
|
||||
+AxisMappings=(AxisName="Brake",Key=B,Scale=1.000000)
|
||||
+AxisMappings=(AxisName="MoveForward",Key=S,Scale=-1.000000)
|
||||
+AxisMappings=(AxisName="MoveUp",Key=E,Scale=1.000000)
|
||||
+AxisMappings=(AxisName="MoveUp",Key=Q,Scale=-1.000000)
|
||||
bAlwaysShowTouchInterface=False
|
||||
bShowConsoleOnFourFingerTap=True
|
||||
DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks
|
||||
|
|
|
@ -53,6 +53,11 @@ public:
|
|||
return Definitions;
|
||||
}
|
||||
|
||||
FActorRegistry &GetActorRegistry()
|
||||
{
|
||||
return Registry;
|
||||
}
|
||||
|
||||
const FActorRegistry &GetActorRegistry() const
|
||||
{
|
||||
return Registry;
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
// 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/CarlaEpisode.h"
|
||||
|
||||
#include "EngineUtils.h"
|
||||
#include "GameFramework/SpectatorPawn.h"
|
||||
|
||||
void UCarlaEpisode::InitializeAtBeginPlay()
|
||||
{
|
||||
auto World = GetWorld();
|
||||
check(World != nullptr);
|
||||
auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
if (PlayerController == nullptr)
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("Can't find player controller!"));
|
||||
return;
|
||||
}
|
||||
Spectator = PlayerController->GetPawn();
|
||||
if (Spectator != nullptr)
|
||||
{
|
||||
FActorDescription Description;
|
||||
Description.Id = TEXT("spectator");
|
||||
Description.Class = Spectator->GetClass();
|
||||
ActorDispatcher.GetActorRegistry().Register(*Spectator, Description);
|
||||
}
|
||||
else
|
||||
{
|
||||
UE_LOG(LogCarla, Error, TEXT("Can't find spectator!"));
|
||||
}
|
||||
}
|
|
@ -20,17 +20,25 @@ class CARLA_API UCarlaEpisode : public UObject
|
|||
|
||||
public:
|
||||
|
||||
void Initialize(const FString &InMapName)
|
||||
void SetMapName(const FString &InMapName)
|
||||
{
|
||||
MapName = InMapName;
|
||||
}
|
||||
|
||||
void InitializeAtBeginPlay();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
const FString &GetMapName() const
|
||||
{
|
||||
return MapName;
|
||||
}
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
APawn *GetSpectatorPawn() const
|
||||
{
|
||||
return Spectator;
|
||||
}
|
||||
|
||||
void RegisterActorFactory(ACarlaActorFactory &ActorFactory)
|
||||
{
|
||||
ActorDispatcher.Bind(ActorFactory);
|
||||
|
@ -89,4 +97,7 @@ private:
|
|||
FString MapName;
|
||||
|
||||
FActorDispatcher ActorDispatcher;
|
||||
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
APawn *Spectator = nullptr;
|
||||
};
|
||||
|
|
|
@ -29,8 +29,10 @@ void ATheNewCarlaGameModeBase::InitGame(
|
|||
{
|
||||
Super::InitGame(MapName, Options, ErrorMessage);
|
||||
|
||||
check(Episode != nullptr);
|
||||
Episode->Initialize(MapName);
|
||||
checkf(
|
||||
Episode != nullptr,
|
||||
TEXT("Missing episode, can't continue without an episode!"));
|
||||
Episode->SetMapName(MapName);
|
||||
|
||||
GameInstance = Cast<UCarlaGameInstance>(GetGameInstance());
|
||||
checkf(
|
||||
|
@ -57,6 +59,7 @@ void ATheNewCarlaGameModeBase::BeginPlay()
|
|||
TaggerDelegate->SetSemanticSegmentationEnabled();
|
||||
}
|
||||
|
||||
Episode->InitializeAtBeginPlay();
|
||||
GameInstance->NotifyBeginEpisode(*Episode);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
#include "Carla/Sensor/Sensor.h"
|
||||
|
||||
#include "GameFramework/SpectatorPawn.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/Version.h>
|
||||
#include <carla/rpc/Actor.h>
|
||||
|
@ -167,6 +169,15 @@ void FTheNewCarlaServer::FPimpl::BindActions()
|
|||
return MakeVectorFromTArray<cr::ActorDefinition>(Episode->GetActorDefinitions());
|
||||
});
|
||||
|
||||
Server.BindSync("get_spectator", [this]() -> cr::Actor {
|
||||
RequireEpisode();
|
||||
auto ActorView = Episode->GetActorRegistry().Find(Episode->GetSpectatorPawn());
|
||||
if (!ActorView.IsValid() || ActorView.GetActor()->IsPendingKill()) {
|
||||
RespondErrorStr("unable to find spectator");
|
||||
}
|
||||
return ActorView;
|
||||
});
|
||||
|
||||
Server.BindSync("spawn_actor", [this](
|
||||
const cr::Transform &Transform,
|
||||
cr::ActorDescription Description) -> cr::Actor {
|
||||
|
|
|
@ -13,4 +13,4 @@
|
|||
0.8.2: 1llrBkZDvJmxXYh4r3jz0wuwz8Q8jRQeZ
|
||||
0.8.3: 1z2XKOk9LoKI-EhxcrpI31W5TeYo2-jjn
|
||||
0.8.4: 1mFNS-w5atQ45yegiTepRIeKBYVm8N8He
|
||||
0.9.0: 10QmgEZxMj3ZYfWeMOf0omRjj4M_eiuC8
|
||||
0.9.0: 1FtC00CrDb7Kz5StBAwb6vqOGbzZtpROx
|
||||
|
|
Loading…
Reference in New Issue