IVSmoke 1.0
Loading...
Searching...
No Matches
IVSmokeHoleData.h
1// Copyright (c) 2026, Team SDB. All rights reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Net/Serialization/FastArraySerializer.h"
7#include "IVSmokeHoleShaders.h"
8#include "IVSmokeHoleData.generated.h"
9
13class UTexture2D;
14struct FIVSmokeHoleGPU;
15
16/**
17 * @struct FIVSmokeHoleNoiseSettings
18 * @brief Noise settings for hole shape distortion.
19 */
20USTRUCT()
21struct IVSMOKE_API FIVSmokeHoleNoiseSettings
22{
23 GENERATED_BODY()
24
25 /** Noise texture for shape distortion. */
26 UPROPERTY(EditAnywhere, Category = "Noise", meta = (Tooltip = "Noise texture for shape distortion."))
27 TObjectPtr<UTexture2D> Texture;
28
29 /** Noise strength. 0 = no noise, 1 = full effect. */
30 UPROPERTY(EditAnywhere, Category = "Noise", meta = (ClampMin = "0.0", ClampMax = "1.0",
31 Tooltip = "Noise strength. 0 = no noise, 1 = full effect."))
32 float Strength = 0.0f;
33
34 /** Noise UV scale. Higher = more detailed patterns. */
35 UPROPERTY(EditAnywhere, Category = "Noise", meta = (ClampMin = "0.1", ClampMax = "2.0",
36 Tooltip = "Noise UV scale. Higher = more detailed patterns."))
37 float Scale = 1.0f;
38};
39
40/**
41 * @struct FIVSmokeHoleDynamicSubject
42 * @brief Dynamic hole generated type data structure
43 */
44USTRUCT()
46{
47 GENERATED_BODY()
48
49 /** Dynamic actors to create holes */
50 UPROPERTY(Transient)
51 TWeakObjectPtr<AActor> TargetActor;
52
53 /** Preset ID. */
54 UPROPERTY(Transient)
55 uint8 PresetID = 0;
56
57 /** Target last world position. */
58 UPROPERTY(Transient)
59 FVector3f LastWorldPosition = FVector3f::ZeroVector;
60
61 /** Target last world rotation. */
62 UPROPERTY(Transient)
63 FQuat LastWorldRotation = FQuat::Identity;
64
65 /** Check valid. */
66 FORCEINLINE bool IsValid() const { return TargetActor.IsValid(); }
67};
68
69/**
70 * @struct FIVSmokeHoleData
71 * @brief Network-optimized hole data structure.
72 */
73USTRUCT()
74struct IVSMOKE_API FIVSmokeHoleData : public FFastArraySerializerItem
75{
76 GENERATED_BODY()
77
78 FIVSmokeHoleData() = default;
79
80 /** This function turns on the dirty flag. */
81 void PostReplicatedAdd(const FIVSmokeHoleArray& InArray);
82
83 /** This function turns on the dirty flag. */
84 void PostReplicatedChange(const FIVSmokeHoleArray& InArray);
85
86 /** This function turns on the dirty flag. */
87 void PreReplicatedRemove(const FIVSmokeHoleArray& InArray);
88
89public:
90
91 /** World position where the hole starts. */
92 UPROPERTY(Transient)
93 FVector3f Position = FVector3f::ZeroVector;
94
95 /** World position where the penetration exits. (Penetration only) */
96 UPROPERTY(Transient)
97 FVector3f EndPosition = FVector3f::ZeroVector;
98
99 /** Hole expiration time (server based). */
100 UPROPERTY(Transient)
101 float ExpirationServerTime = 0.0f;
102
103 /** Preset ID. */
104 UPROPERTY(Transient)
105 uint8 PresetID = 0;
106
107 /** Check if this hole has expired. */
108 FORCEINLINE bool IsExpired(const float CurrentServerTime) const { return CurrentServerTime >= ExpirationServerTime; }
109};
110
111/**
112 * @struct FIVSmokeHoleArray
113 * @brief Fast TArray container for delta replication of hole data.
114 */
115USTRUCT()
116struct IVSMOKE_API FIVSmokeHoleArray : public FFastArraySerializer
117{
118 GENERATED_BODY()
119
120 FIVSmokeHoleArray() : OwnerComponent(nullptr) {}
121
122private:
123 /** Hole data array. */
124 UPROPERTY(Transient, VisibleAnywhere, Category = "IVSmoke | Hole")
125 TArray<FIVSmokeHoleData> Items;
126
127public:
128 /** Owner component reference for replication callbacks. */
129 UPROPERTY(Transient, NotReplicated)
130 TObjectPtr<UIVSmokeHoleGeneratorComponent> OwnerComponent;
131
132 /** FastArray delta replication entry point. */
133 bool NetDeltaSerialize(FNetDeltaSerializeInfo& DeltaParms)
134 {
135 return FFastArraySerializer::FastArrayDeltaSerialize<FIVSmokeHoleData, FIVSmokeHoleArray>(
136 Items, DeltaParms, *this
137 );
138 }
139
140 /** Add new hole and mark dirty. */
141 void AddHole(const FIVSmokeHoleData& NewHole)
142 {
143 Items.Add(NewHole);
144 MarkItemDirty(Items.Last());
145 }
146
147 /** Remove hole by swap and mark dirty. */
148 void RemoveAtSwap(const int32 Index)
149 {
150 if (Items.IsValidIndex(Index))
151 {
152 Items.RemoveAtSwap(Index);
153 MarkArrayDirty();
154 }
155 }
156
157 /** Returns the hole num */
158 FORCEINLINE int32 Num() const { return Items.Num(); }
159
160 /** Returns the index item is valid. */
161 FORCEINLINE bool IsValidIndex(const int32 Index) const { return Items.IsValidIndex(Index); }
162
163 /** Returns the hole data at index. */
164 FORCEINLINE FIVSmokeHoleData& operator[](const int32 Index) { return Items[Index]; }
165
166 /** Returns the hole data at index. */
167 FORCEINLINE const FIVSmokeHoleData& operator[](const int32 Index) const { return Items[Index]; }
168
169 /** Reserve size items array */
170 FORCEINLINE void Reserve(const int32 Number) { Items.Reserve(Number); }
171
172 /** Empty items array and mark dirty. */
173 void Empty();
174
175 /** Converts items array into an array of GPU-compatible hole data structures. */
176 TArray<FIVSmokeHoleGPU> GetHoleGPUData(const float CurrentServerTime) const;
177};
178
179// Enable delta serialization for FIVSmokeHoleArray
180template<>
181struct TStructOpsTypeTraits<FIVSmokeHoleArray> : public TStructOpsTypeTraitsBase2<FIVSmokeHoleArray>
182{
183 enum
184 {
185 WithNetDeltaSerializer = true,
186 };
187};
188
Component that generates hole texture for volumetric smoke. Provides public API for penetration and e...
Fast TArray container for delta replication of hole data.
FORCEINLINE bool IsValidIndex(const int32 Index) const
FORCEINLINE const FIVSmokeHoleData & operator[](const int32 Index) const
void RemoveAtSwap(const int32 Index)
void AddHole(const FIVSmokeHoleData &NewHole)
FORCEINLINE void Reserve(const int32 Number)
FORCEINLINE FIVSmokeHoleData & operator[](const int32 Index)
FORCEINLINE int32 Num() const
Network-optimized hole data structure.
Dynamic hole generated type data structure.
FORCEINLINE bool IsValid() const
Built from FIVSmokeHoleData + UIVSmokeHolePreset at render time.
Noise settings for hole shape distortion.