Add tunezone prediction

This commit is contained in:
trml 2019-09-09 00:53:07 +02:00
parent 38f91d3891
commit bb5eab0cc0
12 changed files with 199 additions and 18 deletions

View file

@ -331,7 +331,7 @@ MACRO_CONFIG_STR(SvConnLoggingServer, sv_conn_logging_server, 128, "", CFGFLAG_S
#endif
MACRO_CONFIG_INT(ClUnpredictedShadow, cl_unpredicted_shadow, 0, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show unpredicted shadow tee to estimate your delay")
MACRO_CONFIG_INT(ClPredictDDRace, cl_predict_ddrace, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Predict some DDRace tiles")
MACRO_CONFIG_INT(ClPredictDDRace, cl_predict_ddrace, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Predict DDRace tiles and tunezones")
MACRO_CONFIG_INT(ClPredictFreeze, cl_predict_freeze, 1, 0, 2, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Predict freeze tiles (0 = off, 1 = on, 2 = partial (allow a small amount of movement in freeze)")
MACRO_CONFIG_INT(ClShowNinja, cl_show_ninja, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show ninja skin")
MACRO_CONFIG_INT(ClShowHookCollOther, cl_show_hook_coll_other, 1, 0, 1, CFGFLAG_CLIENT|CFGFLAG_SAVE, "Show other players' hook collision line")

View file

@ -239,6 +239,8 @@ void CGameClient::OnConsoleInit()
Console()->Register("swap_teams", "", CFGFLAG_SERVER, 0, 0, "Swap the current teams");
Console()->Register("shuffle_teams", "", CFGFLAG_SERVER, 0, 0, "Shuffle the current teams");
// register tune zone command to allow the client prediction to load tunezones from the map
Console()->Register("tune_zone", "i[zone] s[tuning] i[value]", CFGFLAG_CLIENT|CFGFLAG_GAME, ConTuneZone, this, "Tune in zone a variable to value");
for(int i = 0; i < m_All.m_Num; i++)
m_All.m_paComponents[i]->m_pClient = this;
@ -350,6 +352,7 @@ void CGameClient::OnInit()
m_GameWorld.m_GameTickSpeed = SERVER_TICK_SPEED;
m_GameWorld.m_pCollision = Collision();
m_GameWorld.m_pTuningList = m_aTuningList;
m_pMapimages->SetTextureScale(g_Config.m_ClTextEntitiesSize);
}
@ -488,6 +491,7 @@ void CGameClient::OnConnected()
m_GameWorld.m_WorldConfig.m_InfiniteAmmo = true;
for(int i = 0; i < MAX_CLIENTS; i++)
m_aLastWorldCharacters[i].m_Alive = false;
LoadMapSettings();
}
void CGameClient::OnReset()
@ -1999,7 +2003,11 @@ void CGameClient::UpdatePrediction()
m_GameWorld.m_WorldConfig.m_InfiniteAmmo = false;
m_GameWorld.m_WorldConfig.m_IsSolo = !m_Snap.m_aCharacters[m_Snap.m_LocalClientID].m_HasExtendedData && !m_Tuning[g_Config.m_ClDummy].m_PlayerCollision && !m_Tuning[g_Config.m_ClDummy].m_PlayerHooking;
m_GameWorld.m_Core.m_Tuning[g_Config.m_ClDummy] = m_Tuning[g_Config.m_ClDummy];
int TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_LocalCharacterPos));
if(!TuneZone || !m_GameWorld.m_WorldConfig.m_PredictTiles)
m_GameWorld.m_Tuning[g_Config.m_ClDummy] = m_GameWorld.m_Core.m_Tuning[g_Config.m_ClDummy] = m_Tuning[g_Config.m_ClDummy];
else
m_GameWorld.TuningList()[TuneZone] = m_GameWorld.m_Core.m_Tuning[g_Config.m_ClDummy] = m_Tuning[g_Config.m_ClDummy];
// restore characters from previously saved ones if they temporarily left the snapshot
for(int i = 0; i < MAX_CLIENTS; i++)
@ -2299,3 +2307,60 @@ bool CGameClient::IsOtherTeam(int ClientID)
return m_Teams.Team(ClientID) != m_Teams.Team(m_Snap.m_LocalClientID);
}
void CGameClient::LoadMapSettings()
{
// Reset Tunezones
CTuningParams TuningParams;
for(int i = 0; i < NUM_TUNEZONES; i++)
{
TuningList()[i] = TuningParams;
TuningList()[i].Set("gun_curvature", 0);
TuningList()[i].Set("gun_speed", 1400);
TuningList()[i].Set("shotgun_curvature", 0);
TuningList()[i].Set("shotgun_speed", 500);
TuningList()[i].Set("shotgun_speeddiff", 0);
}
// Load map tunings
IMap *pMap = Kernel()->RequestInterface<IMap>();
int Start, Num;
pMap->GetType(MAPITEMTYPE_INFO, &Start, &Num);
for(int i = Start; i < Start + Num; i++)
{
int ItemID;
CMapItemInfoSettings *pItem = (CMapItemInfoSettings *)pMap->GetItem(i, 0, &ItemID);
int ItemSize = pMap->GetItemSize(i);
if(!pItem || ItemID != 0)
continue;
if(ItemSize < (int)sizeof(CMapItemInfoSettings))
break;
if(!(pItem->m_Settings > -1))
break;
int Size = pMap->GetDataSize(pItem->m_Settings);
char *pSettings = (char *)pMap->GetData(pItem->m_Settings);
char *pNext = pSettings;
dbg_msg("New tune ","%s", pNext);
while(pNext < pSettings + Size)
{
int StrSize = str_length(pNext) + 1;
Console()->ExecuteLine(pNext, IConsole::CLIENT_ID_GAME);
pNext += StrSize;
}
pMap->UnloadData(pItem->m_Settings);
break;
}
}
void CGameClient::ConTuneZone(IConsole::IResult *pResult, void *pUserData)
{
CGameClient *pSelf = (CGameClient *)pUserData;
int List = pResult->GetInteger(0);
const char *pParamName = pResult->GetString(1);
float NewValue = pResult->GetFloat(2);
if(List >= 0 && List < NUM_TUNEZONES)
pSelf->TuningList()[List].Set(pParamName, NewValue);
}

View file

@ -154,6 +154,8 @@ class CGameClient : public IGameClient
static void ConchainSpecialDummy(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainClTextEntitiesSize(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConTuneZone(IConsole::IResult *pResult, void *pUserData);
public:
IKernel *Kernel() { return IInterface::Kernel(); }
IEngine *Engine() const { return m_pEngine; }
@ -465,6 +467,14 @@ private:
CCharOrder m_CharOrder;
class CCharacter m_aLastWorldCharacters[MAX_CLIENTS];
enum
{
NUM_TUNEZONES = 256
};
void LoadMapSettings();
CTuningParams m_aTuningList[NUM_TUNEZONES];
CTuningParams *TuningList() { return &m_aTuningList[0]; }
};
ColorRGBA CalculateNameColor(ColorHSLA TextColorHSL);

View file

@ -87,7 +87,11 @@ void CCharacter::HandleJetpack()
{
if (m_Jetpack)
{
float Strength = m_LastJetpackStrength;
float Strength;
if(!m_TuneZone)
Strength = m_LastJetpackStrength;
else
Strength = TuningList()[m_TuneZone].m_JetpackStrength;
TakeDamage(Direction * -1.0f * (Strength / 100.0f / 6.11f), g_pData->m_Weapons.m_Hammer.m_pBase->m_Damage, GetCID(), m_Core.m_ActiveWeapon);
}
}
@ -324,7 +328,11 @@ void CCharacter::FireWeapon()
else
Dir = vec2(0.f, -1.f);
float Strength = Tuning()->m_HammerStrength;
float Strength;
if (!m_TuneZone)
Strength = Tuning()->m_HammerStrength;
else
Strength = TuningList()[m_TuneZone].m_HammerStrength;
vec2 Temp = pTarget->m_Core.m_Vel + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f;
pTarget->Core()->LimitForce(&Temp);
@ -366,7 +374,11 @@ void CCharacter::FireWeapon()
if (!m_Jetpack)
{
int Lifetime;
Lifetime = (int)(GameWorld()->GameTickSpeed()*Tuning()->m_GunLifetime);
if (!m_TuneZone)
Lifetime = (int)(GameWorld()->GameTickSpeed()*Tuning()->m_GunLifetime);
else
Lifetime = (int)(GameWorld()->GameTickSpeed()*TuningList()[m_TuneZone].m_GunLifetime);
new CProjectile
(
GameWorld(),
@ -415,14 +427,24 @@ void CCharacter::FireWeapon()
}
else if(GameWorld()->m_WorldConfig.m_IsDDRace)
{
float LaserReach = Tuning()->m_LaserReach;
float LaserReach;
if (!m_TuneZone)
LaserReach = Tuning()->m_LaserReach;
else
LaserReach = TuningList()[m_TuneZone].m_LaserReach;
new CLaser(GameWorld(), m_Pos, Direction, LaserReach, GetCID(), WEAPON_SHOTGUN);
}
} break;
case WEAPON_GRENADE:
{
int Lifetime = (int)(GameWorld()->GameTickSpeed()*Tuning()->m_GrenadeLifetime);
int Lifetime;
if (!m_TuneZone)
Lifetime = (int)(GameWorld()->GameTickSpeed()*Tuning()->m_GrenadeLifetime);
else
Lifetime = (int)(GameWorld()->GameTickSpeed()*TuningList()[m_TuneZone].m_GrenadeLifetime);
new CProjectile
(
GameWorld(),
@ -441,7 +463,12 @@ void CCharacter::FireWeapon()
case WEAPON_RIFLE:
{
float LaserReach = Tuning()->m_LaserReach;
float LaserReach;
if(!m_TuneZone)
LaserReach = Tuning()->m_LaserReach;
else
LaserReach = TuningList()[m_TuneZone].m_LaserReach;
new CLaser(GameWorld(), m_Pos, Direction, LaserReach, GetCID(), WEAPON_RIFLE);
} break;
@ -462,7 +489,12 @@ void CCharacter::FireWeapon()
if(!m_ReloadTimer)
{
float FireDelay;
Tuning()->Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
if(!m_TuneZone)
Tuning()->Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
else
TuningList()[m_TuneZone].Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
m_ReloadTimer = FireDelay * GameWorld()->GameTickSpeed() / 1000;
}
}
@ -886,6 +918,17 @@ void CCharacter::HandleTiles(int Index)
}
}
void CCharacter::HandleTuneLayer()
{
int CurrentIndex = Collision()->GetMapIndex(m_Pos);
m_TuneZone = GameWorld()->m_WorldConfig.m_PredictTiles ? Collision()->IsTune(CurrentIndex) : 0;
if(m_TuneZone)
m_Core.m_pWorld->m_Tuning[g_Config.m_ClDummy] = TuningList()[m_TuneZone]; // throw tunings from specific zone into gamecore
else
m_Core.m_pWorld->m_Tuning[g_Config.m_ClDummy] = GameWorld()->m_Tuning[g_Config.m_ClDummy];
}
void CCharacter::DDRaceTick()
{
mem_copy(&m_Input, &m_SavedInput, sizeof(m_Input));
@ -904,6 +947,8 @@ void CCharacter::DDRaceTick()
if (m_FreezeTime == 1)
UnFreeze();
}
HandleTuneLayer();
}
void CCharacter::DDRacePostCoreTick()
@ -1185,6 +1230,8 @@ void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtende
m_LastSnapWeapon = pChar->m_Weapon;
m_Alive = true;
m_TuneZone = GameWorld()->m_WorldConfig.m_PredictTiles ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0;
// set the current weapon
if(pChar->m_Weapon != WEAPON_NINJA)
{

View file

@ -88,6 +88,7 @@ public:
DISABLE_HIT_RIFLE=8
};
int m_Hit;
int m_TuneZone;
vec2 m_PrevPos;
vec2 m_PrevPrevPos;
int m_TeleCheckpoint;
@ -207,6 +208,7 @@ private:
void HandleSkippableTiles(int Index);
void DDRaceTick();
void DDRacePostCoreTick();
void HandleTuneLayer();
int m_StrongWeakID;
};

View file

@ -20,6 +20,7 @@ CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEner
m_TelePos = vec2(0,0);
m_WasTele = false;
m_Type = Type;
m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos));
GameWorld()->InsertEntity(this);
DoBounce();
}
@ -45,7 +46,12 @@ bool CLaser::HitCharacter(vec2 From, vec2 To)
{
vec2 Temp;
float Strength = GameWorld()->Tuning()->m_ShotgunStrength;;
float Strength;
if (!m_TuneZone)
Strength = GameWorld()->Tuning()->m_ShotgunStrength;
else
Strength = GameWorld()->TuningList()[m_TuneZone].m_ShotgunStrength;
if(!g_Config.m_SvOldLaser)
Temp = pHit->Core()->m_Vel + normalize(m_PrevPos - pHit->Core()->m_Pos) * Strength;
@ -119,12 +125,18 @@ void CLaser::DoBounce()
m_Pos = TempPos;
m_Dir = normalize(TempDir);
m_Energy -= distance(m_From, m_Pos) + GameWorld()->Tuning()->m_LaserBounceCost;
if(!m_TuneZone)
m_Energy -= distance(m_From, m_Pos) + GameWorld()->Tuning()->m_LaserBounceCost;
else
m_Energy -= distance(m_From, m_Pos) + GameWorld()->TuningList()[m_TuneZone].m_LaserBounceCost;
m_Bounces++;
m_WasTele = false;
int BounceNum = GameWorld()->Tuning()->m_LaserBounceNum;
if(m_TuneZone)
BounceNum = GameWorld()->TuningList()[m_TuneZone].m_LaserBounceNum;
if(m_Bounces > BounceNum)
m_Energy = -1;
@ -143,7 +155,11 @@ void CLaser::DoBounce()
void CLaser::Tick()
{
float Delay = GameWorld()->Tuning()->m_LaserBounceDelay;
float Delay;
if(m_TuneZone)
Delay = GameWorld()->TuningList()[m_TuneZone].m_LaserBounceDelay;
else
Delay = GameWorld()->Tuning()->m_LaserBounceDelay;
if(GameWorld()->m_WorldConfig.m_IsVanilla) // predict old physics on vanilla 0.6 servers
{
@ -177,6 +193,7 @@ CLaser::CLaser(CGameWorld *pGameWorld, int ID, CNetObj_Laser *pLaser)
m_Energy = 0;
m_Type = WEAPON_RIFLE;
m_PrevPos = m_From;
m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos));
m_ID = ID;
}

View file

@ -38,6 +38,7 @@ private:
vec2 m_PrevPos;
int m_Type;
int m_TuneZone;
};
#endif

View file

@ -38,6 +38,8 @@ CProjectile::CProjectile
m_Number = Number;
m_Freeze = Freeze;
m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos));
GameWorld()->InsertEntity(this);
}
@ -49,18 +51,44 @@ vec2 CProjectile::GetPos(float Time)
switch(m_Type)
{
case WEAPON_GRENADE:
Curvature = Tuning()->m_GrenadeCurvature;
Speed = Tuning()->m_GrenadeSpeed;
if(!m_TuneZone)
{
Curvature = Tuning()->m_GrenadeCurvature;
Speed = Tuning()->m_GrenadeSpeed;
}
else
{
Curvature = TuningList()[m_TuneZone].m_GrenadeCurvature;
Speed = TuningList()[m_TuneZone].m_GrenadeSpeed;
}
break;
case WEAPON_SHOTGUN:
Curvature = Tuning()->m_ShotgunCurvature;
Speed = Tuning()->m_ShotgunSpeed;
if(!m_TuneZone)
{
Curvature = Tuning()->m_ShotgunCurvature;
Speed = Tuning()->m_ShotgunSpeed;
}
else
{
Curvature = TuningList()[m_TuneZone].m_ShotgunCurvature;
Speed = TuningList()[m_TuneZone].m_ShotgunSpeed;
}
break;
case WEAPON_GUN:
Curvature = Tuning()->m_GunCurvature;
Speed = Tuning()->m_GunSpeed;
if(!m_TuneZone)
{
Curvature = Tuning()->m_GunCurvature;
Speed = Tuning()->m_GunSpeed;
}
else
{
Curvature = TuningList()[m_TuneZone].m_GunCurvature;
Speed = TuningList()[m_TuneZone].m_GunSpeed;
}
break;
}
@ -183,6 +211,7 @@ CProjectile::CProjectile(CGameWorld *pGameWorld, int ID, CNetObj_Projectile *pPr
Lifetime = pGameWorld->Tuning()->m_ShotgunLifetime * GameWorld()->GameTickSpeed();
m_LifeSpan = Lifetime - (pGameWorld->GameTick() - m_StartTick);
m_ID = ID;
m_TuneZone = Collision()->IsTune(Collision()->GetMapIndex(m_Pos));
}
void CProjectile::FillInfo(CNetObj_Projectile *pProj)

View file

@ -59,6 +59,7 @@ private:
int m_Bouncing;
bool m_Freeze;
int m_TuneZone;
};
#endif

View file

@ -40,6 +40,7 @@ public:
class CGameWorld *GameWorld() { return m_pGameWorld; }
CTuningParams *Tuning() { return GameWorld()->Tuning(); }
CTuningParams *TuningList() { return GameWorld()->TuningList(); }
class CCollision *Collision() { return GameWorld()->Collision(); }
CEntity *TypeNext() { return m_pNextTypeEntity; }
CEntity *TypePrev() { return m_pPrevTypeEntity; }

View file

@ -518,7 +518,11 @@ void CGameWorld::CopyWorld(CGameWorld *pFrom)
m_pCollision = pFrom->m_pCollision;
m_WorldConfig = pFrom->m_WorldConfig;
for(int i = 0; i < 2; i++)
{
m_Core.m_Tuning[i] = pFrom->m_Core.m_Tuning[i];
m_Tuning[i] = pFrom->m_Tuning[i];
}
m_pTuningList = pFrom->m_pTuningList;
m_Teams = pFrom->m_Teams;
// delete the previous entities
for(int i = 0; i < NUM_ENTTYPES; i++)

View file

@ -88,6 +88,10 @@ public:
CEntity *FindMatch(int ObjID, int ObjType, const void *pObjData);
void Clear();
CTuningParams m_Tuning[2];
CTuningParams *m_pTuningList;
CTuningParams *TuningList() { return m_pTuningList; }
private:
void RemoveEntities();