BGE PyAPI support for subclassing any BGE game type from python, scripters define...
[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         ) 
44         : SCA_IActuator(gameobj),
45           m_visible(visible),
46           m_occlusion(occlusion),
47           m_recursive(recursive)
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         return replica;
67 }
68
69 bool
70 KX_VisibilityActuator::Update()
71 {
72         bool bNegativeEvent = IsNegativeEvent();
73         
74         RemoveAllEvents();
75         if (bNegativeEvent) return false;
76
77         KX_GameObject *obj = (KX_GameObject*) GetParent();
78         
79         obj->SetVisible(m_visible, m_recursive);
80         obj->SetOccluder(m_occlusion, 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 #if (PY_VERSION_HEX >= 0x02060000)
95         PyVarObject_HEAD_INIT(NULL, 0)
96 #else
97         /* python 2.5 and below */
98         PyObject_HEAD_INIT( NULL )  /* required py macro */
99         0,                          /* ob_size */
100 #endif
101         "KX_VisibilityActuator",
102         sizeof(PyObjectPlus_Proxy),
103         0,
104         py_base_dealloc,
105         0,
106         0,
107         0,
108         0,
109         py_base_repr,
110         0,0,0,0,0,0,0,0,0,
111         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
112         0,0,0,0,0,0,0,
113         Methods,
114         0,
115         0,
116         &SCA_IActuator::Type,
117         0,0,0,0,0,0,
118         py_base_new
119 };
120
121 PyMethodDef KX_VisibilityActuator::Methods[] = {
122         // Deprecated ----->
123         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, METH_VARARGS,
124                 (PY_METHODCHAR) SetVisible_doc},
125         // <-----
126         {NULL,NULL} //Sentinel
127 };
128
129 PyAttributeDef KX_VisibilityActuator::Attributes[] = {
130         KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible),
131         KX_PYATTRIBUTE_BOOL_RW("useOcclusion", KX_VisibilityActuator, m_occlusion),
132         KX_PYATTRIBUTE_BOOL_RW("useRecursion", KX_VisibilityActuator, m_recursive),
133         { NULL }        //Sentinel
134 };
135
136 /* set visibility ---------------------------------------------------------- */
137 const char 
138 KX_VisibilityActuator::SetVisible_doc[] = 
139 "setVisible(visible?)\n"
140 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
141 "\tSet the properties of the actuator.\n";
142 PyObject* 
143
144 KX_VisibilityActuator::PySetVisible(PyObject* args) {
145         int vis;
146         ShowDeprecationWarning("SetVisible()", "the visible property");
147
148         if(!PyArg_ParseTuple(args, "i:setVisible", &vis)) {
149                 return NULL;
150         }
151
152         m_visible = PyArgToBool(vis);
153
154         Py_RETURN_NONE;
155 }
156
157