Esempio n. 1
0
        public virtual void UpdateBeforeSimulation()
        {
            ProfilerShort.Begin("Thrusters and gyro");
            ThrustSystem.UpdateBeforeSimulation();
            GyroSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
            {
                ProfilerShort.Begin("Wheels");
                WheelSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }

            ProfilerShort.Begin("Conveyors");
            ConveyorSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            ProfilerShort.Begin("Control");
            ControlSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            ProfilerShort.Begin("Cameras");
            CameraSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            if (MySession.Static.Settings.EnableOxygen)
            {
                ProfilerShort.Begin("Oxygen");
                OxygenSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }
        }
Esempio n. 2
0
    //
    // BRAKE
    void BrakingSystem(WheelSystem wheel)
    {
        //PEG DOWN WHEEL WITH BRAKE
        //
        if (wheel.collider != null)
        {
            wheel.collider.brakeTorque = 0f;
        }

        if (Input.GetKeyDown(brake))
        {
            if (brakeActivated)
            {
                if (wheel.attachedMotor)
                {
                    wheel.collider.motorTorque = direction * (availablePushForce / 10f);
                }
                brakeActivated = false;
            }
            else if (!brakeActivated)
            {
                brakeActivated = true;
            }
            //panelControls.brakesButton = false;
        }


        //
        //ACTIVATE BRAKE
        if (brakeActivated && wheel.attachedMotor)
        {
            wheel.collider.brakeTorque = brakeTorque;
        }
    }
Esempio n. 3
0
    //
    //ALLIGN WHEEL TO COLLIDER
    void WheelAllignment(WheelSystem system, Transform wheel)
    {
        if (wheel != null)
        {
            RaycastHit hit;
            WheelHit   CorrespondingGroundHit;
            if (system.collider != null)
            {
                Vector3 ColliderCenterPoint = system.collider.transform.TransformPoint(system.collider.center);
                system.collider.GetGroundHit(out CorrespondingGroundHit);

                if (Physics.Raycast(ColliderCenterPoint, -system.collider.transform.up, out hit, (system.collider.suspensionDistance + system.collider.radius) * transform.localScale.y))
                {
                    wheel.position = hit.point + (system.collider.transform.up * system.collider.radius) * transform.localScale.y;
                    float extension = (-system.collider.transform.InverseTransformPoint(CorrespondingGroundHit.point).y - system.collider.radius) / system.collider.suspensionDistance;
                    Debug.DrawLine(CorrespondingGroundHit.point, CorrespondingGroundHit.point + system.collider.transform.up, extension <= 0.0 ? Color.magenta : Color.white);
                    Debug.DrawLine(CorrespondingGroundHit.point, CorrespondingGroundHit.point - system.collider.transform.forward * CorrespondingGroundHit.forwardSlip * 2f, Color.green);
                    Debug.DrawLine(CorrespondingGroundHit.point, CorrespondingGroundHit.point - system.collider.transform.right * CorrespondingGroundHit.sidewaysSlip * 2f, Color.red);
                }
                else
                {
                    wheel.transform.position = Vector3.Lerp(wheel.transform.position, ColliderCenterPoint - (system.collider.transform.up * system.collider.suspensionDistance) * transform.localScale.y, Time.deltaTime * 10f);
                }
            }
        }
    }
        public void UpdateBeforeSimulation()
        {
            ProfilerShort.Begin("Thrusters");
            MyEntityThrustComponent thrustComp;

            if (CubeGrid.Components.TryGet(out thrustComp))
            {
                thrustComp.UpdateBeforeSimulation(false, Sync.IsServer || CubeGrid.GridSystems.ControlSystem.IsLocallyControlled);
            }
            ProfilerShort.End();

            // Only update gyros if there are gyros in the system
            if (GyroSystem.GyroCount > 0)
            {
                ProfilerShort.Begin("Gyros");
                GyroSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }

            if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
            {
                ProfilerShort.Begin("Wheels");
                WheelSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }

            /*ProfilerShort.Begin("Conveyors");
             * ConveyorSystem.UpdateBeforeSimulation();
             * ProfilerShort.End();*/

            ProfilerShort.Begin("Control");
            ControlSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            ProfilerShort.Begin("Cameras");
            CameraSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            if (MySession.Static.Settings.EnableOxygen && MySession.Static.Settings.EnableOxygenPressurization)
            {
                ProfilerShort.Begin("Oxygen");
                GasSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }

            if (MyPerGameSettings.EnableJumpDrive)
            {
                ProfilerShort.Begin("Jump");
                JumpSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }

            ProfilerShort.Begin("Ship sounds");
            if (ShipSoundComponent != null)
            {
                ShipSoundComponent.Update();
            }
            ProfilerShort.End();
        }
Esempio n. 5
0
        public virtual void UpdateBeforeSimulation()
        {
            ProfilerShort.Begin("Thrusters and Gyro");
            MyEntityThrustComponent thrustComp;

            if (CubeGrid.Components.TryGet(out thrustComp))
            {
                thrustComp.UpdateBeforeSimulation();
            }

            GyroSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
            {
                ProfilerShort.Begin("Wheels");
                WheelSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }

            ProfilerShort.Begin("Conveyors");
            ConveyorSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            ProfilerShort.Begin("Control");
            ControlSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            ProfilerShort.Begin("Cameras");
            CameraSystem.UpdateBeforeSimulation();
            ProfilerShort.End();

            if (MySession.Static.Settings.EnableOxygen)
            {
                ProfilerShort.Begin("Oxygen");
                GasSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }

            if (MyPerGameSettings.EnableJumpDrive)
            {
                ProfilerShort.Begin("Jump");
                JumpSystem.UpdateBeforeSimulation();
                ProfilerShort.End();
            }
        }
Esempio n. 6
0
 //
 //ROTATE WHEEL
 void RotateWheel(Transform wheel, WheelSystem system)
 {
     if (system.collider != null)
     {
         speed = system.collider.rpm;
     }
     if (wheel != null)
     {
         //
         if (system.AxisX)
         {
             wheel.Rotate(new Vector3(speed * Time.deltaTime, 0, 0));
         }
         if (system.AxisY)
         {
             wheel.Rotate(new Vector3(0, speed * Time.deltaTime, 0));
         }
         if (system.AxisZ)
         {
             wheel.Rotate(new Vector3(0, 0, speed * Time.deltaTime));
         }
     }
 }
        public virtual void UnregisterFromSystems(MyCubeBlock block)
        {
            // Note: ResourceDistributor, WeaponSystem and TemrminalSystem can be null on closing (they are not in the ship but in the logical group). That's why they are null-checked
            if (ResourceDistributor != null)
            {
                ProfilerShort.Begin("Unregister Power producer");
                var powerProducer = block.Components.Get <MyResourceSourceComponent>();
                if (powerProducer != null)
                {
                    ResourceDistributor.RemoveSource(powerProducer);
                }

                ProfilerShort.BeginNextBlock("Unregister Power consumer");
                var powerConsumer = block.Components.Get <MyResourceSinkComponent>();
                if (!(block is MyThrust) && powerConsumer != null)
                {
                    ResourceDistributor.RemoveSink(powerConsumer);
                }

                ProfilerShort.End();

                var socketOwner = block as IMyRechargeSocketOwner;
                if (socketOwner != null)
                {
                    socketOwner.RechargeSocket.ResourceDistributor = null;
                }
            }

            ProfilerShort.Begin("Unregister gun object");
            if (WeaponSystem != null)
            {
                var weapon = block as IMyGunObject <MyDeviceBase>;
                if (weapon != null)
                {
                    WeaponSystem.Unregister(weapon);
                }
            }

            ProfilerShort.BeginNextBlock("Unregister functional block");
            if (TerminalSystem != null)
            {
                var functionalBlock = block as MyTerminalBlock;
                if (functionalBlock != null)
                {
                    TerminalSystem.Remove(functionalBlock);
                }
            }

            // CH: We probably don't need to unregister controller blocks here. It's done in ShipController's OnUnregisteredFromGridSystems

            /*ProfilerShort.BeginNextBlock("Unregister controller block");
             * if (ControlSystem != null)
             * {
             *  var controllableBlock = block as MyShipController;
             *  if (controllableBlock != null && controllableBlock.ControllerInfo.Controller != null)
             *      ControlSystem.RemoveControllerBlock(controllableBlock);
             * }*/

            ProfilerShort.BeginNextBlock("Unregister inventory block");
            var inventoryBlock = (block != null && block.HasInventory) ? block : null;

            if (inventoryBlock != null && inventoryBlock.HasInventory)
            {
                ConveyorSystem.Remove(inventoryBlock);
            }

            ProfilerShort.BeginNextBlock("Unregister conveyor block");
            var conveyorBlock = block as IMyConveyorEndpointBlock;

            if (conveyorBlock != null)
            {
                ConveyorSystem.RemoveConveyorBlock(conveyorBlock);
            }

            ProfilerShort.BeginNextBlock("Unregister segment block");
            var segmentBlock = block as IMyConveyorSegmentBlock;

            if (segmentBlock != null)
            {
                ConveyorSystem.RemoveSegmentBlock(segmentBlock);
            }

            ProfilerShort.BeginNextBlock("Unregister Reflector light");
            var reflectorLight = block as MyReflectorLight;

            if (reflectorLight != null)
            {
                ReflectorLightSystem.Unregister(reflectorLight);
            }

            if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
            {
                ProfilerShort.BeginNextBlock("Unregister wheel");
                var wheel = block as MyMotorSuspension;
                if (wheel != null)
                {
                    WheelSystem.Unregister(wheel);
                }
            }

            ProfilerShort.BeginNextBlock("Unregister landing gear");
            var gear = block as IMyLandingGear;

            if (gear != null)
            {
                LandingSystem.Unregister(gear);
            }

            ProfilerShort.BeginNextBlock("Unregister gyro");
            var gyro = block as MyGyro;

            if (gyro != null)
            {
                GyroSystem.Unregister(gyro);
            }

            ProfilerShort.BeginNextBlock("Unregister camera");
            var camera = block as MyCameraBlock;

            if (camera != null)
            {
                CameraSystem.Unregister(camera);
            }

            ProfilerShort.BeginNextBlock("block.OnUnregisteredFromGridSystems()");
            block.OnUnregisteredFromGridSystems();

            ProfilerShort.End();
        }
        public virtual void RegisterInSystems(MyCubeBlock block)
        {
            if (ResourceDistributor != null)
            {
                var powerProducer = block.Components.Get <MyResourceSourceComponent>();
                if (powerProducer != null)
                {
                    ResourceDistributor.AddSource(powerProducer);
                }

                var powerConsumer = block.Components.Get <MyResourceSinkComponent>();
                if (!(block is MyThrust) && powerConsumer != null)
                {
                    ResourceDistributor.AddSink(powerConsumer);
                }

                var socketOwner = block as IMyRechargeSocketOwner;
                if (socketOwner != null)
                {
                    socketOwner.RechargeSocket.ResourceDistributor = ResourceDistributor;
                }
            }

            if (WeaponSystem != null)
            {
                var weapon = block as IMyGunObject <MyDeviceBase>;
                if (weapon != null)
                {
                    WeaponSystem.Register(weapon);
                }
            }

            if (TerminalSystem != null)
            {
                var functionalBlock = block as MyTerminalBlock;
                if (functionalBlock != null)
                {
                    TerminalSystem.Add(functionalBlock);
                }
            }

            // CH: We probably don't need to register controller blocks here. Block that's being added to a grid should not have a controller set
            var controllableBlock = block as MyShipController;

            Debug.Assert(controllableBlock == null || controllableBlock.ControllerInfo.Controller == null, "Controller of added block is not null. Call Cestmir");

            /*if (ControlSystem != null)
             * {
             *  var controllableBlock = block as MyShipController;
             *  if (controllableBlock != null && controllableBlock.ControllerInfo.Controller != null)
             *      ControlSystem.AddControllerBlock(controllableBlock);
             * }*/

            var inventoryBlock = (block != null && block.HasInventory) ? block : null;

            if (inventoryBlock != null)
            {
                ConveyorSystem.Add(inventoryBlock);
            }

            var conveyorBlock = block as IMyConveyorEndpointBlock;

            if (conveyorBlock != null)
            {
                conveyorBlock.InitializeConveyorEndpoint();
                ConveyorSystem.AddConveyorBlock(conveyorBlock);
            }

            var segmentBlock = block as IMyConveyorSegmentBlock;

            if (segmentBlock != null)
            {
                segmentBlock.InitializeConveyorSegment();
                ConveyorSystem.AddSegmentBlock(segmentBlock);
            }

            var reflectorLight = block as MyReflectorLight;

            if (reflectorLight != null)
            {
                ReflectorLightSystem.Register(reflectorLight);
            }

            if (MyFakes.ENABLE_WHEEL_CONTROLS_IN_COCKPIT)
            {
                var wheel = block as MyMotorSuspension;
                if (wheel != null)
                {
                    WheelSystem.Register(wheel);
                }
            }

            var landingGear = block as IMyLandingGear;

            if (landingGear != null)
            {
                LandingSystem.Register(landingGear);
            }

            var gyro = block as MyGyro;

            if (gyro != null)
            {
                GyroSystem.Register(gyro);
            }

            var camera = block as MyCameraBlock;

            if (camera != null)
            {
                CameraSystem.Register(camera);
            }

            block.OnRegisteredToGridSystems();
        }