platform.h

Engine/source/platform/platform.h

More...

Classes:

Namespaces:

namespace

Public Defines

define
_new() (__FILE__, __LINE__)
define
dALIGN(decl) decl

The dALIGN macro ensures the passed declaration is data aligned at 16 byte boundaries.

define
define
define
dMalloc(x) (x, __FILE__, __LINE__)
define
dRealloc(x, y) (x, y, __FILE__, __LINE__)
define
dT(s) s
define
new() 
define

Macro to do in-line debug breaks, used for asserts. Does inline assembly when possible.

define
TORQUE_TMM_ARGS() , fileName, lineNum
define
TORQUE_TMM_ARGS_DECL() ,  char* fileName,   lineNum

Memory functions.

define
TORQUE_TMM_LOC() , __FILE__, __LINE__

Public Enumerations

enum
DFILE_STATUS {  DFILE_OK = 1
}
enum
DriveType {
  DRIVETYPE_FIXED = 0
  DRIVETYPE_REMOVABLE = 1
  DRIVETYPE_REMOTE = 2
  DRIVETYPE_CDROM = 3
  DRIVETYPE_RAMDISK = 4
  DRIVETYPE_UNKNOWN = 5
}

Physical type of a drive.

enum
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)
  CPU_PROP_ALTIVEC = (1<<14)
}

Properties for CPU.

enum
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 
  CPU_Xenon 
}

Global processor identifiers.

Public Typedefs

void *
FILE_HANDLE 

Public Functions

T *

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)
dCopyArray(T * dst, const T * src, dsize_t size)

Destructs an object without freeing the memory associated with it.

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(void * in_pFree)
void *
dMalloc_aligned(dsize_t in_size, S32 alignment)
void *
dMalloc_r(dsize_t in_size, const char * fileName, const dsize_t)
dMemcmp(const void * ptr1, const void * ptr2, dsize_t size)
void *
dMemcpy(void * dst, const void * src, dsize_t size)
void *
dMemmove(void * dst, const void * src, dsize_t size)
void *
dMemset(void * dst, S32 c, dsize_t size)
dOpenFileReadWrite(const char * name, bool append, DFILE_STATUS & error)
bool
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)
void *
dRealloc_r(void * in_pResize, dsize_t in_size, const char * fileName, const dsize_t)
operator new(dsize_t size, const char * fileName, const U32)
operator new[](dsize_t size, const char * fileName, const U32)

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.

CPU_PROP_ALTIVEC = (1<<14)

Supports AltiVec instruction set extension (PPC only).

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
CPU_Xenon

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