mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Keep ticks going
This commit is contained in:
parent
5e02bb5a23
commit
eacc56059b
|
@ -1,6 +1,7 @@
|
|||
#ifndef ANTIBOT_ANTIBOT_DATA_H
|
||||
#define ANTIBOT_ANTIBOT_DATA_H
|
||||
|
||||
#include <base/system.h>
|
||||
#include <base/vmath.h>
|
||||
|
||||
enum
|
||||
|
@ -49,8 +50,10 @@ struct CAntibotCharacterData
|
|||
int m_WeaponChangeTick;
|
||||
};
|
||||
|
||||
struct CAntibotCallbackData
|
||||
struct CAntibotData
|
||||
{
|
||||
int64 m_Now;
|
||||
int64 m_Freq;
|
||||
void (*m_pfnLog)(const char *pMessage, void *pUser);
|
||||
void (*m_pfnReport)(int ClientID, const char *pMessage, void *pUser);
|
||||
void (*m_pfnSend)(int ClientID, const void *pData, int DataSize, int Flags, void *pUser);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
extern "C"
|
||||
{
|
||||
|
||||
void AntibotInit(CAntibotCallbackData *pCallbackData);
|
||||
void AntibotInit(CAntibotData *pCallbackData);
|
||||
void AntibotRoundStart(CAntibotRoundData *pRoundData);
|
||||
void AntibotRoundEnd(void);
|
||||
void AntibotUpdateData(void);
|
||||
|
@ -18,8 +18,9 @@ void AntibotOnHammerFireReloading(int ClientID);
|
|||
void AntibotOnHammerFire(int ClientID);
|
||||
void AntibotOnHammerHit(int ClientID);
|
||||
void AntibotOnDirectInput(int ClientID);
|
||||
void AntibotOnTick(int ClientID);
|
||||
void AntibotOnCharacterTick(int ClientID);
|
||||
void AntibotOnHookAttach(int ClientID, bool Player);
|
||||
void AntibotOnEngineTick(void);
|
||||
void AntibotOnEngineClientJoin(int ClientID);
|
||||
void AntibotOnEngineClientDrop(int ClientID, const char *pReason);
|
||||
void AntibotOnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
|
|
|
@ -1,27 +1,27 @@
|
|||
#include "antibot_data.h"
|
||||
|
||||
static CAntibotCallbackData *g_pCallbacks;
|
||||
static CAntibotData *g_pData;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void AntibotInit(CAntibotCallbackData *pData)
|
||||
void AntibotInit(CAntibotData *pData)
|
||||
{
|
||||
g_pCallbacks = pData;
|
||||
if(g_pCallbacks->m_pfnLog)
|
||||
g_pData = pData;
|
||||
if(g_pData->m_pfnLog)
|
||||
{
|
||||
g_pCallbacks->m_pfnLog("null antibot initialized", g_pCallbacks->m_pUser);
|
||||
g_pData->m_pfnLog("null antibot initialized", g_pData->m_pUser);
|
||||
}
|
||||
}
|
||||
void AntibotRoundStart(CAntibotRoundData *pRoundData) { };
|
||||
void AntibotRoundEnd(void) { };
|
||||
void AntibotUpdateData(void) { }
|
||||
void AntibotDestroy(void) { g_pCallbacks = 0; }
|
||||
void AntibotDestroy(void) { g_pData = 0; }
|
||||
void AntibotDump(void)
|
||||
{
|
||||
if(g_pCallbacks->m_pfnLog)
|
||||
if(g_pData->m_pfnLog)
|
||||
{
|
||||
g_pCallbacks->m_pfnLog("null antibot", g_pCallbacks->m_pUser);
|
||||
g_pData->m_pfnLog("null antibot", g_pData->m_pUser);
|
||||
}
|
||||
}
|
||||
void AntibotOnPlayerInit(int ClientID) { (void)ClientID; }
|
||||
|
@ -31,8 +31,9 @@ void AntibotOnHammerFireReloading(int ClientID) { (void)ClientID; }
|
|||
void AntibotOnHammerFire(int ClientID) { (void)ClientID; }
|
||||
void AntibotOnHammerHit(int ClientID) { (void)ClientID; }
|
||||
void AntibotOnDirectInput(int ClientID) { (void)ClientID; }
|
||||
void AntibotOnTick(int ClientID) { (void)ClientID; }
|
||||
void AntibotOnCharacterTick(int ClientID) { (void)ClientID; }
|
||||
void AntibotOnHookAttach(int ClientID, bool Player) { (void)ClientID; (void)Player; }
|
||||
void AntibotOnEngineTick(void) { }
|
||||
void AntibotOnEngineClientJoin(int ClientID) { (void)ClientID; }
|
||||
void AntibotOnEngineClientDrop(int ClientID, const char *pReason) { (void)ClientID; (void)pReason; }
|
||||
void AntibotOnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) { (void)ClientID; (void)pData; (void)Size; (void)Flags; }
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
virtual void OnHammerFire(int ClientID) = 0;
|
||||
virtual void OnHammerHit(int ClientID) = 0;
|
||||
virtual void OnDirectInput(int ClientID) = 0;
|
||||
virtual void OnTick(int ClientID) = 0;
|
||||
virtual void OnCharacterTick(int ClientID) = 0;
|
||||
virtual void OnHookAttach(int ClientID, bool Player) = 0;
|
||||
|
||||
// Commands
|
||||
|
@ -34,6 +34,7 @@ public:
|
|||
virtual void Init() = 0;
|
||||
|
||||
// Hooks
|
||||
virtual void OnEngineTick() = 0;
|
||||
virtual void OnEngineClientJoin(int ClientID) = 0;
|
||||
virtual void OnEngineClientDrop(int ClientID, const char *pReason) = 0;
|
||||
virtual void OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) = 0;
|
||||
|
|
|
@ -49,12 +49,14 @@ void CAntibot::Init()
|
|||
m_pConsole = Kernel()->RequestInterface<IConsole>();
|
||||
dbg_assert(m_pServer && m_pConsole, "antibot requires server and console");
|
||||
|
||||
mem_zero(&m_CallbackData, sizeof(m_CallbackData));
|
||||
m_CallbackData.m_pfnLog = Log;
|
||||
m_CallbackData.m_pfnReport = Report;
|
||||
m_CallbackData.m_pfnSend = Send;
|
||||
m_CallbackData.m_pUser = this;
|
||||
AntibotInit(&m_CallbackData);
|
||||
mem_zero(&m_Data, sizeof(m_Data));
|
||||
m_Data.m_Now = time_get();
|
||||
m_Data.m_Freq = time_freq();
|
||||
m_Data.m_pfnLog = Log;
|
||||
m_Data.m_pfnReport = Report;
|
||||
m_Data.m_pfnSend = Send;
|
||||
m_Data.m_pUser = this;
|
||||
AntibotInit(&m_Data);
|
||||
}
|
||||
void CAntibot::RoundStart(IGameServer *pGameServer)
|
||||
{
|
||||
|
@ -76,6 +78,8 @@ void CAntibot::RoundEnd()
|
|||
void CAntibot::Dump() { AntibotDump(); }
|
||||
void CAntibot::Update()
|
||||
{
|
||||
m_Data.m_Now = time_get();
|
||||
m_Data.m_Freq = time_freq();
|
||||
GameServer()->FillAntibot(&m_RoundData);
|
||||
AntibotUpdateData();
|
||||
}
|
||||
|
@ -87,9 +91,10 @@ void CAntibot::OnHammerFireReloading(int ClientID) { Update(); AntibotOnHammerFi
|
|||
void CAntibot::OnHammerFire(int ClientID) { Update(); AntibotOnHammerFire(ClientID); }
|
||||
void CAntibot::OnHammerHit(int ClientID) { Update(); AntibotOnHammerHit(ClientID); }
|
||||
void CAntibot::OnDirectInput(int ClientID) { Update(); AntibotOnDirectInput(ClientID); }
|
||||
void CAntibot::OnTick(int ClientID) { Update(); AntibotOnTick(ClientID); }
|
||||
void CAntibot::OnCharacterTick(int ClientID) { Update(); AntibotOnCharacterTick(ClientID); }
|
||||
void CAntibot::OnHookAttach(int ClientID, bool Player) { Update(); AntibotOnHookAttach(ClientID, Player); }
|
||||
|
||||
void CAntibot::OnEngineTick() { Update(); AntibotOnEngineTick(); }
|
||||
void CAntibot::OnEngineClientJoin(int ClientID) { AntibotOnEngineClientJoin(ClientID); }
|
||||
void CAntibot::OnEngineClientDrop(int ClientID, const char *pReason) { AntibotOnEngineClientDrop(ClientID, pReason); }
|
||||
void CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags)
|
||||
|
@ -138,9 +143,10 @@ void CAntibot::OnHammerFireReloading(int ClientID) { }
|
|||
void CAntibot::OnHammerFire(int ClientID) { }
|
||||
void CAntibot::OnHammerHit(int ClientID) { }
|
||||
void CAntibot::OnDirectInput(int ClientID) { }
|
||||
void CAntibot::OnTick(int ClientID) { }
|
||||
void CAntibot::OnCharacterTick(int ClientID) { }
|
||||
void CAntibot::OnHookAttach(int ClientID, bool Player) { }
|
||||
|
||||
void CAntibot::OnEngineTick() { }
|
||||
void CAntibot::OnEngineClientJoin(int ClientID) { }
|
||||
void CAntibot::OnEngineClientDrop(int ClientID, const char *pReason) { }
|
||||
void CAntibot::OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags) { }
|
||||
|
|
|
@ -14,7 +14,7 @@ class CAntibot : public IEngineAntibot
|
|||
class IConsole *Console() const { return m_pConsole; }
|
||||
class IGameServer *GameServer() const { return m_pGameServer; }
|
||||
|
||||
CAntibotCallbackData m_CallbackData;
|
||||
CAntibotData m_Data;
|
||||
CAntibotRoundData m_RoundData;
|
||||
|
||||
void Update();
|
||||
|
@ -28,6 +28,7 @@ public:
|
|||
// Engine
|
||||
virtual void Init();
|
||||
|
||||
virtual void OnEngineTick();
|
||||
virtual void OnEngineClientJoin(int ClientID);
|
||||
virtual void OnEngineClientDrop(int ClientID, const char *pReason);
|
||||
virtual void OnEngineClientMessage(int ClientID, const void *pData, int Size, int Flags);
|
||||
|
@ -43,7 +44,7 @@ public:
|
|||
virtual void OnHammerFire(int ClientID);
|
||||
virtual void OnHammerHit(int ClientID);
|
||||
virtual void OnDirectInput(int ClientID);
|
||||
virtual void OnTick(int ClientID);
|
||||
virtual void OnCharacterTick(int ClientID);
|
||||
virtual void OnHookAttach(int ClientID, bool Player);
|
||||
|
||||
virtual void Dump();
|
||||
|
|
|
@ -758,7 +758,7 @@ void CCharacter::Tick()
|
|||
|
||||
DDRaceTick();
|
||||
|
||||
Antibot()->OnTick(m_pPlayer->GetCID());
|
||||
Antibot()->OnCharacterTick(m_pPlayer->GetCID());
|
||||
|
||||
m_Core.m_Input = m_Input;
|
||||
m_Core.Tick(true);
|
||||
|
|
Loading…
Reference in a new issue