User Tools

Site Tools


4rpl:commands:refreshunitloscache

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
4rpl:commands:refreshunitloscache [2022/03/23 01:29] – Further advise and applications on top of previous edit Vertu4rpl:commands:refreshunitloscache [2024/01/19 01:11] (current) – Define unit range before using. Also did some rewording and SetUnitRange example. Vertu
Line 6: Line 6:
  
 ===== Description ===== ===== Description =====
-Causes the unit to perform line of sight calculations based on the LOS settings. The results are stored and used by API's like [[FindUnitEnemy]]. The LOS cache should be updated when the unit is moved, but not more frequently than absolutely necessary due to it's high performance cost.+Causes the unit to perform line of sight calculations based on the LOS settings. The results are stored and used by [[FindUnitEnemy]]. The LOS cache should be updated when the unit is moved, but not more frequently than absolutely necessary due to it's high performance cost. The best time to update LOSCache is when the unit comes to a stop or travels a certain distance.
  
 ---- ----
 +====IMPORTANT NOTES====
 +RefreshUnitLOSCache is dependent on the range of the unit being defined. This is important if you are not using the built-in range parameter within the CPACK Unit Manager and are instead using code to define range via [[SetUnitRange]]. Always make sure to initialize the range before RefreshingUnitLOSCache or you will get many inconsistencies with the capability of [[FindUnitEnemy]] until range is defined for the unit before a LOSCache refresh.
  
-The range of the unit is also a major factor in the performance intensity of calling this API. It is highly discouraged to use this API for any unit with a range larger than 100. If you however still do, the best way to deal with the performance intensity is to have each unit call RefreshUnitLosCache at a slightly different frame from each other to prevent major stutters and make the performance impact unnoticeable.+The range of the unit is a major factor in the performance intensity of calling this API. It is highly discouraged to use this API for any unit with a range larger than 100. If you however still do, the best way to deal with the performance intensity is to have each unit call RefreshUnitLosCache at a slightly different frame from each other to prevent major stutters and make the performance impact unnoticeable.
  
 For additional reference, do not use this API for a unit with a range more than 200. Any much higher and this API on it's own even when called by a single unit has enough performance impact to cause a noticeable stutter. Besides, you should only really need a max of 200 range for any moving unit if it can go off map, even less if it can't. 300 range should be map-sized most of the time too and best suited for units like the Bertha which don't need this API due to being stationary and having indirect line of sight, being mortar like, or other such units which use [[GetMaxCreeperCell]] or [[GetMaxCreeperCellWithDamage]] instead of this far more expensive API.  For additional reference, do not use this API for a unit with a range more than 200. Any much higher and this API on it's own even when called by a single unit has enough performance impact to cause a noticeable stutter. Besides, you should only really need a max of 200 range for any moving unit if it can go off map, even less if it can't. 300 range should be map-sized most of the time too and best suited for units like the Bertha which don't need this API due to being stationary and having indirect line of sight, being mortar like, or other such units which use [[GetMaxCreeperCell]] or [[GetMaxCreeperCellWithDamage]] instead of this far more expensive API. 
Line 20: Line 22:
 <code 4rpl> <code 4rpl>
 RefreshUnitLOSCache(self) RefreshUnitLOSCache(self)
 +</code>
 +<code 4rpl>
 +#This unit doesn't have range set within the CPACK manager.
 +$RANGE:30
  
 +:Once
 + SetUnitRange(self <-RANGE) #This must be before LOSCache!
 + RefreshUnitLOSCache(self)
 </code> </code>
 <=[[4rpl:start| Index]] <=[[4rpl:start| Index]]
  
4rpl/commands/refreshunitloscache.1648013391.txt.gz · Last modified: 2022/03/23 01:29 by Vertu