2019-04-11 22:46:54 +00:00
|
|
|
/* (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_CLIENT_PREDICTION_GAMEWORLD_H
|
|
|
|
#define GAME_CLIENT_PREDICTION_GAMEWORLD_H
|
|
|
|
|
|
|
|
#include <game/gamecore.h>
|
2022-06-16 16:06:35 +00:00
|
|
|
#include <game/teamscore.h>
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
2022-06-16 16:06:35 +00:00
|
|
|
class CCollision;
|
2019-04-11 22:46:54 +00:00
|
|
|
class CCharacter;
|
2022-06-16 16:06:35 +00:00
|
|
|
class CEntity;
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
class CGameWorld
|
|
|
|
{
|
2022-06-16 16:06:35 +00:00
|
|
|
friend CCharacter;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2019-04-11 22:46:54 +00:00
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ENTTYPE_PROJECTILE = 0,
|
|
|
|
ENTTYPE_LASER,
|
|
|
|
ENTTYPE_PICKUP,
|
|
|
|
ENTTYPE_FLAG,
|
|
|
|
ENTTYPE_CHARACTER,
|
|
|
|
NUM_ENTTYPES
|
|
|
|
};
|
|
|
|
|
|
|
|
CWorldCore m_Core;
|
2019-06-16 14:31:06 +00:00
|
|
|
CTeamsCore m_Teams;
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
CGameWorld();
|
|
|
|
~CGameWorld();
|
|
|
|
|
|
|
|
CEntity *FindFirst(int Type);
|
|
|
|
CEntity *FindLast(int Type);
|
|
|
|
int FindEntities(vec2 Pos, float Radius, CEntity **ppEnts, int Max, int Type);
|
Mark parameters as `const` when possible
According to cppchecker's `constParameter` error:
```
src\engine\gfx\image_manipulation.cpp:7:58: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void Dilate(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest, unsigned char AlphaThreshold = TW_DILATE_ALPHA_THRESHOLD)
^
src\engine\gfx\image_manipulation.cpp:58:67: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void CopyColorValues(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest)
^
src\engine\shared\network_conn.cpp:241:42: style: Parameter 'Addr' can be declared as reference to const [constParameter]
void CNetConnection::DirectInit(NETADDR &Addr, SECURITY_TOKEN SecurityToken, SECURITY_TOKEN Token, bool Sixup)
^
src\base\system.cpp:4060:71: style: Parameter 'random' can be declared as pointer to const [constParameter]
void generate_password(char *buffer, unsigned length, unsigned short *random, unsigned random_length)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:263:38: style: Parameter 'AllocatedMemory' can be declared as reference to const [constParameter]
void Free(SMemoryHeapQueueElement &AllocatedMemory)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:1708:47: style: Parameter 'ImgExtent' can be declared as reference to const [constParameter]
static size_t ImageMipLevelCount(VkExtent3D &ImgExtent)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:2801:29: style: Parameter 'Image' can be declared as reference to const [constParameter]
void ImageBarrier(VkImage &Image, size_t MipMapBase, size_t MipMapCount, size_t LayerBase, size_t LayerCount, VkFormat Format, VkImageLayout OldLayout, VkImageLayout NewLayout)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6495:46: style: Parameter 'ExecBuffer' can be declared as reference to const [constParameter]
void Cmd_Clear(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand_Clear *pCommand)
^
src\game\client\components\skins.cpp:83:72: style: Parameter 'pImg' can be declared as pointer to const [constParameter]
static void CheckMetrics(CSkin::SSkinMetricVariable &Metrics, uint8_t *pImg, int ImgWidth, int ImgX, int ImgY, int CheckWidth, int CheckHeight)
^
src\game\client\prediction\entities\character.h:106:37: style: Parameter 'pNewInput' can be declared as pointer to const [constParameter]
void SetInput(CNetObj_PlayerInput *pNewInput)
^
src\game\client\prediction\gameworld.cpp:245:106: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
^
src\game\client\prediction\gameworld.cpp:245:151: style: Parameter 'pThisOnly' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
^
src\game\client\prediction\gameworld.cpp:283:116: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
std::list<class CCharacter *> CGameWorld::IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, class CEntity *pNotThis)
^
src\game\client\ui.cpp:522:180: style: Parameter 'pReadCursor' can be declared as pointer to const [constParameter]
void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps, int StrLen, CTextCursor *pReadCursor)
^
src\game\client\ui_scrollregion.cpp:23:86: style: Parameter 'pParams' can be declared as pointer to const [constParameter]
void CScrollRegion::Begin(CUIRect *pClipRect, vec2 *pOutOffset, CScrollRegionParams *pParams)
^
src\game\server\scoreworker.h:239:29: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
void Set(float Time, float aTimeCp[NUM_CHECKPOINTS])
^
src\game\server\score.cpp:135:80: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
void CScore::SaveScore(int ClientID, float Time, const char *pTimestamp, float aTimeCp[NUM_CHECKPOINTS], bool NotEligible)
^
src\game\server\teeinfo.cpp:40:57: style: Parameter 'pUseCustomColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
^
src\game\server\teeinfo.cpp:40:80: style: Parameter 'pSkinPartColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
^
```
2022-11-13 14:32:53 +00:00
|
|
|
CCharacter *IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, const CCharacter *pNotThis = nullptr, int CollideWith = -1, const CCharacter *pThisOnly = nullptr);
|
2019-04-11 22:46:54 +00:00
|
|
|
void InsertEntity(CEntity *pEntity, bool Last = false);
|
|
|
|
void RemoveEntity(CEntity *pEntity);
|
2022-05-26 17:04:13 +00:00
|
|
|
void RemoveCharacter(CCharacter *pChar);
|
2019-04-11 22:46:54 +00:00
|
|
|
void Tick();
|
|
|
|
|
|
|
|
// DDRace
|
|
|
|
void ReleaseHooked(int ClientID);
|
Mark parameters as `const` when possible
According to cppchecker's `constParameter` error:
```
src\engine\gfx\image_manipulation.cpp:7:58: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void Dilate(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest, unsigned char AlphaThreshold = TW_DILATE_ALPHA_THRESHOLD)
^
src\engine\gfx\image_manipulation.cpp:58:67: style: Parameter 'pSrc' can be declared as pointer to const [constParameter]
static void CopyColorValues(int w, int h, int BPP, unsigned char *pSrc, unsigned char *pDest)
^
src\engine\shared\network_conn.cpp:241:42: style: Parameter 'Addr' can be declared as reference to const [constParameter]
void CNetConnection::DirectInit(NETADDR &Addr, SECURITY_TOKEN SecurityToken, SECURITY_TOKEN Token, bool Sixup)
^
src\base\system.cpp:4060:71: style: Parameter 'random' can be declared as pointer to const [constParameter]
void generate_password(char *buffer, unsigned length, unsigned short *random, unsigned random_length)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:263:38: style: Parameter 'AllocatedMemory' can be declared as reference to const [constParameter]
void Free(SMemoryHeapQueueElement &AllocatedMemory)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:1708:47: style: Parameter 'ImgExtent' can be declared as reference to const [constParameter]
static size_t ImageMipLevelCount(VkExtent3D &ImgExtent)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:2801:29: style: Parameter 'Image' can be declared as reference to const [constParameter]
void ImageBarrier(VkImage &Image, size_t MipMapBase, size_t MipMapCount, size_t LayerBase, size_t LayerCount, VkFormat Format, VkImageLayout OldLayout, VkImageLayout NewLayout)
^
src\engine\client\backend\vulkan\backend_vulkan.cpp:6495:46: style: Parameter 'ExecBuffer' can be declared as reference to const [constParameter]
void Cmd_Clear(SRenderCommandExecuteBuffer &ExecBuffer, const CCommandBuffer::SCommand_Clear *pCommand)
^
src\game\client\components\skins.cpp:83:72: style: Parameter 'pImg' can be declared as pointer to const [constParameter]
static void CheckMetrics(CSkin::SSkinMetricVariable &Metrics, uint8_t *pImg, int ImgWidth, int ImgX, int ImgY, int CheckWidth, int CheckHeight)
^
src\game\client\prediction\entities\character.h:106:37: style: Parameter 'pNewInput' can be declared as pointer to const [constParameter]
void SetInput(CNetObj_PlayerInput *pNewInput)
^
src\game\client\prediction\gameworld.cpp:245:106: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
^
src\game\client\prediction\gameworld.cpp:245:151: style: Parameter 'pThisOnly' can be declared as pointer to const [constParameter]
CCharacter *CGameWorld::IntersectCharacter(vec2 Pos0, vec2 Pos1, float Radius, vec2 &NewPos, CCharacter *pNotThis, int CollideWith, class CCharacter *pThisOnly)
^
src\game\client\prediction\gameworld.cpp:283:116: style: Parameter 'pNotThis' can be declared as pointer to const [constParameter]
std::list<class CCharacter *> CGameWorld::IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, class CEntity *pNotThis)
^
src\game\client\ui.cpp:522:180: style: Parameter 'pReadCursor' can be declared as pointer to const [constParameter]
void CUI::DoLabel(CUIElement::SUIElementRect &RectEl, const CUIRect *pRect, const char *pText, float Size, int Align, const SLabelProperties &LabelProps, int StrLen, CTextCursor *pReadCursor)
^
src\game\client\ui_scrollregion.cpp:23:86: style: Parameter 'pParams' can be declared as pointer to const [constParameter]
void CScrollRegion::Begin(CUIRect *pClipRect, vec2 *pOutOffset, CScrollRegionParams *pParams)
^
src\game\server\scoreworker.h:239:29: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
void Set(float Time, float aTimeCp[NUM_CHECKPOINTS])
^
src\game\server\score.cpp:135:80: style: Parameter 'aTimeCp' can be declared as const array [constParameter]
void CScore::SaveScore(int ClientID, float Time, const char *pTimestamp, float aTimeCp[NUM_CHECKPOINTS], bool NotEligible)
^
src\game\server\teeinfo.cpp:40:57: style: Parameter 'pUseCustomColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
^
src\game\server\teeinfo.cpp:40:80: style: Parameter 'pSkinPartColors' can be declared as pointer to const [constParameter]
CTeeInfo::CTeeInfo(const char *apSkinPartNames[6], int *pUseCustomColors, int *pSkinPartColors)
^
```
2022-11-13 14:32:53 +00:00
|
|
|
std::list<CCharacter *> IntersectedCharacters(vec2 Pos0, vec2 Pos1, float Radius, const CEntity *pNotThis = nullptr);
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
int m_GameTick;
|
|
|
|
int m_GameTickSpeed;
|
|
|
|
CCollision *m_pCollision;
|
|
|
|
|
|
|
|
// getter for server variables
|
|
|
|
int GameTick() { return m_GameTick; }
|
|
|
|
int GameTickSpeed() { return m_GameTickSpeed; }
|
2022-06-16 16:06:35 +00:00
|
|
|
CCollision *Collision() { return m_pCollision; }
|
2019-06-16 14:31:06 +00:00
|
|
|
CTeamsCore *Teams() { return &m_Teams; }
|
2022-06-11 19:38:18 +00:00
|
|
|
std::vector<SSwitchers> &Switchers() { return m_Core.m_vSwitchers; }
|
2019-04-11 22:46:54 +00:00
|
|
|
CTuningParams *Tuning();
|
|
|
|
CEntity *GetEntity(int ID, int EntityType);
|
2022-06-16 16:06:35 +00:00
|
|
|
CCharacter *GetCharacterByID(int ID) { return (ID >= 0 && ID < MAX_CLIENTS) ? m_apCharacters[ID] : nullptr; }
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
// from gamecontext
|
2021-06-23 05:05:49 +00:00
|
|
|
void CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, int ActivatedTeam, int64_t Mask);
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
// for client side prediction
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
bool m_IsDDRace;
|
|
|
|
bool m_IsVanilla;
|
|
|
|
bool m_IsFNG;
|
|
|
|
bool m_InfiniteAmmo;
|
|
|
|
bool m_PredictTiles;
|
2019-05-02 20:35:08 +00:00
|
|
|
int m_PredictFreeze;
|
2019-04-11 22:46:54 +00:00
|
|
|
bool m_PredictWeapons;
|
2019-05-03 18:57:01 +00:00
|
|
|
bool m_PredictDDRace;
|
2019-05-11 19:13:09 +00:00
|
|
|
bool m_IsSolo;
|
2021-04-23 03:01:38 +00:00
|
|
|
bool m_UseTuneZones;
|
2022-05-19 21:05:15 +00:00
|
|
|
bool m_BugDDRaceInput;
|
2022-07-19 16:34:49 +00:00
|
|
|
bool m_NoWeakHookAndBounce;
|
2019-04-11 22:46:54 +00:00
|
|
|
} m_WorldConfig;
|
|
|
|
|
|
|
|
bool m_IsValidCopy;
|
|
|
|
CGameWorld *m_pParent;
|
|
|
|
CGameWorld *m_pChild;
|
|
|
|
|
|
|
|
void OnModified();
|
|
|
|
void NetObjBegin();
|
2022-05-24 15:26:49 +00:00
|
|
|
void NetCharAdd(int ObjID, CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtended, int GameTeam, bool IsLocal);
|
2021-09-19 12:14:00 +00:00
|
|
|
void NetObjAdd(int ObjID, int ObjType, const void *pObjData, const CNetObj_EntityEx *pDataEx);
|
2019-04-11 22:46:54 +00:00
|
|
|
void NetObjEnd(int LocalID);
|
|
|
|
void CopyWorld(CGameWorld *pFrom);
|
|
|
|
CEntity *FindMatch(int ObjID, int ObjType, const void *pObjData);
|
|
|
|
void Clear();
|
2019-04-13 23:34:15 +00:00
|
|
|
|
2019-09-08 22:53:07 +00:00
|
|
|
CTuningParams *m_pTuningList;
|
|
|
|
CTuningParams *TuningList() { return m_pTuningList; }
|
2021-05-01 01:51:29 +00:00
|
|
|
CTuningParams *GetTuning(int i) { return &TuningList()[i]; }
|
2019-09-08 22:53:07 +00:00
|
|
|
|
2019-04-13 23:34:15 +00:00
|
|
|
private:
|
|
|
|
void RemoveEntities();
|
|
|
|
|
2022-02-09 14:26:50 +00:00
|
|
|
CEntity *m_pNextTraverseEntity = nullptr;
|
2019-04-13 23:34:15 +00:00
|
|
|
CEntity *m_apFirstEntityTypes[NUM_ENTTYPES];
|
|
|
|
|
2022-06-16 16:06:35 +00:00
|
|
|
CCharacter *m_apCharacters[MAX_CLIENTS];
|
2019-04-11 22:46:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class CCharOrder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::list<int> m_IDs; // reverse of the order in the gameworld, since entities will be inserted in reverse
|
|
|
|
CCharOrder()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < MAX_CLIENTS; i++)
|
|
|
|
m_IDs.push_back(i);
|
|
|
|
}
|
|
|
|
void GiveStrong(int c)
|
|
|
|
{
|
|
|
|
if(0 <= c && c < MAX_CLIENTS)
|
|
|
|
{
|
|
|
|
m_IDs.remove(c);
|
|
|
|
m_IDs.push_front(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void GiveWeak(int c)
|
|
|
|
{
|
|
|
|
if(0 <= c && c < MAX_CLIENTS)
|
|
|
|
{
|
|
|
|
m_IDs.remove(c);
|
|
|
|
m_IDs.push_back(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool HasStrongAgainst(int From, int To)
|
|
|
|
{
|
|
|
|
for(int i : m_IDs)
|
|
|
|
{
|
|
|
|
if(i == To)
|
|
|
|
return false;
|
|
|
|
else if(i == From)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|