HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need help with system

03-31-2007, 01:13 AM#1
MaD[Lion]
This is my physic system, but it dont work as i expect, it lags alot when there are alot of particles, while Anitarf & Infrane's particle system doesnt.
I cant find anything in my system (as far as i know) tat leaks anything.
So im thinking of slow functions or methods, but i dont know that much.

I want the good guys to check my system or simply list all the slow functions or methods to avoid. since im a bit outdated.

But in my system im sure i remove every locations, and set their vars to null, also vars of temporarily units to null when not use anymore.
But i dont know what else may cause lag.

I use asin, acos ect... in my system, not sure if these lags.
Attached Files
File type: w3xPhysic System.w3x (42.5 KB)
03-31-2007, 01:40 AM#2
Blackroot
First;
Hidden information:

Collapse JASS:
function PSM_run takes nothing returns nothing
    local integer ps = 0
    local integer vA //acseleration
    local integer vV //speed
    local integer p //particle identifier
    local real X
    local real Y
    local real Z
    local unit P
    //run a loop trough all physic objects and move them
    loop
        if (physic_exist(ps)) then
            set udg_psCurrentPhysicPointer = ps
            set vA = physic_getAcseleration(ps)
            set vV = physic_getSpeed(ps)
            set p = physic_getParticle(ps)
            set P = particle_getUnit(p)
            //make sure the particle unit exist, else just clean up
            if (P==null) then
                call PM_destroy(p)
                call vector_delete(vA)
                call vector_delete(vV)
                call physic_delete(ps)
            else
                call VM_add(vV,vA,vV)
                set X = particle_pX(p)+vector_vX(vV)
                set Y = particle_pY(p)+vector_vY(vV)
                set Z = particle_pZ(p)+vector_vZ(vV)
                call PM_setXYZ(p,X,Y,Z)
                if (not(physic_functionName(ps)==null)) then
                    call ExecuteFunc(physic_functionName(ps))
                endif
            endif
            set P = null
        endif
        set ps = ps+1
        exitwhen ps>=udg_psPointer
    endloop
    //if there are no physics then lets reset pointers to save loop speed
    if ((udg_psFreePointer>=(udg_psPointer-1)) and (udg_psFreePointer>-1)) then
        call vector_resetpointers()
        call particle_resetpointers()
        call physic_resetpointers()
        call echo("Pointers Reset!")
    endif
endfunction


Simply to much math to fast. Try and set it to like .04 second / cycle and multiply all increments by 4. Even simple multiplication can lag very badly, and you're using it all over the place, along with SquareRoot. But the main point of the lag seems to be when the particles collide and also when removed. I'd say avoid square root because it's slow, but that's kind of hard to do. So I'll just say cut down on multiplying in any ways you can think of.
03-31-2007, 02:50 AM#3
grim001
wow why are you making all of this now without using structs? such a waste.

what's supposed to be the purpose of this engine over infrane's? or you could wait a few more weeks for mine to be done, unless you are just doing this for learning purposes, which would be a good thing.

There are 2 main reasons it's slow:
1. you are doing all kinds of un-needed function calls. function calls are ultra slow in JASS. they take longer than trig functions.
2. the period is 100x per second which is way too much. there's no visual benefit to using anything more than 30x per second.


Quote:
Uven simple multiplication can lag very badly,
That's so untrue, multiplication is almost the fastest thing you could ever do aside from even simpler math like addition.


Quote:
But the main point of the lag seems to be when the particles collide
These particles can't collide with each other, they do lag very much when continuously touching the ground though, since he uses a slow method of calculating ground angle.

Quote:
I'd say avoid square root because it's slow, but that's kind of hard to do
Square root can almost always be avoided.
03-31-2007, 08:26 AM#4
ixmike88
Collapse JASS:
function Trig_Periodic_Actions takes nothing returns nothing
  call CameraSetupApplyForPlayer( false, gg_cam_Camera_001, Player(0), 0 )
  call CameraSetupApplyForPlayer( false, gg_cam_Camera_001, Player(1), 0 )
  call CameraSetupApplyForPlayer( false, gg_cam_Camera_001, Player(2), 0 )
  call CameraSetupApplyForPlayer( false, gg_cam_Camera_001, Player(3), 0 )
  call PSM_run()
endfunction

//===========================================================================
function InitTrig_Periodic takes nothing returns nothing
    set gg_trg_Periodic = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Periodic, 0.01 )
    call TriggerAddAction( gg_trg_Periodic, function Trig_Periodic_Actions )
endfunction

I imagine this lags horribly? Why not just lock the camera to the unit? And as grim001 said, the human eye cannot see quicker than 30 frames per second (.03 periodic).
03-31-2007, 03:36 PM#5
blu_da_noob
Apart from all the stuff which has already been mentioned (all of which is quite relevant) you have other stuff. Your vector storage seems quite inefficient. You check if your vector exists by looping through 'free pointers' (the system seems rather cryptic and I haven't explored it, so I don't even what it's for, but a debug message showed it getting up to 15+ with only a few particles going). 15+ checks per particle per iteration will add up. I don't even know exactly what you are doing, but I'm sure there is a better way. (You also do the check whenever deleting the particle, getting the unit etc, which you do often and this would further contribute)

And yes, you have an inordinate number of fluff functions. PM_destroy (calls particle_getUnit (calls particle_exists) and particle_delete (calls particle_exists)). All of this also applies to your physics stuff.
03-31-2007, 04:08 PM#6
grim001
Quote:
I imagine this lags horribly? Why not just lock the camera to the unit? And as grim001 said, the human eye cannot see quicker than 30 frames per second (.03 periodic).

Well, anyone who has played a high-end FPS can tell the difference between 60 FPS and 30 FPS, but in Warcraft 3 the difference isn't great enough to be worth the performance cost.
04-01-2007, 01:15 PM#7
MaD[Lion]
a ok thnx guys, tats all i needed, my current system is alot faster now tho. but still it still lags when it gets to around 30-40 particles

And i made this system jsut for learning yes, cus i know others have better systems :D
04-01-2007, 04:29 PM#8
grim001
I suggest you port it to structs for a better learning experience