feat : 맵 바운딩 박스 처리 / echo 패킷 구조 재 구성 / 더미 클라이언트 랜덤 이동 작업
This commit is contained in:
@@ -11,10 +11,18 @@ public class DummyClientService
|
||||
// 모든거 강종
|
||||
public event Action? OnAllDisconnected;
|
||||
|
||||
public DummyClientService(int count, string ip, int port, string key, int sendIntervalMs = 1000)
|
||||
public DummyClientService(int count, string ip, int port, string key, int sendIntervalMs = 1000, MapBounds? mapBounds = null)
|
||||
{
|
||||
sendInterval = sendIntervalMs;
|
||||
clients = Enumerable.Range(1, count + 1).Select(i => new DummyClients(i, ip, port, key)).ToList();
|
||||
clients = Enumerable.Range(1, count).Select(i =>
|
||||
{
|
||||
DummyClients client = new DummyClients(i, ip, port, key);
|
||||
if (mapBounds != null)
|
||||
{
|
||||
client.Map = mapBounds;
|
||||
}
|
||||
return client;
|
||||
}).ToList();
|
||||
|
||||
Log.Information("[SERVICE] {Count}개 클라이언트 생성 → {Ip}:{Port}", count, ip, port);
|
||||
}
|
||||
@@ -30,30 +38,23 @@ public class DummyClientService
|
||||
{
|
||||
foreach (DummyClients c in clients)
|
||||
{
|
||||
c.PollEvents();
|
||||
try
|
||||
{
|
||||
c.PollEvents();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("[Client {ClientId}] PollEvents 예외: {Ex}", c.clientId, ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(10, ct);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
await Task.Delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SendLoopAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await Task.Delay(500, ct);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
await Task.Delay(500);
|
||||
|
||||
int tick = 0;
|
||||
|
||||
@@ -85,14 +86,7 @@ public class DummyClientService
|
||||
Log.Debug("[TICK {Tick:000}] {Sent}/{Total} 전송", tick, sent, total);
|
||||
tick++;
|
||||
|
||||
try
|
||||
{
|
||||
await Task.Delay(sendInterval, ct);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
await Task.Delay(sendInterval);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ public class DummyClients
|
||||
private float dirX = 0f;
|
||||
private float dirZ = 0f;
|
||||
|
||||
// 맵 경계
|
||||
public MapBounds Map { get; set; } = new MapBounds(-50f, 50f, -50f, 50f);
|
||||
|
||||
// 통계
|
||||
public int SentCount
|
||||
{
|
||||
@@ -71,15 +74,6 @@ public class DummyClients
|
||||
|
||||
listener.NetworkReceiveEvent += (peer, reader, channel, deliveryMethod) =>
|
||||
{
|
||||
short code = reader.GetShort();
|
||||
short bodyLength = reader.GetShort();
|
||||
string? msg = reader.GetString();
|
||||
|
||||
if (msg != null)
|
||||
{
|
||||
RttCount++;
|
||||
}
|
||||
|
||||
ReceivedCount++;
|
||||
reader.Recycle();
|
||||
};
|
||||
@@ -104,8 +98,12 @@ public class DummyClients
|
||||
// 남은 거리가 없으면 새 방향·목표 거리 설정
|
||||
if (distance <= 0f)
|
||||
{
|
||||
// 현재 각도에서 -30~+30도 범위로 회전
|
||||
rotY = (rotY + Random.Shared.Next(-30, 31) + 360) % 360;
|
||||
// 벽에 붙어있으면 반대 방향 강제, 아니면 ±30도 회전
|
||||
int wallRotY = Map.GetRotYAwayFromWall(posX, posZ);
|
||||
rotY = wallRotY >= 0
|
||||
? (wallRotY + Random.Shared.Next(-30, 31) + 360) % 360
|
||||
: (rotY + Random.Shared.Next(-30, 31) + 360) % 360;
|
||||
|
||||
float rad = rotY * MathF.PI / 180f;
|
||||
dirX = MathF.Sin(rad);
|
||||
dirZ = MathF.Cos(rad);
|
||||
@@ -117,9 +115,14 @@ public class DummyClients
|
||||
|
||||
// 이번 틱 이동량 (남은 거리 초과 방지)
|
||||
float step = MathF.Min(moveSpeed * delta, distance);
|
||||
posX += dirX * step;
|
||||
posZ += dirZ * step;
|
||||
distance -= step;
|
||||
float nextX = posX + dirX * step;
|
||||
float nextZ = posZ + dirZ * step;
|
||||
|
||||
// 벽 충돌 시 clamp + 다음 틱에 방향 재설정
|
||||
bool hitWall = Map.Clamp(ref nextX, ref nextZ);
|
||||
posX = nextX;
|
||||
posZ = nextZ;
|
||||
distance = hitWall ? 0f : distance - step;
|
||||
|
||||
// 정수 Vector3 갱신
|
||||
position.X = (int)MathF.Round(posX);
|
||||
|
||||
116
ClientTester/EchoClientTester/DummyService/MapBounds.cs
Normal file
116
ClientTester/EchoClientTester/DummyService/MapBounds.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
namespace ClientTester.DummyService;
|
||||
|
||||
public class MapBounds
|
||||
{
|
||||
public float MinX
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public float MaxX
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public float MinZ
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public float MaxZ
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public MapBounds(float minX, float maxX, float minZ, float maxZ)
|
||||
{
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
MinZ = minZ;
|
||||
MaxZ = maxZ;
|
||||
}
|
||||
|
||||
// 위치가 경계 안에 있는지 체크
|
||||
public bool IsInside(float x, float z)
|
||||
{
|
||||
return x >= MinX && x <= MaxX && z >= MinZ && z <= MaxZ;
|
||||
}
|
||||
|
||||
// 경계 초과 시 clamp, 벽에 부딪혔으면 true 반환
|
||||
public bool Clamp(ref float x, ref float z)
|
||||
{
|
||||
bool hit = false;
|
||||
|
||||
if (x < MinX)
|
||||
{
|
||||
x = MinX;
|
||||
hit = true;
|
||||
}
|
||||
else if (x > MaxX)
|
||||
{
|
||||
x = MaxX;
|
||||
hit = true;
|
||||
}
|
||||
|
||||
if (z < MinZ)
|
||||
{
|
||||
z = MinZ;
|
||||
hit = true;
|
||||
}
|
||||
else if (z > MaxZ)
|
||||
{
|
||||
z = MaxZ;
|
||||
hit = true;
|
||||
}
|
||||
|
||||
return hit;
|
||||
}
|
||||
|
||||
// 현재 위치 기준으로 벽 반대 방향 rotY 계산 (벽 없으면 -1)
|
||||
public int GetRotYAwayFromWall(float x, float z, float margin = 0.5f)
|
||||
{
|
||||
bool atLeft = x <= MinX + margin;
|
||||
bool atRight = x >= MaxX - margin;
|
||||
bool atBottom = z <= MinZ + margin;
|
||||
bool atTop = z >= MaxZ - margin;
|
||||
|
||||
if (!atLeft && !atRight && !atBottom && !atTop)
|
||||
{
|
||||
return -1; // 벽 근처 아님
|
||||
}
|
||||
|
||||
// 벽 반대 방향 벡터 합산
|
||||
float awayX = 0f, awayZ = 0f;
|
||||
if (atLeft)
|
||||
{
|
||||
awayX += 1f;
|
||||
}
|
||||
|
||||
if (atRight)
|
||||
{
|
||||
awayX -= 1f;
|
||||
}
|
||||
|
||||
if (atBottom)
|
||||
{
|
||||
awayZ += 1f;
|
||||
}
|
||||
|
||||
if (atTop)
|
||||
{
|
||||
awayZ -= 1f;
|
||||
}
|
||||
|
||||
// 정규화
|
||||
float len = MathF.Sqrt(awayX * awayX + awayZ * awayZ);
|
||||
awayX /= len;
|
||||
awayZ /= len;
|
||||
|
||||
// 방향 벡터 → rotY (degree)
|
||||
return ((int)(MathF.Atan2(awayX, awayZ) * 180f / MathF.PI) + 360) % 360;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user