Commit 2c703fe
committed
Make RNG in multiplayer more random, fix small RNG bug
`AsyncWorldTimeComp` uses the world's ConstantRandomSeed rather than the constant value of 2. Using the world's ConstantRandomSeed should ensure a unique seed for each save (even if using the same seed).
`AsyncTimeComp` is no longer using the constant value of 1. It now uses the map's unique ID to ensure each map has a unique seed, combined with the world's ConstantRandomSeed to ensure a unique seed for each save file as well.
Several of the seeded methods in `Seeds.cs` now also use world's ConstantRandomSeed to make their RNG feel more unique. Some of those could use `Find.TickManager.TicksGame`, either together with or instead of world's ConstantRandomSeed - which would ensure a different outcome based on the passage of time in-game. However, this depends on whether of not we want this.
I've also updated the patch to `PawnRenderer.SetAllGraphicsDirty` to instead target the lambda the method is calling. Given that the lambda is called in a `LongEventHandler.ExecuteWhenFinished` block, the actual call to the lambda may end up being delayed and us seeding the method would do nothing. On top of that, given that pawn rendering is now using multithreading, if this method was called from a different thread - it could potentially cause some issues, since (I believe) RimWorld's RNG is not thread safe. I am unsure if this could happen, but it's better to be safe here.
Sadly, I haven't applied those changes to every single possible method where we're seeding RNG. `SeedGameLoad` is not really possible to safely seed without further changes. Since that this method is called when there's nothing loaded into the game we could use as our seed, the host would have to generate the seed themselves and share it with all the players when they are joining. Given the extra work, I've opted for leaving this as-is for now.
I've also left `RandPatches`, given that those weren't seeded in the first place.1 parent f0221d0 commit 2c703fe
File tree
3 files changed
+27
-11
lines changed- Source/Client
- AsyncTime
- Patches
3 files changed
+27
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
119 | 121 | | |
120 | 122 | | |
121 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
| |||
153 | 161 | | |
154 | 162 | | |
155 | 163 | | |
156 | | - | |
| 164 | + | |
157 | 165 | | |
158 | 166 | | |
159 | 167 | | |
| |||
177 | 185 | | |
178 | 186 | | |
179 | 187 | | |
180 | | - | |
| 188 | + | |
181 | 189 | | |
182 | 190 | | |
183 | 191 | | |
184 | 192 | | |
185 | 193 | | |
186 | | - | |
| 194 | + | |
187 | 195 | | |
188 | 196 | | |
189 | 197 | | |
| |||
0 commit comments