Skip to content

Instantly share code, notes, and snippets.

@emoon
Created September 30, 2012 20:43
Show Gist options
  • Save emoon/3808389 to your computer and use it in GitHub Desktop.
Save emoon/3808389 to your computer and use it in GitHub Desktop.
typedef struct Poly
{
int x, y, z, .. // etc values
struct Poly* next;
} Poly;
Poly* g_sortArray[MaxBuckets];
static void addPoly(Poly* poly, int z)
{
poly->next = 0;
// must make sure Z is within range here otherwise it can go bad (memory trashing)
Poly* sortPoly = &g_sortArray[z];
if (!sortPoly)
g_sortArray[z] = poly;
else
sortPoly->next = poly;
}
void updateScene()
{
memset(g_sortArray, 0, sizeof(Poly*) * MaxBuckets);
// rotate, etc stuff here
for (poly in polys)
addPoly(poly, Poly_calcZ(poly));
renderPolys();
}
void renderPolys()
{
for (uint i = 0; i < MaxBuckets; ++i)
{
const Poly* poly = &g_sortArray[i];
if (!poly)
continue;
while (poly)
{
drawPoly(poly);
poly = poly->next;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment