Skip to content

Commit

Permalink
No More Physics Buckets (space-wizards#694)
Browse files Browse the repository at this point in the history
* Converted everything (I think) to ICollidable.

* Renamed CollisionManager to PhysicsManager.
Removed the bucket system out of the PhysicsManager.
RayCastResults.Distance was changed from PositiveInfinity to 0f when no entity is hit.

* Soft collidables (bullets) work again.
  • Loading branch information
Acruid authored and PJB3005 committed Oct 25, 2018
1 parent a6d2a34 commit d8ca95d
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 391 deletions.
2 changes: 1 addition & 1 deletion SS14.Client/GameController/GameController.IoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static void RegisterIoC()
IoCManager.Register<IComponentFactory, GodotComponentFactory>();
IoCManager.Register<IComponentManager, ComponentManager>();
IoCManager.Register<IMapManager, ClientMapManager>();
IoCManager.Register<ICollisionManager, CollisionManager>();
IoCManager.Register<IPhysicsManager, PhysicsManager>();
IoCManager.Register<ITimerManager, TimerManager>();
IoCManager.Register<ITaskManager, TaskManager>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void Initialize()

if (collisionEnabled)
{
var cm = IoCManager.Resolve<ICollisionManager>();
var cm = IoCManager.Resolve<IPhysicsManager>();
cm.AddCollidable(this);
}
}
Expand All @@ -84,37 +84,13 @@ public override void Shutdown()
{
if (collisionEnabled)
{
var cm = IoCManager.Resolve<ICollisionManager>();
var cm = IoCManager.Resolve<IPhysicsManager>();
cm.RemoveCollidable(this);
}

base.Shutdown();
}

/// <summary>
/// Handles an incoming component message.
/// </summary>
/// <param name="owner">
/// Object that raised the event. If the event was sent over the network or from some unknown place,
/// this will be null.
/// </param>
/// <param name="message">Message that was sent.</param>
public override void HandleMessage(ComponentMessage message, INetChannel netChannel = null, IComponent component = null)
{
base.HandleMessage(message, netChannel, component);

switch (message)
{
case SpriteChangedMsg msg:
if (collisionEnabled)
{
var cm = IoCManager.Resolve<ICollisionManager>();
cm.UpdateCollidable(this);
}
break;
}
}

/// <inheritdoc />
public override void HandleComponentState(ComponentState state)
{
Expand All @@ -132,7 +108,7 @@ public override void HandleComponentState(ComponentState state)

public bool TryCollision(Vector2 offset, bool bump = false)
{
return IoCManager.Resolve<ICollisionManager>().TryCollide(Owner, offset, bump);
return IoCManager.Resolve<IPhysicsManager>().TryCollide(Owner, offset, bump);
}

/// <summary>
Expand All @@ -141,7 +117,7 @@ public bool TryCollision(Vector2 offset, bool bump = false)
private void EnableCollision()
{
collisionEnabled = true;
var cm = IoCManager.Resolve<ICollisionManager>();
var cm = IoCManager.Resolve<IPhysicsManager>();
cm.AddCollidable(this);
}

Expand All @@ -151,7 +127,7 @@ private void EnableCollision()
private void DisableCollision()
{
collisionEnabled = false;
var cm = IoCManager.Resolve<ICollisionManager>();
var cm = IoCManager.Resolve<IPhysicsManager>();
cm.RemoveCollidable(this);
}
}
Expand Down
2 changes: 1 addition & 1 deletion SS14.Client/Placement/PlacementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace SS14.Client.Placement
public class PlacementManager : IPlacementManager, IDisposable
{
[Dependency]
public readonly ICollisionManager CollisionManager;
public readonly IPhysicsManager PhysicsManager;
[Dependency]
private readonly IClientNetManager NetworkManager;
[Dependency]
Expand Down
2 changes: 1 addition & 1 deletion SS14.Client/Placement/PlacementMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public bool IsColliding(GridLocalCoordinates coordinates)
bounds.Width,
bounds.Height);

if (pManager.CollisionManager.IsColliding(collisionbox, coordinates.MapID))
if (pManager.PhysicsManager.IsColliding(collisionbox, coordinates.MapID))
return true;

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void ICollidable.Bump(List<IEntity> bumpedinto)
public override void OnAdd()
{
base.OnAdd();
var cm = IoCManager.Resolve<ICollisionManager>();
var cm = IoCManager.Resolve<IPhysicsManager>();
cm.AddCollidable(this);
}

Expand All @@ -90,14 +90,14 @@ public override void OnAdd()
/// </summary>
public override void Shutdown()
{
var cm = IoCManager.Resolve<ICollisionManager>();
var cm = IoCManager.Resolve<IPhysicsManager>();
cm.RemoveCollidable(this);
base.Shutdown();
}

public bool TryCollision(Vector2 offset, bool bump = false)
{
return IoCManager.Resolve<ICollisionManager>().TryCollide(Owner, offset, bump);
return IoCManager.Resolve<IPhysicsManager>().TryCollide(Owner, offset, bump);
}
}
}
2 changes: 1 addition & 1 deletion SS14.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private static void RegisterIoC()
IoCManager.Register<INetManager, NetManager>();
IoCManager.Register<IGameTiming, GameTiming>();
IoCManager.Register<IResourceManager, ResourceManager>();
IoCManager.Register<ICollisionManager, CollisionManager>();
IoCManager.Register<IPhysicsManager, PhysicsManager>();
IoCManager.Register<ITimerManager, TimerManager>();
IoCManager.Register<ILogManager, LogManager>();
IoCManager.Register<ITaskManager, TaskManager>();
Expand Down
5 changes: 1 addition & 4 deletions SS14.Shared/GameObjects/ComponentMessages/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public SaidSomethingMsg(ChatChannel channel, string text)
Text = text;
}
}

[Serializable, NetSerializable]
public class SpriteChangedMsg : ComponentMessage { }


[Serializable, NetSerializable]
public class BumpedEntMsg : ComponentMessage
{
Expand Down
9 changes: 0 additions & 9 deletions SS14.Shared/Interfaces/Physics/ICollider.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System.Collections.Generic;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Interfaces.GameObjects;
using SS14.Shared.Map;
using SS14.Shared.Maths;
using SS14.Shared.Physics;

namespace SS14.Shared.Interfaces.Physics
{
public interface ICollisionManager
/// <summary>
/// This service provides access into the physics system.
/// </summary>
public interface IPhysicsManager
{
/// <summary>
/// Checks to see if the specified collision rectangle collides with any of the colliders under management.
Expand All @@ -17,18 +19,18 @@ public interface ICollisionManager
/// <returns>true if collides, false if not</returns>
bool IsColliding(Box2 collider, MapId map);

bool TryCollide(IEntity collider);
bool TryCollide(IEntity collider, Vector2 offset, bool bump = true);
bool TryCollide(IEntity entity, Vector2 offset, bool bump = true);

void AddCollidable(ICollidable collidable);
void RemoveCollidable(ICollidable collidable);
void UpdateCollidable(ICollidable collidable);

/// <summary>
/// Casts a ray in the world and returns the first thing it hit.
/// </summary>
/// <param name="ray">Ray to cast in the world.</param>
/// <param name="maxLength">Maximum length of the ray in meters.</param>
/// <param name="ignoredEnt">A single entity that can be ignored by the RayCast. Useful if the ray starts inside the body of an entity.</param>
/// <returns>A result object describing the hit, if any.</returns>
RayCastResults IntersectRay(Ray ray, float maxLength = 50, IEntity entityignore = null);
RayCastResults IntersectRay(Ray ray, float maxLength = 50, IEntity ignoredEnt = null);
}
}
Loading

0 comments on commit d8ca95d

Please sign in to comment.