Ignore:
Timestamp:
11/30/19 01:30:22 (4 years ago)
Author:
Maciej Komosinski
Message:

Replaced #defined macros for popular random-related operations with functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd_math.h

    r835 r896  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2019  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    2121//random number generator:
    2222#include "random.h"
    23 RandomGenerator& rndGetInstance();
     23RandomGenerator &rndGetInstance();
    2424
    25 #define rnd01 (rndGetInstance().getDouble())
    26 #define rnd0N(limit) (rndGetInstance().getDouble()*(limit))
    27 #define randomN(limit) ((unsigned int)(rndGetInstance().getDouble()*(limit)))
    28 #define setRandomSeed(seed) rndGetInstance().setSeed(seed)
    29 #define setRandomRandomSeed() rndGetInstance().randomize()
    30 
     25inline double rndDouble(double limit_exclusive) { return rndGetInstance().getDouble() * limit_exclusive; }
     26inline unsigned int rndUint(unsigned int limit_exclusive) { return (unsigned int)(rndGetInstance().getDouble() * limit_exclusive); } //returns random from 0..limit_exclusive-1
     27inline void rndSetSeed(unsigned int seed) { rndGetInstance().setSeed(seed); }
     28inline unsigned int rndRandomizeSeed() { return rndGetInstance().randomize(); }
    3129
    3230//floating point specific numbers
     
    6664void fpExceptDisable();
    6765
     66// std::lerp can be used since c++20 (and has some guaranteed properties probably better than this basic formula) but apparently it is not a template
     67template <typename Value, typename Linear> Value universal_lerp(Value a,Value b,Linear t) {return a*(1-t)+b*t;}
     68
    6869#endif
    6970
Note: See TracChangeset for help on using the changeset viewer.