jc-SpaceXp / cNES

NES emulator written in C and targeted for Linux.
zlib License
6 stars 4 forks source link

Better SDL2 game loop thread #6

Closed jc-SpaceXp closed 1 year ago

jc-SpaceXp commented 1 year ago

Whilst recently looking at all the SDL2 code in my project I've noticed the main game loop is a bit of a mess. Mainly that the support of running the emulator for a specified number of cycles differs from how the emulator usually runs.

This bad coding structure has caused the fixed number of cycles version to not support any SDL2 inputs, either keyboard or window events such as closing a window

jc-SpaceXp commented 1 year ago

Messy code fragment I'm talking about

https://github.com/jc-SpaceXp/cNES/blob/12457aa82e7c7cfaec1e9fe5eb821935270a05a0/src/emu.c#L247-L274

jc-SpaceXp commented 1 year ago

e3a41dda4e0a18b7ed6da09d54b03ae77a6672d3 resolves this issue

jc-SpaceXp commented 1 year ago

Here is the new SDL game loop for the curious:

https://github.com/jc-SpaceXp/cNES/blob/e3a41dda4e0a18b7ed6da09d54b03ae77a6672d3/src/emu.c#L249-L272