MitchellSternke / SuperMarioBros-C

An attempt to translate the original Super Mario Bros. for the NES to readable C/C++
625 stars 70 forks source link

No framerate limit and minor compilation issues #1

Closed khedoros closed 6 years ago

khedoros commented 6 years ago

From the source directory, I built the game like this using gcc 4.8.5 and SDL 2.0.3:

g++ -std=c++11 Main.cpp Emulation/*.cpp SMB/*.cpp Util/*.cpp -o smb -lSDL2

First, the compilation errors:

The game itself ran insanely fast. Granted, I didn't look very hard, but I didn't see any framerate limit code.

In Main.cpp, right before while (running), I added:

int program_start = SDL_GetTicks();
int frame = 0;

Inside that main loop block, after the call to SDL_RenderPresent(renderer);, I added the following:

int now = SDL_GetTicks();
int delay = program_start + int(double(frame) * double(1000) / double(60)) - now;
if (delay > 0)
{
    SDL_Delay(delay);
}
frame++;

It's not super elegant, but it works pretty well to correct the framerate to 60FPS.

MitchellSternke commented 6 years ago

Hey @khedoros , thanks for the feedback.

These both seem like valid concerns. Differences in our software/hardware are probably the root cause :smile:

Feel free to open a pull request. I'd be happy to take these changes.