api_random.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef NULLSOFT_API_RANDOM_H
  2. #define NULLSOFT_API_RANDOM_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/platform/types.h>
  5. typedef int (*RandomGenerator)(void);
  6. typedef unsigned long (*UnsignedRandomGenerator)(void);
  7. class api_random : public Dispatchable
  8. {
  9. protected:
  10. api_random() {}
  11. ~api_random() {}
  12. public:
  13. RandomGenerator GetFunction();
  14. UnsignedRandomGenerator GetUnsignedFunction();
  15. int GetNumber();
  16. int GetPositiveNumber();
  17. float GetFloat(); // [0-1]
  18. float GetFloat_LessThanOne(); // [0-1)
  19. float GetFloat_LessThanOne_NotZero(); // (0-1)
  20. double GetDouble(); // [0-1)
  21. public:
  22. DISPATCH_CODES
  23. {
  24. API_RANDOM_GETFUNCTION = 10,
  25. API_RANDOM_GETFUNCTION_UNSIGNED = 11,
  26. API_RANDOM_GETNUMBER = 20,
  27. API_RANDOM_GETPOSITIVENUMBER = 30,
  28. API_RANDOM_GETFLOAT = 40,
  29. API_RANDOM_GETFLOAT2 = 41,
  30. API_RANDOM_GETFLOAT3 = 42,
  31. API_RANDOM_GETDOUBLE = 50,
  32. };
  33. };
  34. inline RandomGenerator api_random::GetFunction()
  35. {
  36. return _call(API_RANDOM_GETFUNCTION, (RandomGenerator )0);
  37. }
  38. inline UnsignedRandomGenerator api_random::GetUnsignedFunction()
  39. {
  40. return _call(API_RANDOM_GETFUNCTION_UNSIGNED, (UnsignedRandomGenerator )0);
  41. }
  42. inline int api_random::GetNumber()
  43. {
  44. return _call(API_RANDOM_GETNUMBER, 0);
  45. }
  46. inline int api_random::GetPositiveNumber()
  47. {
  48. return _call(API_RANDOM_GETPOSITIVENUMBER, 0);
  49. }
  50. inline float api_random::GetFloat()
  51. {
  52. return _call(API_RANDOM_GETFLOAT, 0.f);
  53. }
  54. inline float api_random::GetFloat_LessThanOne()
  55. {
  56. return _call(API_RANDOM_GETFLOAT2, 0.f);
  57. }
  58. inline float api_random::GetFloat_LessThanOne_NotZero()
  59. {
  60. return _call(API_RANDOM_GETFLOAT3, 0.f);
  61. }
  62. inline double api_random::GetDouble()
  63. {
  64. return _call(API_RANDOM_GETDOUBLE, 0.);
  65. }
  66. // {CB401CAB-CC10-48f7-ADB7-9D1D24B40E0C}
  67. static const GUID randomApiGUID =
  68. { 0xcb401cab, 0xcc10, 0x48f7, { 0xad, 0xb7, 0x9d, 0x1d, 0x24, 0xb4, 0xe, 0xc } };
  69. #endif