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