2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** sprite.cpp
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sprite.h"
|
|
|
|
|
2013-10-09 10:30:33 +00:00
|
|
|
#include "sharedstate.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
#include "bitmap.h"
|
|
|
|
#include "etc.h"
|
|
|
|
#include "etc-internal.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
#include "gl-util.h"
|
|
|
|
#include "quad.h"
|
|
|
|
#include "transform.h"
|
|
|
|
#include "shader.h"
|
|
|
|
#include "glstate.h"
|
2014-02-03 14:32:50 +00:00
|
|
|
#include "quadarray.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-12-06 02:24:53 +00:00
|
|
|
#include <SDL_rect.h>
|
|
|
|
|
2013-12-04 16:48:37 +00:00
|
|
|
#include <sigc++/connection.h>
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
struct SpritePrivate
|
|
|
|
{
|
|
|
|
Bitmap *bitmap;
|
2014-08-09 16:35:01 +00:00
|
|
|
DisposeWatch<SpritePrivate, Bitmap> bitmapWatch;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
Quad quad;
|
|
|
|
Transform trans;
|
|
|
|
|
|
|
|
Rect *srcRect;
|
|
|
|
sigc::connection srcRectCon;
|
|
|
|
|
|
|
|
bool mirrored;
|
|
|
|
int bushDepth;
|
|
|
|
float efBushDepth;
|
|
|
|
NormValue bushOpacity;
|
|
|
|
NormValue opacity;
|
|
|
|
BlendType blendType;
|
|
|
|
|
2013-12-06 02:24:53 +00:00
|
|
|
SDL_Rect sceneRect;
|
|
|
|
|
|
|
|
/* Would this sprite be visible on
|
|
|
|
* the screen if drawn? */
|
|
|
|
bool isVisible;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
Color *color;
|
|
|
|
Tone *tone;
|
|
|
|
|
2014-02-03 14:32:50 +00:00
|
|
|
#ifdef RGSS2
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int amp;
|
|
|
|
int length;
|
|
|
|
int speed;
|
|
|
|
float phase;
|
|
|
|
|
|
|
|
/* Wave effect is active (amp != 0) */
|
|
|
|
bool active;
|
|
|
|
/* qArray needs updating */
|
|
|
|
bool dirty;
|
|
|
|
SimpleQuadArray qArray;
|
|
|
|
} wave;
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
EtcTemps tmp;
|
|
|
|
|
2013-10-17 13:28:55 +00:00
|
|
|
sigc::connection prepareCon;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
SpritePrivate()
|
|
|
|
: bitmap(0),
|
2014-08-12 19:12:28 +00:00
|
|
|
bitmapWatch(*this, bitmap),
|
2013-09-01 14:27:21 +00:00
|
|
|
srcRect(&tmp.rect),
|
|
|
|
mirrored(false),
|
|
|
|
bushDepth(0),
|
|
|
|
efBushDepth(0),
|
|
|
|
bushOpacity(128),
|
|
|
|
opacity(255),
|
|
|
|
blendType(BlendNormal),
|
2013-12-06 02:24:53 +00:00
|
|
|
isVisible(false),
|
2013-09-01 14:27:21 +00:00
|
|
|
color(&tmp.color),
|
|
|
|
tone(&tmp.tone)
|
|
|
|
|
|
|
|
{
|
2013-12-06 02:24:53 +00:00
|
|
|
sceneRect.x = sceneRect.y = 0;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
updateSrcRectCon();
|
2013-10-17 13:28:55 +00:00
|
|
|
|
|
|
|
prepareCon = shState->prepareDraw.connect
|
|
|
|
(sigc::mem_fun(this, &SpritePrivate::prepare));
|
2014-02-03 14:32:50 +00:00
|
|
|
|
|
|
|
#ifdef RGSS2
|
|
|
|
wave.amp = 0;
|
|
|
|
wave.length = 180;
|
|
|
|
wave.speed = 360;
|
|
|
|
wave.phase = 0.0;
|
2014-08-16 02:02:44 +00:00
|
|
|
wave.dirty = false;
|
2014-02-03 14:32:50 +00:00
|
|
|
#endif
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~SpritePrivate()
|
|
|
|
{
|
|
|
|
srcRectCon.disconnect();
|
2013-10-17 13:28:55 +00:00
|
|
|
prepareCon.disconnect();
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void recomputeBushDepth()
|
|
|
|
{
|
2013-10-01 00:29:02 +00:00
|
|
|
if (!bitmap)
|
|
|
|
return;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
/* Calculate effective (normalized) bush depth */
|
|
|
|
float texBushDepth = (bushDepth / trans.getScale().y) -
|
|
|
|
(srcRect->y + srcRect->height) +
|
|
|
|
bitmap->height();
|
|
|
|
|
|
|
|
efBushDepth = 1.0 - texBushDepth / bitmap->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void onSrcRectChange()
|
|
|
|
{
|
|
|
|
if (mirrored)
|
|
|
|
quad.setTexRect(srcRect->toFloatRect().hFlipped());
|
|
|
|
else
|
|
|
|
quad.setTexRect(srcRect->toFloatRect());
|
|
|
|
|
|
|
|
quad.setPosRect(IntRect(0, 0, srcRect->width, srcRect->height));
|
|
|
|
recomputeBushDepth();
|
2014-02-03 14:32:50 +00:00
|
|
|
|
|
|
|
#ifdef RGSS2
|
|
|
|
wave.dirty = true;
|
|
|
|
#endif
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void updateSrcRectCon()
|
|
|
|
{
|
|
|
|
/* Cut old connection */
|
|
|
|
srcRectCon.disconnect();
|
|
|
|
/* Create new one */
|
|
|
|
srcRectCon = srcRect->valueChanged.connect
|
|
|
|
(sigc::mem_fun(this, &SpritePrivate::onSrcRectChange));
|
|
|
|
}
|
2013-10-17 13:28:55 +00:00
|
|
|
|
2013-12-06 02:24:53 +00:00
|
|
|
void updateVisibility()
|
|
|
|
{
|
|
|
|
isVisible = false;
|
|
|
|
|
|
|
|
if (!bitmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!opacity)
|
|
|
|
return;
|
|
|
|
|
2014-02-03 14:32:50 +00:00
|
|
|
#ifdef RGSS2
|
|
|
|
if (wave.active)
|
|
|
|
{
|
|
|
|
/* Don't do expensive wave bounding box
|
|
|
|
* calculations */
|
|
|
|
isVisible = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-06 02:24:53 +00:00
|
|
|
/* Compare sprite bounding box against the scene */
|
|
|
|
|
|
|
|
/* If sprite is zoomed/rotated, just opt out for now
|
|
|
|
* for simplicity's sake */
|
|
|
|
const Vec2 &scale = trans.getScale();
|
|
|
|
if (scale.x != 1 || scale.y != 1 || trans.getRotation() != 0)
|
|
|
|
{
|
|
|
|
isVisible = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Rect self;
|
|
|
|
self.x = trans.getPosition().x - trans.getOrigin().x;
|
|
|
|
self.y = trans.getPosition().y - trans.getOrigin().y;
|
|
|
|
self.w = bitmap->width();
|
|
|
|
self.h = bitmap->height();
|
|
|
|
|
|
|
|
isVisible = SDL_HasIntersection(&self, &sceneRect);
|
|
|
|
}
|
|
|
|
|
2014-02-03 14:32:50 +00:00
|
|
|
#ifdef RGSS2
|
|
|
|
void emitWaveChunk(SVertex *&vert, float phase, int width,
|
|
|
|
float zoomY, int chunkY, int chunkLength)
|
|
|
|
{
|
|
|
|
float wavePos = phase + (chunkY / (float) wave.length) * M_PI * 2;
|
|
|
|
float chunkX = sin(wavePos) * wave.amp;
|
|
|
|
|
|
|
|
FloatRect tex(0, chunkY / zoomY, width, chunkLength / zoomY);
|
|
|
|
FloatRect pos = tex;
|
|
|
|
pos.x = chunkX;
|
|
|
|
|
|
|
|
Quad::setTexPosRect(vert, tex, pos);
|
|
|
|
vert += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateWave()
|
|
|
|
{
|
|
|
|
if (!bitmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wave.amp == 0)
|
|
|
|
{
|
|
|
|
wave.active = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wave.active = true;
|
|
|
|
|
|
|
|
int width = srcRect->width;
|
|
|
|
int height = srcRect->height;
|
|
|
|
float zoomY = trans.getScale().y;
|
|
|
|
|
|
|
|
if (wave.amp < -(width / 2))
|
|
|
|
{
|
|
|
|
wave.qArray.resize(0);
|
|
|
|
wave.qArray.commit();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* RMVX does this, and I have no fucking clue why */
|
|
|
|
if (wave.amp < 0)
|
|
|
|
{
|
|
|
|
wave.qArray.resize(1);
|
|
|
|
|
|
|
|
int x = -wave.amp;
|
|
|
|
int w = width - x * 2;
|
|
|
|
|
|
|
|
FloatRect tex(x, srcRect->y, w, srcRect->height);
|
|
|
|
|
|
|
|
Quad::setTexPosRect(&wave.qArray.vertices[0], tex, tex);
|
|
|
|
wave.qArray.commit();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The length of the sprite as it appears on screen */
|
|
|
|
int visibleLength = height * zoomY;
|
|
|
|
|
|
|
|
/* First chunk length (aligned to 8 pixel boundary */
|
|
|
|
int firstLength = ((int) trans.getPosition().y) % 8;
|
|
|
|
|
|
|
|
/* Amount of full 8 pixel chunks in the middle */
|
|
|
|
int chunks = (visibleLength - firstLength) / 8;
|
|
|
|
|
|
|
|
/* Final chunk length */
|
|
|
|
int lastLength = (visibleLength - firstLength) % 8;
|
|
|
|
|
|
|
|
wave.qArray.resize(!!firstLength + chunks + !!lastLength);
|
|
|
|
SVertex *vert = &wave.qArray.vertices[0];
|
|
|
|
|
|
|
|
float phase = (wave.phase * M_PI) / 180.f;
|
|
|
|
|
|
|
|
if (firstLength > 0)
|
|
|
|
emitWaveChunk(vert, phase, width, zoomY, 0, firstLength);
|
|
|
|
|
|
|
|
for (int i = 0; i < chunks; ++i)
|
|
|
|
emitWaveChunk(vert, phase, width, zoomY, firstLength + i * 8, 8);
|
|
|
|
|
|
|
|
if (lastLength > 0)
|
|
|
|
emitWaveChunk(vert, phase, width, zoomY, firstLength + chunks * 8, lastLength);
|
|
|
|
|
|
|
|
wave.qArray.commit();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-10-17 13:28:55 +00:00
|
|
|
void prepare()
|
|
|
|
{
|
2014-02-03 14:32:50 +00:00
|
|
|
#ifdef RGSS2
|
|
|
|
if (wave.dirty)
|
|
|
|
{
|
|
|
|
updateWave();
|
|
|
|
wave.dirty = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-12-06 02:24:53 +00:00
|
|
|
updateVisibility();
|
2013-10-17 13:28:55 +00:00
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Sprite::Sprite(Viewport *viewport)
|
|
|
|
: ViewportElement(viewport)
|
|
|
|
{
|
|
|
|
p = new SpritePrivate;
|
|
|
|
onGeometryChange(scene->getGeometry());
|
|
|
|
}
|
|
|
|
|
|
|
|
Sprite::~Sprite()
|
|
|
|
{
|
2014-08-09 16:35:01 +00:00
|
|
|
unlink();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-08-09 16:35:01 +00:00
|
|
|
delete p;
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, Bitmap, Bitmap*, p->bitmap)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, SrcRect, Rect*, p->srcRect)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, X, int, p->trans.getPosition().x)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, Y, int, p->trans.getPosition().y)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, OX, int, p->trans.getOrigin().x)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, OY, int, p->trans.getOrigin().y)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, ZoomX, float, p->trans.getScale().x)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, ZoomY, float, p->trans.getScale().y)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, Angle, float, p->trans.getRotation())
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, Mirror, bool, p->mirrored)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, BushDepth, int, p->bushDepth)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, BlendType, int, p->blendType)
|
|
|
|
|
|
|
|
DEF_ATTR_SIMPLE(Sprite, BushOpacity, int, p->bushOpacity)
|
|
|
|
DEF_ATTR_SIMPLE(Sprite, Opacity, int, p->opacity)
|
|
|
|
DEF_ATTR_SIMPLE(Sprite, Color, Color*, p->color)
|
|
|
|
DEF_ATTR_SIMPLE(Sprite, Tone, Tone*, p->tone)
|
|
|
|
|
2014-02-03 14:32:50 +00:00
|
|
|
#ifdef RGSS2
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, Width, int, p->srcRect->width)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, Height, int, p->srcRect->height)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, WaveAmp, int, p->wave.amp)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, WaveLength, int, p->wave.length)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, WaveSpeed, int, p->wave.speed)
|
|
|
|
DEF_ATTR_RD_SIMPLE(Sprite, WavePhase, float, p->wave.phase)
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
void Sprite::setBitmap(Bitmap *bitmap)
|
|
|
|
{
|
|
|
|
if (p->bitmap == bitmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->bitmap = bitmap;
|
2014-08-09 16:35:01 +00:00
|
|
|
p->bitmapWatch.update(bitmap);
|
2013-09-28 19:48:02 +00:00
|
|
|
|
|
|
|
if (!bitmap)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bitmap->ensureNonMega();
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
*p->srcRect = bitmap->rect();
|
|
|
|
p->onSrcRectChange();
|
|
|
|
p->quad.setPosRect(p->srcRect->toFloatRect());
|
2014-02-03 14:32:50 +00:00
|
|
|
|
|
|
|
#ifdef RGSS2
|
|
|
|
p->wave.dirty = true;
|
|
|
|
#endif
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setSrcRect(Rect *rect)
|
|
|
|
{
|
|
|
|
if (p->srcRect == rect)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->srcRect = rect;
|
|
|
|
p->updateSrcRectCon();
|
|
|
|
|
|
|
|
if (p->bitmap)
|
|
|
|
p->onSrcRectChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setX(int value)
|
|
|
|
{
|
|
|
|
if (p->trans.getPosition().x == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->trans.setPosition(Vec2(value, getY()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setY(int value)
|
|
|
|
{
|
|
|
|
if (p->trans.getPosition().y == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->trans.setPosition(Vec2(getX(), value));
|
2014-02-03 14:32:50 +00:00
|
|
|
|
|
|
|
#ifdef RGSS2
|
|
|
|
p->wave.dirty = true;
|
|
|
|
#endif
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setOX(int value)
|
|
|
|
{
|
|
|
|
if (p->trans.getOrigin().x == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->trans.setOrigin(Vec2(value, getOY()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setOY(int value)
|
|
|
|
{
|
|
|
|
if (p->trans.getOrigin().y == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->trans.setOrigin(Vec2(getOX(), value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setZoomX(float value)
|
|
|
|
{
|
|
|
|
if (p->trans.getScale().x == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->trans.setScale(Vec2(value, getZoomY()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setZoomY(float value)
|
|
|
|
{
|
|
|
|
if (p->trans.getScale().y == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->trans.setScale(Vec2(getZoomX(), value));
|
|
|
|
p->recomputeBushDepth();
|
2014-02-03 14:32:50 +00:00
|
|
|
|
|
|
|
#ifdef RGSS2
|
|
|
|
p->wave.dirty = true;
|
|
|
|
#endif
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setAngle(float value)
|
|
|
|
{
|
|
|
|
if (p->trans.getRotation() == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->trans.setRotation(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setMirror(bool mirrored)
|
|
|
|
{
|
|
|
|
if (p->mirrored == mirrored)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->mirrored = mirrored;
|
|
|
|
p->onSrcRectChange();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setBushDepth(int value)
|
|
|
|
{
|
|
|
|
if (p->bushDepth == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p->bushDepth = value;
|
|
|
|
p->recomputeBushDepth();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::setBlendType(int type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
default :
|
|
|
|
case BlendNormal :
|
|
|
|
p->blendType = BlendNormal;
|
|
|
|
return;
|
|
|
|
case BlendAddition :
|
|
|
|
p->blendType = BlendAddition;
|
|
|
|
return;
|
|
|
|
case BlendSubstraction :
|
|
|
|
p->blendType = BlendSubstraction;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-03 14:32:50 +00:00
|
|
|
#ifdef RGSS2
|
|
|
|
|
|
|
|
#define DEF_WAVE_SETTER(Name, name, type) \
|
|
|
|
void Sprite::setWave##Name(type value) \
|
|
|
|
{ \
|
|
|
|
if (p->wave.name == value) \
|
|
|
|
return; \
|
|
|
|
p->wave.name = value; \
|
|
|
|
p->wave.dirty = true; \
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_WAVE_SETTER(Amp, amp, int)
|
|
|
|
DEF_WAVE_SETTER(Length, length, int)
|
|
|
|
DEF_WAVE_SETTER(Speed, speed, int)
|
|
|
|
DEF_WAVE_SETTER(Phase, phase, float)
|
|
|
|
|
|
|
|
#undef DEF_WAVE_SETTER
|
|
|
|
|
|
|
|
/* Flashable */
|
|
|
|
void Sprite::update()
|
|
|
|
{
|
|
|
|
Flashable::update();
|
|
|
|
|
|
|
|
p->wave.phase += p->wave.speed / 180;
|
|
|
|
p->wave.dirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
/* SceneElement */
|
|
|
|
void Sprite::draw()
|
|
|
|
{
|
2013-12-06 02:24:53 +00:00
|
|
|
if (!p->isVisible)
|
2013-12-05 17:27:53 +00:00
|
|
|
return;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
if (emptyFlashFlag)
|
|
|
|
return;
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
ShaderBase *base;
|
|
|
|
|
|
|
|
bool renderEffect = p->color->hasEffect() ||
|
|
|
|
p->tone->hasEffect() ||
|
|
|
|
p->opacity != 255 ||
|
|
|
|
flashing ||
|
|
|
|
p->bushDepth != 0;
|
|
|
|
|
|
|
|
if (renderEffect)
|
2013-09-01 14:27:21 +00:00
|
|
|
{
|
2013-12-11 04:22:13 +00:00
|
|
|
SpriteShader &shader = shState->shaders().sprite;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
shader.bind();
|
2013-09-23 05:15:01 +00:00
|
|
|
shader.applyViewportProj();
|
|
|
|
shader.setSpriteMat(p->trans.getMatrix());
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
shader.setTone(p->tone->norm);
|
|
|
|
shader.setOpacity(p->opacity.norm);
|
|
|
|
shader.setBushDepth(p->efBushDepth);
|
|
|
|
shader.setBushOpacity(p->bushOpacity.norm);
|
|
|
|
|
|
|
|
/* When both flashing and effective color are set,
|
|
|
|
* the one with higher alpha will be blended */
|
|
|
|
const Vec4 *blend = (flashing && flashColor.w > p->color->norm.w) ?
|
|
|
|
&flashColor : &p->color->norm;
|
|
|
|
|
|
|
|
shader.setColor(*blend);
|
2013-09-23 05:15:01 +00:00
|
|
|
|
|
|
|
base = &shader;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-11 04:22:13 +00:00
|
|
|
SimpleSpriteShader &shader = shState->shaders().simpleSprite;
|
2013-09-23 05:15:01 +00:00
|
|
|
shader.bind();
|
|
|
|
|
|
|
|
shader.setSpriteMat(p->trans.getMatrix());
|
|
|
|
shader.applyViewportProj();
|
|
|
|
base = &shader;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glState.blendMode.pushSet(p->blendType);
|
|
|
|
|
2013-09-23 05:15:01 +00:00
|
|
|
p->bitmap->bindTex(*base);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2014-02-03 14:32:50 +00:00
|
|
|
#ifdef RGSS2
|
|
|
|
if (p->wave.active)
|
|
|
|
p->wave.qArray.draw();
|
|
|
|
else
|
|
|
|
p->quad.draw();
|
|
|
|
#else
|
2013-09-01 14:27:21 +00:00
|
|
|
p->quad.draw();
|
2014-02-03 14:32:50 +00:00
|
|
|
#endif
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
glState.blendMode.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sprite::onGeometryChange(const Scene::Geometry &geo)
|
|
|
|
{
|
|
|
|
/* Offset at which the sprite will be drawn
|
|
|
|
* relative to screen origin */
|
|
|
|
int xOffset = geo.rect.x - geo.xOrigin;
|
|
|
|
int yOffset = geo.rect.y - geo.yOrigin;
|
|
|
|
|
|
|
|
p->trans.setGlobalOffset(xOffset, yOffset);
|
2013-12-06 02:24:53 +00:00
|
|
|
|
|
|
|
p->sceneRect.w = geo.rect.w;
|
|
|
|
p->sceneRect.h = geo.rect.h;
|
2013-09-01 14:27:21 +00:00
|
|
|
}
|