diff options
author | Matthew Hoops | 2011-05-03 17:17:27 -0400 |
---|---|---|
committer | Matthew Hoops | 2011-05-03 17:25:41 -0400 |
commit | 9cb600099f4c29298707787cafad2741a1cd6686 (patch) | |
tree | fb1930fa56b611317831d66442cba19b18d2e57a /engines/sword25 | |
parent | 3b2283daf850605ca897002afbafe44489c35473 (diff) | |
parent | 95a6098f672191dc0792bd4f9bfa18706bbe8e3a (diff) | |
download | scummvm-rg350-9cb600099f4c29298707787cafad2741a1cd6686.tar.gz scummvm-rg350-9cb600099f4c29298707787cafad2741a1cd6686.tar.bz2 scummvm-rg350-9cb600099f4c29298707787cafad2741a1cd6686.zip |
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'engines/sword25')
49 files changed, 429 insertions, 2684 deletions
diff --git a/engines/sword25/detection.cpp b/engines/sword25/detection.cpp index 3900df2fcf..fe24675f8a 100644 --- a/engines/sword25/detection.cpp +++ b/engines/sword25/detection.cpp @@ -24,8 +24,6 @@ */ #include "base/plugins.h" -#include "common/savefile.h" -#include "common/system.h" #include "engines/advancedDetector.h" #include "sword25/sword25.h" diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 177bd38303..975f08be22 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -32,13 +32,17 @@ * */ +#include "common/debug.h" +#include "common/system.h" +#include "common/textconsole.h" +#include "common/util.h" + #include "sword25/sword25.h" // for kDebugScript #include "sword25/fmv/movieplayer.h" #include "sword25/gfx/graphicengine.h" #include "sword25/gfx/panel.h" #include "sword25/kernel/kernel.h" #include "sword25/package/packagemanager.h" -#include "sword25/sfx/soundengine.h" namespace Sword25 { @@ -121,7 +125,7 @@ void MoviePlayer::update() { const Graphics::Surface *s = _decoder.decodeNextFrame(); if (s) { // Transfer the next frame - assert(s->bytesPerPixel == 4); + assert(s->format.bytesPerPixel == 4); #ifdef THEORA_INDIRECT_RENDERING byte *frameData = (byte *)s->getBasePtr(0, 0); diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index e9901c04b0..86236fbd21 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -41,6 +41,7 @@ #ifdef USE_THEORADEC #include "common/system.h" +#include "common/textconsole.h" #include "graphics/conversion.h" #include "audio/decoders/raw.h" #include "sword25/kernel/common.h" @@ -289,7 +290,7 @@ bool TheoraDecoder::loadStream(Common::SeekableReadStream *stream) { _surface = new Graphics::Surface(); - _surface->create(_theoraInfo.frame_width, _theoraInfo.frame_height, 4); + _surface->create(_theoraInfo.frame_width, _theoraInfo.frame_height, g_system->getScreenFormat()); return true; } diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index a753bc58ac..4ed2af5f98 100644 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -30,9 +30,12 @@ #ifdef USE_THEORADEC +#include "common/rational.h" #include "video/video_decoder.h" #include "audio/audiostream.h" #include "audio/mixer.h" +#include "graphics/pixelformat.h" +#include "graphics/surface.h" #include <theora/theoradec.h> #include <vorbis/codec.h> diff --git a/engines/sword25/gfx/graphicengine.cpp b/engines/sword25/gfx/graphicengine.cpp index 5fefcec420..8bdf2a4a6e 100644 --- a/engines/sword25/gfx/graphicengine.cpp +++ b/engines/sword25/gfx/graphicengine.cpp @@ -112,8 +112,10 @@ bool GraphicEngine::init(int width, int height, int bitDepth, int backbufferCoun _screenRect.right = _width; _screenRect.bottom = _height; - _backSurface.create(width, height, 4); - _frameBuffer.create(width, height, 4); + const Graphics::PixelFormat format = g_system->getScreenFormat(); + + _backSurface.create(width, height, format); + _frameBuffer.create(width, height, format); // Standardmäßig ist Vsync an. setVsync(true); @@ -206,6 +208,7 @@ bool GraphicEngine::fill(const Common::Rect *fillRectPtr, uint color) { for (int i = rect.top; i < rect.bottom; i++) { out = outo; for (int j = rect.left; j < rect.right; j++) { +#if defined(SCUMM_LITTLE_ENDIAN) *out += (byte)(((cb - *out) * ca) >> 8); out++; *out += (byte)(((cg - *out) * ca) >> 8); @@ -214,6 +217,16 @@ bool GraphicEngine::fill(const Common::Rect *fillRectPtr, uint color) { out++; *out = 255; out++; +#else + *out = 255; + out++; + *out += (byte)(((cr - *out) * ca) >> 8); + out++; + *out += (byte)(((cg - *out) * ca) >> 8); + out++; + *out += (byte)(((cb - *out) * ca) >> 8); + out++; +#endif } outo += _backSurface.pitch; diff --git a/engines/sword25/gfx/graphicengine_script.cpp b/engines/sword25/gfx/graphicengine_script.cpp index d67d0038c3..d8daaab32c 100644 --- a/engines/sword25/gfx/graphicengine_script.cpp +++ b/engines/sword25/gfx/graphicengine_script.cpp @@ -81,26 +81,6 @@ static ActionCallback *actionCallbackPtr = 0; // FIXME: should be turned into Gr #define ANIMATION_TEMPLATE_CLASS_NAME "Gfx.AnimationTemplate" static const char *GFX_LIBRARY_NAME = "Gfx"; -// Wie luaL_checkudata, nur ohne dass kein Fehler erzeugt wird. -static void *my_checkudata(lua_State *L, int ud, const char *tname) { - int top = lua_gettop(L); - - void *p = lua_touserdata(L, ud); - if (p != NULL) { /* value is a userdata? */ - if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ - // lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ - LuaBindhelper::getMetatable(L, tname); - if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ - lua_settop(L, top); - return p; - } - } - } - - lua_settop(L, top); - return NULL; -} - static void newUintUserData(lua_State *L, uint value) { void *userData = lua_newuserdata(L, sizeof(value)); memcpy(userData, &value, sizeof(value)); @@ -108,8 +88,8 @@ static void newUintUserData(lua_State *L, uint value) { static AnimationTemplate *checkAnimationTemplate(lua_State *L, int idx = 1) { // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.AnimationTemplate - uint animationTemplateHandle; - if ((animationTemplateHandle = *reinterpret_cast<uint *>(my_checkudata(L, idx, ANIMATION_TEMPLATE_CLASS_NAME))) != 0) { + uint animationTemplateHandle = *reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, idx, ANIMATION_TEMPLATE_CLASS_NAME)); + if (animationTemplateHandle != 0) { AnimationTemplate *animationTemplatePtr = AnimationTemplateRegistry::instance().resolveHandle(animationTemplateHandle); if (!animationTemplatePtr) luaL_error(L, "The animation template with the handle %d does no longer exist.", animationTemplateHandle); @@ -370,10 +350,10 @@ static const luaL_reg GFX_FUNCTIONS[] = { static RenderObjectPtr<RenderObject> checkRenderObject(lua_State *L, bool errorIfRemoved = true) { // Der erste Parameter muss vom Typ userdata sein und die Metatable einer Klasse haben, die von Gfx.RenderObject "erbt". uint *userDataPtr; - if ((userDataPtr = (uint *) my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0 || - (userDataPtr = (uint *) my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0 || - (userDataPtr = (uint *) my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0 || - (userDataPtr = (uint *) my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) { + if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0 || + (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0 || + (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0 || + (userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) { RenderObjectPtr<RenderObject> roPtr(*userDataPtr); if (roPtr.isValid()) return roPtr; @@ -600,11 +580,11 @@ static const luaL_reg RENDEROBJECT_METHODS[] = { static RenderObjectPtr<Panel> checkPanel(lua_State *L) { // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Panel uint *userDataPtr; - if ((userDataPtr = (uint *)my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0) { + if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, PANEL_CLASS_NAME)) != 0) { RenderObjectPtr<RenderObject> roPtr(*userDataPtr); - if (roPtr.isValid()) { + if (roPtr.isValid()) return roPtr->toPanel(); - } else + else luaL_error(L, "The panel with the handle %d does no longer exist.", *userDataPtr); } else { luaL_argcheck(L, 0, 1, "'" PANEL_CLASS_NAME "' expected"); @@ -645,11 +625,11 @@ static const luaL_reg PANEL_METHODS[] = { static RenderObjectPtr<Bitmap> checkBitmap(lua_State *L) { // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Bitmap uint *userDataPtr; - if ((userDataPtr = (uint *)my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0) { + if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, BITMAP_CLASS_NAME)) != 0) { RenderObjectPtr<RenderObject> roPtr(*userDataPtr); - if (roPtr.isValid()) { + if (roPtr.isValid()) return roPtr->toBitmap(); - } else + else luaL_error(L, "The bitmap with the handle %d does no longer exist.", *userDataPtr); } else { luaL_argcheck(L, 0, 1, "'" BITMAP_CLASS_NAME "' expected"); @@ -790,13 +770,12 @@ static const luaL_reg BITMAP_METHODS[] = { static RenderObjectPtr<Animation> checkAnimation(lua_State *L) { // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Animation uint *userDataPtr; - if ((userDataPtr = (uint *)my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0) { + if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, ANIMATION_CLASS_NAME)) != 0) { RenderObjectPtr<RenderObject> roPtr(*userDataPtr); if (roPtr.isValid()) return roPtr->toAnimation(); - else { + else luaL_error(L, "The animation with the handle %d does no longer exist.", *userDataPtr); - } } else { luaL_argcheck(L, 0, 1, "'" ANIMATION_CLASS_NAME "' expected"); } @@ -1064,7 +1043,7 @@ static const luaL_reg ANIMATION_METHODS[] = { static RenderObjectPtr<Text> checkText(lua_State *L) { // Der erste Parameter muss vom Typ userdata sein und die Metatable der Klasse Gfx.Text uint *userDataPtr; - if ((userDataPtr = (uint *)my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) { + if ((userDataPtr = (uint *)LuaBindhelper::my_checkudata(L, 1, TEXT_CLASS_NAME)) != 0) { RenderObjectPtr<RenderObject> roPtr(*userDataPtr); if (roPtr.isValid()) return roPtr->toText(); diff --git a/engines/sword25/gfx/image/art.cpp b/engines/sword25/gfx/image/art.cpp index d30460901d..69f9425a53 100644 --- a/engines/sword25/gfx/image/art.cpp +++ b/engines/sword25/gfx/image/art.cpp @@ -1041,7 +1041,7 @@ static void art_pri_free(ArtPriQ *pq) { free(pq); } -static art_boolean art_pri_empty(ArtPriQ *pq) { +static bool art_pri_empty(ArtPriQ *pq) { return pq->n_items == 0; } @@ -1122,7 +1122,7 @@ static int art_svp_writer_rewind_add_segment(ArtSvpWriter *self, int wind_left, ArtSvpWriterRewind *swr = (ArtSvpWriterRewind *)self; ArtSVP *svp; ArtSVPSeg *seg; - art_boolean left_filled = 0, right_filled = 0; + bool left_filled = 0, right_filled = 0; int wind_right = wind_left + delta_wind; int seg_num; const int init_n_points_max = 4; @@ -1459,7 +1459,7 @@ static ArtActiveSeg *art_svp_intersect_add_point(ArtIntersectCtx *ctx, double x, ArtActiveSeg *seg, ArtBreakFlags break_flags) { ArtActiveSeg *left, *right; double x_min = x, x_max = x; - art_boolean left_live, right_live; + bool left_live, right_live; double d; double new_x; ArtActiveSeg *test, *result = NULL; @@ -1490,9 +1490,9 @@ static ArtActiveSeg *art_svp_intersect_add_point(ArtIntersectCtx *ctx, double x, left = left->left; left_live = (left != NULL); } else - left_live = ART_FALSE; + left_live = false; } else - left_live = ART_FALSE; + left_live = false; } else if (right_live) { if (x >= right->x[(right->flags & ART_ACTIVE_FLAGS_BNEG) ^ 1] && /* It may be that one of these conjuncts turns out to be always @@ -1510,9 +1510,9 @@ static ArtActiveSeg *art_svp_intersect_add_point(ArtIntersectCtx *ctx, double x, right = right->right; right_live = (right != NULL); } else - right_live = ART_FALSE; + right_live = false; } else - right_live = ART_FALSE; + right_live = false; } } @@ -1571,7 +1571,7 @@ static void art_svp_intersect_swap_active(ArtIntersectCtx *ctx, * Return value: True if the intersection took place at the current * scan line, indicating further iteration is needed. **/ -static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, +static bool art_svp_intersect_test_cross(ArtIntersectCtx *ctx, ArtActiveSeg *left_seg, ArtActiveSeg *right_seg, ArtBreakFlags break_flags) { double left_x0, left_y0, left_x1; @@ -1597,17 +1597,17 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (left_x1 < right_seg->x[(right_seg->flags & ART_ACTIVE_FLAGS_BNEG) ^ 1] || left_y1 == right_seg->y0) - return ART_FALSE; + return false; d = left_x1 * right_seg->a + left_y1 * right_seg->b + right_seg->c; if (d < -EPSILON_A) - return ART_FALSE; + return false; else if (d < EPSILON_A) { /* I'm unsure about the break flags here. */ double right_x1 = art_svp_intersect_break(ctx, right_seg, left_x1, left_y1, ART_BREAK_RIGHT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else if (left_y1 > right_y1) { /* Test right (x1, y1) against left segment */ @@ -1615,27 +1615,27 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (right_x1 > left_seg->x[left_seg->flags & ART_ACTIVE_FLAGS_BNEG] || right_y1 == left_seg->y0) - return ART_FALSE; + return false; d = right_x1 * left_seg->a + right_y1 * left_seg->b + left_seg->c; if (d > EPSILON_A) - return ART_FALSE; + return false; else if (d > -EPSILON_A) { /* See above regarding break flags. */ left_x1 = art_svp_intersect_break(ctx, left_seg, right_x1, right_y1, ART_BREAK_LEFT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else { /* left_y1 == right_y1 */ left_x1 = left_seg->x[1]; double right_x1 = right_seg->x[1]; if (left_x1 <= right_x1) - return ART_FALSE; + return false; } art_svp_intersect_swap_active(ctx, left_seg, right_seg); - return ART_TRUE; + return true; } if (left_y1 < right_y1) { @@ -1645,16 +1645,16 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (left_x1 < right_seg->x[(right_seg->flags & ART_ACTIVE_FLAGS_BNEG) ^ 1] || left_y1 == right_seg->y0) - return ART_FALSE; + return false; d = left_x1 * right_seg->a + left_y1 * right_seg->b + right_seg->c; if (d < -EPSILON_A) - return ART_FALSE; + return false; else if (d < EPSILON_A) { double right_x1 = art_svp_intersect_break(ctx, right_seg, left_x1, left_y1, ART_BREAK_RIGHT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else if (left_y1 > right_y1) { /* Test right (x1, y1) against left segment */ @@ -1662,23 +1662,23 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if (right_x1 > left_seg->x[left_seg->flags & ART_ACTIVE_FLAGS_BNEG] || right_y1 == left_seg->y0) - return ART_FALSE; + return false; d = right_x1 * left_seg->a + right_y1 * left_seg->b + left_seg->c; if (d > EPSILON_A) - return ART_FALSE; + return false; else if (d > -EPSILON_A) { left_x1 = art_svp_intersect_break(ctx, left_seg, right_x1, right_y1, ART_BREAK_LEFT); if (left_x1 <= right_x1) - return ART_FALSE; + return false; } } else { /* left_y1 == right_y1 */ left_x1 = left_seg->x[1]; double right_x1 = right_seg->x[1]; if (left_x1 <= right_x1) - return ART_FALSE; + return false; } /* The segments cross. Find the intersection point. */ @@ -1748,7 +1748,7 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, winner->horiz_delta_wind -= loser->delta_wind; art_svp_intersect_swap_active(ctx, left_seg, right_seg); - return ART_TRUE; + return true; } } else if (y == right_seg->y0) { art_svp_intersect_push_pt(ctx, left_seg, x, y); @@ -1764,7 +1764,7 @@ static art_boolean art_svp_intersect_test_cross(ArtIntersectCtx *ctx, if ((break_flags & ART_BREAK_RIGHT) && right_seg->right != NULL) art_svp_intersect_add_point(ctx, x, y, right_seg->right, break_flags); } - return ART_FALSE; + return false; } /** @@ -1885,7 +1885,7 @@ static void art_svp_intersect_horiz(ArtIntersectCtx *ctx, ArtActiveSeg *seg, if (x0 > x1) { ArtActiveSeg *left; - art_boolean first = ART_TRUE; + bool first = true; for (left = seg->left; left != NULL; left = seg->left) { int left_bneg = left->flags & ART_ACTIVE_FLAGS_BNEG; @@ -1902,12 +1902,12 @@ static void art_svp_intersect_horiz(ArtIntersectCtx *ctx, ArtActiveSeg *seg, if (first && left->right != NULL) { art_svp_intersect_test_cross(ctx, left, left->right, ART_BREAK_RIGHT); - first = ART_FALSE; + first = false; } } } else { ArtActiveSeg *right; - art_boolean first = ART_TRUE; + bool first = true; for (right = seg->right; right != NULL; right = seg->right) { int right_bneg = right->flags & ART_ACTIVE_FLAGS_BNEG; @@ -1925,7 +1925,7 @@ static void art_svp_intersect_horiz(ArtIntersectCtx *ctx, ArtActiveSeg *seg, if (first && right->left != NULL) { art_svp_intersect_test_cross(ctx, right->left, right, ART_BREAK_RIGHT); - first = ART_FALSE; + first = false; } } } @@ -2231,7 +2231,7 @@ void art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out) { typedef double artfloat; -struct _ArtSVPRenderAAIter { +struct ArtSVPRenderAAIter { const ArtSVP *svp; int x0, x1; int y; diff --git a/engines/sword25/gfx/image/art.h b/engines/sword25/gfx/image/art.h index 90baa770cf..fe3bbd4982 100644 --- a/engines/sword25/gfx/image/art.h +++ b/engines/sword25/gfx/image/art.h @@ -42,10 +42,6 @@ namespace Sword25 { -typedef byte art_u8; -typedef uint16 art_u16; -typedef uint32 art_u32; - /* These aren't, strictly speaking, configuration macros, but they're damn handy to have around, and may be worth playing with for debugging. */ @@ -55,95 +51,55 @@ typedef uint32 art_u32; /* This one must be used carefully - in particular, p and max should be variables. They can also be pstruct->el lvalues. */ -#define art_expand(p, type, max) do { if(max) { p = art_renew (p, type, max <<= 1); } else { max = 1; p = art_new(type, 1); } } while (0) - -typedef int art_boolean; -#define ART_FALSE 0 -#define ART_TRUE 1 - -/* define pi */ -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif /* M_PI */ - -#ifndef M_SQRT2 -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#endif /* M_SQRT2 */ - -/* Provide macros to feature the GCC function attribute. - */ -#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)) -#define ART_GNUC_PRINTF( format_idx, arg_idx ) \ - __attribute__((__format__ (__printf__, format_idx, arg_idx))) -#define ART_GNUC_NORETURN \ - __attribute__((__noreturn__)) -#else /* !__GNUC__ */ -#define ART_GNUC_PRINTF( format_idx, arg_idx ) -#define ART_GNUC_NORETURN -#endif /* !__GNUC__ */ - -void ART_GNUC_NORETURN -art_die(const char *fmt, ...) ART_GNUC_PRINTF(1, 2); - -void -art_warn(const char *fmt, ...) ART_GNUC_PRINTF(1, 2); - -typedef struct _ArtDRect ArtDRect; -typedef struct _ArtIRect ArtIRect; - -struct _ArtDRect { +#define art_expand(p, type, max) \ + do { \ + if(max) {\ + p = art_renew(p, type, max <<= 1); \ + } else { \ + max = 1; \ + p = art_new(type, 1); \ + } \ + } while (0) + +struct ArtDRect { /*< public >*/ double x0, y0, x1, y1; }; -struct _ArtIRect { - /*< public >*/ - int x0, y0, x1, y1; -}; - -typedef struct _ArtPoint ArtPoint; - -struct _ArtPoint { +struct ArtPoint { /*< public >*/ double x, y; }; /* Basic data structures and constructors for sorted vector paths */ -typedef struct _ArtSVP ArtSVP; -typedef struct _ArtSVPSeg ArtSVPSeg; - -struct _ArtSVPSeg { +struct ArtSVPSeg { int n_points; int dir; /* == 0 for "up", 1 for "down" */ ArtDRect bbox; ArtPoint *points; }; -struct _ArtSVP { +struct ArtSVP { int n_segs; ArtSVPSeg segs[1]; }; -void -art_svp_free(ArtSVP *svp); +void art_svp_free(ArtSVP *svp); -int -art_svp_seg_compare(const void *s1, const void *s2); +int art_svp_seg_compare(const void *s1, const void *s2); /* Basic data structures and constructors for bezier paths */ -typedef enum { +enum ArtPathcode { ART_MOVETO, ART_MOVETO_OPEN, ART_CURVETO, ART_LINETO, ART_END -} ArtPathcode; - -typedef struct _ArtBpath ArtBpath; +}; -struct _ArtBpath { +struct ArtBpath { /*< public >*/ ArtPathcode code; double x1; @@ -156,10 +112,8 @@ struct _ArtBpath { /* Basic data structures and constructors for simple vector paths */ -typedef struct _ArtVpath ArtVpath; - /* CURVETO is not allowed! */ -struct _ArtVpath { +struct ArtVpath { ArtPathcode code; double x; double y; @@ -167,8 +121,7 @@ struct _ArtVpath { /* Some of the functions need to go into their own modules */ -void -art_vpath_add_point(ArtVpath **p_vpath, int *pn_points, int *pn_points_max, +void art_vpath_add_point(ArtVpath **p_vpath, int *pn_points, int *pn_points_max, ArtPathcode code, double x, double y); ArtVpath *art_bez_path_to_vec(const ArtBpath *bez, double flatness); @@ -177,57 +130,49 @@ ArtVpath *art_bez_path_to_vec(const ArtBpath *bez, double flatness); #ifndef ART_WIND_RULE_DEFINED #define ART_WIND_RULE_DEFINED -typedef enum { +enum ArtWindRule { ART_WIND_RULE_NONZERO, ART_WIND_RULE_INTERSECT, ART_WIND_RULE_ODDEVEN, ART_WIND_RULE_POSITIVE -} ArtWindRule; +}; #endif -typedef struct _ArtSvpWriter ArtSvpWriter; - -struct _ArtSvpWriter { +struct ArtSvpWriter { int (*add_segment)(ArtSvpWriter *self, int wind_left, int delta_wind, double x, double y); void (*add_point)(ArtSvpWriter *self, int seg_id, double x, double y); void (*close_segment)(ArtSvpWriter *self, int seg_id); }; -ArtSvpWriter * -art_svp_writer_rewind_new(ArtWindRule rule); +ArtSvpWriter *art_svp_writer_rewind_new(ArtWindRule rule); -ArtSVP * -art_svp_writer_rewind_reap(ArtSvpWriter *self); +ArtSVP *art_svp_writer_rewind_reap(ArtSvpWriter *self); -int -art_svp_seg_compare(const void *s1, const void *s2); +int art_svp_seg_compare(const void *s1, const void *s2); -void -art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out); +void art_svp_intersector(const ArtSVP *in, ArtSvpWriter *out); /* Sort vector paths into sorted vector paths. */ -ArtSVP * -art_svp_from_vpath(ArtVpath *vpath); +ArtSVP *art_svp_from_vpath(ArtVpath *vpath); /* Sort vector paths into sorted vector paths. */ -typedef enum { +enum ArtPathStrokeJoinType { ART_PATH_STROKE_JOIN_MITER, ART_PATH_STROKE_JOIN_ROUND, ART_PATH_STROKE_JOIN_BEVEL -} ArtPathStrokeJoinType; +}; -typedef enum { +enum ArtPathStrokeCapType { ART_PATH_STROKE_CAP_BUTT, ART_PATH_STROKE_CAP_ROUND, ART_PATH_STROKE_CAP_SQUARE -} ArtPathStrokeCapType; +}; -ArtSVP * -art_svp_vpath_stroke(ArtVpath *vpath, +ArtSVP *art_svp_vpath_stroke(ArtVpath *vpath, ArtPathStrokeJoinType join, ArtPathStrokeCapType cap, double line_width, @@ -235,8 +180,7 @@ art_svp_vpath_stroke(ArtVpath *vpath, double flatness); /* This version may have winding numbers exceeding 1. */ -ArtVpath * -art_svp_vpath_stroke_raw(ArtVpath *vpath, +ArtVpath *art_svp_vpath_stroke_raw(ArtVpath *vpath, ArtPathStrokeJoinType join, ArtPathStrokeCapType cap, double line_width, @@ -246,27 +190,22 @@ art_svp_vpath_stroke_raw(ArtVpath *vpath, /* The spiffy antialiased renderer for sorted vector paths. */ -typedef struct _ArtSVPRenderAAStep ArtSVPRenderAAStep; -typedef struct _ArtSVPRenderAAIter ArtSVPRenderAAIter; - -struct _ArtSVPRenderAAStep { +struct ArtSVPRenderAAStep { int x; int delta; /* stored with 16 fractional bits */ }; -ArtSVPRenderAAIter * -art_svp_render_aa_iter(const ArtSVP *svp, +struct ArtSVPRenderAAIter; + +ArtSVPRenderAAIter *art_svp_render_aa_iter(const ArtSVP *svp, int x0, int y0, int x1, int y1); -void -art_svp_render_aa_iter_step(ArtSVPRenderAAIter *iter, int *p_start, +void art_svp_render_aa_iter_step(ArtSVPRenderAAIter *iter, int *p_start, ArtSVPRenderAAStep **p_steps, int *p_n_steps); -void -art_svp_render_aa_iter_done(ArtSVPRenderAAIter *iter); +void art_svp_render_aa_iter_done(ArtSVPRenderAAIter *iter); -void -art_svp_render_aa(const ArtSVP *svp, +void art_svp_render_aa(const ArtSVP *svp, int x0, int y0, int x1, int y1, void (*callback)(void *callback_data, int y, diff --git a/engines/sword25/gfx/image/image.h b/engines/sword25/gfx/image/image.h index 5ac6d1ac25..7029402c4a 100644 --- a/engines/sword25/gfx/image/image.h +++ b/engines/sword25/gfx/image/image.h @@ -55,75 +55,72 @@ public: // Enums /** - @brief Die möglichen Flippingparameter für die Blit-Methode. + @brief The possible flipping parameters for the blit methode. */ enum FLIP_FLAGS { - /// Das Bild wird nicht gespiegelt. + /// The image will not be flipped. FLIP_NONE = 0, - /// Das Bild wird an der horizontalen Achse gespiegelt. + /// The image will be flipped at the horizontal axis. FLIP_H = 1, - /// Das Bild wird an der vertikalen Achse gespiegelt. + /// The image will be flipped at the vertical axis. FLIP_V = 2, - /// Das Bild wird an der horizontalen und vertikalen Achse gespiegelt. + /// The image will be flipped at the horizontal and vertical axis. FLIP_HV = FLIP_H | FLIP_V, - /// Das Bild wird an der horizontalen und vertikalen Achse gespiegelt. + /// The image will be flipped at the horizontal and vertical axis. FLIP_VH = FLIP_H | FLIP_V }; //@{ - /** @name Accessor-Methoden */ + /** @name Accessor methods */ /** - @brief Gibt die Breite des Bildes in Pixeln zurück + @brief Returns the width of the image in pixels */ virtual int getWidth() const = 0; /** - @brief Gibt die Höhe des Bildes in Pixeln zurück + @brief Returns the height of the image in pixels */ virtual int getHeight() const = 0; /** - @brief Gibt das Farbformat des Bildes zurück + @brief Returns the color format of the image */ virtual GraphicEngine::COLOR_FORMATS getColorFormat() const = 0; //@} //@{ - /** @name Render-Methoden */ + /** @name Render methodes */ /** - @brief Rendert das Bild in den Framebuffer. - @param pDest ein Pointer auf das Zielbild. In den meisten Fällen ist dies der Framebuffer. - @param PosX die Position auf der X-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br> - Der Standardwert ist 0. - @param PosY die Position auf der Y-Achse im Zielbild in Pixeln, an der das Bild gerendert werden soll.<br> - Der Standardwert ist 0. - @param Flipping gibt an, wie das Bild gespiegelt werden soll.<br> - Der Standardwert ist BS_Image::FLIP_NONE (keine Spiegelung) - @param pSrcPartRect Pointer auf ein Common::Rect, welches den Ausschnitt des Quellbildes spezifiziert, der gerendert - werden soll oder NULL, falls das gesamte Bild gerendert werden soll.<br> - Dieser Ausschnitt bezieht sich auf das ungespiegelte und unskalierte Bild.<br> - Der Standardwert ist NULL. - @param Color ein ARGB Farbwert, der die Parameter für die Farbmodulation und fürs Alphablending festlegt.<br> - Die Alpha-Komponente der Farbe bestimmt den Alphablending Parameter (0 = keine Deckung, 255 = volle Deckung).<br> - Die Farbkomponenten geben die Farbe für die Farbmodulation an.<br> - Der Standardwert is BS_ARGB(255, 255, 255, 255) (volle Deckung, keine Farbmodulation). - Zum Erzeugen des Farbwertes können die Makros BS_RGB und BS_ARGB benutzt werden. - @param Width gibt die Ausgabebreite des Bildausschnittes an. - Falls diese von der Breite des Bildausschnittes abweicht wird - das Bild entsprechend Skaliert.<br> - Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br> - Der Standardwert ist -1. - @param Width gibt die Ausgabehöhe des Bildausschnittes an. - Falls diese von der Höhe des Bildauschnittes abweicht, wird - das Bild entsprechend Skaliert.<br> - Der Wert -1 gibt an, dass das Bild nicht Skaliert werden soll.<br> - Der Standardwert ist -1. - @return Gibt false zurück, falls das Rendern fehlgeschlagen ist. - @remark Er werden nicht alle Blitting-Operationen von allen BS_Image-Klassen unterstützt.<br> - Mehr Informationen gibt es in der Klassenbeschreibung von BS_Image und durch folgende Methoden: + @brief renders the image in the framebuffer + @param pDest a pointer to the target image. In most cases this is the framebuffer. + @param PosX the position on the X-axis in the target image in pixels where the image is supposed to be rendered.<br> + The default value is 0. + @param PosY the position on the Y-axis in the target image in pixels where the image is supposed to be rendered.<br> + The default value is 0. + @param Flipping how the the image should be flipped.<br> + The default value is BS_Image::FLIP_NONE (no flipping) + @param pSrcPartRect Pointer on Common::Rect which specifies the section to be rendered. If the whole image has to be rendered the Pointer is NULL.<br> + This referes to the unflipped and unscaled image.<br> + The default value is NULL. + @param Color an ARGB color value, which determines the parameters for the color modulation und alpha blending.<br> + The alpha component of the color determines the alpha blending parameter (0 = no covering, 255 = full covering).<br> + The color components determines the color for color modulation.<br> + The default value is BS_ARGB(255, 255, 255, 255) (full covering, no color modulation). + The macros BS_RGB and BS_ARGB can be used for the creation of the color value. + @param Width the output width of the screen section. + The images will be scaled if the output width of the screen section differs from the image section.<br> + The value -1 determines that the image should not be scaled.<br> + The default value is -1. + @param Width the output height of the screen section. + The images will be scaled if the output width of the screen section differs from the image section.<br> + The value -1 determines that the image should not be scaled.<br> + The default value is -1. + @return returns false if the rendering failed. + @remark Not all blitting operations of all BS_Image classes are supported.<br> + More information can be find in the class description of BS_Image and the following methodes: - IsBlitTarget() - IsScalingAllowed() - IsFillingAllowed() @@ -138,79 +135,74 @@ public: int width = -1, int height = -1) = 0; /** - @brief Füllt einen Rechteckigen Bereich des Bildes mit einer Farbe. - @param pFillRect Pointer auf ein Common::Rect, welches den Ausschnitt des Bildes spezifiziert, der gefüllt - werden soll oder NULL, falls das gesamte Bild gefüllt werden soll.<br> - Der Standardwert ist NULL. - @param Color der 32 Bit Farbwert mit dem der Bildbereich gefüllt werden soll. - @remark Es ist möglich über die Methode transparente Rechtecke darzustellen, indem man eine Farbe mit einem Alphawert ungleich - 255 angibt. - @remark Unabhängig vom Farbformat des Bildes muss ein 32 Bit Farbwert angegeben werden. Zur Erzeugung, können die Makros - BS_RGB und BS_ARGB benutzt werden. - @remark Falls das Rechteck nicht völlig innerhalb des Bildschirms ist, wird es automatisch zurechtgestutzt. + @brief fills a rectangular section of the image with a color. + @param pFillRect Pointer on Common::Rect which specifies the section of the image which is supposed to be filled. If the whole image has to be filled this value is NULL.<br> + The default value is NULL. + @param Color the 32 Bit color value for filling the image section. + @remark It is possible to create transparent rectangulars by using a color with alpha value not equal to 255. + @remark Independent from the color format of the image, it must be given a 32 bit color value. The macros BS_RGB and BS_ARGB can be used for the creation of the color value. + @remark If the rectangular is not completely inside the screen area, it will be automatically trimmed. */ virtual bool fill(const Common::Rect *pFillRect = 0, uint color = BS_RGB(0, 0, 0)) = 0; /** - @brief Füllt den Inhalt des Bildes mit Pixeldaten. - @param Pixeldata ein Vector der die Pixeldaten enthält. Sie müssen in dem Farbformat des Bildes vorliegen und es müssen genügend Daten - vorhanden sein, um das ganze Bild zu füllen. - @param Offset der Offset in Byte im Pixeldata-Vector an dem sich der erste zu schreibende Pixel befindet.<br> - Der Standardwert ist 0. - @param Stride der Abstand in Byte zwischen dem Zeilenende und dem Beginn einer neuen Zeile im Pixeldata-Vector.<br> - Der Standardwert ist 0. - @return Gibt false zurück, falls der Aufruf fehlgeschlagen ist. - @remark Ein Aufruf dieser Methode ist nur erlaubt, wenn IsSetContentAllowed() true zurückgibt. + @brief Fills the content of the image with pixel data. + @param Pixeldata a vector which cotains the pixel data. They must be present in the color format of the image and there must be enough data available for filling the whole image. + @param Offset the offset in Byte in Pixeldata-Vector on which the first pixel to write is located.<br> + The default value is 0. + @param Stride the distance in Byte between the end of line and the beginning of a new line in Pixeldata-Vector.<br> + The default value is 0. + @return returns false, if the call failed. + @remark A call of this methode is only allowd if IsSetContentAllowed() returns true. */ virtual bool setContent(const byte *pixeldata, uint size, uint offset, uint stride) = 0; /** - @brief Liest einen Pixel des Bildes. - @param X die X-Koordinate des Pixels. - @param Y die Y-Koordinate des Pixels - @return Gibt den 32-Bit Farbwert des Pixels an der übergebenen Koordinate zurück. - @remark Diese Methode sollte auf keine Fall benutzt werden um größere Teile des Bildes zu lesen, da sie sehr langsam ist. Sie ist - eher dafür gedacht einzelne Pixel des Bildes auszulesen. + @brief Reads out a pixel of the image. + @param X the X-coordinate of the pixel. + @param Y the y-coordinate of the pixel. + @return Returns the 32-bit color value of the pixel at the given position. + @remark This methode should not be used in no way to read out bigger parts of the image because the method is very slow. The method is rather intended for reading out single pixels of the image.. */ virtual uint getPixel(int x, int y) = 0; //@{ - /** @name Auskunfts-Methoden */ + /** @name Information methodes */ /** - @brief Überprüft, ob an dem BS_Image Blit() aufgerufen werden darf. - @return Gibt false zurück, falls ein Blit()-Aufruf an diesem Objekt nicht gestattet ist. + @brief Checks, if it is allowed to call BS_Image Blit(). + @return Returns false, if a Blit() call is not allowed at this object. */ virtual bool isBlitSource() const = 0; /** - @brief Überprüft, ob das BS_Image ein Zielbild für einen Blit-Aufruf sein kann. - @return Gibt false zurück, falls ein Blit-Aufruf mit diesem Objekt als Ziel nicht gestattet ist. + @brief Checks, if the BS_Image can be a target image for a Blit call. + @return Returns false, if a Blit() call with this object as an target is not allowed. */ virtual bool isBlitTarget() const = 0; /** - @brief Gibt true zurück, falls das BS_Image bei einem Aufruf von Blit() skaliert dargestellt werden kann. + @brief Returns true, if the BS_Image is allowed to be scaled by a Blit() call. */ virtual bool isScalingAllowed() const = 0; /** - @brief Gibt true zurück, wenn das BS_Image mit einem Aufruf von Fill() gefüllt werden kann. + @brief Returns true, if the BS_Image is allowed to be filled by a Fill() call. */ virtual bool isFillingAllowed() const = 0; /** - @brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit einem Alphawert dargestellt werden kann. + @brief Returns true, if the BS_Image is allowed to be displayed with an alpha value. */ virtual bool isAlphaAllowed() const = 0; /** - @brief Gibt true zurück, wenn das BS_Image bei einem Aufruf von Blit() mit Farbmodulation dargestellt werden kann. + @brief Return true, if the BS_Image is allowed to be displayed with color modulation by a Blit() call */ virtual bool isColorModulationAllowed() const = 0; /** - @brief Gibt true zurück, wenn der Inhalt des BS_Image durch eine Aufruf von SetContent() ausgetauscht werden kann. + @brief Returns true, if the content of the BS_Image is allowed to be replaced by call of SetContent(). */ virtual bool isSetContentAllowed() const = 0; diff --git a/engines/sword25/gfx/image/pngloader.cpp b/engines/sword25/gfx/image/pngloader.cpp index f54b45254b..f6c00b6968 100644 --- a/engines/sword25/gfx/image/pngloader.cpp +++ b/engines/sword25/gfx/image/pngloader.cpp @@ -84,7 +84,7 @@ static uint findEmbeddedPNG(const byte *fileDataPtr, uint fileSize) { Common::MemoryReadStream stream(fileDataPtr, fileSize); stream.seek(0, SEEK_SET); - // Headerinformationen der Spielstandes einlesen. + // Read header information of savegame uint compressedGamedataSize; loadString(stream); // Marker loadString(stream); // Version @@ -124,7 +124,7 @@ bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&unc error("png_check_sig failed"); } - // Die beiden PNG Strukturen erstellen + // Create both PNG structures png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { error("Could not create libpng read struct."); @@ -135,31 +135,31 @@ bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&unc error("Could not create libpng info struct."); } - // Alternative Lesefunktion benutzen + // Use alternative reading function const byte **ref = &fileDataPtr; png_set_read_fn(png_ptr, (void *)ref, png_user_read_data); - // PNG Header einlesen + // Read PNG header png_read_info(png_ptr, info_ptr); - // PNG Informationen auslesen + // Read out PNG informations png_uint_32 w, h; png_get_IHDR(png_ptr, info_ptr, &w, &h, &bitDepth, &colorType, &interlaceType, NULL, NULL); width = w; height = h; - // Pitch des Ausgabebildes berechnen + // Calculate pitch of output image pitch = GraphicEngine::calcPitch(GraphicEngine::CF_ARGB32, width); - // Speicher für die endgültigen Bilddaten reservieren - // Dieses geschieht vor dem reservieren von Speicher für temporäre Bilddaten um die Fragmentierung des Speichers gering zu halten + // Allocate memory for the final image data. + // To keep memory framentation low this happens before allocating memory for temporary image data. uncompressedDataPtr = new byte[pitch * height]; if (!uncompressedDataPtr) { error("Could not allocate memory for output image."); } - // Bilder jeglicher Farbformate werden zunächst in ARGB Bilder umgewandelt + // Images of all color formates will be transformed into ARGB images if (bitDepth == 16) png_set_strip_16(png_ptr); if (colorType == PNG_COLOR_TYPE_PALETTE) @@ -177,7 +177,7 @@ bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&unc if (colorType != PNG_COLOR_TYPE_RGB_ALPHA) png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER); - // Nachdem die Transformationen registriert wurden, werden die Bilddaten erneut eingelesen + // After the transformations have been registered, the image data is read again. png_read_update_info(png_ptr, info_ptr); png_get_IHDR(png_ptr, info_ptr, &w, &h, &bitDepth, &colorType, NULL, NULL, NULL); width = w; @@ -218,7 +218,7 @@ bool PNGLoader::doDecodeImage(const byte *fileDataPtr, uint fileSize, byte *&unc 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 - error("Error while reading PNG image"); + 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); @@ -251,7 +251,7 @@ bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &w png_structp png_ptr = NULL; png_infop info_ptr = NULL; - // Die beiden PNG Strukturen erstellen + // Create both PNG structures png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { error("Could not create libpng read struct."); @@ -262,14 +262,14 @@ bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &w error("Could not create libpng info struct."); } - // Alternative Lesefunktion benutzen + // Use alternative reading function const byte **ref = &fileDataPtr; png_set_read_fn(png_ptr, (void *)ref, png_user_read_data); - // PNG Header einlesen + // Read PNG Header png_read_info(png_ptr, info_ptr); - // PNG Informationen auslesen + // Read out PNG informations int bitDepth; int colorType; png_uint_32 w, h; @@ -278,7 +278,7 @@ bool PNGLoader::doImageProperties(const byte *fileDataPtr, uint fileSize, int &w width = w; height = h; - // Die Strukturen freigeben + // Destroy libpng structures png_destroy_read_struct(&png_ptr, &info_ptr, NULL); #else // We don't need to read the image properties here... diff --git a/engines/sword25/gfx/image/renderedimage.cpp b/engines/sword25/gfx/image/renderedimage.cpp index 0d2ffb5aee..806d9b27ad 100644 --- a/engines/sword25/gfx/image/renderedimage.cpp +++ b/engines/sword25/gfx/image/renderedimage.cpp @@ -59,7 +59,7 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) : _backSurface = Kernel::getInstance()->getGfx()->getSurface(); - // Datei laden + // Load file byte *pFileData; uint fileSize; pFileData = pPackage->getFile(filename, &fileSize); @@ -68,7 +68,7 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) : return; } - // Bildeigenschaften bestimmen + // Determine image properties int pitch; if (!PNGLoader::imageProperties(pFileData, fileSize, _width, _height)) { error("Could not read image properties."); @@ -76,14 +76,14 @@ RenderedImage::RenderedImage(const Common::String &filename, bool &result) : return; } - // Das Bild dekomprimieren + // Uncompress the image if (!PNGLoader::decodeImage(pFileData, fileSize, _data, _width, _height, pitch)) { error("Could not decode image."); delete[] pFileData; return; } - // Dateidaten freigeben + // Cleanup FileData delete[] pFileData; _doCleanup = true; @@ -134,7 +134,7 @@ bool RenderedImage::fill(const Common::Rect *pFillRect, uint color) { // ----------------------------------------------------------------------------- bool RenderedImage::setContent(const byte *pixeldata, uint size, uint offset, uint stride) { - // Überprüfen, ob PixelData ausreichend viele Pixel enthält um ein Bild der Größe Width * Height zu erzeugen + // Check if PixelData contains enough pixel to create an image with image size equals width * height if (size < static_cast<uint>(_width * _height * 4)) { error("PixelData vector is too small to define a 32 bit %dx%d image.", _width, _height); return false; @@ -187,7 +187,8 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe // Create an encapsulating surface for the data Graphics::Surface srcImage; - srcImage.bytesPerPixel = 4; + // TODO: Is the data really in the screen format? + srcImage.format = g_system->getScreenFormat(); srcImage.pitch = _width * 4; srcImage.w = _width; srcImage.h = _height; @@ -198,11 +199,11 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe srcImage.w = pPartRect->right - pPartRect->left; srcImage.h = pPartRect->bottom - pPartRect->top; - debug(6, "Blit(%d, %d, %d, [%d, %d, %d, %d], %08x, %d, %d)", posX, posY, flipping, + debug(6, "Blit(%d, %d, %d, [%d, %d, %d, %d], %08x, %d, %d)", posX, posY, flipping, pPartRect->left, pPartRect->top, pPartRect->width(), pPartRect->height(), color, width, height); } else { - debug(6, "Blit(%d, %d, %d, [%d, %d, %d, %d], %08x, %d, %d)", posX, posY, flipping, 0, 0, + debug(6, "Blit(%d, %d, %d, [%d, %d, %d, %d], %08x, %d, %d)", posX, posY, flipping, 0, 0, srcImage.w, srcImage.h, color, width, height); } @@ -267,10 +268,11 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe out = outo; in = ino; for (int j = 0; j < img->w; j++) { - int b = in[0]; - int g = in[1]; - int r = in[2]; - int a = in[3]; + uint32 pix = *(uint32 *)in; + int b = (pix >> 0) & 0xff; + int g = (pix >> 8) & 0xff; + int r = (pix >> 16) & 0xff; + int a = (pix >> 24) & 0xff; in += inStep; if (ca != 255) { @@ -282,6 +284,7 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe out += 4; break; case 255: // Full opacity +#if defined(SCUMM_LITTLE_ENDIAN) if (cb != 255) *out++ = (b * cb) >> 8; else @@ -298,9 +301,28 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe *out++ = r; *out++ = a; +#else + *out++ = a; + + if (cr != 255) + *out++ = (r * cr) >> 8; + else + *out++ = r; + + if (cg != 255) + *out++ = (g * cg) >> 8; + else + *out++ = g; + + if (cb != 255) + *out++ = (b * cb) >> 8; + else + *out++ = b; +#endif break; default: // alpha blending +#if defined(SCUMM_LITTLE_ENDIAN) if (cb != 255) *out += ((b - *out) * a * cb) >> 16; else @@ -318,13 +340,32 @@ bool RenderedImage::blit(int posX, int posY, int flipping, Common::Rect *pPartRe out++; *out = 255; out++; +#else + *out = 255; + out++; + if (cr != 255) + *out += ((r - *out) * a * cr) >> 16; + else + *out += ((r - *out) * a) >> 8; + out++; + if (cg != 255) + *out += ((g - *out) * a * cg) >> 16; + else + *out += ((g - *out) * a) >> 8; + out++; + if (cb != 255) + *out += ((b - *out) * a * cb) >> 16; + else + *out += ((b - *out) * a) >> 8; + out++; +#endif } } outo += _backSurface->pitch; ino += inoStep; } - g_system->copyRectToScreen((byte *)_backSurface->getBasePtr(posX, posY), _backSurface->pitch, posX, posY, + g_system->copyRectToScreen((byte *)_backSurface->getBasePtr(posX, posY), _backSurface->pitch, posX, posY, img->w, img->h); } @@ -369,7 +410,7 @@ void RenderedImage::copyDirectly(int posX, int posY) { */ Graphics::Surface *RenderedImage::scale(const Graphics::Surface &srcImage, int xSize, int ySize) { Graphics::Surface *s = new Graphics::Surface(); - s->create(xSize, ySize, srcImage.bytesPerPixel); + s->create(xSize, ySize, srcImage.format); int *horizUsage = scaleLine(xSize, srcImage.w); int *vertUsage = scaleLine(ySize, srcImage.h); @@ -380,8 +421,8 @@ Graphics::Surface *RenderedImage::scale(const Graphics::Surface &srcImage, int x byte *destP = (byte *)s->getBasePtr(0, yp); for (int xp = 0; xp < xSize; ++xp) { - const byte *tempSrcP = srcP + (horizUsage[xp] * srcImage.bytesPerPixel); - for (int byteCtr = 0; byteCtr < srcImage.bytesPerPixel; ++byteCtr) { + const byte *tempSrcP = srcP + (horizUsage[xp] * srcImage.format.bytesPerPixel); + for (int byteCtr = 0; byteCtr < srcImage.format.bytesPerPixel; ++byteCtr) { *destP++ = *tempSrcP++; } } @@ -413,7 +454,7 @@ int *RenderedImage::scaleLine(int size, int srcSize) { distCtr -= 100; } } - + return v; } diff --git a/engines/sword25/gfx/image/renderedimage.h b/engines/sword25/gfx/image/renderedimage.h index 0375c7acbe..e3f23747da 100644 --- a/engines/sword25/gfx/image/renderedimage.h +++ b/engines/sword25/gfx/image/renderedimage.h @@ -50,12 +50,12 @@ public: RenderedImage(const Common::String &filename, bool &result); /** - @brief Erzeugt ein leeres BS_RenderedImage + @brief Creates an empty BS_RenderedImage - @param Width die Breite des zu erzeugenden Bildes. - @param Height die Höhe des zu erzeugenden Bildes - @param Result gibt dem Aufrufer bekannt, ob der Konstruktor erfolgreich ausgeführt wurde. Wenn es nach dem Aufruf false enthalten sollte, - dürfen keine Methoden am Objekt aufgerufen werden und das Objekt ist sofort zu zerstören. + @param Width The width of the image to be created. + @param Height The height of the image to be created + @param Result Informs the caller, whether the constructor is executed successfully. If it contains false + after the call, do not call methods on the object and destroy the object immediately. */ RenderedImage(uint width, uint height, bool &result); RenderedImage(); @@ -84,25 +84,25 @@ public: void replaceContent(byte *pixeldata, int width, int height); virtual uint getPixel(int x, int y); - virtual bool isBlitSource() const { + virtual bool isBlitSource() const { return true; } - virtual bool isBlitTarget() const { + virtual bool isBlitTarget() const { return false; } - virtual bool isScalingAllowed() const { + virtual bool isScalingAllowed() const { return true; } - virtual bool isFillingAllowed() const { + virtual bool isFillingAllowed() const { return false; } - virtual bool isAlphaAllowed() const { + virtual bool isAlphaAllowed() const { return true; } - virtual bool isColorModulationAllowed() const { + virtual bool isColorModulationAllowed() const { return true; } - virtual bool isSetContentAllowed() const { + virtual bool isSetContentAllowed() const { return true; } diff --git a/engines/sword25/gfx/image/swimage.cpp b/engines/sword25/gfx/image/swimage.cpp index ff06491b36..3b9b939eb3 100644 --- a/engines/sword25/gfx/image/swimage.cpp +++ b/engines/sword25/gfx/image/swimage.cpp @@ -47,7 +47,7 @@ SWImage::SWImage(const Common::String &filename, bool &result) : PackageManager *pPackage = Kernel::getInstance()->getPackage(); assert(pPackage); - // Datei laden + // Load file byte *pFileData; uint fileSize; pFileData = pPackage->getFile(filename, &fileSize); @@ -56,21 +56,21 @@ SWImage::SWImage(const Common::String &filename, bool &result) : return; } - // Bildeigenschaften bestimmen + // Determine image properties int pitch; if (!PNGLoader::imageProperties(pFileData, fileSize, _width, _height)) { error("Could not read image properties."); return; } - // Das Bild dekomprimieren + // Uncompress the image byte *pUncompressedData; if (!PNGLoader::decodeImage(pFileData, fileSize, pUncompressedData, _width, _height, pitch)) { error("Could not decode image."); return; } - // Dateidaten freigeben + // Cleanup FileData delete[] pFileData; _imageDataPtr = (uint *)pUncompressedData; diff --git a/engines/sword25/gfx/image/vectorimage.cpp b/engines/sword25/gfx/image/vectorimage.cpp index 094e6a59a8..241e80bad3 100644 --- a/engines/sword25/gfx/image/vectorimage.cpp +++ b/engines/sword25/gfx/image/vectorimage.cpp @@ -47,15 +47,15 @@ namespace Sword25 { #define BEZSMOOTHNESS 0.5 // ----------------------------------------------------------------------------- -// SWF Datentypen +// SWF datatype // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- -// Bitstream Hilfsklasse +// Bitstream helper class // ----------------------------------------------------------------------------- -// Das Parsen von SWF-Dateien erfordert sowohl bitweises Auslesen als auch an -// Bytegrenzen ausgerichtetes Lesen. -// Diese Klasse ist speziell dafür ausgestattet. +// The parsing of SWF files requires both bitwise readout and on Byte boundaries +// oriented reading. +// This class is specially equipped for this. // ----------------------------------------------------------------------------- class VectorImage::SWFBitStream { @@ -85,10 +85,10 @@ public: } inline int32 getSignedBits(uint bitCount) { - // Bits einlesen + // readout bits uint32 temp = getBits(bitCount); - // Falls das Sign-Bit gesetzt ist, den Rest des Rückgabewertes mit 1-Bits auffüllen (Sign Extension) + // If the sign-bit is set, fill the rest of the return value with 1-bit (sign extension) if (temp & 1 << (bitCount - 1)) return (0xffffffff << bitCount) | temp; else @@ -151,28 +151,28 @@ private: // ----------------------------------------------------------------------------- -// Konstanten und Hilfsfunktionen +// Constants and utility functions // ----------------------------------------------------------------------------- namespace { // ----------------------------------------------------------------------------- -// Konstanten +// Constants // ----------------------------------------------------------------------------- -const uint32 MAX_ACCEPTED_FLASH_VERSION = 3; // Die höchste Flash-Dateiversion, die vom Lader akzeptiert wird +const uint32 MAX_ACCEPTED_FLASH_VERSION = 3; // The maximum flash file version that is accepted by the loader // ----------------------------------------------------------------------------- -// Konvertiert SWF-Rechteckdaten in einem Bitstrom in Common::Rect-Objekte +// Converts SWF rectangle data in a bit stream in Common::Rect objects // ----------------------------------------------------------------------------- Common::Rect flashRectToBSRect(VectorImage::SWFBitStream &bs) { bs.flushByte(); - // Feststellen mit wie vielen Bits die einzelnen Komponenten kodiert sind + // Determines how many bits of the single components are encoded uint32 bitsPerValue = bs.getBits(5); - // Die einzelnen Komponenten einlesen + // Readout the single components int32 xMin = bs.getSignedBits(bitsPerValue); int32 xMax = bs.getSignedBits(bitsPerValue); int32 yMin = bs.getSignedBits(bitsPerValue); @@ -182,7 +182,7 @@ Common::Rect flashRectToBSRect(VectorImage::SWFBitStream &bs) { } // ----------------------------------------------------------------------------- -// Berechnet die Bounding-Box eines BS_VectorImageElement +// Calculate the bounding box of a BS_VectorImageElement // ----------------------------------------------------------------------------- Common::Rect CalculateBoundingBox(const VectorImageElement &vectorImageElement) { @@ -214,17 +214,17 @@ Common::Rect CalculateBoundingBox(const VectorImageElement &vectorImageElement) // ----------------------------------------------------------------------------- -// Konstruktion +// Construction // ----------------------------------------------------------------------------- VectorImage::VectorImage(const byte *pFileData, uint fileSize, bool &success, const Common::String &fname) : _pixelData(0), _fname(fname) { success = false; - // Bitstream-Objekt erzeugen - // Im Folgenden werden die Dateidaten aus diesem ausgelesen. + // Create bitstream object + // In the following the file data will be readout of the bitstream object. SWFBitStream bs(pFileData, fileSize); - // SWF-Signatur überprüfen + // Check SWF signature uint32 signature[3]; signature[0] = bs.getByte(); signature[1] = bs.getByte(); @@ -236,37 +236,37 @@ VectorImage::VectorImage(const byte *pFileData, uint fileSize, bool &success, co return; } - // Versionsangabe überprüfen + // Check the version uint32 version = bs.getByte(); if (version > MAX_ACCEPTED_FLASH_VERSION) { error("File is of version %d. Highest accepted version is %d.", version, MAX_ACCEPTED_FLASH_VERSION); return; } - // Dateigröße auslesen und mit der tatsächlichen Größe vergleichen + // Readout filesize and compare with the actual size uint32 storedFileSize = bs.getUInt32(); if (storedFileSize != fileSize) { error("File is not a valid SWF-file"); return; } - // SWF-Maße auslesen + // readout SWF size Common::Rect movieRect = flashRectToBSRect(bs); - // Framerate und Frameanzahl auslesen + // Get frame rate and frame count /* uint32 frameRate = */ bs.getUInt16(); /* uint32 frameCount = */ bs.getUInt16(); - // Tags parsen - // Da wir uns nur für das erste DefineShape-Tag interessieren + // Parse tags + // Because we are only interested in the first DifneShape-Tag... bool keepParsing = true; while (keepParsing) { - // Tags beginnen immer an Bytegrenzen + // Tags always begin on byte boundaries bs.flushByte(); - // Tagtyp und Länge auslesen + // Readout tag type and length uint16 tagTypeAndLength = bs.getUInt16(); uint32 tagType = tagTypeAndLength >> 6; uint32 tagLength = tagTypeAndLength & 0x3f; @@ -286,13 +286,13 @@ VectorImage::VectorImage(const byte *pFileData, uint fileSize, bool &success, co success = parseDefineShape(3, bs); return; default: - // Unbekannte Tags ignorieren + // Ignore unknown tags bs.skipBytes(tagLength); } } - // Die Ausführung darf nicht an dieser Stelle ankommen: Entweder es wird ein Shape gefunden, dann wird die Funktion mit vorher verlassen, oder - // es wird keines gefunden, dann tritt eine Exception auf sobald über das Ende der Datei hinaus gelesen wird. + // The execution must not arrive at this point: Either a shape is found, then the function will be leaved before, or it is found none, then + // an exception occurs as soon as it is read beyond of the end of file. assert(false); } @@ -336,13 +336,13 @@ ArtBpath *VectorImage::storeBez(ArtBpath *bez, int lineStyle, int fillStyle0, in bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { /*uint32 shapeID = */bs.getUInt16(); - // Bounding Box auslesen + // readout bounding box _boundingBox = flashRectToBSRect(bs); - // Erstes Image-Element erzeugen + // create first image element _elements.resize(1); - // Styles einlesen + // read styles uint numFillBits; uint numLineBits; if (!parseStyles(shapeType, bs, numFillBits, numLineBits)) @@ -352,7 +352,7 @@ bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { uint fillStyle0 = 0; uint fillStyle1 = 0; - // Shaperecord parsen + // parse shaperecord // ------------------ double curX = 0; @@ -367,7 +367,7 @@ bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { // Non-Edge Record if (typeFlag == 0) { - // Feststellen welche Parameter gesetzt werden + // Determines which parameters are set uint32 stateNewStyles = bs.getBits(1); uint32 stateLineStyle = bs.getBits(1); uint32 stateFillStyle1 = bs.getBits(1); @@ -378,10 +378,10 @@ bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { uint prevFillStyle0 = fillStyle0; uint prevFillStyle1 = fillStyle1; - // End der Shape-Definition erreicht? + // End of the shape definition is reached? if (!stateNewStyles && !stateLineStyle && !stateFillStyle0 && !stateFillStyle1 && !stateMoveTo) { endOfShapeDiscovered = true; - // Parameter dekodieren + // Decode parameters } else { if (stateMoveTo) { uint32 moveToBits = bs.getBits(5); @@ -410,7 +410,7 @@ bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { numLineBits = 0; } - // Ein neuen Pfad erzeugen, es sei denn, es wurden nur neue Styles definiert + // Create a new path, unless there were only defined new styles if (stateLineStyle || stateFillStyle0 || stateFillStyle1 || stateMoveTo) { // Store previous curve if any if (bezNodes) { @@ -426,15 +426,15 @@ bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { } if (stateNewStyles) { - // An dieser Stelle werden in Flash die alten Style-Definitionen verworfen und mit den neuen überschrieben. - // Es wird ein neues Element begonnen. + // The old style definitions will be discarded and overwritten with the new at this point in Flash. + // A new element will be started with a new element. _elements.resize(_elements.size() + 1); if (!parseStyles(shapeType, bs, numFillBits, numLineBits)) return false; } } } else { - // Edge Record + // Edge record uint32 edgeFlag = bs.getBits(1); uint32 numBits = bs.getBits(4) + 2; @@ -499,7 +499,7 @@ bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { free(bez); - // Bounding-Boxes der einzelnen Elemente berechnen + // Calculate the bounding boxes of each element Common::Array<VectorImageElement>::iterator it = _elements.begin(); for (; it != _elements.end(); ++it) it->_boundingBox = CalculateBoundingBox(*it); @@ -513,16 +513,16 @@ bool VectorImage::parseDefineShape(uint shapeType, SWFBitStream &bs) { bool VectorImage::parseStyles(uint shapeType, SWFBitStream &bs, uint &numFillBits, uint &numLineBits) { bs.flushByte(); - // Fillstyles parsen + // Parse fill styles // ----------------- - // Anzahl an Fillstyles bestimmen + // Determine number of fill styles uint fillStyleCount = bs.getByte(); if (fillStyleCount == 0xff) fillStyleCount = bs.getUInt16(); - // Alle Fillstyles einlesen, falls ein Fillstyle mit Typ != 0 gefunden wird, wird das Parsen abgebrochen. - // Es wird nur "solid fill" (Typ 0) unterstützt. + // Readout all fill styles. If a fill style with Typ != 0 is found, the parsing is aborted. + // Only "solid fill" (Typ 0) is supported. _elements.back()._fillStyles.reserve(fillStyleCount); for (uint i = 0; i < fillStyleCount; ++i) { byte type = bs.getByte(); @@ -543,15 +543,15 @@ bool VectorImage::parseStyles(uint shapeType, SWFBitStream &bs, uint &numFillBit _elements.back()._fillStyles.push_back(color); } - // Linestyles parsen + // Line styles parsen // ----------------- - // Anzahl an Linestyles bestimmen + // Determine number of line styles uint lineStyleCount = bs.getByte(); if (lineStyleCount == 0xff) lineStyleCount = bs.getUInt16(); - // Alle Linestyles einlesen + // Readout all line styles _elements.back()._lineStyles.reserve(lineStyleCount); for (uint i = 0; i < lineStyleCount; ++i) { double width = bs.getUInt16(); @@ -569,7 +569,7 @@ bool VectorImage::parseStyles(uint shapeType, SWFBitStream &bs, uint &numFillBit _elements.back()._lineStyles.push_back(VectorImageElement::LineStyleType(width, color)); } - // Bitbreite für die folgenden Styleindizes auslesen + // Readout the bit width for the following style indices numFillBits = bs.getBits(4); numLineBits = bs.getBits(4); @@ -608,11 +608,11 @@ bool VectorImage::blit(int posX, int posY, static int oldWidth = -2; static int oldHeight = -2; - // Falls Breite oder Höhe 0 sind, muss nichts dargestellt werden. + // If width or height to 0, nothing needs to be shown. if (width == 0 || height == 0) return true; - // Feststellen, ob das alte Bild im Cache nicht wiederbenutzt werden kann und neu Berechnet werden muss + // Determine if the old image in the cache can not be reused and must be recalculated if (!(oldThis == this && oldWidth == width && oldHeight == height)) { render(width, height); diff --git a/engines/sword25/gfx/image/vectorimagerenderer.cpp b/engines/sword25/gfx/image/vectorimagerenderer.cpp index 7587aab4e5..99a47015fb 100644 --- a/engines/sword25/gfx/image/vectorimagerenderer.cpp +++ b/engines/sword25/gfx/image/vectorimagerenderer.cpp @@ -48,7 +48,7 @@ namespace Sword25 { -void art_rgb_fill_run1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int n) { +void art_rgb_fill_run1(byte *buf, byte r, byte g, byte b, int n) { int i; if (r == g && g == b && r == 255) { @@ -62,11 +62,12 @@ void art_rgb_fill_run1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int n) { } } -void art_rgb_run_alpha1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int alpha, int n) { +void art_rgb_run_alpha1(byte *buf, byte r, byte g, byte b, int alpha, int n) { int i; int v; for (i = 0; i < n; i++) { +#if defined(SCUMM_LITTLE_ENDIAN) v = *buf; *buf++ = v + (((b - v) * alpha + 0x80) >> 8); v = *buf; @@ -75,6 +76,16 @@ void art_rgb_run_alpha1(art_u8 *buf, art_u8 r, art_u8 g, art_u8 b, int alpha, in *buf++ = v + (((r - v) * alpha + 0x80) >> 8); v = *buf; *buf++ = MIN(v + alpha, 0xff); +#else + v = *buf; + *buf++ = MIN(v + alpha, 0xff); + v = *buf; + *buf++ = v + (((r - v) * alpha + 0x80) >> 8); + v = *buf; + *buf++ = v + (((g - v) * alpha + 0x80) >> 8); + v = *buf; + *buf++ = v + (((b - v) * alpha + 0x80) >> 8); +#endif } } @@ -82,8 +93,8 @@ typedef struct _ArtRgbSVPAlphaData ArtRgbSVPAlphaData; struct _ArtRgbSVPAlphaData { int alphatab[256]; - art_u8 r, g, b, alpha; - art_u8 *buf; + byte r, g, b, alpha; + byte *buf; int rowstride; int x0, x1; }; @@ -91,12 +102,12 @@ struct _ArtRgbSVPAlphaData { static void art_rgb_svp_alpha_callback1(void *callback_data, int y, int start, ArtSVPRenderAAStep *steps, int n_steps) { ArtRgbSVPAlphaData *data = (ArtRgbSVPAlphaData *)callback_data; - art_u8 *linebuf; + byte *linebuf; int run_x0, run_x1; - art_u32 running_sum = start; + uint32 running_sum = start; int x0, x1; int k; - art_u8 r, g, b; + byte r, g, b; int *alphatab; int alpha; @@ -146,12 +157,12 @@ static void art_rgb_svp_alpha_opaque_callback1(void *callback_data, int y, int start, ArtSVPRenderAAStep *steps, int n_steps) { ArtRgbSVPAlphaData *data = (ArtRgbSVPAlphaData *)callback_data; - art_u8 *linebuf; + byte *linebuf; int run_x0, run_x1; - art_u32 running_sum = start; + uint32 running_sum = start; int x0, x1; int k; - art_u8 r, g, b; + byte r, g, b; int *alphatab; int alpha; @@ -216,7 +227,7 @@ static void art_rgb_svp_alpha_opaque_callback1(void *callback_data, int y, void art_rgb_svp_alpha1(const ArtSVP *svp, int x0, int y0, int x1, int y1, uint32 color, - art_u8 *buf, int rowstride) { + byte *buf, int rowstride) { ArtRgbSVPAlphaData data; byte r, g, b, alpha; int i; @@ -320,7 +331,7 @@ ArtVpath *art_vpath_reverse_free(ArtVpath *a) { return dest; } -void drawBez(ArtBpath *bez1, ArtBpath *bez2, art_u8 *buffer, int width, int height, int deltaX, int deltaY, double scaleX, double scaleY, double penWidth, unsigned int color) { +void drawBez(ArtBpath *bez1, ArtBpath *bez2, byte *buffer, int width, int height, int deltaX, int deltaY, double scaleX, double scaleY, double penWidth, unsigned int color) { ArtVpath *vec = NULL; ArtVpath *vec1 = NULL; ArtVpath *vec2 = NULL; diff --git a/engines/sword25/gfx/screenshot.cpp b/engines/sword25/gfx/screenshot.cpp index 35e94976eb..6ea2b574d6 100644 --- a/engines/sword25/gfx/screenshot.cpp +++ b/engines/sword25/gfx/screenshot.cpp @@ -36,6 +36,7 @@ #define FORBIDDEN_SYMBOL_ALLOW_ALL #include "common/memstream.h" +#include "common/textconsole.h" #include "sword25/gfx/screenshot.h" #include "sword25/kernel/filesystemutil.h" #include <png.h> @@ -127,14 +128,14 @@ Common::SeekableReadStream *Screenshot::createThumbnail(Graphics::Surface *data) // generates a pixel of the target image. Finally, the result as a PNG file is stored as a file. // The source image must be 800x600. - if (data->w != 800 || data->h != 600 || data->bytesPerPixel != 4) { + 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; } // Buffer for the output thumbnail Graphics::Surface thumbnail; - thumbnail.create(200, 125, 4); + thumbnail.create(200, 125, g_system->getScreenFormat()); // Über das Zielbild iterieren und einen Pixel zur Zeit berechnen. uint x, y; diff --git a/engines/sword25/gfx/text.cpp b/engines/sword25/gfx/text.cpp index bbfc3804a3..b1c1708565 100644 --- a/engines/sword25/gfx/text.cpp +++ b/engines/sword25/gfx/text.cpp @@ -173,10 +173,8 @@ bool Text::doRender() { Common::Rect curRect = fontPtr->getCharacterRect((byte)(*iter).text[i]); Common::Rect renderRect(curX, curY, curX + curRect.width(), curY + curRect.height()); - int renderX = curX + (renderRect.left - renderRect.left); - int renderY = curY + (renderRect.top - renderRect.top); renderRect.translate(curRect.left - curX, curRect.top - curY); - result = charMapPtr->blit(renderX, renderY, Image::FLIP_NONE, &renderRect, _modulationColor); + result = charMapPtr->blit(curX, curY, Image::FLIP_NONE, &renderRect, _modulationColor); if (!result) break; diff --git a/engines/sword25/kernel/filesystemutil.cpp b/engines/sword25/kernel/filesystemutil.cpp index b4d4b25f8d..e5ec6c15db 100644 --- a/engines/sword25/kernel/filesystemutil.cpp +++ b/engines/sword25/kernel/filesystemutil.cpp @@ -34,8 +34,7 @@ #include "common/config-manager.h" #include "common/fs.h" -#include "common/savefile.h" -#include "common/system.h" +#include "common/textconsole.h" #include "sword25/kernel/filesystemutil.h" #include "sword25/kernel/persistenceservice.h" diff --git a/engines/sword25/kernel/inputpersistenceblock.cpp b/engines/sword25/kernel/inputpersistenceblock.cpp index f3aebef203..26c924dc82 100644 --- a/engines/sword25/kernel/inputpersistenceblock.cpp +++ b/engines/sword25/kernel/inputpersistenceblock.cpp @@ -32,6 +32,8 @@ * */ +#include "common/textconsole.h" + #include "sword25/kernel/inputpersistenceblock.h" namespace Sword25 { diff --git a/engines/sword25/kernel/kernel.cpp b/engines/sword25/kernel/kernel.cpp index 6b99b0a115..99fec52040 100644 --- a/engines/sword25/kernel/kernel.cpp +++ b/engines/sword25/kernel/kernel.cpp @@ -95,10 +95,8 @@ Kernel::Kernel() : _geometry = new Geometry(this); assert(_geometry); -#ifdef USE_THEORADEC _fmv = new MoviePlayer(this); assert(_fmv); -#endif _initSuccess = true; } @@ -121,10 +119,8 @@ Kernel::~Kernel() { delete _geometry; _geometry = 0; -#ifdef USE_THEORADEC delete _fmv; _fmv = 0; -#endif delete _script; _script = 0; diff --git a/engines/sword25/kernel/kernel.h b/engines/sword25/kernel/kernel.h index 9e7ee0fdd9..3abf43d239 100644 --- a/engines/sword25/kernel/kernel.h +++ b/engines/sword25/kernel/kernel.h @@ -48,6 +48,7 @@ #include "common/scummsys.h" #include "common/random.h" #include "common/stack.h" +#include "common/textconsole.h" #include "common/util.h" #include "engines/engine.h" diff --git a/engines/sword25/kernel/objectregistry.h b/engines/sword25/kernel/objectregistry.h index 8d0f4a314b..69d961ae91 100644 --- a/engines/sword25/kernel/objectregistry.h +++ b/engines/sword25/kernel/objectregistry.h @@ -37,6 +37,7 @@ #include "common/func.h" #include "common/hashmap.h" +#include "common/textconsole.h" #include "sword25/kernel/common.h" namespace Sword25 { diff --git a/engines/sword25/kernel/persistenceservice.cpp b/engines/sword25/kernel/persistenceservice.cpp index be66b6abf0..506eef3c57 100644 --- a/engines/sword25/kernel/persistenceservice.cpp +++ b/engines/sword25/kernel/persistenceservice.cpp @@ -32,6 +32,9 @@ * */ +// Disable symbol overrides so that we can use zlib.h +#define FORBIDDEN_SYMBOL_ALLOW_ALL + #include "common/fs.h" #include "common/savefile.h" #include "sword25/kernel/kernel.h" diff --git a/engines/sword25/math/geometry_script.cpp b/engines/sword25/math/geometry_script.cpp index 6562a0f0a5..4b5e0550fe 100644 --- a/engines/sword25/math/geometry_script.cpp +++ b/engines/sword25/math/geometry_script.cpp @@ -51,27 +51,6 @@ namespace Sword25 { #define REGION_CLASS_NAME "Geo.Region" #define WALKREGION_CLASS_NAME "Geo.WalkRegion" -// How luaL_checkudata, only without that no error is generated. -static void *my_checkudata(lua_State *L, int ud, const char *tname) { - int top = lua_gettop(L); - - void *p = lua_touserdata(L, ud); - if (p != NULL) { /* value is a userdata? */ - if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ - // lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ - LuaBindhelper::getMetatable(L, tname); - /* does it have the correct mt? */ - if (lua_rawequal(L, -1, -2)) { - lua_settop(L, top); - return p; - } - } - } - - lua_settop(L, top); - return NULL; -} - static void newUintUserData(lua_State *L, uint value) { void *userData = lua_newuserdata(L, sizeof(value)); memcpy(userData, &value, sizeof(value)); @@ -276,9 +255,9 @@ static const luaL_reg GEO_FUNCTIONS[] = { static Region *checkRegion(lua_State *L) { // The first parameter must be of type 'userdata', and the Metatable class Geo.Region or Geo.WalkRegion - uint *regionHandlePtr; - if ((regionHandlePtr = reinterpret_cast<uint *>(my_checkudata(L, 1, REGION_CLASS_NAME))) != 0 || - (regionHandlePtr = reinterpret_cast<uint *>(my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) { + uint *regionHandlePtr = reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, 1, REGION_CLASS_NAME)); + if (regionHandlePtr != 0 || + (regionHandlePtr = reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) { return RegionRegistry::instance().resolveHandle(*regionHandlePtr); } else { luaL_argcheck(L, 0, 1, "'" REGION_CLASS_NAME "' expected"); @@ -398,7 +377,7 @@ static const luaL_reg REGION_METHODS[] = { static WalkRegion *checkWalkRegion(lua_State *L) { // The first parameter must be of type 'userdate', and the Metatable class Geo.WalkRegion uint regionHandle; - if ((regionHandle = *reinterpret_cast<uint *>(my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) { + if ((regionHandle = *reinterpret_cast<uint *>(LuaBindhelper::my_checkudata(L, 1, WALKREGION_CLASS_NAME))) != 0) { return reinterpret_cast<WalkRegion *>(RegionRegistry::instance().resolveHandle(regionHandle)); } else { luaL_argcheck(L, 0, 1, "'" WALKREGION_CLASS_NAME "' expected"); diff --git a/engines/sword25/script/luabindhelper.cpp b/engines/sword25/script/luabindhelper.cpp index 5ff9708b95..03a1802a04 100644 --- a/engines/sword25/script/luabindhelper.cpp +++ b/engines/sword25/script/luabindhelper.cpp @@ -303,6 +303,27 @@ bool LuaBindhelper::getMetatable(lua_State *L, const Common::String &tableName) return true; } +// Like luaL_checkudata, only without that no error is generated. +void *LuaBindhelper::my_checkudata(lua_State *L, int ud, const char *tname) { + int top = lua_gettop(L); + + void *p = lua_touserdata(L, ud); + if (p != NULL) { /* value is a userdata? */ + if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ + // lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ + LuaBindhelper::getMetatable(L, tname); + if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ + lua_settop(L, top); + return p; + } + } + } + + lua_settop(L, top); + return NULL; +} + + bool LuaBindhelper::createTable(lua_State *L, const Common::String &tableName) { const char *partBegin = tableName.c_str(); diff --git a/engines/sword25/script/luabindhelper.h b/engines/sword25/script/luabindhelper.h index dc45104d53..94f52743f3 100644 --- a/engines/sword25/script/luabindhelper.h +++ b/engines/sword25/script/luabindhelper.h @@ -110,6 +110,8 @@ public: static bool getMetatable(lua_State *L, const Common::String &tableName); + static void *my_checkudata(lua_State *L, int ud, const char *tname); + private: static bool createTable(lua_State *L, const Common::String &tableName); }; diff --git a/engines/sword25/script/luacallback.cpp b/engines/sword25/script/luacallback.cpp index 137e37bf8d..809676796e 100644 --- a/engines/sword25/script/luacallback.cpp +++ b/engines/sword25/script/luacallback.cpp @@ -32,6 +32,8 @@ * */ +#include "common/textconsole.h" + #include "sword25/script/luacallback.h" #include "sword25/script/luabindhelper.h" diff --git a/engines/sword25/sfx/soundengine.cpp b/engines/sword25/sfx/soundengine.cpp index 03cdaf82b7..08f0f5b4ae 100644 --- a/engines/sword25/sfx/soundengine.cpp +++ b/engines/sword25/sfx/soundengine.cpp @@ -39,6 +39,8 @@ #include "audio/decoders/vorbis.h" +#include "common/system.h" + namespace Sword25 { class SoundResource : public Resource { diff --git a/engines/sword25/sword25.cpp b/engines/sword25/sword25.cpp index 55b9aa340d..38c1c89109 100644 --- a/engines/sword25/sword25.cpp +++ b/engines/sword25/sword25.cpp @@ -34,10 +34,18 @@ #include "common/config-manager.h" #include "common/debug-channels.h" +#include "common/algorithm.h" +#include "common/array.h" +#include "common/error.h" +#include "common/fs.h" +#include "common/singleton.h" +#include "common/str-array.h" +#include "common/str.h" +#include "common/system.h" +#include "common/textconsole.h" #include "engines/util.h" #include "sword25/sword25.h" -#include "sword25/kernel/filesystemutil.h" #include "sword25/kernel/kernel.h" #include "sword25/kernel/persistenceservice.h" #include "sword25/package/packagemanager.h" @@ -56,6 +64,8 @@ const char *const DEFAULT_SCRIPT_FILE = "/system/boot.lua"; Sword25Engine::Sword25Engine(OSystem *syst, const ADGameDescription *gameDesc): Engine(syst), _gameDescription(gameDesc) { + // Setup mixer + syncSoundSettings(); DebugMan.addDebugChannel(kDebugScript, "Script", "Script debug level"); DebugMan.addDebugChannel(kDebugScript, "Scripts", "Script debug level"); @@ -71,10 +81,10 @@ Sword25Engine::~Sword25Engine() { Common::Error Sword25Engine::run() { // Engine initialisation - Common::Error errorCode = appStart(); - if (errorCode != Common::kNoError) { + Common::Error error = appStart(); + if (error.getCode() != Common::kNoError) { appEnd(); - return errorCode; + return error; } // Run the game diff --git a/engines/sword25/sword25.h b/engines/sword25/sword25.h index 9e9679526b..5bd27b311f 100644 --- a/engines/sword25/sword25.h +++ b/engines/sword25/sword25.h @@ -27,12 +27,18 @@ #define SWORD25_H #include "common/scummsys.h" -#include "common/str-array.h" -#include "common/util.h" #include "engines/engine.h" #include "sword25/console.h" +namespace Common { +class Error; +} + +namespace GUI { +class Debugger; +} + struct ADGameDescription; /** diff --git a/engines/sword25/util/lua/lmathlib.cpp b/engines/sword25/util/lua/lmathlib.cpp index ed50539f1f..7e64d75789 100644 --- a/engines/sword25/util/lua/lmathlib.cpp +++ b/engines/sword25/util/lua/lmathlib.cpp @@ -6,6 +6,11 @@ #include <stdlib.h> +// MSVC does not define M_PI, M_SQRT2 and other math defines by default. +// _USE_MATH_DEFINES must be defined in order to have these defined, thus +// we enable it here. For more information, check: +// http://msdn.microsoft.com/en-us/library/4hwaceh6(v=VS.100).aspx +#define _USE_MATH_DEFINES #include <math.h> #define lmathlib_c @@ -16,12 +21,7 @@ #include "lauxlib.h" #include "lualib.h" - -#undef PI -#define PI (3.14159265358979323846) -#define RADIANS_PER_DEGREE (PI/180.0) - - +#define RADIANS_PER_DEGREE (M_PI/180.0) static int math_abs (lua_State *L) { lua_pushnumber(L, fabs(luaL_checknumber(L, 1))); @@ -250,7 +250,7 @@ static const luaL_Reg mathlib[] = { */ LUALIB_API int luaopen_math (lua_State *L) { luaL_register(L, LUA_MATHLIBNAME, mathlib); - lua_pushnumber(L, PI); + lua_pushnumber(L, M_PI); lua_setfield(L, -2, "pi"); #if defined(MACOSX) && defined(__GNUC__) && ! defined( __XLC__ ) // WORKAROUND for a bug in the Mac OS X 10.2.8 SDK. It defines diff --git a/engines/sword25/util/pluto/Makefile b/engines/sword25/util/pluto/Makefile deleted file mode 100644 index 611ecc83d2..0000000000 --- a/engines/sword25/util/pluto/Makefile +++ /dev/null @@ -1,29 +0,0 @@ -LDLIBS= -lm -ldl -llua -LDFLAGS = -rdynamic # -L../lua-5.1.3/src -# CFLAGS= -g3 -Wall -fprofile-arcs -ftest-coverage -CFLAGS= -g3 -Wall -ansi -pedantic - -LIBTOOL=libtool --tag=CC - -default: pluto.so pptest puptest - -%.lo: %.c - $(LIBTOOL) --mode=compile cc $(CFLAGS) -c $< - -pluto.so: pluto.lo pdep.lo lzio.lo - $(LIBTOOL) --mode=link cc -rpath /usr/local/lib/lua/5.1 -o libpluto.la $^ - mv .libs/libpluto.so.0.0.0 $@ - -test: pptest puptest pptest.lua puptest.lua pluto.so - ./pptest - ./puptest - -pptest: pptest.o - $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) - -puptest: puptest.o - $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS) - -clean: - -rm -r *.so *.la *.lo .libs *.a *.o *.bb *.bbg *.da *.gcov pptest puptest test.plh - diff --git a/engines/sword25/util/pluto/pdep/lauxlib.h b/engines/sword25/util/pluto/pdep/lauxlib.h deleted file mode 100644 index d58f290527..0000000000 --- a/engines/sword25/util/pluto/pdep/lauxlib.h +++ /dev/null @@ -1,174 +0,0 @@ -/* -** $Id$ -** Auxiliary functions for building Lua libraries -** See Copyright Notice in lua.h -*/ - - -#ifndef lauxlib_h -#define lauxlib_h - - -#include <stddef.h> -#include <stdio.h> - -#include "lua.h" - - -#if defined(LUA_COMPAT_GETN) -LUALIB_API int (luaL_getn) (lua_State *L, int t); -LUALIB_API void (luaL_setn) (lua_State *L, int t, int n); -#else -#define luaL_getn(L,i) ((int)lua_objlen(L, i)) -#define luaL_setn(L,i,j) ((void)0) /* no op! */ -#endif - -#if defined(LUA_COMPAT_OPENLIB) -#define luaI_openlib luaL_openlib -#endif - - -/* extra error code for `luaL_load' */ -#define LUA_ERRFILE (LUA_ERRERR+1) - - -typedef struct luaL_Reg { - const char *name; - lua_CFunction func; -} luaL_Reg; - - - -LUALIB_API void (luaI_openlib) (lua_State *L, const char *libname, - const luaL_Reg *l, int nup); -LUALIB_API void (luaL_register) (lua_State *L, const char *libname, - const luaL_Reg *l); -LUALIB_API int (luaL_getmetafield) (lua_State *L, int obj, const char *e); -LUALIB_API int (luaL_callmeta) (lua_State *L, int obj, const char *e); -LUALIB_API int (luaL_typerror) (lua_State *L, int narg, const char *tname); -LUALIB_API int (luaL_argerror) (lua_State *L, int numarg, const char *extramsg); -LUALIB_API const char *(luaL_checklstring) (lua_State *L, int numArg, - size_t *l); -LUALIB_API const char *(luaL_optlstring) (lua_State *L, int numArg, - const char *def, size_t *l); -LUALIB_API lua_Number (luaL_checknumber) (lua_State *L, int numArg); -LUALIB_API lua_Number (luaL_optnumber) (lua_State *L, int nArg, lua_Number def); - -LUALIB_API lua_Integer (luaL_checkinteger) (lua_State *L, int numArg); -LUALIB_API lua_Integer (luaL_optinteger) (lua_State *L, int nArg, - lua_Integer def); - -LUALIB_API void (luaL_checkstack) (lua_State *L, int sz, const char *msg); -LUALIB_API void (luaL_checktype) (lua_State *L, int narg, int t); -LUALIB_API void (luaL_checkany) (lua_State *L, int narg); - -LUALIB_API int (luaL_newmetatable) (lua_State *L, const char *tname); -LUALIB_API void *(luaL_checkudata) (lua_State *L, int ud, const char *tname); - -LUALIB_API void (luaL_where) (lua_State *L, int lvl); -LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...); - -LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def, - const char *const lst[]); - -LUALIB_API int (luaL_ref) (lua_State *L, int t); -LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref); - -LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename); -LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz, - const char *name); -LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s); - -LUALIB_API lua_State *(luaL_newstate) (void); - - -LUALIB_API const char *(luaL_gsub) (lua_State *L, const char *s, const char *p, - const char *r); - -LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx, - const char *fname, int szhint); - - - - -/* -** =============================================================== -** some useful macros -** =============================================================== -*/ - -#define luaL_argcheck(L, cond,numarg,extramsg) \ - ((void)((cond) || luaL_argerror(L, (numarg), (extramsg)))) -#define luaL_checkstring(L,n) (luaL_checklstring(L, (n), NULL)) -#define luaL_optstring(L,n,d) (luaL_optlstring(L, (n), (d), NULL)) -#define luaL_checkint(L,n) ((int)luaL_checkinteger(L, (n))) -#define luaL_optint(L,n,d) ((int)luaL_optinteger(L, (n), (d))) -#define luaL_checklong(L,n) ((long)luaL_checkinteger(L, (n))) -#define luaL_optlong(L,n,d) ((long)luaL_optinteger(L, (n), (d))) - -#define luaL_typename(L,i) lua_typename(L, lua_type(L,(i))) - -#define luaL_dofile(L, fn) \ - (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) - -#define luaL_dostring(L, s) \ - (luaL_loadstring(L, s) || lua_pcall(L, 0, LUA_MULTRET, 0)) - -#define luaL_getmetatable(L,n) (lua_getfield(L, LUA_REGISTRYINDEX, (n))) - -#define luaL_opt(L,f,n,d) (lua_isnoneornil(L,(n)) ? (d) : f(L,(n))) - -/* -** {====================================================== -** Generic Buffer manipulation -** ======================================================= -*/ - - - -typedef struct luaL_Buffer { - char *p; /* current position in buffer */ - int lvl; /* number of strings in the stack (level) */ - lua_State *L; - char buffer[LUAL_BUFFERSIZE]; -} luaL_Buffer; - -#define luaL_addchar(B,c) \ - ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \ - (*(B)->p++ = (char)(c))) - -/* compatibility only */ -#define luaL_putchar(B,c) luaL_addchar(B,c) - -#define luaL_addsize(B,n) ((B)->p += (n)) - -LUALIB_API void (luaL_buffinit) (lua_State *L, luaL_Buffer *B); -LUALIB_API char *(luaL_prepbuffer) (luaL_Buffer *B); -LUALIB_API void (luaL_addlstring) (luaL_Buffer *B, const char *s, size_t l); -LUALIB_API void (luaL_addstring) (luaL_Buffer *B, const char *s); -LUALIB_API void (luaL_addvalue) (luaL_Buffer *B); -LUALIB_API void (luaL_pushresult) (luaL_Buffer *B); - - -/* }====================================================== */ - - -/* compatibility with ref system */ - -/* pre-defined references */ -#define LUA_NOREF (-2) -#define LUA_REFNIL (-1) - -#define lua_ref(L,lock) ((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \ - (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0)) - -#define lua_unref(L,ref) luaL_unref(L, LUA_REGISTRYINDEX, (ref)) - -#define lua_getref(L,ref) lua_rawgeti(L, LUA_REGISTRYINDEX, (ref)) - - -#define luaL_reg luaL_Reg - -#endif - - diff --git a/engines/sword25/util/pluto/pdep/ldo.h b/engines/sword25/util/pluto/pdep/ldo.h deleted file mode 100644 index 4c97134805..0000000000 --- a/engines/sword25/util/pluto/pdep/ldo.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -** $Id$ -** Stack and Call structure of Lua -** See Copyright Notice in lua.h -*/ - -#ifndef ldo_h -#define ldo_h - - -#include "lobject.h" -#include "lstate.h" -#include "lzio.h" - - -#define luaD_checkstack(L,n) \ - if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TValue)) \ - luaD_growstack(L, n); \ - else condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); - - -#define incr_top(L) {luaD_checkstack(L,1); L->top++;} - -#define savestack(L,p) ((char *)(p) - (char *)L->stack) -#define restorestack(L,n) ((TValue *)((char *)L->stack + (n))) - -#define saveci(L,p) ((char *)(p) - (char *)L->base_ci) -#define restoreci(L,n) ((CallInfo *)((char *)L->base_ci + (n))) - - -/* results from luaD_precall */ -#define PCRLUA 0 /* initiated a call to a Lua function */ -#define PCRC 1 /* did a call to a C function */ -#define PCRYIELD 2 /* C funtion yielded */ - - -/* type of protected functions, to be ran by `runprotected' */ -typedef void (*Pfunc) (lua_State *L, void *ud); - -LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name); -LUAI_FUNC void luaD_callhook (lua_State *L, int event, int line); -LUAI_FUNC int luaD_precall (lua_State *L, StkId func, int nresults); -LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults); -LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u, - ptrdiff_t oldtop, ptrdiff_t ef); -LUAI_FUNC int luaD_poscall (lua_State *L, StkId firstResult); -LUAI_FUNC void luaD_reallocCI (lua_State *L, int newsize); -LUAI_FUNC void luaD_reallocstack (lua_State *L, int newsize); -LUAI_FUNC void luaD_growstack (lua_State *L, int n); - -LUAI_FUNC void luaD_throw (lua_State *L, int errcode); -LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud); - -LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop); - -#endif - diff --git a/engines/sword25/util/pluto/pdep/lfunc.h b/engines/sword25/util/pluto/pdep/lfunc.h deleted file mode 100644 index 4c2b7fd138..0000000000 --- a/engines/sword25/util/pluto/pdep/lfunc.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -** $Id$ -** Auxiliary functions to manipulate prototypes and closures -** See Copyright Notice in lua.h -*/ - -#ifndef lfunc_h -#define lfunc_h - - -#include "lobject.h" - - -#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \ - cast(int, sizeof(TValue)*((n)-1))) - -#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \ - cast(int, sizeof(TValue *)*((n)-1))) - - -LUAI_FUNC Proto *luaF_newproto (lua_State *L); -LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e); -LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e); -LUAI_FUNC UpVal *luaF_newupval (lua_State *L); -LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level); -LUAI_FUNC void luaF_close (lua_State *L, StkId level); -LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f); -LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c); -LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv); -LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number, - int pc); - - -#endif diff --git a/engines/sword25/util/pluto/pdep/lgc.h b/engines/sword25/util/pluto/pdep/lgc.h deleted file mode 100644 index 5123ccb479..0000000000 --- a/engines/sword25/util/pluto/pdep/lgc.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -** $Id$ -** Garbage Collector -** See Copyright Notice in lua.h -*/ - -#ifndef lgc_h -#define lgc_h - - -#include "lobject.h" - - -/* -** Possible states of the Garbage Collector -*/ -#define GCSpause 0 -#define GCSpropagate 1 -#define GCSsweepstring 2 -#define GCSsweep 3 -#define GCSfinalize 4 - - -/* -** some userful bit tricks -*/ -#define resetbits(x,m) ((x) &= cast(lu_byte, ~(m))) -#define setbits(x,m) ((x) |= (m)) -#define testbits(x,m) ((x) & (m)) -#define bitmask(b) (1<<(b)) -#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2)) -#define l_setbit(x,b) setbits(x, bitmask(b)) -#define resetbit(x,b) resetbits(x, bitmask(b)) -#define testbit(x,b) testbits(x, bitmask(b)) -#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2))) -#define reset2bits(x,b1,b2) resetbits(x, (bit2mask(b1, b2))) -#define test2bits(x,b1,b2) testbits(x, (bit2mask(b1, b2))) - - - -/* -** Layout for bit use in `marked' field: -** bit 0 - object is white (type 0) -** bit 1 - object is white (type 1) -** bit 2 - object is black -** bit 3 - for userdata: has been finalized -** bit 3 - for tables: has weak keys -** bit 4 - for tables: has weak values -** bit 5 - object is fixed (should not be collected) -** bit 6 - object is "super" fixed (only the main thread) -*/ - - -#define WHITE0BIT 0 -#define WHITE1BIT 1 -#define BLACKBIT 2 -#define FINALIZEDBIT 3 -#define KEYWEAKBIT 3 -#define VALUEWEAKBIT 4 -#define FIXEDBIT 5 -#define SFIXEDBIT 6 -#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT) - - -#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) -#define isblack(x) testbit((x)->gch.marked, BLACKBIT) -#define isgray(x) (!isblack(x) && !iswhite(x)) - -#define otherwhite(g) (g->currentwhite ^ WHITEBITS) -#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS) - -#define changewhite(x) ((x)->gch.marked ^= WHITEBITS) -#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT) - -#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x))) - -#define luaC_white(g) cast(lu_byte, (g)->currentwhite & WHITEBITS) - - -#define luaC_checkGC(L) { \ - condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK - 1)); \ - if (G(L)->totalbytes >= G(L)->GCthreshold) \ - luaC_step(L); } - - -#define luaC_barrier(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \ - luaC_barrierf(L,obj2gco(p),gcvalue(v)); } - -#define luaC_barriert(L,t,v) { if (valiswhite(v) && isblack(obj2gco(t))) \ - luaC_barrierback(L,t); } - -#define luaC_objbarrier(L,p,o) \ - { if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \ - luaC_barrierf(L,obj2gco(p),obj2gco(o)); } - -#define luaC_objbarriert(L,t,o) \ - { if (iswhite(obj2gco(o)) && isblack(obj2gco(t))) luaC_barrierback(L,t); } - -LUAI_FUNC size_t luaC_separateudata (lua_State *L, int all); -LUAI_FUNC void luaC_callGCTM (lua_State *L); -LUAI_FUNC void luaC_freeall (lua_State *L); -LUAI_FUNC void luaC_step (lua_State *L); -LUAI_FUNC void luaC_fullgc (lua_State *L); -LUAI_FUNC void luaC_link (lua_State *L, GCObject *o, lu_byte tt); -LUAI_FUNC void luaC_linkupval (lua_State *L, UpVal *uv); -LUAI_FUNC void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v); -LUAI_FUNC void luaC_barrierback (lua_State *L, Table *t); - - -#endif diff --git a/engines/sword25/util/pluto/pdep/llimits.h b/engines/sword25/util/pluto/pdep/llimits.h deleted file mode 100644 index a31ad160ad..0000000000 --- a/engines/sword25/util/pluto/pdep/llimits.h +++ /dev/null @@ -1,128 +0,0 @@ -/* -** $Id$ -** Limits, basic types, and some other `installation-dependent' definitions -** See Copyright Notice in lua.h -*/ - -#ifndef llimits_h -#define llimits_h - - -#include <limits.h> -#include <stddef.h> - - -#include "lua.h" - - -typedef LUAI_UINT32 lu_int32; - -typedef LUAI_UMEM lu_mem; - -typedef LUAI_MEM l_mem; - - - -/* chars used as small naturals (so that `char' is reserved for characters) */ -typedef unsigned char lu_byte; - - -#define MAX_SIZET ((size_t)(~(size_t)0)-2) - -#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2) - - -#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */ - -/* -** conversion of pointer to integer -** this is for hashing only; there is no problem if the integer -** cannot hold the whole pointer value -*/ -#define IntPoint(p) ((unsigned int)(lu_mem)(p)) - - - -/* type to ensure maximum alignment */ -typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; - - -/* result of a `usual argument conversion' over lua_Number */ -typedef LUAI_UACNUMBER l_uacNumber; - - -/* internal assertions for in-house debugging */ -#ifdef lua_assert - -#define check_exp(c,e) (lua_assert(c), (e)) -#define api_check(l,e) lua_assert(e) - -#else - -#define lua_assert(c) ((void)0) -#define check_exp(c,e) (e) -#define api_check luai_apicheck - -#endif - - -#ifndef UNUSED -#define UNUSED(x) ((void)(x)) /* to avoid warnings */ -#endif - - -#ifndef cast -#define cast(t, exp) ((t)(exp)) -#endif - -#define cast_byte(i) cast(lu_byte, (i)) -#define cast_num(i) cast(lua_Number, (i)) -#define cast_int(i) cast(int, (i)) - - - -/* -** type for virtual-machine instructions -** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) -*/ -typedef lu_int32 Instruction; - - - -/* maximum stack for a Lua function */ -#define MAXSTACK 250 - - - -/* minimum size for the string table (must be power of 2) */ -#ifndef MINSTRTABSIZE -#define MINSTRTABSIZE 32 -#endif - - -/* minimum size for string buffer */ -#ifndef LUA_MINBUFFER -#define LUA_MINBUFFER 32 -#endif - - -#ifndef lua_lock -#define lua_lock(L) ((void) 0) -#define lua_unlock(L) ((void) 0) -#endif - -#ifndef luai_threadyield -#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);} -#endif - - -/* -** macro to control inclusion of some hard tests on stack reallocation -*/ -#ifndef HARDSTACKTESTS -#define condhardstacktests(x) ((void)0) -#else -#define condhardstacktests(x) x -#endif - -#endif diff --git a/engines/sword25/util/pluto/pdep/lobject.h b/engines/sword25/util/pluto/pdep/lobject.h deleted file mode 100644 index 35aaed028a..0000000000 --- a/engines/sword25/util/pluto/pdep/lobject.h +++ /dev/null @@ -1,381 +0,0 @@ -/* -** $Id$ -** Type definitions for Lua objects -** See Copyright Notice in lua.h -*/ - - -#ifndef lobject_h -#define lobject_h - - -#include <stdarg.h> - - -#include "llimits.h" -#include "lua.h" - - -/* tags for values visible from Lua */ -#define LAST_TAG LUA_TTHREAD - -#define NUM_TAGS (LAST_TAG+1) - - -/* -** Extra tags for non-values -*/ -#define LUA_TPROTO (LAST_TAG+1) -#define LUA_TUPVAL (LAST_TAG+2) -#define LUA_TDEADKEY (LAST_TAG+3) - - -/* -** Union of all collectable objects -*/ -typedef union GCObject GCObject; - - -/* -** Common Header for all collectable objects (in macro form, to be -** included in other objects) -*/ -#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked - - -/* -** Common header in struct form -*/ -typedef struct GCheader { - CommonHeader; -} GCheader; - - - - -/* -** Union of all Lua values -*/ -typedef union { - GCObject *gc; - void *p; - lua_Number n; - int b; -} Value; - - -/* -** Tagged Values -*/ - -#define TValuefields Value value; int tt - -typedef struct lua_TValue { - TValuefields; -} TValue; - - -/* Macros to test type */ -#define ttisnil(o) (ttype(o) == LUA_TNIL) -#define ttisnumber(o) (ttype(o) == LUA_TNUMBER) -#define ttisstring(o) (ttype(o) == LUA_TSTRING) -#define ttistable(o) (ttype(o) == LUA_TTABLE) -#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) -#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) -#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) -#define ttisthread(o) (ttype(o) == LUA_TTHREAD) -#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) - -/* Macros to access values */ -#define ttype(o) ((o)->tt) -#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) -#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) -#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) -#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) -#define tsvalue(o) (&rawtsvalue(o)->tsv) -#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) -#define uvalue(o) (&rawuvalue(o)->uv) -#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) -#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) -#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) -#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) - -#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) - -/* -** for internal debug only -*/ -#define checkconsistency(obj) \ - lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) - -#define checkliveness(g,obj) \ - lua_assert(!iscollectable(obj) || \ - ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) - - -/* Macros to set values */ -#define setnilvalue(obj) ((obj)->tt=LUA_TNIL) - -#define setnvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } - -#define setpvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } - -#define setbvalue(obj,x) \ - { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } - -#define setsvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ - checkliveness(G(L),i_o); } - -#define setuvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ - checkliveness(G(L),i_o); } - -#define setthvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ - checkliveness(G(L),i_o); } - -#define setclvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ - checkliveness(G(L),i_o); } - -#define sethvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ - checkliveness(G(L),i_o); } - -#define setptvalue(L,obj,x) \ - { TValue *i_o=(obj); \ - i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ - checkliveness(G(L),i_o); } - - - - -#define setobj(L,obj1,obj2) \ - { const TValue *o2=(obj2); TValue *o1=(obj1); \ - o1->value = o2->value; o1->tt=o2->tt; \ - checkliveness(G(L),o1); } - - -/* -** different types of sets, according to destination -*/ - -/* from stack to (same) stack */ -#define setobjs2s setobj -/* to stack (not from same stack) */ -#define setobj2s setobj -#define setsvalue2s setsvalue -#define sethvalue2s sethvalue -#define setptvalue2s setptvalue -/* from table to same table */ -#define setobjt2t setobj -/* to table */ -#define setobj2t setobj -/* to new object */ -#define setobj2n setobj -#define setsvalue2n setsvalue - -#define setttype(obj, tt) (ttype(obj) = (tt)) - - -#define iscollectable(o) (ttype(o) >= LUA_TSTRING) - - - -typedef TValue *StkId; /* index to stack elements */ - - -/* -** String headers for string table -*/ -typedef union TString { - L_Umaxalign dummy; /* ensures maximum alignment for strings */ - struct { - CommonHeader; - lu_byte reserved; - unsigned int hash; - size_t len; - } tsv; -} TString; - - -#define getstr(ts) cast(const char *, (ts) + 1) -#define svalue(o) getstr(tsvalue(o)) - - - -typedef union Udata { - L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ - struct { - CommonHeader; - struct Table *metatable; - struct Table *env; - size_t len; - } uv; -} Udata; - - - - -/* -** Function Prototypes -*/ -typedef struct Proto { - CommonHeader; - TValue *k; /* constants used by the function */ - Instruction *code; - struct Proto **p; /* functions defined inside the function */ - int *lineinfo; /* map from opcodes to source lines */ - struct LocVar *locvars; /* information about local variables */ - TString **upvalues; /* upvalue names */ - TString *source; - int sizeupvalues; - int sizek; /* size of `k' */ - int sizecode; - int sizelineinfo; - int sizep; /* size of `p' */ - int sizelocvars; - int linedefined; - int lastlinedefined; - GCObject *gclist; - lu_byte nups; /* number of upvalues */ - lu_byte numparams; - lu_byte is_vararg; - lu_byte maxstacksize; -} Proto; - - -/* masks for new-style vararg */ -#define VARARG_HASARG 1 -#define VARARG_ISVARARG 2 -#define VARARG_NEEDSARG 4 - - -typedef struct LocVar { - TString *varname; - int startpc; /* first point where variable is active */ - int endpc; /* first point where variable is dead */ -} LocVar; - - - -/* -** Upvalues -*/ - -typedef struct UpVal { - CommonHeader; - TValue *v; /* points to stack or to its own value */ - union { - TValue value; /* the value (when closed) */ - struct { /* double linked list (when open) */ - struct UpVal *prev; - struct UpVal *next; - } l; - } u; -} UpVal; - - -/* -** Closures -*/ - -#define ClosureHeader \ - CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ - struct Table *env - -typedef struct CClosure { - ClosureHeader; - lua_CFunction f; - TValue upvalue[1]; -} CClosure; - - -typedef struct LClosure { - ClosureHeader; - struct Proto *p; - UpVal *upvals[1]; -} LClosure; - - -typedef union Closure { - CClosure c; - LClosure l; -} Closure; - - -#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) -#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) - - -/* -** Tables -*/ - -typedef union TKey { - struct { - TValuefields; - struct Node *next; /* for chaining */ - } nk; - TValue tvk; -} TKey; - - -typedef struct Node { - TValue i_val; - TKey i_key; -} Node; - - -typedef struct Table { - CommonHeader; - lu_byte flags; /* 1<<p means tagmethod(p) is not present */ - lu_byte lsizenode; /* log2 of size of `node' array */ - struct Table *metatable; - TValue *array; /* array part */ - Node *node; - Node *lastfree; /* any free position is before this position */ - GCObject *gclist; - int sizearray; /* size of `array' array */ -} Table; - - - -/* -** `module' operation for hashing (size is always a power of 2) -*/ -#define lmod(s,size) \ - (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1))))) - - -#define twoto(x) (1<<(x)) -#define sizenode(t) (twoto((t)->lsizenode)) - - -#define luaO_nilobject (&luaO_nilobject_) - -LUAI_DATA const TValue luaO_nilobject_; - -#define ceillog2(x) (luaO_log2((x)-1) + 1) - -LUAI_FUNC int luaO_log2 (unsigned int x); -LUAI_FUNC int luaO_int2fb (unsigned int x); -LUAI_FUNC int luaO_fb2int (int x); -LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); -LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); -LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, - va_list argp); -LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); -LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len); - - -#endif - diff --git a/engines/sword25/util/pluto/pdep/lopcodes.h b/engines/sword25/util/pluto/pdep/lopcodes.h deleted file mode 100644 index e1aed0f637..0000000000 --- a/engines/sword25/util/pluto/pdep/lopcodes.h +++ /dev/null @@ -1,268 +0,0 @@ -/* -** $Id$ -** Opcodes for Lua virtual machine -** See Copyright Notice in lua.h -*/ - -#ifndef lopcodes_h -#define lopcodes_h - -#include "llimits.h" - - -/*=========================================================================== - We assume that instructions are unsigned numbers. - All instructions have an opcode in the first 6 bits. - Instructions can have the following fields: - `A' : 8 bits - `B' : 9 bits - `C' : 9 bits - `Bx' : 18 bits (`B' and `C' together) - `sBx' : signed Bx - - A signed argument is represented in excess K; that is, the number - value is the unsigned value minus K. K is exactly the maximum value - for that argument (so that -max is represented by 0, and +max is - represented by 2*max), which is half the maximum for the corresponding - unsigned argument. -===========================================================================*/ - - -enum OpMode {iABC, iABx, iAsBx}; /* basic instruction format */ - - -/* -** size and position of opcode arguments. -*/ -#define SIZE_C 9 -#define SIZE_B 9 -#define SIZE_Bx (SIZE_C + SIZE_B) -#define SIZE_A 8 - -#define SIZE_OP 6 - -#define POS_OP 0 -#define POS_A (POS_OP + SIZE_OP) -#define POS_C (POS_A + SIZE_A) -#define POS_B (POS_C + SIZE_C) -#define POS_Bx POS_C - - -/* -** limits for opcode arguments. -** we use (signed) int to manipulate most arguments, -** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) -*/ -#if SIZE_Bx < LUAI_BITSINT-1 -#define MAXARG_Bx ((1<<SIZE_Bx)-1) -#define MAXARG_sBx (MAXARG_Bx>>1) /* `sBx' is signed */ -#else -#define MAXARG_Bx MAX_INT -#define MAXARG_sBx MAX_INT -#endif - - -#define MAXARG_A ((1<<SIZE_A)-1) -#define MAXARG_B ((1<<SIZE_B)-1) -#define MAXARG_C ((1<<SIZE_C)-1) - - -/* creates a mask with `n' 1 bits at position `p' */ -#define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p) - -/* creates a mask with `n' 0 bits at position `p' */ -#define MASK0(n,p) (~MASK1(n,p)) - -/* -** the following macros help to manipulate instructions -*/ - -#define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0))) -#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ - ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) - -#define GETARG_A(i) (cast(int, ((i)>>POS_A) & MASK1(SIZE_A,0))) -#define SETARG_A(i,u) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ - ((cast(Instruction, u)<<POS_A)&MASK1(SIZE_A,POS_A)))) - -#define GETARG_B(i) (cast(int, ((i)>>POS_B) & MASK1(SIZE_B,0))) -#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ - ((cast(Instruction, b)<<POS_B)&MASK1(SIZE_B,POS_B)))) - -#define GETARG_C(i) (cast(int, ((i)>>POS_C) & MASK1(SIZE_C,0))) -#define SETARG_C(i,b) ((i) = (((i)&MASK0(SIZE_C,POS_C)) | \ - ((cast(Instruction, b)<<POS_C)&MASK1(SIZE_C,POS_C)))) - -#define GETARG_Bx(i) (cast(int, ((i)>>POS_Bx) & MASK1(SIZE_Bx,0))) -#define SETARG_Bx(i,b) ((i) = (((i)&MASK0(SIZE_Bx,POS_Bx)) | \ - ((cast(Instruction, b)<<POS_Bx)&MASK1(SIZE_Bx,POS_Bx)))) - -#define GETARG_sBx(i) (GETARG_Bx(i)-MAXARG_sBx) -#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) - - -#define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \ - | (cast(Instruction, a)<<POS_A) \ - | (cast(Instruction, b)<<POS_B) \ - | (cast(Instruction, c)<<POS_C)) - -#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \ - | (cast(Instruction, a)<<POS_A) \ - | (cast(Instruction, bc)<<POS_Bx)) - - -/* -** Macros to operate RK indices -*/ - -/* this bit 1 means constant (0 means register) */ -#define BITRK (1 << (SIZE_B - 1)) - -/* test whether value is a constant */ -#define ISK(x) ((x) & BITRK) - -/* gets the index of the constant */ -#define INDEXK(r) ((int)(r) & ~BITRK) - -#define MAXINDEXRK (BITRK - 1) - -/* code a constant index as a RK value */ -#define RKASK(x) ((x) | BITRK) - - -/* -** invalid register that fits in 8 bits -*/ -#define NO_REG MAXARG_A - - -/* -** R(x) - register -** Kst(x) - constant (in constant table) -** RK(x) == if ISK(x) then Kst(INDEXK(x)) else R(x) -*/ - - -/* -** grep "ORDER OP" if you change these enums -*/ - -typedef enum { -/*---------------------------------------------------------------------- -name args description -------------------------------------------------------------------------*/ -OP_MOVE,/* A B R(A) := R(B) */ -OP_LOADK,/* A Bx R(A) := Kst(Bx) */ -OP_LOADBOOL,/* A B C R(A) := (Bool)B; if (C) pc++ */ -OP_LOADNIL,/* A B R(A) := ... := R(B) := nil */ -OP_GETUPVAL,/* A B R(A) := UpValue[B] */ - -OP_GETGLOBAL,/* A Bx R(A) := Gbl[Kst(Bx)] */ -OP_GETTABLE,/* A B C R(A) := R(B)[RK(C)] */ - -OP_SETGLOBAL,/* A Bx Gbl[Kst(Bx)] := R(A) */ -OP_SETUPVAL,/* A B UpValue[B] := R(A) */ -OP_SETTABLE,/* A B C R(A)[RK(B)] := RK(C) */ - -OP_NEWTABLE,/* A B C R(A) := {} (size = B,C) */ - -OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C)] */ - -OP_ADD,/* A B C R(A) := RK(B) + RK(C) */ -OP_SUB,/* A B C R(A) := RK(B) - RK(C) */ -OP_MUL,/* A B C R(A) := RK(B) * RK(C) */ -OP_DIV,/* A B C R(A) := RK(B) / RK(C) */ -OP_MOD,/* A B C R(A) := RK(B) % RK(C) */ -OP_POW,/* A B C R(A) := RK(B) ^ RK(C) */ -OP_UNM,/* A B R(A) := -R(B) */ -OP_NOT,/* A B R(A) := not R(B) */ -OP_LEN,/* A B R(A) := length of R(B) */ - -OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ - -OP_JMP,/* sBx pc+=sBx */ - -OP_EQ,/* A B C if ((RK(B) == RK(C)) ~= A) then pc++ */ -OP_LT,/* A B C if ((RK(B) < RK(C)) ~= A) then pc++ */ -OP_LE,/* A B C if ((RK(B) <= RK(C)) ~= A) then pc++ */ - -OP_TEST,/* A C if not (R(A) <=> C) then pc++ */ -OP_TESTSET,/* A B C if (R(B) <=> C) then R(A) := R(B) else pc++ */ - -OP_CALL,/* A B C R(A), ... ,R(A+C-2) := R(A)(R(A+1), ... ,R(A+B-1)) */ -OP_TAILCALL,/* A B C return R(A)(R(A+1), ... ,R(A+B-1)) */ -OP_RETURN,/* A B return R(A), ... ,R(A+B-2) (see note) */ - -OP_FORLOOP,/* A sBx R(A)+=R(A+2); - if R(A) <?= R(A+1) then { pc+=sBx; R(A+3)=R(A) }*/ -OP_FORPREP,/* A sBx R(A)-=R(A+2); pc+=sBx */ - -OP_TFORLOOP,/* A C R(A+3), ... ,R(A+2+C) := R(A)(R(A+1), R(A+2)); - if R(A+3) ~= nil then R(A+2)=R(A+3) else pc++ */ -OP_SETLIST,/* A B C R(A)[(C-1)*FPF+i] := R(A+i), 1 <= i <= B */ - -OP_CLOSE,/* A close all variables in the stack up to (>=) R(A)*/ -OP_CLOSURE,/* A Bx R(A) := closure(KPROTO[Bx], R(A), ... ,R(A+n)) */ - -OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ -} OpCode; - - -#define NUM_OPCODES (cast(int, OP_VARARG) + 1) - - - -/*=========================================================================== - Notes: - (*) In OP_CALL, if (B == 0) then B = top. C is the number of returns - 1, - and can be 0: OP_CALL then sets `top' to last_result+1, so - next open instruction (OP_CALL, OP_RETURN, OP_SETLIST) may use `top'. - - (*) In OP_VARARG, if (B == 0) then use actual number of varargs and - set top (like in OP_CALL with C == 0). - - (*) In OP_RETURN, if (B == 0) then return up to `top' - - (*) In OP_SETLIST, if (B == 0) then B = `top'; - if (C == 0) then next `instruction' is real C - - (*) For comparisons, A specifies what condition the test should accept - (true or false). - - (*) All `skips' (pc++) assume that next instruction is a jump -===========================================================================*/ - - -/* -** masks for instruction properties. The format is: -** bits 0-1: op mode -** bits 2-3: C arg mode -** bits 4-5: B arg mode -** bit 6: instruction set register A -** bit 7: operator is a test -*/ - -enum OpArgMask { - OpArgN, /* argument is not used */ - OpArgU, /* argument is used */ - OpArgR, /* argument is a register or a jump offset */ - OpArgK /* argument is a constant or register/constant */ -}; - -LUAI_DATA const lu_byte luaP_opmodes[NUM_OPCODES]; - -#define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 3)) -#define getBMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 4) & 3)) -#define getCMode(m) (cast(enum OpArgMask, (luaP_opmodes[m] >> 2) & 3)) -#define testAMode(m) (luaP_opmodes[m] & (1 << 6)) -#define testTMode(m) (luaP_opmodes[m] & (1 << 7)) - - -LUAI_DATA const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */ - - -/* number of list items to accumulate before a SETLIST instruction */ -#define LFIELDS_PER_FLUSH 50 - - -#endif diff --git a/engines/sword25/util/pluto/pdep/lstate.h b/engines/sword25/util/pluto/pdep/lstate.h deleted file mode 100644 index 94a6249461..0000000000 --- a/engines/sword25/util/pluto/pdep/lstate.h +++ /dev/null @@ -1,169 +0,0 @@ -/* -** $Id$ -** Global State -** See Copyright Notice in lua.h -*/ - -#ifndef lstate_h -#define lstate_h - -#include "lua.h" - -#include "lobject.h" -#include "ltm.h" -#include "lzio.h" - - - -struct lua_longjmp; /* defined in ldo.c */ - - -/* table of globals */ -#define gt(L) (&L->l_gt) - -/* registry */ -#define registry(L) (&G(L)->l_registry) - - -/* extra stack space to handle TM calls and some other extras */ -#define EXTRA_STACK 5 - - -#define BASIC_CI_SIZE 8 - -#define BASIC_STACK_SIZE (2*LUA_MINSTACK) - - - -typedef struct stringtable { - GCObject **hash; - lu_int32 nuse; /* number of elements */ - int size; -} stringtable; - - -/* -** informations about a call -*/ -typedef struct CallInfo { - StkId base; /* base for this function */ - StkId func; /* function index in the stack */ - StkId top; /* top for this function */ - const Instruction *savedpc; - int nresults; /* expected number of results from this function */ - int tailcalls; /* number of tail calls lost under this entry */ -} CallInfo; - - - -#define curr_func(L) (clvalue(L->ci->func)) -#define ci_func(ci) (clvalue((ci)->func)) -#define f_isLua(ci) (!ci_func(ci)->c.isC) -#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) - - -/* -** `global state', shared by all threads of this state -*/ -typedef struct global_State { - stringtable strt; /* hash table for strings */ - lua_Alloc frealloc; /* function to reallocate memory */ - void *ud; /* auxiliary data to `frealloc' */ - lu_byte currentwhite; - lu_byte gcstate; /* state of garbage collector */ - int sweepstrgc; /* position of sweep in `strt' */ - GCObject *rootgc; /* list of all collectable objects */ - GCObject **sweepgc; /* position of sweep in `rootgc' */ - GCObject *gray; /* list of gray objects */ - GCObject *grayagain; /* list of objects to be traversed atomically */ - GCObject *weak; /* list of weak tables (to be cleared) */ - GCObject *tmudata; /* last element of list of userdata to be GC */ - Mbuffer buff; /* temporary buffer for string concatentation */ - lu_mem GCthreshold; - lu_mem totalbytes; /* number of bytes currently allocated */ - lu_mem estimate; /* an estimate of number of bytes actually in use */ - lu_mem gcdept; /* how much GC is `behind schedule' */ - int gcpause; /* size of pause between successive GCs */ - int gcstepmul; /* GC `granularity' */ - lua_CFunction panic; /* to be called in unprotected errors */ - TValue l_registry; - struct lua_State *mainthread; - UpVal uvhead; /* head of double-linked list of all open upvalues */ - struct Table *mt[NUM_TAGS]; /* metatables for basic types */ - TString *tmname[TM_N]; /* array with tag-method names */ -} global_State; - - -/* -** `per thread' state -*/ -struct lua_State { - CommonHeader; - lu_byte status; - StkId top; /* first free slot in the stack */ - StkId base; /* base of current function */ - global_State *l_G; - CallInfo *ci; /* call info for current function */ - const Instruction *savedpc; /* `savedpc' of current function */ - StkId stack_last; /* last free slot in the stack */ - StkId stack; /* stack base */ - CallInfo *end_ci; /* points after end of ci array*/ - CallInfo *base_ci; /* array of CallInfo's */ - int stacksize; - int size_ci; /* size of array `base_ci' */ - unsigned short nCcalls; /* number of nested C calls */ - unsigned short baseCcalls; /* nested C calls when resuming coroutine */ - lu_byte hookmask; - lu_byte allowhook; - int basehookcount; - int hookcount; - lua_Hook hook; - TValue l_gt; /* table of globals */ - TValue env; /* temporary place for environments */ - GCObject *openupval; /* list of open upvalues in this stack */ - GCObject *gclist; - struct lua_longjmp *errorJmp; /* current error recover point */ - ptrdiff_t errfunc; /* current error handling function (stack index) */ -}; - - -#define G(L) (L->l_G) - - -/* -** Union of all collectable objects -*/ -union GCObject { - GCheader gch; - union TString ts; - union Udata u; - union Closure cl; - struct Table h; - struct Proto p; - struct UpVal uv; - struct lua_State th; /* thread */ -}; - - -/* macros to convert a GCObject into a specific value */ -#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) -#define gco2ts(o) (&rawgco2ts(o)->tsv) -#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) -#define gco2u(o) (&rawgco2u(o)->uv) -#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) -#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) -#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) -#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) -#define ngcotouv(o) \ - check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) -#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) - -/* macro to convert any Lua object into a GCObject */ -#define obj2gco(v) (cast(GCObject *, (v))) - - -LUAI_FUNC lua_State *luaE_newthread (lua_State *L); -LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); - -#endif - diff --git a/engines/sword25/util/pluto/pdep/lstring.h b/engines/sword25/util/pluto/pdep/lstring.h deleted file mode 100644 index c88e4c12a9..0000000000 --- a/engines/sword25/util/pluto/pdep/lstring.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -** $Id$ -** String table (keep all strings handled by Lua) -** See Copyright Notice in lua.h -*/ - -#ifndef lstring_h -#define lstring_h - - -#include "lgc.h" -#include "lobject.h" -#include "lstate.h" - - -#define sizestring(s) (sizeof(union TString)+((s)->len+1)*sizeof(char)) - -#define sizeudata(u) (sizeof(union Udata)+(u)->len) - -#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s))) -#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \ - (sizeof(s)/sizeof(char))-1)) - -#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT) - -LUAI_FUNC void luaS_resize (lua_State *L, int newsize); -LUAI_FUNC Udata *luaS_newudata (lua_State *L, size_t s, Table *e); -LUAI_FUNC TString *luaS_newlstr (lua_State *L, const char *str, size_t l); - - -#endif diff --git a/engines/sword25/util/pluto/pdep/ltm.h b/engines/sword25/util/pluto/pdep/ltm.h deleted file mode 100644 index 1b89683ef3..0000000000 --- a/engines/sword25/util/pluto/pdep/ltm.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -** $Id$ -** Tag methods -** See Copyright Notice in lua.h -*/ - -#ifndef ltm_h -#define ltm_h - - -#include "lobject.h" - - -/* -* WARNING: if you change the order of this enumeration, -* grep "ORDER TM" -*/ -typedef enum { - TM_INDEX, - TM_NEWINDEX, - TM_GC, - TM_MODE, - TM_EQ, /* last tag method with `fast' access */ - TM_ADD, - TM_SUB, - TM_MUL, - TM_DIV, - TM_MOD, - TM_POW, - TM_UNM, - TM_LEN, - TM_LT, - TM_LE, - TM_CONCAT, - TM_CALL, - TM_N /* number of elements in the enum */ -} TMS; - - - -#define gfasttm(g,et,e) ((et) == NULL ? NULL : \ - ((et)->flags & (1u<<(e))) ? NULL : luaT_gettm(et, e, (g)->tmname[e])) - -#define fasttm(l,et,e) gfasttm(G(l), et, e) - -LUAI_DATA const char *const luaT_typenames[]; - - -LUAI_FUNC const TValue *luaT_gettm (Table *events, TMS event, TString *ename); -LUAI_FUNC const TValue *luaT_gettmbyobj (lua_State *L, const TValue *o, - TMS event); -LUAI_FUNC void luaT_init (lua_State *L); - -#endif diff --git a/engines/sword25/util/pluto/pdep/lua.h b/engines/sword25/util/pluto/pdep/lua.h deleted file mode 100644 index 68dd887f0f..0000000000 --- a/engines/sword25/util/pluto/pdep/lua.h +++ /dev/null @@ -1,388 +0,0 @@ -/* -** $Id$ -** Lua - An Extensible Extension Language -** Lua.org, PUC-Rio, Brazil (http://www.lua.org) -** See Copyright Notice at the end of this file -*/ - - -#ifndef lua_h -#define lua_h - -#include <stdarg.h> -#include <stddef.h> - - -#include "sword25/util/lua/luaconf.h" - - -#define LUA_VERSION "Lua 5.1" -#define LUA_RELEASE "Lua 5.1.3" -#define LUA_VERSION_NUM 501 -#define LUA_COPYRIGHT "Copyright (C) 1994-2008 Lua.org, PUC-Rio" -#define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo & W. Celes" - - -/* mark for precompiled code (`<esc>Lua') */ -#define LUA_SIGNATURE "\033Lua" - -/* option for multiple returns in `lua_pcall' and `lua_call' */ -#define LUA_MULTRET (-1) - - -/* -** pseudo-indices -*/ -#define LUA_REGISTRYINDEX (-10000) -#define LUA_ENVIRONINDEX (-10001) -#define LUA_GLOBALSINDEX (-10002) -#define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) - - -/* thread status; 0 is OK */ -#define LUA_YIELD 1 -#define LUA_ERRRUN 2 -#define LUA_ERRSYNTAX 3 -#define LUA_ERRMEM 4 -#define LUA_ERRERR 5 - - -typedef struct lua_State lua_State; - -typedef int (*lua_CFunction) (lua_State *L); - - -/* -** functions that read/write blocks when loading/dumping Lua chunks -*/ -typedef const char * (*lua_Reader) (lua_State *L, void *ud, size_t *sz); - -typedef int (*lua_Writer) (lua_State *L, const void* p, size_t sz, void* ud); - - -/* -** prototype for memory-allocation functions -*/ -typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); - - -/* -** basic types -*/ -#define LUA_TNONE (-1) - -#define LUA_TNIL 0 -#define LUA_TBOOLEAN 1 -#define LUA_TLIGHTUSERDATA 2 -#define LUA_TNUMBER 3 -#define LUA_TSTRING 4 -#define LUA_TTABLE 5 -#define LUA_TFUNCTION 6 -#define LUA_TUSERDATA 7 -#define LUA_TTHREAD 8 - - - -/* minimum Lua stack available to a C function */ -#define LUA_MINSTACK 20 - - -/* -** generic extra include file -*/ -#if defined(LUA_USER_H) -#include LUA_USER_H -#endif - - -/* type of numbers in Lua */ -typedef LUA_NUMBER lua_Number; - - -/* type for integer functions */ -typedef LUA_INTEGER lua_Integer; - - - -/* -** state manipulation -*/ -LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud); -LUA_API void (lua_close) (lua_State *L); -LUA_API lua_State *(lua_newthread) (lua_State *L); - -LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf); - - -/* -** basic stack manipulation -*/ -LUA_API int (lua_gettop) (lua_State *L); -LUA_API void (lua_settop) (lua_State *L, int idx); -LUA_API void (lua_pushvalue) (lua_State *L, int idx); -LUA_API void (lua_remove) (lua_State *L, int idx); -LUA_API void (lua_insert) (lua_State *L, int idx); -LUA_API void (lua_replace) (lua_State *L, int idx); -LUA_API int (lua_checkstack) (lua_State *L, int sz); - -LUA_API void (lua_xmove) (lua_State *from, lua_State *to, int n); - - -/* -** access functions (stack -> C) -*/ - -LUA_API int (lua_isnumber) (lua_State *L, int idx); -LUA_API int (lua_isstring) (lua_State *L, int idx); -LUA_API int (lua_iscfunction) (lua_State *L, int idx); -LUA_API int (lua_isuserdata) (lua_State *L, int idx); -LUA_API int (lua_type) (lua_State *L, int idx); -LUA_API const char *(lua_typename) (lua_State *L, int tp); - -LUA_API int (lua_equal) (lua_State *L, int idx1, int idx2); -LUA_API int (lua_rawequal) (lua_State *L, int idx1, int idx2); -LUA_API int (lua_lessthan) (lua_State *L, int idx1, int idx2); - -LUA_API lua_Number (lua_tonumber) (lua_State *L, int idx); -LUA_API lua_Integer (lua_tointeger) (lua_State *L, int idx); -LUA_API int (lua_toboolean) (lua_State *L, int idx); -LUA_API const char *(lua_tolstring) (lua_State *L, int idx, size_t *len); -LUA_API size_t (lua_objlen) (lua_State *L, int idx); -LUA_API lua_CFunction (lua_tocfunction) (lua_State *L, int idx); -LUA_API void *(lua_touserdata) (lua_State *L, int idx); -LUA_API lua_State *(lua_tothread) (lua_State *L, int idx); -LUA_API const void *(lua_topointer) (lua_State *L, int idx); - - -/* -** push functions (C -> stack) -*/ -LUA_API void (lua_pushnil) (lua_State *L); -LUA_API void (lua_pushnumber) (lua_State *L, lua_Number n); -LUA_API void (lua_pushinteger) (lua_State *L, lua_Integer n); -LUA_API void (lua_pushlstring) (lua_State *L, const char *s, size_t l); -LUA_API void (lua_pushstring) (lua_State *L, const char *s); -LUA_API const char *(lua_pushvfstring) (lua_State *L, const char *fmt, - va_list argp); -LUA_API const char *(lua_pushfstring) (lua_State *L, const char *fmt, ...); -LUA_API void (lua_pushcclosure) (lua_State *L, lua_CFunction fn, int n); -LUA_API void (lua_pushboolean) (lua_State *L, int b); -LUA_API void (lua_pushlightuserdata) (lua_State *L, void *p); -LUA_API int (lua_pushthread) (lua_State *L); - - -/* -** get functions (Lua -> stack) -*/ -LUA_API void (lua_gettable) (lua_State *L, int idx); -LUA_API void (lua_getfield) (lua_State *L, int idx, const char *k); -LUA_API void (lua_rawget) (lua_State *L, int idx); -LUA_API void (lua_rawgeti) (lua_State *L, int idx, int n); -LUA_API void (lua_createtable) (lua_State *L, int narr, int nrec); -LUA_API void *(lua_newuserdata) (lua_State *L, size_t sz); -LUA_API int (lua_getmetatable) (lua_State *L, int objindex); -LUA_API void (lua_getfenv) (lua_State *L, int idx); - - -/* -** set functions (stack -> Lua) -*/ -LUA_API void (lua_settable) (lua_State *L, int idx); -LUA_API void (lua_setfield) (lua_State *L, int idx, const char *k); -LUA_API void (lua_rawset) (lua_State *L, int idx); -LUA_API void (lua_rawseti) (lua_State *L, int idx, int n); -LUA_API int (lua_setmetatable) (lua_State *L, int objindex); -LUA_API int (lua_setfenv) (lua_State *L, int idx); - - -/* -** `load' and `call' functions (load and run Lua code) -*/ -LUA_API void (lua_call) (lua_State *L, int nargs, int nresults); -LUA_API int (lua_pcall) (lua_State *L, int nargs, int nresults, int errfunc); -LUA_API int (lua_cpcall) (lua_State *L, lua_CFunction func, void *ud); -LUA_API int (lua_load) (lua_State *L, lua_Reader reader, void *dt, - const char *chunkname); - -LUA_API int (lua_dump) (lua_State *L, lua_Writer writer, void *data); - - -/* -** coroutine functions -*/ -LUA_API int (lua_yield) (lua_State *L, int nresults); -LUA_API int (lua_resume) (lua_State *L, int narg); -LUA_API int (lua_status) (lua_State *L); - -/* -** garbage-collection function and options -*/ - -#define LUA_GCSTOP 0 -#define LUA_GCRESTART 1 -#define LUA_GCCOLLECT 2 -#define LUA_GCCOUNT 3 -#define LUA_GCCOUNTB 4 -#define LUA_GCSTEP 5 -#define LUA_GCSETPAUSE 6 -#define LUA_GCSETSTEPMUL 7 - -LUA_API int (lua_gc) (lua_State *L, int what, int data); - - -/* -** miscellaneous functions -*/ - -LUA_API int (lua_error) (lua_State *L); - -LUA_API int (lua_next) (lua_State *L, int idx); - -LUA_API void (lua_concat) (lua_State *L, int n); - -LUA_API lua_Alloc (lua_getallocf) (lua_State *L, void **ud); -LUA_API void lua_setallocf (lua_State *L, lua_Alloc f, void *ud); - - - -/* -** =============================================================== -** some useful macros -** =============================================================== -*/ - -#define lua_pop(L,n) lua_settop(L, -(n)-1) - -#define lua_newtable(L) lua_createtable(L, 0, 0) - -#define lua_register(L,n,f) (lua_pushcfunction(L, (f)), lua_setglobal(L, (n))) - -#define lua_pushcfunction(L,f) lua_pushcclosure(L, (f), 0) - -#define lua_strlen(L,i) lua_objlen(L, (i)) - -#define lua_isfunction(L,n) (lua_type(L, (n)) == LUA_TFUNCTION) -#define lua_istable(L,n) (lua_type(L, (n)) == LUA_TTABLE) -#define lua_islightuserdata(L,n) (lua_type(L, (n)) == LUA_TLIGHTUSERDATA) -#define lua_isnil(L,n) (lua_type(L, (n)) == LUA_TNIL) -#define lua_isboolean(L,n) (lua_type(L, (n)) == LUA_TBOOLEAN) -#define lua_isthread(L,n) (lua_type(L, (n)) == LUA_TTHREAD) -#define lua_isnone(L,n) (lua_type(L, (n)) == LUA_TNONE) -#define lua_isnoneornil(L, n) (lua_type(L, (n)) <= 0) - -#define lua_pushliteral(L, s) \ - lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) - -#define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) -#define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) - -#define lua_tostring(L,i) lua_tolstring(L, (i), NULL) - - - -/* -** compatibility macros and functions -*/ - -#define lua_open() luaL_newstate() - -#define lua_getregistry(L) lua_pushvalue(L, LUA_REGISTRYINDEX) - -#define lua_getgccount(L) lua_gc(L, LUA_GCCOUNT, 0) - -#define lua_Chunkreader lua_Reader -#define lua_Chunkwriter lua_Writer - - -/* hack */ -LUA_API void lua_setlevel (lua_State *from, lua_State *to); - - -/* -** {====================================================================== -** Debug API -** ======================================================================= -*/ - - -/* -** Event codes -*/ -#define LUA_HOOKCALL 0 -#define LUA_HOOKRET 1 -#define LUA_HOOKLINE 2 -#define LUA_HOOKCOUNT 3 -#define LUA_HOOKTAILRET 4 - - -/* -** Event masks -*/ -#define LUA_MASKCALL (1 << LUA_HOOKCALL) -#define LUA_MASKRET (1 << LUA_HOOKRET) -#define LUA_MASKLINE (1 << LUA_HOOKLINE) -#define LUA_MASKCOUNT (1 << LUA_HOOKCOUNT) - -typedef struct lua_Debug lua_Debug; /* activation record */ - - -/* Functions to be called by the debuger in specific events */ -typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar); - - -LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar); -LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar); -LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n); -LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n); -LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n); -LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n); - -LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count); -LUA_API lua_Hook lua_gethook (lua_State *L); -LUA_API int lua_gethookmask (lua_State *L); -LUA_API int lua_gethookcount (lua_State *L); - - -struct lua_Debug { - int event; - const char *name; /* (n) */ - const char *namewhat; /* (n) `global', `local', `field', `method' */ - const char *what; /* (S) `Lua', `C', `main', `tail' */ - const char *source; /* (S) */ - int currentline; /* (l) */ - int nups; /* (u) number of upvalues */ - int linedefined; /* (S) */ - int lastlinedefined; /* (S) */ - char short_src[LUA_IDSIZE]; /* (S) */ - /* private part */ - int i_ci; /* active function */ -}; - -/* }====================================================================== */ - - -/****************************************************************************** -* Copyright (C) 1994-2008 Lua.org, PUC-Rio. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be -* included in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -******************************************************************************/ - - -#endif diff --git a/engines/sword25/util/pluto/pdep/lzio.h b/engines/sword25/util/pluto/pdep/lzio.h index 2f167d7d58..2e37f8d202 100644 --- a/engines/sword25/util/pluto/pdep/lzio.h +++ b/engines/sword25/util/pluto/pdep/lzio.h @@ -8,7 +8,7 @@ #ifndef lzio_h #define lzio_h -#include "lua.h" +#include "sword25/util/lua/lua.h" #define EOZ (-1) /* end of stream */ diff --git a/engines/sword25/util/pluto/pdep/pdep.h b/engines/sword25/util/pluto/pdep/pdep.h index c26f4566c5..664fc812b5 100644 --- a/engines/sword25/util/pluto/pdep/pdep.h +++ b/engines/sword25/util/pluto/pdep/pdep.h @@ -1,16 +1,17 @@ #ifndef PDEP_H #define PDEP_H -#include "lua.h" -#include "ldo.h" -#include "lfunc.h" -#include "lgc.h" -#include "llimits.h" -#include "lobject.h" -#include "lopcodes.h" -#include "lstate.h" -#include "lstring.h" -#include "lauxlib.h" +#include "sword25/util/lua/lua.h" +#include "sword25/util/pluto/pdep/lzio.h" +#include "sword25/util/lua/ldo.h" +#include "sword25/util/lua/lfunc.h" +#include "sword25/util/lua/lgc.h" +#include "sword25/util/lua/llimits.h" +#include "sword25/util/lua/lobject.h" +#include "sword25/util/lua/lopcodes.h" +#include "sword25/util/lua/lstate.h" +#include "sword25/util/lua/lstring.h" +#include "sword25/util/lua/lauxlib.h" #define pdep_reallocv(L,b,on,n,e) \ diff --git a/engines/sword25/util/pluto/pptest.cpp b/engines/sword25/util/pluto/pptest.cpp deleted file mode 100644 index 1bfecf2b75..0000000000 --- a/engines/sword25/util/pluto/pptest.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* $Id$ */ - -#include <stdio.h> -#include <stdlib.h> - -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" - -static int LUAF_createludata(lua_State *L) -{ - lua_pushlightuserdata(L, (void*)321); - return 1; -} - -/* A userdata that may be literally persisted */ -static int LUAF_boxinteger(lua_State *L) -{ - /* num */ - int* ptr = lua_newuserdata(L, sizeof(int)); - /* num udata */ - *ptr = luaL_checkint(L, 1); - lua_newtable(L); - /* num udata mt */ - lua_pushstring(L, "__persist"); - /* num udata mt "__persist" */ - lua_pushboolean(L, 1); - /* num udata mt "__persist" true */ - lua_rawset(L, 3); - /* num udata mt */ - lua_setmetatable(L, 2); - /* num udata */ - return 1; -} - -static int LUAF_boxboolean(lua_State *L) -{ - /* bool */ - char* ptr = lua_newuserdata(L, sizeof(char)); - /* bool udata */ - *ptr = lua_toboolean(L, 1); - lua_newtable(L); - /* num udata mt */ - lua_pushstring(L, "__persist"); - /* num udata mt "__persist" */ - lua_getglobal(L, "booleanpersist"); - /* num udata mt "__persist" booleanpersist */ - lua_rawset(L, 3); - /* num udata mt */ - lua_setmetatable(L, 2); - /* num udata */ - return 1; -} - -static int LUAF_unboxboolean(lua_State *L) -{ - /* udata */ - lua_pushboolean(L, *(char*)lua_touserdata(L, 1)); - /* udata bool */ - return 1; -} - -static int LUAF_onerror(lua_State *L) -{ - - const char* str = 0; - if(lua_gettop(L) != 0) - { - str = lua_tostring(L, -1); - printf("%s\n",str); - } - return 0; -} - -int main() -{ - lua_State* L = lua_open(); - - luaL_openlibs(L); - lua_settop(L, 0); - - lua_register(L, "createludata", LUAF_createludata); - lua_register(L, "boxinteger", LUAF_boxinteger); - lua_register(L, "boxboolean", LUAF_boxboolean); - lua_register(L, "unboxboolean", LUAF_unboxboolean); - lua_register(L, "onerror", LUAF_onerror); - - lua_pushcfunction(L, LUAF_onerror); - luaL_loadfile(L, "pptest.lua"); - lua_pcall(L,0,0,1); - - lua_close(L); - - return 0; -} diff --git a/engines/sword25/util/pluto/pptest.lua b/engines/sword25/util/pluto/pptest.lua deleted file mode 100644 index 144da3ee80..0000000000 --- a/engines/sword25/util/pluto/pptest.lua +++ /dev/null @@ -1,168 +0,0 @@ --- $Id$ - -require "pluto" - -permtable = { 1234 } - -perms = { [coroutine.yield] = 1, [permtable] = 2 } - -twithmt = {} -setmetatable( twithmt, { __call = function() return 21 end } ) - -function testfenv() - return abc -end - -setfenv(testfenv, { abc = 456 }) - -function fa(i) - local ia = i + 1 - return fb(ia) -end - -function fb(i) - local ib = i + 1 - ib = ib + fc(ib) - return ib -end - -function fc(i) - local ic = i + 1 - coroutine.yield() - return ic*2 -end - -function func() - return 4 -end - -thr = coroutine.create(fa) -coroutine.resume(thr, 2) - -testtbl = { a = 2, [2] = 4 } - -function funcreturningclosure(n) - return function() - return n - end -end - -function nestedfunc(n) - return (function(m) return m+2 end)(n+3) -end - -testloopa = {} -testloopb = { testloopa = testloopa } -testloopa.testloopb = testloopb - -sharedref = {} -refa = {sharedref = sharedref} -refb = {sharedref = sharedref} - -sptable = { a = 3 } - -setmetatable(sptable, { - __persist = function(tbl) - local a = tbl.a - return function() - return { a = a+3 } - end - end -}) - -literaludata = boxinteger(71) - -function booleanpersist(udata) - local b = unboxboolean(udata) - return function() - return boxboolean(b) - end -end - -function makecounter() - local a = 0 - return { - inc = function() a = a + 1 end, - cur = function() return a end - } -end - -function uvinthreadfunc() - local a = 1 - local b = function() - a = a+1 - coroutine.yield() - a = a+1 - end - a = a+1 - b() - a = a+1 - return a -end - -uvinthread = coroutine.create(uvinthreadfunc) -coroutine.resume(uvinthread) - -niinmt = { a = 3 } -setmetatable(niinmt, {__newindex = function(key, val) end }) - - - - -local function GenerateObjects() - local Table = {} - - function Table:Func() - return { Table, self } - end - - function uvcycle() - return Table:Func() - end -end - -GenerateObjects() - - - -function debuginfo(foo) - foo = foo + foo - return debug.getlocal(1,1) -end - -rootobj = { - testfalse = false, - testtrue = true, - testseven = 7, - testfoobar = "foobar", - testfuncreturnsfour = func, - testnil = nil, - testthread = thr, - testperm = permtable, - testmt = twithmt, - testtbl = testtbl, - testfenv = testfenv, - testclosure = funcreturningclosure(11), - testnilclosure = funcreturningclosure(nil), - testnest = nestedfunc, - testludata = createludata(), - testlooptable = testloopa, - testsharedrefa = refa, - testsharedrefb = refb, - testsptable = sptable, - testliteraludata = literaludata, - testspudata1 = boxboolean(true), - testspudata2 = boxboolean(false), - testsharedupval = makecounter(), - testuvinthread = uvinthread, - testniinmt = niinmt, - testuvcycle = uvcycle, - testdebuginfo = debuginfo -} - -buf = pluto.persist(perms, rootobj) - -onerror() -outfile = io.open("test.plh", "wb") -outfile:write(buf) -outfile:close() diff --git a/engines/sword25/util/pluto/puptest.cpp b/engines/sword25/util/pluto/puptest.cpp deleted file mode 100644 index e9aa7ea305..0000000000 --- a/engines/sword25/util/pluto/puptest.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* $Id$ */ - -#include <stdio.h> -#include <stdlib.h> - -#include "lua.h" -#include "lualib.h" -#include "lauxlib.h" - -static int LUAF_checkludata(lua_State *L) -{ - lua_pushboolean(L, lua_touserdata(L, -1) == (void*)321); - return 1; -} - -static int LUAF_unboxinteger(lua_State *L) -{ - lua_pushnumber(L, *((int*)lua_touserdata(L, -1))); - return 1; -} - -static int LUAF_unboxboolean(lua_State *L) -{ - /* udata */ - lua_pushboolean(L, *(char*)lua_touserdata(L, 1)); - /* udata bool */ - return 1; -} - -static int LUAF_boxboolean(lua_State *L) -{ - /* bool */ - char* ptr = lua_newuserdata(L, sizeof(char)); - /* bool udata */ - *ptr = lua_toboolean(L, 1); - lua_newtable(L); - /* num udata mt */ - lua_pushstring(L, "__persist"); - /* num udata mt "__persist" */ - lua_getglobal(L, "booleanpersist"); - /* num udata mt "__persist" booleanpersist */ - lua_rawset(L, 3); - /* num udata mt */ - lua_setmetatable(L, 2); - /* num udata */ - return 1; -} - -static int LUAF_onerror(lua_State *L) -{ - - const char* str = 0; - if(lua_gettop(L) != 0) - { - str = lua_tostring(L, -1); - printf("%s\n",str); - } - return 0; -} - -int main() -{ - lua_State* L = lua_open(); - - luaL_openlibs(L); - lua_settop(L, 0); - - lua_register(L, "checkludata", LUAF_checkludata); - lua_register(L, "unboxinteger", LUAF_unboxinteger); - lua_register(L, "boxboolean", LUAF_boxboolean); - lua_register(L, "unboxboolean", LUAF_unboxboolean); - lua_register(L, "onerror", LUAF_onerror); - - lua_pushcfunction(L, LUAF_onerror); - luaL_loadfile(L, "puptest.lua"); - lua_pcall(L,0,0,1); - - lua_close(L); - - return 0; -} diff --git a/engines/sword25/util/pluto/puptest.lua b/engines/sword25/util/pluto/puptest.lua deleted file mode 100644 index e5ccdd64bd..0000000000 --- a/engines/sword25/util/pluto/puptest.lua +++ /dev/null @@ -1,93 +0,0 @@ --- $Id$ - -require "pluto" - -permtable = { 1234 } - -perms = { [1] = coroutine.yield, [2] = permtable } - -function testcounter(counter) - local a = counter.cur() - counter.inc() - return counter.cur() == a+1 -end - -function testuvinthread(func) - local success, result = coroutine.resume(func) - return success and result == 5 -end - - -function test(rootobj) - local passed = 0 - local total = 0 - local dotest = function(name,cond) - total = total+1 - if cond then - print(name, " PASSED") - passed = passed + 1 - else - print(name, "* FAILED") - end - end - - - dotest("Boolean FALSE ", rootobj.testfalse == false) - dotest("Boolean TRUE ", rootobj.testtrue == true) - dotest("Number 7 ", rootobj.testseven == 7) - dotest("String 'foobar' ", rootobj.testfoobar == "foobar") - dotest("Func returning 4 ", rootobj.testfuncreturnsfour() == 4) - dotest("Nil value ", rootobj.testnil == nil) - dotest("Thread resume ", coroutine.resume(rootobj.testthread) == true,14) - dotest("Table ", rootobj.testtbl.a == 2 and rootobj.testtbl[2] == 4); - dotest("Permanent table ", rootobj.testperm == permtable) - dotest("Table metatable ", rootobj.testmt() == 21) - dotest("Function env ", rootobj.testfenv() == 456) - dotest("Lua closure ", rootobj.testclosure() == 11) - dotest("Nil in closure ", rootobj.testnilclosure() == nil) - dotest("Nested func ", rootobj.testnest(1) == 6) - dotest("Light userdata ", checkludata(rootobj.testludata)) - dotest("Looped tables ", - rootobj.testlooptable.testloopb.testloopa == - rootobj.testlooptable) - dotest("Shared reference ", rootobj.testsharedrefa.sharedref == - rootobj.testsharedrefb.sharedref) - dotest("Identical tables ", rootobj.testsharedrefa ~= - rootobj.testsharedrefb) - dotest("Table special persist", rootobj.testsptable.a == 6) - dotest("Udata literal persist", - unboxinteger(rootobj.testliteraludata) == 71) - dotest("Udata special persist", - unboxboolean(rootobj.testspudata1) == true and - unboxboolean(rootobj.testspudata2) == false) - dotest("Shared upvalues ", - testcounter(rootobj.testsharedupval)) - dotest("Open upvalues ", - testuvinthread(rootobj.testuvinthread)) - dotest("Upvalue cycles ", - rootobj.testuvcycle()[1] == rootobj.testuvcycle()[2]) - dotest("__newindex metamethod", rootobj.testniinmt.a == 3) - dotest("Debug info ", (rootobj.testdebuginfo(2)) == "foo") - print() - if passed == total then - print("All tests passed.") - else - print(passed .. "/" .. total .. " tests passed.") - end -end - -infile, err = io.open("test.plh", "rb") -if infile == nil then - error("While opening: " .. (err or "no error")) -end - -buf, err = infile:read("*a") -if buf == nil then - error("While reading: " .. (err or "no error")) -end - -infile:close() - -rootobj = pluto.unpersist(perms, buf) - -test(rootobj) |