Blender  V2.59
KX_ConvertProperties.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: KX_ConvertProperties.cpp 35167 2011-02-25 13:30:41Z jesterking $
00003  * ***** BEGIN GPL LICENSE BLOCK *****
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  *
00019  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00020  * All rights reserved.
00021  *
00022  * The Original Code is: all of this file.
00023  *
00024  * Contributor(s): none yet.
00025  *
00026  * ***** END GPL LICENSE BLOCK *****
00027  */
00028 
00034 #include "KX_ConvertProperties.h"
00035 
00036 
00037 #include "DNA_object_types.h"
00038 #include "DNA_property_types.h"
00039 /* end of blender include block */
00040 
00041 
00042 #include "Value.h"
00043 #include "VectorValue.h"
00044 #include "BoolValue.h"
00045 #include "StringValue.h"
00046 #include "FloatValue.h"
00047 #include "KX_GameObject.h"
00048 #include "IntValue.h"
00049 #include "SCA_TimeEventManager.h"
00050 #include "SCA_IScene.h"
00051 
00052 /* This little block needed for linking to Blender... */
00053 #ifdef WIN32
00054 #include "BLI_winstuff.h"
00055 #endif
00056 
00057 void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
00058 {
00059         
00060         bProperty* prop = (bProperty*)object->prop.first;
00061         CValue* propval;        
00062         bool show_debug_info;
00063         while(prop)
00064         {
00065         
00066                 propval = NULL;
00067                 show_debug_info = bool (prop->flag & PROP_DEBUG);
00068 
00069                 switch(prop->type) {
00070                         case GPROP_BOOL:
00071                         {
00072                                 propval = new CBoolValue((bool)(prop->data != 0));
00073                                 gameobj->SetProperty(prop->name,propval);
00074                                 //promp->poin= &prop->data;
00075                                 break;
00076                         }
00077                         case GPROP_INT:
00078                         {
00079                                 propval = new CIntValue((int)prop->data);
00080                                 gameobj->SetProperty(prop->name,propval);
00081                                 break;
00082                         }
00083                         case GPROP_FLOAT:
00084                         {
00085                                 //prop->poin= &prop->data;
00086                                 float floatprop = *((float*)&prop->data);
00087                                 propval = new CFloatValue(floatprop);
00088                                 gameobj->SetProperty(prop->name,propval);
00089                         }
00090                         break;
00091                         case GPROP_STRING:
00092                         {
00093                                 //prop->poin= callocN(MAX_PROPSTRING, "property string");
00094                                 propval = new CStringValue((char*)prop->poin,"");
00095                                 gameobj->SetProperty(prop->name,propval);
00096                                 break;
00097                         }
00098                         case GPROP_TIME:
00099                         {
00100                                 float floatprop = *((float*)&prop->data);
00101 
00102                                 CValue* timeval = new CFloatValue(floatprop);
00103                                 // set a subproperty called 'timer' so that 
00104                                 // we can register the replica of this property 
00105                                 // at the time a game object is replicated (AddObjectActuator triggers this)
00106                                 CValue *bval = new CBoolValue(true);
00107                                 timeval->SetProperty("timer",bval);
00108                                 bval->Release();
00109                                 if (isInActiveLayer)
00110                                 {
00111                                         timemgr->AddTimeProperty(timeval);
00112                                 }
00113                                 
00114                                 propval = timeval;
00115                                 gameobj->SetProperty(prop->name,timeval);
00116 
00117                         }
00118                         default:
00119                         {
00120                                 // todo make an assert etc.
00121                         }
00122                 }
00123                 
00124                 if (propval)
00125                 {
00126                         if (show_debug_info)
00127                         {
00128                                 scene->AddDebugProperty(gameobj,STR_String(prop->name));
00129                         }
00130                         // done with propval, release it
00131                         propval->Release();
00132                 }
00133                 
00134 #ifdef WITH_PYTHON
00135                 /* Warn if we double up on attributes, this isnt quite right since it wont find inherited attributes however there arnt many */
00136                 for(PyAttributeDef *attrdef = KX_GameObject::Attributes; attrdef->m_name; attrdef++) {
00137                         if(strcmp(prop->name, attrdef->m_name)==0) {
00138                                 printf("Warning! user defined property name \"%s\" is also a python attribute for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name);
00139                                 break;
00140                         }
00141                 }
00142                 for(PyMethodDef *methdef = KX_GameObject::Methods; methdef->ml_name; methdef++) {
00143                         if(strcmp(prop->name, methdef->ml_name)==0) {
00144                                 printf("Warning! user defined property name \"%s\" is also a python method for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name);
00145                                 break;
00146                         }
00147                 }
00148                 /* end warning check */
00149 #endif // WITH_PYTHON
00150 
00151                 prop = prop->next;
00152         }
00153         // check if state needs to be debugged
00154         if (object->scaflag & OB_DEBUGSTATE)
00155         {
00156                 //  reserve name for object state
00157                 scene->AddDebugProperty(gameobj,STR_String("__state__"));
00158         }
00159 }