internal BaseMotionPlayer(TaPa_XYCyl Owner, string MotionDataPath, string GamePath, string StartOptionsRunArgs, string RuntimeProcess, string StartOptionsInput, AvalibleProtocols MotionDeviceProtocol, string ConnectonString) { this.Owner = Owner; FrameData = PositionAndTimingDataModel.DataLoadFromFile(MotionDataPath); this.MotionDeviceProtocol = MotionDeviceProtocol; switch (MotionDeviceProtocol) { case AvalibleProtocols.ComPort: if (MotionHardwareInterface != null) { MotionHardwareInterface.Dispose(); } MotionHardwareInterface = JMDM_CylinderPortControlUpdated.ConnectionFactory(ConnectonString); break; default: Owner.PlayBacksEnd.Invoke(); throw new Exception("Error: not a valid Protocol."); } this.GamePath = GamePath; this.StartOptionsRunArgs = StartOptionsRunArgs; this.StartOptionsInput = StartOptionsInput; this.RuntimeProcess = RuntimeProcess; Start(); }
internal virtual void Start() { Run = true; ThreadLoop = new Thread(new ThreadStart( () => { GrabHardware(); lock (LockObj) { LoopFinished = false; if (!StartGame()) { return; } FrameTimer = new Stopwatch(); FrameTimer.Start(); } int PosPointer = 0; while (Run) { while ((ulong)FrameTimer.ElapsedMilliseconds < FrameData[PosPointer].Time) { ; } AnimateFame(FrameData[PosPointer]); FrameTimer.Restart(); PosPointer += 1; if (PosPointer % 10 == 0 && GameRunTime.HasExited) { Run = false; } if (PosPointer >= FrameData.Count) { Run = false; } } ReleaseHardware(); lock (LockObj) LoopFinished = true; if (!GameRunTime.HasExited) { GameRunTime.Kill(); } if (MotionHardwareInterface != null) { MotionHardwareInterface.Dispose(); } if (!StopedFromControl) { Owner.PlayBacksEnd.Invoke(); } })); ThreadLoop.IsBackground = true; ThreadLoop.Start(); }