Thread: [PI] Game engine removed - Grahams Task Scheduler added

Results 1 to 7 of 7
  1. #1 [PI] Game engine removed - Grahams Task Scheduler added 
    Banned
    Join Date
    Oct 2012
    Posts
    103
    Thanks given
    0
    Thanks received
    14
    Rep Power
    0
    Hello. Today I removed my old Hyperion Game engine because I had some issues with it. I added Grahams Task Scheduler instead.

    But I have a question!
    Since I made the main server processes run using the Task sheduler, i removed the catch exception in the main method. So it looked like this:
    Code:
    		scheduler.schedule(new Task() {
    			@Override
                        protected void execute() {
                            itemHandler.process();
                            playerHandler.process();	
                            npcHandler.process();
                            shopHandler.process();
                            CycleEventHandler.getSingleton().process();
                            objectManager.process();
                            fightPits.process();
    						CastleWars.process();
    						pJClans.process();
    						PublicEvent.process();
    						miniGames();
                            }
                 });
    But when I use this, the server never prints out Debug. So I added the Debug to the task from my old PI, so it looks like this:
    Code:
    		scheduler.schedule(new Task() {
    			@Override
                        protected void execute() {
    
    						try {
                                                            if (sleepTime > 0)
    							Thread.sleep(sleepTime);
    						} catch (Exception ex) {
    							ex.printStackTrace();
    							System.out.println("A fatal exception has been thrown!");
    						for(Player p : PlayerHandler.players) {
    							if(p == null)
    								continue;						
    							PlayerSave.saveGame((Client)p);
    							System.out.println("Saved game for " + p.playerName + ".");
    							}
    						}
    						engineTimer.reset();
                            itemHandler.process();
                            playerHandler.process();	
                            npcHandler.process();
                            shopHandler.process();
                            CycleEventHandler.getSingleton().process();
                            objectManager.process();
                            fightPits.process();
    						CastleWars.process();
    						pJClans.process();
    						PublicEvent.process();
    						miniGames();
    						cycleTime = engineTimer.elapsed();
    						if(cycleTime < 575)
    						sleepTime = cycleRate - cycleTime;
    							else
    						sleepTime = 0;
    						cycleTime = engineTimer.elapsed();				
    						sleepTime = cycleRate - cycleTime;
    						totalCycleTime += cycleTime;
    						cycles++;
    						debug();
    				}
                 });
    And it works perfectly. It now prints out debug.

    But I have a very important question. I had to add a catch since there's a Thread that's set to sleep in the task, have I done it wrong?
    Look at the red part.
    Should the catch be added before the task?
    Or should it be within the task, but catch everything? Like:
    Code:
    		scheduler.schedule(new Task() {
    			@Override
                        protected void execute() {
    						try {
    						if (sleepTime > 0)
    							Thread.sleep(sleepTime);
    													engineTimer.reset();
                            itemHandler.process();
                            playerHandler.process();	
                            npcHandler.process();
                            shopHandler.process();
                            CycleEventHandler.getSingleton().process();
                            objectManager.process();
                            fightPits.process();
    						CastleWars.process();
    						pJClans.process();
    						PublicEvent.process();
    						miniGames();
    						cycleTime = engineTimer.elapsed();
    						if(cycleTime < 575)
    						sleepTime = cycleRate - cycleTime;
    							else
    						sleepTime = 0;
    						cycleTime = engineTimer.elapsed();				
    						sleepTime = cycleRate - cycleTime;
    						totalCycleTime += cycleTime;
    						cycles++;
    						debug();
    						} catch (Exception ex) {
    							ex.printStackTrace();
    							System.out.println("A fatal exception has been thrown!");
    						for(Player p : PlayerHandler.players) {
    							if(p == null)
    								continue;						
    							PlayerSave.saveGame((Client)p);
    							System.out.println("Saved game for " + p.playerName + ".");
    							}
    						}
    				}
                 });
    Or is it fine the way I've done it? I'm fairly bad with threads and I know that they can cause deadlocks that's why I'm asking someone with some knowledge if it's done correctly.
    Thanks!
    Reply With Quote  
     

  2. #2  
    Super Donator

    Batukka's Avatar
    Join Date
    Oct 2011
    Posts
    2,433
    Thanks given
    86
    Thanks received
    342
    Rep Power
    496
    Lol the tick runs every 600ms and you're sleeping it? why ?
    Reply With Quote  
     

  3. #3  
    Banned
    Join Date
    Oct 2012
    Posts
    103
    Thanks given
    0
    Thanks received
    14
    Rep Power
    0
    Quote Originally Posted by Bitj View Post
    Lol the tick runs every 600ms and you're sleeping it? why ?
    That's how it is in original PI to..?

    I'm just wondering if I've added the catch exception correctly.

    If you know any other way to make the debug work then feel free to post !
    Reply With Quote  
     

  4. #4  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    why don't you crash the server and see for yourself
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    Oct 2012
    Posts
    103
    Thanks given
    0
    Thanks received
    14
    Rep Power
    0
    Quote Originally Posted by Harlan View Post
    why don't you crash the server and see for yourself
    How would I do that?
    Reply With Quote  
     

  6. #6  
    q.q


    Join Date
    Dec 2010
    Posts
    6,519
    Thanks given
    1,072
    Thanks received
    3,535
    Rep Power
    4752
    dividing by zero is always fun
    Reply With Quote  
     

  7. #7  
    Banned
    Join Date
    Oct 2012
    Posts
    103
    Thanks given
    0
    Thanks received
    14
    Rep Power
    0
    Diving by zero made the server crash and catch exception.

    But that wasn't the problem - the problem is that I don't know what to catch exception of.
    Should i catch it like this:
    Code:
    		scheduler.schedule(new Task() {
    			@Override
                        protected void execute() {
    						try {
    						if (sleepTime > 0)
    					//	sleepTime = sleepTime / 0; Crash
    						Thread.sleep(sleepTime);
    						engineTimer.reset();
    						itemHandler.process();
                            playerHandler.process();	
                            npcHandler.process();
                            shopHandler.process();
                            CycleEventHandler.getSingleton().process();
                            objectManager.process();
                            fightPits.process();
    						CastleWars.process();
    						pJClans.process();
    						PublicEvent.process();
    						miniGames();
    						cycleTime = engineTimer.elapsed();
    						if(cycleTime < 575)
    						sleepTime = cycleRate - cycleTime;
    							else
    						sleepTime = 0;
    						cycleTime = engineTimer.elapsed();				
    						sleepTime = cycleRate - cycleTime;
    						totalCycleTime += cycleTime;
    						cycles++;
    						debug();
    						} catch (Exception ex) {
    							ex.printStackTrace();
    							System.out.println("A fatal exception has been thrown!");
    						for(Player p : PlayerHandler.players) {
    							if(p == null)
    								continue;						
    							PlayerSave.saveGame((Client)p);
    							System.out.println("Saved game for " + p.playerName + ".");
    							System.exit(0);
    							}
    						}
    					}
    				});
    (The entire task)
    Or just the thread sleep?
    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

Similar Threads

  1. Replies: 67
    Last Post: 01-24-2013, 10:26 PM
  2. 2D Game Engine - EXAMPLE
    By Nikki in forum Application Development
    Replies: 4
    Last Post: 06-15-2011, 10:23 AM
  3. game engine
    By Mr Reece in forum Help
    Replies: 0
    Last Post: 11-07-2010, 09:06 AM
  4. Random Game on Panda3D Game Engine
    By MH-60S in forum Application Development
    Replies: 2
    Last Post: 10-23-2010, 08:32 PM
  5. Replies: 0
    Last Post: 03-26-2010, 05:54 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •