Skip to content

Commit

Permalink
尝试在安卓加载fmod库
Browse files Browse the repository at this point in the history
整理代码 框架跟进
  • Loading branch information
MrZ626 committed Jun 24, 2024
1 parent 313dc16 commit a7f863e
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Zenitha
2 changes: 1 addition & 1 deletion assets/fmod20221/cdef.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("ffi").cdef[[
require'ffi'.cdef[[
typedef int FMOD_BOOL;
typedef struct FMOD_SYSTEM FMOD_SYSTEM;
typedef struct FMOD_SOUND FMOD_SOUND;
Expand Down
6 changes: 3 additions & 3 deletions assets/fmod20221/constants.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
local bit=require("bit")
local ffi=require("ffi")
local bit=require'bit'
local ffi=require'ffi'
local require=simpRequire(((...):gsub("[^%.]*$", "")))

---@class FMOD.Master
local M=require("master")
local M=require'master'

M.FMOD_VERSION=0x00020221
M.FMOD_DEBUG_LEVEL_NONE=0x00000000
Expand Down
2 changes: 1 addition & 1 deletion assets/fmod20221/enums.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local require=simpRequire(((...):gsub("[^%.]*$", "")))

---@class FMOD.Master
local M=require("master")
local M=require'master'
local C=M.C

M.FMOD_THREAD_TYPE_MIXER=C.FMOD_THREAD_TYPE_MIXER
Expand Down
2 changes: 1 addition & 1 deletion assets/fmod20221/errors.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
local require=simpRequire(((...):gsub("[^%.]*$", "")))

---@class FMOD.Master
local M=require("master")
local M=require'master'

M.errorString=setmetatable({
[M.FMOD_OK]="No errors.",
Expand Down
55 changes: 37 additions & 18 deletions assets/fmod20221/init.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
local ffi=require("ffi")
local ffi=require'ffi'
local require=simpRequire(((...):gsub(".init$","").."."))

require("cdef")
require'cdef'

---@class FMOD.Master
local M=require("master")

-- search for fmod shared libraries in package.cpath
local fmodPath=package.searchpath("fmod",package.cpath)
local fmodstudioPath=package.searchpath("fmodstudio",package.cpath)

if fmodPath and fmodstudioPath then
-- pretend to load libfmod through Lua (it's going to fail but not raise any errors) so that its location is known when loading libfmodstudio through ffi
-- package.loadlib(fmodPath,"")
M.C=ffi.load(fmodPath)
M.C2=ffi.load(fmodstudioPath)
require("enums")
require("constants")
require("wrap")
require("errors")
local M=require'master'

if SYSTEM=='Android' then
local platform='armeabi-v7a'
local p=io.popen('uname -m')
if p then
local arch=p:read('*a'):lower()
p:close()
if arch:find('v8') or arch:find('64') then
platform='arm64-v8a'
elseif arch:find('x86_64') then
platform='x86_64'
elseif arch:find('x86') then
platform='x86'
end
end
love.filesystem.write('lib/libfmod.so',love.filesystem.read('data','libAndroid/fmod/'..platform..'/libfmod.so'))
love.filesystem.write('lib/libfmodstudio.so',love.filesystem.read('data','libAndroid/fmod/'..platform..'/libfmodstudio.so'))
M.C=ffi.load(love.filesystem.getSaveDirectory()..'/lib/libfmod.so')
M.C2=ffi.load(love.filesystem.getSaveDirectory()..'/lib/libfmodstudio.so')
else
MSG.new('error',"FMOD shared libraries not found!")
-- search for fmod shared libraries in package.cpath
local fmodPath=package.searchpath('fmod',package.cpath)
local fmodstudioPath=package.searchpath('fmodstudio',package.cpath)
if fmodPath and fmodstudioPath then
-- pretend to load libfmod through Lua (it's going to fail but not raise any errors) so that its location is known when loading libfmodstudio through ffi
-- package.loadlib(fmodPath,"")
M.C=ffi.load(fmodPath)
M.C2=ffi.load(fmodstudioPath)
require'enums'
require'constants'
require'wrap'
require'errors'
else
MSG.new('error',"FMOD shared libraries not found!")
end
end


Expand Down
4 changes: 2 additions & 2 deletions assets/fmod20221/wrap.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local ffi=require("ffi")
local ffi=require'ffi'
local require=simpRequire(((...):gsub("[^%.]*$", "")))

---@alias FMOD.GUID FMOD.GUID
Expand All @@ -7,7 +7,7 @@ local require=simpRequire(((...):gsub("[^%.]*$", "")))
---@alias FMOD.Enum FMOD.Enum

---@class FMOD.Master
local M=require("master")
local M=require'master'
local C=M.C
local C2=M.C2

Expand Down
2 changes: 1 addition & 1 deletion assets/scene/dictionary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local contents={
}
-- Base dict data, not formatted
local baseDict do
baseDict=require('assets/dict_base')
baseDict=require'assets/dict_base'
local dictObjMeta={__index=function(obj,k)
if k=='titleText' then
obj.titleText=GC.newText(FONT.get(obj.titleSize,'bold'),obj.titleFull)
Expand Down
2 changes: 1 addition & 1 deletion conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function love.conf(t)
W.width,W.height=1440,900
W.minwidth,W.minheight=288,180
end
W.title=require"version".appName.." "..require"version".appVer
W.title=require'version'.appName.." "..require'version'.appVer

if fs.getInfo('assets/image/icon.png') then
W.icon='assets/image/icon.png'
Expand Down
4 changes: 2 additions & 2 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
-------------------------------------------------------------
-- Load Zenitha

require("Zenitha")
require'Zenitha'
DEBUG.checkLoadTime("Load Zenitha")
-- DEBUG.runVarMonitor()
-- DEBUG.setCollectGarvageVisible()
Expand All @@ -37,7 +37,7 @@ STRING.install()
math.randomseed(os.time()*626)
love.setDeprecationOutput(false)
love.keyboard.setTextInput(false)
VERSION=require"version"
VERSION=require'version'

--------------------------------------------------------------
-- Create directories
Expand Down

0 comments on commit a7f863e

Please sign in to comment.