@@ -35,13 +35,14 @@ public class Rectangles extends PApplet {
3535 public static Spawn [] spawnPoints = new Spawn [2 ];
3636 public static Random generator = new Random ();
3737 public static int deathPoints = 0 ;
38- public static Timeline globalTimeline = new GlobalTimeline (1000 /60 );
38+ public static Timeline globalTimeline = new GlobalTimeline (1000 /144 );
3939 public static Timeline physicsTimeline = new LocalTimeline (globalTimeline , 1 );
40- public static Timeline networkTimeline = new LocalTimeline (globalTimeline , 1 );
41- public static Timeline renderTimeline = new LocalTimeline (globalTimeline , 1 );
40+ public static Timeline networkTimeline = new LocalTimeline (globalTimeline , 3 );
41+ public static Timeline renderTimeline = new LocalTimeline (globalTimeline , 3 );
4242 public static EventManager eventManager = new EventManager ();
43+ public static ExecutorService threadPool = Executors .newFixedThreadPool (NUM_THREADS );
44+
4345
44-
4546 public static Player player ;
4647
4748 private boolean isServer ;
@@ -52,7 +53,6 @@ public class Rectangles extends PApplet {
5253 private GameObj leftWall ;
5354 private GameObj rightWall ;
5455
55- private ExecutorService threadPool = Executors .newFixedThreadPool (NUM_THREADS );
5656 private boolean setup = false ;
5757
5858
@@ -71,41 +71,60 @@ public Rectangles(boolean isServer) {
7171 * Just runs the game loop infinitely
7272 */
7373 public void runLoop () {
74+ for (GameObj obj : movObjects ) {
75+ eventManager .registerHandler (obj , Event .EVENT_COLLISION );
76+ eventManager .registerHandler (obj , Event .EVENT_MOVEMENT );
77+ eventManager .registerHandler (obj , Event .EVENT_PHYSICS );
78+ if (obj .getType () == "player" ) {
79+ eventManager .registerHandler (obj , Event .EVENT_INPUT );
80+ eventManager .registerHandler (obj , Event .EVENT_DEATH );
81+ eventManager .registerHandler (obj , Event .EVENT_SPAWN );
82+ }
83+ HashMap <String , Object > data = new HashMap <>();
84+ data .put ("caller" , obj .getUUID ());
85+ Event e = new Event (Event .EVENT_PHYSICS , globalTimeline .getCurrentTime ()
86+ + physicsTimeline .getTickSize (), data );
87+ eventManager .raiseEvent (e );
88+
89+
90+
91+ }
7492 while (true ) {
75- this .gameLoop (globalTimeline .getAndResetDelta ());
93+ this .gameLoop (globalTimeline .resetDelta ());
7694 }
7795 }
7896
7997 /**
8098 * Single iteration of the game loop
8199 * @param delta local time since last iteration
82100 */
83- private void gameLoop (long delta ) {
84- if (delta > 0 ) {
85- this .updatePhysics (physicsTimeline .getAndResetDelta ());
86- this .updateNetwork (networkTimeline .getAndResetDelta ());
87- this .updateRender (renderTimeline .getAndResetDelta ());
101+ private void gameLoop (boolean delta ) {
102+ if (delta ) {
103+ threadPool .execute (eventManager );
104+ //this.updatePhysics(physicsTimeline.getAndResetDelta());
105+ //this.updateNetwork(networkTimeline.resetDelta());
106+ this .updateRender (renderTimeline .resetDelta ());
88107 }
89108 }
90109
91110 /* Update methods with deltas */
92111 // TODO: Determine if this is event the best way to do it...
93112
94- private void updateRender (long delta ) {
95- if (delta > 0 ) {
113+ private void updateRender (boolean delta ) {
114+ if (delta ) {
96115 this .redraw ();
97116 }
98117 }
99118
100- private void updateNetwork (long delta ) {
101- if (delta > 0 && this .isServer ) {
119+ private void updateNetwork (boolean delta ) {
120+ if (delta && this .isServer ) {
102121 this .server .updateClients ();
103122 }
104123 }
105124
106- private void updatePhysics (long delta ) {
125+ private void updatePhysics (boolean delta ) {
107126 // Dummy Renderer?
108- if (delta > 0 && this .isServer ) {
127+ if (delta && this .isServer ) {
109128 // Update physics
110129 for (GameObj obj : movObjects ) {
111130 obj .getPy ().update (obj , objects );
0 commit comments