[QUOTE=bobbleheadbob;50144355]here.
[lua]for i=1, 7 do
net.WriteBit((id%2) == 1)
id = math.floor(id/2)
end
for i=0, 6 do
id = id + net.ReadBit()*(2^i)
end[/lua][/QUOTE]
Why Read/WriteBit and not Read/WriteUInt?
Edit: Oh, I'm guessing it's because with WriteUInt you'd have to use 8 bits instead of 7. I wonder where this could possibly make a difference.... Australian internet, perhaps?
[QUOTE=bobbleheadbob;50144355]here.
[lua]
function net.WritePlayer(ply)
assert(ply:IsPlayer(), "Invalid argument #1 to WritePlayer (Player expected, got "..type(ply)..".)")
local id = ply:EntIndex()-1
for i=1, 7 do
net.WriteBit((id%2) == 1)
id = math.floor(id/2)
end
end
function net.ReadPlayer()
local id = 0
for i=0, 6 do
id = id + net.ReadBit()*(2^i)
end
return Entity(id+1)
end
[/lua]
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/netPlayer.lua[/url][/QUOTE]
It's way more efficient to shift the bits left and right than to math.floor(x/2) and 2^x
[QUOTE=FPtje;50144403]It's way more efficient to shift the bits left and right than to math.floor(x/2) and 2^x[/QUOTE]
Updated, thanks.
[QUOTE=Neat-Nit;50144375]Why Read/WriteBit and not Read/WriteUInt?
Edit: Oh, I'm guessing it's because with WriteUInt you'd have to use 8 bits instead of 7. I wonder where this could possibly make a difference.... Australian internet, perhaps?[/QUOTE]
You can only have 128 players so you'd only need 7 for net.WriteUInt. 8 for net.WriteInt, but ent indexes never go into the negatives so its pointless.
[QUOTE=bobbleheadbob;50144355]here.
CODE
[url]https://dl.dropboxusercontent.com/u/104427432/Scripts/netPlayer.lua[/url][/QUOTE]
Why use 7 individual bits when you can just use a single net.WriteUInt using 7 as the number of bits
[QUOTE=bigdogmat;50144997]Max players is 128, you'd only need 7 for net.WriteUInt.[/QUOTE]
Yeah, but according to the wiki page, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteUInt]net.WriteUInt[/url]: [quote]Acceptable values range from 1 to 32. 1 = bit, 4 = nibble, 8 = byte, 16 = short, 32 = long.[/quote]
Hmm, it seems I read it too hastily last time, I got the wrong impression that you have to pick one of those 4. Edit: one of those [i][b]5[/b][/i]
[QUOTE=bigdogmat;50144997]You can only have 128 players so you'd only need 7 for net.WriteUInt. 8 for net.WriteInt, but ent indexes never go into the negatives so its pointless.[/QUOTE]
Don't forget the 1 bit of garbage that the net system uses for integers.
[QUOTE=bobbleheadbob;50145033]Don't forget the 1 bit of garbage that the net system uses for integers.[/QUOTE]
It doesn't use any extra bits. For some reason whoever outlined the WriteInt page made it sound like it used an extra bit for gmod, when really it's just the sign bit. Confused me as well until I tested it.
EDIT: Also the fact that it links a page that has all the powers of 2 up to 64, and to get those values you'd need an extra bit when using signed integers.
[QUOTE=bigdogmat;50145048]It doesn't use any extra bits. For some reason whoever outlined the WriteInt page made it sound like it used that extra bit for gmod, when really it's just the sign bit. Confused me to until I tested it.[/QUOTE]
Updated. Thanks.
[QUOTE=Neat-Nit;50145015]Yeah, but according to the wiki page, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/net/WriteUInt]net.WriteUInt[/url]:
Hmm, it seems I read it too hastily last time, I got the wrong impression that you have to pick one of those 4. Edit: one of those [i][b]5[/b][/i][/QUOTE]
Sorry, I added that as a reference -- I'll make it more clear that all values 1-32 are accepted.
[QUOTE=bigdogmat;50145048]It doesn't use any extra bits. For some reason whoever outlined the WriteInt page made it sound like it used an extra bit for gmod, when really it's just the sign bit. Confused me as well until I tested it.
EDIT: Also the fact that it links a page that has all the powers of 2 up to 64, and to get those values you'd need an extra bit when using signed integers.[/QUOTE]
I can't think of a non-critical/bitching-sounding way to say this so you'll just have to trust me when I say that I really am trying to be friendly here: it's [i]a wiki[/i], if you can make the phrasing better or less confusing or less misleading, then by all means go for it. This wiki is for the benefit of everyone, and I'm sure that you all use it every day as the go-to reference for gmod lua. Small improvements go a long way.
Edit: on an off-topic side-note, typing on Wii U sucks. The browser is quite nice but man, they really bombed with the keyboard.
I know this might sound weird but if you really really care about the amount of bits you send why not just:
[CODE]local bits = math.ceil( math.log( game.MaxPlayers(), 2 ) )
function net.WritePlayer(ply)
assert(ply:IsPlayer(), "Invalid argument #1 to WritePlayer (Player expected, got "..type(ply)..".)")
net.WriteUInt(ply:EntIndex()-1,bits)
end
function net.ReadPlayer()
return Entity(net.ReadUInt(bits)+1)
end[/CODE]
?
[QUOTE=Neat-Nit;50145272]it's [i]a wiki[/i], if you can make the phrasing better or less confusing or less misleading, then by all means go for it.keyboard.[/QUOTE]
The thing is, the way its worded it makes it sound like there's an extra bit that Gmod uses. The issue is anyone who knows about how signed and unsigned integers work will get confused by this because they'll think they have to use an extra bit on top of the one for Gmod. It'd make just as much sense to someone who doesn't know about signed and unsigned integers just to say it's a signed bit. And that way it wouldn't confuse people who know about it, and it'd be a win for both sides.
[QUOTE=darkjacky;50145708]I know this might sound weird but if you really really care about the amount of bits you send why not just:
[CODE]local bits = math.ceil( math.log( game.MaxPlayers(), 2 ) )
function net.WritePlayer(ply)
assert(ply:IsPlayer(), "Invalid argument #1 to WritePlayer (Player expected, got "..type(ply)..".)")
net.WriteUInt(ply:EntIndex()-1,bits)
end
function net.ReadPlayer()
return Entity(net.ReadUInt(bits)+1)
end[/CODE]
?[/QUOTE]
I'll add that in, thanks.
[QUOTE=darkjacky;50145708]I know this might sound weird but if you really really care about the amount of bits you send why not just:
[CODE]local bits = math.ceil( math.log( game.MaxPlayers(), 2 ) )
function net.WritePlayer(ply)
assert(ply:IsPlayer(), "Invalid argument #1 to WritePlayer (Player expected, got "..type(ply)..".)")
net.WriteUInt(ply:EntIndex()-1,bits)
end
function net.ReadPlayer()
return Entity(net.ReadUInt(bits)+1)
end[/CODE]
?[/QUOTE]
[code]local max = game.MaxPlayers()
local bits = max == 1 and 1 or math.ceil( math.log( max, 2 ) )
[/code]
log1=0
Hold on, what about concurrency issues? Is it possible for join/disconnect messages to arrive on the client before a net message does? If it can, perhaps the chance of this happening isn't even that small, especially with big net messages.
Imagine one player leaves and another finishes joining right between the server sending a 64kb message and the client receiving it. Could the client be thinking that the newly joined player is the one referred to by the net message? Because if that's even remotely possible, then this optimisation can cause some pretty terrible and hard to find bugs that are really hard to reproduce.
[QUOTE=FPtje;50147121]Hold on, what about concurrency issues? Is it possible for join/disconnect messages to arrive on the client before a net message does? If it can, perhaps the chance of this happening isn't even that small, especially with big net messages.
Imagine one player leaves and another finishes joining right between the server sending a 64kb message and the client receiving it. Could the client be thinking that the newly joined player is the one referred to by the net message? Because if that's even remotely possible, then this optimisation can cause some pretty terrible and hard to find bugs that are really hard to reproduce.[/QUOTE]
Create Queue table, put here all values when broadcasting net message. When player connected, client side initialize hook was called, then client send request for this data. Server receive request, cut data to packets and send to client. Do you mean this?
[QUOTE=FPtje;50147121]Hold on, what about concurrency issues? Is it possible for join/disconnect messages to arrive on the client before a net message does? If it can, perhaps the chance of this happening isn't even that small, especially with big net messages.
Imagine one player leaves and another finishes joining right between the server sending a 64kb message and the client receiving it. Could the client be thinking that the newly joined player is the one referred to by the net message? Because if that's even remotely possible, then this optimisation can cause some pretty terrible and hard to find bugs that are really hard to reproduce.[/QUOTE]
This can already happen in theory with WriteEntity, can't it? There's pretty much nothing to be done about it.
[QUOTE=UnkN;50147302][url]https://github.com/garrynewman/garrysmod/pull/1106#issuecomment-210960873[/url] :nope:[/QUOTE]
I think it's good? Any improvement, no matter how small, is worth implementing.
[QUOTE=bobbleheadbob;50147424]I think it's good? Any improvement, no matter how small, is worth implementing.[/QUOTE]
But not exactly what offered Acecool. [URL=https://facepunch.com/member.php?u=661204]Darkjacky[/URL] present better code, that ready for implement.
[editline]17th April 2016[/editline]
net.WriteUInt with negative integers in second argument
[code]] lua_run util.AddNetworkString("test")
> util.AddNetworkString("test")...
] lua_run_cl net.Receive('test',function(len) print(len,net.WriteUInt(-32)) end)
] lua_run net.Start('test') net.WriteUInt(0,-32) print(net.BytesWritten()) net.Broadcast()
> net.Start('test') net.WriteUInt(0,-32) print(net.BytesWritten()) net.Broadcast()...
-1
Disconnect: Buffer overflow in net message.
Host_EndGame: Buffer overflow in net message
Dropped UnkN from server (Disconnect by user.)
[/code]
net.WriteUInt with 0 in second argument:
[code]] lua_run util.AddNetworkString("test")
> util.AddNetworkString("test")...
] lua_run_cl net.Receive('test',function(len) print(len) print(type(net.WriteUInt(0))) end)
] lua_run net.Start('test') net.WriteUInt(0,0) print(net.BytesWritten()) net.Broadcast()
> net.Start('test') net.WriteUInt(0,0) print(net.BytesWritten()) net.Broadcast()...
3
0
no value[/code]
net.WriteUInt second argument can be only positive integer.
The easiest thing to add/change causes the biggest discussions. Community aided/approved development ladies and gentleman. :v: The last time we had that it was about util.Base64Decode().
[QUOTE=UnkN;50147471][code]lua_run_cl net.Receive('test',function(len) print(len) print(type(net.WriteUInt(0))) end)[/code][/QUOTE]
You should try net.ReadUInt instead :)
anyway writing 0 bytes and reading 0 bytes will give back a result like this
[CODE]
net.Receive("test", function() print(net.ReadUInt(0)) end )
net.Start('test') net.WriteUInt(0,1) net.Broadcast()
result: 5051676
[/CODE]
The result seems to always be > 5000000. (Because Garry.)
Yes I did not keep in mind that math.log with 1 == 0. Fix is not hard though.
[CODE]local bits = math.ceil( math.log( game.MaxPlayers(), 2 ) )
bits = bits > 0 and bits or 1[/CODE]
Or even because inline compare takes no time at all.
[CODE]local bits = math.ceil( math.log( game.MaxPlayers(), 2 ) )
function net.WritePlayer(ply)
assert(ply:IsPlayer(), "Invalid argument #1 to WritePlayer (Player expected, got "..type(ply)..".)")
net.WriteUInt(ply:EntIndex()-1,bits > 0 and bits or 1)
end
function net.ReadPlayer()
return Entity(net.ReadUInt(bits > 0 and bits or 1)+1)
end[/CODE]
Edit::[CODE]local bits = math.Clamp( math.ceil( math.log( game.MaxPlayers(), 2 ) ), 1, 7 )[/CODE]
Should also be fine.
Or[CODE]local bits = math.ceil( math.max( math.log( game.MaxPlayers(), 2 ), 1 ) )[/CODE]
[QUOTE=darkjacky;50148655]
[CODE]local bits = math.ceil( math.log( game.MaxPlayers(), 2 ) )
bits = bits > 0 and bits or 1[/CODE]
Or even because inline compare takes no time at all.
[CODE]local bits = math.ceil( math.log( game.MaxPlayers(), 2 ) )
function net.WritePlayer(ply)
assert(ply:IsPlayer(), "Invalid argument #1 to WritePlayer (Player expected, got "..type(ply)..".)")
net.WriteUInt(ply:EntIndex()-1,bits > 0 and bits or 1)
end
function net.ReadPlayer()
return Entity(net.ReadUInt(bits > 0 and bits or 1)+1)
end[/CODE][/QUOTE]
[lua]local bits = math.ceil( math.log( game.MaxPlayers() + 1, 2 ) )[/lua]
[QUOTE=!cake;50148802][lua]local bits = math.ceil( math.log( game.MaxPlayers() + 1, 2 ) )[/lua][/QUOTE]
Erm, why? game.MaxPlayers() will return number from 1 to 128. If we add 1 to max players, then we got 129 that equivalently to 8(because math.ceil), that disadvantageous.
[QUOTE=UnkN;50148856]Erm, why? game.MaxPlayers() will return number from 1 to 128. If we add 1 to max players, then we got 129 that equivalently to 8(because math.ceil), that disadvantageous.[/QUOTE]
Oops I thought maxplayers was 1 to 127 because signed uint8. Disregard me.
[QUOTE=!cake;50149157]Oops I thought maxplayers was 1 to 127 because signed uint8. Disregard me.[/QUOTE]
The server reserves one slot for whatever reason -- there was an explanation in an earlier page.
lmfao
[IMG]http://i.imgur.com/PjYY0bK.png[/IMG]
I remember there was an update that did something with car wheels, like adding a hitbox or something like that. (It maked this possible: [url]https://scriptfodder.com/scripts/view/1614/tire-popping-mod[/url])
When shooting on some car wheels the game crahes. Could it be because of the update and is anybody else having this issue? This white police car of this pack ([url]https://steamcommunity.com/sharedfiles/filedetails/?id=258999371[/url]) has the problem for me.
I tested it on multiplayer only.
EDIT: The problem is not occuring on single player for me.
Can anybody confirm this?
Any particular reason as to why hitting a very high polygon prop_physics with any weapon results in the game locking up?
Edit:
[url=http://puu.sh/onW3O/87143c0558.zip]Dumpfile[/url]
[url=http://puu.sh/onW67/cf74cda94d.zip]Model file[/url]
[QUOTE=DarthTealc;50159852]I've coded a feature and it all works, it means I can see some gamemodes I might not have otherwise noticed. Do you think this would help improve the server list?
[t]https://i.imgur.com/rzybIWB.png[/t][/QUOTE]
If the objective was to show all the different DarkRP names, then yes.
Sorry, you need to Log In to post a reply to this thread.