Dynamic diesel smoke

Discuss anything related to Train Simulator from DoveTail that does not fit in one of the more specific categories.

Re: Dynamic diesel smoke

Postby cjbarnes5294 » Thu May 22, 2014 6:19 pm

Matt, I'll try and post some suggestions on how you could do the spool up this evening. :)

Chris
The Red Queen Hypothesis, applicable to train sim development?

"Here, you see, it takes all of the running you can do, to keep the same place."
cjbarnes5294
Driver
 
Posts: 398
Images: 82
Joined: Mon Mar 31, 2014 12:40 pm
Location: Gloucestershire/North Yorkshire
Has thanked: 551 times
Been thanked: 187 times

Re: Dynamic diesel smoke

Postby deltic009 » Thu May 22, 2014 7:03 pm

cjbarnes5294 wrote:Matt, I'll try and post some suggestions on how you could do the spool up this evening. :)

Chris

Aww top man, to me that is the key part of clagging, and we have the audio version that just needs the exhaust..I'm sure you know better than me the better values to take from the sim to ensure this only happens at the right moments.

Thanks for your kind offer of help.
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

Re: Dynamic diesel smoke

Postby AndiS » Thu May 22, 2014 7:32 pm

Will be overpowered by the solution Chris is about to prepare, still I need to chime in, saying that you do the whole business in function Upgrade that has parameter time, giving the seconds since last call to it. So dividing the change in RPM by this time gives you RPM change per second which you can map to a colour range after you found out what the values for it are in practice.
Code: Select all
thisRPM = Call("*:GetControlValue", "RPM", 0);
if lastRPM ~= nil then -- if we stored RPM before
   RPMdiff = (thisRPM - lastRPM)/time
   if RPMdiff < 0 then
      RPMdiff = 0 -- don't accept negative numbers, on RPM decrease just do nothing special
   elseif RPMdiff > maxRPMdiff then
      RPMdiff = maxRPMdiff -- set some maximum so you are sure about the value range you get
   end
   volume = RPMdiff * someScalingFactor
end
lastRPM = thisRPM

volume could be a colour of an extra emitter just showing the increase of RPM, or it could be the amount of whatever be added to an existing emitter. Here, I really must hand over to those with the more proven ideas. Just could not hold back in this rave or ideas.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Dynamic diesel smoke

Postby cjbarnes5294 » Thu May 22, 2014 10:59 pm

I was actually thinking of suggesting more or less what you've done, Andi. :D I believe there is a control called DeltaRPM but I don't know if it returns what it says on the tin, so I was thinking of working out if the RPM has changed with the script anyway.

However, I'm a bit knackered tonight and just about to turn in, so I'll put up some more details tomorrow, Matt, if that's ok?

Chris
The Red Queen Hypothesis, applicable to train sim development?

"Here, you see, it takes all of the running you can do, to keep the same place."
cjbarnes5294
Driver
 
Posts: 398
Images: 82
Joined: Mon Mar 31, 2014 12:40 pm
Location: Gloucestershire/North Yorkshire
Has thanked: 551 times
Been thanked: 187 times

Re: Dynamic diesel smoke

Postby deltic009 » Fri May 23, 2014 1:46 am

cjbarnes5294 wrote:I was actually thinking of suggesting more or less what you've done, Andi. :D I believe there is a control called DeltaRPM but I don't know if it returns what it says on the tin, so I was thinking of working out if the RPM has changed with the script anyway.

However, I'm a bit knackered tonight and just about to turn in, so I'll put up some more details tomorrow, Matt, if that's ok?

Chris

Whenever you have time is fine, it will be a slow process for me anyway. Thanks for taking the time to consider helping out.
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

Re: Dynamic diesel smoke

Postby AndiS » Fri May 23, 2014 7:44 am

I had some more ideas. Please note that the code below is a sketch.

  • I formulated the mixing of two colours in a way that will please the programming teachers. The logic is isolated in function blendExhaust and could be expanded to a mix between three colours if there is interest in it.
  • I found MaxRpmChangePerSecond in the simulation blueprint which ought to be the practical limit of the RPM change per second calculated in the script. So dividing the RPM change found by this maximum will yield a number between 0 and 1 suitable for the colour mix.
  • Setting lastRPM to zero makes an if statement in Update obsolete which is always a good thing.
  • RPMdiff now maps the difference of thisRPM and lastRPM to the range of 0 to 1 in one step, shortening the code.

Code: Select all
-- the following can be anywhere in the code, outside all functions
-- preferably at the top where it is easily found and modified
red1 = 0.5
green1 = 0.5
blue1 = 0.5

red2 = 0
green2 = 0
blue2 = 1

MaxRpmChangePerSecond = 50 -- copied from engine simulation file
lastRPM = 0 -- hack to simplify the code in Update which is performed often

-- the following isolates the colour mixing in a separate function
function blendExhaust (mix) -- mix = 0 -> only colour 1; mix = 1 -> only colour 2; mix = 0.5 -> half and half
   local red = red1 * (mix - 1) + red2 * mix
   local green = green1 * (mix - 1) + green2 * mix
   local blue = blue1 * (mix - 1) + blue2 * mix
   Call ("EmitterName:SetEmitterColour", red, green, blue)
end

-- the following is only a fragment of Update, of course
function Update (time)
   thisRPM = Call("*:GetControlValue", "RPM", 0);
   RPMdiff = (thisRPM - lastRPM)/ time / MaxRpmChangePerSecond
   lastRPM = thisRPM
   if RPMdiff < 0 then
      RPMdiff = 0 -- don't accept negative numbers, on RPM decrease just do nothing special
   elseif RPMdiff > 1 then
      RPMdiff = 1 -- set maximum to 1 as this is the maximum input blendExhaust accepts
               -- if MaxRpmChangePerSecond is right, this case will not occur, but who knows ...
   end
   blendExhaust (RPMdiff)
end
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Dynamic diesel smoke

Postby cjbarnes5294 » Sun May 25, 2014 3:38 pm

Andi has very kindly saved me alot of time by coming up with something else I don't think I can improve on, although I may expand upon the blending code. :D Very sorry that I haven't got anything down yet, it's finding the time that's the problem, with several exams over the next couple of weeks. :(

Chris
The Red Queen Hypothesis, applicable to train sim development?

"Here, you see, it takes all of the running you can do, to keep the same place."
cjbarnes5294
Driver
 
Posts: 398
Images: 82
Joined: Mon Mar 31, 2014 12:40 pm
Location: Gloucestershire/North Yorkshire
Has thanked: 551 times
Been thanked: 187 times

Re: Dynamic diesel smoke

Postby AndiS » Sun May 25, 2014 4:12 pm

Glad I left something for you to expand on.
Don't forget that this is all theory, too. Getting it to work can be "fun" still.
But I don't want to take any blame for your exam results, so I will certainly wait patiently, in particular for the coming two weeks that will see me far from RW, so no practical experimenting for me for sure.
AndiS
Top Link Driver!
 
Posts: 736
Joined: Wed Apr 09, 2014 5:48 pm
Has thanked: 268 times
Been thanked: 308 times

Re: Dynamic diesel smoke

Postby deltic009 » Mon May 26, 2014 10:54 am

AndiS wrote:Glad I left something for you to expand on.
Don't forget that this is all theory, too. Getting it to work can be "fun" still.
But I don't want to take any blame for your exam results, so I will certainly wait patiently, in particular for the coming two weeks that will see me far from RW, so no practical experimenting for me for sure.

Thanks for your help both. This is entirely alien to me, so just copying and pasting successfully may prove a challenge to me - but I'm sure like with things like decals etc the community can drag me through to full speed in no time.
deltic009
Full Time Fireman
 
Posts: 62
Joined: Mon Apr 14, 2014 12:52 pm
Has thanked: 16 times
Been thanked: 34 times

Re: Dynamic diesel smoke

Postby JamesLit » Mon Jun 02, 2014 12:14 pm

Sorry I've seemingly disappeared off the face of the earth! I returned last night from my "honeymoon" after getting married on the 24th and being away for about 10 days or so. I've decided to get my priorities right so will be dealing with other things before returning to this - but I would like to thank you guys for perpetuating the conversation with your ideas and help. :D
The Forge Simulation | Like us on Facebook!
Owner & Director | Content built with care, not compromises.
User avatar
JamesLit
Driver
 
Posts: 370
Images: 26
Joined: Mon Apr 07, 2014 3:26 pm
Location: Kent
Has thanked: 433 times
Been thanked: 141 times

PreviousNext

Return to Train Simulator Mess Room

Who is online

Users browsing this forum: No registered users and 2 guests