Skip to content

Commit f03bf8f

Browse files
committed
New features and more performance
1 parent 7f92bd4 commit f03bf8f

File tree

2 files changed

+123
-30
lines changed

2 files changed

+123
-30
lines changed

.github/workflows/yue_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Download Yuescript and unzip yue
2727
run: |
28-
wget https://github.com/pigpigyyy/Yuescript/releases/download/v0.22.3/yue-linux-x86_64.zip
28+
wget https://github.com/pigpigyyy/Yuescript/releases/download/v0.23.6/yue-linux-x86_64.zip
2929
unzip yue-linux-x86_64.zip
3030
rm yue-linux-x86_64.zip
3131

lua/autorun/client/!dynamic-light-controller-entities.yue

Lines changed: 122 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
addonName = "Dynamic Light Controller - Entities"
2+
import IsValid, GetClass from FindMetaTable( "Entity" )
23
PRE_HOOK = PRE_HOOK or HOOK_MONITOR_HIGH
34
CreateClientConVar = CreateClientConVar
45
entities = list.GetForEdit( addonName )
5-
:GetClass = FindMetaTable( "Entity" )
66
import CreateClientside from ents
7+
import TraceLine from util
8+
import Simple from timer
79
import Add from hook
810

11+
traceResult = {}
12+
trace = { output: traceResult }
13+
914
blacklist = {}
1015

1116
do
@@ -33,7 +38,7 @@ do
3338
Add( "NotifyShouldTransmit", addonName, ( entity, shouldtransmit ) ->
3439
if shouldtransmit and dlight_controllers_entities\GetBool! and not entity.DLightController
3540
dlight = entity.__dlight
36-
if dlight and dlight\IsValid!
41+
if dlight and IsValid( dlight )
3742
return
3843

3944
className = GetClass( entity )
@@ -45,6 +50,9 @@ do
4550
return
4651

4752
dlight = CreateClientside( "dlight_controller" )
53+
unless dlight and IsValid( dlight )
54+
return
55+
4856
dlight\SetEnabled( true )
4957

5058
if func( entity, dlight ) == false
@@ -56,7 +64,7 @@ do
5664
return
5765

5866
dlight = entity.__dlight
59-
if dlight and dlight\IsValid!
67+
if dlight and IsValid( dlight )
6068
dlight\Remove!
6169

6270
PRE_HOOK )
@@ -66,7 +74,7 @@ do
6674
return
6775

6876
dlight = entity.__dlight
69-
if dlight and dlight\IsValid!
77+
if dlight and IsValid( dlight )
7078
return
7179

7280
className = GetClass( entity )
@@ -78,6 +86,9 @@ do
7886
return
7987

8088
dlight = CreateClientside( "dlight_controller" )
89+
unless dlight and IsValid( dlight )
90+
return
91+
8192
dlight\SetEnabled( true )
8293

8394
if func( entity, dlight ) == false
@@ -95,10 +106,14 @@ do
95106
return
96107

97108
dlight = entity.__dlight
98-
if dlight and dlight\IsValid!
109+
if dlight and IsValid( dlight )
99110
dlight\Remove!
100111

101-
unless dlight_controllers_entities\GetBool!
112+
bdlight = entity.__beam_dlight
113+
if bdlight and IsValid( dlight )
114+
bdlight\Remove!
115+
116+
unless dlight_controllers_entities\GetBool! and IsValid( entity )
102117
return
103118

104119
className = GetClass( entity )
@@ -110,6 +125,9 @@ do
110125
return
111126

112127
dlight = CreateClientside( "dlight_controller" )
128+
unless dlight and IsValid( dlight )
129+
return
130+
113131
dlight\SetEnabled( true )
114132

115133
if func( entity, dlight ) == false
@@ -125,20 +143,62 @@ do
125143
Add( "EntityRemoved", addonName, ( entity, fullUpdate ) ->
126144
dlight = entity.__dlight
127145
if dlight
128-
if dlight\IsValid!
146+
if IsValid( dlight )
129147
dlight\Remove!
130148

131149
entity.__dlight = nil
132150

133151
dlight = entity.m_eFireDLight
134152
if dlight
135-
if dlight\IsValid!
153+
if IsValid( dlight )
136154
dlight\Remove!
137155

138156
entity.m_eFireDLight = nil
139157

158+
if entity\IsPlayer!
159+
dlight = entity.__beam_dlight
160+
if dlight
161+
if IsValid( dlight )
162+
dlight\Remove!
163+
164+
entity.__beam_dlight = nil
165+
140166
PRE_HOOK )
141167

168+
do
169+
170+
physgun_maxrange = GetConVar( "physgun_maxrange" )
171+
172+
Add "DrawPhysgunBeam", addonName .. " - Physgun", ( ply, wep, enabled, entity, physBone, localPos ) ->
173+
bdlight = wep.__beam_dlight
174+
unless bdlight and IsValid( bdlight )
175+
return
176+
177+
bdlight\SetEnabled( enabled )
178+
179+
unless enabled
180+
return
181+
182+
bdlight\SetLightColor( ply\GetWeaponColor! )
183+
184+
unless IsValid( entity )
185+
trace.start = ply\GetShootPos!
186+
trace.endpos = trace.start + ply\GetAimVector! * physgun_maxrange\GetInt!
187+
trace.filter = ply
188+
TraceLine( trace )
189+
190+
bdlight\SetPos( traceResult.HitPos + traceResult.HitNormal )
191+
return
192+
193+
if physBone ~= 0
194+
matrix = entity\GetBoneMatrix( entity\TranslatePhysBoneToBone( physBone ) )
195+
if matrix
196+
bdlight\SetPos( LocalToWorld( localPos, angle_zero, matrix\GetTranslation!, matrix\GetAngles! ) )
197+
return
198+
199+
bdlight\SetPos( entity\LocalToWorld( localPos ) )
200+
return
201+
142202
do
143203

144204
dlight_controllers_env_fire = CreateClientConVar( "dlight_controllers_env_fire", "0", true, false, "Enables creation dynamic light emitters for env_fire.", 0, 1 )
@@ -156,7 +216,7 @@ do
156216
dlight\SetStyle( 5 )
157217

158218
dlight.LightThink = ->
159-
if entity\IsValid!
219+
if IsValid( entity )
160220
dlight\SetPos( entity\GetPos! )
161221

162222
return true
@@ -297,7 +357,7 @@ do
297357
dlight\SetLocalPos( entity\OBBCenter! )
298358

299359
dlight.LightThink = ->
300-
unless entity\IsValid!
360+
unless IsValid( entity )
301361
dlight\Remove!
302362
return
303363

@@ -308,11 +368,11 @@ do
308368

309369
entities[ "env_sprite" ] = ( entity, dlight ) ->
310370
parent = entity\GetParent!
311-
unless parent and parent\IsValid!
371+
unless parent and IsValid( parent )
312372
return false
313373

314374
old = parent.__dlight
315-
if old and old\IsValid!
375+
if old and IsValid( old )
316376
old\Remove!
317377

318378
parent.__dlight = dlight
@@ -372,23 +432,43 @@ do
372432
dlight_controllers_bullets_radius = CreateClientConVar( "dlight_controllers_bullets_radius", "64", true, false, "", 16, 4096 )
373433
dlight_controllers_bullets_color = CreateClientConVar( "dlight_controllers_bullets_color", "255 100 0", true, false, "" )
374434

375-
r, g, b = unpack( string.Split( dlight_controllers_bullets_color\GetString!, " " ) )
435+
r, g, b = unpack( string.Split( dlight_controllers_bullets_color\GetString!, " " ), nil )
376436
cvars.AddChangeCallback( dlight_controllers_bullets_color\GetName!, ( _, __, value ) ->
377-
r, g, b = unpack( string.Split( value, " " ) )
437+
r, g, b = unpack( string.Split( value, " " ), nil )
378438
addonName )
379439

380440
Add( "EntityFireBullets", addonName, ( data ) =>
381441
unless dlight_controllers_bullets\GetBool!
382442
return
383443

384-
unless r and g and b
385-
r, g, b = 255, 100, 0
444+
Simple 0, ->
445+
trace.start = data.Src
446+
trace.endpos = data.Src + data.Dir * data.Distance
447+
trace.filter = data.Entity
448+
TraceLine( trace )
449+
450+
dlight = CreateClientside( "dlight_controller" )
451+
unless dlight and IsValid( dlight )
452+
return
453+
454+
dlight\SetLifetime( dlight_controllers_bullets_lifetime\GetFloat! )
455+
dlight\SetPos( traceResult.HitPos + traceResult.HitNormal * 2 )
456+
dlight\SetLightColor( r or 255, g or 100, b or 0 )
457+
dlight\SetParent( traceResult.Entity )
458+
dlight\SetBrightness( 0.1 )
459+
dlight\SetEnabled( true )
460+
dlight\SetRadius( 16 )
461+
dlight\Spawn!
462+
return
386463

387464
dlight = CreateClientside( "dlight_controller" )
465+
unless dlight and IsValid( dlight )
466+
return
467+
388468
dlight\SetBrightness( dlight_controllers_bullets_brightness\GetFloat! )
389469
dlight\SetLifetime( dlight_controllers_bullets_lifetime\GetFloat! )
390470
dlight\SetRadius( dlight_controllers_bullets_radius\GetInt! )
391-
dlight\SetLightColor( r, g, b )
471+
dlight\SetLightColor( r or 255, g or 100, b or 0 )
392472
dlight\SetEnabled( true )
393473
dlight\SetPos( data.Src )
394474
dlight\SetParent( @ )
@@ -405,10 +485,13 @@ do
405485
for _, entity in Iterator!
406486
if entity\IsOnFire!
407487
dlight = entity.m_eFireDLight
408-
if dlight and dlight\IsValid!
488+
if dlight and IsValid( dlight )
409489
continue
410490

411491
dlight = CreateClientside( "dlight_controller" )
492+
unless dlight and IsValid( dlight )
493+
return
494+
412495
entity.m_eFireDLight = dlight
413496

414497
dlight\SetStyle( 5 )
@@ -423,7 +506,7 @@ do
423506

424507
dlight = entity.m_eFireDLight
425508
if dlight
426-
if dlight\IsValid!
509+
if IsValid( dlight )
427510
dlight\Remove!
428511

429512
dlight.m_eFireDLight = nil
@@ -446,6 +529,9 @@ do
446529
return
447530

448531
dlight = CreateClientside( "dlight_controller" )
532+
unless dlight and IsValid( dlight )
533+
return
534+
449535
dlight\SetBrightness( dlight_controllers_explosions_brightness\GetFloat! )
450536
dlight\SetLifetime( dlight_controllers_explosions_lifetime\GetFloat! )
451537
dlight\SetRadius( dlight_controllers_explosions_radius\GetInt! )
@@ -465,18 +551,25 @@ do
465551
attachmentID = 0
466552

467553
entities[ "weapon_physgun" ] = ( entity, dlight ) ->
554+
bdlight = CreateClientside( "dlight_controller" )
555+
entity.__beam_dlight = bdlight
556+
bdlight\SetBrightness( 0.01 )
557+
bdlight\SetRadius( 128 )
558+
bdlight\SetStyle( 5 )
559+
bdlight\Spawn!
560+
468561
dlight\SetLightColor( Vector( cvars.String( "cl_weaponcolor" ) ) )
469562
dlight\SetBrightness( 0.5 )
470563
dlight\SetRadius( 64 )
471564
dlight\SetStyle( 5 )
472565

473566
dlight.LightThink = ->
474-
unless entity\IsValid!
567+
unless IsValid( entity )
475568
dlight\Remove!
476569
return
477570

478571
owner = entity\GetOwner!
479-
unless owner and owner\IsValid! and owner\IsPlayer!
572+
unless owner and IsValid( owner ) and owner\IsPlayer!
480573
dlight\SetPos( entity\WorldSpaceCenter! )
481574
dlight\SetEnabled( true )
482575
return
@@ -500,12 +593,12 @@ do
500593
dlight\SetStyle( 5 )
501594

502595
dlight.LightThink = ->
503-
unless entity\IsValid!
596+
unless IsValid( entity )
504597
dlight\Remove!
505598
return
506599

507600
owner = entity\GetOwner!
508-
unless owner and owner\IsValid! and owner\IsPlayer!
601+
unless owner and IsValid( owner ) and owner\IsPlayer!
509602
dlight\SetPos( entity\WorldSpaceCenter! )
510603
dlight\SetEnabled( true )
511604
return
@@ -527,12 +620,12 @@ do
527620
dlight\SetRadius( 32 )
528621

529622
dlight.LightThink = ->
530-
unless entity\IsValid!
623+
unless IsValid( entity )
531624
dlight\Remove!
532625
return
533626

534627
owner = entity\GetOwner!
535-
unless owner and owner\IsValid! and owner\IsPlayer!
628+
unless owner and IsValid( owner ) and owner\IsPlayer!
536629
dlight\SetPos( entity\WorldSpaceCenter! )
537630
dlight\SetEnabled( true )
538631
return
@@ -571,12 +664,12 @@ do
571664
dlight\SetStyle( 5 )
572665

573666
dlight.LightThink = ->
574-
unless entity\IsValid!
667+
unless IsValid( entity )
575668
dlight\Remove!
576669
return
577670

578671
owner = entity\GetOwner!
579-
unless owner and owner\IsValid! and owner\IsPlayer!
672+
unless owner and IsValid( owner ) and owner\IsPlayer!
580673
dlight\SetPos( entity\WorldSpaceCenter! )
581674
dlight\SetEnabled( true )
582675
return
@@ -610,7 +703,7 @@ do
610703
dlight\SetLocalPos( offset1 )
611704

612705
dlight.LightThink = ->
613-
unless entity\IsValid!
706+
unless IsValid( entity )
614707
dlight\Remove!
615708
return
616709

@@ -627,7 +720,7 @@ do
627720
dlight\SetLocalPos( offset2 )
628721

629722
dlight.LightThink = ->
630-
unless entity\IsValid!
723+
unless IsValid( entity )
631724
dlight\Remove!
632725
return
633726

0 commit comments

Comments
 (0)