Skip to content

Commit

Permalink
Threaded screen refresh (tiny FPS increase)
Browse files Browse the repository at this point in the history
  • Loading branch information
masterfeizz committed Jun 21, 2017
1 parent 5172f67 commit 021552c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,5 +1,7 @@
build/
*.cia
*.3dsx
*.smdh

# Prerequisites
*.d
Expand Down
65 changes: 48 additions & 17 deletions ctr/swimp_ctr.c
Expand Up @@ -22,62 +22,93 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../ref_soft/r_local.h"
#include <3ds.h>

#define STACKSIZE 1024

Thread refresh_thread;
Handle refresh_request;

int run_thread = 1;

uint16_t *framebuffer;
uint8_t *swap_buffer;
uint16_t d_8to16table[256];

void SWimp_ThreadFunc(void *arg)
{
while(run_thread)
{
svcWaitSynchronization(refresh_request, U64_MAX);

for(int x=0; x<400; x++)
for(int y=0; y<240;y++)
framebuffer[(x*240 + (239 -y))] = d_8to16table[swap_buffer[y*400 + x]];

gfxFlushBuffers();
gfxSwapBuffers();

svcClearEvent(refresh_request);
}
}

void SWimp_BeginFrame( float camera_separation )
{
}

void SWimp_EndFrame (void)
{
int x, y;
for(x=0; x<400; x++)
{
for(y=0; y<240;y++)
{
framebuffer[(x*240 + (239 -y))] = d_8to16table[vid.buffer[y*400 + x]];
}
}
framebuffer = (uint16_t*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
memcpy(swap_buffer, vid.buffer, 400 * 240);

svcSignalEvent(refresh_request);
}

int SWimp_Init( void *hInstance, void *wndProc )
int SWimp_Init( void *hInstance, void *wndProc )
{
framebuffer = (uint16_t*)gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
svcCreateEvent(&refresh_request,0);
refresh_thread = threadCreate(SWimp_ThreadFunc, 0, STACKSIZE, 0x18, 1, true);
return 0;
}

void SWimp_SetPalette( const unsigned char *palette)
void SWimp_SetPalette( const unsigned char *palette)
{
int i;
unsigned char r, g, b;

if(palette==NULL)
return;

for(i = 0; i < 256; i++){
for(i = 0; i < 256; i++)
{
r = palette[i*4+0];
g = palette[i*4+1];
b = palette[i*4+2];
d_8to16table[i] = RGB8_to_565(r,g,b);
}
}

void SWimp_Shutdown( void )
void SWimp_Shutdown( void )
{
run_thread = 0;

svcSignalEvent(refresh_request);
threadJoin(refresh_thread, U64_MAX);
svcCloseHandle(refresh_request);

free(swap_buffer);
free(vid.buffer);
}

rserr_t SWimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
rserr_t SWimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
{
vid.height = 240;
vid.width = 400;
vid.width = 400;
vid.rowbytes = 400;
vid.buffer = malloc(400*240*8);
vid.buffer = malloc(400 * 240);
swap_buffer = malloc(400 * 240);

return rserr_ok;
}

void SWimp_AppActivate( qboolean active )
void SWimp_AppActivate( qboolean active )
{
}
4 changes: 3 additions & 1 deletion ctr/sys_ctr.c
Expand Up @@ -378,10 +378,12 @@ int main (int argc, char **argv)
int time, oldtime, newtime;

romfsInit();

APT_SetAppCpuTimeLimit(30);
osSetSpeedupEnable(true);

gfxInit(GSP_RGB565_OES,GSP_RGB565_OES,false);
gfxSetDoubleBuffering(GFX_TOP, false);
gfxSetDoubleBuffering(GFX_TOP, true);
gfxSetDoubleBuffering(GFX_BOTTOM, false);
gfxSwapBuffersGpu();

Expand Down

0 comments on commit 021552c

Please sign in to comment.