2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
|
|
|
|
This file is part of Aquaria.
|
|
|
|
|
|
|
|
Aquaria 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.
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2017-01-20 03:51:38 +00:00
|
|
|
#ifndef RENDER_OBJECT_H
|
|
|
|
#define RENDER_OBJECT_H
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
#include "Base.h"
|
2022-05-18 23:34:31 +00:00
|
|
|
#include "EngineEnums.h"
|
2011-08-03 20:05:33 +00:00
|
|
|
#include "Texture.h"
|
Script interface improvements & extensions.
- Pointer typechecks are now enabled by default.
- enabled all script warnings for non-FULL or DEMO builds by default
- Added generic obj_* functions that operate on any type of RenderObject.
These give quite low-level control about the renderer, and are quite
dangerous too.
Subsequently, many functions sharing the same code (*_setPosition, for example)
could be removed, and simply call the generic functions after a type check.
- Added interface function deathNotify(). The original logic of death
notifiers was never used, so i thought i'd make use of it.
This is useful in scripts to safely drop dangling pointers.
- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
which were essentially no-ops.
- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
now it does only push a return value on the stack if the function
is actually supposed to have a retun value.
- Allow variadic calling of entity_msg(). Now any parameters can be passed
to the function, and the target entity will receive all of them.
Any values returned from the entity's msg() callback will be returned
by entity_msg() to the original caller. This allows nice RPC-like
entity communication.
- fixed possible crash in debugLog, bone_update, entity_debugText
- added an override function for loadfile() that is case-insensitive like dofile()
- entity_createEntity returns the created entity now
- spawnParticleEffect returns the associated RenderObject
- Added some text rendering functions
- Added beam_setFirer()
- removed the underflow check in avatar_decrLeaches() I added earlier
- added a panic function for Lua.
- added the Lua debug library
- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate
- misc stuff I forgot
2012-02-05 19:22:54 +00:00
|
|
|
#include "ScriptObject.h"
|
2022-05-19 23:04:19 +00:00
|
|
|
#include "RenderState.h"
|
2016-07-09 02:18:40 +00:00
|
|
|
#include <list>
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
class Core;
|
|
|
|
class StateData;
|
2016-07-09 02:18:40 +00:00
|
|
|
class Texture;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
enum RenderObjectFlags
|
|
|
|
{
|
|
|
|
RO_CLEAR = 0x00,
|
|
|
|
RO_RENDERBORDERS = 0x01,
|
|
|
|
RO_NEXT = 0x02,
|
|
|
|
RO_MOTIONBLUR = 0x04
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AutoSize
|
|
|
|
{
|
|
|
|
AUTO_VIRTUALWIDTH = -101,
|
|
|
|
AUTO_VIRTUALHEIGHT = -102
|
|
|
|
};
|
|
|
|
|
|
|
|
enum ParentManaged
|
|
|
|
{
|
2022-05-20 01:27:15 +00:00
|
|
|
PM_NONE = 0, // child is destroyed with parent, but not deleted. The childs' update() is NOT called.
|
|
|
|
PM_POINTER = 1, // child is deleted together with parent. update() is called.
|
|
|
|
PM_STATIC = 2 // child is destroyed with parent, but not deleted. update() is called.
|
2011-08-03 20:05:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ChildOrder
|
|
|
|
{
|
|
|
|
CHILD_BACK = 0,
|
|
|
|
CHILD_FRONT = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RenderBeforeParent
|
|
|
|
{
|
|
|
|
RBP_NONE = -1,
|
|
|
|
RBP_OFF = 0,
|
|
|
|
RBP_ON = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MotionBlurFrame
|
|
|
|
{
|
|
|
|
Vector position;
|
|
|
|
float rotz;
|
|
|
|
};
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
struct MotionBlurData
|
|
|
|
{
|
|
|
|
MotionBlurData();
|
|
|
|
bool transition;
|
|
|
|
unsigned frameOffsetCounter, frameOffset;
|
|
|
|
float transitionTimer;
|
|
|
|
std::vector<MotionBlurFrame> positions;
|
|
|
|
};
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
class RenderObjectLayer;
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
// FIXME: -- fg
|
|
|
|
// I've scattered a few mutables across this class
|
|
|
|
// These should be part of some struct that gets passed along the render() calls
|
|
|
|
// instead of updating the actual class members
|
|
|
|
|
Script interface improvements & extensions.
- Pointer typechecks are now enabled by default.
- enabled all script warnings for non-FULL or DEMO builds by default
- Added generic obj_* functions that operate on any type of RenderObject.
These give quite low-level control about the renderer, and are quite
dangerous too.
Subsequently, many functions sharing the same code (*_setPosition, for example)
could be removed, and simply call the generic functions after a type check.
- Added interface function deathNotify(). The original logic of death
notifiers was never used, so i thought i'd make use of it.
This is useful in scripts to safely drop dangling pointers.
- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
which were essentially no-ops.
- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
now it does only push a return value on the stack if the function
is actually supposed to have a retun value.
- Allow variadic calling of entity_msg(). Now any parameters can be passed
to the function, and the target entity will receive all of them.
Any values returned from the entity's msg() callback will be returned
by entity_msg() to the original caller. This allows nice RPC-like
entity communication.
- fixed possible crash in debugLog, bone_update, entity_debugText
- added an override function for loadfile() that is case-insensitive like dofile()
- entity_createEntity returns the created entity now
- spawnParticleEffect returns the associated RenderObject
- Added some text rendering functions
- Added beam_setFirer()
- removed the underflow check in avatar_decrLeaches() I added earlier
- added a panic function for Lua.
- added the Lua debug library
- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate
- misc stuff I forgot
2012-02-05 19:22:54 +00:00
|
|
|
class RenderObject : public ScriptObject
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend class Core;
|
|
|
|
RenderObject();
|
|
|
|
virtual ~RenderObject();
|
2022-05-19 23:04:19 +00:00
|
|
|
virtual void render(const RenderState& rs) const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2015-03-23 23:06:51 +00:00
|
|
|
void setTexturePointer(CountedPtr<Texture> t)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
this->texture = t;
|
|
|
|
onSetTexture();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setStateDataObject(StateData *state);
|
2015-03-23 23:06:51 +00:00
|
|
|
bool setTexture(const std::string &name);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2017-01-20 03:51:38 +00:00
|
|
|
void toggleAlpha(float t = 0.2f);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
virtual void update(float dt);
|
|
|
|
bool isDead() const {return _dead;}
|
|
|
|
bool isHidden() const {return _hidden || (parent && parent->isHidden());}
|
|
|
|
|
2022-05-22 05:38:23 +00:00
|
|
|
bool shouldTryToRender() const; // somewhat expensive
|
|
|
|
bool isVisibleInPass(int pass) const;
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
// Set whether the object is hidden. If hidden, no updates (except
|
|
|
|
// lifetime checks) or render operations will be performed, and no
|
|
|
|
// child objects will be updated or rendered.
|
|
|
|
void setHidden(bool hidden) {_hidden = hidden;}
|
|
|
|
|
2017-01-20 03:51:38 +00:00
|
|
|
void setLife(float newlife)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2017-01-20 03:51:38 +00:00
|
|
|
maxLife = this->life = newlife;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2017-01-20 03:51:38 +00:00
|
|
|
void setDecayRate(float newdecayRate)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2017-01-20 03:51:38 +00:00
|
|
|
this->decayRate = newdecayRate;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-05-18 23:34:31 +00:00
|
|
|
void setBlendType (BlendType bt)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 23:34:31 +00:00
|
|
|
_blendType = bt;
|
|
|
|
}
|
|
|
|
inline BlendType getBlendType() const
|
|
|
|
{
|
|
|
|
return (BlendType)_blendType;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
virtual void destroy();
|
|
|
|
|
|
|
|
virtual void flipHorizontal();
|
|
|
|
virtual void flipVertical();
|
|
|
|
|
2015-07-12 20:16:55 +00:00
|
|
|
bool isfh() const { return _fh; }
|
|
|
|
bool isfv() const { return _fv; }
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
// recursive
|
2022-05-19 03:17:00 +00:00
|
|
|
bool isfhr() const;
|
|
|
|
bool isfvr() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t getIdx() const { return idx; }
|
2017-01-20 03:51:38 +00:00
|
|
|
void setIdx(size_t newidx) { this->idx = newidx; }
|
2011-08-03 20:05:33 +00:00
|
|
|
void moveToFront();
|
|
|
|
void moveToBack();
|
|
|
|
|
|
|
|
inline float getCullRadiusSqr() const
|
|
|
|
{
|
2017-01-20 03:51:38 +00:00
|
|
|
if (overrideCullRadiusSqr != 0)
|
2011-08-03 20:05:33 +00:00
|
|
|
return overrideCullRadiusSqr;
|
|
|
|
if (width == 0 || height == 0)
|
|
|
|
return 0;
|
|
|
|
const float w = width*scale.x;
|
|
|
|
const float h = height*scale.y;
|
|
|
|
return w*w + h*h;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
int getTopLayer() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
void enableMotionBlur(int sz=10, int off=5);
|
|
|
|
void disableMotionBlur();
|
|
|
|
|
|
|
|
void addChild(RenderObject *r, ParentManaged pm, RenderBeforeParent rbp = RBP_NONE, ChildOrder order = CHILD_BACK);
|
|
|
|
void removeChild(RenderObject *r);
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector getRealPosition() const;
|
|
|
|
Vector getRealScale() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
StateData *getStateData() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
// HACK: This is defined in RenderObject_inline.h because it needs
|
|
|
|
// the class Core definition. --achurch
|
2022-05-19 03:17:00 +00:00
|
|
|
inline bool isOnScreen() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool isCoordinateInRadius(const Vector &pos, float r) const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
void toggleCull(bool value);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
void safeKill();
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector getWorldPosition() const;
|
|
|
|
Vector getWorldCollidePosition(const Vector &vec=Vector(0,0,0)) const;
|
|
|
|
Vector getInvRotPosition(const Vector &vec) const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
RenderObject *getTopParent() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
virtual void onAnimationKeyPassed(int key){}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector getAbsoluteRotation() const;
|
|
|
|
float getWorldRotation() const;
|
|
|
|
Vector getWorldPositionAndRotation() const; // more efficient shortcut, returns rotation in vector z component
|
|
|
|
Vector getNormal() const;
|
|
|
|
Vector getForward() const;
|
2011-08-03 20:05:33 +00:00
|
|
|
void setOverrideCullRadius(float ovr);
|
|
|
|
void setRenderPass(int pass) { renderPass = pass; }
|
2022-05-19 03:17:00 +00:00
|
|
|
int getRenderPass() const { return renderPass; }
|
2022-06-09 00:32:19 +00:00
|
|
|
|
|
|
|
// TODO: remove this once the render loop is split into a per-pass object collection phase
|
|
|
|
// and an actual rendering phase
|
2022-05-25 19:19:14 +00:00
|
|
|
enum { RENDER_ALL=999 };
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
// Defined in RenderObject_inline.h
|
|
|
|
inline Vector getFollowCameraPosition() const;
|
|
|
|
|
|
|
|
void lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset=0);
|
2012-01-02 20:34:29 +00:00
|
|
|
inline RenderObject *getParent() const {return parent;}
|
2011-08-03 20:05:33 +00:00
|
|
|
void fhTo(bool fh);
|
|
|
|
void addDeathNotify(RenderObject *r);
|
|
|
|
virtual void unloadDevice();
|
|
|
|
virtual void reloadDevice();
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
MotionBlurData *ensureMotionBlur();
|
|
|
|
void freeMotionBlur();
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
//-------------------------------- Methods above, fields below
|
|
|
|
|
|
|
|
static bool renderCollisionShape;
|
|
|
|
static bool renderPaths;
|
2017-01-14 17:10:20 +00:00
|
|
|
static size_t lastTextureApplied;
|
2011-08-03 20:05:33 +00:00
|
|
|
static bool lastTextureRepeat;
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
//--------------------------
|
|
|
|
|
|
|
|
// fields ordered by hotness
|
|
|
|
|
|
|
|
// TODO: this should be a bitmask
|
|
|
|
bool fadeAlphaWithLife;
|
|
|
|
bool renderBeforeParent;
|
|
|
|
bool shareAlphaWithChildren;
|
|
|
|
bool shareColorWithChildren;
|
|
|
|
bool cull;
|
|
|
|
bool ignoreUpdate;
|
|
|
|
bool useOldDT;
|
|
|
|
bool repeatTexture;
|
|
|
|
bool _dead;
|
|
|
|
bool _hidden;
|
|
|
|
bool _fv, _fh;
|
2022-05-18 22:01:27 +00:00
|
|
|
bool _markedForDelete;
|
2022-05-18 17:44:42 +00:00
|
|
|
|
|
|
|
unsigned char pm; // unsigned char to save space
|
|
|
|
|
2022-05-18 23:34:31 +00:00
|
|
|
char _blendType;
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
|
2023-03-02 01:12:32 +00:00
|
|
|
InterpolatedVector position;
|
2023-03-02 01:19:48 +00:00
|
|
|
InterpolatedVector scale;
|
2022-05-21 14:31:10 +00:00
|
|
|
InterpolatedVector color, alpha;
|
2023-03-02 01:31:16 +00:00
|
|
|
InterpolatedVector rotation;
|
2011-08-03 20:05:33 +00:00
|
|
|
InterpolatedVector offset, rotationOffset, internalOffset, beforeScaleOffset;
|
|
|
|
InterpolatedVector velocity, gravity;
|
|
|
|
|
2015-03-23 23:06:51 +00:00
|
|
|
CountedPtr<Texture> texture;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
float life;
|
2022-05-19 03:17:00 +00:00
|
|
|
mutable float followCamera;
|
2022-05-18 17:44:42 +00:00
|
|
|
float alphaMod;
|
|
|
|
float updateCull;
|
|
|
|
int layer;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
float decayRate;
|
|
|
|
float maxLife;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-22 05:38:23 +00:00
|
|
|
// In layers that have multi-pass rendering enabled, the object will only be rendered
|
|
|
|
// in this pass (single-pass layers always render, regardless of this setting).
|
2022-05-18 17:44:42 +00:00
|
|
|
int renderPass;
|
2022-05-22 05:38:23 +00:00
|
|
|
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
float overrideCullRadiusSqr;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
float width, height; // Only used by Quads, but stored here for getCullRadius()
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
// ----------------------
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2014-07-21 20:21:22 +00:00
|
|
|
typedef std::vector<RenderObject*> Children;
|
2022-05-18 22:01:27 +00:00
|
|
|
Children children;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
protected:
|
2022-05-18 17:44:42 +00:00
|
|
|
RenderObject *parent;
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
virtual void onFH(){}
|
|
|
|
virtual void onFV(){}
|
|
|
|
virtual void onSetTexture(){}
|
2022-05-19 23:04:19 +00:00
|
|
|
virtual void onRender(const RenderState& rs) const {}
|
2011-08-03 20:05:33 +00:00
|
|
|
virtual void onUpdate(float dt);
|
|
|
|
virtual void deathNotify(RenderObject *r);
|
|
|
|
virtual void onEndOfLife() {}
|
|
|
|
|
2022-07-18 21:00:22 +00:00
|
|
|
bool updateLife(float dt);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
// Is this object or any of its children rendered in pass "pass"?
|
2022-05-19 03:17:00 +00:00
|
|
|
bool hasRenderPass(const int pass) const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2023-03-02 01:31:16 +00:00
|
|
|
inline void renderCall(const RenderState& rs, const Vector& renderAt, float renderRotation) const;
|
2022-05-19 23:04:19 +00:00
|
|
|
virtual void renderCollision(const RenderState& rs) const;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
typedef std::list<RenderObject*> RenderObjectList;
|
|
|
|
RenderObjectList deathNotifications;
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
size_t idx; // index in layer
|
2011-08-03 20:05:33 +00:00
|
|
|
StateData *stateData;
|
2022-05-18 17:44:42 +00:00
|
|
|
MotionBlurData *motionBlur;
|
2022-05-19 03:17:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const RenderObject &operator=(const RenderObject &r); // undefined
|
2011-08-03 20:05:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|