mirror of
https://github.com/CFC-Servers/material-editor-tool.git
synced 2025-03-04 03:13:00 -05:00
Stop using net.WriteTable, improve net efficiency (#14)
* Stop using net.WriteTable, improve net efficiency * Up precision, remove len * Use Write/ReadInt * Fix rounding issue --------- Co-authored-by: StrawWagen <64710817+StrawWagen@users.noreply.github.com>
This commit is contained in:
parent
a2f4942ff8
commit
278a3400a1
@ -199,16 +199,39 @@ function advMat_Table:Set( ent, texture, data )
|
||||
end
|
||||
|
||||
local requestQueueBatchSize = 50
|
||||
local bitSize = 17
|
||||
local divisor = 100
|
||||
|
||||
if CLIENT then
|
||||
local function readDecimal()
|
||||
return net.ReadInt( bitSize ) / divisor
|
||||
end
|
||||
|
||||
net.Receive( "AdvMatMaterialize", function()
|
||||
local ent = net.ReadEntity()
|
||||
local texture = net.ReadString()
|
||||
local data = net.ReadTable()
|
||||
if not IsValid( ent ) then return end
|
||||
|
||||
if IsValid( ent ) then
|
||||
advMat_Table:Set( ent, texture, data )
|
||||
end
|
||||
local texture = net.ReadString()
|
||||
local data = {
|
||||
texture = texture,
|
||||
AlphaType = net.ReadUInt( 3 ),
|
||||
NoiseOffsetX = readDecimal(),
|
||||
NoiseOffsetY = readDecimal(),
|
||||
NoiseROffset = readDecimal(),
|
||||
NoiseScaleX = readDecimal(),
|
||||
NoiseScaleY = readDecimal(),
|
||||
NoiseSetting = net.ReadString(),
|
||||
OffsetX = readDecimal(),
|
||||
OffsetY = readDecimal(),
|
||||
ROffset = readDecimal(),
|
||||
ScaleX = readDecimal(),
|
||||
ScaleY = readDecimal(),
|
||||
StepOverride = net.ReadString(),
|
||||
UseBump = net.ReadBool() and 1 or 0,
|
||||
UseNoise = net.ReadBool() and 1 or 0,
|
||||
}
|
||||
|
||||
advMat_Table:Set( ent, texture, data )
|
||||
end )
|
||||
|
||||
net.Receive( "AdvMatDematerialize", function()
|
||||
@ -244,6 +267,11 @@ if CLIENT then
|
||||
timer.Create( "AdvMatSyncTimer", 0.05, 1, sendRequestQueue )
|
||||
end )
|
||||
else
|
||||
local function writeDecimal( num )
|
||||
local mult = math.floor( math.Round( num * divisor ) )
|
||||
net.WriteInt( mult, bitSize )
|
||||
end
|
||||
|
||||
function advMat_Table:Sync( ent, ply )
|
||||
local data = ent.MaterialData
|
||||
|
||||
@ -251,7 +279,21 @@ else
|
||||
net.Start( "AdvMatMaterialize" )
|
||||
net.WriteEntity( ent )
|
||||
net.WriteString( data.texture )
|
||||
net.WriteTable( data )
|
||||
net.WriteUInt( data.AlphaType, 3 )
|
||||
writeDecimal( data.NoiseOffsetX )
|
||||
writeDecimal( data.NoiseOffsetY )
|
||||
writeDecimal( data.NoiseROffset )
|
||||
writeDecimal( data.NoiseScaleX )
|
||||
writeDecimal( data.NoiseScaleY )
|
||||
net.WriteString( data.NoiseSetting )
|
||||
writeDecimal( data.OffsetX )
|
||||
writeDecimal( data.OffsetY )
|
||||
writeDecimal( data.ROffset )
|
||||
writeDecimal( data.ScaleX )
|
||||
writeDecimal( data.ScaleY )
|
||||
net.WriteString( data.StepOverride )
|
||||
net.WriteBool( data.UseBump > 0 )
|
||||
net.WriteBool( data.UseNoise > 0 )
|
||||
net.Send( ply )
|
||||
else
|
||||
net.Start( "AdvMatDematerialize" )
|
||||
|
Loading…
Reference in New Issue
Block a user