Yasiu Math 1
Collection of mathematic functions that help create game mechanics and procedural tools
Loading...
Searching...
No Matches
SquirrelRNG.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Grzegorz Krug.
3 * All Rights Reserved.
4 */
5
7
8#pragma once
9
10
11#include "Components/ActorComponent.h"
12
13
14#include "SquirrelRNG.generated.h"
15
16
26UCLASS(BlueprintType, Blueprintable, DefaultToInstanced)
27class YASIUMATH_API USquirrel13 : public UObject {
28public:
29 GENERATED_BODY()
30
31 USquirrel13() {};
32
33 USquirrel13( unsigned int seed )
34 : m_seed(seed), init_seed(seed) {};
35
36 USquirrel13( int position, unsigned int seed )
37 : m_position(position), m_seed(seed), init_position(position), init_seed(seed) {};
38
39 USquirrel13( int position, unsigned int seed, unsigned int variant )
40 : m_position(position), m_seed(seed), m_variant(variant), init_position(position), init_seed(seed) {};
41
42 virtual void GetLifetimeReplicatedProps( TArray<class FLifetimeProperty>& OutLifetimeProps ) const override;
43
45 virtual void Serialize( FArchive& Ar ) override;
46
47
48protected:
49 UPROPERTY(Replicated, SaveGame)
50 int m_position{0};
51
52 UPROPERTY(Replicated, SaveGame)
53 uint32 m_seed{1};
54
56 UPROPERTY(Replicated, SaveGame)
57 int m_variant{0};
58
59 UPROPERTY(Replicated)
60 uint32 init_position = 0;
61
62 UPROPERTY(Replicated)
63 int32 init_seed = 0;
64
65
66public:
71 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
72 void InitBP( int seed, int position = 0 );
73
75 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
76 int GetCurrentInt( int min, int max ) const;
77
79 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
80 int GetNextInt( int min, int max );
81
83 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
84 double GetCurrentDouble() const;
85
89 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
90 double GetNextDouble();
91
93 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
94 int GetPosition() const;
95
97 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
98 void SetPosition( int new_position );
99
104 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
105 void OffsetPosition( int offset = 1 );
106
108 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
109 int32 GetSeed() const;
110
112 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
113 void SetSeed( int new_seed );
114
118 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
119 void SetNoiseVariant( int newVariant = 0 );
120
122 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
124
125
126protected:
128 virtual uint32 get_current_random() const;
129
131 uint32 get_next_random();
132
134 static uint32 RNG_0( int position, unsigned int seed );
135
137 static uint32 RNG_1( int position, unsigned int seed );
138
140 static uint32 RNG_2( int position, unsigned int seed );
141
143 static uint32 RNG_3( int position, unsigned int seed );
144
146 static uint32 RNG_4( int position, unsigned int seed );
147
149 static uint32 RNG_5( int position, unsigned int seed );
150};
151
152
158UCLASS(BlueprintType, Blueprintable, meta=(BlueprintSpawnableComponent), DefaultToInstanced)
159class YASIUMATH_API USquirrel13_RNGComponent : public UActorComponent {
160 GENERATED_BODY()
161
162
163public:
164 USquirrel13_RNGComponent();
165
166 virtual void GetLifetimeReplicatedProps( TArray<class FLifetimeProperty>& OutLifetimeProps ) const override;
167
168 UPROPERTY(BlueprintReadWrite, Replicated, Category="Yasiu|RNG")
169 TObjectPtr<USquirrel13> RNG;
170
176 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
177 void InitBP( int seed, int pos = 0 );
178
179 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
180 int32 GetSeed() const;
181
182 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
183 void SetSeed( int64 Seed );
184
185 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
186 int GetPosition() const;
187
188 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
189 void SetPosition( int Pos );
190
191 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG", BlueprintPure=false)
192 int GetCurrentInt( int min, int max ) const;
193
194 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
195 int GetNextInt( int min, int max );
196
197 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG", BlueprintPure=false)
198 double GetCurrentDouble() const;
199
200 UFUNCTION(BlueprintCallable, Category="Yasiu|RNG")
201 double GetNextDouble();
202};
void InitBP(int seed, int pos=0)
Initialize values of RNG.
void SetSeed(int new_seed)
Set seed noise seed.
int GetCurrentInt(int min, int max) const
Return random value scaled to integer range <min, max> at current position.
virtual void Serialize(FArchive &Ar) override
Serialization of RNG Object.
static uint32 RNG_4(int position, unsigned int seed)
Noise variant.
void OffsetPosition(int offset=1)
Offset current position, can be positive and negative.
static uint32 RNG_3(int position, unsigned int seed)
Noise variant.
double GetNextDouble()
Move position by 1 and return double in range <0, 1>.
void InitBP(int seed, int position=0)
Modify internal values to custom.
static uint32 RNG_2(int position, unsigned int seed)
Noise variant.
int GetNextInt(int min, int max)
Move position by 1 and return random value as integer in range <min, max>.
void SetPosition(int new_position)
Set generator position.
static uint32 RNG_1(int position, unsigned int seed)
Noise variant.
int32 GetSeed() const
Get generator position.
void ResetSeedPos()
Reset to internal initial values, InitBP must be used before!
int m_variant
variable related to selected noise variant
Definition SquirrelRNG.h:57
void SetNoiseVariant(int newVariant=0)
Internal noise variants (it is not initialized, but saved), default=0, max=5 Invalid variants will us...
static uint32 RNG_5(int position, unsigned int seed)
Noise variant.
double GetCurrentDouble() const
Return last random double in range <0, 1>.
static uint32 RNG_0(int position, unsigned int seed)
Noise variant.
int GetPosition() const
Get generator position.