| 03-30-2008, 01:31 PM | #1 |
Hey i made this third person trigger and im trying to optimize it as much as posible but i dont know if it may cause desyncs so heres the trigger before and after. BEFORE: JASS:function Trig_GPS_Keep_Set takes nothing returns nothing local unit u = udg_Gen_Heros[GetPlayerId(GetEnumPlayer()) + 1] local player p = GetEnumPlayer() call SetCameraTargetControllerNoZForPlayer(p, u, 0, 0, false) call SetCameraFieldForPlayer(p, CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(u) / 3.00 + I2R(GetTerrainCliffLevel(GetUnitX(u), GetUnitY(u))) * 80.00, 0.50) call SetCameraFieldForPlayer(p, CAMERA_FIELD_ANGLE_OF_ATTACK, 342.00, 0.50) call SetCameraFieldForPlayer(p, CAMERA_FIELD_TARGET_DISTANCE, 700.00, 0.50) call SetCameraFieldForPlayer(p, CAMERA_FIELD_ROTATION, GetUnitFacing(u), 1.20) call SetCameraFieldForPlayer(p, CAMERA_FIELD_FIELD_OF_VIEW, 100.00, 0.50) set u = null set p = null endfunction function Trig_GPS_Keep_Actions takes nothing returns nothing if (udg_Cam_GPSCount > 0) then call ForForce(udg_Cam_GPSForce, function Trig_GPS_Keep_Set) else call DisableTrigger(gg_trg_GPS_Keep) endif endfunction //=========================================================================== function InitTrig_GPS_Keep takes nothing returns nothing set gg_trg_GPS_Keep = CreateTrigger() call DisableTrigger(gg_trg_GPS_Keep) call TriggerRegisterTimerEventPeriodic(gg_trg_GPS_Keep, 0.50) call TriggerAddAction(gg_trg_GPS_Keep, function Trig_GPS_Keep_Actions) endfunction AFTER: JASS:function Trig_GPS_Keep_Set takes nothing returns nothing local unit u = udg_Gen_Heros[GetPlayerId(GetEnumPlayer()) + 1] local real rZOFFSET = GetUnitFlyHeight(u) / 3.00 + I2R(GetTerrainCliffLevel(GetUnitX(u), GetUnitY(u))) * 80.00 local real rROTATION = GetUnitFacing(u) if (GetLocalPlayer() == GetEnumPlayer()) then call SetCameraTargetController(u, 0, 0, false) call SetCameraField(CAMERA_FIELD_ZOFFSET, rZOFFSET, 0.50) call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 342.00, 0.50) call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 700.00, 0.50) call SetCameraField(CAMERA_FIELD_ROTATION, rROTATION, 1.20) call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 100.00, 0.50) endif set u = null endfunction function Trig_GPS_Keep_Actions takes nothing returns nothing if (udg_Cam_GPSCount > 0) then call ForForce(udg_Cam_GPSForce, function Trig_GPS_Keep_Set) else call DisableTrigger(gg_trg_GPS_Keep) endif endfunction //=========================================================================== function InitTrig_GPS_Keep takes nothing returns nothing set gg_trg_GPS_Keep = CreateTrigger() call DisableTrigger(gg_trg_GPS_Keep) call TriggerRegisterTimerEventPeriodic(gg_trg_GPS_Keep, 0.50) call TriggerAddAction(gg_trg_GPS_Keep, function Trig_GPS_Keep_Actions) endfunction For those who didn't notice, the main diference is the use of "GetLocalPlayer()" to execute only local code and avoid a few "if's" and function calls. Any clue if it may desync? Thanks |
| 03-30-2008, 02:45 PM | #2 |
Are you just trying to make the camera follow a unit? |
| 03-30-2008, 03:07 PM | #3 |
No, its a third person camera, anyway is not about making the trigger work, it already does what it has do to, im just trying to optimize it as much as posible because it executes very often and for up to 12 players. |
| 03-30-2008, 03:36 PM | #4 |
You don't actually have to run use ForForce. You can just run it for GetLocalPlayer, and that will save 11 iterations. (You're already doing this, you just half-run it for the other 11) |
| 03-30-2008, 04:52 PM | #5 |
Yeah i know what you mean, the problem is that i need to access this global "udg_Gen_Heros[GetPlayerId(GetEnumPlayer()) + 1]" and im not sure if i can do it this way "udg_Gen_Heros[GetPlayerId(GetLocalPlayer()) + 1]" without causing a desync, the third person camera is enabled/disabled by the player this is why im using a force, to only run the script for those that have the camera enabled, i guess i could do this "if(IsPlayerInForce(GetLocalPlayer(), toForce)) then" instead of using the "ForForce" my biggest concern is game stability Thanks |
| 03-30-2008, 07:20 PM | #6 |
As long as shared values are the same before and after the trigger runs, there will be no desync. (shared values are things like globals, units, etc) If your local variables are different that doesn't matter, because they're only temporary. All you need to do is make sure the effects of those locals being different doesn't cause a shared value to differ across players. |
| 03-30-2008, 08:51 PM | #7 | |
Quote:
Interesting I never knew what it truly meant to desync, this post has helped 2 people! |
