Global.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. loggingHandler->release(); // must be cleaned up before the thread register
  52. // because it may reference threads
  53. thRegister->cleanUpClosedThreads();
  54. dlls->release();
  55. delete thRegister;
  56. isInitialized = 0;
  57. }
  58. bool Framework::isThreadOk(Thread* t)
  59. {
  60. return thRegister->isThread(t);
  61. }
  62. // Returns the thread register of the framework
  63. Framework::ThreadRegister* Framework::getThreadRegister()
  64. {
  65. return thRegister;
  66. }
  67. #ifdef WIN32
  68. Framework::Point Framework::getMousePos()
  69. {
  70. POINT point;
  71. GetCursorPos(&point);
  72. return {point.x, point.y};
  73. }
  74. //! Sets the mouse position on the screen
  75. void Framework::setMousePos(const Point& pos)
  76. {
  77. SetCursorPos(pos.x, pos.y);
  78. }
  79. #endif
  80. bool Framework::getMouseState(int key)
  81. {
  82. return MouseState[key];
  83. }
  84. bool Framework::getKeyState(unsigned char key)
  85. {
  86. #ifdef WIN32
  87. return GetKeyState(key) & 0x8000;
  88. #else
  89. return 0;
  90. #endif
  91. }
  92. // Returns the DLL register containing all currently dynamically loaded DLLs
  93. Framework::DLLRegister* Framework::getDLLRegister()
  94. {
  95. return Framework::dlls;
  96. }
  97. //! Sets DirectX to debug mode
  98. void Framework::setDebugDX(bool debug)
  99. {
  100. debugDX = debug;
  101. }
  102. #ifdef WIN32
  103. // returns a reference to the mouse
  104. Framework::Mouse& Framework::getMouse()
  105. {
  106. return Framework::mousePointer;
  107. }
  108. //! sets the mouse state to visible or invisible
  109. void Framework::setShowCursor(bool visible)
  110. {
  111. CURSORINFO info = {0};
  112. info.cbSize = sizeof(CURSORINFO);
  113. GetCursorInfo(&info);
  114. if ((info.flags != 0) == (visible == 0)) ShowCursor(visible);
  115. cursorVisible = visible;
  116. }
  117. int Framework::getCurrentThreadId()
  118. {
  119. return currentThreadId;
  120. }
  121. int Framework::getCurrentThreadLockCount()
  122. {
  123. return currentThreadLockCount;
  124. }
  125. #endif