예제 #1
0
        private RailResource()
        {
            MasterInstance master = RailResource.Master;

            if (master == null)
            {
                throw new ApplicationException("RailResource not initialized");
            }

            // Copy references to read-only stuff from the master
            this.EventTypeCompressor  = master.EventTypeCompressor;
            this.EntityTypeCompressor = master.EntityTypeCompressor;
            this.entityFactories      = master.EntityFactories;
            this.entityTypeToKey      = master.EntityTypeToKey;
            this.eventTypeToKey       = master.EventTypeToKey;

            // Clone or instantiate the rest
            this.commandPool = master.CloneCommandPool();
            this.statePools  = master.CloneStatePools();
            this.eventPools  = master.CloneEventPools();

            this.deltaPool         = new RailPool <RailStateDelta>();
            this.commandUpdatePool = new RailPool <RailCommandUpdate>();
#if SERVER
            this.recordPool = new RailPool <RailStateRecord>();
#endif
        }
예제 #2
0
            private void RegisterEvents(RailRegistry registry)
            {
                foreach (Type eventType in registry.EventTypes)
                {
                    IRailPool <RailEvent> statePool =
                        RailResource.CreatePool <RailEvent>(eventType);

                    int typeKey = this.eventPools.Count + 1; // 0 is an invalid type
                    this.eventPools.Add(typeKey, statePool);
                    this.EventTypeToKey.Add(eventType, typeKey);
                }

                this.EventTypeCompressor =
                    new RailIntCompressor(0, this.eventPools.Count + 1);
            }
예제 #3
0
            internal MasterInstance(RailRegistry registry)
            {
                this.EntityFactories      = new Dictionary <int, IRailPool <RailEntity> >();
                this.EntityTypeToKey      = new Dictionary <Type, int>();
                this.EventTypeToKey       = new Dictionary <Type, int>();
                this.EventTypeCompressor  = null;
                this.EntityTypeCompressor = null;

                this.commandPool = null;
                this.statePools  = new Dictionary <int, IRailPool <RailState> >();
                this.eventPools  = new Dictionary <int, IRailPool <RailEvent> >();

                this.RegisterCommand(registry);
                this.RegisterEvents(registry);
                this.RegisterEntities(registry);
            }
예제 #4
0
            private void RegisterEntities(RailRegistry registry)
            {
                foreach (KeyValuePair <Type, Type> pair in registry.EntityTypes)
                {
                    Type entityType = pair.Key;
                    Type stateType  = pair.Value;

                    IRailPool <RailState> statePool =
                        RailResource.CreatePool <RailState>(stateType);
                    IRailPool <RailEntity> entityPool =
                        RailResource.CreatePool <RailEntity>(entityType);

                    int typeKey = this.statePools.Count + 1; // 0 is an invalid type
                    this.statePools.Add(typeKey, statePool);
                    this.EntityFactories.Add(typeKey, entityPool);
                    this.EntityTypeToKey.Add(entityType, typeKey);
                }

                this.EntityTypeCompressor =
                    new RailIntCompressor(0, this.EntityFactories.Count + 1);
            }
예제 #5
0
 private void RegisterCommand(RailRegistry registry)
 {
     this.commandPool =
         RailResource.CreatePool <RailCommand>(registry.CommandType);
 }