v3.inc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**--------------------------------------------------------------------------**\
  2. ====================================
  3. y_timers - Run timers efficiently.
  4. ====================================
  5. Description:
  6. Sets up repeating timers without requiring any SetTimers and arranges them
  7. so that they will be very unlikely to meet (at least for a long time) using
  8. scheduling algorithms to get timers with the same period to be offset. Also
  9. fixes arrays and strings in timers so they can be passed properly.
  10. Legal:
  11. Version: MPL 1.1
  12. The contents of this file are subject to the Mozilla Public License Version
  13. 1.1 (the "License"); you may not use this file except in compliance with
  14. the License. You may obtain a copy of the License at
  15. http://www.mozilla.org/MPL/
  16. Software distributed under the License is distributed on an "AS IS" basis,
  17. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  18. for the specific language governing rights and limitations under the
  19. License.
  20. The Original Code is the YSI timers include.
  21. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  22. Portions created by the Initial Developer are Copyright (C) 2011
  23. the Initial Developer. All Rights Reserved.
  24. Contributors:
  25. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  26. Thanks:
  27. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  28. ZeeX - Very productive conversations.
  29. koolk - IsPlayerinAreaEx code.
  30. TheAlpha - Danish translation.
  31. breadfish - German translation.
  32. Fireburn - Dutch translation.
  33. yom - French translation.
  34. 50p - Polish translation.
  35. Zamaroht - Spanish translation.
  36. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  37. for me to strive to better.
  38. Pixels^ - Running XScripters where the idea was born.
  39. Matite - Pestering me to release it and using it.
  40. Very special thanks to:
  41. Thiadmer - PAWN, whose limits continue to amaze me!
  42. Kye/Kalcor - SA:MP.
  43. SA:MP Team past, present and future - SA:MP.
  44. Version:
  45. 2.0
  46. Changelog:
  47. 29/04/11:
  48. Added version 2 of the code with more advanced options.
  49. 21/03/11:
  50. Added debug printing to timer functions. Uses "P:C" in compiling.
  51. 26/10/10:
  52. Officially added simple calling.
  53. Added "delay" functions.
  54. 12/10/10:
  55. Rewrote for YSI 1.0 using y_scripting.
  56. 11/08/07:
  57. Removed millions of defines to reduce pre-processing.
  58. Added pickups.
  59. 03/08/07:
  60. First version.
  61. </remarks>
  62. \**--------------------------------------------------------------------------**/
  63. // These are the tag-type definitions for the various possible parameter types.
  64. // Array-like definitions.
  65. #define @Yf:@Yg:@Yh:@Yx:#%0#%1|||%3[%4]|||%5,%6;%9||| @Ye:@Yw:#%0#%1|||%3[%4]|||%5,%6;%9|||
  66. #define @Ye:@Yw:#%0#%1|||%2string:%3[%4]|||%5,%6;%9||| @Yf:@Yg:@Yh:@Yx:#%0s#%1,%3|||%5|||%6;%9,%3|||
  67. // This one has an extra parameter because arrays must always be followed by
  68. // their length.
  69. #define @Yw:#%0#%1|||%3[%4]|||%5,%6,%7;%9||| @Yf:@Yg:@Yh:@Yx:#%0ad#%1,%3,%5|||%6|||%7;%9,%3,%5|||
  70. // Tag-like definitions.
  71. #define @Yg:@Yh:@Yx:#%0#%1|||%2:%3|||%5,%6;%9||| @Yf:@Yg:@Yh:@Yx:#%0d#%1,%2:%3|||%5|||%6;%9,%2:%3|||
  72. // Others.
  73. #define @Yh:@Yx:#%0#%1|||%3|||%5,%6;%9||| @Yf:@Yg:@Yh:@Yx:#%0d#%1,%3|||%5|||%6;%9,%3|||
  74. // Main entry point for defer type determination.
  75. #define _YT@CR:%0,%1)%2||| @Yf:@Yg:@Yh:@Yx:##|||%0|||%1;%2|||
  76. // Define for "defer" with timer, parameters and main function.
  77. #define YSI_timer%0[%1]%3(%2) stock%0_yT@(%2)return SetTimerEx(#%0,(I@==-1)?(%1):I@,@Yj:J@,_YT@CR:%2,,)%0|||%0|||(%2)
  78. // Expand additional parameters out to three functions after processing.
  79. #define @Yx:%0||||||;%1,%2|||%4|||(%5) %0);%1(%5);public%4(%5)
  80. // Can't believe I never thought of this before! If only there was a way to
  81. // make it less generic than "id".
  82. #define @Yj:J@,_YT@CR:,,)%0|||%1|||(%3) J@,#);%0();public%0()
  83. #define defer%0(%1) (J@=0,I@=-1,Timer:%0_yT@(%1))
  84. #define repeat%0(%1) (J@=1,I@=-1,Timer:%0_yT@(%1))
  85. // Custom time.
  86. #define Timer:%0[%1]_yT@(%2) I@=%1,Timer:%0_yT@(%2)
  87. #define stop%0; {KillTimer(_:%0);}