DeskSim v2 0.1
Train simulator prototype created for Lokførerskolen
BasicSignal.h
1/****************************************************************/
2/***
3 * @file BasicSignal.h
4 * @brief Contains basic signal class along with enums and structs used by signals.
5 *
6 * @author Endre Heksum
7 * @date March 2022
8 *********************************************************************/
9
10// Copyright 2022 Thomas Arinesalingam, John Ole Bjerke, Endre Heksum & Henrik Markengbakken Karlsen . All Rights Reserved.
11
12#pragma once
13
14#include "CoreMinimal.h"
15#include "GameFramework/Actor.h"
17#include <DeskSimV2/SaveGame/IsSaveableInterface.h>
18#include "BasicSignal.generated.h"
19
23UENUM(BlueprintType)
24enum class ESignalStatus : uint8
25{
26 MClear,
27 MClearReduced,
28 MNotClear,
29 MUnmanned,
30 FClear,
31 FClearReduced,
32 FStop,
33 FUnmanned,
34 DAllowed,
35 DForbidden,
36 DCareful,
37 DFree
38};
39
43UENUM(BlueprintType)
44enum class ESignalType : uint8
45{
46 Main,
47 Forward,
48 Dwarf
49};
50
54USTRUCT()
56{
57 GENERATED_BODY()
58
59 UPROPERTY(VisibleAnywhere)
60 UStaticMeshComponent* LightMesh;
61
62 UPROPERTY(VisibleAnywhere, Transient)
63 UMaterialInstanceDynamic* DynMaterial;
64
65 float BlinkingTimer = 1.0f;
66
67 FTimerHandle LightTimerHandle;
68
69 // Needs a constructor with no params to be used with arrays
70 FSignalLight() :
71 LightMesh(nullptr),
72 DynMaterial(nullptr)
73 {}
74
75 // Constructor for the struct, takes in the light mesh
76 FSignalLight(UStaticMeshComponent* InLightMesh) :
77 LightMesh(InLightMesh),
78 DynMaterial(nullptr)
79 {}
80};
81
89UCLASS(Blueprintable)
90class DESKSIMV2_API ABasicSignal : public AActor, public IIsSaveableInterface
91{
92 GENERATED_BODY()
93
94public:
95 // Sets default values for this actor's properties
97
98protected:
99 // Called when the game starts or when spawned
100 virtual void BeginPlay() override;
101
102 // Called before the actor is destroyed
103 virtual void EndPlay(EEndPlayReason::Type EndPlayReason) override;
104
105public:
106 // Called every frame
107 virtual void Tick(float DeltaTime) override;
108
109 // Sets up the lights, with meshes in sockets and dynamic materials
110 UFUNCTION(BlueprintCallable, CallInEditor, Category = "Signal Light")
111 void SetupLight();
112
113protected:
114
115 // Removes the lights, by unregistering created components
116 UFUNCTION()
117 void RemoveLights();
118
119public:
120
121 UFUNCTION(BlueprintCallable, Category = "Signal Light")
122 void SetLightOnOff(int32 InLightIndex, bool bInLightOn);
123
124 UFUNCTION(BlueprintCallable, Category = "Signal Light")
125 void ToggleLight(int32 InLightIndex);
126
127 UFUNCTION(BlueprintCallable, Category = "Signal Light")
128 void SetLightColor(int32 InLightIndex, FLinearColor InColor);
129
130 UFUNCTION(BlueprintCallable, Category = "Signal Light")
131 void StartLightBlink(int32 InLightIndex, float InSeconds);
132
133 UFUNCTION(BlueprintCallable, Category = "Signal Light")
134 void StopLightBlink(int32 InLightIndex);
135
137 UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Signal Light")
138 void UpdateSignalStatus(ESignalStatus NewSignalStatus);
139
140
141 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Signal Light", SaveGame)
142 FName ID;
143
144 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Signal Light")
145 ESignalType Type;
146
147 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Signal Light")
148 ESignalStatus SignalStatus;
149
150protected:
151
153 UPROPERTY()
154 TArray<FSignalLight> Lights;
155
156public:
157
159 UPROPERTY(EditDefaultsOnly, Category = "Signal Light")
160 UStaticMeshComponent* VisualComponent;
161
163 UPROPERTY(EditDefaultsOnly, Category = "Signal Light")
164 UStaticMesh* BaseLightMesh;
165
167 UPROPERTY(EditDefaultsOnly, Category = "Signal Light")
168 UMaterialInterface* BaseLightMaterial;
169
171 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Signal Light")
172 int32 NumLights = 2;
173
175 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Signal Light")
176 float MaxLightLevel = 10.0f;
177
179 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Signal Light")
180 float LightBlinkPeriod = 2.0f;
181
182 // ---------- RAILWAY INTEGRATION ------------
183
184 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Railway Integration")
185 bool bSnapToNearestRailway;
186
187 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Railway Integration")
188 float OffsetFromRailway = 400.0f;
189
190protected:
191
192 USplineComponent* GetNearestRailwaySplineComponent();
193
194 void SnapToNearestRailway();
195};
A component for placing static meshes along a spline.
Basic signal class, contains functionality to setup and use signal lights.
Definition: BasicSignal.h:91
Definition: IsSaveableInterface.h:20
Contains components and dynamic material of one light.
Definition: BasicSignal.h:56