Introduce and use constexpr CCharacterCore::PhysicalSize

This commit is contained in:
Alexander Akulich 2022-05-28 20:28:44 +03:00
parent deb2e8752f
commit a39bbc702b
11 changed files with 30 additions and 36 deletions

View file

@ -835,13 +835,13 @@ void CHud::RenderPlayerState(const int ClientID)
if(m_pClient->m_Snap.m_aCharacters[ClientID].m_HasExtendedDisplayInfo)
{
bool Grounded = false;
if(Collision()->CheckPoint(pCharacter->m_Pos.x + CCharacter::ms_PhysSize / 2,
pCharacter->m_Pos.y + CCharacter::ms_PhysSize / 2 + 5))
if(Collision()->CheckPoint(pCharacter->m_Pos.x + CCharacterCore::PhysicalSize() / 2,
pCharacter->m_Pos.y + CCharacterCore::PhysicalSize() / 2 + 5))
{
Grounded = true;
}
if(Collision()->CheckPoint(pCharacter->m_Pos.x - CCharacter::ms_PhysSize / 2,
pCharacter->m_Pos.y + CCharacter::ms_PhysSize / 2 + 5))
if(Collision()->CheckPoint(pCharacter->m_Pos.x - CCharacterCore::PhysicalSize() / 2,
pCharacter->m_Pos.y + CCharacterCore::PhysicalSize() / 2 + 5))
{
Grounded = true;
}

View file

@ -190,9 +190,7 @@ void CPlayers::RenderHookCollLine(
ColorRGBA HookCollColor = color_cast<ColorRGBA>(ColorHSLA(g_Config.m_ClHookCollColorNoColl));
float PhysSize = 28.0f;
vec2 OldPos = InitPos + ExDirection * PhysSize * 1.5f;
vec2 OldPos = InitPos + ExDirection * CCharacterCore::PhysicalSize() * 1.5f;
vec2 NewPos = OldPos;
bool DoBreak = false;

View file

@ -2190,7 +2190,6 @@ IGameClient *CreateGameClient()
int CGameClient::IntersectCharacter(vec2 HookPos, vec2 NewPos, vec2 &NewPos2, int ownID)
{
float PhysSize = 28.0f;
float Distance = 0.0f;
int ClosestID = -1;
@ -2220,7 +2219,7 @@ int CGameClient::IntersectCharacter(vec2 HookPos, vec2 NewPos, vec2 &NewPos2, in
vec2 ClosestPoint;
if(closest_point_on_line(HookPos, NewPos, Position, ClosestPoint))
{
if(distance(Position, ClosestPoint) < PhysSize + 2.0f)
if(distance(Position, ClosestPoint) < CCharacterCore::PhysicalSize() + 2.0f)
{
if(ClosestID == -1 || distance(HookPos, Position) < Distance)
{

View file

@ -1087,7 +1087,7 @@ CTeamsCore *CCharacter::TeamsCore()
}
CCharacter::CCharacter(CGameWorld *pGameWorld, int ID, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, CNetObj_DDNetCharacterDisplayInfo *pExtendedDisplayInfo) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_CHARACTER)
CEntity(pGameWorld, CGameWorld::ENTTYPE_CHARACTER, vec2(0, 0), CCharacterCore::PhysicalSize())
{
m_ID = ID;
m_IsLocal = false;
@ -1102,7 +1102,6 @@ CCharacter::CCharacter(CGameWorld *pGameWorld, int ID, CNetObj_Character *pChar,
mem_zero(&m_Core.m_Ninja, sizeof(m_Core.m_Ninja));
mem_zero(&m_SavedInput, sizeof(m_SavedInput));
m_LatestInput = m_LatestPrevInput = m_PrevInput = m_Input = m_SavedInput;
m_ProximityRadius = ms_PhysSize;
m_Core.m_LeftWall = true;
m_ReloadTimer = 0;
m_NumObjectsHit = 0;

View file

@ -405,7 +405,7 @@ void CGameWorld::NetObjAdd(int ObjID, int ObjType, const void *pObjData, const C
// otherwise try to determine its owner by checking if there is only one player nearby
if(NetProj.m_StartTick >= GameTick() - 4)
{
const vec2 NetPos = NetProj.m_Pos - normalize(NetProj.m_Direction) * 28.0 * 0.75;
const vec2 NetPos = NetProj.m_Pos - normalize(NetProj.m_Direction) * CCharacterCore::PhysicalSize() * 0.75;
const bool Prev = (GameTick() - NetProj.m_StartTick) > 1;
float First = 200.0f, Second = 200.0f;
CCharacter *pClosest = 0;

View file

@ -116,15 +116,14 @@ void CCharacterCore::Reset()
void CCharacterCore::Tick(bool UseInput)
{
float PhysSize = 28.0f;
m_MoveRestrictions = m_pCollision->GetMoveRestrictions(UseInput ? IsSwitchActiveCb : 0, this, m_Pos);
m_TriggeredEvents = 0;
// get ground state
bool Grounded = false;
if(m_pCollision->CheckPoint(m_Pos.x + PhysSize / 2, m_Pos.y + PhysSize / 2 + 5))
if(m_pCollision->CheckPoint(m_Pos.x + PhysicalSize() / 2, m_Pos.y + PhysicalSize() / 2 + 5))
Grounded = true;
if(m_pCollision->CheckPoint(m_Pos.x - PhysSize / 2, m_Pos.y + PhysSize / 2 + 5))
if(m_pCollision->CheckPoint(m_Pos.x - PhysicalSize() / 2, m_Pos.y + PhysicalSize() / 2 + 5))
Grounded = true;
vec2 TargetDirection = normalize(vec2(m_Input.m_TargetX, m_Input.m_TargetY));
@ -196,7 +195,7 @@ void CCharacterCore::Tick(bool UseInput)
if(m_HookState == HOOK_IDLE)
{
m_HookState = HOOK_FLYING;
m_HookPos = m_Pos + TargetDirection * PhysSize * 1.5f;
m_HookPos = m_Pos + TargetDirection * PhysicalSize() * 1.5f;
m_HookDir = TargetDirection;
SetHookedPlayer(-1);
m_HookTick = (float)SERVER_TICK_SPEED * (1.25f - m_Tuning.m_HookDuration);
@ -287,7 +286,7 @@ void CCharacterCore::Tick(bool UseInput)
vec2 ClosestPoint;
if(closest_point_on_line(m_HookPos, NewPos, pCharCore->m_Pos, ClosestPoint))
{
if(distance(pCharCore->m_Pos, ClosestPoint) < PhysSize + 2.0f)
if(distance(pCharCore->m_Pos, ClosestPoint) < PhysicalSize() + 2.0f)
{
if(m_HookedPlayer == -1 || distance(m_HookPos, pCharCore->m_Pos) < Distance)
{
@ -322,7 +321,7 @@ void CCharacterCore::Tick(bool UseInput)
m_NewHook = true;
int RandomOut = m_pWorld->RandomOr0((*m_pTeleOuts)[teleNr - 1].size());
m_HookPos = (*m_pTeleOuts)[teleNr - 1][RandomOut] + TargetDirection * PhysSize * 1.5f;
m_HookPos = (*m_pTeleOuts)[teleNr - 1][RandomOut] + TargetDirection * PhysicalSize() * 1.5f;
m_HookDir = TargetDirection;
m_HookTeleBase = m_HookPos;
}
@ -411,9 +410,9 @@ void CCharacterCore::Tick(bool UseInput)
bool CanCollide = (m_Super || pCharCore->m_Super) || (pCharCore->m_Collision && m_Collision && !m_NoCollision && !pCharCore->m_NoCollision && m_Tuning.m_PlayerCollision);
if(CanCollide && Distance < PhysSize * 1.25f && Distance > 0.0f)
if(CanCollide && Distance < PhysicalSize() * 1.25f && Distance > 0.0f)
{
float a = (PhysSize * 1.45f - Distance);
float a = (PhysicalSize() * 1.45f - Distance);
float Velocity = 0.5f;
// make sure that we don't add excess force by checking the
@ -428,7 +427,7 @@ void CCharacterCore::Tick(bool UseInput)
// handle hook influence
if(m_Hook && m_HookedPlayer == i && m_Tuning.m_PlayerHooking)
{
if(Distance > PhysSize * 1.50f) // TODO: fix tweakable variable
if(Distance > PhysicalSize() * 1.50f) // TODO: fix tweakable variable
{
float HookAccel = m_Tuning.m_HookDragAccel * (Distance / m_Tuning.m_HookLength);
float DragSpeed = m_Tuning.m_HookDragSpeed;
@ -467,7 +466,7 @@ void CCharacterCore::Move()
vec2 NewPos = m_Pos;
vec2 OldVel = m_Vel;
m_pCollision->MoveBox(&NewPos, &m_Vel, vec2(28.0f, 28.0f), 0);
m_pCollision->MoveBox(&NewPos, &m_Vel, PhysicalSizeVec2(), 0);
m_Colliding = 0;
if(m_Vel.x < 0.001f && m_Vel.x > -0.001f)
@ -502,7 +501,7 @@ void CCharacterCore::Move()
if((!(pCharCore->m_Super || m_Super) && (m_Solo || pCharCore->m_Solo || !pCharCore->m_Collision || pCharCore->m_NoCollision || (m_Id != -1 && !m_pTeams->CanCollide(m_Id, p)))))
continue;
float D = distance(Pos, pCharCore->m_Pos);
if(D < 28.0f && D >= 0.0f)
if(D < PhysicalSize() && D >= 0.0f)
{
if(a > 0.0f)
m_Pos = LastPos;

View file

@ -211,6 +211,8 @@ class CCharacterCore
std::map<int, std::vector<vec2>> *m_pTeleOuts;
public:
static constexpr float PhysicalSize() { return 28.0f; };
static constexpr vec2 PhysicalSizeVec2() { return vec2(28.0f, 28.0f); };
vec2 m_Pos;
vec2 m_Vel;
bool m_Hook;

View file

@ -20,7 +20,7 @@ MACRO_ALLOC_POOL_ID_IMPL(CCharacter, MAX_CLIENTS)
// Character, "physical" player's part
CCharacter::CCharacter(CGameWorld *pWorld, CNetObj_PlayerInput LastInput) :
CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER, vec2(0, 0), ms_PhysSize)
CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER, vec2(0, 0), CCharacterCore::PhysicalSize())
{
m_Health = 0;
m_Armor = 0;
@ -776,13 +776,13 @@ void CCharacter::TickDefered()
//lastsentcore
vec2 StartPos = m_Core.m_Pos;
vec2 StartVel = m_Core.m_Vel;
bool StuckBefore = Collision()->TestBox(m_Core.m_Pos, vec2(28.0f, 28.0f));
bool StuckBefore = Collision()->TestBox(m_Core.m_Pos, CCharacterCore::PhysicalSizeVec2());
m_Core.m_Id = m_pPlayer->GetCID();
m_Core.Move();
bool StuckAfterMove = Collision()->TestBox(m_Core.m_Pos, vec2(28.0f, 28.0f));
bool StuckAfterMove = Collision()->TestBox(m_Core.m_Pos, CCharacterCore::PhysicalSizeVec2());
m_Core.Quantize();
bool StuckAfterQuant = Collision()->TestBox(m_Core.m_Pos, vec2(28.0f, 28.0f));
bool StuckAfterQuant = Collision()->TestBox(m_Core.m_Pos, CCharacterCore::PhysicalSizeVec2());
m_Pos = m_Core.m_Pos;
if(!StuckBefore && (StuckAfterMove || StuckAfterQuant))

View file

@ -29,9 +29,6 @@ class CCharacter : public CEntity
friend class CSaveTee; // need to use core
public:
//character's size
static const int ms_PhysSize = 28;
CCharacter(CGameWorld *pWorld, CNetObj_PlayerInput LastInput);
void Reset() override;

View file

@ -64,7 +64,7 @@ void CDragger::LookForPlayersToDrag()
mem_zero(pPlayersInRange, sizeof(pPlayersInRange));
int NumPlayersInRange = GameServer()->m_World.FindEntities(m_Pos,
g_Config.m_SvDraggerRange - CCharacter::ms_PhysSize,
g_Config.m_SvDraggerRange - CCharacterCore::PhysicalSize(),
(CEntity **)pPlayersInRange, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
// The closest player (within range) in a team is selected as the target

View file

@ -62,16 +62,16 @@ bool CEntity::GetNearestAirPos(vec2 Pos, vec2 PrevPos, vec2 *pOutPos)
vec2 BlockCenter = vec2(round_to_int(Pos.x), round_to_int(Pos.y)) - PosInBlock + vec2(16.0f, 16.0f);
*pOutPos = vec2(BlockCenter.x + (PosInBlock.x < 16 ? -2.0f : 1.0f), Pos.y);
if(!GameServer()->Collision()->TestBox(*pOutPos, vec2(28.0f, 28.0f)))
if(!GameServer()->Collision()->TestBox(*pOutPos, CCharacterCore::PhysicalSizeVec2()))
return true;
*pOutPos = vec2(Pos.x, BlockCenter.y + (PosInBlock.y < 16 ? -2.0f : 1.0f));
if(!GameServer()->Collision()->TestBox(*pOutPos, vec2(28.0f, 28.0f)))
if(!GameServer()->Collision()->TestBox(*pOutPos, CCharacterCore::PhysicalSizeVec2()))
return true;
*pOutPos = vec2(BlockCenter.x + (PosInBlock.x < 16 ? -2.0f : 1.0f),
BlockCenter.y + (PosInBlock.y < 16 ? -2.0f : 1.0f));
return !GameServer()->Collision()->TestBox(*pOutPos, vec2(28.0f, 28.0f));
return !GameServer()->Collision()->TestBox(*pOutPos, CCharacterCore::PhysicalSizeVec2());
}
bool CEntity::GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *OutPos)
@ -79,7 +79,7 @@ bool CEntity::GetNearestAirPosPlayer(vec2 PlayerPos, vec2 *OutPos)
for(int dist = 5; dist >= -1; dist--)
{
*OutPos = vec2(PlayerPos.x, PlayerPos.y - dist);
if(!GameServer()->Collision()->TestBox(*OutPos, vec2(28.0f, 28.0f)))
if(!GameServer()->Collision()->TestBox(*OutPos, CCharacterCore::PhysicalSizeVec2()))
{
return true;
}
@ -120,4 +120,4 @@ bool NetworkClippedLine(const CGameContext *pGameServer, int SnappingClient, vec
}
float ClippDistance = maximum(ShowDistance.x, ShowDistance.y);
return (absolute(DistanceToLine.x) > ClippDistance || absolute(DistanceToLine.y) > ClippDistance);
}
}