1
0
forked from 0ad/0ad
0ad/source/ps/Player.h
janwas c817566222 # housekeeping
replaced all (*) CStr / CStrW by-value params with const reference. hoo
boy.

please always perform this optimization (actually standard idiom) when
writing the code - it takes little work, tells the next guy that the
string won't be modified, and makes a large performance difference.

(* where possible.. a few require other changes and will follow later)

This was SVN commit r4151.
2006-07-20 14:37:58 +00:00

88 lines
2.0 KiB
C++

#ifndef _Player_H
#define _Player_H
#include "CStr.h"
#include "scripting/SynchedJSObject.h"
#include "scripting/ScriptableObject.h"
#include "scripting/ScriptCustomTypes.h"
class CNetMessage;
class HEntity;
class CTechnology;
typedef SColour SPlayerColour;
class CPlayer : public CSynchedJSObject<CPlayer>
{
public:
typedef void (UpdateCallback)(const CStrW& name, const CStrW& value, CPlayer *player, void *userdata);
private:
CStrW m_Name;
CStrW m_Civilization; // Note: this must be the un-internationalized name of the civ
PS_uint m_PlayerID;
PS_uint m_LOSToken;
SPlayerColour m_Colour;
UpdateCallback *m_UpdateCB;
void *m_UpdateCBData;
std::vector<CTechnology*> m_ActiveTechs;
virtual void Update(const CStrW& name, ISynchedJSProperty *prop);
public:
CPlayer( uint playerID );
~CPlayer();
bool ValidateCommand(CNetMessage *pMsg);
inline PS_uint GetPlayerID() const
{ return m_PlayerID; }
inline void SetPlayerID(PS_uint id)
{ m_PlayerID=id; }
inline PS_uint GetLOSToken() const
{ return m_LOSToken; }
inline const CStrW& GetName() const
{ return m_Name; }
inline void SetName(const CStrW& name)
{ m_Name = name; }
inline const SPlayerColour &GetColour() const
{ return m_Colour; }
inline void SetColour(const SPlayerColour &colour)
{ m_Colour = colour; }
inline void SetUpdateCallback(UpdateCallback *cb, void *userdata)
{
m_UpdateCB=cb;
m_UpdateCBData=userdata;
}
void SetValue(const CStrW& name, const CStrW& value);
inline void AddActiveTech(CTechnology* tech)
{
m_ActiveTechs.push_back(tech);
}
inline const std::vector<CTechnology*>& GetActiveTechs()
{
return m_ActiveTechs;
}
// Caller frees...
std::vector<HEntity>* GetControlledEntities();
// JS Interface Functions
jsval JSI_ToString( JSContext* context, uintN argc, jsval* argv );
jsval JSI_GetControlledEntities( JSContext* context );
jsval JSI_SetColour(JSContext *context, uintN argc, jsval *argv);
jsval JSI_GetColour(JSContext *context, uintN argc, jsval *argv);
static void ScriptingInit();
};
#endif