tilealloc.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4. #include <unistd.h>
  5. #include <rpc/types.h>
  6. #include <rpc/xdr.h>
  7. #include "G3d_intern.h"
  8. /*---------------------------------------------------------------------------*/
  9. /*!
  10. * \brief
  11. *
  12. * Allocates a vector of <em>nofTiles</em> tiles with the same dimensions
  13. * as the tiles of <em>map</em> and large enough to store cell-values of
  14. * <em>type</em>.
  15. *
  16. * \param map
  17. * \param nofTiles
  18. * \param type
  19. * \return void * : a pointer to the vector ... if successful,
  20. * NULL ... otherwise.
  21. */
  22. void *G3d_allocTilesType(G3D_Map * map, int nofTiles, int type)
  23. {
  24. void *tiles;
  25. tiles = G3d_malloc(map->tileSize * G3d_length(type) * nofTiles);
  26. if (tiles == NULL) {
  27. G3d_error("G3d_allocTilesType: error in G3d_malloc");
  28. return NULL;
  29. }
  30. return tiles;
  31. }
  32. /*---------------------------------------------------------------------------*/
  33. /*!
  34. * \brief
  35. *
  36. * Is equivalent to G3d_allocTilesType (map, nofTiles, G3d_fileTypeMap (map)).
  37. *
  38. * \param map
  39. * \param nofTiles
  40. * \return void *
  41. */
  42. void *G3d_allocTiles(G3D_Map * map, int nofTiles)
  43. {
  44. void *tiles;
  45. tiles = G3d_allocTilesType(map, nofTiles, map->typeIntern);
  46. if (tiles == NULL) {
  47. G3d_error("G3d_allocTiles: error in G3d_allocTilesType");
  48. return NULL;
  49. }
  50. return tiles;
  51. }
  52. /*---------------------------------------------------------------------------*/
  53. /*!
  54. * \brief
  55. *
  56. * Is equivalent to <tt>G3d_free (tiles);</tt>
  57. *
  58. * \param tiles
  59. * \return void
  60. */
  61. void G3d_freeTiles(void *tiles)
  62. {
  63. G3d_free(tiles);
  64. }