platform.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 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. #ifndef _PLATFORM_H_
  23. #define _PLATFORM_H_
  24. #ifndef _TORQUECONFIG_H_
  25. #include "torqueConfig.h"
  26. #endif
  27. #ifndef _TORQUE_TYPES_H_
  28. #include "platform/types.h"
  29. #endif
  30. #ifndef _PLATFORMASSERT_H_
  31. #include "platform/platformAssert.h"
  32. #endif
  33. #ifndef _MSGBOX_H_
  34. #include "platform/nativeDialogs/msgBox.h"
  35. #endif
  36. #ifndef TORQUE_OS_WIN
  37. #include <algorithm>
  38. #endif
  39. #ifndef _PLATFORM_ENDIAN_H_
  40. #include "platform/platformEndian.h"
  41. #endif
  42. #ifndef _PLATFORM_CPU_H_
  43. #include "platform/platformCPU.h"
  44. #endif
  45. #ifndef _PLATFORM_STRING_H_
  46. #include "platform/platformString.h"
  47. #endif
  48. #ifndef _PLATFORM_PLATFORMNET_H_
  49. #include "platform/platformNet.h"
  50. #endif
  51. #ifndef _PLATFORM_MEMORY_H_
  52. #include "platform/platformMemory.h"
  53. #endif
  54. #ifndef _PLATFORMFONT_H_
  55. #include "platform/platformFont.h"
  56. #endif
  57. #ifndef _PLATFORM_MATH_H_
  58. #include "platform/platformMath.h"
  59. #endif
  60. #ifndef _PLATFORM_TIME_MANAGER_H_
  61. #include "platform/platformTimeManager.h"
  62. #endif
  63. //------------------------------------------------------------------------------
  64. template <class T> class Vector;
  65. class Point2I;
  66. //------------------------------------------------------------------------------
  67. /// Memory functions
  68. #if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
  69. # define TORQUE_TMM_ARGS_DECL , const char* fileName, const U32 lineNum
  70. # define TORQUE_TMM_ARGS , fileName, lineNum
  71. # define TORQUE_TMM_LOC , __FILE__, __LINE__
  72. #else
  73. # define TORQUE_TMM_ARGS_DECL
  74. # define TORQUE_TMM_ARGS
  75. # define TORQUE_TMM_LOC
  76. #endif
  77. //------------------------------------------------------------------------------
  78. struct Platform
  79. {
  80. struct LocalTime
  81. {
  82. U8 sec; // seconds after minute (0-59)
  83. U8 min; // Minutes after hour (0-59)
  84. U8 hour; // Hours after midnight (0-23)
  85. U8 month; // Month (0-11; 0=january)
  86. U8 monthday; // Day of the month (1-31)
  87. U8 weekday; // Day of the week (0-6, 6=sunday)
  88. U16 year; // current year minus 1900
  89. U16 yearday; // Day of year (0-365)
  90. bool isdst; // true if daylight savings time is active
  91. };
  92. struct FileInfo
  93. {
  94. const char* pFullPath;
  95. const char* pFileName;
  96. U32 fileSize;
  97. bool equal( const FileInfo& fileInfo )
  98. {
  99. return
  100. fileInfo.pFullPath == pFullPath &&
  101. fileInfo.pFileName == pFileName &&
  102. fileInfo.fileSize == fileSize;
  103. }
  104. };
  105. struct VolumeInformation
  106. {
  107. StringTableEntry RootPath;
  108. StringTableEntry Name;
  109. StringTableEntry FileSystem;
  110. U32 SerialNumber;
  111. U32 Type;
  112. bool ReadOnly;
  113. };
  114. typedef void* FILE_HANDLE;
  115. enum DFILE_STATUS
  116. {
  117. DFILE_OK = 1
  118. };
  119. /// Application.
  120. static void init();
  121. static void initConsole();
  122. static void process();
  123. static void shutdown();
  124. static void sleep(U32 ms);
  125. static void restartInstance();
  126. static void postQuitMessage(const U32 in_quitVal);
  127. static void forceShutdown(S32 returnValue);
  128. /// User.
  129. static StringTableEntry getUserHomeDirectory();
  130. static StringTableEntry getUserDataDirectory();
  131. /// Window.
  132. static void initWindow(const Point2I &initialSize, const char *name);
  133. static void setWindowTitle( const char* title );
  134. static void setWindowSize( U32 newWidth, U32 newHeight );
  135. static const Point2I &getWindowSize();
  136. static void minimizeWindow();
  137. static void restoreWindow();
  138. static void setMouseLock(bool locked);
  139. /// GUI.
  140. static void AlertOK(const char *windowTitle, const char *message);
  141. static bool AlertOKCancel(const char *windowTitle, const char *message);
  142. static bool AlertRetry(const char *windowTitle, const char *message);
  143. static bool AlertYesNo(const char *windowTitle, const char *message);
  144. static S32 messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons = MBOkCancel, MBIcons icon = MIInformation);
  145. /// Input.
  146. static void enableKeyboardTranslation(void);
  147. static void disableKeyboardTranslation(void);
  148. /// Date & Time.
  149. static U32 getTime( void );
  150. static U32 getVirtualMilliseconds( void );
  151. static U32 getRealMilliseconds( void );
  152. static void advanceTime(U32 delta);
  153. static S32 getBackgroundSleepTime();
  154. static void getLocalTime(LocalTime &);
  155. static S32 compareFileTimes(const FileTime &a, const FileTime &b);
  156. /// Math.
  157. static float getRandom();
  158. /// Debug.
  159. static void debugBreak();
  160. static void outputDebugString(const char *string);
  161. static void cprintf(const char* str);
  162. /// File IO.
  163. static StringTableEntry getCurrentDirectory();
  164. static bool setCurrentDirectory(StringTableEntry newDir);
  165. static StringTableEntry getTemporaryDirectory();
  166. static StringTableEntry getTemporaryFileName();
  167. static StringTableEntry getExecutableName();
  168. static StringTableEntry getExecutablePath();
  169. static void setMainDotCsDir(const char *dir);
  170. static StringTableEntry getMainDotCsDir();
  171. static StringTableEntry getPrefsPath(const char *file = NULL);
  172. static char *makeFullPathName(const char *path, char *buffer, U32 size, const char *cwd = NULL);
  173. static StringTableEntry stripBasePath(const char *path);
  174. static bool isFullPath(const char *path);
  175. static StringTableEntry makeRelativePathName(const char *path, const char *to);
  176. static bool dumpPath(const char *in_pBasePath, Vector<FileInfo>& out_rFileVector, S32 recurseDepth = -1);
  177. static bool dumpDirectories( const char *path, Vector<StringTableEntry> &directoryVector, S32 depth = 0, bool noBasePath = false );
  178. static bool hasSubDirectory( const char *pPath );
  179. static bool getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime);
  180. static bool isFile(const char *pFilePath);
  181. static S32 getFileSize(const char *pFilePath);
  182. static bool hasExtension(const char* pFilename, const char* pExtension);
  183. static bool isDirectory(const char *pDirPath);
  184. static bool isSubDirectory(const char *pParent, const char *pDir);
  185. static void addExcludedDirectory(const char *pDir);
  186. static void clearExcludedDirectories();
  187. static bool isExcludedDirectory(const char *pDir);
  188. static bool createPath(const char *path);
  189. static bool deleteDirectory( const char* pPath );
  190. static bool fileDelete(const char *name);
  191. static bool fileRename(const char *oldName, const char *newName);
  192. static bool fileTouch(const char *name);
  193. static bool pathCopy(const char *fromName, const char *toName, bool nooverwrite = true);
  194. static StringTableEntry osGetTemporaryDirectory();
  195. /// Misc.
  196. static StringTableEntry createUUID( void );
  197. static bool openWebBrowser( const char* webAddress );
  198. static void openFolder( const char* path );
  199. static const char* getClipboard();
  200. static bool setClipboard(const char *text);
  201. };
  202. #endif // _PLATFORM_H_