clkgtr wrote:Hi there,
recently I am making an loco, as the functions of the loco become more and more, the script is larger and larger.
But if I put many locos in the scenario ,the FPS will drop very low.
So I wonder if there is any way to make the engine script only used for Player controlled train,not usable for AI train.
I once wrote in the script like this
Code: Select all
function Update (time)
if (Call( "GetIsPlayer" ) == 1 then
...................
engine script
......................
end
end
But this caused the player controlled train's script is not usable either.
so could someone please point out where I was wrong in the script
or is there any good idea?
Thanks
Good evening,
You can further reduce script overhead in the AI case with the call "GetIsNearCamera" recently documented by DTG. When the camera is far (by how much, I don't know, but it looks to be more than enough in practice) the call returns 0 and the far away vehicles scripting can be avoided.
Also in some case, it can be beneficial to differenciate the trailing vehicles of a player train from the driven vehicle of a player train by using the GetIsEngineWithKey call.
You our Update() function would therefore look like this:
Code: Select all
function Update(time)
local with_key = Call("GetIsEngineWithKey") == 1
local player = (with_key and Call("GetIsPlayer") == 1)
local is_near = Call("GetIsNearCamera") == 1
if with_key and player then
-- driven vehicle of a player train
elseif player then
-- trailing vehicle of a player train
elseif is_near then
-- pure AI vehicle near the player camera
end
end
Depending on the situation, you can get a substential increase in performance by using "GetIsNearCamera". For instance on a london to brighton scenario with 30+ AI trains a was able to get a performance increase from 27 fps to 30 fps at scenario start just by using the GetIsNearcamera call on the Class 377 scripts.
Also avoiding unnecessary Call() can help a bit.
I hope this helps
Regards,