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:
parent
61e747c8d6
commit
fa287067b4
1 changed files with 100 additions and 89 deletions
19
raycastlib.h
19
raycastlib.h
|
@ -977,6 +977,12 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
|
|||
{
|
||||
// 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 cornerNew;
|
||||
|
||||
|
@ -992,8 +998,8 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
|
|||
cornerNew.x = corner.x + planeOffset.x;
|
||||
cornerNew.y = corner.y + planeOffset.y;
|
||||
|
||||
int16_t xSquareNew = divRoundDown(cornerNew.x,UNITS_PER_SQUARE);
|
||||
int16_t ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE);
|
||||
xSquareNew = divRoundDown(cornerNew.x,UNITS_PER_SQUARE);
|
||||
ySquareNew = divRoundDown(cornerNew.y,UNITS_PER_SQUARE);
|
||||
|
||||
Unit bottomLimit = camera->height - camera->collisionHeightBelow +
|
||||
camera->collisionStepHeight;
|
||||
|
@ -1038,8 +1044,8 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
|
|||
|
||||
#define collHandle(dir)\
|
||||
if (dir##Collides)\
|
||||
cornerNew.dir = (dir##Square) * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2 +\
|
||||
dir##Dir * (UNITS_PER_SQUARE / 2) - dir##Dir;\
|
||||
cornerNew.dir = (dir##Square) * UNITS_PER_SQUARE + UNITS_PER_SQUARE / 2\
|
||||
+ dir##Dir * (UNITS_PER_SQUARE / 2) - dir##Dir;\
|
||||
|
||||
collHandle(x)
|
||||
collHandle(y)
|
||||
|
@ -1062,6 +1068,10 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
|
|||
|
||||
camera->position.x = cornerNew.x - xDir * camera->collisionRadius;
|
||||
camera->position.y = cornerNew.y - yDir * camera->collisionRadius;
|
||||
}
|
||||
|
||||
if (movesInPlane || heightOffset != 0)
|
||||
{
|
||||
camera->height += heightOffset;
|
||||
|
||||
xSquareNew = divRoundDown(camera->position.x,UNITS_PER_SQUARE);
|
||||
|
@ -1074,6 +1084,7 @@ void moveCameraWithCollision(Camera *camera, Vector2D planeOffset,
|
|||
camera->height = clamp(camera->height,
|
||||
floorHeightNew + camera->collisionHeightBelow,
|
||||
ceilingHeightNew - camera->collisionHeightAbove);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue