platform.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <limits>
  23. #include "platform/platform.h"
  24. #include "console/console.h"
  25. #include "console/consoleTypes.h"
  26. #include "platform/threads/mutex.h"
  27. #include "app/mainLoop.h"
  28. #include "platform/input/event.h"
  29. #include "platform/typetraits.h"
  30. const F32 TypeTraits< F32 >::MIN = - F32_MAX;
  31. const F32 TypeTraits< F32 >::MAX = F32_MAX;
  32. const F32 TypeTraits< F32 >::ZERO = 0;
  33. const F32 Float_Inf = std::numeric_limits< F32 >::infinity();
  34. // The tools prefer to allow the CPU time to process
  35. #ifndef TORQUE_TOOLS
  36. S32 sgBackgroundProcessSleepTime = 25;
  37. #else
  38. S32 sgBackgroundProcessSleepTime = 200;
  39. #endif
  40. S32 sgTimeManagerProcessInterval = 1;
  41. Vector<Platform::KeyboardInputExclusion> gKeyboardExclusionList;
  42. bool gInitKeyboardExclusionList = false;
  43. static bool gWebDeployment = false;
  44. void Platform::initConsole()
  45. {
  46. Con::addVariable("$platform::backgroundSleepTime", TypeS32, &sgBackgroundProcessSleepTime, "Controls processor time usage when the game window is out of focus.\n"
  47. "@ingroup Platform\n");
  48. Con::addVariable("$platform::timeManagerProcessInterval", TypeS32, &sgTimeManagerProcessInterval, "Controls processor time usage when the game window is in focus.\n"
  49. "@ingroup Platform\n");
  50. }
  51. S32 Platform::getBackgroundSleepTime()
  52. {
  53. return sgBackgroundProcessSleepTime;
  54. }
  55. ConsoleToolFunction(restartInstance, void, 1, 1, "restartInstance()")
  56. {
  57. StandardMainLoop::setRestart(true);
  58. Platform::postQuitMessage( 0 );
  59. }
  60. void Platform::clearKeyboardInputExclusion()
  61. {
  62. gKeyboardExclusionList.clear();
  63. gInitKeyboardExclusionList = true;
  64. }
  65. void Platform::addKeyboardInputExclusion(const KeyboardInputExclusion &kie)
  66. {
  67. gKeyboardExclusionList.push_back(kie);
  68. }
  69. const bool Platform::checkKeyboardInputExclusion(const InputEventInfo *info)
  70. {
  71. // Do one-time initialization of platform defaults.
  72. if(!gInitKeyboardExclusionList)
  73. {
  74. gInitKeyboardExclusionList = true;
  75. // CodeReview Looks like we don't even need to do #ifdefs here since
  76. // things like cmd-tab don't appear on windows, and alt-tab is an unlikely
  77. // desired bind on other platforms - might be best to simply have a
  78. // global exclusion list and keep it standard on all platforms.
  79. // This might not be so, but it's the current assumption. [bjg 5/4/07]
  80. // Alt-tab
  81. {
  82. KeyboardInputExclusion kie;
  83. kie.key = KEY_TAB;
  84. kie.andModifierMask = SI_ALT;
  85. addKeyboardInputExclusion(kie);
  86. }
  87. // ... others go here...
  88. }
  89. // Walk the list and look for matches.
  90. for(S32 i=0; i<gKeyboardExclusionList.size(); i++)
  91. {
  92. if(gKeyboardExclusionList[i].checkAgainstInput(info))
  93. return true;
  94. }
  95. return false;
  96. }
  97. const bool Platform::KeyboardInputExclusion::checkAgainstInput( const InputEventInfo *info ) const
  98. {
  99. if(info->objType != SI_KEY)
  100. return false;
  101. if(info->objInst != key)
  102. return false;
  103. if((info->modifier & andModifierMask) != andModifierMask)
  104. return false;
  105. if(info->modifier & !(info->modifier & orModifierMask))
  106. return false;
  107. return true;
  108. }
  109. S32 Platform::compareModifiedTimes( const char *firstPath, const char *secondPath )
  110. {
  111. FileTime firstModTime;
  112. if ( !getFileTimes( firstPath, NULL, &firstModTime ) )
  113. return -1;
  114. FileTime secondModTime;
  115. if ( !getFileTimes( secondPath, NULL, &secondModTime ) )
  116. return -1;
  117. return compareFileTimes( firstModTime, secondModTime );
  118. }
  119. bool Platform::getWebDeployment()
  120. {
  121. return gWebDeployment;
  122. }
  123. void Platform::setWebDeployment(bool v)
  124. {
  125. gWebDeployment = v;
  126. }