1

I have a game, written in Python, and I use Panda3d. Now I want to have a possibility for restart, that is, I want to press a button with the result that the main is executed again, just as if the current instance of the game had never existed.

Is there a simple way to do this?

newnewbie
  • 993
  • 2
  • 11
  • 26
  • I recommend you to ask the question within the panda3d community too. But I guess, that that what you want to do isn't possible without starting the panda3d game/application without an other application. Maybe a *launcher* or something else. – Colin O'Coal Mar 18 '13 at 20:27
  • I cannot speak to Panda3D. However, it sounds to me like you need a greater separation between your UI and your 'game engine'. If they are sufficiently separate, you should be able to reset the state of your game engine and have your UI respond accordingly. – john_science Mar 18 '13 at 22:35

2 Answers2

3

Not really. Panda3D doesn't really make this abstraction, that's up to the application developer. It depends on the specific case what "restart" really means; do you want to close the existing window and then reopen a new one? If not, then that means that you have to keep many Panda3D objects in place and can't simply recreate the ShowBase instance. But do you then want to unload any models loaded into memory? Do you want to resend the geometry for your UI objects to the graphics card?

So, depending on your specific needs, you will have to unload and get rid of the objects that you need to restart and then recreate them. If you use an object oriented approach and structure your objects properly, this should be straightforward - ie, you implement an unload() on your Game object that unloads things specific to that game, and then let the references to that object go (causing it to be garbage collected), and create a new one. (Beware of circular references! If you have them, they may keep old instances of your objects in memory even when they have gone out of scope.)

rdb
  • 1,488
  • 1
  • 14
  • 24
1

If you're wanting to restart, you'll have to manually create a function and have it do what you need it to do. There's a post on the Panda website about this very thing, at https://www.panda3d.org/forums/viewtopic.php?t=11422

xsammy_boi
  • 135
  • 1
  • 2
  • 7