Browse Source

Merge pull request #183 from Hoikas/score-rewrite

GameScore Rewrite
Branan Purvine-Riley 12 years ago
parent
commit
b5f70c4a53
  1. 1
      Sources/Plasma/FeatureLib/pfGameScoreMgr/CMakeLists.txt
  2. 478
      Sources/Plasma/FeatureLib/pfGameScoreMgr/pfGameScoreMgr.cpp
  3. 142
      Sources/Plasma/FeatureLib/pfGameScoreMgr/pfGameScoreMgr.h
  4. 2
      Sources/Plasma/FeatureLib/pfMessage/CMakeLists.txt
  5. 154
      Sources/Plasma/FeatureLib/pfMessage/pfGameScoreMsg.h
  6. 7
      Sources/Plasma/FeatureLib/pfMessage/pfMessageCreatable.h
  7. 6
      Sources/Plasma/FeatureLib/pfPython/CMakeLists.txt
  8. 15
      Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp
  9. 33
      Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp
  10. 1
      Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h
  11. 135
      Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp
  12. 41
      Sources/Plasma/FeatureLib/pfPython/pyGameScore.h
  13. 320
      Sources/Plasma/FeatureLib/pfPython/pyGameScoreGlue.cpp
  14. 118
      Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.cpp
  15. 149
      Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.h
  16. 251
      Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsgGlue.cpp
  17. 17
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp
  18. 17
      Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h
  19. 14
      Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp
  20. 4
      Sources/Plasma/FeatureLib/pfPython/pyPlayer.h
  21. 15
      Sources/Plasma/FeatureLib/pfPython/pyPlayerGlue.cpp
  22. 354
      Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.cpp
  23. 115
      Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.h
  24. 235
      Sources/Plasma/FeatureLib/pfPython/pyScoreMgrGlue.cpp
  25. 12
      Sources/Plasma/FeatureLib/pfPython/pyStatusLog.cpp
  26. 6
      Sources/Plasma/FeatureLib/pfPython/pyStatusLog.h
  27. 4
      Sources/Plasma/NucleusLib/inc/plCreatableIndex.h

1
Sources/Plasma/FeatureLib/pfGameScoreMgr/CMakeLists.txt

@ -2,6 +2,7 @@ include_directories(../../CoreLib)
include_directories(../../NucleusLib)
include_directories(../../NucleusLib/inc)
include_directories(../../PubUtilLib)
include_directories(../../FeatureLib)
set(pfGameScoreMgr_SOURCES
pfGameScoreMgr.cpp

478
Sources/Plasma/FeatureLib/pfGameScoreMgr/pfGameScoreMgr.cpp

@ -40,435 +40,141 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "pfGameScoreMgr.h"
#include "pnUtils/pnUtils.h"
#include "pfMessage/pfGameScoreMsg.h"
#include "plNetGameLib/plNetGameLib.h"
#include "pnNetProtocol/pnNetProtocol.h"
//============================================================================
pfGameScore::pfGameScore()
struct ScoreFindParam
{
}
uint32_t fOwnerId;
plString fName;
plKey fReceiver; // because plKey as a void* isn't cool
pfGameScore::~pfGameScore()
{
pfGameScoreMgr::GetInstance()->RemoveCachedScore(scoreId);
}
ScoreFindParam(uint32_t ownerId, plString name, plKey r)
: fOwnerId(ownerId), fName(name), fReceiver(r)
{ }
};
void pfGameScore::Init(
unsigned sid,
unsigned oid,
uint32_t createTime,
const char gname[],
unsigned gType,
int val
) {
scoreId = sid;
ownerId = oid;
createdTime = createTime;
gameType = gType;
value = val;
struct ScoreTransferParam
{
pfGameScore* fTo;
pfGameScore* fFrom;
int32_t fPoints;
plKey fReceiver;
ScoreTransferParam(pfGameScore* to, pfGameScore* from, int32_t points, plKey r)
: fTo(to), fFrom(from), fPoints(points), fReceiver(r)
{ }
};
StrCopy(gameName, gname, arrsize(gameName));
pfGameScoreMgr::GetInstance()->AddCachedScore(this);
}
struct ScoreUpdateParam
{
pfGameScore* fParent;
plKey fReceiver;
int32_t fPoints; // reset points to this if update op
void pfGameScore::CopyFrom(
const pfGameScore* score
) {
scoreId = score->scoreId;
ownerId = score->ownerId;
createdTime = score->createdTime;
gameType = score->gameType;
value = score->value;
ScoreUpdateParam(pfGameScore* s, plKey r, int32_t points = 0)
: fParent(s), fReceiver(r), fPoints(points)
{ }
};
StrCopy(gameName, score->gameName, arrsize(gameName));
//======================================
static void OnScoreSet(ENetError result, void* param)
{
ScoreUpdateParam* p = (ScoreUpdateParam*)param;
pfGameScoreUpdateMsg* msg = new pfGameScoreUpdateMsg(result, p->fParent, p->fPoints);
msg->Send(p->fReceiver);
delete p;
}
//============================================================================
pfGameScoreMgr::pfGameScoreMgr()
void pfGameScore::SetPoints(int32_t value, plKey rcvr)
{
Ref(); // netcode holds us
NetCliAuthScoreSetPoints(fScoreId, value, OnScoreSet, new ScoreUpdateParam(this, rcvr, value));
}
pfGameScoreMgr* pfGameScoreMgr::GetInstance()
//======================================
static void OnScoreUpdate(ENetError result, void* param)
{
static pfGameScoreMgr s_instance;
return &s_instance;
ScoreUpdateParam* p = (ScoreUpdateParam*)param;
pfGameScoreUpdateMsg* msg = new pfGameScoreUpdateMsg(result, p->fParent, p->fPoints);
msg->Send(p->fReceiver);
delete p;
}
void pfGameScoreMgr::AddCachedScore(pfGameScore * score)
void pfGameScore::AddPoints(int32_t add, plKey rcvr)
{
GameScoreLink * scoreLink = fScores.Find(score->scoreId);
if (scoreLink == nil)
{
GameScoreLink * link = new GameScoreLink(score);
fScores.Add(link);
}
else
scoreLink->score->CopyFrom(score);
Ref(); // netcode holds us
NetCliAuthScoreAddPoints(fScoreId, add, OnScoreUpdate, new ScoreUpdateParam(this, rcvr, fValue + add));
}
void pfGameScoreMgr::RemoveCachedScore(unsigned scoreId)
//======================================
void pfGameScore::Delete()
{
if (GameScoreLink * link = fScores.Find(scoreId))
{
delete link;
}
NetCliAuthScoreDelete(fScoreId, nil, nil); // who cares about getting a notify here?
UnRef(); // kthxbai
}
//============================================================================
struct NetWaitOp
//======================================
static void OnScoreTransfer(ENetError result, void* param)
{
ENetError result;
bool complete;
};
static void WaitOpCallback(
ENetError result,
void * param
) {
NetWaitOp * op = (NetWaitOp *)param;
op->result = result;
op->complete = true;
ScoreTransferParam* p = (ScoreTransferParam*)param;
pfGameScoreTransferMsg* msg = new pfGameScoreTransferMsg(result, p->fTo, p->fFrom, p->fPoints);
msg->Send(p->fReceiver);
delete p;
}
//============================================================================
// CreateScore
//============================================================================
struct CreateScoreOp : NetWaitOp
void pfGameScore::TransferPoints(pfGameScore* to, int32_t points, plKey recvr)
{
pfGameScore * score;
};
this->Ref(); to->Ref(); // netcode holds us
NetCliAuthScoreTransferPoints(this->fScoreId, to->fScoreId, points,
OnScoreTransfer, new ScoreTransferParam(to, this, points, recvr));
}
static void CreateScoreCallback(
//======================================
static void OnScoreCreate(
ENetError result,
void * param,
unsigned scoreId,
uint32_t createdTime,
unsigned ownerId,
uint32_t scoreId,
uint32_t createdTime, // ignored
uint32_t ownerId,
const char* gameName,
unsigned gameType,
int value
) {
CreateScoreOp * op = (CreateScoreOp*)param;
op->result = result;
if (IS_NET_SUCCESS(result)) {
op->score->Init(
scoreId,
ownerId,
createdTime,
gameName,
gameType,
value
);
}
else
op->score->scoreId = 0;
op->complete = true;
}
ENetError pfGameScoreMgr::CreateScore(
unsigned ownerId,
const char* gameName,
unsigned gameType,
int value,
pfGameScore& score
uint32_t gameType,
int32_t value
) {
CreateScoreOp param;
memset(&param, 0, sizeof(CreateScoreOp));
param.score = &score;
NetCliAuthScoreCreate(
ownerId,
gameName,
gameType,
value,
CreateScoreCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
return param.result;
}
//============================================================================
// DeleteScore
//============================================================================
ENetError pfGameScoreMgr::DeleteScore(
unsigned scoreId
) {
NetWaitOp param;
memset(&param, 0, sizeof(NetWaitOp));
NetCliAuthScoreDelete(
scoreId,
WaitOpCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
return param.result;
ScoreUpdateParam* p = (ScoreUpdateParam*)param;
pfGameScore* score = new pfGameScore(scoreId, ownerId, _TEMP_CONVERT_FROM_LITERAL(gameName), gameType, value);
pfGameScoreUpdateMsg* msg = new pfGameScoreUpdateMsg(result, score, value);
msg->Send(p->fReceiver);
delete p;
}
//============================================================================
// GetScores
//============================================================================
struct GetScoresOp : NetWaitOp
void pfGameScore::Create(uint32_t ownerId, const plString& name, uint32_t type, int32_t value, plKey rcvr)
{
pfGameScore*** scores;
int* scoreCount;
};
NetCliAuthScoreCreate(ownerId, name.c_str(), type, value, OnScoreCreate, new ScoreUpdateParam(nil, rcvr));
}
static void GetScoresCallback(
//======================================
static void OnScoreFound(
ENetError result,
void * param,
const NetGameScore scores[],
unsigned scoreCount
) {
GetScoresOp * op = (GetScoresOp*)param;
op->result = result;
if (IS_NET_SUCCESS(result)) {
*(op->scores) = new pfGameScore*[scoreCount];
*(op->scoreCount) = scoreCount;
for (int i = 0; i < scoreCount; ++i) {
pfGameScore* score = new pfGameScore();
score->IncRef();
char tempGameName[kMaxGameScoreNameLength];
StrToAnsi(tempGameName, scores[i].gameName, arrsize(tempGameName));
score->Init(
scores[i].scoreId,
scores[i].ownerId,
scores[i].createdTime,
tempGameName,
scores[i].gameType,
scores[i].value
);
(*op->scores)[i] = score;
}
}
else {
*(op->scores) = nil;
op->scoreCount = 0;
}
op->complete = true;
}
ENetError pfGameScoreMgr::GetScoresIncRef(
unsigned ownerId,
const char* gameName,
pfGameScore**& outScoreList,
int& outScoreListCount
) {
GetScoresOp param;
memset(&param, 0, sizeof(GetScoresOp));
param.scores = &outScoreList;
param.scoreCount = &outScoreListCount;
NetCliAuthScoreGetScores(
ownerId,
gameName,
GetScoresCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
return param.result;
}
//============================================================================
// AddPoints
//============================================================================
ENetError pfGameScoreMgr::AddPoints(
unsigned scoreId,
int numPoints
) {
NetWaitOp param;
memset(&param, 0, sizeof(NetWaitOp));
NetCliAuthScoreAddPoints(
scoreId,
numPoints,
WaitOpCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
if (IS_NET_SUCCESS(param.result)) {
if (GameScoreLink * link = fScores.Find(scoreId)) {
link->score->value += numPoints;
}
}
return param.result;
}
//============================================================================
// TransferPoints
//============================================================================
ENetError pfGameScoreMgr::TransferPoints(
unsigned srcScoreId,
unsigned destScoreId,
int numPoints
) {
NetWaitOp param;
memset(&param, 0, sizeof(NetWaitOp));
NetCliAuthScoreTransferPoints(
srcScoreId,
destScoreId,
numPoints,
WaitOpCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
if (IS_NET_SUCCESS(param.result)) {
if (GameScoreLink * link = fScores.Find(srcScoreId)) {
link->score->value -= numPoints;
}
if (GameScoreLink * link = fScores.Find(destScoreId)) {
link->score->value += numPoints;
}
}
return param.result;
}
//============================================================================
// SetPoints
//============================================================================
ENetError pfGameScoreMgr::SetPoints(
unsigned scoreId,
int numPoints
uint32_t scoreCount
) {
NetWaitOp param;
memset(&param, 0, sizeof(NetWaitOp));
NetCliAuthScoreSetPoints(
scoreId,
numPoints,
WaitOpCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
if (IS_NET_SUCCESS(param.result)) {
if (GameScoreLink * link = fScores.Find(scoreId)) {
link->score->value = numPoints;
}
std::vector<pfGameScore*> vec(scoreCount);
for (uint32_t i = 0; i < scoreCount; ++i)
{
const NetGameScore ngs = scores[i];
vec[i] = new pfGameScore(ngs.scoreId, ngs.ownerId, _TEMP_CONVERT_FROM_WCHAR_T(ngs.gameName), ngs.gameType, ngs.value);
}
return param.result;
ScoreFindParam* p = (ScoreFindParam*)param;
pfGameScoreListMsg* msg = new pfGameScoreListMsg(result, vec, p->fOwnerId, p->fName);
msg->Send(p->fReceiver);
delete p;
}
//============================================================================
// GetRankList
//============================================================================
struct GetRanksOp : NetWaitOp
void pfGameScore::Find(uint32_t ownerId, const plString& name, plKey rcvr)
{
NetGameRank*** ranks;
int* rankCount;
};
static void GetRanksCallback(
ENetError result,
void * param,
const NetGameRank ranks[],
unsigned rankCount
) {
GetRanksOp * op = (GetRanksOp*)param;
op->result = result;
if (IS_NET_SUCCESS(result)) {
*(op->ranks) = new NetGameRank*[rankCount];
*(op->rankCount) = rankCount;
for (int i = 0; i < rankCount; ++i) {
NetGameRank * rank = new NetGameRank;
rank->rank = ranks[i].rank;
rank->score = ranks[i].score;
StrCopy(rank->name, ranks[i].name, arrsize(rank->name));
(*op->ranks)[i] = rank;
}
}
else {
*(op->ranks) = nil;
op->rankCount = 0;
}
op->complete = true;
}
ENetError pfGameScoreMgr::GetRankList(
unsigned ownerId,
unsigned scoreGroup,
unsigned parentFolderId,
const char * gameName,
unsigned timePeriod,
unsigned numResults,
unsigned pageNumber,
bool sortDesc,
NetGameRank**& outRankList,
int& outRankListCount
) {
GetRanksOp param;
memset(&param, 0, sizeof(GetRanksOp));
param.ranks = &outRankList;
param.rankCount = &outRankListCount;
NetCliAuthScoreGetRankList(
ownerId,
scoreGroup,
parentFolderId,
gameName,
timePeriod,
numResults,
pageNumber,
sortDesc,
GetRanksCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
return param.result;
NetCliAuthScoreGetScores(ownerId, name.c_str(), OnScoreFound, new ScoreFindParam(ownerId, name, rcvr));
}

142
Sources/Plasma/FeatureLib/pfGameScoreMgr/pfGameScoreMgr.h

@ -39,115 +39,53 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameScoreMgr/pfGameScoreMgr.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMESCOREMGR_PFGAMESCOREMGR_H
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMESCOREMGR_PFGAMESCOREMGR_H
#ifndef _pfGameScoreMgr_h_
#define _pfGameScoreMgr_h_
#include "HeadSpin.h"
#include "pnKeyedObject/plKey.h"
#include "pnNetBase/pnNetBase.h"
#include "pnUtils/pnUtils.h"
struct NetGameRank;
struct pfGameScore : AtomicRef
#include "hsRefCnt.h"
#include "plString.h"
// TODO: Rank List (seems to be unused in regular gameplay though...)
// That's some strange stuff...
/**
* Plasma Game Score
* Mid-level class that encapsulates game scores and sends pfGameScoreMsg notifications
* via the dispatcher when network operations complete.
*/
class pfGameScore : public hsRefCnt
{
unsigned scoreId;
unsigned ownerId;
uint32_t createdTime;
char gameName[kMaxGameScoreNameLength];
unsigned gameType;
int value;
pfGameScore();
~pfGameScore();
void Init(
unsigned sid,
unsigned oid,
uint32_t createTime,
const char gname[],
unsigned gType,
int val
);
void CopyFrom(const pfGameScore* score);
};
uint32_t fScoreId;
uint32_t fOwnerId;
plString fName;
uint32_t fGameType; // EGameScoreTypes
int32_t fValue;
class pfGameScoreMgr
{
private:
pfGameScoreMgr();
struct GameScoreLink : THashKeyVal<unsigned>
{
HASHLINK(GameScoreLink) link;
pfGameScore * score;
GameScoreLink(pfGameScore * gscore)
: THashKeyVal<unsigned>(gscore->scoreId)
, score(gscore)
{
}
};
HASHTABLEDECL(
GameScoreLink,
THashKeyVal<unsigned>,
link
) fScores;
friend class pfGameScoreTransferMsg;
friend class pfGameScoreUpdateMsg;
public:
static pfGameScoreMgr* GetInstance();
void AddCachedScore(pfGameScore * score);
void RemoveCachedScore(unsigned scoreId);
ENetError CreateScore(
unsigned ownerId,
const char* gameName,
unsigned gameType,
int value,
pfGameScore& score
);
ENetError DeleteScore(
unsigned scoreId
);
ENetError AddPoints(
unsigned scoreId,
int numPoints
);
ENetError TransferPoints(
unsigned srcScoreId,
unsigned destScoreId,
int numPoints
);
ENetError SetPoints(
unsigned scoreId,
int numPoints
);
ENetError GetScoresIncRef(
unsigned ownerId,
const char* gameName,
pfGameScore**& outScoreList,
int& outScoreListCount
);
ENetError GetRankList(
unsigned ownerId,
unsigned scoreGroup,
unsigned parentFolderId,
const char * gameName,
unsigned timePeriod,
unsigned numResults,
unsigned pageNumber,
bool sortDesc,
NetGameRank**& outRankList,
int& outRankListCount
);
pfGameScore(uint32_t scoreId, uint32_t owner, plString name, uint32_t type, int32_t value = 0)
: fScoreId(scoreId), fOwnerId(owner), fName(name), fGameType(type), fValue(value)
{ }
plString GetGameName() const { return fName; }
uint32_t GetGameType() const { return fGameType; }
uint32_t GetOwner() const { return fOwnerId; }
int32_t GetPoints() const { return fValue; }
void SetPoints(int32_t value, plKey rcvr = nil);
void AddPoints(int32_t add, plKey rcvr = nil);
void Delete();
void TransferPoints(pfGameScore* to, plKey rcvr = nil) { TransferPoints(to, fValue, rcvr); }
void TransferPoints(pfGameScore* to, int32_t points, plKey rcvr = nil);
static void Create(uint32_t ownerId, const plString& name, uint32_t type, int32_t value, plKey rcvr);
static void Find(uint32_t ownerId, const plString& name, plKey rcvr);
};
#endif // PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMESCOREMGR_PFGAMESCOREMGR_H
#endif // _pfGameScoreMgr_h_

2
Sources/Plasma/FeatureLib/pfMessage/CMakeLists.txt

@ -2,6 +2,7 @@ include_directories(../../CoreLib)
include_directories(../../NucleusLib)
include_directories(../../NucleusLib/inc)
include_directories(../../PubUtilLib)
include_directories(../../FeatureLib)
set(pfMessage_SOURCES
pfKIMsg.cpp
@ -14,6 +15,7 @@ set(pfMessage_SOURCES
set(pfMessage_HEADERS
pfBackdoorMsg.h
pfGameGUIMsg.h
pfGameScoreMsg.h
pfGUINotifyMsg.h
pfKIMsg.h
pfMarkerMsg.h

154
Sources/Plasma/FeatureLib/pfMessage/pfGameScoreMsg.h

@ -0,0 +1,154 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef _pfGameScoreMsg_h_
#define _pfGameScoreMsg_h_
#include "HeadSpin.h"
#include "pfGameScoreMgr/pfGameScoreMgr.h"
#include "pnMessage/plMessage.h"
#include "pnNetBase/pnNetBase.h"
#include <vector>
class pfGameScore;
class pfGameScoreMsg : public plMessage
{
ENetError fResult;
public:
pfGameScoreMsg() { }
pfGameScoreMsg(ENetError result)
: fResult(result)
{ }
CLASSNAME_REGISTER(pfGameScoreMsg);
GETINTERFACE_ANY(pfGameScoreMsg, plMessage);
ENetError GetResult() const { return fResult; }
virtual void Read(hsStream*, hsResMgr*) { FATAL("wtf are you doing???"); }
virtual void Write(hsStream*, hsResMgr*) { FATAL("wtf are you doing???"); }
};
class pfGameScoreListMsg : public pfGameScoreMsg
{
std::vector<pfGameScore*> fScores;
uint32_t fOwnerId;
plString fName;
public:
pfGameScoreListMsg() { }
pfGameScoreListMsg(ENetError result, std::vector<pfGameScore*> vec, uint32_t ownerId, plString name)
: fScores(vec), pfGameScoreMsg(result), fOwnerId(ownerId), fName(name)
{ }
~pfGameScoreListMsg()
{
for (std::vector<pfGameScore*>::iterator it = fScores.begin(); it != fScores.end(); ++it)
(*it)->UnRef();
}
CLASSNAME_REGISTER(pfGameScoreListMsg);
GETINTERFACE_ANY(pfGameScoreListMsg, pfGameScoreMsg);
plString GetName() const { return fName; }
uint32_t GetOwnerID() const { return fOwnerId; }
size_t GetNumScores() const { return fScores.size(); }
pfGameScore* GetScore(size_t idx) const { return fScores.at(idx); }
};
class pfGameScoreTransferMsg : public pfGameScoreMsg
{
pfGameScore* fSource;
pfGameScore* fDestination;
public:
pfGameScoreTransferMsg() { }
pfGameScoreTransferMsg(ENetError result, pfGameScore* to, pfGameScore* from, int32_t points)
: fSource(from), fDestination(to), pfGameScoreMsg(result)
{
if (result == kNetSuccess)
{
from->fValue -= points;
to->fValue += points;
}
}
~pfGameScoreTransferMsg()
{
fSource->UnRef();
fDestination->UnRef();
}
CLASSNAME_REGISTER(pfGameScoreTransferMsg);
GETINTERFACE_ANY(pfGameScoreTransferMsg, pfGameScoreMsg);
pfGameScore* GetDestination() const { return fDestination; }
pfGameScore* GetSource() const { return fSource; }
};
class pfGameScoreUpdateMsg : public pfGameScoreMsg
{
pfGameScore* fScore;
public:
pfGameScoreUpdateMsg() { }
pfGameScoreUpdateMsg(ENetError result, pfGameScore* s, int32_t points)
: fScore(s), pfGameScoreMsg(result)
{
if (result == kNetSuccess)
s->fValue = points;
}
~pfGameScoreUpdateMsg()
{
fScore->UnRef();
}
CLASSNAME_REGISTER(pfGameScoreUpdateMsg);
GETINTERFACE_ANY(pfGameScoreUpdateMsg, pfGameScoreMsg);
pfGameScore* GetScore() const { return fScore; }
};
#endif // _pfGameScoreMsg_h_

7
Sources/Plasma/FeatureLib/pfMessage/pfMessageCreatable.h

@ -68,6 +68,13 @@ REGISTER_CREATABLE( plAvEnableMsg );
REGISTER_CREATABLE( pfGameGUIMsg );
#include "pfGameScoreMsg.h"
REGISTER_NONCREATABLE( pfGameScoreMsg );
REGISTER_CREATABLE( pfGameScoreListMsg );
REGISTER_CREATABLE( pfGameScoreTransferMsg );
REGISTER_CREATABLE( pfGameScoreUpdateMsg );
#include "pfGUINotifyMsg.h"
REGISTER_CREATABLE( pfGUINotifyMsg );

6
Sources/Plasma/FeatureLib/pfPython/CMakeLists.txt

@ -37,6 +37,7 @@ set(pfPython_SOURCES
pyDynamicText.cpp
pyEnum.cpp
pyGameScore.cpp
pyGameScoreMsg.cpp
pyGeometry3.cpp
pyGlueHelpers.cpp
pyGrassShader.cpp
@ -68,7 +69,6 @@ set(pfPython_SOURCES
pyNotify.cpp
pyPlayer.cpp
pySceneObject.cpp
pyScoreMgr.cpp
pySDL.cpp
pySpawnPointInfo.cpp
pyStatusLog.cpp
@ -125,6 +125,7 @@ set(pfPython_HEADERS
pyDynamicText.h
pyEnum.h
pyGameScore.h
pyGameScoreMsg.h
pyGeometry3.h
pyGrassShader.h
pyGUIControl.h
@ -155,7 +156,6 @@ set(pfPython_HEADERS
pyNotify.h
pyPlayer.h
pySceneObject.h
pyScoreMgr.h
pySDL.h
pySpawnPointInfo.h
pyStatusLog.h
@ -208,6 +208,7 @@ set(pfPython_GLUE
pyDrawControlGlue.cpp
pyDynamicTextGlue.cpp
pyGameScoreGlue.cpp
pyGameScoreMsgGlue.cpp
pyGeometry3Glue.cpp
pyGlueHelpers.h
pyGrassShaderGlue.cpp
@ -239,7 +240,6 @@ set(pfPython_GLUE
pyNotifyGlue.cpp
pyPlayerGlue.cpp
pySceneObjectGlue.cpp
pyScoreMgrGlue.cpp
pySDLGlue.cpp
pySpawnPointInfoGlue.cpp
pyStatusLogGlue.cpp

15
Sources/Plasma/FeatureLib/pfPython/cyPythonInterface.cpp

@ -154,8 +154,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pyCluster.h"
#include "pyGrassShader.h"
#include "pyScoreMgr.h"
#include "pyGameScore.h"
#include "pyGameScoreMsg.h"
#include "pyCritterBrain.h"
@ -1494,13 +1494,16 @@ void PythonInterface::AddPlasmaClasses()
// Shaders
pyGrassShader::AddPlasmaClasses(plasmaMod);
// Game Scores
pyScoreMgr::AddPlasmaClasses(plasmaMod);
pyGameScore::AddPlasmaClasses(plasmaMod);
// AI
pyCritterBrain::AddPlasmaClasses(plasmaMod);
// Game Scores
pyGameScore::AddPlasmaClasses(plasmaMod);
pyGameScoreMsg::AddPlasmaClasses(plasmaMod);
pyGameScoreListMsg::AddPlasmaClasses(plasmaMod);
pyGameScoreTransferMsg::AddPlasmaClasses(plasmaMod);
pyGameScoreUpdateMsg::AddPlasmaClasses(plasmaMod);
// Stupid thing
ptImportHook_AddPlasmaClasses(plasmaMod);
}
@ -1523,6 +1526,7 @@ void PythonInterface::AddPlasmaConstantsClasses()
//pyDrawControl::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyDynamicText::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyGameScore::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyGUIControlButton::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyGUIControlMultiLineEdit::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyJournalBook::AddPlasmaConstantsClasses(plasmaConstantsMod);
@ -1531,7 +1535,6 @@ void PythonInterface::AddPlasmaConstantsClasses()
pyNotify::AddPlasmaConstantsClasses(plasmaConstantsMod);
pySDL::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyStatusLog::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyScoreMgr::AddPlasmaConstantsClasses(plasmaConstantsMod);
pyAIMsg::AddPlasmaConstantsClasses(plasmaConstantsMod);

33
Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.cpp

@ -95,6 +95,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pfGameMgr/pfGameMgr.h"
#include "plMessage/plAIMsg.h"
#include "plAvatar/plAvBrainCritter.h"
#include "pfMessage/pfGameScoreMsg.h"
#include "plProfile.h"
@ -136,6 +137,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
// Game manager
#include "Games/pyGameMgrMsg.h"
#include "Games/pyGameCliMsg.h"
#include "pyGameScoreMsg.h"
#include <locale>
@ -189,6 +191,7 @@ const char* plPythonFileMod::fFunctionNames[] =
"OnGameMgrMsg", // kfunc_OnGameMgrMsg
"OnGameCliMsg", // kfunc_OnGameCliMsg
"OnAIMsg", // kfunc_OnAIMsg
"OnGameScoreMsg", // kfunc_OnGameScoreMsg
nil
};
@ -2821,6 +2824,36 @@ hsBool plPythonFileMod::MsgReceive(plMessage* msg)
}
}
if (fPyFunctionInstances[kfunc_OnGameScoreMsg])
{
pfGameScoreMsg* pScoreMsg = pfGameScoreMsg::ConvertNoRef(msg);
if (pScoreMsg)
{
plProfile_BeginTiming(PythonUpdate);
// Creates the final ptGameScoreMsg and ships it off to OnGameScoreMsg
PyObject* pyMsg = pyGameScoreMsg::CreateFinal(pScoreMsg);
PyObject* retVal = PyObject_CallMethod(
fPyFunctionInstances[kfunc_OnGameScoreMsg],
(char*)fFunctionNames[kfunc_OnGameScoreMsg],
"O", pyMsg
);
Py_DECREF(pyMsg);
if (retVal == nil)
{
#ifndef PLASMA_EXTERNAL_RELEASE
// for some reason this function didn't, remember that and not call it again
fPyFunctionInstances[kfunc_OnGameScoreMsg] = nil;
#endif //PLASMA_EXTERNAL_RELEASE
// if there was an error make sure that the stderr gets flushed so it can be seen
ReportError();
}
plProfile_EndTiming(PythonUpdate);
return true;
}
}
return plModifier::MsgReceive(msg);
}

1
Sources/Plasma/FeatureLib/pfPython/plPythonFileMod.h

@ -202,6 +202,7 @@ public:
kfunc_OnGameMgrMsg,
kfunc_OnGameCliMsg,
kfunc_OnAIMsg,
kfunc_OnGameScoreMsg,
kfunc_lastone
};
// array of matching Python instance where the functions are, if defined

135
Sources/Plasma/FeatureLib/pfPython/pyGameScore.cpp

@ -40,98 +40,147 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "pyGameScore.h"
#include "pfGameScoreMgr/pfGameScoreMgr.h"
#include "pyKey.h"
#include "plVault/plVault.h"
pyGameScore::pyGameScore() : fScore(nil)
{
}
pyGameScore::pyGameScore()
: fScore(nil)
{ }
pyGameScore::pyGameScore(pfGameScore * score) : fScore(score)
pyGameScore::pyGameScore(pfGameScore * score)
: fScore(score)
{
fScore->IncRef();
hsRefCnt_SafeRef(score);
}
pyGameScore::~pyGameScore()
{
if (fScore)
fScore->DecRef();
hsRefCnt_SafeUnRef(fScore);
}
int pyGameScore::GetScoreID()
uint32_t pyGameScore::GetOwnerID() const
{
if (fScore)
return fScore->scoreId;
return fScore->GetOwner();
return 0;
}
uint32_t pyGameScore::GetCreatedTime()
int32_t pyGameScore::GetGameType() const
{
if (fScore)
return fScore->createdTime;
return fScore->GetGameType();
return 0;
}
int pyGameScore::GetOwnerID()
int32_t pyGameScore::GetPoints() const
{
if (fScore)
return fScore->ownerId;
return fScore->GetPoints();
return 0;
}
int pyGameScore::GetGameType()
plString pyGameScore::GetGameName() const
{
if (fScore)
return fScore->gameType;
return 0;
return fScore->GetGameName();
return plString::Null;
}
int pyGameScore::GetValue()
void pyGameScore::AddPoints(int32_t numPoints, pyKey& rcvr)
{
if (fScore)
return fScore->value;
return 0;
fScore->AddPoints(numPoints, rcvr.getKey());
}
const char* pyGameScore::GetGameName()
void pyGameScore::Delete()
{
if (fScore)
return fScore->gameName;
{
fScore->Delete();
fScore = nil;
}
}
return "";
void pyGameScore::TransferPoints(pyGameScore* dest, pyKey& rcvr)
{
if (fScore && dest->fScore)
fScore->TransferPoints(dest->fScore, rcvr.getKey());
}
bool pyGameScore::AddPoints(int numPoints)
void pyGameScore::TransferPoints(pyGameScore* dest, int32_t numPoints, pyKey& rcvr)
{
ENetError result = kNetErrScoreWrongType;
if (fScore && dest->fScore)
fScore->TransferPoints(dest->fScore, numPoints, rcvr.getKey());
}
if (fScore && fScore->gameType != kScoreTypeFixed)
result = pfGameScoreMgr::GetInstance()->AddPoints(fScore->scoreId, numPoints);
void pyGameScore::SetPoints(int32_t numPoints, pyKey& rcvr)
{
if (fScore)
fScore->SetPoints(numPoints, rcvr.getKey());
}
return IS_NET_SUCCESS(result);
void pyGameScore::CreateAgeScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr)
{
if (RelVaultNode* ageInfo = VaultGetAgeInfoNodeIncRef())
{
uint32_t ownerId = ageInfo->nodeId;
pfGameScore::Create(ownerId, name, type, points, rcvr.getKey());
ageInfo->DecRef();
} else
hsAssert(false, "Age has no vault... Need to rewrite score python script?");
}
bool pyGameScore::TransferPoints(unsigned destination, int numPoints)
void pyGameScore::CreateGlobalScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr)
{
ENetError result = kNetErrScoreWrongType;
pfGameScore::Create(0, name, type, points, rcvr.getKey());
}
void pyGameScore::CreatePlayerScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr)
{
if (RelVaultNode* node = VaultGetPlayerInfoNodeIncRef())
{
uint32_t ownerId = node->nodeId;
pfGameScore::Create(ownerId, name, type, points, rcvr.getKey());
node->DecRef();
} else
hsAssert(false, "No PlayerInfo node... Need to rewrite python script?");
}
if (fScore && fScore->gameType != kScoreTypeFixed)
result = pfGameScoreMgr::GetInstance()->TransferPoints(fScore->scoreId, destination, numPoints);
void pyGameScore::CreateScore(uint32_t ownerId, const plString& name, uint32_t type, int32_t points, pyKey& rcvr)
{
pfGameScore::Create(ownerId, name, type, points, rcvr.getKey());
}
return IS_NET_SUCCESS(result);
void pyGameScore::FindAgeScores(const plString& name, pyKey& rcvr)
{
if (RelVaultNode* ageInfo = VaultGetAgeInfoNodeIncRef())
{
uint32_t ownerId = ageInfo->nodeId;
pfGameScore::Find(ownerId, name, rcvr.getKey());
ageInfo->DecRef();
} else
hsAssert(false, "Age has no vault... Need to rewrite score python script?");
}
bool pyGameScore::SetPoints(int numPoints)
void pyGameScore::FindGlobalScores(const plString& name, pyKey& rcvr)
{
ENetError result = kNetErrScoreWrongType;
pfGameScore::Find(0, name, rcvr.getKey());
}
if (fScore && fScore->gameType != kScoreTypeFixed)
result = pfGameScoreMgr::GetInstance()->SetPoints(fScore->scoreId, numPoints);
void pyGameScore::FindPlayerScores(const plString& name, pyKey& rcvr)
{
if (RelVaultNode* node = VaultGetPlayerInfoNodeIncRef())
{
uint32_t ownerId = node->nodeId;
pfGameScore::Find(ownerId, name, rcvr.getKey());
node->DecRef();
}
else
hsAssert(false, "No PlayerInfo node.. Need to rewrite python script?");
}
return IS_NET_SUCCESS(result);
void pyGameScore::FindScores(uint32_t ownerId, const plString& name, pyKey& rcvr)
{
pfGameScore::Find(ownerId, name, rcvr.getKey());
}

41
Sources/Plasma/FeatureLib/pfPython/pyGameScore.h

@ -39,8 +39,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021
*==LICENSE==*/
#ifndef pyGameScore_h
#define pyGameScore_h
#ifndef _pyGameScore_h_
#define _pyGameScore_h_
/////////////////////////////////////////////////////////////////////////////
//
@ -52,10 +52,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Python.h>
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "plString.h"
#include "pyGlueHelpers.h"
struct pfGameScore;
class pfGameScore;
class pyKey;
class pyGameScore
{
@ -74,17 +76,28 @@ public:
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScore); // converts a PyObject to a pyGameScore (throws error if not correct type)
static void AddPlasmaClasses(PyObject *m);
int GetScoreID();
uint32_t GetCreatedTime();
int GetOwnerID();
int GetGameType();
int GetValue();
const char* GetGameName();
bool AddPoints(int numPoints);
bool TransferPoints(unsigned destination, int numPoints);
bool SetPoints(int numPoints);
static void AddPlasmaConstantsClasses(PyObject *m);
uint32_t GetOwnerID() const;
int32_t GetGameType() const;
int32_t GetPoints() const;
plString GetGameName() const;
void AddPoints(int32_t numPoints, pyKey& rcvr);
void Delete();
void TransferPoints(pyGameScore* dest, pyKey& rcvr);
void TransferPoints(pyGameScore* dest, int32_t numPoints, pyKey& rcvr);
void SetPoints(int32_t numPoints, pyKey& rcvr);
static void CreateAgeScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr);
static void CreateGlobalScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr);
static void CreatePlayerScore(const plString& name, uint32_t type, int32_t points, pyKey& rcvr);
static void CreateScore(uint32_t ownerId, const plString& name, uint32_t type, int32_t points, pyKey& rcvr);
static void FindAgeScores(const plString& name, pyKey& rcvr);
static void FindGlobalScores(const plString& name, pyKey& rcvr);
static void FindPlayerScores(const plString& name, pyKey& rcvr);
static void FindScores(uint32_t ownerId, const plString& name, pyKey& rcvr);
};
#endif

320
Sources/Plasma/FeatureLib/pfPython/pyGameScoreGlue.cpp

@ -40,8 +40,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/
#include "pyGameScore.h"
#include "pyEnum.h"
#include "pfGameScoreMgr/pfGameScoreMgr.h"
#include "pyKey.h"
// glue functions
PYTHON_CLASS_DEFINITION(ptGameScore, pyGameScore);
@ -51,97 +52,309 @@ PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScore)
PYTHON_NO_INIT_DEFINITION(ptGameScore)
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getScoreID)
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getOwnerID)
{
return PyInt_FromLong(self->fThis->GetScoreID());
return PyLong_FromLong(self->fThis->GetOwnerID());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getCreatedTime)
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getPoints)
{
return PyLong_FromUnsignedLong(self->fThis->GetCreatedTime());
return PyLong_FromLong(self->fThis->GetPoints());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getOwnerID)
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getGameType)
{
return PyInt_FromLong(self->fThis->GetOwnerID());
return PyInt_FromLong(self->fThis->GetGameType());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getValue)
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getName)
{
return PyInt_FromLong(self->fThis->GetValue());
return PyUnicode_FromStringEx(self->fThis->GetGameName());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getGameType)
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, remove)
{
return PyInt_FromLong(self->fThis->GetGameType());
self->fThis->Delete();
PYTHON_RETURN_NONE; // who cares about a result?
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScore, getGameName)
PYTHON_METHOD_DEFINITION(ptGameScore, addPoints, args)
{
return PyString_FromString(self->fThis->GetGameName());
int32_t numPoints = 0;
PyObject* keyObj = nil;
if (!PyArg_ParseTuple(args, "i|O", &numPoints, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "addPoints expects an int and an optional key");
PYTHON_RETURN_ERROR;
}
if (!pyKey::Check(keyObj))
{
PyErr_SetString(PyExc_TypeError, "addPoints expects an int and an optional key");
PYTHON_RETURN_ERROR;
}
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
self->fThis->AddPoints(numPoints, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION(ptGameScore, addPoints, args)
PYTHON_METHOD_DEFINITION_WKEY(ptGameScore, transferPoints, args, kwargs)
{
int numPoints = 0;
if (!PyArg_ParseTuple(args, "i", &numPoints))
char* kwlist[] = { "dest", "points", "key", nil };
PyObject* destObj = nil;
int32_t points = 0; // Hmmm... Evil?
PyObject* keyObj = nil;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist, &destObj, &points, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "addPoints expects an int");
PyErr_SetString(PyExc_TypeError, "transferPoints expects a ptGameScore, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
if (!(pyGameScore::Check(destObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "transferPoints expects a ptGameScore, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
PYTHON_RETURN_BOOL(self->fThis->AddPoints(numPoints));
pyGameScore* dest = pyGameScore::ConvertFrom(destObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
if (points)
self->fThis->TransferPoints(dest, points, *rcvr);
else
self->fThis->TransferPoints(dest, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION(ptGameScore, transferPoints, args)
PYTHON_METHOD_DEFINITION(ptGameScore, setPoints, args)
{
unsigned destination = 0;
int numPoints = 0;
if (!PyArg_ParseTuple(args, "Ii", &destination, &numPoints))
int32_t numPoints = 0;
PyObject* keyObj = nil;
if (!PyArg_ParseTuple(args, "i|O", &numPoints))
{
PyErr_SetString(PyExc_TypeError, "transferPoints expects an unsigned int and an int");
PyErr_SetString(PyExc_TypeError, "setPoints expects an int and an optional ptKey");
PYTHON_RETURN_ERROR;
}
if (!pyKey::Check(keyObj))
{
PyErr_SetString(PyExc_TypeError, "setPoints expects an int and an optional ptKey");
PYTHON_RETURN_ERROR;
}
PYTHON_RETURN_BOOL(self->fThis->TransferPoints(destination, numPoints));
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
self->fThis->SetPoints(numPoints, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION(ptGameScore, setPoints, args)
PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createAgeScore, args, kwargs)
{
char* kwlist[] = { "scoreName", "type", "points", "key", nil };
PyObject* nameObj = nil;
uint32_t type = 0;
int32_t points = 0;
PyObject* keyObj = nil;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OI|iO", kwlist, &nameObj, &type, &points, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "createAgeScore expects a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "createAgeScore expects a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::CreateAgeScore(name, type, points, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createGlobalScore, args, kwargs)
{
char* kwlist[] = { "scoreName", "type", "points", "key", nil };
PyObject* nameObj = nil;
uint32_t type = 0;
int32_t points = 0;
PyObject* keyObj = nil;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OI|iO", kwlist, &nameObj, &type, &points, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "createGlobalScore expects a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "createGlobalScore expects a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::CreateGlobalScore(name, type, points, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createPlayerScore, args, kwargs)
{
char* kwlist[] = { "scoreName", "type", "points", "key", nil };
PyObject* nameObj = nil;
uint32_t type = 0;
int32_t points = 0;
PyObject* keyObj = nil;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OI|iO", kwlist, &nameObj, &type, &points, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "createPlayerScore expects a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "createPlayerScore expects a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::CreatePlayerScore(name, type, points, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION_STATIC_WKEY(ptGameScore, createScore, args, kwargs)
{
char* kwlist[] = { "ownerID", "scoreName", "type", "points", "key", nil };
uint32_t ownerID = 0;
PyObject* nameObj = nil;
uint32_t type = 0;
int32_t points = 0;
PyObject* keyObj = nil;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "IOI|iO", kwlist, &ownerID, &nameObj, &type, &points, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "createScore expects an int, a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "createScore expects an int, a string, an int, an optional int, and an optional ptKey");
PYTHON_RETURN_ERROR;
}
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::CreateScore(ownerID, name, type, points, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findAgeScores, args)
{
int numPoints = 0;
if (!PyArg_ParseTuple(args, "i", &numPoints))
PyObject* nameObj = nil;
PyObject* keyObj = nil;
if (!PyArg_ParseTuple(args, "OO", &nameObj, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "findAgeScores expects a string and a ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "findAgeScores expects a string and a ptKey");
PYTHON_RETURN_ERROR;
}
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::FindAgeScores(name, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findGlobalScores, args)
{
PyObject* nameObj = nil;
PyObject* keyObj = nil;
if (!PyArg_ParseTuple(args, "OO", &nameObj, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "findGlobalScores expects a string and a ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "setPoints expects an int");
PyErr_SetString(PyExc_TypeError, "findGlobalScores expects a string and a ptKey");
PYTHON_RETURN_ERROR;
}
PYTHON_RETURN_BOOL(self->fThis->SetPoints(numPoints));
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::FindGlobalScores(name, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findPlayerScores, args)
{
PyObject* nameObj = nil;
PyObject* keyObj = nil;
if (!PyArg_ParseTuple(args, "OO", &nameObj, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "findPlayerScores expects a string and a ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "findPlayerScores expects a string and a ptKey");
PYTHON_RETURN_ERROR;
}
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::FindPlayerScores(name, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_METHOD_DEFINITION_STATIC(ptGameScore, findScores, args)
{
uint32_t ownerId = 0;
PyObject* nameObj = nil;
PyObject* keyObj = nil;
if (!PyArg_ParseTuple(args, "IOO", &ownerId, &nameObj, &keyObj))
{
PyErr_SetString(PyExc_TypeError, "findScore expects an int, a string, and a ptKey");
PYTHON_RETURN_ERROR;
}
if (!(PyString_CheckEx(nameObj) && pyKey::Check(keyObj)))
{
PyErr_SetString(PyExc_TypeError, "findScore expects an int, a string, and a ptKey");
PYTHON_RETURN_ERROR;
}
plString name = PyString_AsStringEx(nameObj);
pyKey* rcvr = pyKey::ConvertFrom(keyObj);
pyGameScore::FindScores(ownerId, name, *rcvr);
PYTHON_RETURN_NONE; // get result in callback
}
PYTHON_START_METHODS_TABLE(ptGameScore)
PYTHON_METHOD_NOARGS(ptGameScore, getScoreID, "Returns the score id."),
PYTHON_METHOD_NOARGS(ptGameScore, getOwnerID, "Returns a the score owner id."),
PYTHON_METHOD_NOARGS(ptGameScore, getCreatedTime, "Returns a the score creation time."),
PYTHON_METHOD_NOARGS(ptGameScore, getValue, "Returns a the score owner value."),
PYTHON_METHOD_NOARGS(ptGameScore, getGameType, "Returns a the score game type."),
PYTHON_METHOD_NOARGS(ptGameScore, getGameName, "Returns a the score game name."),
PYTHON_METHOD(ptGameScore, addPoints, "Params: numPoints\nAdds points to the score"),
PYTHON_METHOD(ptGameScore, transferPoints, "Params: dest, numPoints\nTransfers points from one score to another"),
PYTHON_METHOD(ptGameScore, setPoints, "Params: numPoints\nSets the number of points in the score\nDon't use to add/remove points, use only to reset values!"),
PYTHON_METHOD_NOARGS(ptGameScore, getGameType, "Returns the score game type."),
PYTHON_METHOD_NOARGS(ptGameScore, getName, "Returns the score game name."),
PYTHON_METHOD_NOARGS(ptGameScore, getOwnerID, "Returns the score owner."),
PYTHON_METHOD_NOARGS(ptGameScore, getPoints, "Returns the number of points in this score"),
PYTHON_METHOD_NOARGS(ptGameScore, remove, "Removes this score from the server"),
PYTHON_METHOD(ptGameScore, addPoints, "Params: points, key\nAdds points to the score"),
PYTHON_METHOD_WKEY(ptGameScore, transferPoints, "Params: dest, points, key\nTransfers points from this score to another"),
PYTHON_METHOD(ptGameScore, setPoints, "Params: numPoints, key\nSets the number of points in the score\nDon't use to add/remove points, use only to reset values!"),
PYTHON_METHOD_STATIC_WKEY(ptGameScore, createAgeScore, "Params: scoreName, type, points, key\nCreates a new score associated with this age"),
PYTHON_METHOD_STATIC_WKEY(ptGameScore, createGlobalScore, "Params: scoreName, type, points, key\nCreates a new global score"),
PYTHON_METHOD_STATIC_WKEY(ptGameScore, createPlayerScore, "Params: scoreName, type, points, key\nCreates a new score associated with this player"),
PYTHON_METHOD_STATIC_WKEY(ptGameScore, createScore, "Params: ownerID, scoreName, type, points, key\nCreates a new score for an arbitrary owner"),
PYTHON_METHOD_STATIC(ptGameScore, findAgeScores, "Params: scoreName, key\nFinds matching scores for this age"),
PYTHON_METHOD_STATIC(ptGameScore, findGlobalScores, "Params: scoreName, key\nFinds matching global scores"),
PYTHON_METHOD_STATIC(ptGameScore, findPlayerScores, "Params: scoreName, key\nFinds matching player scores"),
PYTHON_METHOD_STATIC(ptGameScore, findScores, "Params: ownerID, scoreName, key\nFinds matching scores for an arbitrary owner"),
PYTHON_END_METHODS_TABLE;
// Type structure definition
PLASMA_DEFAULT_TYPE(ptGameScore, "Game score manager");
PLASMA_DEFAULT_TYPE(ptGameScore, "Plasma Game Score");
// required functions for PyObject interoperability
PyObject* pyGameScore::New(pfGameScore* score)
{
ptGameScore* newObj = (ptGameScore*)ptGameScore_type.tp_new(&ptGameScore_type, NULL, NULL);
if (newObj->fThis->fScore)
newObj->fThis->fScore->DecRef();
hsRefCnt_SafeUnRef(newObj->fThis->fScore);
newObj->fThis->fScore = score;
if (newObj->fThis->fScore)
newObj->fThis->fScore->IncRef();
hsRefCnt_SafeRef(newObj->fThis->fScore);
return (PyObject*)newObj;
}
@ -158,3 +371,24 @@ void pyGameScore::AddPlasmaClasses(PyObject *m)
PYTHON_CLASS_IMPORT(m, ptGameScore);
PYTHON_CLASS_IMPORT_END(m);
}
void pyGameScore::AddPlasmaConstantsClasses(PyObject *m)
{
PYTHON_ENUM_START(PtGameScoreTypes);
PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kFixed, kScoreTypeFixed);
PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumulative, kScoreTypeAccumulative);
PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumAllowNegative, kScoreTypeAccumAllowNegative);
PYTHON_ENUM_END(m, PtGameScoreTypes);
PYTHON_ENUM_START(PtScoreRankGroups);
PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kIndividual, kScoreRankGroupIndividual);
PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kNeighborhood, kScoreRankGroupNeighborhood);
PYTHON_ENUM_END(m, PtScoreRankGroups);
PYTHON_ENUM_START(PtScoreTimePeriods);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kOverall, kScoreTimePeriodOverall);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kYear, kScoreTimePeriodYear);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kMonth, kScoreTimePeriodMonth);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kDay, kScoreTimePeriodDay);
PYTHON_ENUM_END(m, PtScoreTimePeriods);
}

118
Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.cpp

@ -0,0 +1,118 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "pyGameScoreMsg.h"
#include "pyGameScore.h"
PyObject* pyGameScoreMsg::CreateFinal(pfGameScoreMsg* msg)
{
if (pfGameScoreListMsg* l = pfGameScoreListMsg::ConvertNoRef(msg))
return pyGameScoreListMsg::New(l);
if (pfGameScoreTransferMsg* t = pfGameScoreTransferMsg::ConvertNoRef(msg))
return pyGameScoreTransferMsg::New(t);
if (pfGameScoreUpdateMsg* u = pfGameScoreUpdateMsg::ConvertNoRef(msg))
return pyGameScoreUpdateMsg::New(u);
return nil;
}
plString pyGameScoreMsg::GetError() const
{
if (fMsg)
return _TEMP_CONVERT_FROM_WCHAR_T(NetErrorToString(fMsg->GetResult()));
return _TEMP_CONVERT_FROM_LITERAL("pfGameScoreMsg is NULL");
}
bool pyGameScoreMsg::IsValid() const
{
if (fMsg)
return IS_NET_SUCCESS(fMsg->GetResult());
return false;
}
plString pyGameScoreListMsg::GetName() const
{
if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg))
return pList->GetName();
return plString::Null;
}
uint32_t pyGameScoreListMsg::GetOwnerID() const
{
if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg))
return pList->GetOwnerID();
return 0;
}
size_t pyGameScoreListMsg::GetNumScores() const
{
if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg))
return pList->GetNumScores();
return 0;
}
PyObject* pyGameScoreListMsg::GetScore(size_t idx) const
{
if (pfGameScoreListMsg* pList = pfGameScoreListMsg::ConvertNoRef(fMsg))
return pyGameScore::New(pList->GetScore(idx));
return nil;
}
PyObject* pyGameScoreTransferMsg::GetDestinationScore() const
{
if (pfGameScoreTransferMsg* pTrans = pfGameScoreTransferMsg::ConvertNoRef(fMsg))
return pyGameScore::New(pTrans->GetDestination());
return nil;
}
PyObject* pyGameScoreTransferMsg::GetSourceScore() const
{
if (pfGameScoreTransferMsg* pTrans = pfGameScoreTransferMsg::ConvertNoRef(fMsg))
return pyGameScore::New(pTrans->GetSource());
return nil;
}
PyObject* pyGameScoreUpdateMsg::GetScore() const
{
if (pfGameScoreUpdateMsg* pUp = pfGameScoreUpdateMsg::ConvertNoRef(fMsg))
return pyGameScore::New(pUp->GetScore());
return nil;
}

149
Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsg.h

@ -0,0 +1,149 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef _pyGameScoreMsg_h_
#define _pyGameScoreMsg_h_
#include "pyGlueHelpers.h"
#include "pfMessage/pfGameScoreMsg.h"
class pyGameScoreMsg
{
protected:
pfGameScoreMsg* fMsg;
pyGameScoreMsg()
: fMsg(nil)
{ }
pyGameScoreMsg(pfGameScoreMsg* msg)
: fMsg(msg)
{
hsRefCnt_SafeRef(msg);
}
public:
virtual ~pyGameScoreMsg()
{
hsRefCnt_SafeUnRef(fMsg);
}
// required functions for PyObject interoperability
PYTHON_EXPOSE_TYPE; // so we can subclass
PYTHON_CLASS_NEW_FRIEND(ptGameScoreMsg);
static PyObject* CreateFinal(pfGameScoreMsg* msg); // returns the proper descendant. Note there is no New
PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreMsg object
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreMsg); // converts a PyObject to a pyGameScoreMsg (throws error if not correct type)
plString GetError() const;
bool IsValid() const;
static void AddPlasmaClasses(PyObject* m);
};
class pyGameScoreListMsg : public pyGameScoreMsg
{
pyGameScoreListMsg()
: pyGameScoreMsg()
{ }
pyGameScoreListMsg(pfGameScoreListMsg* msg)
: pyGameScoreMsg(msg)
{ }
public:
PYTHON_CLASS_NEW_FRIEND(ptGameScoreListMsg);
static PyObject* New(pfGameScoreListMsg* msg);
PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreListMsg object
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreListMsg); // converts a PyObject to a pyGameScoreListMsg (throws error if not correct type)
static void AddPlasmaClasses(PyObject* m);
plString GetName() const;
uint32_t GetOwnerID() const;
size_t GetNumScores() const;
PyObject* GetScore(size_t idx) const;
};
class pyGameScoreTransferMsg : public pyGameScoreMsg
{
pyGameScoreTransferMsg()
: pyGameScoreMsg()
{ }
pyGameScoreTransferMsg(pfGameScoreTransferMsg* msg)
: pyGameScoreMsg(msg)
{ }
public:
PYTHON_CLASS_NEW_FRIEND(ptGameScoreTransferMsg);
static PyObject* New(pfGameScoreTransferMsg* msg);
PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreTransferMsg object
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreTransferMsg); // converts a PyObject to a pyGameScoreTransferMsg (throws error if not correct type)
static void AddPlasmaClasses(PyObject* m);
PyObject* GetDestinationScore() const;
PyObject* GetSourceScore() const;
};
class pyGameScoreUpdateMsg : public pyGameScoreMsg
{
pyGameScoreUpdateMsg()
: pyGameScoreMsg()
{ }
pyGameScoreUpdateMsg(pfGameScoreUpdateMsg* msg)
: pyGameScoreMsg(msg)
{ }
public:
PYTHON_CLASS_NEW_FRIEND(ptGameScoreUpdateMsg);
static PyObject* New(pfGameScoreUpdateMsg* msg);
PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyGameScoreUpdateMsg object
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyGameScoreUpdateMsg); // converts a PyObject to a pyGameScoreUpdateMsg (throws error if not correct type)
static void AddPlasmaClasses(PyObject* m);
PyObject* GetScore() const;
};
#endif // _pyGameScoreMsg_h_

251
Sources/Plasma/FeatureLib/pfPython/pyGameScoreMsgGlue.cpp

@ -0,0 +1,251 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "pyGameScoreMsg.h"
// Maybe we need a better exception? Seems to be the best built in one though
#define PFGS_PYERR PyExc_RuntimeError
// =================================================================
PYTHON_CLASS_DEFINITION(ptGameScoreMsg, pyGameScoreMsg);
PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreMsg, pyGameScoreMsg);
PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreMsg);
PYTHON_NO_INIT_DEFINITION(ptGameScoreMsg);
PYTHON_START_METHODS_TABLE(ptGameScoreMsg)
// We have no methods, but our helpers want a table...
// Eh. Not the end of the world.
PYTHON_END_METHODS_TABLE;
// Type structure definition
PLASMA_DEFAULT_TYPE(ptGameScoreMsg, "Game Score operation callback message");
PYTHON_EXPOSE_TYPE_DEFINITION(ptGameScoreMsg, pyGameScoreMsg);
PYTHON_CLASS_CHECK_IMPL(ptGameScoreMsg, pyGameScoreMsg)
PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreMsg, pyGameScoreMsg)
// Module and method definitions
void pyGameScoreMsg::AddPlasmaClasses(PyObject* m)
{
PYTHON_CLASS_IMPORT_START(m);
PYTHON_CLASS_IMPORT(m, ptGameScoreMsg);
PYTHON_CLASS_IMPORT_END(m);
}
// =================================================================
PYTHON_CLASS_DEFINITION(ptGameScoreListMsg, pyGameScoreListMsg);
PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreListMsg, pyGameScoreListMsg);
PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreListMsg);
PYTHON_NO_INIT_DEFINITION(ptGameScoreListMsg);
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreListMsg, getName)
{
return PyUnicode_FromStringEx(self->fThis->GetName());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreListMsg, getOwnerID)
{
return PyInt_FromLong(self->fThis->GetOwnerID());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreListMsg, getScores)
{
if (self->fThis->IsValid())
{
size_t count = self->fThis->GetNumScores();
PyObject* tup = PyTuple_New(count);
for (size_t i = 0; i < count; ++i)
PyTuple_SetItem(tup, i, self->fThis->GetScore(i));
return tup;
}
PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str());
PYTHON_RETURN_ERROR;
}
PYTHON_START_METHODS_TABLE(ptGameScoreListMsg)
PYTHON_METHOD_NOARGS(ptGameScoreListMsg, getName, "Returns the template score name"),
PYTHON_METHOD_NOARGS(ptGameScoreListMsg, getOwnerID, "Returns the template score ownerID"),
PYTHON_METHOD_NOARGS(ptGameScoreListMsg, getScores, "Returns a list of scores found by the server"),
PYTHON_END_METHODS_TABLE;
// Type structure definition
PLASMA_DEFAULT_TYPE_WBASE(ptGameScoreListMsg, pyGameScoreMsg, "Game Score message for scores found on the server");
// PyObject interop
PyObject* pyGameScoreListMsg::New(pfGameScoreListMsg* msg)
{
ptGameScoreListMsg* newObj = (ptGameScoreListMsg*)ptGameScoreListMsg_type.tp_new(&ptGameScoreListMsg_type, NULL, NULL);
hsRefCnt_SafeUnRef(newObj->fThis->fMsg);
newObj->fThis->fMsg = msg;
hsRefCnt_SafeRef(newObj->fThis->fMsg);
return (PyObject*)newObj;
}
PYTHON_CLASS_CHECK_IMPL(ptGameScoreListMsg, pyGameScoreListMsg)
PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreListMsg, pyGameScoreListMsg)
// Module and method definitions
void pyGameScoreListMsg::AddPlasmaClasses(PyObject* m)
{
PYTHON_CLASS_IMPORT_START(m);
PYTHON_CLASS_IMPORT(m, ptGameScoreListMsg);
PYTHON_CLASS_IMPORT_END(m);
}
// =================================================================
PYTHON_CLASS_DEFINITION(ptGameScoreTransferMsg, pyGameScoreTransferMsg);
PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreTransferMsg, pyGameScoreTransferMsg);
PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreTransferMsg);
PYTHON_NO_INIT_DEFINITION(ptGameScoreTransferMsg);
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreTransferMsg, getDestination)
{
if (self->fThis->IsValid())
{
return self->fThis->GetDestinationScore();
}
PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str());
PYTHON_RETURN_ERROR;
}
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreTransferMsg, getSource)
{
if (self->fThis->IsValid())
{
return self->fThis->GetSourceScore();
}
PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str());
PYTHON_RETURN_ERROR;
}
PYTHON_START_METHODS_TABLE(ptGameScoreTransferMsg)
PYTHON_METHOD_NOARGS(ptGameScoreTransferMsg, getDestination, "Returns the score points were transferred to"),
PYTHON_METHOD_NOARGS(ptGameScoreTransferMsg, getSource, "Returns the score points were transferred from"),
PYTHON_END_METHODS_TABLE;
// Type structure definition
PLASMA_DEFAULT_TYPE_WBASE(ptGameScoreTransferMsg, pyGameScoreMsg, "Game Score message indicating a score point transfer");
// PyObject interop
PyObject* pyGameScoreTransferMsg::New(pfGameScoreTransferMsg* msg)
{
ptGameScoreTransferMsg* newObj = (ptGameScoreTransferMsg*)ptGameScoreTransferMsg_type.tp_new(&ptGameScoreTransferMsg_type, NULL, NULL);
hsRefCnt_SafeUnRef(newObj->fThis->fMsg);
newObj->fThis->fMsg = msg;
hsRefCnt_SafeRef(newObj->fThis->fMsg);
return (PyObject*)newObj;
}
PYTHON_CLASS_CHECK_IMPL(ptGameScoreTransferMsg, pyGameScoreTransferMsg)
PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreTransferMsg, pyGameScoreTransferMsg)
// Module and method definitions
void pyGameScoreTransferMsg::AddPlasmaClasses(PyObject* m)
{
PYTHON_CLASS_IMPORT_START(m);
PYTHON_CLASS_IMPORT(m, ptGameScoreTransferMsg);
PYTHON_CLASS_IMPORT_END(m);
}
// =================================================================
PYTHON_CLASS_DEFINITION(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg);
PYTHON_DEFAULT_NEW_DEFINITION(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg);
PYTHON_DEFAULT_DEALLOC_DEFINITION(ptGameScoreUpdateMsg);
PYTHON_NO_INIT_DEFINITION(ptGameScoreUpdateMsg);
PYTHON_METHOD_DEFINITION_NOARGS(ptGameScoreUpdateMsg, getScore)
{
if (self->fThis->IsValid())
{
return self->fThis->GetScore();
}
PyErr_SetString(PFGS_PYERR, self->fThis->GetError().c_str());
PYTHON_RETURN_ERROR;
}
PYTHON_START_METHODS_TABLE(ptGameScoreUpdateMsg)
PYTHON_METHOD_NOARGS(ptGameScoreUpdateMsg, getScore, "Returns the updated game score"),
PYTHON_END_METHODS_TABLE;
// Type structure definition
PLASMA_DEFAULT_TYPE_WBASE(ptGameScoreUpdateMsg, pyGameScoreMsg, "Game Score message for a score update operation");
// PyObject interop
PyObject* pyGameScoreUpdateMsg::New(pfGameScoreUpdateMsg* msg)
{
ptGameScoreUpdateMsg* newObj = (ptGameScoreUpdateMsg*)ptGameScoreUpdateMsg_type.tp_new(&ptGameScoreUpdateMsg_type, NULL, NULL);
hsRefCnt_SafeUnRef(newObj->fThis->fMsg);
newObj->fThis->fMsg = msg;
hsRefCnt_SafeRef(newObj->fThis->fMsg);
return (PyObject*)newObj;
}
PYTHON_CLASS_CHECK_IMPL(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg)
PYTHON_CLASS_CONVERT_FROM_IMPL(ptGameScoreUpdateMsg, pyGameScoreUpdateMsg)
// Module and method definitions
void pyGameScoreUpdateMsg::AddPlasmaClasses(PyObject* m)
{
PYTHON_CLASS_IMPORT_START(m);
PYTHON_CLASS_IMPORT(m, ptGameScoreUpdateMsg);
PYTHON_CLASS_IMPORT_END(m);
}
// =================================================================
#undef PFGS_PYERR

17
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.cpp

@ -42,22 +42,29 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "pyGlueHelpers.h"
#include "plString.h"
char* PyString_AsStringEx(PyObject* obj)
plString PyString_AsStringEx(PyObject* obj)
{
if (PyString_Check(obj))
return hsStrcpy(PyString_AsString(obj));
return plString::FromUtf8(PyString_AsString(obj));
else if (PyUnicode_Check(obj))
{
PyObject* utf8 = PyUnicode_AsUTF8String(obj);
char* buf = hsStrcpy(PyString_AsString(utf8));
plString str = plString::FromUtf8(PyString_AsString(utf8));
Py_DECREF(utf8);
return buf;
return str;
} else
return NULL; // You suck.
return plString::Null;
}
bool PyString_CheckEx(PyObject* obj)
{
return (PyString_Check(obj) || PyUnicode_Check(obj));
}
PyObject* PyUnicode_FromStringEx(const plString& str)
{
plStringBuffer<wchar_t> buf = str.ToWchar();
return PyUnicode_FromWideChar(buf.GetData(), buf.GetSize());
}

17
Sources/Plasma/FeatureLib/pfPython/pyGlueHelpers.h

@ -45,8 +45,11 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Python.h>
// Useful string functions
char* PyString_AsStringEx(PyObject* obj);
class plString;
plString PyString_AsStringEx(PyObject* obj);
bool PyString_CheckEx(PyObject* obj);
PyObject* PyUnicode_FromStringEx(const plString& str);
// A set of macros to take at least some of the tediousness out of creating straight python glue code
@ -351,6 +354,10 @@ PyModule_AddObject(m, #pythonClassName, (PyObject*)&pythonClassName##_type)
static PyObject *pythonClassName##_##methodName(pythonClassName *self, PyObject *argsVar)
#define PYTHON_METHOD_DEFINITION_NOARGS(pythonClassName, methodName) \
static PyObject *pythonClassName##_##methodName(pythonClassName *self)
#define PYTHON_METHOD_DEFINITION_STATIC(pythonClassName, methodName, argsVar) \
static PyObject *pythonClassName##_##methodName(PyObject*, PyObject *argsVar)
#define PYTHON_METHOD_DEFINITION_STATIC_WKEY(pythonClassName, methodName, argsVar, keywordsVar) \
static PyObject *pythonClassName##_##methodName(PyObject*, PyObject *argsVar, PyObject *keywordsVar)
#define PYTHON_METHOD_DEFINITION_WKEY(pythonClassName, methodName, argsVar, keywordsVar) \
static PyObject *pythonClassName##_##methodName(pythonClassName *self, PyObject *argsVar, PyObject *keywordsVar)
@ -388,6 +395,14 @@ static PyObject *pythonClassName##_##methodName(pythonClassName *self) \
#define PYTHON_METHOD_NOARGS(pythonClassName, methodName, docString) \
{#methodName, (PyCFunction)pythonClassName##_##methodName, METH_NOARGS, docString}
// static method with arguments
#define PYTHON_METHOD_STATIC(pythonClassName, methodName, docString) \
{#methodName, (PyCFunction)pythonClassName##_##methodName, METH_STATIC | METH_VARARGS, docString}
// static method with keywords
#define PYTHON_METHOD_STATIC_WKEY(pythonClassName, methodName, docString) \
{#methodName, (PyCFunction)pythonClassName##_##methodName, METH_STATIC | METH_VARARGS | METH_KEYWORDS, docString}
// method with keywords
#define PYTHON_METHOD_WKEY(pythonClassName, methodName, docString) \
{#methodName, (PyCFunction)pythonClassName##_##methodName, METH_VARARGS | METH_KEYWORDS, docString}

14
Sources/Plasma/FeatureLib/pfPython/pyImageGlue.cpp

@ -287,11 +287,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadJPEGFromDisk, args, "Params: filename,widt
if (PyString_CheckEx(filenameObj))
{
char* text = PyString_AsStringEx(filenameObj);
wchar_t* wText = hsStringToWString(text);
PyObject* ret = pyImage::LoadJPEGFromDisk(wText, width, height);
delete[] wText;
delete[] text;
plString text = PyString_AsStringEx(filenameObj);
PyObject* ret = pyImage::LoadJPEGFromDisk(_TEMP_CONVERT_TO_WCHAR_T(text), width, height);
return ret;
}
else
@ -312,11 +309,8 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadPNGFromDisk, args, "Params: filename,width
}
if (PyString_CheckEx(filenameObj))
{
char* text = PyString_AsStringEx(filenameObj);
wchar_t* wText = hsStringToWString(text);
PyObject* ret = pyImage::LoadPNGFromDisk(wText, width, height);
delete[] wText;
delete[] text;
plString text = PyString_AsStringEx(filenameObj);
PyObject* ret = pyImage::LoadPNGFromDisk(_TEMP_CONVERT_TO_WCHAR_T(text), width, height);
return ret;
}
else

4
Sources/Plasma/FeatureLib/pfPython/pyPlayer.h

@ -62,8 +62,8 @@ class pyPlayer
protected:
plKey fAvatarKey;
std::string fPlayerName;
uint32_t fPlayerID;
float fDistSq; // from local player, temp
uint32_t fPlayerID;
float fDistSq; // from local player, temp
hsBool fIsCCR;
hsBool fIsServer;

15
Sources/Plasma/FeatureLib/pfPython/pyPlayerGlue.cpp

@ -65,31 +65,31 @@ PYTHON_INIT_DEFINITION(ptPlayer, args, keywords)
}
pyKey* key = NULL;
char* name = NULL;
plString name;
uint32_t pid = -1;
float distSeq = -1;
if (pyKey::Check(firstObj))
{
key = pyKey::ConvertFrom(firstObj);
if (!(name = PyString_AsStringEx(secondObj)))
if (!PyString_CheckEx(secondObj))
{
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
PYTHON_RETURN_INIT_ERROR;
}
} else
name = PyString_AsStringEx(secondObj);
if (!(PyNumber_Check(thirdObj) && PyFloat_Check(fourthObj)))
{
delete[] name;
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
PYTHON_RETURN_INIT_ERROR;
}
pid = PyNumber_AsSsize_t(thirdObj, NULL);
distSeq = (float)PyFloat_AsDouble(fourthObj);
} else if (name = PyString_AsStringEx(firstObj)) {
} else if (PyString_CheckEx(firstObj)) {
name = PyString_AsStringEx(firstObj);
if (!PyNumber_Check(secondObj) || thirdObj || fourthObj)
{
delete[] name;
PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
PYTHON_RETURN_INIT_ERROR;
}
@ -100,8 +100,7 @@ PYTHON_INIT_DEFINITION(ptPlayer, args, keywords)
PYTHON_RETURN_INIT_ERROR;
}
self->fThis->Init(key, name, pid, distSeq);
delete[] name;
self->fThis->Init(key, _TEMP_CONVERT_TO_CONST_CHAR(name), pid, distSeq);
PYTHON_RETURN_INIT_OK;
}

354
Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.cpp

@ -1,354 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "pyScoreMgr.h"
#include "pfGameScoreMgr/pfGameScoreMgr.h"
#include "plVault/plVault.h"
#include "plNetCommon/plNetCommon.h"
#include "pyGameScore.h"
pyScoreMgr::pyScoreMgr()
{
}
pyScoreMgr::~pyScoreMgr()
{
}
bool pyScoreMgr::DeleteScore(unsigned scoreId)
{
return IS_NET_SUCCESS(pfGameScoreMgr::GetInstance()->DeleteScore(scoreId));
}
PyObject* pyScoreMgr::CreateGlobalScore(
const char * gameName,
unsigned gameType,
int value
) {
pfGameScore * score = NEWZERO(pfGameScore);
score->IncRef();
pfGameScoreMgr::GetInstance()->CreateScore(0, gameName, gameType, value, *score);
if (score)
{
if (score->scoreId > 0)
{
PyObject* pyScore = pyGameScore::New(score);
score->DecRef();
return pyScore;
}
score->DecRef();
}
PYTHON_RETURN_NONE;
}
PyObject* pyScoreMgr::GetGlobalScores(const char* gameName)
{
pfGameScore** scoreList = nil;
int scoreListCount = 0;
ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(0, gameName, scoreList, scoreListCount);
if (IS_NET_SUCCESS(result) && scoreListCount > 0)
{
PyObject* pyScoreList = PyList_New(scoreListCount);
for (int i = 0; i < scoreListCount; ++i)
{
PyObject* pyScore = pyGameScore::New(scoreList[i]);
PyList_SetItem(pyScoreList, i, pyScore);
scoreList[i]->DecRef();
}
delete [] scoreList;
return pyScoreList;
}
PYTHON_RETURN_NONE;
}
PyObject* pyScoreMgr::CreatePlayerScore(
const char * gameName,
unsigned gameType,
int value
) {
pfGameScore * score = nil;
if (RelVaultNode * rvn = VaultGetPlayerInfoNodeIncRef()) {
unsigned ownerId = rvn->nodeId;
rvn->DecRef();
score = NEWZERO(pfGameScore);
score->IncRef();
pfGameScoreMgr::GetInstance()->CreateScore(ownerId, gameName, gameType, value, *score);
}
if (score)
{
if (score->scoreId > 0)
{
PyObject* pyScore = pyGameScore::New(score);
score->DecRef();
return pyScore;
}
score->DecRef();
}
PYTHON_RETURN_NONE;
}
PyObject* pyScoreMgr::GetPlayerScores(const char* gameName)
{
if (RelVaultNode * rvn = VaultGetPlayerInfoNodeIncRef()) {
unsigned ownerId = rvn->nodeId;
rvn->DecRef();
pfGameScore** scoreList = nil;
int scoreListCount = 0;
ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(ownerId, gameName, scoreList, scoreListCount);
if (IS_NET_SUCCESS(result) && scoreListCount > 0)
{
PyObject* pyScoreList = PyList_New(scoreListCount);
for (int i = 0; i < scoreListCount; ++i)
{
PyObject* pyScore = pyGameScore::New(scoreList[i]);
PyList_SetItem(pyScoreList, i, pyScore);
scoreList[i]->DecRef();
}
delete [] scoreList;
return pyScoreList;
}
}
PYTHON_RETURN_NONE;
}
PyObject* pyScoreMgr::CreateNeighborhoodScore(
const char * gameName,
unsigned gameType,
int value
) {
pfGameScore * score = nil;
plAgeInfoStruct info;
info.SetAgeFilename(kNeighborhoodAgeFilename);
if (RelVaultNode * rvn = VaultGetOwnedAgeInfoIncRef(&info)) {
unsigned ownerId = rvn->nodeId;
rvn->DecRef();
score = NEWZERO(pfGameScore);
score->IncRef();
pfGameScoreMgr::GetInstance()->CreateScore(ownerId, gameName, gameType, value, *score);
}
if (score)
{
if (score->scoreId > 0)
{
PyObject* pyScore = pyGameScore::New(score);
score->DecRef();
return pyScore;
}
score->DecRef();
}
PYTHON_RETURN_NONE;
}
PyObject* pyScoreMgr::GetNeighborhoodScores(const char* gameName)
{
plAgeInfoStruct info;
info.SetAgeFilename(kNeighborhoodAgeFilename);
if (RelVaultNode * rvn = VaultGetOwnedAgeInfoIncRef(&info)) {
unsigned ownerId = rvn->nodeId;
rvn->DecRef();
pfGameScore** scoreList = nil;
int scoreListCount = 0;
ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(ownerId, gameName, scoreList, scoreListCount);
if (IS_NET_SUCCESS(result) && scoreListCount > 0)
{
PyObject* pyScoreList = PyList_New(scoreListCount);
for (int i = 0; i < scoreListCount; ++i)
{
PyObject* pyScore = pyGameScore::New(scoreList[i]);
PyList_SetItem(pyScoreList, i, pyScore);
scoreList[i]->DecRef();
}
delete [] scoreList;
return pyScoreList;
}
}
PYTHON_RETURN_NONE;
}
PyObject* pyScoreMgr::CreateCurrentAgeScore(
const char * gameName,
unsigned gameType,
int value
) {
pfGameScore * score = nil;
if (RelVaultNode * rvn = VaultGetAgeInfoNodeIncRef()) {
unsigned ownerId = rvn->nodeId;
rvn->DecRef();
score = NEWZERO(pfGameScore);
score->IncRef();
pfGameScoreMgr::GetInstance()->CreateScore(ownerId, gameName, gameType, value, *score);
}
if (score)
{
if (score->scoreId > 0)
{
PyObject* pyScore = pyGameScore::New(score);
score->DecRef();
return pyScore;
}
score->DecRef();
}
PYTHON_RETURN_NONE;
}
PyObject* pyScoreMgr::GetCurrentAgeScores(const char* gameName)
{
if (RelVaultNode * rvn = VaultGetAgeInfoNodeIncRef()) {
unsigned ownerId = rvn->nodeId;
rvn->DecRef();
pfGameScore** scoreList = nil;
int scoreListCount = 0;
ENetError result = pfGameScoreMgr::GetInstance()->GetScoresIncRef(ownerId, gameName, scoreList, scoreListCount);
if (IS_NET_SUCCESS(result) && scoreListCount > 0)
{
PyObject* pyScoreList = PyList_New(scoreListCount);
for (int i = 0; i < scoreListCount; ++i)
{
PyObject* pyScore = pyGameScore::New(scoreList[i]);
PyList_SetItem(pyScoreList, i, pyScore);
scoreList[i]->DecRef();
}
delete [] scoreList;
return pyScoreList;
}
}
PYTHON_RETURN_NONE;
}
PyObject * pyScoreMgr::GetRankList(
unsigned scoreGroup,
unsigned parentFolderId,
const char * gameName,
unsigned timePeriod,
unsigned numResults,
unsigned pageNumber,
bool sortDesc
) {
if (RelVaultNode * rvn = VaultGetPlayerInfoNodeIncRef()) {
unsigned ownerId = rvn->nodeId;
rvn->DecRef();
NetGameRank** rankList = nil;
int rankListCount = 0;
ENetError result = pfGameScoreMgr::GetInstance()->GetRankList(
ownerId,
scoreGroup,
parentFolderId,
gameName,
timePeriod,
numResults,
pageNumber,
sortDesc,
rankList,
rankListCount
);
if (IS_NET_SUCCESS(result) && rankListCount > 0)
{
PyObject* pyRankList = PyList_New(rankListCount);
for (int i = 0; i < rankListCount; ++i)
{
char tempStr[kMaxPlayerNameLength];
StrToAnsi(tempStr, rankList[i]->name, arrsize(tempStr));
PyObject* pyRank = PyTuple_New(3);
PyTuple_SetItem(pyRank, 0, PyInt_FromLong(rankList[i]->rank));
PyTuple_SetItem(pyRank, 1, PyString_FromString(tempStr));
PyTuple_SetItem(pyRank, 2, PyInt_FromLong(rankList[i]->score));
PyList_SetItem(pyRankList, i, pyRank);
delete rankList[i];
}
delete [] rankList;
return pyRankList;
}
}
PYTHON_RETURN_NONE;
}

115
Sources/Plasma/FeatureLib/pfPython/pyScoreMgr.h

@ -1,115 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#ifndef pyScoreMgr_h
#define pyScoreMgr_h
/////////////////////////////////////////////////////////////////////////////
//
// NAME: pyScoreMgr
//
// PURPOSE: a wrapper class to provide an interface to the scoring system
//
#include <Python.h>
#include "HeadSpin.h"
#include "hsStlUtils.h"
#include "pyGlueHelpers.h"
class pyScoreMgr
{
public:
pyScoreMgr();
~pyScoreMgr();
// required functions for PyObject interoperability
PYTHON_CLASS_NEW_FRIEND(ptScoreMgr);
PYTHON_CLASS_NEW_DEFINITION;
PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyScoreMgr object
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyScoreMgr); // converts a PyObject to a pyScoreMgr (throws error if not correct type)
static void AddPlasmaClasses(PyObject *m);
static void AddPlasmaConstantsClasses(PyObject *m);
bool DeleteScore(unsigned scoreId);
PyObject* CreateGlobalScore(
const char * gameName,
unsigned gameType,
int value
);
PyObject* GetGlobalScores(const char* gameName);
PyObject* CreatePlayerScore(
const char * gameName,
unsigned gameType,
int value
);
PyObject* GetPlayerScores(const char* gameName);
PyObject* CreateNeighborhoodScore(
const char * gameName,
unsigned gameType,
int value
);
PyObject* GetNeighborhoodScores(const char* gameName);
PyObject* CreateCurrentAgeScore(
const char * gameName,
unsigned gameType,
int value
);
PyObject* GetCurrentAgeScores(const char* gameName);
PyObject * GetRankList(
unsigned scoreGroup,
unsigned parentFolderId,
const char * gameName,
unsigned timePeriod,
unsigned numResults,
unsigned pageNumber,
bool sortDesc
);
};
#endif

235
Sources/Plasma/FeatureLib/pfPython/pyScoreMgrGlue.cpp

@ -1,235 +0,0 @@
/*==LICENSE==*
CyanWorlds.com Engine - MMOG client, server and tools
Copyright (C) 2011 Cyan Worlds, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Additional permissions under GNU GPL version 3 section 7
If you modify this Program, or any covered work, by linking or
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
(or a modified version of those libraries),
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
licensors of this Program grant you additional
permission to convey the resulting work. Corresponding Source for a
non-source form of such a combination shall include the source code for
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
work.
You can contact Cyan Worlds, Inc. by email legal@cyan.com
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/
#include "pyScoreMgr.h"
#include "pyEnum.h"
#include "pfGameScoreMgr/pfGameScoreMgr.h"
// glue functions
PYTHON_CLASS_DEFINITION(ptScoreMgr, pyScoreMgr);
PYTHON_DEFAULT_NEW_DEFINITION(ptScoreMgr, pyScoreMgr)
PYTHON_DEFAULT_DEALLOC_DEFINITION(ptScoreMgr)
PYTHON_INIT_DEFINITION(ptScoreMgr, args, keywords)
{
PYTHON_RETURN_INIT_OK;
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, deleteScore, args)
{
int scoreId;
if (!PyArg_ParseTuple(args, "i", &scoreId))
{
PyErr_SetString(PyExc_TypeError, "deleteScore expects an int");
PYTHON_RETURN_ERROR;
}
PYTHON_RETURN_BOOL(self->fThis->DeleteScore(scoreId));
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, createGlobalScore, args)
{
char* gameName;
int gameType;
int value;
if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value))
{
PyErr_SetString(PyExc_TypeError, "createGlobalScore expects a string, an int, and an int");
PYTHON_RETURN_ERROR;
}
return self->fThis->CreateGlobalScore(gameName, gameType, value);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, getGlobalScores, args)
{
char* gameName;
if (!PyArg_ParseTuple(args, "s", &gameName))
{
PyErr_SetString(PyExc_TypeError, "getGlobalScores expects a string");
PYTHON_RETURN_ERROR;
}
return self->fThis->GetGlobalScores(gameName);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, createPlayerScore, args)
{
char* gameName;
int gameType;
int value;
if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value))
{
PyErr_SetString(PyExc_TypeError, "createPlayerScore expects a string, an int, and an int");
PYTHON_RETURN_ERROR;
}
return self->fThis->CreatePlayerScore(gameName, gameType, value);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, getPlayerScores, args)
{
char* gameName;
if (!PyArg_ParseTuple(args, "s", &gameName))
{
PyErr_SetString(PyExc_TypeError, "getPlayerScores expects a string");
PYTHON_RETURN_ERROR;
}
return self->fThis->GetPlayerScores(gameName);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, createNeighborhoodScore, args)
{
char* gameName;
int gameType;
int value;
if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value))
{
PyErr_SetString(PyExc_TypeError, "createNeighborhoodScore expects a string, an int, and an int");
PYTHON_RETURN_ERROR;
}
return self->fThis->CreateNeighborhoodScore(gameName, gameType, value);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, getNeighborhoodScores, args)
{
char* gameName;
if (!PyArg_ParseTuple(args, "s", &gameName))
{
PyErr_SetString(PyExc_TypeError, "getNeighborhoodScores expects a string");
PYTHON_RETURN_ERROR;
}
return self->fThis->GetNeighborhoodScores(gameName);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, createCurrentAgeScore, args)
{
char* gameName;
int gameType;
int value;
if (!PyArg_ParseTuple(args, "sii", &gameName, &gameType, &value))
{
PyErr_SetString(PyExc_TypeError, "createCurrentAgeScore expects a string, an int, and an int");
PYTHON_RETURN_ERROR;
}
return self->fThis->CreateCurrentAgeScore(gameName, gameType, value);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, getCurrentAgeScores, args)
{
char* gameName;
if (!PyArg_ParseTuple(args, "s", &gameName))
{
PyErr_SetString(PyExc_TypeError, "getCurrentAgeScores expects a string");
PYTHON_RETURN_ERROR;
}
return self->fThis->GetCurrentAgeScores(gameName);
}
PYTHON_METHOD_DEFINITION(ptScoreMgr, getRankList, args)
{
int scoreGroup;
int parentFolderId;
char* gameName;
int timePeriod;
int numResults;
int pageNumber;
int sortDesc;
if (!PyArg_ParseTuple(args, "iisiiii", &scoreGroup, &parentFolderId, &gameName, &timePeriod, &numResults, &pageNumber, &sortDesc))
{
PyErr_SetString(PyExc_TypeError, "getRankList expects two ints, a string, and four more ints");
PYTHON_RETURN_ERROR;
}
return self->fThis->GetRankList(scoreGroup, parentFolderId, gameName, timePeriod, numResults, pageNumber, sortDesc != 0);
}
PYTHON_START_METHODS_TABLE(ptScoreMgr)
PYTHON_METHOD(ptScoreMgr, deleteScore, "Params: scoreId\nDeletes the specified score"),
PYTHON_METHOD(ptScoreMgr, createGlobalScore, "Params: gameName, gameType, value\nCreates a score and returns it"),
PYTHON_METHOD(ptScoreMgr, getGlobalScores, "Params: gameName\nReturns a list of scores associated with the specified game."),
PYTHON_METHOD(ptScoreMgr, createPlayerScore, "Params: gameName, gameType, value\nCreates a score and returns it"),
PYTHON_METHOD(ptScoreMgr, getPlayerScores, "Params: gameName\nReturns a list of scores associated with the specified game."),
PYTHON_METHOD(ptScoreMgr, createNeighborhoodScore, "Params: gameName, gameType, value\nCreates a score and returns it"),
PYTHON_METHOD(ptScoreMgr, getNeighborhoodScores, "Params: gameName\nReturns a list of scores associated with the specified game."),
PYTHON_METHOD(ptScoreMgr, createCurrentAgeScore, "Params: gameName, gameType, value\nCreates a score and returns it"),
PYTHON_METHOD(ptScoreMgr, getCurrentAgeScores, "Params: gameName\nReturns a list of scores associated with the specified game."),
PYTHON_METHOD(ptScoreMgr, getRankList, "Params: ownerInfoId, scoreGroup, parentFolderId, gameName, timePeriod, numResults, pageNumber, sortDesc\nReturns a list of scores and rank"),
PYTHON_END_METHODS_TABLE;
// Type structure definition
PLASMA_DEFAULT_TYPE(ptScoreMgr, "Game score manager");
// required functions for PyObject interoperability
PYTHON_CLASS_NEW_IMPL(ptScoreMgr, pyScoreMgr)
PYTHON_CLASS_CHECK_IMPL(ptScoreMgr, pyScoreMgr)
PYTHON_CLASS_CONVERT_FROM_IMPL(ptScoreMgr, pyScoreMgr)
///////////////////////////////////////////////////////////////////////////
//
// AddPlasmaClasses - the python module definitions
//
void pyScoreMgr::AddPlasmaClasses(PyObject *m)
{
PYTHON_CLASS_IMPORT_START(m);
PYTHON_CLASS_IMPORT(m, ptScoreMgr);
PYTHON_CLASS_IMPORT_END(m);
}
void pyScoreMgr::AddPlasmaConstantsClasses(PyObject *m)
{
PYTHON_ENUM_START(PtGameScoreTypes);
PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kFixed, kScoreTypeFixed);
PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumulative, kScoreTypeAccumulative);
PYTHON_ENUM_ELEMENT(PtGameScoreTypes, kAccumAllowNegative, kScoreTypeAccumAllowNegative);
PYTHON_ENUM_END(m, PtGameScoreTypes);
PYTHON_ENUM_START(PtScoreRankGroups);
PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kIndividual, kScoreRankGroupIndividual);
PYTHON_ENUM_ELEMENT(PtScoreRankGroups, kNeighborhood, kScoreRankGroupNeighborhood);
PYTHON_ENUM_END(m, PtScoreRankGroups);
PYTHON_ENUM_START(PtScoreTimePeriods);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kOverall, kScoreTimePeriodOverall);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kYear, kScoreTimePeriodYear);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kMonth, kScoreTimePeriodMonth);
PYTHON_ENUM_ELEMENT(PtScoreTimePeriods, kDay, kScoreTimePeriodDay);
PYTHON_ENUM_END(m, PtScoreTimePeriods);
}

12
Sources/Plasma/FeatureLib/pfPython/pyStatusLog.cpp

@ -62,14 +62,14 @@ pyStatusLog::~pyStatusLog()
}
hsBool pyStatusLog::Open(const char* logName, uint32_t numLines, uint32_t flags)
hsBool pyStatusLog::Open(plString logName, uint32_t numLines, uint32_t flags)
{
// make sure its closed first
Close();
// create a status log guy for this
fICreatedLog = true;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog( (uint8_t)numLines, logName, flags );
fLog = plStatusLogMgr::GetInstance().CreateStatusLog( (uint8_t)numLines, _TEMP_CONVERT_TO_CONST_CHAR(logName), flags );
if (fLog)
{
fLog->SetForceLog(true);
@ -78,18 +78,18 @@ hsBool pyStatusLog::Open(const char* logName, uint32_t numLines, uint32_t flags)
return false;
}
hsBool pyStatusLog::Write(const char* text)
hsBool pyStatusLog::Write(plString text)
{
if (fLog)
{
fLog->AddLine(text);
fLog->AddLine(_TEMP_CONVERT_TO_CONST_CHAR(text));
return true;
}
return false;
}
hsBool pyStatusLog::WriteColor(const char* text, pyColor& color)
hsBool pyStatusLog::WriteColor(plString text, pyColor& color)
{
if (fLog)
{
@ -97,7 +97,7 @@ hsBool pyStatusLog::WriteColor(const char* text, pyColor& color)
((uint32_t)(color.getRed()*255)<<16) +
((uint32_t)(color.getGreen()*255)<<8) +
((uint32_t)(color.getBlue()*255));
fLog->AddLine( text, st_color );
fLog->AddLine( _TEMP_CONVERT_TO_CONST_CHAR(text), st_color );
return true;
}

6
Sources/Plasma/FeatureLib/pfPython/pyStatusLog.h

@ -80,9 +80,9 @@ public:
static void AddPlasmaClasses(PyObject *m);
static void AddPlasmaConstantsClasses(PyObject *m);
virtual hsBool Open(const char* logName, uint32_t numLines, uint32_t flags);
virtual hsBool Write(const char* text);
virtual hsBool WriteColor(const char* text, pyColor& color);
virtual hsBool Open(plString logName, uint32_t numLines, uint32_t flags);
virtual hsBool Write(plString text);
virtual hsBool WriteColor(plString text, pyColor& color);
virtual void Close();
virtual hsBool IsOpen();

4
Sources/Plasma/NucleusLib/inc/plCreatableIndex.h

@ -947,6 +947,10 @@ CLASS_INDEX_LIST_START
CLASS_INDEX(plAngularVelocityMsg),
CLASS_INDEX(plRideAnimatedPhysMsg),
CLASS_INDEX(plAvBrainRideAnimatedPhysical),
CLASS_INDEX(pfGameScoreMsg),
CLASS_INDEX(pfGameScoreListMsg),
CLASS_INDEX(pfGameScoreTransferMsg),
CLASS_INDEX(pfGameScoreUpdateMsg),
CLASS_INDEX_LIST_END
#endif // plCreatableIndex_inc

Loading…
Cancel
Save