BGE C++ 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 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         PyObject_HEAD_INIT(NULL)
96         0,
97         "KX_VisibilityActuator",
98         sizeof(PyObjectPlus_Proxy),
99         0,
100         py_base_dealloc,
101         0,
102         0,
103         0,
104         0,
105         py_base_repr,
106         0,0,0,0,0,0,
107         py_base_getattro,
108         py_base_setattro,
109         0,0,0,0,0,0,0,0,0,
110         Methods
111
112 };
113
114 PyParentObject 
115 KX_VisibilityActuator::Parents[] = {
116         &KX_VisibilityActuator::Type,
117         &SCA_IActuator::Type,
118         &SCA_ILogicBrick::Type,
119         &CValue::Type,
120         NULL
121 };
122
123 PyMethodDef 
124 KX_VisibilityActuator::Methods[] = {
125         // Deprecated ----->
126         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, METH_VARARGS,
127                 (PY_METHODCHAR) SetVisible_doc},
128         // <-----
129         {NULL,NULL} //Sentinel
130 };
131
132 PyAttributeDef KX_VisibilityActuator::Attributes[] = {
133         KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible),
134         KX_PYATTRIBUTE_BOOL_RW("occlusion", KX_VisibilityActuator, m_occlusion),
135         KX_PYATTRIBUTE_BOOL_RW("recursion", KX_VisibilityActuator, m_recursive),
136         { NULL }        //Sentinel
137 };
138
139 PyObject* KX_VisibilityActuator::py_getattro(PyObject *attr)
140 {
141         py_getattro_up(SCA_IActuator);
142 }
143
144 PyObject* KX_VisibilityActuator::py_getattro_dict() {
145         py_getattro_dict_up(SCA_IActuator);
146 }
147
148 int KX_VisibilityActuator::py_setattro(PyObject *attr, PyObject *value)
149 {
150         py_setattro_up(SCA_IActuator);
151 }
152
153
154 /* set visibility ---------------------------------------------------------- */
155 const char 
156 KX_VisibilityActuator::SetVisible_doc[] = 
157 "setVisible(visible?)\n"
158 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
159 "\tSet the properties of the actuator.\n";
160 PyObject* 
161
162 KX_VisibilityActuator::PySetVisible(PyObject* args) {
163         int vis;
164         ShowDeprecationWarning("SetVisible()", "the visible property");
165
166         if(!PyArg_ParseTuple(args, "i:setVisible", &vis)) {
167                 return NULL;
168         }
169
170         m_visible = PyArgToBool(vis);
171
172         Py_RETURN_NONE;
173 }
174
175