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>()); } }
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); } }
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); } }
private static IRailMemoryPool <RailCommand> CreateCommandPool(RailRegistry registry) { return(registry.CommandType == null ? null : new RailMemoryPool <RailCommand>(new RailFactory <RailCommand>(registry.CommandType))); }