os.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "irrTypes.h"
  6. #include "irrString.h"
  7. #include "path.h"
  8. #include "ILogger.h"
  9. #include "ITimer.h"
  10. // CODE_UNREACHABLE(): Invokes undefined behavior for unreachable code optimization
  11. #if defined(__cpp_lib_unreachable)
  12. #include <utility>
  13. #define CODE_UNREACHABLE() std::unreachable()
  14. #elif defined(__has_builtin)
  15. #if __has_builtin(__builtin_unreachable)
  16. #define CODE_UNREACHABLE() __builtin_unreachable()
  17. #endif
  18. #elif defined(_MSC_VER)
  19. #define CODE_UNREACHABLE() __assume(false)
  20. #endif
  21. #ifndef CODE_UNREACHABLE
  22. #define CODE_UNREACHABLE() (void)0
  23. #endif
  24. namespace irr
  25. {
  26. namespace os
  27. {
  28. class Byteswap
  29. {
  30. public:
  31. static u16 byteswap(u16 num);
  32. static s16 byteswap(s16 num);
  33. static u32 byteswap(u32 num);
  34. static s32 byteswap(s32 num);
  35. static u64 byteswap(u64 num);
  36. static s64 byteswap(s64 num);
  37. static f32 byteswap(f32 num);
  38. // prevent accidental swapping of chars
  39. static inline u8 byteswap(u8 num) { return num; }
  40. static inline c8 byteswap(c8 num) { return num; }
  41. };
  42. class Printer
  43. {
  44. public:
  45. // prints out a string to the console out stdout or debug log or whatever
  46. static void print(const c8 *message, ELOG_LEVEL ll = ELL_INFORMATION);
  47. static void log(const c8 *message, ELOG_LEVEL ll = ELL_INFORMATION);
  48. // The string ": " is added between message and hint
  49. static void log(const c8 *message, const c8 *hint, ELOG_LEVEL ll = ELL_INFORMATION);
  50. static void log(const c8 *message, const io::path &hint, ELOG_LEVEL ll = ELL_INFORMATION);
  51. static ILogger *Logger;
  52. };
  53. class Timer
  54. {
  55. public:
  56. //! returns the current time in milliseconds
  57. static u32 getTime();
  58. //! initializes the real timer
  59. static void initTimer();
  60. //! sets the current virtual (game) time
  61. static void setTime(u32 time);
  62. //! stops the virtual (game) timer
  63. static void stopTimer();
  64. //! starts the game timer
  65. static void startTimer();
  66. //! sets the speed of the virtual timer
  67. static void setSpeed(f32 speed);
  68. //! gets the speed of the virtual timer
  69. static f32 getSpeed();
  70. //! returns if the timer currently is stopped
  71. static bool isStopped();
  72. //! makes the virtual timer update the time value based on the real time
  73. static void tick();
  74. //! returns the current real time in milliseconds
  75. static u32 getRealTime();
  76. private:
  77. static void initVirtualTimer();
  78. static f32 VirtualTimerSpeed;
  79. static s32 VirtualTimerStopCounter;
  80. static u32 StartRealTime;
  81. static u32 LastVirtualTime;
  82. static u32 StaticTime;
  83. };
  84. } // end namespace os
  85. } // end namespace irr