Need improvement of my projectile script

GoGo-Boy

You can change this now in User CP
Reaction score
40
Here's my script for a trigger based projectile system. However I hope that you guys may find s.th. to improve the performance.
For example I dunno how to do that in a whole struct without any non-struct function. Or maybe another system than KT?
JASS:
scope Projectiles
globals
    private constant real FREQUENZY=0.025
    private unit VIC
endglobals
private struct Projectile
    unit attacker
    unit proj
    effect model
    real damage
    real x
    real y
    real x_vel
    real y_vel
    real z
    real time=0
    real max_time
    boolean aoe
    real radius
    real height
    
endstruct
private function Callback takes nothing returns boolean
    local Projectile p=KT_GetData()
    set p.time=p.time+FREQUENZY
    set p.x=p.x+p.x_vel
    set p.y=p.y+p.y_vel
    call SetUnitX(p.proj,p.x)
    call SetUnitY(p.proj,p.y)
    call MoveLocation(LOC,p.x,p.y)
    call SetUnitFlyHeight(p.proj,p.height+p.z-GetLocationZ(LOC),0)
    call GroupEnumUnitsInRange(GROUP,p.x,p.y,p.radius,Filter(function HeroForce))
    set VIC=FirstOfGroup(GROUP)
    if not(VIC==null) then
        call Damage_Physical(p.attacker,VIC,p.damage,ATTACK_TYPE_NORMAL,true,true)
        call UnitApplyTimedLife(p.proj,TIMED_LIFE,2)
        call DestroyEffect(p.model)
        call p.destroy()
        return true
    endif
    if p.time<=p.max_time then
        return false
    endif
    call UnitApplyTimedLife(p.proj,TIMED_LIFE,2)
    call DestroyEffect(p.model)
    call p.destroy()
    return true
endfunction
function Attack takes unit attacker,unit target,real damage,boolean aoe,real radius,real speed,real distance,real scale, string effect_model,real height returns nothing
    local Projectile p=Projectile.create()
    local real x=GetUnitX(attacker)
    local real y=GetUnitY(attacker)
    local real targ_x=GetUnitX(target)
    local real targ_y=GetUnitY(target)
    local real face=Atan2(targ_y-y,targ_x-x)
    set p.attacker=attacker
    set p.x=x
    set p.y=y
    set p.max_time=distance/speed
    set p.x_vel=speed*FREQUENZY*Cos(face)
    set p.y_vel=speed*FREQUENZY*Sin(face)
    set p.aoe=aoe
    set p.radius=radius
    set p.damage=damage
    set p.height=height
    set p.proj=CreateUnit(Player(12),DUMMY2_ID,x,y,Rad2Deg(face))
    call MoveLocation(LOC,x,y)
    set p.z=GetLocationZ(LOC)
    call UnitAddAbility(p.proj,CROW_ABILITY)
    call SetUnitFlyHeight(p.proj,height,0)
    call SetUnitScale(p.proj,scale,scale,scale)
    set p.model=AddSpecialEffectTarget(effect_model,p.proj,"origin")
    call KT_Add(function Callback,p,FREQUENZY)
endfunction
endscope
 

Jesus4Lyf

Good Idea™
Reaction score
397
>For example I dunno how to do that in a whole struct without any non-struct function. Or maybe another system than KT?
Who cares about that?

[LJASS]if not(VIC==null) then[/LJASS]
==>
[LJASS]if VIC!=null then[/LJASS]

That's about all I see.

JASS:
call UnitApplyTimedLife(p.proj,TIMED_LIFE,2)

Why's that fire all the time?

You could port this to T32. That will give a slight speed bonus... I wouldn't be concerned about that sort of thing, though.

Edit: Actually, I think [LJASS]0.025[/LJASS] is too low, personally. Raising it will make it less processor intensive, but less FPS for the motion. Up to you... :)
 

Viikuna

No Marlo no game.
Reaction score
265
It depends on how fast your eye is. Usually human eye works with .03 speed, but some people can see even that fast iterations. ( Also your computer might affect that stuff too somehow, dont know )

.03 is good for most of people, but usually people prefer .025, because it works for everybody.

( Well, at least DotA does, but thats kinda obvious, because it has so big audience. )


And if you desing your stuff properly, there should not be any need to gain extra performance by changing to lower periods. It means that your map is already unplayable with older computers.
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
@ Jesus
I dunno why I fire UnitApplyTimeLife() all the time. It is only run the instance before the projectile is destroyed and the function returns true.
And I thought doing that in a struct only would look better ... no real performance increase^^
About the frequency with that the trigger is run. I'll stick to 0.025 which is 40fps for now. I take that for each of my smooth actions. For me it started to be smooth enough with 40fps while I was still able to realize some kind of laggy movement when I set it on about 30fps. And I really dislike watching things fly in a laggy way^^
Ah and this stuff:
if not(VIC==null) then
==>
if VIC!=null then
Just swapped to "not()" instead of "!=" because I read somewhere that it is better lulz. Well gonna stick to "!=" then.

@ Vikuna
My map isn't lagging like hell or so. But I got quite a lot systems running that have a lot executions. And the worse problem in fact is the terrain since the Wc3 engine doesn't seem to be made for diabloish terrain with steep cliffs and thus a far view for some locations.
Right now I need about 50 units firing an attack so the frames will drop by about 15. Nothing too serious but though I may ask for improvements about that I dunno^^



Thanks you two!
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top