From: Christian Heller Date: Mon, 22 Jul 2013 14:00:53 +0000 (+0200) Subject: More code re-styling and documentation. X-Git-Tag: tce~1137 X-Git-Url: https://plomlompom.com/repos/conditions?a=commitdiff_plain;h=35cdeffc062d3d87f1526bbff10c401b56b1345a;p=plomrogue More code re-styling and documentation. --- diff --git a/src/readwrite.c b/src/readwrite.c index 449e96b..9dbcac4 100644 --- a/src/readwrite.c +++ b/src/readwrite.c @@ -1,10 +1,10 @@ -/* readwrite.c */ +/* readwrite.c */ #include "readwrite.h" #include #include -extern uint16_t read_uint16_bigendian( FILE * file ) +extern uint16_t read_uint16_bigendian(FILE * file) { uint16_t x; x = (uint16_t) fgetc(file) << 8; @@ -12,7 +12,7 @@ extern uint16_t read_uint16_bigendian( FILE * file ) return x; } -extern uint32_t read_uint32_bigendian( FILE * file ) +extern uint32_t read_uint32_bigendian(FILE * file) { uint32_t x; x = (uint32_t) fgetc(file) << 24; @@ -22,13 +22,13 @@ extern uint32_t read_uint32_bigendian( FILE * file ) return x; } -extern void write_uint16_bigendian( uint16_t x, FILE * file ) +extern void write_uint16_bigendian(uint16_t x, FILE * file) { fputc( x >> 8, file ); fputc( x & 0xFF, file ); } -extern void write_uint32_bigendian( uint32_t x, FILE * file ) +extern void write_uint32_bigendian(uint32_t x, FILE * file) { fputc( x >> 24, file); fputc( ( x >> 16 ) & 0xFF, file); diff --git a/src/readwrite.h b/src/readwrite.h index 62e222a..84085d2 100644 --- a/src/readwrite.h +++ b/src/readwrite.h @@ -1,7 +1,7 @@ -/* readwrite.h: +/* readwrite.h: * - * Routines for reading/writing multibyte data from/to files. They ensure a - * defined endianness. + * Routines for reading/writing multibyte data from/to files. They ensure a + * defined endianness. */ #ifndef READWRITE_H @@ -10,9 +10,9 @@ #include #include -extern uint16_t read_uint16_bigendian( FILE * file ); -extern uint32_t read_uint32_bigendian( FILE * file ); -extern void write_uint16_bigendian( uint16_t x, FILE * file ); -extern void write_uint32_bigendian( uint32_t x, FILE * file ); +extern uint16_t read_uint16_bigendian(FILE * file); +extern uint32_t read_uint32_bigendian(FILE * file); +extern void write_uint16_bigendian(uint16_t x, FILE * file); +extern void write_uint32_bigendian(uint32_t x, FILE * file); #endif diff --git a/src/yx_uint16.c b/src/yx_uint16.c index a0b8940..8fb41bf 100644 --- a/src/yx_uint16.c +++ b/src/yx_uint16.c @@ -1,15 +1,24 @@ -#include "yx_uint16.h" +/* yx_uint16.c */ -extern char yx_uint16_cmp (struct yx_uint16 a, struct yx_uint16 b) { -// Compare two coordinates of type yx_uint16. - if (a.y == b.y && a.x == b.x) return 1; - else return 0; } +#include "yx_uint16.h" -extern struct yx_uint16 mv_yx_in_dir (enum dir d, struct yx_uint16 yx) { -// Return yx coordinates one step to the direction d of yx. - if (d == NORTH) yx.y--; - else if (d == EAST) yx.x++; - else if (d == SOUTH) yx.y++; - else if (d == WEST) yx.x--; - return yx; } +extern char yx_uint16_cmp(struct yx_uint16 a, struct yx_uint16 b) +{ + if (a.y == b.y && a.x == b.x) + return 1; + else + return 0; +} +extern struct yx_uint16 mv_yx_in_dir(enum dir d, struct yx_uint16 yx) +{ + if (d == NORTH) + yx.y--; + else if (d == EAST) + yx.x++; + else if (d == SOUTH) + yx.y++; + else if (d == WEST) + yx.x--; + return yx; +} diff --git a/src/yx_uint16.h b/src/yx_uint16.h index 3a13f01..eb951a7 100644 --- a/src/yx_uint16.h +++ b/src/yx_uint16.h @@ -1,19 +1,35 @@ +/* yx_uint16.h + * + * Structs and routines for coordinates and movement in 2-dimensional space + * (such as the ncurses screen and game maps). + */ + #ifndef YX_UINT16_H #define YX_UINT16_H #include -enum dir { - NORTH = 1, - EAST = 2, - SOUTH = 3, - WEST = 4 }; +/* Coordinates for maps of max. 65536x65536 cells. */ +struct yx_uint16 +{ + uint16_t y; + uint16_t x; +}; + +/* This encodes directions. */ + +enum dir +{ + NORTH = 1, + EAST = 2, + SOUTH = 3, + WEST = 4 +}; -struct yx_uint16 { - uint16_t y; - uint16_t x; }; +/* Return 1 if two yx_uint16 coordinates a and b are equal, else 0. */ +extern char yx_uint16_cmp(struct yx_uint16 a, struct yx_uint16 b); -extern char yx_uint16_cmp (struct yx_uint16, struct yx_uint16); -extern struct yx_uint16 mv_yx_in_dir (enum dir, struct yx_uint16); +/* Return yx_uint16 coordinate one step from coordinate yx in direction dir. */ +extern struct yx_uint16 mv_yx_in_dir(enum dir d, struct yx_uint16 yx); #endif