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