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 The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top