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 GAME_CLIENT_COMPONENT_H
|
|
|
|
#define GAME_CLIENT_COMPONENT_H
|
|
|
|
|
2016-08-30 23:39:59 +00:00
|
|
|
#if defined(CONF_VIDEORECORDER)
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/shared/video.h>
|
2016-08-30 23:39:59 +00:00
|
|
|
#endif
|
|
|
|
|
2021-07-12 09:29:59 +00:00
|
|
|
#include <base/color.h>
|
2020-09-26 19:41:58 +00:00
|
|
|
#include <engine/input.h>
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2021-07-12 09:29:59 +00:00
|
|
|
#include <engine/client.h>
|
|
|
|
#include <engine/console.h>
|
|
|
|
#include <game/localization.h>
|
|
|
|
|
|
|
|
#include <engine/config.h>
|
|
|
|
|
|
|
|
class CGameClient;
|
|
|
|
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* This class is inherited by all the client components.
|
|
|
|
*
|
|
|
|
* These components can implement the virtual methods such as OnInit(), OnMessage(int Msg, void *pRawMsg) to provide their functionality.
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
class CComponent
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
friend class CGameClient;
|
|
|
|
|
|
|
|
CGameClient *m_pClient;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-08-30 15:38:22 +00:00
|
|
|
// perhaps propagate pointers for these as well
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the kernel interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IKernel *Kernel() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the graphics interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IGraphics *Graphics() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the text rendering interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class ITextRender *TextRender() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the input interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IInput *Input() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the storage interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IStorage *Storage() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the ui interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class CUI *UI() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the sound interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class ISound *Sound() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the render tools interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class CRenderTools *RenderTools() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the config interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class CConfig *Config() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the console interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IConsole *Console() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the demo player interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IDemoPlayer *DemoPlayer() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the demo recorder interface.
|
|
|
|
*
|
|
|
|
* @param Recorder A member of the RECORDER_x enum
|
|
|
|
* @see RECORDER_MANUAL
|
|
|
|
* @see RECORDER_AUTO
|
|
|
|
* @see RECORDER_RACE
|
|
|
|
* @see RECORDER_REPLAYS
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IDemoRecorder *DemoRecorder(int Recorder) const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the server browser interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IServerBrowser *ServerBrowser() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the layers interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class CLayers *Layers() const;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the collision interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class CCollision *Collision() const;
|
2020-07-09 22:01:00 +00:00
|
|
|
#if defined(CONF_AUTOUPDATE)
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the updater interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IUpdater *Updater() const;
|
2020-07-09 22:01:00 +00:00
|
|
|
#endif
|
2016-08-30 23:39:59 +00:00
|
|
|
|
|
|
|
#if defined(CONF_VIDEORECORDER)
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Gets the current time.
|
|
|
|
* @see time_get()
|
|
|
|
*/
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t time() const
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
|
|
|
return IVideo::Current() ? IVideo::Time() : time_get();
|
|
|
|
}
|
2016-08-30 23:39:59 +00:00
|
|
|
#else
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Gets the current time.
|
|
|
|
* @see time_get()
|
|
|
|
*/
|
2021-06-23 05:05:49 +00:00
|
|
|
int64_t time() const
|
2020-09-26 19:41:58 +00:00
|
|
|
{
|
|
|
|
return time_get();
|
|
|
|
}
|
2016-08-30 23:39:59 +00:00
|
|
|
#endif
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Gets the local time.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
float LocalTime() const;
|
2016-08-30 23:39:59 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
public:
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* The component virtual destructor.
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual ~CComponent() {}
|
2022-01-31 02:11:47 +00:00
|
|
|
/**
|
|
|
|
* Gets the size of the non-abstract component.
|
|
|
|
*/
|
|
|
|
virtual int Sizeof() const = 0;
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get a pointer to the game client.
|
|
|
|
*/
|
2014-09-06 23:53:20 +00:00
|
|
|
class CGameClient *GameClient() const { return m_pClient; }
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Get the client interface.
|
|
|
|
*/
|
2021-07-12 09:29:59 +00:00
|
|
|
class IClient *Client() const;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* This method is called when the client changes state, e.g from offline to online.
|
|
|
|
* @see IClient::STATE_CONNECTING
|
|
|
|
* @see IClient::STATE_LOADING
|
|
|
|
* @see IClient::STATE_ONLINE
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual void OnStateChange(int NewState, int OldState){};
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called to let the components register their console commands.
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual void OnConsoleInit(){};
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called to let the components run initialization code.
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual void OnInit(){};
|
2022-01-20 11:19:06 +00:00
|
|
|
/**
|
|
|
|
* Called to cleanup the component.
|
|
|
|
* This method is called when the client is closed.
|
|
|
|
*/
|
|
|
|
virtual void OnShutdown(){};
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called to reset the component.
|
|
|
|
* This method is usually called on your component constructor to avoid code duplication.
|
|
|
|
* @see CHud::CHud()
|
|
|
|
* @see CHud::OnReset()
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual void OnReset(){};
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called when the window has been resized.
|
|
|
|
*/
|
2018-03-21 14:53:29 +00:00
|
|
|
virtual void OnWindowResize() {}
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called when the component should get rendered.
|
|
|
|
*
|
|
|
|
* The render order depends on the component insertion order.
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual void OnRender(){};
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called when the input gets released, for example when a text box loses focus.
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual void OnRelease(){};
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called on map load.
|
|
|
|
*/
|
2020-09-26 19:41:58 +00:00
|
|
|
virtual void OnMapLoad(){};
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
|
|
|
* Called when receiving a network message.
|
|
|
|
* @param Msg The message type.
|
|
|
|
* @param pRawMsg The message data.
|
|
|
|
* @see NETMSGTYPE_SV_DDRACETIME
|
|
|
|
* @see CNetMsg_Sv_DDRaceTime
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual void OnMessage(int Msg, void *pRawMsg) {}
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
2021-10-23 11:48:21 +00:00
|
|
|
* Called on mouse movement, where the x and y values are deltas.
|
2021-08-30 15:38:22 +00:00
|
|
|
*
|
2021-08-30 15:40:46 +00:00
|
|
|
* @param x The amount of change in the x coordinate since the last call.
|
|
|
|
* @param y The amount of change in the y coordinate since the last call.
|
2021-08-30 15:38:22 +00:00
|
|
|
*/
|
2021-10-23 11:48:21 +00:00
|
|
|
virtual bool OnMouseMove(float x, float y) { return false; }
|
2021-08-30 15:38:22 +00:00
|
|
|
/**
|
2021-08-30 15:40:46 +00:00
|
|
|
* Called on a input event.
|
2021-08-30 15:38:22 +00:00
|
|
|
* @param e The input event.
|
|
|
|
*/
|
2010-05-29 07:25:38 +00:00
|
|
|
virtual bool OnInput(IInput::CEvent e) { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|