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
55 void SetWindowMode(EWindowMode::Type WindowType);
56
61 void SetSimulationSettings(FGlobalSimulationSettings NewSettings);
62
68 UFUNCTION(BlueprintCallable)
69 void SetWorldRendering(bool enabled);
70
75 UFUNCTION(BlueprintCallable)
76 void SetQualityLevel(EQualityLevel newQualityLevel);
77
82 UFUNCTION(BlueprintCallable)
83 void SetQualityLevelFromString(const FString& QualityLevelString);
84
89 UFUNCTION(BlueprintCallable, BlueprintPure)
90 int GetGlobalTargetFrameRate() const;
91
98 UFUNCTION(BlueprintCallable)
99 void SetGlobalTargetFrameRate(int NewTargetFrameRate);
100
105 UFUNCTION(BlueprintCallable, BlueprintPure)
106 float GetGlobalTimeDilation() const;
107
111 UFUNCTION(BlueprintCallable)
112 void SetSpectatorMaxSpeed(float MaxSpeed);
113
117 UFUNCTION(BlueprintCallable)
118 void SetShowSpectatorRainAndSnowfall(bool Show);
119
124 UFUNCTION(BlueprintCallable, BlueprintPure)
125 float GetSpectatorMaxSpeed() const
126 {
127 return SimulationSettings.SpectatorMaxSpeed;
128 }
129
134 UFUNCTION(BlueprintCallable, BlueprintPure)
135 bool GetShowSpectatorRainAndSnowfall() const
136 {
137 return SimulationSettings.ShowSpectatorRainAndSnowfall;
138 }
139
147 UFUNCTION(BlueprintCallable)
148 void SetGlobalTimeDilation(float TimeDilation);
149
153 UFUNCTION(BlueprintCallable)
154 void PauseSimulation();
155
159 UFUNCTION(BlueprintCallable)
160 void UnPauseSimulation();
161
165 UFUNCTION(BlueprintCallable)
166 void PauseSimulationEndOfThisFrame();
167
172 UFUNCTION(BlueprintCallable)
173 void AdvanceFrameCount(int32 FramesToAdvance);
174
179 UFUNCTION(BlueprintCallable)
180 void AdvanceTime(float TimeToAdvance);
181
187 UFUNCTION(BlueprintCallable)
188 void ChangeMapByName(FString MapName);
189
193 UFUNCTION(BlueprintCallable)
194 void ChangeMapByMapPath(const FString& Path);
195
200 UFUNCTION(BlueprintCallable, BlueprintPure)
201 bool GetGrassVisibility() const;
202
206 UFUNCTION(BlueprintCallable)
207 void SetGrassVisibility(bool Visible);
208
213 UFUNCTION(BlueprintCallable, BlueprintPure)
214 bool GetShadowCSMCache() const;
215
216 /*
217 * Set Shadow CSM cache on or off (r.Shadow.CSMCaching)
218 */
219 UFUNCTION(BlueprintCallable)
220 void SetShadowCSMCache(bool CacheShadowCSM);
221
226 UFUNCTION(BlueprintCallable, BlueprintPure)
227 EAntiAliasing GetAntiAliasingMethod() const;
228
233 UFUNCTION(BlueprintCallable)
234 void SetAntiAliasingMethod(EAntiAliasing AntiAliasingMethod);
235
240 UFUNCTION(BlueprintCallable)
241 void SetAntiAliasingMethodFromString(const FString& AntiAliasingMethodString);
242
247 UFUNCTION(BlueprintCallable)
248 void SetInstancedRenderingVisibility(bool Visible);
249
250 /*
251 * Set how far should World Position Offset be rendered in cm.
252 * Only applies for meshes rendered by InstancedRenderer system.
253 */
254 UFUNCTION(BlueprintCallable)
255 void SetWorldPositionOffsetRenderDistance(int32 WorldPositionOffsetDistance);
256
257 /*
258 * Set Nanite max pixels per edge multiplier. Default is 1.0 by the engine.
259 */
260 UFUNCTION(BlueprintCallable)
261 void SetNaniteMaxPixelsPerEdge(float MaxPixelsPerEdge = 1.0f);
262
263 /*
264 * Set Shadow cache invalidation behavior option.
265 * Meshes with World Position Offset (WPO) is very expensive for shadows to be recalculated,
266 * for that reason default option is Rigid, meaning mesh shadows do not move when WPO (wind for example) moves a mesh.
267 * Set this to Auto or Always if you want mesh shadows to move accurately.
268 * Only applies to meshes rendered with InstancedRenderer system.
269 * https://docs.unrealengine.com/5.3/en-US/PythonAPI/class/ShadowCacheInvalidationBehavior.html
270 */
271 UFUNCTION(BlueprintCallable)
272 void SetShadowCacheInvalidationBehavior(EShadowCacheInvalidationBehavior Behaviour = EShadowCacheInvalidationBehavior::Rigid);
273
279 UFUNCTION(BlueprintCallable)
280 void SetShadowCacheInvalidationBehaviorFromString(const FString& BehaviourString);
281
282 /*
283 * Get how far should World Position Offset be rendered.
284 */
285 UFUNCTION(BlueprintCallable)
286 int32 GetWorldPositionOffsetRenderDistance() const;
287
288 /*
289 * Get Nanite max pixels per edge multiplier.
290 */
291 UFUNCTION(BlueprintCallable, BlueprintPure)
292 float GetNaniteMaxPixelsPerEdge() const;
293
294 /*
295 * Get Shadow cache invalidation behavior option.
296 */
297 UFUNCTION(BlueprintCallable, BlueprintPure)
298 EShadowCacheInvalidationBehavior GetShadowCacheInvalidationBehavior() const;
299
303 UFUNCTION(BlueprintCallable, BlueprintPure)
304 bool GetStartWindowInitiallyMinimized() const;
305
309 UFUNCTION(BlueprintCallable)
310 void SetStartWindowInitiallyMinimized(bool Minimized);
311
315 UFUNCTION(BlueprintCallable)
316 void SetRenderCustomDepthPass(bool RenderCustomDepthPass);
317
321 UFUNCTION(BlueprintCallable)
322 void SetUseVirtualShadowMaps(bool UseVirtualShadowMaps);
323
327 UFUNCTION(BlueprintCallable)
328 bool GetIsUsingVirtualShadowMaps() const;
329
333 UFUNCTION(BlueprintCallable)
334 bool GetIsRenderingCustomDepthPass() const;
335
339 UFUNCTION(BlueprintCallable)
340 int32 GetNumberOfWorkerThreads() const;
341
346 UFUNCTION(BlueprintCallable)
347 FString GetConsoleVariableValueString(const FString& VariableName) const;
348
353 UFUNCTION(BlueprintPure)
354 EQualityLevel GetCurrentQualityLevel() const
355 {
356 return GraphicsSettings.QualityLevel;
357 }
358
363 UFUNCTION(BlueprintCallable)
364 TArray<FString> GetMapNames() const
365 {
366 return MapNames;
367 }
368
373 UFUNCTION(BlueprintCallable)
374 TArray<FString> GetMapPaths() const
375 {
376 return MapPaths;
377 }
378
383 UPROPERTY(BlueprintAssignable)
384 FGraphicsSettingsDelegate OnGraphicsSettingsChanged;
385
390 static bool ShouldStartWindowMinimized()
391 {
392 return GetAgrarsenseSettings()->SimulationSettings.StartCameraWindowsMinimized;
393 }
394
400 {
401 return IsMainMenu;
402 }
403
407 UFUNCTION(BlueprintPure)
408 static FGlobalSimulationSettings GetGlobalSimulationSettings()
409 {
410 return GetAgrarsenseSettings()->SimulationSettings;
411 }
412
416 UFUNCTION(BlueprintPure)
417 static bool IsSimulationPaused()
418 {
419 return GetAgrarsenseSettings()->SimulationSettings.IsSimulationPaused;
420 }
421
425 UFUNCTION(BlueprintPure)
426 static FGlobalGraphicsSettings GetGlobalGraphicsSettings()
427 {
428 return GetAgrarsenseSettings()->GraphicsSettings;
429 }
430
431 UFUNCTION(BlueprintPure)
432 bool IsRaytracingSupported() const;
433
434private:
435
436 // Allow AAgrarsenseGameModeBase access private methods
438
440
445 void SetGraphicsSettings(FGlobalGraphicsSettings NewSettings);
446
447 bool ParseLaunchArguments();
448
449 UFUNCTION()
450 void OnSensorSpawned(ASensor* SensorPtr);
451
452 UFUNCTION()
453 void OnSensorDestroyed(ASensor* SensorPtr);
454
455 void SetUltraWithRaytracingLevel();
456
457 void EnableRaytracing();
458
459 void DisableRaytracing();
460
461 void SetUltraQualityLevel();
462
463 void SetBalancedQualityLevel();
464
465 void SetLowQualityLevel();
466
467 int NumberOfPostProcessingSensors = 0;
468
469 bool RenderCustomDepth = false;
470
471 UPROPERTY()
472 TWeakObjectPtr<UWorld> CurrentWorld = nullptr;
473
474 UPROPERTY(config)
475 FGlobalSimulationSettings SimulationSettings;
476
477 UPROPERTY(config)
478 FGlobalGraphicsSettings GraphicsSettings;
479
480 // For AdvanceFrameCount
481 FDelegateHandle AdvanceFramesHandle;
482 int32 FrameCount = 0;
483
484 // For PauseSimulationEndOfThisFrame
485 FDelegateHandle EndOfFrameHandle;
486
487 // Hardcoded map names and paths
488 // These should also be included in DefaultGame.ini file,
489 // otherwise maps are not included in packaged build.
490 // Keep these arrays in sync!
491
492 // Map names, intentionally lower case
493 const TArray<FString> MapNames =
494 {
495 "mainmenu",
496 "rovaniemiforest",
497 "vindeln",
498 "sensorshowcase",
499 "playground"
500 };
501
502 // Maps relative paths
503 const TArray<FString> MapPaths =
504 {
505 "/Game/Agrarsense/Maps/MainMenu",
506 "/Game/Agrarsense/Maps/RovaniemiForest/RovaniemiForest",
507 "/Game/Agrarsense/Maps/Vindeln/Vindeln",
508 "/Game/Agrarsense/Maps/SensorShowCase/SensorShowCase",
509 "/Game/Agrarsense/Maps/Playground"
510 };
511
512 static bool IsMainMenu;
513 static FString CurrentMapName;
514};
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()