platform.h
Engine/source/platform/platform.h
Classes:
Description of a keyboard input we want to ignore.
Namespaces:
Public Defines
_new() (__FILE__, __LINE__)
dALIGN(decl) decl
The dALIGN macro ensures the passed declaration is data aligned at 16 byte boundaries.
dMalloc(x) (x, __FILE__, __LINE__)
dRealloc(x, y) (x, y, __FILE__, __LINE__)
dT(s) s
new()
TORQUE_DEBUGBREAK() ();
Macro to do in-line debug breaks, used for asserts. Does inline assembly when possible.
TORQUE_TMM_ARGS() , fileName, lineNum
TORQUE_TMM_ARGS_DECL() , char* fileName, lineNum
Memory functions.
TORQUE_TMM_LOC() , __FILE__, __LINE__
Public Enumerations
DFILE_STATUS { DFILE_OK = 1 }
DriveType { DRIVETYPE_FIXED = 0 DRIVETYPE_REMOVABLE = 1 DRIVETYPE_REMOTE = 2 DRIVETYPE_CDROM = 3 DRIVETYPE_RAMDISK = 4 DRIVETYPE_UNKNOWN = 5 }
Physical type of a drive.
ProcessorProperties { CPU_PROP_C = (1<<0) CPU_PROP_FPU = (1<<1) CPU_PROP_MMX = (1<<2) CPU_PROP_3DNOW = (1<<3) CPU_PROP_SSE = (1<<4) CPU_PROP_RDTSC = (1<<5) CPU_PROP_SSE2 = (1<<6) CPU_PROP_SSE3 = (1<<7) CPU_PROP_SSE3xt = (1<<8) CPU_PROP_SSE4_1 = (1<<9) CPU_PROP_SSE4_2 = (1<<10) CPU_PROP_MP = (1<<11) CPU_PROP_LE = (1<<12) CPU_PROP_64bit = (1<<13) }
Properties for CPU.
ProcessorType { CPU_X86Compatible CPU_Intel_Unknown CPU_Intel_486 CPU_Intel_Pentium CPU_Intel_PentiumMMX CPU_Intel_PentiumPro CPU_Intel_PentiumII CPU_Intel_PentiumCeleron CPU_Intel_PentiumIII CPU_Intel_Pentium4 CPU_Intel_PentiumM CPU_Intel_Core CPU_Intel_Core2 CPU_Intel_Corei7Xeon CPU_AMD_K6 CPU_AMD_K6_2 CPU_AMD_K6_3 CPU_AMD_Athlon CPU_AMD_Phenom CPU_AMD_PhenomII CPU_AMD_Bulldozer CPU_AMD_Unknown CPU_Cyrix_6x86 CPU_Cyrix_MediaGX CPU_Cyrix_6x86MX CPU_Cyrix_GXm CPU_Cyrix_Unknown CPU_PowerPC_Unknown CPU_PowerPC_601 CPU_PowerPC_603 CPU_PowerPC_603e CPU_PowerPC_603ev CPU_PowerPC_604 CPU_PowerPC_604e CPU_PowerPC_604ev CPU_PowerPC_G3 CPU_PowerPC_G4 CPU_PowerPC_G4_7450 CPU_PowerPC_G4_7455 CPU_PowerPC_G4_7447 CPU_PowerPC_G5 }
Global processor identifiers.
Public Typedefs
void *
FILE_HANDLE
Public Functions
T *
constructArrayInPlace(T * p, U32 num)
T *
constructInPlace(T * p)
Constructs an object that already has memory allocated for it.
T *
constructInPlace(T * p, const T * copy)
Copy constructs an object that already has memory allocated for it.
T *
constructInPlace(T * ptr, T2 t2)
T *
constructInPlace(T * ptr, T2 t2, T3 t3)
T *
constructInPlace(T * ptr, T2 t2, T3 t3, T4 t4)
T *
constructInPlace(T * ptr, T2 t2, T3 t3, T4 t4, T5 t5)
dCopyArray(T * dst, const S * src, dsize_t size)
destructInPlace(T * p)
Destructs an object without freeing the memory associated with it.
dFileClose(FILE_HANDLE handle)
bool
dFileDelete(const char * name)
dFileRead(FILE_HANDLE handle, U32 bytes, char * dst, DFILE_STATUS & error)
bool
dFileRename(const char * oldName, const char * newName)
bool
dFileTouch(const char * name)
dFileWrite(FILE_HANDLE handle, U32 bytes, const char * dst, DFILE_STATUS & error)
dFree_aligned(void * p)
void *
dMalloc_aligned(dsize_t in_size, S32 alignment)
dOpenFileRead(const char * name, DFILE_STATUS & error)
dOpenFileReadWrite(const char * name, bool append, DFILE_STATUS & error)
void *
dRealMalloc(dsize_t in_size)
operator delete(void * ptr)
operator delete[](void * ptr)
setMinimumAllocUnit(U32 allocUnit)
Detailed Description
Public Defines
_new() (__FILE__, __LINE__)
dALIGN(decl) decl
The dALIGN macro ensures the passed declaration is data aligned at 16 byte boundaries.
dALIGN_BEGIN()
dALIGN_END()
dMalloc(x) (x, __FILE__, __LINE__)
dRealloc(x, y) (x, y, __FILE__, __LINE__)
dT(s) s
new()
QSORT_CALLBACK()
TORQUE_DEBUGBREAK() ();
Macro to do in-line debug breaks, used for asserts. Does inline assembly when possible.
TORQUE_TMM_ARGS() , fileName, lineNum
TORQUE_TMM_ARGS_DECL() , char* fileName, lineNum
Memory functions.
TORQUE_TMM_LOC() , __FILE__, __LINE__
Public Enumerations
DFILE_STATUS
Enumerator
- DFILE_OK = 1
DriveType
Enumerator
- DRIVETYPE_FIXED = 0
Non-removable fixed drive.
- DRIVETYPE_REMOVABLE = 1
Removable drive.
- DRIVETYPE_REMOTE = 2
Networked/remote drive.
- DRIVETYPE_CDROM = 3
CD-Rom.
- DRIVETYPE_RAMDISK = 4
A ramdisk!
- DRIVETYPE_UNKNOWN = 5
Don't know.
Physical type of a drive.
ProcessorProperties
Enumerator
- CPU_PROP_C = (1<<0)
We should use C fallback math functions.
- CPU_PROP_FPU = (1<<1)
Has an FPU. (It better!)
- CPU_PROP_MMX = (1<<2)
Supports MMX instruction set extension.
- CPU_PROP_3DNOW = (1<<3)
Supports AMD 3dNow! instruction set extension.
- CPU_PROP_SSE = (1<<4)
Supports SSE instruction set extension.
- CPU_PROP_RDTSC = (1<<5)
Supports Read Time Stamp Counter op.
- CPU_PROP_SSE2 = (1<<6)
Supports SSE2 instruction set extension.
- CPU_PROP_SSE3 = (1<<7)
Supports SSE3 instruction set extension.
- CPU_PROP_SSE3xt = (1<<8)
Supports extended SSE3 instruction set
- CPU_PROP_SSE4_1 = (1<<9)
Supports SSE4_1 instruction set extension.
- CPU_PROP_SSE4_2 = (1<<10)
Supports SSE4_2 instruction set extension.
- CPU_PROP_MP = (1<<11)
This is a multi-processor system.
- CPU_PROP_LE = (1<<12)
This processor is LITTLE ENDIAN.
- CPU_PROP_64bit = (1<<13)
This processor is 64-bit capable.
Properties for CPU.
ProcessorType
Enumerator
- CPU_X86Compatible
- CPU_Intel_Unknown
- CPU_Intel_486
- CPU_Intel_Pentium
- CPU_Intel_PentiumMMX
- CPU_Intel_PentiumPro
- CPU_Intel_PentiumII
- CPU_Intel_PentiumCeleron
- CPU_Intel_PentiumIII
- CPU_Intel_Pentium4
- CPU_Intel_PentiumM
- CPU_Intel_Core
- CPU_Intel_Core2
- CPU_Intel_Corei7Xeon
- CPU_AMD_K6
- CPU_AMD_K6_2
- CPU_AMD_K6_3
- CPU_AMD_Athlon
- CPU_AMD_Phenom
- CPU_AMD_PhenomII
- CPU_AMD_Bulldozer
- CPU_AMD_Unknown
- CPU_Cyrix_6x86
- CPU_Cyrix_MediaGX
- CPU_Cyrix_6x86MX
- CPU_Cyrix_GXm
Media GX w/ MMX.
- CPU_Cyrix_Unknown
- CPU_PowerPC_Unknown
- CPU_PowerPC_601
- CPU_PowerPC_603
- CPU_PowerPC_603e
- CPU_PowerPC_603ev
- CPU_PowerPC_604
- CPU_PowerPC_604e
- CPU_PowerPC_604ev
- CPU_PowerPC_G3
- CPU_PowerPC_G4
- CPU_PowerPC_G4_7450
- CPU_PowerPC_G4_7455
- CPU_PowerPC_G4_7447
- CPU_PowerPC_G5
Global processor identifiers.
note:These enums must be globally scoped so that they work with the inline assembly
Public Typedefs
typedef void * FILE_HANDLE
Public Functions
constructArrayInPlace(T * p, U32 num)
constructInPlace(T * p)
Constructs an object that already has memory allocated for it.
constructInPlace(T * p, const T * copy)
Copy constructs an object that already has memory allocated for it.
constructInPlace(T * ptr, T2 t2)
constructInPlace(T * ptr, T2 t2, T3 t3)
constructInPlace(T * ptr, T2 t2, T3 t3, T4 t4)
constructInPlace(T * ptr, T2 t2, T3 t3, T4 t4, T5 t5)
dCopyArray(T * dst, const S * src, dsize_t size)
dCopyArray(T * dst, const T * src, dsize_t size)
destructInPlace(T * p)
Destructs an object without freeing the memory associated with it.
dFileClose(FILE_HANDLE handle)
dFileDelete(const char * name)
dFileRead(FILE_HANDLE handle, U32 bytes, char * dst, DFILE_STATUS & error)
dFileRename(const char * oldName, const char * newName)
dFileTouch(const char * name)
dFileWrite(FILE_HANDLE handle, U32 bytes, const char * dst, DFILE_STATUS & error)
dFree(const void * p)
dFree(void * in_pFree)
dFree_aligned(void * p)
dMalloc_aligned(dsize_t in_size, S32 alignment)
dMalloc_r(dsize_t in_size, const char * fileName, const dsize_t)
dMemcmp(const void * ptr1, const void * ptr2, dsize_t size)
dMemcpy(void * dst, const void * src, dsize_t size)
dMemmove(void * dst, const void * src, dsize_t size)
dMemset(void * dst, S32 c, dsize_t size)
dOpenFileRead(const char * name, DFILE_STATUS & error)
dOpenFileReadWrite(const char * name, bool append, DFILE_STATUS & error)
dPathCopy(const char * fromName, const char * toName, bool nooverwrite)
dQsort(void * base, U32 nelem, U32 width, S32(QSORT_CALLBACK *fcmp)(const void *, const void *) )
dRealFree(void * in_pFree)
dRealloc_r(void * in_pResize, dsize_t in_size, const char * fileName, const dsize_t)
dRealMalloc(dsize_t in_size)
operator delete(void * ptr)
operator delete[](void * ptr)
operator new(dsize_t size, const char * fileName, const U32)
operator new[](dsize_t size, const char * fileName, const U32)
osGetTemporaryDirectory()
setBreakAlloc(dsize_t )
setMinimumAllocUnit(U32 allocUnit)
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#ifndef _PLATFORM_H_ 25#define _PLATFORM_H_ 26 27#include <stdlib.h> 28 29#ifndef _TORQUECONFIG_H_ 30#include "torqueConfig.h" 31#endif 32#ifndef _TORQUE_TYPES_H_ 33#include "platform/types.h" 34#endif 35#ifndef _PLATFORMASSERT_H_ 36#include "platform/platformAssert.h" 37#endif 38#ifndef _MSGBOX_H_ 39#include "platform/nativeDialogs/msgBox.h" 40#endif 41#ifndef _VERSION_H_ 42#include "app/version.h" 43#endif 44#ifndef _TORQUE_STRING_H_ 45#include "core/util/str.h" 46#endif 47#ifndef _TORQUE_SAFEDELETE_H_ 48#include "core/util/safeDelete.h" 49#endif 50 51#include <new> 52#include <typeinfo> 53 54/// Global processor identifiers. 55/// 56/// @note These enums must be globally scoped so that they work with the inline assembly 57enum ProcessorType 58{ 59 // x86 60 CPU_X86Compatible, 61 CPU_Intel_Unknown, 62 CPU_Intel_486, 63 CPU_Intel_Pentium, 64 CPU_Intel_PentiumMMX, 65 CPU_Intel_PentiumPro, 66 CPU_Intel_PentiumII, 67 CPU_Intel_PentiumCeleron, 68 CPU_Intel_PentiumIII, 69 CPU_Intel_Pentium4, 70 CPU_Intel_PentiumM, 71 CPU_Intel_Core, 72 CPU_Intel_Core2, 73 CPU_Intel_Corei7Xeon, // Core i7 or Xeon 74 CPU_AMD_K6, 75 CPU_AMD_K6_2, 76 CPU_AMD_K6_3, 77 CPU_AMD_Athlon, 78 CPU_AMD_Phenom, 79 CPU_AMD_PhenomII, 80 CPU_AMD_Bulldozer, 81 CPU_AMD_Unknown, 82 CPU_Cyrix_6x86, 83 CPU_Cyrix_MediaGX, 84 CPU_Cyrix_6x86MX, 85 CPU_Cyrix_GXm, ///< Media GX w/ MMX 86 CPU_Cyrix_Unknown, 87 88 // PowerPC 89 CPU_PowerPC_Unknown, 90 CPU_PowerPC_601, 91 CPU_PowerPC_603, 92 CPU_PowerPC_603e, 93 CPU_PowerPC_603ev, 94 CPU_PowerPC_604, 95 CPU_PowerPC_604e, 96 CPU_PowerPC_604ev, 97 CPU_PowerPC_G3, 98 CPU_PowerPC_G4, 99 CPU_PowerPC_G4_7450, 100 CPU_PowerPC_G4_7455, 101 CPU_PowerPC_G4_7447, 102 CPU_PowerPC_G5, 103}; 104 105/// Properties for CPU. 106enum ProcessorProperties 107{ 108 CPU_PROP_C = (1<<0), ///< We should use C fallback math functions. 109 CPU_PROP_FPU = (1<<1), ///< Has an FPU. (It better!) 110 CPU_PROP_MMX = (1<<2), ///< Supports MMX instruction set extension. 111 CPU_PROP_3DNOW = (1<<3), ///< Supports AMD 3dNow! instruction set extension. 112 CPU_PROP_SSE = (1<<4), ///< Supports SSE instruction set extension. 113 CPU_PROP_RDTSC = (1<<5), ///< Supports Read Time Stamp Counter op. 114 CPU_PROP_SSE2 = (1<<6), ///< Supports SSE2 instruction set extension. 115 CPU_PROP_SSE3 = (1<<7), ///< Supports SSE3 instruction set extension. 116 CPU_PROP_SSE3xt = (1<<8), ///< Supports extended SSE3 instruction set 117 CPU_PROP_SSE4_1 = (1<<9), ///< Supports SSE4_1 instruction set extension. 118 CPU_PROP_SSE4_2 = (1<<10), ///< Supports SSE4_2 instruction set extension. 119 CPU_PROP_MP = (1<<11), ///< This is a multi-processor system. 120 CPU_PROP_LE = (1<<12), ///< This processor is LITTLE ENDIAN. 121 CPU_PROP_64bit = (1<<13), ///< This processor is 64-bit capable 122}; 123 124/// Processor info manager. 125struct Processor 126{ 127 /// Gather processor state information. 128 static void init(); 129}; 130 131#if defined(TORQUE_SUPPORTS_GCC_INLINE_X86_ASM) 132#define TORQUE_DEBUGBREAK() { asm ( "int 3"); } 133#elif defined (TORQUE_SUPPORTS_VC_INLINE_X86_ASM) // put this test second so that the __asm syntax doesn't break the Visual Studio Intellisense parser 134#define TORQUE_DEBUGBREAK() { __asm { int 3 }; } 135#else 136/// Macro to do in-line debug breaks, used for asserts. Does inline assembly when possible. 137#define TORQUE_DEBUGBREAK() Platform::debugBreak(); 138#endif 139 140/// Physical type of a drive. 141enum DriveType 142{ 143 DRIVETYPE_FIXED = 0, ///< Non-removable fixed drive. 144 DRIVETYPE_REMOVABLE = 1, ///< Removable drive. 145 DRIVETYPE_REMOTE = 2, ///< Networked/remote drive. 146 DRIVETYPE_CDROM = 3, ///< CD-Rom. 147 DRIVETYPE_RAMDISK = 4, ///< A ramdisk! 148 DRIVETYPE_UNKNOWN = 5 ///< Don't know. 149}; 150 151// Some forward declares for later. 152class Point2I; 153template<class T> class Vector; 154template<typename Signature> class Signal; 155struct InputEventInfo; 156 157namespace Platform 158{ 159 // Time 160 struct LocalTime 161 { 162 U8 sec; ///< Seconds after minute (0-59) 163 U8 min; ///< Minutes after hour (0-59) 164 U8 hour; ///< Hours after midnight (0-23) 165 U8 month; ///< Month (0-11; 0=january) 166 U8 monthday; ///< Day of the month (1-31) 167 U8 weekday; ///< Day of the week (0-6, 6=sunday) 168 U16 year; ///< Current year minus 1900 169 U16 yearday; ///< Day of year (0-365) 170 bool isdst; ///< True if daylight savings time is active 171 }; 172 173 enum ALERT_ASSERT_RESULT 174 { 175 ALERT_ASSERT_DEBUG, 176 ALERT_ASSERT_IGNORE, 177 ALERT_ASSERT_IGNORE_ALL, 178 ALERT_ASSERT_EXIT 179 }; 180 181 182 void getLocalTime(LocalTime &); 183 184 /// Converts the local time to a formatted string appropriate 185 /// for the current platform. 186 String localTimeToString( const LocalTime < ); 187 188 U32 getTime(); 189 U32 getVirtualMilliseconds(); 190 191 /// Returns the milliseconds since the system was started. You should 192 /// not depend on this for high precision timing. 193 /// @see PlatformTimer 194 U32 getRealMilliseconds(); 195 196 void advanceTime(U32 delta); 197 S32 getBackgroundSleepTime(); 198 199 // Platform control 200 void init(); 201 void initConsole(); 202 void shutdown(); 203 void process(); 204 205 // Math control state 206 U32 getMathControlState(); 207 void setMathControlState(U32 state); 208 void setMathControlStateKnown(); 209 210 // Process control 211 void sleep(U32 ms); 212 bool excludeOtherInstances(const char *string); 213 bool checkOtherInstances(const char *string); 214 void restartInstance(); 215 void postQuitMessage(const S32 in_quitVal); 216 void forceShutdown(S32 returnValue); 217 218 // Debug 219 void outputDebugString(const char *string, ...); 220 void debugBreak(); 221 222 // Random 223 F32 getRandom(); 224 225 // Window state 226 void setWindowLocked(bool locked); 227 void minimizeWindow(); 228 //const Point2I &getWindowSize(); 229 void setWindowSize( U32 newWidth, U32 newHeight, bool fullScreen ); 230 void closeWindow(); 231 232 // File stuff 233 bool doCDCheck(); 234 StringTableEntry createPlatformFriendlyFilename(const char *filename); 235 struct FileInfo 236 { 237 const char* pFullPath; 238 const char* pFileName; 239 U32 fileSize; 240 }; 241 bool cdFileExists(const char *filePath, const char *volumeName, S32 serialNum); 242 void fileToLocalTime(const FileTime &ft, LocalTime *lt); 243 /// compare file times returns < 0 if a is earlier than b, >0 if b is earlier than a 244 S32 compareFileTimes(const FileTime &a, const FileTime &b); 245 bool stringToFileTime(const char * string, FileTime * time); 246 bool fileTimeToString(FileTime * time, char * string, U32 strLen); 247 248 /// Compares the last modified time between two file paths. Returns < 0 if 249 /// the first file is earlier than the second, > 0 if the second file is earlier 250 /// than the first, and 0 if the files are equal. 251 /// 252 /// If either of the files doesn't exist it returns -1. 253 S32 compareModifiedTimes( const char *firstPath, const char *secondPath ); 254 255 // Directory functions. Dump path returns false iff the directory cannot be 256 // opened. 257 258 StringTableEntry getCurrentDirectory(); 259 bool setCurrentDirectory(StringTableEntry newDir); 260 261 StringTableEntry getTemporaryDirectory(); 262 StringTableEntry getTemporaryFileName(); 263 264 /// Returns the filename of the torque executable. 265 /// On Win32, this is the .exe file. 266 /// On Mac, this is the .app/ directory bundle. 267 StringTableEntry getExecutableName(); 268 /// Returns full pathname of the torque executable without filename 269 StringTableEntry getExecutablePath(); 270 271 /// Returns the full path to the directory that contains main.tscript. 272 /// Tools scripts are validated as such if they are in this directory or a 273 /// subdirectory of this directory. 274 StringTableEntry getMainDotCsDir(); 275 276 /// Set main.tscript directory. Used in runEntryScript() 277 void setMainDotCsDir(const char *dir); 278 279 StringTableEntry getPrefsPath(const char *file = NULL); 280 281 char *makeFullPathName(const char *path, char *buffer, U32 size, const char *cwd = NULL); 282 StringTableEntry stripBasePath(const char *path); 283 bool isFullPath(const char *path); 284 StringTableEntry makeRelativePathName(const char *path, const char *to); 285 286 String stripExtension( String fileName, Vector< String>& validExtensions ); 287 288 bool dumpPath(const char *in_pBasePath, Vector<FileInfo>& out_rFileVector, S32 recurseDepth = -1); 289 bool dumpDirectories( const char *path, Vector<StringTableEntry> &directoryVector, S32 depth = 0, bool noBasePath = false ); 290 bool hasSubDirectory( const char *pPath ); 291 bool getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime); 292 bool isFile(const char *pFilePath); 293 S32 getFileSize(const char *pFilePath); 294 bool isDirectory(const char *pDirPath); 295 bool isSubDirectory(const char *pParent, const char *pDir); 296 297 void addExcludedDirectory(const char *pDir); 298 void clearExcludedDirectories(); 299 bool isExcludedDirectory(const char *pDir); 300 301 bool deleteDirectory(const char* pPath); 302 bool fileDelete(const char *name); 303 304 /// Given a directory path, create all necessary directories for that path to exist. 305 bool createPath(const char *path); // create a directory path 306 307 // Alerts 308 void AlertOK(const char *windowTitle, const char *message); 309 bool AlertOKCancel(const char *windowTitle, const char *message); 310 bool AlertRetry(const char *windowTitle, const char *message); 311 ALERT_ASSERT_RESULT AlertAssert(const char *windowTitle, const char *message); 312 313 // Volumes 314 struct VolumeInformation 315 { 316 StringTableEntry RootPath; 317 StringTableEntry Name; 318 StringTableEntry FileSystem; 319 U32 SerialNumber; 320 U32 Type; 321 bool ReadOnly; 322 }; 323 extern struct VolumeInformation *PVolumeInformation; 324 325 // Volume functions. 326 void getVolumeNamesList( Vector<const char*>& out_rNameVector, bool bOnlyFixedDrives = false ); 327 void getVolumeInformationList( Vector<VolumeInformation>& out_rVolumeInfoVector, bool bOnlyFixedDrives = false ); 328 329 struct SystemInfo_struct 330 { 331 struct Processor 332 { 333 ProcessorType type; 334 const char* name; 335 U32 mhz; 336 bool isMultiCore; 337 bool isHyperThreaded; 338 U32 numLogicalProcessors; 339 U32 numPhysicalProcessors; 340 U32 numAvailableCores; 341 U32 properties; // CPU type specific enum 342 } processor; 343 }; 344 extern Signal<void(void)> SystemInfoReady; 345 extern SystemInfo_struct SystemInfo; 346 347 // Web page launch function: 348 bool openWebBrowser( const char* webAddress ); 349 350 // display Splash Window 351 bool displaySplashWindow( String path ); 352 353 // close Splash Window 354 bool closeSplashWindow(); 355 356 void openFolder( const char* path ); 357 358 // Open file at the OS level, according to registered file-types. 359 void openFile( const char* path ); 360 361 const char* getLoginPassword(); 362 bool setLoginPassword( const char* password ); 363 364 const char* getClipboard(); 365 bool setClipboard(const char *text); 366 367 // User Specific Functions 368 StringTableEntry getUserHomeDirectory(); 369 StringTableEntry getUserDataDirectory(); 370 bool getUserIsAdministrator(); 371 372 // Displays a fancy platform specific message box 373 S32 messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons = MBOkCancel, MBIcons icon = MIInformation); 374 375 /// Description of a keyboard input we want to ignore. 376 struct KeyboardInputExclusion 377 { 378 KeyboardInputExclusion() 379 { 380 key = 0; 381 orModifierMask = 0; 382 andModifierMask = 0; 383 } 384 385 /// The key code to ignore, e.g. KEY_TAB. If this and the other 386 /// conditions match, ignore the key. 387 S32 key; 388 389 /// if(modifiers | orModifierMask) and the other conditions match, 390 /// ignore the key. 391 U32 orModifierMask; 392 393 /// if((modifiers & andModifierMask) == andModifierMask) and the 394 /// other conditions match, ignore the key stroke. 395 U32 andModifierMask; 396 397 /// Based on the values above, determine if a given input event 398 /// matchs this exclusion rule. 399 const bool checkAgainstInput(const InputEventInfo *info) const; 400 }; 401 402 /// Reset the keyboard input exclusion list. 403 void clearKeyboardInputExclusion(); 404 405 /// Add a new keyboard exclusion. 406 void addKeyboardInputExclusion(const KeyboardInputExclusion &kie); 407 408 /// Check if a given input event should be excluded. 409 const bool checkKeyboardInputExclusion(const InputEventInfo *info); 410 411 412 /// Set/Get whether this is a web deployment 413 bool getWebDeployment(); 414 void setWebDeployment(bool v); 415 416}; 417 418//------------------------------------------------------------------------------ 419// Unicode string conversions 420// UNICODE is a windows platform API switching flag. Don't define it on other platforms. 421#ifdef UNICODE 422#define dT(s) L##s 423#else 424#define dT(s) s 425#endif 426 427//------------------------------------------------------------------------------ 428// Misc StdLib functions 429#define QSORT_CALLBACK FN_CDECL 430inline void dQsort(void *base, U32 nelem, U32 width, S32 (QSORT_CALLBACK *fcmp)(const void *, const void *)) 431{ 432 qsort(base, nelem, width, fcmp); 433} 434 435//-------------------------------------- Some all-around useful inlines and globals 436// 437 438///@defgroup ObjTrickery Object Management Trickery 439/// 440/// These functions are to construct and destruct objects in memory 441/// without causing a free or malloc call to occur. This is so that 442/// we don't have to worry about allocating, say, space for a hundred 443/// NetAddresses with a single malloc call, calling delete on a single 444/// NetAdress, and having it try to free memory out from under us. 445/// 446/// @{ 447 448/// Constructs an object that already has memory allocated for it. 449template <class T> 450inline T* constructInPlace(T* p) 451{ 452 return new ( p ) T; 453} 454template< class T > 455inline T* constructArrayInPlace( T* p, U32 num ) 456{ 457 return new ( p ) T[ num ]; 458} 459 460/// Copy constructs an object that already has memory allocated for it. 461template <class T> 462inline T* constructInPlace(T* p, const T* copy) 463{ 464 return new ( p ) T( *copy ); 465} 466 467template <class T, class T2> inline T* constructInPlace(T* ptr, T2 t2) 468{ 469 return new ( ptr ) T( t2 ); 470} 471 472template <class T, class T2, class T3> inline T* constructInPlace(T* ptr, T2 t2, T3 t3) 473{ 474 return new ( ptr ) T( t2, t3 ); 475} 476 477template <class T, class T2, class T3, class T4> inline T* constructInPlace(T* ptr, T2 t2, T3 t3, T4 t4) 478{ 479 return new ( ptr ) T( t2, t3, t4 ); 480} 481 482template <class T, class T2, class T3, class T4, class T5> inline T* constructInPlace(T* ptr, T2 t2, T3 t3, T4 t4, T5 t5) 483{ 484 return new ( ptr ) T( t2, t3, t4, t5 ); 485} 486 487/// Destructs an object without freeing the memory associated with it. 488template <class T> 489inline void destructInPlace(T* p) 490{ 491 p->~T(); 492} 493 494 495//------------------------------------------------------------------------------ 496/// Memory functions 497 498#if !defined(TORQUE_DISABLE_MEMORY_MANAGER) 499# define TORQUE_TMM_ARGS_DECL , const char* fileName, const U32 lineNum 500# define TORQUE_TMM_ARGS , fileName, lineNum 501# define TORQUE_TMM_LOC , __FILE__, __LINE__ 502 extern void* FN_CDECL operator new(dsize_t size, const char*, const U32); 503 extern void* FN_CDECL operator new[](dsize_t size, const char*, const U32); 504 extern void FN_CDECL operator delete(void* ptr); 505 extern void FN_CDECL operator delete[](void* ptr); 506# define _new new(__FILE__, __LINE__) 507# define new _new 508#else 509# define TORQUE_TMM_ARGS_DECL 510# define TORQUE_TMM_ARGS 511# define TORQUE_TMM_LOC 512#endif 513 514#define dMalloc(x) dMalloc_r(x, __FILE__, __LINE__) 515#define dRealloc(x, y) dRealloc_r(x, y, __FILE__, __LINE__) 516 517extern void setBreakAlloc(dsize_t); 518extern void setMinimumAllocUnit(U32); 519extern void* dMalloc_r(dsize_t in_size, const char*, const dsize_t); 520extern void dFree(void* in_pFree); 521extern void* dRealloc_r(void* in_pResize, dsize_t in_size, const char*, const dsize_t); 522extern void* dRealMalloc(dsize_t); 523extern void dRealFree(void*); 524 525extern void *dMalloc_aligned(dsize_t in_size, S32 alignment); 526extern void dFree_aligned(void *); 527 528 529inline void dFree( const void* p ) 530{ 531 dFree( ( void* ) p ); 532} 533 534// Helper function to copy one array into another of different type 535template<class T,class S> void dCopyArray(T *dst, const S *src, dsize_t size) 536{ 537 for (dsize_t i = 0; i < size; i++) 538 dst[i] = (T)src[i]; 539} 540 541extern void* dMemcpy(void *dst, const void *src, dsize_t size); 542extern void* dMemmove(void *dst, const void *src, dsize_t size); 543extern void* dMemset(void *dst, S32 c, dsize_t size); 544extern S32 dMemcmp(const void *ptr1, const void *ptr2, dsize_t size); 545 546// Special case of the above function when the arrays are the same type (use memcpy) 547template<class T> void dCopyArray(T *dst, const T *src, dsize_t size) 548{ 549 dMemcpy(dst, src, size * sizeof(T)); 550} 551 552/// The dALIGN macro ensures the passed declaration is 553/// data aligned at 16 byte boundaries. 554#if defined( TORQUE_COMPILER_VISUALC ) 555 #define dALIGN( decl ) __declspec( align( 16 ) ) decl 556 #define dALIGN_BEGIN __declspec( align( 16 ) ) 557 #define dALIGN_END 558#elif defined( TORQUE_COMPILER_GCC ) 559 #define dALIGN( decl ) decl __attribute__( ( aligned( 16 ) ) ) 560 #define dALIGN_BEGIN 561 #define dALIGN_END __attribute__( ( aligned( 16 ) ) ) 562#else 563 #define dALIGN( decl ) decl 564 #define dALIGN_BEGIN() 565 #define dALIGN_END() 566#endif 567 568//------------------------------------------------------------------------------ 569// FileIO functions 570extern bool dFileDelete(const char *name); 571extern bool dFileRename(const char *oldName, const char *newName); 572extern bool dFileTouch(const char *name); 573extern bool dPathCopy(const char *fromName, const char *toName, bool nooverwrite = true); 574 575typedef void* FILE_HANDLE; 576enum DFILE_STATUS 577{ 578 DFILE_OK = 1 579}; 580 581extern FILE_HANDLE dOpenFileRead(const char *name, DFILE_STATUS &error); 582extern FILE_HANDLE dOpenFileReadWrite(const char *name, bool append, DFILE_STATUS &error); 583extern S32 dFileRead(FILE_HANDLE handle, U32 bytes, char *dst, DFILE_STATUS &error); 584extern S32 dFileWrite(FILE_HANDLE handle, U32 bytes, const char *dst, DFILE_STATUS &error); 585extern void dFileClose(FILE_HANDLE handle); 586 587extern StringTableEntry osGetTemporaryDirectory(); 588 589//------------------------------------------------------------------------------ 590struct Math 591{ 592 /// Initialize the math library with the appropriate libraries 593 /// to support hardware acceleration features. 594 /// 595 /// @param properties Leave zero to detect available hardware. Otherwise, 596 /// pass CPU instruction set flags that you want to load 597 /// support for. 598 static void init(U32 properties = 0); 599}; 600 601/// @} 602 603#endif 604 605 606