ddnet/src/game/client/component.h

209 lines
4.5 KiB
C
Raw Normal View History

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
#if defined(CONF_VIDEORECORDER)
#include <engine/shared/video.h>
#endif
2021-07-12 09:29:59 +00:00
#include <base/color.h>
#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;
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;
#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;
#endif
#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
{
return IVideo::Current() ? IVideo::Time() : time_get();
}
#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
{
return time_get();
}
#endif
2021-08-30 15:38:22 +00:00
/**
* Gets the local time.
*/
2021-07-12 09:29:59 +00:00
float LocalTime() const;
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() {}
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;
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
*/
virtual void OnStateChange(int NewState, int OldState){};
2021-08-30 15:38:22 +00:00
/**
* Called to let the components register their console commands.
*/
virtual void OnConsoleInit(){};
2021-08-30 15:38:22 +00:00
/**
* Called to let the components run initialization code.
*/
virtual void OnInit(){};
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()
*/
virtual void OnReset(){};
2021-08-30 15:38:22 +00:00
/**
* Called when the window has been resized.
*/
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.
*/
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.
*/
virtual void OnRelease(){};
2021-08-30 15:38:22 +00:00
/**
* Called on map load.
*/
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
/**
* Called on mouse movement
*
* @param x The x coordinates of the mouse.
* @param y The y coordinates of the mouse.
*/
2010-05-29 07:25:38 +00:00
virtual bool OnMouseMove(float x, float y) { return false; }
2021-08-30 15:38:22 +00:00
/**
* Called on a input event
* @param e The input event.
*/
2010-05-29 07:25:38 +00:00
virtual bool OnInput(IInput::CEvent e) { return false; }
};
#endif