Skip to content

Commit

Permalink
修一处没有fmod就爆炸
Browse files Browse the repository at this point in the history
使用更简洁的fmod加载流程
补充语法注释
整理代码(require的单双引号和括号)
  • Loading branch information
MrZ626 committed Jun 25, 2024
1 parent 9e30279 commit 5c8d9cb
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 37 deletions.
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
43 changes: 22 additions & 21 deletions assets/fmod20221/init.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
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")
else
MSG.new('error',"FMOD shared libraries not found!")
end

local M=require'master'

-- (Old method) search for fmod shared libraries in package.cpath
-- local fmodPath=package.searchpath('fmod',package.cpath)
-- local fmodstudioPath=package.searchpath('fmodstudio',package.cpath)
-- -- 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)

M.C=ffi.load('fmod')
if not M.C then MSG.new('error',"FMOD library not found") end

M.C2=ffi.load('fmodstudio')
if not M.C2 then MSG.new('error',"FMODstudio library not found") end

require'enums'
require'constants'
require'wrap'
require'errors'

--------------------------------------------------------------

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
1 change: 1 addition & 0 deletions assets/gamefunc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function playSample(...)
volume=vol,
param={'release',rel*1.0594630943592953^(note-33)},
})
if not event then return end
TASK.new(function()
DEBUG.yieldT(len/1000)
event:stop(FMOD.FMOD_STUDIO_STOP_ALLOWFADEOUT)
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
9 changes: 9 additions & 0 deletions assets/songbook.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
---@class Techmino.MusicMeta
---@field message string
---@field author string
---@field title string
---@field inside? boolean
---@field redirect? string|table<string>
---@field notFound? boolean

---@enum (key) Techmino.MusicName
local songbook={
['8-bit happiness'] ={},
Expand Down Expand Up @@ -116,4 +124,5 @@ setmetatable(songbook,{__call=function(t,name)
}
end})

---@cast songbook table<Techmino.MusicName,Techmino.MusicMeta>
return songbook
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
17 changes: 11 additions & 6 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 Expand Up @@ -420,10 +420,15 @@ TASK.new(function() -- Don't initialize studio at first frame, may cause some we
FMODLoadFunc()
FMOD.setMainVolume(SETTINGS.system.mainVol,true)
for name,data in next,SONGBOOK do
data.intensity=FMOD.music.getParamDesc(name,'intensity')~=nil
data.section=FMOD.music.getParamDesc(name,'section')~=nil
if not FMOD.music.getParamDesc(name,'fade') then
MSG.new('warn',"Missing fade parameter in music '"..name.."'")
if FMOD.music.getDesc(name) then
data.intensity=FMOD.music.getParamDesc(name,'intensity')~=nil
data.section=FMOD.music.getParamDesc(name,'section')~=nil
if not FMOD.music.getParamDesc(name,'fade') then
MSG.new('warn',"Missing 'fade' parameter in music '"..name.."'")
end
else
data.notFound=true
MSG.new('warn',"Music '"..name.."' not found in FMOD")
end
end
end)
Expand Down

0 comments on commit 5c8d9cb

Please sign in to comment.