Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Outerra Tech Demo download. Help with graphics driver issues

Pages: [1] 2

Author Topic: Some questions about the engine  (Read 12853 times)

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Some questions about the engine
« on: November 26, 2012, 02:01:44 pm »

Hopefully these haven't been asked before

1) What is the update rate of the Javascript update function. If I want to create an animation based on time, what happens if the animation takes longer than the update rate.

2) Is it possible to 'destroy' an object in the game via JS, iow, lets say I put a missle on an aircraft and fire it off, can that object be removed from the game.

3) Is it possible to create custom animation like explosions etc.
« Last Edit: November 26, 2012, 02:03:50 pm by mustang60348 »
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Some questions about the engine
« Reply #1 on: November 26, 2012, 02:52:34 pm »

1) Refresh rate. Delta time from previous frame is in the first parameter.
2) Not yet, though you could hide it away somewhere.
3) No, needs particle effects
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #2 on: November 26, 2012, 03:36:33 pm »

Thanks.

For your answer to the second question: Does this mean the update function does not start till the previous one ends. OR is it on a timer of sorts.
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #3 on: November 26, 2012, 03:47:07 pm »

One more question: Is it possible to print values to the console for testing
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Some questions about the engine
« Reply #4 on: November 27, 2012, 01:20:37 am »

The update function is a part of the game loop, and you must not spend long time in there else you block the game.

To print something into console use this.log_err(string) or this.log_dbg(string) or this.log_inf(string)
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #5 on: November 27, 2012, 07:25:09 am »

hmmm. Is the update function on a timer or does it use an interupt system

let me give you some background for these questions. I have been employed working on a commercial simulator, in that system the system that we would call the game loop is on the interupt system that occurs every 33ms, iow, approx 33 times per second. Each process runs within that time frame OR it gets interupted by the next iteration of the loop and doesn't get to finish its execution.

This system though makes it easy to program timed events. The other thing we do is not everything runs EACH iteration. For example there is no need to run the fuel update calcs 33 times a second and ours only run every 3rd iteration and we use a delta time as well so that the fuel calcs stay accurate.

So my questions are just me trying to get a handle on how to use the 'game loop' effectively and to try not to run OUT OF TIME within the 'game loop'.

Within this environment (OUTERRA) , I think someone who is programming the instruments could easily code the instrument to only update every 3rd or 4th iteration thus preventing time overuns.

some generic code

Global Variable --> Loopcounter = 0

Game Loop

{

If LoopCounter = 4 then
{
    Run instrument Code
    LoopCounter = 0
}
else
{
     Increment LoopCounter
}

Now your instrument code would only run every 4th time the game loop starts.

This is just given for those that are concerned about the time inside the game loop. Instruments don't really need to be updated every time thru the loop and would update fine at say 10 or so times per second.
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #6 on: November 27, 2012, 07:41:01 am »

Another example for two instruments  you want to update , One every 3rd iteration and one every 5th iteration

In the INIT Function - Global Variable

Var LoopCounter = 0;

Update_Function
{
 LoopCounter++;

// Now the code for the instrument you want to run every 3rd iteration
if (LoopCounter % 3) = 0
{
    Run instrument Code for instrument every 3rd iteration
}

if (LoopCounter % 5) = 0
{
    Run instrument Code for instrument to run every 5th iteration
}

}
Logged

cameni

  • Brano Kemen
  • Outerra Administrator
  • Hero Member
  • *****
  • Posts: 6721
  • No sense of urgency.
    • outerra.com
Re: Some questions about the engine
« Reply #7 on: November 27, 2012, 07:45:04 am »

It's not "on timer", neither it is an interrupt. It's invoked from within the app loop that prepares stuff for rendering for given frame. We give you the delta time from previous frame, you can accumulate it and compute when you need to update some instruments, in a similar way as you have described.

Right now you never run out of time here because you simply block the rest of the system if you stay in that method too long. Rendering thread is decoupled, but once it runs out of work it will stop as well. So you still have to be careful how much of code you run here, and execute code that doesn't need a frequent updating only after some time.

Code: [Select]
var t=0;
var t2s=0;
function update_frame(dt) {
    t += dt;
    if(t > t2s+2) {
        //code that runs once in two seconds
        ....
        t2s = t;
    }
}

You can also count the loops, but the frame rate doesn't have to be stable.
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #8 on: November 27, 2012, 07:57:14 am »

Perfect, I made some code last night similar to what you presented to move an object every second.

I like to put this stuff in the forums for those that are going to come here later and perhaps are wondering how to cut down on the time in the loop.

I am getting my OV10 Bronco into the engine, have been coding the animations and it got me to thinking that perhaps we don't need to run the ROTATE PARTS functions ALL THE TIME, but only say 10 times per second. So your code would do the trick for that. This would save time in the loop and prevent issues from cropping up.
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #9 on: November 28, 2012, 08:02:53 am »

Would it be possible to get a code snipet of how to start 2 engines in JS. I have tried several things from the JSBSIM docs and nothing seems to work. I am not getting any errors but the second engine doesn't start and when I advance the throttles, the aircraft YAWS as it should with only one engine started.
Logged

angrypig

  • Sr. Member
  • ****
  • Posts: 454
Re: Some questions about the engine
« Reply #10 on: November 29, 2012, 04:17:55 am »

Try this code, i didn't test it yet...

Code: [Select]
   jsb["propulsion/engine[1]/set-running"] = 1; // start the second engine
   jsb["fcs/throttle-cmd-norm[1]"] = jsb["fcs/throttle-cmd-norm[0]"]; // set throttle for the second engine
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #11 on: November 29, 2012, 01:58:08 pm »

Try this code, i didn't test it yet...

Code: [Select]
   jsb["propulsion/engine[1]/set-running"] = 1; // start the second engine
   jsb["fcs/throttle-cmd-norm[1]"] = jsb["fcs/throttle-cmd-norm[0]"]; // set throttle for the second engine

That worked....of course this lead to another problem :), for some reason I changed to turboprop engines and my props aren't turning , I am assuming the value I am getting from the JSB engine is wrong, I am using engine rpm , I think turboprops use a different value to indicate speed
Logged

angrypig

  • Sr. Member
  • ****
  • Posts: 454
Re: Some questions about the engine
« Reply #12 on: November 29, 2012, 02:03:33 pm »

There are a few differences between engine types, try to use this:

Code: [Select]
var rpm = jsb['propulsion/engine[0]/propeller-rpm'];
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #13 on: November 29, 2012, 02:54:55 pm »

That's why i love this engine and the guys here, So quick to answer questions.
Logged

mustang60348

  • Member
  • **
  • Posts: 92
  • newbie
Re: Some questions about the engine
« Reply #14 on: November 30, 2012, 08:53:13 am »

I have the JSB Sim Reference and am looking for a list of all 'things' that are available to set OR read in JSBSIM

For example 'propulsion/engine[0]/propeller-rpm' <-- what other values like this can be read or written to. Is there a list, because it doesn't seem to be in the reference manual.
Logged
Pages: [1] 2