platform.cpp
Engine/source/platform/platform.cpp
Public Variables
Public Functions
ConsoleToolFunction(restartInstance , void , 1 , 1 , "restartInstance()" )
Detailed Description
Public Variables
const F32 Float_Inf
bool gInitKeyboardExclusionList
Vector< Platform::KeyboardInputExclusion > gKeyboardExclusionList
bool gWebDeployment
S32 sgBackgroundProcessSleepTime
S32 sgTimeManagerProcessInterval
Public Functions
ConsoleToolFunction(restartInstance , void , 1 , 1 , "restartInstance()" )
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#include <limits> 25 26#include "platform/platform.h" 27#include "console/console.h" 28#include "console/consoleTypes.h" 29#include "platform/threads/mutex.h" 30#include "app/mainLoop.h" 31#include "platform/input/event.h" 32#include "platform/typetraits.h" 33#include "core/volume.h" 34 35 36const F32 TypeTraits< F32 >::MIN = - F32_MAX; 37const F32 TypeTraits< F32 >::MAX = F32_MAX; 38const F32 TypeTraits< F32 >::ZERO = 0; 39const F32 Float_Inf = std::numeric_limits< F32 >::infinity(); 40 41// The tools prefer to allow the CPU time to process 42#ifndef TORQUE_TOOLS 43S32 sgBackgroundProcessSleepTime = 25; 44#else 45S32 sgBackgroundProcessSleepTime = 200; 46#endif 47S32 sgTimeManagerProcessInterval = 1; 48 49Vector<Platform::KeyboardInputExclusion> gKeyboardExclusionList; 50bool gInitKeyboardExclusionList = false; 51static bool gWebDeployment = false; 52 53void Platform::initConsole() 54{ 55 Con::addVariable("$platform::backgroundSleepTime", TypeS32, &sgBackgroundProcessSleepTime, "Controls processor time usage when the game window is out of focus.\n" 56 "@ingroup Platform\n"); 57 Con::addVariable("$platform::timeManagerProcessInterval", TypeS32, &sgTimeManagerProcessInterval, "Controls processor time usage when the game window is in focus.\n" 58 "@ingroup Platform\n"); 59} 60 61S32 Platform::getBackgroundSleepTime() 62{ 63 return sgBackgroundProcessSleepTime; 64} 65 66ConsoleToolFunction(restartInstance, void, 1, 1, "restartInstance()") 67{ 68 StandardMainLoop::setRestart(true); 69 Platform::postQuitMessage( 0 ); 70} 71 72void Platform::clearKeyboardInputExclusion() 73{ 74 gKeyboardExclusionList.clear(); 75 gInitKeyboardExclusionList = true; 76} 77 78void Platform::addKeyboardInputExclusion(const KeyboardInputExclusion &kie) 79{ 80 gKeyboardExclusionList.push_back(kie); 81} 82 83const bool Platform::checkKeyboardInputExclusion(const InputEventInfo *info) 84{ 85 // Do one-time initialization of platform defaults. 86 if(!gInitKeyboardExclusionList) 87 { 88 gInitKeyboardExclusionList = true; 89 90 // CodeReview Looks like we don't even need to do #ifdefs here since 91 // things like cmd-tab don't appear on windows, and alt-tab is an unlikely 92 // desired bind on other platforms - might be best to simply have a 93 // global exclusion list and keep it standard on all platforms. 94 // This might not be so, but it's the current assumption. [bjg 5/4/07] 95 96 // Alt-tab 97 { 98 KeyboardInputExclusion kie; 99 kie.key = KEY_TAB; 100 kie.andModifierMask = SI_ALT; 101 addKeyboardInputExclusion(kie); 102 } 103 104 // ... others go here... 105 } 106 107 // Walk the list and look for matches. 108 for(S32 i=0; i<gKeyboardExclusionList.size(); i++) 109 { 110 if(gKeyboardExclusionList[i].checkAgainstInput(info)) 111 return true; 112 } 113 114 return false; 115} 116 117const bool Platform::KeyboardInputExclusion::checkAgainstInput( const InputEventInfo *info ) const 118{ 119 if(info->objType != SI_KEY) 120 return false; 121 122 if(info->objInst != key) 123 return false; 124 125 if((info->modifier & andModifierMask) != andModifierMask) 126 return false; 127 128 if(info->modifier & !(info->modifier & orModifierMask)) 129 return false; 130 131 return true; 132} 133 134S32 Platform::compareModifiedTimes( const char *firstPath, const char *secondPath ) 135{ 136 FileTime firstModTime; 137 if ( !getFileTimes( firstPath, NULL, &firstModTime ) ) { 138 //The reason we failed to get file times could be cause it is in a zip. Lets check. 139 return Torque::FS::CompareModifiedTimes(firstPath, secondPath); 140 } 141 142 FileTime secondModTime; 143 if ( !getFileTimes( secondPath, NULL, &secondModTime ) ) 144 return -1; 145 146 return compareFileTimes( firstModTime, secondModTime ); 147} 148 149bool Platform::getWebDeployment() 150{ 151 return gWebDeployment; 152} 153 154void Platform::setWebDeployment(bool v) 155{ 156 gWebDeployment = v; 157} 158 159 160