From 03c4b7a240d53b36c86aea564fb8ae0b0a747604 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 15:09:19 +0200 Subject: WINTERMUTE: Introduce TransformStruct and FloatPoint; add operators to Point32 --- engines/wintermute/graphics/transform_struct.cpp | 127 +++++++++++++++++++++++ engines/wintermute/graphics/transform_struct.h | 87 ++++++++++++++++ engines/wintermute/math/floatrect.h | 52 ++++++++++ engines/wintermute/math/rect32.h | 26 ++++- engines/wintermute/module.mk | 1 + 5 files changed, 292 insertions(+), 1 deletion(-) create mode 100644 engines/wintermute/graphics/transform_struct.cpp create mode 100644 engines/wintermute/graphics/transform_struct.h create mode 100644 engines/wintermute/math/floatrect.h (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_struct.cpp b/engines/wintermute/graphics/transform_struct.cpp new file mode 100644 index 0000000000..9a11aa9fdd --- /dev/null +++ b/engines/wintermute/graphics/transform_struct.cpp @@ -0,0 +1,127 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "engines/wintermute/graphics/transform_struct.h" +#include "engines/wintermute/graphics/transparent_surface.h" + +namespace Wintermute { +void TransformStruct::init(Point32 zoom, uint32 angle, Point32 hotspot, bool alphaDisable, TSpriteBlendMode blendMode, uint32 rgbaMod, bool mirrorX, bool mirrorY, Point32 offset) { + _zoom = zoom; + _angle = angle; + _hotspot = hotspot; + _blendMode = blendMode; + _rgbaMod = rgbaMod; + _alphaDisable = alphaDisable; + _flip = 0; + _flip += TransparentSurface::FLIP_H * mirrorX; + _flip += TransparentSurface::FLIP_V * mirrorY; + _offset = offset; +} + + +TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX, int32 hotspotY, TSpriteBlendMode blendMode, uint32 rgbaMod, bool mirrorX, bool mirrorY, int32 offsetX, int32 offsetY) { + init(Point32(zoomX, zoomY), + angle, + Point32(hotspotX, hotspotY), + false, + blendMode, + rgbaMod, + mirrorX, mirrorY, + Point32(offsetX, offsetY)); +} + +TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, TSpriteBlendMode blendMode, uint32 rgbaMod, bool mirrorX, bool mirrorY) { + init(Point32(zoomX, zoomY), + DEFAULT_ANGLE, + Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), + false, + blendMode, + rgbaMod, + mirrorX, + mirrorY, + Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); +} + +TransformStruct::TransformStruct(int32 zoom, TSpriteBlendMode blendMode, uint32 rgbaMod, bool mirrorX, bool mirrorY) { + init(Point32(zoom, zoom), + DEFAULT_ANGLE, + Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), + false, + blendMode, + rgbaMod, + mirrorX, mirrorY, + Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); +} + +TransformStruct::TransformStruct(int32 zoom, bool mirrorX, bool mirrorY) { + init(Point32(zoom, zoom), + DEFAULT_ANGLE, + Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), + true, + BLEND_NORMAL, + DEFAULT_RGBAMOD, + mirrorX, mirrorY, + Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); +} + +TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX, int32 hotspotY) { + init(Point32(zoomX, zoomY), + angle, + Point32(hotspotX, hotspotY), + true, + BLEND_NORMAL, + DEFAULT_RGBAMOD, + false, false, + Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); +} + +TransformStruct::TransformStruct(int32 zoom) { + init(Point32(zoom, zoom), + DEFAULT_ANGLE, + Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), + true, + BLEND_NORMAL, + DEFAULT_RGBAMOD, + false, false, + Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); +} + +TransformStruct::TransformStruct() { + init(Point32(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y), + DEFAULT_ANGLE, + Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), + true, + BLEND_NORMAL, + DEFAULT_RGBAMOD, + false, false, + Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); +} + +bool TransformStruct::mirrorX() const { + return (bool)(_flip & TransparentSurface::FLIP_H); +} + +bool TransformStruct::mirrorY() const { + return (bool)(_flip & TransparentSurface::FLIP_V); +} + +} diff --git a/engines/wintermute/graphics/transform_struct.h b/engines/wintermute/graphics/transform_struct.h new file mode 100644 index 0000000000..9a28a48bd1 --- /dev/null +++ b/engines/wintermute/graphics/transform_struct.h @@ -0,0 +1,87 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GRAPHICS_TRANSFORM_STRUCT_H +#define GRAPHICS_TRANSFORM_STRUCT_H + +#include "engines/wintermute/math/rect32.h" +#include "engines/wintermute/dctypes.h" + +#define DEFAULT_ZOOM_X 100 +#define DEFAULT_ZOOM_Y 100 +#define DEFAULT_RGBAMOD 0xFFFFFFFF +#define DEFAULT_HOTSPOT_X 0 +#define DEFAULT_HOTSPOT_Y 0 +#define DEFAULT_OFFSET_X 0 +#define DEFAULT_OFFSET_Y 0 +#define DEFAULT_ANGLE 0 + +namespace Wintermute { +/** + * Contains all the required information that define a transform. + * Same source sprite + same TransformStruct = Same resulting sprite. + * Has a number of overloaded constructors to accomodate various argument lists. + */ +struct TransformStruct { +private: + void init(Point32 zoom, uint32 angle, Point32 hotspot, bool alphaDisable, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX, bool mirrorY, Point32 offset); + +public: + TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX, int32 hotspotY, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX = false, bool mirrorY = false, int32 offsetX = 0, int32 offsetY = 0); + TransformStruct(int32 zoomX, int32 zoomY, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX = false, bool mirrorY = false); + TransformStruct(int32 zoom, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX, bool mirrorY); + TransformStruct(int32 zoom, bool mirrorX, bool mirrorY); + TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX = 0, int32 hotspotY = 0); + TransformStruct(int32 zoom); + TransformStruct(); + + Point32 _zoom; ///< Zoom; 100 = no zoom + Point32 _hotspot; ///< Position of the hotspot + uint32 _angle; ///< Rotation angle, in degrees + byte _flip; ///< Bitflag: see TransparentSurface::FLIP_XXX + bool _alphaDisable; + TSpriteBlendMode _blendMode; + uint32 _rgbaMod; ///< RGBa + Point32 _offset; + + bool mirrorX() const; + bool mirrorY() const; + + bool operator==(const TransformStruct &compare) const { + return (compare._angle == _angle && + compare._flip == _flip && + compare._zoom == _zoom && + compare._offset == _offset && + compare._alphaDisable == _alphaDisable && + compare._rgbaMod == _rgbaMod && + compare._blendMode == _blendMode + ); + } + + bool operator!=(const TransformStruct &compare) const { + return !(compare == *this); + } +}; + +} + +#endif diff --git a/engines/wintermute/math/floatrect.h b/engines/wintermute/math/floatrect.h new file mode 100644 index 0000000000..f8eb3827fd --- /dev/null +++ b/engines/wintermute/math/floatrect.h @@ -0,0 +1,52 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef WINTERMUTE_FLOATRECT_H +#define WINTERMUTE_FLOATRECT_H + +namespace Wintermute { + +struct FloatPoint { + float x; + float y; + FloatPoint() : x(0), y(0) {} + FloatPoint(float x1, float y1) : x(x1), y(y1) {} + bool operator==(const FloatPoint &p) const { return x == p.x && y == p.y; } + bool operator!=(const FloatPoint &p) const { return x != p.x || y != p.y; } + FloatPoint operator+(const FloatPoint &delta) const { return FloatPoint (x + delta.x, y + delta.y); } + FloatPoint operator-(const FloatPoint &delta) const { return FloatPoint (x - delta.x, y - delta.y); } + + FloatPoint& operator+=(const FloatPoint &delta) { + x += delta.x; + y += delta.y; + return *this; + } + FloatPoint& operator-=(const FloatPoint &delta) { + x -= delta.x; + y -= delta.y; + return *this; + } +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/math/rect32.h b/engines/wintermute/math/rect32.h index 190c1135cf..6618a51e91 100644 --- a/engines/wintermute/math/rect32.h +++ b/engines/wintermute/math/rect32.h @@ -24,14 +24,38 @@ #define WINTERMUTE_RECT32_H #include "common/system.h" +#include "engines/wintermute/math/floatrect.h" namespace Wintermute { struct Point32 { int32 x; int32 y; -}; + Point32() : x(0), y(0) {} + Point32(int32 x1, int32 y1) : x(x1), y(y1) {} + bool operator==(const Point32 &p) const { return x == p.x && y == p.y; } + bool operator!=(const Point32 &p) const { return x != p.x || y != p.y; } + Point32 operator+(const Point32 &delta) const { return Point32(x + delta.x, y + delta.y); } + Point32 operator-(const Point32 &delta) const { return Point32(x - delta.x, y - delta.y); } + + Point32 &operator+=(const Point32 &delta) { + x += delta.x; + y += delta.y; + return *this; + } + Point32 &operator-=(const Point32 &delta) { + x -= delta.x; + y -= delta.y; + return *this; + } + + operator FloatPoint() { + return FloatPoint(x,y); + } + + +}; struct Rect32 { int32 top, left; ///< The point at the top left of the rectangle (part of the rect). int32 bottom, right; ///< The point at the bottom right of the rectangle (not part of the rect). diff --git a/engines/wintermute/module.mk b/engines/wintermute/module.mk index 32931bf05f..d1edced818 100644 --- a/engines/wintermute/module.mk +++ b/engines/wintermute/module.mk @@ -89,6 +89,7 @@ MODULE_OBJS := \ base/save_thumb_helper.o \ base/timer.o \ detection.o \ + graphics/transform_struct.o \ graphics/transparent_surface.o \ math/math_util.o \ math/matrix4.o \ -- cgit v1.2.3 From 3c0089e31e1392f38cfb0e13d7c4d395bad4f949 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 15:47:05 +0200 Subject: WINTERMUTE: Introduce TransformTools --- engines/wintermute/base/base_sub_frame.cpp | 11 ++++ engines/wintermute/graphics/transform_tools.cpp | 75 +++++++++++++++++++++++++ engines/wintermute/graphics/transform_tools.h | 47 ++++++++++++++++ engines/wintermute/math/floatpoint.h | 52 +++++++++++++++++ engines/wintermute/math/floatrect.h | 52 ----------------- engines/wintermute/math/rect32.h | 3 +- engines/wintermute/module.mk | 1 + 7 files changed, 188 insertions(+), 53 deletions(-) create mode 100644 engines/wintermute/graphics/transform_tools.cpp create mode 100644 engines/wintermute/graphics/transform_tools.h create mode 100644 engines/wintermute/math/floatpoint.h delete mode 100644 engines/wintermute/math/floatrect.h (limited to 'engines') diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index d93cf667f1..d9620d3939 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -38,6 +38,8 @@ #include "engines/wintermute/base/gfx/base_renderer.h" #include "engines/wintermute/base/scriptables/script_value.h" #include "engines/wintermute/base/scriptables/script_stack.h" +#include "engines/wintermute/graphics/transform_tools.h" +#include "engines/wintermute/graphics/transform_struct.h" namespace Wintermute { @@ -256,6 +258,15 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl } if (rotate != 0.0f) { + Point32 boxOffset, rotatedHotspot, hotspotOffset, newOrigin; + Point32 origin(x, y); + Rect32 oldRect = getRect(); + Point32 newHotspot; + TransformStruct transform = TransformStruct(zoomX, zoomY, rotate, _hotspotX, _hotspotY, blendMode, alpha, _mirrorX, _mirrorY, 0, 0); + Rect32 newRect = TransformTools::newRect (oldRect, transform, &newHotspot); + newOrigin = origin - newHotspot; + // When the transform functions are refactored to use TransformStruct this will be like: + // res = _surface->displayTransform(newOrigin.x, newOrigin.y, oldRect, newRect, transformStruct); res = _surface->displayTransform((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _hotspotX, _hotspotY, getRect(), zoomX, zoomY, alpha, rotate, blendMode, _mirrorX, _mirrorY); } else { if (zoomX == 100 && zoomY == 100) { diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp new file mode 100644 index 0000000000..2390b86391 --- /dev/null +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -0,0 +1,75 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + + +#include "engines/wintermute/graphics/transform_tools.h" +#include + +namespace Wintermute { + + FloatPoint TransformTools::transformPoint(FloatPoint point, float rotate, Point32 zoom, bool mirrorX, bool mirrorY) { + /* + * Returns the coordinates for a point after rotation + */ + float rotateRad = rotate * M_PI / 180; + FloatPoint newPoint; + newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/100; + newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/100; + if (mirrorX) newPoint.x *= -1; + if (mirrorY) newPoint.y *= -1; + /* + * I apply the textbook formula, but first I reverse the Y-axis, otherwise + * I'd be performing a rotation in the wrong direction + */ + return newPoint; + } + + Rect32 TransformTools::newRect (Rect32 oldRect, TransformStruct transform, Point32 *newHotspot) { + Point32 nw(oldRect.left, oldRect.top); + Point32 ne(oldRect.right, oldRect.top); + Point32 sw(oldRect.left, oldRect.bottom); + Point32 se(oldRect.right, oldRect.bottom); + + FloatPoint nw1, ne1, sw1, se1; + + nw1 = transformPoint(nw - transform._hotspot, transform._angle, transform._zoom); + ne1 = transformPoint(ne - transform._hotspot, transform._angle, transform._zoom); + sw1 = transformPoint(sw - transform._hotspot, transform._angle, transform._zoom); + se1 = transformPoint(se - transform._hotspot, transform._angle, transform._zoom); + + float top = MIN(nw1.y, MIN(ne1.y, MIN(sw1.y, se1.y))); + float bottom = MAX(nw1.y, MAX(ne1.y, MAX(sw1.y, se1.y))); + float left = MIN(nw1.x, MIN(ne1.x, MIN(sw1.x, se1.x))); + float right = MAX(nw1.x, MAX(ne1.x, MAX(sw1.x, se1.x))); + + Rect32 res; + newHotspot->y = -floor(top); + newHotspot->x = -floor(left); + + res.top = floor(top) + transform._hotspot.y; + res.bottom = ceil(bottom) + transform._hotspot.y; + res.left = floor(left) + transform._hotspot.x; + res.right = ceil(right) + transform._hotspot.x; + + return res; + } +} diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h new file mode 100644 index 0000000000..fbc0653e64 --- /dev/null +++ b/engines/wintermute/graphics/transform_tools.h @@ -0,0 +1,47 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef WINTERMUTE_TRANSFORMTOOLS_H +#define WINTERMUTE_TRANSFORMTOOLS_H + +#include "engines/wintermute/math/rect32.h" +#include "engines/wintermute/math/floatpoint.h" +#include "engines/wintermute/graphics/transform_struct.h" + +namespace Wintermute { +class TransformTools { +public: + /** + * Basic transform (scale + rotate) for a single point + */ + static FloatPoint transformPoint(FloatPoint point, float rotate, Point32 zoom, bool mirrorX = false, bool mirrorY = false); + + /** + * Takes a rectangle, a transform and a pointer to a point, "newHotspot". + * In return you get the smallest rect that can contain the transformed sprite + * and, as a side-effect, "newHotspot" will tell you where the hotspot will + * have ended up in the new rect, for centering. + */ + static Rect32 newRect (Rect32 oldRect, TransformStruct transform, Point32 *newHotspot); +}; +} // end of namespace Wintermute +#endif diff --git a/engines/wintermute/math/floatpoint.h b/engines/wintermute/math/floatpoint.h new file mode 100644 index 0000000000..bf194d8437 --- /dev/null +++ b/engines/wintermute/math/floatpoint.h @@ -0,0 +1,52 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef WINTERMUTE_FLOATPOINT_H +#define WINTERMUTE_FLOATPOINT_H + +namespace Wintermute { + +struct FloatPoint { + float x; + float y; + FloatPoint() : x(0), y(0) {} + FloatPoint(float x1, float y1) : x(x1), y(y1) {} + bool operator==(const FloatPoint &p) const { return x == p.x && y == p.y; } + bool operator!=(const FloatPoint &p) const { return x != p.x || y != p.y; } + FloatPoint operator+(const FloatPoint &delta) const { return FloatPoint (x + delta.x, y + delta.y); } + FloatPoint operator-(const FloatPoint &delta) const { return FloatPoint (x - delta.x, y - delta.y); } + + FloatPoint& operator+=(const FloatPoint &delta) { + x += delta.x; + y += delta.y; + return *this; + } + FloatPoint& operator-=(const FloatPoint &delta) { + x -= delta.x; + y -= delta.y; + return *this; + } +}; + +} // end of namespace Wintermute + +#endif diff --git a/engines/wintermute/math/floatrect.h b/engines/wintermute/math/floatrect.h deleted file mode 100644 index f8eb3827fd..0000000000 --- a/engines/wintermute/math/floatrect.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef WINTERMUTE_FLOATRECT_H -#define WINTERMUTE_FLOATRECT_H - -namespace Wintermute { - -struct FloatPoint { - float x; - float y; - FloatPoint() : x(0), y(0) {} - FloatPoint(float x1, float y1) : x(x1), y(y1) {} - bool operator==(const FloatPoint &p) const { return x == p.x && y == p.y; } - bool operator!=(const FloatPoint &p) const { return x != p.x || y != p.y; } - FloatPoint operator+(const FloatPoint &delta) const { return FloatPoint (x + delta.x, y + delta.y); } - FloatPoint operator-(const FloatPoint &delta) const { return FloatPoint (x - delta.x, y - delta.y); } - - FloatPoint& operator+=(const FloatPoint &delta) { - x += delta.x; - y += delta.y; - return *this; - } - FloatPoint& operator-=(const FloatPoint &delta) { - x -= delta.x; - y -= delta.y; - return *this; - } -}; - -} // end of namespace Wintermute - -#endif diff --git a/engines/wintermute/math/rect32.h b/engines/wintermute/math/rect32.h index 6618a51e91..d44655311c 100644 --- a/engines/wintermute/math/rect32.h +++ b/engines/wintermute/math/rect32.h @@ -24,7 +24,8 @@ #define WINTERMUTE_RECT32_H #include "common/system.h" -#include "engines/wintermute/math/floatrect.h" +#include "engines/wintermute/math/floatpoint.h" +#include "common/rect.h" namespace Wintermute { diff --git a/engines/wintermute/module.mk b/engines/wintermute/module.mk index d1edced818..95f9ba2ffb 100644 --- a/engines/wintermute/module.mk +++ b/engines/wintermute/module.mk @@ -90,6 +90,7 @@ MODULE_OBJS := \ base/timer.o \ detection.o \ graphics/transform_struct.o \ + graphics/transform_tools.o \ graphics/transparent_surface.o \ math/math_util.o \ math/matrix4.o \ -- cgit v1.2.3 From 66ba2ea4558bab4583a7d7bb27e1e254c34f579f Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 16:16:26 +0200 Subject: WINTERMUTE: Refactor some bits to use TransformStruct --- engines/wintermute/base/base_sub_frame.cpp | 4 +- engines/wintermute/base/gfx/base_surface.cpp | 4 +- engines/wintermute/base/gfx/base_surface.h | 3 +- .../base/gfx/osystem/base_surface_osystem.cpp | 75 ++++++++++++++-------- .../base/gfx/osystem/base_surface_osystem.h | 5 +- 5 files changed, 57 insertions(+), 34 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index d9620d3939..b51b723f61 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -265,9 +265,7 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl TransformStruct transform = TransformStruct(zoomX, zoomY, rotate, _hotspotX, _hotspotY, blendMode, alpha, _mirrorX, _mirrorY, 0, 0); Rect32 newRect = TransformTools::newRect (oldRect, transform, &newHotspot); newOrigin = origin - newHotspot; - // When the transform functions are refactored to use TransformStruct this will be like: - // res = _surface->displayTransform(newOrigin.x, newOrigin.y, oldRect, newRect, transformStruct); - res = _surface->displayTransform((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), _hotspotX, _hotspotY, getRect(), zoomX, zoomY, alpha, rotate, blendMode, _mirrorX, _mirrorY); + res = _surface->displayTransform(newOrigin.x, newOrigin.y, oldRect, newRect, transform); } else { if (zoomX == 100 && zoomY == 100) { res = _surface->displayTrans(x - _hotspotX, y - _hotspotY, getRect(), alpha, blendMode, _mirrorX, _mirrorY); diff --git a/engines/wintermute/base/gfx/base_surface.cpp b/engines/wintermute/base/gfx/base_surface.cpp index 2002463ea4..7457e34826 100644 --- a/engines/wintermute/base/gfx/base_surface.cpp +++ b/engines/wintermute/base/gfx/base_surface.cpp @@ -75,8 +75,8 @@ bool BaseSurface::displayHalfTrans(int x, int y, Rect32 rect) { } ////////////////////////////////////////////////////////////////////////// -bool BaseSurface::displayTransform(int x, int y, int hotX, int hotY, Rect32 rect, float zoomX, float zoomY, uint32 alpha, float rotate, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { - return displayTransZoom(x, y, rect, zoomX, zoomY, alpha, blendMode, mirrorX, mirrorY); +bool BaseSurface::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) { + return displayTransform(x, y, rect, newRect, transform); } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/base/gfx/base_surface.h b/engines/wintermute/base/gfx/base_surface.h index b83efa0bb8..be7a5c13ca 100644 --- a/engines/wintermute/base/gfx/base_surface.h +++ b/engines/wintermute/base/gfx/base_surface.h @@ -32,6 +32,7 @@ #include "engines/wintermute/base/base.h" #include "engines/wintermute/math/rect32.h" #include "graphics/surface.h" +#include "engines/wintermute/graphics/transform_struct.h" namespace Wintermute { @@ -53,8 +54,8 @@ public: virtual bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) = 0; virtual bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; + virtual bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) = 0; virtual bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; - virtual bool displayTransform(int x, int y, int hotX, int hotY, Rect32 rect, float zoomX, float zoomY, uint32 alpha, float rotate, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) = 0; virtual bool restore(); virtual bool create(const Common::String &filename, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime = -1, bool keepLoaded = false) = 0; diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index 0572ef2f6e..5a12ad94e4 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -52,6 +52,7 @@ BaseSurfaceOSystem::BaseSurfaceOSystem(BaseGame *inGame) : BaseSurface(inGame) { _lockPixels = nullptr; _lockPitch = 0; _loaded = false; + _rotation = 0; } ////////////////////////////////////////////////////////////////////////// @@ -319,39 +320,56 @@ bool BaseSurfaceOSystem::endPixelOp() { ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { - return drawSprite(x, y, &rect, 100, 100, 0xFFFFFFFF, true, blendMode, mirrorX, mirrorY); + _rotation = 0; + return drawSprite(x, y, &rect, nullptr, TransformStruct(100, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTrans(int x, int y, Rect32 rect, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { - return drawSprite(x, y, &rect, 100, 100, alpha, false, blendMode, mirrorX, mirrorY); + _rotation = 0; + return drawSprite(x, y, &rect, nullptr, TransformStruct(100, blendMode, 0xFFFFFFFF, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTransOffset(int x, int y, Rect32 rect, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX, int offsetY) { - return drawSprite(x, y, &rect, 100, 100, alpha, false, blendMode, mirrorX, mirrorY, offsetX, offsetY); + _rotation = 0; + return drawSprite(x, y, &rect, nullptr, TransformStruct(100, 100, 0, 0, 0, blendMode, alpha, mirrorX, mirrorY, offsetX, offsetY)); } ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { - return drawSprite(x, y, &rect, zoomX, zoomY, alpha, false, blendMode, mirrorX, mirrorY); + _rotation = 0; + return drawSprite(x, y, &rect, nullptr, TransformStruct(zoomX, zoomY, blendMode, alpha, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha, bool transparent, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { - return drawSprite(x, y, &rect, zoomX, zoomY, alpha, !transparent, blendMode, mirrorX, mirrorY); + _rotation = 0; + TransformStruct transform; + if (transparent) { + transform = TransformStruct(zoomX, zoomY, 0, 0, 0, blendMode, alpha, mirrorX, mirrorY); + } else { + transform = TransformStruct(zoomX, zoomY, mirrorX, mirrorY); + } + return drawSprite(x, y, &rect, nullptr, transform); } ////////////////////////////////////////////////////////////////////////// -bool BaseSurfaceOSystem::displayTransform(int x, int y, int hotX, int hotY, Rect32 rect, float zoomX, float zoomY, uint32 alpha, float rotate, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { - return drawSprite(x, y, &rect, zoomX, zoomY, alpha, false, blendMode, mirrorX, mirrorY); +bool BaseSurfaceOSystem::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) { + _rotation = (uint32)transform._angle; + if (transform._angle < 0.0f) { + warning("Negative rotation: %f %d", transform._angle, _rotation); + _rotation = (uint32)(360.0f + transform._angle); + warning("Negative post rotation: %f %d", transform._angle, _rotation); + } + return drawSprite(x, y, &rect, &newRect, transform); } ////////////////////////////////////////////////////////////////////////// -bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, float zoomY, uint32 alpha, bool alphaDisable, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX, int offsetY) { +bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, TransformStruct transform) { BaseRenderOSystem *renderer = static_cast(_gameRef->_renderer); if (!_loaded) { @@ -359,13 +377,13 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, flo } if (renderer->_forceAlphaColor != 0) { - alpha = renderer->_forceAlphaColor; + transform._rgbaMod = renderer->_forceAlphaColor; } - byte r = RGBCOLGetR(alpha); - byte g = RGBCOLGetG(alpha); - byte b = RGBCOLGetB(alpha); - byte a = RGBCOLGetA(alpha); + byte r = RGBCOLGetR(transform._rgbaMod); + byte g = RGBCOLGetG(transform._rgbaMod); + byte b = RGBCOLGetB(transform._rgbaMod); + byte a = RGBCOLGetA(transform._rgbaMod); renderer->setAlphaMod(a); renderer->setColorMod(r, g, b); @@ -386,8 +404,8 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, flo srcRect.setHeight(rect->bottom - rect->top); Common::Rect position; - position.left = x + offsetX; - position.top = y + offsetY; + position.left = x + transform._offset.x; + position.top = y + transform._offset.y; // Crop off-by-ones: if (position.left == -1) { @@ -396,30 +414,35 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, float zoomX, flo if (position.top == -1) { position.top = 0; // TODO: Something is wrong } - - position.setWidth((int16)((float)srcRect.width() * zoomX / 100.f)); - position.setHeight((int16)((float)srcRect.height() * zoomX / 100.f)); - + if (newRect) { + position.top = y; + position.left = x; + position.right = x + (newRect->right - newRect->left); + position.bottom = y + (newRect->top - newRect->bottom); + position.setWidth(newRect->right - newRect->left); + position.setHeight(newRect->bottom - newRect->top); + } else { + position.setWidth((int16)((float)srcRect.width() * transform._zoom.x / 100.f)); + position.setHeight((int16)((float)srcRect.height() * transform._zoom.y / 100.f)); + } renderer->modTargetRect(&position); - /* position.left += offsetX; - position.top += offsetY;*/ - // TODO: This actually requires us to have the SAME source-offsets every time, // But no checking is in place for that yet. // TODO: Optimize by not doing alpha-blits if we lack or disable alpha bool hasAlpha; - if (_hasAlpha && !alphaDisable) { + if (_hasAlpha && !transform._alphaDisable) { hasAlpha = true; } else { hasAlpha = false; } - if (alphaDisable) { + if (transform._alphaDisable) { warning("BaseSurfaceOSystem::drawSprite - AlphaDisable ignored"); } - - renderer->drawSurface(this, _surface, &srcRect, &position, mirrorX, mirrorY, !hasAlpha); + bool mirrorX = transform._flip && TransparentSurface::FLIP_H; + bool mirrorY = transform._flip && TransparentSurface::FLIP_V; + renderer->drawSurface(this, _surface, &srcRect, &position, mirrorX, mirrorY, transform._alphaDisable); return STATUS_OK; } diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h index 9091ec65b1..b6978d50e4 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h @@ -56,7 +56,7 @@ public: bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override; bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayTransform(int x, int y, int hotX, int hotY, Rect32 Rect, float zoomX, float zoomY, uint32 alpha, float rotate, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) override; bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) override; virtual bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false) override; /* static unsigned DLL_CALLCONV ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle); @@ -85,10 +85,11 @@ private: Graphics::Surface *_surface; bool _loaded; bool finishLoad(); - bool drawSprite(int x, int y, Rect32 *rect, float zoomX, float zoomY, uint32 alpha, bool alphaDisable, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX = 0, int offsetY = 0); + bool drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, TransformStruct transformStruct); void genAlphaMask(Graphics::Surface *surface); uint32 getPixelAt(Graphics::Surface *surface, int x, int y); + uint32 _rotation; bool _hasAlpha; void *_lockPixels; int _lockPitch; -- cgit v1.2.3 From 384dd8da7ef8cc7660607301c36b52645942faf0 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 16:27:51 +0200 Subject: WINTERMUTE: Bilinear scaling. Refactor scale(), factor out actual mapping algorithm, add bilinear scaling --- .../wintermute/graphics/transparent_surface.cpp | 129 +++++++++++++++++++-- engines/wintermute/graphics/transparent_surface.h | 12 +- 2 files changed, 128 insertions(+), 13 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index dcdcbf247e..f68259fb94 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -29,6 +29,117 @@ namespace Wintermute { +void TransparentSurface::nearestCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { + int srcW = srcRect.width(); + int srcH = srcRect.height(); + int dstW = dstRect.width(); + int dstH = dstRect.height(); + + assert(dstX >= 0 && dstX < dstW); + assert(dstY >= 0 && dstY < dstH); + + uint32 color; + + if (projX >= srcW || projX < 0 || projY >= srcH || projY < 0) { + color = 0; + } else { + color = READ_UINT32((const byte *)src->getBasePtr(projX, projY)); + } + + WRITE_UINT32((byte *)dst->getBasePtr(dstX, dstY), color); +} + +void TransparentSurface::bilinearCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { + + int srcW = srcRect.width(); + int srcH = srcRect.height(); + int dstW = dstRect.width(); + int dstH = dstRect.height(); + + assert(dstX >= 0 && dstX < dstW); + assert(dstY >= 0 && dstY < dstH); + + float x1 = floor(projX); + float x2 = ceil(projX); + float y1 = floor(projY); + float y2 = ceil(projY); + + uint32 Q11, Q12, Q21, Q22; + + if (x1 >= srcW || x1 < 0 || y1 >= srcH || y1 < 0) { + Q11 = 0; + } else { + Q11 = READ_UINT32((const byte *)src->getBasePtr(x1 + srcRect.left, y1 + srcRect.top)); + } + + if (x1 >= srcW || x1 < 0 || y2 >= srcH || y2 < 0) { + Q12 = 0; + } else { + Q12 = READ_UINT32((const byte *)src->getBasePtr(x1 + srcRect.left, y2 + srcRect.top)); + } + + if (x2 >= srcW || x2 < 0 || y1 >= srcH || y1 < 0) { + Q21 = 0; + } else { + Q21 = READ_UINT32((const byte *)src->getBasePtr(x2 + srcRect.left, y1 + srcRect.top)); + } + + if (x2 >= srcW || x2 < 0 || y2 >= srcH || y2 < 0) { + Q22 = 0; + } else { + Q22 = READ_UINT32((const byte *)src->getBasePtr(x2 + srcRect.left, y2 + srcRect.top)); + } + + byte *Q11s = (byte *)&Q11; + byte *Q12s = (byte *)&Q12; + byte *Q21s = (byte *)&Q21; + byte *Q22s = (byte *)&Q22; + + uint32 color; + byte *dest = (byte *)&color; + + float q11x = (x2 - projX); + float q11y = (y2 - projY); + float q21x = (projX - x1); + float q21y = (y2 - projY); + float q12x = (x2 - projX); + float q12y = (projY - y1); + float q22x = (projX - x1); + float q22y = (projY - y1); + + if (x1 == x2 && y1 == y2) { + for (int c = 0; c < 4; c++) { + dest[c] = ((float)Q11s[c]); + } + } else { + + if (x1 == x2) { + q11x = 0.5; + q12x = 0.5; + q21x = 0.5; + q22x = 0.5; + } else if (y1 == y2) { + q11y = 0.5; + q12y = 0.5; + q21y = 0.5; + q22y = 0.5; + } + + for (int c = 0; c < 4; c++) { + dest[c] = ( + ((float)Q11s[c]) * q11x * q11y + + ((float)Q21s[c]) * q21x * q21y + + ((float)Q12s[c]) * q12x * q12y + + ((float)Q22s[c]) * (1.0 - + q11x * q11y - + q21x * q21y - + q12x * q12y) + ); + } + } + WRITE_UINT32((byte *)dst->getBasePtr(dstX + dstRect.left, dstY + dstRect.top), color); +} + byte *TransparentSurface::_lookup = nullptr; void TransparentSurface::destroyLookup() { @@ -386,13 +497,7 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) const { Common::Rect srcRect(0, 0, (int16)w, (int16)h); Common::Rect dstRect(0, 0, (int16)newWidth, (int16)newHeight); - return scale(srcRect, dstRect); -} - -// Copied from clone2727's https://github.com/clone2727/scummvm/blob/pegasus/engines/pegasus/surface.cpp#L247 -TransparentSurface *TransparentSurface::scale(const Common::Rect &srcRect, const Common::Rect &dstRect) const { - // I'm doing simple linear scaling here - // dstRect(x, y) = srcRect(x * srcW / dstW, y * srcH / dstH); + TransparentSurface *target = new TransparentSurface(); assert(format.bytesPerPixel == 4); @@ -406,9 +511,13 @@ TransparentSurface *TransparentSurface::scale(const Common::Rect &srcRect, const for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { - uint32 color = READ_UINT32((const byte *)getBasePtr(x * srcW / dstW + srcRect.left, - y * srcH / dstH + srcRect.top)); - WRITE_UINT32((byte *)target->getBasePtr(x + dstRect.left, y + dstRect.top), color); + float projX = x / (float)dstW * srcW; + float projY = y / (float)dstH * srcH; + if (FAST_TRANSFORM) { + nearestCopy(projX, projY, x, y, srcRect, dstRect, this, target); + } else { + bilinearCopy(projX, projY, x, y, srcRect, dstRect, this, target); + } } } return target; diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index dc079a1fbc..0f48054d7c 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -24,6 +24,10 @@ #include "graphics/surface.h" + +#define FAST_TRANSFORM 0 + + /* * This code is based on Broken Sword 2.5 engine * @@ -49,6 +53,9 @@ struct TransparentSurface : public Graphics::Surface { void setColorKey(char r, char g, char b); void disableColorKey(); + static void bilinearCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); + static void nearestCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); + // Enums /** @brief The possible flipping parameters for the blit methode. @@ -102,9 +109,8 @@ struct TransparentSurface : public Graphics::Surface { uint color = BS_ARGB(255, 255, 255, 255), int width = -1, int height = -1); void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false); - // The following scale-code supports arbitrary scaling (i.e. no repeats of column 0 at the end of lines) - TransparentSurface *scale(uint16 newWidth, uint16 newHeight) const; - TransparentSurface *scale(const Common::Rect &srcRect, const Common::Rect &dstRect) const; + + TransparentSurface *scale (uint16 newWidth, uint16 newHeight) const; static byte *_lookup; static void destroyLookup(); private: -- cgit v1.2.3 From cced42a765cff0ad89490ebc0e70a7e00b8a2f4f Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 16:38:49 +0200 Subject: WINTERMUTE: Add cast op Common::Rect => Rect32 --- engines/wintermute/math/rect32.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines') diff --git a/engines/wintermute/math/rect32.h b/engines/wintermute/math/rect32.h index d44655311c..821df1880e 100644 --- a/engines/wintermute/math/rect32.h +++ b/engines/wintermute/math/rect32.h @@ -57,12 +57,14 @@ struct Point32 { }; + struct Rect32 { int32 top, left; ///< The point at the top left of the rectangle (part of the rect). int32 bottom, right; ///< The point at the bottom right of the rectangle (not part of the rect). Rect32() : top(0), left(0), bottom(0), right(0) {} Rect32(int32 w, int32 h) : top(0), left(0), bottom(h), right(w) {} + Rect32(Common::Rect rect) : top(rect.top), left(rect.left), bottom(rect.bottom), right(rect.right) {} Rect32(int32 x1, int32 y1, int32 x2, int32 y2) : top(y1), left(x1), bottom(y2), right(x2) { assert(isValidRect()); } -- cgit v1.2.3 From 58e096de97d7b8a0c09f5ac0bd6ff65853669a80 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 16:47:33 +0200 Subject: WINTERMUTE: Add rotation Add actual rotation code, make ticket-system transformStruct-aware --- .../base/gfx/osystem/base_render_osystem.cpp | 21 ++++---- .../base/gfx/osystem/base_render_osystem.h | 3 +- .../base/gfx/osystem/base_surface_osystem.cpp | 5 +- .../wintermute/base/gfx/osystem/render_ticket.cpp | 60 +++++++++++++--------- .../wintermute/base/gfx/osystem/render_ticket.h | 20 ++++---- .../wintermute/graphics/transparent_surface.cpp | 41 +++++++++++++++ engines/wintermute/graphics/transparent_surface.h | 3 +- 7 files changed, 102 insertions(+), 51 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index e1424cea87..e36eeb3ee6 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -256,7 +256,6 @@ void BaseRenderOSystem::fade(uint16 alpha) { return fadeToColor(0, 0, 0, dwAlpha); } - ////////////////////////////////////////////////////////////////////////// void BaseRenderOSystem::fadeToColor(byte r, byte g, byte b, byte a, Common::Rect *rect) { Common::Rect fillRect; @@ -286,7 +285,7 @@ void BaseRenderOSystem::fadeToColor(byte r, byte g, byte b, byte a, Common::Rect Common::Rect sizeRect(fillRect); sizeRect.translate(-fillRect.top, -fillRect.left); surf.fillRect(fillRect, col); - drawSurface(nullptr, &surf, &sizeRect, &fillRect, false, false); + drawSurface(nullptr, &surf, &sizeRect, &fillRect, TransformStruct()); surf.free(); //SDL_SetRenderDrawColor(_renderer, r, g, b, a); @@ -298,16 +297,18 @@ Graphics::PixelFormat BaseRenderOSystem::getPixelFormat() const { return _renderSurface->format; } -void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY, bool disableAlpha) { +void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, TransformStruct transform) { + if (_tempDisableDirtyRects || _disableDirtyRects) { - RenderTicket *ticket = new RenderTicket(owner, surf, srcRect, dstRect, mirrorX, mirrorY, disableAlpha); - ticket->_colorMod = _colorMod; + RenderTicket *ticket = new RenderTicket(owner, surf, srcRect, dstRect, transform); + ticket->_transform._rgbaMod = _colorMod; ticket->_wantsDraw = true; _renderQueue.push_back(ticket); _previousTicket = ticket; drawFromSurface(ticket); return; } + // Start searching from the beginning for the first and second items (since it's empty the first time around // then keep incrementing the start-position, to avoid comparing against already used tickets. if (_drawNum == 0 || _drawNum == 1) { @@ -320,12 +321,11 @@ void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::S } if (owner) { // Fade-tickets are owner-less - RenderTicket compare(owner, nullptr, srcRect, dstRect, mirrorX, mirrorY, disableAlpha); + RenderTicket compare(owner, nullptr, srcRect, dstRect, transform); compare._batchNum = _batchNum; if (_spriteBatch) { _batchNum++; } - compare._colorMod = _colorMod; RenderQueueIterator it; // Avoid calling end() and operator* every time, when potentially going through // LOTS of tickets. @@ -334,7 +334,6 @@ void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::S for (it = _lastAddedTicket; it != endIterator; ++it) { compareTicket = *it; if (*(compareTicket) == compare && compareTicket->_isValid) { - compareTicket->_colorMod = _colorMod; if (_disableDirtyRects) { drawFromSurface(compareTicket); } else { @@ -349,8 +348,7 @@ void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::S } } } - RenderTicket *ticket = new RenderTicket(owner, surf, srcRect, dstRect, mirrorX, mirrorY, disableAlpha); - ticket->_colorMod = _colorMod; + RenderTicket *ticket = new RenderTicket(owner, surf, srcRect, dstRect, transform); if (!_disableDirtyRects) { drawFromTicket(ticket); _previousTicket = ticket; @@ -390,7 +388,7 @@ void BaseRenderOSystem::repeatLastDraw(int offsetX, int offsetY, int numTimesX, dstRect.translate(offsetX, 0); } for (int j = (i == 0 ? 1 : 0); j < numTimesX; j++) { - drawSurface(origTicket->_owner, origTicket->getSurface(), &srcRect, &dstRect, false, false); + drawSurface(origTicket->_owner, origTicket->getSurface(), &srcRect, &dstRect, TransformStruct()); dstRect.translate(offsetX, 0); } dstRect.left = initLeft; @@ -535,7 +533,6 @@ void BaseRenderOSystem::drawTickets() { // convert from screen-coords to surface-coords. dstClip.translate(-offsetX, -offsetY); - _colorMod = ticket->_colorMod; drawFromSurface(ticket, &pos, &dstClip); _needsFlip = true; } diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.h b/engines/wintermute/base/gfx/osystem/base_render_osystem.h index 3cb0fa82a3..b3483f0efa 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.h @@ -33,6 +33,7 @@ #include "common/rect.h" #include "graphics/surface.h" #include "common/list.h" +#include "engines/wintermute/graphics/transform_struct.h" namespace Wintermute { class BaseSurfaceOSystem; @@ -80,7 +81,7 @@ public: virtual bool startSpriteBatch() override; virtual bool endSpriteBatch() override; void endSaveLoad(); - void drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY, bool disableAlpha = false) ; + void drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, TransformStruct transform); void repeatLastDraw(int offsetX, int offsetY, int numTimesX, int numTimesY); BaseSurface *createSurface() override; private: diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index 5a12ad94e4..e1348726b4 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -440,10 +440,7 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, if (transform._alphaDisable) { warning("BaseSurfaceOSystem::drawSprite - AlphaDisable ignored"); } - bool mirrorX = transform._flip && TransparentSurface::FLIP_H; - bool mirrorY = transform._flip && TransparentSurface::FLIP_V; - renderer->drawSurface(this, _surface, &srcRect, &position, mirrorX, mirrorY, transform._alphaDisable); - + renderer->drawSurface(this, _surface, &srcRect, &position, transform); return STATUS_OK; } diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index 36c5d7b740..23cf5c318e 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -26,22 +26,22 @@ * Copyright (c) 2011 Jan Nedoma */ -#include "engines/wintermute/graphics/transparent_surface.h" + #include "engines/wintermute/base/gfx/osystem/render_ticket.h" +#include "engines/wintermute/graphics/transform_tools.h" +#include "common/textconsole.h" namespace Wintermute { -RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, bool mirrorX, bool mirrorY, bool disableAlpha) : _owner(owner), -_srcRect(*srcRect), _dstRect(*dstRect), _drawNum(0), _isValid(true), _wantsDraw(true), _hasAlpha(!disableAlpha) { - _colorMod = 0; +RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, TransformStruct transform) : + _owner(owner), + _srcRect(*srcRect), + _dstRect(*dstRect), + _drawNum(0), + _isValid(true), + _wantsDraw(true), + _transform(transform) { _batchNum = 0; - _mirror = TransparentSurface::FLIP_NONE; - if (mirrorX) { - _mirror |= TransparentSurface::FLIP_V; - } - if (mirrorY) { - _mirror |= TransparentSurface::FLIP_H; - } if (surf) { _surface = new Graphics::Surface(); _surface->create((uint16)srcRect->width(), (uint16)srcRect->height(), surf->format); @@ -51,7 +51,14 @@ _srcRect(*srcRect), _dstRect(*dstRect), _drawNum(0), _isValid(true), _wantsDraw( memcpy(_surface->getBasePtr(0, i), surf->getBasePtr(srcRect->left, srcRect->top + i), srcRect->width() * _surface->format.bytesPerPixel); } // Then scale it if necessary - if (dstRect->width() != srcRect->width() || dstRect->height() != srcRect->height()) { + if (_transform._angle != 0) { + TransparentSurface src(*_surface, false); + Common::Rect srcRect_1(srcRect->left, srcRect->top, srcRect->right, srcRect->bottom); + Graphics::Surface *temp = src.rotate(srcRect_1, transform); + _surface->free(); + delete _surface; + _surface = temp; + } else if (dstRect->width() != srcRect->width() || dstRect->height() != srcRect->height()) { TransparentSurface src(*_surface, false); Graphics::Surface *temp = src.scale(dstRect->width(), dstRect->height()); _surface->free(); @@ -60,6 +67,14 @@ _srcRect(*srcRect), _dstRect(*dstRect), _drawNum(0), _isValid(true), _wantsDraw( } } else { _surface = nullptr; + + if (transform._angle != 0) { // Make sure comparison-tickets get the correct width + Rect32 dstRect; + Point32 newHotspot; + dstRect = TransformTools::newRect(_srcRect, transform, &newHotspot); + _dstRect.setWidth(dstRect.right-dstRect.left); + _dstRect.setHeight(dstRect.bottom-dstRect.top); + } } } @@ -70,32 +85,31 @@ RenderTicket::~RenderTicket() { } } -bool RenderTicket::operator==(RenderTicket &t) { +bool RenderTicket::operator==(const RenderTicket &t) const { if ((t._owner != _owner) || (t._batchNum != _batchNum) || - (t._hasAlpha != _hasAlpha) || - (t._mirror != _mirror) || - (t._colorMod != _colorMod) || + (t._transform != _transform) || (t._dstRect != _dstRect) || - (t._srcRect != _srcRect)) { + (t._srcRect != _srcRect) + ) { return false; } return true; } // Replacement for SDL2's SDL_RenderCopy -void RenderTicket::drawToSurface(Graphics::Surface *_targetSurface) { +void RenderTicket::drawToSurface(Graphics::Surface *_targetSurface) const { TransparentSurface src(*getSurface(), false); Common::Rect clipRect; clipRect.setWidth(getSurface()->w); clipRect.setHeight(getSurface()->h); - src._enableAlphaBlit = _hasAlpha; - src.blit(*_targetSurface, _dstRect.left, _dstRect.top, _mirror, &clipRect, _colorMod, clipRect.width(), clipRect.height()); + src._enableAlphaBlit = !_transform._alphaDisable; + src.blit(*_targetSurface, _dstRect.left, _dstRect.top, _transform._flip, &clipRect, _transform._rgbaMod, clipRect.width(), clipRect.height()); } -void RenderTicket::drawToSurface(Graphics::Surface *_targetSurface, Common::Rect *dstRect, Common::Rect *clipRect) { +void RenderTicket::drawToSurface(Graphics::Surface *_targetSurface, Common::Rect *dstRect, Common::Rect *clipRect) const { TransparentSurface src(*getSurface(), false); bool doDelete = false; if (!clipRect) { @@ -105,8 +119,8 @@ void RenderTicket::drawToSurface(Graphics::Surface *_targetSurface, Common::Rect clipRect->setHeight(getSurface()->h); } - src._enableAlphaBlit = _hasAlpha; - src.blit(*_targetSurface, dstRect->left, dstRect->top, _mirror, clipRect, _colorMod, clipRect->width(), clipRect->height()); + src._enableAlphaBlit = !_transform._alphaDisable; + src.blit(*_targetSurface, dstRect->left, dstRect->top, _transform._flip, clipRect, _transform._rgbaMod, clipRect->width(), clipRect->height()); if (doDelete) { delete clipRect; } diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.h b/engines/wintermute/base/gfx/osystem/render_ticket.h index 968b42b5e1..c294cb3082 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.h +++ b/engines/wintermute/base/gfx/osystem/render_ticket.h @@ -29,6 +29,7 @@ #ifndef WINTERMUTE_RENDER_TICKET_H #define WINTERMUTE_RENDER_TICKET_H +#include "engines/wintermute/graphics/transparent_surface.h" #include "graphics/surface.h" #include "common/rect.h" @@ -37,14 +38,14 @@ namespace Wintermute { class BaseSurfaceOSystem; class RenderTicket { public: - RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest, bool mirrorX = false, bool mirrorY = false, bool disableAlpha = false); - RenderTicket() : _isValid(true), _wantsDraw(false), _drawNum(0) {} + RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRest, TransformStruct transform); + RenderTicket() : _isValid(true), _wantsDraw(false), _drawNum(0), _transform(TransformStruct()) {} ~RenderTicket(); - const Graphics::Surface *getSurface() { return _surface; } + const Graphics::Surface *getSurface() const { return _surface; } // Non-dirty-rects: - void drawToSurface(Graphics::Surface *_targetSurface); + void drawToSurface(Graphics::Surface *_targetSurface) const; // Dirty-rects: - void drawToSurface(Graphics::Surface *_targetSurface, Common::Rect *dstRect, Common::Rect *clipRect); + void drawToSurface(Graphics::Surface *_targetSurface, Common::Rect *dstRect, Common::Rect *clipRect) const; Common::Rect _dstRect; uint32 _batchNum; @@ -52,16 +53,15 @@ public: bool _isValid; bool _wantsDraw; uint32 _drawNum; - uint32 _colorMod; + TransformStruct _transform; + BaseSurfaceOSystem *_owner; - bool operator==(RenderTicket &a); - const Common::Rect *getSrcRect() { return &_srcRect; } + bool operator==(const RenderTicket &a) const; + const Common::Rect *getSrcRect() const { return &_srcRect; } private: Graphics::Surface *_surface; Common::Rect _srcRect; - bool _hasAlpha; - uint32 _mirror; }; } // end of namespace Wintermute diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index f68259fb94..87cb143dac 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -23,9 +23,11 @@ #include "common/endian.h" #include "common/util.h" #include "common/rect.h" +#include "common/math.h" #include "common/textconsole.h" #include "graphics/primitives.h" #include "engines/wintermute/graphics/transparent_surface.h" +#include "engines/wintermute/graphics/transform_tools.h" namespace Wintermute { @@ -494,6 +496,45 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p return retSize; } +TransparentSurface *TransparentSurface::rotate(Common::Rect aSrcRect, TransformStruct transform) const { + Point32 newHotspot; + Rect32 rect = TransformTools::newRect(Rect32 (aSrcRect), transform, &newHotspot); + Common::Rect srcRect(0, 0, (int16)(aSrcRect.right - aSrcRect.left), (int16)(aSrcRect.bottom - aSrcRect.top)); + Common::Rect dstRect(0, 0, (int16)(rect.right - rect.left), (int16)(rect.bottom - rect.top)); + + TransparentSurface *target = new TransparentSurface(); + assert(format.bytesPerPixel == 4); + + int dstW = dstRect.width(); + int dstH = dstRect.height(); + + target->create((uint16)dstW, (uint16)dstH, this->format); + + uint32 invAngle = (360 - transform._angle) % 360; + float invCos = cos(invAngle * M_PI / 180.0); + float invSin = sin(invAngle * M_PI / 180.0); + + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + int x1 = x - newHotspot.x; + int y1 = y - newHotspot.y; + + float targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; + float targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; + + targX += transform._hotspot.x; + targY += transform._hotspot.y; + + if (FAST_TRANSFORM) { + bilinearCopy(targX, targY, x, y, srcRect, dstRect, this, target); + } else { + bilinearCopy(targX, targY, x, y, srcRect, dstRect, this, target); + } + } + } + return target; +} + TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) const { Common::Rect srcRect(0, 0, (int16)w, (int16)h); Common::Rect dstRect(0, 0, (int16)newWidth, (int16)newHeight); diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index 0f48054d7c..b81dbe86e9 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -23,7 +23,7 @@ #define GRAPHICS_TRANSPARENTSURFACE_H #include "graphics/surface.h" - +#include "engines/wintermute/graphics/transform_struct.h" #define FAST_TRANSFORM 0 @@ -111,6 +111,7 @@ struct TransparentSurface : public Graphics::Surface { void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false); TransparentSurface *scale (uint16 newWidth, uint16 newHeight) const; + TransparentSurface *rotate(Common::Rect srcRect, TransformStruct transform) const; static byte *_lookup; static void destroyLookup(); private: -- cgit v1.2.3 From 321c7f071668025b1c9bb16e28a70c29843e45de Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 17:19:52 +0200 Subject: WINTERMUTE: Removed useless argument from rotate() --- engines/wintermute/base/gfx/osystem/render_ticket.cpp | 3 +-- engines/wintermute/graphics/transparent_surface.cpp | 8 ++++---- engines/wintermute/graphics/transparent_surface.h | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index 23cf5c318e..3f94c2e500 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -53,8 +53,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s // Then scale it if necessary if (_transform._angle != 0) { TransparentSurface src(*_surface, false); - Common::Rect srcRect_1(srcRect->left, srcRect->top, srcRect->right, srcRect->bottom); - Graphics::Surface *temp = src.rotate(srcRect_1, transform); + Graphics::Surface *temp = src.rotate(transform); _surface->free(); delete _surface; _surface = temp; diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 87cb143dac..3f64305487 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -496,10 +496,10 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p return retSize; } -TransparentSurface *TransparentSurface::rotate(Common::Rect aSrcRect, TransformStruct transform) const { +TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const { Point32 newHotspot; - Rect32 rect = TransformTools::newRect(Rect32 (aSrcRect), transform, &newHotspot); - Common::Rect srcRect(0, 0, (int16)(aSrcRect.right - aSrcRect.left), (int16)(aSrcRect.bottom - aSrcRect.top)); + Common::Rect srcRect(0, 0, (int16)w, (int16)h); + Rect32 rect = TransformTools::newRect(Rect32 (srcRect), transform, &newHotspot); Common::Rect dstRect(0, 0, (int16)(rect.right - rect.left), (int16)(rect.bottom - rect.top)); TransparentSurface *target = new TransparentSurface(); @@ -526,7 +526,7 @@ TransparentSurface *TransparentSurface::rotate(Common::Rect aSrcRect, TransformS targY += transform._hotspot.y; if (FAST_TRANSFORM) { - bilinearCopy(targX, targY, x, y, srcRect, dstRect, this, target); + nearestCopy(targX, targY, x, y, srcRect, dstRect, this, target); } else { bilinearCopy(targX, targY, x, y, srcRect, dstRect, this, target); } diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index b81dbe86e9..474b10a6f1 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -111,7 +111,7 @@ struct TransparentSurface : public Graphics::Surface { void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false); TransparentSurface *scale (uint16 newWidth, uint16 newHeight) const; - TransparentSurface *rotate(Common::Rect srcRect, TransformStruct transform) const; + TransparentSurface *rotate(TransformStruct transform) const; static byte *_lookup; static void destroyLookup(); private: -- cgit v1.2.3 From e30ab15bb0f21a77f8e1752745cd6ec954661d83 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 17:25:46 +0200 Subject: WINTERMUTE: Move if() outside transform loop --- .../wintermute/graphics/transparent_surface.cpp | 60 ++++++++++++++++------ 1 file changed, 43 insertions(+), 17 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 3f64305487..403ce8984e 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -513,25 +513,41 @@ TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const uint32 invAngle = (360 - transform._angle) % 360; float invCos = cos(invAngle * M_PI / 180.0); float invSin = sin(invAngle * M_PI / 180.0); + float targX; + float targY; - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - int x1 = x - newHotspot.x; - int y1 = y - newHotspot.y; + if (FAST_TRANSFORM) { + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + int x1 = x - newHotspot.x; + int y1 = y - newHotspot.y; - float targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; - float targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; + targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; + targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; - targX += transform._hotspot.x; - targY += transform._hotspot.y; + targX += transform._hotspot.x; + targY += transform._hotspot.y; - if (FAST_TRANSFORM) { nearestCopy(targX, targY, x, y, srcRect, dstRect, this, target); - } else { - bilinearCopy(targX, targY, x, y, srcRect, dstRect, this, target); + } + } + } else { + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + int x1 = x - newHotspot.x; + int y1 = y - newHotspot.y; + + targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; + targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; + + targX += transform._hotspot.x; + targY += transform._hotspot.y; + + bilinearCopy(targX, targY, x, y, srcRect, dstRect, this, target); } } } + return target; } @@ -550,13 +566,23 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) target->create((uint16)dstW, (uint16)dstH, this->format); - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - float projX = x / (float)dstW * srcW; - float projY = y / (float)dstH * srcH; - if (FAST_TRANSFORM) { + if (FAST_TRANSFORM) { + int projX; + int projY; + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + projX = x / dstW * srcW; + projY = y / dstH * srcH; nearestCopy(projX, projY, x, y, srcRect, dstRect, this, target); - } else { + } + } + } else { + float projX; + float projY; + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + projX = x / (float)dstW * srcW; + projY = y / (float)dstH * srcH; bilinearCopy(projX, projY, x, y, srcRect, dstRect, this, target); } } -- cgit v1.2.3 From e47deb0e0e02f8ab288c21a33f5ec6187ab15e71 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 27 Jun 2013 17:28:43 +0200 Subject: WINTERMUTE: Rename pixel copy functions --- engines/wintermute/graphics/transparent_surface.cpp | 12 ++++++------ engines/wintermute/graphics/transparent_surface.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 403ce8984e..bdf074fdd9 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -31,7 +31,7 @@ namespace Wintermute { -void TransparentSurface::nearestCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { +void TransparentSurface::copyPixelNearestNeighbor(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { int srcW = srcRect.width(); int srcH = srcRect.height(); int dstW = dstRect.width(); @@ -51,7 +51,7 @@ void TransparentSurface::nearestCopy(float projX, float projY, int dstX, int dst WRITE_UINT32((byte *)dst->getBasePtr(dstX, dstY), color); } -void TransparentSurface::bilinearCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { +void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { int srcW = srcRect.width(); int srcH = srcRect.height(); @@ -528,7 +528,7 @@ TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const targX += transform._hotspot.x; targY += transform._hotspot.y; - nearestCopy(targX, targY, x, y, srcRect, dstRect, this, target); + copyPixelNearestNeighbor(targX, targY, x, y, srcRect, dstRect, this, target); } } } else { @@ -543,7 +543,7 @@ TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const targX += transform._hotspot.x; targY += transform._hotspot.y; - bilinearCopy(targX, targY, x, y, srcRect, dstRect, this, target); + copyPixelBilinear(targX, targY, x, y, srcRect, dstRect, this, target); } } } @@ -573,7 +573,7 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) for (int x = 0; x < dstW; x++) { projX = x / dstW * srcW; projY = y / dstH * srcH; - nearestCopy(projX, projY, x, y, srcRect, dstRect, this, target); + copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); } } } else { @@ -583,7 +583,7 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) for (int x = 0; x < dstW; x++) { projX = x / (float)dstW * srcW; projY = y / (float)dstH * srcH; - bilinearCopy(projX, projY, x, y, srcRect, dstRect, this, target); + copyPixelBilinear(projX, projY, x, y, srcRect, dstRect, this, target); } } } diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index 474b10a6f1..f9486d1b25 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -53,8 +53,8 @@ struct TransparentSurface : public Graphics::Surface { void setColorKey(char r, char g, char b); void disableColorKey(); - static void bilinearCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); - static void nearestCopy(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); + static void copyPixelBilinear(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); + static void copyPixelNearestNeighbor(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); // Enums /** -- cgit v1.2.3 From d2a249384eed076195b86f24ae1a041a93b3cd89 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Fri, 28 Jun 2013 16:19:34 +0200 Subject: WINTERMUTE: Partial fix for mirrored sprites Still weird with rotated + mirrored + scaled sprites. Offset. --- engines/wintermute/graphics/transform_tools.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 2390b86391..f0a092a31b 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -32,8 +32,8 @@ namespace Wintermute { */ float rotateRad = rotate * M_PI / 180; FloatPoint newPoint; - newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/100; - newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/100; + newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/100.0; + newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/100.0; if (mirrorX) newPoint.x *= -1; if (mirrorY) newPoint.y *= -1; /* -- cgit v1.2.3 From b788ae7f382ca05cecdf0eba5bfb176279299416 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Sat, 29 Jun 2013 12:09:46 +0200 Subject: WINTERMUTE: Swap flip bits --- engines/wintermute/graphics/transparent_surface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index bdf074fdd9..5606d41ae6 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -363,12 +363,12 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p int inStep = 4; int inoStep = img->pitch; - if (flipping & TransparentSurface::FLIP_V) { + if (flipping & TransparentSurface::FLIP_H) { inStep = -inStep; xp = img->w - 1; } - if (flipping & TransparentSurface::FLIP_H) { + if (flipping & TransparentSurface::FLIP_V) { inoStep = -inoStep; yp = img->h - 1; } -- cgit v1.2.3 From 8bed134ad6a155ec6b35e3cba4a212e016bf3c90 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Sun, 7 Jul 2013 23:11:32 +0200 Subject: WINTERMUTE: Force angle normalization This fixes the issues in J.U.L.I.A. --- engines/wintermute/base/base_sub_frame.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'engines') diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index b51b723f61..eb1c859c2f 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -235,6 +235,12 @@ const char* BaseSubFrame::getSurfaceFilename() { ////////////////////////////////////////////////////////////////////// bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, float zoomY, bool precise, uint32 alpha, float rotate, TSpriteBlendMode blendMode) { + + while (rotate < 0) { + rotate += 360.0f; + } + rotate = fmod(rotate, 360.0f); + if (!_surface) { return STATUS_OK; } -- cgit v1.2.3 From 0b21d6dca2ad5be41fa2aa4c2bed2cb694fba4d1 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 8 Jul 2013 15:39:23 +0200 Subject: WINTERMUTE: Fix alpha bug in engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp This fixes the "TV static" bug in J.U.L.I.A. --- engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index e1348726b4..adbef559df 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -328,7 +328,7 @@ bool BaseSurfaceOSystem::display(int x, int y, Rect32 rect, TSpriteBlendMode ble ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTrans(int x, int y, Rect32 rect, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { _rotation = 0; - return drawSprite(x, y, &rect, nullptr, TransformStruct(100, blendMode, 0xFFFFFFFF, mirrorX, mirrorY)); + return drawSprite(x, y, &rect, nullptr, TransformStruct(100, blendMode, alpha, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From b34d7b753912af6dd971872cd702d489974606ff Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 9 Jul 2013 20:57:03 +0200 Subject: WINTERMUTE: *transform as pointer in transform_tools --- engines/wintermute/base/base_sub_frame.cpp | 2 +- .../wintermute/base/gfx/osystem/render_ticket.cpp | 4 ++-- engines/wintermute/graphics/transform_tools.cpp | 21 +++++++++++--------- engines/wintermute/graphics/transform_tools.h | 2 +- .../wintermute/graphics/transparent_surface.cpp | 23 ++++++++++++---------- engines/wintermute/graphics/transparent_surface.h | 2 +- 6 files changed, 30 insertions(+), 24 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index eb1c859c2f..dbf46eae2e 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -269,7 +269,7 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl Rect32 oldRect = getRect(); Point32 newHotspot; TransformStruct transform = TransformStruct(zoomX, zoomY, rotate, _hotspotX, _hotspotY, blendMode, alpha, _mirrorX, _mirrorY, 0, 0); - Rect32 newRect = TransformTools::newRect (oldRect, transform, &newHotspot); + Rect32 newRect = TransformTools::newRect (oldRect, &transform, &newHotspot); newOrigin = origin - newHotspot; res = _surface->displayTransform(newOrigin.x, newOrigin.y, oldRect, newRect, transform); } else { diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index 3f94c2e500..8ea4f18605 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -53,7 +53,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s // Then scale it if necessary if (_transform._angle != 0) { TransparentSurface src(*_surface, false); - Graphics::Surface *temp = src.rotate(transform); + Graphics::Surface *temp = src.rotate(&transform); _surface->free(); delete _surface; _surface = temp; @@ -70,7 +70,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s if (transform._angle != 0) { // Make sure comparison-tickets get the correct width Rect32 dstRect; Point32 newHotspot; - dstRect = TransformTools::newRect(_srcRect, transform, &newHotspot); + dstRect = TransformTools::newRect(_srcRect, &transform, &newHotspot); _dstRect.setWidth(dstRect.right-dstRect.left); _dstRect.setHeight(dstRect.bottom-dstRect.top); } diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index f0a092a31b..2388b88236 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -43,7 +43,10 @@ namespace Wintermute { return newPoint; } - Rect32 TransformTools::newRect (Rect32 oldRect, TransformStruct transform, Point32 *newHotspot) { + Rect32 TransformTools::newRect (Rect32 oldRect, TransformStruct *transform, Point32 *newHotspot) { + + assert (transform); + Point32 nw(oldRect.left, oldRect.top); Point32 ne(oldRect.right, oldRect.top); Point32 sw(oldRect.left, oldRect.bottom); @@ -51,10 +54,10 @@ namespace Wintermute { FloatPoint nw1, ne1, sw1, se1; - nw1 = transformPoint(nw - transform._hotspot, transform._angle, transform._zoom); - ne1 = transformPoint(ne - transform._hotspot, transform._angle, transform._zoom); - sw1 = transformPoint(sw - transform._hotspot, transform._angle, transform._zoom); - se1 = transformPoint(se - transform._hotspot, transform._angle, transform._zoom); + nw1 = transformPoint(nw - transform->_hotspot, transform->_angle, transform->_zoom); + ne1 = transformPoint(ne - transform->_hotspot, transform->_angle, transform->_zoom); + sw1 = transformPoint(sw - transform->_hotspot, transform->_angle, transform->_zoom); + se1 = transformPoint(se - transform->_hotspot, transform->_angle, transform->_zoom); float top = MIN(nw1.y, MIN(ne1.y, MIN(sw1.y, se1.y))); float bottom = MAX(nw1.y, MAX(ne1.y, MAX(sw1.y, se1.y))); @@ -65,10 +68,10 @@ namespace Wintermute { newHotspot->y = -floor(top); newHotspot->x = -floor(left); - res.top = floor(top) + transform._hotspot.y; - res.bottom = ceil(bottom) + transform._hotspot.y; - res.left = floor(left) + transform._hotspot.x; - res.right = ceil(right) + transform._hotspot.x; + res.top = floor(top) + transform->_hotspot.y; + res.bottom = ceil(bottom) + transform->_hotspot.y; + res.left = floor(left) + transform->_hotspot.x; + res.right = ceil(right) + transform->_hotspot.x; return res; } diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h index fbc0653e64..ae60e5ab32 100644 --- a/engines/wintermute/graphics/transform_tools.h +++ b/engines/wintermute/graphics/transform_tools.h @@ -41,7 +41,7 @@ public: * and, as a side-effect, "newHotspot" will tell you where the hotspot will * have ended up in the new rect, for centering. */ - static Rect32 newRect (Rect32 oldRect, TransformStruct transform, Point32 *newHotspot); + static Rect32 newRect (Rect32 oldRect, TransformStruct *transform, Point32 *newHotspot); }; } // end of namespace Wintermute #endif diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 5606d41ae6..1139b08199 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -496,7 +496,10 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p return retSize; } -TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const { +TransparentSurface *TransparentSurface::rotate(TransformStruct *transform) const { + + assert (transform); + Point32 newHotspot; Common::Rect srcRect(0, 0, (int16)w, (int16)h); Rect32 rect = TransformTools::newRect(Rect32 (srcRect), transform, &newHotspot); @@ -510,7 +513,7 @@ TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const target->create((uint16)dstW, (uint16)dstH, this->format); - uint32 invAngle = (360 - transform._angle) % 360; + uint32 invAngle = (360 - transform->_angle) % 360; float invCos = cos(invAngle * M_PI / 180.0); float invSin = sin(invAngle * M_PI / 180.0); float targX; @@ -522,11 +525,11 @@ TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const int x1 = x - newHotspot.x; int y1 = y - newHotspot.y; - targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; - targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; + targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform->_zoom.x + srcRect.left; + targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform->_zoom.y + srcRect.top; - targX += transform._hotspot.x; - targY += transform._hotspot.y; + targX += transform->_hotspot.x; + targY += transform->_hotspot.y; copyPixelNearestNeighbor(targX, targY, x, y, srcRect, dstRect, this, target); } @@ -537,11 +540,11 @@ TransparentSurface *TransparentSurface::rotate(TransformStruct transform) const int x1 = x - newHotspot.x; int y1 = y - newHotspot.y; - targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; - targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; + targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform->_zoom.x + srcRect.left; + targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform->_zoom.y + srcRect.top; - targX += transform._hotspot.x; - targY += transform._hotspot.y; + targX += transform->_hotspot.x; + targY += transform->_hotspot.y; copyPixelBilinear(targX, targY, x, y, srcRect, dstRect, this, target); } diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index f9486d1b25..c01b10d96f 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -111,7 +111,7 @@ struct TransparentSurface : public Graphics::Surface { void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false); TransparentSurface *scale (uint16 newWidth, uint16 newHeight) const; - TransparentSurface *rotate(TransformStruct transform) const; + TransparentSurface *rotate(TransformStruct *transform) const; static byte *_lookup; static void destroyLookup(); private: -- cgit v1.2.3 From 285ed18979a470c458654f9f0c42ca02aa927f80 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 9 Jul 2013 21:02:55 +0200 Subject: WINTERMUTE: Rename rotate() -> rotoscale() for consistency --- engines/wintermute/base/gfx/osystem/render_ticket.cpp | 2 +- engines/wintermute/graphics/transparent_surface.cpp | 3 ++- engines/wintermute/graphics/transparent_surface.h | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index 8ea4f18605..2049d3ec57 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -53,7 +53,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s // Then scale it if necessary if (_transform._angle != 0) { TransparentSurface src(*_surface, false); - Graphics::Surface *temp = src.rotate(&transform); + Graphics::Surface *temp = src.rotoscale(&transform); _surface->free(); delete _surface; _surface = temp; diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 1139b08199..07c2537d0f 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -496,9 +496,10 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p return retSize; } -TransparentSurface *TransparentSurface::rotate(TransformStruct *transform) const { +TransparentSurface *TransparentSurface::rotoscale(TransformStruct *transform) const { assert (transform); + assert (transform->_angle != 0); // This would not be ideal Point32 newHotspot; Common::Rect srcRect(0, 0, (int16)w, (int16)h); diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index c01b10d96f..2798323379 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -111,7 +111,7 @@ struct TransparentSurface : public Graphics::Surface { void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false); TransparentSurface *scale (uint16 newWidth, uint16 newHeight) const; - TransparentSurface *rotate(TransformStruct *transform) const; + TransparentSurface *rotoscale (TransformStruct *transform) const; static byte *_lookup; static void destroyLookup(); private: -- cgit v1.2.3 From ae589c41ff869bb7e2352a2a60764b46bd80b72c Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 9 Jul 2013 21:52:16 +0200 Subject: WINTERMUTE: Deprecate setAlphaMod, setColorMod --- engines/wintermute/base/gfx/osystem/base_render_osystem.cpp | 13 +++---------- .../wintermute/base/gfx/osystem/base_surface_osystem.cpp | 8 -------- 2 files changed, 3 insertions(+), 18 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index e36eeb3ee6..143879c991 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -60,8 +60,7 @@ BaseRenderOSystem::BaseRenderOSystem(BaseGame *inGame) : BaseRenderer(inGame) { _borderLeft = _borderRight = _borderTop = _borderBottom = 0; _ratioX = _ratioY = 1.0f; - setAlphaMod(255); - setColorMod(255, 255, 255); + _colorMod = 0xFFFFFFFF; _dirtyRect = nullptr; _disableDirtyRects = false; _tempDisableDirtyRects = 0; @@ -151,15 +150,11 @@ bool BaseRenderOSystem::initRenderer(int width, int height, bool windowed) { } void BaseRenderOSystem::setAlphaMod(byte alpha) { - byte r = RGBCOLGetR(_colorMod); - byte g = RGBCOLGetB(_colorMod); - byte b = RGBCOLGetB(_colorMod); - _colorMod = BS_ARGB(alpha, r, g, b); + error("DEPRECATED: BaseRenderOSystem::setAlphaMod(byte alpha)"); } void BaseRenderOSystem::setColorMod(byte r, byte g, byte b) { - byte alpha = RGBCOLGetA(_colorMod); - _colorMod = BS_ARGB(alpha, r, g, b); + error("DEPRECATED: void BaseRenderOSystem::setColorMod(byte r, byte g, byte b)"); } bool BaseRenderOSystem::indicatorFlip() { @@ -278,8 +273,6 @@ void BaseRenderOSystem::fadeToColor(byte r, byte g, byte b, byte a, Common::Rect //TODO: This is only here until I'm sure about the final pixelformat uint32 col = _renderSurface->format.ARGBToColor(a, r, g, b); - setAlphaMod(255); - setColorMod(255, 255, 255); Graphics::Surface surf; surf.create((uint16)fillRect.width(), (uint16)fillRect.height(), _renderSurface->format); Common::Rect sizeRect(fillRect); diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index adbef559df..a7866472e7 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -380,14 +380,6 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, transform._rgbaMod = renderer->_forceAlphaColor; } - byte r = RGBCOLGetR(transform._rgbaMod); - byte g = RGBCOLGetG(transform._rgbaMod); - byte b = RGBCOLGetB(transform._rgbaMod); - byte a = RGBCOLGetA(transform._rgbaMod); - - renderer->setAlphaMod(a); - renderer->setColorMod(r, g, b); - #if 0 // These are kept for reference if BlendMode is reimplemented at some point. if (alphaDisable) { SDL_SetTextureBlendMode(_texture, SDL_BLENDMODE_NONE); -- cgit v1.2.3 From b6ed5ee816e7bb23e21acfaee56835e167c6025f Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 9 Jul 2013 22:10:33 +0200 Subject: WINTERMUTE: Reinstate rgbaMod comparisons for compare-tickets --- engines/wintermute/base/gfx/osystem/base_render_osystem.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index 143879c991..e647b0e446 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -327,6 +327,7 @@ void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::S for (it = _lastAddedTicket; it != endIterator; ++it) { compareTicket = *it; if (*(compareTicket) == compare && compareTicket->_isValid) { + compareTicket->_transform._rgbaMod = transform._rgbaMod; if (_disableDirtyRects) { drawFromSurface(compareTicket); } else { @@ -526,6 +527,7 @@ void BaseRenderOSystem::drawTickets() { // convert from screen-coords to surface-coords. dstClip.translate(-offsetX, -offsetY); + _colorMod = ticket->_transform._rgbaMod; drawFromSurface(ticket, &pos, &dstClip); _needsFlip = true; } -- cgit v1.2.3 From 1b9967400dbf28fa34dde175fdb4ad88c39ea623 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 9 Jul 2013 22:20:39 +0200 Subject: WINTERMUTE: Use constants from transform_tools for consistency --- engines/wintermute/base/base_sprite.h | 9 +++++---- engines/wintermute/base/base_sub_frame.cpp | 15 ++++++++------- .../wintermute/base/gfx/osystem/base_surface_osystem.h | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/base_sprite.h b/engines/wintermute/base/base_sprite.h index 05cb9fc936..6badffa827 100644 --- a/engines/wintermute/base/base_sprite.h +++ b/engines/wintermute/base/base_sprite.h @@ -32,6 +32,7 @@ #include "engines/wintermute/coll_templ.h" #include "engines/wintermute/base/base_script_holder.h" +#include "engines/wintermute/graphics/transform_tools.h" namespace Wintermute { class BaseFrame; @@ -44,17 +45,17 @@ public: void setDefaults(); DECLARE_PERSISTENT(BaseSprite, BaseScriptHolder) - bool getBoundingRect(Rect32 *rect, int x, int y, float scaleX = 100, float scaleY = 100); + bool getBoundingRect(Rect32 *rect, int x, int y, float scaleX = DEFAULT_ZOOM_X, float scaleY = DEFAULT_ZOOM_Y); int32 _moveY; int32 _moveX; - bool display(int x, int y, BaseObject *registerOwner = nullptr, float zoomX = 100, float zoomY = 100, uint32 alpha = 0xFFFFFFFF, float rotate = 0.0f, TSpriteBlendMode blendMode = BLEND_NORMAL); - bool getCurrentFrame(float zoomX = 100, float zoomY = 100); + bool display(int x, int y, BaseObject *registerOwner = nullptr, float zoomX = DEFAULT_ZOOM_X, float zoomY = DEFAULT_ZOOM_Y, uint32 alpha = DEFAULT_RGBAMOD, float rotate = DEFAULT_ANGLE, TSpriteBlendMode blendMode = BLEND_NORMAL); + bool getCurrentFrame(float zoomX = DEFAULT_ZOOM_X, float zoomY = DEFAULT_ZOOM_Y); void reset(); bool isChanged(); bool isFinished(); bool loadBuffer(byte *buffer, bool compete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); bool loadFile(const Common::String &filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); - bool draw(int x, int y, BaseObject *Register = nullptr, float zoomX = 100, float zoomY = 100, uint32 alpha = 0xFFFFFFFF); + bool draw(int x, int y, BaseObject *Register = nullptr, float zoomX = DEFAULT_ZOOM_X, float zoomY = DEFAULT_ZOOM_Y, uint32 alpha = DEFAULT_RGBAMOD); bool _looping; int32 _currentFrame; bool addFrame(const char *filename, uint32 delay = 0, int hotspotX = 0, int hotspotY = 0, Rect32 *rect = nullptr); diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index dbf46eae2e..0028de1908 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -48,8 +48,9 @@ IMPLEMENT_PERSISTENT(BaseSubFrame, false) ////////////////////////////////////////////////////////////////////////// BaseSubFrame::BaseSubFrame(BaseGame *inGame) : BaseScriptable(inGame, true) { _surface = nullptr; - _hotspotX = _hotspotY = 0; - _alpha = 0xFFFFFFFF; + _hotspotX = DEFAULT_HOTSPOT_X; + _hotspotY = DEFAULT_HOTSPOT_Y; + _alpha = DEFAULT_RGBAMOD; _transparent = 0xFFFF00FF; _wantsDefaultRect = false; @@ -246,7 +247,7 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl } if (registerOwner != nullptr && !_decoration) { - if (zoomX == 100 && zoomY == 100) { + if (zoomX == DEFAULT_ZOOM_X && zoomY == DEFAULT_ZOOM_Y) { BaseEngine::getRenderer()->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, x - _hotspotX + getRect().left, y - _hotspotY + getRect().top, getRect().right - getRect().left, getRect().bottom - getRect().top, zoomX, zoomY, precise)); } else { BaseEngine::getRenderer()->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, (int)(x - (_hotspotX + getRect().left) * (zoomX / 100)), (int)(y - (_hotspotY + getRect().top) * (zoomY / 100)), (int)((getRect().right - getRect().left) * (zoomX / 100)), (int)((getRect().bottom - getRect().top) * (zoomY / 100)), zoomX, zoomY, precise)); @@ -259,11 +260,11 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl bool res; //if (Alpha==0xFFFFFFFF) Alpha = _alpha; // TODO: better (combine owner's and self alpha) - if (_alpha != 0xFFFFFFFF) { + if (_alpha != DEFAULT_RGBAMOD) { alpha = _alpha; } - if (rotate != 0.0f) { + if (rotate != DEFAULT_ANGLE) { Point32 boxOffset, rotatedHotspot, hotspotOffset, newOrigin; Point32 origin(x, y); Rect32 oldRect = getRect(); @@ -273,10 +274,10 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl newOrigin = origin - newHotspot; res = _surface->displayTransform(newOrigin.x, newOrigin.y, oldRect, newRect, transform); } else { - if (zoomX == 100 && zoomY == 100) { + if (zoomX == DEFAULT_ZOOM_X && zoomY == DEFAULT_ZOOM_Y) { res = _surface->displayTrans(x - _hotspotX, y - _hotspotY, getRect(), alpha, blendMode, _mirrorX, _mirrorY); } else { - res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / 100)), (int)(y - _hotspotY * (zoomY / 100)), getRect(), zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY); + res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / DEFAULT_ZOOM_X)), (int)(y - _hotspotY * (zoomY / DEFAULT_ZOOM_Y)), getRect(), zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY); } } diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h index b6978d50e4..7eef416d0e 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h @@ -51,11 +51,11 @@ public: bool endPixelOp() override; - bool displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override; + bool displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = DEFAULT_RGBAMOD, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = DEFAULT_RGBAMOD, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = DEFAULT_RGBAMOD, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override; bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = DEFAULT_RGBAMOD, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) override; bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) override; virtual bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false) override; -- cgit v1.2.3 From dafcef5c9f5ddc27ca804ea1da0ab37720b103c8 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 11:17:10 +0200 Subject: WINTERMUTE: Replace normalization loop with if() for legibility --- engines/wintermute/base/base_sub_frame.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index 0028de1908..6f79d7f3a7 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -237,11 +237,11 @@ const char* BaseSubFrame::getSurfaceFilename() { ////////////////////////////////////////////////////////////////////// bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, float zoomY, bool precise, uint32 alpha, float rotate, TSpriteBlendMode blendMode) { - while (rotate < 0) { + rotate = fmod(rotate, 360.0f); + if (rotate < 0) { rotate += 360.0f; } - rotate = fmod(rotate, 360.0f); - + if (!_surface) { return STATUS_OK; } -- cgit v1.2.3 From 0153f762b16d33c350cde5f472bba42733f18dc7 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 11:27:40 +0200 Subject: WINTERMUTE: Defaults -> float --- engines/wintermute/graphics/transform_struct.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_struct.h b/engines/wintermute/graphics/transform_struct.h index 9a28a48bd1..ed30044174 100644 --- a/engines/wintermute/graphics/transform_struct.h +++ b/engines/wintermute/graphics/transform_struct.h @@ -26,8 +26,8 @@ #include "engines/wintermute/math/rect32.h" #include "engines/wintermute/dctypes.h" -#define DEFAULT_ZOOM_X 100 -#define DEFAULT_ZOOM_Y 100 +#define DEFAULT_ZOOM_X 100.0 +#define DEFAULT_ZOOM_Y 100.0 #define DEFAULT_RGBAMOD 0xFFFFFFFF #define DEFAULT_HOTSPOT_X 0 #define DEFAULT_HOTSPOT_Y 0 -- cgit v1.2.3 From f014cccb94e0b3244a3e6dca91db7ca7552e6d79 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 11:27:50 +0200 Subject: WINTERMUTE: Formatting --- engines/wintermute/graphics/transform_tools.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 2388b88236..0ab28eb275 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -27,19 +27,16 @@ namespace Wintermute { FloatPoint TransformTools::transformPoint(FloatPoint point, float rotate, Point32 zoom, bool mirrorX, bool mirrorY) { - /* - * Returns the coordinates for a point after rotation - */ float rotateRad = rotate * M_PI / 180; FloatPoint newPoint; - newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/100.0; - newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/100.0; - if (mirrorX) newPoint.x *= -1; - if (mirrorY) newPoint.y *= -1; - /* - * I apply the textbook formula, but first I reverse the Y-axis, otherwise - * I'd be performing a rotation in the wrong direction - */ + newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/DEFAULT_ZOOM_X; + newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/DEFAULT_ZOOM_Y; + if (mirrorX) { + newPoint.x *= -1; + } + if (mirrorY) { + newPoint.y *= -1; + } return newPoint; } -- cgit v1.2.3 From 9f97ad6a3e9e10fa7164a4e545c1705896f77925 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 11:42:16 +0200 Subject: WINTERMUTE: s/*transform/const &transform/ --- engines/wintermute/base/base_sub_frame.cpp | 2 +- .../wintermute/base/gfx/osystem/render_ticket.cpp | 4 +- engines/wintermute/graphics/transform_tools.cpp | 20 +++-- engines/wintermute/graphics/transform_tools.h | 2 +- .../wintermute/graphics/transparent_surface.cpp | 87 +++++++++++----------- engines/wintermute/graphics/transparent_surface.h | 4 +- 6 files changed, 58 insertions(+), 61 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index 6f79d7f3a7..f8c4000324 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -270,7 +270,7 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl Rect32 oldRect = getRect(); Point32 newHotspot; TransformStruct transform = TransformStruct(zoomX, zoomY, rotate, _hotspotX, _hotspotY, blendMode, alpha, _mirrorX, _mirrorY, 0, 0); - Rect32 newRect = TransformTools::newRect (oldRect, &transform, &newHotspot); + Rect32 newRect = TransformTools::newRect (oldRect, transform, &newHotspot); newOrigin = origin - newHotspot; res = _surface->displayTransform(newOrigin.x, newOrigin.y, oldRect, newRect, transform); } else { diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index 2049d3ec57..b11e0722af 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -53,7 +53,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s // Then scale it if necessary if (_transform._angle != 0) { TransparentSurface src(*_surface, false); - Graphics::Surface *temp = src.rotoscale(&transform); + Graphics::Surface *temp = src.rotoscale(transform); _surface->free(); delete _surface; _surface = temp; @@ -70,7 +70,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s if (transform._angle != 0) { // Make sure comparison-tickets get the correct width Rect32 dstRect; Point32 newHotspot; - dstRect = TransformTools::newRect(_srcRect, &transform, &newHotspot); + dstRect = TransformTools::newRect(_srcRect, transform, &newHotspot); _dstRect.setWidth(dstRect.right-dstRect.left); _dstRect.setHeight(dstRect.bottom-dstRect.top); } diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 0ab28eb275..194bedec64 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -40,9 +40,7 @@ namespace Wintermute { return newPoint; } - Rect32 TransformTools::newRect (Rect32 oldRect, TransformStruct *transform, Point32 *newHotspot) { - - assert (transform); + Rect32 TransformTools::newRect (Rect32 oldRect, const TransformStruct &transform, Point32 *newHotspot) { Point32 nw(oldRect.left, oldRect.top); Point32 ne(oldRect.right, oldRect.top); @@ -51,10 +49,10 @@ namespace Wintermute { FloatPoint nw1, ne1, sw1, se1; - nw1 = transformPoint(nw - transform->_hotspot, transform->_angle, transform->_zoom); - ne1 = transformPoint(ne - transform->_hotspot, transform->_angle, transform->_zoom); - sw1 = transformPoint(sw - transform->_hotspot, transform->_angle, transform->_zoom); - se1 = transformPoint(se - transform->_hotspot, transform->_angle, transform->_zoom); + nw1 = transformPoint(nw - transform._hotspot, transform._angle, transform._zoom); + ne1 = transformPoint(ne - transform._hotspot, transform._angle, transform._zoom); + sw1 = transformPoint(sw - transform._hotspot, transform._angle, transform._zoom); + se1 = transformPoint(se - transform._hotspot, transform._angle, transform._zoom); float top = MIN(nw1.y, MIN(ne1.y, MIN(sw1.y, se1.y))); float bottom = MAX(nw1.y, MAX(ne1.y, MAX(sw1.y, se1.y))); @@ -65,10 +63,10 @@ namespace Wintermute { newHotspot->y = -floor(top); newHotspot->x = -floor(left); - res.top = floor(top) + transform->_hotspot.y; - res.bottom = ceil(bottom) + transform->_hotspot.y; - res.left = floor(left) + transform->_hotspot.x; - res.right = ceil(right) + transform->_hotspot.x; + res.top = floor(top) + transform._hotspot.y; + res.bottom = ceil(bottom) + transform._hotspot.y; + res.left = floor(left) + transform._hotspot.x; + res.right = ceil(right) + transform._hotspot.x; return res; } diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h index ae60e5ab32..fb165d7ec8 100644 --- a/engines/wintermute/graphics/transform_tools.h +++ b/engines/wintermute/graphics/transform_tools.h @@ -41,7 +41,7 @@ public: * and, as a side-effect, "newHotspot" will tell you where the hotspot will * have ended up in the new rect, for centering. */ - static Rect32 newRect (Rect32 oldRect, TransformStruct *transform, Point32 *newHotspot); + static Rect32 newRect (Rect32 oldRect, const TransformStruct &transform, Point32 *newHotspot); }; } // end of namespace Wintermute #endif diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 07c2537d0f..0ec0b84f25 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -496,10 +496,9 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p return retSize; } -TransparentSurface *TransparentSurface::rotoscale(TransformStruct *transform) const { +TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transform) const { - assert (transform); - assert (transform->_angle != 0); // This would not be ideal + assert (transform._angle != 0); // This would not be ideal Point32 newHotspot; Common::Rect srcRect(0, 0, (int16)w, (int16)h); @@ -514,43 +513,43 @@ TransparentSurface *TransparentSurface::rotoscale(TransformStruct *transform) co target->create((uint16)dstW, (uint16)dstH, this->format); - uint32 invAngle = (360 - transform->_angle) % 360; + uint32 invAngle = (360 - transform._angle) % 360; float invCos = cos(invAngle * M_PI / 180.0); float invSin = sin(invAngle * M_PI / 180.0); float targX; float targY; - if (FAST_TRANSFORM) { - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - int x1 = x - newHotspot.x; - int y1 = y - newHotspot.y; +#if ENABLE_BILINEAR + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + int x1 = x - newHotspot.x; + int y1 = y - newHotspot.y; - targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform->_zoom.x + srcRect.left; - targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform->_zoom.y + srcRect.top; + targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; + targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; - targX += transform->_hotspot.x; - targY += transform->_hotspot.y; + targX += transform._hotspot.x; + targY += transform._hotspot.y; - copyPixelNearestNeighbor(targX, targY, x, y, srcRect, dstRect, this, target); - } + copyPixelBilinear(targX, targY, x, y, srcRect, dstRect, this, target); } - } else { - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - int x1 = x - newHotspot.x; - int y1 = y - newHotspot.y; + } +#else + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + int x1 = x - newHotspot.x; + int y1 = y - newHotspot.y; - targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform->_zoom.x + srcRect.left; - targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform->_zoom.y + srcRect.top; + targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; + targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; - targX += transform->_hotspot.x; - targY += transform->_hotspot.y; + targX += transform._hotspot.x; + targY += transform._hotspot.y; - copyPixelBilinear(targX, targY, x, y, srcRect, dstRect, this, target); - } + copyPixelNearestNeighbor(targX, targY, x, y, srcRect, dstRect, this, target); } } +#endif return target; } @@ -570,27 +569,27 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) target->create((uint16)dstW, (uint16)dstH, this->format); - if (FAST_TRANSFORM) { - int projX; - int projY; - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - projX = x / dstW * srcW; - projY = y / dstH * srcH; - copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); - } +#if ENABLE_BILINEAR + float projX; + float projY; + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + projX = x / (float)dstW * srcW; + projY = y / (float)dstH * srcH; + copyPixelBilinear(projX, projY, x, y, srcRect, dstRect, this, target); } - } else { - float projX; - float projY; - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - projX = x / (float)dstW * srcW; - projY = y / (float)dstH * srcH; - copyPixelBilinear(projX, projY, x, y, srcRect, dstRect, this, target); - } + } +#else + int projX; + int projY; + for (int y = 0; y < dstH; y++) { + for (int x = 0; x < dstW; x++) { + projX = x / dstW * srcW; + projY = y / dstH * srcH; + copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); } } +#endif return target; } diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index 2798323379..71c139a76a 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -25,7 +25,7 @@ #include "graphics/surface.h" #include "engines/wintermute/graphics/transform_struct.h" -#define FAST_TRANSFORM 0 +#define ENABLE_BILINEAR 0 /* @@ -111,7 +111,7 @@ struct TransparentSurface : public Graphics::Surface { void applyColorKey(uint8 r, uint8 g, uint8 b, bool overwriteAlpha = false); TransparentSurface *scale (uint16 newWidth, uint16 newHeight) const; - TransparentSurface *rotoscale (TransformStruct *transform) const; + TransparentSurface *rotoscale (const TransformStruct &transform) const; static byte *_lookup; static void destroyLookup(); private: -- cgit v1.2.3 From a0561f1aa52b31feff468dc53b6556a683b6a819 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 11:44:38 +0200 Subject: WINTERMUTE: Fix calculation of inverse angles --- engines/wintermute/graphics/transparent_surface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 0ec0b84f25..a0d472389f 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -513,7 +513,7 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo target->create((uint16)dstW, (uint16)dstH, this->format); - uint32 invAngle = (360 - transform._angle) % 360; + uint32 invAngle = 360 - (transform._angle % 360); float invCos = cos(invAngle * M_PI / 180.0); float invSin = sin(invAngle * M_PI / 180.0); float targX; -- cgit v1.2.3 From ab022b179897153b1be97804502f5ece24931e56 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 12:22:07 +0200 Subject: WINTERMUTE: // End of namespace Wintermute --- engines/wintermute/graphics/transform_struct.cpp | 3 +-- engines/wintermute/graphics/transform_struct.h | 4 +--- engines/wintermute/graphics/transform_tools.cpp | 2 +- engines/wintermute/graphics/transform_tools.h | 2 +- engines/wintermute/math/floatpoint.h | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_struct.cpp b/engines/wintermute/graphics/transform_struct.cpp index 9a11aa9fdd..dc5e45feea 100644 --- a/engines/wintermute/graphics/transform_struct.cpp +++ b/engines/wintermute/graphics/transform_struct.cpp @@ -123,5 +123,4 @@ bool TransformStruct::mirrorX() const { bool TransformStruct::mirrorY() const { return (bool)(_flip & TransparentSurface::FLIP_V); } - -} +} // End of namespace Wintermute diff --git a/engines/wintermute/graphics/transform_struct.h b/engines/wintermute/graphics/transform_struct.h index ed30044174..1f7d556fe7 100644 --- a/engines/wintermute/graphics/transform_struct.h +++ b/engines/wintermute/graphics/transform_struct.h @@ -81,7 +81,5 @@ public: return !(compare == *this); } }; - -} - +} // End of namespace Wintermute #endif diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 194bedec64..9e736366c3 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -70,4 +70,4 @@ namespace Wintermute { return res; } -} +} // End of namespace Wintermute diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h index fb165d7ec8..ee4d16acb0 100644 --- a/engines/wintermute/graphics/transform_tools.h +++ b/engines/wintermute/graphics/transform_tools.h @@ -43,5 +43,5 @@ public: */ static Rect32 newRect (Rect32 oldRect, const TransformStruct &transform, Point32 *newHotspot); }; -} // end of namespace Wintermute +} // End of namespace Wintermute #endif diff --git a/engines/wintermute/math/floatpoint.h b/engines/wintermute/math/floatpoint.h index bf194d8437..0c47ef09d7 100644 --- a/engines/wintermute/math/floatpoint.h +++ b/engines/wintermute/math/floatpoint.h @@ -47,6 +47,6 @@ struct FloatPoint { } }; -} // end of namespace Wintermute +} // End of namespace Wintermute #endif -- cgit v1.2.3 From 163cd6a5284a352225fbfa621a1e7152d0e5f8e0 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 12:32:22 +0200 Subject: WINTERMUTE: Constants --- engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index a7866472e7..d218c916e4 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -334,7 +334,7 @@ bool BaseSurfaceOSystem::displayTrans(int x, int y, Rect32 rect, uint32 alpha, T ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTransOffset(int x, int y, Rect32 rect, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX, int offsetY) { _rotation = 0; - return drawSprite(x, y, &rect, nullptr, TransformStruct(100, 100, 0, 0, 0, blendMode, alpha, mirrorX, mirrorY, offsetX, offsetY)); + return drawSprite(x, y, &rect, nullptr, TransformStruct(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y, DEFAULT_ANGLE, DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y, blendMode, alpha, mirrorX, mirrorY, offsetX, offsetY)); } ////////////////////////////////////////////////////////////////////////// @@ -349,7 +349,7 @@ bool BaseSurfaceOSystem::displayZoom(int x, int y, Rect32 rect, float zoomX, flo _rotation = 0; TransformStruct transform; if (transparent) { - transform = TransformStruct(zoomX, zoomY, 0, 0, 0, blendMode, alpha, mirrorX, mirrorY); + transform = TransformStruct(zoomX, zoomY, DEFAULT_ANGLE, DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y, blendMode, alpha, mirrorX, mirrorY); } else { transform = TransformStruct(zoomX, zoomY, mirrorX, mirrorY); } @@ -414,8 +414,8 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, position.setWidth(newRect->right - newRect->left); position.setHeight(newRect->bottom - newRect->top); } else { - position.setWidth((int16)((float)srcRect.width() * transform._zoom.x / 100.f)); - position.setHeight((int16)((float)srcRect.height() * transform._zoom.y / 100.f)); + position.setWidth((int16)((float)srcRect.width() * transform._zoom.x / DEFAULT_ZOOM_X)); + position.setHeight((int16)((float)srcRect.height() * transform._zoom.y / DEFAULT_ZOOM_Y)); } renderer->modTargetRect(&position); -- cgit v1.2.3 From 6f03fbac843410f457115bd075a6926ed3924ce0 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 12:46:32 +0200 Subject: WINTERMUTE: Pass structs by const reference --- engines/wintermute/base/gfx/base_surface.cpp | 2 +- engines/wintermute/base/gfx/base_surface.h | 2 +- engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp | 2 +- engines/wintermute/base/gfx/osystem/base_surface_osystem.h | 2 +- engines/wintermute/base/gfx/osystem/render_ticket.cpp | 4 ++-- engines/wintermute/graphics/transform_tools.cpp | 4 ++-- engines/wintermute/graphics/transform_tools.h | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/base_surface.cpp b/engines/wintermute/base/gfx/base_surface.cpp index 7457e34826..42ec51f39e 100644 --- a/engines/wintermute/base/gfx/base_surface.cpp +++ b/engines/wintermute/base/gfx/base_surface.cpp @@ -75,7 +75,7 @@ bool BaseSurface::displayHalfTrans(int x, int y, Rect32 rect) { } ////////////////////////////////////////////////////////////////////////// -bool BaseSurface::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) { +bool BaseSurface::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) { return displayTransform(x, y, rect, newRect, transform); } diff --git a/engines/wintermute/base/gfx/base_surface.h b/engines/wintermute/base/gfx/base_surface.h index be7a5c13ca..016831fb29 100644 --- a/engines/wintermute/base/gfx/base_surface.h +++ b/engines/wintermute/base/gfx/base_surface.h @@ -54,7 +54,7 @@ public: virtual bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) = 0; virtual bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; - virtual bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) = 0; + virtual bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) = 0; virtual bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) = 0; virtual bool restore(); diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index d218c916e4..8ec60bfd68 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -358,7 +358,7 @@ bool BaseSurfaceOSystem::displayZoom(int x, int y, Rect32 rect, float zoomX, flo ////////////////////////////////////////////////////////////////////////// -bool BaseSurfaceOSystem::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) { +bool BaseSurfaceOSystem::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) { _rotation = (uint32)transform._angle; if (transform._angle < 0.0f) { warning("Negative rotation: %f %d", transform._angle, _rotation); diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h index 7eef416d0e..2e2da3c289 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h @@ -56,7 +56,7 @@ public: bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = DEFAULT_RGBAMOD, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override; bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = DEFAULT_RGBAMOD, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, TransformStruct transform) override; + bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) override; bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) override; virtual bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false) override; /* static unsigned DLL_CALLCONV ReadProc(void *buffer, unsigned size, unsigned count, fi_handle handle); diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index b11e0722af..d510d97dd1 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -51,7 +51,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s memcpy(_surface->getBasePtr(0, i), surf->getBasePtr(srcRect->left, srcRect->top + i), srcRect->width() * _surface->format.bytesPerPixel); } // Then scale it if necessary - if (_transform._angle != 0) { + if (_transform._angle != DEFAULT_ANGLE) { TransparentSurface src(*_surface, false); Graphics::Surface *temp = src.rotoscale(transform); _surface->free(); @@ -67,7 +67,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s } else { _surface = nullptr; - if (transform._angle != 0) { // Make sure comparison-tickets get the correct width + if (transform._angle != DEFAULT_ANGLE) { // Make sure comparison-tickets get the correct width Rect32 dstRect; Point32 newHotspot; dstRect = TransformTools::newRect(_srcRect, transform, &newHotspot); diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 9e736366c3..01e8b486ce 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -26,7 +26,7 @@ namespace Wintermute { - FloatPoint TransformTools::transformPoint(FloatPoint point, float rotate, Point32 zoom, bool mirrorX, bool mirrorY) { + FloatPoint TransformTools::transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX, const bool mirrorY) { float rotateRad = rotate * M_PI / 180; FloatPoint newPoint; newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/DEFAULT_ZOOM_X; @@ -40,7 +40,7 @@ namespace Wintermute { return newPoint; } - Rect32 TransformTools::newRect (Rect32 oldRect, const TransformStruct &transform, Point32 *newHotspot) { + Rect32 TransformTools::newRect (const Rect32 &oldRect, const TransformStruct &transform, Point32 *newHotspot) { Point32 nw(oldRect.left, oldRect.top); Point32 ne(oldRect.right, oldRect.top); diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h index ee4d16acb0..a9eabffe26 100644 --- a/engines/wintermute/graphics/transform_tools.h +++ b/engines/wintermute/graphics/transform_tools.h @@ -33,7 +33,7 @@ public: /** * Basic transform (scale + rotate) for a single point */ - static FloatPoint transformPoint(FloatPoint point, float rotate, Point32 zoom, bool mirrorX = false, bool mirrorY = false); + static FloatPoint transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX = false, const bool mirrorY = false); /** * Takes a rectangle, a transform and a pointer to a point, "newHotspot". @@ -41,7 +41,7 @@ public: * and, as a side-effect, "newHotspot" will tell you where the hotspot will * have ended up in the new rect, for centering. */ - static Rect32 newRect (Rect32 oldRect, const TransformStruct &transform, Point32 *newHotspot); + static Rect32 newRect (const Rect32 &oldRect, const TransformStruct &transform, Point32 *newHotspot); }; } // End of namespace Wintermute #endif -- cgit v1.2.3 From 5a9e917a600eb47dd420f5efd2d52005b68a151c Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 12:53:05 +0200 Subject: WINTERMUTE: Fix operator precedence in scale() --- engines/wintermute/graphics/transparent_surface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index a0d472389f..e20f97b116 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -584,8 +584,8 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) int projY; for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { - projX = x / dstW * srcW; - projY = y / dstH * srcH; + projX = x / (float)dstW * srcW; + projY = y / (float)dstH * srcH; copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); } } -- cgit v1.2.3 From 4405a534e5470cb2f14baad7d76f109f379023cf Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 12:56:18 +0200 Subject: WINTERMUTE: Remove set[Color|Alpha]Mod altogether --- engines/wintermute/base/gfx/osystem/base_render_osystem.cpp | 8 -------- engines/wintermute/base/gfx/osystem/base_render_osystem.h | 2 -- 2 files changed, 10 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index e647b0e446..c81ea14fe9 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -149,14 +149,6 @@ bool BaseRenderOSystem::initRenderer(int width, int height, bool windowed) { return STATUS_OK; } -void BaseRenderOSystem::setAlphaMod(byte alpha) { - error("DEPRECATED: BaseRenderOSystem::setAlphaMod(byte alpha)"); -} - -void BaseRenderOSystem::setColorMod(byte r, byte g, byte b) { - error("DEPRECATED: void BaseRenderOSystem::setColorMod(byte r, byte g, byte b)"); -} - bool BaseRenderOSystem::indicatorFlip() { g_system->copyRectToScreen((byte *)_renderSurface->getBasePtr(_indicatorX, _indicatorY), _renderSurface->pitch, _indicatorX, _indicatorY, _indicatorWidthDrawn, _indicatorHeight); g_system->updateScreen(); diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.h b/engines/wintermute/base/gfx/osystem/base_render_osystem.h index b3483f0efa..63967288b7 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.h @@ -57,8 +57,6 @@ public: BaseImage *takeScreenshot() override; - void setAlphaMod(byte alpha); - void setColorMod(byte r, byte g, byte b); void invalidateTicket(RenderTicket *renderTicket); void invalidateTicketsFromSurface(BaseSurfaceOSystem *surf); void drawFromTicket(RenderTicket *renderTicket); -- cgit v1.2.3 From 9cfea04846b19f17c8c68c9e19a044c1b48c0f7f Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 10 Jul 2013 16:37:51 +0200 Subject: WINTERMUTE: Formatting --- engines/wintermute/graphics/transparent_surface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index e20f97b116..48d550c26f 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -498,8 +498,8 @@ Common::Rect TransparentSurface::blit(Graphics::Surface &target, int posX, int p TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transform) const { - assert (transform._angle != 0); // This would not be ideal - + assert(transform._angle != 0); // This would not be ideal; rotoscale() should never be called in conditional branches where angle = 0 anyway. + Point32 newHotspot; Common::Rect srcRect(0, 0, (int16)w, (int16)h); Rect32 rect = TransformTools::newRect(Rect32 (srcRect), transform, &newHotspot); -- cgit v1.2.3 From 9d4def3bfd541cd95ce62e18fa18d90799fcd791 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Sat, 13 Jul 2013 19:14:10 +0200 Subject: WINTERMUTE: Fix alpha bug in BaseRenderOSystem::fadeToColor Introduced in 37b1ff3, broke fade-in/fade-outs --- engines/wintermute/base/gfx/osystem/base_render_osystem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index c81ea14fe9..2aae973309 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -270,7 +270,9 @@ void BaseRenderOSystem::fadeToColor(byte r, byte g, byte b, byte a, Common::Rect Common::Rect sizeRect(fillRect); sizeRect.translate(-fillRect.top, -fillRect.left); surf.fillRect(fillRect, col); - drawSurface(nullptr, &surf, &sizeRect, &fillRect, TransformStruct()); + TransformStruct temp = TransformStruct(); + temp._alphaDisable = false; + drawSurface(nullptr, &surf, &sizeRect, &fillRect, temp); surf.free(); //SDL_SetRenderDrawColor(_renderer, r, g, b, a); -- cgit v1.2.3 From 64db90ed67e385a7ba8ca18faa0da345987201db Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 20:54:25 +0200 Subject: WINTERMUTE: TransformStruct by reference in engines/wintermute/base/gfx/osystem/base_render_osystem.h --- engines/wintermute/base/gfx/osystem/base_render_osystem.cpp | 5 +++-- engines/wintermute/base/gfx/osystem/base_render_osystem.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index 2aae973309..06cf531a9e 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -284,7 +284,7 @@ Graphics::PixelFormat BaseRenderOSystem::getPixelFormat() const { return _renderSurface->format; } -void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, TransformStruct transform) { +void BaseRenderOSystem::drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, TransformStruct &transform) { if (_tempDisableDirtyRects || _disableDirtyRects) { RenderTicket *ticket = new RenderTicket(owner, surf, srcRect, dstRect, transform); @@ -376,7 +376,8 @@ void BaseRenderOSystem::repeatLastDraw(int offsetX, int offsetY, int numTimesX, dstRect.translate(offsetX, 0); } for (int j = (i == 0 ? 1 : 0); j < numTimesX; j++) { - drawSurface(origTicket->_owner, origTicket->getSurface(), &srcRect, &dstRect, TransformStruct()); + TransformStruct temp = TransformStruct(); + drawSurface(origTicket->_owner, origTicket->getSurface(), &srcRect, &dstRect, temp); dstRect.translate(offsetX, 0); } dstRect.left = initLeft; diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.h b/engines/wintermute/base/gfx/osystem/base_render_osystem.h index 63967288b7..5531961623 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.h @@ -79,7 +79,7 @@ public: virtual bool startSpriteBatch() override; virtual bool endSpriteBatch() override; void endSaveLoad(); - void drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, TransformStruct transform); + void drawSurface(BaseSurfaceOSystem *owner, const Graphics::Surface *surf, Common::Rect *srcRect, Common::Rect *dstRect, TransformStruct &transform); void repeatLastDraw(int offsetX, int offsetY, int numTimesX, int numTimesY); BaseSurface *createSurface() override; private: -- cgit v1.2.3 From 286b1d11ca798249d412adb52e453404de7b727e Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 21:42:16 +0200 Subject: WINTERMUTE: Use Rect::width() and height() in base_surface_osystem.cpp --- engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index 8ec60bfd68..6db4818945 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -409,10 +409,10 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, if (newRect) { position.top = y; position.left = x; - position.right = x + (newRect->right - newRect->left); - position.bottom = y + (newRect->top - newRect->bottom); - position.setWidth(newRect->right - newRect->left); - position.setHeight(newRect->bottom - newRect->top); + position.right = x + newRect->width(); + position.bottom = y + newRect->height(); + position.setWidth(newRect->width()); + position.setHeight(newRect->height()); } else { position.setWidth((int16)((float)srcRect.width() * transform._zoom.x / DEFAULT_ZOOM_X)); position.setHeight((int16)((float)srcRect.height() * transform._zoom.y / DEFAULT_ZOOM_Y)); -- cgit v1.2.3 From 06ec0067665c4aa2369ea0b3b451ca0e7b2951c1 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 21:55:30 +0200 Subject: WINTERMUTE: Remove redeclaration in render_ticket.cpp --- engines/wintermute/base/gfx/osystem/render_ticket.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index d510d97dd1..7f141aa460 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -68,11 +68,11 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s _surface = nullptr; if (transform._angle != DEFAULT_ANGLE) { // Make sure comparison-tickets get the correct width - Rect32 dstRect; + Rect32 newDstRect; Point32 newHotspot; - dstRect = TransformTools::newRect(_srcRect, transform, &newHotspot); - _dstRect.setWidth(dstRect.right-dstRect.left); - _dstRect.setHeight(dstRect.bottom-dstRect.top); + newDstRect = TransformTools::newRect(_srcRect, transform, &newHotspot); + _dstRect.setWidth(newDstRect.right - newDstRect.left); + _dstRect.setHeight(newDstRect.bottom - newDstRect.top); } } } -- cgit v1.2.3 From 63b8132ea3ec6fe6bcfcb43d1e0c9baf481eab1e Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 22:24:46 +0200 Subject: WINTERMUTE: Remove single-argument zoom, rename mirrorX => getMirrorX() in transform_struct.h --- .../base/gfx/osystem/base_surface_osystem.cpp | 4 +-- engines/wintermute/graphics/transform_struct.cpp | 37 ++-------------------- engines/wintermute/graphics/transform_struct.h | 7 ++-- 3 files changed, 6 insertions(+), 42 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index 6db4818945..02f7f991e1 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -321,14 +321,14 @@ bool BaseSurfaceOSystem::endPixelOp() { ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { _rotation = 0; - return drawSprite(x, y, &rect, nullptr, TransformStruct(100, mirrorX, mirrorY)); + return drawSprite(x, y, &rect, nullptr, TransformStruct(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTrans(int x, int y, Rect32 rect, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { _rotation = 0; - return drawSprite(x, y, &rect, nullptr, TransformStruct(100, blendMode, alpha, mirrorX, mirrorY)); + return drawSprite(x, y, &rect, nullptr, TransformStruct(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y, blendMode, alpha, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// diff --git a/engines/wintermute/graphics/transform_struct.cpp b/engines/wintermute/graphics/transform_struct.cpp index dc5e45feea..c179d42ab1 100644 --- a/engines/wintermute/graphics/transform_struct.cpp +++ b/engines/wintermute/graphics/transform_struct.cpp @@ -61,28 +61,6 @@ TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, TSpriteBlendMode blen Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); } -TransformStruct::TransformStruct(int32 zoom, TSpriteBlendMode blendMode, uint32 rgbaMod, bool mirrorX, bool mirrorY) { - init(Point32(zoom, zoom), - DEFAULT_ANGLE, - Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), - false, - blendMode, - rgbaMod, - mirrorX, mirrorY, - Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); -} - -TransformStruct::TransformStruct(int32 zoom, bool mirrorX, bool mirrorY) { - init(Point32(zoom, zoom), - DEFAULT_ANGLE, - Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), - true, - BLEND_NORMAL, - DEFAULT_RGBAMOD, - mirrorX, mirrorY, - Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); -} - TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX, int32 hotspotY) { init(Point32(zoomX, zoomY), angle, @@ -94,17 +72,6 @@ TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 h Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); } -TransformStruct::TransformStruct(int32 zoom) { - init(Point32(zoom, zoom), - DEFAULT_ANGLE, - Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), - true, - BLEND_NORMAL, - DEFAULT_RGBAMOD, - false, false, - Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); -} - TransformStruct::TransformStruct() { init(Point32(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y), DEFAULT_ANGLE, @@ -116,11 +83,11 @@ TransformStruct::TransformStruct() { Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); } -bool TransformStruct::mirrorX() const { +bool TransformStruct::getMirrorX() const { return (bool)(_flip & TransparentSurface::FLIP_H); } -bool TransformStruct::mirrorY() const { +bool TransformStruct::getMirrorY() const { return (bool)(_flip & TransparentSurface::FLIP_V); } } // End of namespace Wintermute diff --git a/engines/wintermute/graphics/transform_struct.h b/engines/wintermute/graphics/transform_struct.h index 1f7d556fe7..6b021b5cd5 100644 --- a/engines/wintermute/graphics/transform_struct.h +++ b/engines/wintermute/graphics/transform_struct.h @@ -48,10 +48,7 @@ private: public: TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX, int32 hotspotY, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX = false, bool mirrorY = false, int32 offsetX = 0, int32 offsetY = 0); TransformStruct(int32 zoomX, int32 zoomY, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX = false, bool mirrorY = false); - TransformStruct(int32 zoom, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX, bool mirrorY); - TransformStruct(int32 zoom, bool mirrorX, bool mirrorY); TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX = 0, int32 hotspotY = 0); - TransformStruct(int32 zoom); TransformStruct(); Point32 _zoom; ///< Zoom; 100 = no zoom @@ -63,8 +60,8 @@ public: uint32 _rgbaMod; ///< RGBa Point32 _offset; - bool mirrorX() const; - bool mirrorY() const; + bool getMirrorX() const; + bool getMirrorY() const; bool operator==(const TransformStruct &compare) const { return (compare._angle == _angle && -- cgit v1.2.3 From d2d72c0110e4e2c265fcc1413958540f182d4353 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 22:39:55 +0200 Subject: WINTERMUTE: #define to const for TransformStruct defaults --- engines/wintermute/base/base_sprite.h | 8 ++++---- engines/wintermute/base/base_sub_frame.cpp | 16 ++++++++-------- .../base/gfx/osystem/base_surface_osystem.cpp | 12 ++++++------ .../base/gfx/osystem/base_surface_osystem.h | 8 ++++---- .../wintermute/base/gfx/osystem/render_ticket.cpp | 4 ++-- engines/wintermute/graphics/transform_struct.cpp | 20 ++++++++++---------- engines/wintermute/graphics/transform_struct.h | 22 +++++++++++----------- engines/wintermute/graphics/transform_tools.cpp | 4 ++-- 8 files changed, 47 insertions(+), 47 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/base_sprite.h b/engines/wintermute/base/base_sprite.h index 6badffa827..d464899b04 100644 --- a/engines/wintermute/base/base_sprite.h +++ b/engines/wintermute/base/base_sprite.h @@ -45,17 +45,17 @@ public: void setDefaults(); DECLARE_PERSISTENT(BaseSprite, BaseScriptHolder) - bool getBoundingRect(Rect32 *rect, int x, int y, float scaleX = DEFAULT_ZOOM_X, float scaleY = DEFAULT_ZOOM_Y); + bool getBoundingRect(Rect32 *rect, int x, int y, float scaleX = kDefaultZoomX, float scaleY = kDefaultZoomY); int32 _moveY; int32 _moveX; - bool display(int x, int y, BaseObject *registerOwner = nullptr, float zoomX = DEFAULT_ZOOM_X, float zoomY = DEFAULT_ZOOM_Y, uint32 alpha = DEFAULT_RGBAMOD, float rotate = DEFAULT_ANGLE, TSpriteBlendMode blendMode = BLEND_NORMAL); - bool getCurrentFrame(float zoomX = DEFAULT_ZOOM_X, float zoomY = DEFAULT_ZOOM_Y); + bool display(int x, int y, BaseObject *registerOwner = nullptr, float zoomX = kDefaultZoomX, float zoomY = kDefaultZoomY, uint32 alpha = kDefaultRgbaMod, float rotate = kDefaultAngle, TSpriteBlendMode blendMode = BLEND_NORMAL); + bool getCurrentFrame(float zoomX = kDefaultZoomX, float zoomY = kDefaultZoomY); void reset(); bool isChanged(); bool isFinished(); bool loadBuffer(byte *buffer, bool compete = true, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); bool loadFile(const Common::String &filename, int lifeTime = -1, TSpriteCacheType cacheType = CACHE_ALL); - bool draw(int x, int y, BaseObject *Register = nullptr, float zoomX = DEFAULT_ZOOM_X, float zoomY = DEFAULT_ZOOM_Y, uint32 alpha = DEFAULT_RGBAMOD); + bool draw(int x, int y, BaseObject *Register = nullptr, float zoomX = kDefaultZoomX, float zoomY = kDefaultZoomY, uint32 alpha = kDefaultRgbaMod); bool _looping; int32 _currentFrame; bool addFrame(const char *filename, uint32 delay = 0, int hotspotX = 0, int hotspotY = 0, Rect32 *rect = nullptr); diff --git a/engines/wintermute/base/base_sub_frame.cpp b/engines/wintermute/base/base_sub_frame.cpp index f8c4000324..7012c28feb 100644 --- a/engines/wintermute/base/base_sub_frame.cpp +++ b/engines/wintermute/base/base_sub_frame.cpp @@ -48,9 +48,9 @@ IMPLEMENT_PERSISTENT(BaseSubFrame, false) ////////////////////////////////////////////////////////////////////////// BaseSubFrame::BaseSubFrame(BaseGame *inGame) : BaseScriptable(inGame, true) { _surface = nullptr; - _hotspotX = DEFAULT_HOTSPOT_X; - _hotspotY = DEFAULT_HOTSPOT_Y; - _alpha = DEFAULT_RGBAMOD; + _hotspotX = kDefaultHotspotX; + _hotspotY = kDefaultHotspotY; + _alpha = kDefaultRgbaMod; _transparent = 0xFFFF00FF; _wantsDefaultRect = false; @@ -247,7 +247,7 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl } if (registerOwner != nullptr && !_decoration) { - if (zoomX == DEFAULT_ZOOM_X && zoomY == DEFAULT_ZOOM_Y) { + if (zoomX == kDefaultZoomX && zoomY == kDefaultZoomY) { BaseEngine::getRenderer()->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, x - _hotspotX + getRect().left, y - _hotspotY + getRect().top, getRect().right - getRect().left, getRect().bottom - getRect().top, zoomX, zoomY, precise)); } else { BaseEngine::getRenderer()->addRectToList(new BaseActiveRect(_gameRef, registerOwner, this, (int)(x - (_hotspotX + getRect().left) * (zoomX / 100)), (int)(y - (_hotspotY + getRect().top) * (zoomY / 100)), (int)((getRect().right - getRect().left) * (zoomX / 100)), (int)((getRect().bottom - getRect().top) * (zoomY / 100)), zoomX, zoomY, precise)); @@ -260,11 +260,11 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl bool res; //if (Alpha==0xFFFFFFFF) Alpha = _alpha; // TODO: better (combine owner's and self alpha) - if (_alpha != DEFAULT_RGBAMOD) { + if (_alpha != kDefaultRgbaMod) { alpha = _alpha; } - if (rotate != DEFAULT_ANGLE) { + if (rotate != kDefaultAngle) { Point32 boxOffset, rotatedHotspot, hotspotOffset, newOrigin; Point32 origin(x, y); Rect32 oldRect = getRect(); @@ -274,10 +274,10 @@ bool BaseSubFrame::draw(int x, int y, BaseObject *registerOwner, float zoomX, fl newOrigin = origin - newHotspot; res = _surface->displayTransform(newOrigin.x, newOrigin.y, oldRect, newRect, transform); } else { - if (zoomX == DEFAULT_ZOOM_X && zoomY == DEFAULT_ZOOM_Y) { + if (zoomX == kDefaultZoomX && zoomY == kDefaultZoomY) { res = _surface->displayTrans(x - _hotspotX, y - _hotspotY, getRect(), alpha, blendMode, _mirrorX, _mirrorY); } else { - res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / DEFAULT_ZOOM_X)), (int)(y - _hotspotY * (zoomY / DEFAULT_ZOOM_Y)), getRect(), zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY); + res = _surface->displayTransZoom((int)(x - _hotspotX * (zoomX / kDefaultZoomX)), (int)(y - _hotspotY * (zoomY / kDefaultZoomY)), getRect(), zoomX, zoomY, alpha, blendMode, _mirrorX, _mirrorY); } } diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index 02f7f991e1..e01a669a2c 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -321,20 +321,20 @@ bool BaseSurfaceOSystem::endPixelOp() { ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { _rotation = 0; - return drawSprite(x, y, &rect, nullptr, TransformStruct(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y, mirrorX, mirrorY)); + return drawSprite(x, y, &rect, nullptr, TransformStruct(kDefaultZoomX, kDefaultZoomY, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTrans(int x, int y, Rect32 rect, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { _rotation = 0; - return drawSprite(x, y, &rect, nullptr, TransformStruct(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y, blendMode, alpha, mirrorX, mirrorY)); + return drawSprite(x, y, &rect, nullptr, TransformStruct(kDefaultZoomX, kDefaultZoomY, blendMode, alpha, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// bool BaseSurfaceOSystem::displayTransOffset(int x, int y, Rect32 rect, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY, int offsetX, int offsetY) { _rotation = 0; - return drawSprite(x, y, &rect, nullptr, TransformStruct(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y, DEFAULT_ANGLE, DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y, blendMode, alpha, mirrorX, mirrorY, offsetX, offsetY)); + return drawSprite(x, y, &rect, nullptr, TransformStruct(kDefaultZoomX, kDefaultZoomY, kDefaultAngle, kDefaultHotspotX, kDefaultHotspotY, blendMode, alpha, mirrorX, mirrorY, offsetX, offsetY)); } ////////////////////////////////////////////////////////////////////////// @@ -349,7 +349,7 @@ bool BaseSurfaceOSystem::displayZoom(int x, int y, Rect32 rect, float zoomX, flo _rotation = 0; TransformStruct transform; if (transparent) { - transform = TransformStruct(zoomX, zoomY, DEFAULT_ANGLE, DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y, blendMode, alpha, mirrorX, mirrorY); + transform = TransformStruct(zoomX, zoomY, kDefaultAngle, kDefaultHotspotX, kDefaultHotspotY, blendMode, alpha, mirrorX, mirrorY); } else { transform = TransformStruct(zoomX, zoomY, mirrorX, mirrorY); } @@ -414,8 +414,8 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, position.setWidth(newRect->width()); position.setHeight(newRect->height()); } else { - position.setWidth((int16)((float)srcRect.width() * transform._zoom.x / DEFAULT_ZOOM_X)); - position.setHeight((int16)((float)srcRect.height() * transform._zoom.y / DEFAULT_ZOOM_Y)); + position.setWidth((int16)((float)srcRect.width() * transform._zoom.x / kDefaultZoomX)); + position.setHeight((int16)((float)srcRect.height() * transform._zoom.y / kDefaultZoomY)); } renderer->modTargetRect(&position); diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h index 2e2da3c289..8f38128039 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h @@ -51,11 +51,11 @@ public: bool endPixelOp() override; - bool displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = DEFAULT_RGBAMOD, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = DEFAULT_RGBAMOD, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = DEFAULT_RGBAMOD, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override; + bool displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = kDefaultRgbaMod, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = kDefaultRgbaMod, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = kDefaultRgbaMod, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override; bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = DEFAULT_RGBAMOD, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = kDefaultRgbaMod, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) override; bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) override; virtual bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false) override; diff --git a/engines/wintermute/base/gfx/osystem/render_ticket.cpp b/engines/wintermute/base/gfx/osystem/render_ticket.cpp index 7f141aa460..091bb6e58a 100644 --- a/engines/wintermute/base/gfx/osystem/render_ticket.cpp +++ b/engines/wintermute/base/gfx/osystem/render_ticket.cpp @@ -51,7 +51,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s memcpy(_surface->getBasePtr(0, i), surf->getBasePtr(srcRect->left, srcRect->top + i), srcRect->width() * _surface->format.bytesPerPixel); } // Then scale it if necessary - if (_transform._angle != DEFAULT_ANGLE) { + if (_transform._angle != kDefaultAngle) { TransparentSurface src(*_surface, false); Graphics::Surface *temp = src.rotoscale(transform); _surface->free(); @@ -67,7 +67,7 @@ RenderTicket::RenderTicket(BaseSurfaceOSystem *owner, const Graphics::Surface *s } else { _surface = nullptr; - if (transform._angle != DEFAULT_ANGLE) { // Make sure comparison-tickets get the correct width + if (transform._angle != kDefaultAngle) { // Make sure comparison-tickets get the correct width Rect32 newDstRect; Point32 newHotspot; newDstRect = TransformTools::newRect(_srcRect, transform, &newHotspot); diff --git a/engines/wintermute/graphics/transform_struct.cpp b/engines/wintermute/graphics/transform_struct.cpp index c179d42ab1..8edbf765b5 100644 --- a/engines/wintermute/graphics/transform_struct.cpp +++ b/engines/wintermute/graphics/transform_struct.cpp @@ -51,14 +51,14 @@ TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 h TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, TSpriteBlendMode blendMode, uint32 rgbaMod, bool mirrorX, bool mirrorY) { init(Point32(zoomX, zoomY), - DEFAULT_ANGLE, - Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), + kDefaultAngle, + Point32(kDefaultHotspotX, kDefaultHotspotY), false, blendMode, rgbaMod, mirrorX, mirrorY, - Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); + Point32(kDefaultOffsetX, kDefaultOffsetY)); } TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 hotspotX, int32 hotspotY) { @@ -67,20 +67,20 @@ TransformStruct::TransformStruct(int32 zoomX, int32 zoomY, uint32 angle, int32 h Point32(hotspotX, hotspotY), true, BLEND_NORMAL, - DEFAULT_RGBAMOD, + kDefaultRgbaMod, false, false, - Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); + Point32(kDefaultOffsetX, kDefaultOffsetY)); } TransformStruct::TransformStruct() { - init(Point32(DEFAULT_ZOOM_X, DEFAULT_ZOOM_Y), - DEFAULT_ANGLE, - Point32(DEFAULT_HOTSPOT_X, DEFAULT_HOTSPOT_Y), + init(Point32(kDefaultZoomX, kDefaultZoomY), + kDefaultAngle, + Point32(kDefaultHotspotX, kDefaultHotspotY), true, BLEND_NORMAL, - DEFAULT_RGBAMOD, + kDefaultRgbaMod, false, false, - Point32(DEFAULT_OFFSET_X, DEFAULT_OFFSET_Y)); + Point32(kDefaultOffsetX, kDefaultOffsetY)); } bool TransformStruct::getMirrorX() const { diff --git a/engines/wintermute/graphics/transform_struct.h b/engines/wintermute/graphics/transform_struct.h index 6b021b5cd5..3fec9c0d0d 100644 --- a/engines/wintermute/graphics/transform_struct.h +++ b/engines/wintermute/graphics/transform_struct.h @@ -20,21 +20,21 @@ * */ -#ifndef GRAPHICS_TRANSFORM_STRUCT_H -#define GRAPHICS_TRANSFORM_STRUCT_H +#ifndef WINTERMUTE_TRANSFORM_STRUCT_H +#define WINTERMUTE_TRANSFORM_STRUCT_H #include "engines/wintermute/math/rect32.h" #include "engines/wintermute/dctypes.h" -#define DEFAULT_ZOOM_X 100.0 -#define DEFAULT_ZOOM_Y 100.0 -#define DEFAULT_RGBAMOD 0xFFFFFFFF -#define DEFAULT_HOTSPOT_X 0 -#define DEFAULT_HOTSPOT_Y 0 -#define DEFAULT_OFFSET_X 0 -#define DEFAULT_OFFSET_Y 0 -#define DEFAULT_ANGLE 0 - +const float kDefaultZoomX = 100.0; +const float kDefaultZoomY = 100.0; +const uint32 kDefaultRgbaMod = 0xFFFFFFFF; +const int32 kDefaultHotspotX = 0; +const int32 kDefaultHotspotY = 0; +const int32 kDefaultOffsetX = 0; +const int32 kDefaultOffsetY = 0; +const int32 kDefaultAngle = 0; + namespace Wintermute { /** * Contains all the required information that define a transform. diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 01e8b486ce..1ba48433ef 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -29,8 +29,8 @@ namespace Wintermute { FloatPoint TransformTools::transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX, const bool mirrorY) { float rotateRad = rotate * M_PI / 180; FloatPoint newPoint; - newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/DEFAULT_ZOOM_X; - newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/DEFAULT_ZOOM_Y; + newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/kDefaultZoomX; + newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/kDefaultZoomY; if (mirrorX) { newPoint.x *= -1; } -- cgit v1.2.3 From 0d407fd2066fb94d19e7fd7e4bf703dd68d34ec9 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 22:59:57 +0200 Subject: WINTERMUTE: Express 180.0f as float in TransformTools --- engines/wintermute/graphics/transform_tools.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 1ba48433ef..52e6a51296 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -27,7 +27,7 @@ namespace Wintermute { FloatPoint TransformTools::transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX, const bool mirrorY) { - float rotateRad = rotate * M_PI / 180; + float rotateRad = rotate * M_PI / 180.0f; FloatPoint newPoint; newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/kDefaultZoomX; newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/kDefaultZoomY; -- cgit v1.2.3 From aeb4c0953805185ab70ceecb8e38b3b47c4322d9 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 23:29:55 +0200 Subject: WINTERMUTE: Doxygen comments in TransformStruct --- engines/wintermute/graphics/transform_tools.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h index a9eabffe26..0d81fb66da 100644 --- a/engines/wintermute/graphics/transform_tools.h +++ b/engines/wintermute/graphics/transform_tools.h @@ -36,8 +36,12 @@ public: static FloatPoint transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX = false, const bool mirrorY = false); /** - * Takes a rectangle, a transform and a pointer to a point, "newHotspot". - * In return you get the smallest rect that can contain the transformed sprite + * @param &point the point on which the transform is to be applied + * @param rotate the angle in degrees + * @param &zoom zoom x,y in percent + * @param mirrorX flip along the vertical axis? + * @param mirrorY flip along the horizontal axis? + * @return the smallest rect that can contain the transformed sprite * and, as a side-effect, "newHotspot" will tell you where the hotspot will * have ended up in the new rect, for centering. */ -- cgit v1.2.3 From 1ecdd2d61ad6dcf809c0cfaa37e7d9bbceb6bad3 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Mon, 15 Jul 2013 22:39:55 +0200 Subject: WINTERMUTE: #define to const for TransformStruct defaults --- engines/wintermute/graphics/transform_struct.h | 4 ++-- engines/wintermute/graphics/transform_tools.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_struct.h b/engines/wintermute/graphics/transform_struct.h index 3fec9c0d0d..0ca7e9167d 100644 --- a/engines/wintermute/graphics/transform_struct.h +++ b/engines/wintermute/graphics/transform_struct.h @@ -26,8 +26,8 @@ #include "engines/wintermute/math/rect32.h" #include "engines/wintermute/dctypes.h" -const float kDefaultZoomX = 100.0; -const float kDefaultZoomY = 100.0; +const uint32 kDefaultZoomX = 100; +const uint32 kDefaultZoomY = 100; const uint32 kDefaultRgbaMod = 0xFFFFFFFF; const int32 kDefaultHotspotX = 0; const int32 kDefaultHotspotY = 0; diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 52e6a51296..73f48402f4 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -29,8 +29,8 @@ namespace Wintermute { FloatPoint TransformTools::transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX, const bool mirrorY) { float rotateRad = rotate * M_PI / 180.0f; FloatPoint newPoint; - newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad))*zoom.x/kDefaultZoomX; - newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad))*zoom.y/kDefaultZoomY; + newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad)) * zoom.x / kDefaultZoomX; + newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad)) * zoom.y / kDefaultZoomY; if (mirrorX) { newPoint.x *= -1; } -- cgit v1.2.3 From f872d316784b43e394e3c7c3490181fd465b7ba0 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 16 Jul 2013 01:05:08 +0200 Subject: WINTERMUTE: Fix type-related warnings in base_surface_osystem.cpp --- .../wintermute/base/gfx/osystem/base_surface_osystem.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index e01a669a2c..e90df52e38 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -361,9 +361,9 @@ bool BaseSurfaceOSystem::displayZoom(int x, int y, Rect32 rect, float zoomX, flo bool BaseSurfaceOSystem::displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) { _rotation = (uint32)transform._angle; if (transform._angle < 0.0f) { - warning("Negative rotation: %f %d", transform._angle, _rotation); + warning("Negative rotation: %d %d", transform._angle, _rotation); _rotation = (uint32)(360.0f + transform._angle); - warning("Negative post rotation: %f %d", transform._angle, _rotation); + warning("Negative post rotation: %d %d", transform._angle, _rotation); } return drawSprite(x, y, &rect, &newRect, transform); } @@ -423,12 +423,13 @@ bool BaseSurfaceOSystem::drawSprite(int x, int y, Rect32 *rect, Rect32 *newRect, // But no checking is in place for that yet. // TODO: Optimize by not doing alpha-blits if we lack or disable alpha - bool hasAlpha; + + bool hasAlpha = false; + if (_hasAlpha && !transform._alphaDisable) { hasAlpha = true; - } else { - hasAlpha = false; - } + } + if (transform._alphaDisable) { warning("BaseSurfaceOSystem::drawSprite - AlphaDisable ignored"); } -- cgit v1.2.3 From 566495de3b62c135767a3bf473e5a52d190caa15 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 16 Jul 2013 02:15:57 +0200 Subject: WINTERMUTE: Remove unused variable in transparent_surface.cpp --- engines/wintermute/graphics/transparent_surface.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 48d550c26f..7aa25d1502 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -106,8 +106,6 @@ void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, i float q21y = (y2 - projY); float q12x = (x2 - projX); float q12y = (projY - y1); - float q22x = (projX - x1); - float q22y = (projY - y1); if (x1 == x2 && y1 == y2) { for (int c = 0; c < 4; c++) { @@ -119,12 +117,10 @@ void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, i q11x = 0.5; q12x = 0.5; q21x = 0.5; - q22x = 0.5; } else if (y1 == y2) { q11y = 0.5; q12y = 0.5; q21y = 0.5; - q22y = 0.5; } for (int c = 0; c < 4; c++) { -- cgit v1.2.3 From 567cd1eb123357fe474066fd73328bb2aeab42ca Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 16 Jul 2013 22:05:40 +0200 Subject: WINTERMUTE: zoom parameter in display*** is now integer --- engines/wintermute/base/gfx/base_surface.h | 4 ++-- engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp | 4 ++-- engines/wintermute/base/gfx/osystem/base_surface_osystem.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/base_surface.h b/engines/wintermute/base/gfx/base_surface.h index 016831fb29..e308b29996 100644 --- a/engines/wintermute/base/gfx/base_surface.h +++ b/engines/wintermute/base/gfx/base_surface.h @@ -50,12 +50,12 @@ public: virtual bool displayHalfTrans(int x, int y, Rect32 rect); virtual bool isTransparentAt(int x, int y); - virtual bool displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; + virtual bool displayTransZoom(int x, int y, Rect32 rect, int32 zoomX, int32 zoomY, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = 0xFFFFFFFF, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) = 0; virtual bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) = 0; - virtual bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; + virtual bool displayZoom(int x, int y, Rect32 rect, int32 zoomX, int32 zoomY, uint32 alpha = 0xFFFFFFFF, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) = 0; virtual bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) = 0; virtual bool restore(); virtual bool create(const Common::String &filename, bool defaultCK, byte ckRed, byte ckGreen, byte ckBlue, int lifeTime = -1, bool keepLoaded = false) = 0; diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp index e90df52e38..e0b7aea5a3 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.cpp @@ -338,14 +338,14 @@ bool BaseSurfaceOSystem::displayTransOffset(int x, int y, Rect32 rect, uint32 al } ////////////////////////////////////////////////////////////////////////// -bool BaseSurfaceOSystem::displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { +bool BaseSurfaceOSystem::displayTransZoom(int x, int y, Rect32 rect, int32 zoomX, int32 zoomY, uint32 alpha, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { _rotation = 0; return drawSprite(x, y, &rect, nullptr, TransformStruct(zoomX, zoomY, blendMode, alpha, mirrorX, mirrorY)); } ////////////////////////////////////////////////////////////////////////// -bool BaseSurfaceOSystem::displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha, bool transparent, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { +bool BaseSurfaceOSystem::displayZoom(int x, int y, Rect32 rect, int32 zoomX, int32 zoomY, uint32 alpha, bool transparent, TSpriteBlendMode blendMode, bool mirrorX, bool mirrorY) { _rotation = 0; TransformStruct transform; if (transparent) { diff --git a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h index 8f38128039..5290170db8 100644 --- a/engines/wintermute/base/gfx/osystem/base_surface_osystem.h +++ b/engines/wintermute/base/gfx/osystem/base_surface_osystem.h @@ -51,11 +51,11 @@ public: bool endPixelOp() override; - bool displayTransZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = kDefaultRgbaMod, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayTransZoom(int x, int y, Rect32 rect, int32 zoomX, int32 zoomY, uint32 alpha = kDefaultRgbaMod, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; bool displayTrans(int x, int y, Rect32 rect, uint32 alpha = kDefaultRgbaMod, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; bool displayTransOffset(int x, int y, Rect32 rect, uint32 alpha = kDefaultRgbaMod, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false, int offsetX = 0, int offsetY = 0) override; bool display(int x, int y, Rect32 rect, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; - bool displayZoom(int x, int y, Rect32 rect, float zoomX, float zoomY, uint32 alpha = kDefaultRgbaMod, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; + bool displayZoom(int x, int y, Rect32 rect, int32 zoomX, int32 zoomY, uint32 alpha = kDefaultRgbaMod, bool transparent = false, TSpriteBlendMode blendMode = BLEND_NORMAL, bool mirrorX = false, bool mirrorY = false) override; bool displayTransform(int x, int y, Rect32 rect, Rect32 newRect, const TransformStruct &transform) override; bool repeatLastDisplayOp(int offsetX, int offsetY, int numTimesX, int numTimesY) override; virtual bool putSurface(const Graphics::Surface &surface, bool hasAlpha = false) override; -- cgit v1.2.3 From 381df0c64ac88a704f931b0011d7f3f730c5caba Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 16 Jul 2013 22:08:40 +0200 Subject: WINTERMUTE: Various explicit casts * for floor/ceil output in transform_tools.cpp * for projX/Y in transparent_surface.cpp * in transpaprent_surface.cpp --- engines/wintermute/graphics/transform_tools.cpp | 12 ++++++------ engines/wintermute/graphics/transparent_surface.cpp | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index 73f48402f4..ff90707615 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -60,13 +60,13 @@ namespace Wintermute { float right = MAX(nw1.x, MAX(ne1.x, MAX(sw1.x, se1.x))); Rect32 res; - newHotspot->y = -floor(top); - newHotspot->x = -floor(left); + newHotspot->y = (uint32)(-floor(top)); + newHotspot->x = (uint32)(-floor(left)); - res.top = floor(top) + transform._hotspot.y; - res.bottom = ceil(bottom) + transform._hotspot.y; - res.left = floor(left) + transform._hotspot.x; - res.right = ceil(right) + transform._hotspot.x; + res.top = (int32)(floor(top)) + transform._hotspot.y; + res.bottom = (int32)(ceil(bottom)) + transform._hotspot.y; + res.left = (int32)(floor(left)) + transform._hotspot.x; + res.right = (int32)(ceil(right)) + transform._hotspot.x; return res; } diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 7aa25d1502..49ac2bdc5a 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -45,7 +45,7 @@ void TransparentSurface::copyPixelNearestNeighbor(float projX, float projY, int if (projX >= srcW || projX < 0 || projY >= srcH || projY < 0) { color = 0; } else { - color = READ_UINT32((const byte *)src->getBasePtr(projX, projY)); + color = READ_UINT32((const byte *)src->getBasePtr((int)projX, (int)projY)); } WRITE_UINT32((byte *)dst->getBasePtr(dstX, dstY), color); @@ -71,25 +71,25 @@ void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, i if (x1 >= srcW || x1 < 0 || y1 >= srcH || y1 < 0) { Q11 = 0; } else { - Q11 = READ_UINT32((const byte *)src->getBasePtr(x1 + srcRect.left, y1 + srcRect.top)); + Q11 = READ_UINT32((const byte *)src->getBasePtr((int)(x1 + srcRect.left),(int)(y1 + srcRect.top))); } if (x1 >= srcW || x1 < 0 || y2 >= srcH || y2 < 0) { Q12 = 0; } else { - Q12 = READ_UINT32((const byte *)src->getBasePtr(x1 + srcRect.left, y2 + srcRect.top)); + Q12 = READ_UINT32((const byte *)src->getBasePtr((int)(x1 + srcRect.left), (int)(y2 + srcRect.top))); } if (x2 >= srcW || x2 < 0 || y1 >= srcH || y1 < 0) { Q21 = 0; } else { - Q21 = READ_UINT32((const byte *)src->getBasePtr(x2 + srcRect.left, y1 + srcRect.top)); + Q21 = READ_UINT32((const byte *)src->getBasePtr((int)(x2 + srcRect.left), (int)(y1 + srcRect.top))); } if (x2 >= srcW || x2 < 0 || y2 >= srcH || y2 < 0) { Q22 = 0; } else { - Q22 = READ_UINT32((const byte *)src->getBasePtr(x2 + srcRect.left, y2 + srcRect.top)); + Q22 = READ_UINT32((const byte *)src->getBasePtr((int)(x2 + srcRect.left), (int)(y2 + srcRect.top))); } byte *Q11s = (byte *)&Q11; @@ -124,7 +124,7 @@ void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, i } for (int c = 0; c < 4; c++) { - dest[c] = ( + dest[c] = (byte)( ((float)Q11s[c]) * q11x * q11y + ((float)Q21s[c]) * q21x * q21y + ((float)Q12s[c]) * q12x * q12y + @@ -580,8 +580,8 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) int projY; for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { - projX = x / (float)dstW * srcW; - projY = y / (float)dstH * srcH; + projX = (int)(x / (float)dstW * srcW); + projY = (int)(y / (float)dstH * srcH); copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); } } -- cgit v1.2.3 From 86c8d238a4c14dd26b251a1662473b38cfaa1cdc Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Tue, 16 Jul 2013 22:44:29 +0200 Subject: WINTERMUTE: const Common::Rect rect& in rect32.h --- engines/wintermute/math/rect32.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wintermute/math/rect32.h b/engines/wintermute/math/rect32.h index 821df1880e..79d6e80017 100644 --- a/engines/wintermute/math/rect32.h +++ b/engines/wintermute/math/rect32.h @@ -64,7 +64,7 @@ struct Rect32 { Rect32() : top(0), left(0), bottom(0), right(0) {} Rect32(int32 w, int32 h) : top(0), left(0), bottom(h), right(w) {} - Rect32(Common::Rect rect) : top(rect.top), left(rect.left), bottom(rect.bottom), right(rect.right) {} + Rect32(const Common::Rect &rect) : top(rect.top), left(rect.left), bottom(rect.bottom), right(rect.right) {} Rect32(int32 x1, int32 y1, int32 x2, int32 y2) : top(y1), left(x1), bottom(y2), right(x2) { assert(isValidRect()); } -- cgit v1.2.3 From 1a8a9bab861402e81dd2e5407182f3c0a7cc479b Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 17 Jul 2013 02:14:48 +0200 Subject: WINTERMUTE: Compile bilinear copy only if needed --- engines/wintermute/graphics/transparent_surface.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 49ac2bdc5a..534e51684e 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -31,6 +31,8 @@ namespace Wintermute { + +#ifndef ENABLE_BILINEAR void TransparentSurface::copyPixelNearestNeighbor(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { int srcW = srcRect.width(); int srcH = srcRect.height(); @@ -50,7 +52,9 @@ void TransparentSurface::copyPixelNearestNeighbor(float projX, float projY, int WRITE_UINT32((byte *)dst->getBasePtr(dstX, dstY), color); } +#endif +#ifdef ENABLE_BILINEAR void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { int srcW = srcRect.width(); @@ -137,6 +141,7 @@ void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, i } WRITE_UINT32((byte *)dst->getBasePtr(dstX + dstRect.left, dstY + dstRect.top), color); } +#endif byte *TransparentSurface::_lookup = nullptr; -- cgit v1.2.3 From 14d151ab31d8163f3e7dc943be191c3a98bd4f6b Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Wed, 17 Jul 2013 23:37:21 +0200 Subject: WINTERMUTE: Fix #ifdef in transparent_surface.[h|cpp] --- .../wintermute/graphics/transparent_surface.cpp | 46 +++++++++++----------- engines/wintermute/graphics/transparent_surface.h | 4 +- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 534e51684e..4eabc356b4 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -32,28 +32,6 @@ namespace Wintermute { -#ifndef ENABLE_BILINEAR -void TransparentSurface::copyPixelNearestNeighbor(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { - int srcW = srcRect.width(); - int srcH = srcRect.height(); - int dstW = dstRect.width(); - int dstH = dstRect.height(); - - assert(dstX >= 0 && dstX < dstW); - assert(dstY >= 0 && dstY < dstH); - - uint32 color; - - if (projX >= srcW || projX < 0 || projY >= srcH || projY < 0) { - color = 0; - } else { - color = READ_UINT32((const byte *)src->getBasePtr((int)projX, (int)projY)); - } - - WRITE_UINT32((byte *)dst->getBasePtr(dstX, dstY), color); -} -#endif - #ifdef ENABLE_BILINEAR void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { @@ -141,6 +119,26 @@ void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, i } WRITE_UINT32((byte *)dst->getBasePtr(dstX + dstRect.left, dstY + dstRect.top), color); } +#else +void TransparentSurface::copyPixelNearestNeighbor(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { + int srcW = srcRect.width(); + int srcH = srcRect.height(); + int dstW = dstRect.width(); + int dstH = dstRect.height(); + + assert(dstX >= 0 && dstX < dstW); + assert(dstY >= 0 && dstY < dstH); + + uint32 color; + + if (projX >= srcW || projX < 0 || projY >= srcH || projY < 0) { + color = 0; + } else { + color = READ_UINT32((const byte *)src->getBasePtr((int)projX, (int)projY)); + } + + WRITE_UINT32((byte *)dst->getBasePtr(dstX, dstY), color); +} #endif byte *TransparentSurface::_lookup = nullptr; @@ -520,7 +518,7 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo float targX; float targY; -#if ENABLE_BILINEAR +#ifdef ENABLE_BILINEAR for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { int x1 = x - newHotspot.x; @@ -570,7 +568,7 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) target->create((uint16)dstW, (uint16)dstH, this->format); -#if ENABLE_BILINEAR +#ifdef ENABLE_BILINEAR float projX; float projY; for (int y = 0; y < dstH; y++) { diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index 71c139a76a..7182967aa6 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -53,9 +53,11 @@ struct TransparentSurface : public Graphics::Surface { void setColorKey(char r, char g, char b); void disableColorKey(); +#ifdef ENABLE_BILINEAR static void copyPixelBilinear(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); +#else static void copyPixelNearestNeighbor(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); - +#endif // Enums /** @brief The possible flipping parameters for the blit methode. -- cgit v1.2.3 From d83e4e1268e7422abd6f00463065f6e12fea15f7 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 18 Jul 2013 16:03:06 +0200 Subject: WINTERMUTE: FActor out TransformStruc initialization in repeatLastDraw loop --- engines/wintermute/base/gfx/osystem/base_render_osystem.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index 06cf531a9e..58bd8d34e1 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -371,12 +371,13 @@ void BaseRenderOSystem::repeatLastDraw(int offsetX, int offsetY, int numTimesX, int initLeft = dstRect.left; int initRight = dstRect.right; + TransformStruct temp = TransformStruct(kDefaultZoomX, kDefaultZoomY, kDefaultAngle, kDefaultHotspotX, kDefaultHotspotY, BLEND_NORMAL, kDefaultRgbaMod, false, false, kDefaultOffsetX, kDefaultOffsetY); + for (int i = 0; i < numTimesY; i++) { if (i == 0) { dstRect.translate(offsetX, 0); } for (int j = (i == 0 ? 1 : 0); j < numTimesX; j++) { - TransformStruct temp = TransformStruct(); drawSurface(origTicket->_owner, origTicket->getSurface(), &srcRect, &dstRect, temp); dstRect.translate(offsetX, 0); } -- cgit v1.2.3 From 56aa1297d13304666aa91cc57a5da88f3aa20b5f Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 18 Jul 2013 16:05:23 +0200 Subject: WINTERMUTE: Bring consts inside namespace in transform_struct.h --- engines/wintermute/graphics/transform_struct.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_struct.h b/engines/wintermute/graphics/transform_struct.h index 0ca7e9167d..acde410e89 100644 --- a/engines/wintermute/graphics/transform_struct.h +++ b/engines/wintermute/graphics/transform_struct.h @@ -26,6 +26,13 @@ #include "engines/wintermute/math/rect32.h" #include "engines/wintermute/dctypes.h" +namespace Wintermute { +/** + * Contains all the required information that define a transform. + * Same source sprite + same TransformStruct = Same resulting sprite. + * Has a number of overloaded constructors to accomodate various argument lists. + */ + const uint32 kDefaultZoomX = 100; const uint32 kDefaultZoomY = 100; const uint32 kDefaultRgbaMod = 0xFFFFFFFF; @@ -35,12 +42,6 @@ const int32 kDefaultOffsetX = 0; const int32 kDefaultOffsetY = 0; const int32 kDefaultAngle = 0; -namespace Wintermute { -/** - * Contains all the required information that define a transform. - * Same source sprite + same TransformStruct = Same resulting sprite. - * Has a number of overloaded constructors to accomodate various argument lists. - */ struct TransformStruct { private: void init(Point32 zoom, uint32 angle, Point32 hotspot, bool alphaDisable, TSpriteBlendMode blendMode, uint32 alpha, bool mirrorX, bool mirrorY, Point32 offset); -- cgit v1.2.3 From b5adcda94719792c15a2cb72e9c0ad191f8fa224 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 18 Jul 2013 16:12:01 +0200 Subject: WINTERMUTE: s/WINTERMUTE_TRANSFORMTOOLS_H/WINTERMUTE_TRANSFORM_TOOLS_H/ --- engines/wintermute/graphics/transform_tools.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h index 0d81fb66da..77b41a9045 100644 --- a/engines/wintermute/graphics/transform_tools.h +++ b/engines/wintermute/graphics/transform_tools.h @@ -20,8 +20,8 @@ * */ -#ifndef WINTERMUTE_TRANSFORMTOOLS_H -#define WINTERMUTE_TRANSFORMTOOLS_H +#ifndef WINTERMUTE_TRANSFORM_TOOLS_H +#define WINTERMUTE_TRANSFORM_TOOLS_H #include "engines/wintermute/math/rect32.h" #include "engines/wintermute/math/floatpoint.h" -- cgit v1.2.3 From 1c25eb24900445ba704e759239572a86ea88c3e1 Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 18 Jul 2013 16:32:42 +0200 Subject: WINTERMUTE: Formatting --- .../wintermute/graphics/transparent_surface.cpp | 35 +++++----------------- 1 file changed, 7 insertions(+), 28 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 4eabc356b4..3c64930fcb 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -518,38 +518,24 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo float targX; float targY; -#ifdef ENABLE_BILINEAR for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { int x1 = x - newHotspot.x; int y1 = y - newHotspot.y; - targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; - targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; + targX = ((x1 * invCos - y1 * invSin)) * kDefaultZoomX / transform._zoom.x + srcRect.left; + targY = ((x1 * invSin + y1 * invCos)) * kDefaultZoomY / transform._zoom.y + srcRect.top; targX += transform._hotspot.x; targY += transform._hotspot.y; +#ifdef ENABLE_BILINEAR copyPixelBilinear(targX, targY, x, y, srcRect, dstRect, this, target); - } - } #else - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - int x1 = x - newHotspot.x; - int y1 = y - newHotspot.y; - - targX = ((x1 * invCos - y1 * invSin)) * 100.0 / transform._zoom.x + srcRect.left; - targY = ((x1 * invSin + y1 * invCos)) * 100.0 / transform._zoom.y + srcRect.top; - - targX += transform._hotspot.x; - targY += transform._hotspot.y; - copyPixelNearestNeighbor(targX, targY, x, y, srcRect, dstRect, this, target); +#endif } } -#endif - return target; } @@ -568,27 +554,20 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) target->create((uint16)dstW, (uint16)dstH, this->format); -#ifdef ENABLE_BILINEAR + float projX; float projY; for (int y = 0; y < dstH; y++) { for (int x = 0; x < dstW; x++) { projX = x / (float)dstW * srcW; projY = y / (float)dstH * srcH; +#ifdef ENABLE_BILINEAR copyPixelBilinear(projX, projY, x, y, srcRect, dstRect, this, target); - } - } #else - int projX; - int projY; - for (int y = 0; y < dstH; y++) { - for (int x = 0; x < dstW; x++) { - projX = (int)(x / (float)dstW * srcW); - projY = (int)(y / (float)dstH * srcH); copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); +#endif } } -#endif return target; } -- cgit v1.2.3 From 204c75bc2733fb5b4251e73d6859398dd50f942a Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 18 Jul 2013 17:02:40 +0200 Subject: WINTERMUTE: s/255,255,255,255/kDefaultMod/ --- engines/wintermute/base/gfx/osystem/base_render_osystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines') diff --git a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp index 58bd8d34e1..866a8a1623 100644 --- a/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp +++ b/engines/wintermute/base/gfx/osystem/base_render_osystem.cpp @@ -60,7 +60,7 @@ BaseRenderOSystem::BaseRenderOSystem(BaseGame *inGame) : BaseRenderer(inGame) { _borderLeft = _borderRight = _borderTop = _borderBottom = 0; _ratioX = _ratioY = 1.0f; - _colorMod = 0xFFFFFFFF; + _colorMod = kDefaultRgbaMod; _dirtyRect = nullptr; _disableDirtyRects = false; _tempDisableDirtyRects = 0; -- cgit v1.2.3 From e3381cff0db4ebc8be62a2f7f2b228cd55cd23bc Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 1 Aug 2013 01:42:51 +0200 Subject: WINTERMUTE: #ifdef ENABLE_BILINEAR -> #if ENBABLE_BILINEAR --- engines/wintermute/graphics/transparent_surface.cpp | 6 +++--- engines/wintermute/graphics/transparent_surface.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transparent_surface.cpp b/engines/wintermute/graphics/transparent_surface.cpp index 3c64930fcb..5b7c416ee9 100644 --- a/engines/wintermute/graphics/transparent_surface.cpp +++ b/engines/wintermute/graphics/transparent_surface.cpp @@ -32,7 +32,7 @@ namespace Wintermute { -#ifdef ENABLE_BILINEAR +#if ENABLE_BILINEAR void TransparentSurface::copyPixelBilinear(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst) { int srcW = srcRect.width(); @@ -529,7 +529,7 @@ TransparentSurface *TransparentSurface::rotoscale(const TransformStruct &transfo targX += transform._hotspot.x; targY += transform._hotspot.y; -#ifdef ENABLE_BILINEAR +#if ENABLE_BILINEAR copyPixelBilinear(targX, targY, x, y, srcRect, dstRect, this, target); #else copyPixelNearestNeighbor(targX, targY, x, y, srcRect, dstRect, this, target); @@ -561,7 +561,7 @@ TransparentSurface *TransparentSurface::scale(uint16 newWidth, uint16 newHeight) for (int x = 0; x < dstW; x++) { projX = x / (float)dstW * srcW; projY = y / (float)dstH * srcH; -#ifdef ENABLE_BILINEAR +#if ENABLE_BILINEAR copyPixelBilinear(projX, projY, x, y, srcRect, dstRect, this, target); #else copyPixelNearestNeighbor(projX, projY, x, y, srcRect, dstRect, this, target); diff --git a/engines/wintermute/graphics/transparent_surface.h b/engines/wintermute/graphics/transparent_surface.h index 7182967aa6..7b5579f389 100644 --- a/engines/wintermute/graphics/transparent_surface.h +++ b/engines/wintermute/graphics/transparent_surface.h @@ -53,7 +53,7 @@ struct TransparentSurface : public Graphics::Surface { void setColorKey(char r, char g, char b); void disableColorKey(); -#ifdef ENABLE_BILINEAR +#if ENABLE_BILINEAR static void copyPixelBilinear(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); #else static void copyPixelNearestNeighbor(float projX, float projY, int dstX, int dstY, const Common::Rect &srcRect, const Common::Rect &dstRect, const TransparentSurface *src, TransparentSurface *dst); -- cgit v1.2.3 From c32769e0b7e63e9e9b8bf0fc7d4caa91554fa8ad Mon Sep 17 00:00:00 2001 From: Tobia Tesan Date: Thu, 1 Aug 2013 02:48:14 +0200 Subject: WINTERMUTE; Indentation in transform_* --- engines/wintermute/graphics/transform_tools.cpp | 71 +++++++++++++------------ engines/wintermute/graphics/transform_tools.h | 2 + 2 files changed, 38 insertions(+), 35 deletions(-) (limited to 'engines') diff --git a/engines/wintermute/graphics/transform_tools.cpp b/engines/wintermute/graphics/transform_tools.cpp index ff90707615..4f05e19a92 100644 --- a/engines/wintermute/graphics/transform_tools.cpp +++ b/engines/wintermute/graphics/transform_tools.cpp @@ -26,48 +26,49 @@ namespace Wintermute { - FloatPoint TransformTools::transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX, const bool mirrorY) { - float rotateRad = rotate * M_PI / 180.0f; - FloatPoint newPoint; - newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad)) * zoom.x / kDefaultZoomX; - newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad)) * zoom.y / kDefaultZoomY; - if (mirrorX) { - newPoint.x *= -1; - } - if (mirrorY) { - newPoint.y *= -1; - } - return newPoint; +FloatPoint TransformTools::transformPoint(const FloatPoint &point, const float rotate, const Point32 &zoom, const bool mirrorX, const bool mirrorY) { + float rotateRad = rotate * M_PI / 180.0f; + FloatPoint newPoint; + newPoint.x = (point.x * cos(rotateRad) - point.y * sin(rotateRad)) * zoom.x / kDefaultZoomX; + newPoint.y = (point.x * sin(rotateRad) + point.y * cos(rotateRad)) * zoom.y / kDefaultZoomY; + if (mirrorX) { + newPoint.x *= -1; } + if (mirrorY) { + newPoint.y *= -1; + } + return newPoint; +} - Rect32 TransformTools::newRect (const Rect32 &oldRect, const TransformStruct &transform, Point32 *newHotspot) { +Rect32 TransformTools::newRect (const Rect32 &oldRect, const TransformStruct &transform, Point32 *newHotspot) { - Point32 nw(oldRect.left, oldRect.top); - Point32 ne(oldRect.right, oldRect.top); - Point32 sw(oldRect.left, oldRect.bottom); - Point32 se(oldRect.right, oldRect.bottom); + Point32 nw(oldRect.left, oldRect.top); + Point32 ne(oldRect.right, oldRect.top); + Point32 sw(oldRect.left, oldRect.bottom); + Point32 se(oldRect.right, oldRect.bottom); - FloatPoint nw1, ne1, sw1, se1; + FloatPoint nw1, ne1, sw1, se1; - nw1 = transformPoint(nw - transform._hotspot, transform._angle, transform._zoom); - ne1 = transformPoint(ne - transform._hotspot, transform._angle, transform._zoom); - sw1 = transformPoint(sw - transform._hotspot, transform._angle, transform._zoom); - se1 = transformPoint(se - transform._hotspot, transform._angle, transform._zoom); + nw1 = transformPoint(nw - transform._hotspot, transform._angle, transform._zoom); + ne1 = transformPoint(ne - transform._hotspot, transform._angle, transform._zoom); + sw1 = transformPoint(sw - transform._hotspot, transform._angle, transform._zoom); + se1 = transformPoint(se - transform._hotspot, transform._angle, transform._zoom); - float top = MIN(nw1.y, MIN(ne1.y, MIN(sw1.y, se1.y))); - float bottom = MAX(nw1.y, MAX(ne1.y, MAX(sw1.y, se1.y))); - float left = MIN(nw1.x, MIN(ne1.x, MIN(sw1.x, se1.x))); - float right = MAX(nw1.x, MAX(ne1.x, MAX(sw1.x, se1.x))); + float top = MIN(nw1.y, MIN(ne1.y, MIN(sw1.y, se1.y))); + float bottom = MAX(nw1.y, MAX(ne1.y, MAX(sw1.y, se1.y))); + float left = MIN(nw1.x, MIN(ne1.x, MIN(sw1.x, se1.x))); + float right = MAX(nw1.x, MAX(ne1.x, MAX(sw1.x, se1.x))); - Rect32 res; - newHotspot->y = (uint32)(-floor(top)); - newHotspot->x = (uint32)(-floor(left)); + Rect32 res; + newHotspot->y = (uint32)(-floor(top)); + newHotspot->x = (uint32)(-floor(left)); - res.top = (int32)(floor(top)) + transform._hotspot.y; - res.bottom = (int32)(ceil(bottom)) + transform._hotspot.y; - res.left = (int32)(floor(left)) + transform._hotspot.x; - res.right = (int32)(ceil(right)) + transform._hotspot.x; + res.top = (int32)(floor(top)) + transform._hotspot.y; + res.bottom = (int32)(ceil(bottom)) + transform._hotspot.y; + res.left = (int32)(floor(left)) + transform._hotspot.x; + res.right = (int32)(ceil(right)) + transform._hotspot.x; + + return res; +} - return res; - } } // End of namespace Wintermute diff --git a/engines/wintermute/graphics/transform_tools.h b/engines/wintermute/graphics/transform_tools.h index 77b41a9045..e59c47272a 100644 --- a/engines/wintermute/graphics/transform_tools.h +++ b/engines/wintermute/graphics/transform_tools.h @@ -28,6 +28,7 @@ #include "engines/wintermute/graphics/transform_struct.h" namespace Wintermute { + class TransformTools { public: /** @@ -47,5 +48,6 @@ public: */ static Rect32 newRect (const Rect32 &oldRect, const TransformStruct &transform, Point32 *newHotspot); }; + } // End of namespace Wintermute #endif -- cgit v1.2.3