Transport Fever 2

Transport Fever 2

AI Builder
Payzman 27 Jun, 2022 @ 2:08am
ModelRepLookup is sometimes missing models
So I have not really looked deeper into this, but sometimes the model rep lookup in the vehicleutil script seems to be missing some models after discovering the vehicles. The vehicleUtil.getTopSpeed method seems to often have that problem.

I couldn't find any super-obvious issues with the discoverVehicle method, however I have an alternate idea for implementation (possibly). Maybe just cache the vehicles on the go (idk if that has a big impact on performance - not a lua expert by a long shot)

function vehicleUtil.safeModelLookup(modelId) local vehicle = vehicleUtil.modelRepLookup[modelId] if not vehicle then vehicle = api.res.modelRep.get(modelId) -- if it's nil now something is really broken :/ vehicleUtil.modelRepLookup[modelId] = vehicle end end
< >
Showing 1-1 of 1 comments
okeating  [developer] 28 Jun, 2022 @ 12:30pm 
I had a lot of trouble with the modelRep early on, basically calling into it frequently resulted in game freezing and unexplained crash to desktop. I have a feeling that calling into the api is implemented by copying all the underlying objects. I am a java developer by trade and I find it hard to get my head around the idea that the default behaviour of C++ is to copy all its objects unless you explicitly pass it as a pointer. I am sure it creates a lot of wasted cpu cycles.

I think the problem with the missing models is that I have tried to do an ad-hoc filter on climate, there doesn't seem to be anything in the api that lists the "vehicle sets" and the model rep (interestingly not the mu rep) contains all vehicles, and I wanted to respect the climate restrictions when in force.
I have now changed the implementation though so that it will store all vehicles but just keeps a separate set of the filtered.
Interestingly the code snippet above has been in place for a few days already although the problem is that its not just the models but I use it to gather a lot of the cargo data which otherwise requires a lot of looping over compartments and so on, and because the ai builder inspects every possible consist that can quickly add up.
< >
Showing 1-1 of 1 comments
Per page: 1530 50