Skip to content

Commit b330a0f

Browse files
authored
refactor(random): Reorder RandomValue function definitions (2) (TheSuperHackers#2405)
1 parent 4473275 commit b330a0f

1 file changed

Lines changed: 60 additions & 60 deletions

File tree

Core/GameEngine/Source/Common/RandomValue.cpp

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -65,50 +65,16 @@ static UnsignedInt theGameLogicSeed[6] =
6565
0xf22d0e56L, 0x883126e9L, 0xc624dd2fL, 0x702c49cL, 0x9e353f7dL, 0x6fdf3b64L
6666
};
6767

68-
// Add with carry. SUM is replaced with A + B + C, C is replaced with 1 if there was a carry, 0 if there wasn't. A carry occurred if the sum is less than one of the inputs. This is addition, so carry can never be more than one.
69-
#define ADC(SUM, A, B, C) SUM = (A) + (B) + (C); C = ((SUM < (A)) || (SUM < (B)))
70-
71-
static UnsignedInt randomValue(UnsignedInt *seed)
68+
UnsignedInt GetGameLogicRandomSeed()
7269
{
73-
UnsignedInt ax;
74-
UnsignedInt c = 0;
75-
76-
77-
ADC(ax, seed[5], seed[4], c); /* mov ax,seed+20 */
78-
/* add ax,seed+16 */
79-
seed[4] = ax; /* mov seed+8,ax */
80-
81-
ADC(ax, ax, seed[3], c); /* adc ax,seed+12 */
82-
seed[3] = ax; /* mov seed+12,ax */
83-
84-
ADC(ax, ax, seed[2], c); /* adc ax,seed+8 */
85-
seed[2] = ax; /* mov seed+8,ax */
86-
87-
ADC(ax, ax, seed[1], c); /* adc ax,seed+4 */
88-
seed[1] = ax; /* mov seed+4,ax */
89-
90-
ADC(ax, ax, seed[0], c); /* adc ax,seed+0 */
91-
seed[0] = ax; /* mov seed+0,ax */
70+
return theGameLogicBaseSeed;
71+
}
9272

93-
/* Increment seed array, bubbling up the carries. */
94-
if (!++seed[5])
95-
{
96-
if (!++seed[4])
97-
{
98-
if (!++seed[3])
99-
{
100-
if (!++seed[2])
101-
{
102-
if (!++seed[1])
103-
{
104-
++seed[0];
105-
++ax;
106-
}
107-
}
108-
}
109-
}
110-
}
111-
return(ax);
73+
UnsignedInt GetGameLogicRandomSeedCRC()
74+
{
75+
CRC c;
76+
c.computeCRC(theGameLogicSeed, 6*sizeof(UnsignedInt));
77+
return c.get();
11278
}
11379

11480
static void seedRandom(UnsignedInt SEED, UnsignedInt *seed)
@@ -130,24 +96,6 @@ static void seedRandom(UnsignedInt SEED, UnsignedInt *seed)
13096
seed[5] = ax; /* mov seed+20,eax */
13197
}
13298

133-
//
134-
// It is necessary to separate the GameClient and GameLogic usage of random
135-
// values to ensure that the GameLogic remains deterministic, regardless
136-
// of the effects displayed on the GameClient.
137-
//
138-
139-
UnsignedInt GetGameLogicRandomSeed()
140-
{
141-
return theGameLogicBaseSeed;
142-
}
143-
144-
UnsignedInt GetGameLogicRandomSeedCRC()
145-
{
146-
CRC c;
147-
c.computeCRC(theGameLogicSeed, 6*sizeof(UnsignedInt));
148-
return c.get();
149-
}
150-
15199
void InitRandom()
152100
{
153101
#ifdef DETERMINISTIC
@@ -177,6 +125,58 @@ DEBUG_LOG(( "InitRandom %08lx",seed));
177125
#endif
178126
}
179127

128+
// Add with carry. SUM is replaced with A + B + C, C is replaced with 1 if there was a carry, 0 if there wasn't. A carry occurred if the sum is less than one of the inputs. This is addition, so carry can never be more than one.
129+
#define ADC(SUM, A, B, C) SUM = (A) + (B) + (C); C = ((SUM < (A)) || (SUM < (B)))
130+
131+
static UnsignedInt randomValue(UnsignedInt *seed)
132+
{
133+
UnsignedInt ax;
134+
UnsignedInt c = 0;
135+
136+
137+
ADC(ax, seed[5], seed[4], c); /* mov ax,seed+20 */
138+
/* add ax,seed+16 */
139+
seed[4] = ax; /* mov seed+8,ax */
140+
141+
ADC(ax, ax, seed[3], c); /* adc ax,seed+12 */
142+
seed[3] = ax; /* mov seed+12,ax */
143+
144+
ADC(ax, ax, seed[2], c); /* adc ax,seed+8 */
145+
seed[2] = ax; /* mov seed+8,ax */
146+
147+
ADC(ax, ax, seed[1], c); /* adc ax,seed+4 */
148+
seed[1] = ax; /* mov seed+4,ax */
149+
150+
ADC(ax, ax, seed[0], c); /* adc ax,seed+0 */
151+
seed[0] = ax; /* mov seed+0,ax */
152+
153+
/* Increment seed array, bubbling up the carries. */
154+
if (!++seed[5])
155+
{
156+
if (!++seed[4])
157+
{
158+
if (!++seed[3])
159+
{
160+
if (!++seed[2])
161+
{
162+
if (!++seed[1])
163+
{
164+
++seed[0];
165+
++ax;
166+
}
167+
}
168+
}
169+
}
170+
}
171+
return(ax);
172+
}
173+
174+
//
175+
// It is necessary to separate the GameClient and GameLogic usage of random
176+
// values to ensure that the GameLogic remains deterministic, regardless
177+
// of the effects displayed on the GameClient.
178+
//
179+
180180
//
181181
// Integer random value
182182
//

0 commit comments

Comments
 (0)