HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Lag Check?

09-19-2008, 03:48 PM#1
Tastingo
Hey I decided to create AI for my game, and the game started lagging very badly when I added the AI to it. I want to eliminate the lag so that the game is playable, and wanted to start with the beginning before I start editing the rest. I heard something about the function GroupEnumUnitsOfPlayer is very costly so I'm not sure if thats the problem. (Keep in mind this is being ran every .01 seconds)

Collapse JASS:
function AI takes nothing returns nothing
local integer a = 0
local real x
local real y
local group g = CreateGroup()
local unit u
    loop
        exitwhen a>11
        if( GetPlayerController(Player(a)) == MAP_CONTROL_COMPUTER ) then
            call GroupClear(g)
            call GroupEnumUnitsOfPlayer(g, Player(a), null)
            set u = FirstOfGroup(g)
            set x = GetUnitX(u)
            set y = GetUnitY(u)
            call MoveRectTo( udg_Region[a], x, y )
            call AttackingAI( a, udg_Region[a])
        endif
        set a = a + 1
    endloop
call DestroyGroup(g)
set g = null
set u = null
endfunction

//===========================================================================
function InitTrig_AI takes nothing returns nothing
    set gg_trg_AI = CreateTrigger(  )
    call TriggerRegisterTimerEvent( gg_trg_AI, 0.01, true )
    call TriggerAddAction( gg_trg_AI, function AI )
endfunction
09-19-2008, 04:29 PM#2
Toadcop
don't use so low periods... imo for AI you don't need less than 0.1...
09-19-2008, 04:43 PM#3
Tastingo
Well what would be a good low number to use? I need it to be a low number because the function it runs checks if a unit is within range of it, and to switch targets between units to get the closest unit. Being ally or enemy.
09-19-2008, 04:52 PM#4
Deaod
try 0.03125 or 0.04.
09-19-2008, 06:17 PM#5
Tastingo
Ok thanks. Do you guys see any problems with the script? I heard that GroupEnumUnitsOfPlayer is costly. Do you know if thats true, and if I should set the unit to a variable instead?
09-19-2008, 07:03 PM#6
moyack
call GroupEnumUnitsOfPlayer(g, Player(a), null) this leaks

Add a TRUE function so you can add it to the GroupEnum function.

Collapse JASS:
function DoTrue takes nothing returns boolean
   return true
endfunction

call GroupEnumUnitsOfPlayer(g, Player(a), Condition(function DoTrue))
Additionally, if you're giving orders to the AI units, you shouldn't use low values, 0.1, 0.2 is enough. If the AI is like a normal melee one, then a value of 0.2 is enough.
09-19-2008, 07:15 PM#7
Bobo_The_Kodo
Collapse JASS:
call GroupEnumUnitsOfPlayer(g, Player(a), Condition(function DoTrue))

Doesn't that leak as well?

I would create a global private boolexpr and set it to Condition(function DoTrue) at map init, then use it for the groupenum
09-19-2008, 08:01 PM#8
Bobo_The_Kodo
Oh w/e, its still faster
09-19-2008, 08:11 PM#9
Tastingo
Ok thanks, does anyone notice any other problems with it?
09-19-2008, 09:26 PM#10
Bobo_The_Kodo
Are you saying that creating a boolexpr is faster than referencing a global?
09-23-2008, 12:39 AM#11
Tastingo
Would be nice to know whats faster :P, so if someone can tell me then that would be sick. (Want to use the faster one of course) Thank you.
09-23-2008, 01:05 AM#12
Captain Griffen
Quote:
Originally Posted by Bobo_The_Kodo
Are you saying that creating a boolexpr is faster than referencing a global?

One isn't created; if it was, it would leak.
09-23-2008, 01:11 AM#13
Bobo_The_Kodo
Whats this do then: Condition(function DoTrue)
?
09-23-2008, 01:44 AM#14
Ammorth
references some sort of internal table and (if the boolexpr for that function doesn't exist, it creates it and stores it in the table and then) returns the stored boolexpr.
09-23-2008, 07:50 AM#15
Alexander244
Quick benchmark for you guys:
Expand JASS:
I have subtracted the average for an empty run from each of the other results:

Zero Units:
TestResult%
Global3.33 micro seconds24% faster
Condition(func)4.13 micro seconds
Ten Units:
TestResult%
Global66.54 micro seconds1.7% faster
Condition(func)67.72 micro seconds