- Joined
- Oct 12, 2011
- Messages
- 3,449
This is about my PathingColor library. Here is the code:
I use it in my game, somehow it causes the FPS to drop slowly. I just call the function (
If someone can help me to find the problem, it will be so much appreciated.
Thank you.
JASS:
library PathingColor initializer onInit requires IsTerrainWalkable
// Configuration
globals
private constant integer FLYING_CHECKER = 'h008'
private constant integer BUILDING_CHECKER = 'n000'
endglobals
/*
PathingColor v1.2
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
by: Dalvengyr
Description
¯¯¯¯¯¯¯¯¯¯¯
An extension to IsTerrainWalkable. This library allows you
to detect 8 types of possible pathing colors in Warcraft III.
Additionally, it's also able to check terrain's pathing
type (walkability, flyability, and buildability).
Here is the color specifications:
Color Buildable Walkable Flyable Red Green Blue
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
White x x x 255 255 255
Magenta x x o 255 0 255
Cyan x o x 0 255 255
Blue x o o 0 0 255
Yellow o x x 255 255 0
Red o x o 255 0 0
Green o o x 0 255 0
Black o o o 0 0 0
(You can check your pathing map by pressing 'p' at terrain editor.)
API
¯¯¯
1. Used for checking certain point's pathability color.
| function GetTerrainPathingColor takes real x, real y returns integer
Returned values (pathing colors):
| PATHING_COLOR_WHITE
| PATHING_COLOR_MAGENTA
| PATHING_COLOR_CYAN
| PATHING_COLOR_BLUE
| PATHING_COLOR_YELLOW
| PATHING_COLOR_RED
| PATHING_COLOR_GREEN
| PATHING_COLOR_BLACK
2. Used for checking certain color's pathing type.
| function IsColorPathingType takes integer color, integer pathingType returns boolean
3. Used for checking certain point's pathing type.
| function IsTerrainPathingType takes real x, real y, integer pathingType returns boolean
Pathing types:
| PATHING_TYPE_FLYABLE
| PATHING_TYPE_WALKABLE
| PATHING_TYPE_BUILDABLE
How to import
¯¯¯¯¯¯¯¯¯¯¯¯¯
- Copy Fly Checker and Build Checker (units) at object editor.
- Install IsTerrainWalkable correctly.
- Make sure MAX_RANGE of that system is less than 32.
- Configure this system (available above).
Credits
¯¯¯¯¯¯¯
- IsTerrainWalkable by Vexorian n Anitarf
- TheHelper.net for complete pathing types tutorial
Link
¯¯¯¯
hiveworkshop.com/forums/spells-569/pathing-color-v1-0-a-263230/
*/
globals
private rect TempRect
private unit FlyChecker
private unit BuildChecker
private real ReturnX
private real ReturnY
private group DisableGroup = CreateGroup()
private group EnableGroup = CreateGroup()
private constant real BUILD_COLLISION_SIZE = 64
private constant real FLY_COLLISION_SIZE = 1
constant integer PATHING_COLOR_WHITE = 0
constant integer PATHING_COLOR_MAGENTA = 1
constant integer PATHING_COLOR_CYAN = 2
constant integer PATHING_COLOR_BLUE = 3
constant integer PATHING_COLOR_YELLOW = 4
constant integer PATHING_COLOR_RED = 5
constant integer PATHING_COLOR_GREEN = 6
constant integer PATHING_COLOR_BLACK = 7
constant integer PATHING_TYPE_FLYABLE = 0
constant integer PATHING_TYPE_WALKABLE = 1
constant integer PATHING_TYPE_BUILDABLE= 2
endglobals
private function IsInRect takes real x, real y returns boolean
return x > GetRectMinX(TempRect) and x < GetRectMaxX(TempRect) and y > GetRectMinY(TempRect) and y < GetRectMaxY(TempRect)
endfunction
private function IsInRadius takes real x, real y, real x2, real y2 returns boolean
return (x-x2)*(x-x2)+(y-y2)*(y-y2) < FLY_COLLISION_SIZE*FLY_COLLISION_SIZE
endfunction
function GetTerrainPathingColor takes real x, real y returns integer
local unit fog
local integer color = 0
call MoveRectTo(TempRect, x, y)
call GroupEnumUnitsInRect(DisableGroup, TempRect, null)
loop
set fog = FirstOfGroup(DisableGroup)
exitwhen fog == null
call GroupRemoveUnit(DisableGroup, fog)
call GroupAddUnit(EnableGroup, fog)
call SetUnitPathing(fog, false)
endloop
call SetUnitPosition(FlyChecker, x, y)
if IsInRadius(x, y, GetUnitX(FlyChecker), GetUnitY(FlyChecker)) then
set color = color + 1
endif
call SetUnitX(FlyChecker, ReturnX)
call SetUnitY(FlyChecker, ReturnY)
if IsTerrainWalkable(x, y) then
set color = color + 2
endif
call SetUnitPosition(BuildChecker, x, y)
if IsInRect(GetUnitX(BuildChecker), GetUnitY(BuildChecker)) then
set color = color + 4
endif
call SetUnitPosition(BuildChecker, ReturnX, ReturnY)
loop
set fog = FirstOfGroup(EnableGroup)
exitwhen fog == null
call GroupRemoveUnit(EnableGroup, fog)
call SetUnitPathing(fog, true)
endloop
return color
endfunction
function IsColorPathingType takes integer color, integer pathing returns boolean
if pathing == PATHING_TYPE_FLYABLE then
return color == 1 or color == 3 or color == 5 or color == 7
elseif pathing == PATHING_TYPE_WALKABLE then
return color == 2 or color == 3 or color == 6 or color == 7
elseif pathing == PATHING_TYPE_BUILDABLE then
return color == 4 or color == 5 or color == 6 or color == 7
endif
return false
endfunction
function IsTerrainPathingType takes real x, real y, integer pathing returns boolean
return IsColorPathingType(GetTerrainPathingColor(x, y), pathing)
endfunction
private function onInit takes nothing returns nothing
local player p = Player(PLAYER_NEUTRAL_PASSIVE)
set TempRect = Rect(0, 0, BUILD_COLLISION_SIZE, BUILD_COLLISION_SIZE)
set BuildChecker = CreateUnit(p, BUILDING_CHECKER, 999999, 999999, 0)
call PauseUnit(BuildChecker, true)
call ShowUnit(BuildChecker, false)
set FlyChecker = CreateUnit(p, FLYING_CHECKER, 999999, 999999, 0)
call PauseUnit(FlyChecker, true)
call ShowUnit(FlyChecker, false)
call SetUnitPosition(BuildChecker, GetRectMaxX(bj_mapInitialPlayableArea), GetRectMaxY(bj_mapInitialPlayableArea))
set ReturnX = GetUnitX(BuildChecker)
set ReturnY = GetUnitY(BuildChecker)
endfunction
endlibrary
GetTerrainPathingColor
) approximately 6 times every 0.06250 second. When I tried to disable the line that call this function, the fps drop is gone. I literally have no idea why is this happening. SetUnitPosition
shouldn't be extremely heavy like that. If it's indeed that heavy, so I could say that wc3 is extremely retarded.If someone can help me to find the problem, it will be so much appreciated.
Thank you.
Last edited by a moderator: