[vjass] Can this be improved?

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
I'm still trying to improve the struct found in this topic, but I'm not sure if the code is efficient.

JASS:
library Effects requires HandleVars

    struct sfx
    
        timer   t = CreateTimer()
        string  m
        real    x
        real    y
        real    d
        
        method onDestroy takes nothing returns nothing
            set .t = null
            set .m = null
            set .x = 0
            set .y = 0
            set .d = 0
        endmethod
        
        static method CallBack takes nothing returns nothing
          local sfx a = GetHandleInteger( GetExpiredTimer(), "i" )
            call DestroyEffect( AddSpecialEffect( a.m, GetRandomReal( a.x - a.d, a.x + a.d ), GetRandomReal( a.y - a.d, a.y + a.d ) ) )
        endmethod
        
        method Stop takes nothing returns nothing
            call PauseTimer( .t )
            call DestroyTimer( .t )
            call FlushHandleInteger( .t, "i" )
        endmethod
        
        method Pause takes nothing returns nothing
            call PauseTimer( .t )
        endmethod
        
        method Start takes real timeout, string m, real x, real y, real d returns nothing
          local sfx   a = sfx.create()
            
            set a.m = m
            set a.x = x
            set a.y = y
            set a.d = d
            
            call SetHandleInteger( .t, "i", a )
            call TimerStart( .t, timeout, true, function sfx.CallBack )
        endmethod
        
    endstruct

endlibrary


JASS:
scope test initializer init

    function Actions takes nothing returns nothing
        local sfx a = sfx.create()
        local sfx b = sfx.create()
        
        call FogModifierStart( CreateFogModifierRect( Player( 0 ), FOG_OF_WAR_VISIBLE, GetWorldBounds(), true, true ) )
        
        call a.Start( 0.2, "Abilities\\Spells\\Human\\SpellSteal\\SpellStealMissile.mdl", -650, -900, 300 )
        call b.Start( 1, "Abilities\\Weapons\\Bolt\\BoltImpact.mdl", 650, 350, 500 )
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction( t, function Actions )
        call TriggerExecute( t )
        
        set t = null
    endfunction

endscope


The thing is, I know jass very well and looking at this code it looks very efficient to me.
But I do not know the limitations or boundary's of vjass.
I've heard from a friend that i should use something called a timerObject library, but would it be more efficient?
 

Romek

Super Moderator
Reaction score
964
Can't you put the entire thing into 1 library?

JASS:
        method onDestroy takes nothing returns nothing
            set .t = null
            set .m = null
            set .x = 0
            set .y = 0
            set .d = 0
        endmethod


Globals don't need to be nulled.
And reals/integers don't need to be nulled, even when local.

JASS:
private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction( t, function Actions )
        call TriggerExecute( t )
        
        set t = null
    endfunction


Can't you just do:
JASS:
private function init takes nothing returns nothing
        call Actions()
    endfunction
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
Can't you put the entire thing into 1 library?
Globals don't need to be nulled.
And reals/integers don't need to be nulled, even when local.

Now I do understand that nothing has to be nulled, since it doesn't leak because you will always have the reference to access it again.
I do it for another reason, since I personally want to use as little memory as possible.

This struct may be called perhaps 50 times in my map, so.. it doesn't actually recycle the globals.
So the entire game, the globals will have there values and therefor useless memory is consumed.

Correct me if I'm wrong though.

>Can't you just do:

Yes I can, but that was just a testing trigger.
Don't worry about that :rolleyes:
 

Flare

Stops copies me!
Reaction score
662
This struct may be called perhaps 50 times in my map, so.. it doesn't actually recycle the globals.
So the entire game, the globals will have there values and therefor useless memory is consumed.

Structs do recycle their indexes (when destroyed)
JASS:
local MyStruct a = MyStruct.create ()
call BJDebugMsg (I2S (a))
call a.destroy ()
set a = MyStruct.create ()
call BJDebugMsg (I2S (a))
call a.destroy ()

That should display 1 twice (assuming no previous instances of MyStruct still exist)

And you don't really need to have the timer has a struct member (which have an array of timers that may never be used when you can just create them as you need them) - you can pass a timer argument to your Stop method, and do
JASS:
call PauseTimer (whichTimer)
call DestroyTimer (whichTimer) //Although timer recycling would be preferable to creating/destroying, look for Vexorian's TimerUtils over at WC3Campaigns
call FlushHandleInteger (whichTimer, "i")
 

Xorifelse

I'd love to elaborate about discussions...........
Reaction score
87
JASS:

local MyStruct a = MyStruct.create ()
call BJDebugMsg (I2S (a))
call a.destroy ()
set a = MyStruct.create ()
call BJDebugMsg (I2S (a))
call a.destroy ()

But for example, if I do..

JASS:
local structure a = structure.create()
local structure b = structure.create()
local structure c = structure.create()

call b.destroy()
set b = structure.create()

 // Some code..

call c.destroy()
call a.destroy()


Wouldn't that disrupt the values containing of c?
 

Flare

Stops copies me!
Reaction score
662
No.

Let's say we start at 1 i.e.
a=1
b=2
c=3

123

b is destroyed
1#3

b is created again
123

c is destroyed
12#

a is destroyed
#2#

If you destroyed all 3, then recreated them in a different order, stuff might get mixed up, but you are setting the members to a definite value with your create method so it won't really matter what value it was before, since it's probably gonna be different in the .create (...) call

New structs use the first available index, as far as I know (I don't really know how the allocate method works, hopefully Vexorian will elaborate)

Just add a BJDebugMsg ("<Struct variable> is equal to " + I2S (structVar)) and see what is displayed

(NOTE: For all I know, I could be completely wrong :D)
 

emjlr3

Change can be a good thing
Reaction score
395
as soon as a saw "requiers handle vars" i stopped reading, that should be your first improvement
 

Romek

Super Moderator
Reaction score
964
as soon as a saw "requiers handle vars" i stopped reading, that should be your first improvement
They're not THAT bad are they?
They're just slightly slower than other systems, although in return, they have no limit.
 

Forty

New Member
Reaction score
6
why does everybody dislike handle vars? i mean.... dota uses gamecache, and does dota have any problems with lagg or performance?
 

Forty

New Member
Reaction score
6
did you ever have problems with it. or in dota? and where exactly does HV use I2H(i)?
 

Flare

Stops copies me!
Reaction score
662
did you ever have problems with it. or in dota? and where exactly does HV use I2H(i)?

1) I've never used LHV before, and have no intention of ever doing so
2) DotA isn't really a very good example to go by as regards exceptional coding - from alot of what I've seen over at DotA forum, there are a number of leaks, and it's still using I2H-based stuff even when vJASS is available
3)
JASS:
function GetHandleHandle takes handle subject, string name returns handle
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

That's one
JASS:
function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTimer takes handle subject, string name returns timer
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleTrigger takes handle subject, string name returns trigger
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleEffect takes handle subject, string name returns effect
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleGroup takes handle subject, string name returns group
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleLightning takes handle subject, string name returns lightning
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
function GetHandleWidget takes handle subject, string name returns widget
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

and a few more, just for good measure

There's a thread over at WC3C about how/why it's bad, if only I could find it...

EDIT: Here it is
 
Reaction score
333
did you ever have problems with it. or in dota?

It is enough that it is known to be buggy. There are circumstances under which I2H functions are probably safe, but why risk it? Although you are not using any of the unsafe functions in your code, HandleVars is still outdated and also inferior to the alternatives. Go with something like CSData instead.

and where exactly does HV use I2H(i)?

Here, for example:

JASS:
function GetHandleUnit takes handle subject, string name returns unit
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction
 

Flare

Stops copies me!
Reaction score
662
H2I is not equal to I2H?

There's only 1 kind of integer, so H2I won't return a real (for example) when called

But, there's many different kinds of handles (and all have different ID's) so what's stopping you from retrieving a timer instead of a unit? Both are handles, both have handle ID's, they are both valid returns. Then, what happens if you use the timer for a unit function e.g. KillUnit - how can you kill a timer with KillUnit? And that's where I2H falls down - there's no guarantee that you're going to retrieve the specific type (even if you be more specific and do "returns unit" or something)

so where is your I2H? i dont get it
JASS:
//The function is designed to return a unit
function GetHandleUnit takes handle subject, string name returns unit
//But wait, what&#039;s this!? We are returning an integer, even though we are supposed to return a unit!
//And from here, you just hope that you have got the right type...
return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
return null
endfunction
 

Forty

New Member
Reaction score
6
okay then just use GetHandleInteger which will not cause any problems and will use structs. and again, i dont see a problem

i mean, if you are not an idiot, your map will not crash.
 

Flare

Stops copies me!
Reaction score
662
okay then just use GetHandleInteger which will not cause any problems and will use structs
Well, if you were going to use a cache-based system, you'd be better off with CSSafeCache (since it removes all access to Get/SetHandleHandle-esque functions, to get rid of any temptations, and it's vJASS so you don't have to do anything other than CnP the code)

if you are not an idiot
We may not be idiots, but there are always people who will chance their arm, just for the hell of it...
 

emjlr3

Change can be a good thing
Reaction score
395
1. its slower then anything else
2. it can lead to massive bugs
3. there are much better options available - which don't bug and which are much faster and easier to use

do you really need any more reasons to to use it?
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top