POSIXState.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "math/mPoint2.h"
  23. #include "platformPOSIX/platformPOSIX.h"
  24. //#include "platformX86UNIX/platformGL.h"
  25. #include "core/strings/stringFunctions.h"
  26. #define Display int
  27. #define Window int
  28. #define Screen int
  29. #include <libgen.h> // for basename
  30. typedef void (*LockFunc_t)(void);
  31. class x86UNIXPlatformState
  32. {
  33. private:
  34. Point2I mDesktopSize;
  35. Point2I mWindowSize;
  36. S32 mDesktopBpp;
  37. Display *mDisplay;
  38. Window mCurrentWindow;
  39. Screen *mScreenPointer;
  40. int mScreenNumber;
  41. char mWindowName[40];
  42. char mExePathName[4096];
  43. char mExeName[40];
  44. bool mWindowCreated;
  45. bool mWindowActive;
  46. bool mWindowLocked;
  47. bool mXWindowsRunning;
  48. bool mDedicated;
  49. bool mCDAudioEnabled;
  50. bool mDSleep;
  51. bool mUseRedirect;
  52. public:
  53. U32 currentTime;
  54. void setDisplayPointer( Display *displayPointer ) { mDisplay = displayPointer; }
  55. Display* getDisplayPointer() { return mDisplay; }
  56. void setScreenNumber( int newNumber ) { mScreenNumber = newNumber; }
  57. int getScreenNumber() { return mScreenNumber; }
  58. void setScreenPointer( Screen *newScreenPointer )
  59. { mScreenPointer = newScreenPointer; }
  60. Screen * getScreenPointer() { return mScreenPointer; }
  61. // for compatibility, convert 24 bpp to 32
  62. void setDesktopBpp( S32 bpp )
  63. {
  64. if (bpp == 24)
  65. mDesktopBpp = 32;
  66. else
  67. mDesktopBpp = bpp;
  68. }
  69. S32 getDesktopBpp() { return mDesktopBpp; }
  70. void setDesktopSize( S32 horizontal, S32 vertical )
  71. { mDesktopSize.set( horizontal, vertical ); }
  72. Point2I getDesktopSize() { return mDesktopSize; }
  73. void setWindow( Window newWindow ) { mCurrentWindow = newWindow; }
  74. Window getWindow() { return mCurrentWindow; }
  75. void setWindowSize (S32 horizontal, S32 vertical )
  76. { mWindowSize.set ( horizontal, vertical ); }
  77. void setWindowSize( Point2I size ) { mWindowSize = size; }
  78. Point2I& getWindowSize() { return ( mWindowSize ); }
  79. void setWindowName (const char * windowName)
  80. {
  81. if (windowName == NULL)
  82. dStrncpy( mWindowName, "", sizeof( mWindowName ));
  83. else
  84. dStrncpy( mWindowName, windowName, sizeof( mWindowName ) );
  85. }
  86. const char * getWindowName() { return mWindowName; }
  87. void setExePathName(const char* exePathName)
  88. {
  89. if (exePathName == NULL)
  90. dStrncpy(mExePathName, "", sizeof(mExePathName));
  91. else
  92. dStrncpy(mExePathName, exePathName, sizeof(mExePathName));
  93. // set the base exe name field
  94. char tempBuf[2048];
  95. dStrncpy(tempBuf, mExePathName, 2048);
  96. dStrncpy(mExeName, basename(tempBuf), sizeof(mExeName));
  97. }
  98. const char * getExePathName() { return mExePathName; }
  99. const char * getExeName() { return mExeName; }
  100. bool windowCreated() { return mWindowCreated; }
  101. bool windowActive() { return mWindowActive; }
  102. bool windowLocked() { return mWindowLocked; }
  103. void setWindowCreated(bool windowCreated)
  104. { mWindowCreated = windowCreated; }
  105. void setWindowActive(bool windowActive)
  106. { mWindowActive = windowActive; }
  107. void setWindowLocked(bool windowLocked)
  108. { mWindowLocked = windowLocked; }
  109. bool isXWindowsRunning() { return mXWindowsRunning; }
  110. void setXWindowsRunning(bool running) { mXWindowsRunning = running; }
  111. bool isDedicated() { return mDedicated; }
  112. void setDedicated(bool dedicated) { mDedicated = dedicated; }
  113. bool getCDAudioEnabled() { return mCDAudioEnabled; }
  114. void setCDAudioEnabled(bool enabled) { mCDAudioEnabled = enabled; }
  115. bool getDSleep() { return mDSleep; }
  116. void setDSleep(bool enabled) { mDSleep = enabled; }
  117. bool getUseRedirect() { return mUseRedirect; }
  118. void setUseRedirect(bool enabled) { mUseRedirect = enabled; }
  119. x86UNIXPlatformState()
  120. {
  121. currentTime = 0;
  122. mDesktopBpp = 16;
  123. mDesktopSize.set( 0, 0 );
  124. mWindowSize.set( 800, 600 );
  125. setWindowName("Torque");
  126. setExePathName(NULL);
  127. mWindowCreated = mWindowActive = mWindowLocked = false;
  128. mXWindowsRunning = false;
  129. mDedicated = false;
  130. mCDAudioEnabled = false;
  131. mDSleep = false;
  132. #ifdef USE_FILE_REDIRECT
  133. mUseRedirect = true;
  134. #else
  135. mUseRedirect = false;
  136. #endif
  137. }
  138. };
  139. extern x86UNIXPlatformState * x86UNIXState;