コード例 #1
0
ファイル: Compilation.cs プロジェクト: simonl/TypeTheory
        private static Structure <Guid> CompileType(IUniverse universe, Class <Guid, Guid, Func <Term <Guid>, Term <Guid> > > @class)
        {
            switch (@class.Tag)
            {
            case Class <Guid, Guid, Func <Term <Guid>, Term <Guid> > > .Tags.Quantifier:
            {
                var quantifier = (Class <Guid, Guid, Func <Term <Guid>, Term <Guid> > > .Quantifier)@class;

                Term <Guid> dependency = Compile(quantifier.Dependency.TypeOf());

                var depUniverse = new Term <Guid> .Universe(quantifier.Dependency.Universe.Rank);

                var qualifiedDependency = new Qualified <Guid, Guid>(depUniverse, dependency, quantifier.Dependency.Term);

                return(new Structure <Guid> .Pair(qualifiedDependency, quantifier.Dependent(null)));
            }

            case Class <Guid, Guid, Func <Term <Guid>, Term <Guid> > > .Tags.Shift:
            {
                var shift = (Class <Guid, Guid, Func <Term <Guid>, Term <Guid> > > .Shift)@class;

                return(new Structure <Guid> .Continuation(shift.Content(null)));
            }

            default:
                throw new InvalidProgramException("Should never happen.");
            }
        }
コード例 #2
0
        public void ResetCamera(IUniverse universe)
        {
            if (universe == null) return;

            var volumeCopy = universe.Volume.Clone();
            ActiveCamera = new Camera(volumeCopy);
        }
コード例 #3
0
        public IUniverse GetUniverse(int id)
        {
            if (universeCache == null)
                universeCache = mapGenerator.GenerateUniverse(id);

            return universeCache;
        }
コード例 #4
0
        public Body NextBody(IUniverse universe)
        {
            const float centralBodyMass = 1e16f;

            if (didGenerateCentralBody == false)
            {
                didGenerateCentralBody = true;
                return(new Body(
                           mass: centralBodyMass,
                           position: Vector2.Zero,
                           velocity: Vector2.Zero,
                           acceleration: Vector2.Zero
                           ));
            }

            const uint  dMin = 300;
            const uint  dMax = 500;
            const float mMin = centralBodyMass / 1e6f;
            const float mMax = centralBodyMass / 1e5f;

            double tetha    = random.NextDouble() * 2 * Math.PI;
            double distance = random.NextDouble() * (dMax - dMin) + dMin;
            double velocity = Math.Sqrt((universe.GravitationalConstant * centralBodyMass) / distance);
            float  bodyMass = (float)random.NextDouble() * (mMax - mMin) + mMin;

            return(new Body(
                       mass: bodyMass,
                       position: new Vector2((float)(Math.Cos(tetha) * distance), (float)(Math.Sin(tetha) * distance)),
                       velocity: new Vector2((float)(Math.Cos(tetha - 0.5 * Math.PI) * velocity), (float)(Math.Sin(tetha - 0.5 * Math.PI) * velocity)),
                       acceleration: Vector2.Zero
                       ));
        }
        /// <summary>
        /// The initiate event logger.
        /// </summary>
        /// <param name="universe">
        /// The universe.
        /// </param>
        public void InitiateEventLogger(IUniverse universe)
        {
            if (universe == null)
            {
                return;
            }

            var events = (decimal)universe.UniverseEvents.Count();

            if (events < 10m)
            {
                this.logger.LogInformation("Less than 10 events in the universe. Not logging (%) completion.");
                return;
            }

            for (decimal i = 1; i <= 10m; i++)
            {
                var fraction             = 0.1m * i;
                var percentageEventIndex = (int)Math.Floor(events * fraction);
                var universeEvent        = universe.UniverseEvents.ElementAt(percentageEventIndex - 1);
                var landMark             = new PercentageLandMark(
                    universeEvent,
                    $"Universe event processing {fraction * 100}% towards completion. {universeEvent.EventTime}");
                this.list.Add(landMark);
            }
        }
コード例 #6
0
ファイル: LiveSubscription.cs プロジェクト: nooperpudd/Lean
 /// <summary>
 /// Initializes a new instance of the <see cref="LiveSubscription"/> class
 /// </summary>
 /// <param name="universe">The universe of the subscription</param>
 /// <param name="security">The security this subscription is for</param>
 /// <param name="enumerator">The subscription's data source</param>
 /// <param name="utcStartTime">The start time of the subscription</param>
 /// <param name="utcEndTime">The end time of the subscription</param>
 public LiveSubscription(IUniverse universe, Security security, IEnumerator<BaseData> enumerator, DateTime utcStartTime, DateTime utcEndTime)
     : base(universe, security, enumerator, utcStartTime, utcEndTime)
 {
     NeedsMoveNext = true;
     IsCustomData = security.SubscriptionDataConfig.IsCustomData;
     StreamStore = new StreamStore(Configuration, security);
 }
コード例 #7
0
 public SimulationRecorder(IUniverse universe, float duration, float framesPerSecond)
 {
     Universe        = universe;
     Duration        = duration;
     FramesPerSecond = framesPerSecond;
     snapshots       = new SerializedUniverse(universe.BodyCount, duration, framesPerSecond);
 }
コード例 #8
0
 public GameState()
 {
     // By default create a standard player and add to the list of players
     ActivePlayer = new Player();
     Players.Add(ActivePlayer);
     Universe = new Universe();
 }
コード例 #9
0
        public TestDataUniverse(IUniverse universe)
        {
            _universe = universe;
            var planets = _universe.Planets();
            var mercury = planets.Create("Mercury");
            var venus   = planets.Create("Venus");
            var earth   = planets.Create("Earth");

            planets.Create("Mars");
            planets.Create("Jupiter");
            planets.Create("Saturn");
            planets.Create("Uranus");

            var properties = _universe.Properties();
            var atmosphere = properties.Create("Atmosphere");
            var water      = properties.Create("Water");
            var solid      = properties.Create("Solid");
            var radiation  = properties.Create("Radiation");
            var hot        = properties.Create("Hot");
            var cold       = properties.Create("Cold");
            var ice        = properties.Create("Ice");

            earth.Properties().Add(atmosphere);
            earth.Properties().Add(water);

            venus.Properties().Add(hot);
            venus.Properties().Add(radiation);

            mercury.Properties().Add(solid);
            mercury.Properties().Add(ice);
            mercury.Properties().Add(cold);
        }
コード例 #10
0
        private static SimResults RunSim(long numSteps)
        {
            double halfYear = 3.1558149 * Math.Pow(10, 7) / 2.0; // seconds;
            double timeStep = halfYear / numSteps;

            IUniverse sunEarthUni     = SunEarthUniverse();
            var       earth           = sunEarthUni.Bodies.First();
            Vector3   earthStartPos   = earth.Dynamics.Kinematics.Transform.Pos;
            Vector3   expectedHalfway = new Vector3(-earthStartPos.X, earthStartPos.Y, earthStartPos.Z);

            Stopwatch stopwatch = Stopwatch.StartNew();

            for (int i = 0; i < numSteps; i++)
            {
                sunEarthUni.Update(timeStep);
            }
            stopwatch.Stop();
            double halfwayTime = stopwatch.Elapsed.TotalSeconds;
            double halfwayDiff = (expectedHalfway - earth.Dynamics.Kinematics.Transform.Pos).Magnitude;

            stopwatch.Start();
            for (int i = 0; i < numSteps; i++)
            {
                sunEarthUni.Update(timeStep);
            }
            stopwatch.Stop();
            double endTime = stopwatch.Elapsed.TotalSeconds;
            double endDiff = (earthStartPos - earth.Dynamics.Kinematics.Transform.Pos).Magnitude;

            return(new SimResults(numSteps, halfwayTime, halfwayDiff, endTime, endDiff));
        }
コード例 #11
0
ファイル: Serialization.cs プロジェクト: simonl/TypeTheory
        public static IEnumerable <Bits> EncodeUniverse(IUniverse universe)
        {
            var rank     = Encoding.EncodeNumber(universe.Rank);
            var polarity = Encoding.EncodeNullable(Encoding.EncodePolarity, universe.Polarity);

            return(Encoding.Concatenate(rank, polarity));
        }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UniverseSelectionEventArgs"/> class
 /// </summary>
 /// <param name="universe">The universe that raised this event</param>
 /// <param name="configuration">Theconfiguration for the data</param>
 /// <param name="dateTimeUtc">The date time this event was fired in UTC</param>
 /// <param name="data">The data contained within this event</param>
 public UniverseSelectionEventArgs(IUniverse universe, SubscriptionDataConfig configuration, DateTime dateTimeUtc, IReadOnlyList<BaseData> data)
 {
     Universe = universe;
     Configuration = configuration;
     DateTimeUtc = dateTimeUtc;
     Data = data;
 }
コード例 #13
0
        float AnalizeDescriptor(IUniverse universe, int x, int y)
        {
            int desc = universe.GetObjectDescriptor(x, y);

            if (desc == 0)//empty
            {
                return(0);
            }
            else if (desc == descriptor)//friend
            {
                return(genome.GetFriendly());
            }
            else if (desc < 0)//food
            {
                return(genome.GetHunger());
            }
            else//enemy
            {
                if (GetAge() >= ConstsUniverse.CellAge_AdultCell)
                {
                    return(genome.GetAggression());
                }
                else
                {
                    return(ConstsUniverse.CellGenome_Child_Aggression);
                }
            }
        }
コード例 #14
0
        public byte[] GetData(IScene scene, IUniverse universe)
        {
            var data = new byte[512];

            foreach (var state in scene.DeviceStates)
            {
                var device       = state.Device;
                var deviceType   = state.GetDeviceType();
                var currentState = state;
                foreach (var filter in DeviceFilters)
                {
                    var filterType = filter.GetDeviceType();
                    if (filterType.IsAssignableFrom(deviceType))
                    {
                        currentState = filter.Filter(currentState);
                    }
                }
                if (currentState.Data.Length != device.ChannelsCount)
                {
                    throw new InvalidOperationException($"device {device.Identifier} should have {device.ChannelsCount} channels but it's state's payload is {currentState.Data.Length}.");
                }
                currentState.Data.CopyTo(data, universe.Devices[device] - 1);
            }
            return(data);
        }
コード例 #15
0
 public FixedTimePhysicsRunner(IUniverse uni, double timeStep = 0)
 {
     Universe = uni;
     if (timeStep != 0)
     {
         FrameLength = timeStep;
     }
 }
コード例 #16
0
        /// <summary>
        /// Erzuegt ein neues Universum.
        /// </summary>
        /// <param name="name">Name des neuen Universums.</param>
        /// <param name="seed">Weltgenerator-Seed für das neue Universum.</param>
        /// <returns>Die Guid des neuen Universums.</returns>
        public Guid NewUniverse(string name, int seed)
        {
            Guid guid = Guid.NewGuid();

            universe = new Universe(guid, name, seed);
            persistenceManager.SaveUniverse(universe);
            return(guid);
        }
コード例 #17
0
        public MainViewModel(IUniverse universe)
        {
            ListPlanetsViewModel       = new ListPlanetsViewModel(universe);
            ListPropertiesViewModel    = new ListPropertiesViewModel(universe);
            PlanetDescriptionViewModel = new PlanetDescriptionViewModel(universe);

            ListPlanetsViewModel.PlanetSelected += PlanetDescriptionViewModel.ShowPlanetDescription;
        }
コード例 #18
0
        private static ITerm <Id, Id> ForallType <Id>(IUniverse universe, Id identifier, Func <ITerm <Id, Id>, ITerm <Id, Id> > dependent)
        {
            var dependency = universe.Qualify <Id, Id, Id>(term: identifier);

            var variable = new Term <Id, Id>(new TermF <Id, Id, ITerm <Id, Id> > .Variable(dependency.Term));

            return(new Term <Id, Id>(new TermF <Id, Id, ITerm <Id, Id> > .Type(new Class <Id, Id, ITerm <Id, Id> > .Quantifier(dependency, dependent(variable)))));
        }
コード例 #19
0
ファイル: ControllerBase.cs プロジェクト: georg-jung/DmxSharp
 // use the scene generator factory, because a specific SceneGenerator might be shared if given as argument
 public ControllerBase(IUniverse universe, ISceneTranslator sceneTranslator, ISceneGeneratorFactory sceneGeneratorFactory, ISink channelSink)
 {
     _channelSink                 = channelSink;
     Universe                     = universe;
     SceneTranslator              = sceneTranslator;
     SceneGenerator               = sceneGeneratorFactory.CreateGenerator(Universe);
     SceneGenerator.SceneChanged += SceneChanged;
     SceneGenerator.Signal(StartupSignal.Value);
 }
コード例 #20
0
        public void TestMethod2()
        {
            Factory factory = new Factory();

            IUniverse rebelde = factory.getUniverse("Rebelde");

            rebelde.SetName("Erick");
            Assert.AreEqual("Erick", rebelde.GetName());
        }
コード例 #21
0
        public void TestMethod3()
        {
            Factory factory = new Factory();

            IUniverse planeta = factory.getUniverse("Planeta");

            planeta.SetName("Mercurio");
            Assert.AreEqual("Mercurio", planeta.GetName());
        }
コード例 #22
0
        public ListPropertiesViewModel(IUniverse universe)
        {
            _properties = new AsyncProperties(universe.Properties());
            _properties.NewPropertyEvent += (sender, args) => _addProperty(args.Property);

            CreateProperty = new CreateProperty(_properties);

            _loadProperties();
        }
コード例 #23
0
        public IUniverse GetUniverse(int id)
        {
            if (universeCache == null)
            {
                universeCache = mapGenerator.GenerateUniverse(id);
            }

            return(universeCache);
        }
コード例 #24
0
        public void TestMethod4()
        {
            Factory factory = new Factory();

            IUniverse soldado = factory.getUniverse("Soldado");

            soldado.SetName("Capitán");
            Assert.AreEqual("Capitán", soldado.GetName());
        }
コード例 #25
0
        public static IExpression <Bind, Id, T> Qualify <Bind, Id, T>(this IUniverse universe, T term)
        {
            var type = new Term <Bind, Id>(new TermF <Bind, Id, ITerm <Bind, Id> > .Universe(universe));

            return(new Expression <Bind, Id, T>(
                       universe: universe.TypeOf(),
                       type: type,
                       term: term));
        }
コード例 #26
0
ファイル: Serialization.cs プロジェクト: simonl/TypeTheory
        private static IEnumerable <Bits> EncodeTerm(IUniverse universe, Productions production)
        {
            if (universe.Rank == 0)
            {
                return(EncodeTerm(production));
            }

            return(EncodeType(production));
        }
コード例 #27
0
 public void Listen(IUniverse uni)
 {
     ProcessBeforeFrame(uni);
     uni.FrameFinished += (sender, e) =>
     {
         T res = ProcessAfterFrame(uni);
         ReadingComplete?.Invoke(this, new FrameReading <T>(res, e.FrameLength));
     };
 }
コード例 #28
0
        public ListPlanetsViewModel(IUniverse universe)
        {
            _planets = new AsyncPlanets(universe.Planets());
            _planets.NewPlanetEvent += (sender, args) => { _addPlanet(args.Planet); };

            CreatePlanet  = new CreatePlanet(_planets);
            ReloadPlanets = new RelayCommand(_loadPlanets);

            _loadPlanets();
        }
コード例 #29
0
        /// <summary>
        /// The play.
        /// </summary>
        /// <param name="universe">
        /// The universe.
        /// </param>
        public void Play(IUniverse universe)
        {
            if (universe == null)
            {
                this.logger.LogError("added to play null universe. Returning.");
                return;
            }

            this.PlayUniverse(universe);
        }
コード例 #30
0
        private void saveChunk(int planetId, IChunk value)
        {
            IUniverse universe = GetUniverse(0);

            if (!disablePersistence && value.ChangeCounter > 0)
            {
                chunkPersistence.Save(universe.Id, planetId, value);
                value.ChangeCounter = 0;
            }
        }
コード例 #31
0
        private IPlanet loadPlanet(int index)
        {
            IUniverse universe = GetUniverse(0);

            var cache = new ChunkCache(idx => loadChunk(index, idx), (_, chunk) => saveChunk(index, chunk));

            _managers[index] = new PlanetResourceManager(cache);

            return(mapGenerator.GeneratePlanet(universe.Id, 4567));
        }
コード例 #32
0
        public static IUniverse Dual(this IUniverse universe)
        {
            if (universe.Polarity == null)
            {
                throw new ArgumentException("Universe must describe a polarized type.");
            }

            var polarity = Dual(universe.Polarity.Value);

            return(new Universe(universe.Rank, polarity));
        }
コード例 #33
0
        public void SetUp()
        {
            _universe = Substitute.For<IUniverse>();
            _gravitySimulator = Substitute.For<IGravitySimulator>();
            _gameObjectFactory = Substitute.For<IGameObjectFactory>();
            _keyboardHandler = Substitute.For<IKeyboardHandler>();
            _actionHandler = Substitute.For<IActionHandler>();
            _drawingManager = Substitute.For<IDrawingManager>();

            _gameEngine = new GameEngine(_universe, _gravitySimulator, _gameObjectFactory, _keyboardHandler, _actionHandler, _drawingManager);
        }
コード例 #34
0
        internal GameObjectFactory(IContentManager contentManager, IGraphicsFactory graphicsFactory, IGravitySimulator gravitySimulator, IDrawingManager drawingManager, IUniverse universe, IShipComponentFactory shipComponentFactory)
        {
            _contentManager = contentManager;
            _graphicsFactory = graphicsFactory;
            _gravitySimulator = gravitySimulator;
            _drawingManager = drawingManager;
            _universe = universe;

            _shipComponentFactory = shipComponentFactory;
            _gameObjects = new List<IGameObject>();
        }
コード例 #35
0
        internal void SnapshotUniverse(IUniverse universe)
        {
            List <float[]> bodies = new List <float[]>();

            foreach (Body body in universe.Bodies)
            {
                bodies.Add(new float[] { body.Radius, body.Position.X, body.Position.Y });
            }

            framesBodiesCoordinates.Add(bodies);
        }
コード例 #36
0
 public ConsoleOutputManager(IUniverse universe)
 {
     this.universe = universe;
     width         = universe.GetWidth();
     height        = universe.GetHeight();
     borderStr    += '+';
     for (int i = 0; i < width; i++)
     {
         borderStr += '-';
     }
     borderStr += '+';
     disposed   = false;
 }
コード例 #37
0
ファイル: GameEngine.cs プロジェクト: DaveEmmerson/SpaceWar2
        internal GameEngine(IUniverse universe, IGravitySimulator gravitySimulator, IGameObjectFactory gameObjectFactory, IKeyboardHandler keyboardHandler, IActionHandler actionHandler, IDrawingManager drawingManager)
        {
            _universe = universe;
            _drawingManager = drawingManager;
            _gravitySimulator = gravitySimulator;

            _gameObjectFactory = gameObjectFactory;

            _keyboardHandler = keyboardHandler;
            _actionHandler = actionHandler;
            _controllerFactory = new ControllerFactory(_keyboardHandler);
            actionHandler.RegisterTriggerAction(Keys.Space, () => _paused = !_paused);
        }
コード例 #38
0
        internal SpaceWar2Game()
        {
            _contentManager = new ContentManagerWrapper(Content.ServiceProvider, "Content");
            var graphicsDeviceManager = new GraphicsDeviceManager(this);
            _graphicsDevice = new GraphicsDeviceWrapper(graphicsDeviceManager);

            _universe = Universe.CreateDefault();
            _drawingManager = new DrawingManager(_universe);
            _gravitySimulator = new GravitySimulator();
            _shipComponentFactory = new ShipComponentFactory();
            _graphicsFactory = new GraphicsFactory();

            _gameObjectFactory = new GameObjectFactory(_contentManager, _graphicsFactory, _gravitySimulator, _drawingManager, _universe, _shipComponentFactory);

            _keyboardHandler = new KeyboardHandler(new KeyboardWrapper());

            var actionHandler = new ActionHandler(_keyboardHandler);

            _gameEngine = new GameEngine(_universe, _gravitySimulator, _gameObjectFactory, _keyboardHandler, actionHandler, _drawingManager);

            SetUpActions(actionHandler);
        }
コード例 #39
0
 /// <summary>
 /// Erzuegt ein neues Universum.
 /// </summary>
 /// <param name="name">Name des neuen Universums.</param>
 /// <param name="seed">Weltgenerator-Seed für das neue Universum.</param>
 /// <returns>Die Guid des neuen Universums.</returns>
 public Guid NewUniverse(string name, int seed)
 {
     Guid guid = Guid.NewGuid();
     universe = new Universe(guid, name, seed);
     persistenceManager.SaveUniverse(universe);
     return guid;
 }
コード例 #40
0
 public FixedTimePhysicsRunner(IUniverse uni, double timeStep = 0)
 {
     Universe = uni;
     if (timeStep != 0) FrameLength = timeStep;
 }
コード例 #41
0
ファイル: GameTests.cs プロジェクト: jancowol/game-of-life-cs
 private static IUniverse EvolveUniverse(IUniverse initialUniverse)
 {
     var game = new Game();
     return game.Tick(initialUniverse);
 }
 public IEnumerable<ICellLocation> Filter(IUniverse universe)
 {
     return new CellsWithLiveNeighbourCountFilter(universe.LiveCellLocations, 2, 3)
         .Filter(universe.LiveCellLocations);
 }
コード例 #43
0
 public RealTimePhysicsRunner(IUniverse uni)
 {
     Universe = uni;
 }
コード例 #44
0
ファイル: InputHandlers.cs プロジェクト: domisterwoozy/LabBox
 public static ItemSelector<IBody> BodySelector(IInputObservable input, IUniverse uni, Func<Vector3> rayOrigin, Func<Vector3> rayDir)
 {
     return new ItemSelector<IBody>(input, () => uni.RaySelect(rayOrigin(), rayDir()));
 }
コード例 #45
0
 private void WhenGettingAUniverse()
 {
     result = GetModel().GetByName(UniverseName);
 }
コード例 #46
0
ファイル: Map.cs プロジェクト: jvbsl/OctoAwesome-MapViewer
 private void LoadGenerator(IMapGenerator generator)
 {
     Generator = generator;
     generatorName = generator.GetType().Name;
     Universe = generator.GenerateUniverse(0);
     Planet = generator.GeneratePlanet(0, seed);
 }
コード例 #47
0
 /// <summary>
 /// Event invocator for the <see cref="UniverseSelection"/> event
 /// </summary>
 /// <param name="universe">The universe to perform selection on the data</param>
 /// <param name="config">The configuration of the universe</param>
 /// <param name="dateTimeUtc">The current date time in UTC</param>
 /// <param name="data">The universe selection data to be operated on</param>
 protected virtual void OnUniverseSelection(IUniverse universe, SubscriptionDataConfig config, DateTime dateTimeUtc, IReadOnlyList<BaseData> data)
 {
     var handler = UniverseSelection;
     if (handler != null) handler(this, new UniverseSelectionEventArgs(universe, config, dateTimeUtc, data));
 }
コード例 #48
0
        public void SetUp()
        {
            _universe = Substitute.For<IUniverse>();
            _universe.Volume.Returns(_volume);

            _drawingManager = new DrawingManager(_universe);
        }
コード例 #49
0
ファイル: InputHandlers.cs プロジェクト: domisterwoozy/LabBox
 public static ItemSelector<IBody> BodySelector(IInputObservable input, IUniverse uni, ICamera cam)
 {
     return BodySelector(input, uni, () => cam.Pos, () => (cam.LookAtPos - cam.Pos).UnitDirection);
 }
コード例 #50
0
ファイル: Game.cs プロジェクト: jancowol/game-of-life-cs
 public IUniverse Tick(IUniverse universe)
 {
     return new Universe(FilterNextGenerationLiveCells(universe));
 }
コード例 #51
0
ファイル: Game.cs プロジェクト: jancowol/game-of-life-cs
 public IEnumerable<ICellLocation> FilterNextGenerationLiveCells(IUniverse universe)
 {
     return _cellLocationFilters.SelectMany(f => f.Filter(universe));
 }
コード例 #52
0
ファイル: Program.cs プロジェクト: jancowol/game-of-life-cs
 private static void RenderUniverse(IUniverse universe)
 {
     Console.Clear();
     foreach (var cell in universe.LiveCellLocations.Cast<XYCellLocation>())
     {
         Console.SetCursorPosition(cell.X, cell.Y);
         Console.Write("O");
     }
 }
コード例 #53
0
 /// <summary>
 /// Erzuegt ein neues Universum.
 /// </summary>
 /// <param name="name">Name des neuen Universums.</param>
 /// <param name="seed">Weltgenerator-Seed für das neue Universum.</param>
 public void NewUniverse(string name, int seed)
 {
     universe = new Universe(Guid.NewGuid(), name, seed);
         persistenceManager.SaveUniverse(universe);
 }
コード例 #54
0
        /// <summary>
        /// Lädt das Universum mit der angegebenen Guid.
        /// </summary>
        /// <param name="universeId">Die Guid des Universums.</param>
        /// <returns>Das geladene Universum.</returns>
        public void LoadUniverse(Guid universeId)
        {
            // Alte Daten entfernen
            if (universe != null)
                UnloadUniverse();

            // Neuen Daten loaden/generieren
            universe = persistenceManager.LoadUniverse(universeId);
            if (universe == null)
                throw new Exception();
        }
コード例 #55
0
 internal DrawingManager(IUniverse universe)
 {
     ResetCamera(universe);
     _drawableObjects = new List<IGameObject>();
 }
コード例 #56
0
ファイル: InputHandlers.cs プロジェクト: domisterwoozy/LabBox
 public static ItemSelector<IBody> BodySelector(IInputObservable input, IUniverse uni, Vector3 rayOrigin, Vector3 rayDir)
 {
     return BodySelector(input, uni, () => rayOrigin, () => rayDir);
 }
コード例 #57
0
        /// <summary>
        /// Creates a new subscription for universe selection
        /// </summary>
        /// <param name="universe">The universe to add a subscription for</param>
        /// <param name="startTimeUtc">The start time of the subscription in utc</param>
        /// <param name="endTimeUtc">The end time of the subscription in utc</param>
        protected virtual Subscription CreateUniverseSubscription(
            IUniverse universe,
            DateTime startTimeUtc,
            DateTime endTimeUtc
            )
        {
            // grab the relevant exchange hours
            var config = universe.Configuration;

            var exchangeHours = SecurityExchangeHoursProvider.FromDataFolder()
                .GetExchangeHours(config.Market, null, config.SecurityType);

            // create a canonical security object
            var security = new Security(exchangeHours, config, universe.SubscriptionSettings.Leverage);

            IEnumerator<BaseData> enumerator;
            if (config.Type == typeof (CoarseFundamental))
            {
                // since we're binding to the data queue exchange we'll need to let him
                // know that we expect this data
                _dataQueueHandler.Subscribe(_job, new Dictionary<SecurityType, List<string>>
                {
                    {config.SecurityType, new List<string>{config.Symbol}}
                });

                var enqueable = new EnqueableEnumerator<BaseData>();
                _exchange.SetHandler(config.Symbol, data =>
                {
                    var universeData = data as BaseDataCollection;
                    if (universeData != null)
                    {
                        enqueable.EnqueueRange(universeData.Data);
                    }
                });
                enumerator = enqueable;
            }
            else
            {
                var localStartTime = startTimeUtc.ConvertFromUtc(config.TimeZone);
                var localEndTime = endTimeUtc.ConvertFromUtc(config.TimeZone);

                // define our data enumerator
                var tradeableDates = Time.EachTradeableDay(security, localStartTime, localEndTime);
                var reader = new SubscriptionDataReader(config, localStartTime, localEndTime, _resultHandler, tradeableDates, true);
                _customExchange.AddEnumerator(reader);

                var enqueable = new EnqueableEnumerator<BaseData>();
                _customExchange.SetHandler(config.Symbol, data =>
                {
                    var universeData = data as BaseDataCollection;
                    if (universeData != null)
                    {
                        enqueable.EnqueueRange(universeData.Data);
                    }
                    else
                    {
                        enqueable.Enqueue(data);
                    }
                });
                enumerator = enqueable;
            }

            // create the subscription
            var subscription = new Subscription(universe, security, enumerator, new TimeZoneOffsetProvider(security.SubscriptionDataConfig.TimeZone, startTimeUtc, endTimeUtc), startTimeUtc, endTimeUtc);

            return subscription;
        }
コード例 #58
0
        /// <summary>
        /// Adds a new subscription for universe selection
        /// </summary>
        /// <param name="universe">The universe to add a subscription for</param>
        /// <param name="startTimeUtc">The start time of the subscription in utc</param>
        /// <param name="endTimeUtc">The end time of the subscription in utc</param>
        public void AddUniverseSubscription(
            IUniverse universe,
            DateTime startTimeUtc,
            DateTime endTimeUtc
            )
        {
            // grab the relevant exchange hours
            SubscriptionDataConfig config = universe.Configuration;

            var exchangeHours = SecurityExchangeHoursProvider.FromDataFolder()
                .GetExchangeHours(config.Market, null, config.SecurityType);

            // create a canonical security object
            var security = new Security(exchangeHours, config, universe.SubscriptionSettings.Leverage);

            var localStartTime = startTimeUtc.ConvertFromUtc(config.TimeZone);
            var localEndTime = endTimeUtc.ConvertFromUtc(config.TimeZone);

            // define our data enumerator
            var tradeableDates = Time.EachTradeableDay(security, localStartTime, localEndTime);
            var enumerator = new SubscriptionDataReader(config, localStartTime, localEndTime, _resultHandler, tradeableDates, false);

            // create the subscription
            var subscription = new LiveSubscription(universe, security, enumerator, startTimeUtc, endTimeUtc);

            // only message the user if it's one of their universe types
            _subscriptions.AddOrUpdate(new SymbolSecurityType(subscription), subscription);
        }
コード例 #59
0
        public void SetUp()
        {
            _contentManager = Substitute.For<IContentManager>();
            _graphicsFactory = Substitute.For<IGraphicsFactory>();
            _gravitySimulator = Substitute.For<IGravitySimulator>();
            _drawingManager = Substitute.For<IDrawingManager>();
            _universe = Substitute.For<IUniverse>();
            _shipComponentFactory = Substitute.For<IShipComponentFactory>();

            _gameObjectFactory = new GameObjectFactory(_contentManager, _graphicsFactory, _gravitySimulator, _drawingManager, _universe, _shipComponentFactory);
        }
コード例 #60
0
        /// <summary>
        /// Speichert das Universum.
        /// </summary>
        /// <param name="universe">Das zu speichernde Universum</param>
        public void SaveUniverse(IUniverse universe)
        {
            string path = Path.Combine(GetRoot(), universe.Id.ToString());
            Directory.CreateDirectory(path);

            string file = Path.Combine(path, UniverseFilename);
            using (Stream stream = File.Open(file, FileMode.Create, FileAccess.Write))
            {
                using (GZipStream zip = new GZipStream(stream, CompressionMode.Compress))
                {
                    universe.Serialize(zip);
                }
            }
        }