21#include "Kismet/GameplayStatics.h"
22#include "Kismet/KismetSystemLibrary.h"
23#include "Engine/World.h"
25#include "ROSIntegration/Classes/ROSIntegrationGameInstance.h"
33 PrimaryActorTick.bCanEverTick =
false;
38 Super::InitGame(MapName, Options, ErrorMessage);
54 Super::EndPlay(EndPlayReason);
56 if (EndPlayReason == EEndPlayReason::Type::Quit || EndPlayReason == EEndPlayReason::Type::EndPlayInEditor)
70 if (EndPlayReason == EEndPlayReason::Type::EndPlayInEditor)
72 EditorEndPlayCleanup();
78void AAgrarsenseGameModeBase::EditorEndPlayCleanup()
84 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();
135 Settings->
Setup(World);
138 UROSIntegrationGameInstance* RosInstance = Cast<UROSIntegrationGameInstance>(World->GetGameInstance());
139 bool ROSConnected = RosInstance->IsROSConnected();
169 UE_LOG(LogTemp, Error, TEXT(
"Missing LidarManager class or it already exists."));
176 if (IsValid(simulationLevelManagerActor))
189 TArray<AActor*> WeatherActors;
190 UGameplayStatics::GetAllActorsOfClass(World, AWeather::StaticClass(), WeatherActors);
191 if (!WeatherActors.IsEmpty())
193 Weather = Cast<AWeather>(WeatherActors[0]);
196 if (WeatherActors.Num() >= 2)
198 UE_LOG(LogTemp, Warning, TEXT(
"AAgrarsenseGameModeBase.cpp: Level has multiple Weather blueprints. Make sure to only use one."));
206 TArray<AActor*> InstancedRendererActors;
207 UGameplayStatics::GetAllActorsOfClass(World, AInstancedRenderer::StaticClass(), InstancedRendererActors);
208 if (!InstancedRendererActors.IsEmpty())
221 UWorld* World = GetWorld();
227 auto developerToolsWidget = CreateWidget<UUserWidget>(World,
DeveloperTools);
228 developerToolsWidget->AddToViewport(10);
233 UE_LOG(LogTemp, Error, TEXT(
"Missing DeveloperTools class! Please open AgrarsenseGameMode in Unreal and add it."));
248 TArray<AActor*> Spectators;
249 UGameplayStatics::GetAllActorsOfClass(World, ASpectator::StaticClass(), Spectators);
250 if (!Spectators.IsEmpty())
252 Spectator = Cast<ASpectator>(Spectators[0]);
255 if (Spectators.Num() >= 2)
257 UE_LOG(LogTemp, Warning, TEXT(
"AAgrarsenseGameModeBase.cpp: Level has multiple Spectator blueprints. Make sure to only use one."));
266 TArray<AActor*> Taggers;
267 UGameplayStatics::GetAllActorsOfClass(World, ATagger::StaticClass(), Taggers);
268 for (AActor* TaggerActor : Taggers)
272 TaggerActor->Destroy();
279 if (World && GEngine && GEngine->GameViewport)
286 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
static bool AttemptToLaunchROSBridge
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)