private static void CheckItem(PhysicsLogic item) { if (item.Engine != null || item.isChecked) { throw new InvalidOperationException("A PhysicsLogic cannot be added to more then one engine or added twice."); } item.isChecked = true; }
private static void PreCheckItem(PhysicsLogic item) { if (item == null) { throw new ArgumentNullException("item"); } item.isChecked = false; }
void Start() { physicsLogic = this.gameObject.GetComponent <PhysicsLogic> (); movmentLogic = this.gameObject.GetComponent <MovmentLogic> (); scoreLogic = this.gameObject.GetComponent <ScoreLogic>(); playerStatsLogic = this.gameObject.GetComponent <PlayerStatsLogic>(); missionLogic = this.gameObject.GetComponent <MissionLogic>(); animationLogic = this.gameObject.GetComponent <AnimationLogic>(); soundLogic = this.gameObject.GetComponent <SoundLogic>(); }
public MainWindow() { InitializeComponent(); SetMouseEvents(); SetUiElements(); CreateLogic(); SetRenderTimer(60); SetFollowMouseTimer(); Logic.TimerSwitch = true; void SetMouseEvents() { PreviewMouseDown += HoldMouseEventHandler; PreviewMouseUp += ReleaseMouseEventHandler; } void SetUiElements() { var c1 = new WpfCircle(50); var c2 = new WpfCircle(50); Cnvs.Children.Add(c1.Ellipse); Cnvs.Children.Add(c2.Ellipse); entities = new List <WpfCircle>() { c1, c2 }; } void CreateLogic() { Logic = new PhysicsLogic(GetScreenWidth, GetScreenHeight, entities.ToArray()); } void SetFollowMouseTimer() { FollowMouseTimer = new DispatcherTimer(DispatcherPriority.Send); FollowMouseTimer.Tick += FollowMouseTick; FollowMouseTimer.Interval = TimeSpan.FromMilliseconds(16); } void SetRenderTimer(int ticksPerSecond) { RenderUiTimer = new DispatcherTimer(DispatcherPriority.Send); RenderUiTimer.Tick += Draw; RenderUiTimer.Interval = TimeSpan.FromMilliseconds(1000 / ticksPerSecond); RenderUiTimer.Start(); } }
private bool IsLogicExpired(PhysicsLogic logic) { if (!logic.Lifetime.IsExpired) { return(false); } if (LogicsRemoved != null) { removedLogics.Add(logic); } logic.OnRemovedInternal(); return(true); }
private void AddPendingLogics() { logics.AddRange(pendingLogics); for (int index = 0; index < pendingLogics.Count; ++index) { PhysicsLogic logic = pendingLogics[index]; logic.OnAddedInternal(); } if (LogicsAdded != null) { LogicsAdded(this, new CollectionEventArgs <PhysicsLogic>(pendingLogics.AsReadOnly())); } pendingLogics.Clear(); this.logicsNeedSorting = true; }
/// <summary> /// Adds a PhysicsLogic to the pending queue and will be truly added on a call to Update. /// </summary> /// <param name="item">The PhysicsLogic to be added.</param> public void AddLogic(PhysicsLogic item) { PreCheckItem(item); lock (syncRoot) { ReadOnlyCollection <Body> logicBodies = item.LogicBodies; PreCheckBodies(logicBodies); CheckLogic(item); CheckBodies(logicBodies); item.OnPendingInternal(this); pendingLogics.Add(item); BodiesOnPending(logicBodies); pendingBodies.AddRange(logicBodies); } }
/// <summary> /// Refreshes the table /// </summary> private void Render(object sender, EventArgs e) { if (timer_running) { if ((DateTime.Now - last_render).TotalMilliseconds < 20) { // only once per 20ms return; } last_render = DateTime.Now; // apply physics PhysicsLogic.TransformSystem(tableDepositor); // refresh the image tablePanel.tableAreaPanel.Repaint(tableDepositor); // refresh opengGL window if (table3D != null && table3D.IsVisible) { table3D.Repaint(tableDepositor); } } }
/// <summary> /// Adds a collection of PhysicsLogics to the pending queue and will be truly added on a call to Update. /// </summary> /// <param name="collection">The collection to be Added</param> /// <typeparam name="T">A Type inherited from PhysicsLogic</typeparam> public void AddLogicRange <T>(ICollection <T> collection) where T : PhysicsLogic { if (collection == null) { throw new ArgumentNullException("collection"); } if (collection.Count == 0) { return; } lock (syncRoot) { List <Body> logicBodies = new List <Body>(); foreach (T item in collection) { PreCheckItem(item); logicBodies.AddRange(item.LogicBodies); } PreCheckBodies(logicBodies); PhysicsLogic[] array = new PhysicsLogic[collection.Count]; int index = 0; foreach (T item in collection) { CheckLogic(item); array[index++] = item; } CheckBodies(logicBodies); foreach (T item in collection) { item.OnPendingInternal(this); } pendingLogics.AddRange(array); BodiesOnPending(logicBodies); pendingBodies.AddRange(logicBodies); } }
// Use this for initialization void Start() { physicsLogic = GameObject.Find("Logic").GetComponent <PhysicsLogic>(); }
private void CheckLogic(PhysicsLogic logic) { CheckItem(logic); logic.BeforeAddCheck(this); }