加载外部库模块化
This commit is contained in:
@@ -2,6 +2,66 @@ local gc=love.graphics
|
|||||||
local int=math.floor
|
local int=math.floor
|
||||||
local sub,find,format=string.sub,string.find,string.format
|
local sub,find,format=string.sub,string.find,string.format
|
||||||
|
|
||||||
|
do--LOADLIB
|
||||||
|
local libName={
|
||||||
|
CC={
|
||||||
|
Windows="CCloader",
|
||||||
|
Linux="CCloader",
|
||||||
|
Android="libCCloader.so",
|
||||||
|
libFunc="luaopen_CCloader",
|
||||||
|
},
|
||||||
|
NETlib={
|
||||||
|
Windows="client",
|
||||||
|
Linux="client",
|
||||||
|
Android="client.so",
|
||||||
|
libFunc="client",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
function LOADLIB(name)
|
||||||
|
local libName=libName[name]
|
||||||
|
if system=="Windows"or system=="Linux"then
|
||||||
|
local success,message=require(libName[system])
|
||||||
|
if success then
|
||||||
|
LOG.print(name.." load successfully","warn",color.green)
|
||||||
|
else
|
||||||
|
LOG.print("Cannot load "..name..": "..message,"warn",color.red)
|
||||||
|
end
|
||||||
|
elseif system=="Android"then
|
||||||
|
local fs=love.filesystem
|
||||||
|
local platform={"arm64-v8a","armeabi-v7a"}
|
||||||
|
local libFunc
|
||||||
|
for i=1,#platform do
|
||||||
|
local soFile,size=fs.read("data","libAndroid/"..platform[i].."/"..libName.Android)
|
||||||
|
if soFile then
|
||||||
|
local success,message=fs.write(libName.Android,soFile,size)
|
||||||
|
if success then
|
||||||
|
libFunc,message=package.loadlib(table.concat({fs.getSaveDirectory(),libName.Android},"/"),libName.libFunc)
|
||||||
|
if libFunc then
|
||||||
|
LOG.print(name.." lib loaded","warn",color.green)
|
||||||
|
break
|
||||||
|
else
|
||||||
|
LOG.print("Cannot load "..name..": "..message,"warn",color.red)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
LOG.print("Write "..name.."-"..platform[i].." to saving failed: "..message,"warn",color.red)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
LOG.print("Read "..name.."-"..platform[i].." failed","warn",color.red)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if not libFunc then
|
||||||
|
LOG.print("failed to load "..name,"warn",color.red)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
LOG.print(name.." load successfully","warn",color.green)
|
||||||
|
libFunc()
|
||||||
|
else
|
||||||
|
LOG.print("No "..name.." for "..system,"warn",color.red)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
do--setFont
|
do--setFont
|
||||||
local newFont=gc.setNewFont
|
local newFont=gc.setNewFont
|
||||||
local setNewFont=gc.setFont
|
local setNewFont=gc.setFont
|
||||||
@@ -25,7 +85,6 @@ do--setFont
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
function setFont(s)
|
function setFont(s)
|
||||||
local f=fontCache[s]
|
|
||||||
if s~=currentFontSize then
|
if s~=currentFontSize then
|
||||||
if not fontCache[s]then
|
if not fontCache[s]then
|
||||||
fontCache[s]=newFont(s)
|
fontCache[s]=newFont(s)
|
||||||
@@ -92,17 +151,34 @@ do--dumpTable
|
|||||||
end
|
end
|
||||||
do--HTTPrequest
|
do--HTTPrequest
|
||||||
local http=require("socket.http")
|
local http=require("socket.http")
|
||||||
function HTTPrequest(url)
|
function HTTPrequest(url,method)
|
||||||
local data={}
|
local data={}
|
||||||
local res,code,response_headers,response_body=http.request{
|
local res,code,response_headers,response_body=http.request{
|
||||||
url=url,
|
url=url,
|
||||||
sink=ltn12.sink.table(data)
|
sink=ltn12.sink.table(data),
|
||||||
|
method=method or"GET",
|
||||||
}
|
}
|
||||||
if code~=200 then
|
if code~=200 then
|
||||||
LOG.print("NET ERROR: code="..(code or"nil"))
|
LOG.print("NET ERROR: code="..(code or"nil"))
|
||||||
end
|
end
|
||||||
return data[1]
|
return data[1]
|
||||||
end
|
end
|
||||||
|
--[[
|
||||||
|
LOADLIB("NETlib")
|
||||||
|
function HTTPrequest(url,method)
|
||||||
|
local task,err=client.httpraw{
|
||||||
|
url=url,
|
||||||
|
method=method,
|
||||||
|
-- header={},
|
||||||
|
-- body="",
|
||||||
|
}
|
||||||
|
if not err then
|
||||||
|
TASK.new(TICK.httpRequest,{code=task,time=0})
|
||||||
|
else
|
||||||
|
LOG.print("NET error: "..err,"error")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
do--json
|
do--json
|
||||||
--
|
--
|
||||||
|
|||||||
55
parts/ai.lua
55
parts/ai.lua
@@ -16,59 +16,7 @@ local Timer=love.timer.getTime
|
|||||||
local blockPos={4,4,4,4,4,5,4}
|
local blockPos={4,4,4,4,4,5,4}
|
||||||
local scs={{0,1},{0,1},{0,1},{0,1},{0,1},{.5,.5},{-.5,1.5}}
|
local scs={{0,1},{0,1},{0,1},{0,1},{0,1},{.5,.5},{-.5,1.5}}
|
||||||
-------------------------------------------------Cold clear
|
-------------------------------------------------Cold clear
|
||||||
do
|
if LOADLIB("CC")then
|
||||||
local fs=love.filesystem
|
|
||||||
if system=="Windows"then
|
|
||||||
local success,message=require("CCloader")
|
|
||||||
if success then
|
|
||||||
LOG.print("CC load successfully","warn",color.green)
|
|
||||||
else
|
|
||||||
LOG.print("Cannot load CC: "..message,"warn",color.red)
|
|
||||||
end
|
|
||||||
if fs.getInfo("CCloader.dll")then
|
|
||||||
NOGAME="delCC"
|
|
||||||
end
|
|
||||||
elseif system=="Linux"then
|
|
||||||
local success,message=require("CCloader")
|
|
||||||
if success then
|
|
||||||
LOG.print("CC load successfully","warn",color.green)
|
|
||||||
else
|
|
||||||
LOG.print("Cannot load CC: "..message,"warn",color.red)
|
|
||||||
end
|
|
||||||
elseif system=="Android"then
|
|
||||||
local armList={"arm64-v8a","armeabi-v7a"}
|
|
||||||
local libFunc,success,message
|
|
||||||
for i=1,#armList do
|
|
||||||
local CCloader_f,size=fs.read("data","libAndroid/"..armList[i].."/libCCloader.so")
|
|
||||||
if CCloader_f then
|
|
||||||
LOG.print("Read CC-"..armList[i].." successfully","warn",color.green)
|
|
||||||
success,message=fs.write("libCCloader.so",CCloader_f,size)
|
|
||||||
if success then
|
|
||||||
LOG.print("Write CC-"..armList[i].." to saving successfully","warn",color.green)
|
|
||||||
libFunc,message=package.loadlib(table.concat({fs.getSaveDirectory(),"libCCloader.so"},"/"),"luaopen_CCloader")
|
|
||||||
if libFunc then
|
|
||||||
LOG.print("CC lib loaded","warn",color.green)
|
|
||||||
break
|
|
||||||
else
|
|
||||||
LOG.print("Cannot load CC: "..message,"warn",color.red)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
LOG.print("Write CC-"..armList[i].." to saving failed","warn",color.red)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
LOG.print("Read CC-"..armList[i].." failed","warn",color.red)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not libFunc then
|
|
||||||
LOG.print("failed to load CC","warn",color.red)
|
|
||||||
goto FAILED
|
|
||||||
end
|
|
||||||
LOG.print("CC load successfully","warn",color.green)
|
|
||||||
libFunc()
|
|
||||||
else
|
|
||||||
LOG.print("No CC for "..system,"warn",color.red)
|
|
||||||
goto FAILED
|
|
||||||
end
|
|
||||||
local CCblockID={6,5,4,3,2,1,0}
|
local CCblockID={6,5,4,3,2,1,0}
|
||||||
CC={
|
CC={
|
||||||
getConf= cc.get_default_config ,--()options,weights
|
getConf= cc.get_default_config ,--()options,weights
|
||||||
@@ -135,7 +83,6 @@ do
|
|||||||
collectgarbage()
|
collectgarbage()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
::FAILED::
|
|
||||||
-------------------------------------------------9 Stack setup
|
-------------------------------------------------9 Stack setup
|
||||||
local dirCount={1,1,3,3,3,0,1}
|
local dirCount={1,1,3,3,3,0,1}
|
||||||
local spinOffset={
|
local spinOffset={
|
||||||
|
|||||||
Reference in New Issue
Block a user