Source

pygamekit / gameobject.pxi

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715

from variable cimport *
from mathutils cimport *
from prerequisites cimport *

from gkmath cimport *

OBJECT_TYPES = (
    'NULL',
    'CAMERA',
    'LIGHT',
    'ENTITY',
    'OBJECT',
    'SKELETON',
    'PARTICLES'
)

cdef to_GameObject(gkGameObject *ob):
    if ob!=NULL:
        t = ob.getType()
        if t == GK_ENTITY:
            return wrap(Entity, ob)
        elif t == GK_SKELETON:
            return wrap(Skeleton, ob)
        elif t == GK_CAMERA:
            return wrap(Camera, ob)
        else:
            return wrap(GameObject, ob)
    else:
        return None

cdef gkGameObject* cloneRecursiveImpl(gkGameObject* ob,
                                      int lifespan=0,
                                      bool instance=True):
    
    cdef gkScene *scn = ob.getOwner()
    cdef gkGameObjectArrayIterator it = ob.getChildren().iterator()
    cdef gkGameObject *ob2, *c, *c2
    cdef gkEntity *e
    
    if scn == NULL:
        return NULL
    
    ob2 = scn.cloneObject(ob, lifespan, instance)
    
    while it.hasMoreElements():
        c = it.getNext()
        ob2.removeChild(c)
        # Assumes every mesh child of skeleton has skeletal animation
        # (Until we get parent-to-bone in gamekit)
        if ob.getType() == GK_SKELETON and c.getType() == GK_ENTITY \
                and instance:
            c2 = cloneRecursiveImpl(c, lifespan, False)
            e = <gkEntity *>c2
            e.setSkeleton(ob2.getSkeleton())
            e.createInstance()
        else:
            c2 = cloneRecursiveImpl(c, lifespan, instance)
        ob2.addChild(c2)
        c2.setTransform(c.getTransform())
        
    return ob2

    
cdef class GameObject(pywrap):
    '''
    All game objects are derived from this class.
    
    Most attributes are writable and makes the necessary transformations.
    
    Properties can be read, assigned or deleted from game objects as items::
    
        my_object['my_property'] = 3
        del my_object['my_property']
    
    Properties can be booleans, integers, floats, strings, vectors or
    quaternions.
    
    You can create any object type and add it to a scene::
    
        ob = GameObject("some_name")
        ob.scene = my_scene
        # or:
        my_scene.add_object(ob)
        
    If there is an object with the same name (globally), it will be assigned
    a different name.
        
    Objects that aren't in a scene are destroyed when unallocated. Therefore
    you may destroy objects when you remove them from the scene::
        ob.scene = None
        # or:
        my_scene.remove_object(ob)
        # now, if ob is unallocated, it will be destroyed
        del ob
        
    If you must ensure an object is destroyed, use this instead::
    
        ob.destroy()
        # or:
        scene.destroy_object(ob)
        
    Any Python references to that object will become invalid.

    .. warning::
        Accessing deleted objects will crash gamekit. In the future it will
        throw an error instead.
    '''
    
    # TODO: make this __cinit__, but not being executed with __new__?
    def __init__(self, name='Unnamed'):
        cdef gkGameObject* ob
        ob = gkGameObjectManager().createObject(gkString(name))
        if ob == NULL:
            ob = gkGameObjectManager()\
                .createObject(getUniqueName(gkString(name)))
        self._p = ob
            
    def __dealloc__(self):
        if (<gkGameObject*>self._p).getOwner() == NULL:
            gkGameObjectManager().destroy(<gkGameObject*>self._p)
            # TODO: mark as invalid
            # TODO: detect non-python deallocations
            
    def destroy(self):
        cdef gkGameObject* ob = <gkGameObject*>self._p
        cdef gkScene* scn = ob.getOwner()
        if scn != NULL:
            scn.destroyObject(ob)
        else:
            gkGameObjectManager().destroy(<gkGameObject*>self._p)
    
    @property
    def type(self):
        '''
        Object type can be one of the following strings:
        
        ========= =========================
        String    Type (Blender equivalent)
        ========= =========================
        ENTITY    Mesh object
        SKELETON  Armature
        CAMERA    Camera
        LIGHT     Light
        PARTICLES Particle emitter (mesh)
        OBJECT    Empty or unknown object
        ========= =========================
        
        '''
        
        return OBJECT_TYPES[(<gkGameObject*>self._p).getType()]
            
    property name:
        '''
        The name of the object. It's guaranteed to be unique.
        '''
        def __get__(self):
            return (<gkGameObject*>self._p).getName().c_str()
    
    def __getitem__(self,item):
        cdef gkVariable *v
        cdef int t
        cdef gkString s = gkString(item)
        cdef gkGameObject* o = <gkGameObject*>self._p
        
        if o.hasVariable(s):
            v = o.getVariable(s)
            t = v.getType()
            if t==VAR_REAL:
                return v.getValueReal()
            elif t==VAR_BOOL:
                return v.getValueBool()
            elif t==VAR_INT:
                return v.getValueInt()
            elif t==VAR_VEC3:
                return Vector().assign(v.getValueVector3())
            elif t==VAR_QUAT:
                return Quaternion().assign(v.getValueQuaternion())
            else:
                return str(v.getValueString().c_str())
            
        raise KeyError("This GameObject doesn't have property "+str(item))
        
    def __setitem__(self,item,value):
        cdef gkVariable *v
        cdef int t
        cdef gkString s = gkString(item)
        cdef gkGameObject* o = <gkGameObject*>self._p
        
        if o.hasVariable(s):
            v = o.getVariable(s)
        else:
            v = o.createVariable(s, 0)
            
        if isinstance(value, float):
            v.setValue(<gkScalar>value)
        elif isinstance(value, int):
            v.setValueInt(value)
        elif isinstance(value, pybool):
            v.setValue(<bool>value)
        elif isinstance(value, str):
            v.setValue(gkString(value))
        elif isinstance(value, Vector):
            v.setValue((<Vector>value).v[0])
        elif isinstance(value, Quaternion):
            v.setValue((<Quaternion>value).q[0])
        else:
            raise TypeError(
                "Unsupported type for property {} (type is {})".format(
                    item, type(item).__name__))
        
    def __delitem__(self,item):
        (<gkGameObject*>self._p).removeVariable(gkString(item))
        
    def __contains__(self,item):
        cdef gkGameObject* o = <gkGameObject*>self._p
        
        return o.hasVariable(gkString(item))
        
    def __hash__(self):
        return str(self).__hash__()
        
    def clone(self, life_span=0, instantiate=True):
        cdef gkGameObject *ob = <gkGameObject*>self._p
        cdef gkScene* scn = ob.getOwner()
        if scn==NULL:
            ob = ob.clone(getUniqueName(ob.getName()))
            return wrap(GameObject, ob)
        else:
            ob = scn.cloneObject(ob, life_span, instantiate)
        
    def clone_recursive(self, lifespan=0):
        '''
        Returns a copy of the object having a copy of all children.
        Skeletons are associated accordingly.
        '''
        cdef gkGameObject *ob = cloneRecursiveImpl(<gkGameObject*>self._p, lifespan)
        return to_GameObject(ob)
        
    property scene:
        def __get__(self):
            cdef gkScene *scn = (<gkGameObject*>self._p).getOwner()
            if scn!=NULL:
                return wrap(Scene, scn)
        
        def __set__(self, Scene scene):
            cdef gkGameObject *ob = <gkGameObject*>self._p
            cdef gkScene *scn
            
            scn = ob.getOwner()
            if scn!=NULL:
                scn.removeObject(ob)

            scn = <gkScene*>scene._p
            if scn!=NULL:
                scn.addObject(ob)
                ob.createInstance()

    property parent:
        '''
        Parent GameObject from which inherits position, rotation and scale.
        Can be set to change the parent.
        
        Local transformation is not changed. Use parent_in_place to change
        parent while retaining world transformation.
        
        Set to None to unparent.
        '''
        def __get__(self):
            cdef gkGameObject* ob = (<gkGameObject*>self._p).getParent()
            return to_GameObject(ob)
            
        def __set__(self, GameObject ob):
            if ob:
                (<gkGameObject*>self._p).setParent(<gkGameObject*>ob._p)
            else:
                (<gkGameObject*>self._p).clearParent()
                
    property parent_in_place:
        '''
        Parent GameObject from which inherits position, rotation and scale.
        It has the same value as parent, but when changed, local transformation
        is modified to retain the world transformation.
        
        Set to None to unparent in place.
        '''
        def __get__(self):
            cdef gkGameObject* ob = (<gkGameObject*>self._p).getParent()
            return to_GameObject(ob)
            
        def __set__(self, GameObject ob):
            if ob:
                (<gkGameObject*>self._p).setParentInPlace(<gkGameObject*>ob._p)
            else:
                (<gkGameObject*>self._p).clearParentInPlace()
                
    @property
    def children(self):
        '''
        Iterable containing all children of the game object.
        '''
        return wrap(GameObjectArray, &((<gkGameObject*>self._p).getChildren()))
        
    property position:
        '''
        Position in parent coordinates. If it has no parent, it's the same as
        position_world.
        '''
        def __get__(self):
            cdef gkVector3 v = (<gkGameObject*>self._p).getPosition()
            return Vector(v.x, v.y, v.z)
            
        def __set__(self,pos):
            cdef gkVector3 v = gkVector3()
            v.x = pos[0]
            v.y = pos[1]
            v.z = pos[2]

            (<gkGameObject*>self._p).setPosition(v)

    property position_world:
        '''
        Position in world coordinates. If it has no parent, it's the same as
        position.
        '''
        
        def __get__(self):
            cdef gkVector3 v = (<gkGameObject*>self._p).getWorldPosition()
            return Vector(v.x, v.y, v.z)

        def __set__(self, pos):
            cdef gkGameObject *ob = <gkGameObject*>self._p
            if ob.getParent()!=NULL:
                ob.setPosition(ob.getParent().getWorldTransform().inverse().mul(gkVector3(pos[0], pos[1], pos[2])))
            else:
                ob.setPosition(gkVector3(pos[0], pos[1], pos[2]))

    property rotation:
        '''
        Euler rotation in parent coordinates. If it has no parent, it's the same as
        rotation_world.
        
        It's a Vector with an euler rotation in radians. It's recommended to use
        orientation instead, which is a Quaternion.
        '''

        def __get__(self):
            cdef gkEuler r = (<gkGameObject*>self._p).getRotation()
            return Vector(r.x.valueRadians(), r.y.valueRadians(), r.z.valueRadians())

        def __set__(self,rot):
            cdef gkEuler r = gkEuler()
            r.x = gkRadian(rot[0])
            r.y = gkRadian(rot[1])
            r.z = gkRadian(rot[2])
            (<gkGameObject*>self._p).setOrientation(r)
            
    property rotation_world:
        '''
        Euler rotation in world coordinates. If it has no parent, it's the same as
        rotation.
        
        It's a Vector with an euler rotation in radians. It's recommended to use
        orientation instead, which is a Quaternion.
        '''

        def __get__(self):
            cdef gkEuler r = (<gkGameObject*>self._p).getWorldRotation()
            return Vector(r.x.valueRadians(), r.y.valueRadians(), r.z.valueRadians())

        def __set__(self, rot):
            cdef gkGameObject *ob = <gkGameObject*>self._p
            cdef gkEuler r = gkEuler()
            r.x = gkRadian(rot[0])
            r.y = gkRadian(rot[1])
            r.z = gkRadian(rot[2])
            if ob.getParent()!=NULL:
                ob.setOrientation(ob.getParent().getWorldOrientation().inverse())
                ob.rotate(r, TRANSFORM_PARENT)
            else:
                ob.setOrientation(r)

    property orientation:
        '''
        Quaternion rotation in parent coordinates. If it has no parent, it's the same as
        orientation_world.
        '''
        
        def __get__(self):
            cdef Quaternion q = Quaternion()
            (q.q).assign((<gkGameObject*>self._p).getOrientation())
            return q
            
        def __set__(self, Quaternion q):
            (<gkGameObject*>self._p).setOrientation(<gkQuaternion>(q.q)[0])

    property orientation_world:
        '''
        Quaternion rotation in world coordinates. If it has no parent, it's the same as
        orientation.
        '''
        
        def __get__(self):
            cdef Quaternion q = Quaternion()
            (q.q).assign((<gkGameObject*>self._p).getWorldOrientation())
            return q
            
        def __set__(self, Quaternion q):
            cdef gkGameObject *ob = <gkGameObject*>self._p
            if ob.getParent()!=NULL:
                ob.setOrientation(ob.getParent().getWorldOrientation().inverse())
                ob.rotate(<gkQuaternion>(q.q)[0], TRANSFORM_PARENT)
            else:
                ob.setOrientation(<gkQuaternion>(q.q)[0])

    property scale:
        '''
        Local scaling factor.
        '''
        
        def __get__(self):
            cdef gkVector3 v = (<gkGameObject*>self._p).getScale()
            return Vector(v.x, v.y, v.z)
            
        def __set__(self, pos):
            cdef gkVector3 v = gkVector3()
            v.x = pos[0]
            v.y = pos[1]
            v.z = pos[2]
            (<gkGameObject*>self._p).setScale(v)

    property linear_velocity:
        '''
        Linear velocity of the dynamic or rigid body object.
        '''
        
        def __get__(self):
            cdef gkVector3 v = (<gkGameObject*>self._p).getLinearVelocity()
            return Vector(v.x, v.y, v.z)
            
        def __set__(self,pos):
            cdef gkVector3 v = gkVector3()
            v.x = pos[0]
            v.y = pos[1]
            v.z = pos[2]
            (<gkGameObject*>self._p).setLinearVelocity(v,TRANSFORM_PARENT)
            
    property angular_velocity:
        '''
        Angular velocity of the dynamic or rigid body object.
        '''
        
        def __get__(self):
            cdef gkVector3 v = (<gkGameObject*>self._p).getAngularVelocity()
            return Vector(v.x, v.y, v.z)
            
        def __set__(self,pos):
            cdef gkVector3 v = gkVector3()
            v.x = pos[0]
            v.y = pos[1]
            v.z = pos[2]
            (<gkGameObject*>self._p).setAngularVelocity(v,TRANSFORM_PARENT)
            
    def translate(self, pos):
        
        cdef gkVector3 v = gkVector3()
        v.x = pos[0]
        v.y = pos[1]
        v.z = pos[2]

        (<gkGameObject*>self._p).translate(v, TRANSFORM_PARENT)

    def translate_local(self, pos):
        cdef gkVector3 v = gkVector3()
        v.x = pos[0]
        v.y = pos[1]
        v.z = pos[2]

        (<gkGameObject*>self._p).translate(v, TRANSFORM_LOCAL)

    def translate_world(self, pos):
        cdef gkVector3 v = gkVector3()
        v.x = pos[0]
        v.y = pos[1]
        v.z = pos[2]

        (<gkGameObject*>self._p).translate(v, TRANSFORM_WORLD)

    def rotate(self, drot):
        cdef gkEuler r = gkEuler()
        r.x = gkRadian(drot[0])
        r.y = gkRadian(drot[1])
        r.z = gkRadian(drot[2])
        (<gkGameObject*>self._p).rotate(r, TRANSFORM_PARENT)

    def rotate_local(self, drot):
        cdef gkEuler r = gkEuler()
        r.x = gkRadian(drot[0])
        r.y = gkRadian(drot[1])
        r.z = gkRadian(drot[2])
        (<gkGameObject*>self._p).rotate(r, TRANSFORM_LOCAL)

    def rotate_world(self, drot):
        cdef gkEuler r = gkEuler()
        r.x = gkRadian(drot[0])
        r.y = gkRadian(drot[1])
        r.z = gkRadian(drot[2])
        (<gkGameObject*>self._p).rotate(r, TRANSFORM_WORLD)
        
    # Rigid body stuff
    
    def apply_torque(self, t):
        cdef gkVector3 v = gkVector3()
        v.x = t[0]
        v.y = t[1]
        v.z = t[2]

        (<gkGameObject*>self._p).applyTorque(v, TRANSFORM_PARENT)

    def apply_torque_local(self, t):
        cdef gkVector3 v = gkVector3()
        v.x = t[0]
        v.y = t[1]
        v.z = t[2]

        (<gkGameObject*>self._p).applyTorque(v, TRANSFORM_LOCAL)

    def apply_torque_world(self, t):
        cdef gkVector3 v = gkVector3()
        v.x = t[0]
        v.y = t[1]
        v.z = t[2]

        (<gkGameObject*>self._p).applyTorque(v, TRANSFORM_WORLD)

    def apply_force(self, f):
        cdef gkVector3 v = gkVector3()
        v.x = f[0]
        v.y = f[1]
        v.z = f[2]

        (<gkGameObject*>self._p).applyForce(v, TRANSFORM_PARENT)

    def apply_force_local(self, f):
        cdef gkVector3 v = gkVector3()
        v.x = f[0]
        v.y = f[1]
        v.z = f[2]

        (<gkGameObject*>self._p).applyForce(v, TRANSFORM_LOCAL)

    def apply_force_world(self, f):
        cdef gkVector3 v = gkVector3()
        v.x = f[0]
        v.y = f[1]
        v.z = f[2]

        (<gkGameObject*>self._p).applyForce(v, TRANSFORM_WORLD)

    def suspend_dynamics(self):
        (<gkGameObject*>self._p).getPhysicsController().suspend(True)

    def resume_dynamics(self):
        (<gkGameObject*>self._p).getPhysicsController().suspend(False)

    @property
    def animations(self):
        '''
        Iterable of *known* animations for this object.
        Use animations['animation_name'] to get an animation and add it to this iterable.
        '''
        
        return wrap(AnimationList, self._p)
        
    def add_sensor(self, Sensor sensor):
        '''
        Bounds the sensor to the game object and returns the same sensor, 
        or a copy if it's bound already to another object.
        
        
        Example::
        
            my_sensor = my_object.add_sensor(Collision("floor"))
            
        This sets Sensor.owner, and also some sensors (such as Collision and Ray) require this.
        '''
        old = getattr(sensor,'owner',None)
        if old is not None and old!=self:
            sensor = sensor.copy()
        sensor._set_owner(self)
        return sensor
        
    def add_actuator(self, actuator):
        '''
        Bounds the actuator to the game object and returns the same actuator,
        or a copy if it's bound already to another object.
            
        This sets Actuator.owner, and also most actuators require this.
        '''
        old = getattr(actuator,'owner',None)
        if old is not None and old!=self:
            actuator = actuator.copy()
        actuator._set_owner(self)
        return actuator
        
    property visible:
        '''Sets or returns the visibility of the object.
        If `True` it will be visible; if `False` it will be invisible. Physics will be unaffected.'''
        
        def __get__(self):
            return not (<gkGameObject*>self._p).getProperties().isInvisible()
        
        def __set__(self, bool v):
            cdef gkGameObjectProperties *prop = &((<gkGameObject*>self._p).getProperties())
            prop.m_mode |= GK_INVISIBLE
            if v:
                prop.m_mode -= GK_INVISIBLE
            (<gkGameObject*>self._p).getNode().setVisible(v, False)
        


cdef class Skeleton(GameObject):
    
    #def something(self, a, b, c, d):
        #cdef gkBone *b1 = (<gkSkeleton*>self._p).getBone(gkString('tizq'))
        #cdef gkBone *b2 = (<gkSkeleton*>self._p).getBone(gkString('tder'))
        #cdef gkTransformState t1 = gkTransformState()
        #cdef gkTransformState t2 = gkTransformState()
        #cdef gkVector3 v1, v2
        #t1.loc.x = a
        #t1.loc.z = b
        #t2.loc.x = c
        #t2.loc.z = d
        #t1.loc.y=0.5
        #t2.loc.y=0.5
        #b1.applyChannelTransform(t1, 1)
        #b2.applyChannelTransform(t2, 1)
        #v1 = b1.getPose().loc
        #v2 = b2.getPose().loc
        ##print v1.x, v1.y, v1.z, "   ", v2.x, v2.y, v2.z

    property bones:
        def __get__(self):
            return wrap(BoneList, self._p)

cdef class Bone(pywrap):
    
    pass

cdef class BoneList(pywrap):
    
    def __getitem__(self, name):
        cdef gkBone *b = (<gkSkeleton*>self._p).getBone(gkString(name))
        if b:
            return wrap(Bone, b)
        return None

cdef class GameObjectList(pywrap):
    # Actually wraps gkScene
        
    def __list__(self):
        cdef int hack1 "h;/*" = 0
        cdef gkGameObjectHashMapIterator it, hack2 "gkGameObjectHashMap::Iterator __pyx_v_it /**/"
        
        hack2 = (<gkScene*>self._p).getObjects().iterator()
        
        ret = []
        
        while it.hasMoreElements():
            ret.append(to_GameObject(it.getNext().second))
            
        return ret
        
    def __iter__(self):
        return self.__list__().__iter__() #TODO: can be made more efficient
        
    def __getitem__(self,item):
        cdef gkGameObject *ob = (<gkScene*>self._p).getObject(gkString(item))
        return to_GameObject(ob)

    def __len__(self):
        return (<gkScene*>self._p).getObjects().size()
        
    def __delitem__(self, item):
        cdef gkScene *scn = <gkScene*>self._p
        scn.removeObject(scn.getObject(gkString(item)))
    
cdef class GameObjectArray(pywrap):
    
    cdef list list
        
    def __list__(self):
        cdef gkGameObjectArrayIterator it = (<gkGameObjectArray*>self._p).iterator()
        
        if self.list: return self.list  # TODO: what I was going to do with this?
        
        ret = []
        
        while (it.hasMoreElements()):
            ret.append(to_GameObject(it.getNext()))
            
        return ret
        
    def __iter__(self):
        return self.__list__().__iter__() #TODO: can be made more efficient
        
    def __getitem__(self, item):
        return self.__list__().__getitem__(item)

    def __len__(self):
        return (<gkGameObjectArray*>self._p).size()
    
    # TODO: __delitem__