Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.0 KiB

  1. #include <glos.h>
  2. #include <GL/gl.h>
  3. #include <GL/glu.h>
  4. #ifndef NT
  5. #include <stdlib.h>
  6. #include <assert.h>
  7. #else
  8. #include "winmem.h"
  9. #endif
  10. #include "monotone.h"
  11. #include "msort.h"
  12. static int comp_priorityq( Vert **x, Vert **y );
  13. static void grow_priorityq( GLUtriangulatorObj *tobj );
  14. void
  15. __gl_init_priorityq( GLUtriangulatorObj *tobj, long s )
  16. {
  17. assert( ! tobj->parray ) ;
  18. tobj->phead = 0;
  19. tobj->ptail = 0;
  20. tobj->psize = s > 0 ? s : 1;
  21. tobj->parray = (Vert **)
  22. malloc( (unsigned int) (sizeof( Vert *) * tobj->psize) );
  23. }
  24. void
  25. __gl_add_priorityq( GLUtriangulatorObj *tobj, Vert *v )
  26. {
  27. assert( tobj->parray );
  28. if( tobj->ptail == tobj->psize ) grow_priorityq( tobj );
  29. tobj->parray[tobj->ptail++] = v;
  30. }
  31. int
  32. __gl_more_priorityq( GLUtriangulatorObj *tobj )
  33. {
  34. return tobj->phead != tobj->ptail;
  35. }
  36. void
  37. __gl_sort_priorityq( GLUtriangulatorObj *tobj )
  38. {
  39. assert( tobj->phead <= tobj->ptail );
  40. __gl_msort( tobj, (void **)tobj->parray+tobj->phead,
  41. tobj->ptail-tobj->phead, sizeof(Vert *), (SortFunc) comp_priorityq );
  42. }
  43. Vert *
  44. __gl_remove_priorityq( GLUtriangulatorObj *tobj )
  45. {
  46. return tobj->parray[tobj->phead++];
  47. }
  48. void
  49. __gl_free_priorityq( GLUtriangulatorObj *tobj )
  50. {
  51. if (tobj->parray) { free( tobj->parray ); tobj->parray = 0; }
  52. }
  53. static void
  54. grow_priorityq( GLUtriangulatorObj *tobj )
  55. {
  56. tobj->psize *= 2;
  57. tobj->parray = (Vert **)
  58. realloc( tobj->parray, (unsigned int)(sizeof(Vert*)*tobj->psize) );
  59. }
  60. static int
  61. comp_priorityq( Vert **vp1, Vert **vp2 )
  62. {
  63. float diff = (*vp1)->s - (*vp2)->s;
  64. if (diff < (float)0.0) return -1;
  65. if (diff > (float)0.0) return 1;
  66. if (diff == (float)0.0)
  67. diff = (*vp1)->t - (*vp2)->t;
  68. if (diff < (float)0.0) return -1;
  69. if (diff > (float)0.0) return 1;
  70. return 0;
  71. }
  72. void
  73. __gl_setpriority_priorityq( GLUtriangulatorObj *tobj, int s, int t )
  74. {
  75. int i;
  76. for( i=tobj->phead; i<tobj->ptail; i++ ) {
  77. tobj->parray[i]->s = tobj->parray[i]->v[s];
  78. tobj->parray[i]->t = tobj->parray[i]->v[t];
  79. }
  80. }