Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define export extern "C" __declspec( dllexport )
- #include <Windows.h>
- #define NULL 0
- #define FALSE 0
- #define TRUE 1
- int chunkNum=0;
- class DSCube
- {
- public:
- int width;
- int height;
- int depth;
- double*** cube;
- DSCube(int w, int h, int d)
- {
- width = w;
- height = h;
- depth = d;
- cube = new double**[width];
- for (int i=0; i<width; i++)
- {
- cube [i] = new double*[height];
- for (int j=0; j<height; j++)
- {
- cube [i][j] = new double[depth];
- for (int k=0; k<depth; k++)
- {
- cube [i][j][k]=0;
- }
- }
- }
- }
- ~DSCube()
- {
- for (int i=0; i<height; i++)
- {
- for (int j=0; j<depth; j++)
- {
- delete[] cube[i][j];
- }
- delete[] cube[i];
- }
- delete[] cube;
- }
- };
- class CubeChunk
- {
- public:
- DSCube* cubeId;
- int chunkId;
- CubeChunk* nextChunk;
- CubeChunk(int w, int h, int d)
- {
- chunkId=chunkNum;
- cubeId= new DSCube(w,h,d);
- nextChunk=NULL; }
- ~CubeChunk()
- {
- delete cubeId;
- }
- };
- class CubeList
- {
- public:
- CubeChunk* firstChunk;
- int elementsNum;
- CubeList()
- {
- firstChunk = NULL;
- elementsNum = 0;
- }
- ~CubeList()
- {
- if (firstChunk != NULL)
- {
- CubeChunk* actChunk = firstChunk;
- CubeChunk* nextChunk = (*actChunk).nextChunk;
- for (int i=0; i<chunkNum;i++)
- {
- delete actChunk;
- CubeChunk* actChunk = nextChunk;
- CubeChunk* nextChunk = (*actChunk).nextChunk;
- }
- }
- }
- int CreateNewChunk(int w, int h, int d)
- {
- CubeChunk* newChunk = new CubeChunk(w, h, d);
- CubeChunk* actChunk = firstChunk;
- for (int i=1; i<elementsNum;i++)
- {
- actChunk = (*actChunk).nextChunk;
- }
- if (firstChunk != NULL)
- {
- (*actChunk).nextChunk = newChunk;
- }
- else
- {
- firstChunk = newChunk;
- }
- chunkNum++;
- elementsNum++;
- (*newChunk).chunkId = chunkNum;
- return chunkNum;
- }
- void DeleteChunk(int chunkId)
- {
- if (firstChunk != NULL)
- {
- CubeChunk* beforeChunk = firstChunk;
- CubeChunk* actChunk = firstChunk;
- if ((*firstChunk).chunkId == chunkId)
- {
- actChunk = (*firstChunk).nextChunk;
- delete firstChunk;
- firstChunk = actChunk;
- elementsNum--;
- }
- else
- {
- //cerca il chunk attuale e quello precedente
- for (int i=1; i<elementsNum;i++)
- {
- beforeChunk = actChunk;
- actChunk = (*actChunk).nextChunk;
- if ((*actChunk).chunkId == chunkId)
- {
- (*beforeChunk).nextChunk = (*actChunk).nextChunk;
- delete actChunk;
- elementsNum--;
- break;
- }
- }
- }
- }
- }
- DSCube* GetDSCube(int chunkId)
- {
- if (firstChunk != NULL)
- {
- CubeChunk* actChunk = firstChunk;
- for (int i=1; i<elementsNum;i++)
- {
- if ((*actChunk).chunkId == chunkId)
- {
- break;
- }
- actChunk = (*actChunk).nextChunk;
- }
- if ((*actChunk).chunkId == chunkId)
- {
- return (*actChunk).cubeId;
- }
- else
- {
- return NULL;
- }
- }
- }
- };
- CubeList lista;
- export double CreateDSCube(double width, double height, double depth)
- {
- return (double) lista.CreateNewChunk((int) width, (int) height, (int) depth);
- }
- export double DestroyDSCube(double id)
- {
- lista.DeleteChunk((int) id);
- return TRUE;
- }
- export double DSCubeExists(double id)
- {
- if (lista.GetDSCube((int) id) == NULL)
- {
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- export double DSCubeSet(double id, double x, double y, double z, double value)
- {
- DSCube* dsCube = lista.GetDSCube((int) id);
- int X=(int) x;
- int Y=(int) y;
- int Z=(int) z;
- if (dsCube != NULL)
- {
- /*(*dsCube).cube[X][Y][Z] = value;
- return TRUE;*/
- if (X>=0 && X<(*dsCube).width && Y>=0 && Y<(*dsCube).height && Z>=0 && Z<(*dsCube).depth)
- {
- (*dsCube).cube[X][Y][Z] = value;
- return (*dsCube).width;
- }
- else
- {
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
- }
- export double DSCubeGet(double id, double x, double y, double z)
- {
- DSCube* dsCube = lista.GetDSCube((int) id);
- int X=(int) x;
- int Y=(int) y;
- int Z=(int) z;
- if (dsCube != NULL)
- {
- /*return (*dsCube).cube[X][Y][Z];*/
- if (X>=0 && X<(*dsCube).width && Y>=0 && Y<(*dsCube).height && Z>=0 && Z<(*dsCube).depth)
- {
- return (*dsCube).cube[X][Y][Z];
- }
- else
- {
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement