mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-05-10 19:13:44 +00:00
Fix some small performance bottlenecks:
- Vector interpolation. Also removed unused interpolation trigger events. - Game::collideCircleWithGrid() - GridRender::onRender() (removed Andrew's hack, use fixed map file!) - make use of glVertex3i() & memchr() in GridRender
This commit is contained in:
parent
99e32e0ee7
commit
2d7eeb4781
12 changed files with 183 additions and 345 deletions
|
@ -9092,9 +9092,8 @@ void Avatar::onUpdate(float dt)
|
||||||
|
|
||||||
|
|
||||||
int hw = collideCircle;
|
int hw = collideCircle;
|
||||||
Vector fix;
|
|
||||||
|
|
||||||
if (dsq->game->collideCircleWithGrid(position, hw, &fix))
|
if (dsq->game->collideCircleWithGrid(position, hw))
|
||||||
{
|
{
|
||||||
if (dsq->game->lastCollideTileType == OT_HURT
|
if (dsq->game->lastCollideTileType == OT_HURT
|
||||||
&& dsq->continuity.getWorldType() != WT_SPIRIT
|
&& dsq->continuity.getWorldType() != WT_SPIRIT
|
||||||
|
|
|
@ -206,7 +206,6 @@ void CollideEntity::updateMovement(float dt)
|
||||||
|
|
||||||
const int hw = collideRadius;
|
const int hw = collideRadius;
|
||||||
bool freeRange = false;
|
bool freeRange = false;
|
||||||
Vector fix;
|
|
||||||
|
|
||||||
if (isv(EV_COLLIDELEVEL,1))
|
if (isv(EV_COLLIDELEVEL,1))
|
||||||
{
|
{
|
||||||
|
@ -216,7 +215,7 @@ void CollideEntity::updateMovement(float dt)
|
||||||
bool doesFreeRange = !isPullable();
|
bool doesFreeRange = !isPullable();
|
||||||
if (doesFreeRange)
|
if (doesFreeRange)
|
||||||
{
|
{
|
||||||
if (dsq->game->collideCircleWithGrid(position, hw, &fix))
|
if (dsq->game->collideCircleWithGrid(position, hw))
|
||||||
{
|
{
|
||||||
// starting in a collision state
|
// starting in a collision state
|
||||||
freeRange = true;
|
freeRange = true;
|
||||||
|
@ -232,7 +231,7 @@ void CollideEntity::updateMovement(float dt)
|
||||||
{
|
{
|
||||||
if (getState() == STATE_PUSH)
|
if (getState() == STATE_PUSH)
|
||||||
{
|
{
|
||||||
if (!freeRange && dsq->game->collideCircleWithGrid(position, hw, &fix))
|
if (!freeRange && dsq->game->collideCircleWithGrid(position, hw))
|
||||||
{
|
{
|
||||||
position = lastPosition;
|
position = lastPosition;
|
||||||
collided = true;
|
collided = true;
|
||||||
|
@ -241,7 +240,7 @@ void CollideEntity::updateMovement(float dt)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!freeRange && ((!canLeaveWater && !isUnderWater() && wasUnderWater) || dsq->game->collideCircleWithGrid(position, hw, &fix)))
|
if (!freeRange && ((!canLeaveWater && !isUnderWater() && wasUnderWater) || dsq->game->collideCircleWithGrid(position, hw)))
|
||||||
{
|
{
|
||||||
position = lastPosition;
|
position = lastPosition;
|
||||||
onHitWall();
|
onHitWall();
|
||||||
|
|
|
@ -11161,47 +11161,72 @@ Vector Game::getClosestPointOnLine(Vector a, Vector b, Vector p)
|
||||||
return a + V;
|
return a + V;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Game::collideCircleWithGrid(Vector position, int r, Vector *fill)
|
bool Game::collideCircleWithGrid(const Vector& position, int r)
|
||||||
{
|
{
|
||||||
Vector tile = position;
|
TileVector t(position);
|
||||||
TileVector t(tile);
|
|
||||||
tile.x = t.x;
|
|
||||||
tile.y = t.y;
|
|
||||||
|
|
||||||
float hsz = TILE_SIZE/2;
|
const float hsz = TILE_SIZE/2;
|
||||||
int xrange=1,yrange=1;
|
const int xrange = (r/TILE_SIZE)+1;
|
||||||
xrange = (r/TILE_SIZE)+1;
|
const int yrange = (r/TILE_SIZE)+1;
|
||||||
yrange = (r/TILE_SIZE)+1;
|
|
||||||
|
|
||||||
for (int x = tile.x-xrange; x <= tile.x+xrange; x++)
|
// quick early check if out of bounds
|
||||||
|
const int xstart = t.x-xrange;
|
||||||
|
const int ystart = t.y-yrange;
|
||||||
|
if (xstart < 0 || ystart < 0)
|
||||||
{
|
{
|
||||||
for (int y = tile.y-yrange; y <= tile.y+yrange; y++)
|
lastCollideTileType = (ObsType)1;
|
||||||
|
lastCollidePosition = TileVector::worldVector(xstart, ystart);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int r2 = sqr(r);
|
||||||
|
const int xmax = t.x+xrange;
|
||||||
|
const int ymax = t.y+yrange;
|
||||||
|
|
||||||
|
for (int x = xstart; x <= xmax; x++)
|
||||||
|
{
|
||||||
|
if (x >= MAX_GRID)
|
||||||
{
|
{
|
||||||
int v = this->getGrid(TileVector(x, y));
|
lastCollideTileType = (ObsType)1;
|
||||||
|
lastCollidePosition = TileVector::worldVector(x, ystart);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y = ystart; y <= ymax; y++)
|
||||||
|
{
|
||||||
|
if (y >= MAX_GRID)
|
||||||
|
{
|
||||||
|
lastCollideTileType = (ObsType)1;
|
||||||
|
lastCollidePosition = TileVector::worldVector(x, y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int v = getGridRaw(x, y); // known to be in bounds
|
||||||
if (v != 0)
|
if (v != 0)
|
||||||
{
|
{
|
||||||
//if (tile.x == x && tile.y == y) return true;
|
lastCollidePosition = TileVector::worldVector(x, y);
|
||||||
TileVector t(x, y);
|
|
||||||
lastCollidePosition = t.worldVector();
|
|
||||||
//if (tile.x == x && tile.y == y) return true;
|
|
||||||
float rx = (x*TILE_SIZE)+TILE_SIZE/2;
|
float rx = (x*TILE_SIZE)+TILE_SIZE/2;
|
||||||
float ry = (y*TILE_SIZE)+TILE_SIZE/2;
|
float ry = (y*TILE_SIZE)+TILE_SIZE/2;
|
||||||
|
|
||||||
float rSqr;
|
|
||||||
lastCollideTileType = (ObsType)v;
|
lastCollideTileType = (ObsType)v;
|
||||||
|
|
||||||
rSqr = sqr(position.x - (rx+hsz)) + sqr(position.y - (ry+hsz));
|
float yp = sqr(position.y - (ry+hsz));
|
||||||
if (rSqr < sqr(r)) return true;
|
float xp = sqr(position.x - (rx+hsz));
|
||||||
|
|
||||||
rSqr = sqr(position.x - (rx-hsz)) + sqr(position.y - (ry+hsz));
|
if (xp + yp < r2)
|
||||||
if (rSqr < sqr(r)) return true;
|
return true;
|
||||||
|
|
||||||
rSqr = sqr(position.x - (rx-hsz)) + sqr(position.y - (ry-hsz));
|
float xm = sqr(position.x - (rx-hsz));
|
||||||
if (rSqr < sqr(r)) return true;
|
|
||||||
|
|
||||||
rSqr = sqr(position.x - (rx+hsz)) + sqr(position.y - (ry-hsz));
|
if (xm + yp < r2)
|
||||||
if (rSqr < sqr(r)) return true;
|
return true;
|
||||||
|
|
||||||
|
float ym = sqr(position.y - (ry-hsz));
|
||||||
|
if (xm + ym < r2)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (xp < ym)
|
||||||
|
return true;
|
||||||
|
|
||||||
if (position.x > rx-hsz && position.x < rx+hsz)
|
if (position.x > rx-hsz && position.x < rx+hsz)
|
||||||
{
|
{
|
||||||
|
@ -11211,7 +11236,6 @@ bool Game::collideCircleWithGrid(Vector position, int r, Vector *fill)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (position.y > ry-hsz && position.y < ry+hsz)
|
if (position.y > ry-hsz && position.y < ry+hsz)
|
||||||
{
|
{
|
||||||
if (fabsf(rx - position.x) < r+hsz)
|
if (fabsf(rx - position.x) < r+hsz)
|
||||||
|
@ -11226,7 +11250,7 @@ bool Game::collideCircleWithGrid(Vector position, int r, Vector *fill)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Game::collideBoxWithGrid(Vector position, int hw, int hh)
|
bool Game::collideBoxWithGrid(const Vector& position, int hw, int hh)
|
||||||
{
|
{
|
||||||
Vector tile = position;
|
Vector tile = position;
|
||||||
TileVector t(tile);
|
TileVector t(tile);
|
||||||
|
|
|
@ -636,7 +636,8 @@ public:
|
||||||
|
|
||||||
std::string getSelectedChoice() { return selectedChoice; }
|
std::string getSelectedChoice() { return selectedChoice; }
|
||||||
|
|
||||||
int getGrid(const TileVector &tile);
|
int getGrid(const TileVector &tile) const;
|
||||||
|
int getGridRaw(unsigned int x, unsigned int y) const;
|
||||||
const signed char *getGridColumn(int tileX);
|
const signed char *getGridColumn(int tileX);
|
||||||
void setGrid(const TileVector &tile, int v);
|
void setGrid(const TileVector &tile, int v);
|
||||||
bool isObstructed(const TileVector &tile, int t = -1);
|
bool isObstructed(const TileVector &tile, int t = -1);
|
||||||
|
@ -669,8 +670,8 @@ public:
|
||||||
|
|
||||||
void registerSporeDrop(const Vector &pos, int t);
|
void registerSporeDrop(const Vector &pos, int t);
|
||||||
|
|
||||||
bool collideBoxWithGrid(Vector position, int w, int h);
|
bool collideBoxWithGrid(const Vector& position, int w, int h);
|
||||||
bool collideCircleWithGrid(Vector position, int r, Vector *fill=0);
|
bool collideCircleWithGrid(const Vector& position, int r);
|
||||||
|
|
||||||
bool collideHairVsCircle(Entity *a, int num, const Vector &pos2, int radius, float perc=0);
|
bool collideHairVsCircle(Entity *a, int num, const Vector &pos2, int radius, float perc=0);
|
||||||
|
|
||||||
|
@ -1214,7 +1215,13 @@ extern Game *game;
|
||||||
// INLINE FUNCTIONS
|
// INLINE FUNCTIONS
|
||||||
|
|
||||||
inline
|
inline
|
||||||
int Game::getGrid(const TileVector &tile)
|
int Game::getGridRaw(unsigned int x, unsigned int y) const
|
||||||
|
{
|
||||||
|
return grid[x][y];
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int Game::getGrid(const TileVector &tile) const
|
||||||
{
|
{
|
||||||
if (tile.x < 0 || tile.x >= MAX_GRID || tile.y < 0 || tile.y >= MAX_GRID) return 1;
|
if (tile.x < 0 || tile.x >= MAX_GRID || tile.y < 0 || tile.y >= MAX_GRID) return 1;
|
||||||
return grid[tile.x][tile.y];
|
return grid[tile.x][tile.y];
|
||||||
|
|
|
@ -39,6 +39,31 @@ void GridRender::onUpdate(float dt)
|
||||||
if (obsType != OT_BLACK) { blendEnabled = true; }
|
if (obsType != OT_BLACK) { blendEnabled = true; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static void doRenderGrid(int x, int startCol, int endCol)
|
||||||
|
{
|
||||||
|
const int drawx1 = x*TILE_SIZE;
|
||||||
|
const int drawx2 = (x+1)*TILE_SIZE;
|
||||||
|
const int drawy1 = startCol*TILE_SIZE;
|
||||||
|
const int drawy2 = (endCol+1)*TILE_SIZE;
|
||||||
|
|
||||||
|
#ifdef BBGE_BUILD_OPENGL
|
||||||
|
glBegin(GL_QUADS);
|
||||||
|
glVertex3i(drawx1, drawy2, 0.0f);
|
||||||
|
glVertex3i(drawx2, drawy2, 0.0f);
|
||||||
|
glVertex3i(drawx2, drawy1, 0.0f);
|
||||||
|
glVertex3i(drawx1, drawy1, 0.0f);
|
||||||
|
glEnd();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef BBGE_BUILD_DIRECTX
|
||||||
|
core->blitD3DVerts(0,
|
||||||
|
drawx1, drawy1,
|
||||||
|
drawx2, drawy1,
|
||||||
|
drawx2, drawy2,
|
||||||
|
drawx1, drawy2);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void GridRender::onRender()
|
void GridRender::onRender()
|
||||||
{
|
{
|
||||||
switch(obsType)
|
switch(obsType)
|
||||||
|
@ -59,7 +84,7 @@ void GridRender::onRender()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const int obsType = int(this->obsType);
|
int obsType = this->obsType;
|
||||||
Vector camPos = core->cameraPos;
|
Vector camPos = core->cameraPos;
|
||||||
camPos.x -= core->getVirtualOffX() * (core->invGlobalScale);
|
camPos.x -= core->getVirtualOffX() * (core->invGlobalScale);
|
||||||
const TileVector ct(camPos);
|
const TileVector ct(camPos);
|
||||||
|
@ -77,57 +102,43 @@ void GridRender::onRender()
|
||||||
startY = 0;
|
startY = 0;
|
||||||
if (endY >= MAX_GRID)
|
if (endY >= MAX_GRID)
|
||||||
endY = MAX_GRID-1;
|
endY = MAX_GRID-1;
|
||||||
for (int x = startX; x <= endX; x++)
|
for (int x = startX; x <= endX; ++x)
|
||||||
{
|
{
|
||||||
const signed char *gridColumn = dsq->game->getGridColumn(x);
|
const signed char *gridColumn = dsq->game->getGridColumn(x);
|
||||||
int startCol = -1, endCol;
|
int startCol = -1, y;
|
||||||
for (int y = startY; y <= endY; y++)
|
|
||||||
|
// fast-forward to next drawable byte
|
||||||
|
if(const signed char *next = (const signed char*)memchr(gridColumn + startY, obsType, endY - startY + 1)) // find next byte with correct obs type
|
||||||
{
|
{
|
||||||
int v = gridColumn[y];
|
y = next - gridColumn; // will get incremented right away, which is okay, because we alrady set startCol
|
||||||
// HACK: Don't draw the leftmost or rightmost column of
|
startCol = y;
|
||||||
// black tiles (otherwise they "leak out" around the
|
}
|
||||||
// edges of the Sun Temple). --achurch
|
else
|
||||||
if (v == OT_BLACK && ((dsq->game->getGridColumn(x-1))[y] != OT_BLACK || (dsq->game->getGridColumn(x+1))[y] != OT_BLACK))
|
continue; // nothing do draw in this column
|
||||||
v = OT_EMPTY;
|
|
||||||
|
|
||||||
if (v == obsType && startCol == -1)
|
for ( ; y < endY; ++y)
|
||||||
|
{
|
||||||
|
if (gridColumn[y] != obsType)
|
||||||
{
|
{
|
||||||
startCol = y;
|
doRenderGrid(x, startCol, y - 1);
|
||||||
}
|
|
||||||
else if ((v != obsType || y == endY) && startCol != -1)
|
// fast-forward to next drawable byte
|
||||||
{
|
if(const signed char *next = (const signed char*)memchr(gridColumn + y, obsType, endY - y)) // find next byte with correct obs type
|
||||||
endCol = y;
|
{
|
||||||
if (v != obsType)
|
y = next - gridColumn; // will get incremented right away, which is okay, because we alrady set startCol
|
||||||
endCol--;
|
startCol = y;
|
||||||
|
}
|
||||||
const float drawx1 = x*TILE_SIZE;
|
else
|
||||||
const float drawx2 = (x+1)*TILE_SIZE;
|
break;
|
||||||
const float drawy1 = startCol*TILE_SIZE;
|
|
||||||
const float drawy2 = (endCol+1)*TILE_SIZE;
|
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_OPENGL
|
|
||||||
glBegin(GL_QUADS);
|
|
||||||
glVertex3f(drawx1, drawy2, 0.0f);
|
|
||||||
glVertex3f(drawx2, drawy2, 0.0f);
|
|
||||||
glVertex3f(drawx2, drawy1, 0.0f);
|
|
||||||
glVertex3f(drawx1, drawy1, 0.0f);
|
|
||||||
glEnd();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BBGE_BUILD_DIRECTX
|
|
||||||
core->blitD3DVerts(0,
|
|
||||||
drawx1, drawy1,
|
|
||||||
drawx2, drawy1,
|
|
||||||
drawx2, drawy2,
|
|
||||||
drawx1, drawy2);
|
|
||||||
#endif
|
|
||||||
startCol = -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (y == endY)
|
||||||
|
{
|
||||||
|
doRenderGrid(x, startCol, y);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SongLineRender::SongLineRender()
|
SongLineRender::SongLineRender()
|
||||||
{
|
{
|
||||||
followCamera = 1;
|
followCamera = 1;
|
||||||
|
|
|
@ -46,11 +46,7 @@ void Segmented::destroySegments(float life)
|
||||||
for (int i = 0; i < segments.size(); i++)
|
for (int i = 0; i < segments.size(); i++)
|
||||||
{
|
{
|
||||||
segments[i]->setLife(life);
|
segments[i]->setLife(life);
|
||||||
segments[i]->setDecayRate(1.0);
|
segments[i]->setDecayRate(1.0f);
|
||||||
|
|
||||||
//segments[i]->setLife(1.0);
|
|
||||||
//segments[i]->setDecayRate(1.0/life);
|
|
||||||
//segments[i]->setDecayRate(1.0/life);
|
|
||||||
segments[i]->fadeAlphaWithLife = true;
|
segments[i]->fadeAlphaWithLife = true;
|
||||||
}
|
}
|
||||||
segments.clear();
|
segments.clear();
|
||||||
|
@ -84,7 +80,7 @@ void Segmented::updateSegment(int i, const Vector &diff)
|
||||||
|
|
||||||
float angle;
|
float angle;
|
||||||
MathFunctions::calculateAngleBetweenVectorsInDegrees(Vector(0,0,0), diff, angle);
|
MathFunctions::calculateAngleBetweenVectorsInDegrees(Vector(0,0,0), diff, angle);
|
||||||
segments[i]->rotation.interpolateTo(Vector(0,0,angle), 0.2);
|
segments[i]->rotation.interpolateTo(Vector(0,0,angle), 0.2f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Segmented::updateAlpha(float a)
|
void Segmented::updateAlpha(float a)
|
||||||
|
@ -105,46 +101,25 @@ void Segmented::warpSegments(const Vector &position)
|
||||||
|
|
||||||
void Segmented::updateSegments(const Vector &position, bool reverse)
|
void Segmented::updateSegments(const Vector &position, bool reverse)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
if (lastPositions.empty())
|
|
||||||
{
|
|
||||||
for (int i = 0; i < segments.size(); i++)
|
|
||||||
{
|
|
||||||
segments[i]->position = position;
|
|
||||||
}
|
|
||||||
lastPositions.resize(numSegments);
|
|
||||||
for (int i = 0; i < numSegments; i++)
|
|
||||||
{
|
|
||||||
lastPositions.push_back(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
const int top = segments.size()-1;
|
const int top = segments.size()-1;
|
||||||
Vector lastPosition = position;
|
const Vector *lastPosition = &position;
|
||||||
if (!reverse)
|
if (!reverse)
|
||||||
{
|
{
|
||||||
for (int i = 0; i <= top; i++)
|
for (int i = 0; i <= top; i++)
|
||||||
{
|
{
|
||||||
const Vector diff = lastPosition - segments[i]->position;
|
const Vector diff = *lastPosition - segments[i]->position;
|
||||||
updateSegment(i, diff);
|
updateSegment(i, diff);
|
||||||
lastPosition = segments[i]->position;
|
lastPosition = &segments[i]->position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (int i = top; i >= 0; i--)
|
for (int i = top; i >= 0; i--)
|
||||||
{
|
{
|
||||||
const Vector diff = lastPosition - segments[i]->position;
|
const Vector diff = *lastPosition - segments[i]->position;
|
||||||
updateSegment(i, diff);
|
updateSegment(i, diff);
|
||||||
lastPosition = segments[i]->position;
|
lastPosition = &segments[i]->position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
for (int i = lastPositions.size()-1; i > 0; i--)
|
|
||||||
{
|
|
||||||
lastPositions[i] = lastPositions[i-1];
|
|
||||||
}
|
|
||||||
lastPositions[0] = position;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,14 +37,19 @@ public:
|
||||||
|
|
||||||
TileVector() : x(0),y(0) {}
|
TileVector() : x(0),y(0) {}
|
||||||
|
|
||||||
Vector worldVector() const
|
inline Vector worldVector() const
|
||||||
|
{
|
||||||
|
return worldVector(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static Vector worldVector(int x, int y)
|
||||||
{
|
{
|
||||||
return Vector(x*TILE_SIZE+TILE_SIZE/2, y*TILE_SIZE+TILE_SIZE/2);
|
return Vector(x*TILE_SIZE+TILE_SIZE/2, y*TILE_SIZE+TILE_SIZE/2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isZero() const
|
inline bool isZero() const
|
||||||
{
|
{
|
||||||
return (x==0 && y==0);
|
return !(x | y);
|
||||||
}
|
}
|
||||||
|
|
||||||
int x,y;
|
int x,y;
|
||||||
|
|
|
@ -94,6 +94,7 @@ GL_FUNC(void,glTexCoord2f,(GLfloat s, GLfloat t),(s,t),)
|
||||||
GL_FUNC(void,glTexCoord2d,(GLdouble s, GLdouble 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,glVertex2f,(GLfloat x, GLfloat y),(x,y),)
|
||||||
GL_FUNC(void,glVertex3f,(GLfloat x, GLfloat y, GLfloat z),(x,y,z),)
|
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...
|
// stuff GLU needs...
|
||||||
GL_FUNC(void,glGetIntegerv,(GLenum pname, GLint *params),(pname,params),)
|
GL_FUNC(void,glGetIntegerv,(GLenum pname, GLint *params),(pname,params),)
|
||||||
|
|
|
@ -297,7 +297,7 @@ Vector RenderObject::getInvRotPosition(const Vector &vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderObject::matrixChain()
|
void RenderObject::matrixChain()
|
||||||
{
|
{
|
||||||
if (parent)
|
if (parent)
|
||||||
parent->matrixChain();
|
parent->matrixChain();
|
||||||
|
|
||||||
|
@ -1256,35 +1256,8 @@ void RenderObject::onUpdate(float dt)
|
||||||
// left that above for safety since I'm not certain. --achurch
|
// left that above for safety since I'm not certain. --achurch
|
||||||
if (isHidden()) return;
|
if (isHidden()) return;
|
||||||
|
|
||||||
/*
|
position += velocity * dt;
|
||||||
width.update(dt);
|
velocity += gravity * 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);
|
position.update(dt);
|
||||||
velocity.update(dt);
|
velocity.update(dt);
|
||||||
scale.update(dt);
|
scale.update(dt);
|
||||||
|
|
|
@ -221,7 +221,7 @@ public:
|
||||||
inline Vector getFollowCameraPosition() const;
|
inline Vector getFollowCameraPosition() const;
|
||||||
|
|
||||||
void lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset=0);
|
void lookAt(const Vector &pos, float t, float minAngle, float maxAngle, float offset=0);
|
||||||
RenderObject *getParent() const {return parent;}
|
inline RenderObject *getParent() const {return parent;}
|
||||||
void applyBlendType();
|
void applyBlendType();
|
||||||
void fhTo(bool fh);
|
void fhTo(bool fh);
|
||||||
void addDeathNotify(RenderObject *r);
|
void addDeathNotify(RenderObject *r);
|
||||||
|
|
192
BBGE/Vector.cpp
192
BBGE/Vector.cpp
|
@ -268,19 +268,6 @@ void VectorPath::append(const VectorPath &path)
|
||||||
pathNodes.push_back(path.pathNodes[i]);
|
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)
|
void VectorPath::cut(int n)
|
||||||
{
|
{
|
||||||
std::vector<VectorPathNode> copy = pathNodes;
|
std::vector<VectorPathNode> copy = pathNodes;
|
||||||
|
@ -302,7 +289,7 @@ void VectorPath::removeNode(int t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector VectorPath::getValue(float percent)
|
Vector VectorPath::getValue(float usePercent)
|
||||||
{
|
{
|
||||||
if (pathNodes.empty())
|
if (pathNodes.empty())
|
||||||
{
|
{
|
||||||
|
@ -310,11 +297,9 @@ Vector VectorPath::getValue(float percent)
|
||||||
return Vector(0,0,0);
|
return Vector(0,0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float usePercent = percent;
|
VectorPathNode *target = 0;
|
||||||
VectorPathNode *from = 0, *target = 0;
|
VectorPathNode *from = &pathNodes[0];
|
||||||
from = &pathNodes[0];
|
for (int i = 0; i < pathNodes.size(); ++i)
|
||||||
int i = 0;
|
|
||||||
for (i = 0; i < pathNodes.size(); i++)
|
|
||||||
{
|
{
|
||||||
if (pathNodes[i].percent >= usePercent)
|
if (pathNodes[i].percent >= usePercent)
|
||||||
{
|
{
|
||||||
|
@ -460,28 +445,11 @@ float InterpolatedVector::interpolateTo(Vector vec, float timePeriod, int loopTy
|
||||||
data->loopType = loopType;
|
data->loopType = loopType;
|
||||||
data->pingPong = pingPong;
|
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;
|
return data->timePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InterpolatedVector::setInterpolationTrigger(InterpolatedVector *trigger, bool triggerFlag)
|
|
||||||
{
|
|
||||||
InterpolatedVectorData *data = ensureData();
|
|
||||||
data->trigger = trigger;
|
|
||||||
data->triggerFlag = triggerFlag;
|
|
||||||
}
|
|
||||||
void InterpolatedVector::stop()
|
void InterpolatedVector::stop()
|
||||||
{
|
{
|
||||||
if (data)
|
if (data)
|
||||||
|
@ -498,34 +466,8 @@ void InterpolatedVector::startPath(float time, float ease)
|
||||||
data->followingPath = true;
|
data->followingPath = true;
|
||||||
data->loopType = 0;
|
data->loopType = 0;
|
||||||
data->pingPong = false;
|
data->pingPong = false;
|
||||||
data->speedPath = false;
|
|
||||||
data->endOfPathEvent.set(0);
|
|
||||||
// get the right values to start off with
|
// get the right values to start off with
|
||||||
updatePath(0);
|
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()
|
void InterpolatedVector::stopPath()
|
||||||
|
@ -543,109 +485,46 @@ void InterpolatedVector::resumePath()
|
||||||
void InterpolatedVector::updatePath(float dt)
|
void InterpolatedVector::updatePath(float dt)
|
||||||
{
|
{
|
||||||
InterpolatedVectorData *data = ensureData();
|
InterpolatedVectorData *data = ensureData();
|
||||||
|
if (data->pathTimer > data->pathTime)
|
||||||
if (!data->speedPath)
|
|
||||||
{
|
{
|
||||||
if (data->pathTimer > data->pathTime)
|
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)
|
||||||
{
|
{
|
||||||
Vector value = data->path.getPathNode(data->path.getNumPathNodes()-1)->value;
|
if (data->loopType > 0)
|
||||||
this->x = value.x;
|
data->loopType -= 1;
|
||||||
this->y = value.y;
|
|
||||||
this->z = value.z;
|
|
||||||
if (data->loopType != 0)
|
|
||||||
{
|
|
||||||
if (data->loopType > 0)
|
|
||||||
data->loopType -= 1;
|
|
||||||
|
|
||||||
int oldLoopType = data->loopType;
|
int oldLoopType = data->loopType;
|
||||||
|
|
||||||
if (data->pingPong)
|
if (data->pingPong)
|
||||||
{
|
{
|
||||||
// flip path
|
// flip path
|
||||||
data->path.flip();
|
data->path.flip();
|
||||||
startPath(data->pathTime);
|
startPath(data->pathTime);
|
||||||
data->loopType = oldLoopType;
|
data->loopType = oldLoopType;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
startPath(data->pathTime);
|
|
||||||
data->loopType = oldLoopType;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stopPath();
|
startPath(data->pathTime);
|
||||||
data->endOfPathEvent.call();
|
data->loopType = oldLoopType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data->pathTimer += dt * data->pathTimeMultiplier;
|
stopPath();
|
||||||
|
|
||||||
// ;//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
|
else
|
||||||
{
|
{
|
||||||
if (!isInterpolating())
|
data->pathTimer += dt * data->pathTimeMultiplier;
|
||||||
{
|
|
||||||
data->currentPathNode++;
|
float perc = data->pathTimer/data->pathTime;
|
||||||
VectorPathNode *node = data->path.getPathNode(data->currentPathNode);
|
Vector value = data->path.getValue(perc);
|
||||||
/*
|
this->x = value.x;
|
||||||
if (node)
|
this->y = value.y;
|
||||||
{
|
this->z = value.z;
|
||||||
|
|
||||||
}
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,9 +553,9 @@ void InterpolatedVector::doInterpolate(float dt)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
data->timePassed += 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->y = data->target.y;
|
||||||
this->z = data->target.z;
|
this->z = data->target.z;
|
||||||
data->interpolating = false;
|
data->interpolating = false;
|
||||||
|
@ -698,11 +577,6 @@ void InterpolatedVector::doInterpolate(float dt)
|
||||||
interpolateTo (data->target, data->timePeriod, data->loopType, data->pingPong, data->ease, IS_LOOPING);
|
interpolateTo (data->target, data->timePeriod, data->loopType, data->pingPong, data->ease, IS_LOOPING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
data->endOfInterpolationEvent.call();
|
|
||||||
data->endOfInterpolationEvent.set(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -435,7 +435,6 @@ public:
|
||||||
void realPercentageCalc();
|
void realPercentageCalc();
|
||||||
void removeNodes(int startInclusive, int endInclusive);
|
void removeNodes(int startInclusive, int endInclusive);
|
||||||
float getSubSectionLength(int startIncl, int endIncl);
|
float getSubSectionLength(int startIncl, int endIncl);
|
||||||
void subdivide();
|
|
||||||
protected:
|
protected:
|
||||||
std::vector <VectorPathNode> pathNodes;
|
std::vector <VectorPathNode> pathNodes;
|
||||||
};
|
};
|
||||||
|
@ -446,52 +445,34 @@ struct InterpolatedVectorData
|
||||||
{
|
{
|
||||||
InterpolatedVectorData()
|
InterpolatedVectorData()
|
||||||
{
|
{
|
||||||
trigger = 0;
|
|
||||||
triggerFlag = false;
|
|
||||||
pendingInterpolation = false;
|
|
||||||
interpolating = false;
|
interpolating = false;
|
||||||
pingPong = false;
|
pingPong = false;
|
||||||
loopType = 0;
|
loopType = 0;
|
||||||
pathTimer = 0;
|
pathTimer = 0;
|
||||||
pathTime = 0;
|
pathTime = 0;
|
||||||
pathSpeed = 1;
|
pathSpeed = 1;
|
||||||
currentPathNode = 0;
|
|
||||||
pathTimeMultiplier = 1;
|
pathTimeMultiplier = 1;
|
||||||
timePassed = 0;
|
timePassed = 0;
|
||||||
timePeriod = 0;
|
timePeriod = 0;
|
||||||
timeSpeedMultiplier = 1;
|
|
||||||
timeSpeedEase = 0;
|
|
||||||
//fakeTimePassed = 0;
|
//fakeTimePassed = 0;
|
||||||
speedPath = false;
|
|
||||||
ease = false;
|
ease = false;
|
||||||
followingPath = false;
|
followingPath = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
InterpolatedVector *trigger;
|
Vector from;
|
||||||
bool triggerFlag;
|
Vector target;
|
||||||
bool pendingInterpolation;
|
|
||||||
|
VectorPath path;
|
||||||
|
|
||||||
|
int loopType;
|
||||||
|
|
||||||
|
float pathTimer, pathTime;
|
||||||
|
float pathSpeed;
|
||||||
|
float pathTimeMultiplier;
|
||||||
|
float timePassed, timePeriod;
|
||||||
|
|
||||||
bool interpolating;
|
bool interpolating;
|
||||||
bool pingPong;
|
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 ease;
|
||||||
bool followingPath;
|
bool followingPath;
|
||||||
};
|
};
|
||||||
|
@ -530,7 +511,6 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setInterpolationTrigger(InterpolatedVector *trigger, bool triggerFlag);
|
|
||||||
enum InterpolateToFlag { NONE=0, IS_LOOPING };
|
enum InterpolateToFlag { NONE=0, IS_LOOPING };
|
||||||
float interpolateTo (Vector vec, float timePeriod, int loopType = 0, bool pingPong = false, bool ease = false, InterpolateToFlag flag = NONE);
|
float interpolateTo (Vector vec, float timePeriod, int loopType = 0, bool pingPong = false, bool ease = false, InterpolateToFlag flag = NONE);
|
||||||
void inline update(float dt)
|
void inline update(float dt)
|
||||||
|
@ -538,16 +518,6 @@ public:
|
||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (data->pendingInterpolation && data->trigger)
|
|
||||||
{
|
|
||||||
if (data->trigger->isInterpolating() == data->triggerFlag)
|
|
||||||
{
|
|
||||||
data->interpolating = true;
|
|
||||||
data->pendingInterpolation = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isFollowingPath())
|
if (isFollowingPath())
|
||||||
{
|
{
|
||||||
updatePath(dt);
|
updatePath(dt);
|
||||||
|
|
Loading…
Add table
Reference in a new issue