source: 2013/30/MiskaK/MW2(My Warfare 2)/Paranneltu Jypeli/Physics2DDotNet/Solvers/CollisionSolver.cs @ 4507

Revision 4507, 3.3 KB checked in by anlakane, 6 years ago (diff)

Talletus.

Line 
1#region MIT License
2/*
3 * Copyright (c) 2005-2008 Jonathan Mark Porter. http://physics2d.googlepages.com/
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22#endregion
23
24
25
26#if UseDouble
27using Scalar = System.Double;
28#else
29using Scalar = System.Single;
30#endif
31using System;
32using System.Collections.Generic;
33using System.Collections.ObjectModel;
34using Physics2DDotNet.Joints;
35
36
37namespace Physics2DDotNet.Solvers
38{
39
40#if !(WINDOWS_PHONE || XBOX)
41    [Serializable]
42#endif
43    public abstract class CollisionSolver
44    {
45        protected static void SetTag(Body body, object tag)
46        {
47            if (body == null) { throw new ArgumentNullException("body"); }
48            body.SolverTag = tag;
49        }
50
51        PhysicsEngine engine;
52
53        protected List<Joint> Joints { get { return engine.joints; } }
54        protected List<Body> Bodies { get { return engine.bodies; } }
55        /// <summary>
56        /// The engine this solver is in.
57        /// </summary>
58        public PhysicsEngine Engine
59        {
60            get { return engine; }
61        }
62
63        protected internal abstract bool TryGetIntersection(TimeStep step, Body first, Body second, out IContact contact);
64        protected internal abstract void Solve(TimeStep step);
65
66        internal void OnAddedInternal(PhysicsEngine engine)
67        {
68            if (this.engine != null) { throw new InvalidOperationException(); }
69            this.engine = engine;
70            OnAdded();
71            this.AddBodyRange(engine.bodies);
72        }
73        internal void OnRemovedInternal()
74        {
75            engine = null;
76            Clear();
77            OnRemoved();
78        }
79        protected virtual void OnAdded() { }
80        protected virtual void OnRemoved() { }
81
82
83        protected internal virtual void Clear() { }
84
85        protected internal virtual void AddBodyRange(List<Body> collection) { }
86        protected internal virtual void AddJointRange(List<Joint> collection) { }
87
88        protected internal virtual void RemoveExpiredBodies() { }
89        protected internal virtual void RemoveExpiredJoints() { }
90        protected void Detect(TimeStep step)
91        {
92            engine.BroadPhase.Detect(step);
93        }
94
95        protected internal abstract void CheckJoint(Joint joint);
96    }
97
98}
Note: See TracBrowser for help on using the repository browser.