20 projected textures with no shadows should be ok I suppose.
[QUOTE=garry;38194512]Optimised the internals of the userdata system[/QUOTE]
Can you explain this? I'm curious.
I've experimented a lot with userdata implementations and ended up using light userdata as a key and a table instead of full userdata.
pseduo code:
[lua]
function Push(pointer, meta)
REGISTRY[pointer] = REGISTRY[pointer] or setmetatable({__ptr = pointer}, meta)
end
function Get(pos)
local obj = STACK[pos]
return cast(obj.__ptr)
end
[/lua]
This means when you push entities to lua it won't create any new userdata if it has already been pushed once. It will just reuse.
When I'm done with the entity I just remove the table from the registry and set its metatable to a NULL one.
[QUOTE=CapsAdmin;38195744]Can you explain this? I'm curious.
I've experimented a lot with userdata implementations and ended up using light userdata as a key and a table instead of full userdata.
pseduo code:
[lua]
function Push(pointer, meta)
REGISTRY[pointer] = REGISTRY[pointer] or setmetatable({__ptr = pointer}, meta)
end
function Get(pos)
local obj = STACK[pos]
return cast(obj.__ptr)
end
[/lua]
This means when you push entities to lua it won't create any new userdata if it has already been pushed once. It will just reuse.
When I'm done with the entity I just remove the table from the registry and set its metatable to a NULL one.[/QUOTE]
Yeah the entity system already does that.
The issue I had was that when I was pushing userdata I was allocating and pushing a pointer.. so when it came to look up the type I was pushing the meta table and getting the typeid which was stored on it.
So instead of doing that stupid shit I store a generic struct as the userdata, which has the typeid and a data pointer.
This is a bit of a speed up because pretty much every call to an entity, or vector, or whatever, looks at the type.. so instead of pushing a table, looking up a member blah blah blah. It just converts the userdata and looks at the type id.
[QUOTE=twoski;38195424]flashlight[/QUOTE]
How'd you get it to maintain the player's angles? I tried using a projectedtexture in my gamemode but when I set the player to be the parent not only is it laggy, but it just faces Angle(0, 0, 0) for everyone not in first person.
ie. if I'm looking at another player's flashlight, it faces 0 0 0. If I'm looking at my own flashlight from 3rd person, it faces 0 0 0. If I'm looking at my own flashlight from 1st person, it's correct, if laggy.
A clientside alternative would be the shit.
[lua]
function meta:LuaFlashlight( on )
if on then
local c = Color( 255, 255, 200 )
local b = 4 // brightness
local size = 50
if self:GetLoadout( 3 ) == UTIL_LIGHT then
b = 6
size = 55
end
self.FlashlightEnt = ents.Create( "env_projectedtexture" )
self.FlashlightEnt:SetParent( self )
self.FlashlightEnt:SetLocalPos( Vector(0,0,64) )
self.FlashlightEnt:SetLocalAngles( Angle(0,0,0) )
self.FlashlightEnt:SetKeyValue( "enableshadows", 0 )
self.FlashlightEnt:SetKeyValue( "farz", 512 ) // distance of light
self.FlashlightEnt:SetKeyValue( "nearz", 12 ) //12
self.FlashlightEnt:SetKeyValue( "lightfov", size ) // size of light
self.FlashlightEnt:SetKeyValue( "lightcolor", Format( "%i %i %i 255", c.r * b, c.g * b, c.b * b ) )
self.FlashlightEnt:Spawn()
self.FlashlightEnt:Input( "SpotlightTexture", NULL, NULL, "effects/Flashlight001.vmt" )
self:EmitSound( "items/flashlight1.wav", 50, 110 )
else
if IsValid( self.FlashlightEnt ) then
self.FlashlightEnt:Remove()
self:EmitSound( "items/flashlight1.wav", 50, 90 )
end
end
end[/lua]
[QUOTE=garry;38195448]Was annoying me, so I added the ability to force texture filtering.
[img]http://puu.sh/1iZnd[/img]
[img]http://puu.sh/1iZny[/img]
[/QUOTE]
Wow, just wow. I literally jumped out of my chair when I saw this!
[QUOTE=twoski;38195424]Because i'm such a motherfucking boss i went and remade the default flashlight in Lua.
[t]http://i.imgur.com/gErGv.jpg[/t]
[t]http://i.imgur.com/TOb0V.jpg[/t]
[t]http://i.imgur.com/QDmSA.jpg[/t]
Pros:
- All done in Lua, using an env_projectedtexture.
- Customizable color, length, radius, flashlight texture, shadow settings.
Cons:
- It's all fucking serverside because ents.Create doesn't exist on the client anymore.
- IT'S ALL FUCKING SERVERSIDE. I dunno what the performance hit of 20 projected textures all being used at once would be but i'd hazard a guess that it will shit all over your FPS.
If possible it would be nice to be able to create these on the client. Why did ents.Create get removed from clientside anyhow?[/QUOTE]
Maybe instead of an fps expensive flashlight, just make the flashlight twitch and burn out when you get within a certain distance from the invisible dude. That would make things way more scary.
Or even when they flash the light on the invisible dude, then you could have it burn out so they get to see him for a second then he is gone and that player loses his light.
[QUOTE=Disseminate;38196225]How'd you get it to maintain the player's angles? I tried using a projectedtexture in my gamemode but when I set the player to be the parent not only is it laggy, but it just faces Angle(0, 0, 0) for everyone not in first person.
ie. if I'm looking at another player's flashlight, it faces 0 0 0. If I'm looking at my own flashlight from 3rd person, it faces 0 0 0. If I'm looking at my own flashlight from 1st person, it's correct, if laggy.
A clientside alternative would be the shit.[/QUOTE]
How about you're using the players [I]EyeAngles()[/I] to determine the correct angle for the env_projectedtexture-entity?
[QUOTE=find me;38196633]Maybe instead of an fps expensive flashlight, just make the flashlight twitch and burn out when you get within a certain distance from the invisible dude. That would make things way more scary.
Or even when they flash the light on the invisible dude, then you could have it burn out so they get to see him for a second then he is gone and that player loses his light.[/QUOTE]
Currently your flashlight runs on battery power, so you can't keep it on forever. The problem is, with 20+ players there will be times where every player has their flashlight on. In this case, it would be smarter to just have clientside flashlights.
But i am at the mercy of what garry decides to do with gmod lua so if he decides to allow certain ents to be spawnable clientside then i'm making this code clientside.
gb-radial converted to gmod 13:
[url]https://dl.dropbox.com/u/15312597/lua/gmod/gb-radial%20gmod%2013.zip[/url]
I take no credit for this mod. I only updated it to gmod 13.
[QUOTE=twoski;38196396][lua]
function meta:LuaFlashlight( on )
if on then
local c = Color( 255, 255, 200 )
local b = 4 // brightness
local size = 50
if self:GetLoadout( 3 ) == UTIL_LIGHT then
b = 6
size = 55
end
self.FlashlightEnt = ents.Create( "env_projectedtexture" )
self.FlashlightEnt:SetParent( self )
self.FlashlightEnt:SetLocalPos( Vector(0,0,64) )
self.FlashlightEnt:SetLocalAngles( Angle(0,0,0) )
self.FlashlightEnt:SetKeyValue( "enableshadows", 0 )
self.FlashlightEnt:SetKeyValue( "farz", 512 ) // distance of light
self.FlashlightEnt:SetKeyValue( "nearz", 12 ) //12
self.FlashlightEnt:SetKeyValue( "lightfov", size ) // size of light
self.FlashlightEnt:SetKeyValue( "lightcolor", Format( "%i %i %i 255", c.r * b, c.g * b, c.b * b ) )
self.FlashlightEnt:Spawn()
self.FlashlightEnt:Input( "SpotlightTexture", NULL, NULL, "effects/Flashlight001.vmt" )
self:EmitSound( "items/flashlight1.wav", 50, 110 )
else
if IsValid( self.FlashlightEnt ) then
self.FlashlightEnt:Remove()
self:EmitSound( "items/flashlight1.wav", 50, 90 )
end
end
end[/lua][/QUOTE]
Change your avatar and i'll buy you a new title.
I made a simple library for editing the new skypaint entity, and some spawnmenu options. [url=http://steamcommunity.com/sharedfiles/filedetails/?id=104858249]It's up on workshop now.[/url]
[thumb]http://i.imgur.com/WynpU.jpg[/thumb]
You can grab the code [URL="https://github.com/samuelmaddock/skypaint"]here[/URL], go make some cool stuff. I expect to see some audio visualizers in a few days. I left in a [I]FadeTo[/I] function which could be abused for cool purposes too. :smile:
env_projectiletexture is that expensive?
twoski, you can create a clientsidemodel instead
run something on the client to move each player's flashlight clientsidemodel entity infront of their respected players, and use this entity as a basis for the flashlight
[QUOTE=Remscar;38201820]Change your avatar and i'll buy you a new title.[/QUOTE]
compromises must be made i suppose
[QUOTE=Bletotum;38203330]twoski, you can create a clientsidemodel instead
run something on the client to move each player's flashlight clientsidemodel entity infront of their respected players, and use this entity as a basis for the flashlight[/QUOTE]
how exactly would a clientside prop emit light? they are basically the same as a prop_physics but without a physics mesh. I am asking for the ability to create entities other than physics props on the client.
[QUOTE=rebel1324;38202864]env_projectiletexture is that expensive?[/QUOTE]
Projected Texture, you mean. But yes, they seem to be... my framerate started dipping when i was messing around with several of them in sandbox (the lamp entity in sandbox uses them).
[QUOTE=samm5506;38202358]I made a simple library for editing the new skypaint entity, and some spawnmenu options. [url=http://steamcommunity.com/sharedfiles/filedetails/?id=104858249]It's up on workshop now.[/url]
[thumb]http://i.imgur.com/WynpU.jpg[/thumb]
[/QUOTE]
This should have been in vanilla gmod tbh.
oh, I see
I thought your issue was having a clientside entity other than using the players themselves
also I completely missed [url=http://www.facepunch.com/showthread.php?t=1215271&p=38196396&viewfull=1#post38196396]this[/url] post
Back on the rape swep...
[img]http://puu.sh/1jccT[/img]
[url]http://www.facepunch.com/showthread.php?t=1195105[/url]
She's happy so I'm happy
So since GLON was removed, and I don't like JSON, I created my own 'database system' that saves shit to .txt files, reads info from the files and organizes them into ready tables to use.
This is a major breakthrough for me, because I did this with no proper knowledge on how databases are coded and/or work. It's also slow as shit, but I don't give a fuck. :v:
It takes 35 seconds to process this:
[lua]stealth_p228=1:2,2:2,3:2,4:2,5:1
stealth_deagle=1:2,2:2,3:4,4:1,5:1
stealth_fiveseven=1:3,2:2,3:2,4:4,5:1
stealth_glock18=1:5,2:2,3:2,4:1
stealth_usp=1:2,2:1,5:1,4:3,3:2[/lua]
into this:
[lua]stealth_p228:
up:
1:
l = 2
n = 1
2:
l = 2
n = 2
3:
l = 2
n = 3
4:
l = 2
n = 4
5:
l = 1
n = 5
stealth_deagle:
up:
1:
l = 2
n = 1
2:
l = 2
n = 2
3:
l = 4
n = 3
4:
l = 1
n = 4
5:
l = 1
n = 5
stealth_fiveseven:
up:
1:
l = 3
n = 1
2:
l = 2
n = 2
3:
l = 2
n = 3
4:
l = 4
n = 4
5:
l = 1
n = 5
stealth_usp:
up:
1:
l = 2
n = 1
2:
l = 1
n = 2
3:
l = 1
n = 5
4:
l = 3
n = 4
5:
l = 2
n = 3
stealth_glock18:
up:
1:
l = 5
n = 1
2:
l = 2
n = 2
3:
l = 2
n = 3
4:
l = 1
n = 4
[/lua]
100000 times.
I did some benchmarks and apparently it takes 7 seconds to read the file 100000 times and 28 seconds to organize the table.
JSON's output is 562 symbols and mine is 173 symbols, but it only takes JSON 10 seconds to decode all that.
Edit: Welp, this was an interesting test, and I'll stick to JSON, because I realized that I can do the same with JSON, but much faster.
[QUOTE=LEETNOOB;38206259]blargh[/QUOTE]
Did you try any of the other glon replacements that people here on facepunch have made? Like von [url]http://www.facepunch.com/showthread.php?t=1194008[/url]
[QUOTE=Divran;38206554]Did you try any of the other glon replacements that people here on facepunch have made? Like von [url]http://www.facepunch.com/showthread.php?t=1194008[/url][/QUOTE]
Yeah, but I forgot what it was called. :X
Thanks for that though.
On another note, I think I'm gonna use this thing I made to encode on the server, send it to the client, and decode it there in order to network less stuff. (726 bytes vs 173)
I still use this. It's based on garry's keyvaluestotable and tabletokeyvalues:
[lua]
function Deserialize(sIn)
SRL = nil
RunString(sIn)
return SRL
end
local allowedtypes = {}
allowedtypes["string"] = true
allowedtypes["number"] = true
allowedtypes["table"] = true
allowedtypes["Vector"] = true
allowedtypes["Angle"] = true
allowedtypes["boolean"] = true
local function MakeTable(tab, done)
local str = ""
local done = done or {}
local sequential = table.IsSequential(tab)
for key, value in pairs(tab) do
local keytype = type(key)
local valuetype = type(value)
if allowedtypes[keytype] and allowedtypes[valuetype] then
if sequential then
key = ""
else
if keytype == "number" or keytype == "boolean" then
key ="["..tostring(key).."]="
else
key = "["..string.format("%q", tostring(key)).."]="
end
end
if valuetype == "table" and not done[value] then
done[value] = true
if type(value._serialize) == "function" then
str = str..key..value:_serialize()..","
else
str = str..key.."{"..MakeTable(value, done).."},"
end
else
if valuetype == "string" then
value = string.format("%q", value)
elseif valuetype == "Vector" then
value = "Vector("..value.x..","..value.y..","..value.z..")"
elseif valuetype == "Angle" then
value = "Angle("..value.pitch..","..value.yaw..","..value.roll..")"
else
value = tostring(value)
end
str = str .. key .. value .. ","
end
end
end
if string.sub(str, -1) == "," then
return string.sub(str, 1, #str - 1)
else
return str
end
end
function Serialize(tIn, bRaw)
if bRaw then
return "{"..MakeTable(tIn).."}"
end
return "SRL={"..MakeTable(tIn).."}"
end
[/lua]
I just tried making something to parse what you put up for shits and giggles. The file reading really kills me, took me around 23 seconds to read the file 100,000 times.
Without reading the file though, it only takes around 2 seconds to parse it 100,000 times.
[lua]local input = [[stealth_p228=1:2,2:2,3:2,4:2,5:1stealth_deagle=1:2,2:2,3:4,4:1,5:1
stealth_fiveseven=1:3,2:2,3:2,4:4,5:1
stealth_glock18=1:5,2:2,3:2,4:1
stealth_usp=1:2,2:1,5:1,4:3,3:2]]
local function parse( input )
local out = {}
for name, data in input:gmatch( "(.-)=([^\n]+)" ) do
out[ name ] = {
up = {}
}
local index = 1
for n, l in data:gmatch( "(.-):([^,]+),?" ) do
out[ name ][ "up" ][ index ] = {
l = l,
n = n
}
index = index + 1
end
end
return out
end
local starttime = SysTime()
for i=1, 100000 do
parse( input )
end
local endtime = SysTime()
print( "COMPLETED!", endtime - starttime )
print( "Output:" )
PrintTable( parse( input ) )[/lua]
[IMG]http://puu.sh/1jh2e[/IMG]
Not much of a json fan in lua. Sure it's useful to have when dealing with the internet but for internal uses it it feels like if you were to use a lua compilable data in javascript. Why not make "lson"?
There are many implementations of it out there and it's relatively easy to make.
The fact that JSON is already implemented in a lot of other languages and is still human-readable is the biggest advantage for me.
[QUOTE=_nonSENSE;38207112]The fact that JSON is already implemented in a lot of other languages and is still human-readable is the biggest advantage for me.[/QUOTE]
That's true. I'm talking more about data that doesn't leave glua. BUt when you do want it to leave lua it's dead easy to do (tojson(loadstring(data)()))
I'd rather use "lson" or json rather than keyvalues or anything else though.
Here's the functions for the texture filtering.
[url]http://garry.tv/post/34414478795/texture-filtering[/url]
[vid]https://dl.dropbox.com/u/4838268/gm_construct%202012-10-27%2014-01-27.webm[/vid]
It doesnt work too well at all though, my constraint solver sucks
After countless Makefile revisions and code digging and disbelief that this could even work, I managed this (on linux):
[code]
lua_run require'luasocket'
> require'luasocket'...
lua_run luasocket_stuff.luaopen_socket_core()
> luasocket_stuff.luaopen_socket_core()...
lua_run s=socket.tcp()
> s=socket.tcp()...
lua_run s:connect("91.152.xxx.xxx",12345)
> s:connect("91.152.xxx.xxx",12345)...
lua_run print(s:receive())
> print(s:receive())...
HELLO Garry :D nil nil
[/code]
Thanks for all the fishe...symbols, Garry!
[QUOTE=Python1320;38207554]After countless Makefile revisions and code digging and disbelief that this could even work, I managed this (on linux):
[code]
lua_run require'luasocket'
> require'luasocket'...
lua_run luasocket_stuff.luaopen_socket_core()
> luasocket_stuff.luaopen_socket_core()...
lua_run s=socket.tcp()
> s=socket.tcp()...
lua_run s:connect("91.152.xxx.xxx",12345)
> s:connect("91.152.xxx.xxx",12345)...
lua_run print(s:receive())
> print(s:receive())...
HELLO Garry :D nil nil
[/code]
Thanks for all the fishe...symbols, Garry![/QUOTE]
shh!!
Sorry, you need to Log In to post a reply to this thread.