Advertisement
Guest User

Untitled

a guest
Jan 16th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. #define export extern "C" __declspec( dllexport )
  2.  
  3. #include <Windows.h>
  4.  
  5. #define NULL 0
  6. #define FALSE 0
  7. #define TRUE 1
  8.  
  9. int chunkNum=0;
  10.  
  11. class DSCube
  12. {
  13. public:
  14. int width;
  15. int height;
  16. int depth;
  17. double*** cube;
  18.  
  19. DSCube(int w, int h, int d)
  20. {
  21. width = w;
  22. height = h;
  23. depth = d;
  24. cube = new double**[width];
  25. for (int i=0; i<width; i++)
  26. {
  27. cube [i] = new double*[height];
  28. for (int j=0; j<height; j++)
  29. {
  30. cube [i][j] = new double[depth];
  31. for (int k=0; k<depth; k++)
  32. {
  33. cube [i][j][k]=0;
  34. }
  35. }
  36. }
  37. }
  38.  
  39. ~DSCube()
  40. {
  41. for (int i=0; i<height; i++)
  42. {
  43. for (int j=0; j<depth; j++)
  44. {
  45. delete[] cube[i][j];
  46. }
  47. delete[] cube[i];
  48. }
  49. delete[] cube;
  50. }
  51.  
  52.  
  53. };
  54.  
  55. class CubeChunk
  56. {
  57. public:
  58. DSCube* cubeId;
  59. int chunkId;
  60. CubeChunk* nextChunk;
  61.  
  62. CubeChunk(int w, int h, int d)
  63. {
  64. chunkId=chunkNum;
  65. cubeId= new DSCube(w,h,d);
  66. nextChunk=NULL; }
  67.  
  68. ~CubeChunk()
  69. {
  70. delete cubeId;
  71. }
  72. };
  73.  
  74. class CubeList
  75. {
  76. public:
  77. CubeChunk* firstChunk;
  78. int elementsNum;
  79.  
  80. CubeList()
  81. {
  82. firstChunk = NULL;
  83. elementsNum = 0;
  84. }
  85.  
  86. ~CubeList()
  87. {
  88. if (firstChunk != NULL)
  89. {
  90. CubeChunk* actChunk = firstChunk;
  91. CubeChunk* nextChunk = (*actChunk).nextChunk;
  92. for (int i=0; i<chunkNum;i++)
  93. {
  94. delete actChunk;
  95. CubeChunk* actChunk = nextChunk;
  96. CubeChunk* nextChunk = (*actChunk).nextChunk;
  97. }
  98. }
  99. }
  100.  
  101. int CreateNewChunk(int w, int h, int d)
  102. {
  103. CubeChunk* newChunk = new CubeChunk(w, h, d);
  104. CubeChunk* actChunk = firstChunk;
  105. for (int i=1; i<elementsNum;i++)
  106. {
  107. actChunk = (*actChunk).nextChunk;
  108. }
  109. if (firstChunk != NULL)
  110. {
  111. (*actChunk).nextChunk = newChunk;
  112. }
  113. else
  114. {
  115. firstChunk = newChunk;
  116. }
  117. chunkNum++;
  118. elementsNum++;
  119. (*newChunk).chunkId = chunkNum;
  120. return chunkNum;
  121. }
  122.  
  123. void DeleteChunk(int chunkId)
  124. {
  125. if (firstChunk != NULL)
  126. {
  127. CubeChunk* beforeChunk = firstChunk;
  128. CubeChunk* actChunk = firstChunk;
  129. if ((*firstChunk).chunkId == chunkId)
  130. {
  131. actChunk = (*firstChunk).nextChunk;
  132. delete firstChunk;
  133. firstChunk = actChunk;
  134. elementsNum--;
  135. }
  136. else
  137. {
  138. //cerca il chunk attuale e quello precedente
  139. for (int i=1; i<elementsNum;i++)
  140. {
  141. beforeChunk = actChunk;
  142. actChunk = (*actChunk).nextChunk;
  143. if ((*actChunk).chunkId == chunkId)
  144. {
  145. (*beforeChunk).nextChunk = (*actChunk).nextChunk;
  146. delete actChunk;
  147. elementsNum--;
  148. break;
  149. }
  150. }
  151. }
  152. }
  153. }
  154.  
  155. DSCube* GetDSCube(int chunkId)
  156. {
  157. if (firstChunk != NULL)
  158. {
  159.  
  160. CubeChunk* actChunk = firstChunk;
  161. for (int i=1; i<elementsNum;i++)
  162. {
  163. if ((*actChunk).chunkId == chunkId)
  164. {
  165. break;
  166. }
  167. actChunk = (*actChunk).nextChunk;
  168.  
  169. }
  170.  
  171. if ((*actChunk).chunkId == chunkId)
  172. {
  173. return (*actChunk).cubeId;
  174. }
  175. else
  176. {
  177. return NULL;
  178. }
  179. }
  180. }
  181. };
  182.  
  183. CubeList lista;
  184.  
  185. export double CreateDSCube(double width, double height, double depth)
  186. {
  187.  
  188. return (double) lista.CreateNewChunk((int) width, (int) height, (int) depth);
  189. }
  190.  
  191. export double DestroyDSCube(double id)
  192. {
  193. lista.DeleteChunk((int) id);
  194. return TRUE;
  195. }
  196.  
  197. export double DSCubeExists(double id)
  198. {
  199. if (lista.GetDSCube((int) id) == NULL)
  200. {
  201. return FALSE;
  202. }
  203. else
  204. {
  205. return TRUE;
  206. }
  207. }
  208.  
  209. export double DSCubeSet(double id, double x, double y, double z, double value)
  210. {
  211. DSCube* dsCube = lista.GetDSCube((int) id);
  212. int X=(int) x;
  213. int Y=(int) y;
  214. int Z=(int) z;
  215. if (dsCube != NULL)
  216. {
  217. /*(*dsCube).cube[X][Y][Z] = value;
  218. return TRUE;*/
  219. if (X>=0 && X<(*dsCube).width && Y>=0 && Y<(*dsCube).height && Z>=0 && Z<(*dsCube).depth)
  220. {
  221. (*dsCube).cube[X][Y][Z] = value;
  222. return (*dsCube).width;
  223. }
  224. else
  225. {
  226. return FALSE;
  227. }
  228. }
  229. else
  230. {
  231. return FALSE;
  232. }
  233. }
  234.  
  235. export double DSCubeGet(double id, double x, double y, double z)
  236. {
  237. DSCube* dsCube = lista.GetDSCube((int) id);
  238. int X=(int) x;
  239. int Y=(int) y;
  240. int Z=(int) z;
  241. if (dsCube != NULL)
  242. {
  243. /*return (*dsCube).cube[X][Y][Z];*/
  244. if (X>=0 && X<(*dsCube).width && Y>=0 && Y<(*dsCube).height && Z>=0 && Z<(*dsCube).depth)
  245. {
  246. return (*dsCube).cube[X][Y][Z];
  247. }
  248. else
  249. {
  250. return FALSE;
  251. }
  252. }
  253. else
  254. {
  255. return FALSE;
  256. }
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement