2
3
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-14 10:37:41 -04:00

Convert plUoid's object name to a plString

This commit is contained in:
2012-01-28 16:24:20 -08:00
parent 442a733fbb
commit e34414889f
122 changed files with 810 additions and 842 deletions

View File

@ -194,12 +194,12 @@ void cyMisc::ConsoleNet(const char* command, hsBool netForce)
// PURPOSE : Execute a console command from a python script,
// optionally propagate over the net
//
PyObject* cyMisc::FindSceneObject(const char* name, const char* ageName)
PyObject* cyMisc::FindSceneObject(const plString& name, const char* ageName)
{
// assume that we won't find the sceneobject (key is equal to nil)
plKey key=nil;
if ( name || name[0] != 0)
if ( !name.IsEmpty() )
{
const char* theAge = ageName;
if ( ageName[0] == 0 )
@ -209,18 +209,17 @@ PyObject* cyMisc::FindSceneObject(const char* name, const char* ageName)
if ( key == nil )
{
char errmsg[256];
sprintf(errmsg,"Sceneobject %s not found",name);
PyErr_SetString(PyExc_NameError, errmsg);
plString errmsg = plString::Format("Sceneobject %s not found",name.c_str());
PyErr_SetString(PyExc_NameError, errmsg.c_str());
return nil; // return nil cause we errored
}
return pySceneObject::New(key);
}
PyObject* cyMisc::FindActivator(const char* name)
PyObject* cyMisc::FindActivator(const plString& name)
{
plKey key = nil;
if (name && strlen(name) > 0)
if (!name.IsEmpty())
{
std::vector<plKey> keylist;
plKeyFinder::Instance().ReallyStupidActivatorSearch(name, keylist);
@ -453,9 +452,9 @@ hsBool cyMisc::WasLocallyNotified(pyKey &selfkey)
// PURPOSE : Return the net client (account) name of the player whose avatar
// key is provided.
//
const char* cyMisc::GetClientName(pyKey &avKey)
plString cyMisc::GetClientName(pyKey &avKey)
{
return plNetClientMgr::GetInstance()->GetPlayerName(avKey.getKey()).s_str();
return plNetClientMgr::GetInstance()->GetPlayerName(avKey.getKey());
}
PyObject* cyMisc::GetAvatarKeyFromClientID(int clientID)
@ -546,9 +545,9 @@ hsBool cyMisc::ValidateKey(pyKey& key)
//
// PURPOSE : Return the local net client (account) name
//
const char* cyMisc::GetLocalClientName()
plString cyMisc::GetLocalClientName()
{
return plNetClientMgr::GetInstance()->GetPlayerName().c_str();
return plNetClientMgr::GetInstance()->GetPlayerName();
}
@ -1910,7 +1909,7 @@ int cyMisc::GetNumParticles(pyKey& host)
}
void cyMisc::SetLightColorValue(pyKey& light, std::string lightName, hsScalar r, hsScalar g, hsScalar b, hsScalar a)
void cyMisc::SetLightColorValue(pyKey& light, const plString& lightName, hsScalar r, hsScalar g, hsScalar b, hsScalar a)
{
// lightName is the name of the light object attached to the light that we want to talk to
// for the bug lights, this would be "RTOmni-BugLightTest"
@ -1958,7 +1957,7 @@ void cyMisc::SetLightColorValue(pyKey& light, std::string lightName, hsScalar r,
}
#include "pnMessage/plEnableMsg.h"
void cyMisc::SetLightAnimationOn(pyKey& light, std::string lightName, hsBool start)
void cyMisc::SetLightAnimationOn(pyKey& light, const plString& lightName, hsBool start)
{
// lightName is the name of the light object attached to the light that we want to talk to
// for the bug lights, this would be "RTOmni-BugLightTest"
@ -2449,28 +2448,26 @@ const char* cyMisc::GetCameraNumber(int number)
plCameraModifier1* pCam = plVirtualCam1::Instance()->GetCameraNumber(number-1);
if (pCam->GetTarget())
{
const char* ret = pCam->GetTarget()->GetKeyName();
const char* ret = pCam->GetTarget()->GetKeyName().c_str();
(ret==nil) ? "empty" : ret;
char str[256];
sprintf(str, "saving camera named %s to chronicle\n",ret);
plVirtualCam1::Instance()->AddMsgToLog(str);
plString str = plString::Format("saving camera named %s to chronicle\n",ret);
plVirtualCam1::Instance()->AddMsgToLog(str.c_str());
return ret;
}
plVirtualCam1::Instance()->AddMsgToLog("sending empty to camera chronicle\n");
return "empty";
}
void cyMisc::RebuildCameraStack(const char* name, const char* ageName)
void cyMisc::RebuildCameraStack(const plString& name, const char* ageName)
{
plKey key=nil;
char str[256];
sprintf(str, "attempting to restore camera named %s from chronicle\n",name);
plVirtualCam1::Instance()->AddMsgToLog(str);
if (strcmp(name, "empty") == 0)
plString str = plString::Format("attempting to restore camera named %s from chronicle\n",name.c_str());
plVirtualCam1::Instance()->AddMsgToLog(str.c_str());
if (name.Compare("empty") == 0)
return;
if ( name || name[0] != 0)
if ( !name.IsEmpty() )
{
key=plKeyFinder::Instance().StupidSearch(nil,nil,plSceneObject::Index(), name, false);
}
@ -2481,9 +2478,8 @@ void cyMisc::RebuildCameraStack(const char* name, const char* ageName)
{
// give up and force built in 3rd person
plVirtualCam1::Instance()->PushThirdPerson();
char errmsg[256];
sprintf(errmsg,"Sceneobject %s not found",name);
PyErr_SetString(PyExc_NameError, errmsg);
plString errmsg = plString::Format("Sceneobject %s not found",name.c_str());
PyErr_SetString(PyExc_NameError, errmsg.c_str());
}
}
else
@ -2506,9 +2502,8 @@ void cyMisc::RebuildCameraStack(const char* name, const char* ageName)
}
}
plVirtualCam1::Instance()->PushThirdPerson();
char errmsg[256];
sprintf(errmsg,"Sceneobject %s has no camera modifier",name);
PyErr_SetString(PyExc_NameError, errmsg);
plString errmsg = plString::Format("Sceneobject %s has no camera modifier",name.c_str());
PyErr_SetString(PyExc_NameError, errmsg.c_str());
}
}
@ -2670,10 +2665,10 @@ void cyMisc::FakeLinkToObject(pyKey& avatar, pyKey& object)
plgDispatch::MsgSend(msg);
}
void cyMisc::FakeLinkToObjectNamed(const char* name)
void cyMisc::FakeLinkToObjectNamed(const plString& name)
{
plKey key = nil;
if ( name || name[0] != 0)
if ( !name.IsEmpty() )
{
key = plKeyFinder::Instance().StupidSearch(nil,nil,plSceneObject::Index(), name, false);
}

View File

@ -142,8 +142,8 @@ public:
// PURPOSE : Execute a console command from a python script,
// optionally propagate over the net
//
static PyObject* FindSceneObject(const char* name, const char* ageName); // returns pySceneObject
static PyObject* FindActivator(const char* name); // returns pyKey
static PyObject* FindSceneObject(const plString& name, const char* ageName); // returns pySceneObject
static PyObject* FindActivator(const plString& name); // returns pyKey
/////////////////////////////////////////////////////////////////////////////
//
@ -252,7 +252,7 @@ public:
// PURPOSE : Return the net client (account) name of the player whose avatar
// key is provided.
//
static const char* GetClientName(pyKey &avKey);
static plString GetClientName(pyKey &avKey);
static PyObject* GetAvatarKeyFromClientID(int clientID); // returns pyKey
static int GetLocalClientID();
@ -268,7 +268,7 @@ public:
//
// PURPOSE : Return the local net client (account) name
//
static const char* GetLocalClientName();
static plString GetLocalClientName();
//
@ -697,8 +697,8 @@ public:
static void SetParticleOffset(float x, float y, float z, pyKey& particles);
static void KillParticles(float time, float pct, pyKey& particles);
static int GetNumParticles(pyKey& host);
static void SetLightColorValue(pyKey& light, std::string lightName, hsScalar r, hsScalar g, hsScalar b, hsScalar a);
static void SetLightAnimationOn(pyKey& light, std::string lightName, hsBool start);
static void SetLightColorValue(pyKey& light, const plString& lightName, hsScalar r, hsScalar g, hsScalar b, hsScalar a);
static void SetLightAnimationOn(pyKey& light, const plString& lightName, hsBool start);
//////////////////////////////////////////////////////////////////////////////
//
// Function : RegisterForControlEventMessages
@ -799,7 +799,7 @@ public:
static int GetNumCameras();
static const char* GetCameraNumber(int number);
static void RebuildCameraStack(const char* name, const char* ageName);
static void RebuildCameraStack(const plString& name, const char* ageName);
static void PyClearCameraStack();
static void RecenterCamera();
static bool IsFirstPerson();
@ -877,8 +877,8 @@ public:
// PURPOSE : takes an avatar key and an object key and fake-links the avatar
// to that object's position. appears to be a link to other players
//
static void FakeLinkToObject(pyKey& avatar, pyKey& object);
static void FakeLinkToObjectNamed(const char* name);
static void FakeLinkToObject(pyKey& avatar, pyKey& object);
static void FakeLinkToObjectNamed(const plString& name);
//////////////////////////////////////////////////////////////////////////////
//

View File

@ -112,10 +112,10 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtGetClientName, args, "Params: avatarKey=None\n
PYTHON_RETURN_ERROR;
}
pyKey* key = pyKey::ConvertFrom(keyObj);
return PyString_FromString(cyMisc::GetClientName(*key));
return PyString_FromString(cyMisc::GetClientName(*key).s_str());
}
else
return PyString_FromString(cyMisc::GetLocalClientName());
return PyString_FromString(cyMisc::GetLocalClientName().c_str());
}
PYTHON_GLOBAL_METHOD_DEFINITION_NOARGS(PtGetLocalAvatar, "This will return a ptSceneobject of the local avatar\n"

View File

@ -183,7 +183,7 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtFindSceneobject, args, "Params: name,ageName\n
PyErr_SetString(PyExc_TypeError, "PtFindSceneobject expects two strings");
PYTHON_RETURN_ERROR;
}
return cyMisc::FindSceneObject(name, ageName);
return cyMisc::FindSceneObject(plString::FromUtf8(name), ageName);
}
PYTHON_GLOBAL_METHOD_DEFINITION(PtFindActivator, args, "Params: name\nThis will try to find an activator based on its name\n"
@ -197,7 +197,7 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtFindActivator, args, "Params: name\nThis will
PYTHON_RETURN_ERROR;
}
return cyMisc::FindActivator(name);
return cyMisc::FindActivator(plString::FromUtf8(name));
}
PYTHON_BASIC_GLOBAL_METHOD_DEFINITION(PtClearCameraStack, cyMisc::ClearCameraStack, "Clears the camera stack")

View File

@ -141,23 +141,17 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtSetLightValue, args, "Params: key,name,r,g,b,a
PYTHON_RETURN_ERROR;
}
pyKey* key = pyKey::ConvertFrom(keyObj);
std::string name = "";
plString name;
if (PyUnicode_Check(nameObj))
{
int strLen = PyUnicode_GetSize(nameObj);
wchar_t* text = TRACKED_NEW wchar_t[strLen + 1];
PyUnicode_AsWideChar((PyUnicodeObject*)nameObj, text, strLen);
text[strLen] = L'\0';
char* cText = hsWStringToString(text);
name = cText;
delete [] cText;
delete [] text;
PyObject* utf8 = PyUnicode_AsUTF8String(nameObj);
name = plString::FromUtf8(PyString_AsString(utf8));
Py_DECREF(utf8);
}
else if (PyString_Check(nameObj))
{
// we'll allow this, just in case something goes weird
char* text = PyString_AsString(nameObj);
name = text;
name = plString::FromUtf8(PyString_AsString(nameObj));
}
else
{
@ -184,23 +178,17 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtSetLightAnimStart, args, "Params: key,name,sta
PYTHON_RETURN_ERROR;
}
pyKey* key = pyKey::ConvertFrom(keyObj);
std::string name = "";
plString name;
if (PyUnicode_Check(nameObj))
{
int strLen = PyUnicode_GetSize(nameObj);
wchar_t* text = TRACKED_NEW wchar_t[strLen + 1];
PyUnicode_AsWideChar((PyUnicodeObject*)nameObj, text, strLen);
text[strLen] = L'\0';
char* cText = hsWStringToString(text);
name = cText;
delete [] cText;
delete [] text;
PyObject* utf8 = PyUnicode_AsUTF8String(nameObj);
name = plString::FromUtf8(PyString_AsString(utf8));
Py_DECREF(utf8);
}
else if (PyString_Check(nameObj))
{
// we'll allow this, just in case something goes weird
char* text = PyString_AsString(nameObj);
name = text;
name = plString::FromUtf8(PyString_AsString(nameObj));
}
else
{
@ -363,7 +351,7 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtRebuildCameraStack, args, "Params: name,ageNam
PyErr_SetString(PyExc_TypeError, "PtRebuildCameraStack expects two strings");
PYTHON_RETURN_ERROR;
}
cyMisc::RebuildCameraStack(name, ageName);
cyMisc::RebuildCameraStack(plString::FromUtf8(name), ageName);
PYTHON_RETURN_NONE;
}

View File

@ -331,7 +331,6 @@ hsBool plPythonFileMod::fAtConvertTime = false;
plPythonFileMod::plPythonFileMod()
{
fPythonFile = nil;
fModuleName = nil;
fModule = nil;
fLocalNotify= true;
fIsFirstTimeEval = true;
@ -404,15 +403,15 @@ plPythonFileMod::~plPythonFileMod()
}
// then get rid of this module
// NOTE: fModule shouldn't be made in the plugin, only at runtime
if ( fModuleName && fModule )
if ( !fModuleName.IsNull() && fModule )
{
//_PyModule_Clear(fModule);
PyObject *m;
PyObject *modules = PyImport_GetModuleDict();
if( modules && (m = PyDict_GetItemString(modules, fModuleName)) && PyModule_Check(m))
if( modules && (m = PyDict_GetItemString(modules, fModuleName.c_str())) && PyModule_Check(m))
{
hsStatusMessageF("Module %s removed from python dictionary",fModuleName);
PyDict_DelItemString(modules, fModuleName);
PyDict_DelItemString(modules, fModuleName.c_str());
}
else
{
@ -422,8 +421,7 @@ plPythonFileMod::~plPythonFileMod()
// we need to set our pointer to nil to make sure we don't try to use it
fModule = nil;
}
delete [] fModuleName;
fModuleName = nil;
fModuleName = plString::Null;
}
#include "plPythonPack.h"
@ -510,11 +508,8 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj)
{
plKey pkey = sobj->GetKey();
// nope, must be the first object. Then use it as the basis for the module
char modulename[256];
IMakeModuleName(modulename,sobj);
delete [] fModuleName;
fModuleName = StrDup(modulename);
fModule = PythonInterface::CreateModule(modulename);
fModuleName = IMakeModuleName(sobj);
fModule = PythonInterface::CreateModule(fModuleName.c_str());
// if we can't create the instance then there is nothing to do here
if (!ILoadPythonCode())
@ -634,17 +629,16 @@ void plPythonFileMod::AddTarget(plSceneObject* sobj)
NamedComponent comp;
comp.isActivator = (isNamedAttr == 1);
comp.id = parameter.fID;
comp.name = TRACKED_NEW char[strlen(parameter.datarecord.fString) + 1];
strcpy(comp.name, parameter.datarecord.fString);
comp.name = plString::FromUtf8(parameter.datarecord.fString);
fNamedCompQueue.Append(comp);
}
else
{
if (isNamedAttr == 1)
IFindActivatorAndAdd(parameter.datarecord.fString, parameter.fID);
IFindActivatorAndAdd(plString::FromUtf8(parameter.datarecord.fString), parameter.fID);
else
IFindResponderAndAdd(parameter.datarecord.fString, parameter.fID);
IFindResponderAndAdd(plString::FromUtf8(parameter.datarecord.fString), parameter.fID);
}
}
}
@ -951,7 +945,7 @@ void plPythonFileMod::HandleDiscardedKey( plKeyEventMsg *msg )
//
// NOTE: This modifier wasn't intended to have multiple targets
//
void plPythonFileMod::IMakeModuleName(char* modulename,plSceneObject* sobj)
plString plPythonFileMod::IMakeModuleName(plSceneObject* sobj)
{
// Forgive my general crapulance...
// This strips underscores out of module names
@ -960,13 +954,14 @@ void plPythonFileMod::IMakeModuleName(char* modulename,plSceneObject* sobj)
plKey pKey = GetKey();
plKey sKey = sobj->GetKey();
const char* pKeyName = pKey->GetName();
const char* pSobjName = sKey->GetName();
const char* pKeyName = pKey->GetName().c_str();
const char* pSobjName = sKey->GetName().c_str();
UInt16 len = hsStrlen(pKeyName);
UInt16 slen = hsStrlen(pSobjName);
UInt16 len = pKey->GetName().GetSize();
UInt16 slen = sKey->GetName().GetSize();
hsAssert(len+slen < 256, "Warning: String length exceeds 256 characters.");
char modulename[256];
int i, k = 0;
for(i = 0; i < slen; i++)
@ -983,6 +978,7 @@ void plPythonFileMod::IMakeModuleName(char* modulename,plSceneObject* sobj)
}
modulename[k] = '\0';
plString name = plString::FromUtf8(modulename);
// check to see if we are attaching to a clone?
plKeyImp* pKeyImp = (plKeyImp*)(sKey);
@ -992,7 +988,7 @@ void plPythonFileMod::IMakeModuleName(char* modulename,plSceneObject* sobj)
// add the cloneID to the end of the module name
// and set the fIAmAClone flag
UInt32 cloneID = pKeyImp->GetUoid().GetCloneID();
sprintf(modulename,"%s%d",modulename,cloneID);
name += plString::Format("%d", cloneID);
fAmIAttachedToClone = true;
}
@ -1001,8 +997,10 @@ void plPythonFileMod::IMakeModuleName(char* modulename,plSceneObject* sobj)
{
// if not unique then add the sequence number to the end of the modulename
UInt32 seqID = pKeyImp->GetUoid().GetLocation().GetSequenceNumber();
sprintf(modulename,"%s%d",modulename,seqID);
name += plString::Format("%d", seqID);
}
return name;
}
/////////////////////////////////////////////////////////////////////////////
@ -1047,9 +1045,9 @@ void plPythonFileMod::ISetKeyValue(const plKey& key, Int32 id)
// PURPOSE : find a responder by name in all age and page locations
// : and add to the Parameter list
//
void plPythonFileMod::IFindResponderAndAdd(const char *responderName, Int32 id)
void plPythonFileMod::IFindResponderAndAdd(const plString &responderName, Int32 id)
{
if ( responderName != nil )
if ( !responderName.IsNull() )
{
std::vector<plKey> keylist;
const plLocation &loc = GetKey()->GetUoid().GetLocation();
@ -1075,9 +1073,9 @@ void plPythonFileMod::IFindResponderAndAdd(const char *responderName, Int32 id)
// PURPOSE : find a responder by name in all age and page locations
// : and add to the Parameter list
//
void plPythonFileMod::IFindActivatorAndAdd(const char *activatorName, Int32 id)
void plPythonFileMod::IFindActivatorAndAdd(const plString &activatorName, Int32 id)
{
if ( activatorName != nil )
if ( !activatorName.IsNull() )
{
std::vector<plKey> keylist;
const plLocation &loc = GetKey()->GetUoid().GetLocation();
@ -1236,8 +1234,6 @@ hsBool plPythonFileMod::MsgReceive(plMessage* msg)
IFindActivatorAndAdd(comp.name, comp.id);
else
IFindResponderAndAdd(comp.name, comp.id);
delete [] comp.name;
}
fNamedCompQueue.Reset();
@ -1756,9 +1752,9 @@ hsBool plPythonFileMod::MsgReceive(plMessage* msg)
{
// yes...
// call it
char* roomname = "";
const char* roomname = "";
if ( pRLNMsg->GetRoom() != nil )
roomname = (char*)pRLNMsg->GetRoom()->GetName();
roomname = pRLNMsg->GetRoom()->GetName().c_str();
plProfile_BeginTiming(PythonUpdate);
PyObject* retVal = PyObject_CallMethod(
@ -2837,11 +2833,10 @@ hsBool plPythonFileMod::MsgReceive(plMessage* msg)
//
void plPythonFileMod::ReportError()
{
char objectName[128];
StrCopy(objectName, this->GetKeyName(), arrsize(objectName));
StrPack(objectName, " - ", arrsize(objectName));
plString objectName = this->GetKeyName();
objectName += _TEMP_CONVERT_FROM_LITERAL(" - ");
PythonInterface::WriteToStdErr(objectName);
PythonInterface::WriteToStdErr(objectName.c_str());
PyErr_Print(); // make sure the error is printed
PyErr_Clear(); // clear the error
@ -2984,4 +2979,4 @@ void plPythonFileMod::Write(hsStream* stream, hsResMgr* mgr)
//// kGlobalNameKonstant /////////////////////////////////////////////////
// My continued attempt to spread the CORRECT way to spell konstant. -mcn
char plPythonFileMod::kGlobalNameKonstant[] = "VeryVerySpecialPythonFileMod";
plString plPythonFileMod::kGlobalNameKonstant = _TEMP_CONVERT_FROM_LITERAL("VeryVerySpecialPythonFileMod");

View File

@ -74,10 +74,10 @@ protected:
hsBool IEval(double secs, hsScalar del, UInt32 dirty);
void IMakeModuleName(char* modulename,plSceneObject* sobj);
plString IMakeModuleName(plSceneObject* sobj);
char* fPythonFile;
char* fModuleName;
plString fModuleName;
// the list of receivers that want to be notified
hsTArray<plKey> fReceivers;
@ -104,15 +104,15 @@ protected:
struct NamedComponent
{
char* name;
Int32 id;
bool isActivator;
plString name;
Int32 id;
bool isActivator;
};
hsTArray<NamedComponent> fNamedCompQueue;
virtual void IFindResponderAndAdd(const char *responderName, Int32 id);
virtual void IFindActivatorAndAdd(const char *activatorName, Int32 id);
virtual void IFindResponderAndAdd(const plString &responderName, Int32 id);
virtual void IFindActivatorAndAdd(const plString &activatorName, Int32 id);
void ISetKeyValue(const plKey& key, Int32 id);
bool ILoadPythonCode();
@ -210,7 +210,7 @@ public:
static const char* fFunctionNames[];
// The konstant hard-coded name to be used for all global pythonFileMods
static char kGlobalNameKonstant[];
static plString kGlobalNameKonstant;
// API for processing discarded keys as the deafult key catcher
void HandleDiscardedKey( plKeyEventMsg *msg );

View File

@ -605,7 +605,7 @@ const plPythonSDLModifier* plPythonSDLModifier::FindAgeSDL()
return sdlMod;
plNetClientApp::StaticErrorMsg("pfmod %s has a nil python SDL modifier for age sdl %s",
pfmod->GetKeyName() ? pfmod->GetKeyName() : "?", ageName);
pfmod->GetKeyName().s_str("?"), ageName);
}
else
{
@ -614,11 +614,11 @@ const plPythonSDLModifier* plPythonSDLModifier::FindAgeSDL()
else
if (!key->ObjectIsLoaded())
plNetClientApp::StaticErrorMsg("key %s not loaded for age sdl %s",
key->GetName() ? key->GetName() : "?", ageName);
key->GetName().s_str("?"), ageName);
else
if (!plPythonFileMod::ConvertNoRef(key->ObjectIsLoaded()))
plNetClientApp::StaticErrorMsg("key %s is not a python file mod for age sdl %s",
key->GetName() ? key->GetName() : "?", ageName);
key->GetName().s_str("?"), ageName);
}
}
else

View File

@ -200,7 +200,7 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16
}
// let's create a nice name for this thing based on the filename
std::string name = "PtImageFromDisk_";
plString name = _TEMP_CONVERT_FROM_LITERAL("PtImageFromDisk_");
const wchar* i = filename;
int charsChecked = 0;
@ -219,10 +219,9 @@ PyObject* pyImage::LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16
i++;
}
char* cName = hsWStringToString(i);
name = name + cName;
name += plString::FromWchar(i);
hsgResMgr::ResMgr()->NewKey(name.c_str(), theMipmap, plLocation::kGlobalFixedLoc);
hsgResMgr::ResMgr()->NewKey(name, theMipmap, plLocation::kGlobalFixedLoc);
return pyImage::New( theMipmap );
}

View File

@ -58,8 +58,7 @@ UInt32 pyJournalBook::fNextKeyID = 0;
void pyJournalBook::IMakeNewKey( void )
{
char name[ 128 ];
sprintf( name, "pyJournalBook-%d", fNextKeyID++ );
plString name = plString::Format( "pyJournalBook-%d", fNextKeyID++ );
hsgResMgr::ResMgr()->NewKey( name, fBook, plLocation::kGlobalFixedLoc );
fBook->GetKey()->RefObject();
@ -96,14 +95,14 @@ pyJournalBook::pyJournalBook( std::wstring esHTMLSource, pyImage &coverImage, py
IMakeNewKey();
}
pyJournalBook::pyJournalBook( const char *esHTMLSource, pyImage &coverImage, pyKey callbackKey, const char *guiName )
pyJournalBook::pyJournalBook( const char *esHTMLSource, pyImage &coverImage, pyKey callbackKey, const plString &guiName )
{
fBook = TRACKED_NEW pfJournalBook( esHTMLSource, coverImage.GetKey(), callbackKey.getKey(),
callbackKey.getKey() != nil ? callbackKey.getKey()->GetUoid().GetLocation() : plLocation::kGlobalFixedLoc, guiName );
IMakeNewKey();
}
pyJournalBook::pyJournalBook( std::wstring esHTMLSource, pyImage &coverImage, pyKey callbackKey, const char *guiName )
pyJournalBook::pyJournalBook( std::wstring esHTMLSource, pyImage &coverImage, pyKey callbackKey, const plString &guiName )
{
fBook = TRACKED_NEW pfJournalBook( esHTMLSource.c_str(), coverImage.GetKey(), callbackKey.getKey(),
callbackKey.getKey() != nil ? callbackKey.getKey()->GetUoid().GetLocation() : plLocation::kGlobalFixedLoc, guiName );
@ -135,7 +134,7 @@ pyJournalBook::~pyJournalBook()
}
}
void pyJournalBook::MakeBook(std::string esHTMLSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, std::string guiName /* = "" */)
void pyJournalBook::MakeBook(std::string esHTMLSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, plString guiName /* = "" */)
{
if (fBook)
fBook->GetKey()->UnRefObject();
@ -144,11 +143,11 @@ void pyJournalBook::MakeBook(std::string esHTMLSource, plKey coverImageKey /* =
if (callbackKey != nil)
loc = callbackKey->GetUoid().GetLocation();
fBook = TRACKED_NEW pfJournalBook(esHTMLSource.c_str(), coverImageKey, callbackKey, loc, guiName.c_str());
fBook = TRACKED_NEW pfJournalBook(esHTMLSource.c_str(), coverImageKey, callbackKey, loc, guiName);
IMakeNewKey();
}
void pyJournalBook::MakeBook(std::wstring esHTMLSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, std::string guiName /* = "" */)
void pyJournalBook::MakeBook(std::wstring esHTMLSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, plString guiName /* = "" */)
{
if (fBook)
fBook->GetKey()->UnRefObject();
@ -157,7 +156,7 @@ void pyJournalBook::MakeBook(std::wstring esHTMLSource, plKey coverImageKey /* =
if (callbackKey != nil)
loc = callbackKey->GetUoid().GetLocation();
fBook = TRACKED_NEW pfJournalBook(esHTMLSource.c_str(), coverImageKey, callbackKey, loc, guiName.c_str());
fBook = TRACKED_NEW pfJournalBook(esHTMLSource.c_str(), coverImageKey, callbackKey, loc, guiName);
IMakeNewKey();
}
@ -235,18 +234,18 @@ void pyJournalBook::AllowPageTurning( bool allow )
fBook->AllowPageTurning(allow);
}
void pyJournalBook::SetGUI( const char *guiName )
void pyJournalBook::SetGUI( const plString &guiName )
{
if (fBook != nil)
fBook->SetGUI(guiName);
}
void pyJournalBook::LoadGUI( const char *guiName )
void pyJournalBook::LoadGUI( const plString &guiName )
{
pfJournalBook::LoadGUI(guiName);
}
void pyJournalBook::UnloadGUI( const char *guiName )
void pyJournalBook::UnloadGUI( const plString &guiName )
{
pfJournalBook::UnloadGUI(guiName);
}

View File

@ -78,8 +78,8 @@ protected:
pyJournalBook( std::wstring esHTMLSource, pyKey callbackKey );
pyJournalBook( const char *esHTMLSource, pyImage &coverImage, pyKey callbackKey );
pyJournalBook( std::wstring esHTMLSource, pyImage &coverImage, pyKey callbackKey );
pyJournalBook( const char *esHTMLSource, pyImage &coverImage, pyKey callbackKey, const char *guiName );
pyJournalBook( std::wstring esHTMLSource, pyImage &coverImage, pyKey callbackKey, const char *guiName );
pyJournalBook( const char *esHTMLSource, pyImage &coverImage, pyKey callbackKey, const plString &guiName );
pyJournalBook( std::wstring esHTMLSource, pyImage &coverImage, pyKey callbackKey, const plString &guiName );
public:
virtual ~pyJournalBook();
@ -88,8 +88,8 @@ public:
// required functions for PyObject interoperability
PYTHON_CLASS_NEW_FRIEND(ptBook);
static PyObject *New(std::string htmlSource, plKey coverImageKey = nil, plKey callbackKey = nil, std::string guiName = "");
static PyObject *New(std::wstring htmlSource, plKey coverImageKey = nil, plKey callbackKey = nil, std::string guiName = "");
static PyObject *New(std::string htmlSource, plKey coverImageKey = nil, plKey callbackKey = nil, plString guiName = _TEMP_CONVERT_FROM_LITERAL(""));
static PyObject *New(std::wstring htmlSource, plKey coverImageKey = nil, plKey callbackKey = nil, plString guiName = _TEMP_CONVERT_FROM_LITERAL(""));
PYTHON_CLASS_CHECK_DEFINITION; // returns true if the PyObject is a pyJournalBook object
PYTHON_CLASS_CONVERT_FROM_DEFINITION(pyJournalBook); // converts a PyObject to a pyJournalBook (throws error if not correct type)
@ -98,8 +98,8 @@ public:
static void AddPlasmaConstantsClasses(PyObject *m);
// Deletes the existing book and re-creates it, for use by the python glue
void MakeBook(std::string esHTMLSource, plKey coverImageKey = nil, plKey callbackKey = nil, std::string guiName = "");
void MakeBook(std::wstring esHTMLSource, plKey coverImageKey = nil, plKey callbackKey = nil, std::string guiName = "");
void MakeBook(std::string esHTMLSource, plKey coverImageKey = nil, plKey callbackKey = nil, plString guiName = _TEMP_CONVERT_FROM_LITERAL(""));
void MakeBook(std::wstring esHTMLSource, plKey coverImageKey = nil, plKey callbackKey = nil, plString guiName = _TEMP_CONVERT_FROM_LITERAL(""));
// Interface functions per book
virtual void Show( hsBool startOpened );
@ -117,10 +117,10 @@ public:
virtual void SetSize( hsScalar width, hsScalar height );
virtual void SetGUI( const char *guiName );
virtual void SetGUI( const plString &guiName );
static void LoadGUI( const char *guiName );
static void UnloadGUI( const char *guiName );
static void LoadGUI( const plString &guiName );
static void UnloadGUI( const plString &guiName );
static void UnloadAllGUIs();
virtual PyObject *GetMovie( UInt8 index ); // returns cyAnimation

View File

@ -101,9 +101,9 @@ PYTHON_INIT_DEFINITION(ptBook, args, keywords)
callbackKey = pyKey::ConvertFrom(callbackObj)->getKey();
}
std::string guiNameStr = "";
plString guiNameStr;
if (guiName)
guiNameStr = guiName;
guiNameStr = plString::FromUtf8(guiName);
// convert the sourcecode object
if (PyUnicode_Check(sourceObj))
@ -225,7 +225,7 @@ PYTHON_METHOD_DEFINITION(ptBook, setGUI, args)
PyErr_SetString(PyExc_TypeError, "setGUI expects a string");
PYTHON_RETURN_ERROR;
}
self->fThis->SetGUI(guiName);
self->fThis->SetGUI(plString::FromUtf8(guiName));
PYTHON_RETURN_NONE;
}
@ -293,14 +293,14 @@ PYTHON_END_METHODS_TABLE;
PLASMA_DEFAULT_TYPE(ptBook, "Params: esHTMLSource,coverImage=None,callbackKey=None,guiName=''\nCreates a new book");
// required functions for PyObject interoperability
PyObject *pyJournalBook::New(std::string htmlSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, std::string guiName /* = "" */)
PyObject *pyJournalBook::New(std::string htmlSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, plString guiName /* = "" */)
{
ptBook *newObj = (ptBook*)ptBook_type.tp_new(&ptBook_type, NULL, NULL);
newObj->fThis->MakeBook(htmlSource, coverImageKey, callbackKey, guiName);
return (PyObject*)newObj;
}
PyObject *pyJournalBook::New(std::wstring htmlSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, std::string guiName /* = "" */)
PyObject *pyJournalBook::New(std::wstring htmlSource, plKey coverImageKey /* = nil */, plKey callbackKey /* = nil */, plString guiName /* = "" */)
{
ptBook *newObj = (ptBook*)ptBook_type.tp_new(&ptBook_type, NULL, NULL);
newObj->fThis->MakeBook(htmlSource, coverImageKey, callbackKey, guiName);
@ -329,7 +329,7 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtLoadBookGUI, args, "Params: guiName\nLoads the
PyErr_SetString(PyExc_TypeError, "PtLoadBookGUI expects a string");
PYTHON_RETURN_ERROR;
}
pyJournalBook::LoadGUI(guiName);
pyJournalBook::LoadGUI(plString::FromUtf8(guiName));
PYTHON_RETURN_NONE;
}
@ -341,7 +341,7 @@ PYTHON_GLOBAL_METHOD_DEFINITION(PtUnloadBookGUI, args, "Params: guiName\nUnloads
PyErr_SetString(PyExc_TypeError, "PtUnloadBookGUI expects a string");
PYTHON_RETURN_ERROR;
}
pyJournalBook::UnloadGUI(guiName);
pyJournalBook::UnloadGUI(plString::FromUtf8(guiName));
PYTHON_RETURN_NONE;
}

View File

@ -52,6 +52,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Python.h>
#include "pyGlueHelpers.h"
#include "plString.h"
class plPythonFileMod;
class pySceneObject;
@ -98,7 +99,7 @@ public:
// getter and setters
virtual plKey getKey() { return fKey; }
virtual void setKey(plKey key) { fKey=key; }
virtual const char* getName() const { return fKey ? fKey->GetName() : "nil"; }
virtual const char* getName() const { return fKey ? fKey->GetName().c_str() : "nil"; }
#ifndef BUILDING_PYPLASMA
PyObject* GetPySceneObject();

View File

@ -210,21 +210,21 @@ void pySceneObject::SetNetForce(hsBool state)
}
const char* pySceneObject::GetName()
plString pySceneObject::GetName()
{
if ( fSceneObjects.Count() > 0 )
return fSceneObjects[0]->GetName();
return "";
return _TEMP_CONVERT_FROM_LITERAL("");
}
PyObject* pySceneObject::findObj(const char* name)
PyObject* pySceneObject::findObj(const plString& name)
{
PyObject* pSobj = nil;
// search through the plKeys that we have looking for this name
int i;
for ( i=0; i<fSceneObjects.Count(); i++ )
{
if ( hsStrEQ(name,fSceneObjects[i]->GetName()) )
if ( name == fSceneObjects[i]->GetName() )
{
pSobj = pySceneObject::New(fSceneObjects[i],fPyMod);
break;
@ -235,7 +235,7 @@ PyObject* pySceneObject::findObj(const char* name)
if ( pSobj == nil )
{
// throw a Python error, so the coder knows it didn't work
PyErr_SetString(PyExc_KeyError, name);
PyErr_SetString(PyExc_KeyError, name.c_str());
}
return pSobj;

View File

@ -114,9 +114,9 @@ public:
virtual void SetNetForce(hsBool state);
virtual PyObject* findObj(const char* name); // pySceneObject
virtual PyObject* findObj(const plString& name); // pySceneObject
virtual const char* GetName();
virtual plString GetName();
virtual std::vector<PyObject*> GetResponders(); // pyKey list
virtual std::vector<PyObject*> GetPythonMods(); // pyKey list
//

View File

@ -151,12 +151,12 @@ PYTHON_METHOD_DEFINITION(ptSceneobject, findObject, args)
PyErr_SetString(PyExc_TypeError, "findObject expects a string");
PYTHON_RETURN_ERROR;
}
return self->fThis->findObj(name);
return self->fThis->findObj(plString::FromUtf8(name));
}
PYTHON_METHOD_DEFINITION_NOARGS(ptSceneobject, getName)
{
return PyString_FromString(self->fThis->GetName());
return PyString_FromString(self->fThis->GetName().c_str());
}
PYTHON_METHOD_DEFINITION_NOARGS(ptSceneobject, getResponders)

View File

@ -64,8 +64,7 @@ static unsigned s_keyseq;
//============================================================================
static plKey CreateAndRefImageKey (unsigned nodeId, plMipmap * mipmap) {
char keyName[MAX_PATH];
StrPrintf(keyName, arrsize(keyName), "VaultImg_%u_%u", nodeId, s_keyseq++);
plString keyName = plString::Format("VaultImg_%u_%u", nodeId, s_keyseq++);
plKey key = hsgResMgr::ResMgr()->NewKey(keyName, mipmap, plLocation::kGlobalFixedLoc);