mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
CWE Directory Reorganization
Rearrange directory structure of CWE to be loosely equivalent to the H'uru Plasma repository. Part 1: Movement of directories and files.
This commit is contained in:
191
Sources/Plasma/NucleusLib/pnKeyedObject/hsKeyedObject.cpp
Normal file
191
Sources/Plasma/NucleusLib/pnKeyedObject/hsKeyedObject.cpp
Normal file
@ -0,0 +1,191 @@
|
||||
/*==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 "hsKeyedObject.h"
|
||||
#include "plKeyImp.h"
|
||||
#include "hsResMgr.h"
|
||||
#include "../pnDispatch/plDispatch.h"
|
||||
#include "../pnMessage/plSelfDestructMsg.h"
|
||||
|
||||
void hsKeyedObject::SetKey(plKey k)
|
||||
{
|
||||
if (fpKey != nil)
|
||||
{
|
||||
hsAssert(k == nil || k == fpKey, "Changing an object's key is not allowed");
|
||||
((plKeyImp*)fpKey)->SetObjectPtr(nil);
|
||||
}
|
||||
|
||||
fpKey = k;
|
||||
|
||||
if (fpKey != nil)
|
||||
((plKeyImp*)fpKey)->SetObjectPtr(this);
|
||||
}
|
||||
|
||||
hsBool hsKeyedObject::SendRef(plRefMsg* refMsg, plRefFlags::Type flags)
|
||||
{
|
||||
plKey key = GetKey(); // for linux build
|
||||
return hsgResMgr::SendRef(key, refMsg, flags);
|
||||
}
|
||||
|
||||
const char* hsKeyedObject::GetKeyName() const
|
||||
{
|
||||
if (fpKey)
|
||||
return fpKey->GetName();
|
||||
else
|
||||
return "(unknown)";
|
||||
}
|
||||
|
||||
hsKeyedObject::~hsKeyedObject()
|
||||
{
|
||||
if( fpKey && fpKey->ObjectIsLoaded() )
|
||||
{
|
||||
// If our key is pointing to an object (presumably back to us),
|
||||
// then UnRegister will call SetObjectPtr(nil) will unregister the key (and us), which will
|
||||
// decrement our RefCnt. Unfortunately, we are here because of a call
|
||||
// to our destructor, in which case we don't want to go back into our
|
||||
// destructor again. So we'll just up the RefCnt, plKey::UnRegister will dec it back to 1.
|
||||
hsRefCnt_SafeRef(fpKey->ObjectIsLoaded());
|
||||
}
|
||||
UnRegister();
|
||||
}
|
||||
|
||||
void hsKeyedObject::UnRegister()
|
||||
{
|
||||
if (fpKey)
|
||||
{
|
||||
if (plgDispatch::Dispatch())
|
||||
plgDispatch::Dispatch()->UnRegisterAll(fpKey);
|
||||
|
||||
((plKeyImp *)fpKey)->SetObjectPtr(nil);
|
||||
}
|
||||
}
|
||||
|
||||
plKey hsKeyedObject::RegisterAs(plFixedKeyId fixedKey)
|
||||
{
|
||||
plUoid meUoid(fixedKey);
|
||||
|
||||
hsAssert(meUoid.GetClassType() == ClassIndex(), "Registering as wrong type!");
|
||||
plKey key = hsgResMgr::ResMgr()->FindKey(meUoid);
|
||||
if (key == nil)
|
||||
{
|
||||
key = hsgResMgr::ResMgr()->NewKey(meUoid, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetKey(key);
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
|
||||
void hsKeyedObject::UnRegisterAs(plFixedKeyId fixedKey)
|
||||
{
|
||||
plUoid uoid(fixedKey);
|
||||
UnRegisterAsManual(uoid);
|
||||
}
|
||||
|
||||
plKey hsKeyedObject::RegisterAsManual(plUoid& meUoid, const char* p)
|
||||
{
|
||||
hsAssert(meUoid.GetClassType() == ClassIndex(),"Registering as wrong type!");
|
||||
// Really should be a NewKey() call just for fixed keys, so change this once player rooms behave
|
||||
plKey pkey = hsgResMgr::ResMgr()->ReRegister(p,meUoid);
|
||||
|
||||
if (pkey)
|
||||
SetKey(pkey);
|
||||
return pkey;
|
||||
}
|
||||
|
||||
|
||||
void hsKeyedObject::UnRegisterAsManual(plUoid& inUoid)
|
||||
{
|
||||
if (fpKey)
|
||||
{
|
||||
plUoid myUoid = fpKey->GetUoid();
|
||||
if (!(inUoid == myUoid))
|
||||
{
|
||||
#if !HS_BUILD_FOR_UNIX // disable for unix servers
|
||||
char inStr[255], myStr[255];
|
||||
inUoid.StringIze(inStr);
|
||||
myUoid.StringIze(myStr);
|
||||
hsAssert(false,
|
||||
xtl::format("Request to Unregister wrong FixedKey, keyName=%s, inUoid=%s, myUoid=%s",
|
||||
fpKey->GetName() ? fpKey->GetName() : "?", inStr, myStr).c_str());
|
||||
#endif
|
||||
}
|
||||
((plKeyImp*)fpKey)->UnRegister();
|
||||
}
|
||||
}
|
||||
|
||||
void hsKeyedObject::Validate()
|
||||
{
|
||||
const char* msg = "KeyedObject invalid!";
|
||||
|
||||
if (fpKey)
|
||||
{
|
||||
hsAssert(fpKey->GetObjectPtr() == this, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void hsKeyedObject::Read(hsStream* s, hsResMgr* mgr)
|
||||
{
|
||||
plKey pK = mgr->ReadKey(s);
|
||||
SetKey(pK);
|
||||
}
|
||||
|
||||
void hsKeyedObject::Write(hsStream* s, hsResMgr* mgr)
|
||||
{
|
||||
hsAssert(GetKey(),"hsKeyedObject:Must have a key!");
|
||||
mgr->WriteKey(s, fpKey);
|
||||
}
|
||||
|
||||
hsBool hsKeyedObject::MsgReceive(plMessage* msg)
|
||||
{
|
||||
plSelfDestructMsg* nuke = plSelfDestructMsg::ConvertNoRef(msg);
|
||||
if (nuke)
|
||||
{
|
||||
hsAssert(RefCnt() == 1, "Trying to selfdestruct with bogus refcnt");
|
||||
hsRefCnt_SafeUnRef(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
return plReceiver::MsgReceive(msg);
|
||||
}
|
105
Sources/Plasma/NucleusLib/pnKeyedObject/hsKeyedObject.h
Normal file
105
Sources/Plasma/NucleusLib/pnKeyedObject/hsKeyedObject.h
Normal file
@ -0,0 +1,105 @@
|
||||
/*==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 hsKeyedObject_h_inc
|
||||
#define hsKeyedObject_h_inc
|
||||
|
||||
#include "plReceiver.h"
|
||||
#include "plRefFlags.h"
|
||||
|
||||
#include "plKey.h"
|
||||
#include "plFixedKey.h"
|
||||
|
||||
class hsStream;
|
||||
class plRefMsg;
|
||||
class plUoid;
|
||||
|
||||
class hsKeyedObject : public plReceiver
|
||||
{
|
||||
public:
|
||||
hsKeyedObject() : fpKey(nil) {}
|
||||
virtual ~hsKeyedObject();
|
||||
|
||||
CLASSNAME_REGISTER(hsKeyedObject);
|
||||
GETINTERFACE_ANY(hsKeyedObject, plReceiver);
|
||||
|
||||
const plKey& GetKey() const { return fpKey; }
|
||||
const char* GetKeyName() const;
|
||||
|
||||
virtual void Validate();
|
||||
virtual hsBool IsFinal() { return true; }; // experimental; currently "is ready to process Loads"
|
||||
|
||||
virtual void Read(hsStream* s, hsResMgr* mgr);
|
||||
virtual void Write(hsStream* s, hsResMgr* mgr);
|
||||
|
||||
virtual hsBool MsgReceive(plMessage* msg);
|
||||
|
||||
//----------------------
|
||||
// Send a reference to GetKey() via enclosed message. See plKey::SendRef()
|
||||
//----------------------
|
||||
hsBool SendRef(plRefMsg* refMsg, plRefFlags::Type flags);
|
||||
|
||||
//----------------------------------------
|
||||
// Fixed key functions
|
||||
// The following are to be matched pairs!
|
||||
//----------------------------------------
|
||||
plKey RegisterAs(plFixedKeyId fixedKey); // a fixed Key value from plFixedKey.h
|
||||
void UnRegisterAs(plFixedKeyId fixedKey);
|
||||
|
||||
// used when manually loading the player room
|
||||
plKey RegisterAsManual(plUoid& uoid, const char* p);
|
||||
void UnRegisterAsManual(plUoid& uoid);
|
||||
|
||||
// If you want clone keys to share a type of object, override this function for it.
|
||||
// (You can also return a new object that shares only some of the original's data)
|
||||
virtual hsKeyedObject* GetSharedObject() { return nil; }
|
||||
|
||||
protected:
|
||||
friend class plResManager;
|
||||
|
||||
virtual void SetKey(plKey k);
|
||||
void UnRegister();
|
||||
|
||||
private:
|
||||
plKey fpKey;
|
||||
};
|
||||
|
||||
#endif // hsKeyedObject_h_inc
|
181
Sources/Plasma/NucleusLib/pnKeyedObject/plFixedKey.cpp
Normal file
181
Sources/Plasma/NucleusLib/pnKeyedObject/plFixedKey.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
/*==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==*/
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// plFixedKey
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "hsUtils.h"
|
||||
#include "plUoid.h"
|
||||
#include <string.h>
|
||||
|
||||
//// plKeySeed ///////////////////////////////////////////////////////////////
|
||||
// Our seed struct. Defined here so it doesn't have to be in the .h file
|
||||
|
||||
struct plKeySeed
|
||||
{
|
||||
plFixedKeyId feFixedKey;
|
||||
// NOTE: The following fields are broken out to make adding to the fixed key list easier.
|
||||
// However, what they really are, are just the fields of plUoid (including plLocation)
|
||||
UInt16 fType;
|
||||
const char *fObj;
|
||||
|
||||
hsBool Match( plKeySeed *p )
|
||||
{
|
||||
if( ( fType == p->fType ) && stricmp( p->fObj, fObj ) == 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#include "plFixedKey.h"
|
||||
#include "plCreatableIndex.h"
|
||||
#include "../pnKeyedObject/plKey.h"
|
||||
#include "../pnFactory/plCreator.h"
|
||||
|
||||
// Rules for SeedList:
|
||||
// 1) Must be in the Same order as enum fixedKey
|
||||
// 2) For now at least, all your fixed keys get put into the kGlobalFixedLoc room, reserved just for fixed keys
|
||||
// 2) Be sure your ClassIndex CLASS_INDEX(plSceneObject) matches the type of object you want to have the fixedKey
|
||||
// 3) Make sure the Obj is unique for this location/Type Combo... (validated at runtime)
|
||||
|
||||
plKeySeed SeedList[] = {
|
||||
// Key Enum Type Obj
|
||||
|
||||
{ kFirst_Fixed_KEY, CLASS_INDEX_SCOPED( plSceneObject ), "kFirst_Fixed_KEY" },
|
||||
|
||||
{ kLOSObject_KEY, CLASS_INDEX_SCOPED( plLOSDispatch ), "kLOSObject_KEY", },
|
||||
{ kTimerCallbackManager_KEY, CLASS_INDEX_SCOPED( plTimerCallbackManager ), "kTimerCallbackManager_KEY", },
|
||||
{ kConsoleObject_KEY, CLASS_INDEX_SCOPED( pfConsole ), "kConsoleObject_KEY", },
|
||||
{ kAudioSystem_KEY, CLASS_INDEX_SCOPED( plAudioSystem ), "kAudioSystem_KEY", },
|
||||
{ kInput_KEY, CLASS_INDEX_SCOPED( plInputManager ), "kInput_KEY", },
|
||||
{ kClient_KEY, CLASS_INDEX_SCOPED( plClient ), "kClient_KEY", },
|
||||
{ kNetClientMgr_KEY, CLASS_INDEX_SCOPED( plNetClientMgr ), "kNetClientMgr_KEY", },
|
||||
{ kListenerMod_KEY, CLASS_INDEX_SCOPED( plListener ), "kListenerMod_KEY", },
|
||||
{ kTransitionMgr_KEY, CLASS_INDEX_SCOPED( plTransitionMgr ), "kTransitionMgr_KEY", },
|
||||
{ kLinkEffectsMgr_KEY, CLASS_INDEX_SCOPED( plLinkEffectsMgr ), "kLinkEffectsMgr_KEY", },
|
||||
{ kGameGUIMgr_KEY, CLASS_INDEX_SCOPED( pfGameGUIMgr ), "kGameGUIMgr_KEY", },
|
||||
{ kGameGUIDynamicDlg_KEY, CLASS_INDEX_SCOPED( plSceneNode ), "kGameGUIDynamicDlg_KEY", },
|
||||
{ kVirtualCamera1_KEY, CLASS_INDEX_SCOPED( plVirtualCam1 ), "kVirtualCamera_KEY", },
|
||||
{ kDefaultCameraMod1_KEY, CLASS_INDEX_SCOPED( plCameraModifier1 ), "kDefaultCameraMod1_KEY", },
|
||||
{ kKIGUIGlue_KEY, CLASS_INDEX_SCOPED( pfKI ), "kKIGUIGlue_KEY", },
|
||||
{ kClothingMgr_KEY, CLASS_INDEX_SCOPED( plClothingMgr ), "kClothingMgr_KEY", },
|
||||
{ kInputInterfaceMgr_KEY, CLASS_INDEX_SCOPED( plInputInterfaceMgr ), "kInputInterfaceMgr_KEY", },
|
||||
{ kAVIWriter_KEY, CLASS_INDEX_SCOPED( plAVIWriter ), "kAVIWriter_KEY", },
|
||||
{ kResManagerHelper_KEY, CLASS_INDEX_SCOPED( plResManagerHelper ), "kResManagerHelper_KEY", },
|
||||
{ kAvatarMgr_KEY, CLASS_INDEX_SCOPED( plAvatarMgr ), "kAvatarMgr_KEY", },
|
||||
{ kSimulationMgr_KEY, CLASS_INDEX_SCOPED( plSimulationMgr ), "kSimulationMgr_KEY", },
|
||||
{ kTransitionCamera_KEY, CLASS_INDEX_SCOPED( plCameraModifier1 ), "kTransitionCamera_KEY", },
|
||||
{ kCCRMgr_KEY, CLASS_INDEX_SCOPED( plCCRMgr ), "kCCRMgr_KEY", },
|
||||
{ kNetClientCloneRoom_KEY, CLASS_INDEX_SCOPED( plSceneNode ), "kNetClientCloneRoom_KEY", },
|
||||
{ kMarkerMgr_KEY, CLASS_INDEX_SCOPED( pfMarkerMgr ), "kMarkerMgr_KEY", },
|
||||
{ kAutoProfile_KEY, CLASS_INDEX_SCOPED( plAutoProfile ), "kAutoProfile_KEY", },
|
||||
{ kGlobalVisMgr_KEY, CLASS_INDEX_SCOPED( plVisMgr ), "kGlobalVisMgr_KEY", },
|
||||
{ kFontCache_KEY, CLASS_INDEX_SCOPED( plFontCache ), "kFontCache_KEY", },
|
||||
{ kRelevanceMgr_KEY, CLASS_INDEX_SCOPED( plRelevanceMgr ), "kRelevanceMgr_KEY", },
|
||||
{ kJournalBookMgr_KEY, CLASS_INDEX_SCOPED( pfJournalBook ), "kJournalBookMgr_KEY" },
|
||||
{ kAgeLoader_KEY, CLASS_INDEX_SCOPED( plAgeLoader), "kAgeLoader_KEY" },
|
||||
{ kBuiltIn3rdPersonCamera_KEY, CLASS_INDEX_SCOPED( plCameraModifier1 ), "kBuiltIn3rdPersonCamera_KEY", },
|
||||
{ kSecurePreloader_KEY, CLASS_INDEX_SCOPED( pfSecurePreloader ), "kSecurePreloader_KEY", },
|
||||
|
||||
|
||||
{ kLast_Fixed_KEY, CLASS_INDEX_SCOPED( plSceneObject ), "kLast_Fixed_KEY", }
|
||||
};
|
||||
|
||||
|
||||
//// plFixedKeyValidator /////////////////////////////////////////////////////
|
||||
// Static class that validates the fixed key list on startup, to make sure
|
||||
// you didn't mess up the array.
|
||||
|
||||
class plFixedKeyValidator
|
||||
{
|
||||
private:
|
||||
static plFixedKeyValidator fValidator;
|
||||
|
||||
plFixedKeyValidator::plFixedKeyValidator()
|
||||
{
|
||||
// verify that each Seed is in the correct spot...via the enum...
|
||||
int i;
|
||||
for (i= kFirst_Fixed_KEY; i < kLast_Fixed_KEY; i++)
|
||||
{
|
||||
plKeySeed *p= &SeedList[i];
|
||||
hsAssert(i == p->feFixedKey, "The fixed key table in plFixedKey.h is invalid (a fixed key is misplaced). Please ensure the list follows the given restrictions.");
|
||||
}
|
||||
// check for duplicates
|
||||
for (i= kFirst_Fixed_KEY; i < kLast_Fixed_KEY; i++)
|
||||
{
|
||||
for (int c = i+1; c < kLast_Fixed_KEY; c++)
|
||||
{
|
||||
hsAssert(!SeedList[i].Match(&SeedList[c]),
|
||||
"The fixed key table in plFixedKey.h is invalid (there are duplicate fixed keys). Please ensure the list follows the given restrictions.");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
plFixedKeyValidator plFixedKeyValidator::fValidator;
|
||||
|
||||
//// The plUoid Fixed-Key Constructor ////////////////////////////////////////
|
||||
// Put here because a) it's fixedKey dependant and b) it ensures that this
|
||||
// file gets compiled.
|
||||
|
||||
plUoid::plUoid(plFixedKeyId fixedkey)
|
||||
{
|
||||
hsAssert(fixedkey < kLast_Fixed_KEY, "Request for Fixed key is out of Range");
|
||||
|
||||
fObjectName = nil;
|
||||
Invalidate();
|
||||
|
||||
plKeySeed* p= &SeedList[fixedkey];
|
||||
|
||||
fLocation = plLocation::kGlobalFixedLoc;
|
||||
fClassType = p->fType;
|
||||
fObjectName = hsStrcpy(p->fObj);
|
||||
fObjectID = 0;
|
||||
fCloneID = 0;
|
||||
fClonePlayerID = 0;
|
||||
}
|
||||
|
94
Sources/Plasma/NucleusLib/pnKeyedObject/plFixedKey.h
Normal file
94
Sources/Plasma/NucleusLib/pnKeyedObject/plFixedKey.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*==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 PLFIXEDKEY_H
|
||||
#define PLFIXEDKEY_H
|
||||
|
||||
|
||||
// Using Fixed Key feature:
|
||||
// Add a new fixedkey to the enum list below.
|
||||
// Then add, to the Seed list (in plFixedKey.cpp) in the Corresponding
|
||||
// position, (don't screw up, it will be validated...)
|
||||
// The "Full Address" data for you Fixed key (see rules in plFixedKey.cpp)
|
||||
|
||||
enum plFixedKeyId
|
||||
{
|
||||
kFirst_Fixed_KEY,
|
||||
|
||||
kLOSObject_KEY,
|
||||
kTimerCallbackManager_KEY,
|
||||
kConsoleObject_KEY,
|
||||
kAudioSystem_KEY,
|
||||
kInput_KEY,
|
||||
kClient_KEY,
|
||||
kNetClientMgr_KEY,
|
||||
kListenerMod_KEY,
|
||||
kTransitionMgr_KEY,
|
||||
kLinkEffectsMgr_KEY,
|
||||
kGameGUIMgr_KEY,
|
||||
kGameGUIDynamicDlg_KEY,
|
||||
kVirtualCamera1_KEY,
|
||||
kDefaultCameraMod1_KEY,
|
||||
kKIGUIGlue_KEY,
|
||||
kClothingMgr_KEY,
|
||||
kInputInterfaceMgr_KEY,
|
||||
kAVIWriter_KEY,
|
||||
kResManagerHelper_KEY,
|
||||
kAvatarMgr_KEY,
|
||||
kSimulationMgr_KEY,
|
||||
kTransitionCamera_KEY,
|
||||
kCCRMgr_KEY,
|
||||
kNetClientCloneRoom_KEY,
|
||||
kMarkerMgr_KEY,
|
||||
kAutoProfile_KEY,
|
||||
kGlobalVisMgr_KEY,
|
||||
kFontCache_KEY,
|
||||
kRelevanceMgr_KEY,
|
||||
kJournalBookMgr_KEY,
|
||||
kAgeLoader_KEY,
|
||||
kBuiltIn3rdPersonCamera_KEY,
|
||||
kSecurePreloader_KEY,
|
||||
|
||||
kLast_Fixed_KEY
|
||||
};
|
||||
|
||||
|
||||
#endif
|
303
Sources/Plasma/NucleusLib/pnKeyedObject/plKey.cpp
Normal file
303
Sources/Plasma/NucleusLib/pnKeyedObject/plKey.cpp
Normal file
@ -0,0 +1,303 @@
|
||||
/*==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==*/
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// plKey - An opaque pointer to actual key data, so that we can keep track
|
||||
// of how many people have pointers (plKeys) to key data (plKeyImp)
|
||||
// and destroy the key data when it's been fully unreffed.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "plKey.h"
|
||||
#include "plUoid.h"
|
||||
#include <string.h>
|
||||
#include "hsResMgr.h"
|
||||
#include "hsTypes.h"
|
||||
|
||||
#define TRACK_REFS 0 // MEMLEAKFISH
|
||||
|
||||
#if TRACK_REFS
|
||||
#include "plCreatableIndex.h"
|
||||
#include "plClassIndexMacros.h"
|
||||
#include "plTweak.h"
|
||||
|
||||
int mlfTrack = 1;
|
||||
|
||||
static const char* keyNameToLookFor = "AgeSDLHook";
|
||||
static const UInt16 CLASS_TO_TRACK = CLASS_INDEX_SCOPED(plSceneObject);
|
||||
static const int kCloneID = 0;
|
||||
static const int kClonePlayerID = 0;
|
||||
static plKeyData* lastData = nil;
|
||||
static const int kLocSeq = -1;
|
||||
|
||||
class keyDataFriend : public plKeyData
|
||||
{
|
||||
public:
|
||||
UInt16 RefCount() const { return fRefCount; }
|
||||
};
|
||||
|
||||
static int IsTracked(const plKeyData* keyData)
|
||||
{
|
||||
if( mlfTrack && keyData )
|
||||
{
|
||||
if( keyData->GetUoid().GetObjectName() && !stricmp(keyData->GetUoid().GetObjectName(), keyNameToLookFor)
|
||||
&& (keyData->GetUoid().GetClassType() == CLASS_TO_TRACK) )
|
||||
{
|
||||
if( (kCloneID < 0)
|
||||
||(kCloneID == keyData->GetUoid().GetCloneID()) )
|
||||
{
|
||||
if( (kLocSeq < 0)
|
||||
||(kLocSeq == keyData->GetUoid().GetLocation().GetSequenceNumber()) )
|
||||
{
|
||||
plConst(UInt16) kMinRefCount(0);
|
||||
const keyDataFriend* kdf = (keyDataFriend*)keyData;
|
||||
if( kdf->RefCount() > kMinRefCount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char* CloneString(const plKeyData* keyData)
|
||||
{
|
||||
static char buff[256];
|
||||
if( keyData )
|
||||
{
|
||||
sprintf(buff, "CID:%d, CPID:%d LOC:%d",
|
||||
keyData->GetUoid().GetCloneID(),
|
||||
keyData->GetUoid().GetClonePlayerID(),
|
||||
keyData->GetUoid().GetLocation().GetSequenceNumber());
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buff, "nil");
|
||||
}
|
||||
return buff;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
plKey::plKey() : fKeyData(nil)
|
||||
{
|
||||
}
|
||||
|
||||
plKey::plKey(void* ptr) : fKeyData(nil)
|
||||
{
|
||||
hsAssert(!ptr, "Attempting to publically construct a non-nil key");
|
||||
}
|
||||
|
||||
plKey::plKey(const plKey& rhs) : fKeyData(rhs.fKeyData)
|
||||
{
|
||||
#if TRACK_REFS // FOR DEBUGGING ONLY
|
||||
if( IsTracked(fKeyData) )
|
||||
{
|
||||
char msg[ 512 ];
|
||||
sprintf( msg, "C: Key %s %s is being constructed using the plKey(plKey&) constructor", keyNameToLookFor, CloneString(fKeyData) );
|
||||
//hsAssert( false, msg );
|
||||
hsStatusMessageF(msg);
|
||||
}
|
||||
#endif
|
||||
IIncRef();
|
||||
}
|
||||
|
||||
plKey::plKey(plKeyData* data, hsBool ignore) : fKeyData(data)
|
||||
{
|
||||
#if TRACK_REFS // FOR DEBUGGING ONLY
|
||||
if( IsTracked(fKeyData) )
|
||||
{
|
||||
char msg[ 512 ];
|
||||
sprintf( msg, "C: Key %s %s is being constructed using the plKey(plKeyData*, hsBool) constructor", keyNameToLookFor, CloneString(fKeyData) );
|
||||
//hsAssert( false, msg );
|
||||
hsStatusMessageF(msg);
|
||||
}
|
||||
#endif
|
||||
IIncRef();
|
||||
}
|
||||
|
||||
plKey::~plKey()
|
||||
{
|
||||
#if TRACK_REFS // FOR DEBUGGING ONLY
|
||||
if( IsTracked(fKeyData) )
|
||||
{
|
||||
char msg[ 512 ];
|
||||
sprintf( msg, "D: Key %s %s is being destructed", keyNameToLookFor, CloneString(fKeyData) );
|
||||
//hsAssert( false, msg );
|
||||
hsStatusMessageF(msg);
|
||||
}
|
||||
#endif
|
||||
IDecRef();
|
||||
}
|
||||
|
||||
plKey &plKey::operator=( const plKey &rhs )
|
||||
{
|
||||
#if TRACK_REFS // FOR DEBUGGING ONLY
|
||||
if( fKeyData != rhs.fKeyData )
|
||||
{
|
||||
if( IsTracked(rhs.fKeyData) )
|
||||
{
|
||||
char msg[ 512 ];
|
||||
if (fKeyData == nil)
|
||||
sprintf( msg, "=: Key %s %s is being assigned to a nil key", keyNameToLookFor, CloneString(rhs.fKeyData) );
|
||||
else
|
||||
sprintf( msg, "=: Key %s %s is being assigned to %s", keyNameToLookFor, CloneString(rhs.fKeyData), fKeyData->GetUoid().GetObjectName() );
|
||||
//hsAssert( false, msg );
|
||||
hsStatusMessageF(msg);
|
||||
}
|
||||
if( IsTracked(fKeyData) )
|
||||
{
|
||||
char msg[ 512 ];
|
||||
if (fKeyData == nil)
|
||||
sprintf( msg, "=: Nil key is being assigned to %s %s", keyNameToLookFor, CloneString(fKeyData) );
|
||||
else
|
||||
sprintf( msg, "=: Key %s %s is being assigned to %s", fKeyData->GetUoid().GetObjectName(), CloneString(fKeyData), keyNameToLookFor );
|
||||
//hsAssert( false, msg );
|
||||
hsStatusMessageF(msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if( fKeyData != rhs.fKeyData )
|
||||
{
|
||||
IDecRef();
|
||||
fKeyData = rhs.fKeyData;
|
||||
IIncRef();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
hsBool plKey::operator==( const plKey &rhs ) const
|
||||
{
|
||||
return fKeyData == rhs.fKeyData;
|
||||
}
|
||||
|
||||
hsBool plKey::operator==( const plKeyData *rhs ) const
|
||||
{
|
||||
return fKeyData == rhs;
|
||||
}
|
||||
|
||||
plKeyData *plKey::operator->() const
|
||||
{
|
||||
return fKeyData;
|
||||
}
|
||||
|
||||
plKeyData &plKey::operator*() const
|
||||
{
|
||||
return *fKeyData;
|
||||
}
|
||||
|
||||
void plKey::IIncRef()
|
||||
{
|
||||
if (!fKeyData)
|
||||
return;
|
||||
|
||||
hsAssert(fKeyData->fRefCount < 0xffff, "Too many refs to plKeyImp");
|
||||
fKeyData->fRefCount++;
|
||||
|
||||
#if TRACK_REFS // FOR DEBUGGING ONLY
|
||||
if( IsTracked(fKeyData) )
|
||||
{
|
||||
char msg[ 512 ];
|
||||
plConst(int) kMaxCnt(30);
|
||||
if( fKeyData->fRefCount > kMaxCnt )
|
||||
*msg = 0;
|
||||
if( lastData && (fKeyData != lastData) )
|
||||
*msg = 0;
|
||||
lastData = fKeyData;
|
||||
sprintf( msg, "+: Key %s %s is being reffed! Refcount: %d", keyNameToLookFor, CloneString(fKeyData), fKeyData->fRefCount );
|
||||
//hsAssert( false, msg );
|
||||
hsStatusMessageF(msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fKeyData->fRefCount == 1)
|
||||
hsgResMgr::ResMgr()->IKeyReffed((plKeyImp*)fKeyData);
|
||||
}
|
||||
|
||||
void plKey::IDecRef()
|
||||
{
|
||||
if (!fKeyData)
|
||||
return;
|
||||
|
||||
hsAssert(fKeyData->fRefCount, "Dec'ing ref on unreffed key");
|
||||
fKeyData->fRefCount--;
|
||||
|
||||
#if TRACK_REFS // FOR DEBUGGING ONLY
|
||||
if( IsTracked(fKeyData) )
|
||||
{
|
||||
char msg[ 512 ];
|
||||
plConst(int) kMinCnt(2);
|
||||
if( fKeyData->fRefCount < kMinCnt )
|
||||
*msg = 0;
|
||||
if( lastData && (fKeyData != lastData) )
|
||||
*msg = 0;
|
||||
lastData = fKeyData;
|
||||
sprintf( msg, "-: Key %s %s is being de-reffed! Refcount: %d", keyNameToLookFor, CloneString(fKeyData), fKeyData->fRefCount );
|
||||
//hsAssert( false, msg );
|
||||
hsStatusMessageF(msg);
|
||||
if( fKeyData->fRefCount == 0 )
|
||||
*msg = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (fKeyData->fRefCount == 0)
|
||||
hsgResMgr::ResMgr()->IKeyUnreffed((plKeyImp*)fKeyData);
|
||||
}
|
||||
|
||||
//// plKeyData ///////////////////////////////////////////////////////////////
|
||||
// Our base class of key data
|
||||
|
||||
plKeyData::plKeyData()
|
||||
{
|
||||
fRefCount = 0;
|
||||
}
|
||||
|
||||
plKeyData::~plKeyData()
|
||||
{
|
||||
// hsAssert(fRefCount == 0, "Deleting key data when someone still has a ref to it");
|
||||
}
|
||||
|
||||
|
157
Sources/Plasma/NucleusLib/pnKeyedObject/plKey.h
Normal file
157
Sources/Plasma/NucleusLib/pnKeyedObject/plKey.h
Normal file
@ -0,0 +1,157 @@
|
||||
/*==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 plKey_h_inc
|
||||
#define plKey_h_inc
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "plRefFlags.h"
|
||||
|
||||
class hsKeyedObject;
|
||||
class plRefMsg;
|
||||
class plUoid;
|
||||
class hsBitVector;
|
||||
|
||||
//// plKey ///////////////////////////////////////////////////////////////////
|
||||
// Pointer to a plKeyData struct, which is a handle to a keyedObject
|
||||
|
||||
class plKeyData;
|
||||
class plKeyImp;
|
||||
|
||||
class plKey
|
||||
{
|
||||
public:
|
||||
// Constructors and destructors and copy stuff
|
||||
plKey();
|
||||
plKey(const plKey& rhs);
|
||||
plKey(void* ptr); // For constructing a nil key
|
||||
~plKey();
|
||||
plKey& operator=(const plKey& rhs);
|
||||
|
||||
hsBool operator==(const plKey& rhs) const;
|
||||
hsBool operator==(const plKeyData* rhs) const;
|
||||
hsBool operator!=(const plKey& rhs) const { return !(*this == rhs); }
|
||||
hsBool operator!=(const plKeyData* rhs) const { return !(*this == rhs); }
|
||||
|
||||
plKeyData* operator->() const;
|
||||
plKeyData& operator*() const;
|
||||
|
||||
operator plKeyImp*() const { return (plKeyImp*)fKeyData; }
|
||||
|
||||
static plKey Make(plKeyData* data) { return plKey(data, false); }
|
||||
|
||||
protected:
|
||||
// Pointer to our real key
|
||||
plKeyData* fKeyData;
|
||||
void IIncRef();
|
||||
void IDecRef();
|
||||
|
||||
// Internal constructor, extra param is to distinguish it from the void* constructor
|
||||
plKey(plKeyData* data, hsBool ignore);
|
||||
};
|
||||
|
||||
//// plKeyData ///////////////////////////////////////////////////////////////
|
||||
// Base virtual class that provides the essential functionality you would
|
||||
// want from a plKey-ish thing.
|
||||
|
||||
class plKeyData
|
||||
{
|
||||
public:
|
||||
virtual const plUoid& GetUoid() const=0;
|
||||
virtual const char* GetName() const=0;
|
||||
|
||||
virtual hsKeyedObject* GetObjectPtr()=0;
|
||||
virtual hsKeyedObject* ObjectIsLoaded() const=0;
|
||||
virtual hsKeyedObject* VerifyLoaded() = 0;
|
||||
|
||||
//----------------------
|
||||
// Allow a keyed object to behave as if it has an active ref when in fact the object
|
||||
// should only be active ref'ed by a non-keyed parent. Essentially just bumps/decs
|
||||
// the active ref count to facilitate normal object creation/destruction
|
||||
//----------------------
|
||||
virtual hsKeyedObject* RefObject(plRefFlags::Type flags = plRefFlags::kActiveRef)=0;
|
||||
virtual void UnRefObject(plRefFlags::Type flags = plRefFlags::kActiveRef)=0;
|
||||
|
||||
//----------------------
|
||||
// Release has two behaviors, depending on whether the ref is active or passive:
|
||||
// Active - Release decs the ActiveRefCnt. When it gets to zero, the object will be deleted.
|
||||
// Passive - Unregisters my interest in when the object is created or destroyed.
|
||||
//----------------------
|
||||
virtual void Release(plKey targetKey)=0;
|
||||
|
||||
virtual UInt16 GetActiveRefs() const = 0;
|
||||
|
||||
virtual UInt16 GetNumNotifyCreated() const = 0;
|
||||
virtual plRefMsg* GetNotifyCreated(int i) const = 0;
|
||||
virtual const hsBitVector& GetActiveBits() const = 0;
|
||||
|
||||
protected:
|
||||
// Protected so only the registry can create it
|
||||
plKeyData();
|
||||
virtual ~plKeyData();
|
||||
|
||||
#ifdef HS_DEBUGGING
|
||||
// Debugging info fields
|
||||
const char* fIDName;
|
||||
const char* fClassType;
|
||||
#endif
|
||||
|
||||
//// RefCount Stuff //////////////////////////////////////////////////////////
|
||||
// The refcounts on plKeyData/plKeyImps are zero-based. When you first create
|
||||
// a new plKeyImp (which should ONLY ever be done inside the resMgr), it gets
|
||||
// a refcount of zero. Assigning a new plKey to represent it bumps it to 1,
|
||||
// and when that key goes away, the refcount drops to zero and the ResManager
|
||||
// is notified of the fact and may delete the keyImp.
|
||||
// So the only refcounts on keys outside of the resMgr should be one or more;
|
||||
// only inside the resMgr should there EVER exist keys with a refcount of 0.
|
||||
//
|
||||
// Using our own refCount system instead of hsRefCnt allows us to make it all
|
||||
// protected, so that only plKey can actually ref/unref, which is as it should
|
||||
// be.
|
||||
|
||||
// Only one class should ever touch this...
|
||||
friend class plKey;
|
||||
|
||||
// Refcount--the number of plKeys that have pointers to us.
|
||||
UInt16 fRefCount;
|
||||
};
|
||||
|
||||
#endif // plKey_h_inc
|
666
Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp
Normal file
666
Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp
Normal file
@ -0,0 +1,666 @@
|
||||
/*==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 "plKeyImp.h"
|
||||
#include "hsStream.h"
|
||||
#include "hsKeyedObject.h"
|
||||
#include "hsResMgr.h"
|
||||
#include "hsTypes.h"
|
||||
#include "../pnMessage/plRefMsg.h"
|
||||
#include "../pnMessage/plSelfDestructMsg.h"
|
||||
#include "hsTimer.h"
|
||||
#include "plProfile.h"
|
||||
#include "plgDispatch.h"
|
||||
|
||||
plProfile_CreateMemCounter("Keys", "Memory", KeyMem);
|
||||
|
||||
static UInt32 CalcKeySize(plKeyImp* key)
|
||||
{
|
||||
UInt32 nameLen = 0;
|
||||
if (key->GetUoid().GetObjectName())
|
||||
nameLen = strlen(key->GetUoid().GetObjectName()) + 1;
|
||||
return sizeof(plKeyImp) + nameLen;
|
||||
}
|
||||
|
||||
//#define LOG_ACTIVE_REFS
|
||||
#ifdef LOG_ACTIVE_REFS
|
||||
#include "plCreatableIndex.h"
|
||||
static const char* kObjName = "GUI_District_OptionsMenuGUI";
|
||||
static UInt16 kClassType = CLASS_INDEX_SCOPED(plSceneNode);
|
||||
static UInt32 kCloneID = 0;
|
||||
hsBool IsTrackedKey(const plKeyImp* key)
|
||||
{
|
||||
return hsStrEQ(key->GetName(), kObjName) && key->GetUoid().GetClassType() == kClassType && key->GetUoid().GetCloneID() == kCloneID;
|
||||
}
|
||||
#endif
|
||||
|
||||
plKeyImp::plKeyImp() :
|
||||
fObjectPtr(nil),
|
||||
fStartPos(-1),
|
||||
fDataLen(-1),
|
||||
fNumActiveRefs(0),
|
||||
fPendingRefs(1),
|
||||
fCloneOwner(nil)
|
||||
{
|
||||
#ifdef HS_DEBUGGING
|
||||
fIDName = nil;
|
||||
fClassType = nil;
|
||||
#endif
|
||||
}
|
||||
|
||||
plKeyImp::plKeyImp(plUoid u, UInt32 pos,UInt32 len):
|
||||
fUoid(u),
|
||||
fObjectPtr(nil),
|
||||
fStartPos(pos),
|
||||
fDataLen(len),
|
||||
fNumActiveRefs(0),
|
||||
fPendingRefs(1),
|
||||
fCloneOwner(nil)
|
||||
{
|
||||
plProfile_NewMem(KeyMem, CalcKeySize(this));
|
||||
|
||||
#ifdef HS_DEBUGGING
|
||||
fIDName = fUoid.GetObjectName();
|
||||
fClassType = plFactory::GetNameOfClass( fUoid.GetClassType() );
|
||||
#endif
|
||||
}
|
||||
|
||||
plKeyImp::~plKeyImp()
|
||||
{
|
||||
plProfile_DelMem(KeyMem, CalcKeySize(this));
|
||||
|
||||
#if defined(HS_DEBUGGING) && 0
|
||||
// Colin debugging
|
||||
char buf[512];
|
||||
sprintf(buf, "0x%x %s %s\n", this, fIDName, fClassType);
|
||||
hsStatusMessage(buf);
|
||||
#endif
|
||||
|
||||
hsAssert(fObjectPtr == nil, "Deleting non-nil key! Bad idea!");
|
||||
|
||||
if (fCloneOwner != nil)
|
||||
{
|
||||
// Must be a clone, remove us from our parent list
|
||||
((plKeyImp*)fCloneOwner)->RemoveClone(this);
|
||||
}
|
||||
|
||||
for (int i = 0; i < fClones.GetCount(); i++)
|
||||
{
|
||||
if (fClones[i])
|
||||
fClones[i]->UnRegister();
|
||||
}
|
||||
fClones.Reset();
|
||||
|
||||
// This is normally empty by now, but if we never got loaded,
|
||||
// there will be unsent ref messages in the NotifyCreated list
|
||||
ClearNotifyCreated();
|
||||
}
|
||||
|
||||
void plKeyImp::SetUoid(const plUoid& uoid)
|
||||
{
|
||||
fUoid = uoid;
|
||||
#ifdef HS_DEBUGGING
|
||||
fIDName = fUoid.GetObjectName();
|
||||
fClassType = plFactory::GetNameOfClass(fUoid.GetClassType());
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* plKeyImp::GetName() const
|
||||
{
|
||||
return fUoid.GetObjectName();
|
||||
}
|
||||
|
||||
hsKeyedObject* plKeyImp::GetObjectPtr()
|
||||
{
|
||||
return ObjectIsLoaded();
|
||||
}
|
||||
|
||||
hsKeyedObject* plKeyImp::ObjectIsLoaded() const
|
||||
{
|
||||
return this ? fObjectPtr : nil;
|
||||
}
|
||||
|
||||
// Copy the contents of p for cloning process
|
||||
void plKeyImp::CopyForClone(const plKeyImp *p, UInt32 playerID, UInt32 cloneID)
|
||||
{
|
||||
fObjectPtr = nil; // the clone object start as nil
|
||||
fUoid = p->GetUoid(); // we will set the UOID the same to start
|
||||
|
||||
#ifdef HS_DEBUGGING
|
||||
fIDName = fUoid.GetObjectName();
|
||||
fClassType = plFactory::GetNameOfClass( fUoid.GetClassType() );
|
||||
#endif
|
||||
|
||||
fStartPos = p->GetStartPos();
|
||||
fDataLen = p->GetDataLen();
|
||||
fUoid.SetClone(playerID, cloneID);
|
||||
}
|
||||
|
||||
hsKeyedObject* plKeyImp::VerifyLoaded()
|
||||
{
|
||||
if (!fObjectPtr)
|
||||
hsgResMgr::ResMgr()->ReadObject(this);
|
||||
|
||||
return fObjectPtr;
|
||||
}
|
||||
|
||||
//// Read/Write //////////////////////////////////////////////////////////////
|
||||
// The actual key read/writes for the index file, the only time the whole
|
||||
// key is ever actually stored.
|
||||
|
||||
void plKeyImp::Read(hsStream* s)
|
||||
{
|
||||
fUoid.Read(s);
|
||||
s->ReadSwap(&fStartPos);
|
||||
s->ReadSwap(&fDataLen);
|
||||
|
||||
plProfile_NewMem(KeyMem, CalcKeySize(this));
|
||||
|
||||
#ifdef HS_DEBUGGING
|
||||
fIDName = fUoid.GetObjectName();
|
||||
fClassType = plFactory::GetNameOfClass(fUoid.GetClassType());
|
||||
#endif
|
||||
}
|
||||
|
||||
void plKeyImp::SkipRead(hsStream* s)
|
||||
{
|
||||
plUoid tempUoid;
|
||||
tempUoid.Read(s);
|
||||
s->ReadSwap32();
|
||||
s->ReadSwap32();
|
||||
}
|
||||
|
||||
void plKeyImp::Write(hsStream* s)
|
||||
{
|
||||
fUoid.Write(s);
|
||||
s->WriteSwap(fStartPos);
|
||||
s->WriteSwap(fDataLen);
|
||||
if (fStartPos == (UInt32)-1)
|
||||
int foo = 0;
|
||||
}
|
||||
|
||||
//// WriteObject /////////////////////////////////////////////////////////////
|
||||
// Writes the key's object to the already opened stream
|
||||
|
||||
void plKeyImp::WriteObject(hsStream* stream)
|
||||
{
|
||||
hsKeyedObject* ko = ObjectIsLoaded();
|
||||
if (ko == nil)
|
||||
{
|
||||
// Mark the key as not written
|
||||
fStartPos = (UInt32)-1;
|
||||
fDataLen = (UInt32)-1;
|
||||
return;
|
||||
}
|
||||
|
||||
fStartPos = stream->GetPosition();
|
||||
hsgResMgr::ResMgr()->WriteCreatable(stream, ko);
|
||||
fDataLen = stream->GetPosition() - fStartPos;
|
||||
}
|
||||
|
||||
void plKeyImp::UnRegister() // called from plRegistry
|
||||
{
|
||||
plKey safeRefUntilWereDone = plKey::Make(this);
|
||||
|
||||
hsKeyedObject* ko = ObjectIsLoaded();
|
||||
if (ko)
|
||||
{
|
||||
INotifyDestroyed();
|
||||
fObjectPtr = nil;
|
||||
fNumActiveRefs = 0;
|
||||
|
||||
hsRefCnt_SafeUnRef(ko);
|
||||
}
|
||||
IClearRefs();
|
||||
ClearNotifyCreated();
|
||||
};
|
||||
|
||||
hsKeyedObject* plKeyImp::RefObject(plRefFlags::Type flags)
|
||||
{
|
||||
if ((flags == plRefFlags::kPassiveRef) && !ObjectIsLoaded())
|
||||
return nil;
|
||||
|
||||
#ifdef LOG_ACTIVE_REFS
|
||||
if (IsTrackedKey(this))
|
||||
hsStatusMessageF("@@@ RefObject adding active ref to %s (%d total)", kObjName, fNumActiveRefs+1);
|
||||
#endif // LOG_ACTIVE_REFS
|
||||
|
||||
IncActiveRefs();
|
||||
|
||||
return VerifyLoaded(); // load object on demand
|
||||
}
|
||||
|
||||
void plKeyImp::UnRefObject(plRefFlags::Type flags)
|
||||
{
|
||||
// Rather than using hsRefCnt's, make Ref and
|
||||
// UnRef work with ActiveRef system
|
||||
if ( (flags == plRefFlags::kPassiveRef) && !ObjectIsLoaded())
|
||||
return;
|
||||
|
||||
#ifdef LOG_ACTIVE_REFS
|
||||
if (IsTrackedKey(this))
|
||||
hsStatusMessageF("@@@ UnRefObject releasing active ref to %s (%d total)", kObjName, fNumActiveRefs-1);
|
||||
#endif // LOG_ACTIVE_REFS
|
||||
DecActiveRefs();
|
||||
|
||||
if( !GetActiveRefs() )
|
||||
{
|
||||
INotifyDestroyed();
|
||||
|
||||
IClearRefs();
|
||||
ClearNotifyCreated();
|
||||
|
||||
plKey key=plKey::Make( this ); // for linux build
|
||||
plSelfDestructMsg* nuke = TRACKED_NEW plSelfDestructMsg( key );
|
||||
plgDispatch::Dispatch()->MsgSend(nuke);
|
||||
}
|
||||
}
|
||||
|
||||
hsKeyedObject* plKeyImp::SetObjectPtr(hsKeyedObject* p)
|
||||
{
|
||||
hsKeyedObject* retVal = nil;
|
||||
|
||||
// If our object is the only one with a ref to us, this function will crash, so we
|
||||
// make sure we have an extra ref, just like in UnRegister().
|
||||
plKey safeRefUntilWereDone = plKey::Make(this);
|
||||
|
||||
if (p)
|
||||
{
|
||||
#ifdef HS_DEBUGGING
|
||||
if (fClassType)
|
||||
{
|
||||
char str[2048];
|
||||
sprintf(str, "Mismatch of class (we are a %s, given a %s)", fClassType, p->ClassName());
|
||||
hsAssert(fClassType == p->ClassName() || strcmp(fClassType, p->ClassName()) == 0, str); // points to static
|
||||
}
|
||||
else
|
||||
fClassType = p->ClassName();
|
||||
#endif
|
||||
|
||||
hsAssert(!fObjectPtr, "Setting an ObjectPtr thats already Set!");
|
||||
|
||||
retVal = fObjectPtr = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fObjectPtr)
|
||||
UnRegister();
|
||||
|
||||
fObjectPtr = nil;
|
||||
retVal = nil;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void plKeyImp::ClearNotifyCreated()
|
||||
{
|
||||
for (int i = 0; i < fNotifyCreated.GetCount(); i++)
|
||||
hsRefCnt_SafeUnRef(fNotifyCreated[i]);
|
||||
fNotifyCreated.Reset();
|
||||
fNotified.Reset();
|
||||
fActiveRefs.Reset();
|
||||
}
|
||||
|
||||
void plKeyImp::AddNotifyCreated(plRefMsg* msg, plRefFlags::Type flags)
|
||||
{
|
||||
if (!(flags == plRefFlags::kPassiveRef))
|
||||
{
|
||||
#ifdef LOG_ACTIVE_REFS
|
||||
if (IsTrackedKey(this))
|
||||
{
|
||||
hsStatusMessageF("@@@ %s(%s) adding active ref to %s (%d total)", msg->GetReceiver(0)->GetName(),
|
||||
plFactory::GetNameOfClass(msg->GetReceiver(0)->GetUoid().GetClassType()), kObjName, fNumActiveRefs+1);
|
||||
}
|
||||
#endif // LOG_ACTIVE_REFS
|
||||
|
||||
IncActiveRefs();
|
||||
SetActiveRef(GetNumNotifyCreated());
|
||||
}
|
||||
|
||||
hsRefCnt_SafeRef(msg);
|
||||
fNotifyCreated.Append(msg);
|
||||
}
|
||||
|
||||
void plKeyImp::RemoveNotifyCreated(int i)
|
||||
{
|
||||
hsRefCnt_SafeUnRef(fNotifyCreated[i]);
|
||||
fNotifyCreated.Remove(i);
|
||||
|
||||
fNotified.RemoveBit(i);
|
||||
fActiveRefs.RemoveBit(i);
|
||||
}
|
||||
|
||||
void plKeyImp::AddRef(plKeyImp* key) const
|
||||
{
|
||||
fPendingRefs++;
|
||||
fRefs.Append(key);
|
||||
}
|
||||
|
||||
|
||||
void plKeyImp::RemoveRef(plKeyImp* key) const
|
||||
{
|
||||
int idx = fRefs.Find(key);
|
||||
if (fRefs.kMissingIndex != idx)
|
||||
fRefs.Remove(idx);
|
||||
}
|
||||
|
||||
void plKeyImp::AddClone(plKeyImp* key)
|
||||
{
|
||||
hsAssert(!GetClone(key->GetUoid().GetClonePlayerID(), key->GetUoid().GetCloneID()),
|
||||
"Adding a clone which is already there?");
|
||||
|
||||
key->fCloneOwner = plKey::Make(this);
|
||||
fClones.Append(key);
|
||||
}
|
||||
|
||||
void plKeyImp::RemoveClone(plKeyImp* key) const
|
||||
{
|
||||
if (key->GetUoid().IsClone())
|
||||
{
|
||||
int idx = fClones.Find(key);
|
||||
if (idx != -1)
|
||||
{
|
||||
fClones.Remove(idx);
|
||||
key->fCloneOwner = nil;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plKey plKeyImp::GetClone(UInt32 playerID, UInt32 cloneID) const
|
||||
{
|
||||
for (int i = 0; i < fClones.GetCount(); i++)
|
||||
{
|
||||
plKeyImp* cloneKey = fClones[i];
|
||||
if (cloneKey
|
||||
&& cloneKey->GetUoid().GetCloneID() == cloneID
|
||||
&& cloneKey->GetUoid().GetClonePlayerID() == playerID)
|
||||
return plKey::Make(cloneKey);
|
||||
}
|
||||
|
||||
return plKey();
|
||||
}
|
||||
|
||||
UInt32 plKeyImp::GetNumClones()
|
||||
{
|
||||
return fClones.GetCount();
|
||||
}
|
||||
|
||||
plKey plKeyImp::GetCloneByIdx(UInt32 idx)
|
||||
{
|
||||
if (idx < fClones.GetCount())
|
||||
return plKey::Make(fClones[idx]);
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
void plKeyImp::SatisfyPending(plRefMsg* msg) const
|
||||
{
|
||||
for (int i = 0; i < msg->GetNumReceivers(); i++)
|
||||
((plKeyImp*)msg->GetReceiver(i))->SatisfyPending();
|
||||
}
|
||||
|
||||
void plKeyImp::SatisfyPending() const
|
||||
{
|
||||
hsAssert(fPendingRefs > 0, "Have more requests satisfied than we made");
|
||||
if (!--fPendingRefs)
|
||||
{
|
||||
#ifdef PL_SEND_SATISFIED
|
||||
plSatisfiedMsg* msg = TRACKED_NEW plSatisfiedMsg(this);
|
||||
plgDispatch::MsgSend(msg);
|
||||
#endif // PL_SEND_SATISFIED
|
||||
}
|
||||
}
|
||||
|
||||
void plKeyImp::ISetupNotify(plRefMsg* msg, plRefFlags::Type flags)
|
||||
{
|
||||
msg->SetSender(nil);
|
||||
|
||||
AddNotifyCreated(msg, flags);
|
||||
|
||||
hsAssert(msg->GetNumReceivers(), "nil object getting a reference");
|
||||
for (int i = 0; i < msg->GetNumReceivers(); i++)
|
||||
((plKeyImp*)msg->GetReceiver(i))->AddRef(plKey::Make(this));
|
||||
}
|
||||
|
||||
void plKeyImp::SetupNotify(plRefMsg* msg, plRefFlags::Type flags)
|
||||
{
|
||||
hsKeyedObject* ko = ObjectIsLoaded();
|
||||
|
||||
ISetupNotify(msg, flags);
|
||||
|
||||
// the KeyedObject is already Loaded, so we better go ahead and send the notify message just added.
|
||||
if (ko)
|
||||
{
|
||||
hsRefCnt_SafeRef(ko);
|
||||
msg->SetRef(ko);
|
||||
msg->SetTimeStamp(hsTimer::GetSysSeconds());
|
||||
|
||||
// Add ref, since Dispatch will unref this msg but we want to keep using it.
|
||||
hsRefCnt_SafeRef(msg);
|
||||
|
||||
SetNotified(GetNumNotifyCreated()-1);
|
||||
SatisfyPending(msg);
|
||||
|
||||
#ifdef LOAD_IN_THREAD // test for resLoader
|
||||
plgDispatch::Dispatch()->MsgQueue(msg);
|
||||
#else
|
||||
plgDispatch::Dispatch()->MsgSend(msg);
|
||||
#endif
|
||||
|
||||
hsRefCnt_SafeUnRef(ko);
|
||||
}
|
||||
hsRefCnt_SafeUnRef(msg);
|
||||
}
|
||||
|
||||
// We could just call NotifyCreated() on all our fRefs, and then fix
|
||||
// up fNotified to only get set when the message actually was delivered (i.e.
|
||||
// refMsg->GetReceiver(0)->GetObjectPtr() != nil. But that only really works
|
||||
// if we guarantee the refMsg->GetNumReceivers() == 1.
|
||||
// This looks like it'll take forever to run, but this is only called right
|
||||
// when our object has just been loaded, at which time normally fRefs.GetCount() == 0.
|
||||
void plKeyImp::INotifySelf(hsKeyedObject* ko)
|
||||
{
|
||||
for (int i = 0; i < fRefs.GetCount(); i++)
|
||||
{
|
||||
hsKeyedObject* rcv = fRefs[i]->GetObjectPtr();
|
||||
if (rcv)
|
||||
{
|
||||
for (int j = 0; j < fRefs[i]->fNotifyCreated.GetCount(); j++)
|
||||
{
|
||||
plRefMsg* refMsg = fRefs[i]->fNotifyCreated[j];
|
||||
if (refMsg && refMsg->GetRef() && !fRefs[i]->IsNotified(j))
|
||||
{
|
||||
hsAssert(refMsg->GetRef() == rcv, "Ref message out of sync with its ref");
|
||||
|
||||
// GetNumReceivers() should always be 1 for a refMsg.
|
||||
for (int k = 0; k < refMsg->GetNumReceivers(); k++)
|
||||
{
|
||||
if (&(*refMsg->GetReceiver(k)) == (plKeyData*)this)
|
||||
{
|
||||
fRefs[i]->SetNotified(j);
|
||||
fRefs[i]->SatisfyPending(refMsg);
|
||||
|
||||
hsRefCnt_SafeRef(refMsg);
|
||||
plgDispatch::MsgSend(refMsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void plKeyImp::NotifyCreated()
|
||||
{
|
||||
hsKeyedObject* ko = GetObjectPtr();
|
||||
hsRefCnt_SafeRef(ko);
|
||||
hsAssert(ko, "Notifying of created before on nil object");
|
||||
|
||||
INotifySelf(ko);
|
||||
|
||||
for (int i = 0; i < GetNumNotifyCreated(); i++)
|
||||
{
|
||||
if (!IsNotified(i) && GetNotifyCreated(i)->GetReceiver(0)->GetObjectPtr())
|
||||
{
|
||||
plRefMsg* msg = GetNotifyCreated(i);
|
||||
msg->SetRef(ko);
|
||||
msg->SetTimeStamp(hsTimer::GetSysSeconds());
|
||||
msg->SetContext(plRefMsg::kOnCreate);
|
||||
hsRefCnt_SafeRef(msg);
|
||||
|
||||
SetNotified(i);
|
||||
SatisfyPending(msg);
|
||||
|
||||
plgDispatch::MsgSend(msg);
|
||||
}
|
||||
}
|
||||
hsRefCnt_SafeUnRef(ko);
|
||||
}
|
||||
|
||||
void plKeyImp::INotifyDestroyed()
|
||||
{
|
||||
hsKeyedObject* ko = GetObjectPtr();
|
||||
hsAssert(ko, "Notifying of destroy on already destroyed");
|
||||
int i;
|
||||
for( i = 0; i < GetNumNotifyCreated(); i++ )
|
||||
{
|
||||
hsAssert(ko, "Notifying of destroy on already destroyed");
|
||||
plRefMsg* msg = GetNotifyCreated(i);
|
||||
msg->SetRef(ko);
|
||||
msg->SetTimeStamp(hsTimer::GetSysSeconds());
|
||||
msg->SetContext(plRefMsg::kOnDestroy);
|
||||
hsRefCnt_SafeRef(msg);
|
||||
msg->Send();
|
||||
}
|
||||
fNotified.Clear();
|
||||
}
|
||||
|
||||
void plKeyImp::IClearRefs()
|
||||
{
|
||||
while (GetNumRefs())
|
||||
IRelease(GetRef(0));
|
||||
fRefs.Reset();
|
||||
|
||||
for (int i = 0; i < GetNumNotifyCreated(); i++)
|
||||
{
|
||||
plRefMsg* msg = GetNotifyCreated(i);
|
||||
for (int j = 0; j < msg->GetNumReceivers(); j++)
|
||||
((plKeyImp*)msg->GetReceiver(j))->RemoveRef(this);
|
||||
}
|
||||
}
|
||||
|
||||
void plKeyImp::Release(plKey targetKey)
|
||||
{
|
||||
IRelease((plKeyImp*)targetKey);
|
||||
}
|
||||
|
||||
void plKeyImp::IRelease(plKeyImp* iTargetKey)
|
||||
{
|
||||
// Remove the target key from my ref list
|
||||
RemoveRef(iTargetKey);
|
||||
|
||||
// Inspect the target key to find whether it is supposed to send a message
|
||||
// to me on destruction, and to find out if I have an active of passive
|
||||
// ref on this key. Not sure why I don't track my own active/passive ref states
|
||||
hsBool isActive = false;
|
||||
int iTarg = -1;
|
||||
for (int i = 0; (iTarg < 0) && (i < iTargetKey->GetNumNotifyCreated()); i++)
|
||||
{
|
||||
plMessage* rcvMsg = iTargetKey->GetNotifyCreated(i);
|
||||
for (int j = 0; j < rcvMsg->GetNumReceivers(); j++)
|
||||
{
|
||||
if (&(*rcvMsg->GetReceiver(j)) == (plKeyData*)this)
|
||||
{
|
||||
isActive = iTargetKey->IsActiveRef(iTarg = i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (iTarg < 0)
|
||||
{
|
||||
// If it doesn't send me a message on destruction, I am assuming I don't have an
|
||||
// active ref on the key (seems to be always true, but should we depend on it?)
|
||||
// Since it doesn't send me a message, and won't be destroyed by the release, no
|
||||
// need to do anything more here
|
||||
return;
|
||||
}
|
||||
|
||||
// If releasing this target causes its destruction, we'll notify
|
||||
// everyone that target is dead. Otherwise, we'll remove
|
||||
// releaser from target's notify list and notify releaser
|
||||
// it's been removed. Object doesn't actually get deleted until
|
||||
// it receives the SelfDestruct msg, by which time everyone referencing
|
||||
// it has been notified it is going away.
|
||||
#ifdef LOG_ACTIVE_REFS
|
||||
if (isActive && IsTrackedKey(iTargetKey))
|
||||
hsStatusMessageF("@@@ %s(%s) releasing active ref on %s (%d total)", GetName(), plFactory::GetNameOfClass(GetUoid().GetClassType()), kObjName, iTargetKey->fNumActiveRefs-1);
|
||||
#endif // LOG_ACTIVE_REFS
|
||||
|
||||
if (isActive && iTargetKey->GetActiveRefs() && !iTargetKey->DecActiveRefs())
|
||||
{
|
||||
iTargetKey->INotifyDestroyed();
|
||||
|
||||
iTargetKey->IClearRefs();
|
||||
iTargetKey->ClearNotifyCreated();
|
||||
|
||||
plKey key = plKey::Make(iTargetKey);
|
||||
plSelfDestructMsg* nuke = TRACKED_NEW plSelfDestructMsg(key);
|
||||
plgDispatch::Dispatch()->MsgSend(nuke);
|
||||
}
|
||||
else
|
||||
{
|
||||
plRefMsg* refMsg = iTargetKey->GetNotifyCreated(iTarg);
|
||||
hsRefCnt_SafeRef(refMsg);
|
||||
iTargetKey->RemoveNotifyCreated(iTarg);
|
||||
if (refMsg)
|
||||
{
|
||||
refMsg->SetRef(iTargetKey->ObjectIsLoaded());
|
||||
refMsg->SetTimeStamp(hsTimer::GetSysSeconds());
|
||||
refMsg->SetContext(plRefMsg::kOnRemove);
|
||||
hsRefCnt_SafeRef(refMsg);
|
||||
plgDispatch::MsgSend(refMsg);
|
||||
}
|
||||
hsRefCnt_SafeUnRef(refMsg);
|
||||
}
|
||||
}
|
177
Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.h
Normal file
177
Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.h
Normal file
@ -0,0 +1,177 @@
|
||||
/*==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 plKeyImp_inc
|
||||
#define plKeyImp_inc
|
||||
|
||||
#include "plKey.h"
|
||||
#include "hsTemplates.h"
|
||||
#include "plUoid.h"
|
||||
#include "hsBitVector.h"
|
||||
#include "plRefFlags.h"
|
||||
|
||||
//------------------------------------
|
||||
// plKey is a handle to a keyedObject
|
||||
//------------------------------------
|
||||
class plKeyImp : public plKeyData
|
||||
{
|
||||
public:
|
||||
plKeyImp();
|
||||
plKeyImp(plUoid, UInt32 pos,UInt32 len);
|
||||
virtual ~plKeyImp();
|
||||
|
||||
virtual const plUoid& GetUoid() const { return fUoid; }
|
||||
virtual const char* GetName() const;
|
||||
|
||||
virtual hsKeyedObject* GetObjectPtr();
|
||||
virtual hsKeyedObject* ObjectIsLoaded() const;
|
||||
virtual hsKeyedObject* VerifyLoaded();
|
||||
|
||||
// called before writing to disk so that static keys can have faster lookups (int compare instead of string compare)
|
||||
void SetObjectID(UInt32 id) {fUoid.SetObjectID(id);}
|
||||
|
||||
//----------------------
|
||||
// I/O
|
||||
// ResMgr performs read, so it can search for an existing instance....
|
||||
//----------------------
|
||||
void Read(hsStream* s);
|
||||
void Write(hsStream* s);
|
||||
void WriteObject(hsStream* s);
|
||||
// For when you need to skip over a key in a stream
|
||||
static void SkipRead(hsStream* s);
|
||||
|
||||
UInt32 GetStartPos() const { return fStartPos; } // for ResMgr to read the Objects
|
||||
UInt32 GetDataLen() const { return fDataLen; } // for ResMgr to read the Objects
|
||||
|
||||
//----------------------
|
||||
// Allow a keyed object to behave as if it has an active ref when in fact the object
|
||||
// should only be active ref'ed by a non-keyed parent. Essentially just bumps/decs
|
||||
// the active ref count to facilitate normal object creation/destruction
|
||||
//----------------------
|
||||
virtual hsKeyedObject* RefObject(plRefFlags::Type flags = plRefFlags::kActiveRef);
|
||||
virtual void UnRefObject(plRefFlags::Type flags = plRefFlags::kActiveRef);
|
||||
|
||||
//----------------------
|
||||
// Release has two behaviors, depending on whether the ref is active or passive:
|
||||
// Active - Release decs the ActiveRefCnt. When it gets to zero, the object will be deleted.
|
||||
// Passive - Unregisters my interest in when the object is created or destroyed.
|
||||
//----------------------
|
||||
virtual void Release(plKey targetKey);
|
||||
|
||||
void UnRegister();
|
||||
void SetUoid(const plUoid& uoid);
|
||||
void SetupNotify(plRefMsg* msg, plRefFlags::Type flags);
|
||||
|
||||
// hsKeyedObject use only!
|
||||
hsKeyedObject* SetObjectPtr(hsKeyedObject* p);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// ResManager/Registry use only!
|
||||
//
|
||||
|
||||
//----------------------
|
||||
// Clone access
|
||||
//----------------------
|
||||
void AddClone(plKeyImp* c);
|
||||
void RemoveClone(plKeyImp* c) const;
|
||||
plKey GetClone(UInt32 playerID, UInt32 cloneID) const;
|
||||
void CopyForClone(const plKeyImp* p, UInt32 playerID, UInt32 cloneID); // Copy the contents of p for cloning process
|
||||
|
||||
UInt32 GetNumClones();
|
||||
plKey GetCloneByIdx(UInt32 idx);
|
||||
plKey GetCloneOwner() { return fCloneOwner; }
|
||||
|
||||
void NotifyCreated();
|
||||
void ISetupNotify(plRefMsg* msg, plRefFlags::Type flags); // Setup notifcations for reference, don't send anything.
|
||||
|
||||
void AddRef(plKeyImp* key) const;
|
||||
UInt16 GetNumRefs() const { return fRefs.GetCount(); }
|
||||
plKeyImp* GetRef(int i) const { return fRefs[i]; }
|
||||
void RemoveRef(plKeyImp *key) const;
|
||||
|
||||
virtual UInt16 GetActiveRefs() const { return fNumActiveRefs; }
|
||||
virtual UInt16 GetNumNotifyCreated() const { return fNotifyCreated.GetCount(); }
|
||||
virtual plRefMsg* GetNotifyCreated(int i) const { return fNotifyCreated[i]; }
|
||||
virtual const hsBitVector& GetActiveBits() const { return fActiveRefs; }
|
||||
|
||||
protected:
|
||||
void AddNotifyCreated(plRefMsg* msg, plRefFlags::Type flags);
|
||||
void ClearNotifyCreated();
|
||||
UInt16 GetNumNotifyCreated() { return fNotifyCreated.GetCount(); }
|
||||
plRefMsg* GetNotifyCreated(int i) { return fNotifyCreated[i]; }
|
||||
void RemoveNotifyCreated(int i);
|
||||
|
||||
UInt16 IncActiveRefs() { return ++fNumActiveRefs; }
|
||||
UInt16 DecActiveRefs() { return fNumActiveRefs ? --fNumActiveRefs : 0; }
|
||||
|
||||
hsBool IsActiveRef(int i) const { return fActiveRefs.IsBitSet(i) != 0; }
|
||||
void SetActiveRef(int i, hsBool on=true) { fActiveRefs.SetBit(i, on); }
|
||||
hsBool IsNotified(int i) const { return fNotified.IsBitSet(i) != 0; }
|
||||
void SetNotified(int i, hsBool on=true) { fNotified.SetBit(i, on); }
|
||||
|
||||
void SatisfyPending(plRefMsg* msg) const;
|
||||
void SatisfyPending() const;
|
||||
|
||||
void INotifySelf(hsKeyedObject* ko);
|
||||
void INotifyDestroyed();
|
||||
void IClearRefs();
|
||||
|
||||
void IRelease(plKeyImp* keyImp);
|
||||
|
||||
hsKeyedObject* fObjectPtr;
|
||||
|
||||
// These fields are the ones actually saved to disk
|
||||
plUoid fUoid;
|
||||
UInt32 fStartPos; // where I live in the Datafile
|
||||
UInt32 fDataLen; // Length in the Datafile
|
||||
|
||||
// Following used by hsResMgr to notify on defered load or when a passive ref is destroyed.
|
||||
UInt16 fNumActiveRefs; // num active refs on me
|
||||
hsBitVector fActiveRefs; // Which of notify created are active refs
|
||||
hsBitVector fNotified; // which of notifycreated i've already notified.
|
||||
hsTArray<plRefMsg*> fNotifyCreated; // people to notify when I'm created or destroyed
|
||||
mutable hsTArray<plKeyImp*> fRefs; // refs I've made (to be released when I'm unregistered).
|
||||
mutable Int16 fPendingRefs; // Outstanding requests I have out.
|
||||
mutable hsTArray<plKeyImp*> fClones; // clones of me
|
||||
mutable plKey fCloneOwner; // pointer for clones back to the owning key
|
||||
};
|
||||
|
||||
#endif // hsRegistry_inc
|
225
Sources/Plasma/NucleusLib/pnKeyedObject/plMsgForwarder.cpp
Normal file
225
Sources/Plasma/NucleusLib/pnKeyedObject/plMsgForwarder.cpp
Normal file
@ -0,0 +1,225 @@
|
||||
/*==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 "plMsgForwarder.h"
|
||||
#include "hsResMgr.h"
|
||||
#include "hsTypes.h"
|
||||
#include "../pnMessage/plMessage.h"
|
||||
#include "../pnKeyedObject/plKey.h"
|
||||
#include "../pnNetCommon/plNetApp.h"
|
||||
#include "../pnNetCommon/plSynchedObject.h"
|
||||
|
||||
#include "../pnMessage/plSelfDestructMsg.h"
|
||||
#include "../pnMessage/plMessageWithCallbacks.h"
|
||||
|
||||
|
||||
class plForwardCallback
|
||||
{
|
||||
public:
|
||||
hsTArray<plKey> fOrigReceivers;
|
||||
int fNumCallbacks;
|
||||
hsBool fNetPropogate;
|
||||
};
|
||||
|
||||
plMsgForwarder::plMsgForwarder()
|
||||
{
|
||||
}
|
||||
|
||||
plMsgForwarder::~plMsgForwarder()
|
||||
{
|
||||
CallbackMap::iterator i = fCallbacks.begin();
|
||||
|
||||
for (; i != fCallbacks.end(); i++)
|
||||
delete (*i).second;
|
||||
}
|
||||
|
||||
void plMsgForwarder::Read(hsStream* s, hsResMgr* mgr)
|
||||
{
|
||||
hsKeyedObject::Read(s, mgr);
|
||||
|
||||
int numKeys = s->ReadSwap32();
|
||||
fForwardKeys.Reset();
|
||||
fForwardKeys.Expand(numKeys);
|
||||
fForwardKeys.SetCount(numKeys);
|
||||
for (int i = 0; i < numKeys; i++)
|
||||
{
|
||||
plKey key = mgr->ReadKey(s);
|
||||
fForwardKeys[i] = key;
|
||||
}
|
||||
}
|
||||
|
||||
void plMsgForwarder::Write(hsStream* s, hsResMgr* mgr)
|
||||
{
|
||||
hsKeyedObject::Write(s, mgr);
|
||||
|
||||
int numKeys = fForwardKeys.Count();
|
||||
s->WriteSwap32(numKeys);
|
||||
for (int i = 0; i < numKeys; i++)
|
||||
mgr->WriteKey(s, fForwardKeys[i]);
|
||||
}
|
||||
|
||||
hsBool plMsgForwarder::MsgReceive(plMessage* msg)
|
||||
{
|
||||
// Self destruct messages are for us only
|
||||
plSelfDestructMsg *selfMsg = plSelfDestructMsg::ConvertNoRef(msg);
|
||||
if (selfMsg)
|
||||
return hsKeyedObject::MsgReceive(msg);
|
||||
|
||||
// If this is a callback message, it needs to be handled differently
|
||||
if (IForwardCallbackMsg(msg))
|
||||
return true;
|
||||
|
||||
// All other messages are forwarded
|
||||
IForwardMsg(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
hsBool plMsgForwarder::IForwardCallbackMsg(plMessage *msg)
|
||||
{
|
||||
// Only process as a callback message if it is one, AND it has callbacks
|
||||
plMessageWithCallbacks *callbackMsg = plMessageWithCallbacks::ConvertNoRef(msg);
|
||||
if (callbackMsg && callbackMsg->GetNumCallbacks() > 0)
|
||||
{
|
||||
for (int i = 0; i < callbackMsg->GetNumCallbacks(); i++)
|
||||
{
|
||||
plEventCallbackMsg *event = callbackMsg->GetEventCallback(i);
|
||||
hsAssert(event, "Message forwarder only supports event callback messages");
|
||||
if (event)
|
||||
{
|
||||
plForwardCallback *fc = TRACKED_NEW plForwardCallback;
|
||||
fc->fNumCallbacks = fForwardKeys.Count();
|
||||
|
||||
// Turn off net propagate the callbacks to us will all be local. Only the
|
||||
// callback we send will go over the net
|
||||
fc->fNetPropogate = (event->HasBCastFlag(plMessage::kNetPropagate) != 0);
|
||||
event->SetBCastFlag(plMessage::kNetPropagate, false);
|
||||
|
||||
for (int j = 0; j < event->GetNumReceivers(); j++)
|
||||
fc->fOrigReceivers.Append((plKey)event->GetReceiver(j));
|
||||
|
||||
event->ClearReceivers();
|
||||
event->AddReceiver(GetKey());
|
||||
|
||||
fCallbacks[event] = fc;
|
||||
|
||||
#if 0
|
||||
hsStatusMessageF("Adding CBMsg, eventSender=%s, eventRemoteMsg=%d\n",
|
||||
event->GetSender() ? event->GetSender()->GetName() : "nil", fc->fNetPropogate);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
hsStatusMessageF("Fwding CBMsg, sender=%s, remoteMsg=%d",
|
||||
msg->GetSender() ? msg->GetSender()->GetName() : "nil", msg->HasBCastFlag(plMessage::kNetNonLocal));
|
||||
#endif
|
||||
IForwardMsg(callbackMsg);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Callback from one of our forward keys. Don't send the final callback to the original
|
||||
// requester until all forward keys have reported in.
|
||||
plEventCallbackMsg *eventMsg = plEventCallbackMsg::ConvertNoRef(msg);
|
||||
if (eventMsg)
|
||||
{
|
||||
CallbackMap::const_iterator it = fCallbacks.find(eventMsg);
|
||||
if (it != fCallbacks.end())
|
||||
{
|
||||
plForwardCallback *fc = it->second;
|
||||
if (--fc->fNumCallbacks == 0)
|
||||
{
|
||||
hsStatusMessageF("plEventCallbackMsg received, erasing, sender=%s, remoteMsg=%d\n",
|
||||
msg->GetSender() ? msg->GetSender()->GetName() : "nil", msg->HasBCastFlag(plMessage::kNetNonLocal));
|
||||
|
||||
fCallbacks.erase(eventMsg);
|
||||
|
||||
plUoid uoid = GetKey()->GetUoid();
|
||||
hsBool locallyOwned = (plNetClientApp::GetInstance()->IsLocallyOwned(uoid) != plSynchedObject::kNo);
|
||||
|
||||
// If the callback was originally net propagated, and we own this forwarder, net propagate the callback
|
||||
if (fc->fNetPropogate && locallyOwned)
|
||||
eventMsg->SetBCastFlag(plMessage::kNetPropagate);
|
||||
|
||||
eventMsg->ClearReceivers();
|
||||
eventMsg->AddReceivers(fc->fOrigReceivers);
|
||||
eventMsg->SetSender(GetKey());
|
||||
hsRefCnt_SafeRef(eventMsg);
|
||||
eventMsg->Send();
|
||||
|
||||
delete fc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
hsStatusMessageF("! Unknown plEventCallbackMsg received, sender=%s, remoteMsg=%d\n",
|
||||
msg->GetSender() ? msg->GetSender()->GetName() : "nil", msg->HasBCastFlag(plMessage::kNetNonLocal));
|
||||
hsAssert(0, "Unknown plEventCallbackMsg received");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void plMsgForwarder::IForwardMsg(plMessage *msg)
|
||||
{
|
||||
// Back up the message's original receivers
|
||||
hsTArray<plKey> oldKeys;
|
||||
for (int i = 0; i < msg->GetNumReceivers(); i++)
|
||||
oldKeys.Append((plKey)msg->GetReceiver(i));
|
||||
|
||||
// Set to our receivers and send
|
||||
hsRefCnt_SafeRef(msg);
|
||||
msg->ClearReceivers();
|
||||
msg->AddReceivers(fForwardKeys);
|
||||
msg->Send();
|
||||
|
||||
// Reset back to the original receivers. This is so we don't screw up objects
|
||||
// who reuse their messages
|
||||
msg->ClearReceivers();
|
||||
msg->AddReceivers(oldKeys);
|
||||
}
|
||||
|
||||
void plMsgForwarder::AddForwardKey(plKey key)
|
||||
{
|
||||
if (fForwardKeys.Find(key) == fForwardKeys.kMissingIndex)
|
||||
fForwardKeys.Append(key);
|
||||
}
|
79
Sources/Plasma/NucleusLib/pnKeyedObject/plMsgForwarder.h
Normal file
79
Sources/Plasma/NucleusLib/pnKeyedObject/plMsgForwarder.h
Normal file
@ -0,0 +1,79 @@
|
||||
/*==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 plMsgForwarder_h_inc
|
||||
#define plMsgForwarder_h_inc
|
||||
|
||||
#include "hsKeyedObject.h"
|
||||
#include "hsTemplates.h"
|
||||
#include "hsStlUtils.h"
|
||||
|
||||
|
||||
class plMessageWithCallbacks;
|
||||
class plForwardCallback;
|
||||
|
||||
class plMsgForwarder : public hsKeyedObject
|
||||
{
|
||||
protected:
|
||||
hsTArray<plKey> fForwardKeys;
|
||||
|
||||
typedef std::map<plMessage*, plForwardCallback*> CallbackMap;
|
||||
CallbackMap fCallbacks;
|
||||
|
||||
void IForwardMsg(plMessage *msg);
|
||||
hsBool IForwardCallbackMsg(plMessage *msg);
|
||||
|
||||
public:
|
||||
plMsgForwarder();
|
||||
~plMsgForwarder();
|
||||
|
||||
CLASSNAME_REGISTER(plMsgForwarder);
|
||||
GETINTERFACE_ANY(plMsgForwarder, hsKeyedObject);
|
||||
|
||||
void Read(hsStream* s, hsResMgr* mgr);
|
||||
void Write(hsStream* s, hsResMgr* mgr);
|
||||
|
||||
hsBool MsgReceive(plMessage* msg);
|
||||
|
||||
void AddForwardKey(plKey key);
|
||||
};
|
||||
|
||||
#endif // plMsgForwarder_h_inc
|
61
Sources/Plasma/NucleusLib/pnKeyedObject/plReceiver.h
Normal file
61
Sources/Plasma/NucleusLib/pnKeyedObject/plReceiver.h
Normal file
@ -0,0 +1,61 @@
|
||||
/*==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 plReceiver_inc
|
||||
#define plReceiver_inc
|
||||
|
||||
#include "../pnFactory/plCreatable.h"
|
||||
|
||||
class plMessage;
|
||||
|
||||
class plReceiver : public plCreatable
|
||||
{
|
||||
public:
|
||||
plReceiver() {}
|
||||
|
||||
CLASSNAME_REGISTER( plReceiver );
|
||||
GETINTERFACE_ANY( plReceiver, plCreatable );
|
||||
|
||||
virtual hsBool MsgReceive(plMessage* msg) { return false; }
|
||||
};
|
||||
|
||||
#endif // plReceiver_inc
|
75
Sources/Plasma/NucleusLib/pnKeyedObject/plTempKey.cpp
Normal file
75
Sources/Plasma/NucleusLib/pnKeyedObject/plTempKey.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/*==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 "HeadSpin.h"
|
||||
|
||||
#include "plTempKey.h"
|
||||
#include "hsKeyedObject.h"
|
||||
#include "plUoid.h"
|
||||
|
||||
|
||||
|
||||
plTempKey::plTempKey(hsKeyedObject *pO,const char *nm)
|
||||
{
|
||||
hsAssert(pO,"plTempKey, Need Object!");
|
||||
pO->SetKey(this);
|
||||
plLocation loc( plLocation::kGlobalFixedLoc );
|
||||
fUoid = plUoid( loc, pO->ClassIndex(), "temp");
|
||||
fUoid.SetTemporary( true ); // Must set temp flag!
|
||||
|
||||
#ifdef HS_DEBUGGING
|
||||
fIDName = fUoid.GetObjectName();
|
||||
fClassType = plFactory::GetNameOfClass( fUoid.GetClassType() );
|
||||
#endif
|
||||
}
|
||||
|
||||
plTempKey::~plTempKey()
|
||||
{
|
||||
UnRegister();
|
||||
delete fObjectPtr;
|
||||
fObjectPtr = nil;
|
||||
}
|
||||
|
||||
void plTempKey::VerifyLoaded() const
|
||||
{
|
||||
// Can't do a whole lot in this case for tempKeys :)
|
||||
}
|
||||
|
67
Sources/Plasma/NucleusLib/pnKeyedObject/plTempKey.h
Normal file
67
Sources/Plasma/NucleusLib/pnKeyedObject/plTempKey.h
Normal file
@ -0,0 +1,67 @@
|
||||
/*==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 plTempKey_inc
|
||||
#define plTempKey_inc
|
||||
|
||||
#include "plKeyImp.h"
|
||||
|
||||
class hsKeyedObject;
|
||||
|
||||
//------------------------------------
|
||||
// plTempKey is a handle to a keyedObject, which is not registered
|
||||
// The key may be handed to others to send messages.
|
||||
// when done with a plTempKey call ReleaseTemporary (from Base class plKey)
|
||||
//------------------------------------
|
||||
|
||||
class plTempKey : public plKeyImp
|
||||
{
|
||||
|
||||
public:
|
||||
plTempKey(hsKeyedObject *pO,const char *nm=nil);
|
||||
plTempKey(plUoid u) { fUoid=u; } // used server side
|
||||
~plTempKey(); // USE plKey->ReleaseTemporary to delete this...
|
||||
|
||||
virtual void VerifyLoaded() const;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
284
Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp
Normal file
284
Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.cpp
Normal file
@ -0,0 +1,284 @@
|
||||
/*==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 "plUoid.h"
|
||||
#include "hsStream.h"
|
||||
#include "hsUtils.h"
|
||||
|
||||
//// plLocation //////////////////////////////////////////////////////////////
|
||||
|
||||
const plLocation plLocation::kGlobalFixedLoc(plLocation::kGlobalFixedLocIdx);
|
||||
const plLocation plLocation::kLocalStartLoc(plLocation::kLocalLocStartIdx);
|
||||
const plLocation plLocation::kLocalEndLoc(plLocation::kLocalLocEndIdx);
|
||||
const plLocation plLocation::kNormalStartLoc(plLocation::kNormalLocStartIdx);
|
||||
const plLocation plLocation::kGlobalServerLoc(plLocation::kGlobalServerLocIdx, plLocation::kReserved);
|
||||
const plLocation plLocation::kInvalidLoc;
|
||||
|
||||
plLocation::plLocation(const plLocation& toCopyFrom)
|
||||
{
|
||||
*this = toCopyFrom;
|
||||
}
|
||||
|
||||
void plLocation::Read(hsStream* s)
|
||||
{
|
||||
s->LogReadSwap(&fSequenceNumber, "Location Sequence Number");
|
||||
s->LogReadSwap(&fFlags, "Location Flags");
|
||||
}
|
||||
|
||||
void plLocation::Write(hsStream* s) const
|
||||
{
|
||||
s->WriteSwap(fSequenceNumber);
|
||||
s->WriteSwap(fFlags);
|
||||
}
|
||||
|
||||
plLocation& plLocation::operator=(const plLocation& rhs)
|
||||
{
|
||||
fSequenceNumber = rhs.fSequenceNumber;
|
||||
fFlags = rhs.fFlags;
|
||||
return *this;
|
||||
}
|
||||
|
||||
hsBool plLocation::operator==(const plLocation& u) const
|
||||
{
|
||||
// Ignore the itinerant flag when comparing, because
|
||||
return (fSequenceNumber == u.fSequenceNumber) && ((fFlags & ~kItinerant) == (u.fFlags & ~kItinerant));
|
||||
}
|
||||
|
||||
void plLocation::Set(UInt32 seqNum)
|
||||
{
|
||||
fSequenceNumber = seqNum;
|
||||
}
|
||||
|
||||
void plLocation::Invalidate()
|
||||
{
|
||||
fSequenceNumber = kInvalidLocIdx;
|
||||
fFlags = 0; // Set to kInvalid?
|
||||
}
|
||||
|
||||
hsBool plLocation::IsValid() const
|
||||
{
|
||||
return (fSequenceNumber == kInvalidLocIdx) ? false : true;
|
||||
}
|
||||
|
||||
hsBool plLocation::IsReserved() const
|
||||
{
|
||||
return hsCheckBits(fFlags, kReserved);
|
||||
}
|
||||
|
||||
hsBool plLocation::IsItinerant() const
|
||||
{
|
||||
return hsCheckBits(fFlags, kItinerant);
|
||||
}
|
||||
|
||||
hsBool plLocation::IsVirtual() const
|
||||
{
|
||||
// This returns whether the location is "virtual", i.e. isn't a true room per se. Like fixed keys
|
||||
if (fSequenceNumber == kGlobalFixedLocIdx)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// THIS SHOULD BE FOR DEBUGGING ONLY <hint hint>
|
||||
char* plLocation::StringIze(char* str) const // Format to displayable string
|
||||
{
|
||||
sprintf(str, "S0x%xF0x%x", fSequenceNumber, int(fFlags));
|
||||
return str;
|
||||
}
|
||||
|
||||
plLocation plLocation::MakeReserved(UInt32 number)
|
||||
{
|
||||
return plLocation(kReservedLocAvailableStart + number, kReserved);
|
||||
}
|
||||
|
||||
plLocation plLocation::MakeNormal(UInt32 number)
|
||||
{
|
||||
return plLocation(kNormalLocStartIdx + number);
|
||||
}
|
||||
|
||||
//// plUoid //////////////////////////////////////////////////////////////////
|
||||
|
||||
plUoid::plUoid(const plLocation& location, UInt16 classType, const char* objectName, const plLoadMask& m)
|
||||
{
|
||||
fObjectName = nil;
|
||||
Invalidate();
|
||||
|
||||
fLocation = location;
|
||||
fClassType = classType;
|
||||
fObjectName = hsStrcpy(objectName);
|
||||
fLoadMask = m;
|
||||
fClonePlayerID = 0;
|
||||
}
|
||||
|
||||
plUoid::plUoid(const plUoid& src)
|
||||
{
|
||||
fObjectName = nil;
|
||||
Invalidate();
|
||||
*this = src;
|
||||
}
|
||||
|
||||
plUoid::~plUoid()
|
||||
{
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void plUoid::Read(hsStream* s)
|
||||
{
|
||||
hsAssert(fObjectName == nil, "Reading over an old uoid? You're just asking for trouble, aren't you?");
|
||||
|
||||
// first read contents flags
|
||||
UInt8 contents = s->ReadByte();
|
||||
|
||||
fLocation.Read(s);
|
||||
|
||||
// conditional loadmask read
|
||||
if (contents & kHasLoadMask)
|
||||
fLoadMask.Read(s);
|
||||
else
|
||||
fLoadMask.SetAlways();
|
||||
|
||||
s->LogReadSwap(&fClassType, "ClassType");
|
||||
s->LogReadSwap(&fObjectID, "ObjectID");
|
||||
s->LogSubStreamPushDesc("ObjectName");
|
||||
fObjectName = s->LogReadSafeString();
|
||||
|
||||
// conditional cloneIDs read
|
||||
if (contents & kHasCloneIDs)
|
||||
{
|
||||
s->LogReadSwap( &fCloneID ,"CloneID");
|
||||
UInt16 dummy;
|
||||
s->LogReadSwap(&dummy, "dummy"); // To avoid breaking format
|
||||
s->LogReadSwap( &fClonePlayerID ,"ClonePlayerID");
|
||||
}
|
||||
else
|
||||
{
|
||||
fCloneID = 0;
|
||||
fClonePlayerID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void plUoid::Write(hsStream* s) const
|
||||
{
|
||||
// first write contents byte
|
||||
UInt8 contents = IsClone() ? kHasCloneIDs : 0;
|
||||
if (fLoadMask.IsUsed())
|
||||
contents |= kHasLoadMask;
|
||||
s->WriteByte(contents);
|
||||
|
||||
fLocation.Write(s);
|
||||
|
||||
// conditional loadmask write
|
||||
if (contents & kHasLoadMask)
|
||||
fLoadMask.Write(s);
|
||||
|
||||
s->WriteSwap( fClassType );
|
||||
s->WriteSwap( fObjectID );
|
||||
s->WriteSafeString( fObjectName );
|
||||
|
||||
// conditional cloneIDs write
|
||||
if (contents & kHasCloneIDs)
|
||||
{
|
||||
s->WriteSwap(fCloneID);
|
||||
UInt16 dummy = 0;
|
||||
s->WriteSwap(dummy); // to avoid breaking format
|
||||
s->WriteSwap(fClonePlayerID);
|
||||
}
|
||||
}
|
||||
|
||||
void plUoid::Invalidate()
|
||||
{
|
||||
fObjectID = 0;
|
||||
fCloneID = 0;
|
||||
fClonePlayerID = 0;
|
||||
fClassType = 0;
|
||||
if (fObjectName)
|
||||
delete [] fObjectName;
|
||||
fObjectName = nil;
|
||||
fLocation.Invalidate();
|
||||
fLoadMask = plLoadMask::kAlways;
|
||||
|
||||
}
|
||||
|
||||
hsBool plUoid::IsValid() const
|
||||
{
|
||||
if (!fLocation.IsValid() || fObjectName == nil)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
hsBool plUoid::operator==(const plUoid& u) const
|
||||
{
|
||||
return fLocation == u.fLocation
|
||||
&& fLoadMask == u.fLoadMask
|
||||
&& fClassType == u.fClassType
|
||||
&& hsStrEQ(fObjectName, u.fObjectName)
|
||||
&& fObjectID == u.fObjectID
|
||||
&& fCloneID == u.fCloneID
|
||||
&& fClonePlayerID == u.fClonePlayerID;
|
||||
}
|
||||
|
||||
plUoid& plUoid::operator=(const plUoid& rhs)
|
||||
{
|
||||
fObjectID = rhs.fObjectID;
|
||||
fCloneID = rhs.fCloneID;
|
||||
fClonePlayerID = rhs.fClonePlayerID;
|
||||
fClassType = rhs.fClassType;
|
||||
if (fObjectName)
|
||||
delete [] fObjectName;
|
||||
fObjectName = hsStrcpy(rhs.fObjectName);
|
||||
fLocation = rhs.fLocation;
|
||||
fLoadMask = rhs.fLoadMask;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// THIS SHOULD BE FOR DEBUGGING ONLY <hint hint>
|
||||
char* plUoid::StringIze(char* str) const // Format to displayable string
|
||||
{
|
||||
sprintf(str, "(0x%x:0x%x:%s:C:[%lu,%lu])",
|
||||
fLocation.GetSequenceNumber(),
|
||||
int(fLocation.GetFlags()),
|
||||
fObjectName,
|
||||
GetClonePlayerID(),
|
||||
GetCloneID());
|
||||
return str;
|
||||
}
|
195
Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h
Normal file
195
Sources/Plasma/NucleusLib/pnKeyedObject/plUoid.h
Normal file
@ -0,0 +1,195 @@
|
||||
/*==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==*/
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// plUoid - A Unique Object IDentifier -- basically, each unique Uoid refers
|
||||
// to one and exactly one object.
|
||||
// To define such, it contains three elements:
|
||||
// - A plLocation, which specifies an (age,chapter,page) combo
|
||||
// (as a sequence number)
|
||||
// - A creatable class type (from plFactory)
|
||||
// - An object name
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef plUoid_h_inc
|
||||
#define plUoid_h_inc
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "plFixedKey.h"
|
||||
#include "plLoadMask.h"
|
||||
|
||||
class hsStream;
|
||||
|
||||
//// plLocation //////////////////////////////////////////////////////////////
|
||||
|
||||
class plLocation
|
||||
{
|
||||
public:
|
||||
enum LocFlags
|
||||
{
|
||||
kLocalOnly = 0x1, // Set if nothing in the room saves state.
|
||||
kVolatile = 0x2, // Set is nothing in the room persists when the server exits.
|
||||
kReserved = 0x4,
|
||||
kBuiltIn = 0x8,
|
||||
kItinerant = 0x10,
|
||||
};
|
||||
|
||||
protected:
|
||||
UInt32 fSequenceNumber;
|
||||
UInt16 fFlags;
|
||||
|
||||
enum
|
||||
{
|
||||
kGlobalFixedLocIdx = 0, // Fixed keys go here, think of as "global,fixed,keys"
|
||||
kSceneViewerLocIdx = 1,
|
||||
|
||||
kLocalLocStartIdx = 3, // These are a range of #s that go to local, testing-only pages.
|
||||
kLocalLocEndIdx = 32, // You can't go over the network with any keys with these locs.
|
||||
|
||||
kNormalLocStartIdx = kLocalLocEndIdx + 1,
|
||||
|
||||
kReservedLocStart = 0xff000000, // Reserved locations are ones that aren't real game locations,
|
||||
kGlobalServerLocIdx = kReservedLocStart, // Global pool room for the server. Only the server gets this one
|
||||
|
||||
kReservedLocAvailableStart = kGlobalServerLocIdx + 1, // This is the start of the *really* available ones
|
||||
kReservedLocEnd = 0xfffffffe, // But instead act as a holding place for data
|
||||
|
||||
kInvalidLocIdx = 0xffffffff
|
||||
};
|
||||
|
||||
plLocation(UInt32 seqNum, UInt16 flags=0) : fFlags(flags) { Set(seqNum); }
|
||||
|
||||
public:
|
||||
plLocation() { Invalidate(); }
|
||||
plLocation(const plLocation& toCopyFrom);
|
||||
~plLocation() {}
|
||||
|
||||
void Invalidate();
|
||||
hsBool IsValid() const;
|
||||
hsBool IsReserved() const;
|
||||
hsBool IsItinerant() const;
|
||||
void Set(UInt32 seqNum);
|
||||
UInt32 GetSequenceNumber() const { return fSequenceNumber; }
|
||||
hsBool IsVirtual() const;
|
||||
|
||||
void SetFlags(UInt16 flags) { fFlags |= flags; }
|
||||
UInt16 GetFlags() const { return fFlags; }
|
||||
|
||||
void Read(hsStream* s);
|
||||
void Write(hsStream* s) const;
|
||||
|
||||
hsBool operator==(const plLocation& loc) const;
|
||||
hsBool operator!=(const plLocation& loc) const { return !(loc == *this); }
|
||||
plLocation& operator=(const plLocation& loc);
|
||||
bool operator<(const plLocation& loc ) const { return fSequenceNumber < loc.fSequenceNumber; }
|
||||
|
||||
// THIS SHOULD BE FOR DEBUGGING ONLY <hint hint>
|
||||
char* StringIze(char* str) const; // Format to displayable string. Returns the same string for convenience
|
||||
|
||||
static plLocation MakeReserved(UInt32 number);
|
||||
static plLocation MakeNormal(UInt32 number);
|
||||
|
||||
static const plLocation kGlobalFixedLoc;
|
||||
static const plLocation kSceneViewerLoc;
|
||||
static const plLocation kLocalStartLoc;
|
||||
static const plLocation kLocalEndLoc;
|
||||
static const plLocation kNormalStartLoc;
|
||||
static const plLocation kGlobalServerLoc;
|
||||
static const plLocation kInvalidLoc;
|
||||
};
|
||||
|
||||
//// plUoid //////////////////////////////////////////////////////////////////
|
||||
|
||||
class plUoid
|
||||
{
|
||||
public:
|
||||
plUoid() { fObjectName = nil; Invalidate(); }
|
||||
plUoid(const plLocation& location, UInt16 classType, const char* objectName, const plLoadMask& m=plLoadMask::kAlways);
|
||||
plUoid(plFixedKeyId fixedKey);
|
||||
plUoid(const plUoid& src);
|
||||
~plUoid();
|
||||
|
||||
const plLocation& GetLocation() const { return fLocation; }
|
||||
UInt16 GetClassType() const { return fClassType; }
|
||||
const char* GetObjectName() const { return fObjectName; }
|
||||
const plLoadMask& GetLoadMask() const { return fLoadMask; }
|
||||
|
||||
void Read(hsStream* s);
|
||||
void Write(hsStream* s) const;
|
||||
|
||||
void Invalidate();
|
||||
hsBool IsValid() const;
|
||||
|
||||
plUoid& operator=(const plUoid& u);
|
||||
hsBool operator==(const plUoid& u) const;
|
||||
hsBool operator!=(const plUoid& u) const { return !operator==(u); }
|
||||
|
||||
hsBool IsClone() const { return fCloneID != 0; }
|
||||
UInt32 GetClonePlayerID() const { return fClonePlayerID; }
|
||||
UInt32 GetCloneID() const { return fCloneID; }
|
||||
void SetClone(UInt32 playerID, UInt32 cloneID) { hsAssert(cloneID < 0xffff, "Clone id too high"); fCloneID = UInt16(cloneID); fClonePlayerID = playerID; }
|
||||
|
||||
UInt32 GetObjectID() const { return fObjectID; }
|
||||
// Export time only. Only plRegistryKeyList should call this.
|
||||
void SetObjectID(UInt32 id) { fObjectID = id; }
|
||||
|
||||
// THIS SHOULD BE FOR DEBUGGING ONLY <hint hint>
|
||||
char* StringIze(char* str) const; // Format to displayable string
|
||||
|
||||
protected:
|
||||
enum ContentsFlags // for read/write functions
|
||||
{
|
||||
kHasCloneIDs = 0x1,
|
||||
kHasLoadMask = 0x2,
|
||||
};
|
||||
|
||||
UInt32 fObjectID;
|
||||
UInt32 fClonePlayerID; // The ID of the player who made this clone
|
||||
UInt16 fCloneID; // The ID of this clone (unique per client)
|
||||
UInt16 fClassType;
|
||||
char* fObjectName;
|
||||
plLocation fLocation;
|
||||
plLoadMask fLoadMask;
|
||||
};
|
||||
|
||||
#endif // plUoid_h_inc
|
@ -0,0 +1,59 @@
|
||||
/*==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 pnKeyedObject_inc
|
||||
#define pnKeyedObject_inc
|
||||
|
||||
#include "../pnFactory/plCreator.h"
|
||||
|
||||
#include "hsKeyedObject.h"
|
||||
REGISTER_CREATABLE( hsKeyedObject );
|
||||
|
||||
#include "plReceiver.h"
|
||||
|
||||
REGISTER_NONCREATABLE( plReceiver );
|
||||
|
||||
#include "plMsgForwarder.h"
|
||||
REGISTER_CREATABLE(plMsgForwarder);
|
||||
|
||||
#endif // pnKeyedObject_inc
|
||||
|
Reference in New Issue
Block a user