4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
/**********************************************
20
* Copyright (C) 2002-2003 Bertrand 'blam' LAMY
21
**********************************************/
27
void P3_instance_batch (P3_instance* c, P3_instance* csys) {
31
if (!(c->option & P3_OBJECT_HIDDEN)) {
32
/* compute renderering matrix: enter in this coordsys */
33
P3_multiply_matrix (c->render_matrix, renderer->c_camera->render_matrix, P3_coordsys_get_root_matrix ((P3_coordsys*) c));
34
f = PyObject_CallMethod ((PyObject*) c, "batch", NULL, NULL);
36
if (PyErr_Occurred () != NULL) { PyErr_Print (); }
37
#endif /* SAFE_MODE */
39
i = PyInt_AS_LONG (PySequence_Fast_GET_ITEM (f, 0));
40
p = PySequence_Fast_GET_ITEM (f, 1);
42
csys = (P3_instance*) c;
44
csys = (P3_instance*) p;
47
P3_renderer_add (c, csys);
49
P3_renderer_add_alpha (c, csys);
51
P3_renderer_add (c, csys);
52
P3_renderer_add_alpha (c, csys);
54
P3_renderer_batch (renderer->specials, c, csys, -1);
61
P3_class P3_class_instance = {
63
(batch_func) P3_instance_batch,
64
(render_func) P3_shape_render,
74
static int PyP3Instance_Init (PyObject* self, PyObject* args, PyObject* kwds) {
75
P3_coordsys_initialize ((P3_coordsys*) self);
76
((P3_any_object*) self)->class = &P3_class_instance;
80
static void PyP3Instance_Dealloc (P3_instance* w) {
81
PyObject_GC_UnTrack ((PyObject*) w);
82
Py_XDECREF (w->parent);
83
w->ob_type->tp_free ((PyObject*) w);
86
static PyObject* PyP3Instance_BatchObject (P3_instance* c, PyObject* args) {
88
i = PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 1));
90
P3_renderer_add (PySequence_Fast_GET_ITEM (args, 0), c);
92
P3_renderer_add_alpha (PySequence_Fast_GET_ITEM (args, 0), c);
95
o = PySequence_Fast_GET_ITEM (args, 0);
96
P3_renderer_add (o, c);
97
P3_renderer_add_alpha (o, c);
99
P3_renderer_batch (renderer->specials, PySequence_Fast_GET_ITEM (args, 0), c, -1);
105
static PyObject* PyP3Instance_GetState (P3_instance* a) {
106
P3_chunk* chunk = P3_chunk_new ();
108
P3_chunk_add (chunk, a->m, 19 * sizeof (GLfloat));
109
P3_chunk_add_int (chunk, a->option);
110
tuple = PyTuple_New (2);
111
PyTuple_SET_ITEM (tuple, 0, PyString_FromStringAndSize ((char*) chunk->content, chunk->nb));
112
// HACK because previous object saved their parent
114
PyTuple_SET_ITEM (tuple, 1, Py_None);
115
P3_chunk_dealloc (chunk);
119
static PyObject* PyP3Instance_SetState (P3_instance* a, PyObject* args) {
120
P3_chunk* chunk = P3_chunk_new ();
121
a->class = &P3_class_instance;
122
a->validity = P3_COORDSYS_INVALID;
124
chunk->content = PyString_AS_STRING (PySequence_Fast_GET_ITEM (args, 0));
125
P3_chunk_get (chunk, a->m, 19 * sizeof (GLfloat));
126
a->option = P3_chunk_get_int (chunk);
132
static PyMethodDef PyP3Instance_Methods[] = {
133
// PYP3_COORDSYS_FUNCS,
134
{ "_getstate", (PyCFunction) PyP3Instance_GetState, METH_NOARGS },
135
{ "_setstate", (PyCFunction) PyP3Instance_SetState, METH_O },
136
{ "batch_object", (PyCFunction) PyP3Instance_BatchObject, METH_VARARGS },
145
static PyGetSetDef PyP3Instance_GetSets[] = {
146
// PYP3_CHILD_GETSETS,
147
// PYP3_COORDSYS_GETSETS,
148
// PYP3_VISIBLE_GETSETS,
157
PyTypeObject PyP3Instance_Type = {
158
PyObject_HEAD_INIT(NULL)
163
(destructor) PyP3Instance_Dealloc,/* tp_dealloc */
170
0,/* tp_as_sequence */
171
0,/* tp_as_mapping */
175
PYP3_GENERIC_GETATTR,/* tp_getattro */
178
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,/* tp_flags */
180
(traverseproc) PyP3Child_Traverse,/* tp_traverse */
181
(inquiry) PyP3Child_Clear,/* tp_clear */
182
0,/* tp_richcompare */
183
0,/* tp_weaklistoffset */
186
(PyMethodDef*) &PyP3Instance_Methods,/* tp_methods */
188
(PyGetSetDef*) 0,/* tp_getset */
189
// (PyGetSetDef*) &PyP3Instance_GetSets,/* tp_getset */
190
&PyP3Element_Type,/* tp_base */
194
0,/* tp_dictoffset */
195
(initproc) PyP3Instance_Init,/* tp_init */
196
PYP3_GENERIC_ALLOC,/* tp_alloc */
197
(newfunc) PyP3Object_New,/* tp_new */
198
PYP3_GENERIC_GC_FREE,/* tp_free */