Use a game instance to hold the server
This commit is contained in:
parent
0718b4ad23
commit
037b82a300
|
@ -0,0 +1,21 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "CarlaGameInstance.h"
|
||||
|
||||
#include "CarlaGameController.h"
|
||||
#include "MockGameController.h"
|
||||
|
||||
UCarlaGameInstance::~UCarlaGameInstance() {}
|
||||
|
||||
void UCarlaGameInstance::InitializeGameControllerIfNotPresent(bool bUseMockController)
|
||||
{
|
||||
if (GameController == nullptr) {
|
||||
if (bUseMockController) {
|
||||
GameController = MakeUnique<MockGameController>();
|
||||
UE_LOG(LogCarla, Warning, TEXT("Using mock CARLA controller"));
|
||||
} else {
|
||||
GameController = MakeUnique<CarlaGameController>();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Engine/GameInstance.h"
|
||||
#include "CarlaGameControllerBase.h"
|
||||
#include "CarlaGameInstance.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CARLA_API UCarlaGameInstance : public UGameInstance
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
~UCarlaGameInstance();
|
||||
|
||||
void InitializeGameControllerIfNotPresent(bool bUseMockController);
|
||||
|
||||
CarlaGameControllerBase &GetGameController()
|
||||
{
|
||||
check(GameController != nullptr);
|
||||
return *GameController;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
TUniquePtr<CarlaGameControllerBase> GameController;
|
||||
};
|
|
@ -7,12 +7,10 @@
|
|||
#include "EngineUtils.h"
|
||||
#include "GameFramework/PlayerStart.h"
|
||||
|
||||
#include "CarlaGameController.h"
|
||||
#include "CarlaGameInstance.h"
|
||||
#include "CarlaGameState.h"
|
||||
#include "CarlaPlayerState.h"
|
||||
#include "CarlaPlayerState.h"
|
||||
#include "CarlaVehicleController.h"
|
||||
#include "MockGameController.h"
|
||||
|
||||
ACarlaGameMode::ACarlaGameMode() :
|
||||
Super(),
|
||||
|
@ -21,6 +19,7 @@ ACarlaGameMode::ACarlaGameMode() :
|
|||
PlayerControllerClass = ACarlaVehicleController::StaticClass();
|
||||
GameStateClass = ACarlaGameState::StaticClass();
|
||||
PlayerStateClass = ACarlaPlayerState::StaticClass();
|
||||
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
}
|
||||
|
||||
|
@ -31,12 +30,12 @@ void ACarlaGameMode::InitGame(
|
|||
{
|
||||
Super::InitGame(MapName, Options, ErrorMessage);
|
||||
|
||||
if (bUseMockController) {
|
||||
GameController = MakeUnique<MockGameController>();
|
||||
UE_LOG(LogCarla, Warning, TEXT("Using mock CARLA controller"));
|
||||
} else {
|
||||
GameController = MakeUnique<CarlaGameController>();
|
||||
}
|
||||
UCarlaGameInstance *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(bUseMockController);
|
||||
GameController = &GameInstance->GetGameController();
|
||||
}
|
||||
|
||||
void ACarlaGameMode::RestartPlayer(AController* NewPlayer)
|
||||
|
|
|
@ -40,5 +40,5 @@ private:
|
|||
AController *Player,
|
||||
TArray<APlayerStart *> &UnOccupiedStartPoints);
|
||||
|
||||
TUniquePtr<CarlaGameControllerBase> GameController;
|
||||
CarlaGameControllerBase *GameController;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue