ddnet/src/game/extrainfo.cpp

73 lines
1.8 KiB
C++
Raw Normal View History

/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "extrainfo.h"
#include <base/math.h>
#include <engine/shared/snapshot.h>
#include <game/generated/protocol.h>
bool UseExtraInfo(const CNetObj_Projectile *pProj)
{
bool ExtraInfoFlag = ((abs(pProj->m_VelY) & (1 << 9)) != 0);
2017-06-06 08:11:42 +00:00
return ExtraInfoFlag;
}
2019-05-21 08:51:43 +00:00
void ExtractInfo(const CNetObj_Projectile *pProj, vec2 *StartPos, vec2 *StartVel)
{
2019-05-21 08:51:43 +00:00
if(!UseExtraInfo(pProj))
2017-06-06 08:11:42 +00:00
{
StartPos->x = pProj->m_X;
StartPos->y = pProj->m_Y;
StartVel->x = pProj->m_VelX / 100.0f;
StartVel->y = pProj->m_VelY / 100.0f;
2017-06-06 08:11:42 +00:00
}
else
{
StartPos->x = pProj->m_X / 100.0f;
StartPos->y = pProj->m_Y / 100.0f;
float Angle = pProj->m_VelX / 1000000.0f;
2017-06-06 08:11:42 +00:00
StartVel->x = sin(-Angle);
StartVel->y = cos(-Angle);
}
}
void ExtractExtraInfo(const CNetObj_Projectile *pProj, int *Owner, bool *Explosive, int *Bouncing, bool *Freeze)
{
2017-06-06 08:11:42 +00:00
int Data = pProj->m_VelY;
if(Owner)
{
*Owner = Data & 255;
if((Data >> 8) & 1)
2017-06-06 08:11:42 +00:00
*Owner = -(*Owner);
}
if(Bouncing)
*Bouncing = (Data >> 10) & 3;
2017-06-06 08:11:42 +00:00
if(Explosive)
*Explosive = (Data >> 12) & 1;
2017-06-06 08:11:42 +00:00
if(Freeze)
*Freeze = (Data >> 13) & 1;
}
void SnapshotRemoveExtraInfo(unsigned char *pData)
{
CSnapshot *pSnap = (CSnapshot *)pData;
2017-06-06 08:11:42 +00:00
for(int Index = 0; Index < pSnap->NumItems(); Index++)
{
CSnapshotItem *pItem = pSnap->GetItem(Index);
if(pItem->Type() == NETOBJTYPE_PROJECTILE)
{
CNetObj_Projectile *pProj = (CNetObj_Projectile *)((void *)pItem->Data());
2017-06-06 08:11:42 +00:00
if(UseExtraInfo(pProj))
{
vec2 Pos;
vec2 Vel;
2019-05-21 08:51:43 +00:00
ExtractInfo(pProj, &Pos, &Vel);
2017-06-06 08:11:42 +00:00
pProj->m_X = Pos.x;
pProj->m_Y = Pos.y;
pProj->m_VelX = (int)(Vel.x * 100.0f);
pProj->m_VelY = (int)(Vel.y * 100.0f);
2017-06-06 08:11:42 +00:00
}
}
}
}