From 9dbb5a1566cf0967a40e5f80f498b44f1b9883b5 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 10 Apr 2023 16:57:45 +0200 Subject: [PATCH] further fixes to render ordering --- src/corelib/render.c | 16 ++++++++++++---- src/corelib/render.h | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/corelib/render.c b/src/corelib/render.c index 39539d9..49fb7ff 100644 --- a/src/corelib/render.c +++ b/src/corelib/render.c @@ -147,6 +147,7 @@ void insert_drawcmd_at(size_t index, const drawcmd_t* cmd) { drawcmd_t* insertpoint = g_drawdata + index; drawcmd_t* dest = insertpoint + 1; size_t size = (size_t)(g_drawdata_endptr - g_drawdata); + ++g_drawdata_endptr; if(size > index) { size_t count = (size - index); if(size > 0) @@ -154,29 +155,36 @@ void insert_drawcmd_at(size_t index, const drawcmd_t* cmd) { memmove(dest, insertpoint, count*sizeof(drawcmd_t)); } } - ++g_drawdata_endptr; memcpy(insertpoint, cmd, sizeof(drawcmd_t)); insertpoint->ui = _render_mode == 1; } void draw(const drawcmd_t* cmd) { + if(g_drawdata_endptr == g_drawdata) { + insert_drawcmd_at(0, cmd); + } long top = (size_t)(g_drawdata_endptr - g_drawdata), bot = 0, med = 0; - int ui = _render_mode == 1; if(top != bot) { while(bot <= top) { med = floor((float)(top + bot) / 2); - if(g_drawdata[med].ui < ui || g_drawdata[med].depth > cmd->depth) { + if(g_drawdata[med].depth > cmd->depth) { bot = med+1; - } else if(g_drawdata[med].ui > ui || g_drawdata[med].depth < cmd->depth) { + } else if(g_drawdata[med].depth < cmd->depth) { top = med-1; } else { break; } } } + size_t count = (g_drawdata_endptr - g_drawdata); + int diff = g_drawdata[med].depth - cmd->depth; + while(diff > 0 && med < count) { + med++; + diff = g_drawdata[med].depth - cmd->depth; + } insert_drawcmd_at(med, cmd); } diff --git a/src/corelib/render.h b/src/corelib/render.h index b0c2e7e..73e117e 100644 --- a/src/corelib/render.h +++ b/src/corelib/render.h @@ -9,6 +9,8 @@ extern "C" { typedef int depth_t; +extern int d_debug_next_frame; + typedef enum drawcmdtype_t { DRAWCMDTYPE_MIN = -1, DRAWCMDTYPE_SPRITE = 0,