m4
src/libcpu/libcpu.a
src/libcpu/m68kmake
+src/libframerate/libframerate.a
src/libsdl/libsdl.a
src/libvideo/libvideo.a
src/libsound/libsound.a
AC_OUTPUT(
src/libcpu/Makefile
+ src/libframerate/Makefile
src/libvideo/Makefile
src/libsound/Makefile
src/libjoystick/Makefile
SUBDIRS = \
libcpu \
+ libframerate \
libvideo \
libjoystick \
libkeyboard \
--- /dev/null
+AM_CPPFLAGS = -Wall -Wextra -g $(all_includes)
+
+noinst_LIBRARIES = libframerate.a
+
+libframerate_a_SOURCES = \
+ framerate.c
+
--- /dev/null
+/* frame rate measurement
+ *
+ * (C) 2018 by Andreas Eversberg <jolly@eversberg.eu>
+ * All Rights Reserved
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include "../libsdl/sdl.h"
+#include "framerate.h"
+
+#define MAX_HISTORY 60
+
+double vbl_duration = 1.0 / 60.0;
+static uint32_t ticks_history[MAX_HISTORY];
+static int ticks_count = 0;
+
+void framerate_measure(void)
+{
+ uint32_t ticks = ticks_sdl();
+
+ /* wait some ticks until to get better average when we start */
+ if (ticks_count >= 10 || ticks_count == MAX_HISTORY)
+ vbl_duration = (double)((uint32_t)(ticks - ticks_history[0])) / (double)ticks_count / 1000.0;
+
+ if (ticks_count == MAX_HISTORY) {
+ memmove(ticks_history, ticks_history + 1, sizeof(ticks_history[0]) * (MAX_HISTORY - 1));
+ ticks_count--;
+ }
+ ticks_history[ticks_count++] = ticks;
+}
+
--- /dev/null
+
+extern double vbl_duration;
+
+void framerate_measure(void);
+
#include "sdl.h"
#include "opengl.h"
+#include <SDL2/SDL.h>
#define GL3_PROTOTYPES 1
#include <GL/glew.h>
}
}
+uint32_t ticks_sdl(void)
+{
+ return SDL_GetTicks();
+}
int event_sdl(void);
void swap_sdl(void);
void exit_sdl(void);
+uint32_t ticks_sdl(void);
$(COMMON_LA) \
$(top_builddir)/src/mercenary/libmain.a \
$(top_builddir)/src/libcpu/libcpu.a \
+ $(top_builddir)/src/libframerate/libframerate.a \
$(top_builddir)/src/libvideo/libvideo.a \
$(top_builddir)/src/libsound/libsound.a \
$(top_builddir)/src/libjoystick/libjoystick.a \
$(COMMON_LA) \
$(top_builddir)/src/mercenary/libmain.a \
$(top_builddir)/src/libcpu/libcpu.a \
+ $(top_builddir)/src/libframerate/libframerate.a \
$(top_builddir)/src/libvideo/libvideo.a \
$(top_builddir)/src/libsound/libsound.a \
$(top_builddir)/src/libjoystick/libjoystick.a \
#include "../libsdl/print.h"
#include "../libcpu/m68k.h"
#include "../libcpu/execute.h"
+#include "../libframerate/framerate.h"
#include "../libvideo/video.h"
#include "../libsound/sound.h"
#include "../libjoystick/joystick.h"
/* render result on window */
while (!quit) {
+printf("frame rate: %.6f\n", 1.0 / vbl_duration);
/* handle SDL events */
rc = event_sdl();
if (rc)
opengl_viewport_legacy(debug_opengl);
opengl_blit_legacy(image, config_video_filter);
}
+ /* wait for VBL and show */
swap_sdl();
+ /* measure frame rate */
+ framerate_measure();
/* STEP 3: execute interrupt at rate of 50Hz, render sound */
current_time = SDL_GetTicks();