Skip to content

Commit 9d39f9a

Browse files
committed
[*] fixed player mover bug
[+] add Collision System Editor
1 parent 1a1565b commit 9d39f9a

21 files changed

Lines changed: 330 additions & 152 deletions

File tree

Unity/Assets/LockstepEngine/Collision2D/CRigidbody.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System;
22
using Lockstep.Collision2D;
3+
using Lockstep.Logging;
34
using Lockstep.Math;
45

56
namespace Lockstep.Logic {
67
public delegate void OnFloorResultCallback(bool isOnFloor);
78

89
[Serializable]
910
public class CRigidbody {
10-
public CTransform2D transform { get; set; }
11+
public CTransform2D transform { get; private set; }
1112
public static LFloat G = new LFloat(10);
1213
public static LFloat MinSleepSpeed = new LFloat(true, 100);
1314
public static LFloat FloorFriction = new LFloat(20);
@@ -21,9 +22,18 @@ public class CRigidbody {
2122
public bool isEnable = true;
2223
public bool isSleep = false;
2324
public bool isOnFloor;
25+
26+
public void Init(CTransform2D transform2D){
27+
this.transform = transform2D;
28+
}
29+
30+
//private int __id;
31+
//private static int __idCount;
2432
public void DoStart(){
33+
//__id = __idCount++;
2534
LFloat y = LFloat.zero;
2635
isOnFloor = TestOnFloor(transform.Pos3, ref y);
36+
Speed = LVector3.zero;
2737
isSleep = isOnFloor;
2838
}
2939

@@ -74,6 +84,7 @@ public void DoUpdate(LFloat deltaTime){
7484
public void AddImpulse(LVector3 force){
7585
isSleep = false;
7686
Speed += force / Mass;
87+
//Debug.Log(__id+ " AddImpulse " + force +" after " + Speed);
7788
}
7889
public void ResetSpeed(LFloat ySpeed){
7990
Speed = LVector3.zero;

Unity/Assets/LockstepEngine/Collision2D/CollisionSystem.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public partial class CollisionSystem : ICollisionSystem {
2121
private Dictionary<int, ColliderProxy> id2Proxy = new Dictionary<int, ColliderProxy>();
2222
private HashSet<long> _curPairs = new HashSet<long>();
2323
private HashSet<long> _prePairs = new HashSet<long>();
24-
public const int LayerCount = 32;
24+
public const int MaxLayerCount = 32;
2525
private List<ColliderProxy> tempLst = new List<ColliderProxy>();
2626

2727
public FuncGlobalOnTriggerEvent funcGlobalOnTriggerEvent;
@@ -32,9 +32,11 @@ public ColliderProxy GetCollider(int id){
3232

3333

3434
public int[] AllTypes;
35-
public int[][] InterestingMasks;
35+
public bool[] InterestingMasks;
36+
public int LayerCount;
3637

37-
public void DoStart(int[][] interestingMasks, int[] allTypes){
38+
public void DoStart(bool[] interestingMasks, int[] allTypes){
39+
LayerCount = allTypes.Length;
3840
this.InterestingMasks = interestingMasks;
3941
this.AllTypes = allTypes;
4042
//init _collisionMask//TODO read from file
@@ -151,10 +153,11 @@ public void DoUpdate(LFloat deltaTime){
151153
foreach (var val in tempLst) {
152154
val.IsMoved = false;
153155
var bound = val.GetBounds();
154-
var targetLayers = InterestingMasks[val.LayerType];
155-
foreach (var layerType in targetLayers) {
156-
var boundsTree = GetBoundTree(layerType);
157-
boundsTree.CheckCollision(val, bound);
156+
for (int i = 0; i < LayerCount; i++) {
157+
if (InterestingMasks[val.LayerType * LayerCount + i]) {
158+
var boundsTree = GetBoundTree(i);
159+
boundsTree.CheckCollision(val, bound);
160+
}
158161
}
159162
}
160163

Unity/Assets/LockstepEngine/Collision2D/ICollisionSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Lockstep.Collision2D {
66
public delegate void FuncCollision(ColliderProxy obj);
77

88
public interface ICollisionSystem {
9-
void DoStart(int[][] interestingMasks, int[] allTypes);
9+
void DoStart(bool[] interestingMasks, int[] allTypes);
1010
void DoUpdate(LFloat deltaTime);
1111
ColliderProxy GetCollider(int id);
1212
void AddCollider(ColliderProxy collider);

Unity/Assets/LockstepEngineUnityExt/Collision2D/Test/TestQuadTree.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ public class TestQuadTree : MonoBehaviour {
3131
public float percent = 0.1f;
3232
public int count = 100;
3333

34-
public int[][] InterestingMasks = new int[][] {
35-
new int[] { },
36-
new int[] { },
37-
new int[] {0, 1}
38-
};
34+
public bool[] InterestingMasks;
3935

4036
private int[] allTypes = new int[] {0, 1, 2};
4137

Unity/Assets/LockstepEngineUnityExt/Collision2D/Test/TestRigidbody.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private void Start(){
1818
CRigidbody = new CRigidbody();
1919
CTransform2D = new CTransform2D();
2020
CTransform2D.Pos3 = transform.position.ToLVector3();
21-
CRigidbody.transform = CTransform2D;
21+
CRigidbody.Init(CTransform2D);
2222
CRigidbody.DoStart();
2323
}
2424

8.85 KB
Binary file not shown.
8.3 KB
Binary file not shown.

Unity/Assets/Scenes/Demo.unity

1.98 KB
Binary file not shown.

Unity/Assets/Scripts/Core/Base/BaseEntity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class BaseEntity : BaseLifeCycle, IEntity, ILPTriggerEventHandler {
2121

2222
public BaseEntity(){
2323
Debug.Trace("BaseEntity " + IdCounter.ToString(), true);
24-
rigidbody.transform = transform;
2524
}
2625

2726
protected void RegisterComponent(BaseComponent comp){
@@ -30,6 +29,7 @@ protected void RegisterComponent(BaseComponent comp){
3029
}
3130

3231
public override void DoAwake(){
32+
rigidbody.Init(transform);
3333
EntityId = IdCounter++;
3434
foreach (var comp in allComponents) {
3535
comp.DoAwake();

Unity/Assets/Scripts/Logic/Config/GameConfig.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ public void CopyTo(object dst){
2020
FieldInfo[] fields = dst.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public);
2121
foreach (var field in fields) {
2222
var type = field.FieldType;
23-
if (typeof(BaseComponent).IsAssignableFrom(type)) {
23+
if (typeof(BaseComponent).IsAssignableFrom(type)
24+
|| typeof(CRigidbody).IsAssignableFrom(type)
25+
|| typeof(Transform).IsAssignableFrom(type)
26+
) {
2427
CopyTo(field.GetValue(dst), field.GetValue(Entity));
2528
}
2629
else {
2730
field.SetValue(dst, field.GetValue(Entity));
2831
}
2932
}
30-
3133
}
3234

3335
void CopyTo(object dst, object src){

0 commit comments

Comments
 (0)