FPS checking.
This commit is contained in:
parent
160f940d70
commit
4bc7fbd097
6
alsa.c
6
alsa.c
|
@ -142,8 +142,10 @@ static bool __alsa_stop(void *data)
|
|||
static void __alsa_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
alsa_t *alsa = data;
|
||||
snd_pcm_nonblock(alsa->pcm, state);
|
||||
alsa->nonblock = state;
|
||||
if (snd_pcm_nonblock(alsa->pcm, state) < 0)
|
||||
fprintf(stderr, "SSNES [ERROR]: Could not set PCM to non-blocking. Will not be able to fast-forward.\n");
|
||||
else
|
||||
alsa->nonblock = state;
|
||||
}
|
||||
|
||||
static bool __alsa_start(void *data)
|
||||
|
|
2
config.h
2
config.h
|
@ -92,7 +92,7 @@ static const char* audio_device = NULL;
|
|||
static const int out_latency = 64;
|
||||
|
||||
// Defines the quality (and cpu reqirements) of samplerate conversion.
|
||||
#define SAMPLERATE_QUALITY SRC_SINC_FASTEST
|
||||
#define SAMPLERATE_QUALITY SRC_LINEAR
|
||||
|
||||
|
||||
|
||||
|
|
32
gl.c
32
gl.c
|
@ -21,6 +21,7 @@
|
|||
#include <stdint.h>
|
||||
#include "libsnes.hpp"
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
static GLuint texture;
|
||||
static uint8_t *gl_buffer;
|
||||
|
@ -143,6 +144,12 @@ static void GLFWCALL resize(int width, int height)
|
|||
glLoadIdentity();
|
||||
}
|
||||
|
||||
static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames)
|
||||
{
|
||||
float time = new_tv->tv_sec - tv->tv_sec + (new_tv->tv_usec - tv->tv_usec)/1000000.0;
|
||||
return frames/time;
|
||||
}
|
||||
|
||||
static bool gl_frame(void *data, const uint16_t* frame, int width, int height)
|
||||
{
|
||||
(void)data;
|
||||
|
@ -175,6 +182,31 @@ static bool gl_frame(void *data, const uint16_t* frame, int width, int height)
|
|||
|
||||
glEnd();
|
||||
|
||||
// Shows FPS in taskbar.
|
||||
static int frames = 0;
|
||||
static struct timeval tv;
|
||||
struct timeval new_tv;
|
||||
|
||||
if (frames == 0)
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
if ((frames % 60) == 0 && frames > 0)
|
||||
{
|
||||
gettimeofday(&new_tv, NULL);
|
||||
struct timeval tmp_tv = {
|
||||
.tv_sec = tv.tv_sec,
|
||||
.tv_usec = tv.tv_usec
|
||||
};
|
||||
gettimeofday(&tv, NULL);
|
||||
char tmpstr[256] = {0};
|
||||
|
||||
float fps = tv_to_fps(&tmp_tv, &new_tv, 60);
|
||||
|
||||
snprintf(tmpstr, sizeof(tmpstr) - 1, "SSNES || FPS: %6.1f || Frames: %d", fps, frames);
|
||||
glfwSetWindowTitle(tmpstr);
|
||||
}
|
||||
frames++;
|
||||
|
||||
glfwSwapBuffers();
|
||||
|
||||
return true;
|
||||
|
|
7
oss.c
7
oss.c
|
@ -111,10 +111,13 @@ static bool __oss_start(void *data)
|
|||
static void __oss_set_nonblock_state(void *data, bool state)
|
||||
{
|
||||
int *fd = data;
|
||||
int rc;
|
||||
if (state)
|
||||
fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) | O_NONBLOCK);
|
||||
rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) | O_NONBLOCK);
|
||||
else
|
||||
fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) & (~O_NONBLOCK));
|
||||
rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) & (~O_NONBLOCK));
|
||||
if (rc != 0)
|
||||
fprintf(stderr, "SSNES [ERROR]: Could not set nonblocking on OSS file descriptor. Will not be able to fast-forward.\n");
|
||||
}
|
||||
|
||||
static void __oss_free(void *data)
|
||||
|
|
Loading…
Reference in New Issue