1
0
Fork 0
mirror of https://git.coom.tech/drummyfish/raycastlib.git synced 2024-11-21 20:29:59 +01:00

Optimize movement

This commit is contained in:
Miloslav Číž 2018-09-08 07:28:47 +02:00
parent 61e747c8d6
commit fa287067b4

View file

@ -977,6 +977,12 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
{ {
// TODO: have the cam coll parameters precomputed as macros? => faster // TODO: have the cam coll parameters precomputed as macros? => faster
int8_t movesInPlane = planeOffset.x != 0 || planeOffset.y != 0;
int16_t xSquareNew, ySquareNew;
if (movesInPlane)
{
Vector2D corner; // BBox corner in the movement direction Vector2D corner; // BBox corner in the movement direction
Vector2D cornerNew; Vector2D cornerNew;
@ -992,8 +998,8 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
cornerNew.x = corner.x + planeOffset.x; cornerNew.x = corner.x + planeOffset.x;
cornerNew.y = corner.y + planeOffset.y; cornerNew.y = corner.y + planeOffset.y;
int16_t xSquareNew = divRoundDown(cornerNew.x,UNITS_PER_SQUARE); xSquareNew = divRoundDown(cornerNew.x,UNITS_PER_SQUARE);
int16_t ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE); ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE);
Unit bottomLimit = camera->height - camera->collisionHeightBelow + Unit bottomLimit = camera->height - camera->collisionHeightBelow +
camera->collisionStepHeight; camera->collisionStepHeight;
@ -1038,8 +1044,8 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
#define collHandle(dir)\ #define collHandle(dir)\
if (dir##Collides)\ if (dir##Collides)\
cornerNew.dir = (dir##Square) * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2 +\ cornerNew.dir = (dir##Square) * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2\
dir##Dir * (UNITS_PER_SQUARE / 2) - dir##Dir;\ + dir##Dir * (UNITS_PER_SQUARE / 2) - dir##Dir;\
collHandle(x) collHandle(x)
collHandle(y) collHandle(y)
@ -1062,6 +1068,10 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
camera->position.x = cornerNew.x - xDir * camera->collisionRadius; camera->position.x = cornerNew.x - xDir * camera->collisionRadius;
camera->position.y = cornerNew.y - yDir * camera->collisionRadius; camera->position.y = cornerNew.y - yDir * camera->collisionRadius;
}
if (movesInPlane || heightOffset != 0)
{
camera->height += heightOffset; camera->height += heightOffset;
xSquareNew = divRoundDown(camera->position.x,UNITS_PER_SQUARE); xSquareNew = divRoundDown(camera->position.x,UNITS_PER_SQUARE);
@ -1074,6 +1084,7 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
camera->height = clamp(camera->height, camera->height = clamp(camera->height,
floorHeightNew + camera->collisionHeightBelow, floorHeightNew + camera->collisionHeightBelow,
ceilingHeightNew - camera->collisionHeightAbove); ceilingHeightNew - camera->collisionHeightAbove);
}
} }
#endif #endif