2010-11-20 10:37:14 +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. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#ifndef ENGINE_CLIENT_H
|
|
|
|
#define ENGINE_CLIENT_H
|
|
|
|
#include "kernel.h"
|
|
|
|
|
2012-08-12 10:41:50 +00:00
|
|
|
#include "graphics.h"
|
2020-09-26 19:41:58 +00:00
|
|
|
#include "message.h"
|
2020-10-10 20:58:33 +00:00
|
|
|
#include <base/hash.h>
|
2015-07-22 20:16:49 +00:00
|
|
|
#include <engine/friends.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2020-10-02 13:43:52 +00:00
|
|
|
struct SWarning;
|
|
|
|
|
2014-10-16 15:42:13 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
RECORDER_MANUAL = 0,
|
|
|
|
RECORDER_AUTO = 1,
|
|
|
|
RECORDER_RACE = 2,
|
|
|
|
RECORDER_REPLAYS = 3,
|
|
|
|
RECORDER_MAX = 4,
|
2020-10-18 14:51:26 +00:00
|
|
|
|
|
|
|
NUM_DUMMIES = 2,
|
2014-10-16 15:42:13 +00:00
|
|
|
};
|
|
|
|
|
2017-02-28 09:08:14 +00:00
|
|
|
typedef bool (*CLIENTFUNC_FILTER)(const void *pData, int DataSize, void *pUser);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
class IClient : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("client", 0)
|
|
|
|
protected:
|
|
|
|
// quick access to state of the client
|
|
|
|
int m_State;
|
|
|
|
|
|
|
|
// quick access to time variables
|
2020-10-18 14:51:26 +00:00
|
|
|
int m_PrevGameTick[NUM_DUMMIES];
|
|
|
|
int m_CurGameTick[NUM_DUMMIES];
|
|
|
|
float m_GameIntraTick[NUM_DUMMIES];
|
|
|
|
float m_GameTickTime[NUM_DUMMIES];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2020-10-18 14:51:26 +00:00
|
|
|
int m_PredTick[NUM_DUMMIES];
|
|
|
|
float m_PredIntraTick[NUM_DUMMIES];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
float m_LocalTime;
|
2012-01-01 12:38:46 +00:00
|
|
|
float m_RenderFrameTime;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_GameTickSpeed;
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
float m_FrameTimeAvg;
|
2020-09-26 19:41:58 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
2017-09-03 15:36:51 +00:00
|
|
|
char m_aNews[3000];
|
2021-01-31 10:15:09 +00:00
|
|
|
char m_aMapDownloadUrl[256];
|
2020-10-23 21:25:58 +00:00
|
|
|
int m_Points;
|
2016-05-04 16:23:00 +00:00
|
|
|
int64 m_ReconnectTime;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
class CSnapItem
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int m_Type;
|
2011-02-12 10:40:36 +00:00
|
|
|
int m_ID;
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_DataSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Constants: Client States
|
|
|
|
STATE_OFFLINE - The client is offline.
|
|
|
|
STATE_CONNECTING - The client is trying to connect to a server.
|
|
|
|
STATE_LOADING - The client has connected to a server and is loading resources.
|
|
|
|
STATE_ONLINE - The client is connected to a server and running the game.
|
|
|
|
STATE_DEMOPLAYBACK - The client is playing a demo
|
2020-10-02 13:44:27 +00:00
|
|
|
STATE_QUITTING - The client is quitting.
|
2010-05-29 07:25:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
STATE_OFFLINE = 0,
|
2010-05-29 07:25:38 +00:00
|
|
|
STATE_CONNECTING,
|
|
|
|
STATE_LOADING,
|
|
|
|
STATE_ONLINE,
|
|
|
|
STATE_DEMOPLAYBACK,
|
2020-10-02 13:44:27 +00:00
|
|
|
STATE_QUITTING,
|
2020-01-25 20:00:26 +00:00
|
|
|
STATE_RESTARTING,
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
inline int State() const { return m_State; }
|
|
|
|
|
|
|
|
// tick time access
|
2020-02-19 10:24:58 +00:00
|
|
|
inline int PrevGameTick(int Dummy) const { return m_PrevGameTick[Dummy]; }
|
|
|
|
inline int GameTick(int Dummy) const { return m_CurGameTick[Dummy]; }
|
|
|
|
inline int PredGameTick(int Dummy) const { return m_PredTick[Dummy]; }
|
|
|
|
inline float IntraGameTick(int Dummy) const { return m_GameIntraTick[Dummy]; }
|
|
|
|
inline float PredIntraGameTick(int Dummy) const { return m_PredIntraTick[Dummy]; }
|
|
|
|
inline float GameTickTime(int Dummy) const { return m_GameTickTime[Dummy]; }
|
2010-05-29 07:25:38 +00:00
|
|
|
inline int GameTickSpeed() const { return m_GameTickSpeed; }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// other time access
|
2012-01-01 12:38:46 +00:00
|
|
|
inline float RenderFrameTime() const { return m_RenderFrameTime; }
|
2010-05-29 07:25:38 +00:00
|
|
|
inline float LocalTime() const { return m_LocalTime; }
|
2019-04-11 22:46:54 +00:00
|
|
|
inline float FrameTimeAvg() const { return m_FrameTimeAvg; }
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// actions
|
2017-07-15 15:29:20 +00:00
|
|
|
virtual void Connect(const char *pAddress, const char *pPassword = NULL) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Disconnect() = 0;
|
2014-04-26 18:29:42 +00:00
|
|
|
|
|
|
|
// dummy
|
|
|
|
virtual void DummyDisconnect(const char *pReason) = 0;
|
2014-04-28 13:19:57 +00:00
|
|
|
virtual void DummyConnect() = 0;
|
2014-04-26 18:29:42 +00:00
|
|
|
virtual bool DummyConnected() = 0;
|
2015-04-19 12:40:05 +00:00
|
|
|
virtual bool DummyConnecting() = 0;
|
2014-04-26 18:29:42 +00:00
|
|
|
|
2014-12-31 14:35:49 +00:00
|
|
|
virtual void Restart() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Quit() = 0;
|
2010-10-06 21:07:35 +00:00
|
|
|
virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0;
|
2020-09-26 19:41:58 +00:00
|
|
|
#if defined(CONF_VIDEORECORDER)
|
2019-09-28 04:18:38 +00:00
|
|
|
virtual const char *DemoPlayer_Render(const char *pFilename, int StorageType, const char *pVideoName, int SpeedIndex) = 0;
|
2020-09-26 19:41:58 +00:00
|
|
|
#endif
|
2014-10-16 15:42:13 +00:00
|
|
|
virtual void DemoRecorder_Start(const char *pFilename, bool WithTimestamp, int Recorder) = 0;
|
2011-01-06 22:21:51 +00:00
|
|
|
virtual void DemoRecorder_HandleAutoStart() = 0;
|
2019-05-21 15:21:53 +00:00
|
|
|
virtual void DemoRecorder_Stop(int Recorder, bool RemoveFile = false) = 0;
|
2014-10-16 15:42:13 +00:00
|
|
|
virtual class IDemoRecorder *DemoRecorder(int Recorder) = 0;
|
2010-12-12 15:48:13 +00:00
|
|
|
virtual void AutoScreenshot_Start() = 0;
|
2015-05-19 22:51:02 +00:00
|
|
|
virtual void AutoStatScreenshot_Start() = 0;
|
2017-04-26 03:10:31 +00:00
|
|
|
virtual void AutoCSV_Start() = 0;
|
2011-03-18 18:03:13 +00:00
|
|
|
virtual void ServerBrowserUpdate() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2016-04-29 22:34:12 +00:00
|
|
|
// gfx
|
|
|
|
virtual void SwitchWindowScreen(int Index) = 0;
|
2021-01-31 20:54:04 +00:00
|
|
|
virtual void SetWindowParams(int FullscreenMode, bool IsBorderless) = 0;
|
2016-04-29 22:34:12 +00:00
|
|
|
virtual void ToggleWindowVSync() = 0;
|
2019-03-28 20:51:42 +00:00
|
|
|
virtual void LoadFont() = 0;
|
2020-04-14 15:53:53 +00:00
|
|
|
virtual void Notify(const char *pTitle, const char *pMessage) = 0;
|
2016-04-29 22:34:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// networking
|
|
|
|
virtual void EnterGame() = 0;
|
|
|
|
|
|
|
|
//
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual const char *MapDownloadName() const = 0;
|
|
|
|
virtual int MapDownloadAmount() const = 0;
|
|
|
|
virtual int MapDownloadTotalsize() const = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// input
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual int *GetInput(int Tick, int IsDummy = 0) const = 0;
|
|
|
|
virtual int *GetDirectInput(int Tick, int IsDummy = 0) const = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// remote console
|
|
|
|
virtual void RconAuth(const char *pUsername, const char *pPassword) = 0;
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual bool RconAuthed() const = 0;
|
|
|
|
virtual bool UseTempRconCommands() const = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void Rcon(const char *pLine) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// server info
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual void GetServerInfo(class CServerInfo *pServerInfo) const = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2016-05-05 16:07:00 +00:00
|
|
|
virtual int GetPredictionTime() = 0;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// snapshot interface
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-09-26 19:41:58 +00:00
|
|
|
SNAP_CURRENT = 0,
|
|
|
|
SNAP_PREV = 1
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// TODO: Refactor: should redo this a bit i think, too many virtual calls
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual int SnapNumItems(int SnapID) const = 0;
|
|
|
|
virtual void *SnapFindItem(int SnapID, int Type, int ID) const = 0;
|
|
|
|
virtual void *SnapGetItem(int SnapID, int Index, CSnapItem *pItem) const = 0;
|
|
|
|
virtual int SnapItemSize(int SnapID, int Index) const = 0;
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void SnapInvalidateItem(int SnapID, int Index) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
virtual void SnapSetStaticsize(int ItemType, int Size) = 0;
|
|
|
|
|
|
|
|
virtual int SendMsg(CMsgPacker *pMsg, int Flags) = 0;
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual int SendMsgY(CMsgPacker *pMsg, int Flags, int NetClient = 1) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
int SendPackMsg(T *pMsg, int Flags)
|
|
|
|
{
|
2012-08-09 08:30:04 +00:00
|
|
|
CMsgPacker Packer(pMsg->MsgID(), false);
|
2010-05-29 07:25:38 +00:00
|
|
|
if(pMsg->Pack(&Packer))
|
|
|
|
return -1;
|
|
|
|
return SendMsg(&Packer, Flags);
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
|
|
|
//
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual const char *PlayerName() const = 0;
|
|
|
|
virtual const char *DummyName() const = 0;
|
|
|
|
virtual const char *ErrorString() const = 0;
|
|
|
|
virtual const char *LatestVersion() const = 0;
|
|
|
|
virtual bool ConnectionProblems() const = 0;
|
2011-01-17 12:28:15 +00:00
|
|
|
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual bool SoundInitFailed() const = 0;
|
2011-02-13 05:35:13 +00:00
|
|
|
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual IGraphics::CTextureHandle GetDebugFont() const = 0; // TODO: remove this function
|
2011-04-09 06:41:31 +00:00
|
|
|
|
2011-02-04 17:25:04 +00:00
|
|
|
//DDRace
|
2011-02-13 05:35:13 +00:00
|
|
|
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual const char *GetCurrentMap() const = 0;
|
|
|
|
virtual const char *GetCurrentMapPath() const = 0;
|
|
|
|
virtual SHA256_DIGEST GetCurrentMapSha256() const = 0;
|
|
|
|
virtual unsigned GetCurrentMapCrc() const = 0;
|
2017-09-09 21:10:42 +00:00
|
|
|
|
2019-03-25 19:02:50 +00:00
|
|
|
virtual int GetCurrentRaceTime() = 0;
|
|
|
|
|
2017-09-28 17:13:20 +00:00
|
|
|
virtual void RaceRecord_Start(const char *pFilename) = 0;
|
2017-09-09 21:10:42 +00:00
|
|
|
virtual void RaceRecord_Stop() = 0;
|
|
|
|
virtual bool RaceRecord_IsRecording() = 0;
|
2014-08-13 14:35:15 +00:00
|
|
|
|
|
|
|
virtual void DemoSliceBegin() = 0;
|
|
|
|
virtual void DemoSliceEnd() = 0;
|
2017-02-28 09:08:14 +00:00
|
|
|
virtual void DemoSlice(const char *pDstPath, CLIENTFUNC_FILTER pfnFilter, void *pUser) = 0;
|
2014-09-19 22:36:22 +00:00
|
|
|
|
2017-09-03 15:36:51 +00:00
|
|
|
virtual void RequestDDNetInfo() = 0;
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual bool EditorHasUnsavedData() const = 0;
|
2015-07-22 20:16:49 +00:00
|
|
|
|
2016-10-03 11:56:15 +00:00
|
|
|
virtual void GenerateTimeoutSeed() = 0;
|
|
|
|
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual IFriends *Foes() = 0;
|
2019-04-11 22:46:54 +00:00
|
|
|
|
|
|
|
virtual void GetSmoothTick(int *pSmoothTick, float *pSmoothIntraTick, float MixAmount) = 0;
|
2020-10-02 13:43:52 +00:00
|
|
|
|
|
|
|
virtual SWarning *GetCurWarning() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IGameClient : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("gameclient", 0)
|
|
|
|
protected:
|
|
|
|
public:
|
|
|
|
virtual void OnConsoleInit() = 0;
|
|
|
|
|
2017-07-24 19:43:55 +00:00
|
|
|
virtual void OnRconType(bool UsernameReq) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnRconLine(const char *pLine) = 0;
|
|
|
|
virtual void OnInit() = 0;
|
2020-07-12 15:32:56 +00:00
|
|
|
virtual void InvalidateSnapshot() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnNewSnapshot() = 0;
|
|
|
|
virtual void OnEnterGame() = 0;
|
|
|
|
virtual void OnShutdown() = 0;
|
|
|
|
virtual void OnRender() = 0;
|
2016-04-29 21:05:20 +00:00
|
|
|
virtual void OnUpdate() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnStateChange(int NewState, int OldState) = 0;
|
|
|
|
virtual void OnConnected() = 0;
|
2014-05-03 00:30:05 +00:00
|
|
|
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, bool IsDummy = 0) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnPredict() = 0;
|
2011-01-17 11:28:37 +00:00
|
|
|
virtual void OnActivateEditor() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2017-02-28 09:08:14 +00:00
|
|
|
virtual int OnSnapInput(int *pData, bool Dummy, bool Force) = 0;
|
|
|
|
virtual void OnDummySwap() = 0;
|
2014-04-28 13:19:57 +00:00
|
|
|
virtual void SendDummyInfo(bool Start) = 0;
|
2019-03-25 19:02:50 +00:00
|
|
|
virtual int GetLastRaceTick() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-02-08 21:26:26 +00:00
|
|
|
virtual const char *GetItemName(int Type) const = 0;
|
|
|
|
virtual const char *Version() const = 0;
|
|
|
|
virtual const char *NetVersion() const = 0;
|
|
|
|
virtual int DDNetVersion() const = 0;
|
|
|
|
virtual const char *DDNetVersionStr() const = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2014-04-28 14:47:44 +00:00
|
|
|
virtual void OnDummyDisconnect() = 0;
|
2021-03-17 15:09:39 +00:00
|
|
|
virtual void DummyResetInput() = 0;
|
2019-06-05 17:17:55 +00:00
|
|
|
virtual void Echo(const char *pString) = 0;
|
2020-10-02 13:43:52 +00:00
|
|
|
virtual bool CanDisplayWarning() = 0;
|
2020-10-04 20:46:28 +00:00
|
|
|
virtual bool IsDisplayingWarning() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
2021-01-17 16:18:08 +00:00
|
|
|
void SnapshotRemoveExtraProjectileInfo(unsigned char *pData);
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
extern IGameClient *CreateGameClient();
|
|
|
|
#endif
|