1
0
forked from 0ad/0ad

# Include headers for compilation without PCH

This was SVN commit r3774.
This commit is contained in:
Ykkrosh 2006-04-19 05:30:02 +00:00
parent d158ed9dc9
commit c81df59294
21 changed files with 421 additions and 390 deletions

View File

@ -1,5 +1,7 @@
#include "precompiled.h"
#include <algorithm>
#include "ObjectBase.h"
#include "ObjectManager.h"

View File

@ -6,6 +6,7 @@ class CSkeletonAnim;
#include <vector>
#include <set>
#include <map>
#include "CStr.h"
class CObjectBase

View File

@ -1,13 +1,14 @@
#ifndef _UNIT_H
#define _UNIT_H
#include <set>
class CModel;
class CObjectEntry;
class CEntity;
class CSkeletonAnim;
class CStr8;
class CStrW;
/////////////////////////////////////////////////////////////////////////////////////////////
// CUnit: simple "actor" definition - defines a sole object within the world

View File

@ -10,6 +10,7 @@
#define _UNITMANAGER_H
#include <vector>
#include <set>
#include "Singleton.h"
class CUnit;

View File

@ -23,6 +23,8 @@
#include "precompiled.h"
#include <deque>
#include <map>
#include <set>
#include "debug_stl.h"
#include "lib.h" // match_wildcard

View File

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "lib/types.h"
#include "lib.h"

View File

@ -32,7 +32,7 @@
#include <string.h>
#include <stdlib.h> // abs
#include <errno.h>
static const char* LibError_description(LibError err)
{

View File

@ -29,6 +29,9 @@
#include <deque>
#include <list>
#include <string>
#include <algorithm>
#include <ctime>
// location of a file: either archive or a real directory.
// not many instances => don't worry about efficiency.

View File

@ -25,6 +25,8 @@
#include <set>
#include <map>
#include <algorithm>
#include <ctime>
#include "file_internal.h"

View File

@ -23,6 +23,7 @@
#include "precompiled.h"
#include <time.h>
#include <limits>
#include "lib.h"
#include "byte_order.h"

View File

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <typeinfo>
#include "lib.h"
#include "win_internal.h"

View File

@ -24,6 +24,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <set>
#include "lib.h"
#include "win_internal.h"

View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <math.h>
#include <queue>
#include "win_internal.h"
#include <ddraw.h>

View File

@ -1,203 +1,205 @@
#include "precompiled.h"
#include "GameAttributes.h"
#include "Game.h"
#include "ConfigDB.h"
#include "Network/ServerSession.h"
#include "CLogger.h"
#include "ps/XML/Xeromyces.h"
using namespace std;
CPlayerSlot::CPlayerSlot(int slotID, CPlayer *pPlayer):
m_SlotID(slotID),
m_Assignment(SLOT_OPEN),
m_pSession(NULL),
m_SessionID(0),
m_pPlayer(pPlayer),
m_Callback(NULL)
{
ONCE(
ScriptingInit();
);
//AddProperty(L"session", (GetFn)&CPlayerSlot::JSI_GetSession);
AddLocalProperty(L"session", &m_pSession, true );
AddLocalProperty(L"player", &m_pPlayer, true );
}
CPlayerSlot::~CPlayerSlot()
{}
void CPlayerSlot::ScriptingInit()
{
AddMethod<bool, &CPlayerSlot::JSI_AssignClosed>("assignClosed", 0);
AddMethod<bool, &CPlayerSlot::JSI_AssignToSession>("assignToSession", 1);
AddMethod<bool, &CPlayerSlot::JSI_AssignLocal>("assignLocal", 0);
AddMethod<bool, &CPlayerSlot::JSI_AssignOpen>("assignOpen", 0);
AddProperty(L"assignment", &CPlayerSlot::JSI_GetAssignment);
// AddMethod<bool, &CPlayerSlot::JSI_AssignAI>("assignAI", <num_args>);
CJSObject<CPlayerSlot>::ScriptingInit("PlayerSlot");
}
jsval CPlayerSlot::JSI_GetSession(JSContext* UNUSED(cx))
{
if (m_pSession)
return OBJECT_TO_JSVAL(m_pSession->GetScript());
else
return JSVAL_NULL;
}
jsval CPlayerSlot::JSI_GetAssignment(JSContext* UNUSED(cx))
{
switch (m_Assignment)
{
case SLOT_CLOSED:
return g_ScriptingHost.UCStringToValue(L"closed");
case SLOT_OPEN:
return g_ScriptingHost.UCStringToValue(L"open");
case SLOT_SESSION:
return g_ScriptingHost.UCStringToValue(L"session");
/* case SLOT_AI:*/
default:
return INT_TO_JSVAL(m_Assignment);
}
}
bool CPlayerSlot::JSI_AssignClosed(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
AssignClosed();
return true;
}
bool CPlayerSlot::JSI_AssignOpen(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
AssignOpen();
return true;
}
bool CPlayerSlot::JSI_AssignToSession(JSContext* UNUSED(cx), uintN argc, jsval* argv)
{
if (argc != 1)
return false;
CNetServerSession *pSession=ToNative<CNetServerSession>(argv[0]);
if (pSession)
{
AssignToSession(pSession);
return true;
}
else
return true;
}
bool CPlayerSlot::JSI_AssignLocal(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
AssignToSessionID(1);
return true;
}
void CPlayerSlot::CallCallback()
{
if (m_Callback)
m_Callback(m_CallbackData, this);
}
void CPlayerSlot::SetAssignment(EPlayerSlotAssignment assignment,
CNetServerSession *pSession, int sessionID)
{
m_Assignment=assignment;
m_pSession=pSession;
m_SessionID=sessionID;
CallCallback();
}
void CPlayerSlot::AssignClosed()
{
SetAssignment(SLOT_CLOSED, NULL, -1);
}
void CPlayerSlot::AssignOpen()
{
SetAssignment(SLOT_OPEN, NULL, -1);
}
void CPlayerSlot::AssignToSession(CNetServerSession *pSession)
{
SetAssignment(SLOT_SESSION, pSession, pSession->GetID());
m_pPlayer->SetName(pSession->GetName());
}
void CPlayerSlot::AssignToSessionID(int id)
{
SetAssignment(SLOT_SESSION, NULL, id);
}
void CPlayerSlot::AssignLocal()
{
AssignToSessionID(1);
}
namespace PlayerSlotArray_JS
{
JSBool GetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp )
{
CGameAttributes *pInstance=(CGameAttributes *)JS_GetPrivate(cx, obj);
if (!JSVAL_IS_INT(id))
return JS_FALSE;
uint index=ToPrimitive<uint>(id);
if (index > pInstance->m_NumSlots)
return JS_FALSE;
*vp=OBJECT_TO_JSVAL(pInstance->m_PlayerSlots[index]->GetScript());
return JS_TRUE;
}
JSBool SetProperty( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* UNUSED(vp) )
{
return JS_FALSE;
}
JSClass Class = {
"PlayerSlotArray", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub,
GetProperty, SetProperty,
JS_EnumerateStub, JS_ResolveStub,
JS_ConvertStub, JS_FinalizeStub
};
JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* UNUSED(argv), jsval* rval )
{
if (argc != 0)
return JS_FALSE;
JSObject *newObj=JS_NewObject(cx, &Class, NULL, obj);
*rval=OBJECT_TO_JSVAL(newObj);
return JS_TRUE;
}
};
CGameAttributes::CGameAttributes():
m_MapFile("test01.pmp"),
m_NumSlots(8),
m_UpdateCB(NULL),
m_PlayerUpdateCB(NULL),
m_PlayerSlotAssignmentCB(NULL)
{
ONCE(
ScriptingInit();
);
m_PlayerSlotArrayJS=g_ScriptingHost.CreateCustomObject("PlayerSlotArray");
JS_AddRoot(g_ScriptingHost.GetContext(), &m_PlayerSlotArrayJS);
JS_SetPrivate(g_ScriptingHost.GetContext(), m_PlayerSlotArrayJS, this);
AddSynchedProperty(L"mapFile", &m_MapFile);
AddSynchedProperty(L"numSlots", &m_NumSlots, &CGameAttributes::OnNumSlotsUpdate);
AddSynchedProperty(L"losSetting", &m_LOSSetting);
#include "precompiled.h"
#include <sstream>
#include "GameAttributes.h"
#include "Game.h"
#include "ConfigDB.h"
#include "Network/ServerSession.h"
#include "CLogger.h"
#include "ps/XML/Xeromyces.h"
using namespace std;
CPlayerSlot::CPlayerSlot(int slotID, CPlayer *pPlayer):
m_SlotID(slotID),
m_Assignment(SLOT_OPEN),
m_pSession(NULL),
m_SessionID(0),
m_pPlayer(pPlayer),
m_Callback(NULL)
{
ONCE(
ScriptingInit();
);
//AddProperty(L"session", (GetFn)&CPlayerSlot::JSI_GetSession);
AddLocalProperty(L"session", &m_pSession, true );
AddLocalProperty(L"player", &m_pPlayer, true );
}
CPlayerSlot::~CPlayerSlot()
{}
void CPlayerSlot::ScriptingInit()
{
AddMethod<bool, &CPlayerSlot::JSI_AssignClosed>("assignClosed", 0);
AddMethod<bool, &CPlayerSlot::JSI_AssignToSession>("assignToSession", 1);
AddMethod<bool, &CPlayerSlot::JSI_AssignLocal>("assignLocal", 0);
AddMethod<bool, &CPlayerSlot::JSI_AssignOpen>("assignOpen", 0);
AddProperty(L"assignment", &CPlayerSlot::JSI_GetAssignment);
// AddMethod<bool, &CPlayerSlot::JSI_AssignAI>("assignAI", <num_args>);
CJSObject<CPlayerSlot>::ScriptingInit("PlayerSlot");
}
jsval CPlayerSlot::JSI_GetSession(JSContext* UNUSED(cx))
{
if (m_pSession)
return OBJECT_TO_JSVAL(m_pSession->GetScript());
else
return JSVAL_NULL;
}
jsval CPlayerSlot::JSI_GetAssignment(JSContext* UNUSED(cx))
{
switch (m_Assignment)
{
case SLOT_CLOSED:
return g_ScriptingHost.UCStringToValue(L"closed");
case SLOT_OPEN:
return g_ScriptingHost.UCStringToValue(L"open");
case SLOT_SESSION:
return g_ScriptingHost.UCStringToValue(L"session");
/* case SLOT_AI:*/
default:
return INT_TO_JSVAL(m_Assignment);
}
}
bool CPlayerSlot::JSI_AssignClosed(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
AssignClosed();
return true;
}
bool CPlayerSlot::JSI_AssignOpen(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
AssignOpen();
return true;
}
bool CPlayerSlot::JSI_AssignToSession(JSContext* UNUSED(cx), uintN argc, jsval* argv)
{
if (argc != 1)
return false;
CNetServerSession *pSession=ToNative<CNetServerSession>(argv[0]);
if (pSession)
{
AssignToSession(pSession);
return true;
}
else
return true;
}
bool CPlayerSlot::JSI_AssignLocal(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
AssignToSessionID(1);
return true;
}
void CPlayerSlot::CallCallback()
{
if (m_Callback)
m_Callback(m_CallbackData, this);
}
void CPlayerSlot::SetAssignment(EPlayerSlotAssignment assignment,
CNetServerSession *pSession, int sessionID)
{
m_Assignment=assignment;
m_pSession=pSession;
m_SessionID=sessionID;
CallCallback();
}
void CPlayerSlot::AssignClosed()
{
SetAssignment(SLOT_CLOSED, NULL, -1);
}
void CPlayerSlot::AssignOpen()
{
SetAssignment(SLOT_OPEN, NULL, -1);
}
void CPlayerSlot::AssignToSession(CNetServerSession *pSession)
{
SetAssignment(SLOT_SESSION, pSession, pSession->GetID());
m_pPlayer->SetName(pSession->GetName());
}
void CPlayerSlot::AssignToSessionID(int id)
{
SetAssignment(SLOT_SESSION, NULL, id);
}
void CPlayerSlot::AssignLocal()
{
AssignToSessionID(1);
}
namespace PlayerSlotArray_JS
{
JSBool GetProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp )
{
CGameAttributes *pInstance=(CGameAttributes *)JS_GetPrivate(cx, obj);
if (!JSVAL_IS_INT(id))
return JS_FALSE;
uint index=ToPrimitive<uint>(id);
if (index > pInstance->m_NumSlots)
return JS_FALSE;
*vp=OBJECT_TO_JSVAL(pInstance->m_PlayerSlots[index]->GetScript());
return JS_TRUE;
}
JSBool SetProperty( JSContext* UNUSED(cx), JSObject* UNUSED(obj), jsval UNUSED(id), jsval* UNUSED(vp) )
{
return JS_FALSE;
}
JSClass Class = {
"PlayerSlotArray", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub,
GetProperty, SetProperty,
JS_EnumerateStub, JS_ResolveStub,
JS_ConvertStub, JS_FinalizeStub
};
JSBool Construct( JSContext* cx, JSObject* obj, uint argc, jsval* UNUSED(argv), jsval* rval )
{
if (argc != 0)
return JS_FALSE;
JSObject *newObj=JS_NewObject(cx, &Class, NULL, obj);
*rval=OBJECT_TO_JSVAL(newObj);
return JS_TRUE;
}
};
CGameAttributes::CGameAttributes():
m_MapFile("test01.pmp"),
m_NumSlots(8),
m_UpdateCB(NULL),
m_PlayerUpdateCB(NULL),
m_PlayerSlotAssignmentCB(NULL)
{
ONCE(
ScriptingInit();
);
m_PlayerSlotArrayJS=g_ScriptingHost.CreateCustomObject("PlayerSlotArray");
JS_AddRoot(g_ScriptingHost.GetContext(), &m_PlayerSlotArrayJS);
JS_SetPrivate(g_ScriptingHost.GetContext(), m_PlayerSlotArrayJS, this);
AddSynchedProperty(L"mapFile", &m_MapFile);
AddSynchedProperty(L"numSlots", &m_NumSlots, &CGameAttributes::OnNumSlotsUpdate);
AddSynchedProperty(L"losSetting", &m_LOSSetting);
CXeromyces XeroFile;
if (XeroFile.Load("temp/players.xml") != PSRETURN_OK)
{
@ -207,11 +209,11 @@ CGameAttributes::CGameAttributes():
m_Players.push_back(new CPlayer(0));
m_Players.back()->SetName(L"Gaia");
m_Players.back()->SetColour(SPlayerColour(1.0f, 1.0f, 1.0f));
m_Players.back()->SetColour(SPlayerColour(1.0f, 1.0f, 1.0f));
m_Players.push_back(new CPlayer(1));
m_Players.back()->SetName(L"Player 1");
m_Players.back()->SetColour(SPlayerColour(0.4375f, 0.4375f, 0.8125f));
m_Players.back()->SetName(L"Player 1");
m_Players.back()->SetColour(SPlayerColour(0.4375f, 0.4375f, 0.8125f));
}
else
{
@ -232,187 +234,187 @@ CGameAttributes::CGameAttributes():
m_Players.back()->SetColour(SPlayerColour(r/255.0f, g/255.0f, b/255.0f));
}
}
std::vector<CPlayer *>::iterator it=m_Players.begin();
++it; // Skip Gaia - gaia doesn't account for a slot
for (;it != m_Players.end();++it)
{
m_PlayerSlots.push_back(new CPlayerSlot((*it)->GetPlayerID()-1, *it));
}
// The first player is always the server player in MP, or the local player
// in SP
m_PlayerSlots[0]->AssignToSessionID(1);
}
CGameAttributes::~CGameAttributes()
{
std::vector<CPlayerSlot *>::iterator it=m_PlayerSlots.begin();
while (it != m_PlayerSlots.end())
{
delete (*it)->GetPlayer();
delete *it;
++it;
}
// PT: ??? - Gaia isn't a player slot, but still needs to be deleted; but
// this feels rather unpleasantly inconsistent with the above code, so maybe
// there's a better way to avoid the memory leak.
delete m_Players[0];
JS_RemoveRoot(g_ScriptingHost.GetContext(), &m_PlayerSlotArrayJS);
}
void CGameAttributes::ScriptingInit()
{
g_ScriptingHost.DefineCustomObjectType(&PlayerSlotArray_JS::Class,
PlayerSlotArray_JS::Construct, 0, NULL, NULL, NULL, NULL);
AddMethod<jsval, &CGameAttributes::JSI_GetOpenSlot>("getOpenSlot", 0);
AddProperty(L"slots", &CGameAttributes::JSI_GetPlayerSlots);
CJSObject<CGameAttributes>::ScriptingInit("GameAttributes");
}
jsval CGameAttributes::JSI_GetOpenSlot(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
vector <CPlayerSlot *>::iterator it;
for (it = m_PlayerSlots.begin();it != m_PlayerSlots.end();++it)
{
if ((*it)->GetAssignment() == SLOT_OPEN)
return OBJECT_TO_JSVAL((*it)->GetScript());
}
return JSVAL_NULL;
}
jsval CGameAttributes::JSI_GetPlayerSlots(JSContext* UNUSED(cx))
{
return OBJECT_TO_JSVAL(m_PlayerSlotArrayJS);
}
void CGameAttributes::OnNumSlotsUpdate(CSynchedJSObjectBase *owner)
{
CGameAttributes *pInstance=(CGameAttributes*)owner;
// Clamp to a preset upper bound.
CConfigValue *val=g_ConfigDB.GetValue(CFG_MOD, "max_players");
uint maxPlayers=PS_MAX_PLAYERS;
if (val)
val->GetUnsignedInt(maxPlayers);
if (pInstance->m_NumSlots > maxPlayers)
pInstance->m_NumSlots = maxPlayers;
// Resize array according to new number of slots (note that the array
// size will go up to maxPlayers (above), but will never be made smaller -
// this to avoid losing player pointers and make sure they are all
// reclaimed in the end - it's just simpler that way ;-) )
if (pInstance->m_NumSlots > pInstance->m_PlayerSlots.size())
{
for (size_t i=pInstance->m_PlayerSlots.size();i<=pInstance->m_NumSlots;i++)
{
CPlayer *pNewPlayer=new CPlayer((uint)i+1);
pNewPlayer->SetUpdateCallback(pInstance->m_PlayerUpdateCB,
pInstance->m_PlayerUpdateCBData);
pInstance->m_Players.push_back(pNewPlayer);
CPlayerSlot *pNewSlot=new CPlayerSlot((uint)i, pNewPlayer);
pNewSlot->SetCallback(pInstance->m_PlayerSlotAssignmentCB,
pInstance->m_PlayerSlotAssignmentCBData);
pInstance->m_PlayerSlots.push_back(pNewSlot);
}
}
}
CPlayer *CGameAttributes::GetPlayer(int id)
{
if (id >= 0 && id < (int)m_Players.size())
{
return m_Players[id];
}
else
{
LOG(ERROR, "", "CGameAttributes::GetPlayer(): Attempt to get player %d (while there only are %d players)", id, m_Players.size());
return m_Players[0];
}
}
CPlayerSlot *CGameAttributes::GetSlot(int index)
{
if (index >= 0 && index < (int)m_PlayerSlots.size())
return m_PlayerSlots[index];
else
{
LOG(ERROR, "", "CGameAttributes::GetSlot(): Attempt to get slot %d (while there only are %d slots)", index, m_PlayerSlots.size());
return m_PlayerSlots[0];
}
}
void CGameAttributes::FinalizeSlots()
{
// Back up our old slots, and empty the resulting vector
vector<CPlayerSlot *> oldSlots;
oldSlots.swap(m_PlayerSlots);
vector<CPlayer *> oldPlayers;
oldPlayers.swap(m_Players);
m_Players.push_back(oldPlayers[0]); // Gaia
// Copy over the slots we want
uint assignedSlots=0;
for (size_t i=0;i<oldSlots.size();i++)
{
CPlayerSlot *slot=oldSlots[i];
EPlayerSlotAssignment assignment=slot->GetAssignment();
if (assignment != SLOT_OPEN && assignment != SLOT_CLOSED)
{
m_PlayerSlots.push_back(slot);
slot->GetPlayer()->SetPlayerID(assignedSlots+1);
m_Players.push_back(slot->GetPlayer());
assignedSlots++;
}
else
{
LOG(ERROR, "", "CGameAttributes::FinalizeSlots(): slot %d deleted", i);
delete slot->GetPlayer();
delete slot;
}
}
m_NumSlots=assignedSlots;
}
void CGameAttributes::SetValue(CStrW name, CStrW value)
{
ISynchedJSProperty *prop=GetSynchedProperty(name);
if (prop)
{
prop->FromString(value);
}
}
void CGameAttributes::Update(CStrW name, ISynchedJSProperty *attrib)
{
if (m_UpdateCB)
m_UpdateCB(name, attrib->ToString(), m_UpdateCBData);
}
void CGameAttributes::SetPlayerUpdateCallback(CPlayer::UpdateCallback *cb, void *userdata)
{
m_PlayerUpdateCB=cb;
m_PlayerUpdateCBData=userdata;
for (size_t i=0;i<m_Players.size();i++)
{
m_Players[i]->SetUpdateCallback(cb, userdata);
}
}
void CGameAttributes::SetPlayerSlotAssignmentCallback(PlayerSlotAssignmentCB *cb, void *userdata)
{
m_PlayerSlotAssignmentCB=cb;
m_PlayerSlotAssignmentCBData=userdata;
for (size_t i=0;i<m_PlayerSlots.size();i++)
{
m_PlayerSlots[i]->SetCallback(cb, userdata);
}
}
std::vector<CPlayer *>::iterator it=m_Players.begin();
++it; // Skip Gaia - gaia doesn't account for a slot
for (;it != m_Players.end();++it)
{
m_PlayerSlots.push_back(new CPlayerSlot((*it)->GetPlayerID()-1, *it));
}
// The first player is always the server player in MP, or the local player
// in SP
m_PlayerSlots[0]->AssignToSessionID(1);
}
CGameAttributes::~CGameAttributes()
{
std::vector<CPlayerSlot *>::iterator it=m_PlayerSlots.begin();
while (it != m_PlayerSlots.end())
{
delete (*it)->GetPlayer();
delete *it;
++it;
}
// PT: ??? - Gaia isn't a player slot, but still needs to be deleted; but
// this feels rather unpleasantly inconsistent with the above code, so maybe
// there's a better way to avoid the memory leak.
delete m_Players[0];
JS_RemoveRoot(g_ScriptingHost.GetContext(), &m_PlayerSlotArrayJS);
}
void CGameAttributes::ScriptingInit()
{
g_ScriptingHost.DefineCustomObjectType(&PlayerSlotArray_JS::Class,
PlayerSlotArray_JS::Construct, 0, NULL, NULL, NULL, NULL);
AddMethod<jsval, &CGameAttributes::JSI_GetOpenSlot>("getOpenSlot", 0);
AddProperty(L"slots", &CGameAttributes::JSI_GetPlayerSlots);
CJSObject<CGameAttributes>::ScriptingInit("GameAttributes");
}
jsval CGameAttributes::JSI_GetOpenSlot(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSED(argv))
{
vector <CPlayerSlot *>::iterator it;
for (it = m_PlayerSlots.begin();it != m_PlayerSlots.end();++it)
{
if ((*it)->GetAssignment() == SLOT_OPEN)
return OBJECT_TO_JSVAL((*it)->GetScript());
}
return JSVAL_NULL;
}
jsval CGameAttributes::JSI_GetPlayerSlots(JSContext* UNUSED(cx))
{
return OBJECT_TO_JSVAL(m_PlayerSlotArrayJS);
}
void CGameAttributes::OnNumSlotsUpdate(CSynchedJSObjectBase *owner)
{
CGameAttributes *pInstance=(CGameAttributes*)owner;
// Clamp to a preset upper bound.
CConfigValue *val=g_ConfigDB.GetValue(CFG_MOD, "max_players");
uint maxPlayers=PS_MAX_PLAYERS;
if (val)
val->GetUnsignedInt(maxPlayers);
if (pInstance->m_NumSlots > maxPlayers)
pInstance->m_NumSlots = maxPlayers;
// Resize array according to new number of slots (note that the array
// size will go up to maxPlayers (above), but will never be made smaller -
// this to avoid losing player pointers and make sure they are all
// reclaimed in the end - it's just simpler that way ;-) )
if (pInstance->m_NumSlots > pInstance->m_PlayerSlots.size())
{
for (size_t i=pInstance->m_PlayerSlots.size();i<=pInstance->m_NumSlots;i++)
{
CPlayer *pNewPlayer=new CPlayer((uint)i+1);
pNewPlayer->SetUpdateCallback(pInstance->m_PlayerUpdateCB,
pInstance->m_PlayerUpdateCBData);
pInstance->m_Players.push_back(pNewPlayer);
CPlayerSlot *pNewSlot=new CPlayerSlot((uint)i, pNewPlayer);
pNewSlot->SetCallback(pInstance->m_PlayerSlotAssignmentCB,
pInstance->m_PlayerSlotAssignmentCBData);
pInstance->m_PlayerSlots.push_back(pNewSlot);
}
}
}
CPlayer *CGameAttributes::GetPlayer(int id)
{
if (id >= 0 && id < (int)m_Players.size())
{
return m_Players[id];
}
else
{
LOG(ERROR, "", "CGameAttributes::GetPlayer(): Attempt to get player %d (while there only are %d players)", id, m_Players.size());
return m_Players[0];
}
}
CPlayerSlot *CGameAttributes::GetSlot(int index)
{
if (index >= 0 && index < (int)m_PlayerSlots.size())
return m_PlayerSlots[index];
else
{
LOG(ERROR, "", "CGameAttributes::GetSlot(): Attempt to get slot %d (while there only are %d slots)", index, m_PlayerSlots.size());
return m_PlayerSlots[0];
}
}
void CGameAttributes::FinalizeSlots()
{
// Back up our old slots, and empty the resulting vector
vector<CPlayerSlot *> oldSlots;
oldSlots.swap(m_PlayerSlots);
vector<CPlayer *> oldPlayers;
oldPlayers.swap(m_Players);
m_Players.push_back(oldPlayers[0]); // Gaia
// Copy over the slots we want
uint assignedSlots=0;
for (size_t i=0;i<oldSlots.size();i++)
{
CPlayerSlot *slot=oldSlots[i];
EPlayerSlotAssignment assignment=slot->GetAssignment();
if (assignment != SLOT_OPEN && assignment != SLOT_CLOSED)
{
m_PlayerSlots.push_back(slot);
slot->GetPlayer()->SetPlayerID(assignedSlots+1);
m_Players.push_back(slot->GetPlayer());
assignedSlots++;
}
else
{
LOG(ERROR, "", "CGameAttributes::FinalizeSlots(): slot %d deleted", i);
delete slot->GetPlayer();
delete slot;
}
}
m_NumSlots=assignedSlots;
}
void CGameAttributes::SetValue(CStrW name, CStrW value)
{
ISynchedJSProperty *prop=GetSynchedProperty(name);
if (prop)
{
prop->FromString(value);
}
}
void CGameAttributes::Update(CStrW name, ISynchedJSProperty *attrib)
{
if (m_UpdateCB)
m_UpdateCB(name, attrib->ToString(), m_UpdateCBData);
}
void CGameAttributes::SetPlayerUpdateCallback(CPlayer::UpdateCallback *cb, void *userdata)
{
m_PlayerUpdateCB=cb;
m_PlayerUpdateCBData=userdata;
for (size_t i=0;i<m_Players.size();i++)
{
m_Players[i]->SetUpdateCallback(cb, userdata);
}
}
void CGameAttributes::SetPlayerSlotAssignmentCallback(PlayerSlotAssignmentCB *cb, void *userdata)
{
m_PlayerSlotAssignmentCB=cb;
m_PlayerSlotAssignmentCBData=userdata;
for (size_t i=0;i<m_PlayerSlots.size();i++)
{
m_PlayerSlots[i]->SetCallback(cb, userdata);
}
}

View File

@ -11,6 +11,9 @@
*/
#include "precompiled.h"
#include <ctime>
#include "ProfileViewer.h"
#include "Profile.h"
#include "Renderer.h"

View File

@ -8,6 +8,7 @@
#include "maths/MathUtil.h"
#include "lib/ogl.h"
#include <algorithm>
// Handy things for STL:

View File

@ -7,6 +7,8 @@
#include "BaseEntity.h"
#include "lib/sysdep/sysdep.h" // finite
#include <cfloat>
// HEntity
template<> HEntity* ToNative<HEntity>( JSContext* cx, JSObject* obj )

View File

@ -1,5 +1,7 @@
#include "precompiled.h"
#include <queue>
#include "PathfindEngine.h"
//#include "PathfindSparse.h"
#include "ConfigDB.h"

View File

@ -2,6 +2,8 @@
#include "CommandProc.h"
#include <algorithm>
//////////////////////////////////////////////////////////////////////////
template<typename T> T next(T x) { T t = x; return ++t; }
@ -55,7 +57,7 @@ CommandProc::~CommandProc()
void CommandProc::Destroy()
{
for_each(m_Commands.begin(), m_Commands.end(), delete_fn<Command>);
std::for_each(m_Commands.begin(), m_Commands.end(), delete_fn<Command>);
m_Commands.clear();
}

View File

@ -1,3 +1,4 @@
#include <string>
#include <list>
#include <map>

View File

@ -1,6 +1,7 @@
#include "../Messages.h"
#include <map>
#include <string>
namespace AtlasMessage
{