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
|
@ -26,6 +26,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
void initType(rb_data_type_struct &type,
|
void initType(rb_data_type_struct &type,
|
||||||
|
@ -97,6 +98,18 @@ void raiseRbExc(const Exception &exc)
|
||||||
rb_raise(excClass, "%s", exc.msg.c_str());
|
rb_raise(excClass, "%s", exc.msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
raiseDisposedAccess(VALUE self)
|
||||||
|
{
|
||||||
|
const char *klassName = RTYPEDDATA_TYPE(self)->wrap_struct_name;
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
|
strncpy(buf, klassName, sizeof(buf));
|
||||||
|
buf[0] = tolower(buf[0]);
|
||||||
|
|
||||||
|
rb_raise(getRbData()->exc[RGSS], "disposed %s", buf);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_get_args(int argc, VALUE *argv, const char *format, ...)
|
rb_get_args(int argc, VALUE *argv, const char *format, ...)
|
||||||
{
|
{
|
||||||
|
|
|
@ -87,17 +87,34 @@ static void freeInstance(void *inst)
|
||||||
|
|
||||||
#define INIT_TYPE(Klass) initType(Klass##Type, #Klass, freeInstance<Klass>)
|
#define INIT_TYPE(Klass) initType(Klass##Type, #Klass, freeInstance<Klass>)
|
||||||
|
|
||||||
|
void
|
||||||
|
raiseDisposedAccess(VALUE self);
|
||||||
|
|
||||||
|
inline void
|
||||||
|
checkDisposed(VALUE self)
|
||||||
|
{
|
||||||
|
if (!RTYPEDDATA_DATA(self))
|
||||||
|
raiseDisposedAccess(self);
|
||||||
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
static inline C *
|
inline C *
|
||||||
getPrivateData(VALUE self)
|
getPrivateData(VALUE self)
|
||||||
{
|
{
|
||||||
return static_cast<C*>(RTYPEDDATA_DATA(self));
|
C *c = static_cast<C*>(RTYPEDDATA_DATA(self));
|
||||||
|
|
||||||
|
if (!c)
|
||||||
|
raiseDisposedAccess(self);
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
static inline C *
|
static inline C *
|
||||||
getPrivateDataCheck(VALUE self, const rb_data_type_struct &type)
|
getPrivateDataCheck(VALUE self, const rb_data_type_struct &type)
|
||||||
{
|
{
|
||||||
|
/* We don't check for disposed here because any disposable
|
||||||
|
* property is always also nullable */
|
||||||
void *obj = Check_TypedStruct(self, &type);
|
void *obj = Check_TypedStruct(self, &type);
|
||||||
return static_cast<C*>(obj);
|
return static_cast<C*>(obj);
|
||||||
}
|
}
|
||||||
|
@ -286,17 +303,11 @@ rb_check_argc(int actual, int expected)
|
||||||
return self; \
|
return self; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we're not binding a disposable class,
|
|
||||||
* we want to #undef DEF_PROP_CHK_DISP */
|
|
||||||
#define DEF_PROP_CHK_DISP \
|
|
||||||
checkDisposed(k, DISP_CLASS_NAME);
|
|
||||||
|
|
||||||
#define DEF_PROP_OBJ(Klass, PropKlass, PropName, prop_iv) \
|
#define DEF_PROP_OBJ(Klass, PropKlass, PropName, prop_iv) \
|
||||||
RB_METHOD(Klass##Get##PropName) \
|
RB_METHOD(Klass##Get##PropName) \
|
||||||
{ \
|
{ \
|
||||||
RB_UNUSED_PARAM; \
|
RB_UNUSED_PARAM; \
|
||||||
Klass *k = getPrivateData<Klass>(self); (void) k; \
|
checkDisposed(self); \
|
||||||
DEF_PROP_CHK_DISP \
|
|
||||||
return rb_iv_get(self, prop_iv); \
|
return rb_iv_get(self, prop_iv); \
|
||||||
} \
|
} \
|
||||||
RB_METHOD(Klass##Set##PropName) \
|
RB_METHOD(Klass##Set##PropName) \
|
||||||
|
@ -311,13 +322,14 @@ rb_check_argc(int actual, int expected)
|
||||||
return propObj; \
|
return propObj; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Object property with allowed NIL */
|
/* Object property with allowed NIL
|
||||||
|
* FIXME: Getter assumes prop is disposable,
|
||||||
|
* because self.disposed? is not checked in this case.
|
||||||
|
* Should make this more clear */
|
||||||
#define DEF_PROP_OBJ_NIL(Klass, PropKlass, PropName, prop_iv) \
|
#define DEF_PROP_OBJ_NIL(Klass, PropKlass, PropName, prop_iv) \
|
||||||
RB_METHOD(Klass##Get##PropName) \
|
RB_METHOD(Klass##Get##PropName) \
|
||||||
{ \
|
{ \
|
||||||
RB_UNUSED_PARAM; \
|
RB_UNUSED_PARAM; \
|
||||||
Klass *k = getPrivateData<Klass>(self); (void) k; \
|
|
||||||
DEF_PROP_CHK_DISP \
|
|
||||||
return rb_iv_get(self, prop_iv); \
|
return rb_iv_get(self, prop_iv); \
|
||||||
} \
|
} \
|
||||||
RB_METHOD(Klass##Set##PropName) \
|
RB_METHOD(Klass##Set##PropName) \
|
||||||
|
@ -341,7 +353,6 @@ rb_check_argc(int actual, int expected)
|
||||||
{ \
|
{ \
|
||||||
RB_UNUSED_PARAM; \
|
RB_UNUSED_PARAM; \
|
||||||
Klass *k = getPrivateData<Klass>(self); \
|
Klass *k = getPrivateData<Klass>(self); \
|
||||||
DEF_PROP_CHK_DISP \
|
|
||||||
return value_fun(k->get##PropName()); \
|
return value_fun(k->get##PropName()); \
|
||||||
} \
|
} \
|
||||||
RB_METHOD(Klass##Set##PropName) \
|
RB_METHOD(Klass##Set##PropName) \
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "bitmap"
|
|
||||||
|
|
||||||
DEF_TYPE(Bitmap);
|
DEF_TYPE(Bitmap);
|
||||||
|
|
||||||
void bitmapInitProps(Bitmap *b, VALUE self)
|
void bitmapInitProps(Bitmap *b, VALUE self)
|
||||||
|
@ -123,7 +121,7 @@ RB_METHOD(bitmapBlt)
|
||||||
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
src = getPrivateDataCheck<Bitmap>(srcObj, BitmapType);
|
||||||
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->blt(x, y, *src, srcRect->toIntRect(), opacity); );
|
GUARD_EXC( b->blt(x, y, src, srcRect->toIntRect(), opacity); );
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -146,7 +144,7 @@ RB_METHOD(bitmapStretchBlt)
|
||||||
destRect = getPrivateDataCheck<Rect>(destRectObj, RectType);
|
destRect = getPrivateDataCheck<Rect>(destRectObj, RectType);
|
||||||
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
srcRect = getPrivateDataCheck<Rect>(srcRectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(), opacity); );
|
GUARD_EXC( b->stretchBlt(destRect->toIntRect(), src, srcRect->toIntRect(), opacity); );
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,41 +25,74 @@
|
||||||
#include "disposable.h"
|
#include "disposable.h"
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
/* 'Children' are disposables that are disposed together
|
||||||
|
* with their parent. Currently this is only used by Viewport
|
||||||
|
* in RGSS1.
|
||||||
|
* FIXME: Disable this behavior when RGSS2 or 3 */
|
||||||
|
inline void
|
||||||
|
disposableAddChild(VALUE disp, VALUE child)
|
||||||
|
{
|
||||||
|
VALUE children = rb_iv_get(disp, "children");
|
||||||
|
|
||||||
|
if (NIL_P(children))
|
||||||
|
{
|
||||||
|
children = rb_ary_new();
|
||||||
|
rb_iv_set(disp, "children", children);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assumes children are never removed until destruction */
|
||||||
|
rb_ary_push(children, child);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
disposableDisposeChildren(VALUE disp)
|
||||||
|
{
|
||||||
|
VALUE children = rb_iv_get(disp, "children");
|
||||||
|
|
||||||
|
if (NIL_P(children))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ID dispFun = rb_intern("dispose");
|
||||||
|
|
||||||
|
/* Note: RMXP doesn't call overridden 'dispose' methods here */
|
||||||
|
for (long i = 0; i < RARRAY_LEN(children); ++i)
|
||||||
|
rb_funcall2(rb_ary_entry(children, i), dispFun, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
RB_METHOD(disposableDispose)
|
RB_METHOD(disposableDispose)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
Disposable *d = getPrivateData<C>(self);
|
C *c = static_cast<C*>(RTYPEDDATA_DATA(self));
|
||||||
|
|
||||||
d->dispose();
|
/* Nothing to do if already disposed */
|
||||||
|
if (!c)
|
||||||
|
return Qnil;
|
||||||
|
|
||||||
|
/* Inform core */
|
||||||
|
c->wasDisposed();
|
||||||
|
|
||||||
|
disposableDisposeChildren(self);
|
||||||
|
|
||||||
|
delete c;
|
||||||
|
setPrivateData(self, 0);
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
|
||||||
RB_METHOD(disposableIsDisposed)
|
RB_METHOD(disposableIsDisposed)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
Disposable *d = getPrivateData<C>(self);
|
return rb_bool_new(RTYPEDDATA_DATA(self) == 0);
|
||||||
|
|
||||||
return rb_bool_new(d->isDisposed());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
static void disposableBindingInit(VALUE klass)
|
static void disposableBindingInit(VALUE klass)
|
||||||
{
|
{
|
||||||
_rb_define_method(klass, "dispose", disposableDispose<C>);
|
_rb_define_method(klass, "dispose", disposableDispose<C>);
|
||||||
_rb_define_method(klass, "disposed?", disposableIsDisposed<C>);
|
_rb_define_method(klass, "disposed?", disposableIsDisposed);
|
||||||
}
|
|
||||||
|
|
||||||
inline void checkDisposed(Disposable *d, const char *klassName)
|
|
||||||
{
|
|
||||||
RbData *data = getRbData(); (void) data;
|
|
||||||
|
|
||||||
if (d->isDisposed())
|
|
||||||
rb_raise(getRbData()->exc[RGSS], "disposed %s", klassName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // DISPOSABLEBINDING_H
|
#endif // DISPOSABLEBINDING_H
|
||||||
|
|
|
@ -153,9 +153,6 @@ RB_METHOD(FontSetName)
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef DEF_PROP_CHK_DISP
|
|
||||||
#define DEF_PROP_CHK_DISP
|
|
||||||
|
|
||||||
DEF_PROP_I(Font, Size)
|
DEF_PROP_I(Font, Size)
|
||||||
DEF_PROP_B(Font, Bold)
|
DEF_PROP_B(Font, Bold)
|
||||||
DEF_PROP_B(Font, Italic)
|
DEF_PROP_B(Font, Italic)
|
||||||
|
|
|
@ -43,8 +43,6 @@ RB_METHOD(planeInitialize)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "plane"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_NIL(Plane, Bitmap, Bitmap, "bitmap")
|
DEF_PROP_OBJ_NIL(Plane, Bitmap, Bitmap, "bitmap")
|
||||||
DEF_PROP_OBJ(Plane, Color, Color, "color")
|
DEF_PROP_OBJ(Plane, Color, Color, "color")
|
||||||
DEF_PROP_OBJ(Plane, Tone, Tone, "tone")
|
DEF_PROP_OBJ(Plane, Tone, Tone, "tone")
|
||||||
|
|
|
@ -48,8 +48,6 @@ RB_METHOD(spriteInitialize)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "sprite"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_NIL(Sprite, Bitmap, Bitmap, "bitmap")
|
DEF_PROP_OBJ_NIL(Sprite, Bitmap, Bitmap, "bitmap")
|
||||||
DEF_PROP_OBJ(Sprite, Rect, SrcRect, "src_rect")
|
DEF_PROP_OBJ(Sprite, Rect, SrcRect, "src_rect")
|
||||||
DEF_PROP_OBJ(Sprite, Color, Color, "color")
|
DEF_PROP_OBJ(Sprite, Color, Color, "color")
|
||||||
|
|
|
@ -115,15 +115,11 @@ RB_METHOD(tilemapUpdate)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "tilemap"
|
|
||||||
|
|
||||||
RB_METHOD(tilemapGetViewport)
|
RB_METHOD(tilemapGetViewport)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
Tilemap *t = getPrivateData<Tilemap>(self);
|
checkDisposed(self);
|
||||||
|
|
||||||
checkDisposed(t, DISP_CLASS_NAME);
|
|
||||||
|
|
||||||
return rb_iv_get(self, "viewport");
|
return rb_iv_get(self, "viewport");
|
||||||
}
|
}
|
||||||
|
@ -170,4 +166,3 @@ tilemapBindingInit()
|
||||||
INIT_PROP_BIND( Tilemap, OX, "ox" );
|
INIT_PROP_BIND( Tilemap, OX, "ox" );
|
||||||
INIT_PROP_BIND( Tilemap, OY, "oy" );
|
INIT_PROP_BIND( Tilemap, OY, "oy" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,11 +65,14 @@ RB_METHOD(viewportInitialize)
|
||||||
wrapProperty(self, v->getColor(), "color", ColorType);
|
wrapProperty(self, v->getColor(), "color", ColorType);
|
||||||
wrapProperty(self, v->getTone(), "tone", ToneType);
|
wrapProperty(self, v->getTone(), "tone", ToneType);
|
||||||
|
|
||||||
|
/* 'elements' holds all SceneElements that become children
|
||||||
|
* of this viewport, so we can dispose them when the viewport
|
||||||
|
* is disposed */
|
||||||
|
rb_iv_set(self, "elements", rb_ary_new());
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "viewport"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ(Viewport, Rect, Rect, "rect")
|
DEF_PROP_OBJ(Viewport, Rect, Rect, "rect")
|
||||||
DEF_PROP_OBJ(Viewport, Color, Color, "color")
|
DEF_PROP_OBJ(Viewport, Color, Color, "color")
|
||||||
DEF_PROP_OBJ(Viewport, Tone, Tone, "tone")
|
DEF_PROP_OBJ(Viewport, Tone, Tone, "tone")
|
||||||
|
|
|
@ -27,15 +27,14 @@
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
|
||||||
#include "sceneelement-binding.h"
|
#include "sceneelement-binding.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
RB_METHOD(viewportElementGetViewport)
|
RB_METHOD(viewportElementGetViewport)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
ViewportElement *ve = getPrivateData<C>(self);
|
checkDisposed(self);
|
||||||
|
|
||||||
GUARD_EXC( ve->aboutToAccess(); );
|
|
||||||
|
|
||||||
return rb_iv_get(self, "viewport");
|
return rb_iv_get(self, "viewport");
|
||||||
}
|
}
|
||||||
|
@ -77,7 +76,10 @@ viewportElementInitialize(int argc, VALUE *argv, VALUE self)
|
||||||
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END);
|
||||||
|
|
||||||
if (!NIL_P(viewportObj))
|
if (!NIL_P(viewportObj))
|
||||||
|
{
|
||||||
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
|
||||||
|
disposableAddChild(viewportObj, self);
|
||||||
|
}
|
||||||
|
|
||||||
/* Construct object */
|
/* Construct object */
|
||||||
C *ve = new C(viewport);
|
C *ve = new C(viewport);
|
||||||
|
|
|
@ -51,8 +51,6 @@ RB_METHOD(windowUpdate)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "window"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_NIL(Window, Bitmap, Windowskin, "windowskin")
|
DEF_PROP_OBJ_NIL(Window, Bitmap, Windowskin, "windowskin")
|
||||||
DEF_PROP_OBJ_NIL(Window, Bitmap, Contents, "contents")
|
DEF_PROP_OBJ_NIL(Window, Bitmap, Contents, "contents")
|
||||||
DEF_PROP_OBJ(Window, Rect, CursorRect, "cursor_rect")
|
DEF_PROP_OBJ(Window, Rect, CursorRect, "cursor_rect")
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#define SYMD(symbol) { CS##symbol, #symbol }
|
#define SYMD(symbol) { CS##symbol, #symbol }
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|
@ -48,7 +50,9 @@ struct
|
||||||
SYMD(cursor_rect),
|
SYMD(cursor_rect),
|
||||||
SYMD(path),
|
SYMD(path),
|
||||||
SYMD(array),
|
SYMD(array),
|
||||||
SYMD(default_color)
|
SYMD(default_color),
|
||||||
|
SYMD(children),
|
||||||
|
SYMD(dispose)
|
||||||
};
|
};
|
||||||
|
|
||||||
static elementsN(symData);
|
static elementsN(symData);
|
||||||
|
@ -140,6 +144,19 @@ void raiseMrbExc(mrb_state *mrb, const Exception &exc)
|
||||||
mrb_raise(mrb, excClass, exc.msg.c_str());
|
mrb_raise(mrb, excClass, exc.msg.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
raiseDisposedAccess(mrb_state *mrb, mrb_value self)
|
||||||
|
{
|
||||||
|
const char *klassName = DATA_TYPE(self)->struct_name;
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
|
strncpy(buf, klassName, sizeof(buf));
|
||||||
|
buf[0] = tolower(buf[0]);
|
||||||
|
|
||||||
|
mrb_raisef(mrb, getMrbData(mrb)->exc[RGSS],
|
||||||
|
"disposed %S", mrb_str_new_cstr(mrb, buf));
|
||||||
|
}
|
||||||
|
|
||||||
MRB_METHOD_PUB(inspectObject)
|
MRB_METHOD_PUB(inspectObject)
|
||||||
{
|
{
|
||||||
static char buffer[64];
|
static char buffer[64];
|
||||||
|
|
|
@ -50,6 +50,8 @@ enum CommonSymbol
|
||||||
CSpath,
|
CSpath,
|
||||||
CSarray,
|
CSarray,
|
||||||
CSdefault_color,
|
CSdefault_color,
|
||||||
|
CSchildren,
|
||||||
|
CSdispose,
|
||||||
|
|
||||||
CommonSymbolsMax
|
CommonSymbolsMax
|
||||||
};
|
};
|
||||||
|
@ -143,16 +145,10 @@ defineClass(mrb_state *mrb, const char *name)
|
||||||
|
|
||||||
#define MRB_FUN_UNUSED_PARAM { (void) mrb; }
|
#define MRB_FUN_UNUSED_PARAM { (void) mrb; }
|
||||||
|
|
||||||
/* If we're not binding a disposable class,
|
|
||||||
* we want to #undef DEF_PROP_CHK_DISP */
|
|
||||||
#define DEF_PROP_CHK_DISP \
|
|
||||||
checkDisposed(mrb, k, DISP_CLASS_NAME);
|
|
||||||
|
|
||||||
#define DEF_PROP_OBJ(Klass, PropKlass, PropName, prop_iv) \
|
#define DEF_PROP_OBJ(Klass, PropKlass, PropName, prop_iv) \
|
||||||
MRB_METHOD(Klass##Get##PropName) \
|
MRB_METHOD(Klass##Get##PropName) \
|
||||||
{ \
|
{ \
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); (void) k; \
|
checkDisposed(mrb, self); \
|
||||||
DEF_PROP_CHK_DISP \
|
|
||||||
return getProperty(mrb, self, prop_iv); \
|
return getProperty(mrb, self, prop_iv); \
|
||||||
} \
|
} \
|
||||||
MRB_METHOD(Klass##Set##PropName) \
|
MRB_METHOD(Klass##Set##PropName) \
|
||||||
|
@ -171,8 +167,6 @@ defineClass(mrb_state *mrb, const char *name)
|
||||||
#define DEF_PROP_OBJ_NIL(Klass, PropKlass, PropName, prop_iv) \
|
#define DEF_PROP_OBJ_NIL(Klass, PropKlass, PropName, prop_iv) \
|
||||||
MRB_METHOD(Klass##Get##PropName) \
|
MRB_METHOD(Klass##Get##PropName) \
|
||||||
{ \
|
{ \
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); (void) k; \
|
|
||||||
DEF_PROP_CHK_DISP \
|
|
||||||
return getProperty(mrb, self, prop_iv); \
|
return getProperty(mrb, self, prop_iv); \
|
||||||
} \
|
} \
|
||||||
MRB_METHOD(Klass##Set##PropName) \
|
MRB_METHOD(Klass##Set##PropName) \
|
||||||
|
@ -194,7 +188,6 @@ defineClass(mrb_state *mrb, const char *name)
|
||||||
MRB_METHOD(Klass##Get##PropName) \
|
MRB_METHOD(Klass##Get##PropName) \
|
||||||
{ \
|
{ \
|
||||||
Klass *k = getPrivateData<Klass>(mrb, self); \
|
Klass *k = getPrivateData<Klass>(mrb, self); \
|
||||||
DEF_PROP_CHK_DISP \
|
|
||||||
return mrb_##conv_t##_value(k->get##PropName()); \
|
return mrb_##conv_t##_value(k->get##PropName()); \
|
||||||
} \
|
} \
|
||||||
MRB_METHOD(Klass##Set##PropName) \
|
MRB_METHOD(Klass##Set##PropName) \
|
||||||
|
@ -215,6 +208,7 @@ defineClass(mrb_state *mrb, const char *name)
|
||||||
#define DEF_PROP_B(Klass, PropName) \
|
#define DEF_PROP_B(Klass, PropName) \
|
||||||
DEF_PROP(Klass, mrb_bool, PropName, "b", bool)
|
DEF_PROP(Klass, mrb_bool, PropName, "b", bool)
|
||||||
|
|
||||||
|
// FIXME: use initialize_copy
|
||||||
#define CLONE_FUN(Klass) \
|
#define CLONE_FUN(Klass) \
|
||||||
MRB_METHOD(Klass##Clone) \
|
MRB_METHOD(Klass##Clone) \
|
||||||
{ \
|
{ \
|
||||||
|
@ -252,19 +246,33 @@ getSym(mrb_state *mrb, CommonSymbol sym)
|
||||||
return getMrbData(mrb)->symbols[sym];
|
return getMrbData(mrb)->symbols[sym];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
void
|
||||||
inline T *
|
raiseDisposedAccess(mrb_state *mrb, mrb_value self);
|
||||||
|
|
||||||
|
inline void checkDisposed(mrb_state *mrb, mrb_value self)
|
||||||
|
{
|
||||||
|
if (!DATA_PTR(self))
|
||||||
|
raiseDisposedAccess(mrb, self);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class C>
|
||||||
|
inline C *
|
||||||
getPrivateData(mrb_state *mrb, mrb_value self)
|
getPrivateData(mrb_state *mrb, mrb_value self)
|
||||||
{
|
{
|
||||||
(void) mrb;
|
C *c = static_cast<C*>(DATA_PTR(self));
|
||||||
return static_cast<T*>(DATA_PTR(self));
|
|
||||||
|
if (!c)
|
||||||
|
raiseDisposedAccess(mrb, self);
|
||||||
|
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline T *
|
inline T *
|
||||||
getPrivateDataCheck(mrb_state *mrb, mrb_value obj, const mrb_data_type &type)
|
getPrivateDataCheck(mrb_state *mrb, mrb_value obj, const mrb_data_type &type)
|
||||||
{
|
{
|
||||||
return static_cast<T*>(mrb_check_datatype(mrb, obj, &type));
|
void *ptr = mrb_check_datatype(mrb, obj, &type);
|
||||||
|
return static_cast<T*>(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "bitmap"
|
|
||||||
|
|
||||||
DEF_TYPE(Bitmap);
|
DEF_TYPE(Bitmap);
|
||||||
|
|
||||||
MRB_METHOD(bitmapInitialize)
|
MRB_METHOD(bitmapInitialize)
|
||||||
|
@ -111,7 +109,7 @@ MRB_METHOD(bitmapBlt)
|
||||||
src = getPrivateDataCheck<Bitmap>(mrb, srcObj, BitmapType);
|
src = getPrivateDataCheck<Bitmap>(mrb, srcObj, BitmapType);
|
||||||
srcRect = getPrivateDataCheck<Rect>(mrb, srcRectObj, RectType);
|
srcRect = getPrivateDataCheck<Rect>(mrb, srcRectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->blt(x, y, *src, srcRect->toIntRect(), opacity); )
|
GUARD_EXC( b->blt(x, y, src, srcRect->toIntRect(), opacity); )
|
||||||
|
|
||||||
return mrb_nil_value();
|
return mrb_nil_value();
|
||||||
}
|
}
|
||||||
|
@ -134,7 +132,7 @@ MRB_METHOD(bitmapStretchBlt)
|
||||||
destRect = getPrivateDataCheck<Rect>(mrb, destRectObj, RectType);
|
destRect = getPrivateDataCheck<Rect>(mrb, destRectObj, RectType);
|
||||||
srcRect = getPrivateDataCheck<Rect>(mrb, srcRectObj, RectType);
|
srcRect = getPrivateDataCheck<Rect>(mrb, srcRectObj, RectType);
|
||||||
|
|
||||||
GUARD_EXC( b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(), opacity); )
|
GUARD_EXC( b->stretchBlt(destRect->toIntRect(), src, srcRect->toIntRect(), opacity); )
|
||||||
|
|
||||||
return mrb_nil_value();
|
return mrb_nil_value();
|
||||||
}
|
}
|
||||||
|
@ -277,8 +275,7 @@ MRB_METHOD(bitmapTextSize)
|
||||||
|
|
||||||
MRB_METHOD(bitmapGetFont)
|
MRB_METHOD(bitmapGetFont)
|
||||||
{
|
{
|
||||||
Bitmap *b = getPrivateData<Bitmap>(mrb, self);
|
checkDisposed(mrb, self);
|
||||||
checkDisposed(mrb, b, "bitmap");
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSfont);
|
return getProperty(mrb, self, CSfont);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,14 +25,60 @@
|
||||||
#include "disposable.h"
|
#include "disposable.h"
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
|
|
||||||
|
#include "mruby/array.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
/* 'Children' are disposables that are disposed together
|
||||||
|
* with their parent. Currently this is only used by Viewport
|
||||||
|
* in RGSS1.
|
||||||
|
* FIXME: Disable this behavior when RGSS2 or 3 */
|
||||||
|
inline void
|
||||||
|
disposableAddChild(mrb_state *mrb, mrb_value disp, mrb_value child)
|
||||||
|
{
|
||||||
|
mrb_sym sym = getMrbData(mrb)->symbols[CSchildren];
|
||||||
|
mrb_value children = mrb_iv_get(mrb, disp, sym);
|
||||||
|
|
||||||
|
if (mrb_nil_p(children))
|
||||||
|
{
|
||||||
|
children = mrb_ary_new(mrb);
|
||||||
|
mrb_iv_set(mrb, disp, sym, children);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Assumes children are never removed until destruction */
|
||||||
|
mrb_ary_push(mrb, children, child);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
disposableDisposeChildren(mrb_state *mrb, mrb_value disp)
|
||||||
|
{
|
||||||
|
MrbData *mrbData = getMrbData(mrb);
|
||||||
|
mrb_value children = mrb_iv_get(mrb, disp, mrbData->symbols[CSchildren]);
|
||||||
|
|
||||||
|
if (mrb_nil_p(children))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (mrb_int i = 0; i < RARRAY_LEN(children); ++i)
|
||||||
|
mrb_funcall_argv(mrb, mrb_ary_entry(children, i),
|
||||||
|
mrbData->symbols[CSdispose], 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
MRB_METHOD(disposableDispose)
|
MRB_METHOD(disposableDispose)
|
||||||
{
|
{
|
||||||
Disposable *d = getPrivateData<C>(mrb, self);
|
C *c = static_cast<C*>(DATA_PTR(self));
|
||||||
|
|
||||||
d->dispose();
|
/* Nothing to do if already disposed */
|
||||||
|
if (!c)
|
||||||
|
return mrb_nil_value();
|
||||||
|
|
||||||
|
/* Inform core */
|
||||||
|
c->wasDisposed();
|
||||||
|
|
||||||
|
disposableDisposeChildren(mrb, self);
|
||||||
|
|
||||||
|
delete c;
|
||||||
|
DATA_PTR(self) = 0;
|
||||||
|
|
||||||
return mrb_nil_value();
|
return mrb_nil_value();
|
||||||
}
|
}
|
||||||
|
@ -40,9 +86,9 @@ MRB_METHOD(disposableDispose)
|
||||||
template<class C>
|
template<class C>
|
||||||
MRB_METHOD(disposableDisposed)
|
MRB_METHOD(disposableDisposed)
|
||||||
{
|
{
|
||||||
Disposable *d = getPrivateData<C>(mrb, self);
|
MRB_UNUSED_PARAM;
|
||||||
|
|
||||||
return mrb_bool_value(d->isDisposed());
|
return mrb_bool_value(DATA_PTR(self) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
|
@ -52,13 +98,4 @@ static void disposableBindingInit(mrb_state *mrb, RClass *klass)
|
||||||
mrb_define_method(mrb, klass, "disposed?", disposableDisposed<C>, MRB_ARGS_NONE());
|
mrb_define_method(mrb, klass, "disposed?", disposableDisposed<C>, MRB_ARGS_NONE());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void checkDisposed(mrb_state *mrb, Disposable *d, const char *klassName)
|
|
||||||
{
|
|
||||||
MrbData *data = getMrbData(mrb);
|
|
||||||
|
|
||||||
if (d->isDisposed())
|
|
||||||
mrb_raisef(mrb, data->exc[RGSS], "disposed %S",
|
|
||||||
mrb_str_new_static(mrb, klassName, strlen(klassName)));
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // DISPOSABLEBINDING_H
|
#endif // DISPOSABLEBINDING_H
|
||||||
|
|
|
@ -78,9 +78,6 @@ MRB_METHOD(FontSetName)
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef DEF_PROP_CHK_DISP
|
|
||||||
#define DEF_PROP_CHK_DISP
|
|
||||||
|
|
||||||
DEF_PROP_I(Font, Size)
|
DEF_PROP_I(Font, Size)
|
||||||
DEF_PROP_B(Font, Bold)
|
DEF_PROP_B(Font, Bold)
|
||||||
DEF_PROP_B(Font, Italic)
|
DEF_PROP_B(Font, Italic)
|
||||||
|
|
|
@ -43,8 +43,6 @@ MRB_METHOD(planeInitialize)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "plane"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ(Plane, Bitmap, Bitmap, CSbitmap)
|
DEF_PROP_OBJ(Plane, Bitmap, Bitmap, CSbitmap)
|
||||||
DEF_PROP_OBJ(Plane, Color, Color, CScolor)
|
DEF_PROP_OBJ(Plane, Color, Color, CScolor)
|
||||||
DEF_PROP_OBJ(Plane, Tone, Tone, CStone)
|
DEF_PROP_OBJ(Plane, Tone, Tone, CStone)
|
||||||
|
|
|
@ -47,8 +47,6 @@ MRB_METHOD(spriteInitialize)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "sprite"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_NIL(Sprite, Bitmap, Bitmap, CSbitmap)
|
DEF_PROP_OBJ_NIL(Sprite, Bitmap, Bitmap, CSbitmap)
|
||||||
DEF_PROP_OBJ(Sprite, Rect, SrcRect, CSsrc_rect)
|
DEF_PROP_OBJ(Sprite, Rect, SrcRect, CSsrc_rect)
|
||||||
DEF_PROP_OBJ(Sprite, Color, Color, CScolor)
|
DEF_PROP_OBJ(Sprite, Color, Color, CScolor)
|
||||||
|
|
|
@ -118,13 +118,9 @@ MRB_METHOD(tilemapUpdate)
|
||||||
return mrb_nil_value();
|
return mrb_nil_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "tilemap"
|
|
||||||
|
|
||||||
MRB_METHOD(tilemapGetViewport)
|
MRB_METHOD(tilemapGetViewport)
|
||||||
{
|
{
|
||||||
Tilemap *t = getPrivateData<Tilemap>(mrb, self);
|
checkDisposed(mrb, self);
|
||||||
|
|
||||||
checkDisposed(mrb, t, DISP_CLASS_NAME);
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSviewport);
|
return getProperty(mrb, self, CSviewport);
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,6 @@ MRB_METHOD(viewportInitialize)
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "viewport"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ(Viewport, Rect, Rect, CSrect)
|
DEF_PROP_OBJ(Viewport, Rect, Rect, CSrect)
|
||||||
DEF_PROP_OBJ(Viewport, Color, Color, CScolor)
|
DEF_PROP_OBJ(Viewport, Color, Color, CScolor)
|
||||||
DEF_PROP_OBJ(Viewport, Tone, Tone, CStone)
|
DEF_PROP_OBJ(Viewport, Tone, Tone, CStone)
|
||||||
|
|
|
@ -27,13 +27,12 @@
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
|
||||||
#include "sceneelement-binding.h"
|
#include "sceneelement-binding.h"
|
||||||
|
#include "disposable-binding.h"
|
||||||
|
|
||||||
template<class C>
|
template<class C>
|
||||||
MRB_METHOD(viewportElementGetViewport)
|
MRB_METHOD(viewportElementGetViewport)
|
||||||
{
|
{
|
||||||
ViewportElement *ve = getPrivateData<C>(mrb, self);
|
checkDisposed(mrb, self);
|
||||||
|
|
||||||
GUARD_EXC( ve->aboutToAccess(); )
|
|
||||||
|
|
||||||
return getProperty(mrb, self, CSviewport);
|
return getProperty(mrb, self, CSviewport);
|
||||||
}
|
}
|
||||||
|
@ -49,7 +48,10 @@ viewportElementInitialize(mrb_state *mrb, mrb_value self)
|
||||||
mrb_get_args(mrb, "|o", &viewportObj);
|
mrb_get_args(mrb, "|o", &viewportObj);
|
||||||
|
|
||||||
if (!mrb_nil_p(viewportObj))
|
if (!mrb_nil_p(viewportObj))
|
||||||
|
{
|
||||||
viewport = getPrivateDataCheck<Viewport>(mrb, viewportObj, ViewportType);
|
viewport = getPrivateDataCheck<Viewport>(mrb, viewportObj, ViewportType);
|
||||||
|
disposableAddChild(mrb, viewportObj, self);
|
||||||
|
}
|
||||||
|
|
||||||
/* Construct object */
|
/* Construct object */
|
||||||
C *ve = new C(viewport);
|
C *ve = new C(viewport);
|
||||||
|
|
|
@ -49,8 +49,6 @@ MRB_METHOD(windowUpdate)
|
||||||
return mrb_nil_value();
|
return mrb_nil_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "window"
|
|
||||||
|
|
||||||
DEF_PROP_OBJ_NIL(Window, Bitmap, Windowskin, CSwindowskin)
|
DEF_PROP_OBJ_NIL(Window, Bitmap, Windowskin, CSwindowskin)
|
||||||
DEF_PROP_OBJ_NIL(Window, Bitmap, Contents, CScontents)
|
DEF_PROP_OBJ_NIL(Window, Bitmap, Contents, CScontents)
|
||||||
DEF_PROP_OBJ(Window, Rect, CursorRect, CScursor_rect)
|
DEF_PROP_OBJ(Window, Rect, CursorRect, CScursor_rect)
|
||||||
|
|
|
@ -44,8 +44,6 @@
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "eventthread.h"
|
#include "eventthread.h"
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "bitmap"
|
|
||||||
|
|
||||||
#define GUARD_MEGA \
|
#define GUARD_MEGA \
|
||||||
{ \
|
{ \
|
||||||
if (p->megaSurface) \
|
if (p->megaSurface) \
|
||||||
|
@ -292,18 +290,21 @@ Bitmap::Bitmap(const Bitmap &other)
|
||||||
|
|
||||||
p->gl = shState->texPool().request(other.width(), other.height());
|
p->gl = shState->texPool().request(other.width(), other.height());
|
||||||
|
|
||||||
blt(0, 0, other, rect());
|
blt(0, 0, &other, rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap::~Bitmap()
|
Bitmap::~Bitmap()
|
||||||
{
|
{
|
||||||
dispose();
|
if (p->megaSurface)
|
||||||
|
SDL_FreeSurface(p->megaSurface);
|
||||||
|
else
|
||||||
|
shState->texPool().release(p->gl);
|
||||||
|
|
||||||
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Bitmap::width() const
|
int Bitmap::width() const
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
if (p->megaSurface)
|
if (p->megaSurface)
|
||||||
return p->megaSurface->w;
|
return p->megaSurface->w;
|
||||||
|
|
||||||
|
@ -312,8 +313,6 @@ int Bitmap::width() const
|
||||||
|
|
||||||
int Bitmap::height() const
|
int Bitmap::height() const
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
if (p->megaSurface)
|
if (p->megaSurface)
|
||||||
return p->megaSurface->h;
|
return p->megaSurface->h;
|
||||||
|
|
||||||
|
@ -326,45 +325,49 @@ IntRect Bitmap::rect() const
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::blt(int x, int y,
|
void Bitmap::blt(int x, int y,
|
||||||
const Bitmap &source, IntRect rect,
|
const Bitmap *source, IntRect rect,
|
||||||
int opacity)
|
int opacity)
|
||||||
{
|
{
|
||||||
|
if (!source)
|
||||||
|
return;
|
||||||
|
|
||||||
// FIXME: RGSS allows the source rect to both lie outside
|
// FIXME: RGSS allows the source rect to both lie outside
|
||||||
// the bitmap rect and be inverted in both directions;
|
// the bitmap rect and be inverted in both directions;
|
||||||
// clamping only covers a subset of these cases (and
|
// clamping only covers a subset of these cases (and
|
||||||
// doesn't fix anything for a direct stretch_blt call).
|
// doesn't fix anything for a direct stretch_blt call).
|
||||||
|
|
||||||
/* Clamp rect to source bitmap size */
|
/* Clamp rect to source bitmap size */
|
||||||
if (rect.x + rect.w > source.width())
|
if (rect.x + rect.w > source->width())
|
||||||
rect.w = source.width() - rect.x;
|
rect.w = source->width() - rect.x;
|
||||||
|
|
||||||
if (rect.y + rect.h > source.height())
|
if (rect.y + rect.h > source->height())
|
||||||
rect.h = source.height() - rect.y;
|
rect.h = source->height() - rect.y;
|
||||||
|
|
||||||
stretchBlt(IntRect(x, y, rect.w, rect.h),
|
stretchBlt(IntRect(x, y, rect.w, rect.h),
|
||||||
source, rect, opacity);
|
source, rect, opacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bitmap::stretchBlt(const IntRect &destRect,
|
void Bitmap::stretchBlt(const IntRect &destRect,
|
||||||
const Bitmap &source, const IntRect &sourceRect,
|
const Bitmap *source, const IntRect &sourceRect,
|
||||||
int opacity)
|
int opacity)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
|
if (!source)
|
||||||
|
return;
|
||||||
|
|
||||||
opacity = clamp(opacity, 0, 255);
|
opacity = clamp(opacity, 0, 255);
|
||||||
|
|
||||||
if (opacity == 0)
|
if (opacity == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (source.megaSurface())
|
if (source->megaSurface())
|
||||||
{
|
{
|
||||||
/* Don't do transparent blits for now */
|
/* Don't do transparent blits for now */
|
||||||
if (opacity < 255)
|
if (opacity < 255)
|
||||||
source.ensureNonMega();
|
source->ensureNonMega();
|
||||||
|
|
||||||
SDL_Surface *srcSurf = source.megaSurface();
|
SDL_Surface *srcSurf = source->megaSurface();
|
||||||
|
|
||||||
SDL_Rect srcRect = sourceRect;
|
SDL_Rect srcRect = sourceRect;
|
||||||
SDL_Rect dstRect = destRect;
|
SDL_Rect dstRect = destRect;
|
||||||
|
@ -411,7 +414,7 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
||||||
{
|
{
|
||||||
/* Fast blit */
|
/* Fast blit */
|
||||||
GLMeta::blitBegin(p->gl);
|
GLMeta::blitBegin(p->gl);
|
||||||
GLMeta::blitSource(source.p->gl);
|
GLMeta::blitSource(source->p->gl);
|
||||||
GLMeta::blitRectangle(sourceRect, destRect);
|
GLMeta::blitRectangle(sourceRect, destRect);
|
||||||
GLMeta::blitEnd();
|
GLMeta::blitEnd();
|
||||||
}
|
}
|
||||||
|
@ -427,10 +430,10 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
||||||
GLMeta::blitRectangle(destRect, Vec2i());
|
GLMeta::blitRectangle(destRect, Vec2i());
|
||||||
GLMeta::blitEnd();
|
GLMeta::blitEnd();
|
||||||
|
|
||||||
FloatRect bltSubRect((float) sourceRect.x / source.width(),
|
FloatRect bltSubRect((float) sourceRect.x / source->width(),
|
||||||
(float) sourceRect.y / source.height(),
|
(float) sourceRect.y / source->height(),
|
||||||
((float) source.width() / sourceRect.w) * ((float) destRect.w / gpTex.width),
|
((float) source->width() / sourceRect.w) * ((float) destRect.w / gpTex.width),
|
||||||
((float) source.height() / sourceRect.h) * ((float) destRect.h / gpTex.height));
|
((float) source->height() / sourceRect.h) * ((float) destRect.h / gpTex.height));
|
||||||
|
|
||||||
BltShader &shader = shState->shaders().blt;
|
BltShader &shader = shState->shaders().blt;
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
@ -442,7 +445,7 @@ void Bitmap::stretchBlt(const IntRect &destRect,
|
||||||
quad.setTexPosRect(sourceRect, destRect);
|
quad.setTexPosRect(sourceRect, destRect);
|
||||||
quad.setColor(Vec4(1, 1, 1, normOpacity));
|
quad.setColor(Vec4(1, 1, 1, normOpacity));
|
||||||
|
|
||||||
source.p->bindTexture(shader);
|
source->p->bindTexture(shader);
|
||||||
p->bindFBO();
|
p->bindFBO();
|
||||||
p->pushSetViewport(shader);
|
p->pushSetViewport(shader);
|
||||||
|
|
||||||
|
@ -465,8 +468,6 @@ void Bitmap::fillRect(int x, int y,
|
||||||
|
|
||||||
void Bitmap::fillRect(const IntRect &rect, const Vec4 &color)
|
void Bitmap::fillRect(const IntRect &rect, const Vec4 &color)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
p->fillRect(rect, color);
|
p->fillRect(rect, color);
|
||||||
|
@ -495,8 +496,6 @@ void Bitmap::gradientFillRect(const IntRect &rect,
|
||||||
const Vec4 &color1, const Vec4 &color2,
|
const Vec4 &color1, const Vec4 &color2,
|
||||||
bool vertical)
|
bool vertical)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
SimpleColorShader &shader = shState->shaders().simpleColor;
|
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)
|
void Bitmap::clearRect(const IntRect &rect)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
p->fillRect(rect, Vec4());
|
p->fillRect(rect, Vec4());
|
||||||
|
@ -552,8 +549,6 @@ void Bitmap::clearRect(const IntRect &rect)
|
||||||
|
|
||||||
void Bitmap::blur()
|
void Bitmap::blur()
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
Quad &quad = shState->gpQuad();
|
Quad &quad = shState->gpQuad();
|
||||||
|
@ -597,8 +592,6 @@ void Bitmap::blur()
|
||||||
|
|
||||||
void Bitmap::radialBlur(int angle, int divisions)
|
void Bitmap::radialBlur(int angle, int divisions)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
angle = clamp<int>(angle, 0, 359);
|
angle = clamp<int>(angle, 0, 359);
|
||||||
|
@ -694,8 +687,6 @@ void Bitmap::radialBlur(int angle, int divisions)
|
||||||
|
|
||||||
void Bitmap::clear()
|
void Bitmap::clear()
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
p->bindFBO();
|
p->bindFBO();
|
||||||
|
@ -713,8 +704,6 @@ void Bitmap::clear()
|
||||||
|
|
||||||
Color Bitmap::getPixel(int x, int y) const
|
Color Bitmap::getPixel(int x, int y) const
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
if (x < 0 || y < 0 || x >= width() || y >= height())
|
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)
|
void Bitmap::setPixel(int x, int y, const Color &color)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
uint8_t pixel[] =
|
uint8_t pixel[] =
|
||||||
|
@ -767,8 +754,6 @@ void Bitmap::setPixel(int x, int y, const Color &color)
|
||||||
|
|
||||||
void Bitmap::hueChange(int hue)
|
void Bitmap::hueChange(int hue)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
if ((hue % 360) == 0)
|
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)
|
void Bitmap::drawText(const IntRect &rect, const char *str, int align)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
if (*str == '\0')
|
if (*str == '\0')
|
||||||
|
@ -1042,8 +1025,6 @@ static uint16_t utf8_to_ucs2(const char *_input,
|
||||||
|
|
||||||
IntRect Bitmap::textSize(const char *str)
|
IntRect Bitmap::textSize(const char *str)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
|
|
||||||
TTF_Font *font = p->font->getSdlFont();
|
TTF_Font *font = p->font->getSdlFont();
|
||||||
|
@ -1077,9 +1058,6 @@ SDL_Surface *Bitmap::megaSurface() const
|
||||||
|
|
||||||
void Bitmap::ensureNonMega() const
|
void Bitmap::ensureNonMega() const
|
||||||
{
|
{
|
||||||
if (isDisposed())
|
|
||||||
return;
|
|
||||||
|
|
||||||
GUARD_MEGA;
|
GUARD_MEGA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1092,13 +1070,3 @@ void Bitmap::taintArea(const IntRect &rect)
|
||||||
{
|
{
|
||||||
p->addTaintedArea(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;
|
IntRect rect() const;
|
||||||
|
|
||||||
void blt(int x, int y,
|
void blt(int x, int y,
|
||||||
const Bitmap &source, IntRect rect,
|
const Bitmap *source, IntRect rect,
|
||||||
int opacity = 255);
|
int opacity = 255);
|
||||||
|
|
||||||
void stretchBlt(const IntRect &destRect,
|
void stretchBlt(const IntRect &destRect,
|
||||||
const Bitmap &source, const IntRect &sourceRect,
|
const Bitmap *source, const IntRect &sourceRect,
|
||||||
int opacity = 255);
|
int opacity = 255);
|
||||||
|
|
||||||
void fillRect(int x, int y,
|
void fillRect(int x, int y,
|
||||||
|
@ -119,8 +119,6 @@ public:
|
||||||
sigc::signal<void> modified;
|
sigc::signal<void> modified;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void releaseResources();
|
|
||||||
|
|
||||||
BitmapPrivate *p;
|
BitmapPrivate *p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,39 +25,63 @@
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
|
||||||
#include <sigc++/signal.h>
|
#include <sigc++/signal.h>
|
||||||
|
#include <sigc++/connection.h>
|
||||||
|
|
||||||
class Disposable
|
class Disposable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Disposable()
|
|
||||||
: disposed(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
virtual ~Disposable() {}
|
|
||||||
|
|
||||||
void dispose()
|
|
||||||
{
|
|
||||||
if (disposed)
|
|
||||||
return;
|
|
||||||
|
|
||||||
releaseResources();
|
|
||||||
disposed = true;
|
|
||||||
wasDisposed();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isDisposed() const { return disposed; }
|
|
||||||
|
|
||||||
sigc::signal<void> wasDisposed;
|
sigc::signal<void> wasDisposed;
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void releaseResources() = 0;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool disposed;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Every cpp needs to define DISP_CLASS_NAME for itself (lowercase) */
|
/* A helper struct which monitors the dispose signal of
|
||||||
#define GUARD_DISPOSED \
|
* properties, and automatically sets the prop pointer to
|
||||||
{ if (isDisposed()) throw Exception(Exception::RGSSError, "disposed %s", DISP_CLASS_NAME); }
|
* 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
|
#endif // DISPOSABLE_H
|
||||||
|
|
|
@ -45,6 +45,8 @@ static float fwrap(float value, float range)
|
||||||
struct PlanePrivate
|
struct PlanePrivate
|
||||||
{
|
{
|
||||||
Bitmap *bitmap;
|
Bitmap *bitmap;
|
||||||
|
DisposeWatch<PlanePrivate, Bitmap> bitmapWatch;
|
||||||
|
|
||||||
NormValue opacity;
|
NormValue opacity;
|
||||||
BlendType blendType;
|
BlendType blendType;
|
||||||
Color *color;
|
Color *color;
|
||||||
|
@ -65,6 +67,7 @@ struct PlanePrivate
|
||||||
|
|
||||||
PlanePrivate()
|
PlanePrivate()
|
||||||
: bitmap(0),
|
: bitmap(0),
|
||||||
|
bitmapWatch(this, bitmap),
|
||||||
opacity(255),
|
opacity(255),
|
||||||
blendType(BlendNormal),
|
blendType(BlendNormal),
|
||||||
color(&tmp.color),
|
color(&tmp.color),
|
||||||
|
@ -153,8 +156,6 @@ Plane::Plane(Viewport *viewport)
|
||||||
onGeometryChange(scene->getGeometry());
|
onGeometryChange(scene->getGeometry());
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "plane"
|
|
||||||
|
|
||||||
DEF_ATTR_RD_SIMPLE(Plane, Bitmap, Bitmap*, p->bitmap)
|
DEF_ATTR_RD_SIMPLE(Plane, Bitmap, Bitmap*, p->bitmap)
|
||||||
DEF_ATTR_RD_SIMPLE(Plane, OX, int, p->ox)
|
DEF_ATTR_RD_SIMPLE(Plane, OX, int, p->ox)
|
||||||
DEF_ATTR_RD_SIMPLE(Plane, OY, int, p->oy)
|
DEF_ATTR_RD_SIMPLE(Plane, OY, int, p->oy)
|
||||||
|
@ -168,14 +169,15 @@ DEF_ATTR_SIMPLE(Plane, Tone, Tone*, p->tone)
|
||||||
|
|
||||||
Plane::~Plane()
|
Plane::~Plane()
|
||||||
{
|
{
|
||||||
dispose();
|
unlink();
|
||||||
|
|
||||||
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plane::setBitmap(Bitmap *value)
|
void Plane::setBitmap(Bitmap *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
p->bitmap = value;
|
p->bitmap = value;
|
||||||
|
p->bitmapWatch.update(value);
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return;
|
return;
|
||||||
|
@ -185,8 +187,6 @@ void Plane::setBitmap(Bitmap *value)
|
||||||
|
|
||||||
void Plane::setOX(int value)
|
void Plane::setOX(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
if (p->ox == value)
|
if (p->ox == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -196,8 +196,6 @@ void Plane::setOX(int value)
|
||||||
|
|
||||||
void Plane::setOY(int value)
|
void Plane::setOY(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
if (p->oy == value)
|
if (p->oy == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -207,8 +205,6 @@ void Plane::setOY(int value)
|
||||||
|
|
||||||
void Plane::setZoomX(float value)
|
void Plane::setZoomX(float value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
if (p->zoomX == value)
|
if (p->zoomX == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -218,8 +214,6 @@ void Plane::setZoomX(float value)
|
||||||
|
|
||||||
void Plane::setZoomY(float value)
|
void Plane::setZoomY(float value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
if (p->zoomY == value)
|
if (p->zoomY == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -229,8 +223,6 @@ void Plane::setZoomY(float value)
|
||||||
|
|
||||||
void Plane::setBlendType(int value)
|
void Plane::setBlendType(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
switch (value)
|
switch (value)
|
||||||
{
|
{
|
||||||
default :
|
default :
|
||||||
|
@ -252,9 +244,6 @@ void Plane::draw()
|
||||||
if (!p->bitmap)
|
if (!p->bitmap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (p->bitmap->isDisposed())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!p->opacity)
|
if (!p->opacity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -307,16 +296,3 @@ void Plane::onGeometryChange(const Scene::Geometry &geo)
|
||||||
p->sceneGeo = geo;
|
p->sceneGeo = geo;
|
||||||
p->quadSourceDirty = true;
|
p->quadSourceDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plane::aboutToAccess() const
|
|
||||||
{
|
|
||||||
GUARD_DISPOSED
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Plane::releaseResources()
|
|
||||||
{
|
|
||||||
unlink();
|
|
||||||
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
|
|
|
@ -52,9 +52,6 @@ private:
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void onGeometryChange(const Scene::Geometry &);
|
void onGeometryChange(const Scene::Geometry &);
|
||||||
void aboutToAccess() const;
|
|
||||||
|
|
||||||
void releaseResources();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLANE_H
|
#endif // PLANE_H
|
||||||
|
|
|
@ -143,15 +143,11 @@ void SceneElement::setScene(Scene &scene)
|
||||||
|
|
||||||
int SceneElement::getZ() const
|
int SceneElement::getZ() const
|
||||||
{
|
{
|
||||||
aboutToAccess();
|
|
||||||
|
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneElement::setZ(int value)
|
void SceneElement::setZ(int value)
|
||||||
{
|
{
|
||||||
aboutToAccess();
|
|
||||||
|
|
||||||
if (z == value)
|
if (z == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -161,15 +157,11 @@ void SceneElement::setZ(int value)
|
||||||
|
|
||||||
bool SceneElement::getVisible() const
|
bool SceneElement::getVisible() const
|
||||||
{
|
{
|
||||||
aboutToAccess();
|
|
||||||
|
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneElement::setVisible(bool value)
|
void SceneElement::setVisible(bool value)
|
||||||
{
|
{
|
||||||
aboutToAccess();
|
|
||||||
|
|
||||||
visible = value;
|
visible = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -78,10 +78,6 @@ public:
|
||||||
DECL_ATTR_VIRT( Z, int )
|
DECL_ATTR_VIRT( Z, int )
|
||||||
DECL_ATTR_VIRT( Visible, bool )
|
DECL_ATTR_VIRT( Visible, bool )
|
||||||
|
|
||||||
/* Disposable classes reimplement this to
|
|
||||||
* check if they're disposed before access */
|
|
||||||
virtual void aboutToAccess() const {}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/* A bit about OpenGL state:
|
/* A bit about OpenGL state:
|
||||||
*
|
*
|
||||||
|
|
|
@ -43,6 +43,7 @@
|
||||||
struct SpritePrivate
|
struct SpritePrivate
|
||||||
{
|
{
|
||||||
Bitmap *bitmap;
|
Bitmap *bitmap;
|
||||||
|
DisposeWatch<SpritePrivate, Bitmap> bitmapWatch;
|
||||||
|
|
||||||
Quad quad;
|
Quad quad;
|
||||||
Transform trans;
|
Transform trans;
|
||||||
|
@ -88,6 +89,7 @@ struct SpritePrivate
|
||||||
|
|
||||||
SpritePrivate()
|
SpritePrivate()
|
||||||
: bitmap(0),
|
: bitmap(0),
|
||||||
|
bitmapWatch(this, bitmap),
|
||||||
srcRect(&tmp.rect),
|
srcRect(&tmp.rect),
|
||||||
mirrored(false),
|
mirrored(false),
|
||||||
bushDepth(0),
|
bushDepth(0),
|
||||||
|
@ -165,9 +167,6 @@ struct SpritePrivate
|
||||||
if (!bitmap)
|
if (!bitmap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (bitmap->isDisposed())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!opacity)
|
if (!opacity)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -310,10 +309,10 @@ Sprite::Sprite(Viewport *viewport)
|
||||||
|
|
||||||
Sprite::~Sprite()
|
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, Bitmap, Bitmap*, p->bitmap)
|
||||||
DEF_ATTR_RD_SIMPLE(Sprite, SrcRect, Rect*, p->srcRect)
|
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)
|
void Sprite::setBitmap(Bitmap *bitmap)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->bitmap == bitmap)
|
if (p->bitmap == bitmap)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->bitmap = bitmap;
|
p->bitmap = bitmap;
|
||||||
|
p->bitmapWatch.update(bitmap);
|
||||||
|
|
||||||
if (!bitmap)
|
if (!bitmap)
|
||||||
return;
|
return;
|
||||||
|
@ -367,8 +365,6 @@ void Sprite::setBitmap(Bitmap *bitmap)
|
||||||
|
|
||||||
void Sprite::setSrcRect(Rect *rect)
|
void Sprite::setSrcRect(Rect *rect)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->srcRect == rect)
|
if (p->srcRect == rect)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -381,8 +377,6 @@ void Sprite::setSrcRect(Rect *rect)
|
||||||
|
|
||||||
void Sprite::setX(int value)
|
void Sprite::setX(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->trans.getPosition().x == value)
|
if (p->trans.getPosition().x == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -391,8 +385,6 @@ void Sprite::setX(int value)
|
||||||
|
|
||||||
void Sprite::setY(int value)
|
void Sprite::setY(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->trans.getPosition().y == value)
|
if (p->trans.getPosition().y == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -405,8 +397,6 @@ void Sprite::setY(int value)
|
||||||
|
|
||||||
void Sprite::setOX(int value)
|
void Sprite::setOX(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->trans.getOrigin().x == value)
|
if (p->trans.getOrigin().x == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -415,8 +405,6 @@ void Sprite::setOX(int value)
|
||||||
|
|
||||||
void Sprite::setOY(int value)
|
void Sprite::setOY(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->trans.getOrigin().y == value)
|
if (p->trans.getOrigin().y == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -425,8 +413,6 @@ void Sprite::setOY(int value)
|
||||||
|
|
||||||
void Sprite::setZoomX(float value)
|
void Sprite::setZoomX(float value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->trans.getScale().x == value)
|
if (p->trans.getScale().x == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -435,8 +421,6 @@ void Sprite::setZoomX(float value)
|
||||||
|
|
||||||
void Sprite::setZoomY(float value)
|
void Sprite::setZoomY(float value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->trans.getScale().y == value)
|
if (p->trans.getScale().y == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -450,8 +434,6 @@ void Sprite::setZoomY(float value)
|
||||||
|
|
||||||
void Sprite::setAngle(float value)
|
void Sprite::setAngle(float value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->trans.getRotation() == value)
|
if (p->trans.getRotation() == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -460,8 +442,6 @@ void Sprite::setAngle(float value)
|
||||||
|
|
||||||
void Sprite::setMirror(bool mirrored)
|
void Sprite::setMirror(bool mirrored)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->mirrored == mirrored)
|
if (p->mirrored == mirrored)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -471,8 +451,6 @@ void Sprite::setMirror(bool mirrored)
|
||||||
|
|
||||||
void Sprite::setBushDepth(int value)
|
void Sprite::setBushDepth(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->bushDepth == value)
|
if (p->bushDepth == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -482,8 +460,6 @@ void Sprite::setBushDepth(int value)
|
||||||
|
|
||||||
void Sprite::setBlendType(int type)
|
void Sprite::setBlendType(int type)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
default :
|
default :
|
||||||
|
@ -504,7 +480,6 @@ void Sprite::setBlendType(int type)
|
||||||
#define DEF_WAVE_SETTER(Name, name, type) \
|
#define DEF_WAVE_SETTER(Name, name, type) \
|
||||||
void Sprite::setWave##Name(type value) \
|
void Sprite::setWave##Name(type value) \
|
||||||
{ \
|
{ \
|
||||||
GUARD_DISPOSED; \
|
|
||||||
if (p->wave.name == value) \
|
if (p->wave.name == value) \
|
||||||
return; \
|
return; \
|
||||||
p->wave.name = value; \
|
p->wave.name = value; \
|
||||||
|
@ -529,14 +504,6 @@ void Sprite::update()
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Disposable */
|
|
||||||
void Sprite::releaseResources()
|
|
||||||
{
|
|
||||||
unlink();
|
|
||||||
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SceneElement */
|
/* SceneElement */
|
||||||
void Sprite::draw()
|
void Sprite::draw()
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,8 +75,6 @@ private:
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void onGeometryChange(const Scene::Geometry &);
|
void onGeometryChange(const Scene::Geometry &);
|
||||||
|
|
||||||
void releaseResources();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SPRITE_H
|
#endif // SPRITE_H
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
#include "tileatlas.h"
|
#include "tileatlas.h"
|
||||||
|
|
||||||
#include <sigc++/connection.h>
|
#include <sigc++/connection.h>
|
||||||
|
#include <sigc++/bind.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -241,6 +242,8 @@ struct TilemapPrivate
|
||||||
Bitmap *autotiles[autotileCount];
|
Bitmap *autotiles[autotileCount];
|
||||||
|
|
||||||
Bitmap *tileset;
|
Bitmap *tileset;
|
||||||
|
DisposeWatch<TilemapPrivate, Bitmap> tilesetWatch;
|
||||||
|
|
||||||
Table *mapData;
|
Table *mapData;
|
||||||
Table *flashData;
|
Table *flashData;
|
||||||
Table *priorities;
|
Table *priorities;
|
||||||
|
@ -352,6 +355,7 @@ struct TilemapPrivate
|
||||||
TilemapPrivate(Viewport *viewport)
|
TilemapPrivate(Viewport *viewport)
|
||||||
: viewport(viewport),
|
: viewport(viewport),
|
||||||
tileset(0),
|
tileset(0),
|
||||||
|
tilesetWatch(this, tileset),
|
||||||
mapData(0),
|
mapData(0),
|
||||||
flashData(0),
|
flashData(0),
|
||||||
priorities(0),
|
priorities(0),
|
||||||
|
@ -439,7 +443,7 @@ struct TilemapPrivate
|
||||||
|
|
||||||
void updateAtlasInfo()
|
void updateAtlasInfo()
|
||||||
{
|
{
|
||||||
if (!tileset || tileset->isDisposed())
|
if (!tileset)
|
||||||
{
|
{
|
||||||
atlas.size = Vec2i();
|
atlas.size = Vec2i();
|
||||||
return;
|
return;
|
||||||
|
@ -468,9 +472,6 @@ struct TilemapPrivate
|
||||||
if (!autotiles[i])
|
if (!autotiles[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (autotiles[i]->isDisposed())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (autotiles[i]->megaSurface())
|
if (autotiles[i]->megaSurface())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -516,15 +517,22 @@ struct TilemapPrivate
|
||||||
flashDirty = true;
|
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 */
|
/* Checks for the minimum amount of data needed to display */
|
||||||
bool verifyResources()
|
bool verifyResources()
|
||||||
{
|
{
|
||||||
if (!tileset)
|
if (!tileset)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (tileset->isDisposed())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!mapData)
|
if (!mapData)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1211,7 +1219,7 @@ void Tilemap::Autotiles::set(int i, Bitmap *bitmap)
|
||||||
|
|
||||||
p->autotilesDispCon[i].disconnect();
|
p->autotilesDispCon[i].disconnect();
|
||||||
p->autotilesDispCon[i] = bitmap->wasDisposed.connect
|
p->autotilesDispCon[i] = bitmap->wasDisposed.connect
|
||||||
(sigc::mem_fun(p, &TilemapPrivate::invalidateAtlasContents));
|
(sigc::bind(sigc::mem_fun(p, &TilemapPrivate::onAutotileDisposed), i));
|
||||||
|
|
||||||
p->updateAutotileInfo();
|
p->updateAutotileInfo();
|
||||||
}
|
}
|
||||||
|
@ -1232,7 +1240,7 @@ Tilemap::Tilemap(Viewport *viewport)
|
||||||
|
|
||||||
Tilemap::~Tilemap()
|
Tilemap::~Tilemap()
|
||||||
{
|
{
|
||||||
dispose();
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tilemap::update()
|
void Tilemap::update()
|
||||||
|
@ -1259,8 +1267,6 @@ Tilemap::Autotiles &Tilemap::getAutotiles() const
|
||||||
return p->autotilesProxy;
|
return p->autotilesProxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "tilemap"
|
|
||||||
|
|
||||||
DEF_ATTR_RD_SIMPLE(Tilemap, Viewport, Viewport*, p->viewport)
|
DEF_ATTR_RD_SIMPLE(Tilemap, Viewport, Viewport*, p->viewport)
|
||||||
DEF_ATTR_RD_SIMPLE(Tilemap, Tileset, Bitmap*, p->tileset)
|
DEF_ATTR_RD_SIMPLE(Tilemap, Tileset, Bitmap*, p->tileset)
|
||||||
DEF_ATTR_RD_SIMPLE(Tilemap, MapData, Table*, p->mapData)
|
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)
|
void Tilemap::setViewport(Viewport *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->viewport == value)
|
if (p->viewport == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1294,12 +1298,14 @@ void Tilemap::setViewport(Viewport *value)
|
||||||
|
|
||||||
void Tilemap::setTileset(Bitmap *value)
|
void Tilemap::setTileset(Bitmap *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->tileset == value)
|
if (p->tileset == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->tileset = value;
|
p->tileset = value;
|
||||||
|
p->tilesetWatch.update(value);
|
||||||
|
|
||||||
|
if (!value)
|
||||||
|
return;
|
||||||
|
|
||||||
p->invalidateAtlasSize();
|
p->invalidateAtlasSize();
|
||||||
p->tilesetCon.disconnect();
|
p->tilesetCon.disconnect();
|
||||||
|
@ -1311,13 +1317,14 @@ void Tilemap::setTileset(Bitmap *value)
|
||||||
|
|
||||||
void Tilemap::setMapData(Table *value)
|
void Tilemap::setMapData(Table *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->mapData == value)
|
if (p->mapData == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->mapData = value;
|
p->mapData = value;
|
||||||
|
|
||||||
|
if (!value)
|
||||||
|
return;
|
||||||
|
|
||||||
p->invalidateBuffers();
|
p->invalidateBuffers();
|
||||||
p->mapDataCon.disconnect();
|
p->mapDataCon.disconnect();
|
||||||
p->mapDataCon = value->modified.connect
|
p->mapDataCon = value->modified.connect
|
||||||
|
@ -1326,13 +1333,14 @@ void Tilemap::setMapData(Table *value)
|
||||||
|
|
||||||
void Tilemap::setFlashData(Table *value)
|
void Tilemap::setFlashData(Table *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->flashData == value)
|
if (p->flashData == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->flashData = value;
|
p->flashData = value;
|
||||||
|
|
||||||
|
if (!value)
|
||||||
|
return;
|
||||||
|
|
||||||
p->invalidateFlash();
|
p->invalidateFlash();
|
||||||
p->flashDataCon.disconnect();
|
p->flashDataCon.disconnect();
|
||||||
p->flashDataCon = value->modified.connect
|
p->flashDataCon = value->modified.connect
|
||||||
|
@ -1341,13 +1349,14 @@ void Tilemap::setFlashData(Table *value)
|
||||||
|
|
||||||
void Tilemap::setPriorities(Table *value)
|
void Tilemap::setPriorities(Table *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->priorities == value)
|
if (p->priorities == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->priorities = value;
|
p->priorities = value;
|
||||||
|
|
||||||
|
if (!value)
|
||||||
|
return;
|
||||||
|
|
||||||
p->invalidateBuffers();
|
p->invalidateBuffers();
|
||||||
p->prioritiesCon.disconnect();
|
p->prioritiesCon.disconnect();
|
||||||
p->prioritiesCon = value->modified.connect
|
p->prioritiesCon = value->modified.connect
|
||||||
|
@ -1356,8 +1365,6 @@ void Tilemap::setPriorities(Table *value)
|
||||||
|
|
||||||
void Tilemap::setVisible(bool value)
|
void Tilemap::setVisible(bool value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->visible == value)
|
if (p->visible == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1373,8 +1380,6 @@ void Tilemap::setVisible(bool value)
|
||||||
|
|
||||||
void Tilemap::setOX(int value)
|
void Tilemap::setOX(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->offset.x == value)
|
if (p->offset.x == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1385,8 +1390,6 @@ void Tilemap::setOX(int value)
|
||||||
|
|
||||||
void Tilemap::setOY(int value)
|
void Tilemap::setOY(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->offset.y == value)
|
if (p->offset.y == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -1395,9 +1398,3 @@ void Tilemap::setOY(int value)
|
||||||
p->zOrderDirty = true;
|
p->zOrderDirty = true;
|
||||||
p->mapViewportDirty = true;
|
p->mapViewportDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Tilemap::releaseResources()
|
|
||||||
{
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
|
|
|
@ -68,8 +68,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TilemapPrivate *p;
|
TilemapPrivate *p;
|
||||||
|
|
||||||
void releaseResources();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TILEMAP_H
|
#endif // TILEMAP_H
|
||||||
|
|
|
@ -116,13 +116,9 @@ inline bool contains(const C &c, const V &v)
|
||||||
type get##name() const { return loc; } \
|
type get##name() const { return loc; } \
|
||||||
void set##name(type value) { loc = value; }
|
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) \
|
#define DEF_ATTR_RD_SIMPLE_DETAILED(klass, name, type, location, keyword1) \
|
||||||
type klass :: get##name() keyword1 \
|
type klass :: get##name() keyword1 \
|
||||||
{ \
|
{ \
|
||||||
CHK_DISP \
|
|
||||||
return location; \
|
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) \
|
DEF_ATTR_RD_SIMPLE_DETAILED(klass, name, type, location, keyword1) \
|
||||||
void klass :: set##name(type value) \
|
void klass :: set##name(type value) \
|
||||||
{ \
|
{ \
|
||||||
CHK_DISP \
|
|
||||||
location = value; \
|
location = value; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,10 +125,10 @@ void Viewport::initViewport(int x, int y, int width, int height)
|
||||||
|
|
||||||
Viewport::~Viewport()
|
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, OX, int, geometry.xOrigin)
|
||||||
DEF_ATTR_RD_SIMPLE(Viewport, OY, int, geometry.yOrigin)
|
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)
|
void Viewport::setOX(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (geometry.xOrigin == value)
|
if (geometry.xOrigin == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -150,8 +148,6 @@ void Viewport::setOX(int value)
|
||||||
|
|
||||||
void Viewport::setOY(int value)
|
void Viewport::setOY(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (geometry.yOrigin == value)
|
if (geometry.yOrigin == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -161,8 +157,6 @@ void Viewport::setOY(int value)
|
||||||
|
|
||||||
void Viewport::setRect(Rect *value)
|
void Viewport::setRect(Rect *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->rect == value)
|
if (p->rect == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -210,14 +204,6 @@ void Viewport::onGeometryChange(const Geometry &geo)
|
||||||
p->recomputeOnScreen();
|
p->recomputeOnScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Disposable */
|
|
||||||
void Viewport::releaseResources()
|
|
||||||
{
|
|
||||||
unlink();
|
|
||||||
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ViewportElement::ViewportElement(Viewport *viewport, int z)
|
ViewportElement::ViewportElement(Viewport *viewport, int z)
|
||||||
: SceneElement(viewport ? *viewport : *shState->screen(), z),
|
: SceneElement(viewport ? *viewport : *shState->screen(), z),
|
||||||
|
|
|
@ -51,8 +51,6 @@ private:
|
||||||
void onGeometryChange(const Geometry &);
|
void onGeometryChange(const Geometry &);
|
||||||
bool isEffectiveViewport(Rect *&, Color *&, Tone *&) const;
|
bool isEffectiveViewport(Rect *&, Color *&, Tone *&) const;
|
||||||
|
|
||||||
void releaseResources();
|
|
||||||
|
|
||||||
ViewportPrivate *p;
|
ViewportPrivate *p;
|
||||||
friend struct ViewportPrivate;
|
friend struct ViewportPrivate;
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,11 @@ struct QuadChunk
|
||||||
struct WindowPrivate
|
struct WindowPrivate
|
||||||
{
|
{
|
||||||
Bitmap *windowskin;
|
Bitmap *windowskin;
|
||||||
|
DisposeWatch<WindowPrivate, Bitmap> windowskinWatch;
|
||||||
|
|
||||||
Bitmap *contents;
|
Bitmap *contents;
|
||||||
|
DisposeWatch<WindowPrivate, Bitmap> contentsWatch;
|
||||||
|
|
||||||
bool bgStretch;
|
bool bgStretch;
|
||||||
Rect *cursorRect;
|
Rect *cursorRect;
|
||||||
bool active;
|
bool active;
|
||||||
|
@ -246,7 +250,9 @@ struct WindowPrivate
|
||||||
|
|
||||||
WindowPrivate(Viewport *viewport = 0)
|
WindowPrivate(Viewport *viewport = 0)
|
||||||
: windowskin(0),
|
: windowskin(0),
|
||||||
|
windowskinWatch(this, windowskin),
|
||||||
contents(0),
|
contents(0),
|
||||||
|
contentsWatch(this, contents, &WindowPrivate::markControlVertDirty),
|
||||||
bgStretch(true),
|
bgStretch(true),
|
||||||
cursorRect(&tmp.rect),
|
cursorRect(&tmp.rect),
|
||||||
active(true),
|
active(true),
|
||||||
|
@ -280,7 +286,7 @@ struct WindowPrivate
|
||||||
prepareCon.disconnect();
|
prepareCon.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onCursorRectChange()
|
void markControlVertDirty()
|
||||||
{
|
{
|
||||||
controlsVertDirty = true;
|
controlsVertDirty = true;
|
||||||
}
|
}
|
||||||
|
@ -289,7 +295,7 @@ struct WindowPrivate
|
||||||
{
|
{
|
||||||
cursorRectCon.disconnect();
|
cursorRectCon.disconnect();
|
||||||
cursorRectCon = cursorRect->valueChanged.connect
|
cursorRectCon = cursorRect->valueChanged.connect
|
||||||
(sigc::mem_fun(this, &WindowPrivate::onCursorRectChange));
|
(sigc::mem_fun(this, &WindowPrivate::markControlVertDirty));
|
||||||
}
|
}
|
||||||
|
|
||||||
void buildBaseVert()
|
void buildBaseVert()
|
||||||
|
@ -686,7 +692,11 @@ Window::Window(Viewport *viewport)
|
||||||
|
|
||||||
Window::~Window()
|
Window::~Window()
|
||||||
{
|
{
|
||||||
dispose();
|
p->controlsElement.release();
|
||||||
|
|
||||||
|
unlink();
|
||||||
|
|
||||||
|
delete p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::update()
|
void Window::update()
|
||||||
|
@ -695,8 +705,6 @@ void Window::update()
|
||||||
p->stepAnimations();
|
p->stepAnimations();
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DISP_CLASS_NAME "window"
|
|
||||||
|
|
||||||
DEF_ATTR_SIMPLE(Window, X, int, p->position.x)
|
DEF_ATTR_SIMPLE(Window, X, int, p->position.x)
|
||||||
DEF_ATTR_SIMPLE(Window, Y, int, p->position.y)
|
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)
|
void Window::setWindowskin(Bitmap *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
p->windowskin = value;
|
p->windowskin = value;
|
||||||
|
p->windowskinWatch.update(value);
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
return;
|
return;
|
||||||
|
@ -728,12 +735,11 @@ void Window::setWindowskin(Bitmap *value)
|
||||||
|
|
||||||
void Window::setContents(Bitmap *value)
|
void Window::setContents(Bitmap *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED;
|
|
||||||
|
|
||||||
if (p->contents == value)
|
if (p->contents == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->contents = value;
|
p->contents = value;
|
||||||
|
p->contentsWatch.update(value);
|
||||||
p->controlsVertDirty = true;
|
p->controlsVertDirty = true;
|
||||||
|
|
||||||
if (!value)
|
if (!value)
|
||||||
|
@ -745,8 +751,6 @@ void Window::setContents(Bitmap *value)
|
||||||
|
|
||||||
void Window::setStretch(bool value)
|
void Window::setStretch(bool value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (value == p->bgStretch)
|
if (value == p->bgStretch)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -756,21 +760,17 @@ void Window::setStretch(bool value)
|
||||||
|
|
||||||
void Window::setCursorRect(Rect *value)
|
void Window::setCursorRect(Rect *value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->cursorRect == value)
|
if (p->cursorRect == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
p->cursorRect = value;
|
p->cursorRect = value;
|
||||||
|
|
||||||
p->refreshCursorRectCon();
|
p->refreshCursorRectCon();
|
||||||
p->onCursorRectChange();
|
p->markControlVertDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::setActive(bool value)
|
void Window::setActive(bool value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->active == value)
|
if (p->active == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -780,8 +780,6 @@ void Window::setActive(bool value)
|
||||||
|
|
||||||
void Window::setPause(bool value)
|
void Window::setPause(bool value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->pause == value)
|
if (p->pause == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -793,8 +791,6 @@ void Window::setPause(bool value)
|
||||||
|
|
||||||
void Window::setWidth(int value)
|
void Window::setWidth(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->size.x == value)
|
if (p->size.x == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -804,8 +800,6 @@ void Window::setWidth(int value)
|
||||||
|
|
||||||
void Window::setHeight(int value)
|
void Window::setHeight(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->size.y == value)
|
if (p->size.y == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -815,8 +809,6 @@ void Window::setHeight(int value)
|
||||||
|
|
||||||
void Window::setOX(int value)
|
void Window::setOX(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->contentsOffset.x == value)
|
if (p->contentsOffset.x == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -826,8 +818,6 @@ void Window::setOX(int value)
|
||||||
|
|
||||||
void Window::setOY(int value)
|
void Window::setOY(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->contentsOffset.y == value)
|
if (p->contentsOffset.y == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -837,8 +827,6 @@ void Window::setOY(int value)
|
||||||
|
|
||||||
void Window::setOpacity(int value)
|
void Window::setOpacity(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->opacity == value)
|
if (p->opacity == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -848,8 +836,6 @@ void Window::setOpacity(int value)
|
||||||
|
|
||||||
void Window::setBackOpacity(int value)
|
void Window::setBackOpacity(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->backOpacity == value)
|
if (p->backOpacity == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -859,8 +845,6 @@ void Window::setBackOpacity(int value)
|
||||||
|
|
||||||
void Window::setContentsOpacity(int value)
|
void Window::setContentsOpacity(int value)
|
||||||
{
|
{
|
||||||
GUARD_DISPOSED
|
|
||||||
|
|
||||||
if (p->contentsOpacity == value)
|
if (p->contentsOpacity == value)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -897,12 +881,3 @@ void Window::onViewportChange()
|
||||||
{
|
{
|
||||||
p->controlsElement.setScene(*this->scene);
|
p->controlsElement.setScene(*this->scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::releaseResources()
|
|
||||||
{
|
|
||||||
p->controlsElement.release();
|
|
||||||
|
|
||||||
unlink();
|
|
||||||
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
|
|
|
@ -65,8 +65,6 @@ private:
|
||||||
void setVisible(bool value);
|
void setVisible(bool value);
|
||||||
|
|
||||||
void onViewportChange();
|
void onViewportChange();
|
||||||
|
|
||||||
void releaseResources();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WINDOW_H
|
#endif // WINDOW_H
|
||||||
|
|
Loading…
Reference in New Issue