~jtaylor/ubuntu/oneiric/soya/fix-780305

« back to all changes in this revision

Viewing changes to c_src/python/i_instance.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Dequènes (Duck)
  • Date: 2005-01-30 09:55:06 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050130095506-f21p6v6cgaobhn5j
Tags: 0.9.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * P3 python wrapper
3
 
 *
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.
8
 
 *
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.
13
 
 *
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
17
 
 */
18
 
 
19
 
/**********************************************
20
 
 * Copyright (C) 2002-2003 Bertrand 'blam' LAMY
21
 
 **********************************************/
22
 
 
23
 
/*==========+
24
 
 | INSTANCE |
25
 
 +==========*/
26
 
 
27
 
void P3_instance_batch (P3_instance* c, P3_instance* csys) {
28
 
  PyObject* f;
29
 
  PyObject* p;
30
 
  long i;
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);
35
 
#ifdef SAFE_MODE
36
 
    if (PyErr_Occurred () != NULL) { PyErr_Print (); }
37
 
#endif /* SAFE_MODE */
38
 
    if (f != NULL) {
39
 
      i = PyInt_AS_LONG (PySequence_Fast_GET_ITEM (f, 0));
40
 
      p = PySequence_Fast_GET_ITEM (f, 1);
41
 
      if (p == Py_None) {
42
 
        csys = (P3_instance*) c;
43
 
      } else {
44
 
        csys = (P3_instance*) p;
45
 
      }
46
 
      if (i == 0) {
47
 
        P3_renderer_add (c, csys);
48
 
      } else if (i == 1) {
49
 
        P3_renderer_add_alpha (c, csys);
50
 
      } else if (i == 2) {
51
 
        P3_renderer_add       (c, csys);
52
 
        P3_renderer_add_alpha (c, csys);
53
 
      } else if (i == 3) {
54
 
        P3_renderer_batch (renderer->specials, c, csys, -1);
55
 
      }
56
 
      Py_DECREF (f);
57
 
    }
58
 
  }
59
 
}
60
 
 
61
 
P3_class P3_class_instance = {
62
 
  P3_ID_INSTANCE,
63
 
  (batch_func)     P3_instance_batch,
64
 
  (render_func)    P3_shape_render,
65
 
  (shadow_func)    0,
66
 
  (raypick_func)   0,
67
 
  (raypick_b_func) 0,
68
 
};
69
 
 
70
 
/*---------+
71
 
 | Methods |
72
 
 +---------*/
73
 
 
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;
77
 
        return 0;
78
 
}
79
 
 
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);
84
 
}
85
 
 
86
 
static PyObject* PyP3Instance_BatchObject (P3_instance* c, PyObject* args) {
87
 
  long i;
88
 
  i = PyInt_AS_LONG (PySequence_Fast_GET_ITEM (args, 1));
89
 
  if (i == 0) {
90
 
    P3_renderer_add (PySequence_Fast_GET_ITEM (args, 0), c);
91
 
  } else if (i == 1) {
92
 
    P3_renderer_add_alpha (PySequence_Fast_GET_ITEM (args, 0), c);
93
 
  } else if (i == 2) {
94
 
    void* o;
95
 
    o = PySequence_Fast_GET_ITEM (args, 0);
96
 
    P3_renderer_add       (o, c);
97
 
    P3_renderer_add_alpha (o, c);
98
 
  } else if (i == 3) {
99
 
    P3_renderer_batch (renderer->specials, PySequence_Fast_GET_ITEM (args, 0), c, -1);
100
 
  }
101
 
  Py_INCREF (Py_None);
102
 
  return Py_None;
103
 
}
104
 
 
105
 
static PyObject* PyP3Instance_GetState (P3_instance* a) {
106
 
  P3_chunk* chunk = P3_chunk_new ();
107
 
  PyObject* tuple;
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
113
 
  Py_INCREF (Py_None);
114
 
  PyTuple_SET_ITEM (tuple, 1, Py_None);
115
 
  P3_chunk_dealloc (chunk);
116
 
  return tuple;
117
 
}
118
 
 
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;
123
 
  a->parent = NULL;
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);
127
 
  free (chunk);
128
 
  Py_INCREF (Py_None);
129
 
  return Py_None;
130
 
}
131
 
 
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 },
137
 
  { NULL, NULL }
138
 
};
139
 
 
140
 
/*---------+
141
 
 | Get Set |
142
 
 +---------*/
143
 
 
144
 
/*
145
 
static PyGetSetDef PyP3Instance_GetSets[] = {
146
 
//  PYP3_CHILD_GETSETS,
147
 
//  PYP3_COORDSYS_GETSETS,
148
 
//  PYP3_VISIBLE_GETSETS,
149
 
        { NULL }
150
 
};
151
 
*/
152
 
 
153
 
/*------+
154
 
 | Type |
155
 
 +------*/
156
 
 
157
 
PyTypeObject PyP3Instance_Type = {
158
 
  PyObject_HEAD_INIT(NULL)
159
 
  0,
160
 
  "_soya._Coordsys",
161
 
  sizeof(P3_instance),
162
 
  0,
163
 
  (destructor) PyP3Instance_Dealloc,/* tp_dealloc */
164
 
  0,/* tp_print */
165
 
  0,/* tp_getattr */
166
 
  0,/* tp_setattr */
167
 
  0,/* tp_compare */
168
 
  0,/* tp_repr */
169
 
  0,/* tp_as_number */
170
 
  0,/* tp_as_sequence */
171
 
  0,/* tp_as_mapping */
172
 
  0,/* tp_hash */
173
 
  0,/* tp_call */
174
 
  0,/* tp_str */
175
 
  PYP3_GENERIC_GETATTR,/* tp_getattro */
176
 
  0,/* tp_setattro */
177
 
  0,/* tp_as_buffer */
178
 
  Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,/* tp_flags */
179
 
  0,/* tp_doc */
180
 
  (traverseproc) PyP3Child_Traverse,/* tp_traverse */
181
 
  (inquiry) PyP3Child_Clear,/* tp_clear */
182
 
  0,/* tp_richcompare */
183
 
  0,/* tp_weaklistoffset */
184
 
  0,/* tp_iter */
185
 
  0,/* tp_iternext */
186
 
  (PyMethodDef*) &PyP3Instance_Methods,/* tp_methods */
187
 
  0,/* tp_members */
188
 
  (PyGetSetDef*) 0,/* tp_getset */
189
 
//  (PyGetSetDef*) &PyP3Instance_GetSets,/* tp_getset */
190
 
  &PyP3Element_Type,/* tp_base */
191
 
  0,/* tp_dict */
192
 
  0,/* tp_descr_get */
193
 
  0,/* tp_descr_set */
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 */
199
 
};
200
 
 
201