Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

love.js #50

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
4 changes: 3 additions & 1 deletion intro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ function intro_update(dt)
end

if introprogress > 0.5 and playedwilhelm == nil then
playsound(stabsound)
if love.system.getOS() ~= "Web" then
playsound(stabsound)
end

playedwilhelm = true
end
Expand Down
34 changes: 32 additions & 2 deletions musicloader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ music = {

music.stringlist = table.concat(music.toload, ";")

-- music loading constants

local musicpath = "sounds/%s.ogg"

local function getfilename(name)
local filename = name:match("%.[mo][pg][3g]$") and name or musicpath:format(name) -- mp3 or ogg
if love.filesystem.getInfo(filename).type == "file" then
return filename
else
print(string.format("thread can't load \"%s\": not a file!", filename))
end
end

function loadsong(name)
local filename = getfilename(name)
if filename then
local source = love.audio.newSource(love.sound.newDecoder(filename, 512 * 1024), "static")
--print("thread loaded music", name)
return source
end
return false
end

-- music object

function music:init()
self.thread:start()
end
Expand All @@ -35,8 +60,13 @@ end
function music:play(name)
if name and soundenabled then
if self.loaded[name] == false then
local source = self.thread:demand(name)
self:onLoad(name, source)
local source = love.thread.getChannel(name):pop()
if source == nil then
source = loadsong(name)
end
if source ~= nil then
self:onLoad(name, source)
end
end
if self.loaded[name] then
self.loaded[name]:play()
Expand Down
20 changes: 3 additions & 17 deletions musicloader_thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ require("love.filesystem")
require("love.sound")
require("love.audio")
require("love.timer")

local musicpath = "sounds/%s.ogg"
require("musicloader")

local musiclist = {}
local musictoload = {} -- waiting to be loaded into memory
Expand All @@ -22,24 +21,11 @@ local function getmusiclist()
end
end

local function getfilename(name)
local filename = name:match("%.[mo][pg][3g]$") and name or musicpath:format(name) -- mp3 or ogg
if love.filesystem.getInfo(filename).type == "file" then
return filename
else
print(string.format("thread can't load \"%s\": not a file!", filename))
end
end

local function loadmusic()
if #musictoload > 0 then
local name = table.remove(musictoload, 1)
local filename = getfilename(name)
if filename then
local source = love.audio.newSource(love.sound.newDecoder(filename, 512 * 1024), "static")
--print("thread loaded music", name)
love.thread.getChannel(name):push(source)
end
local source = loadsong(name)
love.thread.getChannel(name):push(source)
end
end

Expand Down
6 changes: 6 additions & 0 deletions shaders/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ shaders.passes = {}
-- call at the end of love.load
-- numpasses is the max number of concurrent shaders (default 2)
function shaders:init(numpasses)
if true then return end
numpasses = numpasses or 2

local files = love.filesystem.getDirectoryItems("shaders")
Expand Down Expand Up @@ -131,6 +132,7 @@ end
-- pass nil as the second argument to disable that shader pass
-- don't call before shaders:init()
function shaders:set(i, shadername)
if true then return end
i = i or 1
local pass = self.passes[i]
if not pass then return end
Expand All @@ -150,6 +152,7 @@ end
-- for tweaking some of the 'extern' parameters in the shaders
-- returns true if it worked, false with an error message otherwise
function shaders:setParameter(shadername, paramname, ...)
if true then return end
if self.effects[shadername] then
local effect = self.effects[shadername][1]
return pcall(effect.send, effect, paramname, ...)
Expand All @@ -160,6 +163,7 @@ end
-- automatically called on init
-- should also be called when resolution changes or fullscreen is toggled
function shaders:refresh()
if true then return end
if not self.scale or self.scale ~= scale
or not self.xres or not self.yres
or self.xres ~= love.graphics.getWidth() or self.yres ~= love.graphics.getHeight() then
Expand All @@ -180,6 +184,7 @@ end
-- call in love.draw before drawing whatever you want post-processed
-- note: don't change shaders in between predraw and postdraw!
function shaders:predraw()
if true then return end
-- only predraw the first available pass here (we'll do the rest in postdraw)
self.curcanvas = nil
for i,v in ipairs(self.passes) do
Expand All @@ -194,6 +199,7 @@ end

-- call in love.draw after drawing whatever you want post-processed
function shaders:postdraw()
if true then return end
if not self.curcanvas then return end

local blendmode, alphamode = love.graphics.getBlendMode()
Expand Down