Agrarsense
AgrarsenseSettings.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "Engine/World.h"
10#include "GameFramework/GameUserSettings.h"
11
14
15#include "AgrarsenseSettings.generated.h"
16
17class ASensor;
18
22DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGraphicsSettingsDelegate, FGlobalGraphicsSettings, GraphicsSettings);
23
24/*
25 * AGRARSENSE settings class.
26 */
27UCLASS(BlueprintType, Blueprintable)
28class AGRARSENSE_API UAgrarsenseSettings : public UGameUserSettings
29{
30 GENERATED_BODY()
31
32public:
33
34 UFUNCTION(BlueprintPure)
35 static UAgrarsenseSettings* GetAgrarsenseSettings();
36
41 void Setup(UWorld* World);
42
43 virtual void PostInitProperties() override;
44
48 void LoadSettings(bool bForceReload = false) override;
49
50 void ApplySettings(bool bCheckForCommandLineOverrides) override;
51
56 void SetGraphicsSettings(FGlobalGraphicsSettings NewSettings);
57
61 void SetWindowMode(EWindowMode::Type WindowType);
62
67 void SetSimulationSettings(FGlobalSimulationSettings NewSettings);
68
74 UFUNCTION(BlueprintCallable)
75 void SetWorldRendering(bool enabled);
76
81 UFUNCTION(BlueprintCallable)
82 void SetQualityLevel(EQualityLevel newQualityLevel);
83
88 UFUNCTION(BlueprintCallable)
89 void SetQualityLevelFromString(const FString& QualityLevelString);
90
95 UFUNCTION(BlueprintCallable, BlueprintPure)
96 int GetGlobalTargetFrameRate() const;
97
104 UFUNCTION(BlueprintCallable)
105 void SetGlobalTargetFrameRate(int NewTargetFrameRate);
106
111 UFUNCTION(BlueprintCallable, BlueprintPure)
112 float GetGlobalTimeDilation() const;
113
117 UFUNCTION(BlueprintCallable)
118 void SetSpectatorMaxSpeed(float MaxSpeed);
119
123 UFUNCTION(BlueprintCallable)
124 void SetShowSpectatorRainAndSnowfall(bool Show);
125
130 UFUNCTION(BlueprintCallable, BlueprintPure)
131 float GetSpectatorMaxSpeed() const
132 {
133 return SimulationSettings.SpectatorMaxSpeed;
134 }
135
140 UFUNCTION(BlueprintCallable, BlueprintPure)
141 bool GetShowSpectatorRainAndSnowfall() const
142 {
143 return SimulationSettings.ShowSpectatorRainAndSnowfall;
144 }
145
153 UFUNCTION(BlueprintCallable)
154 void SetGlobalTimeDilation(float TimeDilation);
155
159 UFUNCTION(BlueprintCallable)
160 void PauseSimulation();
161
165 UFUNCTION(BlueprintCallable)
166 void UnPauseSimulation();
167
171 UFUNCTION(BlueprintCallable)
172 void PauseSimulationEndOfThisFrame();
173
178 UFUNCTION(BlueprintCallable)
179 void AdvanceFrameCount(int32 FramesToAdvance);
180
185 UFUNCTION(BlueprintCallable)
186 void AdvanceTime(float TimeToAdvance);
187
193 UFUNCTION(BlueprintCallable)
194 void ChangeMapByName(FString MapName);
195
199 UFUNCTION(BlueprintCallable)
200 void ChangeMapByMapPath(const FString& Path);
201
206 UFUNCTION(BlueprintCallable, BlueprintPure)
207 bool GetGrassVisibility() const;
208
212 UFUNCTION(BlueprintCallable)
213 void SetGrassVisibility(bool Visible);
214
219 UFUNCTION(BlueprintCallable, BlueprintPure)
220 bool GetShadowCSMCache() const;
221
222 /*
223 * Set Shadow CSM cache on or off (r.Shadow.CSMCaching)
224 */
225 UFUNCTION(BlueprintCallable)
226 void SetShadowCSMCache(bool CacheShadowCSM);
227
232 UFUNCTION(BlueprintCallable, BlueprintPure)
233 EAntiAliasing GetAntiAliasingMethod() const;
234
239 UFUNCTION(BlueprintCallable)
240 void SetAntiAliasingMethod(EAntiAliasing AntiAliasingMethod);
241
246 UFUNCTION(BlueprintCallable)
247 void SetAntiAliasingMethodFromString(const FString& AntiAliasingMethodString);
248
253 UFUNCTION(BlueprintCallable)
254 void SetInstancedRenderingVisibility(bool Visible);
255
256 /*
257 * Set how far should World Position Offset be rendered in cm.
258 * Only applies for meshes rendered by InstancedRenderer system.
259 */
260 UFUNCTION(BlueprintCallable)
261 void SetWorldPositionOffsetRenderDistance(int32 WorldPositionOffsetDistance);
262
263 /*
264 * Set Nanite max pixels per edge multiplier. Default is 1.0 by the engine.
265 */
266 UFUNCTION(BlueprintCallable)
267 void SetNaniteMaxPixelsPerEdge(float MaxPixelsPerEdge = 1.0f);
268
269 /*
270 * Set Shadow cache invalidation behavior option.
271 * Meshes with World Position Offset (WPO) is very expensive for shadows to be recalculated,
272 * for that reason default option is Rigid, meaning mesh shadows do not move when WPO (wind for example) moves a mesh.
273 * Set this to Auto or Always if you want mesh shadows to move accurately.
274 * Only applies to meshes rendered with InstancedRenderer system.
275 * https://docs.unrealengine.com/5.3/en-US/PythonAPI/class/ShadowCacheInvalidationBehavior.html
276 */
277 UFUNCTION(BlueprintCallable)
278 void SetShadowCacheInvalidationBehavior(EShadowCacheInvalidationBehavior Behaviour = EShadowCacheInvalidationBehavior::Rigid);
279
285 UFUNCTION(BlueprintCallable)
286 void SetShadowCacheInvalidationBehaviorFromString(const FString& BehaviourString);
287
288 /*
289 * Get how far should World Position Offset be rendered.
290 */
291 UFUNCTION(BlueprintCallable)
292 int32 GetWorldPositionOffsetRenderDistance() const;
293
294 /*
295 * Get Nanite max pixels per edge multiplier.
296 */
297 UFUNCTION(BlueprintCallable, BlueprintPure)
298 float GetNaniteMaxPixelsPerEdge() const;
299
300 /*
301 * Get Shadow cache invalidation behavior option.
302 */
303 UFUNCTION(BlueprintCallable, BlueprintPure)
304 EShadowCacheInvalidationBehavior GetShadowCacheInvalidationBehavior() const;
305
309 UFUNCTION(BlueprintCallable, BlueprintPure)
310 bool GetStartWindowInitiallyMinimized() const;
311
315 UFUNCTION(BlueprintCallable)
316 void SetStartWindowInitiallyMinimized(bool Minimized);
317
321 UFUNCTION(BlueprintCallable)
322 void SetRenderCustomDepthPass(bool RenderCustomDepthPass);
323
327 UFUNCTION(BlueprintCallable)
328 void SetUseVirtualShadowMaps(bool UseVirtualShadowMaps);
329
333 UFUNCTION(BlueprintCallable)
334 bool GetIsUsingVirtualShadowMaps() const;
335
339 UFUNCTION(BlueprintCallable)
340 bool GetIsRenderingCustomDepthPass() const;
341
345 UFUNCTION(BlueprintCallable)
346 int32 GetNumberOfWorkerThreads() const;
347
352 UFUNCTION(BlueprintCallable)
353 FString GetConsoleVariableValueString(const FString& VariableName) const;
354
359 UFUNCTION(BlueprintPure)
360 EQualityLevel GetCurrentQualityLevel() const
361 {
362 return GraphicsSettings.QualityLevel;
363 }
364
369 UFUNCTION(BlueprintCallable)
370 TArray<FString> GetMapNames() const
371 {
372 return MapNames;
373 }
374
379 UFUNCTION(BlueprintCallable)
380 TArray<FString> GetMapPaths() const
381 {
382 return MapPaths;
383 }
384
389 UPROPERTY(BlueprintAssignable)
390 FGraphicsSettingsDelegate OnGraphicsSettingsChanged;
391
396 static bool ShouldStartWindowMinimized()
397 {
398 return GetAgrarsenseSettings()->SimulationSettings.StartCameraWindowsMinimized;
399 }
400
406 {
407 return IsMainMenu;
408 }
409
413 UFUNCTION(BlueprintPure)
414 static FGlobalSimulationSettings GetGlobalSimulationSettings()
415 {
416 return GetAgrarsenseSettings()->SimulationSettings;
417 }
418
422 UFUNCTION(BlueprintPure)
423 static bool IsSimulationPaused()
424 {
425 return GetAgrarsenseSettings()->SimulationSettings.IsSimulationPaused;
426 }
427
431 UFUNCTION(BlueprintPure)
432 static FGlobalGraphicsSettings GetGlobalGraphicsSettings()
433 {
434 return GetAgrarsenseSettings()->GraphicsSettings;
435 }
436
437private:
438
439 // Allow AAgrarsenseGameModeBase access private methods
441
443
444 bool ParseLaunchArguments();
445
446 UFUNCTION()
447 void OnSensorSpawned(ASensor* SensorPtr);
448
449 UFUNCTION()
450 void OnSensorDestroyed(ASensor* SensorPtr);
451
452 void SetUltraWithRaytracingLevel();
453
454 bool IsRaytracingSupported() const;
455
456 void EnableRaytracing();
457
458 void DisableRaytracing();
459
460 void SetUltraQualityLevel();
461
462 void SetBalancedQualityLevel();
463
464 void SetLowQualityLevel();
465
466 int NumberOfPostProcessingSensors = 0;
467
468 bool RenderCustomDepth = false;
469
470 UPROPERTY()
471 TWeakObjectPtr<UWorld> CurrentWorld = nullptr;
472
473 UPROPERTY(config)
474 FGlobalSimulationSettings SimulationSettings;
475
476 UPROPERTY(config)
477 FGlobalGraphicsSettings GraphicsSettings;
478
479 // For AdvanceFrameCount
480 FDelegateHandle AdvanceFramesHandle;
481 int32 FrameCount = 0;
482
483 // For PauseSimulationEndOfThisFrame
484 FDelegateHandle EndOfFrameHandle;
485
486 // Hardcoded map names and paths
487 // These should also be included in DefaultGame.ini file,
488 // otherwise maps are not included in packaged build.
489 // Keep these arrays in sync!
490
491 // Map names, intentionally lower case
492 const TArray<FString> MapNames =
493 {
494 "mainmenu",
495 "rovaniemiforest",
496 "vindeln",
497 "sensorshowcase",
498 "playground"
499 };
500
501 // Maps relative paths
502 const TArray<FString> MapPaths =
503 {
504 "/Game/Agrarsense/Maps/MainMenu",
505 "/Game/Agrarsense/Maps/RovaniemiForest/RovaniemiForest",
506 "/Game/Agrarsense/Maps/Vindeln/Vindeln",
507 "/Game/Agrarsense/Maps/SensorShowCase/SensorShowCase",
508 "/Game/Agrarsense/Maps/Playground"
509 };
510
511 static bool IsMainMenu;
512 static FString CurrentMapName;
513};
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FGraphicsSettingsDelegate, FGlobalGraphicsSettings, GraphicsSettings)
EAntiAliasing
Definition: AntiAliasing.h:15
EQualityLevel
Definition: QualityLevel.h:16
Definition: Sensor.h:44
static FString CurrentMapName
static bool IsPlayingInMainMenu()