diff options
Diffstat (limited to 'engines/sword25')
-rw-r--r-- | engines/sword25/gfx/image/art.cpp | 136 | ||||
-rw-r--r-- | engines/sword25/gfx/image/imgloader.cpp | 13 | ||||
-rw-r--r-- | engines/sword25/gfx/screenshot.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/kernel/inputpersistenceblock.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/script/luabindhelper.h | 2 | ||||
-rw-r--r-- | engines/sword25/util/lua/lbaselib.cpp | 7 | ||||
-rw-r--r-- | engines/sword25/util/lua/llex.cpp | 26 | ||||
-rw-r--r-- | engines/sword25/util/lua/lobject.cpp | 8 | ||||
-rw-r--r-- | engines/sword25/util/lua/lstrlib.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/util/lua/luaconf.h | 5 | ||||
-rw-r--r-- | engines/sword25/util/lua/scummvm_file.cpp | 2 | ||||
-rw-r--r-- | engines/sword25/util/pluto/pluto.cpp | 26 |
12 files changed, 105 insertions, 126 deletions
diff --git a/engines/sword25/gfx/image/art.cpp b/engines/sword25/gfx/image/art.cpp index 2ba102e779..3944a207c8 100644 --- a/engines/sword25/gfx/image/art.cpp +++ b/engines/sword25/gfx/image/art.cpp @@ -328,18 +328,6 @@ static void art_vpath_render_bez(ArtVpath **p_vpath, int *pn, int *pn_max, double x2, double y2, double x3, double y3, double flatness) { - double x3_0, y3_0; - double z3_0_dot; - double z1_dot, z2_dot; - double z1_perp, z2_perp; - double max_perp_sq; - - double x_m, y_m; - double xa1, ya1; - double xa2, ya2; - double xb1, yb1; - double xb2, yb2; - /* It's possible to optimize this routine a fair amount. First, once the _dot conditions are met, they will also be met in @@ -363,11 +351,13 @@ static void art_vpath_render_bez(ArtVpath **p_vpath, int *pn, int *pn_max, */ - x3_0 = x3 - x0; - y3_0 = y3 - y0; + bool subDivide = false; + + double x3_0 = x3 - x0; + double y3_0 = y3 - y0; - /* z3_0_dot is dist z0-z3 squared */ - z3_0_dot = x3_0 * x3_0 + y3_0 * y3_0; + // z3_0_dot is dist z0-z3 squared + double z3_0_dot = x3_0 * x3_0 + y3_0 * y3_0; if (z3_0_dot < 0.001) { /* if start and end point are almost identical, the flatness tests @@ -375,72 +365,68 @@ static void art_vpath_render_bez(ArtVpath **p_vpath, int *pn, int *pn_max, * the other two control points are the same as the start point, * too. */ - if (hypot(x1 - x0, y1 - y0) < 0.001 - && hypot(x2 - x0, y2 - y0) < 0.001) - goto nosubdivide; - else - goto subdivide; - } - - /* we can avoid subdivision if: - - z1 has distance no more than flatness from the z0-z3 line - - z1 is no more z0'ward than flatness past z0-z3 - - z1 is more z0'ward than z3'ward on the line traversing z0-z3 - - and correspondingly for z2 */ - - /* perp is distance from line, multiplied by dist z0-z3 */ - max_perp_sq = flatness * flatness * z3_0_dot; - - z1_perp = (y1 - y0) * x3_0 - (x1 - x0) * y3_0; - if (z1_perp * z1_perp > max_perp_sq) - goto subdivide; + if (!(hypot(x1 - x0, y1 - y0) < 0.001 + && hypot(x2 - x0, y2 - y0) < 0.001)) + subDivide = true; + } else { + /* we can avoid subdivision if: - z2_perp = (y3 - y2) * x3_0 - (x3 - x2) * y3_0; - if (z2_perp * z2_perp > max_perp_sq) - goto subdivide; + z1 has distance no more than flatness from the z0-z3 line - z1_dot = (x1 - x0) * x3_0 + (y1 - y0) * y3_0; - if (z1_dot < 0 && z1_dot * z1_dot > max_perp_sq) - goto subdivide; + z1 is no more z0'ward than flatness past z0-z3 - z2_dot = (x3 - x2) * x3_0 + (y3 - y2) * y3_0; - if (z2_dot < 0 && z2_dot * z2_dot > max_perp_sq) - goto subdivide; + z1 is more z0'ward than z3'ward on the line traversing z0-z3 - if (z1_dot + z1_dot > z3_0_dot) - goto subdivide; + and correspondingly for z2 */ - if (z2_dot + z2_dot > z3_0_dot) - goto subdivide; + // perp is distance from line, multiplied by dist z0-z3 + double max_perp_sq = flatness * flatness * z3_0_dot; + double z1_perp = (y1 - y0) * x3_0 - (x1 - x0) * y3_0; + if (z1_perp * z1_perp > max_perp_sq) { + subDivide = true; + } else { + double z2_perp = (y3 - y2) * x3_0 - (x3 - x2) * y3_0; + if (z2_perp * z2_perp > max_perp_sq) { + subDivide = true; + } else { + double z1_dot = (x1 - x0) * x3_0 + (y1 - y0) * y3_0; + if (z1_dot < 0 && z1_dot * z1_dot > max_perp_sq) { + subDivide = true; + } else { + double z2_dot = (x3 - x2) * x3_0 + (y3 - y2) * y3_0; + if (z2_dot < 0 && z2_dot * z2_dot > max_perp_sq) + subDivide = true; + else if (z1_dot + z1_dot > z3_0_dot) + subDivide = true; + else if (z2_dot + z2_dot > z3_0_dot) + subDivide = true; + } + } + } + } -nosubdivide: - /* don't subdivide */ - art_vpath_add_point(p_vpath, pn, pn_max, - ART_LINETO, x3, y3); - return; - -subdivide: - - xa1 = (x0 + x1) * 0.5; - ya1 = (y0 + y1) * 0.5; - xa2 = (x0 + 2 * x1 + x2) * 0.25; - ya2 = (y0 + 2 * y1 + y2) * 0.25; - xb1 = (x1 + 2 * x2 + x3) * 0.25; - yb1 = (y1 + 2 * y2 + y3) * 0.25; - xb2 = (x2 + x3) * 0.5; - yb2 = (y2 + y3) * 0.5; - x_m = (xa2 + xb1) * 0.5; - y_m = (ya2 + yb1) * 0.5; - - art_vpath_render_bez(p_vpath, pn, pn_max, - x0, y0, xa1, ya1, xa2, ya2, x_m, y_m, flatness); - art_vpath_render_bez(p_vpath, pn, pn_max, - x_m, y_m, xb1, yb1, xb2, yb2, x3, y3, flatness); + if (subDivide) { + double xa1 = (x0 + x1) * 0.5; + double ya1 = (y0 + y1) * 0.5; + double xa2 = (x0 + 2 * x1 + x2) * 0.25; + double ya2 = (y0 + 2 * y1 + y2) * 0.25; + double xb1 = (x1 + 2 * x2 + x3) * 0.25; + double yb1 = (y1 + 2 * y2 + y3) * 0.25; + double xb2 = (x2 + x3) * 0.5; + double yb2 = (y2 + y3) * 0.5; + double x_m = (xa2 + xb1) * 0.5; + double y_m = (ya2 + yb1) * 0.5; + + art_vpath_render_bez(p_vpath, pn, pn_max, + x0, y0, xa1, ya1, xa2, ya2, x_m, y_m, flatness); + art_vpath_render_bez(p_vpath, pn, pn_max, + x_m, y_m, xb1, yb1, xb2, yb2, x3, y3, flatness); + } else { + // don't subdivide + art_vpath_add_point(p_vpath, pn, pn_max, + ART_LINETO, x3, y3); + } } /** diff --git a/engines/sword25/gfx/image/imgloader.cpp b/engines/sword25/gfx/image/imgloader.cpp index 1df0fba70c..e103626416 100644 --- a/engines/sword25/gfx/image/imgloader.cpp +++ b/engines/sword25/gfx/image/imgloader.cpp @@ -33,18 +33,19 @@ #include "sword25/gfx/image/image.h" #include "sword25/gfx/image/imgloader.h" #include "graphics/pixelformat.h" -#include "graphics/png.h" +#include "graphics/decoders/png.h" namespace Sword25 { bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, byte *&uncompressedDataPtr, int &width, int &height, int &pitch) { Common::MemoryReadStream *fileStr = new Common::MemoryReadStream(fileDataPtr, fileSize, DisposeAfterUse::NO); - Graphics::PNG *png = new Graphics::PNG(); - if (!png->read(fileStr)) // the fileStr pointer, and thus pFileData will be deleted after this is done + + Graphics::PNGDecoder png; + if (!png.loadStream(*fileStr)) // the fileStr pointer, and thus pFileData will be deleted after this is done error("Error while reading PNG image"); - Graphics::PixelFormat format = Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); - Graphics::Surface *pngSurface = png->getSurface(format); + const Graphics::Surface *sourceSurface = png.getSurface(); + Graphics::Surface *pngSurface = sourceSurface->convertTo(Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24), png.getPalette()); width = pngSurface->w; height = pngSurface->h; @@ -53,7 +54,7 @@ bool ImgLoader::decodePNGImage(const byte *fileDataPtr, uint fileSize, byte *&un pngSurface->free(); delete pngSurface; - delete png; + delete fileStr; // Signal success return true; diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index de7b62fba9..0ea4bff906 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -74,7 +74,7 @@ Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) // The source image must be 800x600. if (data->w != 800 || data->h != 600 || data->format.bytesPerPixel != 4) { error("The sreenshot dimensions have to be 800x600 in order to be saved as a thumbnail."); - return false; + return 0; } // Buffer for the output thumbnail diff --git a/engines/sword25/kernel/inputpersistenceblock.cpp b/engines/sword25/kernel/inputpersistenceblock.cpp index cdce539c31..0fe5d88b80 100644 --- a/engines/sword25/kernel/inputpersistenceblock.cpp +++ b/engines/sword25/kernel/inputpersistenceblock.cpp @@ -86,7 +86,7 @@ void InputPersistenceBlock::read(bool &value) { if (checkMarker(BOOL_MARKER)) { uint uintBool = READ_LE_UINT32(_iter); _iter += 4; - value = uintBool == 0 ? false : true; + value = uintBool != 0; } else { value = false; } diff --git a/engines/sword25/script/luabindhelper.h b/engines/sword25/script/luabindhelper.h index 0cb6d37bdc..5223d4440e 100644 --- a/engines/sword25/script/luabindhelper.h +++ b/engines/sword25/script/luabindhelper.h @@ -40,7 +40,7 @@ namespace Sword25 { #define lua_pushbooleancpp(L, b) (lua_pushboolean(L, b ? 1 : 0)) -#define lua_tobooleancpp(L, i) (lua_toboolean(L, i) == 0 ? false : true) +#define lua_tobooleancpp(L, i) (lua_toboolean(L, i) != 0) struct lua_constant_reg { const char *Name; diff --git a/engines/sword25/util/lua/lbaselib.cpp b/engines/sword25/util/lua/lbaselib.cpp index 3f0b645164..659c61d956 100644 --- a/engines/sword25/util/lua/lbaselib.cpp +++ b/engines/sword25/util/lua/lbaselib.cpp @@ -6,10 +6,7 @@ -#include <ctype.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include "common/util.h" #define lbaselib_c #define LUA_LIB @@ -62,7 +59,7 @@ static int luaB_tonumber (lua_State *L) { luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range"); n = strtoul(s1, &s2, base); if (s1 != s2) { /* at least one valid digit? */ - while (isspace((unsigned char)(*s2))) s2++; /* skip trailing spaces */ + while (Common::isSpace(*s2)) s2++; /* skip trailing spaces */ if (*s2 == '\0') { /* no invalid trailing characters? */ lua_pushnumber(L, (lua_Number)n); return 1; diff --git a/engines/sword25/util/lua/llex.cpp b/engines/sword25/util/lua/llex.cpp index 464ab3ec15..f8433d3afa 100644 --- a/engines/sword25/util/lua/llex.cpp +++ b/engines/sword25/util/lua/llex.cpp @@ -5,9 +5,7 @@ */ -#include <ctype.h> -#include <stdio.h> -#include <string.h> +#include "common/util.h" #define llex_c #define LUA_CORE @@ -188,7 +186,7 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { sprintf(buf, "%.1f", 1.0); ls->decpoint = '.'; for (i = 0; buf[i]; i++) { - if (!isspace(static_cast<unsigned char>(buf[i])) && !isdigit(static_cast<unsigned char>(buf[i]))) { + if (!Common::isSpace(buf[i]) && !Common::isDigit(buf[i])) { ls->decpoint = buf[i]; break; } @@ -204,13 +202,13 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { /* LUA_NUMBER */ static void read_numeral (LexState *ls, SemInfo *seminfo) { - lua_assert(isdigit(ls->current)); + lua_assert(Common::isDigit(ls->current)); do { save_and_next(ls); - } while (isdigit(ls->current) || ls->current == '.'); + } while (Common::isDigit(ls->current) || ls->current == '.'); if (check_next(ls, "Ee")) /* `E'? */ check_next(ls, "+-"); /* optional exponent sign */ - while (isalnum(ls->current) || ls->current == '_') + while (Common::isAlnum(ls->current) || ls->current == '_') save_and_next(ls); save(ls, '\0'); buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ @@ -313,7 +311,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { case '\r': save(ls, '\n'); inclinenumber(ls); continue; case EOZ: continue; /* will raise an error next loop */ default: { - if (!isdigit(ls->current)) + if (!Common::isDigit(ls->current)) save_and_next(ls); /* handles \\, \", \', and \? */ else { /* \xxx */ int i = 0; @@ -321,7 +319,7 @@ static void read_string (LexState *ls, int del, SemInfo *seminfo) { do { c = 10*c + (ls->current-'0'); next(ls); - } while (++i<3 && isdigit(ls->current)); + } while (++i<3 && Common::isDigit(ls->current)); if (c > UCHAR_MAX) luaX_lexerror(ls, "escape sequence too large", TK_STRING); save(ls, c); @@ -412,7 +410,7 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_DOTS; /* ... */ else return TK_CONCAT; /* .. */ } - else if (!isdigit(ls->current)) return '.'; + else if (!Common::isDigit(ls->current)) return '.'; else { read_numeral(ls, seminfo); return TK_NUMBER; @@ -422,21 +420,21 @@ static int llex (LexState *ls, SemInfo *seminfo) { return TK_EOS; } default: { - if (isspace(ls->current)) { + if (Common::isSpace(ls->current)) { lua_assert(!currIsNewline(ls)); next(ls); continue; } - else if (isdigit(ls->current)) { + else if (Common::isDigit(ls->current)) { read_numeral(ls, seminfo); return TK_NUMBER; } - else if (isalpha(ls->current) || ls->current == '_') { + else if (Common::isAlpha(ls->current) || ls->current == '_') { /* identifier or reserved word */ TString *ts; do { save_and_next(ls); - } while (isalnum(ls->current) || ls->current == '_'); + } while (Common::isAlnum(ls->current) || ls->current == '_'); ts = luaX_newstring(ls, luaZ_buffer(ls->buff), luaZ_bufflen(ls->buff)); if (ts->tsv.reserved > 0) /* reserved word? */ diff --git a/engines/sword25/util/lua/lobject.cpp b/engines/sword25/util/lua/lobject.cpp index 24718931ed..1ffee52556 100644 --- a/engines/sword25/util/lua/lobject.cpp +++ b/engines/sword25/util/lua/lobject.cpp @@ -4,11 +4,7 @@ ** See Copyright Notice in lua.h */ -#include <ctype.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> +#include "common/util.h" #define lobject_c #define LUA_CORE @@ -94,7 +90,7 @@ int luaO_str2d (const char *s, lua_Number *result) { if (*endptr == 'x' || *endptr == 'X') /* maybe an hexadecimal constant? */ *result = cast_num(strtoul(s, &endptr, 16)); if (*endptr == '\0') return 1; /* most common case */ - while (isspace(cast(unsigned char, *endptr))) endptr++; + while (Common::isSpace(*endptr)) endptr++; if (*endptr != '\0') return 0; /* invalid trailing characters? */ return 1; } diff --git a/engines/sword25/util/lua/lstrlib.cpp b/engines/sword25/util/lua/lstrlib.cpp index bcc869cb98..ed68a2fa00 100644 --- a/engines/sword25/util/lua/lstrlib.cpp +++ b/engines/sword25/util/lua/lstrlib.cpp @@ -5,6 +5,8 @@ */ +#define FORBIDDEN_SYMBOL_EXCEPTION_ctype_h + #include <ctype.h> #include <stddef.h> #include <stdio.h> diff --git a/engines/sword25/util/lua/luaconf.h b/engines/sword25/util/lua/luaconf.h index f5affe9fd7..53d0f55290 100644 --- a/engines/sword25/util/lua/luaconf.h +++ b/engines/sword25/util/lua/luaconf.h @@ -182,8 +182,7 @@ #define LUAI_FUNC static #define LUAI_DATA /* empty */ -#elif defined(__GNUC__) && ((__GNUC__*100 + __GNUC_MINOR__) >= 302) && \ - defined(__ELF__) && !defined(__PLAYSTATION2__) +#elif GCC_ATLEAST(3, 2) && defined(__ELF__) && !defined(__PLAYSTATION2__) /* ** The PS2 gcc compiler doesn't like the visibility attribute, so ** we use the normal "extern" definitions in the block below @@ -643,7 +642,7 @@ union luai_Cast { double l_d; long l_l; }; ** CHANGE it if you have a way to implement it in your system. */ #define lua_popen(L,c,m) ((void)((void)c, m), \ - luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0) + luaL_error(L, LUA_QL("popen") " not supported"), (FILE *)0) #define lua_pclose(L,file) ((void)((void)L, file), 0) /* diff --git a/engines/sword25/util/lua/scummvm_file.cpp b/engines/sword25/util/lua/scummvm_file.cpp index 33053a71cb..b5f1388129 100644 --- a/engines/sword25/util/lua/scummvm_file.cpp +++ b/engines/sword25/util/lua/scummvm_file.cpp @@ -22,7 +22,7 @@ #include "sword25/util/lua/scummvm_file.h" #include "common/config-manager.h" -#include "common/util.h" +#include "common/language.h" namespace Sword25 { diff --git a/engines/sword25/util/pluto/pluto.cpp b/engines/sword25/util/pluto/pluto.cpp index 957f5af795..d645e5ed2a 100644 --- a/engines/sword25/util/pluto/pluto.cpp +++ b/engines/sword25/util/pluto/pluto.cpp @@ -159,7 +159,7 @@ static int persistspecialobject(PersistInfo *pi, int defaction) lua_pushvalue(pi->L, -3); /* perms reftbl ... obj mt __persist obj */ #ifdef PLUTO_PASS_USERDATA_TO_PERSIST - lua_pushlightuserdata(pi->L, (void*)pi->writer); + lua_pushlightuserdata(pi->L, (void *)pi->writer); lua_pushlightuserdata(pi->L, pi->ud); /* perms reftbl ... obj mt __persist obj ud */ lua_call(pi->L, 3, 1); @@ -663,7 +663,7 @@ static void persist(PersistInfo *pi) } lua_pushvalue(pi->L, -1); /* perms reftbl ... obj obj */ - lua_pushlightuserdata(pi->L, (void*)(++(pi->counter))); + lua_pushlightuserdata(pi->L, (void *)(++(pi->counter))); /* perms reftbl ... obj obj ref */ lua_rawset(pi->L, 2); /* perms reftbl ... obj */ @@ -854,7 +854,7 @@ static void registerobject(int ref, UnpersistInfo *upi) { /* perms reftbl ... obj */ lua_checkstack(upi->L, 2); - lua_pushlightuserdata(upi->L, (void*)ref); + lua_pushlightuserdata(upi->L, (void *)ref); /* perms reftbl ... obj ref */ lua_pushvalue(upi->L, -2); /* perms reftbl ... obj ref obj */ @@ -989,7 +989,7 @@ static void unpersisttable(int ref, UnpersistInfo *upi) static UpVal *makeupval(lua_State *L, int stackpos) { UpVal *uv = pdep_new(L, UpVal); - pdep_link(L, (GCObject*)uv, LUA_TUPVAL); + pdep_link(L, (GCObject *)uv, LUA_TUPVAL); uv->tt = LUA_TUPVAL; uv->v = &uv->u.value; uv->u.l.prev = NULL; @@ -1025,8 +1025,8 @@ static Proto *makefakeproto(lua_State *L, lu_byte nups) static void boxupval_start(lua_State *L) { LClosure *lcl; - lcl = (LClosure*)pdep_newLclosure(L, 1, hvalue(&L->l_gt)); - pushclosure(L, (Closure*)lcl); + lcl = (LClosure *)pdep_newLclosure(L, 1, hvalue(&L->l_gt)); + pushclosure(L, (Closure *)lcl); /* ... func */ lcl->p = makefakeproto(L, 1); @@ -1053,7 +1053,7 @@ static void unboxupval(lua_State *L) LClosure *lcl; UpVal *uv; - lcl = (LClosure*)clvalue(getobject(L, -1)); + lcl = (LClosure *)clvalue(getobject(L, -1)); uv = lcl->upvals[0]; lua_pop(L, 1); /* ... */ @@ -1071,8 +1071,8 @@ static void unpersistfunction(int ref, UnpersistInfo *upi) verify(LIF(Z,read)(&upi->zio, &nupvalues, sizeof(lu_byte)) == 0); - lcl = (LClosure*)pdep_newLclosure(upi->L, nupvalues, hvalue(&upi->L->l_gt)); - pushclosure(upi->L, (Closure*)lcl); + lcl = (LClosure *)pdep_newLclosure(upi->L, nupvalues, hvalue(&upi->L->l_gt)); + pushclosure(upi->L, (Closure *)lcl); /* perms reftbl ... func */ /* Put *some* proto in the closure, before the GC can find it */ @@ -1393,9 +1393,9 @@ static void unpersistthread(int ref, UnpersistInfo *upi) verify(LIF(Z,read)(&upi->zio, &stackpos, sizeof(size_t)) == 0); uv->v = L2->stack + stackpos; - gcunlink(upi->L, (GCObject*)uv); + gcunlink(upi->L, (GCObject *)uv); uv->marked = luaC_white(g); - *nextslot = (GCObject*)uv; + *nextslot = (GCObject *)uv; nextslot = &uv->next; uv->u.l.prev = &G(L2)->uvhead; uv->u.l.next = G(L2)->uvhead.u.l.next; @@ -1482,7 +1482,7 @@ static int inreftable(lua_State *L, int ref) int res; lua_checkstack(L, 1); /* perms reftbl ... */ - lua_pushlightuserdata(L, (void*)ref); + lua_pushlightuserdata(L, (void *)ref); /* perms reftbl ... ref */ lua_gettable(L, 2); /* perms reftbl ... obj? */ @@ -1571,7 +1571,7 @@ static void unpersist(UnpersistInfo *upi) lua_pushnil(upi->L); /* perms reftbl ... nil */ } else { - lua_pushlightuserdata(upi->L, (void*)ref); + lua_pushlightuserdata(upi->L, (void *)ref); /* perms reftbl ... ref */ lua_gettable(upi->L, 2); /* perms reftbl ... obj? */ |