2.50:
[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 occlusion,
42         bool recursive,
43         PyTypeObject* T
44         ) 
45         : SCA_IActuator(gameobj,T),
46           m_visible(visible),
47           m_occlusion(occlusion),
48           m_recursive(recursive)
49 {
50         // intentionally empty
51 }
52
53 KX_VisibilityActuator::~KX_VisibilityActuator(
54         void
55         )
56 {
57         // intentionally empty
58 }
59
60 CValue*
61 KX_VisibilityActuator::GetReplica(
62         void
63         )
64 {
65         KX_VisibilityActuator* replica = new KX_VisibilityActuator(*this);
66         replica->ProcessReplica();
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->SetOccluder(m_occlusion, m_recursive);
82         obj->UpdateBuckets(m_recursive);
83
84         return false;
85 }
86
87 /* ------------------------------------------------------------------------- */
88 /* Python functions                                                          */
89 /* ------------------------------------------------------------------------- */
90
91
92
93 /* Integration hooks ------------------------------------------------------- */
94 PyTypeObject KX_VisibilityActuator::Type = {
95 #if (PY_VERSION_HEX >= 0x02060000)
96         PyVarObject_HEAD_INIT(NULL, 0)
97 #else
98         /* python 2.5 and below */
99         PyObject_HEAD_INIT( NULL )  /* required py macro */
100         0,                          /* ob_size */
101 #endif
102         "KX_VisibilityActuator",
103         sizeof(PyObjectPlus_Proxy),
104         0,
105         py_base_dealloc,
106         0,
107         0,
108         0,
109         0,
110         py_base_repr,
111         0,0,0,0,0,0,
112         py_base_getattro,
113         py_base_setattro,
114         0,0,0,0,0,0,0,0,0,
115         Methods
116
117 };
118
119 PyParentObject 
120 KX_VisibilityActuator::Parents[] = {
121         &KX_VisibilityActuator::Type,
122         &SCA_IActuator::Type,
123         &SCA_ILogicBrick::Type,
124         &CValue::Type,
125         NULL
126 };
127
128 PyMethodDef 
129 KX_VisibilityActuator::Methods[] = {
130         // Deprecated ----->
131         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, METH_VARARGS,
132                 (PY_METHODCHAR) SetVisible_doc},
133         // <-----
134         {NULL,NULL} //Sentinel
135 };
136
137 PyAttributeDef KX_VisibilityActuator::Attributes[] = {
138         KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible),
139         KX_PYATTRIBUTE_BOOL_RW("useOcclusion", KX_VisibilityActuator, m_occlusion),
140         KX_PYATTRIBUTE_BOOL_RW("useRecursion", KX_VisibilityActuator, m_recursive),
141         { NULL }        //Sentinel
142 };
143
144 PyObject* KX_VisibilityActuator::py_getattro(PyObject *attr)
145 {
146         py_getattro_up(SCA_IActuator);
147 }
148
149 PyObject* KX_VisibilityActuator::py_getattro_dict() {
150         py_getattro_dict_up(SCA_IActuator);
151 }
152
153 int KX_VisibilityActuator::py_setattro(PyObject *attr, PyObject *value)
154 {
155         py_setattro_up(SCA_IActuator);
156 }
157
158
159 /* set visibility ---------------------------------------------------------- */
160 const char 
161 KX_VisibilityActuator::SetVisible_doc[] = 
162 "setVisible(visible?)\n"
163 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
164 "\tSet the properties of the actuator.\n";
165 PyObject* 
166
167 KX_VisibilityActuator::PySetVisible(PyObject* args) {
168         int vis;
169         ShowDeprecationWarning("SetVisible()", "the visible property");
170
171         if(!PyArg_ParseTuple(args, "i:setVisible", &vis)) {
172                 return NULL;
173         }
174
175         m_visible = PyArgToBool(vis);
176
177         Py_RETURN_NONE;
178 }
179
180