Changed Python _getattr/_setattr methods to use const STR_String& instead of char...
[blender.git] / source / gameengine / Ketsji / KX_VisibilityActuator.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  * Actuator to toggle visibility/invisibility of objects
32  */
33
34 #include "KX_VisibilityActuator.h"
35 #include "KX_GameObject.h"
36
37 #ifdef HAVE_CONFIG_H
38 #include <config.h>
39 #endif
40
41 KX_VisibilityActuator::KX_VisibilityActuator(
42         SCA_IObject* gameobj,
43         bool visible,
44         PyTypeObject* T
45         ) 
46         : SCA_IActuator(gameobj,T),
47           m_visible(visible)
48 {
49         // intentionally empty
50 }
51
52 KX_VisibilityActuator::~KX_VisibilityActuator(
53         void
54         )
55 {
56         // intentionally empty
57 }
58
59 CValue*
60 KX_VisibilityActuator::GetReplica(
61         void
62         )
63 {
64         KX_VisibilityActuator* replica = new KX_VisibilityActuator(*this);
65         replica->ProcessReplica();
66         // this will copy properties and so on...
67         CValue::AddDataToReplica(replica);
68         return replica;
69 }
70
71 bool
72 KX_VisibilityActuator::Update(
73         double curtime,
74         double deltatime
75         )
76 {
77         bool bNegativeEvent = IsNegativeEvent();
78         
79         RemoveAllEvents();
80         if (bNegativeEvent) return false;
81
82         KX_GameObject *obj = (KX_GameObject*) GetParent();
83         
84         obj->SetVisible(m_visible);
85         obj->MarkVisible();
86
87         return true;
88 }
89
90 /* ------------------------------------------------------------------------- */
91 /* Python functions                                                          */
92 /* ------------------------------------------------------------------------- */
93
94
95
96 /* Integration hooks ------------------------------------------------------- */
97 PyTypeObject 
98 KX_VisibilityActuator::Type = {
99         PyObject_HEAD_INIT(&PyType_Type)
100         0,
101         "KX_VisibilityActuator",
102         sizeof(KX_VisibilityActuator),
103         0,
104         PyDestructor,
105         0,
106         __getattr,
107         __setattr,
108         0, //&MyPyCompare,
109         __repr,
110         0, //&cvalue_as_number,
111         0,
112         0,
113         0,
114         0
115 };
116
117 PyParentObject 
118 KX_VisibilityActuator::Parents[] = {
119         &KX_VisibilityActuator::Type,
120         &SCA_IActuator::Type,
121         &SCA_ILogicBrick::Type,
122         &CValue::Type,
123         NULL
124 };
125
126 PyMethodDef 
127 KX_VisibilityActuator::Methods[] = {
128         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, 
129          METH_VARARGS, SetVisible_doc},
130         {NULL,NULL} //Sentinel
131 };
132
133 PyObject* 
134 KX_VisibilityActuator::_getattr(
135         const STR_String& attr
136         ) 
137 {
138         _getattr_up(SCA_IActuator);
139 };
140
141
142
143 /* set visibility ---------------------------------------------------------- */
144 char 
145 KX_VisibilityActuator::SetVisible_doc[] = 
146 "setVisible(visible?)\n"
147 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
148 "\tSet the properties of the actuator.\n";
149 PyObject* 
150
151 KX_VisibilityActuator::PySetVisible(PyObject* self, 
152                                     PyObject* args, 
153                                     PyObject* kwds) {
154         int vis;
155
156         if(!PyArg_ParseTuple(args, "i", &vis)) {
157                 return NULL;
158         }
159
160         m_visible = PyArgToBool(vis);
161
162         Py_Return;
163 }
164
165