ensystem.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. /**
  2. * \defgroup System System
  3. * @{
  4. */
  5. /**
  6. \brief Returns world time
  7. \param[out] hour \p int Hour
  8. \param[out] minute \p int Minute
  9. \param[out] second \p int Second
  10. \return \p void
  11. @code
  12. int hour = 0;
  13. int minute = 0;
  14. int second = 0;
  15. GetHourMinuteSecondUTC(hour, minute, second);
  16. Print(hour);
  17. Print(minute);
  18. Print(second);
  19. >> hour = 16
  20. >> minute = 38
  21. >> second = 7
  22. @endcode
  23. */
  24. proto void GetHourMinuteSecond(out int hour, out int minute, out int second);
  25. /**
  26. \brief Returns world date
  27. \param[out] year \p int Year
  28. \param[out] month \p int Month
  29. \param[out] day \p int Day
  30. \return \p void
  31. @code
  32. int year = 0;
  33. int month = 0;
  34. int day = 0;
  35. GetYearMonthDay(year, month, day);
  36. Print(year);
  37. Print(month);
  38. Print(day);
  39. >> year = 2015
  40. >> month = 3
  41. >> day = 24
  42. @endcode
  43. */
  44. proto void GetYearMonthDay(out int year, out int month, out int day);
  45. /**
  46. \brief Returns UTC world time
  47. \param[out] hour \p int Hour
  48. \param[out] minute \p int Minute
  49. \param[out] second \p int Second
  50. \return \p void
  51. @code
  52. int hour = 0;
  53. int minute = 0;
  54. int second = 0;
  55. GetHourMinuteSecondUTC(hour, minute, second);
  56. Print(hour);
  57. Print(minute);
  58. Print(second);
  59. >> hour = 15
  60. >> minute = 38
  61. >> second = 7
  62. @endcode
  63. */
  64. proto void GetHourMinuteSecondUTC(out int hour, out int minute, out int second);
  65. /**
  66. \brief Returns UTC world date
  67. \param[out] year \p int Year
  68. \param[out] month \p int Month
  69. \param[out] day \p int Day
  70. \return \p void
  71. @code
  72. int year = 0;
  73. int month = 0;
  74. int day = 0;
  75. GetYearMonthDayUTC(year, month, day);
  76. Print(year);
  77. Print(month);
  78. Print(day);
  79. >> year = 2015
  80. >> month = 3
  81. >> day = 24
  82. @endcode
  83. */
  84. proto void GetYearMonthDayUTC(out int year, out int month, out int day);
  85. proto string GetProfileName();
  86. proto string GetMachineName();
  87. //! performance counter. Returns number of CPU ticks between 'prev' and 'now'
  88. proto native int TickCount(int prev);
  89. /**
  90. \brief Switches memory validation (huge slowdown! Use with care only for certain section of code!)
  91. \param enable \p bool Enable
  92. \return \p void
  93. @code
  94. ???
  95. @endcode
  96. */
  97. proto native void MemoryValidation(bool enable);
  98. /**
  99. \brief Returns command line argument
  100. \param name of a command line argument
  101. \param val \p string value of the param or empty string if the param hasn't been found
  102. \return True if param is present, False if hasn't been found
  103. @code
  104. string param;
  105. GetCLIParam("world", param); // return a value when program executed with param -world something
  106. @endcode
  107. */
  108. proto bool GetCLIParam(string param, out string val);
  109. /**
  110. \brief Returns if command line argument is present
  111. \param name of a command line argument
  112. \return True if param is present, False if hasn't been found
  113. @code
  114. if (IsCLIParam("verbose")) // Prints "something" when program executed with param -verbose
  115. {
  116. Print("something");
  117. }
  118. @endcode
  119. */
  120. proto native bool IsCLIParam(string param);
  121. #ifdef ENF_DONE
  122. //! developer tool - start video grabber
  123. proto native void StartVideo(string name);
  124. //! developer tool - stop video grabber
  125. proto native void StopVideo();
  126. #endif
  127. /**
  128. * \defgroup Keyboard Keyboard input API
  129. * @{
  130. */
  131. enum KeyCode
  132. {
  133. KC_ESCAPE,
  134. KC_1,
  135. KC_2,
  136. KC_3,
  137. KC_4,
  138. KC_5,
  139. KC_6,
  140. KC_7,
  141. KC_8,
  142. KC_9,
  143. KC_0,
  144. KC_MINUS, ///< - on main keyboard
  145. KC_EQUALS,
  146. KC_BACK, ///< backspace
  147. KC_TAB,
  148. KC_Q,
  149. KC_W,
  150. KC_E,
  151. KC_R,
  152. KC_T,
  153. KC_Y,
  154. KC_U,
  155. KC_I,
  156. KC_O,
  157. KC_P,
  158. KC_LBRACKET,
  159. KC_RBRACKET,
  160. KC_RETURN, ///< Enter on main keyboard
  161. KC_LCONTROL,
  162. KC_A,
  163. KC_S,
  164. KC_D,
  165. KC_F,
  166. KC_G,
  167. KC_H,
  168. KC_J,
  169. KC_K,
  170. KC_L,
  171. KC_SEMICOLON,
  172. KC_APOSTROPHE,
  173. KC_GRAVE, ///< accent grave
  174. KC_LSHIFT,
  175. KC_BACKSLASH,
  176. KC_Z,
  177. KC_X,
  178. KC_C,
  179. KC_V,
  180. KC_B,
  181. KC_N,
  182. KC_M,
  183. KC_COMMA,
  184. KC_PERIOD, ///< . on main keyboard
  185. KC_SLASH, ///< / on main keyboard
  186. KC_RSHIFT,
  187. KC_MULTIPLY, ///< * on numeric keypad
  188. KC_LMENU, ///< left Alt
  189. KC_SPACE,
  190. KC_CAPITAL,
  191. KC_F1,
  192. KC_F2,
  193. KC_F3,
  194. KC_F4,
  195. KC_F5,
  196. KC_F6,
  197. KC_F7,
  198. KC_F8,
  199. KC_F9,
  200. KC_F10,
  201. KC_NUMLOCK,
  202. KC_SCROLL, ///< Scroll Lock
  203. KC_NUMPAD7,
  204. KC_NUMPAD8,
  205. KC_NUMPAD9,
  206. KC_SUBTRACT, ///< - on numeric keypad
  207. KC_NUMPAD4,
  208. KC_NUMPAD5,
  209. KC_NUMPAD6,
  210. KC_ADD, ///< + on numeric keypad
  211. KC_NUMPAD1,
  212. KC_NUMPAD2,
  213. KC_NUMPAD3,
  214. KC_NUMPAD0,
  215. KC_DECIMAL, ///< . on numeric keypad
  216. KC_OEM_102, ///< < > | on UK/Germany keyboards
  217. KC_F11,
  218. KC_F12,
  219. KC_NUMPADEQUALS, ///< = on numeric keypad (NEC PC98)
  220. KC_PREVTRACK, ///< Previous Track (DIKC_CIRCUMFLEX on Japanese keyboard)
  221. KC_AT, ///< (NEC PC98)
  222. KC_COLON, ///< (NEC PC98)
  223. KC_UNDERLINE, ///< (NEC PC98)
  224. KC_STOP, ///< (NEC PC98)
  225. KC_AX, ///< (Japan AX)
  226. KC_UNLABELED, ///< (J3100)
  227. KC_NEXTTRACK, ///< Next Track
  228. KC_NUMPADENTER, ///< Enter on numeric keypad
  229. KC_RCONTROL,
  230. KC_MUTE, ///< Mute
  231. KC_CALCULATOR, ///< Calculator
  232. KC_PLAYPAUSE, ///< Play / Pause
  233. KC_MEDIASTOP, ///< Media Stop
  234. KC_VOLUMEDOWN, ///< Volume -
  235. KC_VOLUMEUP, ///< Volume +
  236. KC_WEBHOME, ///< Web home
  237. KC_NUMPADCOMMA, ///< , on numeric keypad (NEC PC98)
  238. KC_DIVIDE, ///< / on numeric keypad
  239. KC_SYSRQ,
  240. KC_RMENU, ///< right Alt
  241. KC_PAUSE, ///< Pause
  242. KC_HOME, ///< Home on arrow keypad
  243. KC_UP, ///< UpArrow on arrow keypad
  244. KC_PRIOR, ///< PgUp on arrow keypad
  245. KC_LEFT, ///< LeftArrow on arrow keypad
  246. KC_RIGHT, ///< RightArrow on arrow keypad
  247. KC_END, ///< End on arrow keypad
  248. KC_DOWN, ///< DownArrow on arrow keypad
  249. KC_NEXT, ///< PgDn on arrow keypad
  250. KC_INSERT, ///< Insert on arrow keypad
  251. KC_DELETE, ///< Delete on arrow keypad
  252. KC_LWIN, ///< Left Windows key
  253. KC_RWIN, ///< Right Windows key
  254. KC_APPS, ///< AppMenu key
  255. KC_POWER, ///< System Power
  256. KC_SLEEP, ///< System Sleep
  257. KC_WAKE, ///< System Wake
  258. KC_MEDIASELECT ///< Media Select
  259. };
  260. /*!
  261. Gets key state
  262. \param key Key code
  263. \returns 0 when not pressed, 15. bit set when pressed, 0.-14. bit pressed count
  264. */
  265. proto native int KeyState(KeyCode key);
  266. /*!
  267. Clears the key state.
  268. Call this function if you want to overcome autorepeating in reporting key state. If called, the KeyState returns pressed only after the key is released and pressed again.
  269. */
  270. proto native void ClearKey(KeyCode key);
  271. /** @}*/
  272. //! returns index of defined key in InputDevice by its name
  273. //proto native int GetDefKey(string name);
  274. //proto native int DefKeyState(int defkey, bool clear);
  275. /**
  276. * \defgroup Mouse Mouse API
  277. * @{
  278. */
  279. enum MouseState
  280. {
  281. LEFT,
  282. RIGHT,
  283. MIDDLE,
  284. X,
  285. Y,
  286. WHEEL
  287. };
  288. //const int MB_PRESSED_MASK
  289. /*!
  290. Returns state of mouse button. It's combination of number of release/pressed edges and mask MB_PRESSED_MASK
  291. that is set when button is pressed.
  292. If you want just to check if button is pressed, use this: if(GetMouseState(MouseState.LEFT) & MB_PRESSED_MASK)) Print("left button pressed");
  293. */
  294. proto native int GetMouseState(MouseState index);
  295. // Gets current mouse position
  296. proto void GetMousePos(out int x, out int y);
  297. // Gets current screen size (resolution)
  298. proto void GetScreenSize(out int x, out int y);
  299. /** @}*/
  300. /**
  301. * \defgroup Gamepad API
  302. * @{
  303. */
  304. enum GamepadButton
  305. {
  306. BUTTON_NONE,
  307. MENU,
  308. VIEW,
  309. A,
  310. B,
  311. X,
  312. Y,
  313. PAD_UP,
  314. PAD_DOWN,
  315. PAD_LEFT,
  316. PAD_RIGHT,
  317. SHOULDER_LEFT,
  318. SHOULDER_RIGHT,
  319. THUMB_LEFT,
  320. THUMB_RIGHT
  321. };
  322. enum GamepadAxis
  323. {
  324. LEFT_THUMB_HORIZONTAL,
  325. LEFT_THUMB_VERTICAL,
  326. RIGHT_THUMB_HORIZONTAL,
  327. RIGHT_THUMB_VERTICAL,
  328. LEFT_TRIGGER,
  329. RIGHT_TRIGGER,
  330. };
  331. //! return if the button is pressed or not
  332. proto native int GetGamepadButton(GamepadButton button);
  333. //! return value in gamepad axis <-1000; 1000>
  334. proto native float GetGamepadAxis(GamepadAxis axis);
  335. /** @}*/
  336. //----------------------------------------------
  337. /**
  338. * \defgroup File FileIO API
  339. * @{
  340. */
  341. enum FileMode
  342. {
  343. READ,
  344. WRITE,
  345. APPEND
  346. };
  347. typedef int[] ParseHandle;
  348. typedef int[] FileHandle;
  349. proto native ParseHandle BeginParse(string filename);
  350. proto int ParseLine(ParseHandle tp, int num, string tokens[]);
  351. proto native void EndParse(ParseHandle file);
  352. //!Check existence of file
  353. proto bool FileExist(string name);
  354. /**
  355. \brief Opens File
  356. @param name of a file to open, (you can use filesystem prefixes ('$profile','$saves','$mission'). For accessing profile dir use '$profile', e.g. '$profile:myfilename.txt')
  357. @param mode constants FileMode.WRITE, FileMode.READ or FileMode.APPEND flag can be used
  358. \return file handle ID or 0 if fails
  359. \n usage :
  360. @code
  361. FileHandle file = OpenFile("$profile:testiik.txt", FileMode.WRITE);
  362. //FileHandle file = OpenFile("$profile:testiik.txt", FileMode.APPEND);
  363. if (file != 0)
  364. {
  365. FPrintln(file, "line1");
  366. FPrintln(file, "line2");
  367. FPrintln(file, "line3");
  368. CloseFile(file);
  369. }
  370. @endcode
  371. */
  372. proto FileHandle OpenFile(string name, FileMode mode);
  373. /**
  374. Reads raw data from file.
  375. \param param_array Receiving array for the data. Valid types are int[] or string
  376. \param length Length of data
  377. \returns number of read bytes
  378. */
  379. proto int ReadFile(FileHandle file, void param_array, int length);
  380. /**
  381. \brief Close the File
  382. @param file File handle ID of a opened file
  383. \return void
  384. \n usage :
  385. @code
  386. FileHandle file = OpenFile("$profile:testiik.txt", FileMode.WRITE);
  387. if (file != 0)
  388. {
  389. FPrintln(file, "line1");
  390. FPrintln(file, "line2");
  391. FPrintln(file, "line3");
  392. CloseFile(file);
  393. }
  394. @endcode
  395. */
  396. proto void CloseFile(FileHandle file);
  397. /**
  398. \brief Write to file
  399. @param file File handle ID of a opened file
  400. @param var Value to write
  401. \return void
  402. \n usage :
  403. @code
  404. FileHandle file = OpenFile("$profile:testiik.txt", FileMode.WRITE);
  405. if (file != 0)
  406. {
  407. FPrint(file, "A");
  408. FPrint(file, "B");
  409. FPrint(file, "C");
  410. CloseFile(file);
  411. }
  412. @endcode
  413. */
  414. proto void FPrint(FileHandle file, void var);
  415. /**
  416. \brief Write to file and add new line
  417. @param file File handle ID of a opened file
  418. @param var Value to write
  419. \return void
  420. \n usage :
  421. @code
  422. FileHandle file = OpenFile("$profile:testiik.txt", FileMode.WRITE);
  423. if (file != 0)
  424. {
  425. FPrintln(file, "line1");
  426. FPrintln(file, "line2");
  427. FPrintln(file, "line3");
  428. CloseFile(file);
  429. }
  430. @endcode
  431. */
  432. proto void FPrintln(FileHandle file, void var);
  433. /**
  434. \brief Get line from file, every next call of this function returns next line
  435. @param file File handle ID of a opened file
  436. @param var Value to write
  437. \return int Count of chars or -1 if is not any for read (end of file is EMPTY line)
  438. \n usage :
  439. @code
  440. FileHandle file_handle = OpenFile("$profile:testiik.txt", FileMode.READ);
  441. string line_content;
  442. while ( FGets( file_handle, line_content ) > 0 )
  443. {
  444. Print(line_content);
  445. }
  446. CloseFile(file_handle);
  447. @endcode
  448. */
  449. proto int FGets(FileHandle file, string var);
  450. typedef int[] FindFileHandle;
  451. enum FileAttr
  452. {
  453. DIRECTORY, ///<File is directory
  454. HIDDEN, ///<File is hidden
  455. READONLY, ///<File is read-only
  456. INVALID ///<Invalid file
  457. };
  458. enum FindFileFlags
  459. {
  460. DIRECTORIES, ///<Looks for files in fs directories only.
  461. ARCHIVES, ///<Looks for files in archive only. (.pak)
  462. ALL ///<Looks in archives and fs directories.
  463. }
  464. proto FindFileHandle FindFile(string pattern, out string fileName, out FileAttr fileAttributes, FindFileFlags flags);
  465. proto bool FindNextFile(FindFileHandle handle, out string fileName, out FileAttr fileAttributes);
  466. proto native void CloseFindFile(FindFileHandle handle);
  467. //!Makes a directory
  468. proto native bool MakeDirectory(string name);
  469. //!delete file. Works only on "$profile:" and "$saves:" locations
  470. proto native bool DeleteFile(string name);
  471. //! copy file. destName must be "$profile:" or "$saves:" location
  472. proto native bool CopyFile(string sourceName, string destName);
  473. /** @}*/
  474. //@}