diff --git a/binding/binding-util.h b/binding/binding-util.h index 50142bf..a441bb6 100644 --- a/binding/binding-util.h +++ b/binding/binding-util.h @@ -314,6 +314,19 @@ raiseRbExc(exc); \ } \ } +#define GFX_GUARD_EXC(exp) \ +{\ +GFX_LOCK; \ +try {\ +exp \ +} catch (const Exception &exc) {\ +GFX_UNLOCK; \ +raiseRbExc(exc); \ +}\ +GFX_UNLOCK;\ +} + + template static inline VALUE objectLoad(int argc, VALUE *argv, VALUE self) { const char *data; @@ -437,6 +450,10 @@ return self; \ * FIXME: Getter assumes prop is disposable, * because self.disposed? is not checked in this case. * Should make this more clear */ + +// -------------- +// Do not wait for Graphics.update +// -------------- #if RAPI_FULL > 187 #define DEF_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \ RB_METHOD(Klass##Get##PropName) { \ @@ -546,4 +563,80 @@ _rb_define_method(klass, prop_name_s, Klass##Get##PropName); \ _rb_define_method(klass, prop_name_s "=", Klass##Set##PropName); \ } +// -------------- +// Wait for Graphics.update +// -------------- +#if RAPI_FULL > 187 +#define DEF_GFX_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \ +RB_METHOD(Klass##Get##PropName) { \ +RB_UNUSED_PARAM; \ +return rb_iv_get(self, prop_iv); \ +} \ +RB_METHOD(Klass##Set##PropName) { \ +RB_UNUSED_PARAM; \ +rb_check_argc(argc, 1); \ +Klass *k = getPrivateData(self); \ +VALUE propObj = *argv; \ +PropKlass *prop; \ +if (NIL_P(propObj)) \ +prop = 0; \ +else \ +prop = getPrivateDataCheck(propObj, PropKlass##Type); \ +GFX_GUARD_EXC(k->set##PropName(prop);) \ +rb_iv_set(self, prop_iv, propObj); \ +return propObj; \ +} +#else +#define DEF_GFX_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) \ +DEF_PROP_OBJ_REF(Klass, PropKlass, PropName, prop_iv) +#endif + +/* Object property which is copied by value, not reference */ +#if RAPI_FULL > 187 +#define DEF_GFX_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) \ +RB_METHOD(Klass##Get##PropName) { \ +RB_UNUSED_PARAM; \ +checkDisposed(self); \ +return rb_iv_get(self, prop_iv); \ +} \ +RB_METHOD(Klass##Set##PropName) { \ +rb_check_argc(argc, 1); \ +Klass *k = getPrivateData(self); \ +VALUE propObj = *argv; \ +PropKlass *prop; \ +prop = getPrivateDataCheck(propObj, PropKlass##Type); \ +GFX_GUARD_EXC(k->set##PropName(*prop);) \ +return propObj; \ +} +#else +#define DEF_GFX_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) \ +DEF_PROP_OBJ_VAL(Klass, PropKlass, PropName, prop_iv) +#endif + +#define DEF_GFX_PROP(Klass, type, PropName, arg_fun, value_fun) \ +RB_METHOD(Klass##Get##PropName) { \ +RB_UNUSED_PARAM; \ +Klass *k = getPrivateData(self); \ +type value = 0; \ +GUARD_EXC(value = k->get##PropName();) \ +return value_fun(value); \ +} \ +RB_METHOD(Klass##Set##PropName) { \ +rb_check_argc(argc, 1); \ +Klass *k = getPrivateData(self); \ +type value; \ +rb_##arg_fun##_arg(*argv, &value); \ +GFX_GUARD_EXC(k->set##PropName(value);) \ +return *argv; \ +} + +#define DEF_GFX_PROP_I(Klass, PropName) \ +DEF_GFX_PROP(Klass, int, PropName, int, rb_fix_new) + +#define DEF_GFX_PROP_F(Klass, PropName) \ +DEF_GFX_PROP(Klass, double, PropName, float, rb_float_new) + +#define DEF_GFX_PROP_B(Klass, PropName) \ +DEF_GFX_PROP(Klass, bool, PropName, bool, rb_bool_new) + #endif // BINDING_UTIL_H diff --git a/binding/bitmap-binding.cpp b/binding/bitmap-binding.cpp index fbd70f1..39fb57a 100644 --- a/binding/bitmap-binding.cpp +++ b/binding/bitmap-binding.cpp @@ -26,6 +26,7 @@ #include "exception.h" #include "font.h" #include "sharedstate.h" +#include "graphics.h" #if RAPI_FULL > 187 DEF_TYPE(Bitmap); @@ -57,17 +58,19 @@ RB_METHOD(bitmapInitialize) { char *filename; rb_get_args(argc, argv, "z", &filename RB_ARG_END); - GUARD_EXC(b = new Bitmap(filename);) + GFX_GUARD_EXC(b = new Bitmap(filename);) } else { int width, height; rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END); - GUARD_EXC(b = new Bitmap(width, height);) + GFX_GUARD_EXC(b = new Bitmap(width, height);) } setPrivateData(self, b); bitmapInitProps(b, self); + GFX_UNLOCK; + return self; } @@ -123,7 +126,7 @@ RB_METHOD(bitmapBlt) { src = getPrivateDataCheck(srcObj, BitmapType); srcRect = getPrivateDataCheck(srcRectObj, RectType); - GUARD_EXC(b->blt(x, y, *src, srcRect->toIntRect(), opacity);); + GFX_GUARD_EXC(b->blt(x, y, *src, srcRect->toIntRect(), opacity);); return self; } @@ -146,7 +149,7 @@ RB_METHOD(bitmapStretchBlt) { destRect = getPrivateDataCheck(destRectObj, RectType); srcRect = getPrivateDataCheck(srcRectObj, RectType); - GUARD_EXC(b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(), + GFX_GUARD_EXC(b->stretchBlt(destRect->toIntRect(), *src, srcRect->toIntRect(), opacity);); return self; @@ -167,7 +170,7 @@ RB_METHOD(bitmapFillRect) { rect = getPrivateDataCheck(rectObj, RectType); color = getPrivateDataCheck(colorObj, ColorType); - GUARD_EXC(b->fillRect(rect->toIntRect(), color->norm);); + GFX_GUARD_EXC(b->fillRect(rect->toIntRect(), color->norm);); } else { int x, y, width, height; @@ -176,7 +179,7 @@ RB_METHOD(bitmapFillRect) { color = getPrivateDataCheck(colorObj, ColorType); - GUARD_EXC(b->fillRect(x, y, width, height, color->norm);); + GFX_GUARD_EXC(b->fillRect(x, y, width, height, color->norm);); } return self; @@ -186,8 +189,8 @@ RB_METHOD(bitmapClear) { RB_UNUSED_PARAM; Bitmap *b = getPrivateData(self); - - GUARD_EXC(b->clear();) + + GFX_GUARD_EXC(b->clear();) return self; } @@ -219,7 +222,7 @@ RB_METHOD(bitmapSetPixel) { color = getPrivateDataCheck(colorObj, ColorType); - GUARD_EXC(b->setPixel(x, y, *color);); + GFX_GUARD_EXC(b->setPixel(x, y, *color);); return self; } @@ -231,7 +234,7 @@ RB_METHOD(bitmapHueChange) { rb_get_args(argc, argv, "i", &hue RB_ARG_END); - GUARD_EXC(b->hueChange(hue);); + GFX_GUARD_EXC(b->hueChange(hue);); return self; } @@ -257,7 +260,7 @@ RB_METHOD(bitmapDrawText) { rect = getPrivateDataCheck(rectObj, RectType); - GUARD_EXC(b->drawText(rect->toIntRect(), str, align);); + GFX_GUARD_EXC(b->drawText(rect->toIntRect(), str, align);); } else { int x, y, width, height; @@ -272,7 +275,7 @@ RB_METHOD(bitmapDrawText) { &align RB_ARG_END); } - GUARD_EXC(b->drawText(x, y, width, height, str, align);); + GFX_GUARD_EXC(b->drawText(x, y, width, height, str, align);); } return self; @@ -300,7 +303,7 @@ RB_METHOD(bitmapTextSize) { return wrapObject(rect, RectType); } -DEF_PROP_OBJ_VAL(Bitmap, Font, Font, "font") +DEF_GFX_PROP_OBJ_VAL(Bitmap, Font, Font, "font") RB_METHOD(bitmapGradientFillRect) { Bitmap *b = getPrivateData(self); @@ -320,7 +323,7 @@ RB_METHOD(bitmapGradientFillRect) { color1 = getPrivateDataCheck(color1Obj, ColorType); color2 = getPrivateDataCheck(color2Obj, ColorType); - GUARD_EXC(b->gradientFillRect(rect->toIntRect(), color1->norm, color2->norm, + GFX_GUARD_EXC(b->gradientFillRect(rect->toIntRect(), color1->norm, color2->norm, vertical);); } else { int x, y, width, height; @@ -331,7 +334,7 @@ RB_METHOD(bitmapGradientFillRect) { color1 = getPrivateDataCheck(color1Obj, ColorType); color2 = getPrivateDataCheck(color2Obj, ColorType); - GUARD_EXC(b->gradientFillRect(x, y, width, height, color1->norm, + GFX_GUARD_EXC(b->gradientFillRect(x, y, width, height, color1->norm, color2->norm, vertical);); } @@ -349,13 +352,13 @@ RB_METHOD(bitmapClearRect) { rect = getPrivateDataCheck(rectObj, RectType); - GUARD_EXC(b->clearRect(rect->toIntRect());); + GFX_GUARD_EXC(b->clearRect(rect->toIntRect());); } else { int x, y, width, height; rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END); - GUARD_EXC(b->clearRect(x, y, width, height);); + GFX_GUARD_EXC(b->clearRect(x, y, width, height);); } return self; @@ -366,7 +369,9 @@ RB_METHOD(bitmapBlur) { Bitmap *b = getPrivateData(self); + GFX_LOCK; b->blur(); + GFX_UNLOCK; return Qnil; } @@ -377,7 +382,9 @@ RB_METHOD(bitmapRadialBlur) { int angle, divisions; rb_get_args(argc, argv, "ii", &angle, &divisions RB_ARG_END); + GFX_LOCK; b->radialBlur(angle, divisions); + GFX_UNLOCK; return Qnil; } @@ -389,7 +396,7 @@ RB_METHOD(bitmapGetRawData) { int size = b->width() * b->height() * 4; VALUE ret = rb_str_new(0, size); - GUARD_EXC(b->getRaw(RSTRING_PTR(ret), size);); + GFX_GUARD_EXC(b->getRaw(RSTRING_PTR(ret), size);); return ret; } @@ -403,7 +410,7 @@ RB_METHOD(bitmapSetRawData) { Bitmap *b = getPrivateData(self); - GUARD_EXC(b->replaceRaw(RSTRING_PTR(str), RSTRING_LEN(str));); + GFX_GUARD_EXC(b->replaceRaw(RSTRING_PTR(str), RSTRING_LEN(str));); return self; } @@ -417,11 +424,7 @@ RB_METHOD(bitmapSaveToFile) { Bitmap *b = getPrivateData(self); - try { - b->saveToFile(RSTRING_PTR(str)); - } catch (const Exception &e) { - raiseRbExc(e); - } + GFX_GUARD_EXC(b->saveToFile(RSTRING_PTR(str));); return RUBY_Qnil; } @@ -465,7 +468,7 @@ RB_METHOD(bitmapSetPlaying){ Bitmap *b = getPrivateData(self); - GUARD_EXC((play) ? b->play() : b->stop();); + GFX_GUARD_EXC((play) ? b->play() : b->stop();); return RUBY_Qnil; } @@ -476,7 +479,7 @@ RB_METHOD(bitmapPlay){ rb_check_argc(argc, 0); Bitmap *b = getPrivateData(self); - GUARD_EXC(b->play();); + GFX_GUARD_EXC(b->play();); return RUBY_Qnil; } @@ -487,7 +490,7 @@ RB_METHOD(bitmapStop){ rb_check_argc(argc, 0); Bitmap *b = getPrivateData(self); - GUARD_EXC(b->stop();); + GFX_GUARD_EXC(b->stop();); return RUBY_Qnil; } @@ -501,7 +504,7 @@ RB_METHOD(bitmapGotoStop){ Bitmap *b = getPrivateData(self); - GUARD_EXC(b->gotoAndStop(frame);); + GFX_GUARD_EXC(b->gotoAndStop(frame);); return RUBY_Qnil; } @@ -515,7 +518,7 @@ RB_METHOD(bitmapGotoPlay){ Bitmap *b = getPrivateData(self); - GUARD_EXC(b->gotoAndPlay(frame);); + GFX_GUARD_EXC(b->gotoAndPlay(frame);); return RUBY_Qnil; } @@ -560,7 +563,7 @@ RB_METHOD(bitmapAddFrame){ int ret; - GUARD_EXC(ret = b->addFrame(*src, pos);); + GFX_GUARD_EXC(ret = b->addFrame(*src, pos);); return INT2NUM(ret); } @@ -580,7 +583,7 @@ RB_METHOD(bitmapRemoveFrame){ if (pos < 0) pos = 0; } - GUARD_EXC(b->removeFrame(pos);); + GFX_GUARD_EXC(b->removeFrame(pos);); return RUBY_Qnil; } @@ -592,7 +595,7 @@ RB_METHOD(bitmapNextFrame){ Bitmap *b = getPrivateData(self); - GUARD_EXC(b->nextFrame();); + GFX_GUARD_EXC(b->nextFrame();); return INT2NUM(b->currentFrameI()); } @@ -604,7 +607,7 @@ RB_METHOD(bitmapPreviousFrame){ Bitmap *b = getPrivateData(self); - GUARD_EXC(b->previousFrame();); + GFX_GUARD_EXC(b->previousFrame();); return INT2NUM(b->currentFrameI()); } @@ -617,7 +620,7 @@ RB_METHOD(bitmapSetFPS){ Bitmap *b = getPrivateData(self); - GUARD_EXC( + GFX_GUARD_EXC( if (RB_TYPE_P(fps, RUBY_T_FLOAT)) { b->setAnimationFPS(RFLOAT_VALUE(fps)); } @@ -650,7 +653,8 @@ RB_METHOD(bitmapSetLooping){ rb_get_args(argc, argv, "b", &loop RB_ARG_END); Bitmap *b = getPrivateData(self); - GUARD_EXC(b->setLooping(loop);); + + GFX_GUARD_EXC(b->setLooping(loop);); return rb_bool_new(loop); } @@ -678,7 +682,8 @@ RB_METHOD(bitmapSnapToBitmap) { Bitmap *newbitmap = 0; int pos = (position == RUBY_Qnil) ? -1 : NUM2INT(position); - GUARD_EXC(newbitmap = new Bitmap(*b, pos);); + + GFX_GUARD_EXC(newbitmap = new Bitmap(*b, pos);); VALUE ret = rb_obj_alloc(rb_class_of(self)); @@ -705,11 +710,11 @@ RB_METHOD(bitmapInitializeCopy) { Bitmap *orig = getPrivateData(origObj); Bitmap *b = 0; - GUARD_EXC(b = new Bitmap(*orig);); + + GFX_GUARD_EXC(b = new Bitmap(*orig);); bitmapInitProps(b, self); b->setFont(orig->getFont()); - setPrivateData(self, b); return self; diff --git a/binding/disposable-binding.h b/binding/disposable-binding.h index 6a4c50e..637c042 100644 --- a/binding/disposable-binding.h +++ b/binding/disposable-binding.h @@ -24,6 +24,7 @@ #include "disposable.h" #include "binding-util.h" +#include "graphics.h" /* 'Children' are disposables that are disposed together * with their parent. Currently this is only used by Viewport @@ -31,6 +32,7 @@ inline void disposableAddChild(VALUE disp, VALUE child) { + GFX_LOCK; if (NIL_P(disp) || NIL_P(child)) { return; } @@ -50,11 +52,13 @@ disposableAddChild(VALUE disp, VALUE child) if (!exists) rb_ary_push(children, child); + GFX_UNLOCK; } inline void disposableRemoveChild(VALUE disp, VALUE child) { + GFX_LOCK; if (NIL_P(disp) || NIL_P(child)) { return; } @@ -68,7 +72,7 @@ disposableRemoveChild(VALUE disp, VALUE child) return; rb_funcall(children, rb_intern("delete_at"), 1, index); - + GFX_UNLOCK; } inline void @@ -102,7 +106,9 @@ RB_METHOD(disposableDispose) if (rgssVer == 1) disposableDisposeChildren(self); + GFX_LOCK; d->dispose(); + GFX_UNLOCK; return Qnil; } diff --git a/binding/graphics-binding.cpp b/binding/graphics-binding.cpp index 6b4ce34..d7a02be 100644 --- a/binding/graphics-binding.cpp +++ b/binding/graphics-binding.cpp @@ -31,34 +31,44 @@ RB_METHOD(graphicsDelta) { RB_UNUSED_PARAM; - - return ULL2NUM(shState->graphics().getDelta()); + GFX_LOCK; + VALUE ret = ULL2NUM(shState->graphics().getDelta()); + GFX_UNLOCK; + return ret; } RB_METHOD(graphicsUpdate) { RB_UNUSED_PARAM; #if RAPI_MAJOR >= 2 - rb_thread_call_without_gvl([](void*) -> void* {shState->graphics().update(); return 0;}, 0, 0, 0); + rb_thread_call_without_gvl([](void*) -> void* { + GFX_LOCK; + shState->graphics().update(); + GFX_UNLOCK; + return 0; + }, 0, 0, 0); #else shState->graphics().update(); #endif - return Qnil; } RB_METHOD(graphicsAverageFrameRate) { RB_UNUSED_PARAM; - - return rb_float_new(shState->graphics().averageFrameRate()); + GFX_LOCK; + VALUE ret = rb_float_new(shState->graphics().averageFrameRate()); + GFX_UNLOCK; + return ret; } RB_METHOD(graphicsFreeze) { RB_UNUSED_PARAM; + GFX_LOCK; shState->graphics().freeze(); + GFX_UNLOCK; return Qnil; } @@ -73,7 +83,7 @@ RB_METHOD(graphicsTransition) rb_get_args(argc, argv, "|izi", &duration, &filename, &vague RB_ARG_END); - GUARD_EXC( shState->graphics().transition(duration, filename, vague); ) + GFX_GUARD_EXC( shState->graphics().transition(duration, filename, vague); ) return Qnil; } @@ -82,7 +92,9 @@ RB_METHOD(graphicsFrameReset) { RB_UNUSED_PARAM; + GFX_LOCK; shState->graphics().frameReset(); + GFX_UNLOCK; return Qnil; } @@ -98,7 +110,9 @@ RB_METHOD(graphics##Set##PropName) \ RB_UNUSED_PARAM; \ int value; \ rb_get_args(argc, argv, "i", &value RB_ARG_END); \ +GFX_LOCK; \ shState->graphics().set##PropName(value); \ +GFX_UNLOCK; \ return rb_fix_new(value); \ } @@ -113,7 +127,9 @@ RB_METHOD(graphics##Set##PropName) \ RB_UNUSED_PARAM; \ bool value; \ rb_get_args(argc, argv, "b", &value RB_ARG_END); \ +GFX_LOCK; \ shState->graphics().set##PropName(value); \ +GFX_UNLOCK; \ return rb_bool_new(value); \ } @@ -128,7 +144,9 @@ RB_METHOD(graphics##Set##PropName) \ RB_UNUSED_PARAM; \ double value; \ rb_get_args(argc, argv, "f", &value RB_ARG_END); \ +GFX_LOCK; \ shState->graphics().set##PropName(value); \ +GFX_UNLOCK; \ return rb_float_new(value); \ } @@ -153,11 +171,15 @@ RB_METHOD(graphicsWait) int duration; rb_get_args(argc, argv, "i", &duration RB_ARG_END); #if RAPI_MAJOR >= 2 - rb_thread_call_without_gvl([](void* d) -> void* {shState->graphics().wait(*(int*)d); return 0;}, (int*)&duration, 0, 0); + rb_thread_call_without_gvl([](void* d) -> void* { + GFX_LOCK; + shState->graphics().wait(*(int*)d); + GFX_UNLOCK; + return 0; + }, (int*)&duration, 0, 0); #else shState->graphics().wait(duration); #endif - return Qnil; } @@ -168,7 +190,9 @@ RB_METHOD(graphicsFadeout) int duration; rb_get_args(argc, argv, "i", &duration RB_ARG_END); + GFX_LOCK; shState->graphics().fadeout(duration); + GFX_UNLOCK; return Qnil; } @@ -180,7 +204,9 @@ RB_METHOD(graphicsFadein) int duration; rb_get_args(argc, argv, "i", &duration RB_ARG_END); + GFX_LOCK; shState->graphics().fadein(duration); + GFX_UNLOCK; return Qnil; } @@ -192,7 +218,8 @@ RB_METHOD(graphicsSnapToBitmap) RB_UNUSED_PARAM; Bitmap *result = 0; - GUARD_EXC( result = shState->graphics().snapToBitmap(); ); + + GFX_GUARD_EXC( result = shState->graphics().snapToBitmap(); ); VALUE obj = wrapObject(result, BitmapType); bitmapInitProps(result, obj); @@ -207,7 +234,9 @@ RB_METHOD(graphicsResizeScreen) int width, height; rb_get_args(argc, argv, "ii", &width, &height RB_ARG_END); + GFX_LOCK; shState->graphics().resizeScreen(width, height); + GFX_UNLOCK; return Qnil; } @@ -216,7 +245,9 @@ RB_METHOD(graphicsReset) { RB_UNUSED_PARAM; + GFX_LOCK; shState->graphics().reset(); + GFX_UNLOCK; return Qnil; } @@ -243,14 +274,7 @@ RB_METHOD(graphicsPlayMovie) void graphicsScreenshotInternal(const char *filename) { - try - { - shState->graphics().screenshot(filename); - } - catch(const Exception &e) - { - raiseRbExc(e); - } + GFX_GUARD_EXC(shState->graphics().screenshot(filename);); } RB_METHOD(graphicsScreenshot) @@ -260,8 +284,12 @@ RB_METHOD(graphicsScreenshot) VALUE filename; rb_scan_args(argc, argv, "1", &filename); SafeStringValue(filename); + #if RAPI_MAJOR >= 2 - rb_thread_call_without_gvl([](void* fn) -> void* {graphicsScreenshotInternal((const char*)fn); return 0;}, (void*)filename, 0, 0); + rb_thread_call_without_gvl([](void* fn) -> void* { + graphicsScreenshotInternal((const char*)fn); + return 0; + }, (void*)filename, 0, 0); #else graphicsScreenshotInternal(RSTRING_PTR(filename)); #endif diff --git a/binding/plane-binding.cpp b/binding/plane-binding.cpp index deb7566..3d0e106 100644 --- a/binding/plane-binding.cpp +++ b/binding/plane-binding.cpp @@ -36,25 +36,27 @@ RB_METHOD(planeInitialize) { setPrivateData(self, p); + GFX_LOCK; p->initDynAttribs(); wrapProperty(self, &p->getColor(), "color", ColorType); wrapProperty(self, &p->getTone(), "tone", ToneType); + GFX_UNLOCK; return self; } -DEF_PROP_OBJ_REF(Plane, Bitmap, Bitmap, "bitmap") -DEF_PROP_OBJ_VAL(Plane, Color, Color, "color") -DEF_PROP_OBJ_VAL(Plane, Tone, Tone, "tone") +DEF_GFX_PROP_OBJ_REF(Plane, Bitmap, Bitmap, "bitmap") +DEF_GFX_PROP_OBJ_VAL(Plane, Color, Color, "color") +DEF_GFX_PROP_OBJ_VAL(Plane, Tone, Tone, "tone") -DEF_PROP_I(Plane, OX) -DEF_PROP_I(Plane, OY) -DEF_PROP_I(Plane, Opacity) -DEF_PROP_I(Plane, BlendType) +DEF_GFX_PROP_I(Plane, OX) +DEF_GFX_PROP_I(Plane, OY) +DEF_GFX_PROP_I(Plane, Opacity) +DEF_GFX_PROP_I(Plane, BlendType) -DEF_PROP_F(Plane, ZoomX) -DEF_PROP_F(Plane, ZoomY) +DEF_GFX_PROP_F(Plane, ZoomX) +DEF_GFX_PROP_F(Plane, ZoomY) void planeBindingInit() { VALUE klass = rb_define_class("Plane", rb_cObject); diff --git a/binding/sceneelement-binding.h b/binding/sceneelement-binding.h index 02c019e..7d52d0e 100644 --- a/binding/sceneelement-binding.h +++ b/binding/sceneelement-binding.h @@ -24,6 +24,7 @@ #include "scene.h" #include "binding-util.h" +#include "graphics.h" template RB_METHOD(sceneElementGetZ) @@ -46,7 +47,7 @@ RB_METHOD(sceneElementSetZ) int z; rb_get_args(argc, argv, "i", &z RB_ARG_END); - GUARD_EXC( se->setZ(z); ); + GFX_GUARD_EXC( se->setZ(z); ); return rb_fix_new(z); } @@ -72,7 +73,7 @@ RB_METHOD(sceneElementSetVisible) bool visible; rb_get_args(argc, argv, "b", &visible RB_ARG_END); - GUARD_EXC( se->setVisible(visible); ); + GFX_GUARD_EXC( se->setVisible(visible); ); return rb_bool_new(visible); } diff --git a/binding/sprite-binding.cpp b/binding/sprite-binding.cpp index 453fb14..890cf1d 100644 --- a/binding/sprite-binding.cpp +++ b/binding/sprite-binding.cpp @@ -1,23 +1,23 @@ /* -** sprite-binding.cpp -** -** This file is part of mkxp. -** -** Copyright (C) 2013 Jonas Kulla -** -** mkxp is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** mkxp is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with mkxp. If not, see . -*/ + ** sprite-binding.cpp + ** + ** This file is part of mkxp. + ** + ** Copyright (C) 2013 Jonas Kulla + ** + ** mkxp is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 2 of the License, or + ** (at your option) any later version. + ** + ** mkxp is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with mkxp. If not, see . + */ #include "binding-types.h" #include "binding-util.h" @@ -35,103 +35,105 @@ DEF_ALLOCFUNC(Sprite); #endif RB_METHOD(spriteInitialize) { - Sprite *s = viewportElementInitialize(argc, argv, self); - - setPrivateData(self, s); - - /* Wrap property objects */ - s->initDynAttribs(); - - wrapProperty(self, &s->getSrcRect(), "src_rect", RectType); - wrapProperty(self, &s->getColor(), "color", ColorType); - wrapProperty(self, &s->getTone(), "tone", ToneType); - - return self; + GFX_LOCK; + Sprite *s = viewportElementInitialize(argc, argv, self); + + setPrivateData(self, s); + + /* Wrap property objects */ + s->initDynAttribs(); + + wrapProperty(self, &s->getSrcRect(), "src_rect", RectType); + wrapProperty(self, &s->getColor(), "color", ColorType); + wrapProperty(self, &s->getTone(), "tone", ToneType); + + GFX_UNLOCK; + return self; } -DEF_PROP_OBJ_REF(Sprite, Bitmap, Bitmap, "bitmap") -DEF_PROP_OBJ_VAL(Sprite, Rect, SrcRect, "src_rect") -DEF_PROP_OBJ_VAL(Sprite, Color, Color, "color") -DEF_PROP_OBJ_VAL(Sprite, Tone, Tone, "tone") +DEF_GFX_PROP_OBJ_REF(Sprite, Bitmap, Bitmap, "bitmap") +DEF_GFX_PROP_OBJ_VAL(Sprite, Rect, SrcRect, "src_rect") +DEF_GFX_PROP_OBJ_VAL(Sprite, Color, Color, "color") +DEF_GFX_PROP_OBJ_VAL(Sprite, Tone, Tone, "tone") -DEF_PROP_I(Sprite, X) -DEF_PROP_I(Sprite, Y) -DEF_PROP_I(Sprite, OX) -DEF_PROP_I(Sprite, OY) -DEF_PROP_I(Sprite, BushDepth) -DEF_PROP_I(Sprite, BushOpacity) -DEF_PROP_I(Sprite, Opacity) -DEF_PROP_I(Sprite, BlendType) -DEF_PROP_I(Sprite, WaveAmp) -DEF_PROP_I(Sprite, WaveLength) -DEF_PROP_I(Sprite, WaveSpeed) +DEF_GFX_PROP_I(Sprite, X) +DEF_GFX_PROP_I(Sprite, Y) +DEF_GFX_PROP_I(Sprite, OX) +DEF_GFX_PROP_I(Sprite, OY) +DEF_GFX_PROP_I(Sprite, BushDepth) +DEF_GFX_PROP_I(Sprite, BushOpacity) +DEF_GFX_PROP_I(Sprite, Opacity) +DEF_GFX_PROP_I(Sprite, BlendType) +DEF_GFX_PROP_I(Sprite, WaveAmp) +DEF_GFX_PROP_I(Sprite, WaveLength) +DEF_GFX_PROP_I(Sprite, WaveSpeed) -DEF_PROP_F(Sprite, ZoomX) -DEF_PROP_F(Sprite, ZoomY) -DEF_PROP_F(Sprite, Angle) -DEF_PROP_F(Sprite, WavePhase) +DEF_GFX_PROP_F(Sprite, ZoomX) +DEF_GFX_PROP_F(Sprite, ZoomY) +DEF_GFX_PROP_F(Sprite, Angle) +DEF_GFX_PROP_F(Sprite, WavePhase) -DEF_PROP_B(Sprite, Mirror) +DEF_GFX_PROP_B(Sprite, Mirror) RB_METHOD(spriteWidth) { - RB_UNUSED_PARAM; - - Sprite *s = getPrivateData(self); - - int value = 0; - GUARD_EXC(value = s->getWidth();) - - return rb_fix_new(value); + RB_UNUSED_PARAM; + + Sprite *s = getPrivateData(self); + + int value = 0; + GUARD_EXC(value = s->getWidth();) + + return rb_fix_new(value); } RB_METHOD(spriteHeight) { - RB_UNUSED_PARAM; - - Sprite *s = getPrivateData(self); - - int value = 0; - GUARD_EXC(value = s->getHeight();) - - return rb_fix_new(value); + RB_UNUSED_PARAM; + + Sprite *s = getPrivateData(self); + + int value = 0; + GUARD_EXC(value = s->getHeight();) + + return rb_fix_new(value); } void spriteBindingInit() { - VALUE klass = rb_define_class("Sprite", rb_cObject); + VALUE klass = rb_define_class("Sprite", rb_cObject); #if RAPI_FULL > 187 - rb_define_alloc_func(klass, classAllocate<&SpriteType>); + rb_define_alloc_func(klass, classAllocate<&SpriteType>); #else - rb_define_alloc_func(klass, SpriteAllocate); + rb_define_alloc_func(klass, SpriteAllocate); #endif - - disposableBindingInit(klass); - flashableBindingInit(klass); - viewportElementBindingInit(klass); - - _rb_define_method(klass, "initialize", spriteInitialize); - - INIT_PROP_BIND(Sprite, Bitmap, "bitmap"); - INIT_PROP_BIND(Sprite, SrcRect, "src_rect"); - INIT_PROP_BIND(Sprite, X, "x"); - INIT_PROP_BIND(Sprite, Y, "y"); - INIT_PROP_BIND(Sprite, OX, "ox"); - INIT_PROP_BIND(Sprite, OY, "oy"); - INIT_PROP_BIND(Sprite, ZoomX, "zoom_x"); - INIT_PROP_BIND(Sprite, ZoomY, "zoom_y"); - INIT_PROP_BIND(Sprite, Angle, "angle"); - INIT_PROP_BIND(Sprite, Mirror, "mirror"); - INIT_PROP_BIND(Sprite, BushDepth, "bush_depth"); - INIT_PROP_BIND(Sprite, Opacity, "opacity"); - INIT_PROP_BIND(Sprite, BlendType, "blend_type"); - INIT_PROP_BIND(Sprite, Color, "color"); - INIT_PROP_BIND(Sprite, Tone, "tone"); - - _rb_define_method(klass, "width", spriteWidth); - _rb_define_method(klass, "height", spriteHeight); - - INIT_PROP_BIND(Sprite, BushOpacity, "bush_opacity"); - - INIT_PROP_BIND(Sprite, WaveAmp, "wave_amp"); - INIT_PROP_BIND(Sprite, WaveLength, "wave_length"); - INIT_PROP_BIND(Sprite, WaveSpeed, "wave_speed"); - INIT_PROP_BIND(Sprite, WavePhase, "wave_phase"); + + disposableBindingInit(klass); + flashableBindingInit(klass); + viewportElementBindingInit(klass); + + _rb_define_method(klass, "initialize", spriteInitialize); + + INIT_PROP_BIND(Sprite, Bitmap, "bitmap"); + INIT_PROP_BIND(Sprite, SrcRect, "src_rect"); + INIT_PROP_BIND(Sprite, X, "x"); + INIT_PROP_BIND(Sprite, Y, "y"); + INIT_PROP_BIND(Sprite, OX, "ox"); + INIT_PROP_BIND(Sprite, OY, "oy"); + INIT_PROP_BIND(Sprite, ZoomX, "zoom_x"); + INIT_PROP_BIND(Sprite, ZoomY, "zoom_y"); + INIT_PROP_BIND(Sprite, Angle, "angle"); + INIT_PROP_BIND(Sprite, Mirror, "mirror"); + INIT_PROP_BIND(Sprite, BushDepth, "bush_depth"); + INIT_PROP_BIND(Sprite, Opacity, "opacity"); + INIT_PROP_BIND(Sprite, BlendType, "blend_type"); + INIT_PROP_BIND(Sprite, Color, "color"); + INIT_PROP_BIND(Sprite, Tone, "tone"); + + _rb_define_method(klass, "width", spriteWidth); + _rb_define_method(klass, "height", spriteHeight); + + INIT_PROP_BIND(Sprite, BushOpacity, "bush_opacity"); + + INIT_PROP_BIND(Sprite, WaveAmp, "wave_amp"); + INIT_PROP_BIND(Sprite, WaveLength, "wave_length"); + INIT_PROP_BIND(Sprite, WaveSpeed, "wave_speed"); + INIT_PROP_BIND(Sprite, WavePhase, "wave_phase"); } diff --git a/binding/tilemap-binding.cpp b/binding/tilemap-binding.cpp index 1d6ef7d..9e28739 100644 --- a/binding/tilemap-binding.cpp +++ b/binding/tilemap-binding.cpp @@ -1,23 +1,23 @@ /* -** tilemap-binding.cpp -** -** This file is part of mkxp. -** -** Copyright (C) 2013 Jonas Kulla -** -** mkxp is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** mkxp is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with mkxp. If not, see . -*/ + ** tilemap-binding.cpp + ** + ** This file is part of mkxp. + ** + ** Copyright (C) 2013 Jonas Kulla + ** + ** mkxp is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 2 of the License, or + ** (at your option) any later version. + ** + ** mkxp is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with mkxp. If not, see . + */ #include "bitmap.h" #include "table.h" @@ -35,33 +35,34 @@ DEF_TYPE_CUSTOMFREE(TilemapAutotiles, RUBY_TYPED_NEVER_FREE); #endif RB_METHOD(tilemapAutotilesSet) { - Tilemap::Autotiles *a = getPrivateData(self); - - int i; - VALUE bitmapObj; - - rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END); - - Bitmap *bitmap = getPrivateDataCheck(bitmapObj, BitmapType); - - a->set(i, bitmap); - - VALUE ary = rb_iv_get(self, "array"); - rb_ary_store(ary, i, bitmapObj); - - return self; + Tilemap::Autotiles *a = getPrivateData(self); + + int i; + VALUE bitmapObj; + + rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END); + + Bitmap *bitmap = getPrivateDataCheck(bitmapObj, BitmapType); + + GFX_LOCK; + a->set(i, bitmap); + + VALUE ary = rb_iv_get(self, "array"); + rb_ary_store(ary, i, bitmapObj); + GFX_UNLOCK; + return self; } RB_METHOD(tilemapAutotilesGet) { - int i; - rb_get_args(argc, argv, "i", &i RB_ARG_END); - - if (i < 0 || i > 6) - return Qnil; - - VALUE ary = rb_iv_get(self, "array"); - - return rb_ary_entry(ary, i); + int i; + rb_get_args(argc, argv, "i", &i RB_ARG_END); + + if (i < 0 || i > 6) + return Qnil; + + VALUE ary = rb_iv_get(self, "array"); + + return rb_ary_entry(ary, i); } #if RAPI_FULL > 187 @@ -71,122 +72,126 @@ DEF_ALLOCFUNC(Tilemap); #endif RB_METHOD(tilemapInitialize) { - Tilemap *t; - - /* Get parameters */ - VALUE viewportObj = Qnil; - Viewport *viewport = 0; - - rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END); - - if (!NIL_P(viewportObj)) - viewport = getPrivateDataCheck(viewportObj, ViewportType); - - /* Construct object */ - t = new Tilemap(viewport); - - rb_iv_set(self, "viewport", viewportObj); - - setPrivateData(self, t); - - t->initDynAttribs(); - - wrapProperty(self, &t->getAutotiles(), "autotiles", TilemapAutotilesType); - - wrapProperty(self, &t->getColor(), "color", ColorType); - wrapProperty(self, &t->getTone(), "tone", ToneType); - - VALUE autotilesObj = rb_iv_get(self, "autotiles"); - - VALUE ary = rb_ary_new2(7); - for (int i = 0; i < 7; ++i) - rb_ary_push(ary, Qnil); - - rb_iv_set(autotilesObj, "array", ary); - - /* Circular reference so both objects are always - * alive at the same time */ - rb_iv_set(autotilesObj, "tilemap", self); - - return self; + Tilemap *t; + + /* Get parameters */ + VALUE viewportObj = Qnil; + Viewport *viewport = 0; + + rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END); + + if (!NIL_P(viewportObj)) + viewport = getPrivateDataCheck(viewportObj, ViewportType); + + GFX_LOCK; + /* Construct object */ + t = new Tilemap(viewport); + + rb_iv_set(self, "viewport", viewportObj); + + setPrivateData(self, t); + + t->initDynAttribs(); + + wrapProperty(self, &t->getAutotiles(), "autotiles", TilemapAutotilesType); + + wrapProperty(self, &t->getColor(), "color", ColorType); + wrapProperty(self, &t->getTone(), "tone", ToneType); + + VALUE autotilesObj = rb_iv_get(self, "autotiles"); + + VALUE ary = rb_ary_new2(7); + for (int i = 0; i < 7; ++i) + rb_ary_push(ary, Qnil); + + rb_iv_set(autotilesObj, "array", ary); + + /* Circular reference so both objects are always + * alive at the same time */ + rb_iv_set(autotilesObj, "tilemap", self); + + GFX_UNLOCK; + return self; } RB_METHOD(tilemapGetAutotiles) { - RB_UNUSED_PARAM; - - checkDisposed(self); - - return rb_iv_get(self, "autotiles"); + RB_UNUSED_PARAM; + + checkDisposed(self); + + return rb_iv_get(self, "autotiles"); } RB_METHOD(tilemapUpdate) { - RB_UNUSED_PARAM; - - Tilemap *t = getPrivateData(self); - - t->update(); - - return Qnil; + RB_UNUSED_PARAM; + + Tilemap *t = getPrivateData(self); + + GFX_LOCK; + t->update(); + GFX_UNLOCK; + + return Qnil; } RB_METHOD(tilemapGetViewport) { - RB_UNUSED_PARAM; - - checkDisposed(self); - - return rb_iv_get(self, "viewport"); + RB_UNUSED_PARAM; + + checkDisposed(self); + + return rb_iv_get(self, "viewport"); } -DEF_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, "tileset") -DEF_PROP_OBJ_REF(Tilemap, Table, MapData, "map_data") -DEF_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data") -DEF_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities") +DEF_GFX_PROP_OBJ_REF(Tilemap, Bitmap, Tileset, "tileset") +DEF_GFX_PROP_OBJ_REF(Tilemap, Table, MapData, "map_data") +DEF_GFX_PROP_OBJ_REF(Tilemap, Table, FlashData, "flash_data") +DEF_GFX_PROP_OBJ_REF(Tilemap, Table, Priorities, "priorities") -DEF_PROP_OBJ_VAL(Tilemap, Color, Color, "color") -DEF_PROP_OBJ_VAL(Tilemap, Tone, Tone, "tone") +DEF_GFX_PROP_OBJ_VAL(Tilemap, Color, Color, "color") +DEF_GFX_PROP_OBJ_VAL(Tilemap, Tone, Tone, "tone") -DEF_PROP_B(Tilemap, Visible) +DEF_GFX_PROP_B(Tilemap, Visible) -DEF_PROP_I(Tilemap, OX) -DEF_PROP_I(Tilemap, OY) +DEF_GFX_PROP_I(Tilemap, OX) +DEF_GFX_PROP_I(Tilemap, OY) -DEF_PROP_I(Tilemap, Opacity) -DEF_PROP_I(Tilemap, BlendType) +DEF_GFX_PROP_I(Tilemap, Opacity) +DEF_GFX_PROP_I(Tilemap, BlendType) void tilemapBindingInit() { - VALUE klass = rb_define_class("TilemapAutotiles", rb_cObject); + VALUE klass = rb_define_class("TilemapAutotiles", rb_cObject); #if RAPI_FULL > 187 - rb_define_alloc_func(klass, classAllocate<&TilemapAutotilesType>); + rb_define_alloc_func(klass, classAllocate<&TilemapAutotilesType>); #endif - - _rb_define_method(klass, "[]=", tilemapAutotilesSet); - _rb_define_method(klass, "[]", tilemapAutotilesGet); - - klass = rb_define_class("Tilemap", rb_cObject); + + _rb_define_method(klass, "[]=", tilemapAutotilesSet); + _rb_define_method(klass, "[]", tilemapAutotilesGet); + + klass = rb_define_class("Tilemap", rb_cObject); #if RAPI_FULL > 187 - rb_define_alloc_func(klass, classAllocate<&TilemapType>); + rb_define_alloc_func(klass, classAllocate<&TilemapType>); #else - rb_define_alloc_func(klass, TilemapAllocate); + rb_define_alloc_func(klass, TilemapAllocate); #endif - - disposableBindingInit(klass); - - _rb_define_method(klass, "initialize", tilemapInitialize); - _rb_define_method(klass, "autotiles", tilemapGetAutotiles); - _rb_define_method(klass, "update", tilemapUpdate); - - _rb_define_method(klass, "viewport", tilemapGetViewport); - - INIT_PROP_BIND(Tilemap, Tileset, "tileset"); - INIT_PROP_BIND(Tilemap, MapData, "map_data"); - INIT_PROP_BIND(Tilemap, FlashData, "flash_data"); - INIT_PROP_BIND(Tilemap, Priorities, "priorities"); - INIT_PROP_BIND(Tilemap, Visible, "visible"); - INIT_PROP_BIND(Tilemap, OX, "ox"); - INIT_PROP_BIND(Tilemap, OY, "oy"); - - INIT_PROP_BIND(Tilemap, Opacity, "opacity"); - INIT_PROP_BIND(Tilemap, BlendType, "blend_type"); - INIT_PROP_BIND(Tilemap, Color, "color"); - INIT_PROP_BIND(Tilemap, Tone, "tone"); + + disposableBindingInit(klass); + + _rb_define_method(klass, "initialize", tilemapInitialize); + _rb_define_method(klass, "autotiles", tilemapGetAutotiles); + _rb_define_method(klass, "update", tilemapUpdate); + + _rb_define_method(klass, "viewport", tilemapGetViewport); + + INIT_PROP_BIND(Tilemap, Tileset, "tileset"); + INIT_PROP_BIND(Tilemap, MapData, "map_data"); + INIT_PROP_BIND(Tilemap, FlashData, "flash_data"); + INIT_PROP_BIND(Tilemap, Priorities, "priorities"); + INIT_PROP_BIND(Tilemap, Visible, "visible"); + INIT_PROP_BIND(Tilemap, OX, "ox"); + INIT_PROP_BIND(Tilemap, OY, "oy"); + + INIT_PROP_BIND(Tilemap, Opacity, "opacity"); + INIT_PROP_BIND(Tilemap, BlendType, "blend_type"); + INIT_PROP_BIND(Tilemap, Color, "color"); + INIT_PROP_BIND(Tilemap, Tone, "tone"); } diff --git a/binding/tilemapvx-binding.cpp b/binding/tilemapvx-binding.cpp index 02e4df1..c7e2868 100644 --- a/binding/tilemapvx-binding.cpp +++ b/binding/tilemapvx-binding.cpp @@ -1,23 +1,23 @@ /* -** tilemapvx-binding.cpp -** -** This file is part of mkxp. -** -** Copyright (C) 2014 Jonas Kulla -** -** mkxp is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** mkxp is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with mkxp. If not, see . -*/ + ** tilemapvx-binding.cpp + ** + ** This file is part of mkxp. + ** + ** Copyright (C) 2014 Jonas Kulla + ** + ** mkxp is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 2 of the License, or + ** (at your option) any later version. + ** + ** mkxp is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with mkxp. If not, see . + */ #include "bitmap.h" #include "sharedstate.h" @@ -39,132 +39,135 @@ DEF_ALLOCFUNC(TilemapVX); #endif RB_METHOD(tilemapVXInitialize) { - TilemapVX *t; - - /* Get parameters */ - VALUE viewportObj = Qnil; - Viewport *viewport = 0; - - rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END); - - if (!NIL_P(viewportObj)) - viewport = getPrivateDataCheck(viewportObj, ViewportType); - - /* Construct object */ - t = new TilemapVX(viewport); - - setPrivateData(self, t); - - rb_iv_set(self, "viewport", viewportObj); - - wrapProperty(self, &t->getBitmapArray(), "bitmap_array", BitmapArrayType, - rb_const_get(rb_cObject, rb_intern("Tilemap"))); - - VALUE autotilesObj = rb_iv_get(self, "bitmap_array"); - - VALUE ary = rb_ary_new2(9); - for (int i = 0; i < 9; ++i) - rb_ary_push(ary, Qnil); - - rb_iv_set(autotilesObj, "array", ary); - - /* Circular reference so both objects are always - * alive at the same time */ - rb_iv_set(autotilesObj, "tilemap", self); - - return self; + TilemapVX *t; + + GFX_LOCK; + /* Get parameters */ + VALUE viewportObj = Qnil; + Viewport *viewport = 0; + + rb_get_args(argc, argv, "|o", &viewportObj RB_ARG_END); + + if (!NIL_P(viewportObj)) + viewport = getPrivateDataCheck(viewportObj, ViewportType); + + /* Construct object */ + t = new TilemapVX(viewport); + + setPrivateData(self, t); + + rb_iv_set(self, "viewport", viewportObj); + + wrapProperty(self, &t->getBitmapArray(), "bitmap_array", BitmapArrayType, + rb_const_get(rb_cObject, rb_intern("Tilemap"))); + + VALUE autotilesObj = rb_iv_get(self, "bitmap_array"); + + VALUE ary = rb_ary_new2(9); + for (int i = 0; i < 9; ++i) + rb_ary_push(ary, Qnil); + + rb_iv_set(autotilesObj, "array", ary); + + /* Circular reference so both objects are always + * alive at the same time */ + rb_iv_set(autotilesObj, "tilemap", self); + + GFX_UNLOCK; + return self; } RB_METHOD(tilemapVXGetBitmapArray) { - RB_UNUSED_PARAM; - - checkDisposed(self); - - return rb_iv_get(self, "bitmap_array"); + RB_UNUSED_PARAM; + + checkDisposed(self); + + return rb_iv_get(self, "bitmap_array"); } RB_METHOD(tilemapVXUpdate) { - RB_UNUSED_PARAM; - - TilemapVX *t = getPrivateData(self); - - t->update(); - - return Qnil; + RB_UNUSED_PARAM; + + TilemapVX *t = getPrivateData(self); + + t->update(); + + return Qnil; } -DEF_PROP_OBJ_REF(TilemapVX, Viewport, Viewport, "viewport") -DEF_PROP_OBJ_REF(TilemapVX, Table, MapData, "map_data") -DEF_PROP_OBJ_REF(TilemapVX, Table, FlashData, "flash_data") -DEF_PROP_OBJ_REF(TilemapVX, Table, Flags, "flags") +DEF_GFX_PROP_OBJ_REF(TilemapVX, Viewport, Viewport, "viewport") +DEF_GFX_PROP_OBJ_REF(TilemapVX, Table, MapData, "map_data") +DEF_GFX_PROP_OBJ_REF(TilemapVX, Table, FlashData, "flash_data") +DEF_GFX_PROP_OBJ_REF(TilemapVX, Table, Flags, "flags") -DEF_PROP_B(TilemapVX, Visible) +DEF_GFX_PROP_B(TilemapVX, Visible) -DEF_PROP_I(TilemapVX, OX) -DEF_PROP_I(TilemapVX, OY) +DEF_GFX_PROP_I(TilemapVX, OX) +DEF_GFX_PROP_I(TilemapVX, OY) RB_METHOD(tilemapVXBitmapsSet) { - TilemapVX::BitmapArray *a = getPrivateData(self); - - int i; - VALUE bitmapObj; - - rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END); - - Bitmap *bitmap = getPrivateDataCheck(bitmapObj, BitmapType); - - a->set(i, bitmap); - - VALUE ary = rb_iv_get(self, "array"); - rb_ary_store(ary, i, bitmapObj); - - return self; + TilemapVX::BitmapArray *a = getPrivateData(self); + + int i; + VALUE bitmapObj; + + rb_get_args(argc, argv, "io", &i, &bitmapObj RB_ARG_END); + + Bitmap *bitmap = getPrivateDataCheck(bitmapObj, BitmapType); + + GFX_LOCK; + a->set(i, bitmap); + + VALUE ary = rb_iv_get(self, "array"); + rb_ary_store(ary, i, bitmapObj); + GFX_UNLOCK; + return self; } RB_METHOD(tilemapVXBitmapsGet) { - int i; - rb_get_args(argc, argv, "i", &i RB_ARG_END); - - if (i < 0 || i > 8) - return Qnil; - - VALUE ary = rb_iv_get(self, "array"); - - return rb_ary_entry(ary, i); + int i; + rb_get_args(argc, argv, "i", &i RB_ARG_END); + + if (i < 0 || i > 8) + return Qnil; + + VALUE ary = rb_iv_get(self, "array"); + + return rb_ary_entry(ary, i); } void tilemapVXBindingInit() { - VALUE klass = rb_define_class("Tilemap", rb_cObject); + VALUE klass = rb_define_class("Tilemap", rb_cObject); #if RAPI_FULL > 187 - rb_define_alloc_func(klass, classAllocate<&TilemapVXType>); + rb_define_alloc_func(klass, classAllocate<&TilemapVXType>); #else - rb_define_alloc_func(klass, TilemapVXAllocate); + rb_define_alloc_func(klass, TilemapVXAllocate); #endif - - disposableBindingInit(klass); - - _rb_define_method(klass, "initialize", tilemapVXInitialize); - _rb_define_method(klass, "bitmaps", tilemapVXGetBitmapArray); - _rb_define_method(klass, "update", tilemapVXUpdate); - - INIT_PROP_BIND(TilemapVX, Viewport, "viewport"); - INIT_PROP_BIND(TilemapVX, MapData, "map_data"); - INIT_PROP_BIND(TilemapVX, FlashData, "flash_data"); - INIT_PROP_BIND(TilemapVX, Visible, "visible"); - INIT_PROP_BIND(TilemapVX, OX, "ox"); - INIT_PROP_BIND(TilemapVX, OY, "oy"); - - if (rgssVer == 3) { - INIT_PROP_BIND(TilemapVX, Flags, "flags"); - } else { - INIT_PROP_BIND(TilemapVX, Flags, "passages"); - } - - klass = rb_define_class_under(klass, "BitmapArray", rb_cObject); + + disposableBindingInit(klass); + + _rb_define_method(klass, "initialize", tilemapVXInitialize); + _rb_define_method(klass, "bitmaps", tilemapVXGetBitmapArray); + _rb_define_method(klass, "update", tilemapVXUpdate); + + INIT_PROP_BIND(TilemapVX, Viewport, "viewport"); + INIT_PROP_BIND(TilemapVX, MapData, "map_data"); + INIT_PROP_BIND(TilemapVX, FlashData, "flash_data"); + INIT_PROP_BIND(TilemapVX, Visible, "visible"); + INIT_PROP_BIND(TilemapVX, OX, "ox"); + INIT_PROP_BIND(TilemapVX, OY, "oy"); + + if (rgssVer == 3) { + INIT_PROP_BIND(TilemapVX, Flags, "flags"); + } else { + INIT_PROP_BIND(TilemapVX, Flags, "passages"); + } + + klass = rb_define_class_under(klass, "BitmapArray", rb_cObject); #if RAPI_FULL > 187 - rb_define_alloc_func(klass, classAllocate<&BitmapArrayType>); + rb_define_alloc_func(klass, classAllocate<&BitmapArrayType>); #endif - - _rb_define_method(klass, "[]=", tilemapVXBitmapsSet); - _rb_define_method(klass, "[]", tilemapVXBitmapsGet); + + _rb_define_method(klass, "[]=", tilemapVXBitmapsSet); + _rb_define_method(klass, "[]", tilemapVXBitmapsGet); } diff --git a/binding/viewport-binding.cpp b/binding/viewport-binding.cpp index b84aaee..cbf503e 100644 --- a/binding/viewport-binding.cpp +++ b/binding/viewport-binding.cpp @@ -1,23 +1,23 @@ /* -** viewport-binding.cpp -** -** This file is part of mkxp. -** -** Copyright (C) 2013 Jonas Kulla -** -** mkxp is free software: you can redistribute it and/or modify -** it under the terms of the GNU General Public License as published by -** the Free Software Foundation, either version 2 of the License, or -** (at your option) any later version. -** -** mkxp is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with mkxp. If not, see . -*/ + ** viewport-binding.cpp + ** + ** This file is part of mkxp. + ** + ** Copyright (C) 2013 Jonas Kulla + ** + ** mkxp is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 2 of the License, or + ** (at your option) any later version. + ** + ** mkxp is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with mkxp. If not, see . + */ #include "binding-types.h" #include "binding-util.h" @@ -34,70 +34,72 @@ DEF_ALLOCFUNC(Viewport); #endif RB_METHOD(viewportInitialize) { - Viewport *v; - - if (argc == 0 && rgssVer >= 3) { - v = new Viewport(); - } else if (argc == 1) { - /* The rect arg is only used to init the viewport, - * and does NOT replace its 'rect' property */ - VALUE rectObj; - Rect *rect; - - rb_get_args(argc, argv, "o", &rectObj RB_ARG_END); - - rect = getPrivateDataCheck(rectObj, RectType); - - v = new Viewport(rect); - } else { - int x, y, width, height; - - rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END); - - v = new Viewport(x, y, width, height); - } - - setPrivateData(self, v); - - /* Wrap property objects */ - v->initDynAttribs(); - - wrapProperty(self, &v->getRect(), "rect", RectType); - wrapProperty(self, &v->getColor(), "color", ColorType); - 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; + Viewport *v; + + if (argc == 0 && rgssVer >= 3) { + GFX_LOCK; + v = new Viewport(); + } else if (argc == 1) { + /* The rect arg is only used to init the viewport, + * and does NOT replace its 'rect' property */ + VALUE rectObj; + Rect *rect; + + rb_get_args(argc, argv, "o", &rectObj RB_ARG_END); + + rect = getPrivateDataCheck(rectObj, RectType); + + GFX_LOCK; + v = new Viewport(rect); + } else { + int x, y, width, height; + + rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END); + GFX_LOCK; + v = new Viewport(x, y, width, height); + } + + setPrivateData(self, v); + + /* Wrap property objects */ + v->initDynAttribs(); + + wrapProperty(self, &v->getRect(), "rect", RectType); + wrapProperty(self, &v->getColor(), "color", ColorType); + 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()); + GFX_UNLOCK; + return self; } -DEF_PROP_OBJ_VAL(Viewport, Rect, Rect, "rect") -DEF_PROP_OBJ_VAL(Viewport, Color, Color, "color") -DEF_PROP_OBJ_VAL(Viewport, Tone, Tone, "tone") +DEF_GFX_PROP_OBJ_VAL(Viewport, Rect, Rect, "rect") +DEF_GFX_PROP_OBJ_VAL(Viewport, Color, Color, "color") +DEF_GFX_PROP_OBJ_VAL(Viewport, Tone, Tone, "tone") -DEF_PROP_I(Viewport, OX) -DEF_PROP_I(Viewport, OY) +DEF_GFX_PROP_I(Viewport, OX) +DEF_GFX_PROP_I(Viewport, OY) void viewportBindingInit() { - VALUE klass = rb_define_class("Viewport", rb_cObject); + VALUE klass = rb_define_class("Viewport", rb_cObject); #if RAPI_FULL > 187 - rb_define_alloc_func(klass, classAllocate<&ViewportType>); + rb_define_alloc_func(klass, classAllocate<&ViewportType>); #else - rb_define_alloc_func(klass, ViewportAllocate); + rb_define_alloc_func(klass, ViewportAllocate); #endif - - disposableBindingInit(klass); - flashableBindingInit(klass); - sceneElementBindingInit(klass); - - _rb_define_method(klass, "initialize", viewportInitialize); - - INIT_PROP_BIND(Viewport, Rect, "rect"); - INIT_PROP_BIND(Viewport, OX, "ox"); - INIT_PROP_BIND(Viewport, OY, "oy"); - INIT_PROP_BIND(Viewport, Color, "color"); - INIT_PROP_BIND(Viewport, Tone, "tone"); + + disposableBindingInit(klass); + flashableBindingInit(klass); + sceneElementBindingInit(klass); + + _rb_define_method(klass, "initialize", viewportInitialize); + + INIT_PROP_BIND(Viewport, Rect, "rect"); + INIT_PROP_BIND(Viewport, OX, "ox"); + INIT_PROP_BIND(Viewport, OY, "oy"); + INIT_PROP_BIND(Viewport, Color, "color"); + INIT_PROP_BIND(Viewport, Tone, "tone"); } diff --git a/binding/viewportelement-binding.h b/binding/viewportelement-binding.h index b057155..21c9d1b 100644 --- a/binding/viewportelement-binding.h +++ b/binding/viewportelement-binding.h @@ -27,6 +27,7 @@ #include "binding-util.h" #include "binding-types.h" #include "debugwriter.h" +#include "graphics.h" #include "sceneelement-binding.h" #include "disposable-binding.h" @@ -62,7 +63,7 @@ RB_METHOD(viewportElementSetViewport) disposableAddChild(viewportObj, self); } - GUARD_EXC( ve->setViewport(viewport); ); + GFX_GUARD_EXC( ve->setViewport(viewport); ); rb_iv_set(self, "viewport", viewportObj); @@ -87,13 +88,14 @@ viewportElementInitialize(int argc, VALUE *argv, VALUE self) disposableAddChild(viewportObj, self); } + GFX_LOCK; /* Construct object */ C *ve = new C(viewport); /* Set property objects */ rb_iv_set(self, "viewport", viewportObj); - + GFX_UNLOCK; return ve; } diff --git a/binding/window-binding.cpp b/binding/window-binding.cpp index 677375f..102466a 100644 --- a/binding/window-binding.cpp +++ b/binding/window-binding.cpp @@ -31,6 +31,7 @@ DEF_ALLOCFUNC(Window); #endif RB_METHOD(windowInitialize) { + GFX_LOCK; Window *w = viewportElementInitialize(argc, argv, self); setPrivateData(self, w); @@ -39,6 +40,7 @@ RB_METHOD(windowInitialize) { wrapProperty(self, &w->getCursorRect(), "cursor_rect", RectType); + GFX_UNLOCK; return self; } @@ -47,28 +49,28 @@ RB_METHOD(windowUpdate) { Window *w = getPrivateData(self); - GUARD_EXC(w->update();); + GFX_GUARD_EXC(w->update();); return Qnil; } -DEF_PROP_OBJ_REF(Window, Bitmap, Windowskin, "windowskin") -DEF_PROP_OBJ_REF(Window, Bitmap, Contents, "contents") -DEF_PROP_OBJ_VAL(Window, Rect, CursorRect, "cursor_rect") +DEF_GFX_PROP_OBJ_REF(Window, Bitmap, Windowskin, "windowskin") +DEF_GFX_PROP_OBJ_REF(Window, Bitmap, Contents, "contents") +DEF_GFX_PROP_OBJ_VAL(Window, Rect, CursorRect, "cursor_rect") -DEF_PROP_B(Window, Stretch) -DEF_PROP_B(Window, Active) -DEF_PROP_B(Window, Pause) +DEF_GFX_PROP_B(Window, Stretch) +DEF_GFX_PROP_B(Window, Active) +DEF_GFX_PROP_B(Window, Pause) -DEF_PROP_I(Window, X) -DEF_PROP_I(Window, Y) -DEF_PROP_I(Window, Width) -DEF_PROP_I(Window, Height) -DEF_PROP_I(Window, OX) -DEF_PROP_I(Window, OY) -DEF_PROP_I(Window, Opacity) -DEF_PROP_I(Window, BackOpacity) -DEF_PROP_I(Window, ContentsOpacity) +DEF_GFX_PROP_I(Window, X) +DEF_GFX_PROP_I(Window, Y) +DEF_GFX_PROP_I(Window, Width) +DEF_GFX_PROP_I(Window, Height) +DEF_GFX_PROP_I(Window, OX) +DEF_GFX_PROP_I(Window, OY) +DEF_GFX_PROP_I(Window, Opacity) +DEF_GFX_PROP_I(Window, BackOpacity) +DEF_GFX_PROP_I(Window, ContentsOpacity) void windowBindingInit() { VALUE klass = rb_define_class("Window", rb_cObject); diff --git a/binding/windowvx-binding.cpp b/binding/windowvx-binding.cpp index 3dc891d..f44b27a 100644 --- a/binding/windowvx-binding.cpp +++ b/binding/windowvx-binding.cpp @@ -25,6 +25,7 @@ #include "windowvx.h" #include "bitmap.h" +#include "graphics.h" #if RAPI_FULL > 187 DEF_TYPE_CUSTOMNAME(WindowVX, "Window"); @@ -37,6 +38,7 @@ void bitmapInitProps(Bitmap *b, VALUE self); RB_METHOD(windowVXInitialize) { WindowVX *w; + GFX_LOCK; if (rgssVer >= 3) { int x, y, width, height; x = y = width = height = 0; @@ -63,6 +65,7 @@ RB_METHOD(windowVXInitialize) { bitmapInitProps(contents, contentsObj); rb_iv_set(self, "contents", contentsObj); + GFX_UNLOCK; return self; } @@ -71,7 +74,9 @@ RB_METHOD(windowVXUpdate) { WindowVX *w = getPrivateData(self); + GFX_LOCK; w->update(); + GFX_UNLOCK; return Qnil; } @@ -82,8 +87,10 @@ RB_METHOD(windowVXMove) { int x, y, width, height; rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END); + GFX_LOCK; w->move(x, y, width, height); - + GFX_UNLOCK; + return Qnil; } @@ -103,28 +110,28 @@ RB_METHOD(windowVXIsClosed) { return rb_bool_new(w->isClosed()); } -DEF_PROP_OBJ_REF(WindowVX, Bitmap, Windowskin, "windowskin") -DEF_PROP_OBJ_REF(WindowVX, Bitmap, Contents, "contents") +DEF_GFX_PROP_OBJ_REF(WindowVX, Bitmap, Windowskin, "windowskin") +DEF_GFX_PROP_OBJ_REF(WindowVX, Bitmap, Contents, "contents") -DEF_PROP_OBJ_VAL(WindowVX, Rect, CursorRect, "cursor_rect") -DEF_PROP_OBJ_VAL(WindowVX, Tone, Tone, "tone") +DEF_GFX_PROP_OBJ_VAL(WindowVX, Rect, CursorRect, "cursor_rect") +DEF_GFX_PROP_OBJ_VAL(WindowVX, Tone, Tone, "tone") -DEF_PROP_I(WindowVX, X) -DEF_PROP_I(WindowVX, Y) -DEF_PROP_I(WindowVX, OX) -DEF_PROP_I(WindowVX, OY) -DEF_PROP_I(WindowVX, Width) -DEF_PROP_I(WindowVX, Height) -DEF_PROP_I(WindowVX, Padding) -DEF_PROP_I(WindowVX, PaddingBottom) -DEF_PROP_I(WindowVX, Opacity) -DEF_PROP_I(WindowVX, BackOpacity) -DEF_PROP_I(WindowVX, ContentsOpacity) -DEF_PROP_I(WindowVX, Openness) +DEF_GFX_PROP_I(WindowVX, X) +DEF_GFX_PROP_I(WindowVX, Y) +DEF_GFX_PROP_I(WindowVX, OX) +DEF_GFX_PROP_I(WindowVX, OY) +DEF_GFX_PROP_I(WindowVX, Width) +DEF_GFX_PROP_I(WindowVX, Height) +DEF_GFX_PROP_I(WindowVX, Padding) +DEF_GFX_PROP_I(WindowVX, PaddingBottom) +DEF_GFX_PROP_I(WindowVX, Opacity) +DEF_GFX_PROP_I(WindowVX, BackOpacity) +DEF_GFX_PROP_I(WindowVX, ContentsOpacity) +DEF_GFX_PROP_I(WindowVX, Openness) -DEF_PROP_B(WindowVX, Active) -DEF_PROP_B(WindowVX, ArrowsVisible) -DEF_PROP_B(WindowVX, Pause) +DEF_GFX_PROP_B(WindowVX, Active) +DEF_GFX_PROP_B(WindowVX, ArrowsVisible) +DEF_GFX_PROP_B(WindowVX, Pause) void windowVXBindingInit() { VALUE klass = rb_define_class("Window", rb_cObject); diff --git a/src/display/bitmap.cpp b/src/display/bitmap.cpp index e2c0517..9c0475d 100644 --- a/src/display/bitmap.cpp +++ b/src/display/bitmap.cpp @@ -762,7 +762,7 @@ int Bitmap::height() const bool Bitmap::isMega() const{ guardDisposed(); - return p->megaSurface || p->animation.enabled; + return p->megaSurface; } bool Bitmap::isAnimated() const { diff --git a/src/display/graphics.cpp b/src/display/graphics.cpp index 0d84f62..fb84541 100644 --- a/src/display/graphics.cpp +++ b/src/display/graphics.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #ifdef MKXPZ_STEAM #include "steamshim_child.h" @@ -609,25 +610,18 @@ struct GraphicsPrivate { return ret; } - void lockResources() { + void setLock() { SDL_LockMutex(glResourceLock); - SDL_GL_MakeCurrent(threadData->window, glCtx); + SDL_GL_MakeCurrent(threadData->window, threadData->glContext); } - void unlockResources() { + void releaseLock() { SDL_UnlockMutex(glResourceLock); } }; -#define GRAPHICS_THREAD_LOCK(exp) \ -p->lockResources(); \ -{ \ - exp \ -} - Graphics::Graphics(RGSSThreadData *data) { p = new GraphicsPrivate(data); - // To appease people who don't want players to have // emulator-like speedups // Nothing stops anybody from building with this @@ -660,8 +654,8 @@ unsigned long long Graphics::lastUpdate() { return p->last_update; } -void Graphics::update() {GRAPHICS_THREAD_LOCK( - +void Graphics::update() { + p->last_update = shState->runTime(); p->checkShutDownReset(); p->checkSyncLock(); @@ -691,9 +685,9 @@ void Graphics::update() {GRAPHICS_THREAD_LOCK( p->checkResize(); p->redrawScreen(); -)} +} -void Graphics::freeze() {GRAPHICS_THREAD_LOCK( +void Graphics::freeze() { p->frozen = true; p->checkShutDownReset(); @@ -701,9 +695,9 @@ void Graphics::freeze() {GRAPHICS_THREAD_LOCK( /* Capture scene into frozen buffer */ p->compositeToBuffer(p->frozenScene); -)} +} -void Graphics::transition(int duration, const char *filename, int vague) {GRAPHICS_THREAD_LOCK( +void Graphics::transition(int duration, const char *filename, int vague) { p->checkSyncLock(); if (!p->frozen) @@ -804,9 +798,9 @@ void Graphics::transition(int duration, const char *filename, int vague) {GRAPHI delete transMap; p->frozen = false; -)} +} -void Graphics::frameReset() {GRAPHICS_THREAD_LOCK(p->fpsLimiter.resetFrameAdjust();)} +void Graphics::frameReset() {p->fpsLimiter.resetFrameAdjust();} static void guardDisposed() {} @@ -814,7 +808,7 @@ DEF_ATTR_RD_SIMPLE(Graphics, FrameRate, int, p->frameRate) DEF_ATTR_SIMPLE(Graphics, FrameCount, int, p->frameCount) -void Graphics::setFrameRate(int value) {GRAPHICS_THREAD_LOCK( +void Graphics::setFrameRate(int value) { p->frameRate = clamp(value, 10, 120); if (p->threadData->config.syncToRefreshrate) @@ -825,20 +819,20 @@ void Graphics::setFrameRate(int value) {GRAPHICS_THREAD_LOCK( p->fpsLimiter.setDesiredFPS(p->frameRate); shState->input().recalcRepeat((unsigned int)p->frameRate); -)} +} double Graphics::averageFrameRate() { return p->averageFPS(); } -void Graphics::wait(int duration) {GRAPHICS_THREAD_LOCK( +void Graphics::wait(int duration) { for (int i = 0; i < duration; ++i) { p->checkShutDownReset(); p->redrawScreen(); } -)} +} -void Graphics::fadeout(int duration) {GRAPHICS_THREAD_LOCK( +void Graphics::fadeout(int duration) { FBO::unbind(); float curr = p->brightness; @@ -861,9 +855,9 @@ void Graphics::fadeout(int duration) {GRAPHICS_THREAD_LOCK( update(); } } -)} +} -void Graphics::fadein(int duration) {GRAPHICS_THREAD_LOCK( +void Graphics::fadein(int duration) { FBO::unbind(); float curr = p->brightness; @@ -886,17 +880,15 @@ void Graphics::fadein(int duration) {GRAPHICS_THREAD_LOCK( update(); } } -)} +} Bitmap *Graphics::snapToBitmap() { Bitmap *bitmap = new Bitmap(width(), height()); + + p->compositeToBuffer(bitmap->getGLTypes()); - GRAPHICS_THREAD_LOCK( - p->compositeToBuffer(bitmap->getGLTypes()); - - /* Taint entire bitmap */ - bitmap->taintArea(IntRect(0, 0, width(), height())); - ); + /* Taint entire bitmap */ + bitmap->taintArea(IntRect(0, 0, width(), height())); return bitmap; } @@ -904,7 +896,7 @@ int Graphics::width() const { return p->scRes.x; } int Graphics::height() const { return p->scRes.y; } -void Graphics::resizeScreen(int width, int height) {GRAPHICS_THREAD_LOCK( +void Graphics::resizeScreen(int width, int height) { // width = clamp(width, 1, 640); // height = clamp(height, 1, 480); @@ -929,19 +921,19 @@ void Graphics::resizeScreen(int width, int height) {GRAPHICS_THREAD_LOCK( p->threadData->rqWindowAdjust.set(); shState->eThread().requestWindowResize(width, height); update(); -)} +} void Graphics::playMovie(const char *filename) { Debug() << "Graphics.playMovie(" << filename << ") not implemented"; } -void Graphics::screenshot(const char *filename) {GRAPHICS_THREAD_LOCK( +void Graphics::screenshot(const char *filename) { p->threadData->rqWindowAdjust.wait(); Bitmap *ss = snapToBitmap(); ss->saveToFile(filename); ss->dispose(); delete ss; -)} +} DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness) @@ -955,7 +947,7 @@ void Graphics::setBrightness(int value) { p->screen.setBrightness(value / 255.0); } -void Graphics::reset() {GRAPHICS_THREAD_LOCK( +void Graphics::reset() { /* Dispose all live Disposables */ IntruListLink *iter; @@ -973,35 +965,35 @@ void Graphics::reset() {GRAPHICS_THREAD_LOCK( setFrameRate(DEF_FRAMERATE); setBrightness(255); -)} +} -void Graphics::center() {GRAPHICS_THREAD_LOCK( +void Graphics::center() { if (getFullscreen()) return; p->threadData->rqWindowAdjust.reset(); p->threadData->ethread->requestWindowCenter(); -)} +} bool Graphics::getFullscreen() const { return p->threadData->ethread->getFullscreen(); } -void Graphics::setFullscreen(bool value) {GRAPHICS_THREAD_LOCK( +void Graphics::setFullscreen(bool value) { p->threadData->ethread->requestFullscreenMode(value); -)} +} bool Graphics::getShowCursor() const { return p->threadData->ethread->getShowCursor(); } -void Graphics::setShowCursor(bool value) {GRAPHICS_THREAD_LOCK( +void Graphics::setShowCursor(bool value) { p->threadData->ethread->requestShowCursor(value); -)} +} double Graphics::getScale() const { return (double)p->scSize.y / p->scRes.y; } -void Graphics::setScale(double factor) {GRAPHICS_THREAD_LOCK( +void Graphics::setScale(double factor) { p->threadData->rqWindowAdjust.wait(); factor = clamp(factor, 0.5, 2.0); @@ -1014,7 +1006,7 @@ void Graphics::setScale(double factor) {GRAPHICS_THREAD_LOCK( p->threadData->rqWindowAdjust.set(); shState->eThread().requestWindowResize(widthpx, heightpx); update(); -)} +} bool Graphics::getFrameskip() const { return p->useFrameSkip; } @@ -1048,13 +1040,12 @@ void Graphics::repaintWait(const AtomicFlag &exitCond, bool checkReset) { GLMeta::blitEnd(); } -void Graphics::lockResources(bool lock) { - if (lock) { - p->lockResources(); - return; - } - - p->unlockResources(); +void Graphics::lock() { + p->setLock(); +} + +void Graphics::unlock() { + p->releaseLock(); } void Graphics::addDisposable(Disposable *d) { p->dispList.append(d->link); } diff --git a/src/display/graphics.h b/src/display/graphics.h index ff3ddcc..8cb1e77 100644 --- a/src/display/graphics.h +++ b/src/display/graphics.h @@ -78,7 +78,8 @@ public: void repaintWait(const AtomicFlag &exitCond, bool checkReset = true); - void lockResources(bool lock); + void lock(); + void unlock(); private: Graphics(RGSSThreadData *data); @@ -93,10 +94,7 @@ private: GraphicsPrivate *p; }; -#define GFX_BLOCK(exp) \ -shState->graphics().lockResources(true); \ -{ \ - exp \ -} +#define GFX_LOCK shState->graphics().lock() +#define GFX_UNLOCK shState->graphics().unlock() #endif // GRAPHICS_H diff --git a/src/net/net.cpp b/src/net/net.cpp index c012b88..3594599 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -147,9 +147,11 @@ HTTPResponse HTTPRequest::get() { else { int err = result.error(); const char *errname = httpErrorNames[err]; + delete client; throw Exception(Exception::MKXPError, "Failed to GET %s (%i: %s)", destination.c_str(), err, errname); } + delete client; return ret; } @@ -192,8 +194,10 @@ HTTPResponse HTTPRequest::post(StringMap &postData) { else { int err = result.error(); const char *errname = httpErrorNames[err]; + delete client; throw Exception(Exception::MKXPError, "Failed to POST %s (%i: %s)", destination.c_str(), err, errname); } + delete client; return ret; } @@ -231,7 +235,9 @@ HTTPResponse HTTPRequest::post(const char *body, const char *content_type) { } else { int err = result.error(); + delete client; throw Exception(Exception::MKXPError, "Failed to POST %s (%i: %s)", destination.c_str(), err, httpErrorNames[err]); } + delete client; return ret; }