Ejemplo n.º 1
0
        public RailResource(RailRegistry registry)
        {
            entityTypeToKey = new Dictionary <Type, int>();
            eventTypeToKey  = new Dictionary <Type, int>();

            commandPool = CreateCommandPool(registry);
            entityPools = new Dictionary <int, IRailMemoryPool <RailEntityBase> >();
            statePools  = new Dictionary <int, IRailMemoryPool <RailState> >();
            eventPools  = new Dictionary <int, IRailMemoryPool <RailEvent> >();

            RegisterEvents(registry);
            RegisterEntities(registry);

            EventTypeCompressor  = new RailIntCompressor(0, eventPools.Count + 1);
            EntityTypeCompressor = new RailIntCompressor(0, entityPools.Count + 1);

            deltaPool         = new RailMemoryPool <RailStateDelta>(new RailFactory <RailStateDelta>());
            commandUpdatePool =
                new RailMemoryPool <RailCommandUpdate>(new RailFactory <RailCommandUpdate>());

            if (registry.Component == Component.Server)
            {
                recordPool =
                    new RailMemoryPool <RailStateRecord>(new RailFactory <RailStateRecord>());
            }
        }
Ejemplo n.º 2
0
        private void RegisterEvents(RailRegistry registry)
        {
            foreach (EventConstructionInfo eventInfo in registry.EventTypes)
            {
                IRailMemoryPool <RailEvent> statePool = new RailMemoryPool <RailEvent>(
                    new RailFactory <RailEvent>(eventInfo.Type, eventInfo.ConstructorParams));

                int typeKey = eventPools.Count + 1; // 0 is an invalid type
                eventPools.Add(typeKey, statePool);
                eventTypeToKey.Add(eventInfo.Type, typeKey);
            }
        }
Ejemplo n.º 3
0
        private void RegisterEntities(RailRegistry registry)
        {
            foreach (EntityConstructionInfo pair in registry.EntityTypes)
            {
                IRailMemoryPool <RailState> statePool = new RailMemoryPool <RailState>(
                    new RailFactory <RailState>(pair.State));
                IRailMemoryPool <RailEntityBase> entityPool = new RailMemoryPool <RailEntityBase>(
                    new RailFactory <RailEntityBase>(pair.Entity, pair.ConstructorParamsEntity));

                int typeKey = statePools.Count + 1; // 0 is an invalid type
                statePools.Add(typeKey, statePool);
                entityPools.Add(typeKey, entityPool);
                entityTypeToKey.Add(pair.Entity, typeKey);
            }
        }
Ejemplo n.º 4
0
 private static IRailMemoryPool <RailCommand> CreateCommandPool(RailRegistry registry)
 {
     return(registry.CommandType == null ?
            null :
            new RailMemoryPool <RailCommand>(new RailFactory <RailCommand>(registry.CommandType)));
 }