2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** scene.h
|
|
|
|
**
|
|
|
|
** 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SCENE_H
|
|
|
|
#define SCENE_H
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
#include "intrulist.h"
|
|
|
|
#include "etc.h"
|
|
|
|
#include "etc-internal.h"
|
|
|
|
|
|
|
|
class SceneElement;
|
|
|
|
class Viewport;
|
2014-08-12 19:50:59 +00:00
|
|
|
class WindowVX;
|
2013-09-01 14:27:21 +00:00
|
|
|
class Window;
|
2013-12-31 21:31:24 +00:00
|
|
|
struct ScanRow;
|
2013-10-13 20:00:38 +00:00
|
|
|
struct TilemapPrivate;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
class Scene
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Geometry
|
|
|
|
{
|
2015-02-10 15:42:32 +00:00
|
|
|
/* Position and size relative to parent */
|
2013-09-01 14:27:21 +00:00
|
|
|
IntRect rect;
|
2015-02-10 15:42:32 +00:00
|
|
|
|
|
|
|
/* Origin of contents */
|
|
|
|
Vec2i orig;
|
|
|
|
|
|
|
|
Vec2i offset() const
|
|
|
|
{
|
|
|
|
return rect.pos() - orig;
|
|
|
|
}
|
2013-09-01 14:27:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Scene();
|
2013-09-30 17:30:05 +00:00
|
|
|
virtual ~Scene();
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
virtual void composite();
|
2015-07-07 13:56:21 +00:00
|
|
|
virtual void requestViewportRender(const Vec4& /* color */,
|
|
|
|
const Vec4& /* flash */,
|
|
|
|
const Vec4& /* tone */) {}
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
const Geometry &getGeometry() const { return geometry; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void insert(SceneElement &element);
|
2013-10-13 10:58:56 +00:00
|
|
|
void insertAfter(SceneElement &element, SceneElement &after);
|
2013-09-01 14:27:21 +00:00
|
|
|
void reinsert(SceneElement &element);
|
|
|
|
|
|
|
|
/* Notify all elements that geometry has changed */
|
|
|
|
void notifyGeometryChange();
|
|
|
|
|
|
|
|
IntruList<SceneElement> elements;
|
|
|
|
Geometry geometry;
|
|
|
|
|
|
|
|
friend class SceneElement;
|
|
|
|
friend class Window;
|
2014-08-12 19:50:59 +00:00
|
|
|
friend class WindowVX;
|
2014-08-17 01:58:01 +00:00
|
|
|
friend struct ZLayer;
|
2013-09-01 14:27:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SceneElement
|
|
|
|
{
|
|
|
|
public:
|
2014-08-30 22:51:23 +00:00
|
|
|
SceneElement(Scene &scene, int z = 0, int spriteY = 0);
|
2013-09-01 14:27:21 +00:00
|
|
|
virtual ~SceneElement();
|
|
|
|
|
|
|
|
void setScene(Scene &scene);
|
|
|
|
|
|
|
|
DECL_ATTR_VIRT( Z, int )
|
|
|
|
DECL_ATTR_VIRT( Visible, bool )
|
|
|
|
|
2014-09-23 19:12:58 +00:00
|
|
|
virtual void aboutToAccess() const = 0;
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
protected:
|
2013-10-17 13:27:48 +00:00
|
|
|
/* A bit about OpenGL state:
|
|
|
|
*
|
|
|
|
* If we're not inside the draw cycle (ie. the 'draw()'
|
|
|
|
* handle), you're free to change any GL state through
|
|
|
|
* gl-util, except for those in GLState which you should
|
|
|
|
* push/pop as needed.
|
|
|
|
*
|
|
|
|
* If we're _drawing_, you should probably not touch most
|
|
|
|
* things in GLState. For scissored rendering, use push with
|
|
|
|
* setIntersect(), and then pop afterwards.
|
|
|
|
* Blendmode you can push/pop as you like. Do NOT touch viewport.
|
|
|
|
* Texture/Shader bindings you're free to modify without
|
|
|
|
* cleanup (and therefore you should expect dirty state).
|
|
|
|
* Do NOT touch the FBO::Draw binding. If you have to do work
|
|
|
|
* immediately before drawing that touches this (such as flushing
|
|
|
|
* Bitmaps), use the 'prepareDraw' signal in SharedState that
|
|
|
|
* will fire immediately before each frame draw.
|
|
|
|
*/
|
2013-09-01 14:27:21 +00:00
|
|
|
virtual void draw() = 0;
|
2013-10-17 13:27:48 +00:00
|
|
|
|
|
|
|
// FIXME: This should be a signal
|
2013-09-01 14:27:21 +00:00
|
|
|
virtual void onGeometryChange(const Scene::Geometry &) {}
|
|
|
|
|
2014-05-07 15:52:11 +00:00
|
|
|
/* Compares two elements in terms of their display priority;
|
2013-09-06 11:10:41 +00:00
|
|
|
* elements with lower priority are drawn earlier */
|
|
|
|
bool operator<(const SceneElement &o) const;
|
|
|
|
|
2014-08-16 11:50:57 +00:00
|
|
|
void setSpriteY(int value);
|
2013-09-01 14:27:21 +00:00
|
|
|
void unlink();
|
|
|
|
|
|
|
|
IntruListLink<SceneElement> link;
|
|
|
|
const unsigned int creationStamp;
|
|
|
|
int z;
|
|
|
|
bool visible;
|
|
|
|
Scene *scene;
|
|
|
|
|
|
|
|
friend class Scene;
|
|
|
|
friend class Viewport;
|
2013-10-13 20:00:38 +00:00
|
|
|
friend struct TilemapPrivate;
|
2014-08-16 11:50:57 +00:00
|
|
|
|
|
|
|
private:
|
2014-08-30 22:51:23 +00:00
|
|
|
|
|
|
|
/* RGSS2 introduced an enhanced type of Z ordering: sprites with
|
|
|
|
* the same Z are first ordered by their Y value (higher Y = closer
|
|
|
|
* to player) and then by creation time. However, the Enterbrain devs
|
|
|
|
* botched their implementation, and now every other scene element
|
|
|
|
* subclass is sorted as if it was a sprite with a fixed Y of 0.
|
|
|
|
* In RGSS3, they tried to fix this for the Window class, badly. It
|
|
|
|
* now behaves as if it was a sprite with fixed Y of infinity. This
|
|
|
|
* means that sprites created _after_ a window with the same Z will
|
|
|
|
* still always be displayed below said window. */
|
2014-08-16 11:50:57 +00:00
|
|
|
int spriteY;
|
2013-09-01 14:27:21 +00:00
|
|
|
};
|
|
|
|
|
2014-09-23 19:12:58 +00:00
|
|
|
#define ABOUT_TO_ACCESS_NOOP \
|
|
|
|
void aboutToAccess() const {}
|
|
|
|
|
|
|
|
#define ABOUT_TO_ACCESS_DISP \
|
|
|
|
void aboutToAccess() const { guardDisposed(); }
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
#endif // SCENE_H
|