diff --git a/Zframework/init.lua b/Zframework/init.lua index 91f1d39a..937d6006 100644 --- a/Zframework/init.lua +++ b/Zframework/init.lua @@ -2,11 +2,11 @@ SCR= require"Zframework/screen" COLOR= require"Zframework/color" SCN= require"Zframework/scene" LOG= require"Zframework/log" +WS= require"Zframework/websocket" -require"Zframework/loadLib" +loadLib=require"Zframework/loadLib" require"Zframework/wheelScroll" require"Zframework/network" --- require"Zframework/websocket" require"Zframework/setFont" require"Zframework/mDraw" diff --git a/Zframework/loadLib.lua b/Zframework/loadLib.lua index bdc75d42..9f682e67 100644 --- a/Zframework/loadLib.lua +++ b/Zframework/loadLib.lua @@ -1,19 +1,4 @@ -local libs={ - CC={ - Windows="CCloader", - Linux="CCloader", - Android="libCCloader.so", - libFunc="luaopen_CCloader", - }, - NETlib={ - Windows="client", - Linux="client", - Android="client.so", - libFunc="luaopen_client", - }, -} -function loadLib(name) - local libName=libs[name] +return function(name,libName) if SYSTEM=="Windows"or SYSTEM=="Linux"then local r1,r2,r3=pcall(require,libName[SYSTEM]) if r1 and r2 then diff --git a/Zframework/network.lua b/Zframework/network.lua index 0e217ce4..02e31632 100644 --- a/Zframework/network.lua +++ b/Zframework/network.lua @@ -1,4 +1,9 @@ -client=loadLib("NETlib") +client=loadLib("NETlib",{ + Windows="client", + Linux="client", + Android="client.so", + libFunc="luaopen_client", +}) if client then function httpRequest(tick,path,method,header,body) local task,err=client.httpraw{ @@ -14,42 +19,28 @@ if client then end TASK.netTaskCount=TASK.netTaskCount+1 end - - function wsConnect(tick,path,header) - if TASK.wsConnecting then - LOG.print(text.waitNetTask,"message") - return - end - local task,err=client.wsraw{ - url="ws://"..PATH.url..":"..PATH.port..path, - origin=PATH.url, - header=header, - } - if task then - TASK.newWS(tick,task) - else - LOG.print("NETlib error: "..err,"warn") - end - TASK.netTaskCount=TASK.netTaskCount+1 - end - - function wsWrite(data) - if WSCONN then - local writeErr=client.write(WSCONN,data) - if writeErr then - LOG.print(writeErr,"error") - return - end - return true - else - LOG.print(text.wsNoConn,"warn") - end - end else - local function noNetLib() + function httpRequest() LOG.print("[NO NETlib for "..SYSTEM.."]",5,COLOR.yellow) end - httpRequest=noNetLib - wsConnect=noNetLib - wsWrite=noNetLib +end + +function wsConnect(path,body) + local ws=WS.new() + ws:settimeout(6.26) + ws:connect(PATH.url..":"..PATH.port,path,body) + TASK.netTaskCount=TASK.netTaskCount+1 +end + +function wsWrite(data) + if WSCONN then + local writeErr=client.write(WSCONN,data) + if writeErr then + LOG.print(writeErr,"error") + return + end + return true + else + LOG.print(text.wsNoConn,"warn") + end end \ No newline at end of file diff --git a/Zframework/task.lua b/Zframework/task.lua index eb900da7..7627d834 100644 --- a/Zframework/task.lua +++ b/Zframework/task.lua @@ -5,7 +5,6 @@ local tasks={} local TASK={ netTaskCount=0, - wsConnecting=false, } function TASK.getCount() return #tasks @@ -18,9 +17,6 @@ function TASK.update() if T.net then TASK.netTaskCount=TASK.netTaskCount-1 end - if T.ws then - TASK.wsConnecting=false - end rem(tasks,i) end end @@ -48,20 +44,6 @@ function TASK.newNet(code,...) } end end -function TASK.newWS(code,...) - TASK.wsConnecting=true - local thread=ct.create(code) - ct.resume(thread,...) - if ct.status(thread)~="dead"then - tasks[#tasks+1]={ - thread=thread, - code=code, - args={...}, - net=true, - ws=true, - } - end -end function TASK.removeTask_code(code) for i=#tasks,1,-1 do if tasks[i].code==code then diff --git a/parts/ai.lua b/parts/ai.lua index 5cc5899d..866ab9cb 100644 --- a/parts/ai.lua +++ b/parts/ai.lua @@ -14,7 +14,12 @@ local ins,rem=table.insert,table.remove -- 11~13:LL,RR,DD local blockPos={4,4,4,4,4,5,4} -------------------------------------------------Cold clear -local _CC=loadLib("CC")cc=nil +local _CC=loadLib("CC",{ + Windows="CCloader", + Linux="CCloader", + Android="libCCloader.so", + libFunc="luaopen_CCloader", +})cc=nil if _CC then local CCblockID={6,5,4,3,2,1,0} CC={