2017-01-21 17:27:46 +01:00
|
|
|
|
// Class CFifo, gestion d'une liste en fifo
|
|
|
|
|
|
2017-01-21 23:43:44 +01:00
|
|
|
|
#include <stdlib.h>
|
2017-02-12 00:51:38 +01:00
|
|
|
|
#include <SDL2/SDL_stdinc.h>
|
2017-01-21 17:27:46 +01:00
|
|
|
|
#include "fifo.h"
|
|
|
|
|
|
|
|
|
|
|
2017-02-12 00:51:38 +01:00
|
|
|
|
// gestion d'une pile class<73>e en valeur croissantes
|
|
|
|
|
// typiquement reprend les coordonn<6E>es les plus proches
|
2017-01-21 17:27:46 +01:00
|
|
|
|
// du but en premier lieu
|
|
|
|
|
|
2017-02-12 13:14:22 +01:00
|
|
|
|
CPileTriee::CPileTriee (Sint32 taille)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-12 13:14:22 +01:00
|
|
|
|
m_taille = taille;
|
|
|
|
|
m_max = m_out = 0;
|
|
|
|
|
m_data = (Element *) malloc (sizeof (Element) * taille);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CPileTriee::~CPileTriee()
|
|
|
|
|
{
|
2017-02-12 13:14:22 +01:00
|
|
|
|
free (m_data);
|
2017-01-21 17:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-12 00:51:38 +01:00
|
|
|
|
Sint32 CPileTriee::get()
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-12 13:14:22 +01:00
|
|
|
|
if (m_out == m_max)
|
|
|
|
|
return -1;
|
|
|
|
|
Sint32 val = m_data [m_out].pos;
|
|
|
|
|
m_out++;
|
|
|
|
|
if (m_out >= m_taille)
|
|
|
|
|
m_out = 0;
|
|
|
|
|
return val;
|
|
|
|
|
}
|
2017-01-21 17:27:46 +01:00
|
|
|
|
|
2017-02-12 13:14:22 +01:00
|
|
|
|
void CPileTriee::put (Sint32 pos, Sint32 dist)
|
2017-01-21 17:27:46 +01:00
|
|
|
|
{
|
2017-02-12 13:14:22 +01:00
|
|
|
|
Sint32 i = m_out;
|
|
|
|
|
Sint32 p, d, m;
|
|
|
|
|
|
|
|
|
|
while (i != m_max)
|
|
|
|
|
{
|
|
|
|
|
// le point est-il plus proche que celui-l<> ?
|
|
|
|
|
if (dist < m_data[i].dist)
|
|
|
|
|
{
|
|
|
|
|
// oui, insert et d<>cale le suivant
|
|
|
|
|
p = m_data[i].pos;
|
|
|
|
|
d = m_data[i].dist;
|
|
|
|
|
m_data[i].pos = pos;
|
|
|
|
|
m_data[i].dist = dist;
|
|
|
|
|
pos = p;
|
|
|
|
|
dist = d;
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
if (i >= m_taille)
|
|
|
|
|
i = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ajoute le point <20>loign<67> <20> la suite
|
|
|
|
|
m = m_max + 1;
|
|
|
|
|
if (m >= m_taille)
|
|
|
|
|
m = 0;
|
|
|
|
|
if (m != m_out)
|
|
|
|
|
{
|
|
|
|
|
m_data[m_max].pos = pos;
|
|
|
|
|
m_data[m_max].dist = dist;
|
|
|
|
|
m_max = m;
|
|
|
|
|
}
|
2017-02-12 00:51:38 +01:00
|
|
|
|
}
|