svn merge -r 16490:16592 https://svn.blender.org/svnroot/bf-blender/trunk/blender...
[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 recursive,
42         PyTypeObject* T
43         ) 
44         : SCA_IActuator(gameobj,T),
45           m_visible(visible),
46           m_recursive(recursive)
47 {
48         // intentionally empty
49 }
50
51 KX_VisibilityActuator::~KX_VisibilityActuator(
52         void
53         )
54 {
55         // intentionally empty
56 }
57
58 CValue*
59 KX_VisibilityActuator::GetReplica(
60         void
61         )
62 {
63         KX_VisibilityActuator* replica = new KX_VisibilityActuator(*this);
64         replica->ProcessReplica();
65         // this will copy properties and so on...
66         CValue::AddDataToReplica(replica);
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->UpdateBuckets(m_recursive);
82
83         return false;
84 }
85
86 /* ------------------------------------------------------------------------- */
87 /* Python functions                                                          */
88 /* ------------------------------------------------------------------------- */
89
90
91
92 /* Integration hooks ------------------------------------------------------- */
93 PyTypeObject 
94 KX_VisibilityActuator::Type = {
95         PyObject_HEAD_INIT(&PyType_Type)
96         0,
97         "KX_VisibilityActuator",
98         sizeof(KX_VisibilityActuator),
99         0,
100         PyDestructor,
101         0,
102         __getattr,
103         __setattr,
104         0, //&MyPyCompare,
105         __repr,
106         0, //&cvalue_as_number,
107         0,
108         0,
109         0,
110         0
111 };
112
113 PyParentObject 
114 KX_VisibilityActuator::Parents[] = {
115         &KX_VisibilityActuator::Type,
116         &SCA_IActuator::Type,
117         &SCA_ILogicBrick::Type,
118         &CValue::Type,
119         NULL
120 };
121
122 PyMethodDef 
123 KX_VisibilityActuator::Methods[] = {
124         {"set", (PyCFunction) KX_VisibilityActuator::sPySetVisible, 
125          METH_VARARGS, SetVisible_doc},
126         {NULL,NULL} //Sentinel
127 };
128
129 PyObject* 
130 KX_VisibilityActuator::_getattr(
131         const STR_String& attr
132         ) 
133 {
134         _getattr_up(SCA_IActuator);
135 };
136
137
138
139 /* set visibility ---------------------------------------------------------- */
140 char 
141 KX_VisibilityActuator::SetVisible_doc[] = 
142 "setVisible(visible?)\n"
143 "\t - visible? : Make the object visible? (KX_TRUE, KX_FALSE)"
144 "\tSet the properties of the actuator.\n";
145 PyObject* 
146
147 KX_VisibilityActuator::PySetVisible(PyObject* self, 
148                                     PyObject* args, 
149                                     PyObject* kwds) {
150         int vis;
151
152         if(!PyArg_ParseTuple(args, "i", &vis)) {
153                 return NULL;
154         }
155
156         m_visible = PyArgToBool(vis);
157
158         Py_Return;
159 }
160
161