• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Proof of concept Using ForForce to get rid of limit op

Status
Not open for further replies.
Level 17
Joined
Apr 27, 2008
Messages
2,455
[Proof of concept] Using ForForce and one force to get rid of limit op

Nothing new, but as far i know there is no resource like that submitted somewhere.

JASS:
library Thread

    struct Thread extends array
    
        private static integer Iterations = 0
        private static force F
        private static timer Tim
        
        private static method initCount takes nothing returns nothing
            set thistype.Iterations = 0
        endmethod
            
        private static method display takes nothing returns nothing
            call BJDebugMsg(I2S(thistype.Iterations))
        endmethod
        
        static method displayMax takes nothing returns nothing
            call TimerStart(thistype.Tim,0,false,function thistype.display)
        endmethod
        
        static method new takes code func returns nothing
            call thistype.initCount()
            call ForForce(thistype.F,func)
        endmethod
        
        static method operator count takes nothing returns integer
            set thistype.Iterations = thistype.Iterations+1
            return thistype.Iterations
        endmethod
        
        private static method onInit takes nothing returns nothing
            set thistype.F = CreateForce()
            set thistype.Tim = CreateTimer()
            call ForceAddPlayer(thistype.F,GetLocalPlayer())
        endmethod

    endstruct
        
endlibrary

An example :

JASS:
library ThreadSample initializer Init uses Thread

    globals
        private hashtable Data
        private real X = 0
        private real Y = 0
        private constant integer OFFSET = 64
        private real X_min
        private real Y_min
        private real X_max
        private real Y_max
    endglobals

    private function ScanMap takes nothing returns nothing
        /*
        call BJDebugMsg("ScanMap : max loop iterations before thread crash : ")
        call Thread.displayMax()
        */
        // When you know the value AND your code is the final version, just comment this 2 above line code
        loop
        exitwhen Y > Y_max
            set X = X_min
            loop
            exitwhen X > X_max
                call SaveInteger(Data,R2I(X),R2I(Y),GetTerrainType(X,Y))
            set X = X+OFFSET
            endloop
        
            set Y = Y+OFFSET
            if Thread.count == 18 then
            // now in my case with this code and map size 256*256, it was 18 before thread crash, but for your code, first put a big value like 100000
                call Thread.new(function ScanMap)
            endif
        endloop
    endfunction
    
    private function Init takes nothing returns nothing
        local rect map = GetWorldBounds()
        
        set Data = InitHashtable()
        set X_min = GetRectMinX(map)
        set Y_min = GetRectMinY(map)
        set X_max = GetRectMaxX(map)
        set Y_max = GetRectMaxY(map)
        call RemoveRect(map)
        set X = X_min
        set Y = Y_min
        call TriggerSleepAction(0)
        call BJDebugMsg("scan will start")
        call Thread.new(function ScanMap)
        call BJDebugMsg("scan completed")
        call BJDebugMsg(I2S(LoadInteger(Data,25600,1920)))
        
    endfunction
    
endlibrary
Feel free to copy nothing, some lines, or the whole part of this, to submit your own resource, i don't care to submit it myself.
 
Last edited:

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
- Never believe some warcraft "fact" without a proof, even from an "experienced" user, that's how myths & legends born.
You could provide simple example, especially for new users to test this out, with additional (even small) description on top of your script.

This is not really required for experienced users, though many hivers would be pleased to see some bonus information.
 
Level 13
Joined
Nov 7, 2014
Messages
571
why not simply use 0timers.

"0 timers", assuming you mean: call TimerStart(t, 0, false, function some_function), execute the function "asynchronously":

JASS:
function foo takes nothing returns nothing
    call BJDebugMsg("foo")
endfunction

...
call TimerStart(t, 0, false, function foo)
call BJDebugMsg("bar")
...
// =>
// bar
// foo

ForForce executes the function "synchronously":
JASS:
function foo takes nothing returns nothing
    call BJDebugMsg("foo")
endfunction

...
call ForForce(bj_FORCE_PLAYER[15], function foo)
call BJDebugMsg("bar")
...
// =>
// foo
// bar
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Simply because it's delayed.

Frankly i didn't know about the asynchronous part, but btw is it really asynchronous or does it work like a stack ? (Last timer end the first)
EDIT : Oh wait, you didn't use two timers in your sample, then the output is obvious.
 
Last edited:
Level 2
Joined
Feb 15, 2016
Messages
9
Are there any advantages to this over TriggerExecute?

As far as I can tell, TriggerExecute works just as well for resetting the ops limit. Is ForForce faster than TriggerExecute?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
It is supposed to be faster, also it's more dynamic and elegant, since you don't need to create a trigger and in general an agent/handle just to run your code.
I mean only this force one time and that's all.
You can even run Forforce in a local block (If GetLocalPlayer ...), but yeah it will desync in many cases.
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
That's not what i remember about that, i mean ForForce was for me at least 50 % faster.
But anyway, even if you're right, that's still better than TriggerEvaluate because you don't need to create a trigger and a trigger condition just to run your code.
 
Status
Not open for further replies.
Top