Browse Source

Implement new pfGameScore class and friends

pfGameScore will call you back on actions that require server ops. Also, we
ref count the score instead of using some weird hashtable manager class
because the server never actually tells us if someone else changes the
score.
Adam Johnson 13 years ago
parent
commit
bbdc5cd0bb
  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. 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)
include_directories(../../NucleusLib/inc) include_directories(../../NucleusLib/inc)
include_directories(../../PubUtilLib) include_directories(../../PubUtilLib)
include_directories(../../FeatureLib)
set(pfGameScoreMgr_SOURCES set(pfGameScoreMgr_SOURCES
pfGameScoreMgr.cpp 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==*/ *==LICENSE==*/
#include "pfGameScoreMgr.h" #include "pfGameScoreMgr.h"
#include "pfMessage/pfGameScoreMsg.h"
#include "pnUtils/pnUtils.h"
#include "plNetGameLib/plNetGameLib.h" #include "plNetGameLib/plNetGameLib.h"
#include "pnNetProtocol/pnNetProtocol.h" #include "pnNetProtocol/pnNetProtocol.h"
//============================================================================ struct ScoreFindParam
pfGameScore::pfGameScore()
{ {
} uint32_t fOwnerId;
plString fName;
plKey fReceiver; // because plKey as a void* isn't cool
pfGameScore::~pfGameScore() ScoreFindParam(uint32_t ownerId, plString name, plKey r)
{ : fOwnerId(ownerId), fName(name), fReceiver(r)
pfGameScoreMgr::GetInstance()->RemoveCachedScore(scoreId); { }
} };
void pfGameScore::Init( struct ScoreTransferParam
unsigned sid, {
unsigned oid, pfGameScore* fTo;
uint32_t createTime, pfGameScore* fFrom;
const char gname[], int32_t fPoints;
unsigned gType, plKey fReceiver;
int val
) { ScoreTransferParam(pfGameScore* to, pfGameScore* from, int32_t points, plKey r)
scoreId = sid; : fTo(to), fFrom(from), fPoints(points), fReceiver(r)
ownerId = oid; { }
createdTime = createTime; };
gameType = gType;
value = val;
StrCopy(gameName, gname, arrsize(gameName)); struct ScoreUpdateParam
pfGameScoreMgr::GetInstance()->AddCachedScore(this); {
} pfGameScore* fParent;
plKey fReceiver;
int32_t fPoints; // reset points to this if update op
void pfGameScore::CopyFrom( ScoreUpdateParam(pfGameScore* s, plKey r, int32_t points = 0)
const pfGameScore* score : fParent(s), fReceiver(r), fPoints(points)
) { { }
scoreId = score->scoreId; };
ownerId = score->ownerId;
createdTime = score->createdTime;
gameType = score->gameType;
value = score->value;
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;
} }
//============================================================================ void pfGameScore::SetPoints(int32_t value, plKey rcvr)
pfGameScoreMgr::pfGameScoreMgr()
{ {
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; ScoreUpdateParam* p = (ScoreUpdateParam*)param;
return &s_instance; 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); Ref(); // netcode holds us
if (scoreLink == nil) NetCliAuthScoreAddPoints(fScoreId, add, OnScoreUpdate, new ScoreUpdateParam(this, rcvr, fValue + add));
{
GameScoreLink * link = new GameScoreLink(score);
fScores.Add(link);
}
else
scoreLink->score->CopyFrom(score);
} }
void pfGameScoreMgr::RemoveCachedScore(unsigned scoreId) //======================================
void pfGameScore::Delete()
{ {
if (GameScoreLink * link = fScores.Find(scoreId)) NetCliAuthScoreDelete(fScoreId, nil, nil); // who cares about getting a notify here?
{ UnRef(); // kthxbai
delete link;
}
} }
//============================================================================ //======================================
struct NetWaitOp static void OnScoreTransfer(ENetError result, void* param)
{ {
ENetError result; ScoreTransferParam* p = (ScoreTransferParam*)param;
bool complete; pfGameScoreTransferMsg* msg = new pfGameScoreTransferMsg(result, p->fTo, p->fFrom, p->fPoints);
}; msg->Send(p->fReceiver);
delete p;
static void WaitOpCallback(
ENetError result,
void * param
) {
NetWaitOp * op = (NetWaitOp *)param;
op->result = result;
op->complete = true;
} }
//============================================================================ void pfGameScore::TransferPoints(pfGameScore* to, int32_t points, plKey recvr)
// CreateScore
//============================================================================
struct CreateScoreOp : NetWaitOp
{ {
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, ENetError result,
void * param, void * param,
unsigned scoreId, uint32_t scoreId,
uint32_t createdTime, uint32_t createdTime, // ignored
unsigned ownerId, 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, const char* gameName,
unsigned gameType, uint32_t gameType,
int value, int32_t value
pfGameScore& score
) {
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; ScoreUpdateParam* p = (ScoreUpdateParam*)param;
memset(&param, 0, sizeof(NetWaitOp)); pfGameScore* score = new pfGameScore(scoreId, ownerId, _TEMP_CONVERT_FROM_LITERAL(gameName), gameType, value);
pfGameScoreUpdateMsg* msg = new pfGameScoreUpdateMsg(result, score, value);
NetCliAuthScoreDelete( msg->Send(p->fReceiver);
scoreId, delete p;
WaitOpCallback,
&param
);
while (!param.complete) {
NetClientUpdate();
AsyncSleep(10);
}
return param.result;
} }
//============================================================================ void pfGameScore::Create(uint32_t ownerId, const plString& name, uint32_t type, int32_t value, plKey rcvr)
// GetScores
//============================================================================
struct GetScoresOp : NetWaitOp
{ {
pfGameScore*** scores; NetCliAuthScoreCreate(ownerId, name.c_str(), type, value, OnScoreCreate, new ScoreUpdateParam(nil, rcvr));
int* scoreCount; }
};
static void GetScoresCallback( //======================================
static void OnScoreFound(
ENetError result, ENetError result,
void * param, void * param,
const NetGameScore scores[], const NetGameScore scores[],
unsigned scoreCount uint32_t 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
) { ) {
NetWaitOp param; std::vector<pfGameScore*> vec(scoreCount);
memset(&param, 0, sizeof(NetWaitOp)); for (uint32_t i = 0; i < scoreCount; ++i)
{
NetCliAuthScoreSetPoints( const NetGameScore ngs = scores[i];
scoreId, vec[i] = new pfGameScore(ngs.scoreId, ngs.ownerId, _TEMP_CONVERT_FROM_WCHAR_T(ngs.gameName), ngs.gameType, ngs.value);
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; ScoreFindParam* p = (ScoreFindParam*)param;
pfGameScoreListMsg* msg = new pfGameScoreListMsg(result, vec, p->fOwnerId, p->fName);
msg->Send(p->fReceiver);
delete p;
} }
//============================================================================ void pfGameScore::Find(uint32_t ownerId, const plString& name, plKey rcvr)
// GetRankList
//============================================================================
struct GetRanksOp : NetWaitOp
{ {
NetGameRank*** ranks; NetCliAuthScoreGetScores(ownerId, name.c_str(), OnScoreFound, new ScoreFindParam(ownerId, name, rcvr));
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;
} }

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 Mead, WA 99021
*==LICENSE==*/ *==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/FeatureLib/pfGameScoreMgr/pfGameScoreMgr.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMESCOREMGR_PFGAMESCOREMGR_H #ifndef _pfGameScoreMgr_h_
#define PLASMA20_SOURCES_PLASMA_FEATURELIB_PFGAMESCOREMGR_PFGAMESCOREMGR_H #define _pfGameScoreMgr_h_
#include "HeadSpin.h" #include "HeadSpin.h"
#include "pnKeyedObject/plKey.h"
#include "pnNetBase/pnNetBase.h" #include "pnNetBase/pnNetBase.h"
#include "pnUtils/pnUtils.h" #include "hsRefCnt.h"
#include "plString.h"
struct NetGameRank;
// TODO: Rank List (seems to be unused in regular gameplay though...)
struct pfGameScore : AtomicRef // 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; uint32_t fScoreId;
unsigned ownerId; uint32_t fOwnerId;
uint32_t createdTime; plString fName;
char gameName[kMaxGameScoreNameLength]; uint32_t fGameType; // EGameScoreTypes
unsigned gameType; int32_t fValue;
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);
};
class pfGameScoreMgr friend class pfGameScoreTransferMsg;
{ friend class pfGameScoreUpdateMsg;
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;
public: public:
static pfGameScoreMgr* GetInstance(); 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)
void AddCachedScore(pfGameScore * score); { }
void RemoveCachedScore(unsigned scoreId);
plString GetGameName() const { return fName; }
ENetError CreateScore( uint32_t GetGameType() const { return fGameType; }
unsigned ownerId, uint32_t GetOwner() const { return fOwnerId; }
const char* gameName, int32_t GetPoints() const { return fValue; }
unsigned gameType, void SetPoints(int32_t value, plKey rcvr = nil);
int value,
pfGameScore& score void AddPoints(int32_t add, plKey rcvr = nil);
); void Delete();
ENetError DeleteScore( void TransferPoints(pfGameScore* to, plKey rcvr = nil) { TransferPoints(to, fValue, rcvr); }
unsigned scoreId void TransferPoints(pfGameScore* to, int32_t points, plKey rcvr = nil);
);
ENetError AddPoints( static void Create(uint32_t ownerId, const plString& name, uint32_t type, int32_t value, plKey rcvr);
unsigned scoreId, static void Find(uint32_t ownerId, const plString& name, plKey rcvr);
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
);
}; };
#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)
include_directories(../../NucleusLib/inc) include_directories(../../NucleusLib/inc)
include_directories(../../PubUtilLib) include_directories(../../PubUtilLib)
include_directories(../../FeatureLib)
set(pfMessage_SOURCES set(pfMessage_SOURCES
pfKIMsg.cpp pfKIMsg.cpp
@ -14,6 +15,7 @@ set(pfMessage_SOURCES
set(pfMessage_HEADERS set(pfMessage_HEADERS
pfBackdoorMsg.h pfBackdoorMsg.h
pfGameGUIMsg.h pfGameGUIMsg.h
pfGameScoreMsg.h
pfGUINotifyMsg.h pfGUINotifyMsg.h
pfKIMsg.h pfKIMsg.h
pfMarkerMsg.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 ); REGISTER_CREATABLE( pfGameGUIMsg );
#include "pfGameScoreMsg.h"
REGISTER_NONCREATABLE( pfGameScoreMsg );
REGISTER_CREATABLE( pfGameScoreListMsg );
REGISTER_CREATABLE( pfGameScoreTransferMsg );
REGISTER_CREATABLE( pfGameScoreUpdateMsg );
#include "pfGUINotifyMsg.h" #include "pfGUINotifyMsg.h"
REGISTER_CREATABLE( pfGUINotifyMsg ); REGISTER_CREATABLE( pfGUINotifyMsg );

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

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

Loading…
Cancel
Save