From 0587158f9208ecf9f39a6dd0ef7cb7c5663a39f8 Mon Sep 17 00:00:00 2001 From: lbsa71 Date: Tue, 13 Mar 2007 08:55:47 +0000 Subject: -- Trying to get trunk to run from first build * Collected required dll's into /bin * Moved timer start for great justice * Added some Writes to Console, and a Status field * Added dumb NullPhysicsScene and NullPhysicsActor that kicks in if Physics Plugin not specified * Svn-ignored a shitload --- src/physics/PhysicsManager.cs | 119 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 4 deletions(-) (limited to 'src/physics') diff --git a/src/physics/PhysicsManager.cs b/src/physics/PhysicsManager.cs index e5d5bd6..1fee628 100644 --- a/src/physics/PhysicsManager.cs +++ b/src/physics/PhysicsManager.cs @@ -46,15 +46,21 @@ namespace PhysicsSystem public PhysicsScene GetPhysicsScene(string engineName) { - if(_plugins.ContainsKey(engineName)) + if( String.IsNullOrEmpty( engineName ) ) + { + return new NullPhysicsScene(); + } + + if(_plugins.ContainsKey(engineName)) { ServerConsole.MainConsole.Instance.WriteLine("creating "+engineName); return _plugins[engineName].GetScene(); } else { - ServerConsole.MainConsole.Instance.WriteLine("couldn't find physicsEngine: "+ engineName); - return null; + string error = String.Format("couldn't find physicsEngine: {0}", engineName); + ServerConsole.MainConsole.Instance.WriteLine( error ); + throw new ArgumentException( error ); } } @@ -108,6 +114,14 @@ namespace PhysicsSystem public abstract class PhysicsScene { + public static PhysicsScene Null + { + get + { + return new NullPhysicsScene(); + } + } + public abstract PhysicsActor AddAvatar(PhysicsVector position); public abstract PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size); @@ -124,8 +138,49 @@ namespace PhysicsSystem } } + public class NullPhysicsScene : PhysicsScene + { + private static int m_workIndicator; + + public override PhysicsActor AddAvatar(PhysicsVector position) + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : AddAvatar({0})", position ); + return PhysicsActor.Null; + } + + public override PhysicsActor AddPrim(PhysicsVector position, PhysicsVector size) + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : AddPrim({0},{1})", position, size ); + return PhysicsActor.Null; + } + + public override void Simulate(float timeStep) + { + m_workIndicator = ( m_workIndicator + 1 ) % 10; + + ServerConsole.MainConsole.Instance.SetStatus( m_workIndicator.ToString() ); + } + + public override void GetResults() + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : GetResults()" ); + } + + public override void SetTerrain(float[] heightMap) + { + ServerConsole.MainConsole.Instance.WriteLine("NullPhysicsScene : SetTerrain({0} items)", heightMap.Length ); + } + + public override bool IsThreaded + { + get { return false; } + } + } + public abstract class PhysicsActor { + public static readonly PhysicsActor Null = new NullPhysicsActor(); + public abstract PhysicsVector Position { get; @@ -153,7 +208,61 @@ namespace PhysicsSystem public abstract void SetMomentum(PhysicsVector momentum); } - public class PhysicsVector + public class NullPhysicsActor : PhysicsActor + { + public override PhysicsVector Position + { + get + { + return PhysicsVector.Zero; + } + set + { + return; + } + } + + public override PhysicsVector Velocity + { + get + { + return PhysicsVector.Zero; + } + set + { + return; + } + } + + public override PhysicsVector Acceleration + { + get { return PhysicsVector.Zero; } + } + + public override bool Flying + { + get + { + return false; + } + set + { + return; + } + } + + public override void AddForce(PhysicsVector force) + { + return; + } + + public override void SetMomentum(PhysicsVector momentum) + { + return; + } + } + + public class PhysicsVector { public float X; public float Y; @@ -170,5 +279,7 @@ namespace PhysicsSystem Y = y; Z = z; } + + public static readonly PhysicsVector Zero = new PhysicsVector(0f, 0f, 0f); } } -- cgit v1.1