129 lines
3.6 KiB
C#
129 lines
3.6 KiB
C#
using BrewMonster.Network;
|
|
using CSNetwork.C2SCommand;
|
|
using CSNetwork.GPDataType;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.ConstrainedExecution;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
using CSNetwork.Protocols;
|
|
using UnityEngine.LightTransport;
|
|
|
|
public class CECHostMove
|
|
{
|
|
ushort m_wMoveStamp;
|
|
float m_fMoveTime;
|
|
CECHostPlayer m_pHost;
|
|
CECCounter m_CmdTimeCnt;
|
|
bool m_bStop;
|
|
const int MOVECMD_INTERVAL = 500;
|
|
Vector3 m_vLastSevPos;
|
|
|
|
public CECHostMove(CECHostPlayer pHost)
|
|
{
|
|
m_wMoveStamp = 0;
|
|
m_fMoveTime = 0.0f;
|
|
m_pHost = pHost;
|
|
m_bStop = true;
|
|
m_CmdTimeCnt = new CECCounter();
|
|
m_CmdTimeCnt.SetPeriod(MOVECMD_INTERVAL);
|
|
}
|
|
public void Tick(ulong dwDeltaTime)
|
|
{
|
|
m_CmdTimeCnt.IncCounter(dwDeltaTime);
|
|
}
|
|
public void SendMoveCmd(in Vector3 vCurPos, in Vector3 vVel, int iMoveMode, bool bForceSend = false)
|
|
{
|
|
Vector3 vMoveDir = vVel;
|
|
float fSpeed = vMoveDir.magnitude;
|
|
SendMoveCmd(vCurPos, fSpeed, iMoveMode, bForceSend);
|
|
Debug.LogWarning("HoangDev :SendMoveCmd 111");
|
|
}
|
|
void SendMoveCmd(in Vector3 vCurPos,
|
|
float fSpeed, int iMoveMode, bool bForceSend)
|
|
{
|
|
if (m_bStop)
|
|
{
|
|
// m_CmdTimeCnt.Reset();
|
|
m_CmdTimeCnt.SetCounter((ulong)(m_fMoveTime * 1000));
|
|
m_bStop = false;
|
|
}
|
|
Debug.LogWarning("HoangDev :SendMoveCmd 2222");
|
|
|
|
if (!bForceSend && !m_CmdTimeCnt.IsFull())
|
|
return;
|
|
Debug.LogWarning("HoangDev :SendMoveCmd 3333");
|
|
|
|
int iTime = (int)(m_fMoveTime * 1000);
|
|
|
|
if (iTime < 200)
|
|
{
|
|
if (iTime == 0 || !bForceSend)
|
|
{
|
|
// if time is too little, wait again
|
|
m_CmdTimeCnt.SetCounter((ulong)iTime);
|
|
return;
|
|
}
|
|
}
|
|
Debug.LogWarning("HoangDev :SendMoveCmd 4444");
|
|
|
|
m_CmdTimeCnt.Reset();
|
|
|
|
c2s_CmdPlayerMove(vCurPos, vCurPos, iTime/* MOVECMD_INTERVAL */, fSpeed, iMoveMode, m_wMoveStamp++);
|
|
|
|
m_vLastSevPos = vCurPos;
|
|
}
|
|
private void Reset()
|
|
{
|
|
m_bStop = true;
|
|
}
|
|
private void c2s_CmdPlayerMove(in Vector3 vCurPos, in Vector3 vDest,
|
|
int iTime, float fSpeed, int iMoveMode, ushort wStamp)
|
|
{
|
|
gamedatasend gamedatasend = new gamedatasend();
|
|
|
|
//TODO: tim cach convert vector 3 unity sang System.Numerics.Vector3
|
|
gamedatasend.Data = C2SCommandFactory.CreatePlayerMove(ToSysVec3(vCurPos), ToSysVec3(vDest), (ushort)iTime, (short)fSpeed, (byte)iMoveMode, wStamp);
|
|
UnityGameSession.SendProtocol(gamedatasend);
|
|
Debug.Log("HoangDev : SendProtocolSendProtocolSendProtocol");
|
|
}
|
|
public void GroundMove(float ftime)
|
|
{
|
|
m_fMoveTime += ftime;
|
|
}
|
|
public System.Numerics.Vector3 ToSysVec3(UnityEngine.Vector3 v)
|
|
=> new System.Numerics.Vector3(v.x, v.y, v.z);
|
|
}
|
|
public struct CDR_INFO
|
|
{
|
|
//the aabb
|
|
public Vector3 vCenter;
|
|
//@note : the caller should make sure ext(.x, .y, .z) > 0. By Kuiwu[22/9/2005]
|
|
public Vector3 vExtent;
|
|
|
|
public float fStepHeight;
|
|
|
|
// Velocity Info
|
|
public Vector3 vXOZVelDir;
|
|
public float fYVel;
|
|
public float fSpeed;
|
|
|
|
// time span ( sec )
|
|
public float t;
|
|
|
|
// Gravity acceleration
|
|
public float fGravityAccel;
|
|
|
|
// the Climb Slope Thresh
|
|
public float fSlopeThresh;
|
|
|
|
// Tangent plane Info
|
|
public Vector3 vTPNormal;
|
|
|
|
// Absolute Velocity: output for forcast!
|
|
public Vector3 vAbsVelocity;
|
|
|
|
|
|
//the moving dist
|
|
public float fMoveDist;
|
|
}; |