diff options
Diffstat (limited to 'source/gameengine/Expressions')
-rw-r--r-- | source/gameengine/Expressions/CMakeLists.txt | 86 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_BoolValue.h (renamed from source/gameengine/Expressions/BoolValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_C-Api.cpp | 123 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_C-Api.h | 67 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_ConstExpr.h (renamed from source/gameengine/Expressions/ConstExpr.h) | 12 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_EmptyValue.h (renamed from source/gameengine/Expressions/EmptyValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_ErrorValue.h (renamed from source/gameengine/Expressions/ErrorValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_Expression.h (renamed from source/gameengine/Expressions/Expression.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_FloatValue.h (renamed from source/gameengine/Expressions/FloatValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_HashedPtr.h (renamed from source/gameengine/Expressions/KX_HashedPtr.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_IdentifierExpr.h (renamed from source/gameengine/Expressions/IdentifierExpr.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_IfExpr.h (renamed from source/gameengine/Expressions/IfExpr.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_InputParser.h (renamed from source/gameengine/Expressions/InputParser.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_IntValue.h (renamed from source/gameengine/Expressions/IntValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_ListValue.h (renamed from source/gameengine/Expressions/ListValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_Operator1Expr.h (renamed from source/gameengine/Expressions/Operator1Expr.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_Operator2Expr.h (renamed from source/gameengine/Expressions/Operator2Expr.h) | 12 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_PyObjectPlus.h (renamed from source/gameengine/Expressions/PyObjectPlus.h) | 34 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_Python.h (renamed from source/gameengine/Expressions/KX_Python.h) | 8 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_PythonCallBack.h | 40 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_StringValue.h (renamed from source/gameengine/Expressions/StringValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_Value.h (renamed from source/gameengine/Expressions/Value.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_VectorValue.h (renamed from source/gameengine/Expressions/VectorValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/EXP_VoidValue.h (renamed from source/gameengine/Expressions/VoidValue.h) | 10 | ||||
-rw-r--r-- | source/gameengine/Expressions/SConscript | 2 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/BoolValue.cpp (renamed from source/gameengine/Expressions/BoolValue.cpp) | 8 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/ConstExpr.cpp (renamed from source/gameengine/Expressions/ConstExpr.cpp) | 6 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/EmptyValue.cpp (renamed from source/gameengine/Expressions/EmptyValue.cpp) | 14 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/ErrorValue.cpp (renamed from source/gameengine/Expressions/ErrorValue.cpp) | 2 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/Expression.cpp (renamed from source/gameengine/Expressions/Expression.cpp) | 4 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/FloatValue.cpp (renamed from source/gameengine/Expressions/FloatValue.cpp) | 12 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/HashedPtr.cpp (renamed from source/gameengine/Expressions/KX_HashedPtr.cpp) | 28 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/IdentifierExpr.cpp (renamed from source/gameengine/Expressions/IdentifierExpr.cpp) | 2 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/IfExpr.cpp (renamed from source/gameengine/Expressions/IfExpr.cpp) | 8 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/InputParser.cpp (renamed from source/gameengine/Expressions/InputParser.cpp) | 26 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/IntValue.cpp (renamed from source/gameengine/Expressions/IntValue.cpp) | 12 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/ListValue.cpp (renamed from source/gameengine/Expressions/ListValue.cpp) | 19 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/Operator1Expr.cpp (renamed from source/gameengine/Expressions/Operator1Expr.cpp) | 4 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/Operator2Expr.cpp (renamed from source/gameengine/Expressions/Operator2Expr.cpp) | 6 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/PyObjectPlus.cpp (renamed from source/gameengine/Expressions/PyObjectPlus.cpp) | 25 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/PythonCallBack.cpp | 119 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/StringValue.cpp (renamed from source/gameengine/Expressions/StringValue.cpp) | 8 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/Value.cpp (renamed from source/gameengine/Expressions/Value.cpp) | 20 | ||||
-rw-r--r-- | source/gameengine/Expressions/intern/VectorValue.cpp (renamed from source/gameengine/Expressions/VectorValue.cpp) | 10 |
44 files changed, 435 insertions, 442 deletions
diff --git a/source/gameengine/Expressions/CMakeLists.txt b/source/gameengine/Expressions/CMakeLists.txt index 6907f314503..6ab4d3fdacc 100644 --- a/source/gameengine/Expressions/CMakeLists.txt +++ b/source/gameengine/Expressions/CMakeLists.txt @@ -36,47 +36,53 @@ set(INC_SYS ) set(SRC - BoolValue.cpp - ConstExpr.cpp - EXP_C-Api.cpp - EmptyValue.cpp - ErrorValue.cpp - Expression.cpp - FloatValue.cpp - IdentifierExpr.cpp - IfExpr.cpp - InputParser.cpp - IntValue.cpp - KX_HashedPtr.cpp - ListValue.cpp - Operator1Expr.cpp - Operator2Expr.cpp - PyObjectPlus.cpp - StringValue.cpp - Value.cpp - VectorValue.cpp + intern/BoolValue.cpp + intern/ConstExpr.cpp + intern/EmptyValue.cpp + intern/ErrorValue.cpp + intern/Expression.cpp + intern/FloatValue.cpp + intern/IdentifierExpr.cpp + intern/IfExpr.cpp + intern/InputParser.cpp + intern/IntValue.cpp + intern/HashedPtr.cpp + intern/ListValue.cpp + intern/Operator1Expr.cpp + intern/Operator2Expr.cpp + intern/PyObjectPlus.cpp + intern/StringValue.cpp + intern/Value.cpp + intern/VectorValue.cpp - BoolValue.h - ConstExpr.h - EXP_C-Api.h - EmptyValue.h - ErrorValue.h - Expression.h - FloatValue.h - IdentifierExpr.h - IfExpr.h - InputParser.h - IntValue.h - KX_HashedPtr.h - KX_Python.h - ListValue.h - Operator1Expr.h - Operator2Expr.h - PyObjectPlus.h - StringValue.h - Value.h - VectorValue.h - VoidValue.h + EXP_BoolValue.h + EXP_ConstExpr.h + EXP_EmptyValue.h + EXP_ErrorValue.h + EXP_Expression.h + EXP_FloatValue.h + EXP_HashedPtr.h + EXP_IdentifierExpr.h + EXP_IfExpr.h + EXP_InputParser.h + EXP_IntValue.h + EXP_ListValue.h + EXP_Operator1Expr.h + EXP_Operator2Expr.h + EXP_PyObjectPlus.h + EXP_Python.h + EXP_StringValue.h + EXP_Value.h + EXP_VectorValue.h + EXP_VoidValue.h ) +if(WITH_PYTHON) + list(APPEND SRC + intern/PythonCallBack.cpp + + EXP_PythonCallBack.h + ) +endif() + blender_add_lib(ge_logic_expressions "${SRC}" "${INC}" "${INC_SYS}") diff --git a/source/gameengine/Expressions/BoolValue.h b/source/gameengine/Expressions/EXP_BoolValue.h index 161d6112f68..98ba1d75e52 100644 --- a/source/gameengine/Expressions/BoolValue.h +++ b/source/gameengine/Expressions/EXP_BoolValue.h @@ -12,14 +12,14 @@ * */ -/** \file BoolValue.h +/** \file EXP_BoolValue.h * \ingroup expressions */ -#ifndef __BOOLVALUE_H__ -#define __BOOLVALUE_H__ +#ifndef __EXP_BOOLVALUE_H__ +#define __EXP_BOOLVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" /** * Smart Boolean Value class. @@ -62,4 +62,4 @@ private: #endif }; -#endif /* __BOOLVALUE_H__ */ +#endif /* __EXP_BOOLVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_C-Api.cpp b/source/gameengine/Expressions/EXP_C-Api.cpp deleted file mode 100644 index 2822fd8f6de..00000000000 --- a/source/gameengine/Expressions/EXP_C-Api.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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 2 - * 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, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file gameengine/Expressions/EXP_C-Api.cpp - * \ingroup expressions - */ - -#include "EXP_C-Api.h" -#include "IntValue.h" -#include "BoolValue.h" -#include "StringValue.h" -#include "ErrorValue.h" -#include "InputParser.h" - -EXP_ValueHandle EXP_CreateInt(int innie) -{ - return (EXP_ValueHandle) new CIntValue(innie); -} - - - -EXP_ValueHandle EXP_CreateBool(int innie) -{ - return (EXP_ValueHandle) new CBoolValue(innie!=0); -} - - - -EXP_ValueHandle EXP_CreateString(const char* str) -{ - - return (EXP_ValueHandle) new CStringValue(str,""); -} - - - -void EXP_SetName(EXP_ValueHandle inval,const char* newname) -{ - ((CValue*) inval)->SetName(newname); -} - - - -/* calculate expression from inputtext */ -EXP_ValueHandle EXP_ParseInput(const char* inputtext) -{ - CValue* resultval=NULL; - CParser parser; - CExpression* expr = parser.ProcessText(inputtext); - if (expr) - { - resultval = expr->Calculate(); - expr->Release(); - } - else - { - resultval = new CErrorValue("couldn't parsetext"); - } - - return (EXP_ValueHandle) resultval; -} - - - -void EXP_ReleaseValue(EXP_ValueHandle inval) -{ - ((CValue*) inval)->Release(); -} - - - -int EXP_IsValid(EXP_ValueHandle inval) -{ - return !((CValue*) inval)->IsError(); -} - - - -/* assign property 'propval' to 'destinationval' */ -void EXP_SetProperty(EXP_ValueHandle destinationval, - const char *propname, - EXP_ValueHandle propval) -{ - ((CValue*) destinationval)->SetProperty(propname,(CValue*)propval); -} - - - -const char* EXP_GetText(EXP_ValueHandle inval) -{ - return ((CValue*) inval)->GetText(); -} - - - -EXP_ValueHandle EXP_GetProperty(EXP_ValueHandle inval,const char* propname) -{ - return (EXP_ValueHandle) ((CValue*)inval)->GetProperty(propname); -} diff --git a/source/gameengine/Expressions/EXP_C-Api.h b/source/gameengine/Expressions/EXP_C-Api.h deleted file mode 100644 index d73b0a209d4..00000000000 --- a/source/gameengine/Expressions/EXP_C-Api.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * 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 2 - * 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, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file EXP_C-Api.h - * \ingroup expressions - */ - -#ifndef __EXP_C_API_H__ -#define __EXP_C_API_H__ - -#define EXP_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name - -EXP_DECLARE_HANDLE(EXP_ValueHandle); -EXP_DECLARE_HANDLE(EXP_ExpressionHandle); - - -#ifdef __cplusplus -extern "C" { -#endif - -extern EXP_ValueHandle EXP_CreateInt(int innie); -extern EXP_ValueHandle EXP_CreateBool(int innie); -extern EXP_ValueHandle EXP_CreateString(const char* str); -extern void EXP_SetName(EXP_ValueHandle,const char* newname); - -/* calculate expression from inputtext */ -extern EXP_ValueHandle EXP_ParseInput(const char* inputtext); -extern void EXP_ReleaseValue(EXP_ValueHandle); -extern int EXP_IsValid(EXP_ValueHandle); - -/* assign property 'propval' to 'destinationval' */ -extern void EXP_SetProperty(EXP_ValueHandle destinationval, const char *propname, EXP_ValueHandle propval); - -/* returns NULL if property doesn't exist */ -extern EXP_ValueHandle EXP_GetProperty(EXP_ValueHandle inval,const char* propname); - -const char* EXP_GetText(EXP_ValueHandle); - -#ifdef __cplusplus -} -#endif - -#endif /* __EXP_C_API_H__ */ diff --git a/source/gameengine/Expressions/ConstExpr.h b/source/gameengine/Expressions/EXP_ConstExpr.h index 768f2bbd10e..b4456dacdf3 100644 --- a/source/gameengine/Expressions/ConstExpr.h +++ b/source/gameengine/Expressions/EXP_ConstExpr.h @@ -12,15 +12,15 @@ * */ -/** \file ConstExpr.h +/** \file EXP_ConstExpr.h * \ingroup expressions */ -#ifndef __CONSTEXPR_H__ -#define __CONSTEXPR_H__ +#ifndef __EXP_CONSTEXPR_H__ +#define __EXP_CONSTEXPR_H__ -#include "Expression.h" -#include "Value.h" // Added by ClassView +#include "EXP_Expression.h" +#include "EXP_Value.h" // Added by ClassView class CConstExpr : public CExpression { @@ -51,4 +51,4 @@ private: #endif }; -#endif /* __CONSTEXPR_H__ */ +#endif /* __EXP_CONSTEXPR_H__ */ diff --git a/source/gameengine/Expressions/EmptyValue.h b/source/gameengine/Expressions/EXP_EmptyValue.h index 88ef206f0f0..d23addb9f9f 100644 --- a/source/gameengine/Expressions/EmptyValue.h +++ b/source/gameengine/Expressions/EXP_EmptyValue.h @@ -12,14 +12,14 @@ * */ -/** \file EmptyValue.h +/** \file EXP_EmptyValue.h * \ingroup expressions */ -#ifndef __EMPTYVALUE_H__ -#define __EMPTYVALUE_H__ +#ifndef __EXP_EMPTYVALUE_H__ +#define __EXP_EMPTYVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" class CListValue; @@ -46,4 +46,4 @@ public: #endif }; -#endif /* __EMPTYVALUE_H__ */ +#endif /* __EXP_EMPTYVALUE_H__ */ diff --git a/source/gameengine/Expressions/ErrorValue.h b/source/gameengine/Expressions/EXP_ErrorValue.h index 61c72151f40..a6f91ca200a 100644 --- a/source/gameengine/Expressions/ErrorValue.h +++ b/source/gameengine/Expressions/EXP_ErrorValue.h @@ -12,14 +12,14 @@ * */ -/** \file ErrorValue.h +/** \file EXP_ErrorValue.h * \ingroup expressions */ -#ifndef __ERRORVALUE_H__ -#define __ERRORVALUE_H__ +#ifndef __EXP_ERRORVALUE_H__ +#define __EXP_ERRORVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" class CErrorValue : public CPropValue { @@ -44,4 +44,4 @@ private: #endif }; -#endif /* __ERRORVALUE_H__ */ +#endif /* __EXP_ERRORVALUE_H__ */ diff --git a/source/gameengine/Expressions/Expression.h b/source/gameengine/Expressions/EXP_Expression.h index 9a4f1f93284..66a6e9476ff 100644 --- a/source/gameengine/Expressions/Expression.h +++ b/source/gameengine/Expressions/EXP_Expression.h @@ -12,14 +12,14 @@ * */ -/** \file Expression.h +/** \file EXP_Expression.h * \ingroup expressions */ -#ifndef __EXPRESSION_H__ -#define __EXPRESSION_H__ +#ifndef __EXP_EXPRESSION_H__ +#define __EXP_EXPRESSION_H__ -#include "Value.h" +#include "EXP_Value.h" //extern int gRefCountExpr; // only for debugging purposes (detect mem.leaks) @@ -146,4 +146,4 @@ protected: #endif }; -#endif /* __EXPRESSION_H__ */ +#endif /* __EXP_EXPRESSION_H__ */ diff --git a/source/gameengine/Expressions/FloatValue.h b/source/gameengine/Expressions/EXP_FloatValue.h index 379c3e951bc..3c16c57d16d 100644 --- a/source/gameengine/Expressions/FloatValue.h +++ b/source/gameengine/Expressions/EXP_FloatValue.h @@ -12,14 +12,14 @@ * */ -/** \file FloatValue.h +/** \file EXP_FloatValue.h * \ingroup expressions */ -#ifndef __FLOATVALUE_H__ -#define __FLOATVALUE_H__ +#ifndef __EXP_FLOATVALUE_H__ +#define __EXP_FLOATVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" class CFloatValue : public CPropValue { @@ -55,4 +55,4 @@ protected: #endif }; -#endif /* __FLOATVALUE_H__ */ +#endif /* __EXP_FLOATVALUE_H__ */ diff --git a/source/gameengine/Expressions/KX_HashedPtr.h b/source/gameengine/Expressions/EXP_HashedPtr.h index acd9d4daafa..7c7c5f6e5ec 100644 --- a/source/gameengine/Expressions/KX_HashedPtr.h +++ b/source/gameengine/Expressions/EXP_HashedPtr.h @@ -25,19 +25,17 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file KX_HashedPtr.h +/** \file EXP_HashedPtr.h * \ingroup expressions */ -#ifndef __KX_HASHEDPTR_H__ -#define __KX_HASHEDPTR_H__ +#ifndef __EXP_HASHEDPTR_H__ +#define __EXP_HASHEDPTR_H__ #ifdef WITH_CXX_GUARDEDALLOC #include "MEM_guardedalloc.h" #endif -unsigned int KX_Hash(void *inDWord); - class CHashedPtr { void* m_valptr; @@ -58,4 +56,4 @@ public: #endif }; -#endif /* __KX_HASHEDPTR_H__ */ +#endif /* __EXP_HASHEDPTR_H__ */ diff --git a/source/gameengine/Expressions/IdentifierExpr.h b/source/gameengine/Expressions/EXP_IdentifierExpr.h index 26eb3691378..96ef3677cf3 100644 --- a/source/gameengine/Expressions/IdentifierExpr.h +++ b/source/gameengine/Expressions/EXP_IdentifierExpr.h @@ -25,14 +25,14 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file IdentifierExpr.h +/** \file EXP_IdentifierExpr.h * \ingroup expressions */ -#ifndef __IDENTIFIEREXPR_H__ -#define __IDENTIFIEREXPR_H__ +#ifndef __EXP_IDENTIFIEREXPR_H__ +#define __EXP_IDENTIFIEREXPR_H__ -#include "Expression.h" +#include "EXP_Expression.h" class CIdentifierExpr : public CExpression { @@ -56,4 +56,4 @@ public: #endif }; -#endif /* __IDENTIFIEREXPR_H__ */ +#endif /* __EXP_IDENTIFIEREXPR_H__ */ diff --git a/source/gameengine/Expressions/IfExpr.h b/source/gameengine/Expressions/EXP_IfExpr.h index 80e35471d82..43b4b8faf53 100644 --- a/source/gameengine/Expressions/IfExpr.h +++ b/source/gameengine/Expressions/EXP_IfExpr.h @@ -12,14 +12,14 @@ * */ -/** \file IfExpr.h +/** \file EXP_IfExpr.h * \ingroup expressions */ -#ifndef __IFEXPR_H__ -#define __IFEXPR_H__ +#ifndef __EXP_IFEXPR_H__ +#define __EXP_IFEXPR_H__ -#include "Expression.h" +#include "EXP_Expression.h" class CIfExpr : public CExpression { @@ -51,4 +51,4 @@ public: #endif }; -#endif /* __IFEXPR_H__ */ +#endif /* __EXP_IFEXPR_H__ */ diff --git a/source/gameengine/Expressions/InputParser.h b/source/gameengine/Expressions/EXP_InputParser.h index 50bb1ae2f6e..80471009a16 100644 --- a/source/gameengine/Expressions/InputParser.h +++ b/source/gameengine/Expressions/EXP_InputParser.h @@ -14,15 +14,15 @@ * */ -/** \file InputParser.h +/** \file EXP_InputParser.h * \ingroup expressions */ -#ifndef __INPUTPARSER_H__ -#define __INPUTPARSER_H__ +#ifndef __EXP_INPUTPARSER_H__ +#define __EXP_INPUTPARSER_H__ class CParser; -#include "Expression.h" +#include "EXP_Expression.h" class CParser @@ -114,5 +114,5 @@ private: #endif }; -#endif +#endif /* __EXP_INPUTPARSER_H__ */ diff --git a/source/gameengine/Expressions/IntValue.h b/source/gameengine/Expressions/EXP_IntValue.h index 6da975f4f7f..a1cd96a888e 100644 --- a/source/gameengine/Expressions/IntValue.h +++ b/source/gameengine/Expressions/EXP_IntValue.h @@ -12,15 +12,15 @@ * */ -/** \file IntValue.h +/** \file EXP_IntValue.h * \ingroup expressions */ -#ifndef __INTVALUE_H__ -#define __INTVALUE_H__ +#ifndef __EXP_INTVALUE_H__ +#define __EXP_INTVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" typedef long long cInt; @@ -70,4 +70,4 @@ private: #endif }; -#endif /* __INTVALUE_H__ */ +#endif /* __EXP_INTVALUE_H__ */ diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/EXP_ListValue.h index bb188179836..f5421066f62 100644 --- a/source/gameengine/Expressions/ListValue.h +++ b/source/gameengine/Expressions/EXP_ListValue.h @@ -12,14 +12,14 @@ * */ -/** \file ListValue.h +/** \file EXP_ListValue.h * \ingroup expressions */ -#ifndef __LISTVALUE_H__ -#define __LISTVALUE_H__ +#ifndef __EXP_LISTVALUE_H__ +#define __EXP_LISTVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" class CListValue : public CPropValue { @@ -88,5 +88,5 @@ private: bool m_bReleaseContents; }; -#endif /* __LISTVALUE_H__ */ +#endif /* __EXP_LISTVALUE_H__ */ diff --git a/source/gameengine/Expressions/Operator1Expr.h b/source/gameengine/Expressions/EXP_Operator1Expr.h index 3dd76f773f2..9a05ce9c0c4 100644 --- a/source/gameengine/Expressions/Operator1Expr.h +++ b/source/gameengine/Expressions/EXP_Operator1Expr.h @@ -12,14 +12,14 @@ * */ -/** \file Operator1Expr.h +/** \file EXP_Operator1Expr.h * \ingroup expressions */ -#ifndef __OPERATOR1EXPR_H__ -#define __OPERATOR1EXPR_H__ +#ifndef __EXP_OPERATOR1EXPR_H__ +#define __EXP_OPERATOR1EXPR_H__ -#include "Expression.h" +#include "EXP_Expression.h" class COperator1Expr : public CExpression { @@ -56,4 +56,4 @@ private: #endif }; -#endif /* __OPERATOR1EXPR_H__ */ +#endif /* __EXP_OPERATOR1EXPR_H__ */ diff --git a/source/gameengine/Expressions/Operator2Expr.h b/source/gameengine/Expressions/EXP_Operator2Expr.h index 8c30b7cd634..cd7a492fde0 100644 --- a/source/gameengine/Expressions/Operator2Expr.h +++ b/source/gameengine/Expressions/EXP_Operator2Expr.h @@ -12,16 +12,16 @@ * */ -/** \file Operator2Expr.h +/** \file EXP_Operator2Expr.h * \ingroup expressions */ -#ifndef __OPERATOR2EXPR_H__ -#define __OPERATOR2EXPR_H__ +#ifndef __EXP_OPERATOR2EXPR_H__ +#define __EXP_OPERATOR2EXPR_H__ -#include "Expression.h" -#include "Value.h" // Added by ClassView +#include "EXP_Expression.h" +#include "EXP_Value.h" // Added by ClassView class COperator2Expr : public CExpression { @@ -62,5 +62,5 @@ private: #endif }; -#endif /* __OPERATOR2EXPR_H__ */ +#endif /* __EXP_OPERATOR2EXPR_H__ */ diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/EXP_PyObjectPlus.h index e2e7c248795..dd612a08494 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/EXP_PyObjectPlus.h @@ -25,12 +25,12 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file PyObjectPlus.h +/** \file EXP_PyObjectPlus.h * \ingroup expressions */ -#ifndef __PYOBJECTPLUS_H__ -#define __PYOBJECTPLUS_H__ +#ifndef __EXP_PYOBJECTPLUS_H__ +#define __EXP_PYOBJECTPLUS_H__ /* for now keep weakrefs optional */ #define USE_WEAKREFS @@ -40,7 +40,7 @@ #error Must be compiled with C++ #endif -#include "KX_Python.h" +#include "EXP_Python.h" #include "STR_String.h" #include "MT_Vector3.h" #include "SG_QList.h" @@ -65,21 +65,21 @@ typedef struct { #define ShowDeprecationWarning(old_way, new_way) \ { \ static WarnLink wlink = {false, NULL}; \ - if ((m_ignore_deprecation_warnings || wlink.warn_done)==0) \ + if ((PyObjectPlus::m_ignore_deprecation_warnings || wlink.warn_done)==0) \ { \ - ShowDeprecationWarning_func(old_way, new_way); \ + PyObjectPlus::ShowDeprecationWarning_func(old_way, new_way); \ \ - WarnLink *wlink_last= GetDeprecationWarningLinkLast(); \ + WarnLink *wlink_last= PyObjectPlus::GetDeprecationWarningLinkLast(); \ wlink.warn_done = true; \ wlink.link = NULL; \ \ if(wlink_last) { \ wlink_last->link= (void *)&(wlink); \ - SetDeprecationWarningLinkLast(&(wlink)); \ + PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ } \ else { \ - SetDeprecationWarningFirst(&(wlink)); \ - SetDeprecationWarningLinkLast(&(wlink)); \ + PyObjectPlus::SetDeprecationWarningFirst(&(wlink)); \ + PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ } \ } \ } \ @@ -111,6 +111,8 @@ typedef struct PyObjectPlus_Proxy { /* Opposite of BGE_PROXY_REF */ #define BGE_PROXY_FROM_REF(_self) (((PyObjectPlus *)_self)->GetProxy()) +/* Same as 'BGE_PROXY_REF' but doesn't incref. */ +#define BGE_PROXY_FROM_REF_BORROW(_self) _bge_proxy_from_ref_borrow((void *)_self) // This must be the first line of each @@ -631,6 +633,16 @@ public: #ifdef WITH_PYTHON PyObject *PyUnicode_From_STR_String(const STR_String& str); + +inline PyObject *_bge_proxy_from_ref_borrow(void *self_v) +{ + PyObject *self_proxy = BGE_PROXY_FROM_REF(self_v); + /* this is typically _very_ bad practice, + * however we know the proxy is owned by 'self_v' */ + self_proxy->ob_refcnt--; + return self_proxy; +} + #endif -#endif /* __PYOBJECTPLUS_H__ */ +#endif /* __EXP_PYOBJECTPLUS_H__ */ diff --git a/source/gameengine/Expressions/KX_Python.h b/source/gameengine/Expressions/EXP_Python.h index 62dd9a13dd4..f904151085e 100644 --- a/source/gameengine/Expressions/KX_Python.h +++ b/source/gameengine/Expressions/EXP_Python.h @@ -25,12 +25,12 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file KX_Python.h +/** \file EXP_Python.h * \ingroup expressions */ -#ifndef __KX_PYTHON_H__ -#define __KX_PYTHON_H__ +#ifndef __EXP_PYTHON_H__ +#define __EXP_PYTHON_H__ //#define USE_DL_EXPORT @@ -79,4 +79,4 @@ #undef toupper #endif -#endif /* __KX_PYTHON_H__ */ +#endif /* __EXP_PYTHON_H__ */ diff --git a/source/gameengine/Expressions/EXP_PythonCallBack.h b/source/gameengine/Expressions/EXP_PythonCallBack.h new file mode 100644 index 00000000000..f0cbcac0c6f --- /dev/null +++ b/source/gameengine/Expressions/EXP_PythonCallBack.h @@ -0,0 +1,40 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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 2 + * 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, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Porteries Tristan. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file EXP_PythonCallBack.h + * \ingroup expressions + */ + +#ifndef __EXP_PYTHON_CALLBACK_H__ +#define __EXP_PYTHON_CALLBACK_H__ + +#include "EXP_Python.h" + +/** Execute each functions with at least one argument + * \param functionlist The python list which contains callbacks. + * \param arglist The first item in the tuple to execute callbacks (can be NULL for no arguments). + * \param minargcount The minimum of quantity of arguments possible. + * \param maxargcount The maximum of quantity of arguments possible. + */ +void RunPythonCallBackList(PyObject *functionlist, PyObject **arglist, unsigned int minargcount, unsigned int maxargcount); + +#endif // __EXP_PYTHON_CALLBACK_H__ diff --git a/source/gameengine/Expressions/StringValue.h b/source/gameengine/Expressions/EXP_StringValue.h index cb60600ad88..ca59ebf1f82 100644 --- a/source/gameengine/Expressions/StringValue.h +++ b/source/gameengine/Expressions/EXP_StringValue.h @@ -12,14 +12,14 @@ * */ -/** \file StringValue.h +/** \file EXP_StringValue.h * \ingroup expressions */ -#ifndef __STRINGVALUE_H__ -#define __STRINGVALUE_H__ +#ifndef __EXP_STRINGVALUE_H__ +#define __EXP_STRINGVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" class CStringValue : public CPropValue { @@ -58,4 +58,4 @@ private: #endif }; -#endif /* __STRINGVALUE_H__ */ +#endif /* __EXP_STRINGVALUE_H__ */ diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/EXP_Value.h index c7e9a40a059..014fc59405f 100644 --- a/source/gameengine/Expressions/Value.h +++ b/source/gameengine/Expressions/EXP_Value.h @@ -12,12 +12,12 @@ * */ -/** \file Value.h +/** \file EXP_Value.h * \ingroup expressions */ -#ifndef __VALUE_H__ -#define __VALUE_H__ +#ifndef __EXP_VALUE_H__ +#define __EXP_VALUE_H__ #ifdef _MSC_VER # pragma warning (disable:4786) @@ -159,7 +159,7 @@ public: }; -#include "PyObjectPlus.h" +#include "EXP_PyObjectPlus.h" #ifdef WITH_PYTHON #include "object.h" #endif @@ -429,4 +429,4 @@ protected: #endif }; -#endif /* __VALUE_H__ */ +#endif /* __EXP_VALUE_H__ */ diff --git a/source/gameengine/Expressions/VectorValue.h b/source/gameengine/Expressions/EXP_VectorValue.h index 717fa68f6dc..d87d5097156 100644 --- a/source/gameengine/Expressions/VectorValue.h +++ b/source/gameengine/Expressions/EXP_VectorValue.h @@ -12,14 +12,14 @@ * */ -/** \file VectorValue.h +/** \file EXP_VectorValue.h * \ingroup expressions */ -#ifndef __VECTORVALUE_H__ -#define __VECTORVALUE_H__ +#ifndef __EXP_VECTORVALUE_H__ +#define __EXP_VECTORVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" #define KX_X 0 #define KX_Y 1 @@ -91,4 +91,4 @@ protected: #endif }; -#endif /* __VECTORVALUE_H__ */ +#endif /* __EXP_VECTORVALUE_H__ */ diff --git a/source/gameengine/Expressions/VoidValue.h b/source/gameengine/Expressions/EXP_VoidValue.h index 4f74910dd8a..8b2c29488d7 100644 --- a/source/gameengine/Expressions/VoidValue.h +++ b/source/gameengine/Expressions/EXP_VoidValue.h @@ -27,14 +27,14 @@ * ***** END GPL LICENSE BLOCK ***** */ -/** \file VoidValue.h +/** \file EXP_VoidValue.h * \ingroup expressions */ -#ifndef __VOIDVALUE_H__ -#define __VOIDVALUE_H__ +#ifndef __EXP_VOIDVALUE_H__ +#define __EXP_VOIDVALUE_H__ -#include "Value.h" +#include "EXP_Value.h" // // Void value, used to transport *any* type of data @@ -78,4 +78,4 @@ public: #endif }; -#endif /* __VOIDVALUE_H__ */ +#endif /* __EXP_VOIDVALUE_H__ */ diff --git a/source/gameengine/Expressions/SConscript b/source/gameengine/Expressions/SConscript index 48102e5ba3c..b66d36c2080 100644 --- a/source/gameengine/Expressions/SConscript +++ b/source/gameengine/Expressions/SConscript @@ -27,7 +27,7 @@ Import ('env') -sources = env.Glob('*.cpp') +sources = env.Glob('intern/*.cpp') incs = [ '.', diff --git a/source/gameengine/Expressions/BoolValue.cpp b/source/gameengine/Expressions/intern/BoolValue.cpp index 9ff53395056..1523a9212ba 100644 --- a/source/gameengine/Expressions/BoolValue.cpp +++ b/source/gameengine/Expressions/intern/BoolValue.cpp @@ -16,10 +16,10 @@ * */ -#include "BoolValue.h" -#include "StringValue.h" -#include "ErrorValue.h" -#include "VoidValue.h" +#include "EXP_BoolValue.h" +#include "EXP_StringValue.h" +#include "EXP_ErrorValue.h" +#include "EXP_VoidValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/ConstExpr.cpp b/source/gameengine/Expressions/intern/ConstExpr.cpp index c41cf5a54f5..597427ecfe5 100644 --- a/source/gameengine/Expressions/ConstExpr.cpp +++ b/source/gameengine/Expressions/intern/ConstExpr.cpp @@ -16,9 +16,9 @@ * */ -#include "Value.h" // for precompiled header -#include "ConstExpr.h" -#include "VectorValue.h" +#include "EXP_Value.h" // for precompiled header +#include "EXP_ConstExpr.h" +#include "EXP_VectorValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/EmptyValue.cpp b/source/gameengine/Expressions/intern/EmptyValue.cpp index f8e72181ed7..9227626777d 100644 --- a/source/gameengine/Expressions/EmptyValue.cpp +++ b/source/gameengine/Expressions/intern/EmptyValue.cpp @@ -16,13 +16,13 @@ * */ -#include "EmptyValue.h" -#include "IntValue.h" -#include "FloatValue.h" -#include "StringValue.h" -#include "ErrorValue.h" -#include "ListValue.h" -#include "VoidValue.h" +#include "EXP_EmptyValue.h" +#include "EXP_IntValue.h" +#include "EXP_FloatValue.h" +#include "EXP_StringValue.h" +#include "EXP_ErrorValue.h" +#include "EXP_ListValue.h" +#include "EXP_VoidValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/ErrorValue.cpp b/source/gameengine/Expressions/intern/ErrorValue.cpp index 46e09b9073f..c03ceb88073 100644 --- a/source/gameengine/Expressions/ErrorValue.cpp +++ b/source/gameengine/Expressions/intern/ErrorValue.cpp @@ -15,7 +15,7 @@ * */ -#include "ErrorValue.h" +#include "EXP_ErrorValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/Expression.cpp b/source/gameengine/Expressions/intern/Expression.cpp index 2428df977d3..6a98a15aa12 100644 --- a/source/gameengine/Expressions/Expression.cpp +++ b/source/gameengine/Expressions/intern/Expression.cpp @@ -15,8 +15,8 @@ * */ -#include "Expression.h" -#include "ErrorValue.h" +#include "EXP_Expression.h" +#include "EXP_ErrorValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/FloatValue.cpp b/source/gameengine/Expressions/intern/FloatValue.cpp index 4d6f3f467eb..0f86a429d81 100644 --- a/source/gameengine/Expressions/FloatValue.cpp +++ b/source/gameengine/Expressions/intern/FloatValue.cpp @@ -15,12 +15,12 @@ * */ -#include "FloatValue.h" -#include "IntValue.h" -#include "StringValue.h" -#include "BoolValue.h" -#include "ErrorValue.h" -#include "VoidValue.h" +#include "EXP_FloatValue.h" +#include "EXP_IntValue.h" +#include "EXP_StringValue.h" +#include "EXP_BoolValue.h" +#include "EXP_ErrorValue.h" +#include "EXP_VoidValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/KX_HashedPtr.cpp b/source/gameengine/Expressions/intern/HashedPtr.cpp index bd42892cc8d..005ac16b231 100644 --- a/source/gameengine/Expressions/KX_HashedPtr.cpp +++ b/source/gameengine/Expressions/intern/HashedPtr.cpp @@ -30,16 +30,22 @@ */ -#include "KX_HashedPtr.h" +#include "EXP_HashedPtr.h" -unsigned int KX_Hash(void *inDWord) + +CHashedPtr::CHashedPtr(void* val) : m_valptr(val) +{ +} + + +unsigned int CHashedPtr::hash() const { #if defined(_WIN64) && !defined(FREE_WINDOWS64) - unsigned __int64 key = (unsigned __int64)inDWord; + unsigned __int64 key = (unsigned __int64)m_valptr; #elif defined(FREE_WINDOWS64) - unsigned long long key = (unsigned long long)inDWord; + unsigned long long key = (unsigned long long)m_valptr; #else - unsigned long key = (unsigned long)inDWord; + unsigned long key = (unsigned long)m_valptr; #endif key += ~(key << 16); @@ -51,15 +57,3 @@ unsigned int KX_Hash(void *inDWord) return (unsigned int)(key & 0xffffffff); } - - -CHashedPtr::CHashedPtr(void* val) : m_valptr(val) -{ -} - - - -unsigned int CHashedPtr::hash() const -{ - return KX_Hash(m_valptr); -} diff --git a/source/gameengine/Expressions/IdentifierExpr.cpp b/source/gameengine/Expressions/intern/IdentifierExpr.cpp index c9e053574cd..8fbbf41cd63 100644 --- a/source/gameengine/Expressions/IdentifierExpr.cpp +++ b/source/gameengine/Expressions/intern/IdentifierExpr.cpp @@ -30,7 +30,7 @@ */ -#include "IdentifierExpr.h" +#include "EXP_IdentifierExpr.h" CIdentifierExpr::CIdentifierExpr(const STR_String& identifier,CValue* id_context) :m_identifier(identifier) diff --git a/source/gameengine/Expressions/IfExpr.cpp b/source/gameengine/Expressions/intern/IfExpr.cpp index 152ca8704ce..b4e2fe7315b 100644 --- a/source/gameengine/Expressions/IfExpr.cpp +++ b/source/gameengine/Expressions/intern/IfExpr.cpp @@ -15,10 +15,10 @@ * */ -#include "IfExpr.h" -#include "EmptyValue.h" -#include "ErrorValue.h" -#include "BoolValue.h" +#include "EXP_IfExpr.h" +#include "EXP_EmptyValue.h" +#include "EXP_ErrorValue.h" +#include "EXP_BoolValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/InputParser.cpp b/source/gameengine/Expressions/intern/InputParser.cpp index 4ba3585455b..e8cc7fba284 100644 --- a/source/gameengine/Expressions/InputParser.cpp +++ b/source/gameengine/Expressions/intern/InputParser.cpp @@ -19,23 +19,23 @@ #include "MT_assert.h" -#include "Value.h" -#include "InputParser.h" -#include "ErrorValue.h" -#include "IntValue.h" -#include "StringValue.h" -#include "FloatValue.h" -#include "BoolValue.h" -#include "EmptyValue.h" -#include "ConstExpr.h" -#include "Operator2Expr.h" -#include "Operator1Expr.h" -#include "IdentifierExpr.h" +#include "EXP_Value.h" +#include "EXP_InputParser.h" +#include "EXP_ErrorValue.h" +#include "EXP_IntValue.h" +#include "EXP_StringValue.h" +#include "EXP_FloatValue.h" +#include "EXP_BoolValue.h" +#include "EXP_EmptyValue.h" +#include "EXP_ConstExpr.h" +#include "EXP_Operator2Expr.h" +#include "EXP_Operator1Expr.h" +#include "EXP_IdentifierExpr.h" // this is disable at the moment, I expected a memleak from it, but the error-cleanup was the reason // well, looks we don't need it anyway, until maybe the Curved Surfaces are integrated into CSG // cool things like (IF(LOD==1,CCurvedValue,IF(LOD==2,CCurvedValue2)) etc... -#include "IfExpr.h" +#include "EXP_IfExpr.h" #if (defined(WIN32) || defined(WIN64)) && !defined(FREE_WINDOWS) #define strcasecmp _stricmp diff --git a/source/gameengine/Expressions/IntValue.cpp b/source/gameengine/Expressions/intern/IntValue.cpp index 82d2e94dbb0..25aff5b32ab 100644 --- a/source/gameengine/Expressions/IntValue.cpp +++ b/source/gameengine/Expressions/intern/IntValue.cpp @@ -17,12 +17,12 @@ #include <stdio.h> -#include "IntValue.h" -#include "ErrorValue.h" -#include "FloatValue.h" -#include "BoolValue.h" -#include "StringValue.h" -#include "VoidValue.h" +#include "EXP_IntValue.h" +#include "EXP_ErrorValue.h" +#include "EXP_FloatValue.h" +#include "EXP_BoolValue.h" +#include "EXP_StringValue.h" +#include "EXP_VoidValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/intern/ListValue.cpp index 75e3b490505..557ce7be300 100644 --- a/source/gameengine/Expressions/ListValue.cpp +++ b/source/gameengine/Expressions/intern/ListValue.cpp @@ -19,11 +19,11 @@ #include <stdio.h> -#include "ListValue.h" -#include "StringValue.h" -#include "VoidValue.h" +#include "EXP_ListValue.h" +#include "EXP_StringValue.h" +#include "EXP_VoidValue.h" #include <algorithm> -#include "BoolValue.h" +#include "EXP_BoolValue.h" #include "BLI_sys_types.h" /* for intptr_t support */ @@ -432,7 +432,7 @@ static PyObject *listvalue_buffer_concat(PyObject *self, PyObject *other) for (i=0;i<numitems;i++) { - listitemval = listval->ConvertPythonToValue(PyList_GetItem(other,i), true, "cList + pyList: CListValue, "); + listitemval = listval->ConvertPythonToValue(PyList_GET_ITEM(other, i), true, "cList + pyList: CListValue, "); if (listitemval) { listval_new->SetValue(i+numitems_orig, listitemval); @@ -583,7 +583,8 @@ PyObject *CListValue::Pyappend(PyObject *value) return NULL; if (!BGE_PROXY_PYOWNS(m_proxy)) { - PyErr_SetString(PyExc_TypeError, "CList.append(i): this CValueList is used internally for the game engine and can't be modified"); + PyErr_SetString(PyExc_TypeError, + "CList.append(i): internal values can't be modified"); return NULL; } @@ -594,6 +595,12 @@ PyObject *CListValue::Pyappend(PyObject *value) PyObject *CListValue::Pyreverse() { + if (!BGE_PROXY_PYOWNS(m_proxy)) { + PyErr_SetString(PyExc_TypeError, + "CList.reverse(): internal values can't be modified"); + return NULL; + } + std::reverse(m_pValueArray.begin(),m_pValueArray.end()); Py_RETURN_NONE; } diff --git a/source/gameengine/Expressions/Operator1Expr.cpp b/source/gameengine/Expressions/intern/Operator1Expr.cpp index b985f76825d..add0376f487 100644 --- a/source/gameengine/Expressions/Operator1Expr.cpp +++ b/source/gameengine/Expressions/intern/Operator1Expr.cpp @@ -15,8 +15,8 @@ * */ -#include "Operator1Expr.h" -#include "EmptyValue.h" +#include "EXP_Operator1Expr.h" +#include "EXP_EmptyValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/Operator2Expr.cpp b/source/gameengine/Expressions/intern/Operator2Expr.cpp index b03d00e7f77..0a7f30b8cc8 100644 --- a/source/gameengine/Expressions/Operator2Expr.cpp +++ b/source/gameengine/Expressions/intern/Operator2Expr.cpp @@ -19,9 +19,9 @@ // have to do the trick // when expression is cached, there will be a call to UpdateCalc() instead of Calc() -#include "Operator2Expr.h" -#include "StringValue.h" -#include "VoidValue.h" +#include "EXP_Operator2Expr.h" +#include "EXP_StringValue.h" +#include "EXP_VoidValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/intern/PyObjectPlus.cpp index c025d439fc0..de45bee76a7 100644 --- a/source/gameengine/Expressions/PyObjectPlus.cpp +++ b/source/gameengine/Expressions/intern/PyObjectPlus.cpp @@ -47,7 +47,7 @@ #include <stdlib.h> #include <stddef.h> -#include "PyObjectPlus.h" +#include "EXP_PyObjectPlus.h" #include "STR_String.h" #include "MT_Vector3.h" #include "MEM_guardedalloc.h" @@ -80,7 +80,7 @@ void PyObjectPlus::ProcessReplica() } /* Sometimes we might want to manually invalidate a BGE type even if - * it hasnt been released by the BGE, say for example when an object + * it hasn't been released by the BGE, say for example when an object * is removed from a scene, accessing it may cause problems. * * In this case the current proxy is made invalid, disowned, @@ -148,12 +148,18 @@ PyObject *PyObjectPlus::py_base_repr(PyObject *self) // This should be the ent PyObject *PyObjectPlus::py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyTypeObject *base_type; - PyObjectPlus_Proxy *base = NULL; - if (!PyArg_ParseTuple(args, "O:Base PyObjectPlus", &base)) + /* one or more args is needed */ + if (!PyTuple_GET_SIZE(args)) { + PyErr_SetString(PyExc_TypeError, + "Expected at least one argument"); return NULL; + } + + PyObjectPlus_Proxy *base = (PyObjectPlus_Proxy *)PyTuple_GET_ITEM(args, 0); - /* the 'base' PyObject may be subclassed (multiple times even) + /** + * the 'base' PyObject may be subclassed (multiple times even) * we need to find the first C++ defined class to check 'type' * is a subclass of the base arguments type. * @@ -162,12 +168,13 @@ PyObject *PyObjectPlus::py_base_new(PyTypeObject *type, PyObject *args, PyObject * eg. * * # CustomOb is called 'type' in this C code + * \code{.py} * class CustomOb(GameTypes.KX_GameObject): * pass * * # this calls py_base_new(...), the type of 'CustomOb' is checked to be a subclass of the 'cont.owner' type * ob = CustomOb(cont.owner) - * + * \endcode * */ base_type= Py_TYPE(base); while (base_type && !BGE_PROXY_CHECK_TYPE(base_type)) @@ -418,7 +425,7 @@ PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef * return NULL; } #ifdef USE_MATHUTILS - return Vector_CreatePyObject(val, attrdef->m_imax, Py_NEW, NULL); + return Vector_CreatePyObject(val, attrdef->m_imax, NULL); #else PyObject *resultlist = PyList_New(attrdef->m_imax); for (unsigned int i=0; i<attrdef->m_imax; i++) @@ -435,7 +442,7 @@ PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef * return NULL; } #ifdef USE_MATHUTILS - return Matrix_CreatePyObject(val, attrdef->m_imin, attrdef->m_imax, Py_WRAP, NULL); + return Matrix_CreatePyObject_wrap(val, attrdef->m_imin, attrdef->m_imax, NULL); #else PyObject *collist = PyList_New(attrdef->m_imin); for (unsigned int i=0; i<attrdef->m_imin; i++) @@ -458,7 +465,7 @@ PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef * #ifdef USE_MATHUTILS float fval[3]; val->getValue(fval); - return Vector_CreatePyObject(fval, 3, Py_NEW, NULL); + return Vector_CreatePyObject(fval, 3, NULL); #else PyObject *resultlist = PyList_New(3); for (unsigned int i=0; i<3; i++) diff --git a/source/gameengine/Expressions/intern/PythonCallBack.cpp b/source/gameengine/Expressions/intern/PythonCallBack.cpp new file mode 100644 index 00000000000..3fb84569eca --- /dev/null +++ b/source/gameengine/Expressions/intern/PythonCallBack.cpp @@ -0,0 +1,119 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * 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 2 + * 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, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Contributor(s): Porteries Tristan. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file gameengine/Expressions/intern/PythonCallBack.cpp + * \ingroup expressions + */ + +#include "EXP_PythonCallBack.h" +#include <iostream> +#include <stdarg.h> + +#include "BLI_alloca.h" + +/** Check if a python value is a function and have the correct number of arguments. + * \param value The python value to check. + * \param minargcount The minimum of arguments possible. + * \param maxargcount The maximum of arguments possible. + * \param r_argcount The number of argument of this function, this variable will be + * changed in the function. + */ +static PyObject *CheckPythonFunction(PyObject *value, unsigned int minargcount, unsigned int maxargcount, unsigned int &r_argcount) +{ + if (PyMethod_Check(value)) { + PyCodeObject *code = ((PyCodeObject *)PyFunction_GET_CODE(PyMethod_GET_FUNCTION(value))); + // *args support + r_argcount = (code->co_flags & CO_VARARGS) ? maxargcount : (code->co_argcount - 1); + } + else if (PyFunction_Check(value)) { + PyCodeObject *code = ((PyCodeObject *)PyFunction_GET_CODE(value)); + // *args support + r_argcount = (code->co_flags & CO_VARARGS) ? maxargcount : code->co_argcount; + } + else { // is not a methode or a function + PyErr_Format(PyExc_TypeError, "items must be functions or methodes, not %s", + Py_TYPE(value)->tp_name); + return NULL; + } + + if (r_argcount < minargcount || r_argcount > maxargcount) { + // wrong number of arguments + PyErr_Format(PyExc_TypeError, "methode or function (%s) has invalid number of arguments (%i) must be between %i and %i", + Py_TYPE(value)->tp_name, r_argcount, minargcount, maxargcount); + return NULL; + } + + return value; +} + +/** Create a python tuple to call a python function + * \param argcount The lenght of the tuple. + * \param arglist The fully list of python arguments [size >= argcount]. + */ +static PyObject *CreatePythonTuple(unsigned int argcount, PyObject **arglist) +{ + PyObject *tuple = PyTuple_New(argcount); + + for (unsigned int i = 0; i < argcount; ++i) { + PyObject *item = arglist[i]; + // increment reference and copy it in a new tuple + Py_INCREF(item); + PyTuple_SET_ITEM(tuple, i, item); + } + + return tuple; +} + +void RunPythonCallBackList(PyObject *functionlist, PyObject **arglist, unsigned int minargcount, unsigned int maxargcount) +{ + unsigned int size = PyList_Size(functionlist); + PyObject **argTuples = (PyObject **)BLI_array_alloca(argTuples, maxargcount - minargcount + 1); + memset(argTuples, 0, sizeof(PyObject *) * (maxargcount - minargcount + 1)); + + for (unsigned int i = 0; i < size; ++i) { + unsigned int funcargcount = 0; + + PyObject *item = PyList_GET_ITEM(functionlist, i); + PyObject *func = CheckPythonFunction(item, minargcount, maxargcount, funcargcount); + if (!func) { // this item fails the check + PyErr_Print(); + PyErr_Clear(); + continue; + } + + // get correct argument tuple. + PyObject *tuple = argTuples[funcargcount - minargcount]; + if (!tuple) + argTuples[funcargcount - minargcount] = tuple = CreatePythonTuple(funcargcount, arglist); + + PyObject *ret = PyObject_Call(func, tuple, NULL); + if (!ret) { // if ret is NULL this seems that the function doesn't work ! + PyErr_Print(); + PyErr_Clear(); + } + else + Py_DECREF(ret); + } + + for (unsigned int i = 0; i <= (maxargcount - minargcount); ++i) + Py_XDECREF(argTuples[i]); +} diff --git a/source/gameengine/Expressions/StringValue.cpp b/source/gameengine/Expressions/intern/StringValue.cpp index 098949c9d7b..ddf61dc441c 100644 --- a/source/gameengine/Expressions/StringValue.cpp +++ b/source/gameengine/Expressions/intern/StringValue.cpp @@ -15,10 +15,10 @@ * */ -#include "StringValue.h" -#include "BoolValue.h" -#include "ErrorValue.h" -#include "VoidValue.h" +#include "EXP_StringValue.h" +#include "EXP_BoolValue.h" +#include "EXP_ErrorValue.h" +#include "EXP_VoidValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/intern/Value.cpp index bdef2dbd5b0..f8796a76e76 100644 --- a/source/gameengine/Expressions/Value.cpp +++ b/source/gameengine/Expressions/intern/Value.cpp @@ -17,15 +17,15 @@ * purpose. It is provided "as is" without express or implied warranty. * */ -#include "Value.h" -#include "BoolValue.h" -#include "FloatValue.h" -#include "IntValue.h" -#include "VectorValue.h" -#include "VoidValue.h" -#include "StringValue.h" -#include "ErrorValue.h" -#include "ListValue.h" +#include "EXP_Value.h" +#include "EXP_BoolValue.h" +#include "EXP_FloatValue.h" +#include "EXP_IntValue.h" +#include "EXP_VectorValue.h" +#include "EXP_VoidValue.h" +#include "EXP_StringValue.h" +#include "EXP_ErrorValue.h" +#include "EXP_ListValue.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction @@ -568,7 +568,7 @@ CValue *CValue::ConvertPythonToValue(PyObject *pyobj, const bool do_type_excepti Py_ssize_t numitems = PyList_GET_SIZE(pyobj); for (i=0;i<numitems;i++) { - PyObject *listitem = PyList_GetItem(pyobj,i); /* borrowed ref */ + PyObject *listitem = PyList_GET_ITEM(pyobj,i); /* borrowed ref */ CValue* listitemval = ConvertPythonToValue(listitem, error_prefix); if (listitemval) { diff --git a/source/gameengine/Expressions/VectorValue.cpp b/source/gameengine/Expressions/intern/VectorValue.cpp index 6931ba2aa76..a3d44116317 100644 --- a/source/gameengine/Expressions/VectorValue.cpp +++ b/source/gameengine/Expressions/intern/VectorValue.cpp @@ -19,12 +19,12 @@ # pragma warning (disable:4786) #endif -#include "Value.h" -#include "VectorValue.h" -#include "ErrorValue.h" +#include "EXP_Value.h" +#include "EXP_VectorValue.h" +#include "EXP_ErrorValue.h" //#include "MatrixValue.h" -#include "VoidValue.h" -#include "StringValue.h" +#include "EXP_VoidValue.h" +#include "EXP_StringValue.h" //#include "FactoryManager.h" |