BGE Python API cleanup - no functionality changes
[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         // this will copy properties and so on...
68         CValue::AddDataToReplica(replica);
69         return replica;
70 }
71
72 bool
73 KX_VisibilityActuator::Update()
74 {
75         bool bNegativeEvent = IsNegativeEvent();
76         
77         RemoveAllEvents();
78         if (bNegativeEvent) return false;
79
80         KX_GameObject *obj = (KX_GameObject*) GetParent();
81         
82         obj->SetVisible(m_visible, m_recursive);
83         obj->SetOccluder(m_occlusion, m_recursive);
84         obj->UpdateBuckets(m_recursive);
85
86         return false;
87 }
88
89 /* ------------------------------------------------------------------------- */
90 /* Python functions                                                          */
91 /* ------------------------------------------------------------------------- */
92
93
94
95 /* Integration hooks ------------------------------------------------------- */
96 PyTypeObject KX_VisibilityActuator::Type = {
97         PyObject_HEAD_INIT(NULL)
98         0,
99         "KX_VisibilityActuator",
100         sizeof(PyObjectPlus_Proxy),
101         0,
102         py_base_dealloc,
103         0,
104         0,
105         0,
106         0,
107         py_base_repr,
108         0,0,0,0,0,0,
109         py_base_getattro,
110         py_base_setattro,
111         0,0,0,0,0,0,0,0,0,
112         Methods
113
114 };
115
116 PyParentObject 
117 KX_VisibilityActuator::Parents[] = {
118         &KX_VisibilityActuator::Type,
119         &SCA_IActuator::Type,
120         &SCA_ILogicBrick::Type,
121         &CValue::Type,
122         NULL
123 };
124
125 PyMethodDef 
126 KX_VisibilityActuator::Methods[] = {
127         // Deprecated ----->
128         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, METH_VARARGS,
129                 (PY_METHODCHAR) SetVisible_doc},
130         // <-----
131         {NULL,NULL} //Sentinel
132 };
133
134 PyAttributeDef KX_VisibilityActuator::Attributes[] = {
135         KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible),
136         KX_PYATTRIBUTE_BOOL_RW("occlusion", KX_VisibilityActuator, m_occlusion),
137         KX_PYATTRIBUTE_BOOL_RW("recursion", KX_VisibilityActuator, m_recursive),
138         { NULL }        //Sentinel
139 };
140
141 PyObject* KX_VisibilityActuator::py_getattro(PyObject *attr)
142 {
143         py_getattro_up(SCA_IActuator);
144 }
145
146 int KX_VisibilityActuator::py_setattro(PyObject *attr, PyObject *value)
147 {
148         py_setattro_up(SCA_IActuator);
149 }
150
151
152 /* set visibility ---------------------------------------------------------- */
153 const char 
154 KX_VisibilityActuator::SetVisible_doc[] = 
155 "setVisible(visible?)\n"
156 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
157 "\tSet the properties of the actuator.\n";
158 PyObject* 
159
160 KX_VisibilityActuator::PySetVisible(PyObject* self, 
161                                     PyObject* args, 
162                                     PyObject* kwds) {
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