Global.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. currentThreadLockCount = 0;
  26. #ifdef WIN32
  27. currentThreadId = GetCurrentThreadId();
  28. #else
  29. currentThreadId = gettid();
  30. #endif
  31. loggingHandler = new Logging::LoggingHandler();
  32. thRegister = new ThreadRegister();
  33. #ifdef WIN32
  34. Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  35. ULONG_PTR gdiplusToken;
  36. Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, 0);
  37. msgExit = 0;
  38. MouseTrack = 1;
  39. #endif
  40. for (int i = 0; i < 3; ++i)
  41. MouseState[i] = 0;
  42. dlls = new DLLRegister();
  43. _hinst = hInst;
  44. isInitialized = 1;
  45. debugDX = 0;
  46. cursorVisible = 1;
  47. }
  48. void Framework::releaseFramework()
  49. {
  50. if (!isInitialized) return;
  51. thRegister->cleanUpClosedThreads();
  52. dlls->release();
  53. delete thRegister;
  54. loggingHandler->release();
  55. isInitialized = 0;
  56. }
  57. bool Framework::isThreadOk(Thread* t)
  58. {
  59. return thRegister->isThread(t);
  60. }
  61. // Returns the thread register of the framework
  62. Framework::ThreadRegister* Framework::getThreadRegister()
  63. {
  64. return thRegister;
  65. }
  66. #ifdef WIN32
  67. Framework::Point Framework::getMousePos()
  68. {
  69. POINT point;
  70. GetCursorPos(&point);
  71. return {point.x, point.y};
  72. }
  73. //! Sets the mouse position on the screen
  74. void Framework::setMousePos(const Point& pos)
  75. {
  76. SetCursorPos(pos.x, pos.y);
  77. }
  78. #endif
  79. bool Framework::getMouseState(int key)
  80. {
  81. return MouseState[key];
  82. }
  83. bool Framework::getKeyState(unsigned char key)
  84. {
  85. #ifdef WIN32
  86. return GetKeyState(key) & 0x8000;
  87. #else
  88. return 0;
  89. #endif
  90. }
  91. // Returns the DLL register containing all currently dynamically loaded DLLs
  92. Framework::DLLRegister* Framework::getDLLRegister()
  93. {
  94. return Framework::dlls;
  95. }
  96. //! Sets DirectX to debug mode
  97. void Framework::setDebugDX(bool debug)
  98. {
  99. debugDX = debug;
  100. }
  101. #ifdef WIN32
  102. // returns a reference to the mouse
  103. Framework::Mouse& Framework::getMouse()
  104. {
  105. return Framework::mousePointer;
  106. }
  107. //! sets the mouse state to visible or invisible
  108. void Framework::setShowCursor(bool visible)
  109. {
  110. CURSORINFO info = {0};
  111. info.cbSize = sizeof(CURSORINFO);
  112. GetCursorInfo(&info);
  113. if ((info.flags != 0) == (visible == 0)) ShowCursor(visible);
  114. cursorVisible = visible;
  115. }
  116. int Framework::getCurrentThreadId()
  117. {
  118. return currentThreadId;
  119. }
  120. int Framework::getCurrentThreadLockCount()
  121. {
  122. return currentThreadLockCount;
  123. }
  124. #endif