fxengine/src/fxengine.c

111 lines
1.9 KiB
C

#define GINT_NEED_VRAM
#include <gint/display.h>
#include <stdint.h>
#include <fxengine/fxengine.h>
#include <gint/std/stdlib.h>
#include <gint/std/string.h>
#include <stdbool.h>
#include <fxengine/renderlist.h>
#include <fxengine/render/buffer.h>
#ifdef USE_LIBLOG
#include <liblog.h>
#endif
// FPS count
#ifdef USE_LIBPROF
#include <libprof.h>
static uint32_t frame_interval_min=1000000;
static uint32_t frame_interval_max=1;
static uint32_t fps=0;
uint32_t fe_get_fps()
{
return fps;
}
#endif
// Triple buffering
#define BUFFER_SIZE 256
static uint32_t triple_buffering_area[2*BUFFER_SIZE]; // 2 buffers supplémentaires
static uint32_t * const temp_buffers[2] = {&triple_buffering_area[0], &triple_buffering_area[BUFFER_SIZE]};
static uint32_t * gint_vram=0;
static uint32_t working_buffer=0;
static void check_vram()
{
if (gint_vram==0)
gint_vram=vram;
}
void fe_callback_start()
{
vram=gint_vram;
}
void fe_callback_end()
{
vram=temp_buffers[working_buffer];
}
void fe_draw()
{
memcpy(gint_vram, temp_buffers[1-working_buffer], sizeof(uint32_t)*BUFFER_SIZE);
}
void switch_frame()
{
working_buffer=1-working_buffer;
vram=temp_buffers[working_buffer];
dclear(C_WHITE);
}
static volatile bool quit=true;
void fe_load()
{
#ifdef USE_LIBLOG
ll_send("fxEngine loader :\n");
#endif
check_vram();
#ifdef USE_LIBLOG
ll_send(">> Got vram\n");
#endif
fe_callback_end();
#ifdef USE_LIBLOG
ll_send(">> Started triple \n buffering\n");
#endif
quit=false;
#ifdef USE_LIBLOG
ll_send("run fxEng. thread\n");
#endif
while (1)
{
fe_clear_zbuffer();
fe_render();
#ifdef USE_LIBLOG
ll_send("Frame rendered.\n");
#endif
switch_frame();
if (quit)
break;
}
#ifdef USE_LIBLOG
ll_send("ended fxEngine.\n");
#endif
// Free some malloc
//// as object list
}
void fe_quit()
{
quit=1;
}