2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
2020-01-06 22:16:27 +00:00
|
|
|
// Copyright (C) 2012-2016 by Matthew "Kaito Sinclaire" Walsh.
|
2023-03-31 12:53:31 +00:00
|
|
|
// Copyright (C) 1999-2023 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// 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
|
2016-05-18 00:42:11 +00:00
|
|
|
/// \brief RNG for client effects and PRNG for game actions
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
#ifndef __M_RANDOM__
|
|
|
|
#define __M_RANDOM__
|
|
|
|
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "m_fixed.h"
|
|
|
|
|
2014-03-17 12:13:16 +00:00
|
|
|
//#define DEBUGRANDOM
|
|
|
|
|
2016-03-26 22:48:12 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// M_Random functions pull random numbers of various types that aren't network synced.
|
2016-03-26 22:48:12 +00:00
|
|
|
// P_Random functions pulls random bytes from a PRNG that is network synced.
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// RNG functions
|
2016-03-27 14:33:15 +00:00
|
|
|
fixed_t M_RandomFixed(void);
|
|
|
|
UINT8 M_RandomByte(void);
|
|
|
|
INT32 M_RandomKey(INT32 a);
|
|
|
|
INT32 M_RandomRange(INT32 a, INT32 b);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// PRNG functions
|
|
|
|
#ifdef DEBUGRANDOM
|
2016-03-26 22:48:12 +00:00
|
|
|
#define P_RandomFixed() P_RandomFixedD(__FILE__, __LINE__)
|
2016-03-27 14:33:15 +00:00
|
|
|
#define P_RandomByte() P_RandomByteD(__FILE__, __LINE__)
|
2016-03-26 22:48:12 +00:00
|
|
|
#define P_RandomKey(c) P_RandomKeyD(__FILE__, __LINE__, c)
|
2014-03-15 16:59:03 +00:00
|
|
|
#define P_RandomRange(c, d) P_RandomRangeD(__FILE__, __LINE__, c, d)
|
2016-03-26 22:48:12 +00:00
|
|
|
fixed_t P_RandomFixedD(const char *rfile, INT32 rline);
|
2016-03-27 14:33:15 +00:00
|
|
|
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);
|
2014-03-15 16:59:03 +00:00
|
|
|
#else
|
2016-03-26 22:48:12 +00:00
|
|
|
fixed_t P_RandomFixed(void);
|
2016-03-27 14:33:15 +00:00
|
|
|
UINT8 P_RandomByte(void);
|
|
|
|
INT32 P_RandomKey(INT32 a);
|
|
|
|
INT32 P_RandomRange(INT32 a, INT32 b);
|
2014-03-15 16:59:03 +00:00
|
|
|
#endif
|
2016-03-27 14:33:15 +00:00
|
|
|
|
|
|
|
// 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
|
2016-03-26 22:48:12 +00:00
|
|
|
fixed_t P_RandomPeek(void);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// Working with the seed for PRNG
|
2014-03-17 12:13:16 +00:00
|
|
|
#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
|
2014-03-15 16:59:03 +00:00
|
|
|
UINT32 P_GetRandSeed(void);
|
|
|
|
UINT32 P_GetInitSeed(void);
|
|
|
|
void P_SetRandSeed(UINT32 seed);
|
2014-03-17 12:13:16 +00:00
|
|
|
#endif
|
2014-03-15 16:59:03 +00:00
|
|
|
UINT32 M_RandomizedSeed(void);
|
|
|
|
|
|
|
|
#endif
|