3489: Port some refactor from teeworlds-0.7 r=heinrich5991 a=Kaffeine

Hi, devs.

I'm considering options to rebase another mod on the DDNet code and I found a lot of missing API.
I also think that it would be simpler for you to cherry-pick patches if DDNet will provide and use a similar API.

I ran the client and checked that the configuration save/load works correctly.

Backported changes overview:
- Extract some `CGameContext` code to methods (`SendMotd()`, `SendSettings()`)
- Provide getters for CEntity members and make some of them `private`
- Extract allocation macros from `entity.h` to `alloc.h` (to reduce includes)
- Extract / introduce `CConsole::Init()`
- Introduce CConfig API from commit de5859b371 (the old API is kept and still used in the codebase)

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Alexander Akulich <akulichalexander@gmail.com>
This commit is contained in:
bors[bot] 2021-01-10 14:50:43 +00:00 committed by GitHub
commit c6e2d42624
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
57 changed files with 461 additions and 323 deletions

View file

@ -1941,6 +1941,7 @@ set_src(ENGINE_SERVER GLOB_RECURSE src/engine/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
ddracechat.h ddracechat.h
ddracecommands.cpp ddracecommands.cpp

View file

@ -272,6 +272,8 @@ CClient::CClient() :
m_pSound = 0; m_pSound = 0;
m_pGameClient = 0; m_pGameClient = 0;
m_pMap = 0; m_pMap = 0;
m_pConfigManager = 0;
m_pConfig = 0;
m_pConsole = 0; m_pConsole = 0;
m_RenderFrameTime = 0.0001f; m_RenderFrameTime = 0.0001f;
@ -2961,6 +2963,8 @@ void CClient::InitInterfaces()
m_pInput = Kernel()->RequestInterface<IEngineInput>(); m_pInput = Kernel()->RequestInterface<IEngineInput>();
m_pMap = Kernel()->RequestInterface<IEngineMap>(); m_pMap = Kernel()->RequestInterface<IEngineMap>();
m_pMasterServer = Kernel()->RequestInterface<IEngineMasterServer>(); m_pMasterServer = Kernel()->RequestInterface<IEngineMasterServer>();
m_pConfigManager = Kernel()->RequestInterface<IConfigManager>();
m_pConfig = m_pConfigManager->Values();
#if defined(CONF_AUTOUPDATE) #if defined(CONF_AUTOUPDATE)
m_pUpdater = Kernel()->RequestInterface<IUpdater>(); m_pUpdater = Kernel()->RequestInterface<IUpdater>();
#endif #endif
@ -3338,8 +3342,7 @@ void CClient::Run()
if(!s_SavedConfig) if(!s_SavedConfig)
{ {
// write down the config and quit // write down the config and quit
IConfig *pConfig = Kernel()->RequestInterface<IConfig>(); if(!m_pConfigManager->Save())
if(!pConfig->Save())
m_Warnings.emplace_back(SWarning(Localize("Saving ddnet-settings.cfg failed"))); m_Warnings.emplace_back(SWarning(Localize("Saving ddnet-settings.cfg failed")));
s_SavedConfig = true; s_SavedConfig = true;
} }
@ -4265,7 +4268,7 @@ int main(int argc, const char **argv) // ignore_convention
IEngine *pEngine = CreateEngine("DDNet", Silent, 1); IEngine *pEngine = CreateEngine("DDNet", Silent, 1);
IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT); IConsole *pConsole = CreateConsole(CFGFLAG_CLIENT);
IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_CLIENT, argc, argv); // ignore_convention IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_CLIENT, argc, argv); // ignore_convention
IConfig *pConfig = CreateConfig(); IConfigManager *pConfigManager = CreateConfigManager();
IEngineSound *pEngineSound = CreateEngineSound(); IEngineSound *pEngineSound = CreateEngineSound();
IEngineInput *pEngineInput = CreateEngineInput(); IEngineInput *pEngineInput = CreateEngineInput();
IEngineTextRender *pEngineTextRender = CreateEngineTextRender(); IEngineTextRender *pEngineTextRender = CreateEngineTextRender();
@ -4284,7 +4287,7 @@ int main(int argc, const char **argv) // ignore_convention
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngine); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngine);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfig); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfigManager);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineSound); // IEngineSound RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineSound); // IEngineSound
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<ISound *>(pEngineSound), false); RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<ISound *>(pEngineSound), false);
@ -4316,7 +4319,8 @@ int main(int argc, const char **argv) // ignore_convention
} }
pEngine->Init(); pEngine->Init();
pConfig->Init(); pConfigManager->Init();
pConsole->Init();
pEngineMasterServer->Init(); pEngineMasterServer->Init();
pEngineMasterServer->Load(); pEngineMasterServer->Load();

View file

@ -90,6 +90,8 @@ class CClient : public IClient, public CDemoPlayer::IListener
IEngineSound *m_pSound; IEngineSound *m_pSound;
IGameClient *m_pGameClient; IGameClient *m_pGameClient;
IEngineMap *m_pMap; IEngineMap *m_pMap;
IConfigManager *m_pConfigManager;
CConfig *m_pConfig;
IConsole *m_pConsole; IConsole *m_pConsole;
IStorage *m_pStorage; IStorage *m_pStorage;
IUpdater *m_pUpdater; IUpdater *m_pUpdater;
@ -274,6 +276,8 @@ public:
IEngineSound *Sound() { return m_pSound; } IEngineSound *Sound() { return m_pSound; }
IGameClient *GameClient() { return m_pGameClient; } IGameClient *GameClient() { return m_pGameClient; }
IEngineMasterServer *MasterServer() { return m_pMasterServer; } IEngineMasterServer *MasterServer() { return m_pMasterServer; }
IConfigManager *ConfigManager() { return m_pConfigManager; }
CConfig *Config() { return m_pConfig; }
IStorage *Storage() { return m_pStorage; } IStorage *Storage() { return m_pStorage; }
IUpdater *Updater() { return m_pUpdater; } IUpdater *Updater() { return m_pUpdater; }
ISteam *Steam() { return m_pSteam; } ISteam *Steam() { return m_pSteam; }

View file

@ -38,9 +38,9 @@ void CFriends::Init(bool Foes)
{ {
m_Foes = Foes; m_Foes = Foes;
IConfig *pConfig = Kernel()->RequestInterface<IConfig>(); IConfigManager *pConfigManager = Kernel()->RequestInterface<IConfigManager>();
if(pConfig) if(pConfigManager)
pConfig->RegisterCallback(ConfigSaveCallback, this); pConfigManager->RegisterCallback(ConfigSaveCallback, this);
IConsole *pConsole = Kernel()->RequestInterface<IConsole>(); IConsole *pConsole = Kernel()->RequestInterface<IConsole>();
if(pConsole) if(pConsole)
@ -158,7 +158,7 @@ void CFriends::Friends()
} }
} }
void CFriends::ConfigSaveCallback(IConfig *pConfig, void *pUserData) void CFriends::ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData)
{ {
CFriends *pSelf = (CFriends *)pUserData; CFriends *pSelf = (CFriends *)pUserData;
char aBuf[128]; char aBuf[128];
@ -175,6 +175,6 @@ void CFriends::ConfigSaveCallback(IConfig *pConfig, void *pUserData)
str_escape(&pDst, pSelf->m_aFriends[i].m_aClan, pEnd); str_escape(&pDst, pSelf->m_aFriends[i].m_aClan, pEnd);
str_append(aBuf, "\"", sizeof(aBuf)); str_append(aBuf, "\"", sizeof(aBuf));
pConfig->WriteLine(aBuf); pConfigManager->WriteLine(aBuf);
} }
} }

View file

@ -17,7 +17,7 @@ class CFriends : public IFriends
static void ConRemoveFriend(IConsole::IResult *pResult, void *pUserData); static void ConRemoveFriend(IConsole::IResult *pResult, void *pUserData);
static void ConFriends(IConsole::IResult *pResult, void *pUserData); static void ConFriends(IConsole::IResult *pResult, void *pUserData);
static void ConfigSaveCallback(IConfig *pConfig, void *pUserData); static void ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData);
public: public:
CFriends(); CFriends();

View file

@ -89,9 +89,9 @@ void CServerBrowser::SetBaseInfo(class CNetClient *pClient, const char *pNetVers
m_pMasterServer = Kernel()->RequestInterface<IMasterServer>(); m_pMasterServer = Kernel()->RequestInterface<IMasterServer>();
m_pConsole = Kernel()->RequestInterface<IConsole>(); m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pFriends = Kernel()->RequestInterface<IFriends>(); m_pFriends = Kernel()->RequestInterface<IFriends>();
IConfig *pConfig = Kernel()->RequestInterface<IConfig>(); IConfigManager *pConfigManager = Kernel()->RequestInterface<IConfigManager>();
if(pConfig) if(pConfigManager)
pConfig->RegisterCallback(ConfigSaveCallback, this); pConfigManager->RegisterCallback(ConfigSaveCallback, this);
} }
const CServerInfo *CServerBrowser::SortedGet(int Index) const const CServerInfo *CServerBrowser::SortedGet(int Index) const
@ -1264,7 +1264,7 @@ int CServerBrowser::LoadingProgression() const
return 100.0f * Loaded / Servers; return 100.0f * Loaded / Servers;
} }
void CServerBrowser::ConfigSaveCallback(IConfig *pConfig, void *pUserData) void CServerBrowser::ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData)
{ {
CServerBrowser *pSelf = (CServerBrowser *)pUserData; CServerBrowser *pSelf = (CServerBrowser *)pUserData;
@ -1274,7 +1274,7 @@ void CServerBrowser::ConfigSaveCallback(IConfig *pConfig, void *pUserData)
{ {
net_addr_str(&pSelf->m_aFavoriteServers[i], aAddrStr, sizeof(aAddrStr), true); net_addr_str(&pSelf->m_aFavoriteServers[i], aAddrStr, sizeof(aAddrStr), true);
str_format(aBuffer, sizeof(aBuffer), "add_favorite %s", aAddrStr); str_format(aBuffer, sizeof(aBuffer), "add_favorite %s", aAddrStr);
pConfig->WriteLine(aBuffer); pConfigManager->WriteLine(aBuffer);
} }
} }

View file

@ -206,7 +206,7 @@ private:
void SetInfo(CServerEntry *pEntry, const CServerInfo &Info); void SetInfo(CServerEntry *pEntry, const CServerInfo &Info);
static void ConfigSaveCallback(IConfig *pConfig, void *pUserData); static void ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData);
}; };
#endif #endif

View file

@ -5,21 +5,22 @@
#include "kernel.h" #include "kernel.h"
class IConfig : public IInterface class IConfigManager : public IInterface
{ {
MACRO_INTERFACE("config", 0) MACRO_INTERFACE("config", 0)
public: public:
typedef void (*SAVECALLBACKFUNC)(IConfig *pConfig, void *pUserData); typedef void (*SAVECALLBACKFUNC)(IConfigManager *pConfig, void *pUserData);
virtual void Init() = 0; virtual void Init() = 0;
virtual void Reset() = 0; virtual void Reset() = 0;
virtual bool Save() = 0; virtual bool Save() = 0;
virtual class CConfig *Values() = 0;
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0; virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) = 0;
virtual void WriteLine(const char *pLine) = 0; virtual void WriteLine(const char *pLine) = 0;
}; };
extern IConfig *CreateConfig(); extern IConfigManager *CreateConfigManager();
#endif #endif

View file

@ -81,6 +81,7 @@ public:
typedef void (*FCommandCallback)(IResult *pResult, void *pUserData); typedef void (*FCommandCallback)(IResult *pResult, void *pUserData);
typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData); typedef void (*FChainCommandCallback)(IResult *pResult, void *pUserData, FCommandCallback pfnCallback, void *pCallbackUserData);
virtual void Init() = 0;
virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const = 0; virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int Flagmask) const = 0;
virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp) = 0; virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp) = 0;
virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) = 0; virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser) = 0;

View file

@ -118,10 +118,11 @@ void CRegister::RegisterGotCount(CNetChunk *pChunk)
} }
} }
void CRegister::Init(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole) void CRegister::Init(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, CConfig *pConfig, IConsole *pConsole)
{ {
m_pNetServer = pNetServer; m_pNetServer = pNetServer;
m_pMasterServer = pMasterServer; m_pMasterServer = pMasterServer;
m_pConfig = pConfig;
m_pConsole = pConsole; m_pConsole = pConsole;
} }

View file

@ -29,6 +29,7 @@ class CRegister
class CNetServer *m_pNetServer; class CNetServer *m_pNetServer;
class IEngineMasterServer *m_pMasterServer; class IEngineMasterServer *m_pMasterServer;
class CConfig *m_pConfig;
class IConsole *m_pConsole; class IConsole *m_pConsole;
bool m_Sixup; bool m_Sixup;
@ -51,7 +52,7 @@ class CRegister
public: public:
CRegister(bool Sixup); CRegister(bool Sixup);
void Init(class CNetServer *pNetServer, class IEngineMasterServer *pMasterServer, class IConsole *pConsole); void Init(class CNetServer *pNetServer, class IEngineMasterServer *pMasterServer, class CConfig *pConfig, class IConsole *pConsole);
void RegisterUpdate(int Nettype); void RegisterUpdate(int Nettype);
int RegisterProcessPacket(struct CNetChunk *pPacket, SECURITY_TOKEN ResponseToken = 0); int RegisterProcessPacket(struct CNetChunk *pPacket, SECURITY_TOKEN ResponseToken = 0);
void FeedToken(NETADDR Addr, SECURITY_TOKEN ResponseToken); void FeedToken(NETADDR Addr, SECURITY_TOKEN ResponseToken);

View file

@ -2335,10 +2335,10 @@ int CServer::LoadMap(const char *pMapName)
return 1; return 1;
} }
void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole) void CServer::InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, CConfig *pConfig, IConsole *pConsole)
{ {
m_Register.Init(pNetServer, pMasterServer, pConsole); m_Register.Init(pNetServer, pMasterServer, pConfig, pConsole);
m_RegSixup.Init(pNetServer, pMasterServer, pConsole); m_RegSixup.Init(pNetServer, pMasterServer, pConfig, pConsole);
} }
int CServer::Run() int CServer::Run()
@ -2407,7 +2407,7 @@ int CServer::Run()
m_NetServer.SetCallbacks(NewClientCallback, NewClientNoAuthCallback, ClientRejoinCallback, DelClientCallback, this); m_NetServer.SetCallbacks(NewClientCallback, NewClientNoAuthCallback, ClientRejoinCallback, DelClientCallback, this);
m_Econ.Init(Console(), &m_ServerBan); m_Econ.Init(Config(), Console(), &m_ServerBan);
#if defined(CONF_FAMILY_UNIX) #if defined(CONF_FAMILY_UNIX)
m_Fifo.Init(Console(), g_Config.m_SvInputFifo, CFGFLAG_SERVER); m_Fifo.Init(Console(), g_Config.m_SvInputFifo, CFGFLAG_SERVER);
@ -3495,10 +3495,10 @@ int main(int argc, const char **argv) // ignore_convention
IConsole *pConsole = CreateConsole(CFGFLAG_SERVER | CFGFLAG_ECON); IConsole *pConsole = CreateConsole(CFGFLAG_SERVER | CFGFLAG_ECON);
IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer(); IEngineMasterServer *pEngineMasterServer = CreateEngineMasterServer();
IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_SERVER, argc, argv); // ignore_convention IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_SERVER, argc, argv); // ignore_convention
IConfig *pConfig = CreateConfig(); IConfigManager *pConfigManager = CreateConfigManager();
IEngineAntibot *pEngineAntibot = CreateEngineAntibot(); IEngineAntibot *pEngineAntibot = CreateEngineAntibot();
pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer, pConsole); pServer->InitRegister(&pServer->m_NetServer, pEngineMasterServer, pConfigManager->Values(), pConsole);
{ {
bool RegisterFail = false; bool RegisterFail = false;
@ -3510,7 +3510,7 @@ int main(int argc, const char **argv) // ignore_convention
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pGameServer); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pGameServer);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConsole);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfig); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pConfigManager);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineMasterServer); // register as both RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineMasterServer); // register as both
RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IMasterServer *>(pEngineMasterServer), false); RegisterFail = RegisterFail || !pKernel->RegisterInterface(static_cast<IMasterServer *>(pEngineMasterServer), false);
RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineAntibot); RegisterFail = RegisterFail || !pKernel->RegisterInterface(pEngineAntibot);
@ -3524,7 +3524,8 @@ int main(int argc, const char **argv) // ignore_convention
} }
pEngine->Init(); pEngine->Init();
pConfig->Init(); pConfigManager->Init();
pConsole->Init();
pEngineMasterServer->Init(); pEngineMasterServer->Init();
pEngineMasterServer->Load(); pEngineMasterServer->Load();

View file

@ -89,6 +89,7 @@ public:
class CServer : public IServer class CServer : public IServer
{ {
class IGameServer *m_pGameServer; class IGameServer *m_pGameServer;
class CConfig *m_pConfig;
class IConsole *m_pConsole; class IConsole *m_pConsole;
class IStorage *m_pStorage; class IStorage *m_pStorage;
class IEngineAntibot *m_pAntibot; class IEngineAntibot *m_pAntibot;
@ -107,6 +108,7 @@ class CServer : public IServer
public: public:
class IGameServer *GameServer() { return m_pGameServer; } class IGameServer *GameServer() { return m_pGameServer; }
class CConfig *Config() { return m_pConfig; }
class IConsole *Console() { return m_pConsole; } class IConsole *Console() { return m_pConsole; }
class IStorage *Storage() { return m_pStorage; } class IStorage *Storage() { return m_pStorage; }
class IEngineAntibot *Antibot() { return m_pAntibot; } class IEngineAntibot *Antibot() { return m_pAntibot; }
@ -366,7 +368,7 @@ public:
void StopRecord(int ClientID); void StopRecord(int ClientID);
bool IsRecording(int ClientID); bool IsRecording(int ClientID);
void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, IConsole *pConsole); void InitRegister(CNetServer *pNetServer, IEngineMasterServer *pMasterServer, CConfig *pConfig, IConsole *pConsole);
int Run(); int Run();
static void ConTestingCommands(IConsole::IResult *pResult, void *pUser); static void ConTestingCommands(IConsole::IResult *pResult, void *pUser);

View file

@ -5,48 +5,34 @@
#include <engine/shared/protocol.h> #include <engine/shared/protocol.h>
#include <engine/storage.h> #include <engine/storage.h>
CConfiguration g_Config; CConfig g_Config;
class CConfig : public IConfig void EscapeParam(char *pDst, const char *pSrc, int size)
{ {
IStorage *m_pStorage; for(int i = 0; *pSrc && i < size - 1; ++i)
IOHANDLE m_ConfigFile;
bool m_Failed;
struct CCallback
{ {
SAVECALLBACKFUNC m_pfnFunc; if(*pSrc == '"' || *pSrc == '\\') // escape \ and "
void *m_pUserData; *pDst++ = '\\';
}; *pDst++ = *pSrc++;
}
enum *pDst = 0;
{
MAX_CALLBACKS = 16
};
CCallback m_aCallbacks[MAX_CALLBACKS];
int m_NumCallbacks;
void EscapeParam(char *pDst, const char *pSrc, int Size)
{
str_escape(&pDst, pSrc, pDst + Size);
} }
public: CConfigManager::CConfigManager()
CConfig()
{ {
m_pStorage = 0;
m_ConfigFile = 0; m_ConfigFile = 0;
m_NumCallbacks = 0; m_NumCallbacks = 0;
m_Failed = false; m_Failed = false;
} }
virtual void Init() void CConfigManager::Init()
{ {
m_pStorage = Kernel()->RequestInterface<IStorage>(); m_pStorage = Kernel()->RequestInterface<IStorage>();
Reset(); Reset();
} }
virtual void Reset() void CConfigManager::Reset()
{ {
#define MACRO_CONFIG_INT(Name, ScriptName, def, min, max, flags, desc) g_Config.m_##Name = def; #define MACRO_CONFIG_INT(Name, ScriptName, def, min, max, flags, desc) g_Config.m_##Name = def;
#define MACRO_CONFIG_COL(Name, ScriptName, def, flags, desc) MACRO_CONFIG_INT(Name, ScriptName, def, 0, 0, flags, desc) #define MACRO_CONFIG_COL(Name, ScriptName, def, flags, desc) MACRO_CONFIG_INT(Name, ScriptName, def, 0, 0, flags, desc)
@ -59,7 +45,7 @@ public:
#undef MACRO_CONFIG_STR #undef MACRO_CONFIG_STR
} }
virtual bool Save() bool CConfigManager::Save()
{ {
if(!m_pStorage || !g_Config.m_ClSaveSettings) if(!m_pStorage || !g_Config.m_ClSaveSettings)
return true; return true;
@ -129,7 +115,7 @@ public:
return true; return true;
} }
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData) void CConfigManager::RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData)
{ {
dbg_assert(m_NumCallbacks < MAX_CALLBACKS, "too many config callbacks"); dbg_assert(m_NumCallbacks < MAX_CALLBACKS, "too many config callbacks");
m_aCallbacks[m_NumCallbacks].m_pfnFunc = pfnFunc; m_aCallbacks[m_NumCallbacks].m_pfnFunc = pfnFunc;
@ -137,7 +123,7 @@ public:
m_NumCallbacks++; m_NumCallbacks++;
} }
virtual void WriteLine(const char *pLine) void CConfigManager::WriteLine(const char *pLine)
{ {
if(!m_ConfigFile || if(!m_ConfigFile ||
io_write(m_ConfigFile, pLine, str_length(pLine)) != static_cast<unsigned>(str_length(pLine)) || io_write(m_ConfigFile, pLine, str_length(pLine)) != static_cast<unsigned>(str_length(pLine)) ||
@ -148,6 +134,5 @@ public:
#endif #endif
m_Failed = true; m_Failed = true;
} }
};
IConfig *CreateConfig() { return new CConfig; } IConfigManager *CreateConfigManager() { return new CConfigManager; }

View file

@ -4,14 +4,16 @@
#define ENGINE_SHARED_CONFIG_H #define ENGINE_SHARED_CONFIG_H
#include <base/detect.h> #include <base/detect.h>
#include <engine/config.h>
#define CONFIG_FILE "settings_ddnet.cfg" #define CONFIG_FILE "settings_ddnet.cfg"
#define AUTOEXEC_FILE "autoexec.cfg" #define AUTOEXEC_FILE "autoexec.cfg"
#define AUTOEXEC_CLIENT_FILE "autoexec_client.cfg" #define AUTOEXEC_CLIENT_FILE "autoexec_client.cfg"
#define AUTOEXEC_SERVER_FILE "autoexec_server.cfg" #define AUTOEXEC_SERVER_FILE "autoexec_server.cfg"
struct CConfiguration class CConfig
{ {
public:
#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Save, Desc) int m_##Name; #define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Save, Desc) int m_##Name;
#define MACRO_CONFIG_COL(Name, ScriptName, Def, Save, Desc) unsigned m_##Name; #define MACRO_CONFIG_COL(Name, ScriptName, Def, Save, Desc) unsigned m_##Name;
#define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Save, Desc) char m_##Name[Len]; // Flawfinder: ignore #define MACRO_CONFIG_STR(Name, ScriptName, Len, Def, Save, Desc) char m_##Name[Len]; // Flawfinder: ignore
@ -21,7 +23,7 @@ struct CConfiguration
#undef MACRO_CONFIG_STR #undef MACRO_CONFIG_STR
}; };
extern CConfiguration g_Config; extern CConfig g_Config;
enum enum
{ {
@ -41,4 +43,36 @@ enum
CFGFLAG_COLALPHA = 1 << 11, CFGFLAG_COLALPHA = 1 << 11,
}; };
class CConfigManager : public IConfigManager
{
enum
{
MAX_CALLBACKS = 16
};
struct CCallback
{
SAVECALLBACKFUNC m_pfnFunc;
void *m_pUserData;
};
class IStorage *m_pStorage;
IOHANDLE m_ConfigFile;
bool m_Failed;
CCallback m_aCallbacks[MAX_CALLBACKS];
int m_NumCallbacks;
public:
CConfigManager();
virtual void Init();
virtual void Reset();
virtual bool Save();
virtual CConfig *Values() { return &g_Config; }
virtual void RegisterCallback(SAVECALLBACKFUNC pfnFunc, void *pUserData);
virtual void WriteLine(const char *pLine);
};
#endif #endif

View file

@ -571,8 +571,6 @@ void CConsole::ExecuteFile(const char *pFilename, int ClientID, bool LogFailure,
if(str_comp(pFilename, pCur->m_pFilename) == 0) if(str_comp(pFilename, pCur->m_pFilename) == 0)
return; return;
if(!m_pStorage)
m_pStorage = Kernel()->RequestInterface<IStorage>();
if(!m_pStorage) if(!m_pStorage)
return; return;
@ -951,6 +949,31 @@ CConsole::CConsole(int FlagMask)
Register("access_status", "i[accesslevel]", CFGFLAG_SERVER, ConCommandStatus, this, "List all commands which are accessible for admin = 0, moderator = 1, helper = 2, all = 3"); Register("access_status", "i[accesslevel]", CFGFLAG_SERVER, ConCommandStatus, this, "List all commands which are accessible for admin = 0, moderator = 1, helper = 2, all = 3");
Register("cmdlist", "", CFGFLAG_SERVER | CFGFLAG_CHAT, ConUserCommandStatus, this, "List all commands which are accessible for users"); Register("cmdlist", "", CFGFLAG_SERVER | CFGFLAG_CHAT, ConUserCommandStatus, this, "List all commands which are accessible for users");
// DDRace
m_Cheated = false;
}
CConsole::~CConsole()
{
CCommand *pCommand = m_pFirstCommand;
while(pCommand)
{
CCommand *pNext = pCommand->m_pNext;
if(pCommand->m_pfnCallback == Con_Chain)
delete static_cast<CChain *>(pCommand->m_pUserData);
// Temp commands are on m_TempCommands heap, so don't delete them
if(!pCommand->m_Temp)
delete pCommand;
pCommand = pNext;
}
}
void CConsole::Init()
{
m_pConfig = Kernel()->RequestInterface<IConfigManager>()->Values();
m_pStorage = Kernel()->RequestInterface<IStorage>();
// TODO: this should disappear // TODO: this should disappear
#define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Flags, Desc) \ #define MACRO_CONFIG_INT(Name, ScriptName, Def, Min, Max, Flags, Desc) \
{ \ { \
@ -977,25 +1000,6 @@ CConsole::CConsole(int FlagMask)
#undef MACRO_CONFIG_INT #undef MACRO_CONFIG_INT
#undef MACRO_CONFIG_COL #undef MACRO_CONFIG_COL
#undef MACRO_CONFIG_STR #undef MACRO_CONFIG_STR
// DDRace
m_Cheated = false;
}
CConsole::~CConsole()
{
CCommand *pCommand = m_pFirstCommand;
while(pCommand)
{
CCommand *pNext = pCommand->m_pNext;
if(pCommand->m_pfnCallback == Con_Chain)
delete static_cast<CChain *>(pCommand->m_pUserData);
// Temp commands are on m_TempCommands heap, so don't delete them
if(!pCommand->m_Temp)
delete pCommand;
pCommand = pNext;
}
} }
void CConsole::ParseArguments(int NumArgs, const char **ppArguments) void CConsole::ParseArguments(int NumArgs, const char **ppArguments)

View file

@ -46,6 +46,7 @@ class CConsole : public IConsole
}; };
CExecFile *m_pFirstExec; CExecFile *m_pFirstExec;
class CConfig *m_pConfig;
class IStorage *m_pStorage; class IStorage *m_pStorage;
int m_AccessLevel; int m_AccessLevel;
@ -196,6 +197,7 @@ public:
CConsole(int FlagMask); CConsole(int FlagMask);
~CConsole(); ~CConsole();
virtual void Init();
virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int FlagMask) const; virtual const CCommandInfo *FirstCommandInfo(int AccessLevel, int FlagMask) const;
virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp); virtual const CCommandInfo *GetCommandInfo(const char *pName, int FlagMask, bool Temp);
virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser); virtual void PossibleCommands(const char *pStr, int FlagMask, bool Temp, FPossibleCallback pfnCallback, void *pUser);

View file

@ -59,8 +59,9 @@ void CEcon::ConLogout(IConsole::IResult *pResult, void *pUserData)
pThis->m_NetConsole.Drop(pThis->m_UserClientID, "Logout"); pThis->m_NetConsole.Drop(pThis->m_UserClientID, "Logout");
} }
void CEcon::Init(IConsole *pConsole, CNetBan *pNetBan) void CEcon::Init(CConfig *pConfig, IConsole *pConsole, CNetBan *pNetBan)
{ {
m_pConfig = pConfig;
m_pConsole = pConsole; m_pConsole = pConsole;
for(auto &Client : m_aClients) for(auto &Client : m_aClients)

View file

@ -5,6 +5,8 @@
#include <engine/console.h> #include <engine/console.h>
class CConfig;
class CEcon class CEcon
{ {
enum enum
@ -28,6 +30,7 @@ class CEcon
}; };
CClient m_aClients[NET_MAX_CONSOLE_CLIENTS]; CClient m_aClients[NET_MAX_CONSOLE_CLIENTS];
CConfig *m_pConfig;
IConsole *m_pConsole; IConsole *m_pConsole;
CNetConsole m_NetConsole; CNetConsole m_NetConsole;
@ -45,7 +48,7 @@ class CEcon
public: public:
IConsole *Console() { return m_pConsole; } IConsole *Console() { return m_pConsole; }
void Init(IConsole *pConsole, class CNetBan *pNetBan); void Init(CConfig *pConfig, IConsole *pConsole, class CNetBan *pNetBan);
void Update(); void Update();
void Send(int ClientID, const char *pLine); void Send(int ClientID, const char *pLine);
void Shutdown(); void Shutdown();

View file

@ -26,6 +26,7 @@ protected:
class CUI *UI() const { return m_pClient->UI(); } class CUI *UI() const { return m_pClient->UI(); }
class ISound *Sound() const { return m_pClient->Sound(); } class ISound *Sound() const { return m_pClient->Sound(); }
class CRenderTools *RenderTools() const { return m_pClient->RenderTools(); } class CRenderTools *RenderTools() const { return m_pClient->RenderTools(); }
class CConfig *Config() const { return m_pClient->Config(); }
class IConsole *Console() const { return m_pClient->Console(); } class IConsole *Console() const { return m_pClient->Console(); }
class IDemoPlayer *DemoPlayer() const { return m_pClient->DemoPlayer(); } class IDemoPlayer *DemoPlayer() const { return m_pClient->DemoPlayer(); }
class IDemoRecorder *DemoRecorder(int Recorder) const { return m_pClient->DemoRecorder(Recorder); } class IDemoRecorder *DemoRecorder(int Recorder) const { return m_pClient->DemoRecorder(Recorder); }

View file

@ -250,9 +250,9 @@ void CBinds::SetDefaults()
void CBinds::OnConsoleInit() void CBinds::OnConsoleInit()
{ {
// bindings // bindings
IConfig *pConfig = Kernel()->RequestInterface<IConfig>(); IConfigManager *pConfigManager = Kernel()->RequestInterface<IConfigManager>();
if(pConfig) if(pConfigManager)
pConfig->RegisterCallback(ConfigSaveCallback, this); pConfigManager->RegisterCallback(ConfigSaveCallback, this);
Console()->Register("bind", "s[key] r[command]", CFGFLAG_CLIENT, ConBind, this, "Bind key to execute the command"); Console()->Register("bind", "s[key] r[command]", CFGFLAG_CLIENT, ConBind, this, "Bind key to execute the command");
Console()->Register("dump_binds", "?s[key]", CFGFLAG_CLIENT, ConDumpBinds, this, "Print command executed by this keybindind or all binds"); Console()->Register("dump_binds", "?s[key]", CFGFLAG_CLIENT, ConDumpBinds, this, "Print command executed by this keybindind or all binds");
@ -423,13 +423,13 @@ const char *CBinds::GetKeyBindModifiersName(int Modifier)
return aModifier; return aModifier;
} }
void CBinds::ConfigSaveCallback(IConfig *pConfig, void *pUserData) void CBinds::ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData)
{ {
CBinds *pSelf = (CBinds *)pUserData; CBinds *pSelf = (CBinds *)pUserData;
char aBuffer[256]; char aBuffer[256];
char *pEnd = aBuffer + sizeof(aBuffer); char *pEnd = aBuffer + sizeof(aBuffer);
pConfig->WriteLine("unbindall"); pConfigManager->WriteLine("unbindall");
for(int i = 0; i < MODIFIER_COMBINATION_COUNT; i++) for(int i = 0; i < MODIFIER_COMBINATION_COUNT; i++)
{ {
for(int j = 0; j < KEY_LAST; j++) for(int j = 0; j < KEY_LAST; j++)
@ -443,7 +443,7 @@ void CBinds::ConfigSaveCallback(IConfig *pConfig, void *pUserData)
str_escape(&pDst, pSelf->m_aapKeyBindings[i][j], pEnd); str_escape(&pDst, pSelf->m_aapKeyBindings[i][j], pEnd);
str_append(aBuffer, "\"", sizeof(aBuffer)); str_append(aBuffer, "\"", sizeof(aBuffer));
pConfig->WriteLine(aBuffer); pConfigManager->WriteLine(aBuffer);
} }
} }
} }

View file

@ -15,7 +15,7 @@ class CBinds : public CComponent
static void ConUnbindAll(IConsole::IResult *pResult, void *pUserData); static void ConUnbindAll(IConsole::IResult *pResult, void *pUserData);
class IConsole *GetConsole() const { return Console(); } class IConsole *GetConsole() const { return Console(); }
static void ConfigSaveCallback(class IConfig *pConfig, void *pUserData); static void ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData);
public: public:
CBinds(); CBinds();

View file

@ -744,8 +744,6 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
TextRender()->SetCurFont(NULL); TextRender()->SetCurFont(NULL);
} }
typedef void (*pfnAssignFuncCallback)(CConfiguration *pConfig, int Value);
typedef struct typedef struct
{ {
CLocConstString m_Name; CLocConstString m_Name;

View file

@ -84,6 +84,7 @@ class CGameClient : public IGameClient
class ITextRender *m_pTextRender; class ITextRender *m_pTextRender;
class IClient *m_pClient; class IClient *m_pClient;
class ISound *m_pSound; class ISound *m_pSound;
class CConfig *m_pConfig;
class IConsole *m_pConsole; class IConsole *m_pConsole;
class IStorage *m_pStorage; class IStorage *m_pStorage;
class IDemoPlayer *m_pDemoPlayer; class IDemoPlayer *m_pDemoPlayer;
@ -135,6 +136,7 @@ public:
class ISound *Sound() const { return m_pSound; } class ISound *Sound() const { return m_pSound; }
class IInput *Input() const { return m_pInput; } class IInput *Input() const { return m_pInput; }
class IStorage *Storage() const { return m_pStorage; } class IStorage *Storage() const { return m_pStorage; }
class CConfig *Config() const { return m_pConfig; }
class IConsole *Console() { return m_pConsole; } class IConsole *Console() { return m_pConsole; }
class ITextRender *TextRender() const { return m_pTextRender; } class ITextRender *TextRender() const { return m_pTextRender; }
class IDemoPlayer *DemoPlayer() const { return m_pDemoPlayer; } class IDemoPlayer *DemoPlayer() const { return m_pDemoPlayer; }

View file

@ -6346,6 +6346,7 @@ void CEditor::Init()
{ {
m_pInput = Kernel()->RequestInterface<IInput>(); m_pInput = Kernel()->RequestInterface<IInput>();
m_pClient = Kernel()->RequestInterface<IClient>(); m_pClient = Kernel()->RequestInterface<IClient>();
m_pConfig = Kernel()->RequestInterface<IConfigManager>()->Values();
m_pConsole = Kernel()->RequestInterface<IConsole>(); m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pGraphics = Kernel()->RequestInterface<IGraphics>(); m_pGraphics = Kernel()->RequestInterface<IGraphics>();
m_pTextRender = Kernel()->RequestInterface<ITextRender>(); m_pTextRender = Kernel()->RequestInterface<ITextRender>();

View file

@ -631,6 +631,7 @@ class CEditor : public IEditor
{ {
class IInput *m_pInput; class IInput *m_pInput;
class IClient *m_pClient; class IClient *m_pClient;
class CConfig *m_pConfig;
class IConsole *m_pConsole; class IConsole *m_pConsole;
class IGraphics *m_pGraphics; class IGraphics *m_pGraphics;
class ITextRender *m_pTextRender; class ITextRender *m_pTextRender;
@ -642,6 +643,7 @@ class CEditor : public IEditor
public: public:
class IInput *Input() { return m_pInput; }; class IInput *Input() { return m_pInput; };
class IClient *Client() { return m_pClient; }; class IClient *Client() { return m_pClient; };
class CConfig *Config() { return m_pConfig; }
class IConsole *Console() { return m_pConsole; }; class IConsole *Console() { return m_pConsole; };
class IGraphics *Graphics() { return m_pGraphics; }; class IGraphics *Graphics() { return m_pGraphics; };
class ISound *Sound() { return m_pSound; } class ISound *Sound() { return m_pSound; }

62
src/game/server/alloc.h Normal file
View file

@ -0,0 +1,62 @@
/* (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. */
#ifndef GAME_SERVER_ALLOC_H
#define GAME_SERVER_ALLOC_H
#include <new>
#include <base/system.h>
#define MACRO_ALLOC_HEAP() \
public: \
void *operator new(size_t Size) \
{ \
void *p = malloc(Size); \
mem_zero(p, Size); \
return p; \
} \
void operator delete(void *pPtr) \
{ \
free(pPtr); \
} \
\
private:
#define MACRO_ALLOC_POOL_ID() \
public: \
void *operator new(size_t Size, int id); \
void operator delete(void *p, int id); \
void operator delete(void *p); /* NOLINT(misc-new-delete-overloads) */ \
\
private:
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
void *POOLTYPE::operator new(size_t Size, int id) \
{ \
dbg_assert(sizeof(POOLTYPE) == Size, "size error"); \
dbg_assert(!ms_PoolUsed##POOLTYPE[id], "already used"); \
/*dbg_msg("pool", "++ %s %d", #POOLTYPE, id);*/ \
ms_PoolUsed##POOLTYPE[id] = 1; \
mem_zero(ms_PoolData##POOLTYPE[id], Size); \
return ms_PoolData##POOLTYPE[id]; \
} \
void POOLTYPE::operator delete(void *p, int id) \
{ \
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
dbg_assert(id == (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE, "invalid id"); \
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
ms_PoolUsed##POOLTYPE[id] = 0; \
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
} \
void POOLTYPE::operator delete(void *p) /* NOLINT(misc-new-delete-overloads) */ \
{ \
int id = (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE; \
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
ms_PoolUsed##POOLTYPE[id] = 0; \
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
}
#endif

View file

@ -7,6 +7,9 @@
#include <game/server/teams.h> #include <game/server/teams.h>
#include <game/version.h> #include <game/version.h>
#include "entities/character.h"
#include "player.h"
bool CheckClientID(int ClientID); bool CheckClientID(int ClientID);
void CGameContext::ConCredits(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConCredits(IConsole::IResult *pResult, void *pUserData)

View file

@ -1,7 +1,9 @@
/* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */ /* (c) Shereef Marzouk. See "licence DDRace.txt" and the readme.txt in the root of the distribution for more information. */
#include "gamecontext.h" #include "gamecontext.h"
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <game/server/entities/character.h>
#include <game/server/gamemodes/DDRace.h> #include <game/server/gamemodes/DDRace.h>
#include <game/server/player.h>
#include <game/server/save.h> #include <game/server/save.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include <game/version.h> #include <game/version.h>

View file

@ -2,8 +2,10 @@
/* 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. */
#include <antibot/antibot_data.h> #include <antibot/antibot_data.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <game/generated/server_data.h>
#include <game/mapitems.h> #include <game/mapitems.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/player.h>
#include <new> #include <new>
#include "character.h" #include "character.h"
@ -18,9 +20,8 @@ MACRO_ALLOC_POOL_ID_IMPL(CCharacter, MAX_CLIENTS)
// Character, "physical" player's part // Character, "physical" player's part
CCharacter::CCharacter(CGameWorld *pWorld) : CCharacter::CCharacter(CGameWorld *pWorld) :
CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER) CEntity(pWorld, CGameWorld::ENTTYPE_CHARACTER, vec2(0, 0), ms_PhysSize)
{ {
m_ProximityRadius = ms_PhysSize;
m_Health = 0; m_Health = 0;
m_Armor = 0; m_Armor = 0;
m_StrongWeakID = 0; m_StrongWeakID = 0;
@ -128,12 +129,12 @@ void CCharacter::SetSolo(bool Solo)
bool CCharacter::IsGrounded() bool CCharacter::IsGrounded()
{ {
if(GameServer()->Collision()->CheckPoint(m_Pos.x + m_ProximityRadius / 2, m_Pos.y + m_ProximityRadius / 2 + 5)) if(GameServer()->Collision()->CheckPoint(m_Pos.x + GetProximityRadius() / 2, m_Pos.y + GetProximityRadius() / 2 + 5))
return true; return true;
if(GameServer()->Collision()->CheckPoint(m_Pos.x - m_ProximityRadius / 2, m_Pos.y + m_ProximityRadius / 2 + 5)) if(GameServer()->Collision()->CheckPoint(m_Pos.x - GetProximityRadius() / 2, m_Pos.y + GetProximityRadius() / 2 + 5))
return true; return true;
int MoveRestrictionsBelow = GameServer()->Collision()->GetMoveRestrictions(m_Pos + vec2(0, m_ProximityRadius / 2 + 4), 0.0f); int MoveRestrictionsBelow = GameServer()->Collision()->GetMoveRestrictions(m_Pos + vec2(0, GetProximityRadius() / 2 + 4), 0.0f);
if(MoveRestrictionsBelow & CANTMOVE_DOWN) if(MoveRestrictionsBelow & CANTMOVE_DOWN)
{ {
return true; return true;
@ -223,7 +224,7 @@ void CCharacter::HandleNinja()
// Set velocity // Set velocity
m_Core.m_Vel = m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity; m_Core.m_Vel = m_Ninja.m_ActivationDir * g_pData->m_Weapons.m_Ninja.m_Velocity;
vec2 OldPos = m_Pos; vec2 OldPos = m_Pos;
GameServer()->Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(m_ProximityRadius, m_ProximityRadius), 0.f); GameServer()->Collision()->MoveBox(&m_Core.m_Pos, &m_Core.m_Vel, vec2(GetProximityRadius(), GetProximityRadius()), 0.f);
// reset velocity so the client doesn't predict stuff // reset velocity so the client doesn't predict stuff
m_Core.m_Vel = vec2(0.f, 0.f); m_Core.m_Vel = vec2(0.f, 0.f);
@ -232,7 +233,7 @@ void CCharacter::HandleNinja()
{ {
CCharacter *aEnts[MAX_CLIENTS]; CCharacter *aEnts[MAX_CLIENTS];
vec2 Dir = m_Pos - OldPos; vec2 Dir = m_Pos - OldPos;
float Radius = m_ProximityRadius * 2.0f; float Radius = GetProximityRadius() * 2.0f;
vec2 Center = OldPos + Dir * 0.5f; vec2 Center = OldPos + Dir * 0.5f;
int Num = GameServer()->m_World.FindEntities(Center, Radius, (CEntity **)aEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); int Num = GameServer()->m_World.FindEntities(Center, Radius, (CEntity **)aEnts, MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
@ -264,7 +265,7 @@ void CCharacter::HandleNinja()
continue; continue;
// check so we are sufficiently close // check so we are sufficiently close
if(distance(aEnts[i]->m_Pos, m_Pos) > (m_ProximityRadius * 2.0f)) if(distance(aEnts[i]->m_Pos, m_Pos) > (GetProximityRadius() * 2.0f))
continue; continue;
// Hit a player, give him damage and stuffs... // Hit a player, give him damage and stuffs...
@ -399,7 +400,7 @@ void CCharacter::FireWeapon()
return; return;
} }
vec2 ProjStartPos = m_Pos + Direction * m_ProximityRadius * 0.75f; vec2 ProjStartPos = m_Pos + Direction * GetProximityRadius() * 0.75f;
switch(m_Core.m_ActiveWeapon) switch(m_Core.m_ActiveWeapon)
{ {
@ -416,7 +417,7 @@ void CCharacter::FireWeapon()
CCharacter *apEnts[MAX_CLIENTS]; CCharacter *apEnts[MAX_CLIENTS];
int Hits = 0; int Hits = 0;
int Num = GameServer()->m_World.FindEntities(ProjStartPos, m_ProximityRadius * 0.5f, (CEntity **)apEnts, int Num = GameServer()->m_World.FindEntities(ProjStartPos, GetProximityRadius() * 0.5f, (CEntity **)apEnts,
MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER); MAX_CLIENTS, CGameWorld::ENTTYPE_CHARACTER);
for(int i = 0; i < Num; ++i) for(int i = 0; i < Num; ++i)
@ -429,7 +430,7 @@ void CCharacter::FireWeapon()
// set his velocity to fast upward (for now) // set his velocity to fast upward (for now)
if(length(pTarget->m_Pos - ProjStartPos) > 0.0f) if(length(pTarget->m_Pos - ProjStartPos) > 0.0f)
GameServer()->CreateHammerHit(pTarget->m_Pos - normalize(pTarget->m_Pos - ProjStartPos) * m_ProximityRadius * 0.5f, Teams()->TeamMask(Team(), -1, m_pPlayer->GetCID())); GameServer()->CreateHammerHit(pTarget->m_Pos - normalize(pTarget->m_Pos - ProjStartPos) * GetProximityRadius() * 0.5f, Teams()->TeamMask(Team(), -1, m_pPlayer->GetCID()));
else else
GameServer()->CreateHammerHit(ProjStartPos, Teams()->TeamMask(Team(), -1, m_pPlayer->GetCID())); GameServer()->CreateHammerHit(ProjStartPos, Teams()->TeamMask(Team(), -1, m_pPlayer->GetCID()));
@ -1379,13 +1380,13 @@ void CCharacter::HandleBroadcast()
void CCharacter::HandleSkippableTiles(int Index) void CCharacter::HandleSkippableTiles(int Index)
{ {
// handle death-tiles and leaving gamelayer // handle death-tiles and leaving gamelayer
if((GameServer()->Collision()->GetCollisionAt(m_Pos.x + m_ProximityRadius / 3.f, m_Pos.y - m_ProximityRadius / 3.f) == TILE_DEATH || if((GameServer()->Collision()->GetCollisionAt(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
GameServer()->Collision()->GetCollisionAt(m_Pos.x + m_ProximityRadius / 3.f, m_Pos.y + m_ProximityRadius / 3.f) == TILE_DEATH || GameServer()->Collision()->GetCollisionAt(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH ||
GameServer()->Collision()->GetCollisionAt(m_Pos.x - m_ProximityRadius / 3.f, m_Pos.y - m_ProximityRadius / 3.f) == TILE_DEATH || GameServer()->Collision()->GetCollisionAt(m_Pos.x - GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
GameServer()->Collision()->GetFCollisionAt(m_Pos.x + m_ProximityRadius / 3.f, m_Pos.y - m_ProximityRadius / 3.f) == TILE_DEATH || GameServer()->Collision()->GetFCollisionAt(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
GameServer()->Collision()->GetFCollisionAt(m_Pos.x + m_ProximityRadius / 3.f, m_Pos.y + m_ProximityRadius / 3.f) == TILE_DEATH || GameServer()->Collision()->GetFCollisionAt(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH ||
GameServer()->Collision()->GetFCollisionAt(m_Pos.x - m_ProximityRadius / 3.f, m_Pos.y - m_ProximityRadius / 3.f) == TILE_DEATH || GameServer()->Collision()->GetFCollisionAt(m_Pos.x - GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f) == TILE_DEATH ||
GameServer()->Collision()->GetCollisionAt(m_Pos.x - m_ProximityRadius / 3.f, m_Pos.y + m_ProximityRadius / 3.f) == TILE_DEATH) && GameServer()->Collision()->GetCollisionAt(m_Pos.x - GetProximityRadius() / 3.f, m_Pos.y + GetProximityRadius() / 3.f) == TILE_DEATH) &&
!m_Super && !(Team() && Teams()->TeeFinished(m_pPlayer->GetCID()))) !m_Super && !(Team() && Teams()->TeeFinished(m_pPlayer->GetCID())))
{ {
Die(m_pPlayer->GetCID(), WEAPON_WORLD); Die(m_pPlayer->GetCID(), WEAPON_WORLD);
@ -1477,10 +1478,10 @@ void CCharacter::HandleTiles(int Index)
m_TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex); m_TileFIndex = GameServer()->Collision()->GetFTileIndex(MapIndex);
m_MoveRestrictions = GameServer()->Collision()->GetMoveRestrictions(IsSwitchActiveCb, this, m_Pos, 18.0f, MapIndex); m_MoveRestrictions = GameServer()->Collision()->GetMoveRestrictions(IsSwitchActiveCb, this, m_Pos, 18.0f, MapIndex);
//Sensitivity //Sensitivity
int S1 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x + m_ProximityRadius / 3.f, m_Pos.y - m_ProximityRadius / 3.f)); int S1 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f));
int S2 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x + m_ProximityRadius / 3.f, m_Pos.y + m_ProximityRadius / 3.f)); int S2 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x + GetProximityRadius() / 3.f, m_Pos.y + GetProximityRadius() / 3.f));
int S3 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x - m_ProximityRadius / 3.f, m_Pos.y - m_ProximityRadius / 3.f)); int S3 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x - GetProximityRadius() / 3.f, m_Pos.y - GetProximityRadius() / 3.f));
int S4 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x - m_ProximityRadius / 3.f, m_Pos.y + m_ProximityRadius / 3.f)); int S4 = GameServer()->Collision()->GetPureMapIndex(vec2(m_Pos.x - GetProximityRadius() / 3.f, m_Pos.y + GetProximityRadius() / 3.f));
int Tile1 = GameServer()->Collision()->GetTileIndex(S1); int Tile1 = GameServer()->Collision()->GetTileIndex(S1);
int Tile2 = GameServer()->Collision()->GetTileIndex(S2); int Tile2 = GameServer()->Collision()->GetTileIndex(S2);
int Tile3 = GameServer()->Collision()->GetTileIndex(S3); int Tile3 = GameServer()->Collision()->GetTileIndex(S3);

View file

@ -4,24 +4,13 @@
#define GAME_SERVER_ENTITIES_CHARACTER_H #define GAME_SERVER_ENTITIES_CHARACTER_H
#include <engine/antibot.h> #include <engine/antibot.h>
#include <game/generated/protocol.h>
#include <game/generated/server_data.h>
#include <game/server/entity.h> #include <game/server/entity.h>
#include <game/server/save.h> #include <game/server/save.h>
#include <game/gamecore.h>
class CAntibot; class CAntibot;
class CGameTeams; class CGameTeams;
struct CAntibotCharacterData; struct CAntibotCharacterData;
enum
{
WEAPON_GAME = -3, // team switching etc
WEAPON_SELF = -2, // console kill command
WEAPON_WORLD = -1, // death tiles etc
};
enum enum
{ {
FAKETUNE_FREEZE = 1, FAKETUNE_FREEZE = 1,

View file

@ -3,7 +3,9 @@
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/gamemodes/DDRace.h> #include <game/server/gamemodes/DDRace.h>
#include <game/server/player.h>
#include "character.h"
#include "door.h" #include "door.h"
CDoor::CDoor(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length, CDoor::CDoor(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length,
@ -64,7 +66,7 @@ void CDoor::Snap(int SnappingClient)
return; return;
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem( CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(
NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
if(!pObj) if(!pObj)
return; return;

View file

@ -6,8 +6,11 @@
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/gamemodes/DDRace.h> #include <game/server/gamemodes/DDRace.h>
#include <game/server/player.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include "character.h"
CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW, CDragger::CDragger(CGameWorld *pGameWorld, vec2 Pos, float Strength, bool NW,
int CaughtTeam, int Layer, int Number) : int CaughtTeam, int Layer, int Number) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER) CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
@ -222,7 +225,7 @@ void CDragger::Snap(int SnappingClient)
if(i == -1) if(i == -1)
{ {
obj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem( obj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(
NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
} }
else else
{ {

View file

@ -3,8 +3,10 @@
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/player.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include "character.h"
#include "gun.h" #include "gun.h"
#include "plasma.h" #include "plasma.h"
@ -121,7 +123,7 @@ void CGun::Snap(int SnappingClient)
int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11; int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11;
if(Char && Char->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()]) && (!Tick)) if(Char && Char->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()]) && (!Tick))
return; return;
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
if(!pObj) if(!pObj)
return; return;

View file

@ -8,6 +8,8 @@
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include "character.h"
CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner, int Type) : CLaser::CLaser(CGameWorld *pGameWorld, vec2 Pos, vec2 Direction, float StartEnergy, int Owner, int Type) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER) CEntity(pGameWorld, CGameWorld::ENTTYPE_LASER)
{ {
@ -273,7 +275,7 @@ void CLaser::Snap(int SnappingClient)
if(!CmaskIsSet(TeamMask, SnappingClient)) if(!CmaskIsSet(TeamMask, SnappingClient))
return; return;
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
if(!pObj) if(!pObj)
return; return;

View file

@ -5,6 +5,9 @@
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/mapitems.h> #include <game/mapitems.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/player.h>
#include "character.h"
CLight::CLight(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length, CLight::CLight(CGameWorld *pGameWorld, vec2 Pos, float Rotation, int Length,
int Layer, int Number) : int Layer, int Number) :
@ -112,7 +115,7 @@ void CLight::Snap(int SnappingClient)
return; return;
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem( CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(
NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
if(!pObj) if(!pObj)
return; return;

View file

@ -3,15 +3,17 @@
#include "pickup.h" #include "pickup.h"
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/player.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include "character.h"
CPickup::CPickup(CGameWorld *pGameWorld, int Type, int SubType, int Layer, int Number) : CPickup::CPickup(CGameWorld *pGameWorld, int Type, int SubType, int Layer, int Number) :
CEntity(pGameWorld, CGameWorld::ENTTYPE_PICKUP) CEntity(pGameWorld, CGameWorld::ENTTYPE_PICKUP, vec2(0, 0), PickupPhysSize)
{ {
m_Type = Type; m_Type = Type;
m_Subtype = SubType; m_Subtype = SubType;
m_ProximityRadius = PickupPhysSize;
m_Layer = Layer; m_Layer = Layer;
m_Number = Number; m_Number = Number;
@ -164,7 +166,7 @@ void CPickup::Snap(int SnappingClient)
return; return;
int Size = Server()->IsSixup(SnappingClient) ? 3 * 4 : sizeof(CNetObj_Pickup); int Size = Server()->IsSixup(SnappingClient) ? 3 * 4 : sizeof(CNetObj_Pickup);
CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, m_ID, Size)); CNetObj_Pickup *pP = static_cast<CNetObj_Pickup *>(Server()->SnapNewItem(NETOBJTYPE_PICKUP, GetID(), Size));
if(!pP) if(!pP)
return; return;

View file

@ -5,8 +5,11 @@
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/gamemodes/DDRace.h> #include <game/server/gamemodes/DDRace.h>
#include <game/server/player.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include "character.h"
const float PLASMA_ACCEL = 1.1f; const float PLASMA_ACCEL = 1.1f;
CPlasma::CPlasma(CGameWorld *pGameWorld, vec2 Pos, vec2 Dir, bool Freeze, CPlasma::CPlasma(CGameWorld *pGameWorld, vec2 Pos, vec2 Dir, bool Freeze,
@ -101,7 +104,7 @@ void CPlasma::Snap(int SnappingClient)
return; return;
CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem( CNetObj_Laser *pObj = static_cast<CNetObj_Laser *>(Server()->SnapNewItem(
NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser)));
if(!pObj) if(!pObj)
return; return;

View file

@ -4,10 +4,13 @@
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/gamemodes/DDRace.h> #include <game/server/gamemodes/DDRace.h>
#include <game/server/player.h>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include "character.h"
CProjectile::CProjectile( CProjectile::CProjectile(
CGameWorld *pGameWorld, CGameWorld *pGameWorld,
int Type, int Type,
@ -316,7 +319,7 @@ void CProjectile::Snap(int SnappingClient)
if(m_Owner != -1 && !CmaskIsSet(TeamMask, SnappingClient)) if(m_Owner != -1 && !CmaskIsSet(TeamMask, SnappingClient))
return; return;
CNetObj_Projectile *pProj = static_cast<CNetObj_Projectile *>(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, m_ID, sizeof(CNetObj_Projectile))); CNetObj_Projectile *pProj = static_cast<CNetObj_Projectile *>(Server()->SnapNewItem(NETOBJTYPE_PROJECTILE, GetID(), sizeof(CNetObj_Projectile)));
if(pProj) if(pProj)
{ {
if(SnappingClient > -1 && GameServer()->m_apPlayers[SnappingClient] && GameServer()->m_apPlayers[SnappingClient]->GetClientVersion() >= VERSION_DDNET_ANTIPING_PROJECTILE) if(SnappingClient > -1 && GameServer()->m_apPlayers[SnappingClient] && GameServer()->m_apPlayers[SnappingClient]->GetClientVersion() >= VERSION_DDNET_ANTIPING_PROJECTILE)

View file

@ -3,17 +3,18 @@
#include "entity.h" #include "entity.h"
#include "gamecontext.h" #include "gamecontext.h"
#include "player.h"
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Entity // Entity
////////////////////////////////////////////////// //////////////////////////////////////////////////
CEntity::CEntity(CGameWorld *pGameWorld, int ObjType) CEntity::CEntity(CGameWorld *pGameWorld, int ObjType, vec2 Pos, int ProximityRadius)
{ {
m_pGameWorld = pGameWorld; m_pGameWorld = pGameWorld;
m_ObjType = ObjType; m_ObjType = ObjType;
m_Pos = vec2(0, 0); m_Pos = Pos;
m_ProximityRadius = 0; m_ProximityRadius = ProximityRadius;
m_MarkedForDestroy = false; m_MarkedForDestroy = false;
m_ID = Server()->SnapNewID(); m_ID = Server()->SnapNewID();

View file

@ -4,60 +4,9 @@
#define GAME_SERVER_ENTITY_H #define GAME_SERVER_ENTITY_H
#include <base/vmath.h> #include <base/vmath.h>
#include <game/server/gameworld.h>
#include <new>
#define MACRO_ALLOC_HEAP() \ #include "alloc.h"
public: \ #include "gameworld.h"
void *operator new(size_t Size) \
{ \
void *p = malloc(Size); \
mem_zero(p, Size); \
return p; \
} \
void operator delete(void *pPtr) \
{ \
free(pPtr); \
} \
\
private:
#define MACRO_ALLOC_POOL_ID() \
public: \
void *operator new(size_t Size, int id); \
void operator delete(void *p, int id); \
void operator delete(void *p); /* NOLINT(misc-new-delete-overloads) */ \
\
private:
#define MACRO_ALLOC_POOL_ID_IMPL(POOLTYPE, PoolSize) \
static char ms_PoolData##POOLTYPE[PoolSize][sizeof(POOLTYPE)] = {{0}}; \
static int ms_PoolUsed##POOLTYPE[PoolSize] = {0}; \
void *POOLTYPE::operator new(size_t Size, int id) \
{ \
dbg_assert(sizeof(POOLTYPE) == Size, "size error"); \
dbg_assert(!ms_PoolUsed##POOLTYPE[id], "already used"); \
/*dbg_msg("pool", "++ %s %d", #POOLTYPE, id);*/ \
ms_PoolUsed##POOLTYPE[id] = 1; \
mem_zero(ms_PoolData##POOLTYPE[id], Size); \
return ms_PoolData##POOLTYPE[id]; \
} \
void POOLTYPE::operator delete(void *p, int id) \
{ \
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
dbg_assert(id == (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE, "invalid id"); \
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
ms_PoolUsed##POOLTYPE[id] = 0; \
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
} \
void POOLTYPE::operator delete(void *p) /* NOLINT(misc-new-delete-overloads) */ \
{ \
int id = (POOLTYPE *)p - (POOLTYPE *)ms_PoolData##POOLTYPE; \
dbg_assert(ms_PoolUsed##POOLTYPE[id], "not used"); \
/*dbg_msg("pool", "-- %s %d", #POOLTYPE, id);*/ \
ms_PoolUsed##POOLTYPE[id] = 0; \
mem_zero(ms_PoolData##POOLTYPE[id], sizeof(POOLTYPE)); \
}
/* /*
Class: Entity Class: Entity
@ -67,50 +16,86 @@ class CEntity
{ {
MACRO_ALLOC_HEAP() MACRO_ALLOC_HEAP()
private:
friend class CGameWorld; // entity list handling friend class CGameWorld; // entity list handling
CEntity *m_pPrevTypeEntity; CEntity *m_pPrevTypeEntity;
CEntity *m_pNextTypeEntity; CEntity *m_pNextTypeEntity;
protected: /* Identity */
class CGameWorld *m_pGameWorld; class CGameWorld *m_pGameWorld;
bool m_MarkedForDestroy;
int m_ID; int m_ID;
int m_ObjType; int m_ObjType;
public: /*
CEntity(CGameWorld *pGameWorld, int Objtype); Variable: m_ProximityRadius
virtual ~CEntity(); Contains the physical size of the entity.
*/
float m_ProximityRadius;
class CGameWorld *GameWorld() { return m_pGameWorld; } /* State */
class CGameContext *GameServer() { return GameWorld()->GameServer(); } bool m_MarkedForDestroy;
class IServer *Server() { return GameWorld()->Server(); }
CEntity *TypeNext() { return m_pNextTypeEntity; } public: // TODO: Maybe make protected
CEntity *TypePrev() { return m_pPrevTypeEntity; } /* State */
/* /*
Function: destroy Variable: m_Pos
Contains the current posititon of the entity.
*/
vec2 m_Pos;
/* Getters */
int GetID() const { return m_ID; }
public:
/* Constructor */
CEntity(CGameWorld *pGameWorld, int Objtype, vec2 Pos = vec2(0, 0), int ProximityRadius = 0);
/* Destructor */
virtual ~CEntity();
/* Objects */
class CGameWorld *GameWorld() { return m_pGameWorld; }
class CConfig *Config() { return m_pGameWorld->Config(); }
class CGameContext *GameServer() { return m_pGameWorld->GameServer(); }
class IServer *Server() { return m_pGameWorld->Server(); }
/* Getters */
CEntity *TypeNext() { return m_pNextTypeEntity; }
CEntity *TypePrev() { return m_pPrevTypeEntity; }
const vec2 &GetPos() const { return m_Pos; }
float GetProximityRadius() const { return m_ProximityRadius; }
bool IsMarkedForDestroy() const { return m_MarkedForDestroy; }
/* Setters */
void MarkForDestroy() { m_MarkedForDestroy = true; }
/* Other functions */
/*
Function: Destroy
Destroys the entity. Destroys the entity.
*/ */
virtual void Destroy() { delete this; } virtual void Destroy() { delete this; }
/* /*
Function: reset Function: Reset
Called when the game resets the map. Puts the entity Called when the game resets the map. Puts the entity
back to it's starting state or perhaps destroys it. back to its starting state or perhaps destroys it.
*/ */
virtual void Reset() {} virtual void Reset() {}
/* /*
Function: tick Function: Tick
Called progress the entity to the next tick. Updates Called to progress the entity to the next tick. Updates
and moves the entity to it's new state and position. and moves the entity to its new state and position.
*/ */
virtual void Tick() {} virtual void Tick() {}
/* /*
Function: tick_defered Function: TickDefered
Called after all entities tick() function has been called. Called after all entities Tick() function has been called.
*/ */
virtual void TickDefered() {} virtual void TickDefered() {}
@ -121,12 +106,12 @@ public:
virtual void TickPaused() {} virtual void TickPaused() {}
/* /*
Function: snap Function: Snap
Called when a new snapshot is being generated for a specific Called when a new snapshot is being generated for a specific
client. client.
Arguments: Arguments:
snapping_client - ID of the client which snapshot is SnappingClient - ID of the client which snapshot is
being generated. Could be -1 to create a complete being generated. Could be -1 to create a complete
snapshot of everything in the game for demo snapshot of everything in the game for demo
recording. recording.
@ -139,7 +124,7 @@ public:
entity. entity.
Arguments: Arguments:
snapping_client - ID of the client which snapshot is SnappingClient - ID of the client which snapshot is
being generated. Could be -1 to create a complete being generated. Could be -1 to create a complete
snapshot of everything in the game for demo snapshot of everything in the game for demo
recording. recording.
@ -152,18 +137,6 @@ public:
bool GameLayerClipped(vec2 CheckPos); bool GameLayerClipped(vec2 CheckPos);
/*
Variable: proximity_radius
Contains the physical size of the entity.
*/
float m_ProximityRadius;
/*
Variable: pos
Contains the current posititon of the entity.
*/
vec2 m_Pos;
// DDRace // DDRace
bool GetNearestAirPos(vec2 Pos, vec2 ColPos, vec2 *pOutPos); bool GetNearestAirPos(vec2 Pos, vec2 ColPos, vec2 *pOutPos);

View file

@ -2,6 +2,7 @@
/* 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. */
#include "eventhandler.h" #include "eventhandler.h"
#include "gamecontext.h" #include "gamecontext.h"
#include "player.h"
////////////////////////////////////////////////// //////////////////////////////////////////////////
// Event handler // Event handler

View file

@ -13,17 +13,19 @@
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <engine/shared/datafile.h> #include <engine/shared/datafile.h>
#include <engine/shared/linereader.h> #include <engine/shared/linereader.h>
#include <engine/shared/memheap.h>
#include <engine/storage.h> #include <engine/storage.h>
#include <game/collision.h> #include <game/collision.h>
#include <game/gamecore.h> #include <game/gamecore.h>
#include <game/version.h> #include <game/version.h>
#include <new>
#include <string.h> #include <string.h>
#include <game/generated/protocol7.h> #include <game/generated/protocol7.h>
#include <game/generated/protocolglue.h> #include <game/generated/protocolglue.h>
#include "entities/character.h"
#include "gamemodes/DDRace.h" #include "gamemodes/DDRace.h"
#include "player.h"
#include "score.h" #include "score.h"
enum enum
@ -469,6 +471,28 @@ void CGameContext::SendWeaponPickup(int ClientID, int Weapon)
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID); Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
} }
void CGameContext::SendMotd(int ClientID)
{
CNetMsg_Sv_Motd Msg;
Msg.m_pMessage = g_Config.m_SvMotd;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
}
void CGameContext::SendSettings(int ClientID)
{
if(Server()->IsSixup(ClientID))
{
protocol7::CNetMsg_Sv_ServerSettings Msg;
Msg.m_KickVote = g_Config.m_SvVoteKick;
Msg.m_KickMin = g_Config.m_SvVoteKickMin;
Msg.m_SpecVote = g_Config.m_SvVoteSpectate;
Msg.m_TeamLock = 0;
Msg.m_TeamBalance = 0;
Msg.m_PlayerSlots = g_Config.m_SvMaxClients - g_Config.m_SvSpectatorSlots;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, ClientID);
}
}
void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImportant) void CGameContext::SendBroadcast(const char *pText, int ClientID, bool IsImportant)
{ {
CNetMsg_Sv_Broadcast Msg; CNetMsg_Sv_Broadcast Msg;
@ -1361,23 +1385,8 @@ void CGameContext::OnClientConnected(int ClientID)
} }
#endif #endif
// send motd SendMotd(ClientID);
CNetMsg_Sv_Motd Msg; SendSettings(ClientID);
Msg.m_pMessage = g_Config.m_SvMotd;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
//send sixup settings
if(Server()->IsSixup(ClientID))
{
protocol7::CNetMsg_Sv_ServerSettings Msg;
Msg.m_KickVote = g_Config.m_SvVoteKick;
Msg.m_KickMin = g_Config.m_SvVoteKickMin;
Msg.m_SpecVote = g_Config.m_SvVoteSpectate;
Msg.m_TeamLock = 0;
Msg.m_TeamBalance = 0;
Msg.m_PlayerSlots = g_Config.m_SvMaxClients - g_Config.m_SvSpectatorSlots;
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_NORECORD, ClientID);
}
Server()->ExpireServerInfo(); Server()->ExpireServerInfo();
} }
@ -2989,18 +2998,15 @@ void CGameContext::ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *p
pfnCallback(pResult, pCallbackUserData); pfnCallback(pResult, pCallbackUserData);
if(pResult->NumArguments()) if(pResult->NumArguments())
{ {
CNetMsg_Sv_Motd Msg;
Msg.m_pMessage = g_Config.m_SvMotd;
CGameContext *pSelf = (CGameContext *)pUserData; CGameContext *pSelf = (CGameContext *)pUserData;
for(int i = 0; i < MAX_CLIENTS; ++i) pSelf->SendMotd(-1);
if(pSelf->m_apPlayers[i])
pSelf->Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, i);
} }
} }
void CGameContext::OnConsoleInit() void CGameContext::OnConsoleInit()
{ {
m_pServer = Kernel()->RequestInterface<IServer>(); m_pServer = Kernel()->RequestInterface<IServer>();
m_pConfig = Kernel()->RequestInterface<IConfigManager>()->Values();
m_pConsole = Kernel()->RequestInterface<IConsole>(); m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pEngine = Kernel()->RequestInterface<IEngine>(); m_pEngine = Kernel()->RequestInterface<IEngine>();
m_pStorage = Kernel()->RequestInterface<IStorage>(); m_pStorage = Kernel()->RequestInterface<IStorage>();
@ -3047,6 +3053,7 @@ void CGameContext::OnConsoleInit()
void CGameContext::OnInit(/*class IKernel *pKernel*/) void CGameContext::OnInit(/*class IKernel *pKernel*/)
{ {
m_pServer = Kernel()->RequestInterface<IServer>(); m_pServer = Kernel()->RequestInterface<IServer>();
m_pConfig = Kernel()->RequestInterface<IConfigManager>()->Values();
m_pConsole = Kernel()->RequestInterface<IConsole>(); m_pConsole = Kernel()->RequestInterface<IConsole>();
m_pEngine = Kernel()->RequestInterface<IEngine>(); m_pEngine = Kernel()->RequestInterface<IEngine>();
m_pStorage = Kernel()->RequestInterface<IStorage>(); m_pStorage = Kernel()->RequestInterface<IStorage>();

View file

@ -6,7 +6,6 @@
#include <engine/antibot.h> #include <engine/antibot.h>
#include <engine/console.h> #include <engine/console.h>
#include <engine/server.h> #include <engine/server.h>
#include <engine/shared/memheap.h>
#include <game/layers.h> #include <game/layers.h>
#include <game/mapbugs.h> #include <game/mapbugs.h>
@ -16,9 +15,8 @@
#include <base/tl/string.h> #include <base/tl/string.h>
#include "eventhandler.h" #include "eventhandler.h"
#include "gamecontroller.h" //#include "gamecontroller.h"
#include "gameworld.h" #include "gameworld.h"
#include "player.h"
#include "teehistorian.h" #include "teehistorian.h"
#include <memory> #include <memory>
@ -58,8 +56,12 @@ enum
NUM_TUNEZONES = 256 NUM_TUNEZONES = 256
}; };
class CConfig;
class CHeap;
class CPlayer;
class CScore; class CScore;
class IConsole; class IConsole;
class IGameController;
class IEngine; class IEngine;
class IStorage; class IStorage;
struct CAntibotData; struct CAntibotData;
@ -68,6 +70,7 @@ struct CScoreRandomMapResult;
class CGameContext : public IGameServer class CGameContext : public IGameServer
{ {
IServer *m_pServer; IServer *m_pServer;
CConfig *m_pConfig;
IConsole *m_pConsole; IConsole *m_pConsole;
IEngine *m_pEngine; IEngine *m_pEngine;
IStorage *m_pStorage; IStorage *m_pStorage;
@ -130,6 +133,7 @@ class CGameContext : public IGameServer
public: public:
IServer *Server() const { return m_pServer; } IServer *Server() const { return m_pServer; }
CConfig *Config() { return m_pConfig; }
IConsole *Console() { return m_pConsole; } IConsole *Console() { return m_pConsole; }
IEngine *Engine() { return m_pEngine; } IEngine *Engine() { return m_pEngine; }
IStorage *Storage() { return m_pStorage; } IStorage *Storage() { return m_pStorage; }
@ -219,6 +223,8 @@ public:
void SendChat(int ClientID, int Team, const char *pText, int SpamProtectionClientID = -1, int Flags = CHAT_SIX | CHAT_SIXUP); void SendChat(int ClientID, int Team, const char *pText, int SpamProtectionClientID = -1, int Flags = CHAT_SIX | CHAT_SIXUP);
void SendEmoticon(int ClientID, int Emoticon); void SendEmoticon(int ClientID, int Emoticon);
void SendWeaponPickup(int ClientID, int Weapon); void SendWeaponPickup(int ClientID, int Weapon);
void SendMotd(int ClientID);
void SendSettings(int ClientID);
void SendBroadcast(const char *pText, int ClientID, bool IsImportant = true); void SendBroadcast(const char *pText, int ClientID, bool IsImportant = true);
void List(int ClientID, const char *filter); void List(int ClientID, const char *filter);

View file

@ -5,9 +5,11 @@
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include "entities/character.h"
#include "entities/pickup.h" #include "entities/pickup.h"
#include "gamecontext.h" #include "gamecontext.h"
#include "gamecontroller.h" #include "gamecontroller.h"
#include "player.h"
#include "entities/door.h" #include "entities/door.h"
#include "entities/dragger.h" #include "entities/dragger.h"
@ -20,6 +22,7 @@
IGameController::IGameController(class CGameContext *pGameServer) IGameController::IGameController(class CGameContext *pGameServer)
{ {
m_pGameServer = pGameServer; m_pGameServer = pGameServer;
m_pConfig = m_pGameServer->Config();
m_pServer = m_pGameServer->Server(); m_pServer = m_pGameServer->Server();
m_pGameType = "unknown"; m_pGameType = "unknown";
@ -81,7 +84,7 @@ void IGameController::EvaluateSpawnType(CSpawnEval *pEval, int Type)
break; break;
for(int c = 0; c < Num; ++c) for(int c = 0; c < Num; ++c)
if(GameServer()->Collision()->CheckPoint(m_aaSpawnPoints[Type][i] + Positions[Index]) || if(GameServer()->Collision()->CheckPoint(m_aaSpawnPoints[Type][i] + Positions[Index]) ||
distance(aEnts[c]->m_Pos, m_aaSpawnPoints[Type][i] + Positions[Index]) <= aEnts[c]->m_ProximityRadius) distance(aEnts[c]->m_Pos, m_aaSpawnPoints[Type][i] + Positions[Index]) <= aEnts[c]->GetProximityRadius())
{ {
Result = -1; Result = -1;
break; break;

View file

@ -29,10 +29,12 @@ class IGameController
int m_aNumSpawnPoints[3]; int m_aNumSpawnPoints[3];
class CGameContext *m_pGameServer; class CGameContext *m_pGameServer;
class CConfig *m_pConfig;
class IServer *m_pServer; class IServer *m_pServer;
protected: protected:
CGameContext *GameServer() const { return m_pGameServer; } CGameContext *GameServer() const { return m_pGameServer; }
CConfig *Config() { return m_pConfig; }
IServer *Server() const { return m_pServer; } IServer *Server() const { return m_pServer; }
struct CSpawnEval struct CSpawnEval

View file

@ -2,8 +2,10 @@
/* 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. */
#include "gameworld.h" #include "gameworld.h"
#include "entities/character.h"
#include "entity.h" #include "entity.h"
#include "gamecontext.h" #include "gamecontext.h"
#include "player.h"
#include <algorithm> #include <algorithm>
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <utility> #include <utility>
@ -14,6 +16,7 @@
CGameWorld::CGameWorld() CGameWorld::CGameWorld()
{ {
m_pGameServer = 0x0; m_pGameServer = 0x0;
m_pConfig = 0x0;
m_pServer = 0x0; m_pServer = 0x0;
m_Paused = false; m_Paused = false;
@ -33,6 +36,7 @@ CGameWorld::~CGameWorld()
void CGameWorld::SetGameServer(CGameContext *pGameServer) void CGameWorld::SetGameServer(CGameContext *pGameServer)
{ {
m_pGameServer = pGameServer; m_pGameServer = pGameServer;
m_pConfig = m_pGameServer->Config();
m_pServer = m_pGameServer->Server(); m_pServer = m_pGameServer->Server();
} }

View file

@ -36,12 +36,14 @@ private:
CEntity *m_apFirstEntityTypes[NUM_ENTTYPES]; CEntity *m_apFirstEntityTypes[NUM_ENTTYPES];
class CGameContext *m_pGameServer; class CGameContext *m_pGameServer;
class CConfig *m_pConfig;
class IServer *m_pServer; class IServer *m_pServer;
void UpdatePlayerMaps(); void UpdatePlayerMaps();
public: public:
class CGameContext *GameServer() { return m_pGameServer; } class CGameContext *GameServer() { return m_pGameServer; }
class CConfig *Config() { return m_pConfig; }
class IServer *Server() { return m_pServer; } class IServer *Server() { return m_pServer; }
bool m_ResetRequested; bool m_ResetRequested;

View file

@ -2,15 +2,14 @@
/* 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. */
#include "player.h" #include "player.h"
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <new>
#include "entities/character.h"
#include "gamecontext.h" #include "gamecontext.h"
#include "gamemodes/DDRace.h" #include "gamemodes/DDRace.h"
#include <engine/server.h> #include <engine/server.h>
#include <game/gamecore.h> #include <game/gamecore.h>
#include <game/server/teams.h> #include <game/server/teams.h>
#include <game/version.h> #include <game/version.h>
#include <time.h>
MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS) MACRO_ALLOC_POOL_ID_IMPL(CPlayer, MAX_CLIENTS)

View file

@ -3,12 +3,18 @@
#ifndef GAME_SERVER_PLAYER_H #ifndef GAME_SERVER_PLAYER_H
#define GAME_SERVER_PLAYER_H #define GAME_SERVER_PLAYER_H
#include "alloc.h"
// this include should perhaps be removed // this include should perhaps be removed
#include "entities/character.h"
#include "gamecontext.h"
#include "score.h" #include "score.h"
#include "teeinfo.h" #include "teeinfo.h"
#include <memory>
enum
{
WEAPON_GAME = -3, // team switching etc
WEAPON_SELF = -2, // console kill command
WEAPON_WORLD = -1, // death tiles etc
};
// player object // player object
class CPlayer class CPlayer

View file

@ -3,7 +3,9 @@
#include <cstdio> #include <cstdio>
#include <new> #include <new>
#include "entities/character.h"
#include "gamemodes/DDRace.h" #include "gamemodes/DDRace.h"
#include "player.h"
#include "teams.h" #include "teams.h"
#include <engine/shared/config.h> #include <engine/shared/config.h>

View file

@ -1,6 +1,7 @@
#include "score.h" #include "score.h"
#include "entities/character.h" #include "entities/character.h"
#include "gamemodes/DDRace.h" #include "gamemodes/DDRace.h"
#include "player.h"
#include "save.h" #include "save.h"
#include <base/system.h> #include <base/system.h>

View file

@ -4,6 +4,9 @@
#include "teehistorian.h" #include "teehistorian.h"
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include "entities/character.h"
#include "player.h"
CGameTeams::CGameTeams(CGameContext *pGameContext) : CGameTeams::CGameTeams(CGameContext *pGameContext) :
m_pGameContext(pGameContext) m_pGameContext(pGameContext)
{ {

View file

@ -4,6 +4,7 @@
#include <engine/shared/config.h> #include <engine/shared/config.h>
#include <game/server/gamecontext.h> #include <game/server/gamecontext.h>
#include <game/server/score.h>
#include <game/teamscore.h> #include <game/teamscore.h>
#include <utility> #include <utility>

View file

@ -9,7 +9,7 @@
#include <time.h> #include <time.h>
struct CConfiguration; class CConfig;
class CTuningParams; class CTuningParams;
class CUuidManager; class CUuidManager;
@ -34,7 +34,7 @@ public:
SHA256_DIGEST m_MapSha256; SHA256_DIGEST m_MapSha256;
int m_MapCrc; int m_MapCrc;
CConfiguration *m_pConfig; CConfig *m_pConfig;
CTuningParams *m_pTuning; CTuningParams *m_pTuning;
CUuidManager *m_pUuids; CUuidManager *m_pUuids;
}; };

View file

@ -332,17 +332,18 @@ int main(int argc, const char **argv) // ignore_convention
IKernel *pKernel = IKernel::Create(); IKernel *pKernel = IKernel::Create();
IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv); IStorage *pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv);
IConfig *pConfig = CreateConfig(); IConfigManager *pConfigManager = CreateConfigManager();
m_pConsole = CreateConsole(CFGFLAG_MASTER); m_pConsole = CreateConsole(CFGFLAG_MASTER);
bool RegisterFail = !pKernel->RegisterInterface(pStorage); bool RegisterFail = !pKernel->RegisterInterface(pStorage);
RegisterFail |= !pKernel->RegisterInterface(m_pConsole); RegisterFail |= !pKernel->RegisterInterface(m_pConsole);
RegisterFail |= !pKernel->RegisterInterface(pConfig); RegisterFail |= !pKernel->RegisterInterface(pConfigManager);
if(RegisterFail) if(RegisterFail)
return -1; return -1;
pConfig->Init(); pConfigManager->Init();
m_pConsole->Init();
m_NetBan.Init(m_pConsole, pStorage); m_NetBan.Init(m_pConsole, pStorage);
if(argc > 1) // ignore_convention if(argc > 1) // ignore_convention
m_pConsole->ParseArguments(argc - 1, &argv[1]); // ignore_convention m_pConsole->ParseArguments(argc - 1, &argv[1]); // ignore_convention

View file

@ -12,7 +12,7 @@ class TeeHistorian : public ::testing::Test
{ {
protected: protected:
CTeeHistorian m_TH; CTeeHistorian m_TH;
CConfiguration m_Config; CConfig m_Config;
CTuningParams m_Tuning; CTuningParams m_Tuning;
CUuidManager m_UuidManager; CUuidManager m_UuidManager;
CTeeHistorian::CGameInfo m_GameInfo; CTeeHistorian::CGameInfo m_GameInfo;