Global.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #define Global
  2. #ifdef WIN32
  3. # include <objidl.h>
  4. #endif
  5. #include "DLLRegister.h"
  6. #include "File.h"
  7. #include "Globals.h"
  8. #include "Logging.h"
  9. #include "Model3DList.h"
  10. #include "TextureList.h"
  11. #include "Thread.h"
  12. #include "Timer.h"
  13. #include "Window.h"
  14. #ifdef WIN32
  15. # include <GdiPlus.h>
  16. # pragma comment(lib, "gdiplus.lib")
  17. # include "Mouse.h"
  18. # include "Window.h"
  19. #else
  20. # include <unistd.h>
  21. #endif
  22. void Framework::initFramework(HINSTANCE__* hInst)
  23. {
  24. if (isInitialized) return;
  25. #ifdef WIN32
  26. currentThreadId = GetCurrentThreadId();
  27. #else
  28. currentThreadId = gettid();
  29. #endif
  30. loggingHandler = new Logging::LoggingHandler();
  31. thRegister = new ThreadRegister();
  32. #ifdef WIN32
  33. Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  34. ULONG_PTR gdiplusToken;
  35. Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, 0);
  36. msgExit = 0;
  37. MouseTrack = 1;
  38. #endif
  39. for (int i = 0; i < 3; ++i)
  40. MouseState[i] = 0;
  41. dlls = new DLLRegister();
  42. _hinst = hInst;
  43. isInitialized = 1;
  44. debugDX = 0;
  45. cursorVisible = 1;
  46. }
  47. void Framework::releaseFramework()
  48. {
  49. if (!isInitialized) return;
  50. thRegister->cleanUpClosedThreads();
  51. dlls->release();
  52. delete thRegister;
  53. loggingHandler->release();
  54. isInitialized = 0;
  55. }
  56. bool Framework::isThreadOk(Thread* t)
  57. {
  58. return thRegister->isThread(t);
  59. }
  60. // Returns the thread register of the framework
  61. Framework::ThreadRegister* Framework::getThreadRegister()
  62. {
  63. return thRegister;
  64. }
  65. #ifdef WIN32
  66. Framework::Point Framework::getMousePos()
  67. {
  68. POINT point;
  69. GetCursorPos(&point);
  70. return {point.x, point.y};
  71. }
  72. //! Sets the mouse position on the screen
  73. void Framework::setMousePos(const Point& pos)
  74. {
  75. SetCursorPos(pos.x, pos.y);
  76. }
  77. #endif
  78. bool Framework::getMouseState(int key)
  79. {
  80. return MouseState[key];
  81. }
  82. bool Framework::getKeyState(unsigned char key)
  83. {
  84. #ifdef WIN32
  85. return GetKeyState(key) & 0x8000;
  86. #else
  87. return 0;
  88. #endif
  89. }
  90. // Returns the DLL register containing all currently dynamically loaded DLLs
  91. Framework::DLLRegister* Framework::getDLLRegister()
  92. {
  93. return Framework::dlls;
  94. }
  95. //! Sets DirectX to debug mode
  96. void Framework::setDebugDX(bool debug)
  97. {
  98. debugDX = debug;
  99. }
  100. #ifdef WIN32
  101. // returns a reference to the mouse
  102. Framework::Mouse& Framework::getMouse()
  103. {
  104. return Framework::mousePointer;
  105. }
  106. //! sets the mouse state to visible or invisible
  107. void Framework::setShowCursor(bool visible)
  108. {
  109. CURSORINFO info = {0};
  110. info.cbSize = sizeof(CURSORINFO);
  111. GetCursorInfo(&info);
  112. if ((info.flags != 0) == (visible == 0)) ShowCursor(visible);
  113. cursorVisible = visible;
  114. }
  115. #endif