Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 14 15 16 17 18 Next »
Problems with an emitter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear Mode
Problems with an emitter
20-04-2015, 07:33 PM,
#7
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Problems with an emitter
You do realise, that you've essentially killed the optimisation that was there.

Go back to what I posted. The DTVar is set on change, propagated once and it's happy. With what you have, not only are you sending way more data than you need due to writeTable, but you're also sending redundant data every second.

What I posted already worked, and it way more optimal than using writeTable and the timer.

Networking Problems
To spell it out, this is what write table does in pseudo Lua code:
for Key, Value in pairs( Table ) do
net.writeUInt( TypeID( Key ), 8 )
net.write<KeyType>( Value )

net.writeUInt( TypeID( Value ), 8 )
net.write<ValueType>( Value )
end
net.writeUInt( 0, 8 )
Thus, the write table code you have is sending:
net.writeUInt( TYPE_STRING, 8 ) --8 bits
net.writeString( "Active" ) -- 7 * 8 bits, 8 bits per character and a null terminating character at the end

net.writeUInt( TYPE_NUMBER, 8 ) -- 8 bits
net.writeDouble( wire.ports.Active ) -- 64 bits for a number that's either 0 or 1!!!

net.writeUInt( TYPE_STRING, 8 ) -- 8 bits
net.writeString( "HP" ) -- 3 * 8 bits, 8 bits per character and a null terminating character at the end

net.writeUInt( TYPE_NUMBER, 8 ) -- 8 bits
net.writeDouble( wire.ports.HP ) -- 64 bits again, when it's a percentage value!

net.writeUInt( 0, 8 ) -- 8 bits to mark the end of the table
Total per send: 8 + ( 7 * 8 ) + 8 + 64 + 8 + ( 3 * 8 ) + 8 + 64 + 8 = 248 bits or 31 bytes per send every time.

Now compare that to using 2 DTVars:
net.setDTVar( "Int", 1, wire.ports.HP )
net.setDTVar( "Bool", 1, wire.ports.Active ~= 0 )
Total sent ONLY WHEN CHANGED: 32 + 1 = 33 bits = 4.125 bytes at the most if both values change.

Input change detection problems
You've also now added a completely redundant and overly complicated way of detecting input changes. The input hook was designed for this purpose.
hook( "input", "OnInputChange", function( Input, Value )
--This section runs when an input changes!!!
if Input == "Active" then
net.setDTVar( "Bool", 1, Value ~= 0 )
elseif Input == "HP" then
net.setDTVar( "Int", 1, Value )
end
end )
This accomplishes changing the DTVars (and note that the DTVars only network if the value you are providing is different to what's already stored, this is their entire purpose!) without a clunky timer or a table or checking against other values.

So, back to what I posted before with the added tweak to the active network value:
--@name Field Door HP
--@author TheNextDecade
--@sharedscreen

if SERVER then
wire.createInputs({"Active","HP"},{"normal","normal"})

--This runs when an input changes, which is what we want
hook("input","InputChange",function(Input,Value)
if Input == "Active" then
net.setDTVar("Bool", 1, Value ~= 0)
elseif Input == "HP" then
net.setDTVar("Int", 1, Value)
end
end)

--You were probably wondering why the initial values aren't set.
--The answer is, you have to set them initially, the input hook doesn't run on startup
net.setDTVar("Bool", 1, ( wire.ports.Active or 0 ) ~= 0)
net.setDTVar("Int", 1, wire.ports.HP or 0)
else
--There's no need for this function to be in the server environment, it's rendering which is client only.
function Drawer(posy,posx,col,hp)
render.setColor(col[1]-100,col[2]-100,col[3]-100,col[4])
render.drawFilledCircle(60,63,22,22)
render.setColor(col[1]-150,col[2]-150,col[3]-150,col[4])
render.drawCircle(60,63,22,22)
render.setColor(col[1],col[2],col[3],col[4])
local Perc = 40/100*hp
render.drawRect(55,43,10,Perc)
render.drawRectOutline(55,43,10,40)
end
--ents.self() is not a method, no need for a :
local Itself = ents.self()

hook("render","Render",function()
local On = net.getDTVar("Bool",1)
if not On then return end

render.start3D2D(Itself:pos(),Itself:ang(),1)
Drawer(60,63,{150,250,150,50},net.getDTVar("Int",1))
render.end3D2D()
end)
end
Nothing is more deterring than when someone you are trying to help completely ignores what you've posted and ends up with something far worse and a load of misconceptions about what the code is doing.

I hope that you will not ignore this post and understand why what you have now is much, much worse. If you have any questions about what I've written please ask rather than ending with a chip that steadily declines into unmaintainable.
Find
Reply
« Next Oldest | Next Newest »


Messages In This Thread
Problems with an emitter - by Destiny's Player - 18-04-2015, 10:19 PM
RE: Problems with an emitter - by Person8880 - 19-04-2015, 11:28 AM
RE: Problems with an emitter - by Destiny's Player - 19-04-2015, 01:20 PM
RE: Problems with an emitter - by Person8880 - 19-04-2015, 01:51 PM
RE: Problems with an emitter - by Destiny's Player - 19-04-2015, 09:05 PM
RE: Problems with an emitter - by TheOneAndOnlyTee - 20-04-2015, 01:10 AM
RE: Problems with an emitter - by Person8880 - 20-04-2015, 07:33 PM
RE: Problems with an emitter - by Destiny's Player - 20-04-2015, 08:36 PM
RE: Problems with an emitter - by TheOneAndOnlyTee - 21-04-2015, 02:42 PM
RE: Problems with an emitter - by Destiny's Player - 21-04-2015, 02:51 PM
RE: Problems with an emitter - by LocInt - 21-04-2015, 05:32 PM
RE: Problems with an emitter - by Person8880 - 21-04-2015, 05:52 PM
RE: Problems with an emitter - by Destiny's Player - 21-04-2015, 06:23 PM
RE: Problems with an emitter - by Person8880 - 21-04-2015, 08:06 PM
RE: Problems with an emitter - by Destiny's Player - 21-04-2015, 08:22 PM
RE: Problems with an emitter - by Iajret - 21-04-2015, 09:41 PM
RE: Problems with an emitter - by LocInt - 22-04-2015, 05:18 AM
RE: Problems with an emitter - by Person8880 - 22-04-2015, 05:41 PM

  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.