Lift 'Disposable' concept from core into bindings
Instead of replicating the RGSS Disposable interface in C++ and merely binding it, redefine the 'disposed' state as the entire core object being deleted (and the binding object's private pointer being null). This makes the behavior more accurate in regard to RMXP. It is now for example possible to subclass disposable classes and access their 'dispose'/'disposed?' methods without initializing the base class first (because the internal pointer is simply null before initialization). Accessing any other base methods will still raise an exception. There are some quirks and irregular behavior in RMXP; eg. most nullable bitmap attributes of disposable classes (Sprite, Plane etc.) can still be queried afterwards, but some cannot (Tilemap#tileset), and disposing certain attributes crashes RMXP entirely (Tilemap#autotiles[n]). mkxp tries to behave as close possible, but will be more lenient some circumstances. To the core, disposed bitmap attributes will look identically to null, which slightly diverges from RMXP (where they're treated as still existing, but aren't drawn). The Disposable interface has been retained containing a single signal, for the binding to inform core when objects are disposed (so active attributes can be set to null).
This commit is contained in:
parent
b7af8cc92f
commit
e858bbdcf5
38 changed files with 341 additions and 386 deletions
|
@ -44,8 +44,6 @@
|
|||
#include "font.h"
|
||||
#include "eventthread.h"
|
||||
|
||||
#define DISP_CLASS_NAME "bitmap"
|
||||
|
||||
#define GUARD_MEGA \
|
||||
{ \
|
||||
if (p->megaSurface) \
|
||||
|
@ -292,18 +290,21 @@ Bitmap::Bitmap(const Bitmap &other)
|
|||
|
||||
p->gl = shState->texPool().request(other.width(), other.height());
|
||||
|
||||
blt(0, 0, other, rect());
|
||||
blt(0, 0, &other, rect());
|
||||
}
|
||||
|
||||
Bitmap::~Bitmap()
|
||||
{
|
||||
dispose();
|
||||
if (p->megaSurface)
|
||||
SDL_FreeSurface(p->megaSurface);
|
||||
else
|
||||
shState->texPool().release(p->gl);
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
||||
int Bitmap::width() const
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
if (p->megaSurface)
|
||||
return p->megaSurface->w;
|
||||
|
||||
|
@ -312,8 +313,6 @@ int Bitmap::width() const
|
|||
|
||||
int Bitmap::height() const
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
if (p->megaSurface)
|
||||
return p->megaSurface->h;
|
||||
|
||||
|
@ -326,45 +325,49 @@ IntRect Bitmap::rect() const
|
|||
}
|
||||
|
||||
void Bitmap::blt(int x, int y,
|
||||
const Bitmap &source, IntRect rect,
|
||||
const Bitmap *source, IntRect rect,
|
||||
int opacity)
|
||||
{
|
||||
if (!source)
|
||||
return;
|
||||
|
||||
// FIXME: RGSS allows the source rect to both lie outside
|
||||
// the bitmap rect and be inverted in both directions;
|
||||
// clamping only covers a subset of these cases (and
|
||||
// doesn't fix anything for a direct stretch_blt call).
|
||||
|
||||
/* Clamp rect to source bitmap size */
|
||||
if (rect.x + rect.w > source.width())
|
||||
rect.w = source.width() - rect.x;
|
||||
if (rect.x + rect.w > source->width())
|
||||
rect.w = source->width() - rect.x;
|
||||
|
||||
if (rect.y + rect.h > source.height())
|
||||
rect.h = source.height() - rect.y;
|
||||
if (rect.y + rect.h > source->height())
|
||||
rect.h = source->height() - rect.y;
|
||||
|
||||
stretchBlt(IntRect(x, y, rect.w, rect.h),
|
||||
source, rect, opacity);
|
||||
}
|
||||
|
||||
void Bitmap::stretchBlt(const IntRect &destRect,
|
||||
const Bitmap &source, const IntRect &sourceRect,
|
||||
const Bitmap *source, const IntRect &sourceRect,
|
||||
int opacity)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
if (!source)
|
||||
return;
|
||||
|
||||
opacity = clamp(opacity, 0, 255);
|
||||
|
||||
if (opacity == 0)
|
||||
return;
|
||||
|
||||
if (source.megaSurface())
|
||||
if (source->megaSurface())
|
||||
{
|
||||
/* Don't do transparent blits for now */
|
||||
if (opacity < 255)
|
||||
source.ensureNonMega();
|
||||
source->ensureNonMega();
|
||||
|
||||
SDL_Surface *srcSurf = source.megaSurface();
|
||||
SDL_Surface *srcSurf = source->megaSurface();
|
||||
|
||||
SDL_Rect srcRect = sourceRect;
|
||||
SDL_Rect dstRect = destRect;
|
||||
|
@ -411,7 +414,7 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
|||
{
|
||||
/* Fast blit */
|
||||
GLMeta::blitBegin(p->gl);
|
||||
GLMeta::blitSource(source.p->gl);
|
||||
GLMeta::blitSource(source->p->gl);
|
||||
GLMeta::blitRectangle(sourceRect, destRect);
|
||||
GLMeta::blitEnd();
|
||||
}
|
||||
|
@ -427,10 +430,10 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
|||
GLMeta::blitRectangle(destRect, Vec2i());
|
||||
GLMeta::blitEnd();
|
||||
|
||||
FloatRect bltSubRect((float) sourceRect.x / source.width(),
|
||||
(float) sourceRect.y / source.height(),
|
||||
((float) source.width() / sourceRect.w) * ((float) destRect.w / gpTex.width),
|
||||
((float) source.height() / sourceRect.h) * ((float) destRect.h / gpTex.height));
|
||||
FloatRect bltSubRect((float) sourceRect.x / source->width(),
|
||||
(float) sourceRect.y / source->height(),
|
||||
((float) source->width() / sourceRect.w) * ((float) destRect.w / gpTex.width),
|
||||
((float) source->height() / sourceRect.h) * ((float) destRect.h / gpTex.height));
|
||||
|
||||
BltShader &shader = shState->shaders().blt;
|
||||
shader.bind();
|
||||
|
@ -442,7 +445,7 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
|||
quad.setTexPosRect(sourceRect, destRect);
|
||||
quad.setColor(Vec4(1, 1, 1, normOpacity));
|
||||
|
||||
source.p->bindTexture(shader);
|
||||
source->p->bindTexture(shader);
|
||||
p->bindFBO();
|
||||
p->pushSetViewport(shader);
|
||||
|
||||
|
@ -465,8 +468,6 @@ void Bitmap::fillRect(int x, int y,
|
|||
|
||||
void Bitmap::fillRect(const IntRect &rect, const Vec4 &color)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
p->fillRect(rect, color);
|
||||
|
@ -495,8 +496,6 @@ void Bitmap::gradientFillRect(const IntRect &rect,
|
|||
const Vec4 &color1, const Vec4 &color2,
|
||||
bool vertical)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
SimpleColorShader &shader = shState->shaders().simpleColor;
|
||||
|
@ -541,8 +540,6 @@ void Bitmap::clearRect(int x, int y, int width, int height)
|
|||
|
||||
void Bitmap::clearRect(const IntRect &rect)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
p->fillRect(rect, Vec4());
|
||||
|
@ -552,8 +549,6 @@ void Bitmap::clearRect(const IntRect &rect)
|
|||
|
||||
void Bitmap::blur()
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
Quad &quad = shState->gpQuad();
|
||||
|
@ -597,8 +592,6 @@ void Bitmap::blur()
|
|||
|
||||
void Bitmap::radialBlur(int angle, int divisions)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
angle = clamp<int>(angle, 0, 359);
|
||||
|
@ -694,8 +687,6 @@ void Bitmap::radialBlur(int angle, int divisions)
|
|||
|
||||
void Bitmap::clear()
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
p->bindFBO();
|
||||
|
@ -713,8 +704,6 @@ void Bitmap::clear()
|
|||
|
||||
Color Bitmap::getPixel(int x, int y) const
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
if (x < 0 || y < 0 || x >= width() || y >= height())
|
||||
|
@ -745,8 +734,6 @@ Color Bitmap::getPixel(int x, int y) const
|
|||
|
||||
void Bitmap::setPixel(int x, int y, const Color &color)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
uint8_t pixel[] =
|
||||
|
@ -767,8 +754,6 @@ void Bitmap::setPixel(int x, int y, const Color &color)
|
|||
|
||||
void Bitmap::hueChange(int hue)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
if ((hue % 360) == 0)
|
||||
|
@ -815,8 +800,6 @@ void Bitmap::drawText(int x, int y,
|
|||
|
||||
void Bitmap::drawText(const IntRect &rect, const char *str, int align)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
if (*str == '\0')
|
||||
|
@ -1042,8 +1025,6 @@ static uint16_t utf8_to_ucs2(const char *_input,
|
|||
|
||||
IntRect Bitmap::textSize(const char *str)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
GUARD_MEGA;
|
||||
|
||||
TTF_Font *font = p->font->getSdlFont();
|
||||
|
@ -1077,9 +1058,6 @@ SDL_Surface *Bitmap::megaSurface() const
|
|||
|
||||
void Bitmap::ensureNonMega() const
|
||||
{
|
||||
if (isDisposed())
|
||||
return;
|
||||
|
||||
GUARD_MEGA;
|
||||
}
|
||||
|
||||
|
@ -1092,13 +1070,3 @@ void Bitmap::taintArea(const IntRect &rect)
|
|||
{
|
||||
p->addTaintedArea(rect);
|
||||
}
|
||||
|
||||
void Bitmap::releaseResources()
|
||||
{
|
||||
if (p->megaSurface)
|
||||
SDL_FreeSurface(p->megaSurface);
|
||||
else
|
||||
shState->texPool().release(p->gl);
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
|
|
@ -49,11 +49,11 @@ public:
|
|||
IntRect rect() const;
|
||||
|
||||
void blt(int x, int y,
|
||||
const Bitmap &source, IntRect rect,
|
||||
const Bitmap *source, IntRect rect,
|
||||
int opacity = 255);
|
||||
|
||||
void stretchBlt(const IntRect &destRect,
|
||||
const Bitmap &source, const IntRect &sourceRect,
|
||||
const Bitmap *source, const IntRect &sourceRect,
|
||||
int opacity = 255);
|
||||
|
||||
void fillRect(int x, int y,
|
||||
|
@ -119,8 +119,6 @@ public:
|
|||
sigc::signal<void> modified;
|
||||
|
||||
private:
|
||||
void releaseResources();
|
||||
|
||||
BitmapPrivate *p;
|
||||
};
|
||||
|
||||
|
|
|
@ -25,39 +25,63 @@
|
|||
#include "exception.h"
|
||||
|
||||
#include <sigc++/signal.h>
|
||||
#include <sigc++/connection.h>
|
||||
|
||||
class Disposable
|
||||
{
|
||||
public:
|
||||
Disposable()
|
||||
: disposed(false)
|
||||
{}
|
||||
|
||||
virtual ~Disposable() {}
|
||||
|
||||
void dispose()
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
releaseResources();
|
||||
disposed = true;
|
||||
wasDisposed();
|
||||
}
|
||||
|
||||
bool isDisposed() const { return disposed; }
|
||||
|
||||
sigc::signal<void> wasDisposed;
|
||||
|
||||
protected:
|
||||
virtual void releaseResources() = 0;
|
||||
|
||||
private:
|
||||
bool disposed;
|
||||
};
|
||||
|
||||
/* Every cpp needs to define DISP_CLASS_NAME for itself (lowercase) */
|
||||
#define GUARD_DISPOSED \
|
||||
{ if (isDisposed()) throw Exception(Exception::RGSSError, "disposed %s", DISP_CLASS_NAME); }
|
||||
/* A helper struct which monitors the dispose signal of
|
||||
* properties, and automatically sets the prop pointer to
|
||||
* null. Can call an optional notify method when prop is
|
||||
* nulled */
|
||||
template<class C, typename P>
|
||||
struct DisposeWatch
|
||||
{
|
||||
typedef void (C::*NotifyFun)();
|
||||
|
||||
/* The object owning the prop (and this helper) */
|
||||
C *owner;
|
||||
/* Optional notify method */
|
||||
const NotifyFun notify;
|
||||
/* Location of the prop pointer inside the owner */
|
||||
P *&propLocation;
|
||||
sigc::connection dispCon;
|
||||
|
||||
DisposeWatch(C *owner, P *&propLocation, NotifyFun notify = 0)
|
||||
: owner(owner),
|
||||
notify(notify),
|
||||
propLocation(propLocation)
|
||||
{}
|
||||
|
||||
~DisposeWatch()
|
||||
{
|
||||
dispCon.disconnect();
|
||||
}
|
||||
|
||||
/* Call this when a new object was set for the prop */
|
||||
void update(Disposable *prop)
|
||||
{
|
||||
dispCon.disconnect();
|
||||
|
||||
if (!prop)
|
||||
return;
|
||||
|
||||
dispCon = prop->wasDisposed.connect
|
||||
(sigc::mem_fun(this, &DisposeWatch::onDisposed));
|
||||
}
|
||||
|
||||
private:
|
||||
void onDisposed()
|
||||
{
|
||||
dispCon.disconnect();
|
||||
propLocation = 0;
|
||||
|
||||
if (notify)
|
||||
(owner->*notify)();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // DISPOSABLE_H
|
||||
|
|
|
@ -45,6 +45,8 @@ static float fwrap(float value, float range)
|
|||
struct PlanePrivate
|
||||
{
|
||||
Bitmap *bitmap;
|
||||
DisposeWatch<PlanePrivate, Bitmap> bitmapWatch;
|
||||
|
||||
NormValue opacity;
|
||||
BlendType blendType;
|
||||
Color *color;
|
||||
|
@ -65,6 +67,7 @@ struct PlanePrivate
|
|||
|
||||
PlanePrivate()
|
||||
: bitmap(0),
|
||||
bitmapWatch(this, bitmap),
|
||||
opacity(255),
|
||||
blendType(BlendNormal),
|
||||
color(&tmp.color),
|
||||
|
@ -153,8 +156,6 @@ Plane::Plane(Viewport *viewport)
|
|||
onGeometryChange(scene->getGeometry());
|
||||
}
|
||||
|
||||
#define DISP_CLASS_NAME "plane"
|
||||
|
||||
DEF_ATTR_RD_SIMPLE(Plane, Bitmap, Bitmap*, p->bitmap)
|
||||
DEF_ATTR_RD_SIMPLE(Plane, OX, int, p->ox)
|
||||
DEF_ATTR_RD_SIMPLE(Plane, OY, int, p->oy)
|
||||
|
@ -168,14 +169,15 @@ DEF_ATTR_SIMPLE(Plane, Tone, Tone*, p->tone)
|
|||
|
||||
Plane::~Plane()
|
||||
{
|
||||
dispose();
|
||||
unlink();
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
||||
void Plane::setBitmap(Bitmap *value)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
p->bitmap = value;
|
||||
p->bitmapWatch.update(value);
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
|
@ -185,8 +187,6 @@ void Plane::setBitmap(Bitmap *value)
|
|||
|
||||
void Plane::setOX(int value)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
if (p->ox == value)
|
||||
return;
|
||||
|
||||
|
@ -196,8 +196,6 @@ void Plane::setOX(int value)
|
|||
|
||||
void Plane::setOY(int value)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
if (p->oy == value)
|
||||
return;
|
||||
|
||||
|
@ -207,8 +205,6 @@ void Plane::setOY(int value)
|
|||
|
||||
void Plane::setZoomX(float value)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
if (p->zoomX == value)
|
||||
return;
|
||||
|
||||
|
@ -218,8 +214,6 @@ void Plane::setZoomX(float value)
|
|||
|
||||
void Plane::setZoomY(float value)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
if (p->zoomY == value)
|
||||
return;
|
||||
|
||||
|
@ -229,8 +223,6 @@ void Plane::setZoomY(float value)
|
|||
|
||||
void Plane::setBlendType(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
switch (value)
|
||||
{
|
||||
default :
|
||||
|
@ -252,9 +244,6 @@ void Plane::draw()
|
|||
if (!p->bitmap)
|
||||
return;
|
||||
|
||||
if (p->bitmap->isDisposed())
|
||||
return;
|
||||
|
||||
if (!p->opacity)
|
||||
return;
|
||||
|
||||
|
@ -307,16 +296,3 @@ void Plane::onGeometryChange(const Scene::Geometry &geo)
|
|||
p->sceneGeo = geo;
|
||||
p->quadSourceDirty = true;
|
||||
}
|
||||
|
||||
void Plane::aboutToAccess() const
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
}
|
||||
|
||||
|
||||
void Plane::releaseResources()
|
||||
{
|
||||
unlink();
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
|
|
@ -52,9 +52,6 @@ private:
|
|||
|
||||
void draw();
|
||||
void onGeometryChange(const Scene::Geometry &);
|
||||
void aboutToAccess() const;
|
||||
|
||||
void releaseResources();
|
||||
};
|
||||
|
||||
#endif // PLANE_H
|
||||
|
|
|
@ -143,15 +143,11 @@ void SceneElement::setScene(Scene &scene)
|
|||
|
||||
int SceneElement::getZ() const
|
||||
{
|
||||
aboutToAccess();
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
void SceneElement::setZ(int value)
|
||||
{
|
||||
aboutToAccess();
|
||||
|
||||
if (z == value)
|
||||
return;
|
||||
|
||||
|
@ -161,15 +157,11 @@ void SceneElement::setZ(int value)
|
|||
|
||||
bool SceneElement::getVisible() const
|
||||
{
|
||||
aboutToAccess();
|
||||
|
||||
return visible;
|
||||
}
|
||||
|
||||
void SceneElement::setVisible(bool value)
|
||||
{
|
||||
aboutToAccess();
|
||||
|
||||
visible = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -78,10 +78,6 @@ public:
|
|||
DECL_ATTR_VIRT( Z, int )
|
||||
DECL_ATTR_VIRT( Visible, bool )
|
||||
|
||||
/* Disposable classes reimplement this to
|
||||
* check if they're disposed before access */
|
||||
virtual void aboutToAccess() const {}
|
||||
|
||||
protected:
|
||||
/* A bit about OpenGL state:
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
struct SpritePrivate
|
||||
{
|
||||
Bitmap *bitmap;
|
||||
DisposeWatch<SpritePrivate, Bitmap> bitmapWatch;
|
||||
|
||||
Quad quad;
|
||||
Transform trans;
|
||||
|
@ -88,6 +89,7 @@ struct SpritePrivate
|
|||
|
||||
SpritePrivate()
|
||||
: bitmap(0),
|
||||
bitmapWatch(this, bitmap),
|
||||
srcRect(&tmp.rect),
|
||||
mirrored(false),
|
||||
bushDepth(0),
|
||||
|
@ -165,9 +167,6 @@ struct SpritePrivate
|
|||
if (!bitmap)
|
||||
return;
|
||||
|
||||
if (bitmap->isDisposed())
|
||||
return;
|
||||
|
||||
if (!opacity)
|
||||
return;
|
||||
|
||||
|
@ -310,10 +309,10 @@ Sprite::Sprite(Viewport *viewport)
|
|||
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
unlink();
|
||||
|
||||
#define DISP_CLASS_NAME "sprite"
|
||||
delete p;
|
||||
}
|
||||
|
||||
DEF_ATTR_RD_SIMPLE(Sprite, Bitmap, Bitmap*, p->bitmap)
|
||||
DEF_ATTR_RD_SIMPLE(Sprite, SrcRect, Rect*, p->srcRect)
|
||||
|
@ -344,12 +343,11 @@ DEF_ATTR_RD_SIMPLE(Sprite, WavePhase, float, p->wave.phase)
|
|||
|
||||
void Sprite::setBitmap(Bitmap *bitmap)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->bitmap == bitmap)
|
||||
return;
|
||||
|
||||
p->bitmap = bitmap;
|
||||
p->bitmapWatch.update(bitmap);
|
||||
|
||||
if (!bitmap)
|
||||
return;
|
||||
|
@ -367,8 +365,6 @@ void Sprite::setBitmap(Bitmap *bitmap)
|
|||
|
||||
void Sprite::setSrcRect(Rect *rect)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->srcRect == rect)
|
||||
return;
|
||||
|
||||
|
@ -381,8 +377,6 @@ void Sprite::setSrcRect(Rect *rect)
|
|||
|
||||
void Sprite::setX(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->trans.getPosition().x == value)
|
||||
return;
|
||||
|
||||
|
@ -391,8 +385,6 @@ void Sprite::setX(int value)
|
|||
|
||||
void Sprite::setY(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->trans.getPosition().y == value)
|
||||
return;
|
||||
|
||||
|
@ -405,8 +397,6 @@ void Sprite::setY(int value)
|
|||
|
||||
void Sprite::setOX(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->trans.getOrigin().x == value)
|
||||
return;
|
||||
|
||||
|
@ -415,8 +405,6 @@ void Sprite::setOX(int value)
|
|||
|
||||
void Sprite::setOY(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->trans.getOrigin().y == value)
|
||||
return;
|
||||
|
||||
|
@ -425,8 +413,6 @@ void Sprite::setOY(int value)
|
|||
|
||||
void Sprite::setZoomX(float value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->trans.getScale().x == value)
|
||||
return;
|
||||
|
||||
|
@ -435,8 +421,6 @@ void Sprite::setZoomX(float value)
|
|||
|
||||
void Sprite::setZoomY(float value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->trans.getScale().y == value)
|
||||
return;
|
||||
|
||||
|
@ -450,8 +434,6 @@ void Sprite::setZoomY(float value)
|
|||
|
||||
void Sprite::setAngle(float value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->trans.getRotation() == value)
|
||||
return;
|
||||
|
||||
|
@ -460,8 +442,6 @@ void Sprite::setAngle(float value)
|
|||
|
||||
void Sprite::setMirror(bool mirrored)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->mirrored == mirrored)
|
||||
return;
|
||||
|
||||
|
@ -471,8 +451,6 @@ void Sprite::setMirror(bool mirrored)
|
|||
|
||||
void Sprite::setBushDepth(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->bushDepth == value)
|
||||
return;
|
||||
|
||||
|
@ -482,8 +460,6 @@ void Sprite::setBushDepth(int value)
|
|||
|
||||
void Sprite::setBlendType(int type)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
switch (type)
|
||||
{
|
||||
default :
|
||||
|
@ -504,7 +480,6 @@ void Sprite::setBlendType(int type)
|
|||
#define DEF_WAVE_SETTER(Name, name, type) \
|
||||
void Sprite::setWave##Name(type value) \
|
||||
{ \
|
||||
GUARD_DISPOSED; \
|
||||
if (p->wave.name == value) \
|
||||
return; \
|
||||
p->wave.name = value; \
|
||||
|
@ -529,14 +504,6 @@ void Sprite::update()
|
|||
|
||||
#endif
|
||||
|
||||
/* Disposable */
|
||||
void Sprite::releaseResources()
|
||||
{
|
||||
unlink();
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
||||
/* SceneElement */
|
||||
void Sprite::draw()
|
||||
{
|
||||
|
|
|
@ -75,8 +75,6 @@ private:
|
|||
|
||||
void draw();
|
||||
void onGeometryChange(const Scene::Geometry &);
|
||||
|
||||
void releaseResources();
|
||||
};
|
||||
|
||||
#endif // SPRITE_H
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include "tileatlas.h"
|
||||
|
||||
#include <sigc++/connection.h>
|
||||
#include <sigc++/bind.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
@ -241,6 +242,8 @@ struct TilemapPrivate
|
|||
Bitmap *autotiles[autotileCount];
|
||||
|
||||
Bitmap *tileset;
|
||||
DisposeWatch<TilemapPrivate, Bitmap> tilesetWatch;
|
||||
|
||||
Table *mapData;
|
||||
Table *flashData;
|
||||
Table *priorities;
|
||||
|
@ -352,6 +355,7 @@ struct TilemapPrivate
|
|||
TilemapPrivate(Viewport *viewport)
|
||||
: viewport(viewport),
|
||||
tileset(0),
|
||||
tilesetWatch(this, tileset),
|
||||
mapData(0),
|
||||
flashData(0),
|
||||
priorities(0),
|
||||
|
@ -439,7 +443,7 @@ struct TilemapPrivate
|
|||
|
||||
void updateAtlasInfo()
|
||||
{
|
||||
if (!tileset || tileset->isDisposed())
|
||||
if (!tileset)
|
||||
{
|
||||
atlas.size = Vec2i();
|
||||
return;
|
||||
|
@ -468,9 +472,6 @@ struct TilemapPrivate
|
|||
if (!autotiles[i])
|
||||
continue;
|
||||
|
||||
if (autotiles[i]->isDisposed())
|
||||
continue;
|
||||
|
||||
if (autotiles[i]->megaSurface())
|
||||
continue;
|
||||
|
||||
|
@ -516,15 +517,22 @@ struct TilemapPrivate
|
|||
flashDirty = true;
|
||||
}
|
||||
|
||||
void onAutotileDisposed(int i)
|
||||
{
|
||||
/* RMXP actually crashes if an active autotile bitmap is disposed..
|
||||
* let's not crash ourselves, for consistency's sake */
|
||||
autotiles[i] = 0;
|
||||
autotilesCon[i].disconnect();
|
||||
autotilesDispCon[i].disconnect();
|
||||
atlasDirty = true;
|
||||
}
|
||||
|
||||
/* Checks for the minimum amount of data needed to display */
|
||||
bool verifyResources()
|
||||
{
|
||||
if (!tileset)
|
||||
return false;
|
||||
|
||||
if (tileset->isDisposed())
|
||||
return false;
|
||||
|
||||
if (!mapData)
|
||||
return false;
|
||||
|
||||
|
@ -1211,7 +1219,7 @@ void Tilemap::Autotiles::set(int i, Bitmap *bitmap)
|
|||
|
||||
p->autotilesDispCon[i].disconnect();
|
||||
p->autotilesDispCon[i] = bitmap->wasDisposed.connect
|
||||
(sigc::mem_fun(p, &TilemapPrivate::invalidateAtlasContents));
|
||||
(sigc::bind(sigc::mem_fun(p, &TilemapPrivate::onAutotileDisposed), i));
|
||||
|
||||
p->updateAutotileInfo();
|
||||
}
|
||||
|
@ -1232,7 +1240,7 @@ Tilemap::Tilemap(Viewport *viewport)
|
|||
|
||||
Tilemap::~Tilemap()
|
||||
{
|
||||
dispose();
|
||||
delete p;
|
||||
}
|
||||
|
||||
void Tilemap::update()
|
||||
|
@ -1259,8 +1267,6 @@ Tilemap::Autotiles &Tilemap::getAutotiles() const
|
|||
return p->autotilesProxy;
|
||||
}
|
||||
|
||||
#define DISP_CLASS_NAME "tilemap"
|
||||
|
||||
DEF_ATTR_RD_SIMPLE(Tilemap, Viewport, Viewport*, p->viewport)
|
||||
DEF_ATTR_RD_SIMPLE(Tilemap, Tileset, Bitmap*, p->tileset)
|
||||
DEF_ATTR_RD_SIMPLE(Tilemap, MapData, Table*, p->mapData)
|
||||
|
@ -1274,8 +1280,6 @@ DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->offset.y)
|
|||
|
||||
void Tilemap::setViewport(Viewport *value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->viewport == value)
|
||||
return;
|
||||
|
||||
|
@ -1294,12 +1298,14 @@ void Tilemap::setViewport(Viewport *value)
|
|||
|
||||
void Tilemap::setTileset(Bitmap *value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->tileset == value)
|
||||
return;
|
||||
|
||||
p->tileset = value;
|
||||
p->tilesetWatch.update(value);
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
p->invalidateAtlasSize();
|
||||
p->tilesetCon.disconnect();
|
||||
|
@ -1311,13 +1317,14 @@ void Tilemap::setTileset(Bitmap *value)
|
|||
|
||||
void Tilemap::setMapData(Table *value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->mapData == value)
|
||||
return;
|
||||
|
||||
p->mapData = value;
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
p->invalidateBuffers();
|
||||
p->mapDataCon.disconnect();
|
||||
p->mapDataCon = value->modified.connect
|
||||
|
@ -1326,13 +1333,14 @@ void Tilemap::setMapData(Table *value)
|
|||
|
||||
void Tilemap::setFlashData(Table *value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->flashData == value)
|
||||
return;
|
||||
|
||||
p->flashData = value;
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
p->invalidateFlash();
|
||||
p->flashDataCon.disconnect();
|
||||
p->flashDataCon = value->modified.connect
|
||||
|
@ -1341,13 +1349,14 @@ void Tilemap::setFlashData(Table *value)
|
|||
|
||||
void Tilemap::setPriorities(Table *value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->priorities == value)
|
||||
return;
|
||||
|
||||
p->priorities = value;
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
|
||||
p->invalidateBuffers();
|
||||
p->prioritiesCon.disconnect();
|
||||
p->prioritiesCon = value->modified.connect
|
||||
|
@ -1356,8 +1365,6 @@ void Tilemap::setPriorities(Table *value)
|
|||
|
||||
void Tilemap::setVisible(bool value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->visible == value)
|
||||
return;
|
||||
|
||||
|
@ -1373,8 +1380,6 @@ void Tilemap::setVisible(bool value)
|
|||
|
||||
void Tilemap::setOX(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->offset.x == value)
|
||||
return;
|
||||
|
||||
|
@ -1385,8 +1390,6 @@ void Tilemap::setOX(int value)
|
|||
|
||||
void Tilemap::setOY(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->offset.y == value)
|
||||
return;
|
||||
|
||||
|
@ -1395,9 +1398,3 @@ void Tilemap::setOY(int value)
|
|||
p->zOrderDirty = true;
|
||||
p->mapViewportDirty = true;
|
||||
}
|
||||
|
||||
|
||||
void Tilemap::releaseResources()
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
|
|
|
@ -68,8 +68,6 @@ public:
|
|||
|
||||
private:
|
||||
TilemapPrivate *p;
|
||||
|
||||
void releaseResources();
|
||||
};
|
||||
|
||||
#endif // TILEMAP_H
|
||||
|
|
|
@ -116,13 +116,9 @@ inline bool contains(const C &c, const V &v)
|
|||
type get##name() const { return loc; } \
|
||||
void set##name(type value) { loc = value; }
|
||||
|
||||
/* Undef this if not needed */
|
||||
#define CHK_DISP GUARD_DISPOSED
|
||||
|
||||
#define DEF_ATTR_RD_SIMPLE_DETAILED(klass, name, type, location, keyword1) \
|
||||
type klass :: get##name() keyword1 \
|
||||
{ \
|
||||
CHK_DISP \
|
||||
return location; \
|
||||
}
|
||||
|
||||
|
@ -130,7 +126,6 @@ inline bool contains(const C &c, const V &v)
|
|||
DEF_ATTR_RD_SIMPLE_DETAILED(klass, name, type, location, keyword1) \
|
||||
void klass :: set##name(type value) \
|
||||
{ \
|
||||
CHK_DISP \
|
||||
location = value; \
|
||||
}
|
||||
|
||||
|
|
|
@ -125,10 +125,10 @@ void Viewport::initViewport(int x, int y, int width, int height)
|
|||
|
||||
Viewport::~Viewport()
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
unlink();
|
||||
|
||||
#define DISP_CLASS_NAME "viewport"
|
||||
delete p;
|
||||
}
|
||||
|
||||
DEF_ATTR_RD_SIMPLE(Viewport, OX, int, geometry.xOrigin)
|
||||
DEF_ATTR_RD_SIMPLE(Viewport, OY, int, geometry.yOrigin)
|
||||
|
@ -139,8 +139,6 @@ DEF_ATTR_SIMPLE(Viewport, Tone, Tone*, p->tone)
|
|||
|
||||
void Viewport::setOX(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (geometry.xOrigin == value)
|
||||
return;
|
||||
|
||||
|
@ -150,8 +148,6 @@ void Viewport::setOX(int value)
|
|||
|
||||
void Viewport::setOY(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (geometry.yOrigin == value)
|
||||
return;
|
||||
|
||||
|
@ -161,8 +157,6 @@ void Viewport::setOY(int value)
|
|||
|
||||
void Viewport::setRect(Rect *value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->rect == value)
|
||||
return;
|
||||
|
||||
|
@ -210,14 +204,6 @@ void Viewport::onGeometryChange(const Geometry &geo)
|
|||
p->recomputeOnScreen();
|
||||
}
|
||||
|
||||
/* Disposable */
|
||||
void Viewport::releaseResources()
|
||||
{
|
||||
unlink();
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
||||
|
||||
ViewportElement::ViewportElement(Viewport *viewport, int z)
|
||||
: SceneElement(viewport ? *viewport : *shState->screen(), z),
|
||||
|
|
|
@ -51,8 +51,6 @@ private:
|
|||
void onGeometryChange(const Geometry &);
|
||||
bool isEffectiveViewport(Rect *&, Color *&, Tone *&) const;
|
||||
|
||||
void releaseResources();
|
||||
|
||||
ViewportPrivate *p;
|
||||
friend struct ViewportPrivate;
|
||||
|
||||
|
|
|
@ -169,7 +169,11 @@ struct QuadChunk
|
|||
struct WindowPrivate
|
||||
{
|
||||
Bitmap *windowskin;
|
||||
DisposeWatch<WindowPrivate, Bitmap> windowskinWatch;
|
||||
|
||||
Bitmap *contents;
|
||||
DisposeWatch<WindowPrivate, Bitmap> contentsWatch;
|
||||
|
||||
bool bgStretch;
|
||||
Rect *cursorRect;
|
||||
bool active;
|
||||
|
@ -246,7 +250,9 @@ struct WindowPrivate
|
|||
|
||||
WindowPrivate(Viewport *viewport = 0)
|
||||
: windowskin(0),
|
||||
windowskinWatch(this, windowskin),
|
||||
contents(0),
|
||||
contentsWatch(this, contents, &WindowPrivate::markControlVertDirty),
|
||||
bgStretch(true),
|
||||
cursorRect(&tmp.rect),
|
||||
active(true),
|
||||
|
@ -280,7 +286,7 @@ struct WindowPrivate
|
|||
prepareCon.disconnect();
|
||||
}
|
||||
|
||||
void onCursorRectChange()
|
||||
void markControlVertDirty()
|
||||
{
|
||||
controlsVertDirty = true;
|
||||
}
|
||||
|
@ -289,7 +295,7 @@ struct WindowPrivate
|
|||
{
|
||||
cursorRectCon.disconnect();
|
||||
cursorRectCon = cursorRect->valueChanged.connect
|
||||
(sigc::mem_fun(this, &WindowPrivate::onCursorRectChange));
|
||||
(sigc::mem_fun(this, &WindowPrivate::markControlVertDirty));
|
||||
}
|
||||
|
||||
void buildBaseVert()
|
||||
|
@ -686,7 +692,11 @@ Window::Window(Viewport *viewport)
|
|||
|
||||
Window::~Window()
|
||||
{
|
||||
dispose();
|
||||
p->controlsElement.release();
|
||||
|
||||
unlink();
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
||||
void Window::update()
|
||||
|
@ -695,8 +705,6 @@ void Window::update()
|
|||
p->stepAnimations();
|
||||
}
|
||||
|
||||
#define DISP_CLASS_NAME "window"
|
||||
|
||||
DEF_ATTR_SIMPLE(Window, X, int, p->position.x)
|
||||
DEF_ATTR_SIMPLE(Window, Y, int, p->position.y)
|
||||
|
||||
|
@ -716,9 +724,8 @@ DEF_ATTR_RD_SIMPLE(Window, ContentsOpacity, int, p->contentsOpacity)
|
|||
|
||||
void Window::setWindowskin(Bitmap *value)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
p->windowskin = value;
|
||||
p->windowskinWatch.update(value);
|
||||
|
||||
if (!value)
|
||||
return;
|
||||
|
@ -728,12 +735,11 @@ void Window::setWindowskin(Bitmap *value)
|
|||
|
||||
void Window::setContents(Bitmap *value)
|
||||
{
|
||||
GUARD_DISPOSED;
|
||||
|
||||
if (p->contents == value)
|
||||
return;
|
||||
|
||||
p->contents = value;
|
||||
p->contentsWatch.update(value);
|
||||
p->controlsVertDirty = true;
|
||||
|
||||
if (!value)
|
||||
|
@ -745,8 +751,6 @@ void Window::setContents(Bitmap *value)
|
|||
|
||||
void Window::setStretch(bool value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (value == p->bgStretch)
|
||||
return;
|
||||
|
||||
|
@ -756,21 +760,17 @@ void Window::setStretch(bool value)
|
|||
|
||||
void Window::setCursorRect(Rect *value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->cursorRect == value)
|
||||
return;
|
||||
|
||||
p->cursorRect = value;
|
||||
|
||||
p->refreshCursorRectCon();
|
||||
p->onCursorRectChange();
|
||||
p->markControlVertDirty();
|
||||
}
|
||||
|
||||
void Window::setActive(bool value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->active == value)
|
||||
return;
|
||||
|
||||
|
@ -780,8 +780,6 @@ void Window::setActive(bool value)
|
|||
|
||||
void Window::setPause(bool value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->pause == value)
|
||||
return;
|
||||
|
||||
|
@ -793,8 +791,6 @@ void Window::setPause(bool value)
|
|||
|
||||
void Window::setWidth(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->size.x == value)
|
||||
return;
|
||||
|
||||
|
@ -804,8 +800,6 @@ void Window::setWidth(int value)
|
|||
|
||||
void Window::setHeight(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->size.y == value)
|
||||
return;
|
||||
|
||||
|
@ -815,8 +809,6 @@ void Window::setHeight(int value)
|
|||
|
||||
void Window::setOX(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->contentsOffset.x == value)
|
||||
return;
|
||||
|
||||
|
@ -826,8 +818,6 @@ void Window::setOX(int value)
|
|||
|
||||
void Window::setOY(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->contentsOffset.y == value)
|
||||
return;
|
||||
|
||||
|
@ -837,8 +827,6 @@ void Window::setOY(int value)
|
|||
|
||||
void Window::setOpacity(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->opacity == value)
|
||||
return;
|
||||
|
||||
|
@ -848,8 +836,6 @@ void Window::setOpacity(int value)
|
|||
|
||||
void Window::setBackOpacity(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->backOpacity == value)
|
||||
return;
|
||||
|
||||
|
@ -859,8 +845,6 @@ void Window::setBackOpacity(int value)
|
|||
|
||||
void Window::setContentsOpacity(int value)
|
||||
{
|
||||
GUARD_DISPOSED
|
||||
|
||||
if (p->contentsOpacity == value)
|
||||
return;
|
||||
|
||||
|
@ -897,12 +881,3 @@ void Window::onViewportChange()
|
|||
{
|
||||
p->controlsElement.setScene(*this->scene);
|
||||
}
|
||||
|
||||
void Window::releaseResources()
|
||||
{
|
||||
p->controlsElement.release();
|
||||
|
||||
unlink();
|
||||
|
||||
delete p;
|
||||
}
|
||||
|
|
|
@ -65,8 +65,6 @@ private:
|
|||
void setVisible(bool value);
|
||||
|
||||
void onViewportChange();
|
||||
|
||||
void releaseResources();
|
||||
};
|
||||
|
||||
#endif // WINDOW_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue