Avoid qsort() in rmodels.c
This commit is contained in:
parent
ea82291c90
commit
dc1bd559fd
1 changed files with 13 additions and 11 deletions
|
@ -5567,15 +5567,6 @@ static Model LoadVOX(const char *fileName)
|
||||||
unsigned char *m3d_loaderhook(char *fn, unsigned int *len) { return LoadFileData((const char *)fn, (int *)len); }
|
unsigned char *m3d_loaderhook(char *fn, unsigned int *len) { return LoadFileData((const char *)fn, (int *)len); }
|
||||||
void m3d_freehook(void *data) { UnloadFileData((unsigned char *)data); }
|
void m3d_freehook(void *data) { UnloadFileData((unsigned char *)data); }
|
||||||
|
|
||||||
// Comparison function for qsort
|
|
||||||
static int m3d_compare_faces(const void *a, const void *b)
|
|
||||||
{
|
|
||||||
m3df_t *fa = (m3df_t *)a;
|
|
||||||
m3df_t *fb = (m3df_t *)b;
|
|
||||||
|
|
||||||
return (fa->materialid - fb->materialid);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load M3D mesh data
|
// Load M3D mesh data
|
||||||
static Model LoadM3D(const char *fileName)
|
static Model LoadM3D(const char *fileName)
|
||||||
{
|
{
|
||||||
|
@ -5623,8 +5614,19 @@ static Model LoadM3D(const char *fileName)
|
||||||
// We always need a default material, so we add +1
|
// We always need a default material, so we add +1
|
||||||
model.materialCount++;
|
model.materialCount++;
|
||||||
|
|
||||||
// Sort faces by material.
|
// Sort faces by material (insertion)
|
||||||
qsort(m3d->face, m3d->numface, sizeof(m3df_t), m3d_compare_faces);
|
for (i = 1; i < m3d->numface; i++)
|
||||||
|
{
|
||||||
|
m3df_t key = m3d->face[i];
|
||||||
|
j = i - 1;
|
||||||
|
|
||||||
|
while (j >= 0 && m3d->face[j].materialid > key.materialid)
|
||||||
|
{
|
||||||
|
m3d->face[j+1] = m3d->face[j];
|
||||||
|
j = j - 1;
|
||||||
|
}
|
||||||
|
m3d->face[j+1] = key;
|
||||||
|
}
|
||||||
|
|
||||||
model.meshes = (Mesh *)RL_CALLOC(model.meshCount, sizeof(Mesh));
|
model.meshes = (Mesh *)RL_CALLOC(model.meshCount, sizeof(Mesh));
|
||||||
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
|
model.meshMaterial = (int *)RL_CALLOC(model.meshCount, sizeof(int));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue