Need help with finding some bug.

Viikuna

No Marlo no game.
Reaction score
265
edit. Got it working, it was a stupid little mistake. You can stll try to find it for fun, if you like.


Okay, I have this DayNightFog -system for changing terrain fog.
Its not working ( edit. forgot to tell that not working means that fogs not changing..), ( probably due some stupid li´l mistake, but there might be something else too.. )

And I would like to hear some comments about this system, because I might submit it someday.

code:
JASS:
library DayNightFog

globals
    private constant real DAWN_TIME = 6.00
    private constant real DUSK_TIME = 18.00
    private constant real TIMEOUT = .03
    // For initial day time:
    private constant boolean IT_IS_DAY = true
    private constant real INITIAL_FOG_CHANGE_DURATION = 10.
endglobals

//=======================================================================
// Fog System includes:
//                       -struct fog
//                                  - color and z values and change duration
//                                  - method copyValues takes fog source
//
//                       -array struct PlayerFogData
//                                  - fog day
//                                  - fog night
//                                  - fog special
//                                  - boolean useSpecial
//                                  - boolean useFog
//                                  - method refresh takes boolean instant
//
//=======================================================================
//=======================================================================
struct fog
    real red
    real green
    real blue
    real zstart
    real zend
    real changeDuration
    
    static method create takes real red, real green, real blue, real zstart, real zend returns fog
        local fog f=fog.allocate()
        set f.red=red
        set f.green=green
        set f.blue=blue
        set f.zstart=zstart
        set f.zend=zend
        set f.changeDuration=INITIAL_FOG_CHANGE_DURATION
        return f
    endmethod
    
    method copyValues takes fog source returns nothing
        set .red=source.red
        set .green=source.green
        set .blue=source.blue
        set .zstart=source.zstart
        set .zend=source.zend
    endmethod
endstruct
//=======================================================================
struct PlayerFogData extends array
//=======================================================================
    fog day
    fog night
    fog special
    boolean useSpecial
    boolean useFog
    
    private static boolean IsDay=IT_IS_DAY  
   method operator isDay takes nothing returns boolean
      return .IsDay
   endmethod
   
//====================================================== 
//======================================================     
    private integer id
    private fog now
    private fog velocity
    private fog target
    private integer iterations
    private boolean change
    private static timer T=CreateTimer()
    private static boolean timer=false
    private static trigger Dawn=CreateTrigger()
    private static trigger Dusk=CreateTrigger()
    
    method refresh takes boolean instant returns nothing
        local fog f
        local real red
        local real blue
        local real green
        local real zstart
        local real zend
        if .useFog then
            if .useSpecial and integer(.special)!=0 then
                set f=.special
            else
                if .IsDay and integer(.day)!=0 then
                    set f=.day
                else
                    if integer(.night)!=0 then
                        set f=.night 
                    endif
                endif
            endif
            if integer(f)!=0 then
                if instant then
                    call .now.copyValues(f)
                    set red=.now.red
                    set blue=.now.blue
                    set green=.now.green
                    set zstart=.now.zstart
                    set zend=.now.zend
                    if GetLocalPlayer()==Player(.id) then
                        call SetTerrainFogEx(0,zstart,zend,0.0,red,green,blue)
                   endif
                else
                    set .iterations=R2I(f.changeDuration/TIMEOUT)
                    call .target.copyValues(f)
                    set .velocity.red=(.target.red-.now.red)/.iterations
                    set .velocity.green=(.target.green-.now.green)/.iterations
                    set .velocity.blue=(.target.blue-.now.blue)/.iterations
                    set .velocity.zstart=(.target.zstart-.now.zstart)/.iterations
                    set .velocity.zend=(.target.zend-.now.zend)/.iterations
                    set .change=true
                    if not .timer then
                        set .timer=true
                        call TimerStart(.T,TIMEOUT,true,function PlayerFogData.periodic)
                    endif
                endif
            endif
        endif
    endmethod
    
    //! textmacro Limits takes VALUE
        if $VALUE$ > 1. then
           set $VALUE$=1.
        else
           if $VALUE$ < 0. then
              set $VALUE$ = 0.
           endif
        endif
    //! endtextmacro
    
    private static method periodic takes nothing returns nothing
        local integer i=0
        local integer endcount=12
        local PlayerFogData f
        local real red
        local real blue
        local real green
        local real zstart
        local real zend
        loop
           exitwhen i>11
           set f=PlayerFogData<i>
           if f.change and f.useFog then
               if f.iterations&gt;0 then
                   set f.iterations=f.iterations-1
                   set red=f.now.red+f.velocity.red
                   set green=f.now.green+f.velocity.green
                   set blue=f.now.blue+f.velocity.blue
                   set zstart=f.now.zstart+f.velocity.zstart
                   set zend=f.now.zend+f.velocity.zend
               else
                   set f.change=false
                   set red=f.target.red
                   set blue=f.target.blue
                   set green=f.target.green
                   set zstart=f.target.zstart
                   set zend=f.target.zend
               endif
               //! runtextmacro Limits(&quot;red&quot;)
               //! runtextmacro Limits(&quot;green&quot;)
               //! runtextmacro Limits(&quot;blue&quot;)
               if GetLocalPlayer()==Player(i) then
                   call SetTerrainFogEx(0,zstart,zend,0.0,red,green,blue)
               endif
               set f.now.red=red
               set f.now.green=green
               set f.now.blue=blue
               set f.now.zstart=zstart
               set f.now.zend=zend
           else
              if f.change and not f.useFog then
                 set f.change=false
              endif
              set endcount=endcount-1
              if endcount==0 then
                  call PauseTimer(.T)
                  set .timer=false
              endif
           endif
           set i=i+1
         endloop
    endmethod
    
    private static method IsItDawnYet takes nothing returns boolean
        local integer i=0
        set .IsDay=true
        loop
            exitwhen i&gt;11
            call PlayerFogData<i>.refresh(false)
            set i=i+1
        endloop
        return false
    endmethod
    private static method IsItDuskYet takes nothing returns boolean
        local integer i=0
        set .IsDay=false
        loop
            exitwhen i&gt;11
            call PlayerFogData<i>.refresh(false)
            set i=i+1
        endloop
        return false
    endmethod
    
    private static method onInit takes nothing returns nothing
        local integer i=0
        loop
            exitwhen i&gt;11
            set PlayerFogData<i>.useSpecial=false
            set PlayerFogData<i>.change=false
            set PlayerFogData<i>.useFog=false
            set PlayerFogData<i>.iterations=0
            set PlayerFogData<i>.now=fog.create(0.0,0.0,0.0,0.0,0.0)
            set PlayerFogData<i>.velocity=fog.create(0.0,0.0,0.0,0.0,0.0)
            set PlayerFogData<i>.target=fog.create(0.0,0.0,0.0,0.0,0.0)
            set PlayerFogData<i>.id=i
            set i=i+1
        endloop
        call TriggerRegisterGameStateEvent(.Dawn,GAME_STATE_TIME_OF_DAY,EQUAL,DAWN_TIME)
        call TriggerRegisterGameStateEvent(.Dusk,GAME_STATE_TIME_OF_DAY,EQUAL,DUSK_TIME)
        call TriggerAddCondition(.Dawn,Condition(function PlayerFogData.IsItDawnYet))
        call TriggerAddCondition(.Dusk,Condition(function PlayerFogData.IsItDuskYet))
    endmethod
endstruct

endlibrary</i></i></i></i></i></i></i></i></i></i></i>


example of usage:
JASS:
    local fog f1=fog.create(.764,.812,.831,0.0,12000.)
    local fog f2=fog.create(.121,.164,.731,0.0,3500.)
    set PlayerFogData[0].useFog=true
    set PlayerFogData[0].day=f1
    set PlayerFogData[0].night=f1
    call SetTimeOfDay(10.0)
    call PlayerFogData[0].refresh(true)
 
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