diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2018-04-16 15:07:42 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2018-04-17 18:51:28 +0300 |
commit | 159806140fd33e6ddab951c0f6f180cfbf927d38 (patch) | |
tree | da076be3baa4d987fb5935e220a3d901c926e0e7 /source/gameengine/Expressions | |
parent | 28b996a9d2090efdd74115a653629ef9d7d871f7 (diff) |
Removing Blender Game Engine from Blender 2.8
Folders removed entirely:
* //extern/recastnavigation
* //intern/decklink
* //intern/moto
* //source/blender/editors/space_logic
* //source/blenderplayer
* //source/gameengine
This includes DNA data and any reference to the BGE code in Blender itself.
We are bumping the subversion.
Pending tasks:
* Tile/clamp code in image editor draw code.
* Viewport drawing code (so much of this will go away because of BI removal
that we can wait until then to remove this.
Diffstat (limited to 'source/gameengine/Expressions')
43 files changed, 0 insertions, 8916 deletions
diff --git a/source/gameengine/Expressions/CMakeLists.txt b/source/gameengine/Expressions/CMakeLists.txt deleted file mode 100644 index 9c563a46ea2..00000000000 --- a/source/gameengine/Expressions/CMakeLists.txt +++ /dev/null @@ -1,91 +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) 2006, Blender Foundation -# All rights reserved. -# -# The Original Code is: all of this file. -# -# Contributor(s): Jacques Beaurain. -# -# ***** END GPL LICENSE BLOCK ***** - -set(INC - . - ../SceneGraph - ../../blender/blenlib - ../../../intern/guardedalloc - ../../../intern/string -) - -set(INC_SYS - ../../../intern/moto/include -) - -set(SRC - 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 - intern/ListWrapper.cpp - - 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 - EXP_ListWrapper.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/EXP_BoolValue.h b/source/gameengine/Expressions/EXP_BoolValue.h deleted file mode 100644 index 98ba1d75e52..00000000000 --- a/source/gameengine/Expressions/EXP_BoolValue.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * BoolValue.h: interface for the CBoolValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_BoolValue.h - * \ingroup expressions - */ - -#ifndef __EXP_BOOLVALUE_H__ -#define __EXP_BOOLVALUE_H__ - -#include "EXP_Value.h" - -/** - * Smart Boolean Value class. - * Is used by parser when an expression tree is build containing booleans. - */ - -class CBoolValue : public CPropValue -{ - - //PLUGIN_DECLARE_SERIAL(CBoolValue,CValue) - -public: - static const STR_String sTrueString; - static const STR_String sFalseString; - - CBoolValue(); - CBoolValue(bool inBool); - CBoolValue(bool innie, const char *name, AllocationTYPE alloctype = CValue::HEAPVALUE); - - virtual const STR_String& GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - bool GetBool(); - virtual void SetValue(CValue* newval); - - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - - void Configure(CValue* menuvalue); - virtual CValue* GetReplica(); -#ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython(); -#endif - -private: - bool m_bool; - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CBoolValue") -#endif -}; - -#endif /* __EXP_BOOLVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_ConstExpr.h b/source/gameengine/Expressions/EXP_ConstExpr.h deleted file mode 100644 index b4456dacdf3..00000000000 --- a/source/gameengine/Expressions/EXP_ConstExpr.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * ConstExpr.h: interface for the CConstExpr class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_ConstExpr.h - * \ingroup expressions - */ - -#ifndef __EXP_CONSTEXPR_H__ -#define __EXP_CONSTEXPR_H__ - -#include "EXP_Expression.h" -#include "EXP_Value.h" // Added by ClassView - -class CConstExpr : public CExpression -{ - //PLUGIN_DECLARE_SERIAL_EXPRESSION (CConstExpr,CExpression) -public: - virtual bool MergeExpression(CExpression* otherexpr); - - void BroadcastOperators(VALUE_OPERATOR op); - - virtual unsigned char GetExpressionID(); - CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks); - //bool IsInside(float x,float y,float z,bool bBorderInclude=true); - bool NeedsRecalculated(); - void ClearModified(); - virtual double GetNumber(); - virtual CValue* Calculate(); - CConstExpr(CValue* constval); - CConstExpr(); - virtual ~CConstExpr(); - - -private: - CValue* m_value; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CConstExpr") -#endif -}; - -#endif /* __EXP_CONSTEXPR_H__ */ diff --git a/source/gameengine/Expressions/EXP_EmptyValue.h b/source/gameengine/Expressions/EXP_EmptyValue.h deleted file mode 100644 index d23addb9f9f..00000000000 --- a/source/gameengine/Expressions/EXP_EmptyValue.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * EmptyValue.h: interface for the CEmptyValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_EmptyValue.h - * \ingroup expressions - */ - -#ifndef __EXP_EMPTYVALUE_H__ -#define __EXP_EMPTYVALUE_H__ - -#include "EXP_Value.h" - -class CListValue; - -class CEmptyValue : public CPropValue -{ - //PLUGIN_DECLARE_SERIAL (CEmptyValue,CValue) -public: - CEmptyValue(); - virtual ~CEmptyValue(); - - virtual const STR_String & GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - CListValue* GetPolySoup(); - virtual double* GetVector3(bool bGetTransformedVec=false); - bool IsInside(CValue* testpoint,bool bBorderInclude=true); - CValue * Calc(VALUE_OPERATOR op, CValue *val); - CValue * CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - virtual CValue* GetReplica(); - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CEmptyValue") -#endif -}; - -#endif /* __EXP_EMPTYVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_ErrorValue.h b/source/gameengine/Expressions/EXP_ErrorValue.h deleted file mode 100644 index a6f91ca200a..00000000000 --- a/source/gameengine/Expressions/EXP_ErrorValue.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * ErrorValue.h: interface for the CErrorValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_ErrorValue.h - * \ingroup expressions - */ - -#ifndef __EXP_ERRORVALUE_H__ -#define __EXP_ERRORVALUE_H__ - -#include "EXP_Value.h" - -class CErrorValue : public CPropValue -{ - -public: - virtual const STR_String & GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - CErrorValue(); - CErrorValue(const char *errmsg); - virtual ~CErrorValue(); - virtual CValue* Calc(VALUE_OPERATOR op, CValue* val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - virtual CValue* GetReplica(); - -private: - STR_String m_strErrorText; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CErrorValue") -#endif -}; - -#endif /* __EXP_ERRORVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_Expression.h b/source/gameengine/Expressions/EXP_Expression.h deleted file mode 100644 index 66a6e9476ff..00000000000 --- a/source/gameengine/Expressions/EXP_Expression.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Expression.h: interface for the CExpression class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_Expression.h - * \ingroup expressions - */ - -#ifndef __EXP_EXPRESSION_H__ -#define __EXP_EXPRESSION_H__ - -#include "EXP_Value.h" - -//extern int gRefCountExpr; // only for debugging purposes (detect mem.leaks) - - -#define PLUGIN_DECLARE_SERIAL_EXPRESSION(class_name, base_class_name) \ -public: \ - virtual base_class_name * Copy() { \ - return new class_name; \ - } \ - virtual bool EdSerialize(CompressorArchive& arch, \ - class CFactoryManager* facmgr, \ - bool bIsStoring); \ - virtual bool EdIdSerialize(CompressorArchive& arch, \ - class CFactoryManager* facmgr, \ - bool bIsStoring) \ - { \ - if (bIsStoring) \ - { \ - unsigned char exprID = GetExpressionID(); \ - arch << exprID; \ - } \ - return true; \ - } \ - - - -class CExpression; - - -// for undo/redo system the deletion in the expressiontree can be restored by replacing broken links 'inplace' -class CBrokenLinkInfo -{ - public: - CBrokenLinkInfo(CExpression** pmemexpr,CExpression* expr) - :m_pmemExpr(pmemexpr), - m_pExpr(expr) - { - assertd(pmemexpr); - m_bRestored=false; - }; - - virtual ~CBrokenLinkInfo(); - void RestoreLink(); - void BreakLink(); - - - // members vars - private: - CExpression** m_pmemExpr; - CExpression* m_pExpr; - bool m_bRestored; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CBrokenLinkInfo") -#endif -}; - - - - - - - - -class CExpression -{ -public: - enum { - COPERATOR1EXPRESSIONID = 1, - COPERATOR2EXPRESSIONID = 2, - CCONSTEXPRESSIONID = 3, - CIFEXPRESSIONID = 4, - COPERATORVAREXPRESSIONID = 5, - CIDENTIFIEREXPRESSIONID = 6 - }; - - -protected: - virtual ~CExpression() = 0; //pure virtual -public: - virtual bool MergeExpression(CExpression* otherexpr) = 0; - CExpression(); - - - virtual CValue* Calculate() = 0; //pure virtual - virtual unsigned char GetExpressionID() = 0; - //virtual bool IsInside(float x,float y,float z,bool bBorderInclude=true) = 0; //pure virtual - virtual bool NeedsRecalculated() = 0; // another pure one - virtual CExpression * CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) =0; // another pure one - virtual void ClearModified() = 0; // another pure one - //virtual CExpression * Copy() =0; - virtual void BroadcastOperators(VALUE_OPERATOR op) =0; - - virtual CExpression * AddRef() { // please leave multiline, for debugger !!! - -#ifdef DEBUG - //gRefCountExpr++; - assertd(m_refcount < 255); -#endif - m_refcount++; - return this; - }; - virtual CExpression* Release(CExpression* complicatedtrick=NULL) { -#ifdef DEBUG - //gRefCountExpr--; -#endif - if (--m_refcount < 1) - { - delete this; - } //else - // return this; - return complicatedtrick; - }; - - -protected: - - int m_refcount; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CExpression") -#endif -}; - -#endif /* __EXP_EXPRESSION_H__ */ diff --git a/source/gameengine/Expressions/EXP_FloatValue.h b/source/gameengine/Expressions/EXP_FloatValue.h deleted file mode 100644 index 3c16c57d16d..00000000000 --- a/source/gameengine/Expressions/EXP_FloatValue.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * FloatValue.h: interface for the CFloatValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_FloatValue.h - * \ingroup expressions - */ - -#ifndef __EXP_FLOATVALUE_H__ -#define __EXP_FLOATVALUE_H__ - -#include "EXP_Value.h" - -class CFloatValue : public CPropValue -{ - //PLUGIN_DECLARE_SERIAL (CFloatValue,CValue) -public: - CFloatValue(); - CFloatValue(float fl); - CFloatValue(float fl,const char *name,AllocationTYPE alloctype=CValue::HEAPVALUE); - - virtual const STR_String & GetText(); - - void Configure(CValue* menuvalue); - virtual double GetNumber(); - virtual int GetValueType(); - virtual void SetValue(CValue* newval); - float GetFloat(); - void SetFloat(float fl); - virtual ~CFloatValue(); - virtual CValue* GetReplica(); - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); -#ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython(); -#endif - -protected: - float m_float; - STR_String* m_pstrRep; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CFloatValue") -#endif -}; - -#endif /* __EXP_FLOATVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_HashedPtr.h b/source/gameengine/Expressions/EXP_HashedPtr.h deleted file mode 100644 index 7c7c5f6e5ec..00000000000 --- a/source/gameengine/Expressions/EXP_HashedPtr.h +++ /dev/null @@ -1,59 +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_HashedPtr.h - * \ingroup expressions - */ - -#ifndef __EXP_HASHEDPTR_H__ -#define __EXP_HASHEDPTR_H__ - -#ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" -#endif - -class CHashedPtr -{ - void* m_valptr; - -public: - CHashedPtr(void* val); - - unsigned int hash() const; - - inline friend bool operator ==( const CHashedPtr & rhs,const CHashedPtr & lhs) - { - return rhs.m_valptr == lhs.m_valptr; - } - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CHashedPtr") -#endif -}; - -#endif /* __EXP_HASHEDPTR_H__ */ diff --git a/source/gameengine/Expressions/EXP_IdentifierExpr.h b/source/gameengine/Expressions/EXP_IdentifierExpr.h deleted file mode 100644 index 96ef3677cf3..00000000000 --- a/source/gameengine/Expressions/EXP_IdentifierExpr.h +++ /dev/null @@ -1,59 +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_IdentifierExpr.h - * \ingroup expressions - */ - -#ifndef __EXP_IDENTIFIEREXPR_H__ -#define __EXP_IDENTIFIEREXPR_H__ - -#include "EXP_Expression.h" - -class CIdentifierExpr : public CExpression -{ - CValue* m_idContext; - STR_String m_identifier; -public: - CIdentifierExpr(const STR_String& identifier,CValue* id_context); - virtual ~CIdentifierExpr(); - - virtual CValue* Calculate(); - virtual bool MergeExpression(CExpression* otherexpr); - virtual unsigned char GetExpressionID(); - virtual bool NeedsRecalculated(); - virtual CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks); - virtual void ClearModified(); - virtual void BroadcastOperators(VALUE_OPERATOR op); - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIdentifierExpr") -#endif -}; - -#endif /* __EXP_IDENTIFIEREXPR_H__ */ diff --git a/source/gameengine/Expressions/EXP_IfExpr.h b/source/gameengine/Expressions/EXP_IfExpr.h deleted file mode 100644 index 43b4b8faf53..00000000000 --- a/source/gameengine/Expressions/EXP_IfExpr.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * IfExpr.h: interface for the CIfExpr class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_IfExpr.h - * \ingroup expressions - */ - -#ifndef __EXP_IFEXPR_H__ -#define __EXP_IFEXPR_H__ - -#include "EXP_Expression.h" - -class CIfExpr : public CExpression -{ - //PLUGIN_DECLARE_SERIAL_EXPRESSION (CIfExpr,CExpression) - -private: - CExpression *m_guard, *m_e1, *m_e2; - -public: - virtual bool MergeExpression(CExpression* otherexpr); - CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2); - CIfExpr(); - - virtual unsigned char GetExpressionID(); - virtual ~CIfExpr(); - virtual CValue* Calculate(); - - virtual bool IsInside(float x,float y,float z,bool bBorderInclude=true); - virtual bool NeedsRecalculated(); - - - virtual CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks); - virtual void ClearModified(); - virtual void BroadcastOperators(VALUE_OPERATOR op); - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIfExpr") -#endif -}; - -#endif /* __EXP_IFEXPR_H__ */ diff --git a/source/gameengine/Expressions/EXP_InputParser.h b/source/gameengine/Expressions/EXP_InputParser.h deleted file mode 100644 index 80471009a16..00000000000 --- a/source/gameengine/Expressions/EXP_InputParser.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Parser.h: interface for the CParser class. - * Eindhoven University of Technology 1997 - * OOPS team (Serge vd Boom, Erwin Coumans, Tom Geelen, Wynke Stuylemeier) - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_InputParser.h - * \ingroup expressions - */ - -#ifndef __EXP_INPUTPARSER_H__ -#define __EXP_INPUTPARSER_H__ - -class CParser; -#include "EXP_Expression.h" - - -class CParser -{ -public: - CParser(); - virtual ~CParser(); - - float GetFloat(STR_String& txt); - CValue* GetValue(STR_String& txt, bool bFallbackToText=false); - CExpression* ProcessText(const char *intext); - void SetContext(CValue* context); - -private: - enum symbols { - errorsym, - lbracksym, - rbracksym, - cellsym, - commasym, - opsym, - constsym, - sumsym, - ifsym, - whocodedsym, - eolsym, - idsym - }; // all kinds of symbols - - enum optype { - OPmodulus, - OPplus, - OPminus, - OPtimes, - OPdivide, - OPand, - OPor, - OPequal, - OPunequal, - OPgreater, - OPless, - OPgreaterequal, - OPlessequal, - OPnot - }; // all kinds of operators - - enum consttype { - booltype, - inttype, - floattype, - stringtype - }; // all kinds of constants - - int sym, // current symbol - opkind, // kind of operator, if symbol is an operator - constkind; // kind of operator, if symbol is a constant - - char ch; // current character - int chcount; // index to character in input string - CExpression *errmsg; // contains a errormessage, if scanner error - - STR_String text, // contains a copy of the original text - const_as_string; // string representation of the symbol, if symbol is a constant - bool boolvalue; // value of the boolean, if symbol is a constant of type boolean - CValue* m_identifierContext;// context in which identifiers are looked up - - - void ScanError(const char *str); - CExpression* Error(const char *str); - void NextCh(); - void TermChar(char c); - void DigRep(); - void CharRep(); - void GrabString(int start); - void GrabRealString(int start); - void NextSym(); -#if 0 /* not used yet */ - int MakeInt(); -#endif - const char *Symbol2Str(int s); - void Term(int s); - int Priority(int optor); - CExpression *Ex(int i); - CExpression *Expr(); - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CParser") -#endif -}; - -#endif /* __EXP_INPUTPARSER_H__ */ - diff --git a/source/gameengine/Expressions/EXP_IntValue.h b/source/gameengine/Expressions/EXP_IntValue.h deleted file mode 100644 index a1cd96a888e..00000000000 --- a/source/gameengine/Expressions/EXP_IntValue.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * IntValue.h: interface for the CIntValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_IntValue.h - * \ingroup expressions - */ - -#ifndef __EXP_INTVALUE_H__ -#define __EXP_INTVALUE_H__ - - -#include "EXP_Value.h" - -typedef long long cInt; - -class CIntValue : public CPropValue -{ - //PLUGIN_DECLARE_SERIAL (CIntValue,CValue) - -public: - virtual const STR_String& GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - - cInt GetInt(); - CIntValue(); - CIntValue(cInt innie); - CIntValue(cInt innie, - const char *name, - AllocationTYPE alloctype=CValue::HEAPVALUE); - - virtual CValue* Calc(VALUE_OPERATOR op, - CValue *val); - - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, - VALUE_OPERATOR op, - CValue *val); - - virtual void SetValue(CValue* newval); - - void Configure(CValue* menuvalue); - void AddConfigurationData(CValue* menuvalue); - virtual CValue* GetReplica(); - -#ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython(); -#endif - -protected: - virtual ~CIntValue(); - -private: - cInt m_int; - STR_String* m_pstrRep; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIntValue") -#endif -}; - -#endif /* __EXP_INTVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_ListValue.h b/source/gameengine/Expressions/EXP_ListValue.h deleted file mode 100644 index f5421066f62..00000000000 --- a/source/gameengine/Expressions/EXP_ListValue.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ListValue.h: interface for the CListValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_ListValue.h - * \ingroup expressions - */ - -#ifndef __EXP_LISTVALUE_H__ -#define __EXP_LISTVALUE_H__ - -#include "EXP_Value.h" - -class CListValue : public CPropValue -{ - Py_Header - //PLUGIN_DECLARE_SERIAL (CListValue,CValue) - -public: - CListValue(); - virtual ~CListValue(); - - void AddConfigurationData(CValue* menuvalue); - void Configure(CValue* menuvalue); - void Add(CValue* value); - - /** \attention not implemented yet :( */ - virtual CValue* Calc(VALUE_OPERATOR op,CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, - VALUE_OPERATOR op, - CValue* val); - virtual double GetNumber(); - virtual int GetValueType(); - virtual CValue* GetReplica(); - -public: - void MergeList(CListValue* otherlist); - bool RemoveValue(CValue* val); - void SetReleaseOnDestruct(bool bReleaseContents); - bool SearchValue(CValue* val); - - CValue* FindValue(const STR_String & name); - CValue* FindValue(const char *name); - - void ReleaseAndRemoveAll(); - virtual void SetModified(bool bModified); - virtual inline bool IsModified(); - void Remove(int i); - void Resize(int num); - void SetValue(int i,CValue* val); - CValue* GetValue(int i) { assertd(i < m_pValueArray.size()); return m_pValueArray[i]; } - int GetCount() { return m_pValueArray.size(); } - virtual const STR_String & GetText(); - - bool CheckEqual(CValue* first,CValue* second); - -#ifdef WITH_PYTHON - virtual PyObject *py_repr(void) { - PyObject *py_proxy= this->GetProxy(); - PyObject *py_list= PySequence_List(py_proxy); - PyObject *py_string= PyObject_Repr(py_list); - Py_DECREF(py_list); - Py_DECREF(py_proxy); - return py_string; - } - - KX_PYMETHOD_O(CListValue,append); - KX_PYMETHOD_NOARGS(CListValue,reverse); - KX_PYMETHOD_O(CListValue,index); - KX_PYMETHOD_O(CListValue,count); - KX_PYMETHOD_VARARGS(CListValue,get); - KX_PYMETHOD_O(CListValue,from_id); -#endif - -private: - - std::vector<CValue*> m_pValueArray; - bool m_bReleaseContents; -}; - -#endif /* __EXP_LISTVALUE_H__ */ - diff --git a/source/gameengine/Expressions/EXP_ListWrapper.h b/source/gameengine/Expressions/EXP_ListWrapper.h deleted file mode 100644 index e4c97691acb..00000000000 --- a/source/gameengine/Expressions/EXP_ListWrapper.h +++ /dev/null @@ -1,109 +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. - * - * Contributor(s): Porteries Tristan. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file EXP_ListWrapper.h - * \ingroup expressions - */ - -#ifdef WITH_PYTHON - -#ifndef __EXP_LISTWRAPPER_H__ -#define __EXP_LISTWRAPPER_H__ - -#include "EXP_Value.h" - -class CListWrapper : public CValue -{ - Py_Header -private: - /** The client instance passed as first argument of each callback. - * We use a void * instead of a template to avoid to declare this class - * for each use in KX_PythonInitTypes. - */ - void *m_client; - - // The python object which owned this list. - PyObject *m_base; - - /// Returns true if the list is still valid, else each call will raise an error. - bool (*m_checkValid)(void *); - - /// Returns the list size. - int (*m_getSize)(void *); - - /// Returns the list item for the giving index. - PyObject *(*m_getItem)(void *, int); - - /// Returns name item for the giving index, used for python operator list["name"]. - const char *(*m_getItemName)(void *, int); - - /// Sets the nex item to the index place, return false when failed item conversion. - bool (*m_setItem)(void *, int, PyObject *); - -public: - CListWrapper(void *client, - PyObject *base, - bool (*checkValid)(void *), - int (*getSize)(void *), - PyObject *(*getItem)(void *, int), - const char *(*getItemName)(void *, int), - bool (*setItem)(void *, int, PyObject *)); - ~CListWrapper(); - - /// \section Python Interface - bool CheckValid(); - int GetSize(); - PyObject *GetItem(int index); - const char *GetItemName(int index); - bool SetItem(int index, PyObject *item); - bool AllowSetItem(); - bool AllowGetItemByName(); - - /// \section CValue Inherited Functions. - virtual const STR_String &GetText(); - virtual void SetName(const char *name); - virtual STR_String &GetName(); - virtual CValue *GetReplica(); - virtual CValue *Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - virtual double GetNumber(); - virtual int GetValueType(); - virtual PyObject *py_repr(); - - // Python list operators. - static PySequenceMethods py_as_sequence; - // Python dictionnary operators. - static PyMappingMethods py_as_mapping; - - static Py_ssize_t py_len(PyObject *self); - static PyObject *py_get_item(PyObject *self, Py_ssize_t index); - static int py_set_item(PyObject *self, Py_ssize_t index, PyObject *value); - static PyObject *py_mapping_subscript(PyObject *self, PyObject *key); - static int py_mapping_ass_subscript(PyObject *self, PyObject *key, PyObject *value); - static int py_contains(PyObject *self, PyObject *key); - - KX_PYMETHOD_VARARGS(CListWrapper, Get); -}; - -#endif // __EXP_LISTWRAPPER_H__ - -#endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/EXP_Operator1Expr.h b/source/gameengine/Expressions/EXP_Operator1Expr.h deleted file mode 100644 index 9a05ce9c0c4..00000000000 --- a/source/gameengine/Expressions/EXP_Operator1Expr.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Operator1Expr.h: interface for the COperator1Expr class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_Operator1Expr.h - * \ingroup expressions - */ - -#ifndef __EXP_OPERATOR1EXPR_H__ -#define __EXP_OPERATOR1EXPR_H__ - -#include "EXP_Expression.h" - -class COperator1Expr : public CExpression -{ - //PLUGIN_DECLARE_SERIAL_EXPRESSION (COperator1Expr,CExpression) - - - -public: - virtual bool MergeExpression(CExpression* otherexpr); - virtual void BroadcastOperators(VALUE_OPERATOR op); - - virtual unsigned char GetExpressionID() { return COPERATOR1EXPRESSIONID; } - CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks); - //virtual bool IsInside(float x,float y,float z,bool bBorderInclude = true); - virtual bool NeedsRecalculated(); - void ClearModified() { - if (m_lhs) - m_lhs->ClearModified(); - } - virtual CValue* Calculate(); - COperator1Expr(VALUE_OPERATOR op, CExpression *lhs); - COperator1Expr(); - virtual ~COperator1Expr(); - - - -private: - VALUE_OPERATOR m_op; - CExpression * m_lhs; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:") -#endif -}; - -#endif /* __EXP_OPERATOR1EXPR_H__ */ diff --git a/source/gameengine/Expressions/EXP_Operator2Expr.h b/source/gameengine/Expressions/EXP_Operator2Expr.h deleted file mode 100644 index cd7a492fde0..00000000000 --- a/source/gameengine/Expressions/EXP_Operator2Expr.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Operator2Expr.h: interface for the COperator2Expr class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_Operator2Expr.h - * \ingroup expressions - */ - -#ifndef __EXP_OPERATOR2EXPR_H__ -#define __EXP_OPERATOR2EXPR_H__ - - -#include "EXP_Expression.h" -#include "EXP_Value.h" // Added by ClassView - -class COperator2Expr : public CExpression -{ - //PLUGIN_DECLARE_SERIAL_EXPRESSION (COperator2Expr,CExpression) - -public: - virtual bool MergeExpression(CExpression* otherexpr); - virtual unsigned char GetExpressionID() { return COPERATOR2EXPRESSIONID; } - virtual void BroadcastOperators(VALUE_OPERATOR op); - CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks); - //virtual bool IsInside(float x,float y,float z,bool bBorderInclude=true); - //virtual bool IsLeftInside(float x,float y,float z,bool bBorderInclude); - //virtual bool IsRightInside(float x,float y,float z,bool bBorderInclude); - bool NeedsRecalculated(); - void ClearModified() { - if (m_lhs) - m_lhs->ClearModified(); - if (m_rhs) - m_rhs->ClearModified(); - } - virtual CValue* Calculate(); - COperator2Expr(VALUE_OPERATOR op, CExpression *lhs, CExpression *rhs); - COperator2Expr(); - virtual ~COperator2Expr(); - - -protected: - CExpression * m_rhs; - CExpression * m_lhs; - CValue* m_cached_calculate; // cached result - -private: - VALUE_OPERATOR m_op; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:COperator2Expr") -#endif -}; - -#endif /* __EXP_OPERATOR2EXPR_H__ */ - diff --git a/source/gameengine/Expressions/EXP_PyObjectPlus.h b/source/gameengine/Expressions/EXP_PyObjectPlus.h deleted file mode 100644 index 32dc79cf6eb..00000000000 --- a/source/gameengine/Expressions/EXP_PyObjectPlus.h +++ /dev/null @@ -1,648 +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_PyObjectPlus.h - * \ingroup expressions - */ - -#ifndef __EXP_PYOBJECTPLUS_H__ -#define __EXP_PYOBJECTPLUS_H__ - -/* for now keep weakrefs optional */ -#define USE_WEAKREFS - - -#ifndef __cplusplus // c++ only -#error Must be compiled with C++ -#endif - -#include "EXP_Python.h" -#include "STR_String.h" -#include "MT_Vector3.h" -#include "SG_QList.h" -#include <stddef.h> - -#ifdef WITH_PYTHON -#ifdef USE_MATHUTILS -extern "C" { -#include "../../blender/python/mathutils/mathutils.h" /* so we can have mathutils callbacks */ -#include "../../blender/python/generic/py_capi_utils.h" /* for PyC_LineSpit only */ -} -#endif - -#define MAX_PROP_NAME 64 - -/* Use with ShowDeprecationWarning macro */ -typedef struct { - bool warn_done; - void *link; -} WarnLink; - -#define ShowDeprecationWarning(old_way, new_way) \ -{ \ - static WarnLink wlink = {false, NULL}; \ - if ((PyObjectPlus::m_ignore_deprecation_warnings || wlink.warn_done)==0) \ - { \ - PyObjectPlus::ShowDeprecationWarning_func(old_way, new_way); \ - \ - WarnLink *wlink_last= PyObjectPlus::GetDeprecationWarningLinkLast(); \ - wlink.warn_done = true; \ - wlink.link = NULL; \ - \ - if (wlink_last) { \ - wlink_last->link= (void *)&(wlink); \ - PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ - } \ - else { \ - PyObjectPlus::SetDeprecationWarningFirst(&(wlink)); \ - PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \ - } \ - } \ -} \ - - - -typedef struct PyObjectPlus_Proxy { - PyObject_HEAD /* required python macro */ - class PyObjectPlus *ref; // pointer to GE object, it holds a reference to this proxy - void *ptr; // optional pointer to generic structure, the structure holds no reference to this proxy - bool py_owns; // true if the object pointed by ref should be deleted when the proxy is deleted - bool py_ref; // true if proxy is connected to a GE object (ref is used) -#ifdef USE_WEAKREFS - PyObject *in_weakreflist; // weak reference enabler -#endif -} PyObjectPlus_Proxy; - -#define BGE_PROXY_ERROR_MSG "Blender Game Engine data has been freed, cannot use this python variable" -#define BGE_PROXY_REF(_self) (((PyObjectPlus_Proxy *)_self)->ref) -#define BGE_PROXY_PTR(_self) (((PyObjectPlus_Proxy *)_self)->ptr) -#define BGE_PROXY_PYOWNS(_self) (((PyObjectPlus_Proxy *)_self)->py_owns) -#define BGE_PROXY_PYREF(_self) (((PyObjectPlus_Proxy *)_self)->py_ref) -#ifdef USE_WEAKREFS -# define BGE_PROXY_WKREF(_self) (((PyObjectPlus_Proxy *)_self)->in_weakreflist) -#endif - -/* Note, sometimes we don't care what BGE type this is as long as its a proxy */ -#define BGE_PROXY_CHECK_TYPE(_type) ((_type)->tp_dealloc == PyObjectPlus::py_base_dealloc) - -/* 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 -// PyC++ class -// AttributesPtr correspond to attributes of proxy generic pointer -// each PyC++ class must be registered in KX_PythonInitTypes.cpp -#define __Py_Header \ -public: \ - static PyTypeObject Type; \ - static PyMethodDef Methods[]; \ - static PyAttributeDef Attributes[]; \ - virtual PyTypeObject *GetType(void) { \ - return &Type; \ - } \ - virtual PyObject *GetProxy() { \ - return GetProxyPlus_Ext(this, &Type, NULL); \ - } \ - virtual PyObject *NewProxy(bool py_owns) { \ - return NewProxyPlus_Ext(this, &Type, NULL, py_owns); \ - } \ - -// leave above line empty (macro)! -// use this macro for class that use generic pointer in proxy -// GetProxy() and NewProxy() must be defined to set the correct pointer in the proxy -#define __Py_HeaderPtr \ -public: \ - static PyTypeObject Type; \ - static PyMethodDef Methods[]; \ - static PyAttributeDef Attributes[]; \ - static PyAttributeDef AttributesPtr[]; \ - virtual PyTypeObject *GetType(void) { \ - return &Type; \ - } \ - virtual PyObject *GetProxy(); \ - virtual PyObject *NewProxy(bool py_owns); \ - -// leave above line empty (macro)! -#ifdef WITH_CXX_GUARDEDALLOC -#define Py_Header __Py_Header \ - void *operator new(size_t num_bytes) { \ - return MEM_mallocN(num_bytes, Type.tp_name); \ - } \ - void operator delete(void *mem) { \ - MEM_freeN(mem); \ - } \ - -#else -# define Py_Header __Py_Header -#endif - -#ifdef WITH_CXX_GUARDEDALLOC -#define Py_HeaderPtr __Py_HeaderPtr \ - void *operator new(size_t num_bytes) { \ - return MEM_mallocN(num_bytes, Type.tp_name); \ - } \ - void operator delete(void *mem) { \ - MEM_freeN(mem); \ - } \ - -#else -# define Py_HeaderPtr __Py_HeaderPtr -#endif - -/* - * nonzero values are an error for setattr - * however because of the nested lookups we need to know if the errors - * was because the attribute didnt exits of if there was some problem setting the value - */ - -#define PY_SET_ATTR_COERCE_FAIL 2 -#define PY_SET_ATTR_FAIL 1 -#define PY_SET_ATTR_MISSING -1 -#define PY_SET_ATTR_SUCCESS 0 - -/** - * These macros are helpful when embedding Python routines. The second - * macro is one that also requires a documentation string - */ -#define KX_PYMETHOD(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args, PyObject *kwds); \ - static PyObject * \ - sPy##method_name(PyObject *self, PyObject *args, PyObject *kwds) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ - } \ - -#define KX_PYMETHOD_VARARGS(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *args) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ - } \ - -#define KX_PYMETHOD_NOARGS(class_name, method_name) \ - PyObject *Py##method_name(); \ - static PyObject* \ - sPy##method_name(PyObject *self) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ - } \ - -#define KX_PYMETHOD_O(class_name, method_name) \ - PyObject *Py##method_name(PyObject *value); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *value) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(value) - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ - } \ - -#define KX_PYMETHOD_DOC(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args, PyObject *kwds); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *args, PyObject *kwds) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(...) - " \ - BGE_PROXY_ERROR_MSG); return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \ - } \ - static const char method_name##_doc[]; \ - -#define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \ - PyObject *Py##method_name(PyObject *args); \ - static PyObject* \ - sPy##method_name(PyObject *self, PyObject *args) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(...) - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \ - } \ - static const char method_name##_doc[]; \ - -#define KX_PYMETHOD_DOC_O(class_name, method_name) \ - PyObject *Py##method_name(PyObject *value); \ - static PyObject * \ - sPy##method_name(PyObject *self, PyObject *value) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "(value) - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \ - } \ - static const char method_name##_doc[]; \ - -#define KX_PYMETHOD_DOC_NOARGS(class_name, method_name) \ - PyObject *Py##method_name(); \ - static PyObject * \ - sPy##method_name(PyObject *self) { \ - if (BGE_PROXY_REF(self)==NULL) { \ - PyErr_SetString(PyExc_RuntimeError, \ - #class_name "." #method_name "() - " \ - BGE_PROXY_ERROR_MSG); \ - return NULL; \ - } \ - return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \ - } \ - static const char method_name##_doc[]; \ - - -/* The line above should remain empty */ -/** - * Method table macro (with doc) - */ -#define KX_PYMETHODTABLE(class_name, method_name) \ - {#method_name, (PyCFunction) class_name::sPy##method_name, METH_VARARGS, (const char *)class_name::method_name##_doc} - -#define KX_PYMETHODTABLE_O(class_name, method_name) \ - {#method_name, (PyCFunction) class_name::sPy##method_name, METH_O, (const char *)class_name::method_name##_doc} - -#define KX_PYMETHODTABLE_NOARGS(class_name, method_name) \ - {#method_name, (PyCFunction) class_name::sPy##method_name, METH_NOARGS, (const char *)class_name::method_name##_doc} - -#define KX_PYMETHODTABLE_KEYWORDS(class_name, method_name) \ - {#method_name, (PyCFunction) class_name::sPy##method_name, METH_VARARGS|METH_KEYWORDS, (const char *)class_name::method_name##_doc} - -/** - * Function implementation macro - */ -#define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name(PyObject *args, PyObject *kwds) - -#define KX_PYMETHODDEF_DOC_VARARGS(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name(PyObject *args) - -#define KX_PYMETHODDEF_DOC_O(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name(PyObject *value) - -#define KX_PYMETHODDEF_DOC_NOARGS(class_name, method_name, doc_string) \ -const char class_name::method_name##_doc[] = doc_string; \ -PyObject *class_name::Py##method_name() - -/** - * Attribute management - */ -enum KX_PYATTRIBUTE_TYPE { - KX_PYATTRIBUTE_TYPE_BOOL, - KX_PYATTRIBUTE_TYPE_ENUM, - KX_PYATTRIBUTE_TYPE_SHORT, - KX_PYATTRIBUTE_TYPE_INT, - KX_PYATTRIBUTE_TYPE_FLOAT, - KX_PYATTRIBUTE_TYPE_STRING, - KX_PYATTRIBUTE_TYPE_DUMMY, - KX_PYATTRIBUTE_TYPE_FUNCTION, - KX_PYATTRIBUTE_TYPE_VECTOR, - KX_PYATTRIBUTE_TYPE_FLAG, - KX_PYATTRIBUTE_TYPE_CHAR -}; - -enum KX_PYATTRIBUTE_ACCESS { - KX_PYATTRIBUTE_RW, - KX_PYATTRIBUTE_RO -}; - -struct KX_PYATTRIBUTE_DEF; -typedef int (*KX_PYATTRIBUTE_CHECK_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); -typedef int (*KX_PYATTRIBUTE_SET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); -typedef PyObject *(*KX_PYATTRIBUTE_GET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); - -typedef struct KX_PYATTRIBUTE_DEF { - const char *m_name; // name of the python attribute - KX_PYATTRIBUTE_TYPE m_type; // type of value - KX_PYATTRIBUTE_ACCESS m_access; // read/write access or read-only - int m_imin; // minimum value in case of integer attributes - // (for string: minimum string length, for flag: mask value, for float: matrix row size) - int m_imax; // maximum value in case of integer attributes - // (for string: maximum string length, for flag: 1 if flag is negative, float: vector/matrix col size) - float m_fmin; // minimum value in case of float attributes - float m_fmax; // maximum value in case of float attributes - bool m_clamp; // enforce min/max value by clamping - bool m_usePtr; // the attribute uses the proxy generic pointer, set at runtime - size_t m_offset; // position of field in structure - size_t m_size; // size of field for runtime verification (enum only) - size_t m_length; // length of array, 1=simple attribute - KX_PYATTRIBUTE_CHECK_FUNCTION m_checkFunction; // static function to check the assignment, returns 0 if no error - KX_PYATTRIBUTE_SET_FUNCTION m_setFunction; // static function to check the assignment, returns 0 if no error - KX_PYATTRIBUTE_GET_FUNCTION m_getFunction; // static function to check the assignment, returns 0 if no error - - // The following pointers are just used to have compile time check for attribute type. - // It would have been good to use a union but that would require C99 compatibility - // to initialize specific union fields through designated initializers. - struct { - bool *m_boolPtr; - short int *m_shortPtr; - int *m_intPtr; - float *m_floatPtr; - STR_String *m_stringPtr; - MT_Vector3 *m_vectorPtr; - char *m_charPtr; - } m_typeCheck; -} PyAttributeDef; - -#define KX_PYATTRIBUTE_BOOL_RW(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_BOOL_RW_CHECK(name, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_BOOL_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} } - -/* attribute points to a single bit of an integer field, attribute=true if bit is set */ -#define KX_PYATTRIBUTE_FLAG_RW(name, object, field, bit) \ - { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLAG_RW_CHECK(name, object, field, bit, function) \ - { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLAG_RO(name, object, field, bit) \ - { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } - -/* attribute points to a single bit of an integer field, attribute=true if bit is set*/ -#define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW(name, object, field, bit) \ - { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW_CHECK(name, object, field, bit, function) \ - { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLAG_NEGATIVE_RO(name, object, field, bit) \ - { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } - -// enum field cannot be mapped to pointer (because we would need a pointer for each enum) -// use field size to verify mapping at runtime only, assuming enum size is equal to int size. -#define KX_PYATTRIBUTE_ENUM_RW(name, min, max, clamp, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_ENUM_RW_CHECK(name, min, max, clamp, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_ENUM_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } - -#define KX_PYATTRIBUTE_SHORT_RW(name, min, max, clamp, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_RW_CHECK(name, min, max, clamp, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name, min, max, clamp, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name, min, max, clamp, object, field, length, function) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -// SHORT_LIST -#define KX_PYATTRIBUTE_SHORT_LIST_RW(name, min, max, clamp, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_LIST_RW_CHECK(name, min, max, clamp, object, field, length, function) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_SHORT_LIST_RO(name, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} } - -#define KX_PYATTRIBUTE_INT_RW(name, min, max, clamp, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_RW_CHECK(name, min, max, clamp, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_ARRAY_RW(name, min, max, clamp, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name, min, max, clamp, object, field, length, function) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_ARRAY_RO(name, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} } -// INT_LIST -#define KX_PYATTRIBUTE_INT_LIST_RW(name, min, max, clamp, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_LIST_RW_CHECK(name, min, max, clamp, object, field, length, function) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_INT_LIST_RO(name, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} } - -// always clamp for float -#define KX_PYATTRIBUTE_FLOAT_RW(name, min, max, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_RW_CHECK(name, min, max, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} } -// field must be float[n], returns a sequence -#define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name, min, max, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name, min, max, object, field, length, function) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -// field must be float[n], returns a vector -#define KX_PYATTRIBUTE_FLOAT_VECTOR_RW(name, min, max, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_VECTOR_RW_CHECK(name, min, max, object, field, length, function) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_VECTOR_RO(name, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, length, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} } -// field must be float[n][n], returns a matrix -#define KX_PYATTRIBUTE_FLOAT_MATRIX_RW(name, min, max, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, length, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_MATRIX_RW_CHECK(name, min, max, object, field, length, function) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, length, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_FLOAT_MATRIX_RO(name, object, field, length) \ - { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, length, length, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} } - -// only for STR_String member -#define KX_PYATTRIBUTE_STRING_RW(name, min, max, clamp, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } -#define KX_PYATTRIBUTE_STRING_RW_CHECK(name, min, max, clamp, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } -#define KX_PYATTRIBUTE_STRING_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} } - -// only for char [] array -#define KX_PYATTRIBUTE_CHAR_RW(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } -#define KX_PYATTRIBUTE_CHAR_RW_CHECK(name, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } -#define KX_PYATTRIBUTE_CHAR_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} } - -// for MT_Vector3 member -#define KX_PYATTRIBUTE_VECTOR_RW(name, min, max, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } -#define KX_PYATTRIBUTE_VECTOR_RW_CHECK(name, min, max, clamp, object, field, function) \ - { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } -#define KX_PYATTRIBUTE_VECTOR_RO(name, object, field) \ - { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} } - -#define KX_PYATTRIBUTE_RW_FUNCTION(name, object, getfunction, setfunction) \ - { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_RO_FUNCTION(name, object, getfunction) \ - { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_ARRAY_RW_FUNCTION(name, object, length, getfunction, setfunction) \ - { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0, f, false, false, 0, 0, length, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } -#define KX_PYATTRIBUTE_ARRAY_RO_FUNCTION(name, object, length, getfunction) \ - { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0, f, false, false, 0, 0, length, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } - - -/*------------------------------ - * PyObjectPlus - *------------------------------ */ -typedef PyTypeObject *PyParentObject; /* Define the PyParent Object */ - -#else // WITH_PYTHON - -#ifdef WITH_CXX_GUARDEDALLOC -#define Py_Header \ -public: \ - MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlus") \ - - -#define Py_HeaderPtr \ - MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlusPtr") \ - -#else // WITH_CXX_GUARDEDALLOC - -#define Py_Header \ -public: \ - -#define Py_HeaderPtr \ -public: \ - -#endif /* WITH_CXX_GUARDEDALLOC */ - -#endif - - -// By making SG_QList the ultimate parent for PyObjectPlus objects, it -// allows to put them in 2 different dynamic lists at the same time -// The use of these links is interesting because they free of memory allocation -// but it's very important not to mess up with them. If you decide that -// the SG_QList or SG_DList component is used for something for a certain class, -// they cannot can be used for anything else at a parent level! -// What these lists are and what they are used for must be carefully documented -// at the level where they are used. -// DON'T MAKE ANY USE OF THESE LIST AT THIS LEVEL, they are already used -// at SCA_IActuator, SCA_ISensor, SCA_IController level which rules out the -// possibility to use them at SCA_ILogicBrick, CValue and PyObjectPlus level. -class PyObjectPlus : public SG_QList -{ // The PyObjectPlus abstract class - Py_Header // Always start with Py_Header - -public: - PyObjectPlus(); - - virtual ~PyObjectPlus(); // destructor - -#ifdef WITH_PYTHON - PyObject *m_proxy; /* actually a PyObjectPlus_Proxy */ - - /* These static functions are referenced by ALL PyObjectPlus_Proxy types - * they take the C++ reference from the PyObjectPlus_Proxy and call - * its own virtual py_repr, py_base_dealloc, etc. functions. - */ - - static PyObject* py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds); /* allows subclassing */ - static void py_base_dealloc(PyObject *self); - static PyObject* py_base_repr(PyObject *self); - - /* These are all virtual python methods that are defined in each class - * Our own fake subclassing calls these on each class, then calls the parent */ - virtual PyObject* py_repr(void); - /* subclass may overwrite this function to implement more sophisticated method of validating a proxy */ - virtual bool py_is_valid(void) { return true; } - - static PyObject* py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef); - static int py_set_attrdef(PyObject *self_py, PyObject *value, const PyAttributeDef *attrdef); - - /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */ - static PyObject* pyattr_get_invalid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef); - - static PyObject *GetProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr); - /* self=NULL => proxy to generic pointer detached from GE object - * if py_owns is true, the memory pointed by ptr will be deleted automatically with MEM_freeN - * self!=NULL=> proxy attached to GE object, ptr is optional and point to a struct from which attributes can be defined - * if py_owns is true, the object will be deleted automatically, ptr will NOT be deleted - * (assume object destructor takes care of it) */ - static PyObject *NewProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr, bool py_owns); - - static WarnLink* GetDeprecationWarningLinkFirst(void); - static WarnLink* GetDeprecationWarningLinkLast(void); - static void SetDeprecationWarningFirst(WarnLink* wlink); - static void SetDeprecationWarningLinkLast(WarnLink* wlink); - static void NullDeprecationWarning(); - - /** enable/disable display of deprecation warnings */ - static void SetDeprecationWarnings(bool ignoreDeprecationWarnings); - /** Shows a deprecation warning */ - static void ShowDeprecationWarning_func(const char *method, const char *prop); - static void ClearDeprecationWarning(); - -#endif - - void InvalidateProxy(); - - /** - * Makes sure any internal data owned by this class is deep copied. - */ - virtual void ProcessReplica(); - - static bool m_ignore_deprecation_warnings; -}; - -#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 /* __EXP_PYOBJECTPLUS_H__ */ diff --git a/source/gameengine/Expressions/EXP_Python.h b/source/gameengine/Expressions/EXP_Python.h deleted file mode 100644 index f904151085e..00000000000 --- a/source/gameengine/Expressions/EXP_Python.h +++ /dev/null @@ -1,82 +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_Python.h - * \ingroup expressions - */ - -#ifndef __EXP_PYTHON_H__ -#define __EXP_PYTHON_H__ - -//#define USE_DL_EXPORT - -/* python redefines, quiet the compiler */ -#ifdef _XOPEN_SOURCE -#undef _XOPEN_SOURCE -#endif - -#ifdef _POSIX_C_SOURCE -#undef _POSIX_C_SOURCE -#endif - -#ifdef WITH_PYTHON -#include "Python.h" - -#define USE_MATHUTILS // Blender 2.5x api will use mathutils, for a while we might want to test without it - -#endif - -#ifdef __FreeBSD__ -#include <osreldate.h> -#if __FreeBSD_version > 500039 -#undef isalnum -#undef isalpha -#undef iscntrl -#undef isdigit -#undef isgraph -#undef islower -#undef isprint -#undef ispunct -#undef isspace -#undef isupper -#undef isxdigit -#undef tolower -#undef toupper -#endif -#endif - -#ifdef __APPLE__ -#undef isalnum -#undef isalpha -#undef islower -#undef isspace -#undef isupper -#undef tolower -#undef toupper -#endif - -#endif /* __EXP_PYTHON_H__ */ diff --git a/source/gameengine/Expressions/EXP_PythonCallBack.h b/source/gameengine/Expressions/EXP_PythonCallBack.h deleted file mode 100644 index f0cbcac0c6f..00000000000 --- a/source/gameengine/Expressions/EXP_PythonCallBack.h +++ /dev/null @@ -1,40 +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. - * - * 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/EXP_StringValue.h b/source/gameengine/Expressions/EXP_StringValue.h deleted file mode 100644 index ca59ebf1f82..00000000000 --- a/source/gameengine/Expressions/EXP_StringValue.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * StringValue.h: interface for the CStringValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_StringValue.h - * \ingroup expressions - */ - -#ifndef __EXP_STRINGVALUE_H__ -#define __EXP_STRINGVALUE_H__ - -#include "EXP_Value.h" - -class CStringValue : public CPropValue -{ - - - //PLUGIN_DECLARE_SERIAL(CStringValue,CValue) -public: - /// Construction / destruction - CStringValue(); - CStringValue(const char *txt, const char *name, AllocationTYPE alloctype = CValue::HEAPVALUE); - - virtual ~CStringValue() {} - /// CValue implementation - virtual bool IsEqual(const STR_String & other); - virtual const STR_String & GetText(); - virtual double GetNumber(); - virtual int GetValueType(); - - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - virtual void SetValue(CValue* newval) { m_strString = newval->GetText(); SetModified(true); } - virtual CValue* GetReplica(); -#ifdef WITH_PYTHON - virtual PyObject* ConvertValueToPython() { - return PyUnicode_From_STR_String(m_strString); - } -#endif /* WITH_PYTHON */ - -private: - // data member - STR_String m_strString; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CStringValue") -#endif -}; - -#endif /* __EXP_STRINGVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_Value.h b/source/gameengine/Expressions/EXP_Value.h deleted file mode 100644 index 014fc59405f..00000000000 --- a/source/gameengine/Expressions/EXP_Value.h +++ /dev/null @@ -1,432 +0,0 @@ -/* - * Value.h: interface for the CValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_Value.h - * \ingroup expressions - */ - -#ifndef __EXP_VALUE_H__ -#define __EXP_VALUE_H__ - -#ifdef _MSC_VER -# pragma warning (disable:4786) -#endif - -#include <map> // array functionality for the propertylist -#include "STR_String.h" // STR_String class - -using namespace std; - -#ifdef WITH_CXX_GUARDEDALLOC -#include "MEM_guardedalloc.h" -#endif - -#ifndef GEN_NO_ASSERT -#undef assert -#define assert(exp) ((void)NULL) -#endif - - -#ifndef GEN_NO_TRACE -#undef trace -#define trace(exp) ((void)NULL) -#endif - -#ifndef GEN_NO_DEBUG -#undef debug -#define debug(exp) ((void)NULL) -#endif - -#ifndef GEN_NO_ASSERTD -#undef assertd -#define assertd(exp) ((void)NULL) -#endif - -enum VALUE_OPERATOR { - - VALUE_MOD_OPERATOR, // % - VALUE_ADD_OPERATOR, // + - VALUE_SUB_OPERATOR, // - - VALUE_MUL_OPERATOR, // * - VALUE_DIV_OPERATOR, // / - VALUE_NEG_OPERATOR, // - - VALUE_POS_OPERATOR, // + - VALUE_AND_OPERATOR, // && - VALUE_OR_OPERATOR, // || - VALUE_EQL_OPERATOR, // == - VALUE_NEQ_OPERATOR, // != - VALUE_GRE_OPERATOR, // > - VALUE_LES_OPERATOR, // < - VALUE_GEQ_OPERATOR, // >= - VALUE_LEQ_OPERATOR, // <= - VALUE_NOT_OPERATOR, // ! - VALUE_NO_OPERATOR // no operation at all -}; - -enum VALUE_DATA_TYPE { - VALUE_NO_TYPE, // abstract baseclass - VALUE_INT_TYPE, - VALUE_FLOAT_TYPE, - VALUE_STRING_TYPE, - VALUE_BOOL_TYPE, - VALUE_ERROR_TYPE, - VALUE_EMPTY_TYPE, - VALUE_LIST_TYPE, - VALUE_VOID_TYPE, - VALUE_VECTOR_TYPE, - VALUE_MAX_TYPE //only here to provide number of types -}; - - - -#ifdef DEBUG -//extern int gRefCountValue; // debugonly variable to check if all CValue Refences are Dereferenced at programexit -#endif - -struct HashableInt -{ - HashableInt(int id) : mData(id) { } - - unsigned long Hash() const { return 0;} ////}gHash(&mData, sizeof(int));} - - bool operator==(HashableInt rhs) { return mData == rhs.mData; } - - int mData; -}; - - -// -// Bitfield that stores the flags for each CValue derived class -// -struct ValueFlags { - ValueFlags() : - Modified(true), - Selected(false), - Affected(false), - ReleaseRequested(false), - Error(false), - RefCountDisabled(false), - HasProperties(false), - HasName(false), - Visible(true), - CustomFlag1(false), - CustomFlag2(false) - { - } - - unsigned short Modified : 1; - unsigned short Selected : 1; - unsigned short Affected : 1; - unsigned short ReleaseRequested : 1; - unsigned short Error : 1; - unsigned short RefCountDisabled : 1; - unsigned short HasProperties : 1; - unsigned short HasName : 1; - unsigned short Visible : 1; - unsigned short CustomFlag1 : 1; - unsigned short CustomFlag2 : 1; - - -}; - -/** - * Base Class for all Actions performed on CValue's. Can be extended for undo/redo system in future. - */ -class CAction -{ -public: - CAction() { - }; - virtual ~CAction() { - }; - virtual void Execute() const =0; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CAction") -#endif -}; - - -#include "EXP_PyObjectPlus.h" -#ifdef WITH_PYTHON -#include "object.h" -#endif - -/** - * Baseclass CValue - * - * Together with CExpression, CValue and it's derived classes can be used to - * parse expressions into a parsetree with error detecting/correcting capabilities - * also expandable by a CFactory pluginsystem - * - * Base class for all editor functionality, flexible object type that allows - * calculations and uses reference counting for memory management. - * - * Features: - * - Reference Counting (AddRef() / Release()) - * - Calculations (Calc() / CalcFinal()) - * - Configuration (Configure()) - * - Serialization (EdSerialize() / EdIdSerialize() / EdPtrSerialize() and macro PLUGIN_DECLARE_SERIAL - * - Property system (SetProperty() / GetProperty() / FindIdentifier()) - * - Replication (GetReplica()) - * - Flags (IsSelected() / IsModified() / SetSelected()...) - * - * - Some small editor-specific things added - * - A helperclass CompressorArchive handles the serialization - * - */ -class CValue : public PyObjectPlus - -{ -Py_Header -public: - enum AllocationTYPE { - STACKVALUE = 0, - HEAPVALUE = 1 - }; - - enum DrawTYPE { - STARTFRAME = 0, - ENDFRAME = 1, - INTERFRAME = 2 - }; - - - // Construction / Destruction - CValue(); - -#ifdef WITH_PYTHON - //static PyObject *PyMake(PyObject *, PyObject *); - virtual PyObject *py_repr(void) - { - return PyUnicode_From_STR_String(GetText()); - } - - virtual PyObject *ConvertValueToPython() { - return NULL; - } - - virtual CValue *ConvertPythonToValue(PyObject *pyobj, const bool do_type_exception, const char *error_prefix); - - static PyObject *pyattr_get_name(void *self, const KX_PYATTRIBUTE_DEF *attrdef); - - virtual PyObject *ConvertKeysToPython( void ); -#endif /* WITH_PYTHON */ - - - - // Expression Calculation - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val) = 0; - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) = 0; - virtual void SetOwnerExpression(class CExpression* expr); - - - - void Execute(const CAction& a) - { - a.Execute(); - }; - - /// Reference Counting - int GetRefCount() - { - return m_refcount; - } - - // Add a reference to this value - CValue *AddRef() - { - // Increase global reference count, used to see at the end of the program - // if all CValue-derived classes have been dereferenced to 0 - //debug(gRefCountValue++); -#ifdef DEBUG - //gRefCountValue++; -#endif - m_refcount++; - return this; - } - - // Release a reference to this value (when reference count reaches 0, the value is removed from the heap) - int Release() - { - // Decrease global reference count, used to see at the end of the program - // if all CValue-derived classes have been dereferenced to 0 - //debug(gRefCountValue--); -#ifdef DEBUG - //gRefCountValue--; -#endif - // Decrease local reference count, if it reaches 0 the object should be freed - if (--m_refcount > 0) - { - // Reference count normal, return new reference count - return m_refcount; - } - else - { - // Reference count reached 0, delete ourselves and return 0 - // MT_assert(m_refcount==0, "Reference count reached sub-zero, object released too much"); - - delete this; - return 0; - } - } - - - /// Property Management - virtual void SetProperty(const STR_String& name,CValue* ioProperty); // Set property <ioProperty>, overwrites and releases a previous property with the same name if needed - virtual void SetProperty(const char* name,CValue* ioProperty); - virtual CValue* GetProperty(const char* inName); // Get pointer to a property with name <inName>, returns NULL if there is no property named <inName> - virtual CValue* GetProperty(const STR_String & inName); - const STR_String& GetPropertyText(const STR_String & inName); // Get text description of property with name <inName>, returns an empty string if there is no property named <inName> - float GetPropertyNumber(const STR_String& inName,float defnumber); - virtual bool RemoveProperty(const char *inName); // Remove the property named <inName>, returns true if the property was succesfully removed, false if property was not found or could not be removed - virtual vector<STR_String> GetPropertyNames(); - virtual void ClearProperties(); // Clear all properties - - virtual void SetPropertiesModified(bool inModified); // Set all properties' modified flag to <inModified> - virtual bool IsAnyPropertyModified(); // Check if any of the properties in this value have been modified - - virtual CValue* GetProperty(int inIndex); // Get property number <inIndex> - virtual int GetPropertyCount(); // Get the amount of properties assiocated with this value - - virtual CValue* FindIdentifier(const STR_String& identifiername); - /** Set the wireframe color of this value depending on the CSG - * operator type <op> - * \attention: not implemented */ - virtual void SetColorOperator(VALUE_OPERATOR op); - - virtual const STR_String & GetText() = 0; - virtual double GetNumber() = 0; - virtual int GetValueType(); // Get Prop value type - double* ZeroVector() { return m_sZeroVec; } - virtual double* GetVector3(bool bGetTransformedVec = false); - - virtual STR_String& GetName() = 0; // Retrieve the name of the value - virtual void SetName(const char *name) = 0; // Set the name of the value - /** Sets the value to this cvalue. - * \attention this particular function should never be called. Why not abstract? */ - virtual void SetValue(CValue* newval); - virtual CValue* GetReplica() =0; - virtual void ProcessReplica(); - //virtual CValue* Copy() = 0; - - STR_String op2str(VALUE_OPERATOR op); - - // setting / getting flags - inline void SetSelected(bool bSelected) { m_ValFlags.Selected = bSelected; } - virtual void SetModified(bool bModified) { m_ValFlags.Modified = bModified; } - virtual void SetAffected(bool bAffected=true) { m_ValFlags.Affected = bAffected; } - inline void SetReleaseRequested(bool bReleaseRequested) { m_ValFlags.ReleaseRequested=bReleaseRequested; } - inline void SetError(bool err) { m_ValFlags.Error=err; } - inline void SetVisible (bool vis) { m_ValFlags.Visible=vis; } - - virtual bool IsModified() { return m_ValFlags.Modified; } - inline bool IsError() { return m_ValFlags.Error; } - virtual bool IsAffected() { return m_ValFlags.Affected || m_ValFlags.Modified; } - virtual bool IsSelected() { return m_ValFlags.Selected; } - inline bool IsReleaseRequested() { return m_ValFlags.ReleaseRequested; } - virtual bool IsVisible() { return m_ValFlags.Visible;} - virtual void SetCustomFlag1(bool bCustomFlag) { m_ValFlags.CustomFlag1 = bCustomFlag;} - virtual bool IsCustomFlag1() { return m_ValFlags.CustomFlag1;} - - virtual void SetCustomFlag2(bool bCustomFlag) { m_ValFlags.CustomFlag2 = bCustomFlag;} - virtual bool IsCustomFlag2() { return m_ValFlags.CustomFlag2;} - -protected: - virtual void DisableRefCount(); // Disable reference counting for this value - //virtual void AddDataToReplica(CValue* replica); - virtual ~CValue(); -private: - // Member variables - std::map<STR_String,CValue*>* m_pNamedPropertyArray; // Properties for user/game etc - ValueFlags m_ValFlags; // Frequently used flags in a bitfield (low memoryusage) - int m_refcount; // Reference Counter - static double m_sZeroVec[3]; - -}; - - - -// -// Declare a CValue or CExpression or CWhatever to be serialized by the editor. -// -// This macro introduces the EdSerialize() function (which must be implemented by -// the client) and the EdIdSerialize() function (which is implemented by this macro). -// -// The generated Copy() function returns a pointer to <root_base_class_name> type -// of object. So, for *any* CValue-derived object this should be set to CValue, -// for *any* CExpression-derived object this should be set to CExpression. -// -#define PLUGIN_DECLARE_SERIAL(class_name, root_base_class_name) \ -public: \ - virtual root_base_class_name *Copy() { \ - return new class_name; \ - } \ - virtual bool EdSerialize(CompressorArchive& arch, \ - class CFactoryManager* facmgr, \ - bool bIsStoring); \ - virtual bool EdIdSerialize(CompressorArchive& arch, \ - class CFactoryManager* facmgr, \ - bool bIsStoring) \ - { \ - if (bIsStoring) \ - arch.StoreString(#class_name); \ - return false; \ - } \ - - -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -// CPropValue is a CValue derived class, that implements the identification (String name) -// SetName() / GetName(), -// normal classes should derive from CPropValue, real lightweight classes straight from CValue - - -class CPropValue : public CValue -{ -public: - CPropValue() : - CValue(), - m_strNewName() - - { - } - - virtual ~CPropValue() - { - } - - virtual void SetName(const char *name) { - m_strNewName = name; - } - - virtual STR_String& GetName() { - //STR_String namefromprop = GetPropertyText("Name"); - //if (namefromprop.Length() > 0) - // return namefromprop; - return m_strNewName; - } // name of Value - -protected: - STR_String m_strNewName; // Identification - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CPropValue") -#endif -}; - -#endif /* __EXP_VALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_VectorValue.h b/source/gameengine/Expressions/EXP_VectorValue.h deleted file mode 100644 index d87d5097156..00000000000 --- a/source/gameengine/Expressions/EXP_VectorValue.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * VectorValue.h: interface for the CVectorValue class. - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -/** \file EXP_VectorValue.h - * \ingroup expressions - */ - -#ifndef __EXP_VECTORVALUE_H__ -#define __EXP_VECTORVALUE_H__ - -#include "EXP_Value.h" - -#define KX_X 0 -#define KX_Y 1 -#define KX_Z 2 - - -class CVectorValue : public CPropValue -{ - //PLUGIN_DECLARE_SERIAL(CVectorValue,CValue) - -public: - //void Transform(rcMatrix4x4 mat); - virtual void SetValue(CValue* newval); - void SetVector(double newvec[]); - void Configure(CValue* menuvalue); - virtual double* GetVector3(bool bGetTransformedVec=false); - virtual double GetNumber(); - virtual int GetValueType(); - - CValue* Calc(VALUE_OPERATOR op, CValue *val) { - return val->CalcFinal(VALUE_VECTOR_TYPE, op, this); - } - - CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val); - - - CVectorValue(double vec[3], const char *name,AllocationTYPE alloctype=CValue::HEAPVALUE); - CVectorValue() {}; - - CVectorValue(double vec[3], AllocationTYPE alloctype=CValue::HEAPVALUE); - CVectorValue(float x,float y,float z, AllocationTYPE alloctype = CValue::HEAPVALUE); - virtual ~CVectorValue(); - //virtual bool ExportT3D(File *txtfile,bool bNoName=false); - void AddConfigurationData(CValue* menuvalue); - - - - virtual CValue* GetReplica(); - virtual const STR_String & GetText(); - -#if 0 - void SnapPoint(float num,int snap) - { - if (num > 0) num += ((float)snap / 2); - else num -= ((float)snap / 2); - num = (long)(((long)(num / snap)) * snap); - }; - - void SnapPosition(const double snapvec[]) - { - - if (snapvec[KX_X] >= 1) - SnapPoint(m_vec[KX_X],snapvec[KX_X]); - if (snapvec[KX_Y] >= 1) - SnapPoint(m_vec[KX_Y],snapvec[KX_Y]); - if (snapvec[KX_Z] >= 1) - SnapPoint(m_vec[KX_Z],snapvec[KX_Z]); - - } -#endif - -protected: - double m_vec[3]; - double m_transformedvec[3]; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CVectorValue") -#endif -}; - -#endif /* __EXP_VECTORVALUE_H__ */ diff --git a/source/gameengine/Expressions/EXP_VoidValue.h b/source/gameengine/Expressions/EXP_VoidValue.h deleted file mode 100644 index 8b2c29488d7..00000000000 --- a/source/gameengine/Expressions/EXP_VoidValue.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * VoidValue.h: interface for the CVoidValue class. - * - * ***** 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_VoidValue.h - * \ingroup expressions - */ - -#ifndef __EXP_VOIDVALUE_H__ -#define __EXP_VOIDVALUE_H__ - -#include "EXP_Value.h" - -// -// Void value, used to transport *any* type of data -// -class CVoidValue : public CPropValue -{ - //PLUGIN_DECLARE_SERIAL (CVoidValue,CValue) - -public: - /// Construction/destruction - CVoidValue() : m_bDeleteOnDestruct(false), m_pAnything(NULL) { } - CVoidValue(void *voidptr, bool bDeleteOnDestruct, AllocationTYPE alloctype) : - m_bDeleteOnDestruct(bDeleteOnDestruct), - m_pAnything(voidptr) - { - if (alloctype == STACKVALUE) { - CValue::DisableRefCount(); - } - } - virtual ~CVoidValue(); /* Destruct void value, delete memory if we're owning it */ - - /// Value -> String or number - virtual const STR_String & GetText(); /* Get string description of void value (unimplemented) */ - virtual double GetNumber() { return -1; } - virtual int GetValueType() { return VALUE_VOID_TYPE; } - - /// Value calculation - virtual CValue* Calc(VALUE_OPERATOR op, CValue *val); - virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue* val); - - /// Value replication - virtual CValue* GetReplica(); - - /// Data members - bool m_bDeleteOnDestruct; - void* m_pAnything; - - -#ifdef WITH_CXX_GUARDEDALLOC - MEM_CXX_CLASS_ALLOC_FUNCS("GE:CVoidValue") -#endif -}; - -#endif /* __EXP_VOIDVALUE_H__ */ diff --git a/source/gameengine/Expressions/intern/BoolValue.cpp b/source/gameengine/Expressions/intern/BoolValue.cpp deleted file mode 100644 index 1523a9212ba..00000000000 --- a/source/gameengine/Expressions/intern/BoolValue.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/** \file gameengine/Expressions/BoolValue.cpp - * \ingroup expressions - */ - -// BoolValue.cpp: implementation of the CBoolValue class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include "EXP_BoolValue.h" -#include "EXP_StringValue.h" -#include "EXP_ErrorValue.h" -#include "EXP_VoidValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -const STR_String CBoolValue::sTrueString = "TRUE"; -const STR_String CBoolValue::sFalseString = "FALSE"; - -CBoolValue::CBoolValue() -/* - * pre: false - * effect: constructs a new CBoolValue - */ -{ - trace("Bool constructor error"); -} - - - -CBoolValue::CBoolValue(bool inBool) -: m_bool(inBool) -{ -} // Constructs a new CBoolValue containing <inBool> - - - -CBoolValue::CBoolValue(bool innie,const char *name,AllocationTYPE alloctype) -{ - m_bool = innie; - SetName(name); - - if (alloctype == CValue::STACKVALUE) - CValue::DisableRefCount(); -} - - - -void CBoolValue::SetValue(CValue* newval) -{ - m_bool = (newval->GetNumber() != 0); - SetModified(true); -} - - - -CValue* CBoolValue::Calc(VALUE_OPERATOR op, CValue *val) -/* -pre: -ret: a new object containing the result of applying operator op to this -object and val -*/ -{ - switch (op) - { - case VALUE_POS_OPERATOR: - case VALUE_NEG_OPERATOR: - { - return new CErrorValue (op2str(op) + GetText()); - break; - } - case VALUE_NOT_OPERATOR: - { - return new CBoolValue (!m_bool); - break; - } - default: - { - return val->CalcFinal(VALUE_BOOL_TYPE, op, this); - break; - } - } -} - - - -CValue* CBoolValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -/* -pre: the type of val is dtype -ret: a new object containing the result of applying operator op to val and -this object -*/ -{ - CValue *ret; - - switch (dtype) { - case VALUE_EMPTY_TYPE: - case VALUE_BOOL_TYPE: - { - switch (op) { - case VALUE_AND_OPERATOR: - { - ret = new CBoolValue (((CBoolValue *) val)->GetBool() && m_bool); - break; - } - case VALUE_OR_OPERATOR: - { - ret = new CBoolValue (((CBoolValue *) val)->GetBool() || m_bool); - break; - } - case VALUE_EQL_OPERATOR: - { - ret = new CBoolValue (((CBoolValue *) val)->GetBool() == m_bool); - break; - } - case VALUE_NEQ_OPERATOR: - { - ret = new CBoolValue (((CBoolValue *) val)->GetBool() != m_bool); - break; - } - case VALUE_NOT_OPERATOR: - { - return new CBoolValue (!m_bool); - break; - } - default: - { - ret = new CErrorValue(val->GetText() + op2str(op) + - "[operator not allowed on booleans]"); - break; - } - } - break; - } - case VALUE_STRING_TYPE: - { - switch (op) { - case VALUE_ADD_OPERATOR: - { - ret = new CStringValue(val->GetText() + GetText(),""); - break; - } - default: - { - ret = new CErrorValue(val->GetText() + op2str(op) + "[Only + allowed on boolean and string]"); - break; - } - } - break; - } - default: - ret = new CErrorValue("[type mismatch]" + op2str(op) + GetText()); - } - - return ret; -} - - - -bool CBoolValue::GetBool() -/* -pre: -ret: the bool stored in the object -*/ -{ - return m_bool; -} - - - -double CBoolValue::GetNumber() -{ - return (double)m_bool; -} - - - -int CBoolValue::GetValueType() -{ - return VALUE_BOOL_TYPE; -} - - - -const STR_String& CBoolValue::GetText() -{ - return m_bool ? sTrueString : sFalseString; -} - - - -CValue* CBoolValue::GetReplica() -{ - CBoolValue* replica = new CBoolValue(*this); - replica->ProcessReplica(); - - return replica; -} - -#ifdef WITH_PYTHON -PyObject *CBoolValue::ConvertValueToPython() -{ - return PyBool_FromLong(m_bool != 0); -} -#endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/intern/ConstExpr.cpp b/source/gameengine/Expressions/intern/ConstExpr.cpp deleted file mode 100644 index 597427ecfe5..00000000000 --- a/source/gameengine/Expressions/intern/ConstExpr.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** \file gameengine/Expressions/ConstExpr.cpp - * \ingroup expressions - */ -// ConstExpr.cpp: implementation of the CConstExpr class. - -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include "EXP_Value.h" // for precompiled header -#include "EXP_ConstExpr.h" -#include "EXP_VectorValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CConstExpr::CConstExpr() -{ -} - - - -CConstExpr::CConstExpr(CValue* constval) -/* -pre: -effect: constructs a CConstExpr cointing the value constval -*/ -{ - m_value = constval; -// m_bModified=true; -} - - - -CConstExpr::~CConstExpr() -/* -pre: -effect: deletes the object -*/ -{ - if (m_value) - m_value->Release(); -} - - - -unsigned char CConstExpr::GetExpressionID() -{ - return CCONSTEXPRESSIONID; -} - - - -CValue* CConstExpr::Calculate() -/* -pre: -ret: a new object containing the value of the stored CValue -*/ -{ - return m_value->AddRef(); -} - - - -void CConstExpr::ClearModified() -{ - if (m_value) - { - m_value->SetModified(false); - m_value->SetAffected(false); - } -} - - - -double CConstExpr::GetNumber() -{ - return -1; -} - - - -bool CConstExpr::NeedsRecalculated() -{ - return m_value->IsAffected(); // IsAffected is m_bModified OR m_bAffected !!! -} - - - -CExpression* CConstExpr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) -{ -// parent checks if child is still useful. -// When for example it's value it's deleted flag set -// then release Value, and return NULL in case of constexpression -// else return this... - - assertd(m_value); - if (m_value->IsReleaseRequested()) - { - AddRef(); //numchanges++; - return Release(); - } - else - return this; -} - - - -void CConstExpr::BroadcastOperators(VALUE_OPERATOR op) -{ - assertd(m_value); - m_value->SetColorOperator(op); -} - - - -bool CConstExpr::MergeExpression(CExpression *otherexpr) -{ - assertd(false); - return false; -} diff --git a/source/gameengine/Expressions/intern/EmptyValue.cpp b/source/gameengine/Expressions/intern/EmptyValue.cpp deleted file mode 100644 index 9227626777d..00000000000 --- a/source/gameengine/Expressions/intern/EmptyValue.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/** \file gameengine/Expressions/EmptyValue.cpp - * \ingroup expressions - */ - -// EmptyValue.cpp: implementation of the CEmptyValue class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#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 -////////////////////////////////////////////////////////////////////// - -CEmptyValue::CEmptyValue() -/* - * pre: - * effect: constructs a new CEmptyValue - */ -{ - SetModified(false); -} - - - -CEmptyValue::~CEmptyValue() -/* - * pre: - * effect: deletes the object - */ -{ - -} - - - -CValue *CEmptyValue::Calc(VALUE_OPERATOR op, CValue *val) -/* - * pre: - * ret: a new object containing the result of applying operator op to this - * object and val - */ -{ - return val->CalcFinal(VALUE_EMPTY_TYPE, op, this); - -} - - - -CValue * CEmptyValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -/* - * pre: the type of val is dtype - * ret: a new object containing the result of applying operator op to val and - * this object - */ -{ - return val->AddRef(); -} - - - -double CEmptyValue::GetNumber() -{ - return 0; -} - - - -int CEmptyValue::GetValueType() -{ - return VALUE_EMPTY_TYPE; -} - - - -CListValue* CEmptyValue::GetPolySoup() -{ - CListValue* soup = new CListValue(); - //don't add any poly, while it's an empty value - return soup; -} - - - -bool CEmptyValue::IsInside(CValue* testpoint,bool bBorderInclude) -{ - // empty space is solid, so always inside - return true; -} - - - -double* CEmptyValue::GetVector3(bool bGetTransformedVec) -{ - assertd(false); // don't get vector from me - return ZeroVector(); -} - - - -static STR_String emptyString = STR_String(""); - - -const STR_String & CEmptyValue::GetText() -{ - return emptyString; -} - - - -CValue* CEmptyValue::GetReplica() -{ - CEmptyValue* replica = new CEmptyValue(*this); - replica->ProcessReplica(); - return replica; -} - diff --git a/source/gameengine/Expressions/intern/ErrorValue.cpp b/source/gameengine/Expressions/intern/ErrorValue.cpp deleted file mode 100644 index c03ceb88073..00000000000 --- a/source/gameengine/Expressions/intern/ErrorValue.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/** \file gameengine/Expressions/ErrorValue.cpp - * \ingroup expressions - */ -// ErrorValue.cpp: implementation of the CErrorValue class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include "EXP_ErrorValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CErrorValue::CErrorValue() -/* -pre: -effect: constructs a new CErrorValue containing errormessage "Error" -*/ -{ - m_strErrorText = "Error"; - SetError(true); -} - - - -CErrorValue::CErrorValue(const char *errmsg) -/* -pre: -effect: constructs a new CErrorValue containing errormessage errmsg -*/ -{ - m_strErrorText = "["; - m_strErrorText += errmsg; - m_strErrorText += "]"; - SetError(true); -} - - - -CErrorValue::~CErrorValue() -/* -pre: -effect: deletes the object -*/ -{ - -} - - - -CValue* CErrorValue::Calc(VALUE_OPERATOR op, CValue *val) -/* -pre: -ret: a new object containing the result of applying operator op to this - object and val -*/ -{ - CValue* errorval; - - switch (op) - { - case VALUE_POS_OPERATOR: - case VALUE_NEG_OPERATOR: - case VALUE_NOT_OPERATOR: - { - errorval = new CErrorValue (op2str(op) + GetText()); - break; - } - default: - { - errorval = val->CalcFinal(VALUE_ERROR_TYPE, op, this); - break; - } - } - - return errorval; -} - - - -CValue* CErrorValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -/* -pre: the type of val is dtype -ret: a new object containing the result of applying operator op to val and - this object -*/ -{ - return new CErrorValue (val->GetText() + op2str(op) + GetText()); -} - - - -double CErrorValue::GetNumber() -{ - return -1; -} - - - -int CErrorValue::GetValueType() -{ - return VALUE_ERROR_TYPE; -} - - - -const STR_String & CErrorValue::GetText() -{ - return m_strErrorText; -} - - - -CValue* CErrorValue::GetReplica() -{ - // who would want a copy of an error ? - trace ("Error: ErrorValue::GetReplica() not implemented yet"); - assertd(false); - - return NULL; -} diff --git a/source/gameengine/Expressions/intern/Expression.cpp b/source/gameengine/Expressions/intern/Expression.cpp deleted file mode 100644 index 6a98a15aa12..00000000000 --- a/source/gameengine/Expressions/intern/Expression.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/** \file gameengine/Expressions/Expression.cpp - * \ingroup expressions - */ -// Expression.cpp: implementation of the CExpression class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include "EXP_Expression.h" -#include "EXP_ErrorValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// -#ifdef DEBUG -//int gRefCountExpr; -#endif -CExpression::CExpression()// : m_cached_calculate(NULL) -{ - m_refcount = 1; -#ifdef DEBUG - //gRefCountExpr++; -#endif -} - -CExpression::~CExpression() -{ - assert (m_refcount == 0); -} - - - -// destuctor for CBrokenLinkInfo -CBrokenLinkInfo::~CBrokenLinkInfo() -{ - if (m_pExpr && !m_bRestored) - m_pExpr->Release(); -} - - -void CBrokenLinkInfo::RestoreLink() -{ - - - assertd(m_pExpr); - - if (m_pExpr) - { - if (!m_bRestored) { - m_bRestored=true; - - } - if (*m_pmemExpr) - { - (*m_pmemExpr)->Release(); - } - *m_pmemExpr = m_pExpr; - -// m_pExpr=NULL; - } -} - -void CBrokenLinkInfo::BreakLink() -{ - m_bRestored=false; - m_pExpr->AddRef(); -} - diff --git a/source/gameengine/Expressions/intern/FloatValue.cpp b/source/gameengine/Expressions/intern/FloatValue.cpp deleted file mode 100644 index 0f86a429d81..00000000000 --- a/source/gameengine/Expressions/intern/FloatValue.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/** \file gameengine/Expressions/FloatValue.cpp - * \ingroup expressions - */ -// FloatValue.cpp: implementation of the CFloatValue class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#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 -////////////////////////////////////////////////////////////////////// - -CFloatValue::CFloatValue() -/* -pre: false -effect: constructs a new CFloatValue -*/ -{ - m_pstrRep=NULL; -} - - - -CFloatValue::CFloatValue(float fl) -/* -pre: -effect: constructs a new CFloatValue containing value fl -*/ -{ - m_float = fl; - m_pstrRep=NULL; -} - - - -CFloatValue::CFloatValue(float fl,const char *name,AllocationTYPE alloctype) -/* -pre: -effect: constructs a new CFloatValue containing value fl -*/ -{ - - m_float = fl; - SetName(name); - if (alloctype==CValue::STACKVALUE) - { - CValue::DisableRefCount(); - - } - m_pstrRep=NULL; -} - - - -CFloatValue::~CFloatValue() -/* -pre: -effect: deletes the object -*/ -{ - if (m_pstrRep) - delete m_pstrRep; -} - - - -CValue* CFloatValue::Calc(VALUE_OPERATOR op, CValue *val) -/* -pre: -ret: a new object containing the result of applying operator op to this - object and val -*/ -{ - //return val->CalcFloat(op, this); - switch (op) - { - case VALUE_POS_OPERATOR: - return new CFloatValue (m_float); - break; - case VALUE_NEG_OPERATOR: - return new CFloatValue (-m_float); - break; - case VALUE_NOT_OPERATOR: - return new CBoolValue (m_float == 0.f); - break; - case VALUE_AND_OPERATOR: - case VALUE_OR_OPERATOR: - return new CErrorValue(val->GetText() + op2str(op) + "only allowed on booleans"); - break; - default: - return val->CalcFinal(VALUE_FLOAT_TYPE, op, this); - break; - } -} - - - -CValue* CFloatValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -/* -pre: the type of val is dtype -ret: a new object containing the result of applying operator op to val and - this object -*/ -{ - CValue *ret; - - switch (dtype) { - case VALUE_INT_TYPE: - { - switch (op) { - case VALUE_MOD_OPERATOR: - ret = new CFloatValue(fmod(((CIntValue *) val)->GetInt(), m_float)); - break; - case VALUE_ADD_OPERATOR: - ret = new CFloatValue(((CIntValue *) val)->GetInt() + m_float); - break; - case VALUE_SUB_OPERATOR: - ret = new CFloatValue(((CIntValue *) val)->GetInt() - m_float); - break; - case VALUE_MUL_OPERATOR: - ret = new CFloatValue(((CIntValue *) val)->GetInt() * m_float); - break; - case VALUE_DIV_OPERATOR: - if (m_float == 0) - ret = new CErrorValue("Division by zero"); - else - ret = new CFloatValue (((CIntValue *) val)->GetInt() / m_float); - break; - case VALUE_EQL_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() == m_float); - break; - case VALUE_NEQ_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() != m_float); - break; - case VALUE_GRE_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() > m_float); - break; - case VALUE_LES_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() < m_float); - break; - case VALUE_GEQ_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() >= m_float); - break; - case VALUE_LEQ_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() <= m_float); - break; - case VALUE_NOT_OPERATOR: - ret = new CBoolValue(m_float == 0); - break; - default: - ret = new CErrorValue("illegal operator. please send a bug report."); - break; - } - break; - } - case VALUE_EMPTY_TYPE: - case VALUE_FLOAT_TYPE: - { - switch (op) { - case VALUE_MOD_OPERATOR: - ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_float)); - break; - case VALUE_ADD_OPERATOR: - ret = new CFloatValue(((CFloatValue *) val)->GetFloat() + m_float); - break; - case VALUE_SUB_OPERATOR: - ret = new CFloatValue(((CFloatValue *) val)->GetFloat() - m_float); - break; - case VALUE_MUL_OPERATOR: - ret = new CFloatValue(((CFloatValue *) val)->GetFloat() * m_float); - break; - case VALUE_DIV_OPERATOR: - if (m_float == 0) - ret = new CErrorValue("Division by zero"); - else - ret = new CFloatValue (((CFloatValue *) val)->GetFloat() / m_float); - break; - case VALUE_EQL_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() == m_float); - break; - case VALUE_NEQ_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() != m_float); - break; - case VALUE_GRE_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() > m_float); - break; - case VALUE_LES_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() < m_float); - break; - case VALUE_GEQ_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() >= m_float); - break; - case VALUE_LEQ_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() <= m_float); - break; - case VALUE_NEG_OPERATOR: - ret = new CFloatValue (-m_float); - break; - case VALUE_POS_OPERATOR: - ret = new CFloatValue (m_float); - break; - case VALUE_NOT_OPERATOR: - ret = new CBoolValue(m_float == 0); - break; - default: - ret = new CErrorValue("illegal operator. please send a bug report."); - break; - } - break; - } - case VALUE_STRING_TYPE: - { - switch (op) { - case VALUE_ADD_OPERATOR: - ret = new CStringValue(val->GetText() + GetText(),""); - break; - case VALUE_EQL_OPERATOR: - case VALUE_NEQ_OPERATOR: - case VALUE_GRE_OPERATOR: - case VALUE_LES_OPERATOR: - case VALUE_GEQ_OPERATOR: - case VALUE_LEQ_OPERATOR: - ret = new CErrorValue("[Cannot compare string with float]" + op2str(op) + GetText()); - break; - default: - ret = new CErrorValue("[operator not allowed on strings]" + op2str(op) + GetText()); - break; - } - break; - } - case VALUE_BOOL_TYPE: - ret = new CErrorValue("[operator not valid on boolean and float]" + op2str(op) + GetText()); - break; - case VALUE_ERROR_TYPE: - ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); - break; - default: - ret = new CErrorValue("illegal type. contact your dealer (if any)"); - break; - } - return ret; -} - - - -void CFloatValue::SetFloat(float fl) -{ - m_float = fl; - SetModified(true); -} - - - -float CFloatValue::GetFloat() -/* -pre: -ret: the float stored in the object -*/ -{ - return m_float; -} - - - -double CFloatValue::GetNumber() -{ - return m_float; -} - - - -int CFloatValue::GetValueType() -{ - return VALUE_FLOAT_TYPE; -} - - - -void CFloatValue::SetValue(CValue* newval) -{ - m_float = (float)newval->GetNumber(); - SetModified(true); -} - - - -const STR_String & CFloatValue::GetText() -{ - if (!m_pstrRep) - m_pstrRep = new STR_String(); - - m_pstrRep->Format("%f",m_float); - return *m_pstrRep; -} - - - -CValue* CFloatValue::GetReplica() -{ - CFloatValue* replica = new CFloatValue(*this); - replica->m_pstrRep = NULL; /* should be in CFloatValue::ProcessReplica() but its not defined, no matter */ - replica->ProcessReplica(); - - return replica; -} - - -#ifdef WITH_PYTHON -PyObject *CFloatValue::ConvertValueToPython() -{ - return PyFloat_FromDouble(m_float); -} -#endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/intern/HashedPtr.cpp b/source/gameengine/Expressions/intern/HashedPtr.cpp deleted file mode 100644 index 11d9482f993..00000000000 --- a/source/gameengine/Expressions/intern/HashedPtr.cpp +++ /dev/null @@ -1,57 +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/KX_HashedPtr.cpp - * \ingroup expressions - */ - - -#include "EXP_HashedPtr.h" - - -CHashedPtr::CHashedPtr(void* val) : m_valptr(val) -{ -} - - -unsigned int CHashedPtr::hash() const -{ -#if defined(_WIN64) - unsigned __int64 key = (unsigned __int64)m_valptr; -#else - unsigned long key = (unsigned long)m_valptr; -#endif - - key += ~(key << 16); - key ^= (key >> 5); - key += (key << 3); - key ^= (key >> 13); - key += ~(key << 9); - key ^= (key >> 17); - - return (unsigned int)(key & 0xffffffff); -} diff --git a/source/gameengine/Expressions/intern/IdentifierExpr.cpp b/source/gameengine/Expressions/intern/IdentifierExpr.cpp deleted file mode 100644 index 8fbbf41cd63..00000000000 --- a/source/gameengine/Expressions/intern/IdentifierExpr.cpp +++ /dev/null @@ -1,103 +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/IdentifierExpr.cpp - * \ingroup expressions - */ - - -#include "EXP_IdentifierExpr.h" - -CIdentifierExpr::CIdentifierExpr(const STR_String& identifier,CValue* id_context) -:m_identifier(identifier) -{ - if (id_context) - m_idContext = id_context->AddRef(); - else - m_idContext=NULL; -} - - -CIdentifierExpr::~CIdentifierExpr() -{ - if (m_idContext) - m_idContext->Release(); -} - - - -CValue* CIdentifierExpr::Calculate() -{ - CValue* result = NULL; - if (m_idContext) - result = m_idContext->FindIdentifier(m_identifier); - - return result; -} - - - -bool CIdentifierExpr::MergeExpression(CExpression* otherexpr) -{ - return false; -} - - - -unsigned char CIdentifierExpr::GetExpressionID() -{ - return CIDENTIFIEREXPRESSIONID; -} - - - -bool CIdentifierExpr::NeedsRecalculated() -{ - return true; -} - - - -CExpression* CIdentifierExpr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) -{ - assertd(false); // not implemented yet - return NULL; -} - - - -void CIdentifierExpr::ClearModified() -{ - assertd(false); // not implemented yet -} - - - -void CIdentifierExpr::BroadcastOperators(VALUE_OPERATOR op) -{ - assertd(false); // not implemented yet -} diff --git a/source/gameengine/Expressions/intern/IfExpr.cpp b/source/gameengine/Expressions/intern/IfExpr.cpp deleted file mode 100644 index b4e2fe7315b..00000000000 --- a/source/gameengine/Expressions/intern/IfExpr.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/** \file gameengine/Expressions/IfExpr.cpp - * \ingroup expressions - */ -// IfExpr.cpp: implementation of the CIfExpr class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include "EXP_IfExpr.h" -#include "EXP_EmptyValue.h" -#include "EXP_ErrorValue.h" -#include "EXP_BoolValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - - -CIfExpr::CIfExpr() -{ -} - - - -/* - * pre: - * effect: constructs an CifExpr-object corresponding to IF(guard, e1, e2) - */ -CIfExpr::CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2) -{ - m_guard = guard; - m_e1 = e1; - m_e2 = e2; -} - - - -/* - * pre: - * effect: dereferences the object - */ -CIfExpr::~CIfExpr() -{ - if (m_guard) - m_guard->Release(); - - if (m_e1) - m_e1->Release(); - - if (m_e2) - m_e2->Release(); -} - - - -/** - * pre: - * ret: a new object containing the value of m_e1 if m_guard is a boolean true - * a new object containing the value of m_e2 if m_guard is a boolean false - * an new errorvalue if m_guard is not a boolean - */ -CValue* CIfExpr::Calculate() -{ - CValue *guardval; - guardval = m_guard->Calculate(); - const STR_String& text = guardval->GetText(); - guardval->Release(); - - if (&text == &CBoolValue::sTrueString) - { - return m_e1->Calculate(); - } - else if (&text == &CBoolValue::sFalseString) - { - return m_e2->Calculate(); - } - else - { - return new CErrorValue("Guard should be of boolean type"); - } -} - - - -bool CIfExpr::MergeExpression(CExpression *otherexpr) -{ - assertd(false); - return false; -} - - - -bool CIfExpr::IsInside(float x,float y,float z,bool bBorderInclude) -{ - assertd(false); - return false; -} - - - -bool CIfExpr::NeedsRecalculated() -{ - return (m_guard->NeedsRecalculated() || - m_e1->NeedsRecalculated() || - m_e2->NeedsRecalculated()); -} - - - -CExpression* CIfExpr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) -{ - assertd(false); - return NULL; -} - - - -void CIfExpr::ClearModified() -{ - assertd(false); -} - - - -void CIfExpr::BroadcastOperators(VALUE_OPERATOR op) -{ - assertd(false); -} - - - -unsigned char CIfExpr::GetExpressionID() -{ - return CIFEXPRESSIONID; -} diff --git a/source/gameengine/Expressions/intern/InputParser.cpp b/source/gameengine/Expressions/intern/InputParser.cpp deleted file mode 100644 index 583d8da63cb..00000000000 --- a/source/gameengine/Expressions/intern/InputParser.cpp +++ /dev/null @@ -1,669 +0,0 @@ -/** \file gameengine/Expressions/InputParser.cpp - * \ingroup expressions - */ -// Parser.cpp: implementation of the CParser class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include <stdlib.h> - -#include "MT_assert.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 "EXP_IfExpr.h" - -#if defined(WIN32) || defined(WIN64) -#define strcasecmp _stricmp - -#ifndef strtoll -#define strtoll _strtoi64 -#endif - -#endif /* Def WIN32 or Def WIN64 */ - -#define NUM_PRIORITY 6 -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CParser::CParser() : m_identifierContext(NULL) -{ -} - - - -CParser::~CParser() -{ - if (m_identifierContext) - m_identifierContext->Release(); -} - - - -void CParser::ScanError(const char *str) -{ - // sets the global variable errmsg to an errormessage with - // contents str, appending if it already exists - // AfxMessageBox("Parse Error:"+str,MB_ICONERROR); - if (errmsg) - errmsg = new COperator2Expr(VALUE_ADD_OPERATOR, errmsg, Error(str)); - else - errmsg = Error(str); - - sym = errorsym; -} - - - -CExpression* CParser::Error(const char *str) -{ - // makes and returns a new CConstExpr filled with an CErrorValue - // with string str - // AfxMessageBox("Error:"+str,MB_ICONERROR); - return new CConstExpr(new CErrorValue(str)); -} - - - -void CParser::NextCh() -{ - // sets the global variable ch to the next character, if it exists - // and increases the global variable chcount - chcount++; - - if (chcount < text.Length()) - ch = text[chcount]; - else - ch = 0x00; -} - - - -void CParser::TermChar(char c) -{ - // generates an error if the next char isn't the specified char c, - // otherwise, skip the char - if (ch == c) - { - NextCh(); - } - else - { - STR_String str; - str.Format("Warning: %c expected\ncontinuing without it", c); - trace(str); - } -} - - - -void CParser::DigRep() -{ - // changes the current character to the first character that - // isn't a decimal - while ((ch >= '0') && (ch <= '9')) - NextCh(); -} - - - -void CParser::CharRep() -{ - // changes the current character to the first character that - // isn't an alphanumeric character - while (((ch >= '0') && (ch <= '9')) - || ((ch >= 'a') && (ch <= 'z')) - || ((ch >= 'A') && (ch <= 'Z')) - || (ch == '.') || (ch == '_')) - NextCh(); -} - - - -void CParser::GrabString(int start) -{ - // puts part of the input string into the global variable - // const_as_string, from position start, to position chchount - const_as_string = text.Mid(start, chcount-start); -} - - - -void CParser::GrabRealString(int start) -{ - // works like GrabString but converting \\n to \n - // puts part of the input string into the global variable - // const_as_string, from position start, to position chchount - - int i; - char tmpch; - - const_as_string = STR_String(); - for (i=start;i<chcount;i++) { - tmpch= text[i]; - if ((tmpch =='\\') && (text[i+1] == 'n')) { - tmpch = '\n'; - i++; - } - const_as_string += tmpch; - } -} - - - -void CParser::NextSym() -{ - // sets the global variable sym to the next symbol, and - // if it is an operator - // sets the global variable opkind to the kind of operator - // if it is a constant - // sets the global variable constkind to the kind of operator - // if it is a reference to a cell - // sets the global variable cellcoord to the kind of operator - - errmsg = NULL; - while (ch == ' ' || ch == 0x9) - NextCh(); - - switch (ch) { - case '(': - sym = lbracksym; NextCh(); - break; - case ')': - sym = rbracksym; NextCh(); - break; - case ',': - sym = commasym; NextCh(); - break; - case '%' : - sym = opsym; opkind = OPmodulus; NextCh(); - break; - case '+' : - sym = opsym; opkind = OPplus; NextCh(); - break; - case '-' : - sym = opsym; opkind = OPminus; NextCh(); - break; - case '*' : - sym = opsym; opkind = OPtimes; NextCh(); - break; - case '/' : - sym = opsym; opkind = OPdivide; NextCh(); - break; - case '&' : - sym = opsym; opkind = OPand; NextCh(); TermChar('&'); - break; - case '|' : - sym = opsym; opkind = OPor; NextCh(); TermChar('|'); - break; - case '=' : - sym = opsym; opkind = OPequal; NextCh(); TermChar('='); - break; - case '!' : - sym = opsym; - NextCh(); - if (ch == '=') - { - opkind = OPunequal; - NextCh(); - } - else - { - opkind = OPnot; - } - break; - case '>': - sym = opsym; - NextCh(); - if (ch == '=') - { - opkind = OPgreaterequal; - NextCh(); - } - else - { - opkind = OPgreater; - } - break; - case '<': - sym = opsym; - NextCh(); - if (ch == '=') { - opkind = OPlessequal; - NextCh(); - } else { - opkind = OPless; - } - break; - case '\"' : - { - int start; - sym = constsym; - constkind = stringtype; - NextCh(); - start = chcount; - while ((ch != '\"') && (ch != 0x0)) - NextCh(); - GrabRealString(start); - TermChar('\"'); // check for eol before '\"' - break; - } - case 0x0: sym = eolsym; break; - default: - { - int start; - start = chcount; - DigRep(); - if ((start != chcount) || (ch == '.')) { // number - sym = constsym; - if (ch == '.') { - constkind = floattype; - NextCh(); - DigRep(); - } - else constkind = inttype; - if ((ch == 'e') || (ch == 'E')) { - int mark; - constkind = floattype; - NextCh(); - if ((ch == '+') || (ch == '-')) NextCh(); - mark = chcount; - DigRep(); - if (mark == chcount) { - ScanError("Number expected after 'E'"); - return; - } - } - GrabString(start); - } else if (((ch >= 'a') && (ch <= 'z')) - || ((ch >= 'A') && (ch <= 'Z'))) - { // reserved word? - - start = chcount; - CharRep(); - GrabString(start); - if (!strcasecmp(const_as_string, "SUM")) { - sym = sumsym; - } - else if (!strcasecmp(const_as_string, "NOT")) { - sym = opsym; - opkind = OPnot; - } - else if (!strcasecmp(const_as_string, "AND")) { - sym = opsym; opkind = OPand; - } - else if (!strcasecmp(const_as_string, "OR")) { - sym = opsym; opkind = OPor; - } - else if (!strcasecmp(const_as_string, "IF")) - sym = ifsym; - else if (!strcasecmp(const_as_string, "WHOMADE")) - sym = whocodedsym; - else if (!strcasecmp(const_as_string, "FALSE")) { - sym = constsym; constkind = booltype; boolvalue = false; - } else if (!strcasecmp(const_as_string, "TRUE")) { - sym = constsym; constkind = booltype; boolvalue = true; - } else { - sym = idsym; - //STR_String str; - //str.Format("'%s' makes no sense here", (const char*)funstr); - //ScanError(str); - } - } else { // unknown symbol - STR_String str; - str.Format("Unexpected character '%c'", ch); - NextCh(); - ScanError(str); - return; - } - } - } -} - -#if 0 -int CParser::MakeInt() -{ - // returns the integer representation of the value in the global - // variable const_as_string - // pre: const_as_string contains only numercal chars - return atoi(const_as_string); -} -#endif - -const char *CParser::Symbol2Str(int s) -{ - // returns a string representation of of symbol s, - // for use in Term when generating an error - switch (s) { - case errorsym: return "error"; - case lbracksym: return "("; - case rbracksym: return ")"; - case commasym: return ","; - case opsym: return "operator"; - case constsym: return "constant"; - case sumsym: return "SUM"; - case ifsym: return "IF"; - case whocodedsym: return "WHOMADE"; - case eolsym: return "end of line"; - case idsym: return "identifier"; - } - return "unknown"; // should not happen -} - -void CParser::Term(int s) -{ - // generates an error if the next symbol isn't the specified symbol s - // otherwise, skip the symbol - if (s == sym) { - NextSym(); - } - else { - STR_String msg; - msg.Format("Warning: %s expected\ncontinuing without it", Symbol2Str(s)); - -// AfxMessageBox(msg,MB_ICONERROR); - - trace(msg); - } -} - -int CParser::Priority(int optorkind) -{ - // returns the priority of an operator - // higher number means higher priority - switch (optorkind) { - case OPor: return 1; - case OPand: return 2; - case OPgreater: - case OPless: - case OPgreaterequal: - case OPlessequal: - case OPequal: - case OPunequal: return 3; - case OPplus: - case OPminus: return 4; - case OPmodulus: - case OPtimes: - case OPdivide: return 5; - } - MT_assert(false); - return 0; // should not happen -} - -CExpression *CParser::Ex(int i) -{ - // parses an expression in the imput, starting at priority i, and - // returns an CExpression, containing the parsed input - CExpression *e1 = NULL, *e2 = NULL; - int opkind2; - - if (i < NUM_PRIORITY) { - e1 = Ex(i + 1); - while ((sym == opsym) && (Priority(opkind) == i)) { - opkind2 = opkind; - NextSym(); - e2 = Ex(i + 1); - switch (opkind2) { - case OPmodulus: e1 = new COperator2Expr(VALUE_MOD_OPERATOR,e1, e2); break; - case OPplus: e1 = new COperator2Expr(VALUE_ADD_OPERATOR,e1, e2); break; - case OPminus: e1 = new COperator2Expr(VALUE_SUB_OPERATOR,e1, e2); break; - case OPtimes: e1 = new COperator2Expr(VALUE_MUL_OPERATOR,e1, e2); break; - case OPdivide: e1 = new COperator2Expr(VALUE_DIV_OPERATOR,e1, e2); break; - case OPand: e1 = new COperator2Expr(VALUE_AND_OPERATOR,e1, e2); break; - case OPor: e1 = new COperator2Expr(VALUE_OR_OPERATOR,e1, e2); break; - case OPequal: e1 = new COperator2Expr(VALUE_EQL_OPERATOR,e1, e2); break; - case OPunequal: e1 = new COperator2Expr(VALUE_NEQ_OPERATOR,e1, e2); break; - case OPgreater: e1 = new COperator2Expr(VALUE_GRE_OPERATOR,e1, e2); break; - case OPless: e1 = new COperator2Expr(VALUE_LES_OPERATOR,e1, e2); break; - case OPgreaterequal: e1 = new COperator2Expr(VALUE_GEQ_OPERATOR,e1, e2); break; - case OPlessequal: e1 = new COperator2Expr(VALUE_LEQ_OPERATOR,e1, e2); break; - default: MT_assert(false); break; // should not happen - } - } - } else if (i == NUM_PRIORITY) { - if ((sym == opsym) - && ( (opkind == OPminus) || (opkind == OPnot) || (opkind == OPplus) ) - ) - { - NextSym(); - switch (opkind) { - /* +1 is also a valid number! */ - case OPplus: e1 = new COperator1Expr(VALUE_POS_OPERATOR, Ex(NUM_PRIORITY)); break; - case OPminus: e1 = new COperator1Expr(VALUE_NEG_OPERATOR, Ex(NUM_PRIORITY)); break; - case OPnot: e1 = new COperator1Expr(VALUE_NOT_OPERATOR, Ex(NUM_PRIORITY)); break; - default: - { - // should not happen - e1 = Error("operator +, - or ! expected"); - } - } - } - else { - switch (sym) { - case constsym: - { - switch (constkind) { - case booltype: - e1 = new CConstExpr(new CBoolValue(boolvalue)); - break; - case inttype: - { - cInt temp; - temp = strtoll(const_as_string, NULL, 10); /* atoi is for int only */ - e1 = new CConstExpr(new CIntValue(temp)); - break; - } - case floattype: - { - double temp; - temp = atof(const_as_string); - e1 = new CConstExpr(new CFloatValue(temp)); - break; - } - case stringtype: - e1 = new CConstExpr(new CStringValue(const_as_string,"")); - break; - default : - MT_assert(false); - break; - } - NextSym(); - break; - } - case lbracksym: - NextSym(); - e1 = Ex(1); - Term(rbracksym); - break; - case ifsym: - { - CExpression *e3; - NextSym(); - Term(lbracksym); - e1 = Ex(1); - Term(commasym); - e2 = Ex(1); - if (sym == commasym) { - NextSym(); - e3 = Ex(1); - } else { - e3 = new CConstExpr(new CEmptyValue()); - } - Term(rbracksym); - e1 = new CIfExpr(e1, e2, e3); - break; - } - case idsym: - { - e1 = new CIdentifierExpr(const_as_string,m_identifierContext); - NextSym(); - - break; - } - case errorsym: - { - MT_assert(!e1); - STR_String errtext="[no info]"; - if (errmsg) - { - CValue* errmsgval = errmsg->Calculate(); - errtext=errmsgval->GetText(); - errmsgval->Release(); - - //e1 = Error(errmsg->Calculate()->GetText());//new CConstExpr(errmsg->Calculate()); - - if ( !(errmsg->Release()) ) - { - errmsg=NULL; - } else { - // does this happen ? - MT_assert("does this happen"); - } - } - e1 = Error(errtext); - - break; - } - default: - NextSym(); - //return Error("Expression expected"); - MT_assert(!e1); - e1 = Error("Expression expected"); - } - } - } - return e1; -} - -CExpression *CParser::Expr() -{ - // parses an expression in the imput, and - // returns an CExpression, containing the parsed input - return Ex(1); -} - -CExpression* CParser::ProcessText -(const char *intext) { - - // and parses the string in intext and returns it. - - - CExpression* expr; - text = intext; - - - chcount = 0; - if (text.Length() == 0) { - return NULL; - } - - ch = text[0]; - /* if (ch != '=') { - * expr = new CConstExpr(new CStringValue(text)); - * *dependent = deplist; - * return expr; - * } else - */ - // NextCh(); - NextSym(); - expr = Expr(); - if (sym != eolsym) { - CExpression* oldexpr = expr; - expr = new COperator2Expr(VALUE_ADD_OPERATOR, - oldexpr, Error(STR_String("Extra characters after expression")));//new CConstExpr(new CErrorValue("Extra characters after expression"))); - } - if (errmsg) - errmsg->Release(); - - return expr; -} - - - -float CParser::GetFloat(STR_String& txt) -{ - // returns parsed text into a float - // empty string returns -1 - -// AfxMessageBox("parsed string="+txt); - CValue* val=NULL; - float result=-1; -// String tmpstr; - - CExpression* expr = ProcessText(txt); - if (expr) { - val = expr->Calculate(); - result=(float)val->GetNumber(); - - - - val->Release(); - expr->Release(); - } -// tmpstr.Format("parseresult=%g",result); -// AfxMessageBox(tmpstr); - return result; -} - -CValue* CParser::GetValue(STR_String& txt, bool bFallbackToText) -{ - // returns parsed text into a value, - // empty string returns NULL value ! - // if bFallbackToText then unparsed stuff is put into text - - CValue* result=NULL; - CExpression* expr = ProcessText(txt); - if (expr) { - result = expr->Calculate(); - expr->Release(); - } - if (result) - { - // if the parsed stuff lead to an errorvalue, don't return errors, just NULL - if (result->IsError()) { - result->Release(); - result=NULL; - if (bFallbackToText) { - if (txt.Length()>0) - { - result = new CStringValue(txt,""); - } - } - } - } - return result; -} - -void CParser::SetContext(CValue* context) -{ - if (m_identifierContext) - { - m_identifierContext->Release(); - } - m_identifierContext = context; -} diff --git a/source/gameengine/Expressions/intern/IntValue.cpp b/source/gameengine/Expressions/intern/IntValue.cpp deleted file mode 100644 index 7b2e841f13f..00000000000 --- a/source/gameengine/Expressions/intern/IntValue.cpp +++ /dev/null @@ -1,344 +0,0 @@ -/** \file gameengine/Expressions/IntValue.cpp - * \ingroup expressions - */ -// IntValue.cpp: implementation of the CIntValue class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include <stdio.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 -////////////////////////////////////////////////////////////////////// - -CIntValue::CIntValue() -/* -pre: false -effect: constructs a new CIntValue -*/ -{ - -#ifdef DEBUG_ - m_textval = "Int illegal constructor"; -#endif - m_pstrRep=NULL; -} - - - -CIntValue::CIntValue(cInt innie) -/* -pre: -effect: constructs a new CIntValue containing cInt innie -*/ -{ - m_int = innie; - m_pstrRep=NULL; -} - - - -CIntValue::CIntValue(cInt innie,const char *name,AllocationTYPE alloctype) -{ - m_int = innie; - SetName(name); - - if (alloctype==CValue::STACKVALUE) - { - CValue::DisableRefCount(); - } - m_pstrRep=NULL; - -} - - - -CIntValue::~CIntValue() -/* -pre: -effect: deletes the object -*/ -{ - if (m_pstrRep) - delete m_pstrRep; -} - - - -CValue* CIntValue::Calc(VALUE_OPERATOR op, CValue *val) -/* -pre: -ret: a new object containing the result of applying operator op to this -object and val -*/ -{ - //return val->CalcInt(op, this); - switch (op) { - case VALUE_POS_OPERATOR: - return new CIntValue (m_int); - break; - case VALUE_NEG_OPERATOR: - return new CIntValue (-m_int); - break; - case VALUE_NOT_OPERATOR: - return new CBoolValue (m_int == 0); - break; - case VALUE_AND_OPERATOR: - case VALUE_OR_OPERATOR: - return new CErrorValue(val->GetText() + op2str(op) + "only allowed on booleans"); - break; - default: - return val->CalcFinal(VALUE_INT_TYPE, op, this); - break; - } -} - -/* - * pre: the type of val is dtype - * ret: a new object containing the result of applying operator op to val and - * this object - */ -CValue* CIntValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -{ - CValue *ret; - - switch (dtype) { - case VALUE_EMPTY_TYPE: - case VALUE_INT_TYPE: - { - switch (op) { - case VALUE_MOD_OPERATOR: - ret = new CIntValue (((CIntValue *) val)->GetInt() % m_int); - break; - case VALUE_ADD_OPERATOR: - ret = new CIntValue (((CIntValue *) val)->GetInt() + m_int); - break; - case VALUE_SUB_OPERATOR: - ret = new CIntValue (((CIntValue *) val)->GetInt() - m_int); - break; - case VALUE_MUL_OPERATOR: - ret = new CIntValue (((CIntValue *) val)->GetInt() * m_int); - break; - case VALUE_DIV_OPERATOR: - if (m_int == 0) { - if (val->GetNumber() == 0) { - ret = new CErrorValue("Not a Number"); - } - else { - ret = new CErrorValue("Division by zero"); - } - } - else - ret = new CIntValue (((CIntValue *) val)->GetInt() / m_int); - break; - case VALUE_EQL_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() == m_int); - break; - case VALUE_NEQ_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() != m_int); - break; - case VALUE_GRE_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() > m_int); - break; - case VALUE_LES_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() < m_int); - break; - case VALUE_GEQ_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() >= m_int); - break; - case VALUE_LEQ_OPERATOR: - ret = new CBoolValue(((CIntValue *) val)->GetInt() <= m_int); - break; - case VALUE_NEG_OPERATOR: - ret = new CIntValue (-m_int); - break; - case VALUE_POS_OPERATOR: - ret = new CIntValue (m_int); - break; - case VALUE_NOT_OPERATOR: - ret = new CBoolValue(m_int == 0); - break; - default: - printf("Found op: %d\n", op); - ret = new CErrorValue("illegal operator. please send a bug report."); - break; - } - break; - } - case VALUE_FLOAT_TYPE: - { - switch (op) { - case VALUE_MOD_OPERATOR: - ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_int)); - break; - case VALUE_ADD_OPERATOR: - ret = new CFloatValue (((CFloatValue *) val)->GetFloat() + m_int); - break; - case VALUE_SUB_OPERATOR: - ret = new CFloatValue (((CFloatValue *) val)->GetFloat() - m_int); - break; - case VALUE_MUL_OPERATOR: - ret = new CFloatValue (((CFloatValue *) val)->GetFloat() * m_int); - break; - case VALUE_DIV_OPERATOR: - if (m_int == 0) - ret = new CErrorValue("Division by zero"); - else - ret = new CFloatValue (((CFloatValue *) val)->GetFloat() / m_int); - break; - case VALUE_EQL_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() == m_int); - break; - case VALUE_NEQ_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() != m_int); - break; - case VALUE_GRE_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() > m_int); - break; - case VALUE_LES_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() < m_int); - break; - case VALUE_GEQ_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() >= m_int); - break; - case VALUE_LEQ_OPERATOR: - ret = new CBoolValue(((CFloatValue *) val)->GetFloat() <= m_int); - break; - case VALUE_NOT_OPERATOR: - ret = new CBoolValue(m_int == 0); - break; - default: - ret = new CErrorValue("illegal operator. please send a bug report."); - break; - } - break; - } - case VALUE_STRING_TYPE: - { - switch (op) { - case VALUE_ADD_OPERATOR: - ret = new CStringValue(val->GetText() + GetText(),""); - break; - case VALUE_EQL_OPERATOR: - case VALUE_NEQ_OPERATOR: - case VALUE_GRE_OPERATOR: - case VALUE_LES_OPERATOR: - case VALUE_GEQ_OPERATOR: - case VALUE_LEQ_OPERATOR: - ret = new CErrorValue("[Cannot compare string with integer]" + op2str(op) + GetText()); - break; - default: - ret = new CErrorValue("[operator not allowed on strings]" + op2str(op) + GetText()); - break; - } - break; - } - case VALUE_BOOL_TYPE: - ret = new CErrorValue("[operator not valid on boolean and integer]" + op2str(op) + GetText()); - break; -#if 0 - case VALUE_EMPTY_TYPE: - { - switch (op) { - case VALUE_ADD_OPERATOR: - ret = new CIntValue (m_int); - break; - case VALUE_SUB_OPERATOR: - ret = new CIntValue (-m_int); - break; - default: - { - ret = new CErrorValue(op2str(op) + GetText()); - } - } - break; - } -#endif - case VALUE_ERROR_TYPE: - ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); - break; - default: - ret = new CErrorValue("illegal type. contact your dealer (if any)"); - break; - } - return ret; -} - - -/** - * pre: - * ret: the cInt stored in the object - */ -cInt CIntValue::GetInt() -{ - return m_int; -} - - - -double CIntValue::GetNumber() -{ - return (double) m_int; -} - - - -int CIntValue::GetValueType() -{ - return VALUE_INT_TYPE; -} - - - -const STR_String & CIntValue::GetText() -{ - if (!m_pstrRep) - m_pstrRep=new STR_String(); - m_pstrRep->Format("%lld",m_int); - - return *m_pstrRep; -} - - - -CValue* CIntValue::GetReplica() -{ - CIntValue* replica = new CIntValue(*this); - replica->ProcessReplica(); - replica->m_pstrRep = NULL; - - return replica; -} - - - -void CIntValue::SetValue(CValue* newval) -{ - m_int = (cInt)newval->GetNumber(); - SetModified(true); -} - - -#ifdef WITH_PYTHON -PyObject *CIntValue::ConvertValueToPython() -{ - return PyLong_FromLongLong(m_int); -} -#endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/intern/ListValue.cpp b/source/gameengine/Expressions/intern/ListValue.cpp deleted file mode 100644 index 557ce7be300..00000000000 --- a/source/gameengine/Expressions/intern/ListValue.cpp +++ /dev/null @@ -1,702 +0,0 @@ -/** \file gameengine/Expressions/ListValue.cpp - * \ingroup expressions - */ -// ListValue.cpp: implementation of the CListValue class. -// -////////////////////////////////////////////////////////////////////// -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include <stdio.h> - -#include "EXP_ListValue.h" -#include "EXP_StringValue.h" -#include "EXP_VoidValue.h" -#include <algorithm> -#include "EXP_BoolValue.h" - -#include "BLI_sys_types.h" /* for intptr_t support */ - - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CListValue::CListValue() -: CPropValue() -{ - m_bReleaseContents=true; -} - - - -CListValue::~CListValue() -{ - - if (m_bReleaseContents) { - for (unsigned int i=0;i<m_pValueArray.size();i++) { - m_pValueArray[i]->Release(); - } - } -} - - -static STR_String gstrListRep=STR_String("List"); - -const STR_String & CListValue::GetText() -{ - gstrListRep = "["; - STR_String commastr = ""; - - for (int i=0;i<GetCount();i++) - { - gstrListRep += commastr; - gstrListRep += GetValue(i)->GetText(); - commastr = ","; - } - gstrListRep += "]"; - - return gstrListRep; -} - - - -CValue* CListValue::GetReplica() -{ - CListValue* replica = new CListValue(*this); - - replica->ProcessReplica(); - - replica->m_bReleaseContents=true; // for copy, complete array is copied for now... - // copy all values - int numelements = m_pValueArray.size(); - unsigned int i=0; - replica->m_pValueArray.resize(numelements); - for (i=0;i<m_pValueArray.size();i++) - replica->m_pValueArray[i] = m_pValueArray[i]->GetReplica(); - - - return replica; -}; - - - -void CListValue::SetValue(int i, CValue *val) -{ - assertd(i < m_pValueArray.size()); - m_pValueArray[i]=val; -} - - - -void CListValue::Resize(int num) -{ - m_pValueArray.resize(num); -} - - - -void CListValue::Remove(int i) -{ - assertd(i<m_pValueArray.size()); - m_pValueArray.erase(m_pValueArray.begin()+i); -} - - - -void CListValue::ReleaseAndRemoveAll() -{ - for (unsigned int i=0;i<m_pValueArray.size();i++) - m_pValueArray[i]->Release(); - m_pValueArray.clear();//.Clear(); -} - - - -CValue* CListValue::FindValue(const STR_String &name) -{ - for (int i=0; i < GetCount(); i++) - if (GetValue(i)->GetName() == name) - return GetValue(i); - - return NULL; -} - -CValue* CListValue::FindValue(const char *name) -{ - for (int i=0; i < GetCount(); i++) - if (GetValue(i)->GetName() == name) - return GetValue(i); - - return NULL; -} - -bool CListValue::SearchValue(CValue *val) -{ - for (int i=0;i<GetCount();i++) - if (val == GetValue(i)) - return true; - return false; -} - - - -void CListValue::SetReleaseOnDestruct(bool bReleaseContents) -{ - m_bReleaseContents = bReleaseContents; -} - - - -bool CListValue::RemoveValue(CValue *val) -{ - bool result=false; - - for (int i=GetCount()-1;i>=0;i--) - if (val == GetValue(i)) - { - Remove(i); - result=true; - } - return result; -} - - - -void CListValue::MergeList(CListValue *otherlist) -{ - - int numelements = this->GetCount(); - int numotherelements = otherlist->GetCount(); - - - Resize(numelements+numotherelements); - - for (int i=0;i<numotherelements;i++) - { - SetValue(i+numelements,otherlist->GetValue(i)->AddRef()); - } -} - -bool CListValue::CheckEqual(CValue* first,CValue* second) -{ - bool result = false; - - CValue* eqval = ((CValue*)first)->Calc(VALUE_EQL_OPERATOR,(CValue*)second); - - if (eqval==NULL) - return false; - const STR_String& text = eqval->GetText(); - if (&text==&CBoolValue::sTrueString) - { - result = true; - } - eqval->Release(); - return result; - -} - - -/* --------------------------------------------------------------------- - * Some stuff taken from the header - * --------------------------------------------------------------------- */ -CValue* CListValue::Calc(VALUE_OPERATOR op,CValue *val) -{ - //assert(false); // todo: implement me! - static int error_printed = 0; - if (error_printed==0) { - fprintf(stderr, "CValueList::Calc not yet implemented\n"); - error_printed = 1; - } - return NULL; -} - -CValue* CListValue::CalcFinal(VALUE_DATA_TYPE dtype, - VALUE_OPERATOR op, - CValue* val) -{ - //assert(false); // todo: implement me! - static int error_printed = 0; - if (error_printed==0) { - fprintf(stderr, "CValueList::CalcFinal not yet implemented\n"); - error_printed = 1; - } - return NULL; -} - - - -void CListValue::Add(CValue* value) -{ - m_pValueArray.push_back(value); -} - - - -double CListValue::GetNumber() -{ - return -1; -} - - - -int CListValue::GetValueType() -{ - return VALUE_LIST_TYPE; -} - - - -void CListValue::SetModified(bool bModified) -{ - CValue::SetModified(bModified); - int numels = GetCount(); - - for (int i=0;i<numels;i++) - GetValue(i)->SetModified(bModified); -} - - - -bool CListValue::IsModified() -{ - bool bmod = CValue::IsModified(); //normal own flag - int numels = GetCount(); - - for (int i=0;i<numels;i++) - bmod = bmod || GetValue(i)->IsModified(); - - return bmod; -} - -#ifdef WITH_PYTHON - -/* --------------------------------------------------------------------- */ -/* Python interface ---------------------------------------------------- */ -/* --------------------------------------------------------------------- */ - -static Py_ssize_t listvalue_bufferlen(PyObject *self) -{ - CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self)); - if (list==NULL) - return 0; - - return (Py_ssize_t)list->GetCount(); -} - -static PyObject *listvalue_buffer_item(PyObject *self, Py_ssize_t index) -{ - CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self)); - CValue *cval; - - if (list==NULL) { - PyErr_SetString(PyExc_SystemError, "val = CList[i], " BGE_PROXY_ERROR_MSG); - return NULL; - } - - int count = list->GetCount(); - - if (index < 0) - index = count+index; - - if (index < 0 || index >= count) { - PyErr_SetString(PyExc_IndexError, "CList[i]: Python ListIndex out of range in CValueList"); - return NULL; - } - - cval= list->GetValue(index); - - PyObject *pyobj = cval->ConvertValueToPython(); - if (pyobj) - return pyobj; - else - return cval->GetProxy(); -} - - -/* just slice it into a python list... */ -static PyObject *listvalue_buffer_slice(CListValue *list, Py_ssize_t start, Py_ssize_t stop) -{ - PyObject *newlist; - Py_ssize_t i, j; - - /* caller needs to validate negative index */ -#if 0 - Py_ssize_t len = list->GetCount(); - - if (start > len) start = len; - if (stop > len) stop = len; -#endif - - newlist = PyList_New(stop - start); - if (!newlist) - return NULL; - - for (i = start, j = 0; i < stop; i++, j++) { - PyObject *pyobj = list->GetValue(i)->ConvertValueToPython(); - if (!pyobj) { - pyobj = list->GetValue(i)->GetProxy(); - } - PyList_SET_ITEM(newlist, j, pyobj); - } - return newlist; -} - - -static PyObject *listvalue_mapping_subscript(PyObject *self, PyObject *key) -{ - CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self)); - if (list==NULL) { - PyErr_SetString(PyExc_SystemError, "value = CList[i], " BGE_PROXY_ERROR_MSG); - return NULL; - } - - if (PyUnicode_Check(key)) { - CValue *item = ((CListValue*) list)->FindValue(_PyUnicode_AsString(key)); - if (item) { - PyObject *pyobj = item->ConvertValueToPython(); - if (pyobj) - return pyobj; - else - return item->GetProxy(); - } - } - else if (PyIndex_Check(key)) { - Py_ssize_t index = PyLong_AsSsize_t(key); - return listvalue_buffer_item(self, index); /* wont add a ref */ - } - else if (PySlice_Check(key)) { - Py_ssize_t start, stop, step, slicelength; - - if (PySlice_GetIndicesEx(key, list->GetCount(), &start, &stop, &step, &slicelength) < 0) - return NULL; - - if (slicelength <= 0) { - return PyList_New(0); - } - else if (step == 1) { - return listvalue_buffer_slice(list, start, stop); - } - else { - PyErr_SetString(PyExc_TypeError, "CList[slice]: slice steps not supported"); - return NULL; - } - } - - PyErr_Format(PyExc_KeyError, - "CList[key]: '%R' key not in list", key); - return NULL; -} - -/* clist + list, return a list that python owns */ -static PyObject *listvalue_buffer_concat(PyObject *self, PyObject *other) -{ - CListValue *listval= static_cast<CListValue *>(BGE_PROXY_REF(self)); - Py_ssize_t i, numitems, numitems_orig; - - if (listval==NULL) { - PyErr_SetString(PyExc_SystemError, "CList+other, " BGE_PROXY_ERROR_MSG); - return NULL; - } - - numitems_orig= listval->GetCount(); - - // for now, we support CListValue concatenated with items - // and CListValue concatenated to Python Lists - // and CListValue concatenated with another CListValue - - /* Shallow copy, don't use listval->GetReplica(), it will screw up with KX_GameObjects */ - CListValue* listval_new = new CListValue(); - - if (PyList_Check(other)) - { - CValue* listitemval; - bool error = false; - - numitems = PyList_GET_SIZE(other); - - /* copy the first part of the list */ - listval_new->Resize(numitems_orig + numitems); - for (i=0;i<numitems_orig;i++) - listval_new->SetValue(i, listval->GetValue(i)->AddRef()); - - for (i=0;i<numitems;i++) - { - listitemval = listval->ConvertPythonToValue(PyList_GET_ITEM(other, i), true, "cList + pyList: CListValue, "); - - if (listitemval) { - listval_new->SetValue(i+numitems_orig, listitemval); - } else { - error= true; - break; - } - } - - if (error) { - listval_new->Resize(numitems_orig+i); /* resize so we don't try release NULL pointers */ - listval_new->Release(); - return NULL; /* ConvertPythonToValue above sets the error */ - } - - } - else if (PyObject_TypeCheck(other, &CListValue::Type)) { - // add items from otherlist to this list - CListValue* otherval = static_cast<CListValue *>(BGE_PROXY_REF(other)); - if (otherval==NULL) { - listval_new->Release(); - PyErr_SetString(PyExc_SystemError, "CList+other, " BGE_PROXY_ERROR_MSG); - return NULL; - } - - numitems = otherval->GetCount(); - - /* copy the first part of the list */ - listval_new->Resize(numitems_orig + numitems); /* resize so we don't try release NULL pointers */ - for (i=0;i<numitems_orig;i++) - listval_new->SetValue(i, listval->GetValue(i)->AddRef()); - - /* now copy the other part of the list */ - for (i=0;i<numitems;i++) - listval_new->SetValue(i+numitems_orig, otherval->GetValue(i)->AddRef()); - - } - return listval_new->NewProxy(true); /* python owns this list */ -} - -static int listvalue_buffer_contains(PyObject *self_v, PyObject *value) -{ - CListValue *self = static_cast<CListValue *>(BGE_PROXY_REF(self_v)); - - if (self == NULL) { - PyErr_SetString(PyExc_SystemError, "val in CList, " BGE_PROXY_ERROR_MSG); - return -1; - } - - if (PyUnicode_Check(value)) { - if (self->FindValue((const char *)_PyUnicode_AsString(value))) { - return 1; - } - } - else if (PyObject_TypeCheck(value, &CValue::Type)) { /* not dict like at all but this worked before __contains__ was used */ - CValue *item= static_cast<CValue *>(BGE_PROXY_REF(value)); - for (int i=0; i < self->GetCount(); i++) - if (self->GetValue(i) == item) // Com - return 1; - - } // not using CheckEqual - - return 0; -} - - -static PySequenceMethods listvalue_as_sequence = { - listvalue_bufferlen,//(inquiry)buffer_length, /*sq_length*/ - listvalue_buffer_concat, /*sq_concat*/ - NULL, /*sq_repeat*/ - listvalue_buffer_item, /*sq_item*/ -// TODO, slicing in py3 - NULL, // listvalue_buffer_slice, /*sq_slice*/ - NULL, /*sq_ass_item*/ - NULL, /*sq_ass_slice*/ - (objobjproc)listvalue_buffer_contains, /* sq_contains */ - (binaryfunc) NULL, /* sq_inplace_concat */ - (ssizeargfunc) NULL, /* sq_inplace_repeat */ -}; - - - -/* Is this one used ? */ -static PyMappingMethods instance_as_mapping = { - listvalue_bufferlen, /*mp_length*/ - listvalue_mapping_subscript, /*mp_subscript*/ - NULL /*mp_ass_subscript*/ -}; - - - -PyTypeObject CListValue::Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CListValue", /*tp_name*/ - sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - py_base_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - py_base_repr, /*tp_repr*/ - 0, /*tp_as_number*/ - &listvalue_as_sequence, /*tp_as_sequence*/ - &instance_as_mapping, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call */ - 0, - NULL, - NULL, - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - 0,0,0,0,0,0,0, - Methods, - 0, - 0, - &CValue::Type, - 0,0,0,0,0,0, - py_base_new -}; - -PyMethodDef CListValue::Methods[] = { - /* List style access */ - {"append", (PyCFunction)CListValue::sPyappend,METH_O}, - {"reverse", (PyCFunction)CListValue::sPyreverse,METH_NOARGS}, - {"index", (PyCFunction)CListValue::sPyindex,METH_O}, - {"count", (PyCFunction)CListValue::sPycount,METH_O}, - - /* Dict style access */ - {"get", (PyCFunction)CListValue::sPyget,METH_VARARGS}, - - /* Own cvalue funcs */ - {"from_id", (PyCFunction)CListValue::sPyfrom_id,METH_O}, - - {NULL,NULL} //Sentinel -}; - -PyAttributeDef CListValue::Attributes[] = { - { NULL } //Sentinel -}; - -PyObject *CListValue::Pyappend(PyObject *value) -{ - CValue *objval = ConvertPythonToValue(value, true, "CList.append(i): CValueList, "); - - if (!objval) /* ConvertPythonToValue sets the error */ - return NULL; - - if (!BGE_PROXY_PYOWNS(m_proxy)) { - PyErr_SetString(PyExc_TypeError, - "CList.append(i): internal values can't be modified"); - return NULL; - } - - Add(objval); - - Py_RETURN_NONE; -} - -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; -} - -PyObject *CListValue::Pyindex(PyObject *value) -{ - PyObject *result = NULL; - - CValue *checkobj = ConvertPythonToValue(value, true, "val = cList[i]: CValueList, "); - if (checkobj==NULL) - return NULL; /* ConvertPythonToValue sets the error */ - - int numelem = GetCount(); - for (int i=0;i<numelem;i++) - { - CValue* elem = GetValue(i); - if (checkobj==elem || CheckEqual(checkobj,elem)) - { - result = PyLong_FromLong(i); - break; - } - } - checkobj->Release(); - - if (result==NULL) { - PyErr_SetString(PyExc_ValueError, "CList.index(x): x not in CListValue"); - } - return result; - -} - - - -PyObject *CListValue::Pycount(PyObject *value) -{ - int numfound = 0; - - CValue *checkobj = ConvertPythonToValue(value, false, ""); /* error ignored */ - - if (checkobj==NULL) { /* in this case just return that there are no items in the list */ - PyErr_Clear(); - return PyLong_FromLong(0); - } - - int numelem = GetCount(); - for (int i=0;i<numelem;i++) - { - CValue* elem = GetValue(i); - if (checkobj==elem || CheckEqual(checkobj,elem)) - { - numfound ++; - } - } - checkobj->Release(); - - return PyLong_FromLong(numfound); -} - -/* Matches python dict.get(key, [default]) */ -PyObject *CListValue::Pyget(PyObject *args) -{ - char *key; - PyObject *def = Py_None; - - if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) - return NULL; - - CValue *item = FindValue((const char *)key); - if (item) { - PyObject *pyobj = item->ConvertValueToPython(); - if (pyobj) - return pyobj; - else - return item->GetProxy(); - } - Py_INCREF(def); - return def; -} - - -PyObject *CListValue::Pyfrom_id(PyObject *value) -{ - uintptr_t id= (uintptr_t)PyLong_AsVoidPtr(value); - - if (PyErr_Occurred()) - return NULL; - - int numelem = GetCount(); - for (int i=0;i<numelem;i++) - { - if (reinterpret_cast<uintptr_t>(m_pValueArray[i]->m_proxy) == id) - return GetValue(i)->GetProxy(); - } - PyErr_SetString(PyExc_IndexError, "from_id(#): id not found in CValueList"); - return NULL; - -} - -#endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/intern/ListWrapper.cpp b/source/gameengine/Expressions/intern/ListWrapper.cpp deleted file mode 100644 index db1518a4388..00000000000 --- a/source/gameengine/Expressions/intern/ListWrapper.cpp +++ /dev/null @@ -1,424 +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. - * - * Contributor(s): Porteries Tristan. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file ListWrapper.cpp - * \ingroup expressions - */ - -#ifdef WITH_PYTHON - -#include "EXP_ListWrapper.h" - -static STR_String pythonGeneratorList = "ListWrapper"; - -CListWrapper::CListWrapper(void *client, - PyObject *base, - bool (*checkValid)(void *), - int (*getSize)(void *), - PyObject *(*getItem)(void *, int), - const char *(*getItemName)(void *, int), - bool (*setItem)(void *, int, PyObject *)) -:m_client(client), -m_base(base), -m_checkValid(checkValid), -m_getSize(getSize), -m_getItem(getItem), -m_getItemName(getItemName), -m_setItem(setItem) -{ - // Incref to always have a existing pointer. - Py_INCREF(m_base); -} - -CListWrapper::~CListWrapper() -{ - Py_DECREF(m_base); -} - -bool CListWrapper::CheckValid() -{ - if (m_base && !BGE_PROXY_REF(m_base)) { - return false; - } - return m_checkValid ? (*m_checkValid)(m_client) : true; -} - -int CListWrapper::GetSize() -{ - return (*m_getSize)(m_client); -} - -PyObject *CListWrapper::GetItem(int index) -{ - return (*m_getItem)(m_client, index); -} - -const char *CListWrapper::GetItemName(int index) -{ - return (*m_getItemName)(m_client, index); -} - -bool CListWrapper::SetItem(int index, PyObject *item) -{ - return (*m_setItem)(m_client, index, item); -} - -bool CListWrapper::AllowSetItem() -{ - return m_setItem != NULL; -} - -bool CListWrapper::AllowGetItemByName() -{ - return m_getItemName != NULL; -} - -// ================================================================ - -const STR_String &CListWrapper::GetText() -{ - return pythonGeneratorList; -} - -void CListWrapper::SetName(const char *name) -{ -} - -STR_String &CListWrapper::GetName() -{ - return pythonGeneratorList; -} - -CValue *CListWrapper::GetReplica() -{ - return NULL; -} - -CValue *CListWrapper::Calc(VALUE_OPERATOR op, CValue *val) -{ - return NULL; -} - -CValue *CListWrapper::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -{ - return NULL; -} - -double CListWrapper::GetNumber() -{ - return -1; -} - -int CListWrapper::GetValueType() -{ - return -1; -} - -// We convert all elements to python objects to make a proper repr string. -PyObject *CListWrapper::py_repr() -{ - if (!CheckValid()) { - PyErr_SetString(PyExc_SystemError, "CListWrapper : repr, " BGE_PROXY_ERROR_MSG); - return NULL; - } - - PyObject *py_proxy = GetProxy(); - PyObject *py_list = PySequence_List(py_proxy); - PyObject *py_string = PyObject_Repr(py_list); - Py_DECREF(py_list); - Py_DECREF(py_proxy); - return py_string; -} - - -Py_ssize_t CListWrapper::py_len(PyObject *self) -{ - CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self); - // Invalid list. - if (!list->CheckValid()) { - PyErr_SetString(PyExc_SystemError, "len(CListWrapper), " BGE_PROXY_ERROR_MSG); - return 0; - } - - return (Py_ssize_t)list->GetSize(); -} - -PyObject *CListWrapper::py_get_item(PyObject *self, Py_ssize_t index) -{ - CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self); - // Invalid list. - if (!list->CheckValid()) { - PyErr_SetString(PyExc_SystemError, "val = CListWrapper[i], " BGE_PROXY_ERROR_MSG); - return NULL; - } - - int size = list->GetSize(); - - if (index < 0) { - index = size + index; - } - if (index < 0 || index >= size) { - PyErr_SetString(PyExc_IndexError, "CListWrapper[i]: List index out of range in CListWrapper"); - return NULL; - } - - PyObject *pyobj = list->GetItem(index); - - return pyobj; -} - -int CListWrapper::py_set_item(PyObject *self, Py_ssize_t index, PyObject *value) -{ - CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self); - // Invalid list. - if (!list->CheckValid()) { - PyErr_SetString(PyExc_SystemError, "CListWrapper[i] = val, " BGE_PROXY_ERROR_MSG); - return -1; - } - - if (!list->AllowSetItem()) { - PyErr_SetString(PyExc_TypeError, "CListWrapper's item type doesn't support assignment"); - return -1; - } - - if (!value) { - PyErr_SetString(PyExc_TypeError, "CListWrapper doesn't support item deletion"); - return -1; - } - - int size = list->GetSize(); - - if (index < 0) { - index = size + index; - } - if (index < 0 || index >= size) { - PyErr_SetString(PyExc_IndexError, "CListWrapper[i]: List index out of range in CListWrapper"); - return -1; - } - - if (!list->SetItem(index, value)) { - return -1; - } - return 0; -} - -PyObject *CListWrapper::py_mapping_subscript(PyObject *self, PyObject *key) -{ - CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self); - // Invalid list. - if (!list->CheckValid()) { - PyErr_SetString(PyExc_SystemError, "val = CListWrapper[key], " BGE_PROXY_ERROR_MSG); - return NULL; - } - - if (PyIndex_Check(key)) { - Py_ssize_t index = PyLong_AsSsize_t(key); - return py_get_item(self, index); - } - else if (PyUnicode_Check(key)) { - if (!list->AllowGetItemByName()) { - PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key"); - return NULL; - } - - const char *name = _PyUnicode_AsString(key); - int size = list->GetSize(); - - for (unsigned int i = 0; i < size; ++i) { - if (strcmp(list->GetItemName(i), name) == 0) { - return list->GetItem(i); - } - } - - PyErr_Format(PyExc_KeyError, "requested item \"%s\" does not exist", name); - return NULL; - } - - PyErr_Format(PyExc_KeyError, "CListWrapper[key]: '%R' key not in list", key); - return NULL; -} - -int CListWrapper::py_mapping_ass_subscript(PyObject *self, PyObject *key, PyObject *value) -{ - CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self); - // Invalid list. - if (!list->CheckValid()) { - PyErr_SetString(PyExc_SystemError, "val = CListWrapper[key], " BGE_PROXY_ERROR_MSG); - return -1; - } - - if (!list->AllowSetItem()) { - PyErr_SetString(PyExc_TypeError, "CListWrapper's item type doesn't support assignment"); - return -1; - } - - if (PyIndex_Check(key)) { - Py_ssize_t index = PyLong_AsSsize_t(key); - return py_set_item(self, index, value); - } - else if (PyUnicode_Check(key)) { - if (!list->AllowGetItemByName()) { - PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key"); - return -1; - } - - const char *name = _PyUnicode_AsString(key); - int size = list->GetSize(); - - for (unsigned int i = 0; i < size; ++i) { - if (strcmp(list->GetItemName(i), name) == 0) { - if (!list->SetItem(i, value)) { - return -1; - } - return 0; - } - } - - PyErr_Format(PyExc_KeyError, "requested item \"%s\" does not exist", name); - return -1; - } - - PyErr_Format(PyExc_KeyError, "CListWrapper[key]: '%R' key not in list", key); - return -1; -} - -int CListWrapper::py_contains(PyObject *self, PyObject *key) -{ - CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self); - // Invalid list. - if (!list->CheckValid()) { - PyErr_SetString(PyExc_SystemError, "val = CListWrapper[i], " BGE_PROXY_ERROR_MSG); - return -1; - } - - if (!list->AllowGetItemByName()) { - PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key"); - return -1; - } - - if (!PyUnicode_Check(key)) { - PyErr_SetString(PyExc_SystemError, "key in list, CListWrapper: key must be a string"); - return -1; - } - - const char *name = _PyUnicode_AsString(key); - int size = list->GetSize(); - - for (unsigned int i = 0; i < size; ++i) { - if (strcmp(list->GetItemName(i), name) == 0) { - return 1; - } - } - - return 0; -} - -PySequenceMethods CListWrapper::py_as_sequence = { - py_len, // sq_length - NULL, // sq_concat - NULL, // sq_repeat - py_get_item, // sq_item - NULL, // sq_slice - py_set_item, // sq_ass_item - NULL, // sq_ass_slice - (objobjproc)py_contains, // sq_contains - (binaryfunc) NULL, // sq_inplace_concat - (ssizeargfunc) NULL, // sq_inplace_repeat -}; - -PyMappingMethods CListWrapper::py_as_mapping = { - py_len, // mp_length - py_mapping_subscript, // mp_subscript - py_mapping_ass_subscript // mp_ass_subscript -}; - -PyTypeObject CListWrapper::Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CListWrapper", // tp_name - sizeof(PyObjectPlus_Proxy), // tp_basicsize - 0, // tp_itemsize - py_base_dealloc, // tp_dealloc - 0, // tp_print - 0, // tp_getattr - 0, // tp_setattr - 0, // tp_compare - py_base_repr, // tp_repr - 0, // tp_as_number - &py_as_sequence, // tp_as_sequence - &py_as_mapping, // tp_as_mapping - 0, // tp_hash - 0, // tp_call - 0, - NULL, - NULL, - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - 0,0,0,0,0,0,0, - Methods, - 0, - 0, - &CValue::Type, - 0,0,0,0,0,0, - py_base_new -}; - -PyMethodDef CListWrapper::Methods[] = { - {"get", (PyCFunction)CListWrapper::sPyGet, METH_VARARGS}, - {NULL, NULL} //Sentinel -}; - -PyAttributeDef CListWrapper::Attributes[] = { - {NULL} //Sentinel -}; - -/* Matches python dict.get(key, [default]) */ -PyObject *CListWrapper::PyGet(PyObject *args) -{ - char *name; - PyObject *def = Py_None; - - // Invalid list. - if (!CheckValid()) { - PyErr_SetString(PyExc_SystemError, "val = CListWrapper[i], " BGE_PROXY_ERROR_MSG); - return NULL; - } - - if (!AllowGetItemByName()) { - PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "s|O:get", &name, &def)) { - return NULL; - } - - for (unsigned int i = 0; i < GetSize(); ++i) { - if (strcmp(GetItemName(i), name) == 0) { - return GetItem(i); - } - } - - Py_INCREF(def); - return def; -} - -#endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/intern/Operator1Expr.cpp b/source/gameengine/Expressions/intern/Operator1Expr.cpp deleted file mode 100644 index add0376f487..00000000000 --- a/source/gameengine/Expressions/intern/Operator1Expr.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/** \file gameengine/Expressions/Operator1Expr.cpp - * \ingroup expressions - */ -// Operator1Expr.cpp: implementation of the COperator1Expr class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include "EXP_Operator1Expr.h" -#include "EXP_EmptyValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -COperator1Expr::COperator1Expr() -/* -pre: -effect: constucts an empty COperator1Expr -*/ -{ - m_lhs = NULL; -} - -COperator1Expr::COperator1Expr(VALUE_OPERATOR op, CExpression *lhs) -/* -pre: -effect: constucts a COperator1Expr with op and lhs in it -*/ -{ - m_lhs = lhs; - m_op = op; -} - -COperator1Expr::~COperator1Expr() -/* -pre: -effect: deletes the object -*/ -{ - if (m_lhs) m_lhs->Release(); -} - -CValue * COperator1Expr::Calculate() -/* -pre: -ret: a new object containing the result of applying the operator m_op to the - value of m_lhs -*/ -{ - CValue *ret; - CValue *temp = m_lhs->Calculate(); - CValue* empty = new CEmptyValue(); - ret = empty->Calc(m_op, temp); - empty->Release(); - temp->Release(); - - return ret; -} - -/* -bool COperator1Expr::IsInside(float x, float y, float z,bool bBorderInclude) -{ - - bool result = true; - switch (m_op) - { - - case VALUE_ADD_OPERATOR: - { - - if (m_lhs) - { - result = result || m_lhs->IsInside(x,y,z,bBorderInclude); - } - break; - } - case VALUE_SUB_OPERATOR: - { - result = true; - if (m_lhs) - { - result = result && (!m_lhs->IsInside(x,y,z,bBorderInclude)); - } - break; - } - } - return result; -} - -*/ -bool COperator1Expr::NeedsRecalculated() -{ - return m_lhs->NeedsRecalculated(); -} - -CExpression* COperator1Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) -{ - - CExpression* newlhs = m_lhs->CheckLink(brokenlinks); - - if (newlhs) - { - if (newlhs==m_lhs) { - // not changed - } else { - // changed - //numchanges++; - newlhs->AddRef(); - - //m_lhs->Release(); - brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs)); - - m_lhs = newlhs; - } - return this; - } else { - //numchanges++; - AddRef(); - - return Release(); - } - -} - -void COperator1Expr::BroadcastOperators(VALUE_OPERATOR op) -{ - if (m_lhs) - m_lhs->BroadcastOperators(m_op); -} - - - - -bool COperator1Expr::MergeExpression(CExpression *otherexpr) -{ - if (m_lhs) - return m_lhs->MergeExpression(otherexpr); - - assertd(false); // should not get here, expression is not compatible for merge - return false; -} diff --git a/source/gameengine/Expressions/intern/Operator2Expr.cpp b/source/gameengine/Expressions/intern/Operator2Expr.cpp deleted file mode 100644 index 0a7f30b8cc8..00000000000 --- a/source/gameengine/Expressions/intern/Operator2Expr.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/** \file gameengine/Expressions/Operator2Expr.cpp - * \ingroup expressions - */ -// Operator2Expr.cpp: implementation of the COperator2Expr class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ -// 31 dec 1998 - big update: try to use the cached data for updating, instead of -// rebuilding completely it from left and right node. Modified flags and bounding boxes -// have to do the trick -// when expression is cached, there will be a call to UpdateCalc() instead of Calc() - -#include "EXP_Operator2Expr.h" -#include "EXP_StringValue.h" -#include "EXP_VoidValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -COperator2Expr::COperator2Expr(VALUE_OPERATOR op, CExpression *lhs, CExpression *rhs) -: -m_rhs(rhs), -m_lhs(lhs), -m_cached_calculate(NULL), -m_op(op) -/* -pre: -effect: constucts a COperator2Expr with op, lhs and rhs in it -*/ -{ - -} - -COperator2Expr::COperator2Expr(): -m_rhs(NULL), -m_lhs(NULL), -m_cached_calculate(NULL) - -/* -pre: -effect: constucts an empty COperator2Expr -*/ -{ - -} - -COperator2Expr::~COperator2Expr() -/* -pre: -effect: deletes the object -*/ -{ - if (m_lhs) - m_lhs->Release(); - if (m_rhs) - m_rhs->Release(); - if (m_cached_calculate) - m_cached_calculate->Release(); - -} -CValue* COperator2Expr::Calculate() -/* -pre: -ret: a new object containing the result of applying operator m_op to m_lhs -and m_rhs -*/ -{ - - bool leftmodified,rightmodified; - leftmodified = m_lhs->NeedsRecalculated(); - rightmodified = m_rhs->NeedsRecalculated(); - - // if no modifications on both left and right subtree, and result is already calculated - // then just return cached result... - if (!leftmodified && !rightmodified && (m_cached_calculate)) - { - // not modified, just return m_cached_calculate - } else { - // if not yet calculated, or modified... - - - if (m_cached_calculate) { - m_cached_calculate->Release(); - m_cached_calculate=NULL; - } - - CValue* ffleft = m_lhs->Calculate(); - CValue* ffright = m_rhs->Calculate(); - - ffleft->SetOwnerExpression(this);//->m_pOwnerExpression=this; - ffright->SetOwnerExpression(this);//->m_pOwnerExpression=this; - - m_cached_calculate = ffleft->Calc(m_op,ffright); - - //if (m_cached_calculate) - // m_cached_calculate->Action(CValue::SETOWNEREXPR,&CVoidValue(this,false,CValue::STACKVALUE)); - - ffleft->Release(); - ffright->Release(); - } - - return m_cached_calculate->AddRef(); - -} - -#if 0 -bool COperator2Expr::IsInside(float x, float y, float z,bool bBorderInclude) -{ - bool inside; - inside = false; - - switch (m_op) { - case VALUE_ADD_OPERATOR: - { - // inside = first || second; // optimized with early out if first is inside - // todo: calculate smallest leaf first ! is much faster... - - bool second;//first ;//,second; - - //first = m_lhs->IsInside(x,y,z); - second = m_rhs->IsInside(x,y,z,bBorderInclude); - if (second) - return true; //early out - - // second = m_rhs->IsInside(x,y,z); - - return m_lhs->IsInside(x,y,z,bBorderInclude); - - break; - } - - case VALUE_SUB_OPERATOR: - { - //inside = first && !second; // optimized with early out - // todo: same as with add_operator: calc smallest leaf first - - bool second;//first ;//,second; - //first = m_lhs->IsInside(x,y,z); - second = m_rhs->IsInside(x,y,z,bBorderInclude); - if (second) - return false; - - // second space get subtracted -> negate! - //second = m_rhs->IsInside(x,y,z); - - return (m_lhs->IsInside(x,y,z,bBorderInclude)); - - - break; - } - default: - { - assert(false); - // not yet implemented, only add or sub csg operations - } - } - - return inside; -} - -bool COperator2Expr::IsRightInside(float x, float y, float z,bool bBorderInclude) -{ - return m_rhs->IsInside(x,y,z,bBorderInclude); -} - -bool COperator2Expr::IsLeftInside(float x, float y, float z,bool bBorderInclude) -{ - return m_lhs->IsInside(x,y,z,bBorderInclude); -} -#endif - -bool COperator2Expr::NeedsRecalculated() -{ - // added some lines, just for debugging purposes, it could be a one-liner :) - //bool modleft - //bool modright; - assertd(m_lhs); - assertd(m_rhs); - - //modright = m_rhs->NeedsRecalculated(); - if (m_rhs->NeedsRecalculated()) // early out - return true; - return m_lhs->NeedsRecalculated(); - //modleft = m_lhs->NeedsRecalculated(); - //return (modleft || modright); - -} - - - -CExpression* COperator2Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) -{ -// if both children are 'dead', return NULL -// if only one child is alive, return that child -// if both childresn are alive, return this - - -// bool leftalive = true,rightalive=true; - /* Does this mean the function will always bomb? */ - assertd(false); - assert(m_lhs); - assert(m_rhs); -/* - if (m_cached_calculate) - m_cached_calculate->Action(CValue::REFRESH_CACHE); - - CExpression* newlhs = m_lhs->CheckLink(brokenlinks); - CExpression* newrhs = m_rhs->CheckLink(brokenlinks); - - if (m_lhs != newlhs) - { - brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs)); - } - - if (m_rhs != newrhs) - { - brokenlinks.push_back(new CBrokenLinkInfo(&m_rhs,m_rhs)); - } - - - - m_lhs = newlhs; - m_rhs = newrhs; - - if (m_lhs && m_rhs) { - return this; - } - - AddRef(); - if (m_lhs) - return Release(m_lhs->AddRef()); - - if (m_rhs) - return Release(m_rhs->AddRef()); -/ - - */ - return Release(); -} - - -bool COperator2Expr::MergeExpression(CExpression *otherexpr) -{ - if (m_lhs) - { - if (m_lhs->GetExpressionID() == CExpression::CCONSTEXPRESSIONID) - { - // cross fingers ;) replace constexpr by new tree... - m_lhs->Release(); - m_lhs = otherexpr->AddRef(); - return true; - } - } - - assertd(false); - return false; -} - - -void COperator2Expr::BroadcastOperators(VALUE_OPERATOR op) -{ - if (m_lhs) - m_lhs->BroadcastOperators(m_op); - if (m_rhs) - m_rhs->BroadcastOperators(m_op); -} diff --git a/source/gameengine/Expressions/intern/PyObjectPlus.cpp b/source/gameengine/Expressions/intern/PyObjectPlus.cpp deleted file mode 100644 index 1e4a59aeb5c..00000000000 --- a/source/gameengine/Expressions/intern/PyObjectPlus.cpp +++ /dev/null @@ -1,1226 +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/PyObjectPlus.cpp - * \ingroup expressions - */ - - -/*------------------------------ - * PyObjectPlus cpp - * - * C++ library routines for Crawl 3.2 - * - * Derived from work by - * David Redish - * graduate student - * Computer Science Department - * Carnegie Mellon University (CMU) - * Center for the Neural Basis of Cognition (CNBC) - * http://www.python.org/doc/PyCPP.html - * - * ----------------------------- */ -#include <stdlib.h> -#include <stddef.h> - -#include "EXP_PyObjectPlus.h" -#include "STR_String.h" -#include "MT_Vector3.h" -#include "MEM_guardedalloc.h" - -PyObjectPlus::~PyObjectPlus() -{ -#ifdef WITH_PYTHON - if (m_proxy) { - BGE_PROXY_REF(m_proxy)= NULL; - Py_DECREF(m_proxy); /* Remove own reference, python may still have 1 */ - } -// assert(ob_refcnt==0); -#endif -} - -PyObjectPlus::PyObjectPlus() : SG_QList() // constructor -{ -#ifdef WITH_PYTHON - m_proxy= NULL; -#endif -}; - -void PyObjectPlus::ProcessReplica() -{ -#ifdef WITH_PYTHON - /* Clear the proxy, will be created again if needed with GetProxy() - * otherwise the PyObject will point to the wrong reference */ - m_proxy= NULL; -#endif -} - -/* Sometimes we might want to manually invalidate a BGE type even if - * 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, - * and will raise an error on access. However if python can get access - * to this class again it will make a new proxy and work as expected. - */ -void PyObjectPlus::InvalidateProxy() // check typename of each parent -{ -#ifdef WITH_PYTHON - if (m_proxy) { - BGE_PROXY_REF(m_proxy)=NULL; - Py_DECREF(m_proxy); - m_proxy= NULL; - } -#endif -} - - -#ifdef WITH_PYTHON - -/*------------------------------ - * PyObjectPlus Type -- Every class, even the abstract one should have a Type - * ----------------------------- */ - - -PyTypeObject PyObjectPlus::Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "PyObjectPlus", /*tp_name*/ - sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - py_base_dealloc, /* tp_dealloc */ - 0, /* printfunc tp_print; */ - 0, /* getattrfunc tp_getattr; */ - 0, /* setattrfunc tp_setattr; */ - 0, /* tp_compare */ /* DEPRECATED in python 3.0! */ - py_base_repr, /* tp_repr */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Method suites for standard classes */ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* long tp_flags; */ - 0, 0, 0, 0, - /* weak reference enabler */ -#ifdef USE_WEAKREFS - offsetof(PyObjectPlus_Proxy, in_weakreflist), /* long tp_weaklistoffset; */ -#else - 0, -#endif - 0, 0, - Methods, - 0, - 0, - NULL // no subtype -}; - -PyObject *PyObjectPlus::py_base_repr(PyObject *self) // This should be the entry in Type. -{ - PyObjectPlus *self_plus= BGE_PROXY_REF(self); - if (self_plus==NULL) { - PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG); - return NULL; - } - return self_plus->py_repr(); -} - - -PyObject *PyObjectPlus::py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds) -{ - PyTypeObject *base_type; - - /* 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) - * we need to find the first C++ defined class to check 'type' - * is a subclass of the base arguments type. - * - * This way we can share one tp_new function for every PyObjectPlus - * - * 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)) - base_type= base_type->tp_base; - - if (base_type==NULL || !BGE_PROXY_CHECK_TYPE(base_type)) { - PyErr_SetString(PyExc_TypeError, "can't subclass from a blender game type because the argument given is not a game class or subclass"); - return NULL; - } - - /* use base_type rather than Py_TYPE(base) because we could already be subtyped */ - if (!PyType_IsSubtype(type, base_type)) { - PyErr_Format(PyExc_TypeError, "can't subclass blender game type <%s> from <%s> because it is not a subclass", base_type->tp_name, type->tp_name); - return NULL; - } - - /* invalidate the existing base and return a new subclassed one, - * this is a bit dodgy in that it also attaches its self to the existing object - * which is not really 'correct' python OO but for our use its OK. */ - - PyObjectPlus_Proxy *ret = (PyObjectPlus_Proxy *) type->tp_alloc(type, 0); /* starts with 1 ref, used for the return ref' */ - ret->ref= base->ref; - ret->ptr= base->ptr; - ret->py_owns= base->py_owns; - ret->py_ref = base->py_ref; - - if (ret->py_ref) { - base->ref= NULL; /* invalidate! disallow further access */ - base->ptr = NULL; - if (ret->ref) - ret->ref->m_proxy= NULL; - /* 'base' may be freed after this func finished but not necessarily - * there is no reference to the BGE data now so it will throw an error on access */ - Py_DECREF(base); - if (ret->ref) { - ret->ref->m_proxy= (PyObject *)ret; /* no need to add a ref because one is added when creating. */ - Py_INCREF(ret); /* we return a new ref but m_proxy holds a ref so we need to add one */ - } - } else { - // generic structures don't hold a reference to this proxy, so don't increment ref count - if (ret->py_owns) - // but if the proxy owns the structure, there can be only one owner - base->ptr= NULL; - } - - return (PyObject *)ret; -} - -/** - * \param self A PyObjectPlus_Proxy - */ -void PyObjectPlus::py_base_dealloc(PyObject *self) // python wrapper -{ -#ifdef USE_WEAKREFS - if (BGE_PROXY_WKREF(self) != NULL) - PyObject_ClearWeakRefs((PyObject *) self); -#endif - - if (BGE_PROXY_PYREF(self)) { - PyObjectPlus *self_plus= BGE_PROXY_REF(self); - if (self_plus) { - if (BGE_PROXY_PYOWNS(self)) { /* Does python own this?, then delete it */ - self_plus->m_proxy = NULL; /* Need this to stop ~PyObjectPlus from decrefing m_proxy otherwise its decref'd twice and py-debug crashes */ - delete self_plus; - } - BGE_PROXY_REF(self)= NULL; // not really needed - } - // the generic pointer is not deleted directly, only through self_plus - BGE_PROXY_PTR(self)= NULL; // not really needed - } else { - void *ptr= BGE_PROXY_PTR(self); - if (ptr) { - if (BGE_PROXY_PYOWNS(self)) { /* Does python own this?, then delete it */ - // generic structure owned by python MUST be created though MEM_alloc - MEM_freeN(ptr); - } - BGE_PROXY_PTR(self)= NULL; // not really needed - } - } -#if 0 - /* is ok normally but not for subtyping, use tp_free instead. */ - PyObject_DEL( self ); -#else - Py_TYPE(self)->tp_free(self); -#endif -}; - -/*------------------------------ - * PyObjectPlus Methods -- Every class, even the abstract one should have a Methods -------------------------------*/ -PyMethodDef PyObjectPlus::Methods[] = { - {NULL, NULL} /* Sentinel */ -}; - -#define BGE_PY_ATTR_INVALID (&(PyObjectPlus::Attributes[0])) -PyAttributeDef PyObjectPlus::Attributes[] = { - KX_PYATTRIBUTE_RO_FUNCTION("invalid", PyObjectPlus, pyattr_get_invalid), - {NULL} //Sentinel -}; - - - -PyObject *PyObjectPlus::pyattr_get_invalid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) -{ - return PyBool_FromLong(self_v ? 0:1); -} - -/* note, this is called as a python 'getset, where the PyAttributeDef is the closure */ -PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef) -{ - PyObjectPlus *ref= (BGE_PROXY_REF(self_py)); - char* ptr = (attrdef->m_usePtr) ? (char*)BGE_PROXY_PTR(self_py) : (char*)ref; - if (ptr == NULL || (BGE_PROXY_PYREF(self_py) && (ref==NULL || !ref->py_is_valid()))) { - if (attrdef == BGE_PY_ATTR_INVALID) - Py_RETURN_TRUE; // don't bother running the function - - PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG); - return NULL; - } - - if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY) - { - // fake attribute, ignore - return NULL; - } - if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) - { - // the attribute has no field correspondence, handover processing to function. - if (attrdef->m_getFunction == NULL) - return NULL; - return (*attrdef->m_getFunction)(ptr, attrdef); - } - ptr += attrdef->m_offset; - if (attrdef->m_length > 1) - { - PyObject *resultlist = PyList_New(attrdef->m_length); - for (unsigned int i=0; i<attrdef->m_length; i++) - { - switch (attrdef->m_type) { - case KX_PYATTRIBUTE_TYPE_BOOL: - { - bool *val = reinterpret_cast<bool*>(ptr); - ptr += sizeof(bool); - PyList_SET_ITEM(resultlist, i, PyBool_FromLong(*val)); - break; - } - case KX_PYATTRIBUTE_TYPE_SHORT: - { - short int *val = reinterpret_cast<short int*>(ptr); - ptr += sizeof(short int); - PyList_SET_ITEM(resultlist, i, PyLong_FromLong(*val)); - break; - } - case KX_PYATTRIBUTE_TYPE_ENUM: - // enum are like int, just make sure the field size is the same - if (sizeof(int) != attrdef->m_size) - { - Py_DECREF(resultlist); - return NULL; - } - ATTR_FALLTHROUGH; - case KX_PYATTRIBUTE_TYPE_INT: - { - int *val = reinterpret_cast<int*>(ptr); - ptr += sizeof(int); - PyList_SET_ITEM(resultlist, i, PyLong_FromLong(*val)); - break; - } - case KX_PYATTRIBUTE_TYPE_FLOAT: - { - float *val = reinterpret_cast<float*>(ptr); - ptr += sizeof(float); - PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble(*val)); - break; - } - default: - // no support for array of complex data - Py_DECREF(resultlist); - return NULL; - } - } - return resultlist; - } - else - { - switch (attrdef->m_type) { - case KX_PYATTRIBUTE_TYPE_FLAG: - { - bool bval; - switch (attrdef->m_size) { - case 1: - { - unsigned char *val = reinterpret_cast<unsigned char*>(ptr); - bval = (*val & attrdef->m_imin); - break; - } - case 2: - { - unsigned short *val = reinterpret_cast<unsigned short*>(ptr); - bval = (*val & attrdef->m_imin); - break; - } - case 4: - { - unsigned int *val = reinterpret_cast<unsigned int*>(ptr); - bval = (*val & attrdef->m_imin); - break; - } - default: - return NULL; - } - if (attrdef->m_imax) - bval = !bval; - return PyBool_FromLong(bval); - } - case KX_PYATTRIBUTE_TYPE_BOOL: - { - bool *val = reinterpret_cast<bool*>(ptr); - return PyBool_FromLong(*val); - } - case KX_PYATTRIBUTE_TYPE_SHORT: - { - short int *val = reinterpret_cast<short int*>(ptr); - return PyLong_FromLong(*val); - } - case KX_PYATTRIBUTE_TYPE_ENUM: - // enum are like int, just make sure the field size is the same - if (sizeof(int) != attrdef->m_size) - { - return NULL; - } - ATTR_FALLTHROUGH; - case KX_PYATTRIBUTE_TYPE_INT: - { - int *val = reinterpret_cast<int*>(ptr); - return PyLong_FromLong(*val); - } - case KX_PYATTRIBUTE_TYPE_FLOAT: - { - float *val = reinterpret_cast<float*>(ptr); - if (attrdef->m_imin == 0) { - if (attrdef->m_imax == 0) { - return PyFloat_FromDouble(*val); - } else { - // vector, verify size - if (attrdef->m_size != attrdef->m_imax*sizeof(float)) - { - return NULL; - } -#ifdef USE_MATHUTILS - 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++) - { - PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble(val[i])); - } - return resultlist; -#endif - } - } else { - // matrix case - if (attrdef->m_size != attrdef->m_imax*attrdef->m_imin*sizeof(float)) - { - return NULL; - } -#ifdef USE_MATHUTILS - 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++) - { - PyObject *col = PyList_New(attrdef->m_imax); - for (unsigned int j=0; j<attrdef->m_imax; j++) - { - PyList_SET_ITEM(col, j, PyFloat_FromDouble(val[j])); - } - PyList_SET_ITEM(collist, i, col); - val += attrdef->m_imax; - } - return collist; -#endif - } - } - case KX_PYATTRIBUTE_TYPE_VECTOR: - { - MT_Vector3 *val = reinterpret_cast<MT_Vector3*>(ptr); -#ifdef USE_MATHUTILS - float fval[3]; - val->getValue(fval); - return Vector_CreatePyObject(fval, 3, NULL); -#else - PyObject *resultlist = PyList_New(3); - for (unsigned int i=0; i<3; i++) - { - PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble((*val)[i])); - } - return resultlist; -#endif - } - case KX_PYATTRIBUTE_TYPE_STRING: - { - STR_String *val = reinterpret_cast<STR_String*>(ptr); - return PyUnicode_From_STR_String(*val); - } - case KX_PYATTRIBUTE_TYPE_CHAR: - { - return PyUnicode_FromString(ptr); - } - default: - return NULL; - } - } -} - - -static bool py_check_attr_float(float *var, PyObject *value, const PyAttributeDef *attrdef) -{ - float val = PyFloat_AsDouble(value); - if (val == -1.0f && PyErr_Occurred()) - { - PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name); - return false; - } - if (attrdef->m_clamp) - { - if (val < attrdef->m_fmin) - val = attrdef->m_fmin; - else if (val > attrdef->m_fmax) - val = attrdef->m_fmax; - } - else if (val < attrdef->m_fmin || val > attrdef->m_fmax) - { - PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name); - return false; - } - *var = (float)val; - return true; -} - -/* note, this is called as a python getset */ -int PyObjectPlus::py_set_attrdef(PyObject *self_py, PyObject *value, const PyAttributeDef *attrdef) -{ - PyObjectPlus *ref= (BGE_PROXY_REF(self_py)); - char* ptr = (attrdef->m_usePtr) ? (char*)BGE_PROXY_PTR(self_py) : (char*)ref; - if (ref==NULL || !ref->py_is_valid() || ptr==NULL) { - PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG); - return PY_SET_ATTR_FAIL; - } - - void *undoBuffer = NULL; - void *sourceBuffer = NULL; - size_t bufferSize = 0; - PyObject *item = NULL; // to store object that must be dereferenced in case of error - PyObject *list = NULL; // to store object that must be dereferenced in case of error - - ptr += attrdef->m_offset; - if (attrdef->m_length > 1) - { - if (!PySequence_Check(value)) - { - PyErr_Format(PyExc_TypeError, "expected a sequence for attribute \"%s\"", attrdef->m_name); - return PY_SET_ATTR_FAIL; - } - if (PySequence_Size(value) != attrdef->m_length) - { - PyErr_Format(PyExc_TypeError, "incorrect number of elements in sequence for attribute \"%s\"", attrdef->m_name); - return PY_SET_ATTR_FAIL; - } - switch (attrdef->m_type) - { - case KX_PYATTRIBUTE_TYPE_FUNCTION: - if (attrdef->m_setFunction == NULL) - { - PyErr_Format(PyExc_AttributeError, "function attribute without function for attribute \"%s\", report to blender.org", attrdef->m_name); - return PY_SET_ATTR_FAIL; - } - return (*attrdef->m_setFunction)(ref, attrdef, value); - case KX_PYATTRIBUTE_TYPE_BOOL: - bufferSize = sizeof(bool); - break; - case KX_PYATTRIBUTE_TYPE_SHORT: - bufferSize = sizeof(short int); - break; - case KX_PYATTRIBUTE_TYPE_ENUM: - case KX_PYATTRIBUTE_TYPE_INT: - bufferSize = sizeof(int); - break; - case KX_PYATTRIBUTE_TYPE_FLOAT: - bufferSize = sizeof(float); - break; - default: - // should not happen - PyErr_Format(PyExc_AttributeError, "Unsupported attribute type for attribute \"%s\", report to blender.org", attrdef->m_name); - return PY_SET_ATTR_FAIL; - } - // let's implement a smart undo method - bufferSize *= attrdef->m_length; - undoBuffer = malloc(bufferSize); - sourceBuffer = ptr; - if (undoBuffer) - { - memcpy(undoBuffer, sourceBuffer, bufferSize); - } - for (int i=0; i<attrdef->m_length; i++) - { - item = PySequence_GetItem(value, i); /* new ref */ - switch (attrdef->m_type) - { - case KX_PYATTRIBUTE_TYPE_BOOL: - { - bool *var = reinterpret_cast<bool*>(ptr); - ptr += sizeof(bool); - if (PyLong_Check(item)) - { - *var = (PyLong_AsLong(item) != 0); - } - else if (PyBool_Check(item)) - { - *var = (item == Py_True); - } - else - { - PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name); - goto UNDO_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_SHORT: - { - short int *var = reinterpret_cast<short int*>(ptr); - ptr += sizeof(short int); - if (PyLong_Check(item)) - { - int val = PyLong_AsLong(item); - if (attrdef->m_clamp) - { - if (val < attrdef->m_imin) - val = attrdef->m_imin; - else if (val > attrdef->m_imax) - val = attrdef->m_imax; - } - else if (val < attrdef->m_imin || val > attrdef->m_imax) - { - PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name); - goto UNDO_AND_ERROR; - } - *var = (short int)val; - } - else - { - PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); - goto UNDO_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_ENUM: - // enum are equivalent to int, just make sure that the field size matches: - if (sizeof(int) != attrdef->m_size) - { - PyErr_Format(PyExc_AttributeError, "Size check error for attribute, \"%s\", report to blender.org", attrdef->m_name); - goto UNDO_AND_ERROR; - } - ATTR_FALLTHROUGH; - case KX_PYATTRIBUTE_TYPE_INT: - { - int *var = reinterpret_cast<int*>(ptr); - ptr += sizeof(int); - if (PyLong_Check(item)) - { - int val = PyLong_AsLong(item); - if (attrdef->m_clamp) - { - if (val < attrdef->m_imin) - val = attrdef->m_imin; - else if (val > attrdef->m_imax) - val = attrdef->m_imax; - } - else if (val < attrdef->m_imin || val > attrdef->m_imax) - { - PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name); - goto UNDO_AND_ERROR; - } - *var = (int)val; - } - else - { - PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); - goto UNDO_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_FLOAT: - { - float *var = reinterpret_cast<float*>(ptr); - ptr += sizeof(float); - float val = PyFloat_AsDouble(item); - if (val == -1.0f && PyErr_Occurred()) - { - PyErr_Format(PyExc_TypeError, "expected a float for attribute \"%s\"", attrdef->m_name); - goto UNDO_AND_ERROR; - } - else if (attrdef->m_clamp) - { - if (val < attrdef->m_fmin) - val = attrdef->m_fmin; - else if (val > attrdef->m_fmax) - val = attrdef->m_fmax; - } - else if (val < attrdef->m_fmin || val > attrdef->m_fmax) - { - PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name); - goto UNDO_AND_ERROR; - } - *var = (float)val; - break; - } - default: - // should not happen - PyErr_Format(PyExc_AttributeError, "type check error for attribute \"%s\", report to blender.org", attrdef->m_name); - goto UNDO_AND_ERROR; - } - // finished using item, release - Py_DECREF(item); - item = NULL; - } - // no error, call check function if any - if (attrdef->m_checkFunction != NULL) - { - if ((*attrdef->m_checkFunction)(ref, attrdef) != 0) - { - // if the checing function didnt set an error then set a generic one here so we don't set an error with no exception - if (PyErr_Occurred()==0) - PyErr_Format(PyExc_AttributeError, "type check error for attribute \"%s\", reasion unknown", attrdef->m_name); - - // post check returned an error, restore values - UNDO_AND_ERROR: - if (undoBuffer) - { - memcpy(sourceBuffer, undoBuffer, bufferSize); - free(undoBuffer); - } - if (item) - Py_DECREF(item); - return PY_SET_ATTR_FAIL; - } - } - if (undoBuffer) - free(undoBuffer); - return PY_SET_ATTR_SUCCESS; - } - else // simple attribute value - { - if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION) - { - if (attrdef->m_setFunction == NULL) - { - PyErr_Format(PyExc_AttributeError, "function attribute without function \"%s\", report to blender.org", attrdef->m_name); - return PY_SET_ATTR_FAIL; - } - return (*attrdef->m_setFunction)(ref, attrdef, value); - } - if (attrdef->m_checkFunction != NULL || attrdef->m_type == KX_PYATTRIBUTE_TYPE_VECTOR) - { - // post check function is provided, prepare undo buffer - sourceBuffer = ptr; - switch (attrdef->m_type) - { - case KX_PYATTRIBUTE_TYPE_BOOL: - bufferSize = sizeof(bool); - break; - case KX_PYATTRIBUTE_TYPE_SHORT: - bufferSize = sizeof(short); - break; - case KX_PYATTRIBUTE_TYPE_ENUM: - case KX_PYATTRIBUTE_TYPE_FLAG: - case KX_PYATTRIBUTE_TYPE_CHAR: - bufferSize = attrdef->m_size; - break; - case KX_PYATTRIBUTE_TYPE_INT: - bufferSize = sizeof(int); - break; - case KX_PYATTRIBUTE_TYPE_FLOAT: - bufferSize = sizeof(float); - if (attrdef->m_imax) - bufferSize *= attrdef->m_imax; - if (attrdef->m_imin) - bufferSize *= attrdef->m_imin; - break; - case KX_PYATTRIBUTE_TYPE_STRING: - sourceBuffer = reinterpret_cast<STR_String*>(ptr)->Ptr(); - if (sourceBuffer) - bufferSize = strlen(reinterpret_cast<char*>(sourceBuffer))+1; - break; - case KX_PYATTRIBUTE_TYPE_VECTOR: - bufferSize = sizeof(MT_Vector3); - break; - default: - PyErr_Format(PyExc_AttributeError, "unknown type for attribute \"%s\", report to blender.org", attrdef->m_name); - return PY_SET_ATTR_FAIL; - } - if (bufferSize) - { - undoBuffer = malloc(bufferSize); - if (undoBuffer) - { - memcpy(undoBuffer, sourceBuffer, bufferSize); - } - } - } - - switch (attrdef->m_type) - { - case KX_PYATTRIBUTE_TYPE_BOOL: - { - bool *var = reinterpret_cast<bool*>(ptr); - if (PyLong_Check(value)) - { - *var = (PyLong_AsLong(value) != 0); - } - else if (PyBool_Check(value)) - { - *var = (value == Py_True); - } - else - { - PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_FLAG: - { - bool bval; - if (PyLong_Check(value)) - { - bval = (PyLong_AsLong(value) != 0); - } - else if (PyBool_Check(value)) - { - bval = (value == Py_True); - } - else - { - PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - if (attrdef->m_imax) - bval = !bval; - switch (attrdef->m_size) { - case 1: - { - unsigned char *val = reinterpret_cast<unsigned char*>(ptr); - *val = (*val & ~attrdef->m_imin) | ((bval)?attrdef->m_imin:0); - break; - } - case 2: - { - unsigned short *val = reinterpret_cast<unsigned short*>(ptr); - *val = (*val & ~attrdef->m_imin) | ((bval)?attrdef->m_imin:0); - break; - } - case 4: - { - unsigned int *val = reinterpret_cast<unsigned int*>(ptr); - *val = (*val & ~attrdef->m_imin) | ((bval)?attrdef->m_imin:0); - break; - } - default: - PyErr_Format(PyExc_TypeError, "internal error: unsupported flag field \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_SHORT: - { - short int *var = reinterpret_cast<short int*>(ptr); - if (PyLong_Check(value)) - { - int val = PyLong_AsLong(value); - if (attrdef->m_clamp) - { - if (val < attrdef->m_imin) - val = attrdef->m_imin; - else if (val > attrdef->m_imax) - val = attrdef->m_imax; - } - else if (val < attrdef->m_imin || val > attrdef->m_imax) - { - PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - *var = (short int)val; - } - else - { - PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_ENUM: - // enum are equivalent to int, just make sure that the field size matches: - if (sizeof(int) != attrdef->m_size) - { - PyErr_Format(PyExc_AttributeError, "attribute size check error for attribute \"%s\", report to blender.org", attrdef->m_name); - goto FREE_AND_ERROR; - } - ATTR_FALLTHROUGH; - case KX_PYATTRIBUTE_TYPE_INT: - { - int *var = reinterpret_cast<int*>(ptr); - if (PyLong_Check(value)) - { - int val = PyLong_AsLong(value); - if (attrdef->m_clamp) - { - if (val < attrdef->m_imin) - val = attrdef->m_imin; - else if (val > attrdef->m_imax) - val = attrdef->m_imax; - } - else if (val < attrdef->m_imin || val > attrdef->m_imax) - { - PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - *var = (int)val; - } - else - { - PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_FLOAT: - { - float *var = reinterpret_cast<float*>(ptr); - if (attrdef->m_imin != 0) - { - if (attrdef->m_size != attrdef->m_imin*attrdef->m_imax*sizeof(float)) - { - PyErr_Format(PyExc_TypeError, "internal error: incorrect field size for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - if (!PySequence_Check(value) || PySequence_Size(value) != attrdef->m_imin) - { - PyErr_Format(PyExc_TypeError, "expected a sequence of [%d][%d] floats for attribute \"%s\"", attrdef->m_imin, attrdef->m_imax, attrdef->m_name); - goto FREE_AND_ERROR; - } - for (int i=0; i<attrdef->m_imin; i++) - { - PyObject *list = PySequence_GetItem(value, i); /* new ref */ - if (!PySequence_Check(list) || PySequence_Size(list) != attrdef->m_imax) - { - PyErr_Format(PyExc_TypeError, "expected a sequence of [%d][%d] floats for attribute \"%s\"", attrdef->m_imin, attrdef->m_imax, attrdef->m_name); - goto RESTORE_AND_ERROR; - } - for (int j=0; j<attrdef->m_imax; j++) - { - item = PySequence_GetItem(list, j); /* new ref */ - if (!py_check_attr_float(var, item, attrdef)) - { - PyErr_Format(PyExc_TypeError, "expected a sequence of [%d][%d] floats for attribute \"%s\"", attrdef->m_imin, attrdef->m_imax, attrdef->m_name); - goto RESTORE_AND_ERROR; - } - Py_DECREF(item); - item = NULL; - ++var; - } - Py_DECREF(list); - list = NULL; - } - } - else if (attrdef->m_imax != 0) - { - if (attrdef->m_size != attrdef->m_imax*sizeof(float)) - { - PyErr_Format(PyExc_TypeError, "internal error: incorrect field size for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - if (!PySequence_Check(value) || PySequence_Size(value) != attrdef->m_imax) - { - PyErr_Format(PyExc_TypeError, "expected a sequence of [%d] floats for attribute \"%s\"", attrdef->m_imax, attrdef->m_name); - goto FREE_AND_ERROR; - } - for (int i=0; i<attrdef->m_imax; i++) - { - item = PySequence_GetItem(value, i); /* new ref */ - if (!py_check_attr_float(var, item, attrdef)) - { - goto RESTORE_AND_ERROR; - } - Py_DECREF(item); - item = NULL; - ++var; - } - } - else - { - if (!py_check_attr_float(var, value, attrdef)) - goto FREE_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_VECTOR: - { - if (!PySequence_Check(value) || PySequence_Size(value) != 3) - { - PyErr_Format(PyExc_TypeError, "expected a sequence of 3 floats for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - MT_Vector3 *var = reinterpret_cast<MT_Vector3*>(ptr); - for (int i=0; i<3; i++) - { - item = PySequence_GetItem(value, i); /* new ref */ - float val = PyFloat_AsDouble(item); - Py_DECREF(item); - item = NULL; - if (val == -1.0f && PyErr_Occurred()) - { - PyErr_Format(PyExc_TypeError, "expected a sequence of 3 floats for attribute \"%s\"", attrdef->m_name); - goto RESTORE_AND_ERROR; - } - else if (attrdef->m_clamp) - { - if (val < attrdef->m_fmin) - val = attrdef->m_fmin; - else if (val > attrdef->m_fmax) - val = attrdef->m_fmax; - } - else if (val < attrdef->m_fmin || val > attrdef->m_fmax) - { - PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name); - goto RESTORE_AND_ERROR; - } - (*var)[i] = (MT_Scalar)val; - } - break; - } - case KX_PYATTRIBUTE_TYPE_CHAR: - { - if (PyUnicode_Check(value)) - { - Py_ssize_t val_size; - const char *val = _PyUnicode_AsStringAndSize(value, &val_size); - strncpy(ptr, val, attrdef->m_size); - ptr[attrdef->m_size-1] = 0; - } - else - { - PyErr_Format(PyExc_TypeError, "expected a string for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - break; - } - case KX_PYATTRIBUTE_TYPE_STRING: - { - STR_String *var = reinterpret_cast<STR_String*>(ptr); - if (PyUnicode_Check(value)) - { - Py_ssize_t val_len; - const char *val = _PyUnicode_AsStringAndSize(value, &val_len); /* XXX, should be 'const' but we do a silly trick to have a shorter string */ - if (attrdef->m_clamp) - { - if (val_len < attrdef->m_imin) - { - // can't increase the length of the string - PyErr_Format(PyExc_ValueError, "string length too short for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - else if (val_len > attrdef->m_imax) - { - // trim the string - var->SetLength(attrdef->m_imax); - memcpy(var->Ptr(), val, attrdef->m_imax - 1); - break; - } - } else if (val_len < attrdef->m_imin || val_len > attrdef->m_imax) - { - PyErr_Format(PyExc_ValueError, "string length out of range for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - *var = val; - } - else - { - PyErr_Format(PyExc_TypeError, "expected a string for attribute \"%s\"", attrdef->m_name); - goto FREE_AND_ERROR; - } - break; - } - default: - // should not happen - PyErr_Format(PyExc_AttributeError, "unknown type for attribute \"%s\", report to blender.org", attrdef->m_name); - goto FREE_AND_ERROR; - } - } - // check if post processing is needed - if (attrdef->m_checkFunction != NULL) - { - if ((*attrdef->m_checkFunction)(ref, attrdef) != 0) - { - // restore value - RESTORE_AND_ERROR: - if (undoBuffer) - { - if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_STRING) - { - // special case for STR_String: restore the string - STR_String *var = reinterpret_cast<STR_String*>(ptr); - *var = reinterpret_cast<char*>(undoBuffer); - } - else - { - // other field type have direct values - memcpy(ptr, undoBuffer, bufferSize); - } - } - FREE_AND_ERROR: - if (undoBuffer) - free(undoBuffer); - if (list) - Py_DECREF(list); - if (item) - Py_DECREF(item); - return 1; - } - } - if (undoBuffer) - free(undoBuffer); - return 0; -} - - - -/*------------------------------ - * PyObjectPlus repr -- representations -------------------------------*/ -PyObject *PyObjectPlus::py_repr(void) -{ - PyErr_SetString(PyExc_SystemError, "Representation not overridden by object."); - return NULL; -} - -PyObject *PyObjectPlus::GetProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr) -{ - if (self->m_proxy==NULL) - { - self->m_proxy = reinterpret_cast<PyObject *>PyObject_NEW( PyObjectPlus_Proxy, tp); - BGE_PROXY_PYOWNS(self->m_proxy) = false; - BGE_PROXY_PYREF(self->m_proxy) = true; -#ifdef USE_WEAKREFS - BGE_PROXY_WKREF(self->m_proxy) = NULL; -#endif - } - //PyObject_Print(self->m_proxy, stdout, 0); - //printf("ref %d\n", self->m_proxy->ob_refcnt); - - BGE_PROXY_REF(self->m_proxy) = self; /* Its possible this was set to NULL, so set it back here */ - BGE_PROXY_PTR(self->m_proxy) = ptr; - Py_INCREF(self->m_proxy); /* we own one, thos ones fore the return */ - return self->m_proxy; -} - -PyObject *PyObjectPlus::NewProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr, bool py_owns) -{ - if (!self) - { - // in case of proxy without reference to game object - PyObject *proxy = reinterpret_cast<PyObject *>PyObject_NEW( PyObjectPlus_Proxy, tp); - BGE_PROXY_PYREF(proxy) = false; - BGE_PROXY_PYOWNS(proxy) = py_owns; - BGE_PROXY_REF(proxy) = NULL; - BGE_PROXY_PTR(proxy) = ptr; -#ifdef USE_WEAKREFS - BGE_PROXY_WKREF(proxy) = NULL; -#endif - return proxy; - } - if (self->m_proxy) - { - if (py_owns) - { /* Free */ - BGE_PROXY_REF(self->m_proxy) = NULL; - Py_DECREF(self->m_proxy); - self->m_proxy= NULL; - } - else { - Py_INCREF(self->m_proxy); - return self->m_proxy; - } - - } - - GetProxyPlus_Ext(self, tp, ptr); - if (py_owns) { - BGE_PROXY_PYOWNS(self->m_proxy) = py_owns; - Py_DECREF(self->m_proxy); /* could avoid thrashing here but for now its ok */ - } - return self->m_proxy; -} - -PyObject *PyUnicode_From_STR_String(const STR_String& str) -{ - return PyUnicode_FromStringAndSize(str.ReadPtr(), str.Length()); -} - -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// -/* deprecation warning management */ - -bool PyObjectPlus::m_ignore_deprecation_warnings(false); -void PyObjectPlus::SetDeprecationWarnings(bool ignoreDeprecationWarnings) -{ - m_ignore_deprecation_warnings = ignoreDeprecationWarnings; -} - -void PyObjectPlus::ShowDeprecationWarning_func(const char *old_way, const char *new_way) -{ - printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way); - PyC_LineSpit(); -} - -void PyObjectPlus::ClearDeprecationWarning() -{ - WarnLink *wlink_next; - WarnLink *wlink = GetDeprecationWarningLinkFirst(); - - while (wlink) { - wlink->warn_done= false; /* no need to NULL the link, its cleared before adding to the list next time round */ - wlink_next= reinterpret_cast<WarnLink *>(wlink->link); - wlink->link= NULL; - wlink= wlink_next; - } - NullDeprecationWarning(); -} - -static WarnLink *m_base_wlink_first = NULL; -static WarnLink *m_base_wlink_last = NULL; - -WarnLink* PyObjectPlus::GetDeprecationWarningLinkFirst(void) {return m_base_wlink_first;} -WarnLink* PyObjectPlus::GetDeprecationWarningLinkLast(void) {return m_base_wlink_last;} -void PyObjectPlus::SetDeprecationWarningFirst(WarnLink* wlink) {m_base_wlink_first= wlink;} -void PyObjectPlus::SetDeprecationWarningLinkLast(WarnLink* wlink) {m_base_wlink_last= wlink;} -void PyObjectPlus::NullDeprecationWarning() {m_base_wlink_first= m_base_wlink_last= NULL;} - -#endif // WITH_PYTHON diff --git a/source/gameengine/Expressions/intern/PythonCallBack.cpp b/source/gameengine/Expressions/intern/PythonCallBack.cpp deleted file mode 100644 index 3fb84569eca..00000000000 --- a/source/gameengine/Expressions/intern/PythonCallBack.cpp +++ /dev/null @@ -1,119 +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. - * - * 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/intern/StringValue.cpp b/source/gameengine/Expressions/intern/StringValue.cpp deleted file mode 100644 index ddf61dc441c..00000000000 --- a/source/gameengine/Expressions/intern/StringValue.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/** \file gameengine/Expressions/StringValue.cpp - * \ingroup expressions - */ -// StringValue.cpp: implementation of the CStringValue class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#include "EXP_StringValue.h" -#include "EXP_BoolValue.h" -#include "EXP_ErrorValue.h" -#include "EXP_VoidValue.h" - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -/** - * pre: false - * effect: constructs a new CStringValue - */ -CStringValue::CStringValue() -{ - m_strString = "[Illegal String constructor call]"; -} - -/** - * pre: - * effect: constructs a new CStringValue containing text txt - */ -CStringValue::CStringValue(const char *txt,const char *name,AllocationTYPE alloctype) -{ - m_strString = txt; - SetName(name); - - if (alloctype==CValue::STACKVALUE) - { - CValue::DisableRefCount(); - - } - - -} - - -/** - * pre: - * ret: a new object containing the result of applying operator op to this - * object and val - */ -CValue* CStringValue::Calc(VALUE_OPERATOR op, CValue *val) -{ - //return val->CalrcString(op, this); - return val->CalcFinal(VALUE_STRING_TYPE, op, this); -} - -/** - * pre: the type of val is dtype - * ret: a new object containing the result of applying operator op to val and - * this object - */ -CValue* CStringValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -{ - CValue *ret; - - if (op == VALUE_ADD_OPERATOR) { - if (dtype == VALUE_ERROR_TYPE) - ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); - else - ret = new CStringValue(val->GetText() + GetText(),""); - } - else { - if (dtype == VALUE_STRING_TYPE || dtype == VALUE_EMPTY_TYPE) { - switch (op) { - case VALUE_EQL_OPERATOR: - ret = new CBoolValue(val->GetText() == GetText()); - break; - case VALUE_NEQ_OPERATOR: - ret = new CBoolValue(val->GetText() != GetText()); - break; - case VALUE_GRE_OPERATOR: - ret = new CBoolValue(val->GetText() > GetText()); - break; - case VALUE_LES_OPERATOR: - ret = new CBoolValue(val->GetText() < GetText()); - break; - case VALUE_GEQ_OPERATOR: - ret = new CBoolValue(val->GetText() >= GetText()); - break; - case VALUE_LEQ_OPERATOR: - ret = new CBoolValue(val->GetText() <= GetText()); - break; - default: - ret = new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]"); - break; - } - } - else { - ret = new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]"); - } - } - return ret; -} - - - -double CStringValue::GetNumber() -{ - return -1; -} - - - -int CStringValue::GetValueType() -{ - return VALUE_STRING_TYPE; -} - - - -const STR_String & CStringValue::GetText() -{ - return m_strString; -} - -bool CStringValue::IsEqual(const STR_String & other) -{ - return (m_strString == other); -} - -CValue* CStringValue::GetReplica() -{ - CStringValue* replica = new CStringValue(*this); - replica->ProcessReplica(); - return replica; -}; - - diff --git a/source/gameengine/Expressions/intern/Value.cpp b/source/gameengine/Expressions/intern/Value.cpp deleted file mode 100644 index f8796a76e76..00000000000 --- a/source/gameengine/Expressions/intern/Value.cpp +++ /dev/null @@ -1,672 +0,0 @@ -/** \file gameengine/Expressions/Value.cpp - * \ingroup expressions - */ -// Value.cpp: implementation of the CValue class. -// developed at Eindhoven University of Technology, 1997 -// by the OOPS team -////////////////////////////////////////////////////////////////////// -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ -#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 -////////////////////////////////////////////////////////////////////// - -double CValue::m_sZeroVec[3] = {0.0,0.0,0.0}; - -#ifdef WITH_PYTHON - -PyTypeObject CValue::Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "CValue", - sizeof(PyObjectPlus_Proxy), - 0, - py_base_dealloc, - 0, - 0, - 0, - 0, - py_base_repr, - 0, - 0,0,0,0,0, - NULL, - NULL, - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - 0,0,0,0,0,0,0, - Methods, - 0, - 0, - &PyObjectPlus::Type, - 0,0,0,0,0,0, - py_base_new -}; - -PyMethodDef CValue::Methods[] = { - {NULL,NULL} //Sentinel -}; -#endif // WITH_PYTHON - - -/*#define CVALUE_DEBUG*/ -#ifdef CVALUE_DEBUG -int gRefCount; -struct SmartCValueRef -{ - CValue *m_ref; - int m_count; - SmartCValueRef(CValue *ref) - { - m_ref = ref; - m_count = gRefCount++; - } -}; - -#include <vector> - -std::vector<SmartCValueRef> gRefList; -#endif - -#ifdef DEBUG -//int gRefCountValue; -#endif - -CValue::CValue() - : PyObjectPlus(), - -m_pNamedPropertyArray(NULL), -m_refcount(1) -/* -pre: false -effect: constucts a CValue -*/ -{ - //debug(gRefCountValue++) // debugging -#ifdef DEBUG - //gRefCountValue++; -#ifdef CVALUE_DEBUG - gRefList.push_back(SmartCValueRef(this)); -#endif -#endif -} - - - -CValue::~CValue() -/* -pre: -effect: deletes the object -*/ -{ - ClearProperties(); - - assertd (m_refcount==0); -#ifdef CVALUE_DEBUG - std::vector<SmartCValueRef>::iterator it; - for (it=gRefList.begin(); it!=gRefList.end(); it++) - { - if (it->m_ref == this) - { - *it = gRefList.back(); - gRefList.pop_back(); - break; - } - } -#endif -} - - -/* UNUSED */ -#if 0 -#define VALUE_SUB(val1, val2) (val1)->Calc(VALUE_SUB_OPERATOR, val2) -#define VALUE_MUL(val1, val2) (val1)->Calc(VALUE_MUL_OPERATOR, val2) -#define VALUE_DIV(val1, val2) (val1)->Calc(VALUE_DIV_OPERATOR, val2) -#define VALUE_NEG(val1) (val1)->Calc(VALUE_NEG_OPERATOR, val1) -#define VALUE_POS(val1) (val1)->Calc(VALUE_POS_OPERATOR, val1) -#endif - -STR_String CValue::op2str(VALUE_OPERATOR op) -{ - //pre: - //ret: the stringrepresentation of operator op - - STR_String opmsg; - switch (op) { - case VALUE_MOD_OPERATOR: - opmsg = " % "; - break; - case VALUE_ADD_OPERATOR: - opmsg = " + "; - break; - case VALUE_SUB_OPERATOR: - opmsg = " - "; - break; - case VALUE_MUL_OPERATOR: - opmsg = " * "; - break; - case VALUE_DIV_OPERATOR: - opmsg = " / "; - break; - case VALUE_NEG_OPERATOR: - opmsg = " -"; - break; - case VALUE_POS_OPERATOR: - opmsg = " +"; - break; - case VALUE_AND_OPERATOR: - opmsg = " & "; - break; - case VALUE_OR_OPERATOR: - opmsg = " | "; - break; - case VALUE_EQL_OPERATOR: - opmsg = " = "; - break; - case VALUE_NEQ_OPERATOR: - opmsg = " != "; - break; - case VALUE_NOT_OPERATOR: - opmsg = " !"; - break; - default: - opmsg="Error in Errorhandling routine."; - // AfxMessageBox("Invalid operator"); - break; - } - return opmsg; -} - - - - - -//--------------------------------------------------------------------------------------------------------------------- -// Property Management -//--------------------------------------------------------------------------------------------------------------------- - - - -// -// Set property <ioProperty>, overwrites and releases a previous property with the same name if needed -// -void CValue::SetProperty(const STR_String & name,CValue* ioProperty) -{ - if (ioProperty==NULL) - { // Check if somebody is setting an empty property - trace("Warning:trying to set empty property!"); - return; - } - - if (m_pNamedPropertyArray) - { // Try to replace property (if so -> exit as soon as we replaced it) - CValue* oldval = (*m_pNamedPropertyArray)[name]; - if (oldval) - oldval->Release(); - } - else { // Make sure we have a property array - m_pNamedPropertyArray = new std::map<STR_String,CValue *>; - } - - // Add property at end of array - (*m_pNamedPropertyArray)[name] = ioProperty->AddRef();//->Add(ioProperty); -} - -void CValue::SetProperty(const char* name,CValue* ioProperty) -{ - if (ioProperty==NULL) - { // Check if somebody is setting an empty property - trace("Warning:trying to set empty property!"); - return; - } - - if (m_pNamedPropertyArray) - { // Try to replace property (if so -> exit as soon as we replaced it) - CValue* oldval = (*m_pNamedPropertyArray)[name]; - if (oldval) - oldval->Release(); - } - else { // Make sure we have a property array - m_pNamedPropertyArray = new std::map<STR_String,CValue *>; - } - - // Add property at end of array - (*m_pNamedPropertyArray)[name] = ioProperty->AddRef();//->Add(ioProperty); -} - -// -// Get pointer to a property with name <inName>, returns NULL if there is no property named <inName> -// -CValue* CValue::GetProperty(const STR_String & inName) -{ - if (m_pNamedPropertyArray) { - std::map<STR_String,CValue*>::iterator it = m_pNamedPropertyArray->find(inName); - if (it != m_pNamedPropertyArray->end()) - return (*it).second; - } - return NULL; -} - -CValue* CValue::GetProperty(const char *inName) -{ - if (m_pNamedPropertyArray) { - std::map<STR_String,CValue*>::iterator it = m_pNamedPropertyArray->find(inName); - if (it != m_pNamedPropertyArray->end()) - return (*it).second; - } - return NULL; -} - -// -// Get text description of property with name <inName>, returns an empty string if there is no property named <inName> -// -const STR_String& CValue::GetPropertyText(const STR_String & inName) -{ - const static STR_String sEmpty(""); - - CValue *property = GetProperty(inName); - if (property) - return property->GetText(); - else - return sEmpty; -} - -float CValue::GetPropertyNumber(const STR_String& inName,float defnumber) -{ - CValue *property = GetProperty(inName); - if (property) - return property->GetNumber(); - else - return defnumber; -} - - - -// -// Remove the property named <inName>, returns true if the property was succesfully removed, false if property was not found or could not be removed -// -bool CValue::RemoveProperty(const char *inName) -{ - // Check if there are properties at all which can be removed - if (m_pNamedPropertyArray) - { - std::map<STR_String,CValue*>::iterator it = m_pNamedPropertyArray->find(inName); - if (it != m_pNamedPropertyArray->end()) - { - ((*it).second)->Release(); - m_pNamedPropertyArray->erase(it); - return true; - } - } - - return false; -} - -// -// Get Property Names -// -vector<STR_String> CValue::GetPropertyNames() -{ - vector<STR_String> result; - if (!m_pNamedPropertyArray) return result; - result.reserve(m_pNamedPropertyArray->size()); - - std::map<STR_String,CValue*>::iterator it; - for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) - { - result.push_back((*it).first); - } - return result; -} - -// -// Clear all properties -// -void CValue::ClearProperties() -{ - // Check if we have any properties - if (m_pNamedPropertyArray == NULL) - return; - - // Remove all properties - std::map<STR_String,CValue*>::iterator it; - for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++) - { - CValue* tmpval = (*it).second; - //STR_String name = (*it).first; - tmpval->Release(); - } - - // Delete property array - delete m_pNamedPropertyArray; - m_pNamedPropertyArray=NULL; -} - - - -// -// Set all properties' modified flag to <inModified> -// -void CValue::SetPropertiesModified(bool inModified) -{ - if (!m_pNamedPropertyArray) return; - std::map<STR_String,CValue*>::iterator it; - - for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++) - ((*it).second)->SetModified(inModified); -} - - - -// -// Check if any of the properties in this value have been modified -// -bool CValue::IsAnyPropertyModified() -{ - if (!m_pNamedPropertyArray) return false; - std::map<STR_String,CValue*>::iterator it; - - for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++) - if (((*it).second)->IsModified()) - return true; - - return false; -} - - - -// -// Get property number <inIndex> -// -CValue* CValue::GetProperty(int inIndex) -{ - - int count=0; - CValue* result = NULL; - - if (m_pNamedPropertyArray) - { - std::map<STR_String,CValue*>::iterator it; - for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) - { - if (count++ == inIndex) - { - result = (*it).second; - break; - } - } - - } - return result; -} - - - -// -// Get the amount of properties assiocated with this value -// -int CValue::GetPropertyCount() -{ - if (m_pNamedPropertyArray) - return m_pNamedPropertyArray->size(); - else - return 0; -} - - -double* CValue::GetVector3(bool bGetTransformedVec) -{ - assertd(false); // don't get vector from me - return m_sZeroVec;//::sZero; -} - - -/*--------------------------------------------------------------------------------------------------------------------- - Reference Counting ----------------------------------------------------------------------------------------------------------------------*/ - - - -// -// Release a reference to this value (when reference count reaches 0, the value is removed from the heap) -// - - - -// -// Disable reference counting for this value -// -void CValue::DisableRefCount() -{ - assertd(m_refcount == 1); - m_refcount--; - - //debug(gRefCountValue--); -#ifdef DEBUG - //gRefCountValue--; -#endif - m_ValFlags.RefCountDisabled=true; -} - - - -void CValue::ProcessReplica() /* was AddDataToReplica in 2.48 */ -{ - m_refcount = 1; - -#ifdef DEBUG - //gRefCountValue++; -#endif - PyObjectPlus::ProcessReplica(); - - m_ValFlags.RefCountDisabled = false; - - /* copy all props */ - if (m_pNamedPropertyArray) - { - std::map<STR_String,CValue*> *pOldArray = m_pNamedPropertyArray; - m_pNamedPropertyArray=NULL; - std::map<STR_String,CValue*>::iterator it; - for (it= pOldArray->begin(); (it != pOldArray->end()); it++) - { - CValue *val = (*it).second->GetReplica(); - SetProperty((*it).first,val); - val->Release(); - } - } -} - - - -int CValue::GetValueType() -{ - return VALUE_NO_TYPE; -} - - - -CValue* CValue::FindIdentifier(const STR_String& identifiername) -{ - - CValue* result = NULL; - - int pos = 0; - // if a dot exists, explode the name into pieces to get the subcontext - if ((pos=identifiername.Find('.'))>=0) - { - const STR_String rightstring = identifiername.Right(identifiername.Length() -1 - pos); - const STR_String leftstring = identifiername.Left(pos); - CValue* tempresult = GetProperty(leftstring); - if (tempresult) - { - result=tempresult->FindIdentifier(rightstring); - } - } else - { - result = GetProperty(identifiername); - if (result) - return result->AddRef(); - } - if (!result) - { - // warning here !!! - result = new CErrorValue(identifiername+" not found"); - } - return result; -} - -#ifdef WITH_PYTHON - -PyAttributeDef CValue::Attributes[] = { - KX_PYATTRIBUTE_RO_FUNCTION("name", CValue, pyattr_get_name), - { NULL } //Sentinel -}; - -PyObject *CValue::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) -{ - CValue * self = static_cast<CValue *> (self_v); - return PyUnicode_From_STR_String(self->GetName()); -} - -/** - * There are 2 reasons this could return NULL - * - unsupported type. - * - error converting (overflow). - * - * \param do_type_exception Use to skip raising an exception for unknown types. - */ -CValue *CValue::ConvertPythonToValue(PyObject *pyobj, const bool do_type_exception, const char *error_prefix) -{ - - CValue *vallie; - /* refcounting is broking here! - this crashes anyway, just store a python list for KX_GameObject */ -#if 0 - if (PyList_Check(pyobj)) - { - CListValue* listval = new CListValue(); - bool error = false; - - Py_ssize_t i; - Py_ssize_t numitems = PyList_GET_SIZE(pyobj); - for (i=0;i<numitems;i++) - { - PyObject *listitem = PyList_GET_ITEM(pyobj,i); /* borrowed ref */ - CValue* listitemval = ConvertPythonToValue(listitem, error_prefix); - if (listitemval) - { - listval->Add(listitemval); - } else - { - error = true; - } - } - if (!error) - { - // jippie! could be converted - vallie = listval; - } else - { - // list could not be converted... bad luck - listval->Release(); - } - - } else -#endif - /* note: Boolean check should go before Int check [#34677] */ - if (PyBool_Check(pyobj)) - { - vallie = new CBoolValue( (bool)PyLong_AsLongLong(pyobj) ); - } else - if (PyFloat_Check(pyobj)) - { - const double tval = PyFloat_AsDouble(pyobj); - if (tval > (double)FLT_MAX || tval < (double)-FLT_MAX) { - PyErr_Format(PyExc_OverflowError, "%soverflow converting from float, out of internal range", error_prefix); - vallie = NULL; - } - else { - vallie = new CFloatValue((float)tval); - } - } else - if (PyLong_Check(pyobj)) - { - vallie = new CIntValue( (cInt)PyLong_AsLongLong(pyobj) ); - } else - if (PyUnicode_Check(pyobj)) - { - vallie = new CStringValue(_PyUnicode_AsString(pyobj),""); - } else - if (PyObject_TypeCheck(pyobj, &CValue::Type)) /* Note, don't let these get assigned to GameObject props, must check elsewhere */ - { - vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef(); - } - else { - if (do_type_exception) { - /* return an error value from the caller */ - PyErr_Format(PyExc_TypeError, "%scould convert python value to a game engine property", error_prefix); - } - vallie = NULL; - } - return vallie; - -} - -PyObject *CValue::ConvertKeysToPython(void) -{ - if (m_pNamedPropertyArray) - { - PyObject *pylist= PyList_New(m_pNamedPropertyArray->size()); - Py_ssize_t i= 0; - - std::map<STR_String,CValue*>::iterator it; - for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++) - { - PyList_SET_ITEM(pylist, i++, PyUnicode_From_STR_String((*it).first)); - } - - return pylist; - } - else { - return PyList_New(0); - } -} - -#endif // WITH_PYTHON - - -/////////////////////////////////////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////////////////////////////////// -/* These implementations were moved out of the header */ - -void CValue::SetOwnerExpression(class CExpression* expr) -{ - /* intentionally empty */ -} - -void CValue::SetColorOperator(VALUE_OPERATOR op) -{ - /* intentionally empty */ -} -void CValue::SetValue(CValue* newval) -{ - // no one should get here - assertd(newval->GetNumber() == 10121969); -} diff --git a/source/gameengine/Expressions/intern/VectorValue.cpp b/source/gameengine/Expressions/intern/VectorValue.cpp deleted file mode 100644 index a3d44116317..00000000000 --- a/source/gameengine/Expressions/intern/VectorValue.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/** \file gameengine/Expressions/VectorValue.cpp - * \ingroup expressions - */ -// VectorValue.cpp: implementation of the CVectorValue class. -/* - * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org> - * - * Permission to use, copy, modify, distribute and sell this software - * and its documentation for any purpose is hereby granted without fee, - * provided that the above copyright notice appear in all copies and - * that both that copyright notice and this permission notice appear - * in supporting documentation. Erwin Coumans makes no - * representations about the suitability of this software for any - * purpose. It is provided "as is" without express or implied warranty. - * - */ - -#ifdef _MSC_VER -# pragma warning (disable:4786) -#endif - -#include "EXP_Value.h" -#include "EXP_VectorValue.h" -#include "EXP_ErrorValue.h" -//#include "MatrixValue.h" -#include "EXP_VoidValue.h" -#include "EXP_StringValue.h" -//#include "FactoryManager.h" - - - -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - -CVectorValue::CVectorValue(float x,float y,float z, AllocationTYPE alloctype) -{ - SetCustomFlag1(false);//FancyOutput=false; - - if (alloctype == STACKVALUE) - { - CValue::DisableRefCount(); - }; - - m_vec[KX_X] = m_transformedvec[KX_X] = x; - m_vec[KX_Y] = m_transformedvec[KX_Y] = y; - m_vec[KX_Z] = m_transformedvec[KX_Z] = z; - -} -CVectorValue::CVectorValue(double vec[3], const char *name,AllocationTYPE alloctype) -{ - - SetCustomFlag1(false);//FancyOutput=false; - - m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X]; - m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y]; - m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z]; - - if (alloctype == STACKVALUE) - { - CValue::DisableRefCount(); - - } - - SetName(name); -} - -CVectorValue::CVectorValue(double vec[3], AllocationTYPE alloctype) -{ - - SetCustomFlag1(false);//FancyOutput=false; - - m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X]; - m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y]; - m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z]; - - if (alloctype == STACKVALUE) - { - CValue::DisableRefCount(); - - } - - -} -CVectorValue::~CVectorValue() -{ - -} - -/** - * pre: the type of val is dtype - * ret: a new object containing the result of applying operator op to val and - * this object - */ -CValue* CVectorValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) -{ - CValue *ret = NULL; - - switch (op) { - case VALUE_ADD_OPERATOR: - { - switch (dtype) - { - case VALUE_EMPTY_TYPE: - case VALUE_VECTOR_TYPE: - { - ret = new CVectorValue( - val->GetVector3()[KX_X] + GetVector3()[KX_X], - val->GetVector3()[KX_Y] + GetVector3()[KX_Y], - val->GetVector3()[KX_Z] + GetVector3()[KX_Z], - CValue::HEAPVALUE); - ret->SetName(GetName()); - break; - } - - default: - ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); - } - break; - } - case VALUE_MUL_OPERATOR: - { - switch (dtype) - { - - case VALUE_EMPTY_TYPE: - case VALUE_VECTOR_TYPE: - { - //MT_Vector3 supports 'scaling' by another vector, instead of using general transform, Gino? - //ret = new CVectorValue(val->GetVector3().Scaled(GetVector3()),GetName()); - break; - } - case VALUE_FLOAT_TYPE: - { - ret = new CVectorValue( - val->GetVector3()[KX_X] * GetVector3()[KX_X], - val->GetVector3()[KX_Y] * GetVector3()[KX_Y], - val->GetVector3()[KX_Z] * GetVector3()[KX_Z], - CValue::HEAPVALUE); - ret->SetName(GetName()); - break; - } - - default: - ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); - } - break; - - } - - default: - ret = new CErrorValue(val->GetText() + op2str(op) + GetText()); - } - - - return ret; -} - -double CVectorValue::GetNumber() -{ - return m_vec[KX_X]; -} - - - -int CVectorValue::GetValueType() -{ - return VALUE_VECTOR_TYPE; -} - - - -double* CVectorValue::GetVector3(bool bGetTransformedVec) -{ - if (bGetTransformedVec) - return m_transformedvec; - // else - return m_vec; -} - - - - - -void CVectorValue::SetVector(double newvec[]) -{ - m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X]; - m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y]; - m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z]; - - SetModified(true); -} - - -void CVectorValue::SetValue(CValue *newval) -{ - - double* newvec = ((CVectorValue*)newval)->GetVector3(); - m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X]; - m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y]; - m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z]; - - SetModified(true); -} - -static const STR_String gstrVectorStr=STR_String(); -const STR_String & CVectorValue::GetText() -{ - assertd(false); - return gstrVectorStr; -} - -CValue* CVectorValue::GetReplica() -{ - CVectorValue* replica = new CVectorValue(*this); - replica->ProcessReplica(); - return replica; -}; - -#if 0 -void CVectorValue::Transform(rcMatrix4x4 mat) -{ - m_transformedvec = mat*m_vec; -} -#endif |