y_master.inc 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**--------------------------------------------------------------------------**\
  2. ======================
  3. YSI - Master Include
  4. ======================
  5. Description:
  6. Handles distribution of control of code segments across all running scripts
  7. with YSI to avoid conflicts of checkpoint streamers etc and allow features
  8. like "/commands" displaying all commands on the server.
  9. Now fully autonomous - to use the master system simply define which one you
  10. want and include the script:
  11. #define MASTER 14
  12. #include "Master"
  13. That will make the current script attempt to make itself the main master -
  14. you don't need ANY other code for initialisation anywhere (which took a
  15. while to figure out)...
  16. This is now over 2000 lines of repetitive and complex macros!
  17. Legal:
  18. Version: MPL 1.1
  19. The contents of this file are subject to the Mozilla Public License Version
  20. 1.1 (the "License"); you may not use this file except in compliance with
  21. the License. You may obtain a copy of the License at
  22. http://www.mozilla.org/MPL/
  23. Software distributed under the License is distributed on an "AS IS" basis,
  24. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  25. for the specific language governing rights and limitations under the
  26. License.
  27. The Original Code is the YSI master systems include.
  28. The Initial Developer of the Original Code is Alex "Y_Less" Cole.
  29. Portions created by the Initial Developer are Copyright (C) 2011
  30. the Initial Developer. All Rights Reserved.
  31. Contributors:
  32. ZeeX, koolk, JoeBullet/Google63, g_aSlice/Slice
  33. Thanks:
  34. JoeBullet/Google63 - Handy arbitrary ASM jump code using SCTRL.
  35. ZeeX - Very productive conversations.
  36. koolk - IsPlayerinAreaEx code.
  37. TheAlpha - Danish translation.
  38. breadfish - German translation.
  39. Fireburn - Dutch translation.
  40. yom - French translation.
  41. 50p - Polish translation.
  42. Zamaroht - Spanish translation.
  43. Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
  44. for me to strive to better.
  45. Pixels^ - Running XScripters where the idea was born.
  46. Matite - Pestering me to release it and using it.
  47. Very special thanks to:
  48. Thiadmer - PAWN, whose limits continue to amaze me!
  49. Kye/Kalcor - SA:MP.
  50. SA:MP Team past, present and future - SA:MP.
  51. Version:
  52. 0.2
  53. Changelog:
  54. 06/08/10:
  55. Managed the ultimate - got completely transparent inclusion!
  56. 05/08/10:
  57. Completed new master system, now does all syncing and clients.
  58. 06/10/09:
  59. Rewrote using states.
  60. Added remote function macros.
  61. Reduced the number of masters to a single one. It must have them all.
  62. Vastly simplified the master model - ending the master ends everything.
  63. 06/01/08:
  64. Added code to not pass data if no other script exists.
  65. 17/11/07:
  66. Added code for a script to remove itself from the global list.
  67. 11/10/07:
  68. Not first version but added documentation months late.
  69. Functions:
  70. Public:
  71. -
  72. Core:
  73. -
  74. Stock:
  75. -
  76. Static:
  77. -
  78. Inline:
  79. -
  80. API:
  81. -
  82. Hooks:
  83. -
  84. Callbacks:
  85. -
  86. Definitions:
  87. -
  88. Enums:
  89. -
  90. Macros:
  91. RF - Declare a function which may be remote.
  92. RV - Declare a void function which may be remote.
  93. RS - Declare an optional callback.
  94. RFN - Declare an optional callback with no parameters.
  95. RFC - Declare a slower but shorter function.
  96. RFP - Declare a function with tags and give recall hints.
  97. RFPC - Combination of P and C.
  98. RFCP - Combination of P and C.
  99. Tags:
  100. -
  101. Variables:
  102. Global:
  103. _@ - ID of this script.
  104. Static:
  105. -
  106. Commands:
  107. -
  108. Compile options:
  109. YSI_NO_MASTER - Don't use the master system.
  110. YSI_IS_CLIENT - Script is a client only script.
  111. YSI_IS_SERVER - Script is a server only script.
  112. Operators:
  113. -
  114. Natives:
  115. -
  116. \**--------------------------------------------------------------------------**/
  117. // ALWAYS! The compiler defines this automatically, don't use it as this is
  118. // included multiple times to handle multiple master systems.
  119. #include "..\YSI_Internal\y_compilerpass"
  120. #if AUTO_INCLUDE_GUARD
  121. #if !defined _inc_y_master
  122. #error Did you do <YSI-Core/y_master> instead of the required <YSI-Core\y_master>?
  123. #endif
  124. #undef _inc_y_master
  125. #endif
  126. #if !defined _INC_y_master
  127. #include "..\YSI_Internal\y_version"
  128. #include "y_debug"
  129. #include "..\YSI_Coding\y_hooks"
  130. #include "..\YSI_Internal\y_shortfunc"
  131. #include "..\YSI_Internal\y_natives"
  132. #include "y_master/once"
  133. #endif
  134. #if defined MASTER
  135. #if defined _MASTER
  136. // Store the last master.
  137. #include "y_master\_push_master"
  138. #endif
  139. #else
  140. // Get the previous master (or 0 by default).
  141. #include "y_master\_pop_master"
  142. // Useful debug information (isn't compiled, but shows up with "-l").
  143. P:C(static stock const _POPPED_MASTER = MASTER;);
  144. #endif
  145. #if MASTER < 0 || MASTER >= MAX_MASTERS
  146. #error Invalid MASTER ID.
  147. #endif
  148. #if defined _INC_y_master
  149. // Run at least once - clear previous data.
  150. #include "y_master\_cleanup"
  151. #endif
  152. // Initialise the current master if it hasn't already been done. This is split
  153. // in to 5 parts to reduce compilation times in the common case of not that many
  154. // master systems.
  155. #if MASTER < 16
  156. #include "y_master\_setup_master_A"
  157. #elseif MASTER < 32
  158. #include "y_master\_setup_master_B"
  159. #elseif MASTER < 48
  160. #include "y_master\_setup_master_C"
  161. #else
  162. #include "y_master\_setup_master_D"
  163. #endif
  164. #undef MASTER
  165. // Include all the correct macro versions for the settings we have just found.
  166. #include "y_master\_impl"
  167. #if !defined _INC_y_master
  168. // Only include this lot once.
  169. #define _INC_y_master
  170. #if defined YSI_TESTS
  171. #include "..\YSI_Core\y_testing"
  172. // Get the new master.
  173. #define MASTER 58
  174. #include "y_master"
  175. // Include the tests.
  176. #include "y_master/tests"
  177. // Pop the master.
  178. #include "y_master"
  179. #endif
  180. #endif