| 01-02-2007, 08:16 PM | #1 |
Hi everyone, I have been working lately on a pathing map system, that allows me to store pathing, atleast for AI computers to use it. My problem is that somehow after some processing in the loop, an error ocures randomly, like if Wc3 stopped running the code. Here's my Path module. [I'm running the function SetPath() ] JASS:globals integer array Path1 integer array Path2 integer array Path3 integer array Path4 integer array Path5 integer array Path6 integer array Path7 integer array Path8 integer Extend_X integer Extend_Y constant integer PATH_WALK = 0 constant integer PATH_SHALLOW = 1 constant integer PATH_SEA = 2 constant integer PATH_CLIFF = 3 constant integer PATH_NONE = 4 constant integer PATH_OBJECT = 5 //Object refers to any object blocking path, like path blockers, destructables, doodeds endglobals function GetPathability takes real x, real y returns integer local boolean B local boolean C set B = not ( IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY ) ) set C = not ( IsTerrainPathable( x, y, PATHING_TYPE_WALKABILITY ) ) if B and C then return PATH_SHALLOW elseif B then return PATH_SEA elseif C then return PATH_WALK elseif not ( IsTerrainPathable( x, y, PATHING_TYPE_FLYABILITY ) ) then return PATH_CLIFF else return PATH_NONE endif endfunction function PosX2CellX takes real x returns integer local real k = (x + I2R(Extend_X*64)) / 128.0 local integer d = R2I(k) if k != I2R(d) then set d = d + 1 endif if d < Extend_X then return d endif return Extend_X endfunction function PosY2CellY takes real y returns integer local real k = (y + I2R(Extend_Y*64)) / 128.0 local integer d = R2I(k) if k != I2R(d) then set d = d + 1 endif if d < Extend_Y then return d endif return Extend_Y endfunction function Pos2Cell takes real x, real y returns integer return (PosX2CellX(x)-1)*Extend_X + PosY2CellY(y) endfunction function GetCellX takes integer cell returns integer return R2I(I2R(Extend_Y) / I2R(cell)) endfunction function GetCellY takes integer cell returns integer return cell - (GetCellX(cell)*Extend_X) endfunction function CellX takes integer x returns real return (I2R(x) * 128.0) - (I2R(Extend_X) * 64.0) endfunction function CellY takes integer y returns real return (I2R(y) * 128.0) - (I2R(Extend_Y) * 64.0) endfunction function CellLoc takes integer x, integer y returns location return Location(CellX(x),CellY(y)) endfunction function CellX2 takes integer cell returns real local integer x = GetCellX(cell) return (I2R(x) * 128.0) - (I2R(Extend_X) * 64.0) endfunction function CellY2 takes integer cell returns real local integer y = GetCellY(cell) return (I2R(y) * 128.0) - (I2R(Extend_Y) * 64.0) endfunction function CellLoc2 takes integer cell returns location local integer x = GetCellX(cell) local integer y = GetCellY(cell) return Location(CellX(x),CellY(y)) endfunction function StorePath takes integer cell, integer value returns nothing local integer cell2 = cell if cell2 <= 8192 then set Path1[cell2 - 1] = value elseif cell2 <= 16384 then set cell2 = cell2 - 8192 set Path2[cell2 - 1] = value elseif cell2 <= 24576 then set cell2 = cell2 - 16384 set Path3[cell2 - 1] = value elseif cell2 <= 32768 then set cell2 = cell2 - 24576 set Path4[cell2 - 1] = value elseif cell2 <= 40960 then set cell2 = cell2 - 32768 set Path5[cell2 - 1] = value elseif cell2 <= 49152 then set cell2 = cell2 - 40960 set Path6[cell2 - 1] = value elseif cell2 <= 57344 then set cell2 = cell2 - 49152 set Path7[cell2 - 1] = value elseif cell2 <= 65536 then set cell2 = cell2 - 57344 set Path8[cell2 - 1] = value endif endfunction function GetPath takes integer cell returns integer local integer cell2 = cell if cell2 <= 8192 then return Path1[cell2 - 1] elseif cell2 <= 16384 then set cell2 = cell2 - 8192 return Path2[cell2 - 1] elseif cell2 <= 24576 then set cell2 = cell2 - 16384 return Path3[cell2 - 1] elseif cell2 <= 32768 then set cell2 = cell2 - 24576 return Path4[cell2 - 1] elseif cell2 <= 40960 then set cell2 = cell2 - 32768 return Path5[cell2 - 1] elseif cell2 <= 49152 then set cell2 = cell2 - 40960 return Path6[cell2 - 1] elseif cell2 <= 57344 then set cell2 = cell2 - 49152 return Path7[cell2 - 1] elseif cell2 <= 65536 then set cell2 = cell2 - 57344 return Path8[cell2 - 1] endif return 0 endfunction function Path_Helper takes nothing returns nothing local destructable d = GetEnumDestructable() local integer cell = Pos2Cell(GetDestructableX(d),GetDestructableY(d)) call StorePath(cell,PATH_OBJECT) endfunction // long processing, run only at map init function SetPath takes nothing returns nothing local rect r = GetWorldBounds() local integer d = 1 local integer x = 1 local integer y = 1 local integer f set Extend_X = R2I(GetRectMaxX(r) / 64.0) set Extend_Y = R2I(GetRectMaxY(r) / 64.0) call BJDebugMsg(I2S(Extend_X) + ", " + I2S(Extend_Y) + " done processing, entering loop") loop exitwhen x > Extend_X loop exitwhen y > Extend_Y set f = GetPathability(CellX(x),CellY(y)) call StorePath(d,f) set d = d + 1 set y = y + 1 endloop call BJDebugMsg(I2S(y) + " jumps made") call BJDebugMsg(I2S(x) + " jumps made now") set y = 1 set x = x + 1 endloop call BJDebugMsg("ended loop") call EnumDestructablesInRectAll( GetPlayableMapRect(), function Path_Helper ) endfunction function CleanPathMemory takes nothing returns nothing local integer i loop exitwhen i > Extend_X*Extend_Y call StorePath(i,0) set i = i + 1 endloop endfunction |
| 01-02-2007, 08:25 PM | #2 |
Most likely hits the op limit at 300,000 micro-ops. |
| 01-03-2007, 12:47 AM | #3 |
hmm, thought so, but making the thread go to sleep, for a while, would make it run quite slow, it may be around a max of 69.12 seconds of execution. Any other possible solution? |
| 01-03-2007, 12:48 AM | #4 |
You can try using executeFunc for each main subloop |
| 01-03-2007, 12:55 AM | #5 | |
Quote:
thought so, but i'm not sure if it will cause problems, anyways thanks you both. |
