2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_GAMEATTRIBUTES
|
|
|
|
#define INCLUDED_GAMEATTRIBUTES
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
#include "Player.h"
|
|
|
|
|
|
|
|
#include "scripting/SynchedJSObject.h"
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
#include "simulation/LOSManager.h"
|
2005-02-21 18:13:31 +01:00
|
|
|
|
2008-06-16 20:19:35 +02:00
|
|
|
//class CNetServerSession;
|
|
|
|
class CNetSession;
|
2005-02-21 18:13:31 +01:00
|
|
|
class CGameAttributes;
|
|
|
|
class CPlayerSlot;
|
|
|
|
|
|
|
|
enum EPlayerSlotAssignment
|
|
|
|
{
|
|
|
|
SLOT_CLOSED,
|
|
|
|
SLOT_OPEN,
|
|
|
|
SLOT_SESSION,
|
|
|
|
SLOT_AI
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (PlayerSlotAssignmentCB)(void *data, CPlayerSlot *);
|
|
|
|
|
|
|
|
class CPlayerSlot: public CJSObject<CPlayerSlot>
|
|
|
|
{
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t m_SlotID;
|
2005-02-21 18:13:31 +01:00
|
|
|
EPlayerSlotAssignment m_Assignment;
|
|
|
|
|
2008-06-16 20:19:35 +02:00
|
|
|
//CNetServerSession *m_pSession;
|
|
|
|
CNetSession *m_pSession;
|
2005-02-21 18:13:31 +01:00
|
|
|
int m_SessionID;
|
|
|
|
CPlayer *m_pPlayer;
|
|
|
|
|
|
|
|
PlayerSlotAssignmentCB *m_Callback;
|
|
|
|
void *m_CallbackData;
|
|
|
|
|
|
|
|
bool JSI_AssignClosed(JSContext *cx, uintN argc, jsval *argv);
|
|
|
|
|
|
|
|
// Assign to a session, takes one argument (a NetSession object)
|
|
|
|
bool JSI_AssignToSession(JSContext *cx, uintN argc, jsval *argv);
|
2005-03-31 07:14:17 +02:00
|
|
|
// Assign to the local player in SP or Server Player in MP
|
|
|
|
bool JSI_AssignLocal(JSContext *cx, uintN argc, jsval *argv);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
bool JSI_AssignOpen(JSContext *cx, uintN argc, jsval *argv);
|
|
|
|
|
|
|
|
// TODO This will wait until there actually is AI to set up
|
|
|
|
// bool JSI_AssignAI(JSContext *cx, uintN argc, jsval *argv);
|
|
|
|
|
2005-10-24 04:32:44 +02:00
|
|
|
jsval JSI_GetSession(JSContext* cx);
|
|
|
|
jsval JSI_GetAssignment(JSContext* cx);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
void CallCallback();
|
2008-06-16 20:19:35 +02:00
|
|
|
//void SetAssignment(EPlayerSlotAssignment, CNetServerSession *pSession, int sessionID);
|
|
|
|
void SetAssignment(EPlayerSlotAssignment, CNetSession *pSession, int sessionID);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
friend class CGameAttributes;
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
inline void SetSlotID(size_t slotID)
|
2005-02-21 18:13:31 +01:00
|
|
|
{ m_SlotID=slotID; }
|
|
|
|
|
|
|
|
public:
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
CPlayerSlot(size_t slotID, CPlayer *pPlayer);
|
2005-02-21 18:13:31 +01:00
|
|
|
~CPlayerSlot();
|
|
|
|
|
|
|
|
inline CPlayer *GetPlayer()
|
|
|
|
{ return m_pPlayer; }
|
|
|
|
inline int GetSessionID()
|
|
|
|
{ return m_SessionID; }
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
inline size_t GetSlotID()
|
2005-02-21 18:13:31 +01:00
|
|
|
{ return m_SlotID; }
|
|
|
|
|
|
|
|
// Only applicable on the server host, and may return NULL if the slot
|
|
|
|
// is not assigned to a server session.
|
2008-06-16 20:19:35 +02:00
|
|
|
//inline CNetServerSession *GetSession()
|
|
|
|
//{ return m_pSession; }
|
|
|
|
inline CNetSession *GetSession()
|
2005-02-21 18:13:31 +01:00
|
|
|
{ return m_pSession; }
|
|
|
|
|
|
|
|
|
|
|
|
inline void SetCallback(PlayerSlotAssignmentCB *callback, void *data)
|
|
|
|
{
|
|
|
|
m_Callback=callback;
|
|
|
|
m_CallbackData=data;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline EPlayerSlotAssignment GetAssignment()
|
|
|
|
{ return m_Assignment; }
|
|
|
|
|
|
|
|
// Reset any assignment the slot might have had before and mark the slot as
|
|
|
|
// closed.
|
|
|
|
void AssignClosed();
|
|
|
|
|
|
|
|
// [Server] Assign the slot to a connected session
|
2008-06-16 20:19:35 +02:00
|
|
|
//void AssignToSession(CNetServerSession *pSession);
|
|
|
|
void AssignToSession(CNetSession *pSession);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
// [Client] The slot has been assigned by the server to a session ID, mirror
|
|
|
|
// the assignment
|
|
|
|
void AssignToSessionID(int sessionID);
|
|
|
|
|
|
|
|
// Reset any assignment the slot might have before and mark the slot as free
|
|
|
|
void AssignOpen();
|
2005-04-03 07:02:00 +02:00
|
|
|
|
|
|
|
// Assign to the local player in SP or Server Player in MP
|
|
|
|
void AssignLocal();
|
|
|
|
|
2005-02-21 18:13:31 +01:00
|
|
|
// TODO This will wait until there actually is AI to set up
|
|
|
|
// void AssignAI();
|
2008-04-06 16:03:23 +02:00
|
|
|
|
|
|
|
static void ScriptingInit();
|
2005-02-21 18:13:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
namespace PlayerSlotArray_JS
|
|
|
|
{
|
|
|
|
JSBool GetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
2006-12-16 02:01:15 +01:00
|
|
|
}
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
class CGameAttributes:
|
|
|
|
public CSynchedJSObject<CGameAttributes>,
|
|
|
|
public Singleton<CGameAttributes>
|
|
|
|
{
|
|
|
|
public:
|
2006-07-20 16:37:58 +02:00
|
|
|
typedef void (UpdateCallback)(const CStrW& name, const CStrW& newValue, void *data);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
CStrW m_MapFile;
|
2006-06-10 01:07:11 +02:00
|
|
|
CStrW m_ResourceLevel;
|
|
|
|
CStrW m_StartingPhase;
|
2007-04-27 05:05:26 +02:00
|
|
|
CStrW m_GameMode;
|
2008-07-19 02:36:42 +02:00
|
|
|
int m_LOSSetting; // ELOSSetting
|
2006-10-08 19:39:46 +02:00
|
|
|
bool m_FogOfWar;
|
|
|
|
bool m_ScreenshotMode;
|
2005-10-10 05:35:32 +02:00
|
|
|
|
2006-06-10 01:07:11 +02:00
|
|
|
// Note: we must use the un-internationalized name of the resource level and starting phase
|
|
|
|
|
2005-02-21 18:13:31 +01:00
|
|
|
private:
|
|
|
|
friend JSBool PlayerSlotArray_JS::GetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
size_t m_NumSlots;
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
// All players in the game. m_Players[0] is the Gaia Player, like in CGame.
|
|
|
|
// m_Players[1..n] have a corresponding player slot in m_PlayerSlots[0..n-1]
|
|
|
|
std::vector <CPlayer *> m_Players;
|
|
|
|
|
|
|
|
std::vector <CPlayerSlot *> m_PlayerSlots;
|
|
|
|
JSObject *m_PlayerSlotArrayJS;
|
|
|
|
|
|
|
|
UpdateCallback *m_UpdateCB;
|
|
|
|
void *m_UpdateCBData;
|
|
|
|
|
|
|
|
CPlayer::UpdateCallback *m_PlayerUpdateCB;
|
|
|
|
void *m_PlayerUpdateCBData;
|
|
|
|
|
|
|
|
PlayerSlotAssignmentCB *m_PlayerSlotAssignmentCB;
|
|
|
|
void *m_PlayerSlotAssignmentCBData;
|
|
|
|
|
2006-07-20 16:37:58 +02:00
|
|
|
virtual void Update(const CStrW& name, ISynchedJSProperty *attrib);
|
2005-02-21 18:13:31 +01:00
|
|
|
static void OnNumSlotsUpdate(CSynchedJSObjectBase *owner);
|
|
|
|
|
2005-10-24 04:53:50 +02:00
|
|
|
jsval JSI_GetPlayerSlots(JSContext* cx);
|
2007-05-29 21:01:21 +02:00
|
|
|
jsval_t JSI_GetOpenSlot(JSContext *cx, uintN argc, jsval *argv);
|
2008-11-22 23:44:02 +01:00
|
|
|
jsval JSI_GetUsedSlotsAmount(JSContext* cx);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
CGameAttributes();
|
|
|
|
virtual ~CGameAttributes();
|
|
|
|
|
2006-07-20 16:37:58 +02:00
|
|
|
void SetValue(const CStrW& name, const CStrW& value);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
inline void SetUpdateCallback(UpdateCallback *cb, void *userdata)
|
|
|
|
{
|
|
|
|
m_UpdateCB=cb;
|
|
|
|
m_UpdateCBData=userdata;
|
|
|
|
}
|
|
|
|
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
inline size_t GetSlotCount()
|
2005-02-21 18:13:31 +01:00
|
|
|
{ return m_NumSlots; }
|
|
|
|
|
2007-04-27 05:05:26 +02:00
|
|
|
inline CStrW GetGameMode()
|
|
|
|
{ return m_GameMode; }
|
|
|
|
|
2005-02-21 18:13:31 +01:00
|
|
|
// Remove all slots that are either opened or closed, so that all slots have
|
|
|
|
// an assignment and a player. Player IDs will be assigned in the same order
|
|
|
|
// as the slot indexes, but without holes in the numbering.
|
|
|
|
void FinalizeSlots();
|
|
|
|
|
|
|
|
// Get the player object for the passed Player ID
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
CPlayer *GetPlayer(size_t id);
|
2005-02-21 18:13:31 +01:00
|
|
|
// Get the slot object with the specified index
|
had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).
it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.
after several hours, the code now requires fewer casts and less
guesswork.
other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.
This was SVN commit r5942.
2008-05-11 20:48:32 +02:00
|
|
|
CPlayerSlot *GetSlot(size_t index);
|
2005-02-21 18:13:31 +01:00
|
|
|
|
|
|
|
void SetPlayerUpdateCallback(CPlayer::UpdateCallback *cb, void *userdata);
|
|
|
|
void SetPlayerSlotAssignmentCallback(PlayerSlotAssignmentCB *cb, void *userdata);
|
2008-04-06 16:03:23 +02:00
|
|
|
|
|
|
|
static void ScriptingInit();
|
2005-02-21 18:13:31 +01:00
|
|
|
};
|
|
|
|
#define g_GameAttributes CGameAttributes::GetSingleton()
|
|
|
|
|
|
|
|
#endif
|