Prevent relevant functions from stepping over Graphics.update when threading

This commit is contained in:
Roza 2021-06-04 14:29:45 -04:00
parent c8ac923c1a
commit fbd1783ea3
17 changed files with 762 additions and 609 deletions

View file

@ -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 <class C>
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<Klass>(self); \
VALUE propObj = *argv; \
PropKlass *prop; \
if (NIL_P(propObj)) \
prop = 0; \
else \
prop = getPrivateDataCheck<PropKlass>(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<Klass>(self); \
return rb_iv_get(self, prop_iv); \
} \
RB_METHOD(Klass##Set##PropName) { \
rb_check_argc(argc, 1); \
Klass *k = getPrivateData<Klass>(self); \
VALUE propObj = *argv; \
PropKlass *prop; \
prop = getPrivateDataCheck<PropKlass>(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<Klass>(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<Klass>(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

View file

@ -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<Bitmap>(srcObj, BitmapType);
srcRect = getPrivateDataCheck<Rect>(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<Rect>(destRectObj, RectType);
srcRect = getPrivateDataCheck<Rect>(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<Rect>(rectObj, RectType);
color = getPrivateDataCheck<Color>(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<Color>(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;
@ -187,7 +190,7 @@ RB_METHOD(bitmapClear) {
Bitmap *b = getPrivateData<Bitmap>(self);
GUARD_EXC(b->clear();)
GFX_GUARD_EXC(b->clear();)
return self;
}
@ -219,7 +222,7 @@ RB_METHOD(bitmapSetPixel) {
color = getPrivateDataCheck<Color>(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<Rect>(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<Bitmap>(self);
@ -320,7 +323,7 @@ RB_METHOD(bitmapGradientFillRect) {
color1 = getPrivateDataCheck<Color>(color1Obj, ColorType);
color2 = getPrivateDataCheck<Color>(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<Color>(color1Obj, ColorType);
color2 = getPrivateDataCheck<Color>(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<Rect>(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<Bitmap>(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<Bitmap>(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<Bitmap>(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<Bitmap>(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<Bitmap>(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<Bitmap>(self);
GUARD_EXC(b->stop(););
GFX_GUARD_EXC(b->stop(););
return RUBY_Qnil;
}
@ -501,7 +504,7 @@ RB_METHOD(bitmapGotoStop){
Bitmap *b = getPrivateData<Bitmap>(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<Bitmap>(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<Bitmap>(self);
GUARD_EXC(b->nextFrame(););
GFX_GUARD_EXC(b->nextFrame(););
return INT2NUM(b->currentFrameI());
}
@ -604,7 +607,7 @@ RB_METHOD(bitmapPreviousFrame){
Bitmap *b = getPrivateData<Bitmap>(self);
GUARD_EXC(b->previousFrame(););
GFX_GUARD_EXC(b->previousFrame(););
return INT2NUM(b->currentFrameI());
}
@ -617,7 +620,7 @@ RB_METHOD(bitmapSetFPS){
Bitmap *b = getPrivateData<Bitmap>(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<Bitmap>(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<Bitmap>(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;

View file

@ -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;
}

View file

@ -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

View file

@ -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);

View file

@ -24,6 +24,7 @@
#include "scene.h"
#include "binding-util.h"
#include "graphics.h"
template<class C>
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);
}

View file

@ -35,6 +35,7 @@ DEF_ALLOCFUNC(Sprite);
#endif
RB_METHOD(spriteInitialize) {
GFX_LOCK;
Sprite *s = viewportElementInitialize<Sprite>(argc, argv, self);
setPrivateData(self, s);
@ -46,32 +47,33 @@ RB_METHOD(spriteInitialize) {
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;

View file

@ -44,11 +44,12 @@ RB_METHOD(tilemapAutotilesSet) {
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(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;
}
@ -82,6 +83,7 @@ RB_METHOD(tilemapInitialize) {
if (!NIL_P(viewportObj))
viewport = getPrivateDataCheck<Viewport>(viewportObj, ViewportType);
GFX_LOCK;
/* Construct object */
t = new Tilemap(viewport);
@ -108,6 +110,7 @@ RB_METHOD(tilemapInitialize) {
* alive at the same time */
rb_iv_set(autotilesObj, "tilemap", self);
GFX_UNLOCK;
return self;
}
@ -124,7 +127,9 @@ RB_METHOD(tilemapUpdate) {
Tilemap *t = getPrivateData<Tilemap>(self);
GFX_LOCK;
t->update();
GFX_UNLOCK;
return Qnil;
}
@ -137,21 +142,21 @@ RB_METHOD(tilemapGetViewport) {
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);

View file

@ -41,6 +41,7 @@ DEF_ALLOCFUNC(TilemapVX);
RB_METHOD(tilemapVXInitialize) {
TilemapVX *t;
GFX_LOCK;
/* Get parameters */
VALUE viewportObj = Qnil;
Viewport *viewport = 0;
@ -72,6 +73,7 @@ RB_METHOD(tilemapVXInitialize) {
* alive at the same time */
rb_iv_set(autotilesObj, "tilemap", self);
GFX_UNLOCK;
return self;
}
@ -93,15 +95,15 @@ RB_METHOD(tilemapVXUpdate) {
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<TilemapVX::BitmapArray>(self);
@ -113,11 +115,12 @@ RB_METHOD(tilemapVXBitmapsSet) {
Bitmap *bitmap = getPrivateDataCheck<Bitmap>(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;
}

View file

@ -37,6 +37,7 @@ RB_METHOD(viewportInitialize) {
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,
@ -48,12 +49,13 @@ RB_METHOD(viewportInitialize) {
rect = getPrivateDataCheck<Rect>(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);
}
@ -70,16 +72,16 @@ RB_METHOD(viewportInitialize) {
* 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);

View file

@ -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;
}

View file

@ -31,6 +31,7 @@ DEF_ALLOCFUNC(Window);
#endif
RB_METHOD(windowInitialize) {
GFX_LOCK;
Window *w = viewportElementInitialize<Window>(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<Window>(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);

View file

@ -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<WindowVX>(self);
GFX_LOCK;
w->update();
GFX_UNLOCK;
return Qnil;
}
@ -82,7 +87,9 @@ 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);

View file

@ -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 {

View file

@ -45,6 +45,7 @@
#include <SDL_timer.h>
#include <SDL_video.h>
#include <SDL_mutex.h>
#include <SDL_thread.h>
#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,7 +654,7 @@ 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();
@ -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());
GRAPHICS_THREAD_LOCK(
p->compositeToBuffer(bitmap->getGLTypes());
/* 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<Disposable> *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;
void Graphics::lock() {
p->setLock();
}
p->unlockResources();
void Graphics::unlock() {
p->releaseLock();
}
void Graphics::addDisposable(Disposable *d) { p->dispList.append(d->link); }

View file

@ -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

View file

@ -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;
}