Moved this to its own thread...
When using CASM with the save on reach location, the game stutters pretty bad. Turn it off and it's nice and smooth again. So I looked at the scripts - here's the key part of the main script for that function:
[quote]
if CASMSaveLocationsReached > 0
let rTemp := Call CASMFindNearestMarkerFunction ar_markers
if rTemp != rLastMarker && (rTemp != 0 && rLastMarker != 0)
dbprintc "CASM: Location Reached Save"
let bSave := CASMSaveLocationsReached
endif
endif[/quote]
And here's the function:
[quote]scn CASMFindNearestMarkerFunction
ref rMarker
array_var ar_markers
array_var ar_element
BEGIN Function {ar_markers}
if eval ar_markers != ar_Null
ForEach ar_element <- ar_markers
let rMarker := ar_element["value"]
if IsFormValid rMarker
if rMarker.gbo == MapMarker
let rMarker := ar_element["value"]
if (Player.GetDistance rMarker) <= 2000 && rMarker.GetMapMarkerVisible == 2
; printc "CASM: Marker in range and found, %i" rMarker
SetFunctionValue rMarker
Break
endif
endif
endif
Loop
endif
END[/quote]
First off, there's a deprecated call in the main script:
[quote]
if Player.IsInInterior == 0
if rPrevCell != Player.GetParentCell
let rPrevCell := Player.GetParentCell
let ar_markers := GetCellRefs 32 2
dbprintc "CASM: Changed cell, updating map marker list: Current cell is %n" rPrevCell
endif
endif[/quote]
[quote](array) GetCellRefs typeID:int celldepth:int includeTaken:bool targetCell:cell (deprecated by GetRefs/GetRefsInCell in NVSE 4.5.7)
Replaces ref-walking loops with a single function call that returns an array_var of refs in a cell. If no cell is specified, the player's current cell is used.[/quote]
I don't think that's the cause of the stutter, but it really should be updated to use the NVSE function. In fact, if that's the only Lutana call, Lutana could be eliminated as a depency.
The stutter is probably in finding the closest marker to the player. The function looks through all the static refs around the player. If the ref is a MapMarker, then it checks the distance to the player. it does this every time for every static ref. This is ridiculously heavy on computation unless you just happen to be in an area with few statics.
One way to help this would be to change the routine in the main script that gets the cell refs. After getting the refs, go through the list making a new list of ONLY MapMarker refs! There's no reason to go through EVERY ref every single time. Pare that list down to only those refs you care about. That alone may be enough to get rid of the stutter.
EDIT: Is there a code tag that actually WORKS on the forum? The "standard" code tag inserts visible html markers and tries to color code functions.

