Outerra forum
Anteworld - Outerra Game => Modding: Importer, Tools & Utilities => Topic started by: mustang60348 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.
-
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
-
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.
-
One more question: Is it possible to print values to the console for testing
-
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)
-
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.
-
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
}
}
-
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.
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.
-
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.
-
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.
-
Try this code, i didn't test it yet...
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
-
Try this code, i didn't test it yet...
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
-
There are a few differences between engine types, try to use this:
var rpm = jsb['propulsion/engine[0]/propeller-rpm'];
-
That's why i love this engine and the guys here, So quick to answer questions.
-
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.
-
The best way how to find all these values is a look into JSBSim source code.
There is function bindmodel() in each class that maps variables to strings.
for FGTurboProp class there are:
propulsion/engine[0]/n1
propulsion/engine[0]/reverser
propulsion/engine[0]/power-hp
propulsion/engine[0]/itt-c
propulsion/engine[0]/engtemp-c
propulsion/engine[0]/ielu_intervent
+ common engine values
-
That is awesome, thanks.