critical_graph.cc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "critical_graph.hh"
  9. #include "path_api.hh"
  10. #include "map.hh"
  11. #include "map_cell.hh"
  12. #include "map_man.hh"
  13. #include <math.h>
  14. g1_critical_graph_class::~g1_critical_graph_class()
  15. //{{{
  16. {
  17. if (pool)
  18. i4_free(pool);
  19. pool=0;
  20. }
  21. //}}}
  22. void g1_critical_graph_class::clear_critical_graph()
  23. //{{{
  24. {
  25. if (pool)
  26. i4_free(pool);
  27. pool=0;
  28. pool_connections = 0;
  29. w32 size = sizeof(connection_class)*MAX_CRITICALS*MAX_CONNECTIONS;
  30. pool = (connection_class*)i4_malloc(size, "critical_connections");
  31. memset(pool,0,size);
  32. connection_class *current = pool;
  33. for (w32 j=1; j<MAX_CRITICALS; j++)
  34. {
  35. critical[j].connections=0;
  36. critical[j].connection = current;
  37. current += MAX_CONNECTIONS;
  38. pool_connections += MAX_CONNECTIONS;
  39. }
  40. }
  41. //}}}
  42. void g1_critical_graph_class::compact_critical_graph()
  43. //{{{
  44. {
  45. connection_class *old_pool = pool;
  46. w32 count=0, i,j;
  47. for (j=1; j<criticals; j++)
  48. count += critical[j].connections;
  49. w32 size = sizeof(connection_class)*count;
  50. pool = (connection_class*)i4_malloc(size, "critical_connections");
  51. connection_class *current = pool;
  52. pool_connections = 0;
  53. for (j=1; j<criticals; j++)
  54. {
  55. for (i=0; i<critical[j].connections; i++)
  56. current[i] = critical[j].connection[i];
  57. critical[j].connection = current;
  58. current += critical[j].connections;
  59. pool_connections += critical[j].connections;
  60. }
  61. if (old_pool)
  62. i4_free(old_pool);
  63. }
  64. //}}}
  65. void g1_critical_graph_class::expand_critical_graph()
  66. //{{{
  67. {
  68. connection_class *old_pool = pool;
  69. w32 size = sizeof(connection_class)*MAX_CRITICALS*MAX_CONNECTIONS;
  70. pool = (connection_class*)i4_malloc(size, "critical_connections");
  71. memset(pool,0,size);
  72. connection_class *current = pool;
  73. pool_connections = 0;
  74. for (w32 j=1; j<MAX_CRITICALS; j++)
  75. {
  76. if (j<criticals)
  77. for (w32 i=0; i<critical[j].connections; i++)
  78. current[i] = critical[j].connection[i];
  79. critical[j].connection = current;
  80. current += MAX_CONNECTIONS;
  81. pool_connections += MAX_CONNECTIONS;
  82. }
  83. if (old_pool)
  84. i4_free(old_pool);
  85. }
  86. //}}}
  87. i4_bool g1_critical_graph_class::add_critical_point(i4_float x, i4_float y)
  88. //{{{
  89. {
  90. if (criticals<MAX_CRITICALS)
  91. {
  92. critical[criticals].x=x; // oliy change this to float - jc
  93. critical[criticals].y=y;
  94. critical[criticals].connections=0;
  95. critical[criticals].connection=0;
  96. critical[criticals].selected=0;
  97. criticals++;
  98. return i4_T;
  99. }
  100. else
  101. return i4_F;
  102. }
  103. //}}}
  104. void g1_critical_graph_class::save_points(g1_saver_class *f)
  105. //{{{
  106. {
  107. *f << criticals;
  108. for (w32 j=1; j<criticals; j++)
  109. {
  110. f->write_16(sw16(critical[j].x));
  111. f->write_16(sw16(critical[j].y));
  112. }
  113. }
  114. //}}}
  115. void g1_critical_graph_class::save_graph(g1_saver_class *f)
  116. //{{{
  117. {
  118. w32 count=0, i,j;
  119. for (j=1; j<criticals; j++)
  120. count += critical[j].connections;
  121. *f << (w32)count;
  122. for (j=1; j<criticals; j++)
  123. {
  124. connection_class *conn = &critical[j].connection[0];
  125. *f << critical[j].connections;
  126. for (i=0; i<critical[j].connections; i++, conn++)
  127. {
  128. *f << conn->ref << conn->dist;
  129. for (int g=0; g<G1_GRADE_LEVELS; g++)
  130. *f << conn->size[g];
  131. }
  132. }
  133. }
  134. //}}}
  135. void g1_critical_graph_class::load_points(g1_loader_class *f)
  136. //{{{
  137. {
  138. *f >> criticals;
  139. for (w32 j=1; j<criticals; j++)
  140. {
  141. critical[j].x = i4_float(f->read_16()) + 0.5;
  142. critical[j].y = i4_float(f->read_16()) + 0.5;
  143. critical[j].connection=0;
  144. critical[j].connections=0;
  145. critical[j].selected=0;
  146. }
  147. if (pool)
  148. i4_free(pool);
  149. pool = 0;
  150. pool_connections=0;
  151. }
  152. //}}}
  153. void g1_critical_graph_class::load_graph(g1_loader_class *f)
  154. //{{{
  155. {
  156. if (pool)
  157. i4_free(pool);
  158. pool = 0;
  159. *f >> pool_connections;
  160. w32 size = sizeof(connection_class)*pool_connections;
  161. if (size)
  162. pool = (connection_class*)i4_malloc(size, "critical_connections");
  163. else pool=0;
  164. connection_class *conn = pool;
  165. for (w32 j=1; j<criticals; j++)
  166. {
  167. critical[j].connection = conn;
  168. *f >> critical[j].connections;
  169. for (w32 i=0; i<critical[j].connections; i++, conn++)
  170. {
  171. *f >> conn->ref >> conn->dist;
  172. for (int g=0; g<G1_GRADE_LEVELS; g++)
  173. *f >> conn->size[g];
  174. }
  175. }
  176. }
  177. //}}}
  178. //{{{ Emacs Locals
  179. // Local Variables:
  180. // folded-file: t
  181. // End:
  182. //}}}