52 {
53 try {
54 final Stopwatch stopwatch = Stopwatch.start();
55 final Stopwatch stopwatch2 = Stopwatch.start();
56
57 World world = World.get();
58 MobList<Player> players = World.getPlayers();
59 MobList<Npc> npcs = World.getNpcs();
60
61 world.dequeLogins();
62
63 long elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
64 if (elapsed > 10 && Config.SERVER_DEBUG) {
65 System.out.printf("world.dequeLogins(): %d ms%n", elapsed);
66 }
67
68 stopwatch.reset();
69 world.dequeLogouts();
70 elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
71 if (elapsed > 10 && Config.SERVER_DEBUG) {
72 System.out.printf("world.dequeLogouts(): %d ms%n", elapsed);
73 }
74
75 stopwatch.reset();
76 npcs.forEach(npc -> new NpcPreUpdateTask(npc).run());
77 elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
78 if (elapsed > 10 && Config.SERVER_DEBUG) {
79 System.out.printf("NpcPreUpateTask: %d ms%n", elapsed);
80 }
81
82 stopwatch.reset();
83 players.forEach(player -> new PlayerPreUpdateTask(player).run());
84 elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
85 if (elapsed > 10 && Config.SERVER_DEBUG) {
86 System.out.printf("PlayerPreUpdateTask: %d ms%n", elapsed);
87 }
88
89 stopwatch.reset();
90 world.process();
91 elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
92 if (elapsed > 10 && Config.SERVER_DEBUG) {
93 System.out.printf("world.process(): %d ms%n", elapsed);
94 }
95
96 stopwatch.reset();
97 npcs.forEach(Npc::sequence);
98 elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
99 if (elapsed > 10 && Config.SERVER_DEBUG) {
100 System.out.printf("npc.sequence(): %d ms%n", elapsed);
101 }
102
103 stopwatch.reset();
104 players.forEach(player -> {
105 try {
106 player.sequence();
107 } catch (Exception ex) {
108 logger.error(String.format("error player.sequence(): %s", player), ex);
109 }
110 });
111 elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
112 if (elapsed > 10 && Config.SERVER_DEBUG) {
113 System.out.printf("player.sequence(): %d ms%n", elapsed);
114 }
115
116 stopwatch.reset();
117 try {
118 synchronizer.synchronize(players, npcs);
119 } catch (Exception ex) {
120 logger.fatal("Error in the main game sequencer.", ex);
121 }
122 elapsed = stopwatch.elapsedTime(TimeUnit.MILLISECONDS);
123 if (elapsed > 10 && Config.SERVER_DEBUG) {
124 System.out.printf("synchronizer.synchronize(): %d ms%n", elapsed);
125 }
126 players.forEach(player -> {
127 InterfaceWriter.write(new InformationWriter(player));
128 });
129
130 stopwatch.reset();
131 if (stopwatch2.elapsedTime(TimeUnit.MILLISECONDS) > 60 && Config.SERVER_DEBUG) {
132 System.out.printf("CYCLE END: %d ms%n", stopwatch2.elapsedTime(TimeUnit.MILLISECONDS));
133 }
134 } catch(Exception e) {
135 e.printStackTrace();
136 }
137 }