current_speed callbacks in NML

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
Ruiluth
Engineer
Engineer
Posts: 36
Joined: 24 Jun 2013 02:13
Location: Orbitting Jool

current_speed callbacks in NML

Post by Ruiluth » 04 Feb 2019 04:38

As an experiment, I created a locomotive whose power and tractive effort vary with its speed, as described herel. (TL;DR, a steam locomotive is a constant force machine up to a certain speed, and after that becomes a constant power machine.) However, something I'm noticing in tests is that the tractive effort and power don't update during running. Running cost does as it should, but for some reason, power and tractive effort are frozen at their 0 mph levels from the moment it leaves the depot until it returns. Is this just a quirk of NML or OpenTTD, or is there something I can do to make this work?

User avatar
Gwyd
Chief Executive
Chief Executive
Posts: 692
Joined: 17 Apr 2017 16:52
Location: Western Ile-de-France Region

Re: current_speed callbacks in NML

Post by Gwyd » 04 Feb 2019 06:04

I've done a test on this before, and found that certain properties change instantaneously, but some only change when the train is interacted with. For example I set a train to change graphics by speed, and that worked fine.

Then I coded it to have 0 power after it reached a certain speed. This didn't work, the power only changing after it moved to a different railtype or it was told to stop/start. There may be other triggers I don't know about but there are some properties that can't change on the fly effectively; length, power, capacity etc

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9278
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: current_speed callbacks in NML

Post by planetmaker » 04 Feb 2019 09:06

Ruiluth wrote:As an experiment, I created a locomotive whose power and tractive effort vary with its speed, as described herel. (TL;DR, a steam locomotive is a constant force machine up to a certain speed, and after that becomes a constant power machine.) However, something I'm noticing in tests is that the tractive effort and power don't update during running. Running cost does as it should, but for some reason, power and tractive effort are frozen at their 0 mph levels from the moment it leaves the depot until it returns. Is this just a quirk of NML or OpenTTD, or is there something I can do to make this work?
:) You are reverse-engineering when OpenTTD runs the callbacks. Generally: they are only run when appropriate - they are computationally expensive. Thus different callbacks are triggered by different situations or situation changes only, some are called regularily every X game ticks..

Not all properties can change at all times - by design. In other words: a callback needs being called to take any effect - and not every callback is called at all times, but only when OpenTTD calls it upon the vehicle

Properties affecting the motor of a vehicle only can change when in depot or when the tracktype changes. A running vehicle neither realistically nor ingame can change its maximum power, its tractive effort, etc when it is running - it is an inherent property determined by the motor and the environment - both do not change. It's OpenTTD's job to take the vehicle properties and move it according to that. And that includes limiting acceleration by either available power or tractive effort. IIRC that's already done - for ages. See https://wiki.openttd.org/Tractive_Effort and links therein.

Similarily, the cargo capacity can and will only change in depot and in stations. Similar arguments go for other properties and related callbacks.

Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest