mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7136 from infclass/for-ddnet2
Refactor some core classes (step 1/xxx to shared CGameWorld)
This commit is contained in:
commit
15bdef32a1
|
@ -1995,6 +1995,7 @@ set_src(ENGINE_GFX GLOB src/engine/gfx
|
||||||
image_manipulation.h
|
image_manipulation.h
|
||||||
)
|
)
|
||||||
set_src(GAME_SHARED GLOB src/game
|
set_src(GAME_SHARED GLOB src/game
|
||||||
|
alloc.h
|
||||||
collision.cpp
|
collision.cpp
|
||||||
collision.h
|
collision.h
|
||||||
ddracechat.h
|
ddracechat.h
|
||||||
|
@ -2497,7 +2498,6 @@ if(SERVER)
|
||||||
upnp.h
|
upnp.h
|
||||||
)
|
)
|
||||||
set_src(GAME_SERVER GLOB_RECURSE src/game/server
|
set_src(GAME_SERVER GLOB_RECURSE src/game/server
|
||||||
alloc.h
|
|
||||||
ddracechat.cpp
|
ddracechat.cpp
|
||||||
ddracecommands.cpp
|
ddracecommands.cpp
|
||||||
entities/character.cpp
|
entities/character.cpp
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
/* (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. */
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
||||||
#ifndef GAME_SERVER_ALLOC_H
|
#ifndef GAME_ALLOC_H
|
||||||
#define GAME_SERVER_ALLOC_H
|
#define GAME_ALLOC_H
|
||||||
|
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
|
@ -939,7 +939,7 @@ void CCharacter::HandleTuneLayer()
|
||||||
SetTuneZone(GameWorld()->m_WorldConfig.m_UseTuneZones ? Collision()->IsTune(CurrentIndex) : 0);
|
SetTuneZone(GameWorld()->m_WorldConfig.m_UseTuneZones ? Collision()->IsTune(CurrentIndex) : 0);
|
||||||
|
|
||||||
if(m_IsLocal)
|
if(m_IsLocal)
|
||||||
m_Core.m_pWorld->m_aTuning[g_Config.m_ClDummy] = *GetTuning(m_TuneZone); // throw tunings (from specific zone if in a tunezone) into gamecore if the character is local
|
GameWorld()->m_Core.m_aTuning[g_Config.m_ClDummy] = *GetTuning(m_TuneZone); // throw tunings (from specific zone if in a tunezone) into gamecore if the character is local
|
||||||
m_Core.m_Tuning = *GetTuning(m_TuneZone);
|
m_Core.m_Tuning = *GetTuning(m_TuneZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1107,7 +1107,7 @@ void CCharacter::GiveAllWeapons()
|
||||||
|
|
||||||
CTeamsCore *CCharacter::TeamsCore()
|
CTeamsCore *CCharacter::TeamsCore()
|
||||||
{
|
{
|
||||||
return m_Core.m_pTeams;
|
return GameWorld()->Teams();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCharacter::CCharacter(CGameWorld *pGameWorld, int ID, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended) :
|
CCharacter::CCharacter(CGameWorld *pGameWorld, int ID, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended) :
|
||||||
|
@ -1171,7 +1171,7 @@ void CCharacter::ResetPrediction()
|
||||||
SetWeaponGot(w, false);
|
SetWeaponGot(w, false);
|
||||||
SetWeaponAmmo(w, -1);
|
SetWeaponAmmo(w, -1);
|
||||||
}
|
}
|
||||||
if(m_Core.m_HookedPlayer >= 0)
|
if(m_Core.HookedPlayer() >= 0)
|
||||||
{
|
{
|
||||||
m_Core.SetHookedPlayer(-1);
|
m_Core.SetHookedPlayer(-1);
|
||||||
m_Core.m_HookState = HOOK_IDLE;
|
m_Core.m_HookState = HOOK_IDLE;
|
||||||
|
@ -1355,9 +1355,7 @@ void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtende
|
||||||
|
|
||||||
void CCharacter::SetCoreWorld(CGameWorld *pGameWorld)
|
void CCharacter::SetCoreWorld(CGameWorld *pGameWorld)
|
||||||
{
|
{
|
||||||
m_Core.m_pWorld = &pGameWorld->m_Core;
|
m_Core.SetCoreWorld(&pGameWorld->m_Core, pGameWorld->Collision(), pGameWorld->Teams());
|
||||||
m_Core.m_pCollision = pGameWorld->Collision();
|
|
||||||
m_Core.m_pTeams = pGameWorld->Teams();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCharacter::Match(CCharacter *pChar)
|
bool CCharacter::Match(CCharacter *pChar)
|
||||||
|
|
|
@ -3,33 +3,23 @@
|
||||||
#ifndef GAME_CLIENT_PREDICTION_ENTITY_H
|
#ifndef GAME_CLIENT_PREDICTION_ENTITY_H
|
||||||
#define GAME_CLIENT_PREDICTION_ENTITY_H
|
#define GAME_CLIENT_PREDICTION_ENTITY_H
|
||||||
|
|
||||||
#include "gameworld.h"
|
|
||||||
#include <base/vmath.h>
|
#include <base/vmath.h>
|
||||||
|
|
||||||
#define MACRO_ALLOC_HEAP() \
|
#include <game/alloc.h>
|
||||||
public: \
|
|
||||||
void *operator new(size_t Size) \
|
#include "gameworld.h"
|
||||||
{ \
|
|
||||||
void *p = malloc(Size); \
|
|
||||||
mem_zero(p, Size); \
|
|
||||||
return p; \
|
|
||||||
} \
|
|
||||||
void operator delete(void *pPtr) \
|
|
||||||
{ \
|
|
||||||
free(pPtr); \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
private:
|
|
||||||
|
|
||||||
class CEntity
|
class CEntity
|
||||||
{
|
{
|
||||||
MACRO_ALLOC_HEAP()
|
MACRO_ALLOC_HEAP()
|
||||||
friend class CGameWorld; // entity list handling
|
|
||||||
|
private:
|
||||||
|
friend CGameWorld; // entity list handling
|
||||||
CEntity *m_pPrevTypeEntity;
|
CEntity *m_pPrevTypeEntity;
|
||||||
CEntity *m_pNextTypeEntity;
|
CEntity *m_pNextTypeEntity;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
class CGameWorld *m_pGameWorld;
|
CGameWorld *m_pGameWorld;
|
||||||
bool m_MarkedForDestroy;
|
bool m_MarkedForDestroy;
|
||||||
int m_ID;
|
int m_ID;
|
||||||
int m_ObjType;
|
int m_ObjType;
|
||||||
|
@ -41,7 +31,7 @@ public:
|
||||||
virtual ~CEntity();
|
virtual ~CEntity();
|
||||||
|
|
||||||
std::vector<SSwitchers> &Switchers() { return m_pGameWorld->Switchers(); }
|
std::vector<SSwitchers> &Switchers() { return m_pGameWorld->Switchers(); }
|
||||||
class CGameWorld *GameWorld() { return m_pGameWorld; }
|
CGameWorld *GameWorld() { return m_pGameWorld; }
|
||||||
CTuningParams *Tuning() { return GameWorld()->Tuning(); }
|
CTuningParams *Tuning() { return GameWorld()->Tuning(); }
|
||||||
CTuningParams *TuningList() { return GameWorld()->TuningList(); }
|
CTuningParams *TuningList() { return GameWorld()->TuningList(); }
|
||||||
CTuningParams *GetTuning(int i) { return GameWorld()->GetTuning(i); }
|
CTuningParams *GetTuning(int i) { return GameWorld()->GetTuning(i); }
|
||||||
|
|
|
@ -182,11 +182,6 @@ void CGameWorld::RemoveEntities()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool distCompare(std::pair<float, int> a, std::pair<float, int> b)
|
|
||||||
{
|
|
||||||
return (a.first < b.first);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGameWorld::Tick()
|
void CGameWorld::Tick()
|
||||||
{
|
{
|
||||||
// update all objects
|
// update all objects
|
||||||
|
@ -315,7 +310,7 @@ void CGameWorld::ReleaseHooked(int ClientID)
|
||||||
for(; pChr; pChr = (CCharacter *)pChr->TypeNext())
|
for(; pChr; pChr = (CCharacter *)pChr->TypeNext())
|
||||||
{
|
{
|
||||||
CCharacterCore *pCore = pChr->Core();
|
CCharacterCore *pCore = pChr->Core();
|
||||||
if(pCore->m_HookedPlayer == ClientID)
|
if(pCore->HookedPlayer() == ClientID)
|
||||||
{
|
{
|
||||||
pCore->SetHookedPlayer(-1);
|
pCore->SetHookedPlayer(-1);
|
||||||
pCore->m_HookState = HOOK_RETRACTED;
|
pCore->m_HookState = HOOK_RETRACTED;
|
||||||
|
@ -556,7 +551,7 @@ void CGameWorld::NetObjEnd()
|
||||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||||
if(CCharacter *pChar = GetCharacterByID(i))
|
if(CCharacter *pChar = GetCharacterByID(i))
|
||||||
if(!pChar->m_MarkedForDestroy)
|
if(!pChar->m_MarkedForDestroy)
|
||||||
if(CCharacter *pHookedChar = GetCharacterByID(pChar->m_Core.m_HookedPlayer))
|
if(CCharacter *pHookedChar = GetCharacterByID(pChar->m_Core.HookedPlayer()))
|
||||||
if(pHookedChar->m_MarkedForDestroy)
|
if(pHookedChar->m_MarkedForDestroy)
|
||||||
{
|
{
|
||||||
pHookedChar->m_Pos = pHookedChar->m_Core.m_Pos = pChar->m_Core.m_HookPos;
|
pHookedChar->m_Pos = pHookedChar->m_Core.m_Pos = pChar->m_Core.m_HookPos;
|
||||||
|
|
|
@ -15,8 +15,6 @@ class CEntity;
|
||||||
|
|
||||||
class CGameWorld
|
class CGameWorld
|
||||||
{
|
{
|
||||||
friend CCharacter;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
|
|
@ -97,6 +97,13 @@ void CCharacterCore::Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore
|
||||||
Reset();
|
Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCharacterCore::SetCoreWorld(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams)
|
||||||
|
{
|
||||||
|
m_pWorld = pWorld;
|
||||||
|
m_pCollision = pCollision;
|
||||||
|
m_pTeams = pTeams;
|
||||||
|
}
|
||||||
|
|
||||||
void CCharacterCore::Reset()
|
void CCharacterCore::Reset()
|
||||||
{
|
{
|
||||||
m_Pos = vec2(0, 0);
|
m_Pos = vec2(0, 0);
|
||||||
|
|
|
@ -220,7 +220,6 @@ public:
|
||||||
|
|
||||||
class CCharacterCore
|
class CCharacterCore
|
||||||
{
|
{
|
||||||
friend class CCharacter;
|
|
||||||
CWorldCore *m_pWorld = nullptr;
|
CWorldCore *m_pWorld = nullptr;
|
||||||
CCollision *m_pCollision;
|
CCollision *m_pCollision;
|
||||||
std::map<int, std::vector<vec2>> *m_pTeleOuts;
|
std::map<int, std::vector<vec2>> *m_pTeleOuts;
|
||||||
|
@ -236,8 +235,8 @@ public:
|
||||||
vec2 m_HookTeleBase;
|
vec2 m_HookTeleBase;
|
||||||
int m_HookTick;
|
int m_HookTick;
|
||||||
int m_HookState;
|
int m_HookState;
|
||||||
int m_HookedPlayer;
|
|
||||||
std::set<int> m_AttachedPlayers;
|
std::set<int> m_AttachedPlayers;
|
||||||
|
int HookedPlayer() const { return m_HookedPlayer; }
|
||||||
void SetHookedPlayer(int HookedPlayer);
|
void SetHookedPlayer(int HookedPlayer);
|
||||||
|
|
||||||
int m_ActiveWeapon;
|
int m_ActiveWeapon;
|
||||||
|
@ -272,6 +271,7 @@ public:
|
||||||
int m_TriggeredEvents;
|
int m_TriggeredEvents;
|
||||||
|
|
||||||
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr, std::map<int, std::vector<vec2>> *pTeleOuts = nullptr);
|
void Init(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams = nullptr, std::map<int, std::vector<vec2>> *pTeleOuts = nullptr);
|
||||||
|
void SetCoreWorld(CWorldCore *pWorld, CCollision *pCollision, CTeamsCore *pTeams);
|
||||||
void Reset();
|
void Reset();
|
||||||
void TickDeferred();
|
void TickDeferred();
|
||||||
void Tick(bool UseInput, bool DoDeferredTick = true);
|
void Tick(bool UseInput, bool DoDeferredTick = true);
|
||||||
|
@ -318,6 +318,7 @@ public:
|
||||||
private:
|
private:
|
||||||
CTeamsCore *m_pTeams;
|
CTeamsCore *m_pTeams;
|
||||||
int m_MoveRestrictions;
|
int m_MoveRestrictions;
|
||||||
|
int m_HookedPlayer;
|
||||||
static bool IsSwitchActiveCb(int Number, void *pUser);
|
static bool IsSwitchActiveCb(int Number, void *pUser);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -206,9 +206,9 @@ void CCharacter::HandleJetpack()
|
||||||
{
|
{
|
||||||
float Strength;
|
float Strength;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
Strength = GameServer()->Tuning()->m_JetpackStrength;
|
Strength = Tuning()->m_JetpackStrength;
|
||||||
else
|
else
|
||||||
Strength = GameServer()->TuningList()[m_TuneZone].m_JetpackStrength;
|
Strength = TuningList()[m_TuneZone].m_JetpackStrength;
|
||||||
TakeDamage(Direction * -1.0f * (Strength / 100.0f / 6.11f), 0, m_pPlayer->GetCID(), m_Core.m_ActiveWeapon);
|
TakeDamage(Direction * -1.0f * (Strength / 100.0f / 6.11f), 0, m_pPlayer->GetCID(), m_Core.m_ActiveWeapon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -255,9 +255,9 @@ void CCharacter::HandleNinja()
|
||||||
vec2 GroundElasticity;
|
vec2 GroundElasticity;
|
||||||
|
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
GroundElasticity = vec2(GameServer()->Tuning()->m_GroundElasticityX, GameServer()->Tuning()->m_GroundElasticityY);
|
GroundElasticity = vec2(Tuning()->m_GroundElasticityX, Tuning()->m_GroundElasticityY);
|
||||||
else
|
else
|
||||||
GroundElasticity = vec2(GameServer()->TuningList()[m_TuneZone].m_GroundElasticityX, GameServer()->TuningList()[m_TuneZone].m_GroundElasticityY);
|
GroundElasticity = vec2(TuningList()[m_TuneZone].m_GroundElasticityX, TuningList()[m_TuneZone].m_GroundElasticityY);
|
||||||
|
|
||||||
Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(GetProximityRadius(), GetProximityRadius()), GroundElasticity);
|
Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(GetProximityRadius(), GetProximityRadius()), GroundElasticity);
|
||||||
|
|
||||||
|
@ -470,9 +470,9 @@ void CCharacter::FireWeapon()
|
||||||
|
|
||||||
float Strength;
|
float Strength;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
Strength = GameServer()->Tuning()->m_HammerStrength;
|
Strength = Tuning()->m_HammerStrength;
|
||||||
else
|
else
|
||||||
Strength = GameServer()->TuningList()[m_TuneZone].m_HammerStrength;
|
Strength = TuningList()[m_TuneZone].m_HammerStrength;
|
||||||
|
|
||||||
vec2 Temp = pTarget->m_Core.m_Vel + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f;
|
vec2 Temp = pTarget->m_Core.m_Vel + normalize(Dir + vec2(0.f, -1.1f)) * 10.0f;
|
||||||
Temp = ClampVel(pTarget->m_MoveRestrictions, Temp);
|
Temp = ClampVel(pTarget->m_MoveRestrictions, Temp);
|
||||||
|
@ -494,9 +494,9 @@ void CCharacter::FireWeapon()
|
||||||
{
|
{
|
||||||
float FireDelay;
|
float FireDelay;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
FireDelay = GameServer()->Tuning()->m_HammerHitFireDelay;
|
FireDelay = Tuning()->m_HammerHitFireDelay;
|
||||||
else
|
else
|
||||||
FireDelay = GameServer()->TuningList()[m_TuneZone].m_HammerHitFireDelay;
|
FireDelay = TuningList()[m_TuneZone].m_HammerHitFireDelay;
|
||||||
m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000;
|
m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,9 +508,9 @@ void CCharacter::FireWeapon()
|
||||||
{
|
{
|
||||||
int Lifetime;
|
int Lifetime;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
Lifetime = (int)(Server()->TickSpeed() * GameServer()->Tuning()->m_GunLifetime);
|
Lifetime = (int)(Server()->TickSpeed() * Tuning()->m_GunLifetime);
|
||||||
else
|
else
|
||||||
Lifetime = (int)(Server()->TickSpeed() * GameServer()->TuningList()[m_TuneZone].m_GunLifetime);
|
Lifetime = (int)(Server()->TickSpeed() * TuningList()[m_TuneZone].m_GunLifetime);
|
||||||
|
|
||||||
new CProjectile(
|
new CProjectile(
|
||||||
GameWorld(),
|
GameWorld(),
|
||||||
|
@ -534,9 +534,9 @@ void CCharacter::FireWeapon()
|
||||||
{
|
{
|
||||||
float LaserReach;
|
float LaserReach;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
LaserReach = GameServer()->Tuning()->m_LaserReach;
|
LaserReach = Tuning()->m_LaserReach;
|
||||||
else
|
else
|
||||||
LaserReach = GameServer()->TuningList()[m_TuneZone].m_LaserReach;
|
LaserReach = TuningList()[m_TuneZone].m_LaserReach;
|
||||||
|
|
||||||
new CLaser(&GameServer()->m_World, m_Pos, Direction, LaserReach, m_pPlayer->GetCID(), WEAPON_SHOTGUN);
|
new CLaser(&GameServer()->m_World, m_Pos, Direction, LaserReach, m_pPlayer->GetCID(), WEAPON_SHOTGUN);
|
||||||
GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE, TeamMask());
|
GameServer()->CreateSound(m_Pos, SOUND_SHOTGUN_FIRE, TeamMask());
|
||||||
|
@ -547,9 +547,9 @@ void CCharacter::FireWeapon()
|
||||||
{
|
{
|
||||||
int Lifetime;
|
int Lifetime;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
Lifetime = (int)(Server()->TickSpeed() * GameServer()->Tuning()->m_GrenadeLifetime);
|
Lifetime = (int)(Server()->TickSpeed() * Tuning()->m_GrenadeLifetime);
|
||||||
else
|
else
|
||||||
Lifetime = (int)(Server()->TickSpeed() * GameServer()->TuningList()[m_TuneZone].m_GrenadeLifetime);
|
Lifetime = (int)(Server()->TickSpeed() * TuningList()[m_TuneZone].m_GrenadeLifetime);
|
||||||
|
|
||||||
new CProjectile(
|
new CProjectile(
|
||||||
GameWorld(),
|
GameWorld(),
|
||||||
|
@ -572,9 +572,9 @@ void CCharacter::FireWeapon()
|
||||||
{
|
{
|
||||||
float LaserReach;
|
float LaserReach;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
LaserReach = GameServer()->Tuning()->m_LaserReach;
|
LaserReach = Tuning()->m_LaserReach;
|
||||||
else
|
else
|
||||||
LaserReach = GameServer()->TuningList()[m_TuneZone].m_LaserReach;
|
LaserReach = TuningList()[m_TuneZone].m_LaserReach;
|
||||||
|
|
||||||
new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCID(), WEAPON_LASER);
|
new CLaser(GameWorld(), m_Pos, Direction, LaserReach, m_pPlayer->GetCID(), WEAPON_LASER);
|
||||||
GameServer()->CreateSound(m_Pos, SOUND_LASER_FIRE, TeamMask());
|
GameServer()->CreateSound(m_Pos, SOUND_LASER_FIRE, TeamMask());
|
||||||
|
@ -601,9 +601,9 @@ void CCharacter::FireWeapon()
|
||||||
{
|
{
|
||||||
float FireDelay;
|
float FireDelay;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
GameServer()->Tuning()->Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
|
Tuning()->Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
|
||||||
else
|
else
|
||||||
GameServer()->TuningList()[m_TuneZone].Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
|
TuningList()[m_TuneZone].Get(38 + m_Core.m_ActiveWeapon, &FireDelay);
|
||||||
m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000;
|
m_ReloadTimer = FireDelay * Server()->TickSpeed() / 1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -768,7 +768,8 @@ void CCharacter::Tick()
|
||||||
|
|
||||||
if(m_Core.m_TriggeredEvents & COREEVENT_HOOK_ATTACH_PLAYER)
|
if(m_Core.m_TriggeredEvents & COREEVENT_HOOK_ATTACH_PLAYER)
|
||||||
{
|
{
|
||||||
if(m_Core.m_HookedPlayer != -1 && GameServer()->m_apPlayers[m_Core.m_HookedPlayer]->GetTeam() != TEAM_SPECTATORS)
|
const int HookedPlayer = m_Core.HookedPlayer();
|
||||||
|
if(HookedPlayer != -1 && GameServer()->m_apPlayers[HookedPlayer]->GetTeam() != TEAM_SPECTATORS)
|
||||||
{
|
{
|
||||||
Antibot()->OnHookAttach(m_pPlayer->GetCID(), true);
|
Antibot()->OnHookAttach(m_pPlayer->GetCID(), true);
|
||||||
}
|
}
|
||||||
|
@ -1138,7 +1139,7 @@ bool CCharacter::IsSnappingCharacterInView(int SnappingClientID)
|
||||||
for(const auto &AttachedPlayerID : m_Core.m_AttachedPlayers)
|
for(const auto &AttachedPlayerID : m_Core.m_AttachedPlayers)
|
||||||
{
|
{
|
||||||
CCharacter *pOtherPlayer = GameServer()->GetPlayerChar(AttachedPlayerID);
|
CCharacter *pOtherPlayer = GameServer()->GetPlayerChar(AttachedPlayerID);
|
||||||
if(pOtherPlayer && pOtherPlayer->m_Core.m_HookedPlayer == ID)
|
if(pOtherPlayer && pOtherPlayer->m_Core.HookedPlayer() == ID)
|
||||||
{
|
{
|
||||||
if(!NetworkClippedLine(SnappingClientID, m_Pos, pOtherPlayer->m_Pos))
|
if(!NetworkClippedLine(SnappingClientID, m_Pos, pOtherPlayer->m_Pos))
|
||||||
{
|
{
|
||||||
|
@ -1183,9 +1184,9 @@ void CCharacter::Snap(int SnappingClient)
|
||||||
pDDNetCharacter->m_Flags |= CHARACTERFLAG_SUPER;
|
pDDNetCharacter->m_Flags |= CHARACTERFLAG_SUPER;
|
||||||
if(m_Core.m_EndlessHook)
|
if(m_Core.m_EndlessHook)
|
||||||
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_HOOK;
|
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_HOOK;
|
||||||
if(m_Core.m_CollisionDisabled || !GameServer()->Tuning()->m_PlayerCollision)
|
if(m_Core.m_CollisionDisabled || !Tuning()->m_PlayerCollision)
|
||||||
pDDNetCharacter->m_Flags |= CHARACTERFLAG_COLLISION_DISABLED;
|
pDDNetCharacter->m_Flags |= CHARACTERFLAG_COLLISION_DISABLED;
|
||||||
if(m_Core.m_HookHitDisabled || !GameServer()->Tuning()->m_PlayerHooking)
|
if(m_Core.m_HookHitDisabled || !Tuning()->m_PlayerHooking)
|
||||||
pDDNetCharacter->m_Flags |= CHARACTERFLAG_HOOK_HIT_DISABLED;
|
pDDNetCharacter->m_Flags |= CHARACTERFLAG_HOOK_HIT_DISABLED;
|
||||||
if(m_Core.m_EndlessJump)
|
if(m_Core.m_EndlessJump)
|
||||||
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_JUMP;
|
pDDNetCharacter->m_Flags |= CHARACTERFLAG_ENDLESS_JUMP;
|
||||||
|
@ -1261,7 +1262,7 @@ void CCharacter::SetTeleports(std::map<int, std::vector<vec2>> *pTeleOuts, std::
|
||||||
{
|
{
|
||||||
m_pTeleOuts = pTeleOuts;
|
m_pTeleOuts = pTeleOuts;
|
||||||
m_pTeleCheckOuts = pTeleCheckOuts;
|
m_pTeleCheckOuts = pTeleCheckOuts;
|
||||||
m_Core.m_pTeleOuts = pTeleOuts;
|
m_Core.SetTeleOuts(pTeleOuts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCharacter::FillAntibot(CAntibotCharacterData *pData)
|
void CCharacter::FillAntibot(CAntibotCharacterData *pData)
|
||||||
|
@ -1269,7 +1270,7 @@ void CCharacter::FillAntibot(CAntibotCharacterData *pData)
|
||||||
pData->m_Pos = m_Pos;
|
pData->m_Pos = m_Pos;
|
||||||
pData->m_Vel = m_Core.m_Vel;
|
pData->m_Vel = m_Core.m_Vel;
|
||||||
pData->m_Angle = m_Core.m_Angle;
|
pData->m_Angle = m_Core.m_Angle;
|
||||||
pData->m_HookedPlayer = m_Core.m_HookedPlayer;
|
pData->m_HookedPlayer = m_Core.HookedPlayer();
|
||||||
pData->m_SpawnTick = m_SpawnTick;
|
pData->m_SpawnTick = m_SpawnTick;
|
||||||
pData->m_WeaponChangeTick = m_WeaponChangeTick;
|
pData->m_WeaponChangeTick = m_WeaponChangeTick;
|
||||||
pData->m_aLatestInputs[0].m_TargetX = m_LatestInput.m_TargetX;
|
pData->m_aLatestInputs[0].m_TargetX = m_LatestInput.m_TargetX;
|
||||||
|
@ -1802,7 +1803,7 @@ void CCharacter::HandleTiles(int Index)
|
||||||
{
|
{
|
||||||
if(m_Core.m_Super)
|
if(m_Core.m_Super)
|
||||||
return;
|
return;
|
||||||
int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleOuts)[z - 1].size());
|
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[z - 1].size());
|
||||||
m_Core.m_Pos = (*m_pTeleOuts)[z - 1][TeleOut];
|
m_Core.m_Pos = (*m_pTeleOuts)[z - 1][TeleOut];
|
||||||
if(!g_Config.m_SvTeleportHoldHook)
|
if(!g_Config.m_SvTeleportHoldHook)
|
||||||
{
|
{
|
||||||
|
@ -1817,7 +1818,7 @@ void CCharacter::HandleTiles(int Index)
|
||||||
{
|
{
|
||||||
if(m_Core.m_Super)
|
if(m_Core.m_Super)
|
||||||
return;
|
return;
|
||||||
int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleOuts)[evilz - 1].size());
|
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleOuts)[evilz - 1].size());
|
||||||
m_Core.m_Pos = (*m_pTeleOuts)[evilz - 1][TeleOut];
|
m_Core.m_Pos = (*m_pTeleOuts)[evilz - 1][TeleOut];
|
||||||
if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons)
|
if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons)
|
||||||
{
|
{
|
||||||
|
@ -1844,7 +1845,7 @@ void CCharacter::HandleTiles(int Index)
|
||||||
{
|
{
|
||||||
if(!(*m_pTeleCheckOuts)[k].empty())
|
if(!(*m_pTeleCheckOuts)[k].empty())
|
||||||
{
|
{
|
||||||
int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleCheckOuts)[k].size());
|
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleCheckOuts)[k].size());
|
||||||
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];
|
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];
|
||||||
m_Core.m_Vel = vec2(0, 0);
|
m_Core.m_Vel = vec2(0, 0);
|
||||||
|
|
||||||
|
@ -1881,7 +1882,7 @@ void CCharacter::HandleTiles(int Index)
|
||||||
{
|
{
|
||||||
if(!(*m_pTeleCheckOuts)[k].empty())
|
if(!(*m_pTeleCheckOuts)[k].empty())
|
||||||
{
|
{
|
||||||
int TeleOut = m_Core.m_pWorld->RandomOr0((*m_pTeleCheckOuts)[k].size());
|
int TeleOut = GameWorld()->m_Core.RandomOr0((*m_pTeleCheckOuts)[k].size());
|
||||||
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];
|
m_Core.m_Pos = (*m_pTeleCheckOuts)[k][TeleOut];
|
||||||
|
|
||||||
if(!g_Config.m_SvTeleportHoldHook)
|
if(!g_Config.m_SvTeleportHoldHook)
|
||||||
|
@ -1914,9 +1915,9 @@ void CCharacter::HandleTuneLayer()
|
||||||
m_TuneZone = Collision()->IsTune(CurrentIndex);
|
m_TuneZone = Collision()->IsTune(CurrentIndex);
|
||||||
|
|
||||||
if(m_TuneZone)
|
if(m_TuneZone)
|
||||||
m_Core.m_Tuning = GameServer()->TuningList()[m_TuneZone]; // throw tunings from specific zone into gamecore
|
m_Core.m_Tuning = TuningList()[m_TuneZone]; // throw tunings from specific zone into gamecore
|
||||||
else
|
else
|
||||||
m_Core.m_Tuning = *GameServer()->Tuning();
|
m_Core.m_Tuning = *Tuning();
|
||||||
|
|
||||||
if(m_TuneZone != m_TuneZoneOld) // don't send tunigs all the time
|
if(m_TuneZone != m_TuneZoneOld) // don't send tunigs all the time
|
||||||
{
|
{
|
||||||
|
@ -2229,7 +2230,7 @@ void CCharacter::Pause(bool Pause)
|
||||||
GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = 0;
|
GameServer()->m_World.m_Core.m_apCharacters[m_pPlayer->GetCID()] = 0;
|
||||||
GameServer()->m_World.RemoveEntity(this);
|
GameServer()->m_World.RemoveEntity(this);
|
||||||
|
|
||||||
if(m_Core.m_HookedPlayer != -1) // Keeping hook would allow cheats
|
if(m_Core.HookedPlayer() != -1) // Keeping hook would allow cheats
|
||||||
{
|
{
|
||||||
ResetHook();
|
ResetHook();
|
||||||
GameWorld()->ReleaseHooked(GetPlayer()->GetCID());
|
GameWorld()->ReleaseHooked(GetPlayer()->GetCID());
|
||||||
|
@ -2332,5 +2333,6 @@ CClientMask CCharacter::TeamMask()
|
||||||
|
|
||||||
void CCharacter::SwapClients(int Client1, int Client2)
|
void CCharacter::SwapClients(int Client1, int Client2)
|
||||||
{
|
{
|
||||||
m_Core.SetHookedPlayer(m_Core.m_HookedPlayer == Client1 ? Client2 : m_Core.m_HookedPlayer == Client2 ? Client1 : m_Core.m_HookedPlayer);
|
const int HookedPlayer = m_Core.HookedPlayer();
|
||||||
|
m_Core.SetHookedPlayer(HookedPlayer == Client1 ? Client2 : HookedPlayer == Client2 ? Client1 : HookedPlayer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,9 +58,9 @@ bool CLaser::HitCharacter(vec2 From, vec2 To)
|
||||||
|
|
||||||
float Strength;
|
float Strength;
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
Strength = GameServer()->Tuning()->m_ShotgunStrength;
|
Strength = Tuning()->m_ShotgunStrength;
|
||||||
else
|
else
|
||||||
Strength = GameServer()->TuningList()[m_TuneZone].m_ShotgunStrength;
|
Strength = TuningList()[m_TuneZone].m_ShotgunStrength;
|
||||||
|
|
||||||
vec2 &HitPos = pHit->Core()->m_Pos;
|
vec2 &HitPos = pHit->Core()->m_Pos;
|
||||||
if(!g_Config.m_SvOldLaser)
|
if(!g_Config.m_SvOldLaser)
|
||||||
|
@ -158,7 +158,7 @@ void CLaser::DoBounce()
|
||||||
}
|
}
|
||||||
else if(!m_TuneZone)
|
else if(!m_TuneZone)
|
||||||
{
|
{
|
||||||
m_Energy -= Distance + GameServer()->Tuning()->m_LaserBounceCost;
|
m_Energy -= Distance + Tuning()->m_LaserBounceCost;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -179,9 +179,9 @@ void CLaser::DoBounce()
|
||||||
m_WasTele = false;
|
m_WasTele = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BounceNum = GameServer()->Tuning()->m_LaserBounceNum;
|
int BounceNum = Tuning()->m_LaserBounceNum;
|
||||||
if(m_TuneZone)
|
if(m_TuneZone)
|
||||||
BounceNum = GameServer()->TuningList()[m_TuneZone].m_LaserBounceNum;
|
BounceNum = TuningList()[m_TuneZone].m_LaserBounceNum;
|
||||||
|
|
||||||
if(m_Bounces > BounceNum)
|
if(m_Bounces > BounceNum)
|
||||||
m_Energy = -1;
|
m_Energy = -1;
|
||||||
|
@ -279,9 +279,9 @@ void CLaser::Tick()
|
||||||
|
|
||||||
float Delay;
|
float Delay;
|
||||||
if(m_TuneZone)
|
if(m_TuneZone)
|
||||||
Delay = GameServer()->TuningList()[m_TuneZone].m_LaserBounceDelay;
|
Delay = TuningList()[m_TuneZone].m_LaserBounceDelay;
|
||||||
else
|
else
|
||||||
Delay = GameServer()->Tuning()->m_LaserBounceDelay;
|
Delay = Tuning()->m_LaserBounceDelay;
|
||||||
|
|
||||||
if((Server()->Tick() - m_EvalTick) > (Server()->TickSpeed() * Delay / 1000.0f))
|
if((Server()->Tick() - m_EvalTick) > (Server()->TickSpeed() * Delay / 1000.0f))
|
||||||
DoBounce();
|
DoBounce();
|
||||||
|
|
|
@ -64,13 +64,13 @@ vec2 CProjectile::GetPos(float Time)
|
||||||
case WEAPON_GRENADE:
|
case WEAPON_GRENADE:
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
{
|
{
|
||||||
Curvature = GameServer()->Tuning()->m_GrenadeCurvature;
|
Curvature = Tuning()->m_GrenadeCurvature;
|
||||||
Speed = GameServer()->Tuning()->m_GrenadeSpeed;
|
Speed = Tuning()->m_GrenadeSpeed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Curvature = GameServer()->TuningList()[m_TuneZone].m_GrenadeCurvature;
|
Curvature = TuningList()[m_TuneZone].m_GrenadeCurvature;
|
||||||
Speed = GameServer()->TuningList()[m_TuneZone].m_GrenadeSpeed;
|
Speed = TuningList()[m_TuneZone].m_GrenadeSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -78,13 +78,13 @@ vec2 CProjectile::GetPos(float Time)
|
||||||
case WEAPON_SHOTGUN:
|
case WEAPON_SHOTGUN:
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
{
|
{
|
||||||
Curvature = GameServer()->Tuning()->m_ShotgunCurvature;
|
Curvature = Tuning()->m_ShotgunCurvature;
|
||||||
Speed = GameServer()->Tuning()->m_ShotgunSpeed;
|
Speed = Tuning()->m_ShotgunSpeed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Curvature = GameServer()->TuningList()[m_TuneZone].m_ShotgunCurvature;
|
Curvature = TuningList()[m_TuneZone].m_ShotgunCurvature;
|
||||||
Speed = GameServer()->TuningList()[m_TuneZone].m_ShotgunSpeed;
|
Speed = TuningList()[m_TuneZone].m_ShotgunSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -92,13 +92,13 @@ vec2 CProjectile::GetPos(float Time)
|
||||||
case WEAPON_GUN:
|
case WEAPON_GUN:
|
||||||
if(!m_TuneZone)
|
if(!m_TuneZone)
|
||||||
{
|
{
|
||||||
Curvature = GameServer()->Tuning()->m_GunCurvature;
|
Curvature = Tuning()->m_GunCurvature;
|
||||||
Speed = GameServer()->Tuning()->m_GunSpeed;
|
Speed = Tuning()->m_GunSpeed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Curvature = GameServer()->TuningList()[m_TuneZone].m_GunCurvature;
|
Curvature = TuningList()[m_TuneZone].m_GunCurvature;
|
||||||
Speed = GameServer()->TuningList()[m_TuneZone].m_GunSpeed;
|
Speed = TuningList()[m_TuneZone].m_GunSpeed;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
|
|
||||||
#include <base/vmath.h>
|
#include <base/vmath.h>
|
||||||
|
|
||||||
#include "alloc.h"
|
#include <game/alloc.h>
|
||||||
|
|
||||||
#include "gameworld.h"
|
#include "gameworld.h"
|
||||||
|
|
||||||
class CCollision;
|
class CCollision;
|
||||||
|
@ -60,6 +61,9 @@ public: // TODO: Maybe make protected
|
||||||
/* Objects */
|
/* Objects */
|
||||||
std::vector<SSwitchers> &Switchers() { return m_pGameWorld->m_Core.m_vSwitchers; }
|
std::vector<SSwitchers> &Switchers() { return m_pGameWorld->m_Core.m_vSwitchers; }
|
||||||
CGameWorld *GameWorld() { return m_pGameWorld; }
|
CGameWorld *GameWorld() { return m_pGameWorld; }
|
||||||
|
CTuningParams *Tuning() { return GameWorld()->Tuning(); }
|
||||||
|
CTuningParams *TuningList() { return GameWorld()->TuningList(); }
|
||||||
|
CTuningParams *GetTuning(int i) { return GameWorld()->GetTuning(i); }
|
||||||
class CConfig *Config() { return m_pGameWorld->Config(); }
|
class CConfig *Config() { return m_pGameWorld->Config(); }
|
||||||
class CGameContext *GameServer() { return m_pGameWorld->GameServer(); }
|
class CGameContext *GameServer() { return m_pGameWorld->GameServer(); }
|
||||||
class IServer *Server() { return m_pGameWorld->Server(); }
|
class IServer *Server() { return m_pGameWorld->Server(); }
|
||||||
|
|
|
@ -947,6 +947,8 @@ void CGameContext::OnTick()
|
||||||
m_World.m_Core.m_aTuning[0] = m_Tuning;
|
m_World.m_Core.m_aTuning[0] = m_Tuning;
|
||||||
m_World.Tick();
|
m_World.Tick();
|
||||||
|
|
||||||
|
UpdatePlayerMaps();
|
||||||
|
|
||||||
//if(world.paused) // make sure that the game object always updates
|
//if(world.paused) // make sure that the game object always updates
|
||||||
m_pController->Tick();
|
m_pController->Tick();
|
||||||
|
|
||||||
|
@ -3478,6 +3480,7 @@ void CGameContext::OnInit(const void *pPersistentData)
|
||||||
|
|
||||||
m_Layers.Init(Kernel());
|
m_Layers.Init(Kernel());
|
||||||
m_Collision.Init(&m_Layers);
|
m_Collision.Init(&m_Layers);
|
||||||
|
m_World.m_pTuningList = m_aTuningList;
|
||||||
m_World.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
m_World.m_Core.InitSwitchers(m_Collision.m_HighestSwitchNumber);
|
||||||
|
|
||||||
char aMapName[IO_MAX_PATH_LENGTH];
|
char aMapName[IO_MAX_PATH_LENGTH];
|
||||||
|
@ -4010,6 +4013,67 @@ void CGameContext::OnPostSnap()
|
||||||
m_Events.Clear();
|
m_Events.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGameContext::UpdatePlayerMaps()
|
||||||
|
{
|
||||||
|
const auto DistCompare = [](std::pair<float, int> a, std::pair<float, int> b) -> bool {
|
||||||
|
return (a.first < b.first);
|
||||||
|
};
|
||||||
|
|
||||||
|
if(Server()->Tick() % g_Config.m_SvMapUpdateRate != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::pair<float, int> Dist[MAX_CLIENTS];
|
||||||
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||||
|
{
|
||||||
|
if(!Server()->ClientIngame(i))
|
||||||
|
continue;
|
||||||
|
if(Server()->GetClientVersion(i) >= VERSION_DDNET_OLD)
|
||||||
|
continue;
|
||||||
|
int *pMap = Server()->GetIdMap(i);
|
||||||
|
|
||||||
|
// compute distances
|
||||||
|
for(int j = 0; j < MAX_CLIENTS; j++)
|
||||||
|
{
|
||||||
|
Dist[j].second = j;
|
||||||
|
if(j == i)
|
||||||
|
continue;
|
||||||
|
if(!Server()->ClientIngame(j) || !m_apPlayers[j])
|
||||||
|
{
|
||||||
|
Dist[j].first = 1e10;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
CCharacter *pChr = m_apPlayers[j]->GetCharacter();
|
||||||
|
if(!pChr)
|
||||||
|
{
|
||||||
|
Dist[j].first = 1e9;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!pChr->CanSnapCharacter(i))
|
||||||
|
Dist[j].first = 1e8;
|
||||||
|
else
|
||||||
|
Dist[j].first = length_squared(m_apPlayers[i]->m_ViewPos - pChr->GetPos());
|
||||||
|
}
|
||||||
|
|
||||||
|
// always send the player themselves, even if all in same position
|
||||||
|
Dist[i].first = -1;
|
||||||
|
|
||||||
|
std::nth_element(&Dist[0], &Dist[VANILLA_MAX_CLIENTS - 1], &Dist[MAX_CLIENTS], DistCompare);
|
||||||
|
|
||||||
|
int Index = 1; // exclude self client id
|
||||||
|
for(int j = 0; j < VANILLA_MAX_CLIENTS - 1; j++)
|
||||||
|
{
|
||||||
|
pMap[j + 1] = -1; // also fill player with empty name to say chat msgs
|
||||||
|
if(Dist[j].second == i || Dist[j].first > 5e9f)
|
||||||
|
continue;
|
||||||
|
pMap[Index++] = Dist[j].second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort by real client ids, guarantee order on distance changes, O(Nlog(N)) worst case
|
||||||
|
// sort just clients in game always except first (self client id) and last (fake client id) indexes
|
||||||
|
std::sort(&pMap[1], &pMap[minimum(Index, VANILLA_MAX_CLIENTS - 1)]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool CGameContext::IsClientReady(int ClientID) const
|
bool CGameContext::IsClientReady(int ClientID) const
|
||||||
{
|
{
|
||||||
return m_apPlayers[ClientID] && m_apPlayers[ClientID]->m_IsReady;
|
return m_apPlayers[ClientID] && m_apPlayers[ClientID]->m_IsReady;
|
||||||
|
|
|
@ -285,6 +285,8 @@ public:
|
||||||
void OnSnap(int ClientID) override;
|
void OnSnap(int ClientID) override;
|
||||||
void OnPostSnap() override;
|
void OnPostSnap() override;
|
||||||
|
|
||||||
|
void UpdatePlayerMaps();
|
||||||
|
|
||||||
void *PreProcessMsg(int *pMsgID, CUnpacker *pUnpacker, int ClientID);
|
void *PreProcessMsg(int *pMsgID, CUnpacker *pUnpacker, int ClientID);
|
||||||
void CensorMessage(char *pCensoredMessage, const char *pMessage, int Size);
|
void CensorMessage(char *pCensoredMessage, const char *pMessage, int Size);
|
||||||
void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) override;
|
void OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) override;
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "entity.h"
|
#include "entity.h"
|
||||||
#include "gamecontext.h"
|
#include "gamecontext.h"
|
||||||
#include "gamecontroller.h"
|
#include "gamecontroller.h"
|
||||||
#include "player.h"
|
|
||||||
|
|
||||||
#include <engine/shared/config.h>
|
#include <engine/shared/config.h>
|
||||||
|
|
||||||
|
@ -192,68 +191,6 @@ void CGameWorld::RemoveEntities()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool distCompare(std::pair<float, int> a, std::pair<float, int> b)
|
|
||||||
{
|
|
||||||
return (a.first < b.first);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGameWorld::UpdatePlayerMaps()
|
|
||||||
{
|
|
||||||
if(Server()->Tick() % g_Config.m_SvMapUpdateRate != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
std::pair<float, int> Dist[MAX_CLIENTS];
|
|
||||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
|
||||||
{
|
|
||||||
if(!Server()->ClientIngame(i))
|
|
||||||
continue;
|
|
||||||
if(Server()->GetClientVersion(i) >= VERSION_DDNET_OLD)
|
|
||||||
continue;
|
|
||||||
int *pMap = Server()->GetIdMap(i);
|
|
||||||
|
|
||||||
// compute distances
|
|
||||||
for(int j = 0; j < MAX_CLIENTS; j++)
|
|
||||||
{
|
|
||||||
Dist[j].second = j;
|
|
||||||
if(j == i)
|
|
||||||
continue;
|
|
||||||
if(!Server()->ClientIngame(j) || !GameServer()->m_apPlayers[j])
|
|
||||||
{
|
|
||||||
Dist[j].first = 1e10;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
CCharacter *pChr = GameServer()->m_apPlayers[j]->GetCharacter();
|
|
||||||
if(!pChr)
|
|
||||||
{
|
|
||||||
Dist[j].first = 1e9;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if(!pChr->CanSnapCharacter(i))
|
|
||||||
Dist[j].first = 1e8;
|
|
||||||
else
|
|
||||||
Dist[j].first = length_squared(GameServer()->m_apPlayers[i]->m_ViewPos - pChr->m_Pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// always send the player themselves, even if all in same position
|
|
||||||
Dist[i].first = -1;
|
|
||||||
|
|
||||||
std::nth_element(&Dist[0], &Dist[VANILLA_MAX_CLIENTS - 1], &Dist[MAX_CLIENTS], distCompare);
|
|
||||||
|
|
||||||
int Index = 1; // exclude self client id
|
|
||||||
for(int j = 0; j < VANILLA_MAX_CLIENTS - 1; j++)
|
|
||||||
{
|
|
||||||
pMap[j + 1] = -1; // also fill player with empty name to say chat msgs
|
|
||||||
if(Dist[j].second == i || Dist[j].first > 5e9f)
|
|
||||||
continue;
|
|
||||||
pMap[Index++] = Dist[j].second;
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort by real client ids, guarantee order on distance changes, O(Nlog(N)) worst case
|
|
||||||
// sort just clients in game always except first (self client id) and last (fake client id) indexes
|
|
||||||
std::sort(&pMap[1], &pMap[minimum(Index, VANILLA_MAX_CLIENTS - 1)]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CGameWorld::Tick()
|
void CGameWorld::Tick()
|
||||||
{
|
{
|
||||||
if(m_ResetRequested)
|
if(m_ResetRequested)
|
||||||
|
@ -311,8 +248,6 @@ void CGameWorld::Tick()
|
||||||
|
|
||||||
RemoveEntities();
|
RemoveEntities();
|
||||||
|
|
||||||
UpdatePlayerMaps();
|
|
||||||
|
|
||||||
// find the characters' strong/weak id
|
// find the characters' strong/weak id
|
||||||
int StrongWeakID = 0;
|
int StrongWeakID = 0;
|
||||||
for(CCharacter *pChar = (CCharacter *)FindFirst(ENTTYPE_CHARACTER); pChar; pChar = (CCharacter *)pChar->TypeNext())
|
for(CCharacter *pChar = (CCharacter *)FindFirst(ENTTYPE_CHARACTER); pChar; pChar = (CCharacter *)pChar->TypeNext())
|
||||||
|
@ -428,7 +363,7 @@ void CGameWorld::ReleaseHooked(int ClientID)
|
||||||
for(; pChr; pChr = (CCharacter *)pChr->TypeNext())
|
for(; pChr; pChr = (CCharacter *)pChr->TypeNext())
|
||||||
{
|
{
|
||||||
CCharacterCore *pCore = pChr->Core();
|
CCharacterCore *pCore = pChr->Core();
|
||||||
if(pCore->m_HookedPlayer == ClientID && !pChr->IsSuper())
|
if(pCore->HookedPlayer() == ClientID && !pChr->IsSuper())
|
||||||
{
|
{
|
||||||
pCore->SetHookedPlayer(-1);
|
pCore->SetHookedPlayer(-1);
|
||||||
pCore->m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
|
pCore->m_TriggeredEvents |= COREEVENT_HOOK_RETRACT;
|
||||||
|
@ -436,3 +371,8 @@ void CGameWorld::ReleaseHooked(int ClientID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CTuningParams *CGameWorld::Tuning()
|
||||||
|
{
|
||||||
|
return &m_Core.m_aTuning[0];
|
||||||
|
}
|
||||||
|
|
|
@ -39,8 +39,6 @@ private:
|
||||||
class CConfig *m_pConfig;
|
class CConfig *m_pConfig;
|
||||||
class IServer *m_pServer;
|
class IServer *m_pServer;
|
||||||
|
|
||||||
void UpdatePlayerMaps();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class CGameContext *GameServer() { return m_pGameServer; }
|
class CGameContext *GameServer() { return m_pGameServer; }
|
||||||
class CConfig *Config() { return m_pConfig; }
|
class CConfig *Config() { return m_pConfig; }
|
||||||
|
@ -166,6 +164,12 @@ public:
|
||||||
Returns list with all Characters on line.
|
Returns list with all Characters on line.
|
||||||
*/
|
*/
|
||||||
std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
|
std::vector<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
|
||||||
|
|
||||||
|
CTuningParams *Tuning();
|
||||||
|
|
||||||
|
CTuningParams *m_pTuningList;
|
||||||
|
CTuningParams *TuningList() { return m_pTuningList; }
|
||||||
|
CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
#include <engine/shared/protocol.h>
|
#include <engine/shared/protocol.h>
|
||||||
|
|
||||||
#include "alloc.h"
|
#include <game/alloc.h>
|
||||||
|
|
||||||
#include "teeinfo.h"
|
#include "teeinfo.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
|
@ -100,7 +100,7 @@ void CSaveTee::Save(CCharacter *pChr)
|
||||||
m_HookTick = pChr->m_Core.m_HookTick;
|
m_HookTick = pChr->m_Core.m_HookTick;
|
||||||
|
|
||||||
m_HookState = pChr->m_Core.m_HookState;
|
m_HookState = pChr->m_Core.m_HookState;
|
||||||
m_HookedPlayer = pChr->m_Core.m_HookedPlayer;
|
m_HookedPlayer = pChr->m_Core.HookedPlayer();
|
||||||
m_NewHook = pChr->m_Core.m_NewHook != 0;
|
m_NewHook = pChr->m_Core.m_NewHook != 0;
|
||||||
|
|
||||||
m_InputDirection = pChr->m_SavedInput.m_Direction;
|
m_InputDirection = pChr->m_SavedInput.m_Direction;
|
||||||
|
|
Loading…
Reference in a new issue