コード例 #1
0
ファイル: TickActions.cs プロジェクト: morelli690/Terrarium
        /// <summary>
        ///  Rips through all organisms and wraps their pending actions
        ///  up into the hashtables on a per action type basis.
        /// </summary>
        /// <param name="scheduler">The game scheduler that has all of the organisms.</param>
        internal void GatherActionsFromOrganisms(IGameScheduler scheduler)
        {
            foreach (Organism organism in scheduler.Organisms)
            {
                PendingActions pendingActions = organism.GetThenErasePendingActions();
                if (pendingActions.MoveToAction != null)
                {
                    _moveToActions[organism.ID] = pendingActions.MoveToAction;
                }

                if (pendingActions.AttackAction != null)
                {
                    _attackActions[organism.ID] = pendingActions.AttackAction;
                }

                if (pendingActions.EatAction != null)
                {
                    _eatActions[organism.ID] = pendingActions.EatAction;
                }

                if (pendingActions.ReproduceAction != null)
                {
                    _reproduceActions[organism.ID] = pendingActions.ReproduceAction;
                }

                if (pendingActions.DefendAction != null)
                {
                    _defendActions[organism.ID] = pendingActions.DefendAction;
                }
            }
        }
コード例 #2
0
 public SpriteBatchSystemHandler(IEntityCollectionManager entityCollectionManager, IEcsRxGraphicsDevice graphicsDevice, IRenderTarget2dRegistry renderTarget2dRegistry, IGameScheduler scheduler)
 {
     EntityCollectionManager = entityCollectionManager;
     _systemSubscriptions    = new Dictionary <ISystem, IDisposable>();
     _graphicsDevice         = graphicsDevice;
     _gameScheduler          = scheduler;
     _renderTarget2dRegistry = renderTarget2dRegistry;
 }
コード例 #3
0
ファイル: AppMgr.cs プロジェクト: AnthonyMastrean/terrarium2
 internal static void DestroyScheduler()
 {
     if (theScheduler != null)
     {
         theScheduler.Close();
         theScheduler = null;
     }
 }
コード例 #4
0
 public void Initialize(IBytech bytech, IGameScheduler gameScheduler)
 {
     _bytech        = bytech;
     _gameScheduler = gameScheduler;
     _gameScheduler.OnPreRender.Subscribe(x => PreRender(x));
     _gameScheduler.OnRender.Subscribe(x => Render(x));
     _gameScheduler.OnPostRender.Subscribe(x => PostRender(x));
     _batch = new SpriteBatch(_bytech.GraphicsDeviceManager.GraphicsDevice);
 }
コード例 #5
0
 internal static void DestroyScheduler()
 {
     if (_theScheduler == null)
     {
         return;
     }
     _theScheduler.Close();
     _theScheduler = null;
 }
コード例 #6
0
ファイル: AppMgr.cs プロジェクト: Carolasb/Terrarium
        /// <summary>
        /// Creates the scheduler in the same appdomain as the rest of the game
        /// </summary>
        /// <param name="engine"></param>
        /// <returns></returns>
        internal static IGameScheduler CreateSameDomainScheduler(GameEngine engine)
        {
            if (_theScheduler == null)
            {
                _theScheduler = new GameScheduler();
            }
            else
            {
                throw new ApplicationException("A Scheduler already exists.");
            }

            _theScheduler.CurrentGameEngine = engine;

            return _theScheduler;
        }
コード例 #7
0
        /// <summary>
        /// Creates the scheduler in the same appdomain as the rest of the game
        /// </summary>
        /// <param name="engine"></param>
        /// <returns></returns>
        internal static IGameScheduler CreateSameDomainScheduler(GameEngine engine)
        {
            if (_theScheduler == null)
            {
                _theScheduler = new GameScheduler();
            }
            else
            {
                throw new ApplicationException("A Scheduler already exists.");
            }

            _theScheduler.CurrentGameEngine = engine;

            return(_theScheduler);
        }
コード例 #8
0
ファイル: GameEngine.cs プロジェクト: Carolasb/Terrarium
        /// <summary>
        ///  Constructs a new game engine.
        /// </summary>
        /// <param name="dataPath">The path to save game directory.</param>
        /// <param name="useNetwork">Controls the usage of the network engine.</param>
        /// <param name="deserializeState">Controls if the state is deserialized or not.</param>
        /// <param name="fileName">The path to the state file.</param>
        /// <param name="reportData">Determines if data should be reported.</param>
        /// <param name="leds">Provides a listing of game leds that can be used.</param>
        /// <param name="trackLastRun">Controls whether the PAC keeps track of the last run creature for blacklisting.</param>
        private GameEngine(string dataPath, bool useNetwork, bool deserializeState, string fileName, bool reportData,
            TerrariumLed[] leds, bool trackLastRun)
        {
            _ledIndicators = leds;
            _currentStateFileName = fileName;

            // test to make sure we're not violating any constraints by current
            // physics settings in the engine.
            EngineSettings.EngineSettingsAsserts();

            // Calculate quanta and worldsize if we haven't done so yet
            if (_reloadSettings)
                CalculateWorldSize();

            _pac = new PrivateAssemblyCache(dataPath, fileName, true, trackLastRun);

            // Reset the appdomain policy since we changed the location of the organism dlls
            // This must be done before any animals are loaded in any way.  Make sure this call stays
            // as soon as possible
            AppDomain.CurrentDomain.SetAppDomainPolicy(SecurityUtils.MakePolicyLevel(_pac.AssemblyDirectory));

            _usingNetwork = useNetwork;
            _populationData = new PopulationData(reportData, leds[(int) LedIndicators.ReportWebService]);

            // Should only happen if an exception prevented a previous attempt to start a game
            if (AppMgr.CurrentScheduler != null)
            {
                AppMgr.DestroyScheduler();
            }

            // Create a scheduler that manages giving the creatures timeslices
            _scheduler = AppMgr.CreateSameDomainScheduler(this);
            _scheduler.Quantum = _organismQuanta;

            if (useNetwork)
            {
                // Required to start up the network listeners
                _networkEngine = new NetworkEngine();
            }

            WorldState currentState;
            Boolean successfulDeserialization = false;
            if (deserializeState && File.Exists(fileName))
            {
                try
                {
                    if (_pac.LastRun.Length != 0)
                    {
                        // The process was killed while an organism was being run, blacklist it
                        // Since this potentially means the animal hung the game.
                        _pac.BlacklistAssemblies(new string[] {_pac.LastRun});
                    }
                    this.deserializeState(fileName);
                    currentState = CurrentVector.State;
                    _scheduler.CurrentState = currentState;
                    _scheduler.CompleteOrganismDeserialization();
                    successfulDeserialization = true;
                }
                catch (Exception e)
                {
                    ErrorLog.LogHandledException(e);
                }
            }

            if (successfulDeserialization) return;

            // Set up initial world state
            currentState = new WorldState(GridWidth, GridHeight);
            currentState.TickNumber = 0;
            currentState.StateGuid = Guid.NewGuid();
            currentState.Teleporter = new Teleporter(AnimalCount/EngineSettings.NumberOfAnimalsPerTeleporter);
            currentState.MakeImmutable();

            WorldVector vector = new WorldVector(currentState);
            CurrentVector = vector;
            _scheduler.CurrentState = currentState;
        }
コード例 #9
0
 public MovementSystem(IGameScheduler gameScheduler)
 {
     _gameScheduler = gameScheduler;
 }
コード例 #10
0
ファイル: GraphicsManager.cs プロジェクト: bythope/bytech
 public GraphicsManager(IBytech bytech, IGameScheduler gameScheduler)
 {
     _bytech        = bytech;
     _gameScheduler = gameScheduler;
 }
コード例 #11
0
ファイル: TickActions.cs プロジェクト: NaseUkolyCZ/Terrarium
        /// <summary>
        ///  Rips through all organisms and wraps their pending actions
        ///  up into the hashtables on a per action type basis.
        /// </summary>
        /// <param name="scheduler">The game scheduler that has all of the organisms.</param>
        internal void GatherActionsFromOrganisms(IGameScheduler scheduler)
        {
            foreach (Organism organism in scheduler.Organisms)
            {
                PendingActions pendingActions = organism.GetThenErasePendingActions();
                if (pendingActions.MoveToAction != null)
                {
                    _moveToActions[organism.ID] = pendingActions.MoveToAction;
                }

                if (pendingActions.AttackAction != null)
                {
                    _attackActions[organism.ID] = pendingActions.AttackAction;
                }

                if (pendingActions.EatAction != null)
                {
                    _eatActions[organism.ID] = pendingActions.EatAction;
                }

                if (pendingActions.ReproduceAction != null)
                {
                    _reproduceActions[organism.ID] = pendingActions.ReproduceAction;
                }

                if (pendingActions.DefendAction != null)
                {
                    _defendActions[organism.ID] = pendingActions.DefendAction;
                }
            }
        }
コード例 #12
0
ファイル: AppMgr.cs プロジェクト: Carolasb/Terrarium
 internal static void DestroyScheduler()
 {
     if (_theScheduler == null) return;
     _theScheduler.Close();
     _theScheduler = null;
 }