コード例 #1
0
 /**
  *  @brief Instantiates a 2D physics for tests purpose.
  **/
 internal static void InitTest2D()
 {
     instance                = new Physics2DWorldManager();
     instance.Gravity        = new FPVector(0, -10, 0);
     instance.LockedTimeStep = 0.02f;
     instance.Init();
 }
コード例 #2
0
        public AbstractLockstep(FP deltaTime, ICommunicator communicator, IPhysicsManager physicsManager, int syncWindow, int panicWindow, int rollbackWindow, TrueSyncEventCallback OnGameStarted, TrueSyncEventCallback OnGamePaused, TrueSyncEventCallback OnGameUnPaused, TrueSyncEventCallback OnGameEnded, TrueSyncPlayerDisconnectionCallback OnPlayerDisconnection, TrueSyncUpdateCallback OnStepUpdate, TrueSyncInputCallback GetLocalData)
        {
            this.deltaTime             = deltaTime;
            this.syncWindow            = syncWindow;
            this.panicWindow           = panicWindow;
            this.rollbackWindow        = rollbackWindow;
            this.totalWindow           = syncWindow + rollbackWindow;
            this.StepUpdate            = OnStepUpdate;
            this.OnGameStarted         = OnGameStarted;
            this.OnGamePaused          = OnGamePaused;
            this.OnGameUnPaused        = OnGameUnPaused;
            this.OnGameEnded           = OnGameEnded;
            this.OnPlayerDisconnection = OnPlayerDisconnection;
            this.GetLocalData          = GetLocalData;
            this.ticks        = 0;
            this.players      = new SortedDictionary <byte, TSPlayer>();
            this.communicator = communicator;
            bool flag = communicator != null;

            if (flag)
            {
                this.communicator.AddEventListener(new OnEventReceived(this.OnEventDataReceived));
            }
            this.physicsManager     = physicsManager;
            this.compoundStats      = new CompoundStats();
            this.bufferSyncedInfo   = new GenericBufferWindow <SyncedInfo>(3);
            this.checksumOk         = true;
            this.simulationState    = AbstractLockstep.SimulationState.NOT_STARTED;
            this.bodiesToDestroy    = new Dictionary <int, List <IBody> >();
            this.delegatesToExecute = new Dictionary <int, List <Delegate> >();
            this.ReplayRecord       = ReplayRecord.replayToLoad;
            this.ReplayMode         = ReplayRecord.replayMode;
            this.time = FP.Zero;
            StateTracker.AddTracking(this, "time");
        }
コード例 #3
0
ファイル: EntityFactory.cs プロジェクト: Nosrick/JoyGodot
 public EntityFactory(
     GUIDManager guidManager,
     INeedHandler needHandler,
     IObjectIconHandler objectIconHandler,
     ICultureHandler cultureHandler,
     IEntitySexualityHandler sexualityHandler,
     IEntityBioSexHandler sexHandler,
     IGenderHandler genderHandler,
     IEntityRomanceHandler romanceHandler,
     IJobHandler jobHandler,
     IPhysicsManager physicsManager,
     IEntitySkillHandler skillHandler,
     IDerivedValueHandler derivedValueHandler,
     RNG roller)
 {
     this.GuidManager         = guidManager;
     this.Roller              = roller;
     this.NeedHandler         = needHandler;
     this.ObjectIcons         = objectIconHandler;
     this.CultureHandler      = cultureHandler;
     this.SexualityHandler    = sexualityHandler;
     this.BioSexHandler       = sexHandler;
     this.JobHandler          = jobHandler;
     this.RomanceHandler      = romanceHandler;
     this.GenderHandler       = genderHandler;
     this.PhysicsManager      = physicsManager;
     this.SkillHandler        = skillHandler;
     this.DerivedValueHandler = derivedValueHandler;
 }
コード例 #4
0
ファイル: Root.cs プロジェクト: hccampos/XtremeEngineXNA
        /// <summary>
        /// Initializes the root object.
        /// </summary>
        /// <param name="serviceProvider">
        /// IServiceProvider used to locate the IGraphicsDeviceService implementation.
        /// </param>
        public void Initialize(IServiceProvider serviceProvider)
        {
            try
            {
                //Save the service provider.
                Services = serviceProvider;

                //Get the graphics device from the service provider.
                IGraphicsDeviceService service = Services.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;
                if (service == null)
                {
                    string msg = "could not locate the IGraphicsDeviceService implementation.";
                    throw new NullReferenceException(msg);
                }

                //Get the graphics device from the graphics device service.
                mGraphicsDevice = service.GraphicsDevice;

                //Create the default content manager.
                mDefaultContentManager = new ContentManager(serviceProvider, "Content");

                //Create all the other core plug-ins.
                mSceneManager       = new DefaultSceneManager(this, "sceneManager");
                mPostProcessManager = new DefaultPostProcessManager(this, "postProcessManager");
                mRenderer           = new DeferredRenderer(this, "deferred_renderer");
                mPhysicsManager     = new JigLibXPhysicsManager(this, "physicsManager");
                mEntityManager      = new DefaultEntityManager(this, "entityManager");
                mAnimationManager   = new DefaultAnimationManager(this, "animationManager");
                mGuiManager         = new DefaultGuiManager(this, "guiManager");

                //Update the physics before updating the scene so that the physics objects
                //(which are nodes) can update their positions based on the physics world.
                mPhysicsManager.UpdateOrder = 0;
                mSceneManager.UpdateOrder   = 1;

                mRenderer.Layer = 0;

                //Add all the core plug-ins to the plug-ins dictionary.
                AddPlugin(mSceneManager);
                AddPlugin(mPostProcessManager);
                AddPlugin(mRenderer);
                AddPlugin(mPhysicsManager);
                AddPlugin(mEntityManager);
                AddPlugin(mAnimationManager);
                AddPlugin(mGuiManager);

                //Initialize all the plugins.
                foreach (KeyValuePair <string, IPlugin> kvp in mPlugins)
                {
                    kvp.Value.Initialize();
                }

                mInitialized = true;
            }
            catch (Exception e)
            {
                throw new Exception("Root.Initialize(): " + e.Message);
            }
        }
コード例 #5
0
        /**
         *  @brief Instantiates a new {@link IPhysicsManager}.
         *
         *  @param trueSyncConfig Indicates if is 3D world.
         **/
        public static IPhysicsManager New(TrueSyncConfig trueSyncConfig)
        {
            instance                     = new PhysicsWorldManager();
            instance.Gravity             = trueSyncConfig.gravity3D;
            instance.SpeculativeContacts = trueSyncConfig.speculativeContacts3D;


            return(instance);
        }
コード例 #6
0
ファイル: TrixelParticleSystem.cs プロジェクト: Zeludon/FEZ
 public TrixelParticleSystem(Game game, TrixelParticleSystem.Settings settings)
   : base(game)
 {
   this.settings = settings;
   this.DrawOrder = 10;
   this.PhysicsManager = ServiceHelper.Get<IPhysicsManager>();
   this.CameraManager = ServiceHelper.Get<IGameCameraManager>();
   this.GameState = ServiceHelper.Get<IGameStateManager>();
   this.LightingPostProcess = ServiceHelper.Get<ILightingPostProcess>();
   this.CollisionManager = ServiceHelper.Get<ICollisionManager>();
 }
コード例 #7
0
        /// <summary>
        /// Gets the world manifold.
        /// </summary>
        public void GetWorldManifold(IPhysicsManager physicsManager, out Vector2 normal, Span <Vector2> points)
        {
            PhysicsComponent bodyA  = FixtureA?.Body !;
            PhysicsComponent bodyB  = FixtureB?.Body !;
            IPhysShape       shapeA = FixtureA?.Shape !;
            IPhysShape       shapeB = FixtureB?.Shape !;
            var bodyATransform      = physicsManager.EnsureTransform(bodyA);
            var bodyBTransform      = physicsManager.EnsureTransform(bodyB);

            ContactSolver.InitializeManifold(ref Manifold, bodyATransform, bodyBTransform, shapeA.Radius, shapeB.Radius, out normal, points);
        }
コード例 #8
0
 public TrixelParticleSystem(Game game, TrixelParticleSystem.Settings settings)
     : base(game)
 {
     this.settings            = settings;
     this.DrawOrder           = 10;
     this.PhysicsManager      = ServiceHelper.Get <IPhysicsManager>();
     this.CameraManager       = ServiceHelper.Get <IGameCameraManager>();
     this.GameState           = ServiceHelper.Get <IGameStateManager>();
     this.LightingPostProcess = ServiceHelper.Get <ILightingPostProcess>();
     this.CollisionManager    = ServiceHelper.Get <ICollisionManager>();
 }
コード例 #9
0
        public override void Initialize()
        {
            //Tell the collision manager we want to subscribe...
            IPhysicsManager collisionManager = GameServiceManager.GetService <IPhysicsManager>();

            if (collisionManager != null)
            {
                collisionManager.SubscribeCollisionEvent(this.ParentGameObject.GUID, OnCollision);
            }

            base.Initialize();
        }
コード例 #10
0
        public override void Initialize()
        {
            //Let's grab a reference to the other services that we'll need!
            gameObjectManager = GameServiceManager.GetService<IGameObjectManager>();
            physicsManager = GameServiceManager.GetService<IPhysicsManager>();
            renderer = GameServiceManager.GetService<IRenderer>();

            levelBuilder = new LevelBuilder();
            levelBuilder.Initialize();

            GameOver = false;
        }
コード例 #11
0
 public DungeonEntityPlacer(
     ILiveEntityHandler entityHandler,
     ICultureHandler cultureHandler,
     IEntityTemplateHandler templateHandler,
     IPhysicsManager physicsManager,
     IEntityFactory entityFactory)
 {
     this.EntityFactory         = entityFactory;
     this.CultureHandler        = cultureHandler;
     this.EntityTemplateHandler = templateHandler;
     this.PhysicsManager        = physicsManager;
     this.EntityHandler         = entityHandler;
 }
コード例 #12
0
 public Context(Scene scene,
                SceneManager sceneManager,
                IPhysicsManager physicsManager,
                IInputManager inputManager,
                ContentManager contentManager,
                GraphicsDevice graphicsDevice)
 {
     Scene          = scene;
     SceneManager   = sceneManager;
     PhysicsManager = physicsManager;
     Input          = inputManager;
     Content        = contentManager;
     GraphicsDevice = graphicsDevice;
 }
コード例 #13
0
ファイル: SceneManager.cs プロジェクト: srakowski/coldsteel
        public override void Initialize()
        {
            base.Initialize();
            this._sceneFactory   = Game.Services.GetService <ISceneFactory>();
            this._physicsManager = Game.Services.GetService <IPhysicsManager>();
            this._inputManager   = Game.Services.GetService <IInputManager>();
            _initialized         = true;

            if (_pendingScene != null)
            {
                var sceneName = _pendingScene;
                _pendingScene = null;
                Start(sceneName);
            }
        }
コード例 #14
0
        void Awake()
        {
            instance = this;

            FixedPointConfig currentConfig = ActiveConfig;
            FP lockedTimeStep = currentConfig.lockedTimeStep;


            if (currentConfig.physics2DEnabled || currentConfig.physics3DEnabled)
            {
                PhysicsManager.New(currentConfig);
                PhysicsManager.instance.LockedTimeStep = lockedTimeStep;
                PhysicsManager.instance.Init();
            }
            physics = PhysicsManager.instance;
        }
コード例 #15
0
        /**
         *  @brief Instantiates a new {@link IPhysicsManager}.
         *
         *  @param FixedPointConfig Indicates if is a 2D or 3D world.
         **/
        public static IPhysicsManager New(FixedPointConfig FixedPointConfig)
        {
            if (FixedPointConfig.physics3DEnabled)
            {
                instance                     = new PhysicsWorldManager();
                instance.Gravity             = FixedPointConfig.gravity3D;
                instance.SpeculativeContacts = FixedPointConfig.speculativeContacts3D;
            }
            else if (FixedPointConfig.physics2DEnabled)
            {
                instance                     = new Physics2DWorldManager();
                instance.Gravity             = new FPVector(FixedPointConfig.gravity2D.x, FixedPointConfig.gravity2D.y, 0);
                instance.SpeculativeContacts = FixedPointConfig.speculativeContacts2D;
            }

            return(instance);
        }
コード例 #16
0
        /**
         *  @brief Instantiates a new {@link IPhysicsManager}.
         *
         *  @param trueSyncConfig Indicates if is a 2D or 3D world.
         **/
        public static IPhysicsManager New(TrueSyncConfig trueSyncConfig)
        {
            if (trueSyncConfig.physics3DEnabled)
            {
                instance                     = new PhysicsWorldManager();
                instance.Gravity             = trueSyncConfig.gravity3D;
                instance.SpeculativeContacts = trueSyncConfig.speculativeContacts3D;
            }
            else if (trueSyncConfig.physics2DEnabled)
            {
                instance                     = new Physics2DWorldManager();
                instance.Gravity             = new TSVector(trueSyncConfig.gravity2D.x, trueSyncConfig.gravity2D.y, 0);
                instance.SpeculativeContacts = trueSyncConfig.speculativeContacts2D;
            }

            return(instance);
        }
コード例 #17
0
        public void Initialize(GameServiceContainer gameServices, ContentManager content, PropertyMap propMap, Vector2 position)
        {
            Health = propMap.GetInt("Health");
            Tag    = propMap["Tag"];

            _spriteSheet = content.Load <Texture2D>(SPRITE_SHEET_PATH);

            Sprite = new Sprite(0, 0, SPRITE_SIZE, SPRITE_SIZE, _spriteSheet);

            Position = position;

            IPhysicsManager physicsManager = gameServices.GetService <IPhysicsManager>();

            this.Collider = physicsManager.CreateRectCollider(this, new Vector2(ROCK_SIZE), false);

            _debugTexture = content.Load <Texture2D>(DEBUG_TEXTURE_PATH);
        }
コード例 #18
0
        public static Dictionary<string, Body> DeserializeBodies(XElement element, IPhysicsManager physicsManager, IPhysicsComponent parent)
        {
            Dictionary<string, Body> bodies = new Dictionary<string, Body>();
            IEnumerable<XElement> elements = element.Elements("body");

            foreach (XElement bodyElement in elements)
            {
                Body body = DeserializeBody(bodyElement, physicsManager, parent);

                if (body != null)
                {
                    string name = ((FarseerUserData) body.UserData).Name;
                    bodies.Add(name, body);
                }
            }

            return bodies;
        }
コード例 #19
0
        public static Dictionary <string, Body> DeserializeBodies(XElement element, IPhysicsManager physicsManager, IPhysicsComponent parent)
        {
            Dictionary <string, Body> bodies   = new Dictionary <string, Body>();
            IEnumerable <XElement>    elements = element.Elements("body");

            foreach (XElement bodyElement in elements)
            {
                Body body = DeserializeBody(bodyElement, physicsManager, parent);

                if (body != null)
                {
                    string name = ((FarseerUserData)body.UserData).Name;
                    bodies.Add(name, body);
                }
            }

            return(bodies);
        }
コード例 #20
0
 public GameManager
 (
     IAnimationManager animationManager,
     ICollisionManager collisionManager,
     IConfigManager configManager,
     IContentManager contentManager,
     IEnemysManager enemysManager,
     IInputManager inputManager,
     ILevelManager levelManager,
     IPlayerManager playerManager,
     IPhysicsManager physicsManager,
     IRandomManager randomManager,
     IResolutionManager resolutionManager,
     IScreenManager screenManager,
     ISoundManager soundManager,
     IScrollManager scrollManager,
     IStateManager stateManager,
     ITileManager tileManager,
     IFileManager fileManager,
     ILogger logger
 )
 {
     AnimationManager  = animationManager;
     CollisionManager  = collisionManager;
     ConfigManager     = configManager;
     ContentManager    = contentManager;
     EnemysManager     = enemysManager;
     InputManager      = inputManager;
     LevelManager      = levelManager;
     PlayerManager     = playerManager;
     PhysicsManager    = physicsManager;
     RandomManager     = randomManager;
     ResolutionManager = resolutionManager;
     SoundManager      = soundManager;
     ScreenManager     = screenManager;
     ScrollManager     = scrollManager;
     StateManager      = stateManager;
     TileManager       = tileManager;
     FileManager       = fileManager;
     Logger            = logger;
 }
コード例 #21
0
ファイル: BaseUnitTests.cs プロジェクト: StevePro7/Platformer
#pragma warning restore 618
        public void TestFixtureTearDown()
        {
            AnimationManager  = null;
            CollisionManager  = null;
            ConfigManager     = null;
            ContentManager    = null;
            EnemysManager     = null;
            InputManager      = null;
            LevelManager      = null;
            PlayerManager     = null;
            PhysicsManager    = null;
            RandomManager     = null;
            ResolutionManager = null;
            ScreenManager     = null;
            SoundManager      = null;
            ScrollManager     = null;
            StateManager      = null;
            TileManager       = null;
            FileManager       = null;
            Logger            = null;
        }
コード例 #22
0
ファイル: BaseUnitTests.cs プロジェクト: StevePro7/Platformer
#pragma warning restore 618
        public void TestFixtureSetUp()
        {
            AnimationManager  = MockRepository.GenerateStub <IAnimationManager>();
            CollisionManager  = MockRepository.GenerateStub <ICollisionManager>();
            ConfigManager     = MockRepository.GenerateStub <IConfigManager>();
            ContentManager    = MockRepository.GenerateStub <IContentManager>();
            EnemysManager     = MockRepository.GenerateStub <IEnemysManager>();
            InputManager      = MockRepository.GenerateStub <IInputManager>();
            LevelManager      = MockRepository.GenerateStub <ILevelManager>();
            PlayerManager     = MockRepository.GenerateStub <IPlayerManager>();
            PhysicsManager    = MockRepository.GenerateStub <IPhysicsManager>();
            RandomManager     = MockRepository.GenerateStub <IRandomManager>();
            ResolutionManager = MockRepository.GenerateStub <IResolutionManager>();
            ScreenManager     = MockRepository.GenerateStub <IScreenManager>();
            SoundManager      = MockRepository.GenerateStub <ISoundManager>();
            ScrollManager     = MockRepository.GenerateStub <IScrollManager>();
            StateManager      = MockRepository.GenerateStub <IStateManager>();
            TileManager       = MockRepository.GenerateStub <ITileManager>();
            FileManager       = MockRepository.GenerateStub <IFileManager>();
            Logger            = MockRepository.GenerateStub <ILogger>();
        }
コード例 #23
0
        public override void Deserialize(XElement element)
        {
            IPhysicsManager physicsManager = GameServiceManager.GetService <IPhysicsManager>();

            if (physicsManager != null && element != null)
            {
                //Read in the max velocity value.
                float maxVelocity = float.PositiveInfinity;
                if (element.Element("maxVelocity") != null)
                {
                    float.TryParse(element.Element("maxVelocity").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out maxVelocity);
                }
                MaxVelocity = ConvertUnits.ToSimUnits(maxVelocity);

                if (element.Element("bodies") != null)
                {
                    Bodies = FarseerDeserialization.DeserializeBodies(element.Element("bodies"), physicsManager, this);
                }

                //Record the primary body
                primaryBody = GetPrimaryBody();

                foreach (var body in Bodies.Values)
                {
                    body.Enabled  = false;
                    body.Position = new Vector2(-10f, -10f);
                }

                //A single-body physics component only supports joints that require only a single body (for obvious reasons...)
                //But we'll expect the FarseerDeserialization class to handle any user error with this.
                if (element.Element("joints") != null)
                {
                    this.Joints = FarseerDeserialization.DeserializeJoints(Parent, element.Element("joints"),
                                                                           physicsManager, Bodies);
                }
            }
        }
コード例 #24
0
        public override void Initialize()
        {
            Parent.OnMove += OnMove;

            physicsManager = GameServiceManager.GetService <IPhysicsManager>();

            foreach (var body in Bodies.Values)
            {
                body.Position = ConvertUnits.ToSimUnits(Parent.Position + ((FarseerUserData)body.UserData).Offset) -
                                ((FarseerUserData)body.UserData).TopLeftOffset;
                body.Enabled = true;
            }

            physicsManager.PhysicsWorld.Step(0.000001f);

            foreach (var joint in copyJoints)
            {
                var data = joint.Value.UserData as FarseerJointUserData;

                var bodyA = !string.IsNullOrWhiteSpace(data.BodyAName) &&
                            Bodies.ContainsKey(data.BodyAName)
                                ? Bodies[data.BodyAName]
                                : null;
                var bodyB = !string.IsNullOrWhiteSpace(data.BodyBName) &&
                            Bodies.ContainsKey(data.BodyBName)
                                ? Bodies[data.BodyBName]
                                : null;

                var newJoint = FarseerDeserialization.CopyJoint(joint.Value, bodyA, bodyB, physicsManager.PhysicsWorld);
                physicsManager.PhysicsWorld.AddJoint(newJoint);
                Joints.Add(joint.Key, newJoint);
            }

            copyJoints.Clear();

            base.Initialize();
        }
コード例 #25
0
        public override void Initialize()
        {
            Parent.OnMove += OnMove;

            physicsManager = GameServiceManager.GetService<IPhysicsManager>();

            foreach (var body in Bodies.Values)
            {
                body.Position = ConvertUnits.ToSimUnits(Parent.Position + ((FarseerUserData)body.UserData).Offset) -
                                ((FarseerUserData)body.UserData).TopLeftOffset;
                body.Enabled = true;
            }

            physicsManager.PhysicsWorld.Step(0.000001f);

            foreach (var joint in copyJoints)
            {
                var data = joint.Value.UserData as FarseerJointUserData;

                var bodyA = !string.IsNullOrWhiteSpace(data.BodyAName) &&
                            Bodies.ContainsKey(data.BodyAName)
                                ? Bodies[data.BodyAName]
                                : null;
                var bodyB = !string.IsNullOrWhiteSpace(data.BodyBName) &&
                            Bodies.ContainsKey(data.BodyBName)
                                ? Bodies[data.BodyBName]
                                : null;

                var newJoint = FarseerDeserialization.CopyJoint(joint.Value, bodyA, bodyB, physicsManager.PhysicsWorld);
                physicsManager.PhysicsWorld.AddJoint(newJoint);
                Joints.Add(joint.Key, newJoint);
            }

            copyJoints.Clear();
            
            base.Initialize();
        }
コード例 #26
0
        private static Joint DeserializeJoint(IGameObject parent, XElement jointElement, IPhysicsManager physicsManager, Dictionary<string, Body> bodies)
        {
            Joint joint = null;
            JointType type = JointType.Angle;
            Body bodyA = null, bodyB = null;
            bool collideConnected = false;
            World world = physicsManager.PhysicsWorld;

            var jointData = new FarseerJointUserData();

            if (jointElement.Attribute("type") != null)
                type = (JointType) Enum.Parse(typeof(JointType), jointElement.Attribute("type").Value, true);

            if (jointElement.Element("bodyA") != null)
            {
                var jointName = jointElement.Element("bodyA").Value;
                bodyA = bodies[jointName];
                jointData.BodyAName = jointName;
            }
                

            if (jointElement.Element("bodyB") != null)
            {
                var jointName = jointElement.Element("bodyB").Value;
                bodyB = bodies[jointName];
                jointData.BodyBName = jointName;
            }

            if (jointElement.Element("collideConnected") != null)
                bool.TryParse(jointElement.Element("collideConnected").Value, out collideConnected);

            #region Joint Types Instantiation

            if (bodyA != null)
            {
                switch (type)
                {
                    case JointType.Angle:
                        if (bodyB != null)
                            joint = DeserializeAngleJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.Distance:
                        if (bodyB != null)
                            joint = DeserializeDistanceJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.FixedAngle:
                        joint = DeserializeFixedAngleJoint(jointElement, bodyA, world);
                        break;
                    case JointType.FixedDistance:
                        joint = DeserializeFixedDistanceJoint(jointElement, bodyA, world);
                        break;
                    case JointType.FixedFriction:
                        joint = DeserializeFixedFrictionJoint(jointElement, bodyA, world);
                        break;
                    case JointType.FixedPrismatic:
                        joint = DeserializeFixedPrismaticJoint(jointElement, bodyA, parent, world);
                        break;
                    case JointType.FixedRevolute:
                        joint = DeserializeFixedRevoluteJoint(jointElement, bodyA, world);
                        break;
                    case JointType.Friction:
                        if (bodyB != null)
                            joint = DeserializeFrictionJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.Line:
                        if (bodyB != null)
                            joint = DeserializeLineJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.Prismatic:
                        if (bodyB != null)
                            joint = DeserializePrismaticJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.Pulley:
                        if (bodyB != null)
                            joint = DeserializePulleyJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.Revolute:
                        if (bodyB != null)
                            joint = DeserializeRevoluteJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.Slider:
                        if (bodyB != null)
                            joint = DeserializeSliderJoint(jointElement, bodyA, bodyB, world);
                        break;
                    case JointType.Weld:
                        if (bodyB != null)
                            joint = DeserializeWeldJoint(jointElement, bodyA, bodyB, world);
                        break;
                }
            }
            #endregion

            if (joint != null)
                joint.CollideConnected = collideConnected;

            joint.UserData = jointData;

            return joint;
        }
コード例 #27
0
        public static Body DeserializeBody(XElement element, IPhysicsManager physicsManager, IPhysicsComponent parent)
        {
            Body body = null;
            FarseerUserData userData = new FarseerUserData();
                
            //Read the shape used for this body.
            BodyType bodyType = BodyType.Static;
            if (element.Attribute("bodyType") != null)
            {
                if (element.Attribute("bodyType").Value.StartsWith("d", StringComparison.InvariantCultureIgnoreCase))
                    bodyType = BodyType.Dynamic;
                else if (element.Attribute("bodyType").Value.StartsWith("s", StringComparison.InvariantCultureIgnoreCase))
                    bodyType = BodyType.Static;
                else if (element.Attribute("bodyType").Value.StartsWith("k", StringComparison.InvariantCultureIgnoreCase))
                    bodyType = BodyType.Kinematic;
            }

            bool primary = false;
            if (element.Attribute("primary") != null)
                bool.TryParse(element.Attribute("primary").Value, out primary);

            Shape shape = null;
            XElement shapeElement = element.Element("shape");

            if (shapeElement != null && shapeElement.Attribute("type") != null)
            {
                if (shapeElement.Attribute("type").Value.StartsWith("b", StringComparison.InvariantCultureIgnoreCase))
                    shape = DeserializeBoxShape(shapeElement);
                else if (shapeElement.Attribute("type").Value.StartsWith("c", StringComparison.InvariantCultureIgnoreCase))
                    shape = DeserializeCircleShape(shapeElement);
                else if (shapeElement.Attribute("type").Value.StartsWith("p", StringComparison.InvariantCultureIgnoreCase))
                    shape = DeserializePolygonShape(shapeElement);
            }

            if (shape != null)
            {
                string name;

                body = BodyFactory.CreateBody(physicsManager.PhysicsWorld);
                body.BodyType = bodyType;
                Vector2 offset = Vector2.Zero;

                float friction = 0.5f, linearDamping = 5f, restitution = 0f, mass = 1f;
                bool fixedRotation = false;

                if (element.Element("friction") != null)
                    float.TryParse(element.Element("friction").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out friction);

                if (element.Element("linearDamping") != null)
                    float.TryParse(element.Element("linearDamping").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out linearDamping);

                if (element.Element("restitution") != null)
                    float.TryParse(element.Element("restitution").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out restitution);

                if (element.Element("mass") != null)
                    float.TryParse(element.Element("mass").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out mass);

                if (element.Element("fixedRotation") != null)
                    bool.TryParse(element.Element("fixedRotation").Value, out fixedRotation);

                if (element.Element("offset") != null)
                    offset = offset.DeserializeOffset(element.Element("offset"));
                    
                body.CreateFixture(shape);
                body.Friction = friction;
                body.LinearDamping = linearDamping;
                body.Restitution = restitution;
                body.Mass = mass;
                body.FixedRotation = fixedRotation;

                name = element.Attribute("name") != null ? element.Attribute("name").Value : body.BodyId.ToString();

                userData.TopLeftOffset = ConvertUnits.GetTopLeftCorner(body.FixtureList[0], 0);
                userData.Name = name;
                userData.Primary = primary;
                userData.Owner = parent;
                userData.Offset = offset;

                body.UserData = userData;
            }

            return body;
        }
コード例 #28
0
 public RollbackLockstep(FP deltaTime, ICommunicator communicator, IPhysicsManager physicsManager, int syncWindow, int panicTime, int rollbackWindow, TrueSyncEventCallback OnGameStarted, TrueSyncEventCallback OnGamePaused, TrueSyncEventCallback OnGameUnPaused, TrueSyncEventCallback OnGameEnded, TrueSyncPlayerDisconnectionCallback OnPlayerDisconnection, TrueSyncUpdateCallback OnStepUpdate, TrueSyncInputCallback GetLocalData) : base(deltaTime, communicator, physicsManager, syncWindow, panicTime, rollbackWindow, OnGameStarted, OnGamePaused, OnGameUnPaused, OnGameEnded, OnPlayerDisconnection, OnStepUpdate, GetLocalData)
 {
     this.bufferWorldClone = new GenericBufferWindow <IWorldClone>(rollbackWindow, new GenericBufferWindow <IWorldClone> .NewInstance(physicsManager.GetWorldClone));
     this.rollbackIndex    = rollbackWindow;
     StateTracker.Init(rollbackWindow);
 }
コード例 #29
0
        public static Dictionary <string, Joint> DeserializeJoints(IGameObject parent, XElement element, IPhysicsManager physicsManager, Dictionary <string, Body> bodies)
        {
            Dictionary <string, Joint> joints = new Dictionary <string, Joint>();

            IEnumerable <XElement> jointElements = element.Elements("joint");

            foreach (XElement jointElement in jointElements)
            {
                Joint joint = DeserializeJoint(parent, jointElement, physicsManager, bodies);
                var   name  = jointNum.ToString(CultureInfo.InvariantCulture);

                var xAttribute = jointElement.Attribute("name");
                if (xAttribute != null)
                {
                    name = xAttribute.Value;
                }

                joints.Add(name, joint);
            }

            return(joints);
        }
コード例 #30
0
 /// <summary>
 ///     Creates an instance of this LogicProcessor.
 /// </summary>
 public AimShootLifeProcessor()
 {
     _physMan = IoCManager.Resolve <IPhysicsManager>();
     _entMan  = IoCManager.Resolve <IServerEntityManager>();
     _timeMan = IoCManager.Resolve <IGameTiming>();
 }
コード例 #31
0
        private static Joint DeserializeJoint(IGameObject parent, XElement jointElement, IPhysicsManager physicsManager, Dictionary <string, Body> bodies)
        {
            Joint     joint = null;
            JointType type = JointType.Angle;
            Body      bodyA = null, bodyB = null;
            bool      collideConnected = false;
            World     world            = physicsManager.PhysicsWorld;

            var jointData = new FarseerJointUserData();

            if (jointElement.Attribute("type") != null)
            {
                type = (JointType)Enum.Parse(typeof(JointType), jointElement.Attribute("type").Value, true);
            }

            if (jointElement.Element("bodyA") != null)
            {
                var jointName = jointElement.Element("bodyA").Value;
                bodyA = bodies[jointName];
                jointData.BodyAName = jointName;
            }


            if (jointElement.Element("bodyB") != null)
            {
                var jointName = jointElement.Element("bodyB").Value;
                bodyB = bodies[jointName];
                jointData.BodyBName = jointName;
            }

            if (jointElement.Element("collideConnected") != null)
            {
                bool.TryParse(jointElement.Element("collideConnected").Value, out collideConnected);
            }

            #region Joint Types Instantiation

            if (bodyA != null)
            {
                switch (type)
                {
                case JointType.Angle:
                    if (bodyB != null)
                    {
                        joint = DeserializeAngleJoint(jointElement, bodyA, bodyB, world);
                    }
                    break;

                case JointType.Distance:
                    if (bodyB != null)
                    {
                        joint = DeserializeDistanceJoint(jointElement, bodyA, bodyB, world);
                    }
                    break;

                //case JointType.FixedAngle:
                //    joint = DeserializeFixedAngleJoint(jointElement, bodyA, world);
                //    break;
                //case JointType.FixedDistance:
                //    joint = DeserializeFixedDistanceJoint(jointElement, bodyA, world);
                //    break;
                //case JointType.FixedFriction:
                //    joint = DeserializeFixedFrictionJoint(jointElement, bodyA, world);
                //    break;
                //case JointType.FixedPrismatic:
                //    joint = DeserializeFixedPrismaticJoint(jointElement, bodyA, parent, world);
                //    break;
                //case JointType.FixedRevolute:
                //    joint = DeserializeFixedRevoluteJoint(jointElement, bodyA, world);
                //    break;
                //case JointType.Friction:
                //    if (bodyB != null)
                //        joint = DeserializeFrictionJoint(jointElement, bodyA, bodyB, world);
                //    break;
                //case JointType.FixedLine:
                //    if (bodyB != null)
                //        joint = DeserializeLineJoint(jointElement, bodyA, bodyB, world);
                //    break;
                //case JointType.Prismatic:
                //    if (bodyB != null)
                //        joint = DeserializePrismaticJoint(jointElement, bodyA, bodyB, world);
                //    break;
                //case JointType.Pulley:
                //    if (bodyB != null)
                //        joint = DeserializePulleyJoint(jointElement, bodyA, bodyB, world);
                //    break;
                case JointType.Revolute:
                    if (bodyB != null)
                    {
                        joint = DeserializeRevoluteJoint(jointElement, bodyA, bodyB, world);
                    }
                    break;

                // case JointType.Slider:
                //     if (bodyB != null)
                //         joint = DeserializeSliderJoint(jointElement, bodyA, bodyB, world);
                //     break;
                case JointType.Weld:
                    if (bodyB != null)
                    {
                        joint = DeserializeWeldJoint(jointElement, bodyA, bodyB, world);
                    }
                    break;
                }
            }
            #endregion

            if (joint != null)
            {
                joint.CollideConnected = collideConnected;
            }

            joint.UserData = jointData;

            return(joint);
        }
コード例 #32
0
 public void Init(IPhysicsManager pm)
 {
     f_physicsManager = pm;
 }
コード例 #33
0
        /// <summary>
        /// Update the contact manifold and touching status.
        /// Note: do not assume the fixture AABBs are overlapping or are valid.
        /// </summary>
        /// <param name="wake">Whether we should wake the bodies due to touching changing.</param>
        /// <returns>What current status of the contact is (e.g. start touching, end touching, etc.)</returns>
        internal ContactStatus Update(IPhysicsManager physicsManager, out bool wake)
        {
            PhysicsComponent bodyA = FixtureA !.Body;
            PhysicsComponent bodyB = FixtureB !.Body;

            var oldManifold = Manifold;

            // Re-enable this contact.
            Enabled = true;

            bool touching;
            var  wasTouching = IsTouching;

            wake = false;
            var sensor = !(FixtureA.Hard && FixtureB.Hard);

            var bodyATransform = physicsManager.GetTransform(bodyA);
            var bodyBTransform = physicsManager.GetTransform(bodyB);

            // Is this contact a sensor?
            if (sensor)
            {
                IPhysShape shapeA = FixtureA.Shape;
                IPhysShape shapeB = FixtureB.Shape;
                touching = _manifoldManager.TestOverlap(shapeA, ChildIndexA, shapeB, ChildIndexB, bodyATransform, bodyBTransform);

                // Sensors don't generate manifolds.
                Manifold.PointCount = 0;
            }
            else
            {
                Evaluate(ref Manifold, bodyATransform, bodyBTransform);
                touching = Manifold.PointCount > 0;

                // Match old contact ids to new contact ids and copy the
                // stored impulses to warm start the solver.
                for (var i = 0; i < Manifold.PointCount; ++i)
                {
                    var mp2 = Manifold.Points[i];
                    mp2.NormalImpulse  = 0.0f;
                    mp2.TangentImpulse = 0.0f;
                    var id2 = mp2.Id;

                    for (var j = 0; j < oldManifold.PointCount; ++j)
                    {
                        var mp1 = oldManifold.Points[j];

                        if (mp1.Id.Key == id2.Key)
                        {
                            mp2.NormalImpulse  = mp1.NormalImpulse;
                            mp2.TangentImpulse = mp1.TangentImpulse;
                            break;
                        }
                    }

                    Manifold.Points[i] = mp2;
                }

                if (touching != wasTouching)
                {
                    wake = true;
                }
            }

            IsTouching = touching;
            var status = ContactStatus.NoContact;

            if (!wasTouching)
            {
                if (touching)
                {
                    status = ContactStatus.StartTouching;
                }
            }
            else
            {
                if (!touching)
                {
                    status = ContactStatus.EndTouching;
                }
            }

#if DEBUG
            if (!sensor)
            {
                _debugPhysics.HandlePreSolve(this, oldManifold);
            }
#endif

            return(status);
        }
コード例 #34
0
        public static Body DeserializeBody(XElement element, IPhysicsManager physicsManager, IPhysicsComponent parent)
        {
            Body            body     = null;
            FarseerUserData userData = new FarseerUserData();

            //Read the shape used for this body.
            BodyType bodyType = BodyType.Static;

            if (element.Attribute("bodyType") != null)
            {
                if (element.Attribute("bodyType").Value.StartsWith("d", StringComparison.InvariantCultureIgnoreCase))
                {
                    bodyType = BodyType.Dynamic;
                }
                else if (element.Attribute("bodyType").Value.StartsWith("s", StringComparison.InvariantCultureIgnoreCase))
                {
                    bodyType = BodyType.Static;
                }
                else if (element.Attribute("bodyType").Value.StartsWith("k", StringComparison.InvariantCultureIgnoreCase))
                {
                    bodyType = BodyType.Kinematic;
                }
            }

            bool primary = false;

            if (element.Attribute("primary") != null)
            {
                bool.TryParse(element.Attribute("primary").Value, out primary);
            }

            Shape    shape        = null;
            XElement shapeElement = element.Element("shape");

            if (shapeElement != null && shapeElement.Attribute("type") != null)
            {
                if (shapeElement.Attribute("type").Value.StartsWith("b", StringComparison.InvariantCultureIgnoreCase))
                {
                    shape = DeserializeBoxShape(shapeElement);
                }
                else if (shapeElement.Attribute("type").Value.StartsWith("c", StringComparison.InvariantCultureIgnoreCase))
                {
                    shape = DeserializeCircleShape(shapeElement);
                }
                else if (shapeElement.Attribute("type").Value.StartsWith("p", StringComparison.InvariantCultureIgnoreCase))
                {
                    shape = DeserializePolygonShape(shapeElement);
                }
            }

            if (shape != null)
            {
                string name;

                body          = BodyFactory.CreateBody(physicsManager.PhysicsWorld);
                body.BodyType = bodyType;
                Vector2 offset = Vector2.Zero;

                float friction = 0.5f, linearDamping = 5f, restitution = 0f, mass = 1f;
                bool  fixedRotation = false;

                if (element.Element("friction") != null)
                {
                    float.TryParse(element.Element("friction").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out friction);
                }

                if (element.Element("linearDamping") != null)
                {
                    float.TryParse(element.Element("linearDamping").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out linearDamping);
                }

                if (element.Element("restitution") != null)
                {
                    float.TryParse(element.Element("restitution").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out restitution);
                }

                if (element.Element("mass") != null)
                {
                    float.TryParse(element.Element("mass").Value, NumberStyles.Float, CultureInfo.InvariantCulture, out mass);
                }

                if (element.Element("fixedRotation") != null)
                {
                    bool.TryParse(element.Element("fixedRotation").Value, out fixedRotation);
                }

                if (element.Element("offset") != null)
                {
                    offset = offset.DeserializeOffset(element.Element("offset"));
                }

                body.CreateFixture(shape);
                body.Friction      = friction;
                body.LinearDamping = linearDamping;
                body.Restitution   = restitution;
                body.Mass          = mass;
                body.FixedRotation = fixedRotation;

                name = element.Attribute("name") != null?element.Attribute("name").Value : body.BodyId.ToString();

                userData.TopLeftOffset = ConvertUnits.GetTopLeftCorner(body.FixtureList[0], 0);
                userData.Name          = name;
                userData.Primary       = primary;
                userData.Owner         = parent;
                userData.Offset        = offset;

                body.UserData = userData;
            }

            return(body);
        }
コード例 #35
0
        public static Dictionary<string, Joint> DeserializeJoints(IGameObject parent, XElement element, IPhysicsManager physicsManager, Dictionary<string, Body> bodies)
        {
            Dictionary<string, Joint> joints = new Dictionary<string, Joint>();

            IEnumerable<XElement> jointElements = element.Elements("joint");

            foreach (XElement jointElement in jointElements)
            {
                Joint joint = DeserializeJoint(parent, jointElement, physicsManager, bodies);
                var name = jointNum.ToString(CultureInfo.InvariantCulture);

                var xAttribute = jointElement.Attribute("name");
                if (xAttribute != null) name = xAttribute.Value;

                joints.Add(name, joint);
            }

            return joints;
        }
コード例 #36
0
 public PolygonCollider(ITransformable transformable, IEnumerable <Vector2> vertices, Body body, Shape shape, IPhysicsManager physics) : base(transformable, body, shape, physics)
 {
     _vertices = vertices.ToArray();
 }
コード例 #37
0
 public RectCollider(ITransformable transformable, Body body, Shape shape, Vector2 size, IPhysicsManager physics)
     : base(transformable, body, shape, physics)
 {
     Size = size;
 }