78 lines
1.7 KiB
Lua
78 lines
1.7 KiB
Lua
require "love.sound"
|
|
require "love.thread"
|
|
require "love.math"
|
|
require "love.timer"
|
|
local ctrl = love.thread.getChannel("ctrl")
|
|
local sndc = love.thread.getChannel("snd")
|
|
local pos,look,chunk,rate,bits
|
|
local emsnd
|
|
local function send(c,v)
|
|
sndc:push(c)
|
|
sndc:push(v)
|
|
end
|
|
local function go(uu)
|
|
local t = love.timer.getTime()
|
|
local ok,err,x = xpcall(function()
|
|
local snd,x = dofile("sound.lua")
|
|
snd = snd:phase(pos):clamp(0,chunk,true)
|
|
if not uu then
|
|
snd = assert(snd:compile(rate,bits),"no sound")
|
|
assert(snd:typeOf("SoundData"),"fake sound")
|
|
end
|
|
return snd,x
|
|
end,debug.traceback)
|
|
look = tonumber(x) or look
|
|
local tt = love.timer.getTime()
|
|
sndc:performAtomic(function()
|
|
send("look",look)
|
|
if not uu then
|
|
if not ok then
|
|
send("snd",emsnd)
|
|
print(err)
|
|
else
|
|
send("snd",err)
|
|
end
|
|
pos=pos+chunk
|
|
end
|
|
send("pos",pos)
|
|
end)
|
|
if love.timer.getTime()-tt > 0.01 then
|
|
print("TIME TAKEN:",love.timer.getTime()-tt)
|
|
end
|
|
if not uu then
|
|
t=love.timer.getTime()-t
|
|
local chnkcc=16
|
|
local pgb=math.floor(t/chunk*chnkcc+.5)
|
|
print(("time: %.2f..%.2f\tload: %.2f%%\t[%s%s%s]"):format(
|
|
pos-chunk,pos,
|
|
math.floor(t/chunk*100+.5),
|
|
("#"):rep(math.min(pgb,chnkcc)),
|
|
("."):rep(math.max(0,chnkcc-pgb)),
|
|
("!"):rep(math.max(0,-(chnkcc-pgb)))
|
|
))
|
|
end
|
|
end
|
|
while true do
|
|
local cmd = ctrl:demand()
|
|
local v = ctrl:demand()
|
|
if cmd == "pos" then
|
|
pos = v
|
|
elseif cmd == "look" then
|
|
look = v
|
|
elseif cmd == "chunk" then
|
|
chunk = v
|
|
elseif cmd == "emsnd" then
|
|
emsnd = v
|
|
elseif cmd == "rate" then
|
|
rate = v
|
|
elseif cmd == "bits" then
|
|
bits = v
|
|
elseif cmd == "snd" then
|
|
go()
|
|
elseif cmd == "slook" then
|
|
go(true)
|
|
else
|
|
error("unkc: "..tostring(cmd))
|
|
end
|
|
end
|