From f3353d09e2c940acc5b8d28aacdddccfecce0660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 10 Sep 2018 17:40:27 +0200 Subject: [PATCH] Optimize --- demo1.cpp | 6 ++++-- demo2.cpp | 6 ++++-- demo3.cpp | 13 ++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/demo1.cpp b/demo1.cpp index c22ecfd..8436ccb 100644 --- a/demo1.cpp +++ b/demo1.cpp @@ -812,7 +812,6 @@ int main() previousTime = timeNow; int16_t horizontalStep = (dt * PLAYER_SPEED * (player.mRunning ? 2 : 1)) / 1000; - int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000; Vector2D d = angleToDirection(player.mCamera.direction); @@ -882,8 +881,11 @@ int main() moveOffset = d; } else + { + int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000; player.mCamera.direction += addition * rotationStep; - + } + Unit prevHeight = player.mCamera.height; moveCameraWithCollision(&player.mCamera,moveOffset,player.mVericalSpeed, diff --git a/demo2.cpp b/demo2.cpp index 6a2c33d..d19f15f 100644 --- a/demo2.cpp +++ b/demo2.cpp @@ -852,7 +852,6 @@ int main() previousTime = timeNow; int16_t horizontalStep = (dt * PLAYER_SPEED * (pokitto.bBtn() ? 2 : 1)) / 1000; - int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000; Vector2D d = angleToDirection(player.mCamera.direction); @@ -921,8 +920,11 @@ int main() moveOffset = d; } else + { + int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000; player.mCamera.direction += addition * rotationStep; - + } + Unit prevHeight = player.mCamera.height; moveCameraWithCollision(&player.mCamera,moveOffset,0, diff --git a/demo3.cpp b/demo3.cpp index 493a3a8..4fb7d84 100644 --- a/demo3.cpp +++ b/demo3.cpp @@ -176,8 +176,8 @@ Unit colorAt(int16_t x, int16_t y) heightProfile[absVal(y) % HEIGHT_PROFILE_LENGTH]) / 10,3); } -uint16_t previousColumn = 255; -uint16_t backgroundColumn = 0; +uint16_t previousColumn = 255; ///< Helper for precomputing background. +uint16_t backgroundColumn = 0; ///< Precomputed background column. /** Function for drawing a single pixel (like fragment shader). @@ -185,7 +185,6 @@ uint16_t backgroundColumn = 0; inline void pixelFunc(PixelInfo pixel) { uint8_t c = 0; - int16_t intensity = 0; if (pixel.isWall) @@ -263,9 +262,11 @@ int main() player.setPositionSquare(4,5); + // init changes + for (uint16_t i = 0; i < MAX_CHANGES; ++i) { - changes[i].mCoords.x = i; + changes[i].mCoords.x = (i + 1) * 1000; changes[i].mCoords.y = 0; changes[i].mHeight = floorHeightAt(i,0); } @@ -284,7 +285,6 @@ int main() previousTime = timeNow; int16_t horizontalStep = (dt * PLAYER_SPEED * (player.mRunning ? 2 : 1)) / 1000; - int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000; Vector2D d = angleToDirection(player.mCamera.direction); @@ -421,7 +421,10 @@ int main() moveOffset = d; } else + { + int16_t rotationStep = (dt * PLAYER_ROTATION_SPEED) / 1000; player.mCamera.direction = wrap(player.mCamera.direction + addition * rotationStep,UNITS_PER_SQUARE); + } } editCounter = max(0, editCounter - 1);