2
3
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:
rarified
2021-05-15 12:49:46 -06:00
parent c3f4a640a3
commit 96903e8dca
4002 changed files with 159 additions and 644 deletions

View File

@ -0,0 +1,176 @@
/*==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 "plNetClientRecorder.h"
#include "hsStream.h"
#include "hsTimer.h"
#include "../plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "hsResMgr.h"
#include "plgDispatch.h"
#include "../plSDL/plSDL.h"
#include "../pnNetCommon/plNetApp.h"
#include "../plMessage/plLinkToAgeMsg.h"
#include "../plMessage/plLoadAvatarMsg.h"
#include "../pnMessage/plNotifyMsg.h"
#include "../plMessage/plAgeLoadedMsg.h"
#include "../plStatusLog/plStatusLog.h"
#include "../plFile/hsFiles.h"
plNetClientRecorder::plNetClientRecorder(TimeWrapper* timeWrapper) :
fTimeWrapper(timeWrapper)
{
}
plNetClientRecorder::~plNetClientRecorder()
{
}
double plNetClientRecorder::GetTime()
{
if (fTimeWrapper)
return fTimeWrapper->GetWrappedTime();
else
return hsTimer::GetSysSeconds();
}
void plNetClientRecorder::IMakeFilename(const char* recName, char* path)
{
strcpy(path, "Recordings" PATH_SEPARATOR_STR);
#if HS_BUILD_FOR_WIN32
CreateDirectory(path, NULL);
#endif
const char* lastDot = strrchr(recName, '.');
if (lastDot)
strncat(path, recName, lastDot-recName);
else
strcat(path, recName);
strcat(path, ".rec");
}
bool plNetClientRecorder::IsRecordableMsg(plNetMessage* msg) const
{
UInt16 idx = msg->ClassIndex();
return (
idx == CLASS_INDEX_SCOPED(plNetMsgLoadClone) ||
idx == CLASS_INDEX_SCOPED(plNetMsgSDLStateBCast) ||
idx == CLASS_INDEX_SCOPED(plNetMsgSDLState) ||
idx == CLASS_INDEX_SCOPED(plNetMsgGameMessage)
);
}
plNetClientLoggingRecorder::plNetClientLoggingRecorder(TimeWrapper* timeWrapper) :
plNetClientRecorder(timeWrapper),
fPlaybackTimeOffset(0),
fNextPlaybackTime(0),
fLog(nil),
fBetweenAges(true)
{
}
plNetClientLoggingRecorder::~plNetClientLoggingRecorder()
{
delete fLog;
fLog = nil;
}
bool plNetClientLoggingRecorder::IProcessRecordMsg(plNetMessage* msg, double secs)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
UInt16 gameMsgIdx = gameMsg->StreamInfo()->GetStreamType();
if (gameMsgIdx == CLASS_INDEX_SCOPED(plServerReplyMsg))
return false;
// Throw out any notify messages that don't involve picking (running into
// detectors and that sort of thing should be recreated automatically
// during playback)
if (gameMsgIdx == CLASS_INDEX_SCOPED(plNotifyMsg))
{
bool hasPick = false;
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg());
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
proEventData* event = notifyMsg->GetEventRecord(i);
if (event->fEventType == proEventData::kPicked)
hasPick = true;
}
hsRefCnt_SafeUnRef(notifyMsg);
if (!hasPick)
return false;
}
}
if (fPlaybackTimeOffset == 0)
fPlaybackTimeOffset = secs;
return true;
}
void plNetClientLoggingRecorder::RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs)
{
if (!linkMsg->HasBCastFlag(plMessage::kNetSent))
{
plNetMsgGameMessage netMsgWrap;
// write message (and label) to ram stream
hsRAMStream stream;
hsgResMgr::ResMgr()->WriteCreatable(&stream, linkMsg);
// put stream in net msg wrapper
netMsgWrap.StreamInfo()->CopyStream(&stream);
// netMsgWrap.StreamInfo()->SetStreamType(linkMsg->ClassIndex()); // type of game msg
RecordMsg(&netMsgWrap, secs);
}
}

View File

@ -0,0 +1,194 @@
/*==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 plNetClientRecorder_h_inc
#define plNetClientRecorder_h_inc
#include "hsTypes.h"
class hsStream;
class plNetMessage;
class plStatusLog;
class plLinkToAgeMsg;
class plAgeLoadedMsg;
class hsResMgr;
class plNetClientRecorder
{
public:
class TimeWrapper
{
public:
virtual double GetWrappedTime() = 0;
};
protected:
TimeWrapper *fTimeWrapper;
// Puts the full path to recName in path
virtual void IMakeFilename(const char* recName, char* path);
public:
plNetClientRecorder(TimeWrapper* timeWrapper);
virtual ~plNetClientRecorder();
virtual bool BeginRecording(const char* recName) = 0;;
virtual bool BeginPlayback(const char* recName) { hsAssert(false,"plNetClientRecording: Playback not supported"); return false; }
// Recording functions
virtual bool IsRecordableMsg(plNetMessage* msg) const;
virtual void RecordMsg(plNetMessage* msg, double secs) = 0;
virtual void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs) = 0;
virtual void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) = 0;
// Playback functions
double GetTime();
virtual bool IsQueueEmpty() { hsAssert(false,"plNetClientRecording: Playback not supported"); return true; }
virtual plNetMessage* GetNextMessage() { hsAssert(false,"plNetClientRecording: Playback not supported"); return nil; }
virtual double GetNextMessageTimeDelta() { hsAssert(false,"plNetClientRecording: Playback not supported"); return 0; }
};
class plNetClientLoggingRecorder : public plNetClientRecorder
{
protected:
double fPlaybackTimeOffset;
double fNextPlaybackTime;
plStatusLog* fLog;
// We don't send messages when between ages
bool fBetweenAges;
virtual void ILogMsg(plNetMessage* msg, const char* preText="") = 0;
bool IProcessRecordMsg(plNetMessage* msg, double secs);
public:
plNetClientLoggingRecorder(TimeWrapper* timeWrapper);
~plNetClientLoggingRecorder();
void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs);
virtual void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) = 0;
};
//
// Record the net client msgs to a file
//
class plNetClientStreamRecorder : public plNetClientLoggingRecorder
{
protected:
hsStream* fRecordStream;
hsResMgr* fResMgr;
plNetMessage* IGetNextMessage();
virtual bool IIsValidMsg(plNetMessage* msg);
void ILogMsg(plNetMessage* msg, const char* preText="");
public:
plNetClientStreamRecorder(TimeWrapper* timeWrapper = nil);
~plNetClientStreamRecorder();
bool BeginRecording(const char* recName);
bool BeginPlayback(const char* recName);
// Recording functions
void RecordMsg(plNetMessage* msg, double secs);
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg);
// Playback functions
void SetResMgr(hsResMgr* resmgr) { fResMgr = resmgr; }
hsResMgr* GetResMgr();
bool IsQueueEmpty();
plNetMessage* GetNextMessage();
double GetNextMessageTimeDelta();
};
class plNetClientStatsRecorder : public plNetClientLoggingRecorder
{
protected:
void ILogMsg(plNetMessage* msg, const char* preText="");
public:
plNetClientStatsRecorder(TimeWrapper* timeWrapper = nil);
~plNetClientStatsRecorder();
bool BeginRecording(const char* recName);
// Recording functions
void RecordMsg(plNetMessage* msg, double secs);
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) { };
};
class plNetClientStreamAndStatsRecorder : public plNetClientRecorder
{
protected:
plNetClientStreamRecorder* fStreamRecorder;
plNetClientStatsRecorder* fStatsRecorder;
public:
plNetClientStreamAndStatsRecorder(plNetClientStreamRecorder* streamrec, plNetClientStatsRecorder* statrec) :
plNetClientRecorder(nil),fStreamRecorder(streamrec), fStatsRecorder(statrec) {}
~plNetClientStreamAndStatsRecorder() { delete fStreamRecorder; delete fStatsRecorder; }
bool BeginRecording(const char* recName) { return fStreamRecorder->BeginRecording(recName) && fStatsRecorder->BeginRecording(recName); }
bool BeginPlayback(const char* recName) { return fStreamRecorder->BeginPlayback(recName); }
// Recording functions
bool IsRecordableMsg(plNetMessage* msg) const { return fStreamRecorder->IsRecordableMsg(msg) || fStatsRecorder->IsRecordableMsg(msg); }
void RecordMsg(plNetMessage* msg, double secs) { fStreamRecorder->RecordMsg(msg,secs); fStatsRecorder->RecordMsg(msg,secs); }
void RecordLinkMsg(plLinkToAgeMsg* linkMsg, double secs) { fStreamRecorder->RecordLinkMsg(linkMsg,secs); fStatsRecorder->RecordLinkMsg(linkMsg,secs); }
void RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg) { fStreamRecorder->RecordAgeLoadedMsg(ageLoadedMsg); fStatsRecorder->RecordAgeLoadedMsg(ageLoadedMsg); }
// Playback functions
bool IsQueueEmpty() { return fStreamRecorder->IsQueueEmpty(); }
plNetMessage* GetNextMessage() { return fStreamRecorder->GetNextMessage(); }
double GetNextMessageTimeDelta() { return fStreamRecorder->GetNextMessageTimeDelta(); }
};
class plNetClientStressStreamRecorder : public plNetClientStreamRecorder
{
public:
plNetClientStressStreamRecorder(TimeWrapper* timeWrapper = nil) : plNetClientStreamRecorder(timeWrapper) {}
bool IsRecordableMsg(plNetMessage* msg) const;
};
#endif // plNetClientRecorder_h_inc

View File

@ -0,0 +1,160 @@
/*==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 "plNetClientRecorder.h"
#include "hsStream.h"
#include "../plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "plgDispatch.h"
#include "../plSDL/plSDL.h"
#include "../pnNetCommon/plNetApp.h"
#include "../plMessage/plLinkToAgeMsg.h"
#include "../plMessage/plLoadAvatarMsg.h"
#include "../plMessage/plLinkToAgeMsg.h"
#include "../pnMessage/plNotifyMsg.h"
#include "../plMessage/plAgeLoadedMsg.h"
#include "../plStatusLog/plStatusLog.h"
plNetClientStatsRecorder::plNetClientStatsRecorder(TimeWrapper* timeWrapper) :
plNetClientLoggingRecorder(timeWrapper)
{
if (fLog)
delete fLog;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog(30, "StatsRecorder.log", plStatusLog::kAlignToTop);
}
plNetClientStatsRecorder::~plNetClientStatsRecorder()
{
}
bool plNetClientStatsRecorder::BeginRecording(const char* recName)
{
return true;
}
void plNetClientStatsRecorder::RecordMsg(plNetMessage* msg, double secs)
{
if (IProcessRecordMsg(msg,secs))
{
char stats[256];
sprintf(stats,"tm:%4.2f;sz:%u,plrid:%s%u : ",secs,msg->GetPackSize(),msg->GetHasPlayerID()?"":"XX",msg->GetHasPlayerID()?msg->GetPlayerID():0);
// GetPackSize might compress the buffer on us, so uncompress it
plNetMsgStreamedObject* so = plNetMsgStreamedObject::ConvertNoRef(msg);
if (so)
so->StreamInfo()->Uncompress();
ILogMsg(msg,stats);
}
}
void plNetClientStatsRecorder::ILogMsg(plNetMessage* msg, const char* preText)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), plFactory::GetNameOfClass(gameMsg->StreamInfo()->GetStreamType()));
if (gameMsg->StreamInfo()->GetStreamType() == CLASS_INDEX_SCOPED(plNotifyMsg))
{
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg());
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
const char* eventName = "";
proEventData* event = notifyMsg->GetEventRecord(i);
switch (event->fEventType)
{
case proEventData::kCollision: eventName = "Collision"; break;
case proEventData::kPicked: eventName = "Picked"; break;
case proEventData::kControlKey: eventName = "ControlKey"; break;
case proEventData::kVariable: eventName = "Variable"; break;
case proEventData::kFacing: eventName = "Facing"; break;
case proEventData::kContained: eventName = "Contained"; break;
case proEventData::kActivate: eventName = "Activate"; break;
case proEventData::kCallback: eventName = "Callback"; break;
case proEventData::kResponderState: eventName = "ResponderState"; break;
case proEventData::kMultiStage: eventName = "MultiStage"; break;
case proEventData::kSpawned: eventName = "Spawned"; break;
case proEventData::kClickDrag: eventName = "ClickDrag"; break;
}
fLog->AddLineF("\t%s", eventName);
}
hsRefCnt_SafeUnRef(notifyMsg);
}
}
else if (plNetMsgSDLState* sdlMsg = plNetMsgSDLState::ConvertNoRef(msg))
{
hsReadOnlyStream stream(sdlMsg->StreamInfo()->GetStreamLen(), sdlMsg->StreamInfo()->GetStreamBuf());
char* descName=nil;
int ver;
if (plStateDataRecord::ReadStreamHeader(&stream, &descName, &ver))
{
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), descName);
int i;
plStateDataRecord sdRec(descName, ver);
sdRec.Read(&stream, 0);
plStateDataRecord::SimpleVarsList vars;
sdRec.GetDirtyVars(&vars);
for (i = 0; i < vars.size(); i++)
{
fLog->AddLineF("\t%s", vars[i]->GetVarDescriptor()->GetName());
}
plStateDataRecord::SDVarsList sdVars;
sdRec.GetDirtySDVars(&sdVars);
for (i = 0; i < sdVars.size(); i++)
{
fLog->AddLineF("\t%s", sdVars[i]->GetSDVarDescriptor()->GetName());
}
}
delete [] descName;
}
else
fLog->AddLineF("%s%s", preText, msg->ClassName());
}

View File

@ -0,0 +1,378 @@
/*==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 "plNetClientRecorder.h"
#include "hsStream.h"
#include "../plNetMessage/plNetMessage.h"
#include "plCreatableIndex.h"
#include "hsResMgr.h"
#include "plgDispatch.h"
#include "../plSDL/plSDL.h"
#include "../pnNetCommon/plNetApp.h"
#include "../plMessage/plLinkToAgeMsg.h"
#include "../plMessage/plLoadAvatarMsg.h"
#include "../plMessage/plLinkToAgeMsg.h"
#include "../pnMessage/plNotifyMsg.h"
#include "../plMessage/plAgeLoadedMsg.h"
#include "../plStatusLog/plStatusLog.h"
plNetClientStreamRecorder::plNetClientStreamRecorder(TimeWrapper* timeWrapper) :
plNetClientLoggingRecorder(timeWrapper),
fRecordStream(nil),
fResMgr(nil)
{
if (fLog)
delete fLog;
fLog = plStatusLogMgr::GetInstance().CreateStatusLog(30, "StreamRecorder.log", plStatusLog::kAlignToTop);
}
plNetClientStreamRecorder::~plNetClientStreamRecorder()
{
if (fRecordStream)
{
fRecordStream->Close();
delete fRecordStream;
}
}
hsResMgr* plNetClientStreamRecorder::GetResMgr()
{
if (fResMgr)
return fResMgr;
else
return hsgResMgr::ResMgr();
}
double plNetClientStreamRecorder::GetNextMessageTimeDelta()
{
return fNextPlaybackTime - (GetTime() - fPlaybackTimeOffset);
}
enum NetClientRecFlags
{
kNetClientRecSDLDesc,
};
bool plNetClientStreamRecorder::BeginRecording(const char* recName)
{
if (!fRecordStream)
{
fRecordStream = TRACKED_NEW hsUNIXStream;
char path[256];
IMakeFilename(recName, path);
if (!fRecordStream->Open(path, "wb"))
{
delete fRecordStream;
return false;
}
hsBitVector contentFlags;
contentFlags.SetBit(kNetClientRecSDLDesc);
contentFlags.Write(fRecordStream);
// kNetClientRecSDLDesc
plSDLMgr::GetInstance()->Write(fRecordStream);
return true;
}
return false;
}
bool plNetClientStreamRecorder::BeginPlayback(const char* recName)
{
if (!fRecordStream)
{
fRecordStream = TRACKED_NEW hsUNIXStream;
char path[256];
IMakeFilename(recName, path);
if (fRecordStream->Open(path, "rb"))
{
hsBitVector contentFlags;
contentFlags.Read(fRecordStream);
if (contentFlags.IsBitSet(kNetClientRecSDLDesc))
plSDLMgr::GetInstance()->Read(fRecordStream);
fPlaybackTimeOffset = GetTime();
fNextPlaybackTime = fRecordStream->ReadSwapDouble();
fBetweenAges = false;
}
else
{
delete fRecordStream;
fRecordStream = nil;
return false;
}
return true;
}
return false;
}
void plNetClientStreamRecorder::RecordMsg(plNetMessage* msg, double secs)
{
if (!fRecordStream)
return;
if (IProcessRecordMsg(msg,secs))
{
fRecordStream->WriteSwapDouble(secs - fPlaybackTimeOffset);
GetResMgr()->WriteCreatableVersion(fRecordStream, msg);
ILogMsg(msg);
}
}
void plNetClientStreamRecorder::RecordAgeLoadedMsg(plAgeLoadedMsg* ageLoadedMsg)
{
fLog->AddLineF("Age %s", ageLoadedMsg->fLoaded ? "Loaded" : "Unloaded");
if (ageLoadedMsg->fLoaded)
{
fBetweenAges = false;
fPlaybackTimeOffset = GetTime();
}
else
{
fBetweenAges = true;
}
}
bool plNetClientStreamRecorder::IsQueueEmpty()
{
return (fRecordStream == nil);
}
plNetMessage* plNetClientStreamRecorder::GetNextMessage()
{
plNetMessage* msg = nil;
while (!fBetweenAges && (msg = IGetNextMessage()))
{
if (IIsValidMsg(msg))
return msg;
else
hsRefCnt_SafeUnRef(msg);
}
return nil;
}
plNetMessage* plNetClientStreamRecorder::IGetNextMessage()
{
plNetMessage* msg = nil;
if (!IsQueueEmpty() && GetNextMessageTimeDelta() <= 0 )
{
msg = plNetMessage::ConvertNoRef(GetResMgr()->ReadCreatableVersion(fRecordStream));
// msg->SetPeeked(true);
// Fix the flags on game messages, so we won't get an assert later
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
if (gameMsg)
{
plMessage* plMsg = gameMsg->GetContainedMsg(GetResMgr());
plNetClientApp::GetInstance()->UnInheritNetMsgFlags(plMsg);
// write message (and label) to ram stream
hsRAMStream stream;
GetResMgr()->WriteCreatable(&stream, plMsg);
// put stream in net msg wrapper
gameMsg->StreamInfo()->CopyStream(&stream);
// gameMsg->StreamInfo()->SetStreamType(plMsg->ClassIndex()); // type of game msg
}
double nextPlaybackTime = fRecordStream->ReadSwapDouble();
if (nextPlaybackTime < fNextPlaybackTime)
fBetweenAges = true;
fNextPlaybackTime = nextPlaybackTime;
// If this was the last message, stop playing back
if (fRecordStream->AtEnd())
{
fRecordStream->Close();
delete fRecordStream;
fRecordStream = nil;
}
}
return msg;
}
bool plNetClientStreamRecorder::IIsValidMsg(plNetMessage* msg)
{
if (plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg))
{
Int16 type = gameMsg->StreamInfo()->GetStreamType();
//
// These messages will be regenerated if they are for the local avatar,
// so don't dispatch them in that case.
//
if (type == CLASS_INDEX_SCOPED(plLinkEffectsTriggerMsg))
{
plLinkEffectsTriggerMsg* linkMsg = plLinkEffectsTriggerMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
if (plNetClientApp::GetInstance())
{
bool isLocal = (linkMsg->GetLinkKey() == plNetClientApp::GetInstance()->GetLocalPlayerKey());
hsRefCnt_SafeUnRef(linkMsg);
if (isLocal)
{
ILogMsg(msg, "IGNORING ");
return false;
}
}
}
else if (type == CLASS_INDEX_SCOPED(plLoadAvatarMsg))
{
plLoadAvatarMsg* loadAvMsg = plLoadAvatarMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
if (plNetClientApp::GetInstance())
{
bool isLocal = (loadAvMsg->GetCloneKey() == plNetClientApp::GetInstance()->GetLocalPlayerKey());
hsRefCnt_SafeUnRef(loadAvMsg);
if (isLocal)
{
ILogMsg(msg, "IGNORING ");
return false;
}
}
}
}
ILogMsg(msg);
return true;
}
void plNetClientStreamRecorder::ILogMsg(plNetMessage* msg, const char* preText)
{
if (msg->ClassIndex() == CLASS_INDEX_SCOPED(plNetMsgGameMessage))
{
plNetMsgGameMessage* gameMsg = plNetMsgGameMessage::ConvertNoRef(msg);
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), plFactory::GetNameOfClass(gameMsg->StreamInfo()->GetStreamType()));
if (gameMsg->StreamInfo()->GetStreamType() == CLASS_INDEX_SCOPED(plNotifyMsg))
{
plNotifyMsg* notifyMsg = plNotifyMsg::ConvertNoRef(gameMsg->GetContainedMsg(GetResMgr()));
int numEvents = notifyMsg->GetEventCount();
for (int i = 0; i < numEvents; i++)
{
const char* eventName = "";
proEventData* event = notifyMsg->GetEventRecord(i);
switch (event->fEventType)
{
case proEventData::kCollision: eventName = "Collision"; break;
case proEventData::kPicked: eventName = "Picked"; break;
case proEventData::kControlKey: eventName = "ControlKey"; break;
case proEventData::kVariable: eventName = "Variable"; break;
case proEventData::kFacing: eventName = "Facing"; break;
case proEventData::kContained: eventName = "Contained"; break;
case proEventData::kActivate: eventName = "Activate"; break;
case proEventData::kCallback: eventName = "Callback"; break;
case proEventData::kResponderState: eventName = "ResponderState"; break;
case proEventData::kMultiStage: eventName = "MultiStage"; break;
case proEventData::kSpawned: eventName = "Spawned"; break;
case proEventData::kClickDrag: eventName = "ClickDrag"; break;
}
fLog->AddLineF("\t%s", eventName);
}
hsRefCnt_SafeUnRef(notifyMsg);
}
}
else if (plNetMsgSDLState* sdlMsg = plNetMsgSDLState::ConvertNoRef(msg))
{
hsReadOnlyStream stream(sdlMsg->StreamInfo()->GetStreamLen(), sdlMsg->StreamInfo()->GetStreamBuf());
char* descName=nil;
int ver;
if (plStateDataRecord::ReadStreamHeader(&stream, &descName, &ver))
{
fLog->AddLineF("%s%s(%s)", preText, msg->ClassName(), descName);
int i;
plStateDataRecord sdRec(descName, ver);
sdRec.Read(&stream, 0);
plStateDataRecord::SimpleVarsList vars;
sdRec.GetDirtyVars(&vars);
for (i = 0; i < vars.size(); i++)
{
fLog->AddLineF("\t%s", vars[i]->GetVarDescriptor()->GetName());
}
plStateDataRecord::SDVarsList sdVars;
sdRec.GetDirtySDVars(&sdVars);
for (i = 0; i < sdVars.size(); i++)
{
fLog->AddLineF("\t%s", sdVars[i]->GetSDVarDescriptor()->GetName());
}
}
delete [] descName;
}
else
fLog->AddLineF("%s%s", preText, msg->ClassName());
}
bool plNetClientStressStreamRecorder::IsRecordableMsg(plNetMessage* msg) const
{
UInt16 idx = msg->ClassIndex();
return (
plNetClientStreamRecorder::IsRecordableMsg(msg)
|| idx == CLASS_INDEX_SCOPED(plNetMsgTestAndSet)
|| idx == CLASS_INDEX_SCOPED(plNetMsgGameMessageDirected)
|| idx == CLASS_INDEX_SCOPED(plNetMsgVoice)
);
}