fixed clipping on some machines
[twcon.git] / src / engine / client.h
blob966e8f61af5b18ef0bcc7e56030c18684b955faf
1 /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2 /* If you are missing that file, acquire a complete release at teeworlds.com. */
3 #ifndef ENGINE_CLIENT_H
4 #define ENGINE_CLIENT_H
5 #include "kernel.h"
7 #include "message.h"
9 class IClient : public IInterface
11 MACRO_INTERFACE("client", 0)
12 protected:
13 // quick access to state of the client
14 int m_State;
16 // quick access to time variables
17 int m_PrevGameTick;
18 int m_CurGameTick;
19 float m_GameIntraTick;
20 float m_GameTickTime;
22 int m_PredTick;
23 float m_PredIntraTick;
25 float m_LocalTime;
26 float m_FrameTime;
28 int m_GameTickSpeed;
29 public:
31 class CSnapItem
33 public:
34 int m_Type;
35 int m_ID;
36 int m_DataSize;
39 /* Constants: Client States
40 STATE_OFFLINE - The client is offline.
41 STATE_CONNECTING - The client is trying to connect to a server.
42 STATE_LOADING - The client has connected to a server and is loading resources.
43 STATE_ONLINE - The client is connected to a server and running the game.
44 STATE_DEMOPLAYBACK - The client is playing a demo
45 STATE_QUITING - The client is quiting.
48 enum
50 STATE_OFFLINE=0,
51 STATE_CONNECTING,
52 STATE_LOADING,
53 STATE_ONLINE,
54 STATE_DEMOPLAYBACK,
55 STATE_QUITING,
59 inline int State() const { return m_State; }
61 // tick time access
62 inline int PrevGameTick() const { return m_PrevGameTick; }
63 inline int GameTick() const { return m_CurGameTick; }
64 inline int PredGameTick() const { return m_PredTick; }
65 inline float IntraGameTick() const { return m_GameIntraTick; }
66 inline float PredIntraGameTick() const { return m_PredIntraTick; }
67 inline float GameTickTime() const { return m_GameTickTime; }
68 inline int GameTickSpeed() const { return m_GameTickSpeed; }
70 // other time access
71 inline float FrameTime() const { return m_FrameTime; }
72 inline float LocalTime() const { return m_LocalTime; }
74 // actions
75 virtual void Connect(const char *pAddress) = 0;
76 virtual void Disconnect() = 0;
77 virtual void Quit() = 0;
78 virtual const char *DemoPlayer_Play(const char *pFilename, int StorageType) = 0;
79 virtual void DemoRecorder_Start(const char *pFilename, bool WithTimestamp) = 0;
80 virtual void DemoRecorder_HandleAutoStart() = 0;
81 virtual void DemoRecorder_Stop() = 0;
82 virtual void AutoScreenshot_Start() = 0;
83 virtual void ServerBrowserUpdate() = 0;
85 // networking
86 virtual void EnterGame() = 0;
89 virtual int MapDownloadAmount() = 0;
90 virtual int MapDownloadTotalsize() = 0;
92 // input
93 virtual int *GetInput(int Tick) = 0;
95 // remote console
96 virtual void RconAuth(const char *pUsername, const char *pPassword) = 0;
97 virtual bool RconAuthed() = 0;
98 virtual bool UseTempRconCommands() = 0;
99 virtual void Rcon(const char *pLine) = 0;
101 // server info
102 virtual void GetServerInfo(class CServerInfo *pServerInfo) = 0;
104 // snapshot interface
106 enum
108 SNAP_CURRENT=0,
109 SNAP_PREV=1
112 // TODO: Refactor: should redo this a bit i think, too many virtual calls
113 virtual int SnapNumItems(int SnapID) = 0;
114 virtual void *SnapFindItem(int SnapID, int Type, int ID) = 0;
115 virtual void *SnapGetItem(int SnapID, int Index, CSnapItem *pItem) = 0;
116 virtual void SnapInvalidateItem(int SnapID, int Index) = 0;
118 virtual void SnapSetStaticsize(int ItemType, int Size) = 0;
120 virtual int SendMsg(CMsgPacker *pMsg, int Flags) = 0;
122 template<class T>
123 int SendPackMsg(T *pMsg, int Flags)
125 CMsgPacker Packer(pMsg->MsgID());
126 if(pMsg->Pack(&Packer))
127 return -1;
128 return SendMsg(&Packer, Flags);
132 virtual const char *ErrorString() = 0;
133 virtual const char *LatestVersion() = 0;
134 virtual bool ConnectionProblems() = 0;
136 virtual bool SoundInitFailed() = 0;
138 virtual int GetDebugFont() = 0;
141 class IGameClient : public IInterface
143 MACRO_INTERFACE("gameclient", 0)
144 protected:
145 public:
146 virtual void OnConsoleInit() = 0;
148 virtual void OnRconLine(const char *pLine) = 0;
149 virtual void OnInit() = 0;
150 virtual void OnNewSnapshot() = 0;
151 virtual void OnEnterGame() = 0;
152 virtual void OnShutdown() = 0;
153 virtual void OnRender() = 0;
154 virtual void OnStateChange(int NewState, int OldState) = 0;
155 virtual void OnConnected() = 0;
156 virtual void OnMessage(int MsgID, CUnpacker *pUnpacker) = 0;
157 virtual void OnPredict() = 0;
158 virtual void OnActivateEditor() = 0;
160 virtual int OnSnapInput(int *pData) = 0;
162 virtual const char *GetItemName(int Type) = 0;
163 virtual const char *Version() = 0;
164 virtual const char *NetVersion() = 0;
168 extern IGameClient *CreateGameClient();
169 #endif