mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-06-08 09:31:58 +00:00
Simplify RenderObject::followCamera math, remove branches, cleanup followCamera related code.
It also appears that a RenderObject is always on a layer when rendered. Assert this in the code. This saves some extra branches.
This commit is contained in:
parent
81bfcb2f65
commit
0a3f57486b
5 changed files with 40 additions and 48 deletions
|
@ -164,8 +164,8 @@ public:
|
||||||
int startPass, endPass;
|
int startPass, endPass;
|
||||||
bool visible;
|
bool visible;
|
||||||
float followCamera;
|
float followCamera;
|
||||||
|
Vector followCameraMult; // calculated based on followCameraLock
|
||||||
int followCameraLock; // TODO: replace this with x/y scroll factor
|
int followCameraLock;
|
||||||
|
|
||||||
bool update;
|
bool update;
|
||||||
|
|
||||||
|
|
|
@ -454,6 +454,7 @@ bool RenderObject::isVisibleInPass(int pass) const
|
||||||
|
|
||||||
void RenderObject::render(const RenderState& rs) const
|
void RenderObject::render(const RenderState& rs) const
|
||||||
{
|
{
|
||||||
|
assert(layer != LR_NONE);
|
||||||
if (isHidden()) return;
|
if (isHidden()) return;
|
||||||
|
|
||||||
/// new (breaks anything?)
|
/// new (breaks anything?)
|
||||||
|
@ -484,21 +485,26 @@ void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt, flo
|
||||||
|
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
float followCamera = this->followCamera;
|
if(!parent)
|
||||||
if (layer != LR_NONE && !followCamera)
|
|
||||||
{
|
{
|
||||||
|
// 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];
|
const RenderObjectLayer& rl = core->renderObjectLayers[layer];
|
||||||
followCamera = rl.followCamera;
|
followCamera = rl.followCamera;
|
||||||
|
if(followCamera == 0) // normal object on normal layer
|
||||||
|
goto nofollow;
|
||||||
}
|
}
|
||||||
if (followCamera!=0 && !parent)
|
|
||||||
{
|
if (followCamera == 1) // UI overlay or similar; is independent of camera aka stays in the same spot on the screen
|
||||||
if (followCamera == 1)
|
|
||||||
{
|
{
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0);
|
glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0);
|
||||||
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
|
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
|
||||||
}
|
}
|
||||||
else
|
else // parallax scrolling
|
||||||
{
|
{
|
||||||
Vector pos = getFollowCameraPosition();
|
Vector pos = getFollowCameraPosition();
|
||||||
glTranslatef(pos.x, pos.y, pos.z);
|
glTranslatef(pos.x, pos.y, pos.z);
|
||||||
|
@ -518,6 +524,9 @@ void RenderObject::renderCall(const RenderState& rs, const Vector& renderAt, flo
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
nofollow:
|
||||||
|
// The vast majority of objects ends up here. We're a child, or followCamera == 0 and not on a parallax layer.
|
||||||
|
|
||||||
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
|
glTranslatef(renderPos.x, renderPos.y, renderPos.z);
|
||||||
|
|
||||||
if (RenderObject::renderPaths) // TODO: move this to debug render
|
if (RenderObject::renderPaths) // TODO: move this to debug render
|
||||||
|
|
|
@ -258,8 +258,11 @@ public:
|
||||||
|
|
||||||
float life;
|
float life;
|
||||||
|
|
||||||
// if 0: use value from RenderLayer.
|
// if 0: use value from RenderLayer. If still 0, render normally.
|
||||||
// UI elements have this == 1, ie. are totally unaffacted by camera movement.
|
// UI elements have this == 1, ie. are totally unaffected by camera movement
|
||||||
|
// and stay always on the same place on the screen.
|
||||||
|
// Any value > 0 and < 1 is parallax scrolling, where closer to 0 moves slower
|
||||||
|
// (looks like further away).
|
||||||
float followCamera;
|
float followCamera;
|
||||||
|
|
||||||
float alphaMod;
|
float alphaMod;
|
||||||
|
|
|
@ -228,6 +228,14 @@ void RenderObjectLayer::prepareRender()
|
||||||
core->renderObjectCount += toRender.size();
|
core->renderObjectCount += toRender.size();
|
||||||
toRender.push_back(NULL); // terminate
|
toRender.push_back(NULL); // terminate
|
||||||
core->totalRenderObjectCount += n;
|
core->totalRenderObjectCount += n;
|
||||||
|
|
||||||
|
switch(followCameraLock)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case FCL_NONE: followCameraMult = Vector(1, 1); break; // both H and V affected
|
||||||
|
case FCL_HORZ: followCameraMult = Vector(1, 0); break; // only H affected
|
||||||
|
case FCL_VERT: followCameraMult = Vector(0, 1); break; // only V affected
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderObjectLayer::render() const
|
void RenderObjectLayer::render() const
|
||||||
|
|
|
@ -34,46 +34,18 @@ inline bool RenderObject::isOnScreen() const
|
||||||
|
|
||||||
Vector RenderObject::getFollowCameraPosition() const
|
Vector RenderObject::getFollowCameraPosition() const
|
||||||
{
|
{
|
||||||
|
assert(layer != LR_NONE);
|
||||||
assert(!parent); // this makes no sense when we're not a root object
|
assert(!parent); // this makes no sense when we're not a root object
|
||||||
float f = followCamera;
|
|
||||||
int fcl = 0;
|
|
||||||
if (layer != LR_NONE)
|
|
||||||
{
|
|
||||||
const RenderObjectLayer &rl = core->renderObjectLayers[layer];
|
const RenderObjectLayer &rl = core->renderObjectLayers[layer];
|
||||||
|
Vector mul = rl.followCameraMult;
|
||||||
|
float f = followCamera;
|
||||||
if(!f)
|
if(!f)
|
||||||
f = rl.followCamera;
|
f = rl.followCamera;
|
||||||
fcl = rl.followCameraLock;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f <= 0)
|
if (f <= 0)
|
||||||
{
|
|
||||||
return position;
|
return position;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Vector pos = position;
|
|
||||||
|
|
||||||
switch (fcl)
|
const Vector pos = (position - core->screenCenter) * f + core->screenCenter;
|
||||||
{
|
return position * (Vector(1,1) - mul) + (pos * mul); // lerp
|
||||||
case FCL_HORZ:
|
|
||||||
pos.x = position.x - core->screenCenter.x;
|
|
||||||
pos.x *= f;
|
|
||||||
pos.x = core->screenCenter.x + pos.x;
|
|
||||||
break;
|
|
||||||
case FCL_VERT:
|
|
||||||
pos.y = position.y - core->screenCenter.y;
|
|
||||||
pos.y *= f;
|
|
||||||
pos.y = core->screenCenter.y + pos.y;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
pos = position - core->screenCenter;
|
|
||||||
pos *= f;
|
|
||||||
pos = core->screenCenter + pos;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue