Example #1
0
        public static (NeuralBucket bucket, Task <NeuralBucket> addTask, NeuralPool_ManualTick manualPool) AddToNeuralPool(NeuralUtility.ContainerOutput[] links, NeuralPool_ManualTick manualPool)
        {
            // Create the bucket
            NeuralBucket bucket = new NeuralBucket(links.SelectMany(o => UtilityCore.Iterate(o.InternalLinks, o.ExternalLinks)).ToArray());

            Task <NeuralBucket> task = null;

            if (manualPool != null)
            {
                manualPool.Add(bucket);
            }
            else
            {
                // Add to the pool from another thread.  This way the lock while waiting to add won't tie up this thread
                task = Task.Run(() =>
                {
                    NeuralPool.Instance.Add(bucket);
                    return(bucket);
                });
            }

            return(bucket, task, manualPool);
        }
Example #2
0
        public Bot(BotConstruction_Result construction)
        {
            _options     = construction.ArgsExtra.Options;
            _itemOptions = construction.ArgsExtra.ItemOptions;

            _radiation  = construction.ArgsExtra.Radiation;
            _gravity    = construction.ArgsExtra.Gravity;
            _cameraPool = construction.ArgsExtra.CameraPool;

            _parts                     = construction.PartConstruction;
            _thrusters                 = construction.PartConstruction.GetStandardParts <Thruster>(Thruster.PARTTYPE).ToArray();
            _impulseEngines            = construction.PartConstruction.GetStandardParts <ImpulseEngine>(ImpulseEngine.PARTTYPE).ToArray();
            _projectileGuns            = construction.PartConstruction.GetStandardParts <ProjectileGun>(ProjectileGun.PARTTYPE).ToArray();
            _updatableParts_MainThread = construction.UpdatableParts_MainThread;
            _updatableParts_AnyThread  = construction.UpdatableParts_AnyThread;
            _dna      = construction.DNA;
            _dnaParts = construction.DNAParts;

            this.Model     = construction.Model;
            _visualEffects = construction.VisualEffects;

            _isPhysicsStatic = construction.ArgsExtra.IsPhysicsStatic;
            this.PhysicsBody = construction.PhysicsBody;

            this.Radius = construction.Radius;

            _partTransformToModel = _parts.AllPartsArray.
                                    Select(o =>
            {
                Transform3DGroup transform = new Transform3DGroup();
                transform.Children.Add(new TranslateTransform3D(-o.Position.ToVector()));
                transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(o.Orientation.ToReverse())));
                return(transform);
            }).
                                    ToArray();

            // Hook up events
            if (!_isPhysicsStatic)
            {
                this.PhysicsBody.ApplyForceAndTorque += new EventHandler <BodyApplyForceAndTorqueArgs>(PhysicsBody_ApplyForceAndTorque);
            }

            foreach (var part in _parts.AllPartsArray)
            {
                part.RequestWorldLocation += new EventHandler <PartRequestWorldLocationArgs>(Part_RequestWorldLocation);
                part.RequestWorldSpeed    += new EventHandler <PartRequestWorldSpeedArgs>(Part_RequestWorldSpeed);
                part.RequestParent        += new EventHandler <PartRequestParentArgs>(Part_RequestParent);

                part.Resurrected += Part_Resurrected;
                part.Destroyed   += Part_Destroyed;
            }

            // See if there are parts that can gradually change the ship's mass
            if ((_parts.Containers.Fuels.Count > 0 && _parts.StandardParts.ContainsKey(Thruster.PARTTYPE)) ||
                (_parts.Containers.CargoBays.Count > 0 && (_parts.StandardParts.ContainsKey(ConverterMatterToEnergy.PARTTYPE) || _parts.StandardParts.ContainsKey(ConverterMatterToFuel.PARTTYPE))) ||
                (_parts.Containers.Energies.Count > 0 && _parts.Containers.Fuels.Count > 0 && (_parts.StandardParts.ContainsKey(ConverterEnergyToFuel.PARTTYPE) || _parts.StandardParts.ContainsKey(ConverterFuelToEnergy.PARTTYPE)))
                )
            {
                _hasMassChangingUpdatables_Small = true;
            }
            else
            {
                _hasMassChangingUpdatables_Small = false;
            }

            if (_parts.Containers.Ammos.Count > 0 && _parts.StandardParts.ContainsKey(ProjectileGun.PARTTYPE))
            {
                _hasMassChangingUpdatables_Medium = true;
            }
            else
            {
                _hasMassChangingUpdatables_Medium = false;
            }

            // Set up a neural processor on its own thread/task
            _neuronLinks = construction.Links;
            if (_neuronLinks != null)
            {
                var result = AddToNeuralPool(_neuronLinks, construction.ArgsExtra.NeuralPoolManual);
                _linkBucket           = result.bucket;
                _neuralPoolAddTask    = result.addTask;
                _neuralPoolManualTick = result.manualPool;
            }

            _lifeEvents = construction.PartConstruction.LifeEventWatcher;

            this.ShouldRecalcMass_Large = false;
            this.ShouldRecalcMass_Small = false;

            this.CreationTime = DateTime.UtcNow;
        }
Example #3
0
 public ArenaAccessor(int numRooms, double roomSize, double roomMargins, bool dividerWalls, bool shouldMapBuildSnapshots, Type[] updateTypes_main, Type[] updateTypes_any, NeuralPool_ManualTick neuralPoolManual, (double elapsed, double randPercent)?worldUpdateTime = null)