doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / gameengine / Converter / KX_ConvertProperties.cpp
1 /*
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include "KX_ConvertProperties.h"
30
31
32 #include "DNA_object_types.h"
33 #include "DNA_property_types.h"
34 /* end of blender include block */
35
36
37 #include "Value.h"
38 #include "VectorValue.h"
39 #include "BoolValue.h"
40 #include "StringValue.h"
41 #include "FloatValue.h"
42 #include "KX_GameObject.h"
43 #include "IntValue.h"
44 #include "SCA_TimeEventManager.h"
45 #include "SCA_IScene.h"
46
47 /* This little block needed for linking to Blender... */
48 #ifdef WIN32
49 #include "BLI_winstuff.h"
50 #endif
51
52 void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
53 {
54         
55         bProperty* prop = (bProperty*)object->prop.first;
56         CValue* propval;        
57         bool show_debug_info;
58         while(prop)
59         {
60         
61                 propval = NULL;
62                 show_debug_info = bool (prop->flag & PROP_DEBUG);
63
64                 switch(prop->type) {
65                         case GPROP_BOOL:
66                         {
67                                 propval = new CBoolValue((bool)(prop->data != 0));
68                                 gameobj->SetProperty(prop->name,propval);
69                                 //promp->poin= &prop->data;
70                                 break;
71                         }
72                         case GPROP_INT:
73                         {
74                                 propval = new CIntValue((int)prop->data);
75                                 gameobj->SetProperty(prop->name,propval);
76                                 break;
77                         }
78                         case GPROP_FLOAT:
79                         {
80                                 //prop->poin= &prop->data;
81                                 float floatprop = *((float*)&prop->data);
82                                 propval = new CFloatValue(floatprop);
83                                 gameobj->SetProperty(prop->name,propval);
84                         }
85                         break;
86                         case GPROP_STRING:
87                         {
88                                 //prop->poin= callocN(MAX_PROPSTRING, "property string");
89                                 propval = new CStringValue((char*)prop->poin,"");
90                                 gameobj->SetProperty(prop->name,propval);
91                                 break;
92                         }
93                         case GPROP_TIME:
94                         {
95                                 float floatprop = *((float*)&prop->data);
96
97                                 CValue* timeval = new CFloatValue(floatprop);
98                                 // set a subproperty called 'timer' so that 
99                                 // we can register the replica of this property 
100                                 // at the time a game object is replicated (AddObjectActuator triggers this)
101                                 CValue *bval = new CBoolValue(true);
102                                 timeval->SetProperty("timer",bval);
103                                 bval->Release();
104                                 if (isInActiveLayer)
105                                 {
106                                         timemgr->AddTimeProperty(timeval);
107                                 }
108                                 
109                                 propval = timeval;
110                                 gameobj->SetProperty(prop->name,timeval);
111
112                         }
113                         default:
114                         {
115                                 // todo make an assert etc.
116                         }
117                 }
118                 
119                 if (propval)
120                 {
121                         if (show_debug_info)
122                         {
123                                 scene->AddDebugProperty(gameobj,STR_String(prop->name));
124                         }
125                         // done with propval, release it
126                         propval->Release();
127                 }
128                 
129 #ifdef WITH_PYTHON
130                 /* Warn if we double up on attributes, this isnt quite right since it wont find inherited attributes however there arnt many */
131                 for(PyAttributeDef *attrdef = KX_GameObject::Attributes; attrdef->m_name; attrdef++) {
132                         if(strcmp(prop->name, attrdef->m_name)==0) {
133                                 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);
134                                 break;
135                         }
136                 }
137                 for(PyMethodDef *methdef = KX_GameObject::Methods; methdef->ml_name; methdef++) {
138                         if(strcmp(prop->name, methdef->ml_name)==0) {
139                                 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);
140                                 break;
141                         }
142                 }
143                 /* end warning check */
144 #endif // WITH_PYTHON
145
146                 prop = prop->next;
147         }
148         // check if state needs to be debugged
149         if (object->scaflag & OB_DEBUGSTATE)
150         {
151                 //  reserve name for object state
152                 scene->AddDebugProperty(gameobj,STR_String("__state__"));
153         }
154 }