- 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.
An example :
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.
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
Last edited: