System Smooth Unit Modification

Viikuna

No Marlo no game.
Reaction score
265
Well, the code I posted probably tells how to use readonly. Just use readonly keyword and make sure that you only try to set those values inside struct.

Also, I noticed you added out of bounds checks for those appearance members, which is good.

You should probably do it like this though:

JASS:
local real red2
set .red=.red+addred // we leave .red unaffected by bounds check
set red2=.red
if red2 < 0 then // red2 is .red, but with bounds checked,
   set red2=0    // so it can be used for vertex color change
else
   if red2>522 then
       set red2=522
   endif
endif
call SetUniVertexColor(.unit,red2,// etc..
endif


So you can for example incerease green and blue by 10000 without bugging. This can be useful for undoing all vertex color changes that make unit more red by decereasing those.

edit.Oh yea, it kinda ruins this hook thingy, damn.
 

Viikuna

No Marlo no game.
Reaction score
265
Well, whatever, do what seems best to you. It will be pretty cool anyways.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Just one question... Why 522 ? :S
JASS:
red2>522


Shouldn't it be 255 ? :eek:
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Yeah, I removed it :D
Thanks ;)

Btw, I'm making some test spell now, and I thought I'd make a "Shockwave-like" spell, but the projectile will (After some distance) start decreasing in size, and when it gets really small it'll implode and damage an area :D
Also, maybe shoot out small projectiles as it moves :S

What do you think ? :eek:

I also have this, which is OK imho :D

JASS:
scope Rage initializer Init

    globals
        private constant integer ABILITY_ID = 'A000'
        private constant integer SPELLBOOK_ID = 'A002'
        private constant integer DAMAGEBONUS_ID = 'A001'
    endglobals
    
    private struct Data
    
        integer lvl
        unit caster
        player owner
        
        static method create takes unit u, player p, integer lvl returns Data
            local thistype this = thistype.allocate()
            
            set this.caster = u
            set this.owner = p
            set this.lvl = lvl
            
            return this
        endmethod
        
        private method onDestroy takes nothing returns nothing
            call UnitRemoveAbility( this.caster, SPELLBOOK_ID )
            call SmoothScaleChange.create( this.caster, 1.0, -( this.lvl * 0.25 ) )
            call SmoothColorChange.create( this.caster, 1.0, 0.0, 255.0, 255.0, ( this.lvl * 42.5 ) )
            
            set this.caster = null
            set this.owner = null
        endmethod
        
    endstruct
    
    private function Rage_Ends takes nothing returns nothing
        local Data d = GetTimerData( GetExpiredTimer() )
        
        call d.destroy()
        call ReleaseTimer( GetExpiredTimer() )
    endfunction
    
    private function Spell_Check takes nothing returns boolean
        return GetSpellAbilityId() == ABILITY_ID
    endfunction

    private function Rage_Actions takes nothing returns nothing
        local timer t = NewTimer()
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer( u )
        local integer lvl = GetUnitAbilityLevel( u, ABILITY_ID )
        local Data d = Data.create( u, p, lvl )
        
        call UnitAddAbility( u, SPELLBOOK_ID )
        call SetPlayerAbilityAvailable( d.owner, SPELLBOOK_ID, false )
        call SetUnitAbilityLevel( u, DAMAGEBONUS_ID, d.lvl )
        call SmoothScaleChange.create( u, 1.0, d.lvl * 0.25 )
        call SmoothColorChange.create( u, 1.0, 0.0, -255.0, -255.0, -( d.lvl * 42.5 ) )
        
        call SetTimerData( t, d )
        call TimerStart( t, ( d.lvl * 5. ) + 5., false, function Rage_Ends )
        
        set t = null
        set p = null
        set u = null
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( t, Condition( function Spell_Check ) )
        call TriggerAddAction( t, function Rage_Actions )
    endfunction

endscope


Increase size a bit, and he becomes "redish" and a bit transparent :D
(Though, as I said a in posy #9, it bugs a bit :()
 

quraji

zap
Reaction score
144
Wouldn't the hook thingie badly slow down the periodic stuff...

Why? Please don't tell me hooks in vJass are anything but an extra function call... :eek:
(I haven't seen hook code post-vJass)

Either way, the alternative is to let the user possibly screw this up totally. And maybe people still want to use SetUnit* instead of ModifyUnit* in some cases...
 

Azlier

Old World Ghost
Reaction score
461
>Why? Please don't tell me hooks in vJass are anything but an extra function call...

An extra function call, a TriggerEvaluate, and maybe some other stuff.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>Ugh...anything more than Event?
Hooking should be faster than making an event fire through hook, and then attaching to that, if that's what you're asking.

Point in this case is that's an awfully frequent TriggerEvaluate for smooth colouring. Hooks shouldn't be used on natives that will likely be called periodically, imho.
 

quraji

zap
Reaction score
144
>Hooking should be faster than making an event fire through hook, and then attaching to that, if that's what you're asking.

I meant your system. Although I'm not quite sure that's what I was thinking of...


>Point in this case is that's an awfully frequent TriggerEvaluate for smooth colouring. Hooks shouldn't be used on natives that will likely be called periodically, imho.

Do you really think it would be bad? Doesn't key timers use TriggerEvaluate?

Anyways, as I see it, there are three options:

1. Hook the SetUnit* functions.
2. Replaces the SetUnit* functions with custom ones and hope the user uses those instead.
3. Do nothing and the system breaks if the user does happen to use one.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>I meant your system. Although I'm not quite sure that's what I was thinking of...
>>Hooking should be faster than making an Event fire through hook, and then attaching to that, if that's what you're asking.

My bad. Was meant to be Event. :)

It's not that bad, but it's avoidable... I think either provide a custom function, or don't. I don't see why you need anything other than "modify"... I mean, it would screw up colour stuff when you subtract and then later add for a spell or something.
 

quraji

zap
Reaction score
144
>My bad. Was meant to be Event. :)

Ah. Well I originally was asking do the hooks work like Event (add function as condition to a trigger, call TriggerEvalute, etc.). I haven't seen the code for them yet.

>It's not that bad, but it's avoidable... I think either provide a custom function, or don't. I don't see why you need anything other than "modify"... I mean, it would screw up colour stuff when you subtract and then later add for a spell or something.

Even if it were slow I'd still opt to add them, because they'd only be used in the case where the user tries to use the native SetUnitWhatever functions anyways (and thus only slowing it down in situations that would break the system for that unit anyways...rather have slower or broken?). I still think setting the unit properties could be useful, even though I do like modify more.
 

Komaqtion

You can change this now in User CP.
Reaction score
469
So... What should I do ?!?!

Did you come up with a conclusion ? :eek:
 

quraji

zap
Reaction score
144
So... What should I do ?!?!

Did you come up with a conclusion ? :eek:

So... What should I do ?!?!

Did you come up with a conclusion ? :eek:

Well I can't decide for you but here's the rundown.

The problem: Since your struct tracks the unit's rgba and scale values through modifying them inside your functions, it does not update if the native SetUnitWhatever functions are used. This will obviously screw up any future use of that unit's struct, as the unit's actual values will not match the struct's.

The solutions:
1. Hook the native SetUnitWhatever functions and update the struct values accordingly. Fail-safe, but comes with a possible performance hit if used frequently (according to Jesus4Lyf).

2. Provide your own SetUnitWhatever functions that update the struct. Instruct users to replace any occurrence of those native functions with yours. Simpler, but if the user misses an occurrence of a native function or forgets, then the problem resurfaces.

[del]3. Both[/del]. This would be the best solution, but it is not worth implementing in vJASS (this would work great in cJASS). This is because in vJass the custom Set functions would trigger the hook anyways, defeating the purpose of the custom function. In cJass you can avoid this situation (call hooked functions without triggering the hook).

It's up to you =]
 

Gwypaas

hook DoNothing MakeGUIUsersCrash
Reaction score
50
Why dont you use ARGB? It's like the standard in every color management situation because it's so damn easy to use AND powerful.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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