Mercurial > hg > forks > yadex
changeset 31:f5375d9255f0
Various cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 24 Sep 2011 14:57:59 +0300 |
parents | 967be0f78b4f |
children | 594dea11ccd9 |
files | src/aym.cc src/cfgfile.cc src/drawmap.cc src/sticker.cc src/wadname.h |
diffstat | 5 files changed, 71 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/src/aym.cc Sat Sep 24 14:33:46 2011 +0300 +++ b/src/aym.cc Sat Sep 24 14:57:59 2011 +0300 @@ -185,10 +185,7 @@ if (tolower(*s1) != tolower(*s2)) return (unsigned char) *s1 - (unsigned char) *s2; if (!*s1) - if (!*s2) - return 0; - else - return -1; + return *s2 ? -1 : 0; if (!*s2) return 1; s1++; @@ -209,10 +206,7 @@ if (tolower(*s1) != tolower(*s2)) return (unsigned char) *s1 - (unsigned char) *s2; if (!*s1) - if (!*s2) - return 0; - else - return -1; + return *s2 ? -1 : 0; if (!*s2) return 1; s1++;
--- a/src/cfgfile.cc Sat Sep 24 14:33:46 2011 +0300 +++ b/src/cfgfile.cc Sat Sep 24 14:57:59 2011 +0300 @@ -845,12 +845,8 @@ /* strtoul() sets errno to ERANGE if overflow. In addition, we don't want any non-zero negative numbers. In terms of regexp, /^(0x)?0*$/i. */ - if (errno != 0 - || neg - && ! - (strspn(value + 1, "0") == strlen(value + 1) - || value[1] == '0' - && tolower(value[2]) == 'x' + if (errno != 0 || neg && ! + (strspn(value + 1, "0") == strlen(value + 1) || value[1] == '0' && tolower(value[2]) == 'x' && strspn(value + 3, "0") == strlen(value + 3))) { err("%s(%u,%d): unsigned integer out of range",
--- a/src/drawmap.cc Sat Sep 24 14:33:46 2011 +0300 +++ b/src/drawmap.cc Sat Sep 24 14:57:59 2011 +0300 @@ -328,8 +328,8 @@ int mapy = Vertices[n].y; if (mapx >= mapx0 && mapx <= mapx9 && mapy >= mapy0 && mapy <= mapy9) { - register int scrx = SCREENX(mapx); - register int scry = SCREENY(mapy); + int scrx = SCREENX(mapx); + int scry = SCREENY(mapy); DrawScreenLine(scrx - r, scry - r, scrx + r, scry + r); DrawScreenLine(scrx + r, scry - r, scrx - r, scry + r); } @@ -356,34 +356,42 @@ /* * draw_linedefs - draw the linedefs */ +static int ld_check(int x1, int y1, int x2, int y2) +{ + int mapx0 = MAPX(0), + mapx9 = MAPX(ScrMaxX), + mapy0 = MAPY(ScrMaxY), + mapy9 = MAPY(0); + + return ((x1 < mapx0 && x2 < mapx0) || (x1 > mapx9 && x2 > mapx9) || + (y1 < mapy0 && y2 < mapy0) || (y1 > mapy9 && y2 > mapy9)); +} + + static void draw_linedefs(edit_t * e) { - int mapx0 = MAPX(0); - int mapx9 = MAPX(ScrMaxX); - int mapy0 = MAPY(ScrMaxY); - int mapy9 = MAPY(0); + int mapx0 = MAPX(0), + mapx9 = MAPX(ScrMaxX), + mapy0 = MAPY(ScrMaxY), + mapy9 = MAPY(0); switch (e->obj_type) { case OBJ_THINGS: { - int current_colour = INT_MIN; /* Some impossible colour no. */ - int new_colour; + int new_colour, current_colour = INT_MIN; /* Some impossible colour no. */ for (int n = 0; n < NumLineDefs; n++) { - register int x1 = Vertices[LineDefs[n].start].x; - register int x2 = Vertices[LineDefs[n].end].x; - register int y1 = Vertices[LineDefs[n].start].y; - register int y2 = Vertices[LineDefs[n].end].y; - if (x1 < mapx0 && x2 < mapx0 - || x1 > mapx9 && x2 > mapx9 - || y1 < mapy0 && y2 < mapy0 || y1 > mapy9 && y2 > mapy9) + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; + + if (ld_check(x1, y1, x2, y2)) continue; - if (LineDefs[n].flags & 1) - new_colour = WHITE; - else - new_colour = LIGHTGREY; + + new_colour = (LineDefs[n].flags & 1) ? WHITE : LIGHTGREY; if (new_colour != current_colour) set_colour(current_colour = new_colour); DrawMapLine(x1, y1, x2, y2); @@ -395,14 +403,14 @@ set_colour(LIGHTGREY); for (int n = 0; n < NumLineDefs; n++) { - register int x1 = Vertices[LineDefs[n].start].x; - register int x2 = Vertices[LineDefs[n].end].x; - register int y1 = Vertices[LineDefs[n].start].y; - register int y2 = Vertices[LineDefs[n].end].y; - if (x1 < mapx0 && x2 < mapx0 - || x1 > mapx9 && x2 > mapx9 - || y1 < mapy0 && y2 < mapy0 || y1 > mapy9 && y2 > mapy9) + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; + + if (ld_check(x1, y1, x2, y2)) continue; + DrawMapVector(x1, y1, x2, y2); } break; @@ -414,10 +422,10 @@ for (int n = 0; n < NumLineDefs; n++) { - register int x1 = Vertices[LineDefs[n].start].x; - register int x2 = Vertices[LineDefs[n].end].x; - register int y1 = Vertices[LineDefs[n].start].y; - register int y2 = Vertices[LineDefs[n].end].y; + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; if (x1 < mapx0 && x2 < mapx0 || x1 > mapx9 && x2 > mapx9 || y1 < mapy0 && y2 < mapy0 || y1 > mapy9 && y2 > mapy9) @@ -476,14 +484,14 @@ for (int n = 0; n < NumLineDefs; n++) { - register int x1 = Vertices[LineDefs[n].start].x; - register int x2 = Vertices[LineDefs[n].end].x; - register int y1 = Vertices[LineDefs[n].start].y; - register int y2 = Vertices[LineDefs[n].end].y; - if (x1 < mapx0 && x2 < mapx0 - || x1 > mapx9 && x2 > mapx9 - || y1 < mapy0 && y2 < mapy0 || y1 > mapy9 && y2 > mapy9) + int x1 = Vertices[LineDefs[n].start].x; + int x2 = Vertices[LineDefs[n].end].x; + int y1 = Vertices[LineDefs[n].start].y; + int y2 = Vertices[LineDefs[n].end].y; + + if (ld_check(x1, y1, x2, y2)) continue; + int sd1 = OBJ_NO_NONE; int sd2 = OBJ_NO_NONE; int s1 = OBJ_NO_NONE;
--- a/src/sticker.cc Sat Sep 24 14:33:46 2011 +0300 +++ b/src/sticker.cc Sat Sep 24 14:57:59 2011 +0300 @@ -373,13 +373,11 @@ { if (padding == 0) { - for (image_ptr = img.buf(); image_ptr < image_end; - image_ptr++) - *buf_ptr++ = (u32) ((game_colour[*image_ptr] >> 24) // Assume game_colour unsigned - | (game_colour[*image_ptr] >> 8) & - 0x0000ff00 | (game_colour[*image_ptr] - << 8) & 0x00ff0000 | - (game_colour[*image_ptr] << 24)); + for (image_ptr = img.buf(); image_ptr < image_end; image_ptr++) + *buf_ptr++ = (u32) ((game_colour[*image_ptr] >> 24) | + ((game_colour[*image_ptr] >> 8) & 0x0000ff00) | + ((game_colour[*image_ptr] << 8) & 0x00ff0000) | + (game_colour[*image_ptr] << 24)); } else {
--- a/src/wadname.h Sat Sep 24 14:33:46 2011 +0300 +++ b/src/wadname.h Sat Sep 24 14:57:59 2011 +0300 @@ -53,9 +53,9 @@ */ struct Wad_name { - inline Wad_name (); - inline Wad_name (const Wad_name& source); - inline Wad_name (const char *source); + inline Wad_name(); + inline Wad_name(const Wad_name& source); + inline Wad_name(const char *source); inline Wad_name& operator= (const char *source); inline bool operator== (const Wad_name& ref) const; inline bool operator== (const char *ref) const; @@ -70,7 +70,7 @@ */ inline Wad_name::Wad_name () { - memset (name, 0, sizeof(name)); + memset(name, 0, sizeof(name)); } @@ -82,7 +82,7 @@ */ inline Wad_name::Wad_name (const Wad_name& source) { - memcpy (name, source.name, sizeof name); + memcpy(name, source.name, sizeof name); } @@ -94,12 +94,12 @@ char *p; char *const pmax = name + sizeof name; - for (p = name; *source != '\0' && p < pmax; p++) + for (p = name; *source && p < pmax; p++) *p = toupper (*source++); // Pad with NULs to the end for (; p < pmax; p++) - *p = '\0'; + *p = 0; } @@ -109,12 +109,14 @@ inline Wad_name& Wad_name::operator= (const char *source) { char *p; - char *const pmax = name + sizeof name; - for (p = name; *source != '\0' && p < pmax; p++) - *p = toupper (*source++); + char *const pmax = name + sizeof(name); + + for (p = name; *source && p < pmax; p++) + *p = toupper (*source++); + // Pad with NULs to the end for (; p < pmax; p++) - *p = '\0'; + *p = 0; return *this; } @@ -124,7 +126,7 @@ */ inline bool Wad_name::operator== (const Wad_name& ref) const { - return this == &ref || ! memcmp (name, ref.name, sizeof name); + return this == &ref || ! memcmp(name, ref.name, sizeof name); } @@ -133,7 +135,7 @@ */ inline bool Wad_name::operator== (const char *ref) const { - return ! y_strnicmp (name, ref, sizeof name); + return ! y_strnicmp(name, ref, sizeof name); } @@ -146,11 +148,9 @@ * Return true iff <this> is "smaller" (lexicographically * speaking) than <other>, false otherwise. */ -inline bool Wad_name::less (const Wad_name& other) const +inline bool Wad_name::less(const Wad_name& other) const { - const char *p1 = name; - const char *p2 = other.name; - return memcmp (name, other.name, sizeof name) < 0; + return memcmp(name, other.name, sizeof name) < 0; }