4132: document CComponent r=Jupeyy a=edg-l

I think this will make it easier for future people looking into this class.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Edgar Luque <git@edgarluque.com>
This commit is contained in:
bors[bot] 2021-08-30 18:43:09 +00:00 committed by GitHub
commit d2bfb1e12a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,6 +18,11 @@
class CGameClient;
/**
* 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.
*/
class CComponent
{
protected:
@ -25,54 +30,178 @@ protected:
CGameClient *m_pClient;
// perhaps propagte pointers for these as well
// perhaps propagate pointers for these as well
/**
* Get the kernel interface.
*/
class IKernel *Kernel() const;
/**
* Get the graphics interface.
*/
class IGraphics *Graphics() const;
/**
* Get the text rendering interface.
*/
class ITextRender *TextRender() const;
/**
* Get the input interface.
*/
class IInput *Input() const;
/**
* Get the storage interface.
*/
class IStorage *Storage() const;
/**
* Get the ui interface.
*/
class CUI *UI() const;
/**
* Get the sound interface.
*/
class ISound *Sound() const;
/**
* Get the render tools interface.
*/
class CRenderTools *RenderTools() const;
/**
* Get the config interface.
*/
class CConfig *Config() const;
/**
* Get the console interface.
*/
class IConsole *Console() const;
/**
* Get the demo player interface.
*/
class IDemoPlayer *DemoPlayer() const;
/**
* 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
*/
class IDemoRecorder *DemoRecorder(int Recorder) const;
/**
* Get the server browser interface.
*/
class IServerBrowser *ServerBrowser() const;
/**
* Get the layers interface.
*/
class CLayers *Layers() const;
/**
* Get the collision interface.
*/
class CCollision *Collision() const;
#if defined(CONF_AUTOUPDATE)
/**
* Get the updater interface.
*/
class IUpdater *Updater() const;
#endif
#if defined(CONF_VIDEORECORDER)
/**
* Gets the current time.
* @see time_get()
*/
int64_t time() const
{
return IVideo::Current() ? IVideo::Time() : time_get();
}
#else
/**
* Gets the current time.
* @see time_get()
*/
int64_t time() const
{
return time_get();
}
#endif
/**
* Gets the local time.
*/
float LocalTime() const;
public:
/**
* The component virtual destructor.
*/
virtual ~CComponent() {}
/**
* Get a pointer to the game client.
*/
class CGameClient *GameClient() const { return m_pClient; }
/**
* Get the client interface.
*/
class IClient *Client() const;
/**
* 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){};
/**
* Called to let the components register their console commands.
*/
virtual void OnConsoleInit(){};
/**
* Called to let the components run initialization code.
*/
virtual void OnInit(){};
/**
* 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(){};
/**
* Called when the window has been resized.
*/
virtual void OnWindowResize() {}
/**
* Called when the component should get rendered.
*
* The render order depends on the component insertion order.
*/
virtual void OnRender(){};
/**
* Called when the input gets released, for example when a text box loses focus.
*/
virtual void OnRelease(){};
/**
* Called on map load.
*/
virtual void OnMapLoad(){};
/**
* Called when receiving a network message.
* @param Msg The message type.
* @param pRawMsg The message data.
* @see NETMSGTYPE_SV_DDRACETIME
* @see CNetMsg_Sv_DDRaceTime
*/
virtual void OnMessage(int Msg, void *pRawMsg) {}
/**
* Called on mouse movement, where the x and y values are deltas.
*
* @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.
*/
virtual bool OnMouseMove(float x, float y) { return false; }
/**
* Called on a input event.
* @param e The input event.
*/
virtual bool OnInput(IInput::CEvent e) { return false; }
};