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.
|
|
|
|
*/
|
|
|
|
#include "RenderObject.h"
|
|
|
|
#include "Core.h"
|
|
|
|
#include "MathFunctions.h"
|
2016-07-09 02:18:40 +00:00
|
|
|
#include "RenderBase.h"
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
2014-09-15 18:59:21 +00:00
|
|
|
#include <algorithm>
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2015-07-12 20:16:55 +00:00
|
|
|
#ifdef BBGE_USE_GLM
|
|
|
|
#include "glm/glm.hpp"
|
|
|
|
#include "glm/gtx/transform.hpp"
|
|
|
|
#endif
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
bool RenderObject::renderCollisionShape = false;
|
2017-01-14 17:10:20 +00:00
|
|
|
size_t RenderObject::lastTextureApplied = 0;
|
2011-08-03 20:05:33 +00:00
|
|
|
bool RenderObject::renderPaths = false;
|
|
|
|
|
|
|
|
void RenderObject::toggleAlpha(float t)
|
|
|
|
{
|
|
|
|
if (alpha.x < 0.5f)
|
|
|
|
alpha.interpolateTo(1,t);
|
|
|
|
else
|
|
|
|
alpha.interpolateTo(0,t);
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
int RenderObject::getTopLayer() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
return parent->getTopLayer();
|
|
|
|
}
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderObject::RenderObject()
|
|
|
|
{
|
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
|
|
|
addType(SCO_RENDEROBJECT);
|
2011-08-03 20:05:33 +00:00
|
|
|
useOldDT = false;
|
|
|
|
|
|
|
|
ignoreUpdate = false;
|
|
|
|
renderPass = 0;
|
|
|
|
overrideCullRadiusSqr = 0;
|
|
|
|
repeatTexture = false;
|
|
|
|
alphaMod = 1;
|
2022-05-18 17:44:42 +00:00
|
|
|
motionBlur = 0;
|
2011-08-03 20:05:33 +00:00
|
|
|
idx = -1;
|
|
|
|
_fv = false;
|
|
|
|
_fh = false;
|
2022-05-18 22:01:27 +00:00
|
|
|
_markedForDelete = false;
|
2011-08-03 20:05:33 +00:00
|
|
|
updateCull = -1;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
layer = LR_NONE;
|
|
|
|
cull = true;
|
|
|
|
|
|
|
|
pm = PM_NONE;
|
|
|
|
|
|
|
|
texture = 0;
|
|
|
|
width = 0;
|
|
|
|
height = 0;
|
|
|
|
scale = Vector(1,1,1);
|
|
|
|
color = Vector(1,1,1);
|
|
|
|
alpha.x = 1;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
life = maxLife = 1;
|
|
|
|
decayRate = 0;
|
|
|
|
_dead = false;
|
|
|
|
_hidden = false;
|
|
|
|
fadeAlphaWithLife = false;
|
2022-05-18 23:34:31 +00:00
|
|
|
_blendType = BLEND_DEFAULT;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
followCamera = 0;
|
|
|
|
stateData = 0;
|
|
|
|
parent = 0;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
renderBeforeParent = false;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
shareAlphaWithChildren = false;
|
|
|
|
shareColorWithChildren = false;
|
2023-07-13 22:19:33 +00:00
|
|
|
neverFollowCamera = false;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RenderObject::~RenderObject()
|
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
freeMotionBlur();
|
2022-05-20 01:27:15 +00:00
|
|
|
assert(children.empty()); // if this fires some objects were not deleted and will leak
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getWorldPosition() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
return getWorldCollidePosition();
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
RenderObject* RenderObject::getTopParent() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
RenderObject *p = parent;
|
|
|
|
RenderObject *lastp=0;
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
lastp = p;
|
|
|
|
p = p->parent;
|
|
|
|
}
|
|
|
|
return lastp;
|
|
|
|
}
|
|
|
|
|
2015-07-12 20:16:55 +00:00
|
|
|
#ifdef BBGE_USE_GLM
|
|
|
|
static glm::mat4 matrixChain(const RenderObject *ro)
|
2012-01-02 20:34:29 +00:00
|
|
|
{
|
2015-07-12 20:16:55 +00:00
|
|
|
glm::mat4 tranformMatrix = glm::scale(
|
2023-08-25 22:58:47 +00:00
|
|
|
glm::rotate(
|
|
|
|
glm::translate(
|
|
|
|
ro->getParent() ? matrixChain(ro->getParent()) : glm::mat4(1.0f),
|
|
|
|
glm::vec3(ro->position.x+ro->offset.x, ro->position.y+ro->offset.y, 0)
|
2015-07-12 20:16:55 +00:00
|
|
|
),
|
2023-08-25 22:58:47 +00:00
|
|
|
ro->rotation.z + ro->rotationOffset.z,
|
|
|
|
glm::vec3(0.0f, 0.0f, 1.0f)
|
2015-07-12 20:16:55 +00:00
|
|
|
),
|
|
|
|
glm::vec3(ro->scale.x, ro->scale.y, 0.0f)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (ro->isfh())
|
2015-09-17 21:40:10 +00:00
|
|
|
tranformMatrix *= glm::rotate(180.0f, glm::vec3(0.0f, 1.0f, 0.0f));
|
2015-07-12 20:16:55 +00:00
|
|
|
|
2015-09-17 21:40:10 +00:00
|
|
|
tranformMatrix *= glm::translate(glm::vec3(ro->internalOffset.x, ro->internalOffset.y, 0.0f));
|
2015-07-12 20:16:55 +00:00
|
|
|
return tranformMatrix;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void matrixChain(RenderObject *ro)
|
|
|
|
{
|
|
|
|
if (RenderObject *parent = ro->getParent())
|
|
|
|
matrixChain(parent);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2015-07-12 20:16:55 +00:00
|
|
|
glTranslatef(ro->position.x+ro->offset.x, ro->position.y+ro->offset.y, 0);
|
|
|
|
glRotatef(ro->rotation.z+ro->rotationOffset.z, 0, 0, 1);
|
|
|
|
glScalef(ro->scale.x, ro->scale.y, 0);
|
|
|
|
if (ro->isfh())
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
glRotatef(180, 0, 1, 0);
|
|
|
|
}
|
2015-07-12 20:16:55 +00:00
|
|
|
glTranslatef(ro->internalOffset.x, ro->internalOffset.y, 0);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2015-07-12 20:16:55 +00:00
|
|
|
#endif
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
float RenderObject::getWorldRotation() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
Vector up = getWorldCollidePosition(Vector(0,1));
|
|
|
|
Vector orig = getWorldPosition();
|
|
|
|
float rot = 0;
|
|
|
|
MathFunctions::calculateAngleBetweenVectorsInDegrees(orig, up, rot);
|
|
|
|
return rot;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getWorldPositionAndRotation() const
|
2013-07-20 15:44:27 +00:00
|
|
|
{
|
|
|
|
Vector up = getWorldCollidePosition(Vector(0,1));
|
|
|
|
Vector orig = getWorldPosition();
|
|
|
|
MathFunctions::calculateAngleBetweenVectorsInDegrees(orig, up, orig.z);
|
|
|
|
return orig;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getWorldCollidePosition(const Vector &vec) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2015-07-12 20:16:55 +00:00
|
|
|
#ifdef BBGE_USE_GLM
|
|
|
|
glm::mat4 transformMatrix = glm::translate(
|
|
|
|
matrixChain(this),
|
2016-05-06 22:47:45 +00:00
|
|
|
glm::vec3(vec.x, vec.y, 0.0f)
|
2015-07-12 20:16:55 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return Vector(transformMatrix[3][0], transformMatrix[3][1], 0);
|
|
|
|
#else
|
2011-08-03 20:05:33 +00:00
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
|
2015-07-12 20:16:55 +00:00
|
|
|
matrixChain(this);
|
2016-05-06 22:47:45 +00:00
|
|
|
glTranslatef(vec.x, vec.y, 0);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
float m[16];
|
|
|
|
glGetFloatv(GL_MODELVIEW_MATRIX, m);
|
|
|
|
float x = m[12];
|
|
|
|
float y = m[13];
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
return Vector(x,y,0);
|
2015-07-12 20:16:55 +00:00
|
|
|
#endif
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::fhTo(bool fh)
|
|
|
|
{
|
|
|
|
if ((fh && !_fh) || (!fh && _fh))
|
|
|
|
{
|
|
|
|
flipHorizontal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::flipHorizontal()
|
|
|
|
{
|
|
|
|
bool wasFlippedHorizontal = _fh;
|
|
|
|
|
|
|
|
_fh = !_fh;
|
|
|
|
|
|
|
|
if (wasFlippedHorizontal != _fh)
|
|
|
|
{
|
|
|
|
onFH();
|
|
|
|
}
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::flipVertical()
|
|
|
|
{
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
_fv = !_fv;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::destroy()
|
|
|
|
{
|
|
|
|
for (Children::iterator i = children.begin(); i != children.end(); i++)
|
|
|
|
{
|
|
|
|
// must do this first
|
|
|
|
// otherwise child will try to remove THIS
|
|
|
|
(*i)->parent = 0;
|
2022-05-20 01:27:15 +00:00
|
|
|
(*i)->destroy();
|
|
|
|
if((*i)->pm == PM_POINTER)
|
2011-08-03 20:05:33 +00:00
|
|
|
delete (*i);
|
|
|
|
}
|
|
|
|
children.clear();
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
parent->removeChild(this);
|
|
|
|
parent = 0;
|
|
|
|
}
|
2015-03-23 23:06:51 +00:00
|
|
|
|
|
|
|
texture = NULL;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getRealPosition() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
return position + offset + parent->getRealPosition();
|
|
|
|
}
|
|
|
|
return position + offset;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getRealScale() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
return scale * parent->getRealScale();
|
|
|
|
}
|
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::setStateDataObject(StateData *state)
|
|
|
|
{
|
|
|
|
stateData = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RenderObject::toggleCull(bool value)
|
|
|
|
{
|
|
|
|
cull = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::moveToFront()
|
|
|
|
{
|
2015-01-14 20:42:54 +00:00
|
|
|
if(RenderObject *p = parent)
|
|
|
|
{
|
2015-11-28 22:42:39 +00:00
|
|
|
if(p->children.size() && p->children[p->children.size()-1] != this)
|
2015-01-14 20:42:54 +00:00
|
|
|
{
|
|
|
|
p->removeChild(this);
|
2015-11-28 22:42:39 +00:00
|
|
|
p->addChild(this, (ParentManaged)this->pm, RBP_NONE, CHILD_BACK); // To back of list -> rendered on top
|
2015-01-14 20:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (layer != -1)
|
2011-08-03 20:05:33 +00:00
|
|
|
core->renderObjectLayers[this->layer].moveToFront(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::moveToBack()
|
|
|
|
{
|
2015-01-14 20:42:54 +00:00
|
|
|
if(RenderObject *p = parent)
|
|
|
|
{
|
2015-11-28 22:42:39 +00:00
|
|
|
if(p->children.size() && p->children[0] != this)
|
2015-01-14 20:42:54 +00:00
|
|
|
{
|
|
|
|
p->removeChild(this);
|
2015-11-28 22:42:39 +00:00
|
|
|
p->addChild(this, (ParentManaged)this->pm, RBP_NONE, CHILD_FRONT); // To front of list -> rendered first, below everything else
|
2015-01-14 20:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (layer != -1)
|
2011-08-03 20:05:33 +00:00
|
|
|
core->renderObjectLayers[this->layer].moveToBack(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::enableMotionBlur(int sz, int off)
|
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
MotionBlurData *mb = ensureMotionBlur();
|
|
|
|
mb->transition = false;
|
|
|
|
mb->positions.resize(sz);
|
|
|
|
mb->frameOffsetCounter = 0;
|
|
|
|
mb->frameOffset = off;
|
|
|
|
for (size_t i = 0; i < mb->positions.size(); i++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
mb->positions[i].position = position;
|
|
|
|
mb->positions[i].rotz = rotation.z;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::disableMotionBlur()
|
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
if(MotionBlurData *mb = this->motionBlur)
|
|
|
|
{
|
|
|
|
mb->transition = true;
|
|
|
|
mb->transitionTimer = 1.0;
|
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool RenderObject::isfhr() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-19 03:17:00 +00:00
|
|
|
const RenderObject *p = this;
|
2012-01-31 18:25:13 +00:00
|
|
|
bool fh = false;
|
|
|
|
do
|
|
|
|
if (p->isfh())
|
|
|
|
fh = !fh;
|
|
|
|
while ((p = p->parent));
|
|
|
|
return fh;
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool RenderObject::isfvr() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-19 03:17:00 +00:00
|
|
|
const RenderObject *p = this;
|
2012-01-31 18:25:13 +00:00
|
|
|
bool fv = false;
|
|
|
|
do
|
|
|
|
if (p->isfv())
|
|
|
|
fv = !fv;
|
|
|
|
while ((p = p->parent));
|
|
|
|
return fv;
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool RenderObject::hasRenderPass(const int pass) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (pass == renderPass)
|
|
|
|
return true;
|
2022-05-19 03:17:00 +00:00
|
|
|
for (Children::const_iterator i = children.begin(); i != children.end(); i++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (!(*i)->isDead() && (*i)->hasRenderPass(pass))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-22 05:38:23 +00:00
|
|
|
bool RenderObject::shouldTryToRender() const
|
|
|
|
{
|
2023-06-01 18:19:37 +00:00
|
|
|
return !parent && !_hidden
|
2022-05-22 05:38:23 +00:00
|
|
|
&& alpha.x > 0
|
|
|
|
&& (!cull || isOnScreen());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RenderObject::isVisibleInPass(int pass) const
|
|
|
|
{
|
|
|
|
assert(!parent); // This check should be done for root objects only
|
|
|
|
assert(pass != RENDER_ALL); // why call this when we already know we don't do passes
|
|
|
|
|
2022-05-24 22:40:47 +00:00
|
|
|
return hasRenderPass(pass);
|
2022-05-22 05:38:23 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 23:04:19 +00:00
|
|
|
void RenderObject::render(const RenderState& rs) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2023-05-25 14:58:08 +00:00
|
|
|
assert(parent || layer != LR_NONE);
|
2023-06-01 18:19:37 +00:00
|
|
|
|
|
|
|
if(_hidden)
|
|
|
|
return;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
/// new (breaks anything?)
|
|
|
|
if (alpha.x == 0 || alphaMod == 0) return;
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
if (MotionBlurData *mb = this->motionBlur)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-21 14:31:10 +00:00
|
|
|
RenderState rx(rs);
|
2022-05-18 17:44:42 +00:00
|
|
|
const size_t sz = mb->positions.size();
|
|
|
|
const float m = 1.0f / float(sz);
|
2022-05-21 14:31:10 +00:00
|
|
|
const float m2 = alpha.x * 0.5f * (mb->transition ? mb->transitionTimer : 1.0f);
|
2022-05-18 17:44:42 +00:00
|
|
|
for (size_t i = 0; i < sz; i++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2023-03-02 01:12:32 +00:00
|
|
|
const Vector& renderAt = mb->positions[i].position;
|
2023-03-02 01:31:16 +00:00
|
|
|
const float renderRotation = mb->positions[i].rotz;
|
2022-05-21 14:31:10 +00:00
|
|
|
rx.alpha = (1.0f-(float(i) * m)) * m2;
|
2023-03-02 01:31:16 +00:00
|
|
|
renderCall(rx, renderAt, renderRotation);
|
2016-05-05 17:40:28 +00:00
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-05-18 17:44:42 +00:00
|
|
|
|
2023-03-02 01:31:16 +00:00
|
|
|
renderCall(rs, position, rotation.z);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-02 01:31:16 +00:00
|
|
|
void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt, float renderRotation) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2023-03-02 01:12:32 +00:00
|
|
|
const Vector renderPos = renderAt + offset;
|
2023-03-02 01:31:16 +00:00
|
|
|
renderRotation += rotationOffset.z;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-18 02:04:44 +00:00
|
|
|
glPushMatrix();
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2023-03-02 04:07:05 +00:00
|
|
|
if(!parent)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2023-03-02 04:07:05 +00:00
|
|
|
// Is root object. followCamera has an influence.
|
|
|
|
float followCamera = this->followCamera;
|
|
|
|
if (!followCamera)
|
|
|
|
{
|
|
|
|
// Not set for object. Use global layer value
|
|
|
|
const RenderObjectLayer& rl = core->renderObjectLayers[layer];
|
|
|
|
followCamera = rl.followCamera;
|
|
|
|
if(followCamera == 0) // normal object on normal layer
|
|
|
|
goto nofollow;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (followCamera == 1) // UI overlay or similar; is independent of camera aka stays in the same spot on the screen
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 02:04:44 +00:00
|
|
|
glLoadIdentity();
|
|
|
|
glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0);
|
2023-03-02 01:12:32 +00:00
|
|
|
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2023-03-02 04:07:05 +00:00
|
|
|
else // parallax scrolling
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 02:04:44 +00:00
|
|
|
Vector pos = getFollowCameraPosition();
|
|
|
|
glTranslatef(pos.x, pos.y, pos.z);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-05-18 02:04:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-02 04:07:05 +00:00
|
|
|
nofollow:
|
|
|
|
// The vast majority of objects ends up here. We're a child, or followCamera == 0 and not on a parallax layer.
|
|
|
|
|
2023-03-02 01:12:32 +00:00
|
|
|
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
|
2022-05-18 02:04:44 +00:00
|
|
|
|
2023-03-02 02:41:00 +00:00
|
|
|
if (RenderObject::renderPaths) // TODO: move this to debug render
|
|
|
|
debugRenderPaths();
|
2022-05-18 02:04:44 +00:00
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2023-07-03 16:53:55 +00:00
|
|
|
// Apply rotation and flip
|
|
|
|
glRotatef(renderRotation, 0, 0, 1);
|
|
|
|
if (isfh())
|
|
|
|
glRotatef(180, 0, 1, 0);
|
|
|
|
|
2023-03-02 01:19:48 +00:00
|
|
|
const Vector renderScale = scale * rs.scale;
|
|
|
|
glScalef(renderScale.x, renderScale.y, 1);
|
2022-05-18 02:04:44 +00:00
|
|
|
glTranslatef(internalOffset.x, internalOffset.y, internalOffset.z);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
for (Children::const_iterator i = children.begin(); i != children.end(); i++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (!(*i)->isDead() && (*i)->renderBeforeParent)
|
2022-05-19 23:04:19 +00:00
|
|
|
(*i)->render(rs);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-06-10 01:51:26 +00:00
|
|
|
|
|
|
|
if (rs.pass == RENDER_ALL || renderPass == RENDER_ALL || rs.pass == renderPass)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-24 23:05:52 +00:00
|
|
|
if (texture)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2023-08-24 22:38:36 +00:00
|
|
|
if (texture->gltexid != lastTextureApplied)
|
2022-05-24 23:05:52 +00:00
|
|
|
{
|
2023-08-24 22:38:36 +00:00
|
|
|
texture->apply();
|
2023-05-30 22:55:16 +00:00
|
|
|
lastTextureApplied = texture->gltexid;
|
2022-05-24 23:05:52 +00:00
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-05-24 23:05:52 +00:00
|
|
|
else
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2023-08-24 22:38:36 +00:00
|
|
|
if (lastTextureApplied != 0)
|
2022-05-24 23:05:52 +00:00
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
lastTextureApplied = 0;
|
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-06-05 23:41:50 +00:00
|
|
|
rs.gpu.setBlend(getBlendType());
|
|
|
|
|
2022-05-21 14:31:10 +00:00
|
|
|
// RenderState color applies to everything in the scene graph,
|
|
|
|
// so that needs to be multiplied in unconditionally
|
|
|
|
{
|
|
|
|
Vector col = this->color * rs.color;
|
2022-06-05 23:41:50 +00:00
|
|
|
glColor4f(col.x, col.y, col.z, rs.alpha*alpha.x*alphaMod);
|
2022-05-21 14:31:10 +00:00
|
|
|
}
|
2022-06-05 23:41:50 +00:00
|
|
|
|
2022-05-19 23:04:19 +00:00
|
|
|
onRender(rs);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-21 14:31:10 +00:00
|
|
|
if (renderCollisionShape)
|
|
|
|
renderCollision(rs);
|
|
|
|
}
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
for (Children::const_iterator i = children.begin(); i != children.end(); i++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (!(*i)->isDead() && !(*i)->renderBeforeParent)
|
2022-05-19 23:04:19 +00:00
|
|
|
(*i)->render(rs);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-05-18 02:04:44 +00:00
|
|
|
glPopMatrix();
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 23:04:19 +00:00
|
|
|
void RenderObject::renderCollision(const RenderState& rs) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-03-02 02:41:00 +00:00
|
|
|
void RenderObject::debugRenderPaths() const
|
|
|
|
{
|
|
|
|
if(!position.data)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const size_t N = position.data->path.getNumPathNodes();
|
|
|
|
if(!N)
|
|
|
|
return;
|
|
|
|
|
|
|
|
glLineWidth(4);
|
|
|
|
|
|
|
|
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
for (size_t i = 0; i < N-1; i++)
|
|
|
|
{
|
|
|
|
const VectorPathNode a = position.data->path[i];
|
|
|
|
const VectorPathNode b = position.data->path[i+1];
|
|
|
|
glVertex2f(a.value.x-position.x, a.value.y-position.y);
|
|
|
|
glVertex2f(b.value.x-position.x, b.value.y-position.y);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glPointSize(20);
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
glColor4f(0.5,0.5,1,1);
|
|
|
|
for (size_t i = 0; i < N; i++)
|
|
|
|
{
|
|
|
|
const VectorPathNode& a = position.data->path[i];
|
|
|
|
glVertex2f(a.value.x-position.x, a.value.y-position.y);
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
void RenderObject::addDeathNotify(RenderObject *r)
|
|
|
|
{
|
|
|
|
deathNotifications.remove(r);
|
|
|
|
deathNotifications.push_back(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::deathNotify(RenderObject *r)
|
|
|
|
{
|
|
|
|
deathNotifications.remove(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset)
|
|
|
|
{
|
|
|
|
Vector myPos = this->getWorldPosition();
|
|
|
|
float angle = 0;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
if (myPos.x == pos.x && myPos.y == pos.y)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2016-05-05 17:40:28 +00:00
|
|
|
MathFunctions::calculateAngleBetweenVectorsInDegrees(myPos, pos, angle);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
RenderObject *p = parent;
|
|
|
|
while (p)
|
|
|
|
{
|
|
|
|
angle -= p->rotation.z;
|
|
|
|
p = p->parent;
|
|
|
|
}
|
|
|
|
|
2022-06-20 15:46:37 +00:00
|
|
|
const bool ishfh = this->isfhr();
|
|
|
|
|
|
|
|
if (ishfh)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
angle = 180-angle;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
offset = -offset;
|
|
|
|
}
|
|
|
|
angle += offset;
|
|
|
|
if (angle < minAngle)
|
|
|
|
angle = minAngle;
|
|
|
|
if (angle > maxAngle)
|
|
|
|
angle = maxAngle;
|
|
|
|
|
|
|
|
int amt = 10;
|
2022-06-20 15:46:37 +00:00
|
|
|
if (ishfh)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (pos.x < myPos.x-amt)
|
|
|
|
{
|
|
|
|
angle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pos.x > myPos.x+amt)
|
|
|
|
{
|
|
|
|
angle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rotation.interpolateTo(Vector(0,0,angle), t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::update(float dt)
|
|
|
|
{
|
|
|
|
if (ignoreUpdate)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (useOldDT)
|
|
|
|
{
|
|
|
|
dt = core->get_old_dt();
|
|
|
|
}
|
|
|
|
if (!isDead())
|
|
|
|
{
|
|
|
|
onUpdate(dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::removeChild(RenderObject *r)
|
|
|
|
{
|
|
|
|
r->parent = 0;
|
2014-07-21 20:21:22 +00:00
|
|
|
Children::iterator oldend = children.end();
|
|
|
|
Children::iterator newend = std::remove(children.begin(), oldend, r);
|
|
|
|
if(oldend != newend)
|
|
|
|
{
|
|
|
|
children.resize(std::distance(children.begin(), newend));
|
|
|
|
return;
|
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
for (Children::iterator i = children.begin(); i != children.end(); i++)
|
|
|
|
{
|
|
|
|
(*i)->removeChild(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::safeKill()
|
|
|
|
{
|
|
|
|
alpha = 0;
|
|
|
|
life = 0;
|
|
|
|
onEndOfLife();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
for (RenderObjectList::iterator i = deathNotifications.begin(); i != deathNotifications.end(); i++)
|
|
|
|
{
|
|
|
|
(*i)->deathNotify(this);
|
|
|
|
}
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
if (this->parent)
|
|
|
|
{
|
2022-05-18 22:01:27 +00:00
|
|
|
_markedForDelete = true;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (stateData)
|
|
|
|
stateData->removeRenderObject(this);
|
|
|
|
else
|
|
|
|
core->enqueueRenderObjectDeletion(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getNormal() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
float a = MathFunctions::toRadians(getAbsoluteRotation().z);
|
|
|
|
return Vector(sinf(a),cosf(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
// HACK: this is probably a slow implementation
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getForward() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
Vector v = getWorldCollidePosition(Vector(0,-1, 0));
|
|
|
|
Vector r = v - getWorldCollidePosition();
|
|
|
|
r.normalize2D();
|
|
|
|
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
Vector RenderObject::getAbsoluteRotation() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
Vector r = rotation;
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
return parent->getAbsoluteRotation() + r;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::onUpdate(float dt)
|
|
|
|
{
|
|
|
|
if (isDead()) return;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-07-18 21:00:22 +00:00
|
|
|
if(!updateLife(dt))
|
|
|
|
return;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
// FIXME: We might not need to do lifetime checks either; I just
|
|
|
|
// left that above for safety since I'm not certain. --achurch
|
|
|
|
if (isHidden()) return;
|
|
|
|
|
2012-01-02 20:34:29 +00:00
|
|
|
position += velocity * dt;
|
|
|
|
velocity += gravity * dt;
|
2011-08-03 20:05:33 +00:00
|
|
|
position.update(dt);
|
|
|
|
velocity.update(dt);
|
2022-06-20 16:39:08 +00:00
|
|
|
gravity.update(dt);
|
2011-08-03 20:05:33 +00:00
|
|
|
scale.update(dt);
|
|
|
|
rotation.update(dt);
|
|
|
|
color.update(dt);
|
|
|
|
alpha.update(dt);
|
|
|
|
offset.update(dt);
|
|
|
|
internalOffset.update(dt);
|
|
|
|
rotationOffset.update(dt);
|
|
|
|
|
2022-05-18 22:01:27 +00:00
|
|
|
bool hasChildrenToDelete = false;
|
2011-08-03 20:05:33 +00:00
|
|
|
for (Children::iterator i = children.begin(); i != children.end(); i++)
|
|
|
|
{
|
|
|
|
if (shareAlphaWithChildren)
|
|
|
|
(*i)->alpha.x = this->alpha.x;
|
|
|
|
if (shareColorWithChildren)
|
|
|
|
(*i)->color = this->color;
|
|
|
|
|
2022-05-20 01:27:15 +00:00
|
|
|
if ((*i)->pm != PM_NONE)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
(*i)->update(dt);
|
|
|
|
}
|
2022-05-18 22:01:27 +00:00
|
|
|
hasChildrenToDelete |= (*i)->_markedForDelete;
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-05-18 22:01:27 +00:00
|
|
|
if (hasChildrenToDelete)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 22:01:27 +00:00
|
|
|
size_t w = 0;
|
|
|
|
const size_t N = children.size();
|
|
|
|
for (size_t i = 0; i < N; ++i)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 22:01:27 +00:00
|
|
|
RenderObject *ro = children[i];
|
|
|
|
if(ro->_markedForDelete)
|
|
|
|
{
|
|
|
|
ro->parent = NULL;
|
|
|
|
ro->destroy();
|
2022-05-20 01:27:15 +00:00
|
|
|
if(ro->pm == PM_POINTER)
|
|
|
|
delete ro;
|
2022-05-18 22:01:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
children[w++] = ro;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-05-18 22:01:27 +00:00
|
|
|
children.resize(w);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
if (MotionBlurData *mb = this->motionBlur)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
if(!mb->transition)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
if (mb->frameOffsetCounter >= mb->frameOffset)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
mb->frameOffsetCounter = 0;
|
|
|
|
mb->positions[0].position = position;
|
|
|
|
mb->positions[0].rotz = rotation.z;
|
|
|
|
for (int i = mb->positions.size()-1; i > 0; i--)
|
|
|
|
{
|
|
|
|
mb->positions[i] = mb->positions[i-1];
|
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-05-18 17:44:42 +00:00
|
|
|
else
|
|
|
|
mb->frameOffsetCounter ++;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
else
|
2022-05-18 17:44:42 +00:00
|
|
|
{
|
|
|
|
mb->transitionTimer -= dt*2;
|
|
|
|
if (mb->transitionTimer <= 0)
|
|
|
|
freeMotionBlur();
|
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-05-18 17:44:42 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 21:00:22 +00:00
|
|
|
bool RenderObject::updateLife(float dt)
|
2022-05-18 17:44:42 +00:00
|
|
|
{
|
|
|
|
if (decayRate > 0)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
life -= decayRate*dt;
|
|
|
|
if (life<=0)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-18 17:44:42 +00:00
|
|
|
safeKill();
|
2022-07-18 21:00:22 +00:00
|
|
|
return false;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-18 17:44:42 +00:00
|
|
|
if (fadeAlphaWithLife && !alpha.isInterpolating())
|
|
|
|
{
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
alpha = life/maxLife;
|
|
|
|
}
|
2022-07-18 21:00:22 +00:00
|
|
|
return true;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::unloadDevice()
|
|
|
|
{
|
|
|
|
for (Children::iterator i = children.begin(); i != children.end(); i++)
|
|
|
|
{
|
|
|
|
(*i)->unloadDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::reloadDevice()
|
|
|
|
{
|
|
|
|
for (Children::iterator i = children.begin(); i != children.end(); i++)
|
|
|
|
{
|
|
|
|
(*i)->reloadDevice();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
MotionBlurData* RenderObject::ensureMotionBlur()
|
|
|
|
{
|
|
|
|
MotionBlurData *mb = this->motionBlur;
|
|
|
|
if(!mb)
|
|
|
|
{
|
|
|
|
mb = new MotionBlurData;
|
|
|
|
this->motionBlur = mb;
|
|
|
|
}
|
|
|
|
return mb;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::freeMotionBlur()
|
|
|
|
{
|
|
|
|
if(motionBlur)
|
|
|
|
{
|
|
|
|
delete motionBlur;
|
|
|
|
motionBlur = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-23 23:06:51 +00:00
|
|
|
bool RenderObject::setTexture(const std::string &n)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2023-05-30 22:55:16 +00:00
|
|
|
CountedPtr<Texture> tex = core->getTexture(n);
|
2015-03-23 23:06:51 +00:00
|
|
|
setTexturePointer(tex);
|
2023-05-30 22:55:16 +00:00
|
|
|
return tex->success;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::addChild(RenderObject *r, ParentManaged pm, RenderBeforeParent rbp, ChildOrder order)
|
|
|
|
{
|
|
|
|
if (r->parent)
|
|
|
|
{
|
|
|
|
errorLog("Engine does not support multiple parents");
|
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
|
|
|
return;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (order == CHILD_BACK)
|
|
|
|
children.push_back(r);
|
|
|
|
else
|
2014-07-21 20:21:22 +00:00
|
|
|
children.insert(children.begin(), r);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
r->pm = pm;
|
|
|
|
|
|
|
|
if (rbp == RBP_OFF)
|
|
|
|
r->renderBeforeParent = 0;
|
|
|
|
else if (rbp == RBP_ON)
|
|
|
|
r->renderBeforeParent = 1;
|
|
|
|
|
|
|
|
r->parent = this;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
StateData *RenderObject::getStateData() const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
return parent->getStateData();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return stateData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RenderObject::setOverrideCullRadius(float ovr)
|
|
|
|
{
|
|
|
|
overrideCullRadiusSqr = ovr * ovr;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool RenderObject::isCoordinateInRadius(const Vector &pos, float r) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
Vector d = pos-getRealPosition();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
return (d.getSquaredLength2D() < r*r);
|
|
|
|
}
|
2022-05-18 17:44:42 +00:00
|
|
|
|
|
|
|
MotionBlurData::MotionBlurData()
|
|
|
|
: transition(false), frameOffsetCounter(0), frameOffset(0), transitionTimer(0)
|
|
|
|
{
|
|
|
|
}
|