| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * $Id$ | 
					
						
							| 
									
										
										
										
											2008-04-16 22:40:48 +00:00
										 |  |  |  * ***** BEGIN GPL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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 | 
					
						
							| 
									
										
										
										
											2008-04-16 22:40:48 +00:00
										 |  |  |  * of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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, | 
					
						
							| 
									
										
										
										
											2010-02-12 13:34:04 +00:00
										 |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2008-04-16 22:40:48 +00:00
										 |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 13:32:11 +00:00
										 |  |  | /** \file gameengine/GameLogic/SCA_ILogicBrick.cpp
 | 
					
						
							|  |  |  |  *  \ingroup gamelogic | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-27 00:02:25 +00:00
										 |  |  | #include <stddef.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | #include "SCA_ILogicBrick.h"
 | 
					
						
							| 
									
										
										
										
											2008-09-06 14:13:31 +00:00
										 |  |  | #include "PyObjectPlus.h"
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | SCA_LogicManager* SCA_ILogicBrick::m_sCurrentLogicManager = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-28 11:22:26 +00:00
										 |  |  | SCA_ILogicBrick::SCA_ILogicBrick(SCA_IObject* gameobj) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	: | 
					
						
							| 
									
										
										
										
											2009-06-28 11:22:26 +00:00
										 |  |  | 	CValue(), | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	m_gameobj(gameobj), | 
					
						
							|  |  |  | 	m_Execute_Priority(0), | 
					
						
							|  |  |  | 	m_Execute_Ueber_Priority(0), | 
					
						
							|  |  |  | 	m_bActive(false), | 
					
						
							|  |  |  | 	m_eventval(0) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_text = "KX_LogicBrick"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SCA_ILogicBrick::~SCA_ILogicBrick() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	RemoveEvent(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SCA_ILogicBrick::SetExecutePriority(int execute_Priority) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_Execute_Priority = execute_Priority; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SCA_ILogicBrick::SetUeberExecutePriority(int execute_Priority) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_Execute_Ueber_Priority = execute_Priority; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SCA_ILogicBrick::ReParent(SCA_IObject* parent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	m_gameobj = parent; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-19 07:45:19 +00:00
										 |  |  | void SCA_ILogicBrick::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// nothing to do
 | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | CValue* SCA_ILogicBrick::Calc(VALUE_OPERATOR op, CValue *val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CValue* temp = new CBoolValue(false,""); | 
					
						
							|  |  |  | 	CValue* result = temp->Calc(op,val); | 
					
						
							|  |  |  | 	temp->Release(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | }  | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CValue* SCA_ILogicBrick::CalcFinal(VALUE_DATA_TYPE dtype, | 
					
						
							|  |  |  | 								   VALUE_OPERATOR op, | 
					
						
							|  |  |  | 								   CValue *val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// same as bool implementation, so...
 | 
					
						
							|  |  |  | 	CValue* temp = new CBoolValue(false,""); | 
					
						
							|  |  |  | 	CValue* result = temp->CalcFinal(dtype,op,val); | 
					
						
							|  |  |  | 	temp->Release(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const STR_String& SCA_ILogicBrick::GetText() | 
					
						
							|  |  |  | {  | 
					
						
							|  |  |  | 	if (m_name.Length()) | 
					
						
							|  |  |  | 		return m_name; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return m_text; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | double SCA_ILogicBrick::GetNumber() | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | STR_String& SCA_ILogicBrick::GetName() | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return m_name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | void SCA_ILogicBrick::SetName(const char *name) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	m_name = name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool SCA_ILogicBrick::LessComparedTo(SCA_ILogicBrick* other) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (this->m_Execute_Ueber_Priority < other->m_Execute_Ueber_Priority)  | 
					
						
							|  |  |  | 		|| ((this->m_Execute_Ueber_Priority == other->m_Execute_Ueber_Priority) &&  | 
					
						
							|  |  |  | 		(this->m_Execute_Priority < other->m_Execute_Priority)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SCA_ILogicBrick::RegisterEvent(CValue* eventval) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_eventval) | 
					
						
							|  |  |  | 		m_eventval->Release(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	m_eventval = eventval->AddRef(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SCA_ILogicBrick::RemoveEvent() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_eventval) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_eventval->Release(); | 
					
						
							|  |  |  | 		m_eventval = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CValue* SCA_ILogicBrick::GetEvent() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (m_eventval) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		return m_eventval->AddRef(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #ifdef WITH_PYTHON
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* python stuff */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyTypeObject SCA_ILogicBrick::Type = { | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	PyVarObject_HEAD_INIT(NULL, 0) | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	"SCA_ILogicBrick", | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	sizeof(PyObjectPlus_Proxy), | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0, | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	py_base_dealloc, | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	py_base_repr, | 
					
						
							| 
									
										
										
										
											2009-06-29 12:06:46 +00:00
										 |  |  | 	0,0,0,0,0,0,0,0,0, | 
					
						
							| 
									
										
										
										
											2009-06-28 11:22:26 +00:00
										 |  |  | 	Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | 
					
						
							|  |  |  | 	0,0,0,0,0,0,0, | 
					
						
							|  |  |  | 	Methods, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							| 
									
										
										
										
											2009-06-29 12:06:46 +00:00
										 |  |  | 	&CValue::Type, | 
					
						
							|  |  |  | 	0,0,0,0,0,0, | 
					
						
							|  |  |  | 	py_base_new | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyMethodDef SCA_ILogicBrick::Methods[] = { | 
					
						
							|  |  |  |   {NULL,NULL} //Sentinel
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-02 22:09:57 +00:00
										 |  |  | PyAttributeDef SCA_ILogicBrick::Attributes[] = { | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | 	KX_PYATTRIBUTE_RO_FUNCTION("owner",	SCA_ILogicBrick, pyattr_get_owner), | 
					
						
							| 
									
										
										
										
											2009-06-08 20:08:19 +00:00
										 |  |  | 	KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Priority), | 
					
						
							|  |  |  | 	KX_PYATTRIBUTE_STRING_RO("name", SCA_ILogicBrick, m_name), | 
					
						
							| 
									
										
										
										
											2009-01-02 22:09:57 +00:00
										 |  |  | 	{NULL} //Sentinel
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-02 17:43:56 +00:00
										 |  |  | int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (attrdef->m_type != KX_PYATTRIBUTE_TYPE_STRING || attrdef->m_length != 1) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_AttributeError, "inconsistent check function for attribute type, report to blender.org"); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	SCA_ILogicBrick* brick = reinterpret_cast<SCA_ILogicBrick*>(self); | 
					
						
							|  |  |  | 	STR_String* var = reinterpret_cast<STR_String*>((char*)self+attrdef->m_offset); | 
					
						
							|  |  |  | 	CValue* prop = brick->GetParent()->FindIdentifier(*var); | 
					
						
							|  |  |  | 	bool error = prop->IsError(); | 
					
						
							|  |  |  | 	prop->Release(); | 
					
						
							|  |  |  | 	if (error) { | 
					
						
							|  |  |  | 		PyErr_SetString(PyExc_ValueError, "string does not correspond to a property"); | 
					
						
							|  |  |  | 		return 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-20 15:06:46 +00:00
										 |  |  | /*Attribute functions */ | 
					
						
							|  |  |  | PyObject* SCA_ILogicBrick::pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SCA_ILogicBrick* self= static_cast<SCA_ILogicBrick*>(self_v); | 
					
						
							|  |  |  | 	CValue* parent = self->GetParent(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if (parent) | 
					
						
							|  |  |  | 		return parent->GetProxy(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Py_RETURN_NONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* Conversions for making life better. */ | 
					
						
							|  |  |  | bool SCA_ILogicBrick::PyArgToBool(int boolArg) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-06-26 09:15:41 +00:00
										 |  |  | 	if (boolArg) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 		return true; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyObject* SCA_ILogicBrick::BoolToPyArg(bool boolarg) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2009-06-29 02:25:54 +00:00
										 |  |  | 	return PyLong_FromSsize_t(boolarg? KX_TRUE: KX_FALSE);	 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2009-09-29 21:42:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-31 04:11:39 +00:00
										 |  |  | #endif // WITH_PYTHON
 |