platform.cpp 4.9 KB

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