why have all of your variables static?
|
|

alright if i leave it on a 500 , 1000 , 1500 , 2000, 2500 , 3000 TICK etc..
then it works perfectly fine the way i want it.
however if i tried doing any number that isn't in an increment of 500 it gets all messed up and isn't providing the numbers i desire.
basically i made this so all things processed would go accuratly on a tick instead of being for example with 500
496 504 502 497 492 500 502 498
itll be
500 500 500 500 500 500 500 500
you can run it on 500 and then run it on 600 to see what i mean.
Example Code Of What It Does.Code:public class Process extends Thread { private static final double TICK = 500.0; private static long currentTime; private static long firstTime; private static long lastTime; private static long lastTime2; private static Process process; private static boolean notShutdown = true; public static void main(String[] s) { process = new Process(); } private Process() { new Thread(this).start(); } public void run() { firstTime = System.currentTimeMillis(); while (notShutdown) { /*Start Of Process*/ sendMessage(); /*End Of Process*/ currentTime = System.currentTimeMillis(); double sleep = ((currentTime - firstTime) / (TICK)); int sleep2 = (int)((sleep - ((int) sleep)) * (TICK)); System.out.println("Time: "+(currentTime - firstTime)+" sleep: "+(int)((TICK)-sleep2)+" sleep1: "+sleep+" sleep2: "+sleep2); try { Thread.sleep((int)(TICK) - sleep2); } catch (Exception e){ } } } private static void sendMessage() { lastTime = System.currentTimeMillis() - firstTime; System.out.println("Time: "+(lastTime)+" DIF: "+(lastTime - lastTime2)); lastTime2 = lastTime; } }
Code:Time: 142000 DIF: 500 Time: 142000 sleep: 500 sleep1: 284.0 sleep2: 0 Time: 142500 DIF: 500 Time: 142609 sleep: 391 sleep1: 285.218 sleep2: 109 Time: 143000 DIF: 500 Time: 143094 sleep: 407 sleep1: 286.188 sleep2: 93 Time: 143500 DIF: 500 Time: 143500 sleep: 500 sleep1: 287.0 sleep2: 0 Time: 144000 DIF: 500 Time: 144000 sleep: 500 sleep1: 288.0 sleep2: 0 Time: 144500 DIF: 500 Time: 144500 sleep: 500 sleep1: 289.0 sleep2: 0 Time: 145000 DIF: 500 Time: 145000 sleep: 500 sleep1: 290.0 sleep2: 0 Time: 145500 DIF: 500 Time: 145500 sleep: 500 sleep1: 291.0 sleep2: 0 Time: 146000 DIF: 500

You sure you are ment to be taking away var sleep from itself?Code:int sleep2 = (int)((sleep - ((int) sleep)) * (TICK));
I know you are rounding it by casting it to int but then you are left withI don't understand what you are trying to do.Code:(< 1) * TICK
Im assuming you are trying to do something like;
Code:long startTime = 0; long processStart = 0; long processFinish = 0; long elapsed = 0; public void run() { startTime = System.currentTimeMillis(); while (running) { elapsed = System.currentTimeMillis() - startTime; processStart = System.currentTimeMillis(); sendMessage(); processFinish = System.currentTimeMillis(); long processTime = (processFinish - processStart); int sleep = (int) (TICK - processTime); try { Thread.sleep(sleep); } catch(Exception e) { e.printStackTrace(); } } }

Well in most servers iv'e downloaded when u do somthing every 600ms
its like
594 598 593 599 600 601 595 604 616 584
etc.. so its not always on a 600 mark even if your minus i have it checking the first time the loop was created and then minus's all that stuff now
running on a 500ms tick it works perfectly however... if i put it on a 600ms tick i start getting the following.
600 16 594 16 578 16 609 or somthing like that.. either way the only the 1st part works.
-------------------------------------
I basically just want a server tick that will be accurate and not somthing where it ticks every 600ms but the actual difference between ticks is 600ms for each thing being processed because it really isn't accurately 600ms its a few numbers less or few number more even if you sleep it correctly.
Running the program on a 500ms tick works out perfectly if you want to see what i mean.
Are you serious?

meh forget it i'll just study a bunch of different timer related things till i find somthing that keeps the DIF at 600
This is the above post. the difference is when the sendmessage is told to print out.
the below pretty much represents like all servers thats why i wanna try fixin this issue.
so it'll be 600 600 600 600 every time.
Code:Time: 0 DIF: 0 Time: 609 DIF: 609 Time: 1203 DIF: 594 Time: 1797 DIF: 594 Time: 2406 DIF: 609 Time: 3000 DIF: 594 Time: 3609 DIF: 609 Time: 4203 DIF: 594 Time: 4812 DIF: 609 Time: 5406 DIF: 594 Time: 6000 DIF: 594 Time: 6609 DIF: 609 Time: 7203 DIF: 594 Time: 7812 DIF: 609 Time: 8406 DIF: 594 Time: 9015 DIF: 609 Time: 9609 DIF: 594 Time: 10219 DIF: 610 Time: 10812 DIF: 593 Time: 11406 DIF: 594 Time: 12015 DIF: 609 Time: 12609 DIF: 594 Time: 13219 DIF: 610 Time: 13812 DIF: 593 Time: 14422 DIF: 610

You need to use a CYCLE BASED event manager.
| « 2D MMO [Apply now] need developers | PHP doesn't get the spaces? (Read) » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |