@@ -11,6 +11,7 @@ import { GameStateConstructor } from "@/core/GameState";
1111import { GameCoreService } from "@/core/service/GameCoreService" ;
1212import { EventSystem } from "@/core/events/EventSystem" ;
1313import { binaryInsert } from "@/core/utils/Arrays" ;
14+ import { SyncSystem } from "./SyncSystem" ;
1415
1516@GameCoreService ( )
1617export class World {
@@ -20,6 +21,7 @@ export class World {
2021 private readonly systems : Map < string , System > ;
2122
2223 private updateSchedule : System [ ] ;
24+ private syncSchedule : System [ ] ;
2325 private renderSchedule : System [ ] ;
2426
2527 @GameCoreService ( EventSystem )
@@ -32,6 +34,7 @@ export class World {
3234 this . systems = new Map < string , System > ( ) ;
3335
3436 this . updateSchedule = [ ] ;
37+ this . syncSchedule = [ ] ;
3538 this . renderSchedule = [ ] ;
3639 }
3740
@@ -41,6 +44,12 @@ export class World {
4144 system . execute ( elapsed , frame ) ;
4245 }
4346 }
47+
48+ for ( const system of this . syncSchedule ) {
49+ if ( system . isEnabled ( ) ) {
50+ system . execute ( elapsed , frame ) ;
51+ }
52+ }
4453 }
4554
4655 public render ( elapsed : number , frame : number ) {
@@ -186,6 +195,8 @@ export class World {
186195 private scheduleSystem ( system : System ) {
187196 if ( system instanceof UpdateSystem ) {
188197 binaryInsert ( this . updateSchedule , system , System . byPriority ) ;
198+ } else if ( system instanceof SyncSystem ) {
199+ binaryInsert ( this . syncSchedule , system , System . byPriority ) ;
189200 } else if ( system instanceof RenderSystem ) {
190201 binaryInsert ( this . renderSchedule , system , System . byPriority ) ;
191202 } else {
@@ -205,6 +216,8 @@ export class World {
205216 private unscheduleSystem ( system : System ) {
206217 if ( system instanceof UpdateSystem ) {
207218 this . updateSchedule = this . updateSchedule . filter ( s => s !== system ) ;
219+ } else if ( system instanceof SyncSystem ) {
220+ this . syncSchedule = this . syncSchedule . filter ( s => s !== system ) ;
208221 } else if ( system instanceof RenderSystem ) {
209222 this . renderSchedule = this . renderSchedule . filter ( s => s !== system ) ;
210223 } else {
@@ -226,6 +239,10 @@ export class World {
226239 return this . updateSchedule ;
227240 }
228241
242+ public getSyncSchedule ( ) : System [ ] {
243+ return this . syncSchedule ;
244+ }
245+
229246 public getRenderSchedule ( ) : System [ ] {
230247 return this . renderSchedule ;
231248 }
0 commit comments