Exemplo n.º 1
0
        /// <summary>Initialises the object</summary>
        /// <param name="StateIndex">The state to show</param>
        /// <param name="Overlay">Whether this object is in overlay mode</param>
        /// <param name="Show">Whether the object should be shown immediately on initialisation</param>
        public void Initialize(int StateIndex, bool Overlay, bool Show)
        {
            currentHost.HideObject(internalObject);
            int t = StateIndex;

            if (t >= 0 && States[t].Prototype != null)
            {
                internalObject.Prototype = States[t].Prototype;
            }
            else
            {
                /*
                 * Must internally reset the object, not create a new one.
                 * This allows the reference to keep pointing to the same place
                 */
                internalObject.Prototype = new StaticObject(currentHost);
            }

            CurrentState = StateIndex;
            if (Show)
            {
                if (Overlay)
                {
                    currentHost.ShowObject(internalObject, ObjectType.Overlay);
                }
                else
                {
                    currentHost.ShowObject(internalObject, ObjectType.Dynamic);
                }
            }
        }
Exemplo n.º 2
0
        /// <inheritdoc/>
        public override void Update(AbstractTrain NearestTrain, double TimeElapsed, bool ForceUpdate, bool CurrentlyVisible)
        {
            if (CurrentlyVisible | ForceUpdate)
            {
                if (Object.SecondsSinceLastUpdate >= Object.RefreshRate | ForceUpdate)
                {
                    double timeDelta = Object.SecondsSinceLastUpdate + TimeElapsed;
                    Object.SecondsSinceLastUpdate = 0.0;

                    if (base.Visible)
                    {
                        //Calculate the distance travelled
                        double delta = UpdateTrackFollowerScript(false, NearestTrain, NearestTrain == null ? 0 : NearestTrain.DriverCar, SectionIndex, TrackPosition, Position, true, timeDelta);
                        //Update the front and rear axle track followers
                        FrontAxleFollower.UpdateAbsolute((TrackPosition + FrontAxlePosition) + delta, true, true);
                        RearAxleFollower.UpdateAbsolute((TrackPosition + RearAxlePosition) + delta, true, true);
                        //Update the base object position
                        FrontAxleFollower.UpdateWorldCoordinates(false);
                        RearAxleFollower.UpdateWorldCoordinates(false);
                        UpdateObjectPosition();
                    }

                    //Update the actual animated object- This must be done last in case the user has used Translation or Rotation
                    Object.Update(false, NearestTrain, NearestTrain == null ? 0 : NearestTrain.DriverCar, SectionIndex, FrontAxleFollower.TrackPosition, FrontAxleFollower.WorldPosition, Direction, Up, Side, true, true, timeDelta, true);
                }
                else
                {
                    Object.SecondsSinceLastUpdate += TimeElapsed;
                }

                if (!base.Visible)
                {
                    currentHost.ShowObject(Object.internalObject, ObjectType.Dynamic);
                    base.Visible = true;
                }
            }
            else
            {
                Object.SecondsSinceLastUpdate += TimeElapsed;
                if (base.Visible)
                {
                    currentHost.HideObject(Object.internalObject);
                    base.Visible = false;
                }
            }
        }