diff --git a/.gitignore b/.gitignore index f954e6e407221bc34ce8e7ddbc08f49a3aafb8b9..5da0c3b48cfc0a41c170b95572c8c40177b1e71f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ debugmalloc snake.zip multiplatformLib.o snake.o + +doxygen \ No newline at end of file diff --git a/snake.c b/snake.c index d17e4e07b9ad05c98c36db3e8c58fed43f7ed47a..1877c98597f4a9cb76b3e81b1dec7a2d3ed4b958 100644 --- a/snake.c +++ b/snake.c @@ -795,7 +795,7 @@ int loadConfig(int *tickSpeed, int *repeatMap, int *feedAmount, int *canBite, ch * @param d direction * @param feedAmount food spawn rate * @param canBite can snake bite its own tail - * @return 1 if game over + * @return 1 if game over EOF if error, 0 if nothing really bad happened. */ int tick(Matrix *map, screenData *scrDat, snakeChain *snake, Direction *d, int feedAmount, int canBite){ static int foodTick = 0; diff --git a/structs.h b/structs.h index 21c358045de81e8a75730bdd20c2b4746b40cb15..b25ae4f6e8a10a8afaf85ffa3060d32f8235b869 100644 --- a/structs.h +++ b/structs.h @@ -1,6 +1,9 @@ #ifndef SNAKE_STRUCTS #define SNAKE_STRUCTS +/** + * Enum, storing possible moving directions + */ typedef enum Direction{ NONE = -1, UP = 0, @@ -9,20 +12,49 @@ typedef enum Direction{ LEFT = 3, }Direction; +/** + * 2 dimensional integer vector + * or position + */ typedef struct Vec2i{ int x; int y; }Pos; +/** + * Storing snake linked list. + * The head can count as a sentry (but it is storing data but cannot be removed...) + */ typedef struct snakeChain { + /** + * snake part distance from head. Feature wasn't added + */ int num; + /** + * Snake part's pos + */ struct Vec2i pos; + /** + * direction. Feature wasn't added + */ Direction dir; + /** + * Why do I have to document this. It is obvious + */ struct snakeChain *next; }snakeChain; +/** + * Storing 4 bytes for 1 utf-8 encoded character + * *utf-8 does not always 4 bytes long, can be shorter... + * + * If not using utf-8 encoding, the 1st byte will be used + * + * in utf-8, the first bit can tell is it longer? + * this is why I used union + */ typedef union unichar{ int isUnicone : 1; struct{ @@ -30,9 +62,21 @@ typedef union unichar{ }bytes; }unichar; -typedef struct chunk //struct stores 2 chars and it's color :D + +/** + * 1 1 by 2 chunk. Can store a boolean, is it a food chunk, or it's just a wall or air... + * stores 2 unichar + */ +typedef struct chunk { + /** + * is this a food? + */ int isFood :1; + /** + * If food, it can store a random value. Foods can have multiple texture. I need the random there + * or it stores 2 unichars. + */ union { unichar chars[2]; @@ -40,45 +84,83 @@ typedef struct chunk //struct stores 2 chars and it's color :D }data; /* + colorable feature was not completed... struct{ int fg : 3; //3 bit color codes. int bg : 3; //red green blue black white and 3 other (idk these) }color;*/ }chunk; -typedef struct state{ - struct Vec2i displaySize; - struct Vec2i displayPos; - int commands[2]; -}globalState; - +/** + * While loading the map file, I need to store EVERY characters whitout knowing it's size. + */ typedef struct linkedString{ unichar value; struct linkedString *next; }linkedString; +/** + * The snake's map is a matrix made of chunks. + */ typedef struct chunkMatrix{ + /** + * The 2d array itself + */ chunk **matrix; + /** + * I won't comment the height. It's the matrix width... + */ int width; + /** + * I've commented this. Why? + */ int height; }Matrix; - +/** + * storing texture for foods + * and storing it's length + */ typedef struct foodText{ int len; + /** + * a chunk array containing food textures + */ chunk *text; }foodText; -//Storing important information from the screen +/**Storing important information from the screen + * and from some other things... + * + */ typedef struct screenData{ + /** + * The position of the camera + */ Pos pos; + /**the terminal window's size in chunks + */ Pos size; + /** + * Does the map repeating + */ int repeatMap; + /** + * If the map does repeating, is it repeating on the screen X axis + * If the window is bigger than the map, it won't be printed multiple times + */ int isXRepeat; + /** + * same as the isXRepeat just in the Y axis + */ int isYRepeat; + /** + * Snake can store 2 commands. easier to do a U-turn + */ Direction commands[2]; + /**Storing the food textures + */ foodText foodTexture;//not real texture, but characters - //snake texture will be a bit more difficult }screenData; #endif \ No newline at end of file