m_random.h 2.69 KB
Newer Older
Alam Ed Arias committed
1 2 3 4
// SONIC ROBO BLAST 2
//-----------------------------------------------------------------------------
// Copyright (C) 1993-1996 by id Software, Inc.
// Copyright (C) 1998-2000 by DooM Legacy Team.
5
// Copyright (C) 2012-2016 by Matthew "Kaito Sinclaire" Walsh.
James R. committed
6
// Copyright (C) 1999-2020 by Sonic Team Junior.
Alam Ed Arias committed
7 8 9 10 11 12
//
// This program is free software distributed under the
// terms of the GNU General Public License, version 2.
// See the 'LICENSE' file for more details.
//-----------------------------------------------------------------------------
/// \file  m_random.h
13
/// \brief RNG for client effects and PRNG for game actions
Alam Ed Arias committed
14 15 16 17 18 19 20

#ifndef __M_RANDOM__
#define __M_RANDOM__

#include "doomtype.h"
#include "m_fixed.h"

Alam Ed Arias committed
21 22
//#define DEBUGRANDOM

23

Alam Ed Arias committed
24
// M_Random functions pull random numbers of various types that aren't network synced.
25
// P_Random functions pulls random bytes from a PRNG that is network synced.
Alam Ed Arias committed
26 27

// RNG functions
Inuyasha committed
28 29 30 31
fixed_t M_RandomFixed(void);
UINT8   M_RandomByte(void);
INT32   M_RandomKey(INT32 a);
INT32   M_RandomRange(INT32 a, INT32 b);
Alam Ed Arias committed
32 33 34

// PRNG functions
#ifdef DEBUGRANDOM
35
#define P_RandomFixed()     P_RandomFixedD(__FILE__, __LINE__)
Inuyasha committed
36
#define P_RandomByte()      P_RandomByteD(__FILE__, __LINE__)
37
#define P_RandomKey(c)      P_RandomKeyD(__FILE__, __LINE__, c)
Alam Ed Arias committed
38
#define P_RandomRange(c, d) P_RandomRangeD(__FILE__, __LINE__, c, d)
39
fixed_t P_RandomFixedD(const char *rfile, INT32 rline);
Inuyasha committed
40 41 42
UINT8   P_RandomByteD(const char *rfile, INT32 rline);
INT32   P_RandomKeyD(const char *rfile, INT32 rline, INT32 a);
INT32   P_RandomRangeD(const char *rfile, INT32 rline, INT32 a, INT32 b);
Alam Ed Arias committed
43
#else
44
fixed_t P_RandomFixed(void);
Inuyasha committed
45 46 47
UINT8   P_RandomByte(void);
INT32   P_RandomKey(INT32 a);
INT32   P_RandomRange(INT32 a, INT32 b);
Alam Ed Arias committed
48
#endif
Inuyasha committed
49 50 51 52 53 54 55 56 57

// Macros for other functions
#define M_SignedRandom()  ((INT32)M_RandomByte() - 128) // [-128, 127] signed byte, originally a
#define P_SignedRandom()  ((INT32)P_RandomByte() - 128) // function of its own, moved to a macro

#define M_RandomChance(p) (M_RandomFixed() < p) // given fixed point probability, p, between 0 (0%)
#define P_RandomChance(p) (P_RandomFixed() < p) // and FRACUNIT (100%), returns true p% of the time

// Debugging
58
fixed_t P_RandomPeek(void);
Alam Ed Arias committed
59 60

// Working with the seed for PRNG
Alam Ed Arias committed
61 62 63 64 65 66 67 68
#ifdef DEBUGRANDOM
#define P_GetRandSeed() P_GetRandSeedD(__FILE__, __LINE__)
#define P_GetInitSeed() P_GetInitSeedD(__FILE__, __LINE__)
#define P_SetRandSeed(s) P_SetRandSeedD(__FILE__, __LINE__, s)
UINT32 P_GetRandSeedD(const char *rfile, INT32 rline);
UINT32 P_GetInitSeedD(const char *rfile, INT32 rline);
void P_SetRandSeedD(const char *rfile, INT32 rline, UINT32 seed);
#else
Alam Ed Arias committed
69 70 71
UINT32 P_GetRandSeed(void);
UINT32 P_GetInitSeed(void);
void P_SetRandSeed(UINT32 seed);
Alam Ed Arias committed
72
#endif
Alam Ed Arias committed
73 74 75
UINT32 M_RandomizedSeed(void);

#endif