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
|
@ -87,17 +87,34 @@ static void freeInstance(void *inst)
|
|||
|
||||
#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>
|
||||
static inline C *
|
||||
inline C *
|
||||
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>
|
||||
static inline C *
|
||||
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);
|
||||
return static_cast<C*>(obj);
|
||||
}
|
||||
|
@ -286,17 +303,11 @@ rb_check_argc(int actual, int expected)
|
|||
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) \
|
||||
RB_METHOD(Klass##Get##PropName) \
|
||||
{ \
|
||||
RB_UNUSED_PARAM; \
|
||||
Klass *k = getPrivateData<Klass>(self); (void) k; \
|
||||
DEF_PROP_CHK_DISP \
|
||||
checkDisposed(self); \
|
||||
return rb_iv_get(self, prop_iv); \
|
||||
} \
|
||||
RB_METHOD(Klass##Set##PropName) \
|
||||
|
@ -311,13 +322,14 @@ rb_check_argc(int actual, int expected)
|
|||
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) \
|
||||
RB_METHOD(Klass##Get##PropName) \
|
||||
{ \
|
||||
RB_UNUSED_PARAM; \
|
||||
Klass *k = getPrivateData<Klass>(self); (void) k; \
|
||||
DEF_PROP_CHK_DISP \
|
||||
return rb_iv_get(self, prop_iv); \
|
||||
} \
|
||||
RB_METHOD(Klass##Set##PropName) \
|
||||
|
@ -341,7 +353,6 @@ rb_check_argc(int actual, int expected)
|
|||
{ \
|
||||
RB_UNUSED_PARAM; \
|
||||
Klass *k = getPrivateData<Klass>(self); \
|
||||
DEF_PROP_CHK_DISP \
|
||||
return value_fun(k->get##PropName()); \
|
||||
} \
|
||||
RB_METHOD(Klass##Set##PropName) \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue