further fixes to render ordering

pull/1/head
Sara 2023-04-10 16:57:45 +02:00
parent 3e8eef4200
commit 9dbb5a1566
2 changed files with 14 additions and 4 deletions

View File

@ -147,6 +147,7 @@ void insert_drawcmd_at(size_t index, const drawcmd_t* cmd) {
drawcmd_t* insertpoint = g_drawdata + index; drawcmd_t* insertpoint = g_drawdata + index;
drawcmd_t* dest = insertpoint + 1; drawcmd_t* dest = insertpoint + 1;
size_t size = (size_t)(g_drawdata_endptr - g_drawdata); size_t size = (size_t)(g_drawdata_endptr - g_drawdata);
++g_drawdata_endptr;
if(size > index) { if(size > index) {
size_t count = (size - index); size_t count = (size - index);
if(size > 0) 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)); memmove(dest, insertpoint, count*sizeof(drawcmd_t));
} }
} }
++g_drawdata_endptr;
memcpy(insertpoint, cmd, sizeof(drawcmd_t)); memcpy(insertpoint, cmd, sizeof(drawcmd_t));
insertpoint->ui = _render_mode == 1; insertpoint->ui = _render_mode == 1;
} }
void draw(const drawcmd_t* cmd) { 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), long top = (size_t)(g_drawdata_endptr - g_drawdata),
bot = 0, bot = 0,
med = 0; med = 0;
int ui = _render_mode == 1;
if(top != bot) { if(top != bot) {
while(bot <= top) { while(bot <= top) {
med = floor((float)(top + bot) / 2); 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; 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; top = med-1;
} else { } else {
break; 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); insert_drawcmd_at(med, cmd);
} }

View File

@ -9,6 +9,8 @@ extern "C" {
typedef int depth_t; typedef int depth_t;
extern int d_debug_next_frame;
typedef enum drawcmdtype_t { typedef enum drawcmdtype_t {
DRAWCMDTYPE_MIN = -1, DRAWCMDTYPE_MIN = -1,
DRAWCMDTYPE_SPRITE = 0, DRAWCMDTYPE_SPRITE = 0,