SkyTemple / py-desmume

Python Library and GUI for DeSmuME, the Nintendo DS emulator
GNU General Public License v3.0
25 stars 5 forks source link

Modifying the emulation speed #35

Closed truite-codeuse closed 1 year ago

truite-codeuse commented 1 year ago

Hi ! I was wondering if I could modify the emulation speed ? It seems already sped up using the startup code, maybe I missed something in the doc :flushed:

theCapypara commented 1 year ago

Hi! If you just call the emulator loop in a loop without explicitly waiting, it will run the emulator as fast as possible. You'll need to sleep your program in between frames.

truite-codeuse commented 1 year ago

Thanks a lot ! In case anyone was wondering this is the code I use to run the game at normal speed (approximately) :

from desmume.emulator import DeSmuME
import time

emu = DeSmuME()
emu.open('rom/PokemonPlatine.nds')

emu.volume_set(5)
# Create the window for the emulator
window = emu.create_sdl_window()

# Starting timer to control the framerate
startime = time.monotonic()
# Refresh rate
refresh = 1/60

while not window.has_quit():
    window.process_input()   # Controls are the default DeSmuME controls, see below.
    emu.cycle()
    window.draw()
    # Delay
    time.sleep(refresh - ((time.monotonic() - startime) % refresh))
truite-codeuse commented 1 year ago

I don't know if it's the best solution but it works pretty well !