Browse Source

Merge branch 'eesast:dev' into dev

tags/0.1.0
OctaAcid GitHub 3 years ago
parent
commit
9483f45be9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 11 deletions
  1. +5
    -10
      logic/GameEngine/CollisionChecker.cs
  2. +5
    -1
      logic/Preparation/Utility/XY.cs

+ 5
- 10
logic/GameEngine/CollisionChecker.cs View File

@@ -123,12 +123,9 @@ namespace GameEngine
/// <returns>最大可能的移动距离</returns>
public double FindMax(IMoveable obj, XY nextPos, XY moveVec)
{
double maxLen = (double)uint.MaxValue;
double tmpMax = maxLen; // 暂存最大值
double tmpMax = uint.MaxValue; // 暂存最大值

// 先找只考虑墙的最大距离
// double maxOnlyConsiderWall = FindMaxOnlyConsiderWall(obj, moveVec);
double maxDistance = maxLen;
double maxDistance = uint.MaxValue;
foreach (var listWithLock in lists)
{
var lst = listWithLock.Item1;
@@ -159,13 +156,13 @@ namespace GameEngine
{
double tmp = mod - obj.Radius - listObj.Radius;
// 计算能走的最长距离,好像这么算有一点误差?
tmp = tmp / Math.Cos(Math.Atan2(orgDeltaY, orgDeltaX) - moveVec.Angle());
if (tmp < 0 || tmp > uint.MaxValue || tmp == double.NaN)
tmp = ((int)(tmp * 1000 / Math.Cos(Math.Atan2(orgDeltaY, orgDeltaX) - moveVec.Angle())));
if (tmp < 0 || tmp > uint.MaxValue || double.IsNaN(tmp))
{
tmpMax = uint.MaxValue;
}
else
tmpMax = tmp;
tmpMax = tmp / 1000.0;
}
break;
}
@@ -207,11 +204,9 @@ namespace GameEngine
}
finally
{
// maxLen = Math.Min(maxOnlyConsiderWall, maxDistance); //最大可能距离的最小值
listLock.ExitReadLock();
}
}
// return maxLen;
return maxDistance;
}



+ 5
- 1
logic/Preparation/Utility/XY.cs View File

@@ -64,7 +64,11 @@ namespace Preparation.Utility
}
public static double Distance(XY p1, XY p2)
{
return Math.Sqrt(((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y)));
long c = (((long)(p1.x - p2.x) * (p1.x - p2.x)) + ((long)(p1.y - p2.y) * (p1.y - p2.y))) * 1000000;
long t = c / 2 + 1;
while (t * t > c || (t + 1) * (t + 1) < c)
t = (c / t + t) / 2;
return (double)t / 1000.0;
}
public double Length()
{


Loading…
Cancel
Save