mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-20 12:19:10 +00:00
Build 918
This commit is contained in:
@ -1718,6 +1718,20 @@ void PythonInterface::WriteToStdErr(const char* text)
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* PythonInterface::ImportModule(const char* module)
|
||||
{
|
||||
PyObject* result = nil;
|
||||
PyObject* name = PyString_FromString(module);
|
||||
|
||||
if (name != nil)
|
||||
{
|
||||
result = PyImport_Import(name);
|
||||
Py_DECREF(name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : FindModule
|
||||
@ -2061,6 +2075,78 @@ hsBool PythonInterface::RunPYC(PyObject* code, PyObject* module)
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : RunFunction
|
||||
// PARAMETERS : module - module name to run 'name' in
|
||||
// : name - name of function
|
||||
// : args - tuple with arguments
|
||||
//
|
||||
//
|
||||
PyObject* PythonInterface::RunFunction(PyObject* module, const char* name, PyObject* args)
|
||||
{
|
||||
if (module == NULL)
|
||||
return NULL;
|
||||
|
||||
PyObject* function = PyObject_GetAttrString(module, const_cast<char*>(name));
|
||||
|
||||
PyObject* result = NULL;
|
||||
if (function != nil)
|
||||
{
|
||||
result = PyObject_Call(function, args, NULL);
|
||||
Py_DECREF(function);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PyObject* PythonInterface::ParseArgs(const char* args)
|
||||
{
|
||||
PyObject* result = NULL;
|
||||
PyObject* scope = PyDict_New();
|
||||
if (scope)
|
||||
{
|
||||
//- Py_eval_input makes this function accept only single expresion (not statement)
|
||||
//- When using empty scope, functions and classes like 'file' or '__import__' are not visible
|
||||
result = PyRun_String(args, Py_eval_input, scope, NULL);
|
||||
Py_DECREF(scope);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool PythonInterface::RunFunctionSafe(const char* module, const char* function, const char* args)
|
||||
{
|
||||
PyObject* moduleObj = ImportModule(module);
|
||||
bool result = false;
|
||||
if (moduleObj)
|
||||
{
|
||||
PyObject* argsObj = ParseArgs(args);
|
||||
if (argsObj)
|
||||
{
|
||||
PyObject* callResult = RunFunction(moduleObj, function, argsObj);
|
||||
if (callResult)
|
||||
{
|
||||
result = true;
|
||||
Py_DECREF(callResult);
|
||||
}
|
||||
|
||||
Py_DECREF(argsObj);
|
||||
}
|
||||
Py_DECREF(moduleObj);
|
||||
}
|
||||
|
||||
if (!result)
|
||||
{
|
||||
PyErr_Print();
|
||||
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : GetpyKeyFromPython
|
||||
@ -2073,4 +2159,4 @@ pyKey* PythonInterface::GetpyKeyFromPython(PyObject* pkey)
|
||||
if (!pyKey::Check(pkey))
|
||||
return nil;
|
||||
return pyKey::ConvertFrom(pkey);
|
||||
}
|
||||
}
|
||||
|
@ -138,6 +138,8 @@ public:
|
||||
// Writes 'text' to stderr specified in the python interface
|
||||
static void WriteToStdErr(const char* text);
|
||||
|
||||
static PyObject* ImportModule(const char* module);
|
||||
|
||||
// Find module. If it doesn't exist then don't create, return nil.
|
||||
static PyObject* FindModule(char* module);
|
||||
|
||||
@ -219,6 +221,12 @@ public:
|
||||
//
|
||||
static hsBool RunPYC(PyObject* code, PyObject* module);
|
||||
|
||||
static PyObject* RunFunction(PyObject* module, const char* name, PyObject* args);
|
||||
|
||||
static PyObject* ParseArgs(const char* args);
|
||||
|
||||
static bool RunFunctionSafe(const char* module, const char* function, const char* args);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Function : GetpyKeyFromPython
|
||||
|
@ -1,49 +0,0 @@
|
||||
/*==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==*/
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pyCCRMgr - a wrapper class to provide interface to the pfCCR stuff
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "../pfCCR/plCCRMgr.h"
|
@ -1,56 +0,0 @@
|
||||
/*==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 pyCCRMgr_h_inc
|
||||
#define pyCCRMgr_h_inc
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pyCCRMgr - a wrapper class to provide interface to the pfCCR stuff
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "hsTypes.h"
|
||||
#include "hsStlUtils.h"
|
||||
#include "../pfCCR/plCCRMgr.h"
|
||||
|
||||
|
||||
#endif // pyCCRMgr_h_inc
|
@ -1,45 +0,0 @@
|
||||
/*==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 "pyCCRMgr.h"
|
||||
#include "pyAgeLinkStruct.h"
|
||||
|
||||
#include <python.h>
|
@ -1,44 +0,0 @@
|
||||
/*==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 "pyCCRMgr.h"
|
||||
|
||||
#include <python.h>
|
@ -176,6 +176,13 @@ void pyImage::SaveAsJPEG(const wchar* fileName, UInt8 quality)
|
||||
plJPEG::Instance().WriteToFile( fileName, this->GetImage() );
|
||||
}
|
||||
|
||||
#include "../plGImage/plPNG.h"
|
||||
void pyImage::SaveAsPNG(const wchar* fileName)
|
||||
{
|
||||
|
||||
plPNG::Instance().WriteToFile( fileName, this->GetImage() );
|
||||
}
|
||||
|
||||
#include "hsResMgr.h"
|
||||
#include "../pnKeyedObject/plUoid.h"
|
||||
PyObject* pyImage::LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16 height)
|
||||
|
@ -166,6 +166,7 @@ public:
|
||||
UInt32 GetWidth(); // returns the width of the image
|
||||
UInt32 GetHeight(); // returns the height of the image
|
||||
void SaveAsJPEG(const wchar* fileName, UInt8 quality = 75);
|
||||
void SaveAsPNG(const wchar* fileName);
|
||||
static PyObject* LoadJPEGFromDisk(const wchar* filename, UInt16 width, UInt16 height); // returns pyImage
|
||||
#endif
|
||||
};
|
||||
|
@ -174,6 +174,41 @@ PYTHON_METHOD_DEFINITION(ptImage, saveAsJPEG, args)
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
PYTHON_METHOD_DEFINITION(ptImage, saveAsPNG, args)
|
||||
{
|
||||
PyObject* filenameObj;
|
||||
if (!PyArg_ParseTuple(args, "O", &filenameObj))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "saveAsPNG expects a string");
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
|
||||
if (PyUnicode_Check(filenameObj))
|
||||
{
|
||||
int strLen = PyUnicode_GetSize(filenameObj);
|
||||
wchar_t* text = TRACKED_NEW wchar_t[strLen + 1];
|
||||
PyUnicode_AsWideChar((PyUnicodeObject*)filenameObj, text, strLen);
|
||||
text[strLen] = L'\0';
|
||||
self->fThis->SaveAsPNG(text);
|
||||
delete [] text;
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
else if (PyString_Check(filenameObj))
|
||||
{
|
||||
// we'll allow this, just in case something goes weird
|
||||
char* text = PyString_AsString(filenameObj);
|
||||
wchar_t* wText = hsStringToWString(text);
|
||||
self->fThis->SaveAsPNG(wText);
|
||||
delete [] wText;
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "saveAsPNG expects a string");
|
||||
PYTHON_RETURN_ERROR;
|
||||
}
|
||||
}
|
||||
#endif // BUILDING_PYPLASMA
|
||||
|
||||
PYTHON_START_METHODS_TABLE(ptImage)
|
||||
@ -183,6 +218,7 @@ PYTHON_START_METHODS_TABLE(ptImage)
|
||||
PYTHON_METHOD_NOARGS(ptImage, getWidth, "Returns the width of the image"),
|
||||
PYTHON_METHOD_NOARGS(ptImage, getHeight, "Returns the height of the image"),
|
||||
PYTHON_METHOD(ptImage, saveAsJPEG, "Params: filename,quality=75\nSaves this image to disk as a JPEG file"),
|
||||
PYTHON_METHOD(ptImage, saveAsPNG, "Params: filename\nSaves this image to disk as a PNG file"),
|
||||
#endif
|
||||
PYTHON_END_METHODS_TABLE;
|
||||
|
||||
|
@ -545,7 +545,7 @@ hsBool pySceneObject::IsAvatar()
|
||||
return false;
|
||||
}
|
||||
|
||||
#include "../plAvatar/plAvCallbackAction.h"
|
||||
#include "../plAvatar/plPhysicalControllerCore.h"
|
||||
|
||||
PyObject* pySceneObject::GetAvatarVelocity()
|
||||
{
|
||||
|
@ -171,6 +171,8 @@ PyObject* pyVaultImageNode::Image_GetImage( void )
|
||||
else
|
||||
fMipmapKey->RefObject();
|
||||
}
|
||||
else
|
||||
PYTHON_RETURN_NONE;
|
||||
}
|
||||
|
||||
return pyImage::New(fMipmap);
|
||||
|
Reference in New Issue
Block a user