Taking a screenshot with base.win.saveScreenshot can easily take one second on my machine. That’s enough to miss a lot of collisions and it kills the framerate.
So I thought I’d just throw that in a thread. I never used threads before so I’m probably doing it wrong. It seems to work, but maybe I’m not locking/copying textures properly ?
I made this:
# Module `screenshot`
import threading
def _shoot(screen, file_name):
print "Screenshot..."
screen.write(file_name)
print "...taken", file_name
def take(win, file_name):
screen = win.getScreenshot()
t = threading.Thread(target=_shoot, args=(screen, file_name))
t.start()
And I call it like that:
class MyApp(ShowBase):
...
def takeScreenShot(self):
now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S-%f')
file_name = Filename(now + '.png')
screenshot.take(self.win, file_name)
It seems to work, but I need to be sure. Is that code sane? Or will I see some weird tearing at some point while the texture I’m saving changes due to another render?