Thread: this stupid thing doesn't want to work for me.

Results 1 to 7 of 7
  1. #1 this stupid thing doesn't want to work for me. 
    Banned

    Join Date
    Jan 2009
    Age
    28
    Posts
    2,662
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    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.

    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;
    	}
    }
    Example Code Of What It Does.

    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
    Reply With Quote  
     

  2. #2  
    Registered Member 7Swipe's Avatar
    Join Date
    Jul 2010
    Posts
    132
    Thanks given
    2
    Thanks received
    3
    Rep Power
    7
    why have all of your variables static?

    Quote Originally Posted by White Girl View Post
    like an ice cream and you want moar ice cream and you decide small potent of ice cream isn't enough so you get a fucking birthday cake and eat it all in one blink
    Reply With Quote  
     

  3. #3  
    Member Market Banned Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    29
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    Code:
    int sleep2 = (int)((sleep - ((int) sleep)) * (TICK));
    You sure you are ment to be taking away var sleep from itself?

    I know you are rounding it by casting it to int but then you are left with
    Code:
    (< 1) * TICK
    I don't understand what you are trying to do.

    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();
    		}
    	}
    }


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jan 2009
    Age
    28
    Posts
    2,662
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    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.


    Quote Originally Posted by 7Swipe View Post
    why have all of your variables static?
    Are you serious?
    Reply With Quote  
     

  5. #5  
    Member Market Banned Market Banned

    Zee Best's Avatar
    Join Date
    Feb 2007
    Age
    29
    Posts
    3,036
    Thanks given
    24
    Thanks received
    210
    Rep Power
    1171
    Then use my example above, that will make sure that it sleeps for the remainder of the tick time, try it.


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  6. Thankful user:


  7. #6  
    Banned

    Join Date
    Jan 2009
    Age
    28
    Posts
    2,662
    Thanks given
    66
    Thanks received
    207
    Rep Power
    0
    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
    Reply With Quote  
     

  8. #7  
    Banned

    Join Date
    Jul 2008
    Age
    26
    Posts
    5,826
    Thanks given
    1,301
    Thanks received
    197
    Rep Power
    0
    You need to use a CYCLE BASED event manager.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •