Skip to content

Commit

Permalink
Disabled the filters when paused (#328).
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Oct 23, 2023
1 parent 24451d6 commit cbde861
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/core/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "recent_roms.h"
#include "../../c++/crc/crc.h"
#include "gui.h"
#include "video/effects/pause.h"
#include "video/effects/tv_noise.h"
#if defined (FULLSCREEN_RESFREQ)
#include "video/gfx_monitor.h"
Expand Down Expand Up @@ -644,6 +645,7 @@ BYTE emu_turn_on(void) {
void emu_pause(BYTE mode) {
if (mode) {
if (++info.pause == 1) {
pause_effect.frames = PAUSE_EFFECT_FRAMES;
gui_egds_start_pause();
}
} else {
Expand Down
32 changes: 21 additions & 11 deletions src/video/d3d9/gfx_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
*/

#include "video/gfx.h"
#include "video/effects/pause.h"
#include "d3d9.h"
#include "gui.h"
#include "ppu.h"
#include "info.h"

BYTE gfx_api_init(void) {
return (d3d9_init());
Expand Down Expand Up @@ -77,22 +79,30 @@ void gfx_api_apply_filter(BYTE nidx) {
scrtex = &d3d9.screen.tex[d3d9.screen.index];

if (scrtex->offscreen) {
D3DLOCKED_RECT lrect;
BYTE apply = !info.pause;

gfx.frame.filtered = nes[nidx].p.ppu_screen.rd->frame;

// lock della surface in memoria
IDirect3DSurface9_LockRect(scrtex->offscreen, &lrect, NULL, D3DLOCK_DISCARD);
if (info.pause && pause_effect.frames) {
pause_effect.frames--;
apply = TRUE;
}
if (apply) {
D3DLOCKED_RECT lrect;

// lock della surface in memoria
IDirect3DSurface9_LockRect(scrtex->offscreen, &lrect, NULL, D3DLOCK_DISCARD);

// applico l'effetto
gfx.filter.data.pitch = lrect.Pitch;
gfx.filter.data.pix = lrect.pBits;
gfx.filter.data.width = scrtex->rect.base.w;
gfx.filter.data.height = scrtex->rect.base.h;
gfx.filter.func(nidx);
// applico l'effetto
gfx.filter.data.pitch = lrect.Pitch;
gfx.filter.data.pix = lrect.pBits;
gfx.filter.data.width = scrtex->rect.base.w;
gfx.filter.data.height = scrtex->rect.base.h;
gfx.filter.func(nidx);

// unlock della surface in memoria
IDirect3DSurface9_UnlockRect(scrtex->offscreen);
// unlock della surface in memoria
IDirect3DSurface9_UnlockRect(scrtex->offscreen);
}
}
}
void gfx_api_control_changed_adapter(void *monitor) {
Expand Down
9 changes: 5 additions & 4 deletions src/video/effects/pause.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
_pause_effect pause_effect;

BYTE pause_init(void) {
uint32_t *palette;
_color_RGB pRGB[NUM_COLORS];
WORD i;
_color_RGB pRGB[NUM_COLORS] = { 0 };
uint32_t *palette = NULL;

pause_effect.frames = 0;

if (!(pause_effect.palette = malloc(NUM_COLORS * sizeof(uint32_t)))) {
log_error(uL("pause;unable to allocate the palette"));
Expand All @@ -42,7 +43,7 @@ BYTE pause_init(void) {

ntsc_rgb_modifier((nes_ntsc_t *)pause_effect.ntsc, (BYTE *)pRGB, 0x1A, -0x0A, -0x0A, -0x30);

for (i = 0; i < NUM_COLORS; i++) {
for (int i = 0; i < NUM_COLORS; i++) {
palette[i] = gfx_color(255, pRGB[i].r, pRGB[i].g, pRGB[i].b);
}

Expand Down
5 changes: 5 additions & 0 deletions src/video/effects/pause.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@

#include "common.h"

enum _pause_effect_misc {
PAUSE_EFFECT_FRAMES = 10
};

typedef struct _pause_effect {
void *palette;
void *ntsc;
int frames;
} _pause_effect;

extern _pause_effect pause_effect;
Expand Down
2 changes: 2 additions & 0 deletions src/video/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, B
if (info.on_cfg) {
info.on_cfg = FALSE;
}

pause_effect.frames = info.pause ? PAUSE_EFFECT_FRAMES : 0;
}
void gfx_draw_screen(BYTE nidx) {
BYTE monitor = emu_active_nidx();
Expand Down
20 changes: 15 additions & 5 deletions src/video/opengl/gfx_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
*/

#include "video/gfx.h"
#include "video/effects/pause.h"
#include "opengl.h"
#include "gui.h"
#include "ppu.h"
#include "info.h"

#if defined (_WIN32)
HMONITOR monitor_in_use;
Expand Down Expand Up @@ -54,14 +56,22 @@ void gfx_api_overlay_blit(void *surface, _gfx_rect *rect, double device_pixel_ra
glPixelStoref(GL_UNPACK_ROW_LENGTH, 0);
}
void gfx_api_apply_filter(BYTE nidx) {
BYTE apply = !info.pause;

gfx.frame.filtered = nes[nidx].p.ppu_screen.rd->frame;

// applico l'effetto desiderato
gfx.filter.data.pitch = opengl.surface.pitch;
gfx.filter.data.pix = opengl.surface.pixels;
gfx.filter.data.width = opengl.surface.w;
gfx.filter.data.height = opengl.surface.h;
gfx.filter.func(nidx);
if (info.pause && pause_effect.frames) {
pause_effect.frames--;
apply = TRUE;
}
if (apply) {
gfx.filter.data.pitch = opengl.surface.pitch;
gfx.filter.data.pix = opengl.surface.pixels;
gfx.filter.data.width = opengl.surface.w;
gfx.filter.data.height = opengl.surface.h;
gfx.filter.func(nidx);
}
}
void gfx_api_control_changed_adapter(UNUSED(void *monitor)) {
#if defined (_WIN32)
Expand Down

0 comments on commit cbde861

Please sign in to comment.