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"
|
2012-08-12 10:41:50 +00:00
|
|
|
#include "graphics.h"
|
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
|
|
|
|
int m_PrevGameTick;
|
|
|
|
int m_CurGameTick;
|
|
|
|
float m_GameIntraTick;
|
|
|
|
float m_GameTickTime;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-10-05 15:22:22 +00:00
|
|
|
int m_CurMenuTick;
|
|
|
|
int64 m_MenuStartTime;
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
int m_PredTick;
|
|
|
|
float m_PredIntraTick;
|
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:
|
|
|
|
|
|
|
|
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
|
|
|
|
inline int PrevGameTick() const { return m_PrevGameTick; }
|
|
|
|
inline int GameTick() const { return m_CurGameTick; }
|
2011-10-05 15:22:22 +00:00
|
|
|
inline int MenuTick() const { return m_CurMenuTick; }
|
2010-05-29 07:25:38 +00:00
|
|
|
inline int PredGameTick() const { return m_PredTick; }
|
|
|
|
inline float IntraGameTick() const { return m_GameIntraTick; }
|
|
|
|
inline float PredIntraGameTick() const { return m_PredIntraTick; }
|
|
|
|
inline float GameTickTime() const { return m_GameTickTime; }
|
|
|
|
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
|
|
|
|
virtual void Connect(const char *pAddress) = 0;
|
|
|
|
virtual void Disconnect() = 0;
|
|
|
|
virtual void Quit() = 0;
|
2010-10-06 21:07:35 +00:00
|
|
|
virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0;
|
2010-12-07 23:42:32 +00:00
|
|
|
virtual void DemoRecorder_Start(const char *pFilename, bool WithTimestamp) = 0;
|
2011-01-06 22:21:51 +00:00
|
|
|
virtual void DemoRecorder_HandleAutoStart() = 0;
|
2010-12-07 23:02:24 +00:00
|
|
|
virtual void DemoRecorder_Stop() = 0;
|
2012-07-29 09:54:29 +00:00
|
|
|
virtual void RecordGameMessage(bool State) = 0;
|
2010-12-12 15:48:13 +00:00
|
|
|
virtual void AutoScreenshot_Start() = 0;
|
2011-03-18 18:03:13 +00:00
|
|
|
virtual void ServerBrowserUpdate() = 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;
|
2015-01-20 18:47:26 +00:00
|
|
|
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
|
2015-01-21 12:03:51 +00:00
|
|
|
virtual const int *GetInput(int Tick) 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;
|
2015-01-20 18:47: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
|
2015-01-20 18:47:26 +00:00
|
|
|
virtual void GetServerInfo(class CServerInfo *pServerInfo) const = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
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
|
2015-01-20 18:47:26 +00:00
|
|
|
virtual int SnapNumItems(int SnapID) const = 0;
|
2015-01-21 12:03:51 +00:00
|
|
|
virtual const void *SnapFindItem(int SnapID, int Type, int ID) const = 0;
|
|
|
|
virtual const void *SnapGetItem(int SnapID, int Index, CSnapItem *pItem) const = 0;
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void SnapInvalidateItem(int SnapID, int Index) = 0;
|
2012-07-29 09:54:29 +00:00
|
|
|
|
|
|
|
virtual void *SnapNewItem(int Type, int ID, int Size) = 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;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
//
|
2015-01-20 18:47:26 +00:00
|
|
|
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
|
|
|
|
2015-01-20 18:47:26 +00:00
|
|
|
virtual bool SoundInitFailed() const = 0;
|
2011-02-18 10:41:27 +00:00
|
|
|
|
2015-01-20 18:47:26 +00:00
|
|
|
virtual IGraphics::CTextureHandle GetDebugFont() const = 0; // TODO: remove this function
|
2010-05-29 07:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class IGameClient : public IInterface
|
|
|
|
{
|
|
|
|
MACRO_INTERFACE("gameclient", 0)
|
|
|
|
protected:
|
|
|
|
public:
|
|
|
|
virtual void OnConsoleInit() = 0;
|
|
|
|
|
|
|
|
virtual void OnRconLine(const char *pLine) = 0;
|
|
|
|
virtual void OnInit() = 0;
|
|
|
|
virtual void OnNewSnapshot() = 0;
|
2012-07-29 09:54:29 +00:00
|
|
|
virtual void OnDemoRecSnap() = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnEnterGame() = 0;
|
|
|
|
virtual void OnShutdown() = 0;
|
|
|
|
virtual void OnRender() = 0;
|
|
|
|
virtual void OnStateChange(int NewState, int OldState) = 0;
|
|
|
|
virtual void OnConnected() = 0;
|
2011-02-12 10:40:36 +00:00
|
|
|
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker) = 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
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual int OnSnapInput(int *pData) = 0;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2015-01-20 18:47:26 +00:00
|
|
|
virtual const char *GetItemName(int Type) const = 0;
|
|
|
|
virtual const char *Version() const = 0;
|
|
|
|
virtual const char *NetVersion() const = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
extern IGameClient *CreateGameClient();
|
|
|
|
#endif
|