/// <summary> /// Runs one step of simulation. This is called by the Thread Timer /// </summary> /// <param name="state">Needed to conform to timercall back delegate, not used</param> private void DoSimulation(object state) { if (Monitor.TryEnter(lockObject, targetDeltaTime / 2)) { try { // Do work if (scene != null) { IList <Entity> rootEntity = scene.RootEntities; simTime.FrameStart(); //Do keyframing KeyframeEngine.Step(); //Update behaviours PreUpdateScenegraphChildren(rootEntity); UpdateScenegraphChildren(rootEntity); PostUpdateScenegraphChildren(rootEntity); simTime.FrameEnd(); //Calculate timing //Debug.WriteLine("DeltaTime:" + simTime.DeltaTime); //Notify about a finished simulation step TriggerStepFinished(); } } finally { Monitor.Exit(lockObject); } } }
/// <summary> /// Constructs a new engine instance /// </summary> /// <param name="scene">Scenegraph to use for simulations</param> public SimulationEngine(SceneGraph scene) { this.scene = scene; this.simTime = new SimulationTime(); this.simulateStepTimer = new Timer(new TimerCallback(DoSimulation), null, Timeout.Infinite, targetDeltaTime); updatesPerSecond = 30; targetDeltaTime = 1000 / updatesPerSecond; lastDeltaTime = targetDeltaTime; this.keyframeExecutor = new KeyframeEngine(); }
/// <summary> /// Instantiates a new timeline viewmodel /// </summary> public TimelineViewModel(ITinyMessengerHub messenger, KeyframeEngine engine) { NotifyPropertyUpdateRate = 50; TimelineStart = 0; TimelineEnd = 100; Messenger = messenger; //Set up engine Engine = engine; Engine.CurrentTimeChanged += Engine_CurrentTimeChanged; //SetTimeLine(Engine.Keyframes); //MessengerInstance.Register<SelectedNodeChanged>(this, ActiveNodeChanged); //MessengerInstance.Register<ActiveTimelineChanged>(this, TimelineChanged); Messenger.Subscribe <SelectedEntityChanged>(ActiveEntityChanged); Messenger.Subscribe <InvalidateEntity>(OnInvalidateEntitiesMessage); AddKeyframeCommand = new RelayCommand(CaptureKeyframes, CanCaptureKeyframes); Keyframes = new ObservableCollection <KeyframeViewModel>(); playPauseCommand = new RelayCommand(TogglePlayPauseState); }
public static void Send(KeyframeTimeline timeline, KeyframeEngine engine) { Messenger.Default.Send <ActiveTimelineChanged>(new ActiveTimelineChanged(timeline, engine)); }
private ActiveTimelineChanged(KeyframeTimeline timeline, KeyframeEngine engine) { this.Timeline = timeline; Engine = engine; }