MainMerge.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. if jit then
  2. jit.off()
  3. jit.flush()
  4. print("jit close")
  5. end
  6. real_os_time = real_os_time or os.time
  7. local Timer
  8. function os.time(tb)
  9. if tb then
  10. return real_os_time(tb)
  11. end
  12. Timer = Timer or require("core.Timer")
  13. local t = Timer.now
  14. return 0 < t and (t - t % 1000) / 1000 or real_os_time()
  15. end
  16. real_os_date = real_os_date or os.date
  17. local tb = {}
  18. for i = 1, 64 do
  19. tb[i] = {}
  20. end
  21. local tblen = 0
  22. function os.date(fmt, t)
  23. t = t or os.time()
  24. if fmt == "*t" then
  25. tblen = tblen + 1
  26. if #tb < tblen then
  27. tblen = 1
  28. end
  29. local d = tb[tblen]
  30. d.year, d.month, d.day, d.hour, d.min, d.sec, d.wday,d.yday = global.date(t)
  31. return d
  32. else
  33. return real_os_date(fmt, t)
  34. end
  35. end
  36. adj = adj or {}
  37. envs = envs or {}
  38. file_last_modify_time = file_last_modify_time or {}
  39. loaded = loaded or {}
  40. str2filename = str2filename or {}
  41. local sta = {}
  42. tb_loadfile = tb_loadfile or {}
  43. local function hot_dfs(a)
  44. if loaded[a] then
  45. print("hot=====", a)
  46. loaded[a] = nil
  47. for b in pairs(adj[a]) do
  48. hot_dfs(b)
  49. end
  50. end
  51. end
  52. local function hot()
  53. for k, v in pairs(str2filename) do
  54. local a = global.get_file_last_modify_time(v)
  55. if a ~= file_last_modify_time[k] then
  56. file_last_modify_time[k] = a
  57. tb_loadfile[k] = nil
  58. hot_dfs(k)
  59. end
  60. end
  61. end
  62. collectgarbage("step", 100000)
  63. hot()
  64. collectgarbage("step", 100000)
  65. local path = {
  66. "script/",
  67. "script/module/",
  68. }
  69. local require_cnt = 0
  70. _G.old_require = _G.old_require or require
  71. threadID = threadID or nil
  72. function _G.get_tid()
  73. if not threadID then
  74. threadID = _G.get_thread_id(_G.logic_id)
  75. end
  76. return threadID
  77. end
  78. ConfigLoadFile = ConfigLoadFile or nil
  79. function require(str, not_need_exist)
  80. if not ConfigLoadFile then
  81. ConfigLoadFile = {}
  82. ConfigLoadFile = require("Config")
  83. print("load excel project:", ConfigLoadFile.PROJECT_NAME)
  84. end
  85. require_cnt = require_cnt + 1
  86. adj[str] = adj[str] or {}
  87. if sta[#sta] then
  88. adj[str][sta[#sta]] = true
  89. end
  90. sta[#sta + 1] = str
  91. if not loaded[str] then
  92. loaded[str] = true
  93. envs[str] = envs[str] or {
  94. _G = _G,
  95. assert = assert,
  96. error = error,
  97. getfenv = getfenv,
  98. ipairs = ipairs,
  99. load = load,
  100. next = next,
  101. pairs = pairs,
  102. pcall = pcall,
  103. print = print,
  104. require = require,
  105. setmetatable = setmetatable,
  106. tonumber = tonumber,
  107. tostring = tostring,
  108. type = type,
  109. debug = debug,
  110. io = io,
  111. math = math,
  112. string = string,
  113. table = table,
  114. os = os,
  115. }
  116. envs[str]._ENV = envs[str]
  117. if not str2filename[str] then
  118. local filename = string.gsub(str, "%.", "/") .. ".lua"
  119. local _, excelPos = string.find(filename, "excel/", 1, true)
  120. if excelPos then
  121. local prename = string.sub(filename, 1, excelPos)
  122. local lastname = string.sub(filename, excelPos+1, #filename)
  123. filename = prename .. ConfigLoadFile.PROJECT_NAME .. "/" .. lastname
  124. end
  125. local ac
  126. for _, v in ipairs(path) do
  127. local pre_filename = v .. filename
  128. local a = global.get_file_last_modify_time(pre_filename)
  129. if a ~= 0 then
  130. str2filename[str] = pre_filename
  131. file_last_modify_time[str] = a
  132. ac = true
  133. break
  134. end
  135. end
  136. if not ac then
  137. if not_need_exist then
  138. return
  139. else
  140. assert(nil, str .. " not exist")
  141. end
  142. end
  143. end
  144. local fun = tb_loadfile[str]
  145. if not fun then
  146. local err
  147. fun, err = loadfile(str2filename[str], nil, envs[str])
  148. if not fun then
  149. assert(nil, err)
  150. end
  151. end
  152. local require_cnt_old = require_cnt
  153. fun()
  154. if require_cnt_old < require_cnt then
  155. tb_loadfile[str] = fun
  156. end
  157. end
  158. sta[#sta] = nil
  159. return envs[str]
  160. end
  161. modtb = modtb or nil
  162. local function cmd2str(cmd)
  163. if modtb then
  164. return
  165. end
  166. local f = io.popen(cmd)
  167. local str = f:read("*a")
  168. assert(io.close(f))
  169. return str
  170. end
  171. local function get_modules(str)
  172. if modtb then
  173. return modtb
  174. end
  175. modtb = {}
  176. local i = 1
  177. while true do
  178. local j = string.find(str, "\n", i)
  179. if not j then
  180. break
  181. end
  182. modtb[#modtb + 1] = string.sub(str, i, j - 1)
  183. i = j + 1
  184. end
  185. table.sort(modtb)
  186. return modtb
  187. end
  188. local cmd = os.getenv("OS") == "Windows_NT" and "dir/b script\\module" or "ls script/module"
  189. local m = get_modules(cmd2str(cmd))
  190. local Msg = require("core.Msg")
  191. local InnerMsg = require("core.InnerMsg")
  192. local Config = require("Config")
  193. if Config.IS_MIDDLE == true then
  194. _G['is_middle'] = true
  195. end
  196. local Log = require("common.Log")
  197. local Timer = require("core.Timer")
  198. local Monitor = require("core.Monitor")
  199. local AdminLogic = require("AdminLogic")
  200. local ObjHuman = require("core.ObjHuman")
  201. local Obj = require("core.Obj")
  202. local msg_ex = _G.msg_ex
  203. Timer.now = global.get_msec() --当前时间
  204. function handlerTime(msec)
  205. -- Timer.handlerTime(msec)
  206. end
  207. --合服开始
  208. local MergeServerLogic = require("merge.MergeServerLogic")
  209. MergeServerLogic.Start()
  210. collectgarbage("collect")
  211. print("logic:"..collectgarbage("count"))--, jit.status())