jframe - Why is the proper conversion of nanoseconds to seconds changing in Java when I write to the console? -
I am currently clearing the loop of my game on time in Java, but I get second conversion with nanosecond.
For some reason when I do not write the nanoseconds passed in the console at one time delta (measured in seconds), then works well by dividing by 100,000,000. It seems to me that I have given 1000,000,000 nanoseconds in each other, so I tried to measure how many loops were running per second and printed in the console when it flies to above the required fps. The need for delta to be divided by 1000,000,000 has been slowed to reach this game at a very reasonable price due to completely unknown reasons. I'm totally lost, so why would it be so?
Below the loop, because it stands at present. When the "Comment Trigger" line has been commented, changing its "problem lines" work requires changing its value, which is why it is divided to convert it into appropriate units
while (isRunning) {now = System.nanoTime (); Delta = (Double) (Now - Last Exception Time) / 1000000000; // problem line timer + delta; TimerPlus + = delta; Tic ++; GamePanel.Update (Delta); Last exception date = system. Nanotime (); If (Tick / TimerPlus> 60) {System.out.println ("Fast"); // Problem triggers? } GamePlan. Render (Delta); Timer = 0; } Any other and all help would be greatly appreciated, this is just a plainly misleading issue, if the information is any help, then I will be able to see the JPanel
and Jefframe
, write and compile in an unconnected eclipse IDE. Edit: OK, after trying to work the code (all I did, check that I was back when this problem occurred
while (isRunning) {now = System.nanoTime () =) Delta = (double) (now - last exception time) / 1000000000; Timer + = delta; TimerPlus + = delta; Tic ++; GamePanel.Update (Delta); Last exception date = system. Nanotime (); If (Tick / TimerPlus> 120) {//System.out.println("wow "); } If (timer> = (double) 1 / tick_s_pace) {game panel.render (delta); Timer = 0; } If (TimerPlus> = 1) {System.out.println ("FPS:" + Tik); Ticks = 0; TimerPlus = 0; }}
Now they participate separately on the basis of whether the "Wow" line is commented or not, yet absolutely strange, but the difference from the clean version I was posted first and weird muscular I just hope the problem is easy to solve.
Since I can not comment due to my reputation, I will remove it from there, 1000000000 Try to do 10000000000 or 1000000000 L so that it is a long time. It may be small in an integer.
Besides, why do not you throw it in your thread? If it is running on EDT, it can explain why your program is slowing down.
Comments
Post a Comment