File tree 3 files changed +15
-9
lines changed
script/nodes/flow_control
3 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -66,12 +66,12 @@ String Guid::to_string() const
66
66
67
67
Guid Guid::create_guid ()
68
68
{
69
- RandomNumberGenerator rng;
69
+ Ref< RandomNumberGenerator> rng ( memnew (RandomNumberGenerator)) ;
70
70
71
- uint32_t a = rng. randi ();
72
- uint32_t b = rng. randi ();
73
- uint32_t c = rng. randi ();
74
- uint32_t d = rng. randi ();
71
+ uint32_t a = rng-> randi ();
72
+ uint32_t b = rng-> randi ();
73
+ uint32_t c = rng-> randi ();
74
+ uint32_t d = rng-> randi ();
75
75
76
76
// The 4 bits of digit M indicate the GUID version, and the 1-3 most significant bits
77
77
// of digit N indicate the UUID variant.
Original file line number Diff line number Diff line change 19
19
class OScriptNodeChanceInstance : public OScriptNodeInstance
20
20
{
21
21
DECLARE_SCRIPT_NODE_INSTANCE (OScriptNodeChance);
22
- RandomNumberGenerator _random;
22
+ Ref< RandomNumberGenerator> _random;
23
23
int _chance{ 0 };
24
24
25
25
public:
26
26
int step (OScriptExecutionContext& p_context) override
27
27
{
28
- const int _calculated_chance = _random.randi_range (0 , 100 );
28
+ if (!_random.is_valid ())
29
+ _random.instantiate ();
30
+
31
+ const int _calculated_chance = _random->randi_range (0 , 100 );
29
32
return _calculated_chance <= _chance ? 0 : 1 ;
30
33
}
31
34
};
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ class OScriptNodeRandomInstance : public OScriptNodeInstance
20
20
{
21
21
DECLARE_SCRIPT_NODE_INSTANCE (OScriptNodeRandom);
22
22
23
- RandomNumberGenerator _random;
23
+ Ref< RandomNumberGenerator> _random;
24
24
int _possibilities{ 0 };
25
25
26
26
public:
@@ -29,7 +29,10 @@ class OScriptNodeRandomInstance : public OScriptNodeInstance
29
29
if (_possibilities == 0 )
30
30
return -1 ;
31
31
32
- return _random.randi_range (0 , _possibilities - 1 );
32
+ if (!_random.is_valid ())
33
+ _random.instantiate ();
34
+
35
+ return _random->randi_range (0 , _possibilities - 1 );
33
36
}
34
37
};
35
38
You can’t perform that action at this time.
0 commit comments