Exemplo n.º 1
0
        public override void Update(TimeSpan t)
        {
            this.totalInvestment = this.ecoStats.Values.Sum(stat => stat.Investment);

            var credits = this.Income * t.NumericValue;

            this.invest(credits);
        }
 public ServerContinuousSynchronizer(GameState game, NetServer server, PlayerConnectionLookup connections)
     : base(game)
 {
     this.server = server;
     this.connections = connections;
     this.timeToNextObjectUpdate = TimeSpan.One;
     this.timeToNextEcoUpdate = TimeSpan.One;
 }
Exemplo n.º 3
0
 public ServerContinuousSynchronizer(GameState game, NetServer server, PlayerConnectionLookup connections)
     : base(game)
 {
     this.server                 = server;
     this.connections            = connections;
     this.timeToNextObjectUpdate = TimeSpan.One;
     this.timeToNextEcoUpdate    = TimeSpan.One;
 }
Exemplo n.º 4
0
        public void Update(TimeSpan elapsedS)
        {
            _gameState.Update(elapsedS);

            // Explosions
            foreach (var gameObject in _gameState.DeadGameObjects)
            {
                ExplosionManager.Explode(gameObject);
            }
        }
Exemplo n.º 5
0
        public void Update(TimeSpan elapsedTimeInS)
        {
            for (int i = Particles.Count - 1; i >= 0; i--)
            {
                var particle = Particles[i];

                particle.Update(elapsedTimeInS);

                if (!particle.IsAlive)
                {
                    Particles.RemoveAt(i);
                }
            }
        }
Exemplo n.º 6
0
        public override void Update(TimeSpan t)
        {
            this.timeToNextObjectUpdate -= t;
            this.timeToNextEcoUpdate    -= t;

            if (this.timeToNextEcoUpdate < TimeSpan.Zero)
            {
                this.sendEcoUpdate();
                this.timeToNextEcoUpdate = TimeSpan.One;
            }

            if (this.timeToNextObjectUpdate < TimeSpan.Zero)
            {
                this.sendObjectUpdate();
                // TODO: check math (intent: sends packages more often when there are more objects, to keep update frequency of single objects stable)
                this.timeToNextObjectUpdate = TimeSpan.One * (0.5f / (this.objects.Count + 2));
            }
        }
        public override void Update(TimeSpan t)
        {
            this.timeToNextObjectUpdate -= t;
            this.timeToNextEcoUpdate -= t;

            if (this.timeToNextEcoUpdate < TimeSpan.Zero)
            {
                this.sendEcoUpdate();
                this.timeToNextEcoUpdate = TimeSpan.One;
            }

            if (this.timeToNextObjectUpdate < TimeSpan.Zero)
            {
                this.sendObjectUpdate();
                // TODO: check math (intent: sends packages more often when there are more objects, to keep update frequency of single objects stable)
                this.timeToNextObjectUpdate = TimeSpan.One * (0.5f / (this.objects.Count + 2));
            }
        }
Exemplo n.º 8
0
        public void DistributeResources(TimeSpan elapsedTime)
        {
            currentResources += elapsedTime.NumericValue * totalResourcesProvided;
            var resourceOut = elapsedTime.NumericValue * totalResourcesRequested;

            if (resourceOut <= currentResources)
            {
                foreach (var consumer in resourceConsumers)
                {
                    var consumerGrantedResources = elapsedTime.NumericValue * consumer.RatePerS;
                    var grant = new ResourceGrant(
                        Math.Min(consumer.Maximum, consumerGrantedResources),
                        consumerGrantedResources >= consumer.Maximum);
                    currentResources -= grant.Amount;
                    consumer.ConsumeResources(grant);
                }
                resetForFrame();
                return;
            }

            var sortedConsumers = resourceConsumers.OrderBy((consumer) => (consumer.Maximum / consumer.RatePerS));
            var resourceRatio   = currentResources / resourceOut;

            foreach (var consumer in sortedConsumers)
            {
                var consumerGrantedResources = resourceRatio * elapsedTime.NumericValue * consumer.RatePerS;
                if (consumer.Maximum <= consumerGrantedResources)
                {
                    consumer.ConsumeResources(new ResourceGrant(consumer.Maximum, true));
                    resourceOut      -= consumer.Maximum;
                    currentResources -= consumer.Maximum;
                    resourceRatio     = currentResources / resourceOut;
                }
                else
                {
                    consumer.ConsumeResources(new ResourceGrant(consumerGrantedResources, false));
                    currentResources -= consumerGrantedResources;
                }
            }

            resetForFrame();
        }
Exemplo n.º 9
0
 public abstract void Update(TimeSpan elapsedTime);
Exemplo n.º 10
0
        public override void Update(TimeSpan t)
        {
            this.totalInvestment = this.ecoStats.Values.Sum(stat => stat.Investment);

            var credits = this.Income * t.NumericValue;

            this.invest(credits);
        }
Exemplo n.º 11
0
 public override void Update(TimeSpan elapsedTime)
 {
 }
Exemplo n.º 12
0
 public override void Update(TimeSpan elapsedTime)
 {
 }