77 lines
1.5 KiB
C
77 lines
1.5 KiB
C
// credit to Benoit //
|
|
|
|
#ifndef GRID_H
|
|
#define GRID_H
|
|
#include <stdbool.h>
|
|
|
|
typedef enum special {ROT_CC, ROT_CW} special ;
|
|
|
|
typedef struct linkedList {
|
|
uint8_t coord ; // coord%8 = x ; coord/16 = y
|
|
char* flag ;
|
|
struct linkedList* next ;
|
|
} linkedList ;
|
|
|
|
typedef struct template {
|
|
uint8_t id ;
|
|
uint8_t* lines ; // len = 8
|
|
|
|
bool checkCompat ;
|
|
|
|
uint8_t eastsig ;
|
|
uint8_t westsig ;
|
|
|
|
linkedList* meta ;
|
|
} template ;
|
|
|
|
typedef struct chunk {
|
|
int16_t chx ;
|
|
int16_t chy ;
|
|
|
|
int draw_id ;
|
|
|
|
template chdata ;
|
|
} chunk ;
|
|
|
|
//
|
|
|
|
typedef struct List {
|
|
int hash;
|
|
int x;
|
|
int y;
|
|
chunk* elt;
|
|
struct List* next;
|
|
} *List;
|
|
|
|
typedef struct Grid {
|
|
List* data;
|
|
int capacity;
|
|
int size;
|
|
double loadFactor;
|
|
void (*push)(struct Grid *grid, int x, int z, chunk* elt);
|
|
chunk* (*pop)(struct Grid *grid, int x, int z);
|
|
chunk* (*get)(struct Grid *grid, int x, int z);
|
|
bool (*mem)(struct Grid *grid, int x, int z);
|
|
} *Grid;
|
|
|
|
int generate_hash(int x, int y);
|
|
|
|
Grid newGrid();
|
|
void freeGrid(Grid grid);
|
|
|
|
void gridInsert(Grid grid, int x, int z, chunk* elt);
|
|
chunk* gridGet(Grid grid, int x, int z);
|
|
bool gridMem(Grid grid, int x, int z);
|
|
chunk* gridRemove(Grid grid, int x, int z);
|
|
|
|
chunk** gridIter(Grid grid);
|
|
|
|
typedef struct ChunkCoord {
|
|
int x;
|
|
int z;
|
|
} *ChunkCoord;
|
|
|
|
ChunkCoord newChunkCoord(int x, int z);
|
|
void freeChunkCoord(ChunkCoord coord);
|
|
|
|
#endif |