mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-04 13:27:14 +00:00
Revert "Fix some small performance bottlenecks:"
This reverts commit 2d7eeb4781
.
This commit is contained in:
parent
b26eac658a
commit
16ae453431
12 changed files with 345 additions and 183 deletions
|
@ -94,7 +94,6 @@ GL_FUNC(void,glTexCoord2f,(GLfloat s, GLfloat t),(s,t),)
|
|||
GL_FUNC(void,glTexCoord2d,(GLdouble s, GLdouble t),(s,t),)
|
||||
GL_FUNC(void,glVertex2f,(GLfloat x, GLfloat y),(x,y),)
|
||||
GL_FUNC(void,glVertex3f,(GLfloat x, GLfloat y, GLfloat z),(x,y,z),)
|
||||
GL_FUNC(void,glVertex3i,(GLint x, GLint y, GLint z),(x,y,z),)
|
||||
|
||||
// stuff GLU needs...
|
||||
GL_FUNC(void,glGetIntegerv,(GLenum pname, GLint *params),(pname,params),)
|
||||
|
|
|
@ -297,7 +297,7 @@ Vector RenderObject::getInvRotPosition(const Vector &vec)
|
|||
}
|
||||
|
||||
void RenderObject::matrixChain()
|
||||
{
|
||||
{
|
||||
if (parent)
|
||||
parent->matrixChain();
|
||||
|
||||
|
@ -1256,8 +1256,35 @@ void RenderObject::onUpdate(float dt)
|
|||
// left that above for safety since I'm not certain. --achurch
|
||||
if (isHidden()) return;
|
||||
|
||||
position += velocity * dt;
|
||||
velocity += gravity * dt;
|
||||
/*
|
||||
width.update(dt);
|
||||
height.update(dt);
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
if (!parent && !children.empty() && shareAlphaWithChildren)
|
||||
{
|
||||
propogateAlpha();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
if (flipTimer.updateCheck(dt))
|
||||
{
|
||||
if (flipState == 0)
|
||||
{
|
||||
_fh = !_fh;
|
||||
flipState = 1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (!velocity.isZero())
|
||||
position += velocity * dt;
|
||||
if (!gravity.isZero())
|
||||
velocity += gravity * dt;
|
||||
position.update(dt);
|
||||
velocity.update(dt);
|
||||
scale.update(dt);
|
||||
|
|
|
@ -221,7 +221,7 @@ public:
|
|||
inline Vector getFollowCameraPosition() const;
|
||||
|
||||
void lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset=0);
|
||||
inline RenderObject *getParent() const {return parent;}
|
||||
RenderObject *getParent() const {return parent;}
|
||||
void applyBlendType();
|
||||
void fhTo(bool fh);
|
||||
void addDeathNotify(RenderObject *r);
|
||||
|
|
192
BBGE/Vector.cpp
192
BBGE/Vector.cpp
|
@ -268,6 +268,19 @@ void VectorPath::append(const VectorPath &path)
|
|||
pathNodes.push_back(path.pathNodes[i]);
|
||||
}
|
||||
|
||||
void VectorPath::subdivide()
|
||||
{
|
||||
/*
|
||||
std::vector<VectorPathNode> copy = pathNodes;
|
||||
pathNodes.clear();
|
||||
for (int i = 0; i < copy.size(); i++)
|
||||
{
|
||||
if (i < 4)
|
||||
pathNodes.push_back(i);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void VectorPath::cut(int n)
|
||||
{
|
||||
std::vector<VectorPathNode> copy = pathNodes;
|
||||
|
@ -289,7 +302,7 @@ void VectorPath::removeNode(int t)
|
|||
}
|
||||
}
|
||||
|
||||
Vector VectorPath::getValue(float usePercent)
|
||||
Vector VectorPath::getValue(float percent)
|
||||
{
|
||||
if (pathNodes.empty())
|
||||
{
|
||||
|
@ -297,9 +310,11 @@ Vector VectorPath::getValue(float usePercent)
|
|||
return Vector(0,0,0);
|
||||
}
|
||||
|
||||
VectorPathNode *target = 0;
|
||||
VectorPathNode *from = &pathNodes[0];
|
||||
for (int i = 0; i < pathNodes.size(); ++i)
|
||||
float usePercent = percent;
|
||||
VectorPathNode *from = 0, *target = 0;
|
||||
from = &pathNodes[0];
|
||||
int i = 0;
|
||||
for (i = 0; i < pathNodes.size(); i++)
|
||||
{
|
||||
if (pathNodes[i].percent >= usePercent)
|
||||
{
|
||||
|
@ -445,11 +460,28 @@ float InterpolatedVector::interpolateTo(Vector vec, float timePeriod, int loopTy
|
|||
data->loopType = loopType;
|
||||
data->pingPong = pingPong;
|
||||
|
||||
data->interpolating = true;
|
||||
|
||||
if (!data->trigger)
|
||||
{
|
||||
if (flag != IS_LOOPING)
|
||||
{
|
||||
data->startOfInterpolationEvent.call();
|
||||
data->endOfInterpolationEvent.set(0);
|
||||
}
|
||||
data->interpolating = true;
|
||||
}
|
||||
else
|
||||
data->pendingInterpolation = true;
|
||||
|
||||
return data->timePeriod;
|
||||
}
|
||||
|
||||
void InterpolatedVector::setInterpolationTrigger(InterpolatedVector *trigger, bool triggerFlag)
|
||||
{
|
||||
InterpolatedVectorData *data = ensureData();
|
||||
data->trigger = trigger;
|
||||
data->triggerFlag = triggerFlag;
|
||||
}
|
||||
void InterpolatedVector::stop()
|
||||
{
|
||||
if (data)
|
||||
|
@ -466,8 +498,34 @@ void InterpolatedVector::startPath(float time, float ease)
|
|||
data->followingPath = true;
|
||||
data->loopType = 0;
|
||||
data->pingPong = false;
|
||||
data->speedPath = false;
|
||||
data->endOfPathEvent.set(0);
|
||||
// get the right values to start off with
|
||||
updatePath(0);
|
||||
data->timeSpeedEase = ease;
|
||||
if (ease > 0)
|
||||
{
|
||||
data->timeSpeedMultiplier = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
data->timeSpeedMultiplier = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void InterpolatedVector::startSpeedPath(float speed)
|
||||
{
|
||||
InterpolatedVectorData *data = ensureData();
|
||||
|
||||
data->ease = false;
|
||||
data->currentPathNode = 0;
|
||||
data->pathTimer = 0;
|
||||
data->pathSpeed = speed;
|
||||
data->followingPath = true;
|
||||
data->loopType = 0;
|
||||
data->pingPong = false;
|
||||
data->speedPath = true;
|
||||
updatePath(0);
|
||||
}
|
||||
|
||||
void InterpolatedVector::stopPath()
|
||||
|
@ -485,46 +543,109 @@ void InterpolatedVector::resumePath()
|
|||
void InterpolatedVector::updatePath(float dt)
|
||||
{
|
||||
InterpolatedVectorData *data = ensureData();
|
||||
if (data->pathTimer > data->pathTime)
|
||||
|
||||
if (!data->speedPath)
|
||||
{
|
||||
Vector value = data->path.getPathNode(data->path.getNumPathNodes()-1)->value;
|
||||
this->x = value.x;
|
||||
this->y = value.y;
|
||||
this->z = value.z;
|
||||
if (data->loopType != 0)
|
||||
if (data->pathTimer > data->pathTime)
|
||||
{
|
||||
if (data->loopType > 0)
|
||||
data->loopType -= 1;
|
||||
|
||||
int oldLoopType = data->loopType;
|
||||
|
||||
if (data->pingPong)
|
||||
Vector value = data->path.getPathNode(data->path.getNumPathNodes()-1)->value;
|
||||
this->x = value.x;
|
||||
this->y = value.y;
|
||||
this->z = value.z;
|
||||
if (data->loopType != 0)
|
||||
{
|
||||
// flip path
|
||||
data->path.flip();
|
||||
startPath(data->pathTime);
|
||||
data->loopType = oldLoopType;
|
||||
if (data->loopType > 0)
|
||||
data->loopType -= 1;
|
||||
|
||||
int oldLoopType = data->loopType;
|
||||
|
||||
if (data->pingPong)
|
||||
{
|
||||
// flip path
|
||||
data->path.flip();
|
||||
startPath(data->pathTime);
|
||||
data->loopType = oldLoopType;
|
||||
}
|
||||
else
|
||||
{
|
||||
startPath(data->pathTime);
|
||||
data->loopType = oldLoopType;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
startPath(data->pathTime);
|
||||
data->loopType = oldLoopType;
|
||||
stopPath();
|
||||
data->endOfPathEvent.call();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
stopPath();
|
||||
data->pathTimer += dt * data->pathTimeMultiplier;
|
||||
|
||||
// ;//dt*data->timeSpeedMultiplier;
|
||||
float perc = data->pathTimer/data->pathTime;
|
||||
Vector value = data->path.getValue(perc);
|
||||
this->x = value.x;
|
||||
this->y = value.y;
|
||||
this->z = value.z;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
std::ostringstream os;
|
||||
os << "nodes: " << data->path.getNumPathNodes() << " pathTimer: " << data->pathTimer << " pathTime: " << data->pathTime << " perc: " << perc << " p(" << x << ", " << y << ")";
|
||||
debugLog(os.str());
|
||||
*/
|
||||
/*
|
||||
float diff = data->pathTime - data->pathTimer;
|
||||
if (data->timeSpeedEase > 0)
|
||||
{
|
||||
float secs = 1.0f/data->timeSpeedEase;
|
||||
if (diff <= secs)
|
||||
{
|
||||
data->timeSpeedMultiplier -= dt*data->timeSpeedEase;
|
||||
if (data->timeSpeedMultiplier < 0.1f)
|
||||
data->timeSpeedMultiplier = 0.1f;
|
||||
}
|
||||
}
|
||||
if (data->timeSpeedMultiplier < 1)
|
||||
{
|
||||
data->timeSpeedMultiplier += dt*data->timeSpeedEase;
|
||||
if (data->timeSpeedMultiplier >= 1)
|
||||
data->timeSpeedMultiplier = 1;
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data->pathTimer += dt * data->pathTimeMultiplier;
|
||||
|
||||
float perc = data->pathTimer/data->pathTime;
|
||||
Vector value = data->path.getValue(perc);
|
||||
this->x = value.x;
|
||||
this->y = value.y;
|
||||
this->z = value.z;
|
||||
if (!isInterpolating())
|
||||
{
|
||||
data->currentPathNode++;
|
||||
VectorPathNode *node = data->path.getPathNode(data->currentPathNode);
|
||||
/*
|
||||
if (node)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
stopPath();
|
||||
data->endOfPathEvent.call();
|
||||
}
|
||||
*/
|
||||
if (node)
|
||||
{
|
||||
interpolateTo(node->value, (node->value - Vector(this->x, this->y, this->z)).getLength3D()*(1.0f/data->pathSpeed));
|
||||
}
|
||||
else
|
||||
{
|
||||
// handle looping etc
|
||||
stopPath();
|
||||
data->endOfPathEvent.call();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -553,9 +674,9 @@ void InterpolatedVector::doInterpolate(float dt)
|
|||
}
|
||||
*/
|
||||
data->timePassed += dt;
|
||||
if (data->timePassed >= data->timePeriod)
|
||||
if (data->timePassed >= data->timePeriod)
|
||||
{
|
||||
this->x = data->target.x;
|
||||
this->x = data->target.x;
|
||||
this->y = data->target.y;
|
||||
this->z = data->target.z;
|
||||
data->interpolating = false;
|
||||
|
@ -577,6 +698,11 @@ void InterpolatedVector::doInterpolate(float dt)
|
|||
interpolateTo (data->target, data->timePeriod, data->loopType, data->pingPong, data->ease, IS_LOOPING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
data->endOfInterpolationEvent.call();
|
||||
data->endOfInterpolationEvent.set(0);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
|
|
@ -435,6 +435,7 @@ public:
|
|||
void realPercentageCalc();
|
||||
void removeNodes(int startInclusive, int endInclusive);
|
||||
float getSubSectionLength(int startIncl, int endIncl);
|
||||
void subdivide();
|
||||
protected:
|
||||
std::vector <VectorPathNode> pathNodes;
|
||||
};
|
||||
|
@ -445,34 +446,52 @@ struct InterpolatedVectorData
|
|||
{
|
||||
InterpolatedVectorData()
|
||||
{
|
||||
trigger = 0;
|
||||
triggerFlag = false;
|
||||
pendingInterpolation = false;
|
||||
interpolating = false;
|
||||
pingPong = false;
|
||||
loopType = 0;
|
||||
pathTimer = 0;
|
||||
pathTime = 0;
|
||||
pathSpeed = 1;
|
||||
currentPathNode = 0;
|
||||
pathTimeMultiplier = 1;
|
||||
timePassed = 0;
|
||||
timePeriod = 0;
|
||||
timeSpeedMultiplier = 1;
|
||||
timeSpeedEase = 0;
|
||||
//fakeTimePassed = 0;
|
||||
speedPath = false;
|
||||
ease = false;
|
||||
followingPath = false;
|
||||
}
|
||||
|
||||
Vector from;
|
||||
Vector target;
|
||||
|
||||
VectorPath path;
|
||||
|
||||
int loopType;
|
||||
|
||||
float pathTimer, pathTime;
|
||||
float pathSpeed;
|
||||
float pathTimeMultiplier;
|
||||
float timePassed, timePeriod;
|
||||
InterpolatedVector *trigger;
|
||||
bool triggerFlag;
|
||||
bool pendingInterpolation;
|
||||
|
||||
bool interpolating;
|
||||
bool pingPong;
|
||||
int loopType;
|
||||
|
||||
EventPtr endOfInterpolationEvent;
|
||||
EventPtr startOfInterpolationEvent;
|
||||
EventPtr endOfPathEvent;
|
||||
|
||||
VectorPath path;
|
||||
float pathTimer, pathTime;
|
||||
float pathSpeed;
|
||||
int currentPathNode;
|
||||
float pathTimeMultiplier;
|
||||
|
||||
float timePassed, timePeriod;
|
||||
Vector target;
|
||||
Vector from;
|
||||
|
||||
float timeSpeedMultiplier, timeSpeedEase;
|
||||
//float fakeTimePassed;
|
||||
bool speedPath;
|
||||
bool ease;
|
||||
bool followingPath;
|
||||
};
|
||||
|
@ -511,6 +530,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
void setInterpolationTrigger(InterpolatedVector *trigger, bool triggerFlag);
|
||||
enum InterpolateToFlag { NONE=0, IS_LOOPING };
|
||||
float interpolateTo (Vector vec, float timePeriod, int loopType = 0, bool pingPong = false, bool ease = false, InterpolateToFlag flag = NONE);
|
||||
void inline update(float dt)
|
||||
|
@ -518,6 +538,16 @@ public:
|
|||
if (!data)
|
||||
return;
|
||||
|
||||
if (data->pendingInterpolation && data->trigger)
|
||||
{
|
||||
if (data->trigger->isInterpolating() == data->triggerFlag)
|
||||
{
|
||||
data->interpolating = true;
|
||||
data->pendingInterpolation = false;
|
||||
}
|
||||
else
|
||||
return;
|
||||
}
|
||||
if (isFollowingPath())
|
||||
{
|
||||
updatePath(dt);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue