comparison demos/shooter/scripts/scene.py @ 476:78a1eb57c074

Changed the way instances get deleted from the scene. Instances now get removed at the end of the frame as opposed to after their explosion action is complete. The old way was causing the odd segfault because the instance was being removed before FIFE was finished with it.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 22 Apr 2010 01:18:44 +0000
parents afde89c1d50b
children 6b33d80b468b
comparison
equal deleted inserted replaced
475:afde89c1d50b 476:78a1eb57c074
50 self._layer = objectLayer 50 self._layer = objectLayer
51 self._nodes = list() 51 self._nodes = list()
52 52
53 self._player = None 53 self._player = None
54 self._projectiles = list() 54 self._projectiles = list()
55 self._objectstodelete = list()
55 56
56 self._maxnodes = 128 57 self._maxnodes = 128
57 self._xscale = 0 58 self._xscale = 0
58 59
59 self._time = 0 60 self._time = 0
170 self._world.gameOver() 171 self._world.gameOver()
171 172
172 def endLevel(self): 173 def endLevel(self):
173 self._world.endLevel() 174 self._world.endLevel()
174 175
176 def queueObjectForRemoval(self, obj):
177 self._objectstodelete.append(obj)
178
175 def removeAllProjectiles(self): 179 def removeAllProjectiles(self):
176 projtodelete = list() 180 projtodelete = list()
177 for p in self._projectiles: 181 for p in self._projectiles:
178 p.destroy() 182 p.destroy()
179 projtodelete.append(p) 183 projtodelete.append(p)
217 221
218 def removeObjectFromScene(self, obj): 222 def removeObjectFromScene(self, obj):
219 for node in self._nodes: 223 for node in self._nodes:
220 if obj in node.spaceobjects: 224 if obj in node.spaceobjects:
221 node.spaceobjects.remove(obj) 225 node.spaceobjects.remove(obj)
226 self._layer.deleteInstance(obj.instance)
227 obj.instance = None
222 return 228 return
223 229
224 def attachCamera(self, cam): 230 def attachCamera(self, cam):
225 self._camera = cam 231 self._camera = cam
226 self._camera.setLocation(self._player.location) 232 self._camera.setLocation(self._player.location)
316 #remove any expired projectiles 322 #remove any expired projectiles
317 for p in projtodelete: 323 for p in projtodelete:
318 if p in self._projectiles: 324 if p in self._projectiles:
319 p.destroy() 325 p.destroy()
320 self._projectiles.remove(p) 326 self._projectiles.remove(p)
327
328 for obj in self._objectstodelete:
329 self.removeObjectFromScene(obj)
330 self._layer.deleteInstance(obj.instance)
331 obj.instance = None
332
333 self._objectstodelete = list()
321 334
322 335
323 def _getPlayer(self): 336 def _getPlayer(self):
324 return self._player 337 return self._player
325 338