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"
|
|
|
|
|
|
|
|
#include "message.h"
|
2015-07-22 20:16:49 +00:00
|
|
|
#include <engine/friends.h>
|
2014-04-28 15:26:31 +00:00
|
|
|
#include <engine/shared/config.h>
|
2014-06-05 10:11:41 +00:00
|
|
|
#include <versionsrv/versionsrv.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2014-10-16 15:42:13 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
RECORDER_MANUAL=0,
|
|
|
|
RECORDER_AUTO=1,
|
|
|
|
RECORDER_RACE=2,
|
|
|
|
RECORDER_MAX=3,
|
|
|
|
};
|
|
|
|
|
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
|
2014-04-28 15:26:31 +00:00
|
|
|
int m_PrevGameTick[2];
|
|
|
|
int m_CurGameTick[2];
|
|
|
|
float m_GameIntraTick[2];
|
|
|
|
float m_GameTickTime[2];
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2014-04-28 15:26:31 +00:00
|
|
|
int m_PredTick[2];
|
|
|
|
float m_PredIntraTick[2];
|
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;
|
|
|
|
public:
|
2014-06-05 10:11:41 +00:00
|
|
|
char m_aNews[NEWS_SIZE];
|
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
|
|
|
|
STATE_QUITING - The client is quiting.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
STATE_OFFLINE=0,
|
|
|
|
STATE_CONNECTING,
|
|
|
|
STATE_LOADING,
|
|
|
|
STATE_ONLINE,
|
|
|
|
STATE_DEMOPLAYBACK,
|
|
|
|
STATE_QUITING,
|
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
inline int State() const { return m_State; }
|
|
|
|
|
|
|
|
// tick time access
|
2014-04-28 15:26:31 +00:00
|
|
|
inline int PrevGameTick() const { return m_PrevGameTick[g_Config.m_ClDummy]; }
|
|
|
|
inline int GameTick() const { return m_CurGameTick[g_Config.m_ClDummy]; }
|
|
|
|
inline int PredGameTick() const { return m_PredTick[g_Config.m_ClDummy]; }
|
|
|
|
inline float IntraGameTick() const { return m_GameIntraTick[g_Config.m_ClDummy]; }
|
|
|
|
inline float PredIntraGameTick() const { return m_PredIntraTick[g_Config.m_ClDummy]; }
|
|
|
|
inline float GameTickTime() const { return m_GameTickTime[g_Config.m_ClDummy]; }
|
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; }
|
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;
|
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;
|
2014-10-16 15:42:13 +00:00
|
|
|
virtual void DemoRecorder_Stop(int Recorder) = 0;
|
|
|
|
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;
|
|
|
|
virtual void ToggleFullscreen() = 0;
|
|
|
|
virtual void ToggleWindowBordered() = 0;
|
|
|
|
virtual void ToggleWindowVSync() = 0;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// networking
|
|
|
|
virtual void EnterGame() = 0;
|
|
|
|
|
|
|
|
//
|
2014-08-15 23:06:17 +00:00
|
|
|
virtual const char *MapDownloadName() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int MapDownloadAmount() = 0;
|
|
|
|
virtual int MapDownloadTotalsize() = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
// input
|
|
|
|
virtual int *GetInput(int Tick) = 0;
|
2014-12-01 00:31:58 +00:00
|
|
|
virtual bool InputExists(int Tick) = 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;
|
|
|
|
virtual bool RconAuthed() = 0;
|
2011-07-14 20:07:21 +00:00
|
|
|
virtual bool UseTempRconCommands() = 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
|
|
|
|
virtual void GetServerInfo(class CServerInfo *pServerInfo) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2015-03-14 09:45:11 +00:00
|
|
|
virtual void CheckVersionUpdate() = 0;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
SNAP_CURRENT=0,
|
|
|
|
SNAP_PREV=1
|
|
|
|
};
|
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
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual int SnapNumItems(int SnapID) = 0;
|
|
|
|
virtual void *SnapFindItem(int SnapID, int Type, int ID) = 0;
|
|
|
|
virtual void *SnapGetItem(int SnapID, int Index, CSnapItem *pItem) = 0;
|
|
|
|
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;
|
2014-04-28 13:19:57 +00:00
|
|
|
virtual int SendMsgExY(CMsgPacker *pMsg, int Flags, bool System=true, int NetClient=1) = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
int SendPackMsg(T *pMsg, int Flags)
|
|
|
|
{
|
|
|
|
CMsgPacker Packer(pMsg->MsgID());
|
|
|
|
if(pMsg->Pack(&Packer))
|
|
|
|
return -1;
|
|
|
|
return SendMsg(&Packer, Flags);
|
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
|
|
|
//
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual const char *ErrorString() = 0;
|
|
|
|
virtual const char *LatestVersion() = 0;
|
|
|
|
virtual bool ConnectionProblems() = 0;
|
2011-01-17 12:28:15 +00:00
|
|
|
|
|
|
|
virtual bool SoundInitFailed() = 0;
|
2011-02-13 05:35:13 +00:00
|
|
|
|
2011-02-18 10:41:27 +00:00
|
|
|
virtual int GetDebugFont() = 0;
|
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
|
|
|
|
2011-02-04 17:25:04 +00:00
|
|
|
virtual const char* GetCurrentMap() = 0;
|
|
|
|
virtual int GetCurrentMapCrc() = 0;
|
2016-08-23 01:08:36 +00:00
|
|
|
virtual const char* GetCurrentMapPath() = 0;
|
2011-02-04 17:25:04 +00:00
|
|
|
virtual const char* RaceRecordStart(const char *pFilename) = 0;
|
|
|
|
virtual void RaceRecordStop() = 0;
|
2014-10-16 15:42:13 +00:00
|
|
|
virtual bool RaceRecordIsRecording() = 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
|
|
|
|
|
|
|
virtual void RequestDDNetSrvList() = 0;
|
2017-08-30 19:34:01 +00:00
|
|
|
virtual void RequestDDNetRanks() = 0;
|
2015-03-14 15:10:46 +00:00
|
|
|
virtual bool EditorHasUnsavedData() = 0;
|
2015-07-22 20:16:49 +00:00
|
|
|
|
2016-10-03 11:56:15 +00:00
|
|
|
virtual void GenerateTimeoutSeed() = 0;
|
|
|
|
|
2015-07-22 20:16:49 +00:00
|
|
|
virtual IFriends* Foes() = 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;
|
|
|
|
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;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual const char *GetItemName(int Type) = 0;
|
|
|
|
virtual const char *Version() = 0;
|
|
|
|
virtual const char *NetVersion() = 0;
|
|
|
|
|
2014-04-28 14:47:44 +00:00
|
|
|
virtual void OnDummyDisconnect() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern IGameClient *CreateGameClient();
|
|
|
|
#endif
|