I need an FPS friendly way to show no more than 60 entities are selected for an RTS I am making. The best solution I have found so far is using color, but it can be very hard to notice in dark areas. Halo is the second best option, but it can drop my FPS by 30 with just 5 entities glowing. The last thing I tried was CAM.Start3d2d which, as expected, was terrible. Are there any other options I should try before giving color the win? Thanks for your input.
If it's top-down, why not draw circle/stencil at the feet? You can achieve decent / good looking results with next to no fps loss. If that won't work, you can use sprites, which I know for a fact won't cause much of a loss...
[QUOTE=Acecool;44487400]If it's top-down, why not draw circle/stencil at the feet? You can achieve decent / good looking results with next to no fps loss. If that won't work, you can use sprites, which I know for a fact won't cause much of a loss...[/QUOTE]
Unfortunately it is not top down. I used CAM.Start3d2d to position the circle renders at the entities feet. I had pretty severe FPS drops utilizing even a small amount of circles. I also tried them without using a camera, and the FPS drops were still bad. I haven't tried stencil or sprites yet, but I will definitely give them both a try. Thanks.
Show the code; I have a sneaking suspicion that you may be re-creating data within the cam function, or the loop, which only needs to be defined once.
Example:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/display_something_on_initial_spawn.lua.html[/url]
Notice how in the config, the Material is on the outside of the HUDPaint? Stuff like that, and fonts need to be outside of any of those "every-frame" hooks. For the lua file, remove .html from the file.
[QUOTE=Acecool;44487949]Show the code; I have a sneaking suspicion that you may be re-creating data within the cam function, or the loop, which only needs to be defined once.
Example:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/display_something_on_initial_spawn.lua.html[/url]
Notice how in the config, the Material is on the outside of the HUDPaint? Stuff like that, and fonts need to be outside of any of those "every-frame" hooks. For the lua file, remove .html from the file.[/QUOTE]
This is what it would look like without any Z positioning:
[lua]
hook.Add( "PostDrawOpaqueRenderables", "AddCirc", function()
for _, ent in pairs( SelectedUnits ) do
surface.DrawCircle( ent:GetPos().x, ent:GetPos().y, 10, Color( 255, 0, 0 ) )
end
end)
[/lua]
Thanks again for the help.
DrawCircle I think does dots, right?
Try a poly circle: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/poly/simplified_circles_with_poly.lua.html[/url]
If you want to texturize: [url]http://steamcommunity.com/id/Acecool/screenshots/?appid=4000[/url]
[video=youtube;CZVN4rnnIec]http://www.youtube.com/watch?v=CZVN4rnnIec[/video]
This is one of the calculations I did for v for texturizing: v = ( ( i * _angle / _points ) * _textureScale )
[QUOTE=Acecool;44488743]DrawCircle I think does dots, right?
Try a poly circle: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/poly/simplified_circles_with_poly.lua.html[/url]
If you want to texturize: [url]http://steamcommunity.com/id/Acecool/screenshots/?appid=4000[/url]
[video=youtube;CZVN4rnnIec]http://www.youtube.com/watch?v=CZVN4rnnIec[/video]
This is one of the calculations I did for v for texturizing: v = ( ( i * _angle / _points ) * _textureScale )[/QUOTE]
Correct; it draws dots. Your solution works perfectly with zero FPS drops, however, it only works if gui.EnableScreenClicker is false. Is there any way to make it function while it is true? Thanks.
Interesting; I have noticed that sometimes the circle disappears but I never knew when. Can you post example code because I just tried showing the mouse on screen and it stayed put...
[editline]8th April 2014[/editline]
[QUOTE=Acecool;44489133]Interesting; I have noticed that sometimes the circle disappears but I never knew when. Can you post example code because I just tried showing the mouse on screen and it stayed put...[/QUOTE]
I just tried this; even with the clicker coming on, and disabling it still works fine. Which hook are you using?
[lua]
local _clicker = false;
local function DrawSpeedo( _x, _y, _r, _speed )
if ( !__CLICKER_TIMER || CurTime( ) - __CLICKER_TIMER > 2 ) then
_clicker = !_clicker;
gui.EnableScreenClicker( _clicker );
__CLICKER_TIMER = CurTime( );
end
local _speedo = poly:MakeCircle( _x, _y, _r, 64 );
// Speedo
surface.SetDrawColor( COLOR_BLACK );
surface.DrawPoly( _speedo );
end
hook.Add("HUDPaint", "HUDVehicleSpeedo", function( )
local _p = LocalPlayer( );
local _v = _p:GetVehicle( );
if ( !IsValid( _v ) ) then return; end
local _r = 115;
local _buffer = 15;
DrawSpeedo( ScrW( ) - _r - _buffer, ScrH( ) - _r - _buffer, _r );
end );
[/lua]
[lua]
-- Josh 'Acecool' Moser's poly circle function.
-- [url]http://facepunch.com/showthread.php?t=1348923&p=44207075&viewfull=1#post44207075[/url]
function MakeCirclePoly( _x, _y, _r, _points )
// U is how many times the texture should repeat along the X
local _u = ( _x + _r * 1 ) - _x;
// V is how many times the texture should repeat along the Y
local _v = ( _y + _r * 1 ) - _y;
local _slices = ( 2 * math.pi ) / _points;
local _poly = { };
for i = 0, _points - 1 do
local _angle = ( _slices * i ) % _points;
local x = _x + _r * math.cos( _angle );
local y = _y + _r * math.sin( _angle );
table.insert( _poly, { x = x, y = y, u = _u, v = _v } )
end
return _poly;
end
hook.Add( "PostDrawOpaqueRenderables", "AddCirc", function()
for _, ent in pairs( SelectedUnits ) do
local _poly = MakeCirclePoly( ent:GetPos().x, ent:GetPos().y, 10, 25 );
surface.SetDrawColor( COLOR_RED );
surface.DrawPoly( _poly );
end
end)
[/lua]
I have a simple dframe with a "yes" or "no" button to enable or disable the screen clicker.
I'm having 0 luck displaying it with PostDrawOpaqueRenderables, however with HUDPaint; I'm having no issue at all.
You should be able to do Vector( ):ToScreen( ) and do it in HUDPaint. I'll try to dig up some old code which drew stuff in HUDPaint inside a camera function
I thought it was the screen clicker, but it actually displays when shift, IN_SPEED, is active. As you mentioned, I noticed it disappear a few times while utilizing HUDPaint. Oddly I could never get it to disappear with PostDraw.
I am rendering it in the world right now, and it appears as though the texture location is moving when I move the mouse. Try setting the v to something static.
These:
// U is how many times the texture should repeat along the X
local _u = ( _x + _r * 1 ) - _x;
// V is how many times the texture should repeat along the Y
local _v = ( _y + _r * 1 ) - _y;
[editline]8th April 2014[/editline]
Now I'm seeing that when the mouse is visible, if it's rendered in the world, how the texture disappears. Hmmmm. I have no idea.. I'll keep digging a bit.
[editline]8th April 2014[/editline]
Actually, did we set any material?
[editline]8th April 2014[/editline]
Ok, use surface.SetMaterial( )
local Laser = Material( "effects/flashlight001" )
surface.SetMaterial( Laser )
Actually worked... Now it stays solid...
[editline]8th April 2014[/editline]
Updated: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/poly/simplified_circles_with_poly.lua.html[/url]
The reason it was happening was because we weren't setting the texture while poly expects a texture with the u / v variables. So, the flickering was caused by surface.SetMaterial( ) / Texture being called somewhere and it using that one. So by setting the texture/material to render with with the correct library, surface, it stops the flickering.
Setting them to static changes nothing. I can remove them entirely and nothing changes.
I just set it to the effects/flashlight001 surface.SetMaterial, also played around with the texture thing, or left it as is.. It worked fine after that.
Did you set a material before draw?
Sorry, you need to Log In to post a reply to this thread.