23#include "Kismet/GameplayStatics.h"
24#include "Kismet/KismetSystemLibrary.h"
25#include "Engine/World.h"
27#include "ROSIntegration/Classes/ROSIntegrationGameInstance.h"
34 PrimaryActorTick.bCanEverTick =
false;
39 Super::InitGame(MapName, Options, ErrorMessage);
55 Super::EndPlay(EndPlayReason);
57 if (EndPlayReason == EEndPlayReason::Type::Quit || EndPlayReason == EEndPlayReason::Type::EndPlayInEditor)
71 if (EndPlayReason == EEndPlayReason::Type::EndPlayInEditor)
73 EditorEndPlayCleanup();
79void AAgrarsenseGameModeBase::EditorEndPlayCleanup()
85 IActorInformation::ClearTMapEditor();
100 if (FParse::Param(FCommandLine::Get(), TEXT(
"-vindeln")) && !
MapChanged)
102 LevelName =
"/Game/Agrarsense/Maps/Vindeln/Vindeln";
104 else if (FParse::Param(FCommandLine::Get(), TEXT(
"-rovaniemi")) && !
MapChanged)
106 LevelName =
"/Game/Agrarsense/Maps/RovaniemiForest/RovaniemiForest";
108 else if (FParse::Param(FCommandLine::Get(), TEXT(
"-playground")) && !
MapChanged)
110 LevelName =
"/Game/Agrarsense/Maps/Playground";
113 if (!LevelName.IsEmpty())
116 UGameplayStatics::OpenLevel(GetWorld(), *LevelName);
129 UWorld* World = GetWorld();
141 Settings->
Setup(World);
144 UROSIntegrationGameInstance* RosInstance = Cast<UROSIntegrationGameInstance>(World->GetGameInstance());
145 bool ROSConnected = RosInstance->IsROSConnected();
154 if (
ROSHandle && RosInstance->bConnectToROS && !ROSConnected)
167 UE_LOG(LogTemp, Error, TEXT(
"Missing LidarManager class! Please open AgrarsenseGameMode in Unreal and add it."));
174 if (IsValid(simulationLevelManagerActor))
185 TArray<AActor*> WeatherActors;
186 UGameplayStatics::GetAllActorsOfClass(World, AWeather::StaticClass(), WeatherActors);
187 if (!WeatherActors.IsEmpty())
189 Weather = Cast<AWeather>(WeatherActors[0]);
192 if (WeatherActors.Num() >= 2)
194 UE_LOG(LogTemp, Warning, TEXT(
"AAgrarsenseGameModeBase.cpp: Level has multiple Weather blueprints. Make sure to only use one."));
208 UWorld* World = GetWorld();
214 auto developerToolsWidget = CreateWidget<UUserWidget>(World,
DeveloperTools);
215 developerToolsWidget->AddToViewport(10);
220 UE_LOG(LogTemp, Error, TEXT(
"Missing DeveloperTools class! Please open AgrarsenseGameMode in Unreal and add it."));
233 TArray<AActor*> Spectators;
234 UGameplayStatics::GetAllActorsOfClass(World, ASpectator::StaticClass(), Spectators);
235 if (!Spectators.IsEmpty())
237 Spectator = Cast<ASpectator>(Spectators[0]);
240 if (Spectators.Num() >= 2)
242 UE_LOG(LogTemp, Warning, TEXT(
"AAgrarsenseGameModeBase.cpp: Level has multiple Spectator blueprints. Make sure to only use one."));
248 TArray<AActor*> Taggers;
249 UGameplayStatics::GetAllActorsOfClass(World, ATagger::StaticClass(), Taggers);
250 for (AActor* TaggerActor : Taggers)
254 TaggerActor->Destroy();
262 if (World && GEngine && GEngine->GameViewport)
269 GEngine->GameViewport->AddViewportWidgetContent(OverlayWidget.ToSharedRef());
AAgrarsenseGameModeBase(const FObjectInitializer &ObjectInitializer)
void SpawnNeededActorsBeginPlay()
ALidarManager * LidarManager
TSubclassOf< ASimulationLevelManager > SimulationLevelManagerClass
void BeginPlay() override
void EndPlay(const EEndPlayReason::Type EndPlayReason) override
UAgrarsenseConsoleCommands * AgrarsenseCommands
ASimulationLevelManager * SimulationLevelManager
void SpawnNeededActorsInitGame()
void ParseMapChangeLaunchArgument()
UROSCommands * ROSCommands
static bool StartMessageLogged
AInstancedRenderer * InstancedRenderer
void InitGame(const FString &MapName, const FString &Options, FString &ErrorMessage) override
TSubclassOf< UUserWidget > DeveloperTools
TSubclassOf< ALidarManager > LidarManagerClass
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)
static FString DataPathForThisRun
void Setup(UWorld *World)
static UAgrarsenseSettings * GetAgrarsenseSettings()
void Setup(bool RosIsConnected)