Update
This commit is contained in:
parent
19ab152f5f
commit
f1eaecd79e
@ -5,6 +5,7 @@ require("/koptilnya/libs/utils.txt")
|
|||||||
|
|
||||||
EngineSound = class("EngineSound")
|
EngineSound = class("EngineSound")
|
||||||
|
|
||||||
|
accessorFunc(EngineSound, "_rpm", "RPM", 0)
|
||||||
accessorFunc(EngineSound, "_masterVolume", "MasterVolume", 1)
|
accessorFunc(EngineSound, "_masterVolume", "MasterVolume", 1)
|
||||||
accessorFunc(EngineSound, "_parent", "Parent", chip())
|
accessorFunc(EngineSound, "_parent", "Parent", chip())
|
||||||
|
|
||||||
@ -29,10 +30,11 @@ local function fadeOut(rpm, range)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function EngineSound:initialize(soundsMap)
|
function EngineSound:initialize(soundsMap)
|
||||||
self._rpm = 0
|
self.pitchDamping = 0.2
|
||||||
self._targetRPM = 0
|
self.volumeDamping = 0.3
|
||||||
|
|
||||||
self._soundsMap = soundsMap
|
self._soundsMap = soundsMap
|
||||||
self._sources = {}
|
self._lastRPM = 0
|
||||||
|
|
||||||
for k, v in pairs(soundsMap) do
|
for k, v in pairs(soundsMap) do
|
||||||
bass.loadURL(v.link, "3d noblock", function(snd, err, errtxt)
|
bass.loadURL(v.link, "3d noblock", function(snd, err, errtxt)
|
||||||
@ -42,39 +44,35 @@ function EngineSound:initialize(soundsMap)
|
|||||||
snd:setVolume(0)
|
snd:setVolume(0)
|
||||||
|
|
||||||
v.source = snd
|
v.source = snd
|
||||||
table.insert(self._sources, snd)
|
v.lastPitch = 1
|
||||||
|
v.lastVolume = 0
|
||||||
elseif errtext then
|
elseif errtext then
|
||||||
error(errtxt)
|
error(errtxt)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
hook.add("think", "EngineSound_think", function()
|
hook.add("think", "EngineSound_think", function()
|
||||||
self._rpm = math.lerp(0.2, self._rpm, self._targetRPM)
|
|
||||||
|
|
||||||
for _, v in pairs(self._soundsMap) do
|
for _, v in pairs(self._soundsMap) do
|
||||||
if v.source then
|
if v.source then
|
||||||
v.source:setPos(self:getParent():getPos())
|
v.source:setPos(self:getParent():getPos())
|
||||||
|
|
||||||
local pitch = self._rpm / v.rootPitch
|
|
||||||
local fadeIn = fadeIn(self._rpm, v.fadeIn)
|
local fadeIn = fadeIn(self._rpm, v.fadeIn)
|
||||||
local fadeOut = fadeOut(self._rpm, v.fadeOut)
|
local fadeOut = fadeOut(self._rpm, v.fadeOut)
|
||||||
|
local targetVolume = self:getMasterVolume() * (fadeIn + fadeOut - 1)
|
||||||
|
local targetPitch = self._rpm / v.rootPitch
|
||||||
|
|
||||||
v.source:setVolume(math.max(self:getMasterVolume() * (fadeIn + fadeOut - 1), 0.01))
|
local pitch = math.lerp(self.pitchDamping, v.lastPitch, targetPitch)
|
||||||
v.source:setPitch(math.max(pitch, 0.01))
|
local volume = math.lerp(self.volumeDamping, v.lastVolume, targetVolume)
|
||||||
|
|
||||||
|
v.source:setVolume(volume)
|
||||||
|
v.source:setPitch(pitch)
|
||||||
|
|
||||||
|
v.lastVolume = volume
|
||||||
|
v.lastPitch = pitch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
_lastRPM = _rpm
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function EngineSound:setRPM(rpm)
|
|
||||||
self._targetRPM = rpm
|
|
||||||
end
|
|
||||||
|
|
||||||
function EngineSound:getRPM()
|
|
||||||
return self._rpm
|
|
||||||
end
|
|
||||||
|
|
||||||
function EngineSound:getSources()
|
|
||||||
return self._sources
|
|
||||||
end
|
|
||||||
@ -281,6 +281,8 @@ function Element:_onPaint()
|
|||||||
if self._firstChild then
|
if self._firstChild then
|
||||||
self._firstChild:_postEventToAllReverse("PAINT")
|
self._firstChild:_postEventToAllReverse("PAINT")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:postChildPaint(x, y, w, h)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -362,7 +364,10 @@ end
|
|||||||
function Element:think()
|
function Element:think()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Element:paint()
|
function Element:paint(x, y, w, h)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Element:postChildPaint(x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Element:onMousePressed(x, y, key, keyName)
|
function Element:onMousePressed(x, y, key, keyName)
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
--@include element.txt
|
--@include element.txt
|
||||||
--@include label.txt
|
--@include label.txt
|
||||||
--@include button.txt
|
--@include button.txt
|
||||||
--@include /koptilnya/libs/utils.txt
|
--@include /koptilnya/libs/utils.txt
|
||||||
@ -31,7 +31,8 @@ function EPanel:initialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.minimizeButton = EButton:new()
|
self.minimizeButton = EButton:new()
|
||||||
self.minimizeButton:setText("_")
|
self.minimizeButton:setFont(GUI.fonts["icons"])
|
||||||
|
self.minimizeButton:setText(string.utf8char(0xE73F))
|
||||||
self.minimizeButton:setSize(32, 32)
|
self.minimizeButton:setSize(32, 32)
|
||||||
self.minimizeButton:setRadius(0)
|
self.minimizeButton:setRadius(0)
|
||||||
self.minimizeButton:setColorScheme(colorScheme)
|
self.minimizeButton:setColorScheme(colorScheme)
|
||||||
@ -42,7 +43,7 @@ function EPanel:initialize()
|
|||||||
|
|
||||||
self.closeButton = EButton:new()
|
self.closeButton = EButton:new()
|
||||||
self.closeButton:setFont(GUI.fonts["icons"])
|
self.closeButton:setFont(GUI.fonts["icons"])
|
||||||
self.closeButton:setText(string.utf8char(10005))
|
self.closeButton:setText(string.utf8char(0xE006))
|
||||||
self.closeButton:setSize(32, 32)
|
self.closeButton:setSize(32, 32)
|
||||||
self.closeButton:setRadius(0)
|
self.closeButton:setRadius(0)
|
||||||
self.closeButton:setColorScheme(colorScheme)
|
self.closeButton:setColorScheme(colorScheme)
|
||||||
|
|||||||
@ -8,7 +8,7 @@ GUI = class("GUI")
|
|||||||
|
|
||||||
GUI.static.fonts = {
|
GUI.static.fonts = {
|
||||||
main = render.createFont("Roboto", 16, 700, true),
|
main = render.createFont("Roboto", 16, 700, true),
|
||||||
icons = render.createFont("Roboto Mono", 24, 400, true)
|
icons = render.createFont("Segoe MDL2 Assets", 32, 400, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function GUI:initialize(renderDevice)
|
function GUI:initialize(renderDevice)
|
||||||
|
|||||||
@ -5,7 +5,7 @@ require("render_device.txt")
|
|||||||
RenderDeviceHUD = class("RenderDeviceHUD", RenderDevice)
|
RenderDeviceHUD = class("RenderDeviceHUD", RenderDevice)
|
||||||
|
|
||||||
function RenderDeviceHUD:initialize()
|
function RenderDeviceHUD:initialize()
|
||||||
render.setHUDActive(true)
|
enableHud(player(), true)
|
||||||
self:setSize(render.getResolution())
|
self:setSize(render.getResolution())
|
||||||
|
|
||||||
hook.add("hudshoulddraw", "gui_hudshoulddraw", function(name)
|
hook.add("hudshoulddraw", "gui_hudshoulddraw", function(name)
|
||||||
|
|||||||
@ -1,20 +1,16 @@
|
|||||||
local MODEL_PLACEHOLDER = "models/holograms/cube.mdl"
|
|
||||||
local BUNDLE_SIZE = 2
|
|
||||||
local SEND_DELAY = 0.5
|
|
||||||
|
|
||||||
MeshBuilder = class("MeshBuilder")
|
MeshBuilder = class("MeshBuilder")
|
||||||
|
|
||||||
function MeshBuilder:initialize()
|
function MeshBuilder:initialize(modelPlaceholder, bundleSize, sendDelay)
|
||||||
|
self.modelPlaceholder = modelPlaceholder or "models/holograms/cube.mdl"
|
||||||
|
self.bundleSize = bundleSize or 10
|
||||||
|
self.sendDelay = sendDelay or 0.5
|
||||||
|
|
||||||
self._objects = {}
|
self._objects = {}
|
||||||
self._setups = {}
|
self._setups = {}
|
||||||
|
|
||||||
if CLIENT then
|
if CLIENT then
|
||||||
self._setups = {}
|
self._setups = {}
|
||||||
self._meshData = {}
|
self._meshData = {}
|
||||||
--[[
|
|
||||||
self._shouldBuild = false
|
|
||||||
self._shouldRevision = true
|
|
||||||
]]
|
|
||||||
|
|
||||||
net.receive("holograms", function(len)
|
net.receive("holograms", function(len)
|
||||||
local hasNext = net.readBit()
|
local hasNext = net.readBit()
|
||||||
@ -38,46 +34,7 @@ function MeshBuilder:initialize()
|
|||||||
hasNext = net.readBit()
|
hasNext = net.readBit()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--[[
|
|
||||||
net.receive("revision", function()
|
|
||||||
local hasNext = net.readBit()
|
|
||||||
|
|
||||||
while hasNext == 1 do
|
|
||||||
local key = net.readString()
|
|
||||||
|
|
||||||
net.readEntity(function(ent)
|
|
||||||
local holo = ent:toHologram()
|
|
||||||
|
|
||||||
self._objects[key] = holo
|
|
||||||
end)
|
|
||||||
|
|
||||||
hasNext = net.readBit()
|
|
||||||
end
|
|
||||||
|
|
||||||
self._shouldRevision = false
|
|
||||||
|
|
||||||
if self._shouldBuild then
|
|
||||||
self:build()
|
|
||||||
|
|
||||||
self._shouldBuild = false
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
]]
|
|
||||||
else
|
else
|
||||||
--[[
|
|
||||||
net.receive("revision", function(len, ply)
|
|
||||||
net.start("revision")
|
|
||||||
for k, v in pairs(self._objects) do
|
|
||||||
net.writeBit(1)
|
|
||||||
net.writeString(k)
|
|
||||||
net.writeEntity(v)
|
|
||||||
end
|
|
||||||
net.writeBit(0)
|
|
||||||
net.send()
|
|
||||||
end)
|
|
||||||
]]
|
|
||||||
|
|
||||||
net.receive("setups", function(len, ply)
|
net.receive("setups", function(len, ply)
|
||||||
local hasNext = net.readBit()
|
local hasNext = net.readBit()
|
||||||
|
|
||||||
@ -97,7 +54,7 @@ function MeshBuilder:initialize()
|
|||||||
ang = relativeTo:localToWorldAngles(ang)
|
ang = relativeTo:localToWorldAngles(ang)
|
||||||
end
|
end
|
||||||
|
|
||||||
local holo = holograms.create(pos, ang, MODEL_PLACEHOLDER, scale)
|
local holo = holograms.create(pos, ang, self.modelPlaceholder, scale)
|
||||||
holo:setColor(color)
|
holo:setColor(color)
|
||||||
holo:setMaterial(mat)
|
holo:setMaterial(mat)
|
||||||
holo:setParent(parent)
|
holo:setParent(parent)
|
||||||
@ -152,17 +109,6 @@ if CLIENT then
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MeshBuilder:build()
|
function MeshBuilder:build()
|
||||||
--[[
|
|
||||||
if self._shouldRevision then
|
|
||||||
net.start("revision")
|
|
||||||
net.send()
|
|
||||||
|
|
||||||
self._shouldBuild = true
|
|
||||||
|
|
||||||
return
|
|
||||||
end
|
|
||||||
]]
|
|
||||||
|
|
||||||
local function sendSetups(setups)
|
local function sendSetups(setups)
|
||||||
net.start("setups")
|
net.start("setups")
|
||||||
for k, v in pairs(setups) do
|
for k, v in pairs(setups) do
|
||||||
@ -181,20 +127,20 @@ if CLIENT then
|
|||||||
end
|
end
|
||||||
|
|
||||||
local bundleKeys = table.getKeys(self._setups)
|
local bundleKeys = table.getKeys(self._setups)
|
||||||
if #bundleKeys > BUNDLE_SIZE then
|
if #bundleKeys > self.bundleSize then
|
||||||
local i = 1
|
local i = 1
|
||||||
|
|
||||||
timer.create("sendSetups", SEND_DELAY, math.ceil(#bundleKeys / BUNDLE_SIZE), function()
|
timer.create("sendSetups", self.sendDelay, math.ceil(#bundleKeys / self.bundleSize), function()
|
||||||
local from = (i - 1) * BUNDLE_SIZE + 1
|
local from = (i - 1) * self.bundleSize + 1
|
||||||
local setups = {}
|
local setups = {}
|
||||||
|
|
||||||
for _, v in pairs({ unpack(bundleKeys, from, from + BUNDLE_SIZE - 1) }) do
|
for _, v in pairs({ unpack(bundleKeys, from, from + self.bundleSize - 1) }) do
|
||||||
setups[v] = self._setups[v]
|
setups[v] = self._setups[v]
|
||||||
end
|
end
|
||||||
|
|
||||||
sendSetups(setups)
|
sendSetups(setups)
|
||||||
|
|
||||||
if i < math.ceil(#bundleKeys / BUNDLE_SIZE) then
|
if i < math.ceil(#bundleKeys / self.bundleSize) then
|
||||||
i = i + 1
|
i = i + 1
|
||||||
else
|
else
|
||||||
table.empty(self._setups)
|
table.empty(self._setups)
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
local MAX_QUOTA = 0.75
|
|
||||||
|
|
||||||
Parser = class("Parser")
|
Parser = class("Parser")
|
||||||
|
|
||||||
local initialChipName = chip():getChipName()
|
local initialChipName = chip():getChipName()
|
||||||
@ -7,7 +5,7 @@ local function setStatus(status)
|
|||||||
setName(string.format("%s (%s)", initialChipName, status))
|
setName(string.format("%s (%s)", initialChipName, status))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Parser:initialize(link)
|
function Parser:initialize(link, maxQuota)
|
||||||
if CLIENT then
|
if CLIENT then
|
||||||
local triangles = mesh.trianglesLeft()
|
local triangles = mesh.trianglesLeft()
|
||||||
local createFromObjCoroutine = coroutine.create(function(objData)
|
local createFromObjCoroutine = coroutine.create(function(objData)
|
||||||
@ -24,7 +22,7 @@ function Parser:initialize(link)
|
|||||||
|
|
||||||
setStatus("File received, start parsing...")
|
setStatus("File received, start parsing...")
|
||||||
hook.add("think", "loadingMesh", function()
|
hook.add("think", "loadingMesh", function()
|
||||||
while quotaAverage() < quotaMax() * MAX_QUOTA do
|
while quotaAverage() < quotaMax() * (maxQuota or 0.75) do
|
||||||
if loadMesh() then
|
if loadMesh() then
|
||||||
setName(initialChipName)
|
setName(initialChipName)
|
||||||
self:onLoaded(objData, self.meshData, triangles - mesh.trianglesLeft())
|
self:onLoaded(objData, self.meshData, triangles - mesh.trianglesLeft())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user