Merge with -r 22620:23107.
[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         PyVarObject_HEAD_INIT(NULL, 0)
95         "KX_VisibilityActuator",
96         sizeof(PyObjectPlus_Proxy),
97         0,
98         py_base_dealloc,
99         0,
100         0,
101         0,
102         0,
103         py_base_repr,
104         0,0,0,0,0,0,0,0,0,
105         Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
106         0,0,0,0,0,0,0,
107         Methods,
108         0,
109         0,
110         &SCA_IActuator::Type,
111         0,0,0,0,0,0,
112         py_base_new
113 };
114
115 PyMethodDef KX_VisibilityActuator::Methods[] = {
116         {NULL,NULL} //Sentinel
117 };
118
119 PyAttributeDef KX_VisibilityActuator::Attributes[] = {
120         KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible),
121         KX_PYATTRIBUTE_BOOL_RW("useOcclusion", KX_VisibilityActuator, m_occlusion),
122         KX_PYATTRIBUTE_BOOL_RW("useRecursion", KX_VisibilityActuator, m_recursive),
123         { NULL }        //Sentinel
124 };