RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.engine.GameEngine Class Reference
Inheritance diagram for com.runehive.game.engine.GameEngine:
Collaboration diagram for com.runehive.game.engine.GameEngine:

Public Member Functions

 GameEngine ()

Static Public Member Functions

static int clientTicksToMillis (final int clientTicks)
static int clientTicksToServerTicks (final int clientTicks)
static int millisToTicks (final int millis)

Static Public Attributes

static final int TICK_MILLIS = 600

Protected Member Functions

void runOneIteration ()
Scheduler scheduler ()
String serviceName ()

Private Attributes

final ClientSynchronizer synchronizer

Static Private Attributes

static final Logger logger = LogManager.getLogger(GameEngine.class)

Detailed Description

Definition at line 22 of file GameEngine.java.

Constructor & Destructor Documentation

◆ GameEngine()

com.runehive.game.engine.GameEngine.GameEngine ( )

Definition at line 47 of file GameEngine.java.

47 {
48 synchronizer = (Config.PARALLEL_GAME_ENGINE ? new ParallelClientSynchronizer() : new SequentialClientSynchronizer());
49 }

References com.runehive.Config.PARALLEL_GAME_ENGINE, and synchronizer.

Member Function Documentation

◆ clientTicksToMillis()

int com.runehive.game.engine.GameEngine.clientTicksToMillis ( final int clientTicks)
static

Definition at line 30 of file GameEngine.java.

30 {
31 return clientTicks * 20;
32 }

Referenced by clientTicksToServerTicks().

Here is the caller graph for this function:

◆ clientTicksToServerTicks()

int com.runehive.game.engine.GameEngine.clientTicksToServerTicks ( final int clientTicks)
static

Definition at line 34 of file GameEngine.java.

34 {
35 return millisToTicks(clientTicksToMillis(clientTicks));
36 }

References clientTicksToMillis(), and millisToTicks().

Referenced by com.runehive.game.world.entity.combat.projectile.CombatProjectile.getServerTicks(), com.runehive.game.world.entity.combat.strategy.npc.NpcMagicStrategy.sendProjectile(), and com.runehive.game.world.entity.combat.strategy.npc.NpcRangedStrategy.sendProjectile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ millisToTicks()

int com.runehive.game.engine.GameEngine.millisToTicks ( final int millis)
static

Definition at line 26 of file GameEngine.java.

26 {
27 return millis / TICK_MILLIS;
28 }

References TICK_MILLIS.

Referenced by clientTicksToServerTicks().

Here is the caller graph for this function:

◆ runOneIteration()

void com.runehive.game.engine.GameEngine.runOneIteration ( )
protected

Definition at line 52 of file GameEngine.java.

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 }

References com.runehive.util.Stopwatch.elapsedTime(), com.runehive.game.world.entity.MobList< E extends Mob >.forEach(), com.runehive.game.world.World.get(), com.runehive.game.world.World.getNpcs(), com.runehive.game.world.World.getPlayers(), logger, com.runehive.util.Stopwatch.reset(), com.runehive.game.world.entity.mob.npc.Npc.sequence, com.runehive.Config.SERVER_DEBUG, com.runehive.util.Stopwatch.start(), synchronizer, and com.runehive.content.writer.InterfaceWriter.write().

Here is the call graph for this function:

◆ scheduler()

Scheduler com.runehive.game.engine.GameEngine.scheduler ( )
protected

Definition at line 140 of file GameEngine.java.

140 {
141 return Scheduler.newFixedRateSchedule(0, TICK_MILLIS, TimeUnit.MILLISECONDS);
142 }

References TICK_MILLIS.

◆ serviceName()

String com.runehive.game.engine.GameEngine.serviceName ( )
protected

Definition at line 43 of file GameEngine.java.

43 {
44 return "GameThread";
45 }

Member Data Documentation

◆ logger

final Logger com.runehive.game.engine.GameEngine.logger = LogManager.getLogger(GameEngine.class)
staticprivate

Definition at line 38 of file GameEngine.java.

Referenced by runOneIteration().

◆ synchronizer

final ClientSynchronizer com.runehive.game.engine.GameEngine.synchronizer
private

Definition at line 40 of file GameEngine.java.

Referenced by GameEngine(), and runOneIteration().

◆ TICK_MILLIS

final int com.runehive.game.engine.GameEngine.TICK_MILLIS = 600
static

Definition at line 24 of file GameEngine.java.

Referenced by millisToTicks(), and scheduler().


The documentation for this class was generated from the following file: