Adding doRendering flag to disable audio/picture rendering for performance

This commit is contained in:
Sergio Martin 2024-01-13 11:10:42 +01:00
parent 86ffc7fce7
commit 52bb0987e3
7 changed files with 63 additions and 40 deletions

View File

@ -38,6 +38,7 @@ Nes_Core::Nes_Core() : ppu( this )
mapper = NULL;
memset( &nes, 0, sizeof nes );
memset( &joypad, 0, sizeof joypad );
_doRendering = true;
}
const char * Nes_Core::init()
@ -510,14 +511,17 @@ nes_time_t Nes_Core::emulate_frame()
clock_ = cpu_time_offset;
// TODO: clean this fucking mess up
impl->apu.run_until_( emulate_frame_() );
auto t0 = emulate_frame_();
if (_doRendering == true) impl->apu.run_until_( t0 );
clock_ = cpu_time_offset;
impl->apu.run_until_( cpu_time() );
auto t1 = cpu_time();
if (_doRendering == true) impl->apu.run_until_( t1 );
nes_time_t ppu_frame_length = ppu.frame_length();
nes_time_t length = cpu_time();
nes.timestamp = ppu.end_frame( length );
mapper->end_frame( length );
impl->apu.end_frame( ppu_frame_length );
disable_rendering();

View File

@ -20,6 +20,9 @@ public:
Nes_Core();
~Nes_Core();
// Flag to enable/disable rendering
bool _doRendering;
const char * init();
const char * open( Nes_Cart const* );
void reset( bool full_reset = true, bool erase_battery_ram = false );

View File

@ -140,8 +140,11 @@ const char * Nes_Emu::emulate_frame( int joypad1, int joypad2 )
emu.ppu.host_pixels = NULL;
if (emu._doRendering == true)
{
unsigned changed_count = sound_buf->channels_changed_count();
bool new_enabled = (frame_ != NULL);
if ( sound_buf_changed_count != changed_count || sound_enabled != new_enabled )
{
sound_buf_changed_count = changed_count;
@ -177,10 +180,13 @@ const char * Nes_Emu::emulate_frame( int joypad1, int joypad2 )
f->joypad_read_count = emu.joypad_read_count;
f->burst_phase = emu.ppu.burst_phase;
f->pitch = emu.ppu.host_row_bytes;
if (emu.ppu.host_pixels != NULL)
f->pixels = emu.ppu.host_pixels + f->left;
}
else
f->pixels = NULL;
{
emu.ppu.max_palette_size = 0;
emu.emulate_frame();
}
}
else
{

View File

@ -42,6 +42,9 @@ public:
const uint8_t* getHostPixels () const { return emu.ppu.host_pixels; }
void enableRendering() { emu._doRendering = true; }
void disableRendering() { emu._doRendering = false; }
// Basic emulation
// Emulate one video frame using joypad1 and joypad2 as input. Afterwards, image

View File

@ -64,6 +64,7 @@ int main(int argc, char *argv[])
// Printing provided parameters
printw("[] Rom File Path: '%s'\n", romFilePath.c_str());
printw("[] Sequence File Path: '%s'\n", sequenceFilePath.c_str());
printw("[] Sequence Length: %lu\n", sequence.size());
printw("[] State File Path: '%s'\n", stateFilePath.empty() ? "<Boot Start>" : stateFilePath.c_str());
printw("[] Generating Sequence...\n");

View File

@ -57,8 +57,11 @@ int main(int argc, char *argv[])
// Creating emulator instance
auto e = EmuInstance(romFilePath, initialStateFilePath);
// Disable rendering
e.getInternalEmulator()->disableRendering();
// Getting initial hash
auto initialHash = e.getStateHash();
printf("[] Initial State Hash: 0x%lX%lX\n", initialHash.first, initialHash.second);
// Getting state size
const auto stateSize = e.getStateSize();
@ -98,6 +101,7 @@ int main(int argc, char *argv[])
printf("[] Verification State File: '%s'\n", verificationStateFilePath.c_str());
printf("[] Sequence File: '%s'\n", sequenceFilePath.c_str());
printf("[] Sequence Length: %lu\n", sequenceLength);
printf("[] Initial State Hash: 0x%lX%lX\n", initialHash.first, initialHash.second);
printf("[] State Size: %lu bytes\n", stateSize);
printf("[] Running Test...\n");

View File

@ -1,5 +1,6 @@
nomalloc = environment({'MALLOC_PERTURB_': '0'})
subdir('arkanoid')
subdir('castlevania1')
subdir('superOffroad')
subdir('princeOfPersia')
@ -8,3 +9,4 @@ subdir('ninjaGaiden2')
subdir('ironSword')
subdir('solarJetman')
subdir('tennis')
subdir('nigelMansell')