Math operations causing lag?

Status
Not open for further replies.
Hello,

Im currently working on a racing map and I wanted to make a physics system with more then just turning, accelerating, braking.
I am still doing the math, but I am worried about the calculations drastically reducing the performance of the map.
I calculate speed, position, forces etc. every 0.02 seconds. With 8 players, this means 400 calculation loops per second.
Each calculation includes several trigonometric functions, which to my knowledge, require more processing time then + - * / ^. This means 4000 or so trigonometric functions per second.
Is this still operated fast enough to not reduce performance?

If it isnt, I had the idea of precalculating the functions into an array.

For example, for the Cosine function:

For each Integer myInteger from 0 to 360, do the following actions:
Set ConstCos[myInteger] = Cos(Real(myInteger))

A cosine operator would then be replaced with a reference to the array: ConstCos[Integer(MyDegree)]. Saving only integer degrees wouldnt reduce accuracy by much, as Warcraft 3 only calculates to the 2nd decimal anyway.

Does this make any sense? Or am I worrying about inanities?
 
I'm having no evidence, but MaDOS for example is having 200 lines of calucaltion and runs smoothly with 150 objects moving on the map.

I don't think you need to care about that. What's more is, that you need to care for ineffective functions that often appear in the GUI. When moving units try to avoid locations and use coordinates ( reals ) instead. I recommend to use JASS for a physics system to gain full performance

Just tested 1000.000.000 Cos(x) calls per second without any fps loss.
 
That's not 1 billion, that's 10 million

i see 9 zeros there. for american people, who use the short-scale numbering system (which is just stupid and should be wiped out from the world btw), this is a billion.

anyway, so the math calculation is not a problem.
what about the positioning?
convert coordinates to point is faster then point with polar offset?
 
in the GUI you would use the following code ( converted )

  • test
    • Events
    • Conditions
    • Actions
      • Unit - Move (Triggering unit) instantly to ((Position of (Triggering unit)) offset by 64.00 towards 270.00 degrees)
JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction

call SetUnitPositionLoc( GetTriggerUnit(), PolarProjectionBJ(GetUnitLoc(GetTriggerUnit()), 64.00, 270.00) )

However in jass the script would look like this

JASS:
    local real angle = 270.0*bj_DEGTORAD
    local unit u = GetTriggerUnit()
    
    local real x = GetUnitX(u) + 64.0 * Cos(angle)
    local real y = GetUnitY(u) + 64.0 * Sin(angle)
    
    call SetUnitPosition(u, x, y)

    set u        = null

Now, as you can see in the GUI converted script we use one location, multiple calculations for the same value and two callings for GetTriggerUnit().

unit, real, location, ..., are called handles. There are handles that can cause a memory leak. A unit and a location for example can cause a leak if you do not nullify them ( in some/most cases even destroy ).

Ok, so in GUI converted JASS code we are leaking 2 handles. location & unit. This doesn't really matter if you do not call your funciton too often which massively increases the amount of leaks and therefore slows down warcraft 3. and for a physics system you need dozens of calls per second.

I guess you see my point there.. also the main reason: locations are slower than reals
 
Just tested 1000.000.000 Cos(x) calls per second without any fps loss.


I'm pretty sure that you hit the operation limit with that :p
to execute more then something like 2^16 operations or something you'd need to use a workaround
TriggerExecute for example bypasses the execution limit

however this thread is pointless since there is no proper way to test if something runs smooth
but there are a few things to know:
-special effects leak (even if removed) and are uber performance whores so use them with caution
-same for the GUI unit move function
-the JASS unit move function is like 20 times faster

get some friends and test your stuff online
there is no better way
 
Level 13
Joined
Mar 16, 2008
Messages
941
Just test it?
Gexxo (you may know him as the creater of CastleFight or EveTD) made a leaktest a while ago (link, but care: german) He used a periodic trigger with 10000 calls while the trigger is executed 1000 times, so the values are pretty exact I'd say. Even the 10 million loop calls increased the memory usage of 1.5 mb.
If you don't want to read the entire thread:
Deleted unitgroup: 0,289kb
Deleted location: 0,032kb
In both cases the leak is 0kb if you use a local and null it.
Even if you use a global and null it, the leak remains. Damn globals? oO
Deleted effect: 0.09kb, no matter what you do. (11,631 kb if not removed!)

For sure these values aren't exact, but these test showed what most people want to see :)
In addition, there were millions of tests before, it's only one of them.
 
Status
Not open for further replies.
Top