Ifdef out more RGSS2 functionality

This commit is contained in:
Jonas Kulla 2013-10-06 09:55:27 +02:00
parent ce70b6dc95
commit dd25323cdd
8 changed files with 143 additions and 82 deletions

View File

@ -117,7 +117,17 @@ RB_METHOD(tilemapUpdate)
#define DISP_CLASS_NAME "tilemap" #define DISP_CLASS_NAME "tilemap"
DEF_PROP_OBJ(Tilemap, Viewport, Viewport, "viewport") RB_METHOD(tilemapGetViewport)
{
RB_UNUSED_PARAM;
Tilemap *t = getPrivateData<Tilemap>(self);
checkDisposed(t, DISP_CLASS_NAME);
return rb_iv_get(self, "viewport");
}
DEF_PROP_OBJ(Tilemap, Bitmap, Tileset, "tileset") DEF_PROP_OBJ(Tilemap, Bitmap, Tileset, "tileset")
DEF_PROP_OBJ(Tilemap, Table, MapData, "map_data") DEF_PROP_OBJ(Tilemap, Table, MapData, "map_data")
DEF_PROP_OBJ(Tilemap, Table, FlashData, "flash_data") DEF_PROP_OBJ(Tilemap, Table, FlashData, "flash_data")
@ -148,7 +158,8 @@ tilemapBindingInit()
_rb_define_method(klass, "autotiles", tilemapGetAutotiles); _rb_define_method(klass, "autotiles", tilemapGetAutotiles);
_rb_define_method(klass, "update", tilemapUpdate); _rb_define_method(klass, "update", tilemapUpdate);
INIT_PROP_BIND( Tilemap, Viewport, "viewport" ); _rb_define_method(klass, "viewport", tilemapGetViewport);
INIT_PROP_BIND( Tilemap, Tileset, "tileset" ); INIT_PROP_BIND( Tilemap, Tileset, "tileset" );
INIT_PROP_BIND( Tilemap, MapData, "map_data" ); INIT_PROP_BIND( Tilemap, MapData, "map_data" );
INIT_PROP_BIND( Tilemap, FlashData, "flash_data" ); INIT_PROP_BIND( Tilemap, FlashData, "flash_data" );

View File

@ -120,7 +120,15 @@ MRB_METHOD(tilemapUpdate)
#define DISP_CLASS_NAME "tilemap" #define DISP_CLASS_NAME "tilemap"
DEF_PROP_OBJ(Tilemap, Viewport, Viewport, CSviewport) MRB_METHOD(tilemapGetViewport)
{
Tilemap *t = getPrivateData<Tilemap>(mrb, self);
checkDisposed(mrb, t, DISP_CLASS_NAME);
return getProperty(mrb, self, CSviewport);
}
DEF_PROP_OBJ(Tilemap, Bitmap, Tileset, CStileset) DEF_PROP_OBJ(Tilemap, Bitmap, Tileset, CStileset)
DEF_PROP_OBJ(Tilemap, Table, MapData, CSmap_data) DEF_PROP_OBJ(Tilemap, Table, MapData, CSmap_data)
DEF_PROP_OBJ(Tilemap, Table, FlashData, CSflash_data) DEF_PROP_OBJ(Tilemap, Table, FlashData, CSflash_data)
@ -148,7 +156,8 @@ tilemapBindingInit(mrb_state *mrb)
mrb_define_method(mrb, klass, "autotiles", tilemapGetAutotiles, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "autotiles", tilemapGetAutotiles, MRB_ARGS_NONE());
mrb_define_method(mrb, klass, "update", tilemapUpdate, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "update", tilemapUpdate, MRB_ARGS_NONE());
INIT_PROP_BIND( Tilemap, Viewport, "viewport" ); mrb_define_method(mrb, klass, "viewport", tilemapGetViewport, MRB_ARGS_NONE());
INIT_PROP_BIND( Tilemap, Tileset, "tileset" ); INIT_PROP_BIND( Tilemap, Tileset, "tileset" );
INIT_PROP_BIND( Tilemap, MapData, "map_data" ); INIT_PROP_BIND( Tilemap, MapData, "map_data" );
INIT_PROP_BIND( Tilemap, FlashData, "flash_data" ); INIT_PROP_BIND( Tilemap, FlashData, "flash_data" );

View File

@ -130,11 +130,14 @@ class ScreenScene : public Scene
public: public:
ScreenScene(int width, int height) ScreenScene(int width, int height)
: pp(width, height), : pp(width, height),
brightEffect(false),
actW(width), actH(height) actW(width), actH(height)
{ {
updateReso(width, height); updateReso(width, height);
#ifdef RGSS2
brightEffect = false;
brightnessQuad.setColor(Vec4()); brightnessQuad.setColor(Vec4());
#endif
} }
void composite() void composite()
@ -152,6 +155,7 @@ public:
Scene::composite(); Scene::composite();
#ifdef RGSS2
if (brightEffect) if (brightEffect)
{ {
SimpleColorShader &shader = gState->simpleColorShader(); SimpleColorShader &shader = gState->simpleColorShader();
@ -161,6 +165,7 @@ public:
brightnessQuad.draw(); brightnessQuad.draw();
} }
#endif
pp.finishRender(); pp.finishRender();
} }
@ -186,12 +191,14 @@ public:
shader.unbind(); shader.unbind();
} }
#ifdef RGSS2
void setBrightness(float norm) void setBrightness(float norm)
{ {
brightnessQuad.setColor(Vec4(0, 0, 0, 1.0 - norm)); brightnessQuad.setColor(Vec4(0, 0, 0, 1.0 - norm));
brightEffect = norm < 1.0; brightEffect = norm < 1.0;
} }
#endif
void updateReso(int width, int height) void updateReso(int width, int height)
{ {
@ -199,7 +206,10 @@ public:
geometry.rect.h = height; geometry.rect.h = height;
screenQuad.setTexPosRect(geometry.rect, geometry.rect); screenQuad.setTexPosRect(geometry.rect, geometry.rect);
#ifdef RGSS2
brightnessQuad.setTexPosRect(geometry.rect, geometry.rect); brightnessQuad.setTexPosRect(geometry.rect, geometry.rect);
#endif
notifyGeometryChange(); notifyGeometryChange();
} }
@ -224,9 +234,12 @@ public:
private: private:
PingPong pp; PingPong pp;
Quad screenQuad; Quad screenQuad;
int actW, actH;
#ifdef RGSS2
Quad brightnessQuad; Quad brightnessQuad;
bool brightEffect; bool brightEffect;
int actW, actH; #endif
}; };
struct FPSLimiter struct FPSLimiter
@ -284,7 +297,10 @@ struct GraphicsPrivate
int frameRate; int frameRate;
int frameCount; int frameCount;
#ifdef RGSS2
int brightness; int brightness;
#endif
FPSLimiter fpsLimiter; FPSLimiter fpsLimiter;
@ -304,7 +320,9 @@ struct GraphicsPrivate
screen(scRes.x, scRes.y), screen(scRes.x, scRes.y),
frameRate(40), frameRate(40),
frameCount(0), frameCount(0),
#ifdef RGSS2
brightness(255), brightness(255),
#endif
fpsLimiter(frameRate), fpsLimiter(frameRate),
frozen(false) frozen(false)
{ {
@ -457,58 +475,6 @@ void Graphics::update()
// p->cpuTimer->startTiming(); // p->cpuTimer->startTiming();
} }
void Graphics::wait(int duration)
{
for (int i = 0; i < duration; ++i)
{
gState->checkShutdown();
p->checkResize();
p->redrawScreen();
}
}
void Graphics::fadeout(int duration)
{
if (p->frozen)
FBO::bind(p->frozenScene.fbo, FBO::Read);
for (int i = duration-1; i > -1; --i)
{
setBrightness((255.0 / duration) * i);
if (p->frozen)
{
p->blitToScreen();
p->swapGLBuffer();
}
else
{
update();
}
}
}
void Graphics::fadein(int duration)
{
if (p->frozen)
FBO::bind(p->frozenScene.fbo, FBO::Read);
for (int i = 0; i < duration; ++i)
{
setBrightness((255.0 / duration) * i);
if (p->frozen)
{
p->blitToScreen();
p->swapGLBuffer();
}
else
{
update();
}
}
}
void Graphics::freeze() void Graphics::freeze()
{ {
p->frozen = true; p->frozen = true;
@ -527,7 +493,9 @@ void Graphics::transition(int duration,
vague = clamp(vague, 0, 512); vague = clamp(vague, 0, 512);
Bitmap *transMap = filename ? new Bitmap(filename) : 0; Bitmap *transMap = filename ? new Bitmap(filename) : 0;
#ifdef RGSS2
setBrightness(255); setBrightness(255);
#endif
/* Capture new scene */ /* Capture new scene */
p->compositeToBuffer(p->currentScene.fbo); p->compositeToBuffer(p->currentScene.fbo);
@ -594,6 +562,81 @@ void Graphics::transition(int duration,
p->frozen = false; p->frozen = false;
} }
void Graphics::frameReset()
{
}
#undef RET_IF_DISP
#define RET_IF_DISP(x)
#undef CHK_DISP
#define CHK_DISP
DEF_ATTR_RD_SIMPLE(Graphics, FrameRate, int, p->frameRate)
DEF_ATTR_SIMPLE(Graphics, FrameCount, int, p->frameCount)
void Graphics::setFrameRate(int value)
{
p->frameRate = clamp(value, 10, 120);
p->fpsLimiter.setDesiredFPS(p->frameRate);
}
#ifdef RGSS2
void Graphics::wait(int duration)
{
for (int i = 0; i < duration; ++i)
{
gState->checkShutdown();
p->checkResize();
p->redrawScreen();
}
}
void Graphics::fadeout(int duration)
{
if (p->frozen)
FBO::bind(p->frozenScene.fbo, FBO::Read);
for (int i = duration-1; i > -1; --i)
{
setBrightness((255.0 / duration) * i);
if (p->frozen)
{
p->blitToScreen();
p->swapGLBuffer();
}
else
{
update();
}
}
}
void Graphics::fadein(int duration)
{
if (p->frozen)
FBO::bind(p->frozenScene.fbo, FBO::Read);
for (int i = 0; i < duration; ++i)
{
setBrightness((255.0 / duration) * i);
if (p->frozen)
{
p->blitToScreen();
p->swapGLBuffer();
}
else
{
update();
}
}
}
Bitmap *Graphics::snapToBitmap() Bitmap *Graphics::snapToBitmap()
{ {
Bitmap *bitmap = new Bitmap(width(), height()); Bitmap *bitmap = new Bitmap(width(), height());
@ -603,11 +646,6 @@ Bitmap *Graphics::snapToBitmap()
return bitmap; return bitmap;
} }
void Graphics::frameReset()
{
}
int Graphics::width() const int Graphics::width() const
{ {
return p->scRes.x; return p->scRes.x;
@ -648,23 +686,8 @@ void Graphics::resizeScreen(int width, int height)
p->updateScreenResoRatio(); p->updateScreenResoRatio();
} }
#undef RET_IF_DISP
#define RET_IF_DISP(x)
#undef CHK_DISP
#define CHK_DISP
DEF_ATTR_RD_SIMPLE(Graphics, FrameRate, int, p->frameRate)
DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness) DEF_ATTR_RD_SIMPLE(Graphics, Brightness, int, p->brightness)
DEF_ATTR_SIMPLE(Graphics, FrameCount, int, p->frameCount)
void Graphics::setFrameRate(int value)
{
p->frameRate = clamp(value, 10, 120);
p->fpsLimiter.setDesiredFPS(p->frameRate);
}
void Graphics::setBrightness(int value) void Graphics::setBrightness(int value)
{ {
value = clamp(value, 0, 255); value = clamp(value, 0, 255);
@ -676,6 +699,8 @@ void Graphics::setBrightness(int value)
p->screen.setBrightness(value / 255.0); p->screen.setBrightness(value / 255.0);
} }
#endif
bool Graphics::getFullscreen() const bool Graphics::getFullscreen() const
{ {
return p->threadData->ethread->getFullscreen(); return p->threadData->ethread->getFullscreen();

View File

@ -40,22 +40,24 @@ public:
void transition(int duration = 8, void transition(int duration = 8,
const char *filename = 0, const char *filename = 0,
int vague = 40); int vague = 40);
void frameReset();
DECL_ATTR( FrameRate, int )
DECL_ATTR( FrameCount, int )
#ifdef RGSS2
void wait(int duration); void wait(int duration);
void fadeout(int duration); void fadeout(int duration);
void fadein(int duration); void fadein(int duration);
Bitmap *snapToBitmap(); Bitmap *snapToBitmap();
void frameReset();
int width() const; int width() const;
int height() const; int height() const;
void resizeScreen(int width, int height); void resizeScreen(int width, int height);
DECL_ATTR( FrameRate, int )
DECL_ATTR( FrameCount, int )
DECL_ATTR( Brightness, int ) DECL_ATTR( Brightness, int )
#endif
/* Non-standard extension */ /* Non-standard extension */
DECL_ATTR( Fullscreen, bool ) DECL_ATTR( Fullscreen, bool )

View File

@ -1265,6 +1265,8 @@ DEF_ATTR_RD_SIMPLE(Tilemap, Visible, bool, p->visible)
DEF_ATTR_RD_SIMPLE(Tilemap, OX, int, p->offset.x) DEF_ATTR_RD_SIMPLE(Tilemap, OX, int, p->offset.x)
DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->offset.y) DEF_ATTR_RD_SIMPLE(Tilemap, OY, int, p->offset.y)
#ifdef RGSS2
void Tilemap::setViewport(Viewport *value) void Tilemap::setViewport(Viewport *value)
{ {
GUARD_DISPOSED GUARD_DISPOSED
@ -1283,6 +1285,8 @@ void Tilemap::setViewport(Viewport *value)
p->elem.scanrows[i]->setViewport(value); p->elem.scanrows[i]->setViewport(value);
} }
#endif
void Tilemap::setTileset(Bitmap *value) void Tilemap::setTileset(Bitmap *value)
{ {
GUARD_DISPOSED GUARD_DISPOSED

View File

@ -53,7 +53,11 @@ public:
Autotiles &getAutotiles() const; Autotiles &getAutotiles() const;
#ifndef RGSS2
Viewport *getViewport() const;
#else
DECL_ATTR( Viewport, Viewport* ) DECL_ATTR( Viewport, Viewport* )
#endif
DECL_ATTR( Tileset, Bitmap* ) DECL_ATTR( Tileset, Bitmap* )
DECL_ATTR( MapData, Table* ) DECL_ATTR( MapData, Table* )
DECL_ATTR( FlashData, Table* ) DECL_ATTR( FlashData, Table* )

View File

@ -240,6 +240,8 @@ Viewport *ViewportElement::getViewport() const
return m_viewport; return m_viewport;
} }
#ifdef RGSS2
void ViewportElement::setViewport(Viewport *viewport) void ViewportElement::setViewport(Viewport *viewport)
{ {
m_viewport = viewport; m_viewport = viewport;
@ -247,3 +249,5 @@ void ViewportElement::setViewport(Viewport *viewport)
onViewportChange(); onViewportChange();
onGeometryChange(scene->getGeometry()); onGeometryChange(scene->getGeometry());
} }
#endif

View File

@ -69,7 +69,9 @@ public:
Viewport *getViewport() const; Viewport *getViewport() const;
#ifdef RGSS2
void setViewport(Viewport *viewport = 0); void setViewport(Viewport *viewport = 0);
#endif
protected: protected:
virtual void onViewportChange() {} virtual void onViewportChange() {}