mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 19:29:09 +00:00
Python file names and SynchedObj SDL state names => plString
This commit is contained in:
@ -443,7 +443,7 @@ void cyMisc::DetachObjectSO(pySceneObject& cobj, pySceneObject& pobj, bool netFo
|
||||
//
|
||||
// PURPOSE : set the Python modifier to be dirty and asked to be saved out
|
||||
//
|
||||
void cyMisc::SetDirtySyncState(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags)
|
||||
void cyMisc::SetDirtySyncState(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags)
|
||||
{
|
||||
selfkey.DirtySynchState(SDLStateName, sendFlags);
|
||||
}
|
||||
@ -455,7 +455,7 @@ void cyMisc::SetDirtySyncState(pyKey &selfkey, const char* SDLStateName, uint32_
|
||||
//
|
||||
// PURPOSE : set the Python modifier to be dirty and asked to be saved out
|
||||
//
|
||||
void cyMisc::SetDirtySyncStateWithClients(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags)
|
||||
void cyMisc::SetDirtySyncStateWithClients(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags)
|
||||
{
|
||||
selfkey.DirtySynchState(SDLStateName, sendFlags|plSynchedObject::kBCastToClients);
|
||||
}
|
||||
|
@ -217,7 +217,7 @@ public:
|
||||
//
|
||||
// PURPOSE : set the Python modifier to be dirty and asked to be saved out
|
||||
//
|
||||
static void SetDirtySyncState(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags);
|
||||
static void SetDirtySyncState(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
@ -227,7 +227,7 @@ public:
|
||||
// PURPOSE : set the Python modifier to be dirty and asked to be saved out
|
||||
// specifies that state should be sent to other clients as well as server
|
||||
//
|
||||
static void SetDirtySyncStateWithClients(pyKey &selfkey, const char* SDLStateName, uint32_t sendFlags);
|
||||
static void SetDirtySyncStateWithClients(pyKey &selfkey, const plString& SDLStateName, uint32_t sendFlags);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -336,7 +336,6 @@ bool plPythonFileMod::fAtConvertTime = false;
|
||||
//
|
||||
plPythonFileMod::plPythonFileMod()
|
||||
{
|
||||
fPythonFile = nil;
|
||||
fModule = nil;
|
||||
fLocalNotify= true;
|
||||
fIsFirstTimeEval = true;
|
||||
@ -401,12 +400,6 @@ plPythonFileMod::~plPythonFileMod()
|
||||
fSelfKey = nil;
|
||||
}
|
||||
|
||||
// get rid of the python code
|
||||
if ( fPythonFile )
|
||||
{
|
||||
delete [] fPythonFile;
|
||||
fPythonFile = nil;
|
||||
}
|
||||
// then get rid of this module
|
||||
// NOTE: fModule shouldn't be made in the plugin, only at runtime
|
||||
if ( !fModuleName.IsNull() && fModule )
|
||||
@ -438,14 +431,14 @@ bool plPythonFileMod::ILoadPythonCode()
|
||||
#ifndef PLASMA_EXTERNAL_RELEASE
|
||||
// get code from file and execute in module
|
||||
// see if the file exists first before trying to import it
|
||||
plFileName pyfile = plFileName::Join(".", "python", plString::Format("%s.py", fPythonFile));
|
||||
plFileName pyfile = plFileName::Join(".", "python", plString::Format("%s.py", fPythonFile.c_str()));
|
||||
if (plFileInfo(pyfile).Exists())
|
||||
{
|
||||
char fromLoad[256];
|
||||
//sprintf(fromLoad,"from %s import *", fPythonFile);
|
||||
//sprintf(fromLoad,"from %s import *", fPythonFile.c_str());
|
||||
// ok... we can't really use import because Python remembers too much where global variables came from
|
||||
// ...and using execfile make it sure that globals are defined in this module and not in the imported module
|
||||
sprintf(fromLoad,"execfile('.\\\\python\\\\%s.py')", fPythonFile);
|
||||
sprintf(fromLoad,"execfile('.\\\\python\\\\%s.py')", fPythonFile.c_str());
|
||||
if ( PythonInterface::RunString( fromLoad, fModule) )
|
||||
{
|
||||
// we've loaded the code into our module
|
||||
@ -461,7 +454,7 @@ bool plPythonFileMod::ILoadPythonCode()
|
||||
}
|
||||
DisplayPythonOutput();
|
||||
char errMsg[256];
|
||||
sprintf(errMsg,"Python file %s.py had errors!!! Could not load.",fPythonFile);
|
||||
snprintf(errMsg, arrsize(errMsg), "Python file %s.py had errors!!! Could not load.", fPythonFile.c_str());
|
||||
PythonInterface::WriteToLog(errMsg);
|
||||
hsAssert(0,errMsg);
|
||||
return false;
|
||||
@ -476,7 +469,7 @@ bool plPythonFileMod::ILoadPythonCode()
|
||||
|
||||
DisplayPythonOutput();
|
||||
char errMsg[256];
|
||||
sprintf(errMsg,"Python file %s.py was not found.",fPythonFile);
|
||||
snprintf(errMsg, arrsize(errMsg), "Python file %s.py was not found.", fPythonFile.c_str());
|
||||
PythonInterface::WriteToLog(errMsg);
|
||||
hsAssert(0,errMsg);
|
||||
return false;
|
||||
@ -503,7 +496,7 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj)
|
||||
if ( !fAtConvertTime ) // if this is just an Add that's during a convert, then don't do anymore
|
||||
{
|
||||
// was there a python file module with this?
|
||||
if ( fPythonFile )
|
||||
if ( !fPythonFile.IsEmpty() )
|
||||
{
|
||||
// has the module not been initialized yet
|
||||
if ( !fModule )
|
||||
@ -523,7 +516,7 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj)
|
||||
|
||||
// set the name of the file (in the global dictionary of the module)
|
||||
PyObject* dict = PyModule_GetDict(fModule);
|
||||
PyObject* pfilename = PyString_FromString(fPythonFile);
|
||||
PyObject* pfilename = PyString_FromPlString(fPythonFile);
|
||||
PyDict_SetItemString(dict, "glue_name", pfilename);
|
||||
// next we need to:
|
||||
// - create instance of class
|
||||
@ -542,7 +535,7 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj)
|
||||
{
|
||||
// display any output (NOTE: this would be disabled in production)
|
||||
char errMsg[256];
|
||||
sprintf(errMsg,"Python file %s.py, instance not found.",fPythonFile);
|
||||
snprintf(errMsg, arrsize(errMsg), "Python file %s.py, instance not found.", fPythonFile.c_str());
|
||||
PythonInterface::WriteToLog(errMsg);
|
||||
hsAssert(0, errMsg);
|
||||
return; // if we can't create the instance then there is nothing to do here
|
||||
@ -2933,10 +2926,9 @@ void plPythonFileMod::DisplayPythonOutput()
|
||||
// : Compile it into a Python code object
|
||||
// : (This is usually called by the component)
|
||||
//
|
||||
void plPythonFileMod::SetSourceFile(const char* filename)
|
||||
void plPythonFileMod::SetSourceFile(const plString& filename)
|
||||
{
|
||||
delete [] fPythonFile;
|
||||
fPythonFile = hsStrcpy(filename);
|
||||
fPythonFile = filename;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@ -2996,13 +2988,7 @@ void plPythonFileMod::Read(hsStream* stream, hsResMgr* mgr)
|
||||
plMultiModifier::Read(stream, mgr);
|
||||
|
||||
// read in the compile python code (pyc)
|
||||
if ( fPythonFile )
|
||||
{
|
||||
// if we already have some code, get rid of it!
|
||||
delete [] fPythonFile;
|
||||
fPythonFile = nil;
|
||||
}
|
||||
fPythonFile = stream->ReadSafeString();
|
||||
fPythonFile = stream->ReadSafeString_TEMP();
|
||||
|
||||
// then read in the list of receivers that want to be notified
|
||||
int nRcvs = stream->ReadLE32();
|
||||
|
@ -73,7 +73,7 @@ protected:
|
||||
|
||||
plString IMakeModuleName(plSceneObject* sobj);
|
||||
|
||||
char* fPythonFile;
|
||||
plString fPythonFile;
|
||||
plString fModuleName;
|
||||
|
||||
// the list of receivers that want to be notified
|
||||
@ -131,7 +131,7 @@ public:
|
||||
plPythonSDLModifier* GetSDLMod() { return fSDLMod; }
|
||||
bool WasLocalNotify() { return fLocalNotify; }
|
||||
plPipeline* GetPipeline() { return fPipe; }
|
||||
virtual void SetSourceFile(const char* filename);
|
||||
virtual void SetSourceFile(const plString& filename);
|
||||
virtual int getPythonOutput(std::string* line);
|
||||
virtual void ReportError();
|
||||
virtual void DisplayPythonOutput();
|
||||
|
@ -68,7 +68,7 @@ protected:
|
||||
std::vector<hsStream*> fPackStreams;
|
||||
bool fPackNotFound; // No pack file, don't keep trying
|
||||
|
||||
typedef std::map<std::string, plPackOffsetInfo> FileOffset;
|
||||
typedef std::map<plString, plPackOffsetInfo> FileOffset;
|
||||
FileOffset fFileOffsets;
|
||||
|
||||
plPythonPack();
|
||||
@ -81,16 +81,16 @@ public:
|
||||
bool Open();
|
||||
void Close();
|
||||
|
||||
PyObject* OpenPacked(const char *fileName);
|
||||
bool IsPackedFile(const char* fileName);
|
||||
PyObject* OpenPacked(const plString& sfileName);
|
||||
bool IsPackedFile(const plString& fileName);
|
||||
};
|
||||
|
||||
PyObject* PythonPack::OpenPythonPacked(const char* fileName)
|
||||
PyObject* PythonPack::OpenPythonPacked(const plString& fileName)
|
||||
{
|
||||
return plPythonPack::Instance().OpenPacked(fileName);
|
||||
}
|
||||
|
||||
bool PythonPack::IsItPythonPacked(const char* fileName)
|
||||
bool PythonPack::IsItPythonPacked(const plString& fileName)
|
||||
{
|
||||
return plPythonPack::Instance().IsPackedFile(fileName);
|
||||
}
|
||||
@ -148,9 +148,7 @@ bool plPythonPack::Open()
|
||||
for (int i = 0; i < numFiles; i++)
|
||||
{
|
||||
// and pack the index into our own data structure
|
||||
char* buf = fPackStream->ReadSafeString();
|
||||
std::string pythonName = buf; // reading a "string" from a hsStream directly into a stl string causes memory loss
|
||||
delete [] buf;
|
||||
plString pythonName = fPackStream->ReadSafeString_TEMP();
|
||||
uint32_t offset = fPackStream->ReadLE32();
|
||||
|
||||
plPackOffsetInfo offsetInfo;
|
||||
@ -191,13 +189,12 @@ void plPythonPack::Close()
|
||||
fFileOffsets.clear();
|
||||
}
|
||||
|
||||
PyObject* plPythonPack::OpenPacked(const char* fileName)
|
||||
PyObject* plPythonPack::OpenPacked(const plString& fileName)
|
||||
{
|
||||
if (!Open())
|
||||
return nil;
|
||||
|
||||
std::string pythonName = fileName;
|
||||
pythonName += ".py";
|
||||
plString pythonName = fileName + ".py";
|
||||
|
||||
FileOffset::iterator it = fFileOffsets.find(pythonName);
|
||||
if (it != fFileOffsets.end())
|
||||
@ -213,7 +210,7 @@ PyObject* plPythonPack::OpenPacked(const char* fileName)
|
||||
char *buf = new char[size];
|
||||
uint32_t readSize = fPackStream->Read(size, buf);
|
||||
hsAssert(readSize <= size, plString::Format("Python PackFile %s: Incorrect amount of data, read %d instead of %d",
|
||||
fileName, readSize, size).c_str());
|
||||
fileName.c_str(), readSize, size).c_str());
|
||||
|
||||
// let the python marshal make it back into a code object
|
||||
PyObject *pythonCode = PyMarshal_ReadObjectFromString(buf, size);
|
||||
@ -227,13 +224,12 @@ PyObject* plPythonPack::OpenPacked(const char* fileName)
|
||||
return nil;
|
||||
}
|
||||
|
||||
bool plPythonPack::IsPackedFile(const char* fileName)
|
||||
bool plPythonPack::IsPackedFile(const plString& fileName)
|
||||
{
|
||||
if (!Open())
|
||||
return nil;
|
||||
|
||||
std::string pythonName = fileName;
|
||||
pythonName += ".py";
|
||||
plString pythonName = fileName + ".py";
|
||||
|
||||
FileOffset:: iterator it = fFileOffsets.find(pythonName);
|
||||
if (it != fFileOffsets.end())
|
||||
|
@ -43,11 +43,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#define plPythonPack_h_inc
|
||||
|
||||
typedef struct _object PyObject;
|
||||
class plString;
|
||||
|
||||
namespace PythonPack
|
||||
{
|
||||
PyObject* OpenPythonPacked(const char* fileName);
|
||||
bool IsItPythonPacked(const char* fileName);
|
||||
PyObject* OpenPythonPacked(const plString& fileName);
|
||||
bool IsItPythonPacked(const plString& fileName);
|
||||
}
|
||||
|
||||
#endif // plPythonPack_h_inc
|
||||
|
@ -265,7 +265,9 @@ void plPythonSDLModifier::SetItemIdx(const plString& key, int idx, PyObject* val
|
||||
|
||||
const char* plPythonSDLModifier::GetSDLName() const
|
||||
{
|
||||
return fOwner->fPythonFile;
|
||||
// NOTE: Not changing GetSDLName since most implementations of this
|
||||
// virtual function just return a stored string literal.
|
||||
return fOwner->fPythonFile.c_str();
|
||||
}
|
||||
|
||||
void plPythonSDLModifier::SetFlags(const plString& name, bool sendImmediate, bool skipOwnershipCheck)
|
||||
@ -566,7 +568,7 @@ PyObject* plPythonSDLModifier::ISDLVarToPython(plSimpleStateVariable* var)
|
||||
return pyTuple;
|
||||
}
|
||||
|
||||
bool plPythonSDLModifier::HasSDL(const char* pythonFile)
|
||||
bool plPythonSDLModifier::HasSDL(const plString& pythonFile)
|
||||
{
|
||||
return (plSDLMgr::GetInstance()->FindDescriptor(pythonFile, plSDL::kLatestVersion) != nil);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ public:
|
||||
virtual const char* GetSDLName() const;
|
||||
virtual void SetItemFromSDLVar(plSimpleStateVariable* var);
|
||||
|
||||
static bool HasSDL(const char* pythonFile);
|
||||
static bool HasSDL(const plString& pythonFile);
|
||||
// find the Age global SDL guy... if there is one
|
||||
static const plPythonSDLModifier* FindAgeSDL();
|
||||
static plKey FindAgeSDLTarget();
|
||||
|
@ -206,7 +206,7 @@ plKey pyKey::GetNotifyListItem(int32_t i)
|
||||
|
||||
|
||||
// Set the dirty state on the PythonModifier
|
||||
void pyKey::DirtySynchState(const char* SDLStateName, uint32_t sendFlags)
|
||||
void pyKey::DirtySynchState(const plString& SDLStateName, uint32_t sendFlags)
|
||||
{
|
||||
// see if we have a PythonFileModifier pointer
|
||||
if ( fPyFileMod )
|
||||
|
@ -123,7 +123,7 @@ public:
|
||||
// get a notify list item
|
||||
virtual plKey GetNotifyListItem(int32_t i);
|
||||
// Set the dirty state on the PythonModifier
|
||||
virtual void DirtySynchState(const char* SDLStateName, uint32_t sendFlags);
|
||||
virtual void DirtySynchState(const plString& SDLStateName, uint32_t sendFlags);
|
||||
|
||||
// register and unregister for control key envents
|
||||
virtual void EnableControlKeyEvents();
|
||||
|
Reference in New Issue
Block a user