Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
erysdren committed Apr 28, 2024
1 parent e9808e7 commit 9bc8152
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
36 changes: 22 additions & 14 deletions examples/brdemo/brdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

#include "brdemo.h"

static uint8_t primitive_heap[1500 * 1024];
static br_order_table *order_table = NULL;
static br_uint_64 then = 0;
static br_uint_64 now = 0;
static br_demo demo;

/* begin hook */
void _BrBeginHook(void)
{
Expand All @@ -26,10 +20,15 @@ void _BrEndHook(void)
}

/* initialize program */
int BrDemo(const char *title, int screen_w, int screen_h)
int BrDemo(const char *title, int w, int h, br_demo_cbfn init, br_demo_cbfn tick, br_demo_cbfn quit)
{
static uint8_t primitive_heap[1500 * 1024];
br_error r = BRE_OK;
SDL_Event event;
br_demo demo;
br_order_table *order_table = NULL;
br_uint_64 then = 0;
br_uint_64 now = 0;

/* x11 hint */
SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");
Expand All @@ -42,8 +41,8 @@ int BrDemo(const char *title, int screen_w, int screen_h)

/* begin device */
r = BrDevBeginVar(&screen, "SDL2",
BRT_WIDTH_I32, screen_w,
BRT_HEIGHT_I32, screen_h,
BRT_WIDTH_I32, w,
BRT_HEIGHT_I32, h,
BRT_PIXEL_TYPE_U8, BR_PMT_RGB_888,
BRT_WINDOW_NAME_CSTR, title,
BRT_HIDPI_B, BR_TRUE,
Expand Down Expand Up @@ -83,9 +82,12 @@ int BrDemo(const char *title, int screen_w, int screen_h)
order_table->max_z = ((br_camera *)demo.camera->type_data)->yon_z;

/* do user hook */
r = BrDemoInit(&demo);
if (r != BRE_OK)
return 1;
if (init)
{
r = init(&demo);
if (r != BRE_OK)
return 1;
}

/* start counting time */
then = SDL_GetTicks64();
Expand Down Expand Up @@ -130,14 +132,20 @@ int BrDemo(const char *title, int screen_w, int screen_h)
then = now;

/* do user hook */
r = BrDemoTick(&demo);
if (tick)
{
r = tick(&demo);
if (r != BRE_OK)
break;
}

/* push to screen */
BrPixelmapDoubleBuffer(demo.screen, demo.colour);
}

/* do user hook */
r = BrDemoQuit(&demo);
if (quit)
r = quit(&demo);

/* shutdown renderer */
BrRendererEnd();
Expand Down
4 changes: 3 additions & 1 deletion examples/brdemo/brdemo.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ typedef struct br_demo {
br_pixelmap *depth;
} br_demo;

typedef br_error br_demo_cbfn(br_demo *demo);

/*
* Demo entry point
*/

int BrDemo(const char *title, int screen_w, int screen_h);
int BrDemo(const char *title, int w, int h, br_demo_cbfn init, br_demo_cbfn tick, br_demo_cbfn quit);

/*
* User must implement these!
Expand Down

0 comments on commit 9bc8152

Please sign in to comment.