View Single Post
Old 01-21-2006, 06:29 PM   #3
Vexorian
Free Software Terrorist
 
Vexorian's Avatar


Technical Director
 
Join Date: Apr 2003
Posts: 14,898

Submissions (37)

Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)Vexorian has a reputation beyond repute (1062)

Hero Contest #3 - 2nd Place

Default

GC is a horribly generic name and needs to be more specific to the system but the problem is that you call it everytime
Collapse BAD:

function CameraMainLoop takes nothing returns nothing
    local real array a
    local real array v
    local real array s
    local real array time
    local integer i = 0

    loop
        exitwhen i == 9
        set i = i + 1
        set time[i] = GetStoredReal( GC(), "camera", "time" + I2S(i) ) + CameraPeriod()

        if time[i] > GetStoredReal( GC(), "camera", "endtime" + I2S(i) ) then
            if GetStoredReal( GC(), "camera", "acc2" + I2S(i) ) != 0 then
                call StoreReal( GC(), "camera", "acc" + I2S(i), GetStoredReal( GC(), "camera", "acc2" + I2S(i) ) )
                call StoreReal( GC(), "camera", "startvel" + I2S(i), GetStoredReal( GC(), "camera", "vel" + I2S(i) ) )
                call StoreReal( GC(), "camera", "startdis" + I2S(i), GetStoredReal( GC(), "camera", "dis" + I2S(i) ) )
                call StoreReal( GC(), "camera", "time" + I2S(i), 0.00 )
                call StoreReal( GC(), "camera", "acc2" + I2S(i), 0.00 )
                set time[i] = 0.00
            else
            endif
        endif

        set a[i] = GetStoredReal( GC(), "camera", "acc" + I2S(i) )
        set v[i] = GetStoredReal( GC(), "camera", "startvel" + I2S(i) )
        set s[i] = GetStoredReal( GC(), "camera", "startdis" + I2S(i) )

        call StoreReal( GC(), "camera", "time" + I2S(i), (time[i]) )

        set s[i] = s[i] + ( v[i] * time[i] ) + ( a[i] * time[i] * time[i] / 2 )
        set v[i] = v[i] + ( a[i] * time[i] )
        if i > 3 and i < 7 then
            if s[i] > 360 then
                set s[i] = s[i] - 360
            elseif s[i] < 0 then
                set s[i] = s[i] + 360
            endif
        endif

        call StoreReal( GC(), "camera", "vel" + I2S(i), v[i] )
        call StoreReal( GC(), "camera", "dis" + I2S(i), s[i] )


    endloop

    call PanCameraToTimed( s[1], s[2], 0.00 )
    call SetCameraField( CAMERA_FIELD_ZOFFSET, s[3], 0.00 )
    call SetCameraField( CAMERA_FIELD_ROTATION, s[4], 0.00 )
    call SetCameraField( CAMERA_FIELD_ANGLE_OF_ATTACK, s[5], 0.00 )
    call SetCameraField( CAMERA_FIELD_ROLL, s[6], 0.00 )
    call SetCameraField( CAMERA_FIELD_FIELD_OF_VIEW, s[7], 0.00 )
    call SetCameraField( CAMERA_FIELD_FARZ, s[8], 0.00 )
    call SetCameraField( CAMERA_FIELD_TARGET_DISTANCE, s[9], 0.00 ) 
endfunction

Collapse Good:
function CameraMainLoop takes nothing returns nothing
 local real array a
 local real array v
 local real array s
 local real array time
 local integer i = 0
 local gamecache g=g

    loop
        exitwhen i == 9
        set i = i + 1
        set time[i] = GetStoredReal( g, "camera", "time" + I2S(i) ) + CameraPeriod()

        if time[i] > GetStoredReal( g, "camera", "endtime" + I2S(i) ) then
            if GetStoredReal( g, "camera", "acc2" + I2S(i) ) != 0 then
                call StoreReal( g, "camera", "acc" + I2S(i), GetStoredReal( g, "camera", "acc2" + I2S(i) ) )
                call StoreReal( g, "camera", "startvel" + I2S(i), GetStoredReal( g, "camera", "vel" + I2S(i) ) )
                call StoreReal( g, "camera", "startdis" + I2S(i), GetStoredReal( g, "camera", "dis" + I2S(i) ) )
                call StoreReal( g, "camera", "time" + I2S(i), 0.00 )
                call StoreReal( g, "camera", "acc2" + I2S(i), 0.00 )
                set time[i] = 0.00
            else
            endif
        endif

        set a[i] = GetStoredReal( g, "camera", "acc" + I2S(i) )
        set v[i] = GetStoredReal( g, "camera", "startvel" + I2S(i) )
        set s[i] = GetStoredReal( g, "camera", "startdis" + I2S(i) )

        call StoreReal( g, "camera", "time" + I2S(i), (time[i]) )

        set s[i] = s[i] + ( v[i] * time[i] ) + ( a[i] * time[i] * time[i] / 2 )
        set v[i] = v[i] + ( a[i] * time[i] )
        if i > 3 and i < 7 then
            if s[i] > 360 then
                set s[i] = s[i] - 360
            elseif s[i] < 0 then
                set s[i] = s[i] + 360
            endif
        endif

        call StoreReal( g, "camera", "vel" + I2S(i), v[i] )
        call StoreReal( g, "camera", "dis" + I2S(i), s[i] )


    endloop

    call PanCameraToTimed( s[1], s[2], 0.00 )
    call SetCameraField( CAMERA_FIELD_ZOFFSET, s[3], 0.00 )
    call SetCameraField( CAMERA_FIELD_ROTATION, s[4], 0.00 )
    call SetCameraField( CAMERA_FIELD_ANGLE_OF_ATTACK, s[5], 0.00 )
    call SetCameraField( CAMERA_FIELD_ROLL, s[6], 0.00 )
    call SetCameraField( CAMERA_FIELD_FIELD_OF_VIEW, s[7], 0.00 )
    call SetCameraField( CAMERA_FIELD_FARZ, s[8], 0.00 )
    call SetCameraField( CAMERA_FIELD_TARGET_DISTANCE, s[9], 0.00 ) 
 set g=null
endfunction

Why? Because the GC function has a comparission and a return and many other things that charge the performance - As bad as using BJ functions. In functions like this one it is getting called way too much times and using a local will make the charge lighter,

Any logical explanation for doing this:

Collapse BAD:

    call StoreReal( GC(), "camera", "startdis" + I2S(1), CameraSetupGetDestPositionX( whichSetup ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(2), CameraSetupGetDestPositionY( whichSetup ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(3), CameraSetupGetField( whichSetup, CAMERA_FIELD_ZOFFSET ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(4), CameraSetupGetField( whichSetup, CAMERA_FIELD_ROTATION ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(5), CameraSetupGetField( whichSetup, CAMERA_FIELD_ANGLE_OF_ATTACK ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(6), CameraSetupGetField( whichSetup, CAMERA_FIELD_ROLL ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(7), CameraSetupGetField( whichSetup, CAMERA_FIELD_FIELD_OF_VIEW ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(8), CameraSetupGetField( whichSetup, CAMERA_FIELD_FARZ ) )
    call StoreReal( GC(), "camera", "startdis" + I2S(9), CameraSetupGetField( whichSetup, CAMERA_FIELD_TARGET_DISTANCE ) )

instead of this?

Collapse Good:
    call StoreReal( GC(), "camera", "startdis1", CameraSetupGetDestPositionX( whichSetup ) )
    call StoreReal( GC(), "camera", "startdis2", CameraSetupGetDestPositionY( whichSetup ) )
    call StoreReal( GC(), "camera", "startdis3", CameraSetupGetField( whichSetup, CAMERA_FIELD_ZOFFSET ) )
    call StoreReal( GC(), "camera", "startdis4", CameraSetupGetField( whichSetup, CAMERA_FIELD_ROTATION ) )
    call StoreReal( GC(), "camera", "startdis5", CameraSetupGetField( whichSetup, CAMERA_FIELD_ANGLE_OF_ATTACK ) )
    call StoreReal( GC(), "camera", "startdis6", CameraSetupGetField( whichSetup, CAMERA_FIELD_ROLL ) )
    call StoreReal( GC(), "camera", "startdis7", CameraSetupGetField( whichSetup, CAMERA_FIELD_FIELD_OF_VIEW ) )
    call StoreReal( GC(), "camera", "startdis8", CameraSetupGetField( whichSetup, CAMERA_FIELD_FARZ ) )
    call StoreReal( GC(), "camera", "startdis9", CameraSetupGetField( whichSetup, CAMERA_FIELD_TARGET_DISTANCE ) )

Edit: you also have an ==true in the B2I function which is btw useless
__________________
Zoom (requires log in)Wc3 map optimizer 5.0
Someone should fix .wav sound in this thing.
Zoom (requires log in)JassHelper 0.A.2.A
Turns your simple code into something that is complicated enough to work.
Faster != more useful
Vexorian is offline   Reply With Quote